1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

LibWasm: Ensure that value signs are preserved when casting

Also makes normal arithmetic operations more spec-compliant by actually
ignoring overflow on them.
This commit is contained in:
Ali Mohammad Pur 2021-06-01 23:13:27 +04:30 committed by Ali Mohammad Pur
parent 02b3238c41
commit b15a5d6ada
2 changed files with 9 additions and 9 deletions

View file

@ -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():