Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Unified Diff: test/cctest/wasm/test-run-wasm.cc

Issue 1839333002: [wasm] Fix asm.js semantics for divide by zero in WASM translation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Small code simplifications. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/mjsunit/wasm/asm-wasm-i32.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm.cc
diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc
index 617cec6a0f291f8c5ceb7e06ac3c976c03160a81..b5076362eed63122c1f6e08ac064a7264ec85ba5 100644
--- a/test/cctest/wasm/test-run-wasm.cc
+++ b/test/cctest/wasm/test-run-wasm.cc
@@ -327,33 +327,36 @@ TEST(Run_WasmI32Eqz) {
TEST(Run_WASM_Int32DivS_trap) {
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
CHECK_TRAP(r.Call(100, 0));
CHECK_TRAP(r.Call(-1001, 0));
- CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), -1));
- CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0));
+ CHECK_TRAP(r.Call(kMin, -1));
+ CHECK_TRAP(r.Call(kMin, 0));
}
TEST(Run_WASM_Int32RemS_trap) {
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(33, r.Call(133, 100));
- CHECK_EQ(0, r.Call(std::numeric_limits<int32_t>::min(), -1));
+ CHECK_EQ(0, r.Call(kMin, -1));
CHECK_TRAP(r.Call(100, 0));
CHECK_TRAP(r.Call(-1001, 0));
- CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0));
+ CHECK_TRAP(r.Call(kMin, 0));
}
TEST(Run_WASM_Int32DivU_trap) {
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
- CHECK_EQ(0, r.Call(std::numeric_limits<int32_t>::min(), -1));
+ CHECK_EQ(0, r.Call(kMin, -1));
CHECK_TRAP(r.Call(100, 0));
CHECK_TRAP(r.Call(-1001, 0));
- CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0));
+ CHECK_TRAP(r.Call(kMin, 0));
}
@@ -361,11 +364,63 @@ TEST(Run_WASM_Int32RemU_trap) {
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17, r.Call(217, 100));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_TRAP(r.Call(100, 0));
CHECK_TRAP(r.Call(-1001, 0));
- CHECK_TRAP(r.Call(std::numeric_limits<int32_t>::min(), 0));
- CHECK_EQ(std::numeric_limits<int32_t>::min(),
- r.Call(std::numeric_limits<int32_t>::min(), -1));
+ CHECK_TRAP(r.Call(kMin, 0));
+ CHECK_EQ(kMin, r.Call(kMin, -1));
+}
+
+TEST(Run_WASM_Int32DivS_asmjs) {
+ TestingModule module;
+ module.origin = kAsmJsOrigin;
+ WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
+ BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
+ CHECK_EQ(0, r.Call(0, 100));
+ CHECK_EQ(0, r.Call(100, 0));
+ CHECK_EQ(0, r.Call(-1001, 0));
+ CHECK_EQ(kMin, r.Call(kMin, -1));
+ CHECK_EQ(0, r.Call(kMin, 0));
+}
+
+TEST(Run_WASM_Int32RemS_asmjs) {
+ TestingModule module;
+ module.origin = kAsmJsOrigin;
+ WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
+ BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
+ CHECK_EQ(33, r.Call(133, 100));
+ CHECK_EQ(0, r.Call(kMin, -1));
+ CHECK_EQ(0, r.Call(100, 0));
+ CHECK_EQ(0, r.Call(-1001, 0));
+ CHECK_EQ(0, r.Call(kMin, 0));
+}
+
+TEST(Run_WASM_Int32DivU_asmjs) {
+ TestingModule module;
+ module.origin = kAsmJsOrigin;
+ WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
+ BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
+ CHECK_EQ(0, r.Call(0, 100));
+ CHECK_EQ(0, r.Call(kMin, -1));
+ CHECK_EQ(0, r.Call(100, 0));
+ CHECK_EQ(0, r.Call(-1001, 0));
+ CHECK_EQ(0, r.Call(kMin, 0));
+}
+
+TEST(Run_WASM_Int32RemU_asmjs) {
+ TestingModule module;
+ module.origin = kAsmJsOrigin;
+ WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
+ BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
+ const int32_t kMin = std::numeric_limits<int32_t>::min();
+ CHECK_EQ(17, r.Call(217, 100));
+ CHECK_EQ(0, r.Call(100, 0));
+ CHECK_EQ(0, r.Call(-1001, 0));
+ CHECK_EQ(0, r.Call(kMin, 0));
+ CHECK_EQ(kMin, r.Call(kMin, -1));
}
« no previous file with comments | « src/wasm/wasm-opcodes.h ('k') | test/mjsunit/wasm/asm-wasm-i32.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698