diff options
author | Thomas Lively <tlively@google.com> | 2024-12-20 16:43:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 16:43:02 -0800 |
commit | 4d8a933e1136159160f2b45ad3a9a1c82021a75b (patch) | |
tree | 3cd2878e4a938b1878f4adbae9a2967200e31cb9 /src/wasm/literal.cpp | |
parent | 5ed6cf191aa88b424f6784ba27ac2ab069234fd7 (diff) | |
download | binaryen-4d8a933e1136159160f2b45ad3a9a1c82021a75b.tar.gz binaryen-4d8a933e1136159160f2b45ad3a9a1c82021a75b.tar.bz2 binaryen-4d8a933e1136159160f2b45ad3a9a1c82021a75b.zip |
Fix UBSan on CI (#7173)
The UBSan builder started failing with an error about a misaligned store
in wasm-ctor-eval.cpp. The store was already done via `memcpy` to avoid
alignment issues, but apparently this is no longer enough. Use `void*`
as the destination type to further avoid giving the impression of
guaranteed alignment.
Also fix UB when executing std::abs on minimum negative integers in
literal.cpp.
Diffstat (limited to 'src/wasm/literal.cpp')
-rw-r--r-- | src/wasm/literal.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index b53378cfa..05027ee6b 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -978,8 +978,14 @@ Literal Literal::neg() const { Literal Literal::abs() const { switch (type.getBasic()) { case Type::i32: + if (i32 == std::numeric_limits<int32_t>::min()) { + return *this; + } return Literal(std::abs(i32)); case Type::i64: + if (i64 == std::numeric_limits<int64_t>::min()) { + return *this; + } return Literal(std::abs(i64)); case Type::f32: return Literal(i32 & 0x7fffffff).castToF32(); |