Commit 87354ade authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Remove the WasmTrapHelper

Since TrapIf has been implemented on all platforms, there is no need
anymore for the old WasmTrapHelper code. This CL also removes
TrapIf-specific tests.

R=titzer@chromium.org, clemensh@chromium.org

Change-Id: Ic069598441b7bd63bde2e66f4e536abea5ecebe6
Reviewed-on: https://chromium-review.googlesource.com/452380
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43887}
parent ad75ded2
This diff is collapsed.
...@@ -166,6 +166,19 @@ class WasmGraphBuilder { ...@@ -166,6 +166,19 @@ class WasmGraphBuilder {
Node* BranchExpectTrue(Node* cond, Node** true_node, Node** false_node); Node* BranchExpectTrue(Node* cond, Node** true_node, Node** false_node);
Node* BranchExpectFalse(Node* cond, Node** true_node, Node** false_node); Node* BranchExpectFalse(Node* cond, Node** true_node, Node** false_node);
Node* TrapIfTrue(wasm::TrapReason reason, Node* cond,
wasm::WasmCodePosition position);
Node* TrapIfFalse(wasm::TrapReason reason, Node* cond,
wasm::WasmCodePosition position);
Node* TrapIfEq32(wasm::TrapReason reason, Node* node, int32_t val,
wasm::WasmCodePosition position);
Node* ZeroCheck32(wasm::TrapReason reason, Node* node,
wasm::WasmCodePosition position);
Node* TrapIfEq64(wasm::TrapReason reason, Node* node, int64_t val,
wasm::WasmCodePosition position);
Node* ZeroCheck64(wasm::TrapReason reason, Node* node,
wasm::WasmCodePosition position);
Node* Switch(unsigned count, Node* key); Node* Switch(unsigned count, Node* key);
Node* IfValue(int32_t value, Node* sw); Node* IfValue(int32_t value, Node* sw);
Node* IfDefault(Node* sw); Node* IfDefault(Node* sw);
...@@ -262,7 +275,6 @@ class WasmGraphBuilder { ...@@ -262,7 +275,6 @@ class WasmGraphBuilder {
Node* def_buffer_[kDefaultBufferSize]; Node* def_buffer_[kDefaultBufferSize];
bool has_simd_ = false; bool has_simd_ = false;
WasmTrapHelper* trap_;
wasm::FunctionSig* sig_; wasm::FunctionSig* sig_;
SetOncePointer<const Operator> allocate_heap_number_operator_; SetOncePointer<const Operator> allocate_heap_number_operator_;
......
...@@ -582,8 +582,6 @@ DEFINE_BOOL(wasm_guard_pages, false, ...@@ -582,8 +582,6 @@ DEFINE_BOOL(wasm_guard_pages, false,
"add guard pages to the end of WebWassembly memory" "add guard pages to the end of WebWassembly memory"
" (experimental, no effect on 32-bit)") " (experimental, no effect on 32-bit)")
DEFINE_IMPLICATION(wasm_trap_handler, wasm_guard_pages) DEFINE_IMPLICATION(wasm_trap_handler, wasm_guard_pages)
DEFINE_BOOL(wasm_trap_if, true,
"enable the use of the trap_if operator for traps")
DEFINE_BOOL(wasm_code_fuzzer_gen_test, false, DEFINE_BOOL(wasm_code_fuzzer_gen_test, false,
"Generate a test case when running the wasm-code fuzzer") "Generate a test case when running the wasm-code fuzzer")
DEFINE_BOOL(print_wasm_code, false, "Print WebAssembly code") DEFINE_BOOL(print_wasm_code, false, "Print WebAssembly code")
......
...@@ -1559,11 +1559,6 @@ bool Isolate::ComputeLocation(MessageLocation* target) { ...@@ -1559,11 +1559,6 @@ bool Isolate::ComputeLocation(MessageLocation* target) {
return false; return false;
} }
// TODO(wasm): Remove this once trap-if is always on.
// Background: Without trap-if, the information on the stack trace is
// incomplete (see bug v8:5007).
if (summary.IsWasmCompiled() && !FLAG_wasm_trap_if) return false;
if (summary.IsJavaScript()) { if (summary.IsJavaScript()) {
shared = handle(summary.AsJavaScript().function()->shared()); shared = handle(summary.AsJavaScript().function()->shared());
} }
......
...@@ -253,7 +253,7 @@ WASM_EXEC_TEST(I64SarUseOnlyLowWord) { ...@@ -253,7 +253,7 @@ WASM_EXEC_TEST(I64SarUseOnlyLowWord) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivS) { WASM_EXEC_TEST(I64DivS) {
REQUIRE(I64DivS); REQUIRE(I64DivS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -270,7 +270,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS) { ...@@ -270,7 +270,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) { WASM_EXEC_TEST(I64DivS_Trap) {
REQUIRE(I64DivS); REQUIRE(I64DivS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -281,7 +281,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) { ...@@ -281,7 +281,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) {
CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) { WASM_EXEC_TEST(I64DivS_Byzero_Const) {
REQUIRE(I64DivS); REQUIRE(I64DivS);
for (int8_t denom = -2; denom < 8; denom++) { for (int8_t denom = -2; denom < 8; denom++) {
WasmRunner<int64_t, int64_t> r(execution_mode); WasmRunner<int64_t, int64_t> r(execution_mode);
...@@ -296,7 +296,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) { ...@@ -296,7 +296,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivU) { WASM_EXEC_TEST(I64DivU) {
REQUIRE(I64DivU); REQUIRE(I64DivU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -311,7 +311,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU) { ...@@ -311,7 +311,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) { WASM_EXEC_TEST(I64DivU_Trap) {
REQUIRE(I64DivU); REQUIRE(I64DivU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -321,7 +321,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) { ...@@ -321,7 +321,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) {
CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0))); CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
} }
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) { WASM_EXEC_TEST(I64DivU_Byzero_Const) {
REQUIRE(I64DivU); REQUIRE(I64DivU);
for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) { for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
WasmRunner<uint64_t, uint64_t> r(execution_mode); WasmRunner<uint64_t, uint64_t> r(execution_mode);
...@@ -337,7 +337,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) { ...@@ -337,7 +337,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64RemS) { WASM_EXEC_TEST(I64RemS) {
REQUIRE(I64RemS); REQUIRE(I64RemS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -352,7 +352,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS) { ...@@ -352,7 +352,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) { WASM_EXEC_TEST(I64RemS_Trap) {
REQUIRE(I64RemS); REQUIRE(I64RemS);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode); WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -363,7 +363,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) { ...@@ -363,7 +363,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) {
CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0))); CHECK_TRAP64(r.Call(std::numeric_limits<int64_t>::min(), asi64(0)));
} }
WASM_EXEC_TEST_WITH_TRAP(I64RemU) { WASM_EXEC_TEST(I64RemU) {
REQUIRE(I64RemU); REQUIRE(I64RemU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -378,7 +378,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU) { ...@@ -378,7 +378,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) { WASM_EXEC_TEST(I64RemU_Trap) {
REQUIRE(I64RemU); REQUIRE(I64RemU);
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode); WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
...@@ -839,7 +839,7 @@ WASM_EXEC_TEST(F64UConvertI64) { ...@@ -839,7 +839,7 @@ WASM_EXEC_TEST(F64UConvertI64) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) { WASM_EXEC_TEST(I64SConvertF32a) {
WasmRunner<int64_t, float> r(execution_mode); WasmRunner<int64_t, float> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
...@@ -853,7 +853,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) { ...@@ -853,7 +853,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) { WASM_EXEC_TEST(I64SConvertF64a) {
WasmRunner<int64_t, double> r(execution_mode); WasmRunner<int64_t, double> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
...@@ -867,7 +867,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) { ...@@ -867,7 +867,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) { WASM_EXEC_TEST(I64UConvertF32a) {
WasmRunner<uint64_t, float> r(execution_mode); WasmRunner<uint64_t, float> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
...@@ -881,7 +881,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) { ...@@ -881,7 +881,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) { WASM_EXEC_TEST(I64UConvertF64a) {
WasmRunner<uint64_t, double> r(execution_mode); WasmRunner<uint64_t, double> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
...@@ -1248,7 +1248,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) { ...@@ -1248,7 +1248,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) { WASM_EXEC_TEST(I64SConvertF32b) {
REQUIRE(I64SConvertF32); REQUIRE(I64SConvertF32);
WasmRunner<int64_t, float> r(execution_mode); WasmRunner<int64_t, float> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
...@@ -1263,7 +1263,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) { ...@@ -1263,7 +1263,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) { WASM_EXEC_TEST(I64SConvertF64b) {
REQUIRE(I64SConvertF64); REQUIRE(I64SConvertF64);
WasmRunner<int64_t, double> r(execution_mode); WasmRunner<int64_t, double> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
...@@ -1278,7 +1278,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) { ...@@ -1278,7 +1278,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) { WASM_EXEC_TEST(I64UConvertF32b) {
REQUIRE(I64UConvertF32); REQUIRE(I64UConvertF32);
WasmRunner<uint64_t, float> r(execution_mode); WasmRunner<uint64_t, float> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
...@@ -1292,7 +1292,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) { ...@@ -1292,7 +1292,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) { WASM_EXEC_TEST(I64UConvertF64b) {
REQUIRE(I64UConvertF64); REQUIRE(I64UConvertF64);
WasmRunner<uint64_t, double> r(execution_mode); WasmRunner<uint64_t, double> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
...@@ -1499,7 +1499,9 @@ WASM_EXEC_TEST(I64Rol) { ...@@ -1499,7 +1499,9 @@ WASM_EXEC_TEST(I64Rol) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) { WASM_EXEC_TEST(StoreMem_offset_oob_i64) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
static const MachineType machineTypes[] = { static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
......
...@@ -346,7 +346,7 @@ WASM_EXEC_TEST(I32Sar) { ...@@ -346,7 +346,7 @@ WASM_EXEC_TEST(I32Sar) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) { WASM_EXEC_TEST(Int32DivS_trap) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min(); const int32_t kMin = std::numeric_limits<int32_t>::min();
...@@ -357,7 +357,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) { ...@@ -357,7 +357,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) {
CHECK_TRAP(r.Call(kMin, 0)); CHECK_TRAP(r.Call(kMin, 0));
} }
WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) { WASM_EXEC_TEST(Int32RemS_trap) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min(); const int32_t kMin = std::numeric_limits<int32_t>::min();
...@@ -368,7 +368,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) { ...@@ -368,7 +368,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) {
CHECK_TRAP(r.Call(kMin, 0)); CHECK_TRAP(r.Call(kMin, 0));
} }
WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) { WASM_EXEC_TEST(Int32DivU_trap) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min(); const int32_t kMin = std::numeric_limits<int32_t>::min();
...@@ -379,7 +379,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) { ...@@ -379,7 +379,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) {
CHECK_TRAP(r.Call(kMin, 0)); CHECK_TRAP(r.Call(kMin, 0));
} }
WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) { WASM_EXEC_TEST(Int32RemU_trap) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17, r.Call(217, 100)); CHECK_EQ(17, r.Call(217, 100));
...@@ -390,7 +390,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) { ...@@ -390,7 +390,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) {
CHECK_EQ(kMin, r.Call(kMin, -1)); CHECK_EQ(kMin, r.Call(kMin, -1));
} }
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) { WASM_EXEC_TEST(Int32DivS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) { for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
...@@ -438,7 +438,7 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) { ...@@ -438,7 +438,7 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(Int32DivU_byzero_const) { WASM_EXEC_TEST(Int32DivU_byzero_const) {
for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) { for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
WasmRunner<uint32_t, uint32_t> r(execution_mode); WasmRunner<uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
...@@ -453,7 +453,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_byzero_const) { ...@@ -453,7 +453,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_byzero_const) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap_effect) { WASM_EXEC_TEST(Int32DivS_trap_effect) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8); r.module().AddMemoryElems<int32_t>(8);
...@@ -1062,7 +1062,9 @@ WASM_EXEC_TEST(SignallingNanSurvivesI32ReinterpretF32) { ...@@ -1062,7 +1062,9 @@ WASM_EXEC_TEST(SignallingNanSurvivesI32ReinterpretF32) {
#endif #endif
WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { WASM_EXEC_TEST(LoadMaxUint32Offset) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8); r.module().AddMemoryElems<int32_t>(8);
...@@ -1455,7 +1457,9 @@ WASM_EXEC_TEST(LoadMemI32_alignment) { ...@@ -1455,7 +1457,9 @@ WASM_EXEC_TEST(LoadMemI32_alignment) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) { WASM_EXEC_TEST(LoadMemI32_oob) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
WasmRunner<int32_t, uint32_t> r(execution_mode); WasmRunner<int32_t, uint32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8); int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1111); r.module().RandomizeMemory(1111);
...@@ -1473,7 +1477,9 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) { ...@@ -1473,7 +1477,9 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) { WASM_EXEC_TEST(LoadMem_offset_oob) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
static const MachineType machineTypes[] = { static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
...@@ -1522,7 +1528,9 @@ WASM_EXEC_TEST(LoadMemI32_offset) { ...@@ -1522,7 +1528,9 @@ WASM_EXEC_TEST(LoadMemI32_offset) {
CHECK_EQ(44444444, r.Call(8)); CHECK_EQ(44444444, r.Call(8));
} }
WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
const int kMemSize = 12; const int kMemSize = 12;
// TODO(titzer): Fix misaligned accesses on MIPS and re-enable. // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
for (int offset = 0; offset < kMemSize + 5; ++offset) { for (int offset = 0; offset < kMemSize + 5; ++offset) {
...@@ -1543,7 +1551,9 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { ...@@ -1543,7 +1551,9 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) { WASM_EXEC_TEST(LoadMemI32_const_oob) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
const int kMemSize = 24; const int kMemSize = 24;
for (int offset = 0; offset < kMemSize + 5; offset += 4) { for (int offset = 0; offset < kMemSize + 5; offset += 4) {
for (int index = 0; index < kMemSize + 5; index += 4) { for (int index = 0; index < kMemSize + 5; index += 4) {
...@@ -1603,7 +1613,9 @@ WASM_EXEC_TEST(StoreMemI32_offset) { ...@@ -1603,7 +1613,9 @@ WASM_EXEC_TEST(StoreMemI32_offset) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) { WASM_EXEC_TEST(StoreMem_offset_oob) {
// TODO(eholk): Fix this test for the trap handler.
if (trap_handler::UseTrapHandler()) return;
// 64-bit cases are handled in test-run-wasm-64.cc // 64-bit cases are handled in test-run-wasm-64.cc
static const MachineType machineTypes[] = { static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
...@@ -2526,7 +2538,7 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) { ...@@ -2526,7 +2538,7 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) {
CHECK_EQ(14, r.Call(0, 0)); CHECK_EQ(14, r.Call(0, 0));
} }
WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) { WASM_EXEC_TEST(SimpleCallIndirect) {
TestSignatures sigs; TestSignatures sigs;
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
...@@ -2560,7 +2572,7 @@ WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) { ...@@ -2560,7 +2572,7 @@ WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) {
CHECK_TRAP(r.Call(2)); CHECK_TRAP(r.Call(2));
} }
WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) { WASM_EXEC_TEST(MultipleCallIndirect) {
TestSignatures sigs; TestSignatures sigs;
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_mode);
...@@ -2603,7 +2615,7 @@ WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) { ...@@ -2603,7 +2615,7 @@ WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) {
CHECK_TRAP(r.Call(2, 1, 0)); CHECK_TRAP(r.Call(2, 1, 0));
} }
WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) { WASM_EXEC_TEST(CallIndirect_EmptyTable) {
TestSignatures sigs; TestSignatures sigs;
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
...@@ -2626,7 +2638,7 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) { ...@@ -2626,7 +2638,7 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) {
CHECK_TRAP(r.Call(2)); CHECK_TRAP(r.Call(2));
} }
WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) { WASM_EXEC_TEST(CallIndirect_canonical) {
TestSignatures sigs; TestSignatures sigs;
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
...@@ -2764,7 +2776,7 @@ WASM_EXEC_TEST(F64Max) { ...@@ -2764,7 +2776,7 @@ WASM_EXEC_TEST(F64Max) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) { WASM_EXEC_TEST(I32SConvertF32) {
WasmRunner<int32_t, float> r(execution_mode); WasmRunner<int32_t, float> r(execution_mode);
BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0)));
...@@ -2784,7 +2796,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) { ...@@ -2784,7 +2796,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) { WASM_EXEC_TEST(I32SConvertF64) {
WasmRunner<int32_t, double> r(execution_mode); WasmRunner<int32_t, double> r(execution_mode);
BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0)));
...@@ -2803,7 +2815,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) { ...@@ -2803,7 +2815,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) { WASM_EXEC_TEST(I32UConvertF32) {
WasmRunner<uint32_t, float> r(execution_mode); WasmRunner<uint32_t, float> r(execution_mode);
BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0)));
// The upper bound is (UINT32_MAX + 1), which is the lowest // The upper bound is (UINT32_MAX + 1), which is the lowest
...@@ -2820,7 +2832,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) { ...@@ -2820,7 +2832,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) {
} }
} }
WASM_EXEC_TEST_WITH_TRAP(I32UConvertF64) { WASM_EXEC_TEST(I32UConvertF64) {
WasmRunner<uint32_t, double> r(execution_mode); WasmRunner<uint32_t, double> r(execution_mode);
BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0)));
// The upper bound is (UINT32_MAX + 1), which is the lowest // The upper bound is (UINT32_MAX + 1), which is the lowest
...@@ -2886,7 +2898,7 @@ TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); } ...@@ -2886,7 +2898,7 @@ TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); }
TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); } TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); }
WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) { WASM_EXEC_TEST(Int32RemS_dead) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
WASM_ZERO); WASM_ZERO);
......
...@@ -853,15 +853,6 @@ bool WasmRunnerBase::trap_happened; ...@@ -853,15 +853,6 @@ bool WasmRunnerBase::trap_happened;
} \ } \
RunWasm_##name(kExecuteCompiled); \ RunWasm_##name(kExecuteCompiled); \
} \ } \
TEST(RunWasmCompiledWithoutTrapIf_##name) { \
if (trap_handler::UseTrapHandler()) { \
return; \
} \
bool trap_if = FLAG_wasm_trap_if; \
FLAG_wasm_trap_if = true; \
RunWasm_##name(kExecuteCompiled); \
FLAG_wasm_trap_if = trap_if; \
} \
TEST(RunWasmInterpreted_##name) { \ TEST(RunWasmInterpreted_##name) { \
if (trap_handler::UseTrapHandler()) { \ if (trap_handler::UseTrapHandler()) { \
return; \ return; \
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --trap-if
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
// Collect the Callsite objects instead of just a string:
Error.prepareStackTrace = function(error, frames) {
return frames;
};
var builder = new WasmModuleBuilder();
builder.addMemory(0, 1, false);
var sig_index = builder.addType(kSig_i_v)
// Build a function to resemble this code:
// if (idx < 2) {
// return load(-2 / idx);
// } else if (idx == 2) {
// unreachable;
// } else {
// return call_indirect(idx);
// }
// There are four different traps which are triggered by different input values:
// (0) division by zero; (1) mem oob; (2) unreachable; (3) invalid call target
// Each of them also has a different location where it traps.
builder.addFunction("main", kSig_i_i)
.addBody([
// offset 1
kExprBlock, kWasmI32,
kExprGetLocal, 0,
kExprI32Const, 2,
kExprI32LtU,
kExprIf, kWasmStmt,
// offset 9
kExprI32Const, 0x7e /* -2 */,
kExprGetLocal, 0,
kExprI32DivU,
// offset 15
kExprI32LoadMem, 0, 0,
kExprBr, 1,
kExprEnd,
// offset 21
kExprGetLocal, 0,
kExprI32Const, 2,
kExprI32Eq,
kExprIf, kWasmStmt,
kExprUnreachable,
kExprEnd,
// offset 30
kExprGetLocal, 0,
kExprCallIndirect, sig_index, kTableZero,
kExprEnd,
])
.exportAs("main");
builder.appendToTable([0]);
var module = builder.instantiate();
function testWasmTrap(value, reason, position) {
try {
module.exports.main(value);
fail("expected wasm exception");
} catch (e) {
assertEquals(kTrapMsgs[reason], e.message, "trap reason");
assertEquals(3, e.stack.length, "number of frames");
assertEquals(0, e.stack[0].getLineNumber(), "wasmFunctionIndex");
assertEquals(position, e.stack[0].getPosition(), "position");
}
}
// The actual tests:
testWasmTrap(0, kTrapDivByZero, 14);
testWasmTrap(1, kTrapMemOutOfBounds, 15);
testWasmTrap(2, kTrapUnreachable, 28);
testWasmTrap(3, kTrapFuncInvalid, 32);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment