diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-06-01 23:13:27 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-02 16:09:16 +0430 |
commit | b15a5d6adaa369f23b02238a7f338cbb0215fb9d (patch) | |
tree | 0b64d0ce2fc6438ebf4398f0330da3750bebbdfc | |
parent | 02b3238c41efb80df52d4d7962c11bd39d1fc84c (diff) | |
download | serenity-b15a5d6adaa369f23b02238a7f338cbb0215fb9d.zip |
LibWasm: Ensure that value signs are preserved when casting
Also makes normal arithmetic operations more spec-compliant by actually
ignoring overflow on them.
-rw-r--r-- | Tests/LibWasm/test-wasm.cpp | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp index ecd89f8932..d1143bf1c6 100644 --- a/Tests/LibWasm/test-wasm.cpp +++ b/Tests/LibWasm/test-wasm.cpp @@ -173,10 +173,10 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke) auto value = vm.argument(index++).to_double(global_object); switch (param.kind()) { case Wasm::ValueType::Kind::I32: - arguments.append(Wasm::Value(static_cast<i32>(value))); + arguments.append(Wasm::Value(param, static_cast<u64>(value))); break; case Wasm::ValueType::Kind::I64: - arguments.append(Wasm::Value(static_cast<i64>(value))); + arguments.append(Wasm::Value(param, static_cast<u64>(value))); break; case Wasm::ValueType::Kind::F32: arguments.append(Wasm::Value(static_cast<float>(value))); diff --git a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp index 758d2ddddd..120d2fb0f7 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/Interpreter.cpp @@ -700,17 +700,17 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::i32_popcnt.value(): goto unimplemented; case Instructions::i32_add.value(): - OVF_CHECKED_BINARY_NUMERIC_OPERATION(i32, +, i32); + BINARY_NUMERIC_OPERATION(i32, +, i32); case Instructions::i32_sub.value(): - OVF_CHECKED_BINARY_NUMERIC_OPERATION(i32, -, i32); + BINARY_NUMERIC_OPERATION(i32, -, i32); case Instructions::i32_mul.value(): - OVF_CHECKED_BINARY_NUMERIC_OPERATION(i32, *, i32); + BINARY_NUMERIC_OPERATION(i32, *, i32); case Instructions::i32_divs.value(): - OVF_CHECKED_BINARY_NUMERIC_OPERATION(i32, /, i32, TRAP_IF_NOT(rhs.value() != 0)); + BINARY_NUMERIC_OPERATION(i32, /, i32, TRAP_IF_NOT(!(Checked<i32>(lhs.value()) /= rhs.value()).has_overflow())); case Instructions::i32_divu.value(): - OVF_CHECKED_BINARY_NUMERIC_OPERATION(u32, /, i32, TRAP_IF_NOT(rhs.value() != 0)); + BINARY_NUMERIC_OPERATION(u32, /, i32, TRAP_IF_NOT(rhs.value() != 0)); case Instructions::i32_rems.value(): - BINARY_NUMERIC_OPERATION(i32, %, i32, TRAP_IF_NOT(rhs.value() != 0)); + BINARY_NUMERIC_OPERATION(i32, %, i32, TRAP_IF_NOT(!(Checked<i32>(lhs.value()) /= rhs.value()).has_overflow())); case Instructions::i32_remu.value(): BINARY_NUMERIC_OPERATION(u32, %, i32, TRAP_IF_NOT(rhs.value() != 0)); case Instructions::i32_and.value(): @@ -742,7 +742,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi case Instructions::i64_divu.value(): OVF_CHECKED_BINARY_NUMERIC_OPERATION(u64, /, i64, TRAP_IF_NOT(rhs.value() != 0)); case Instructions::i64_rems.value(): - BINARY_NUMERIC_OPERATION(i64, %, i64, TRAP_IF_NOT(rhs.value() != 0)); + BINARY_NUMERIC_OPERATION(i64, %, i64, TRAP_IF_NOT(!(Checked<i32>(lhs.value()) /= rhs.value()).has_overflow())); case Instructions::i64_remu.value(): BINARY_NUMERIC_OPERATION(u64, %, i64, TRAP_IF_NOT(rhs.value() != 0)); case Instructions::i64_and.value(): |