From 3c8e1598bdf3808c5e6177d534c683e132213c1c Mon Sep 17 00:00:00 2001 From: Clemens Hammacher Date: Tue, 12 Sep 2017 13:00:20 +0200 Subject: [PATCH] [wasm] [test] Introduce enum for runtime exception support We were using a boolean before, which makes the meaning non-obvious when passed as a parameter. With the enum, you actually have to use {kRuntimeExceptionSupport} or {kNoRuntimeExceptionSupport}. R=mtrofin@chromium.org Change-Id: Iaf5a7b6f1b446d4c3e16e044a6055d923d3b0b49 Reviewed-on: https://chromium-review.googlesource.com/660738 Commit-Queue: Clemens Hammacher Reviewed-by: Mircea Trofin Cr-Commit-Position: refs/heads/master@{#47969} --- src/compiler/wasm-compiler.cc | 4 ++-- src/compiler/wasm-compiler.h | 11 ++++++--- test/cctest/wasm/test-run-wasm.cc | 6 +++-- test/cctest/wasm/test-wasm-stack.cc | 3 ++- test/cctest/wasm/test-wasm-trap-position.cc | 6 +++-- test/cctest/wasm/wasm-run-utils.cc | 20 ++++++++-------- test/cctest/wasm/wasm-run-utils.h | 26 +++++++++++---------- 7 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc index 4e9ac82aaa..2f0e2e181c 100644 --- a/src/compiler/wasm-compiler.cc +++ b/src/compiler/wasm-compiler.cc @@ -194,7 +194,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position, Node** effect, Node** control) { // TODO(mtrofin): "!env_" happens when we generate a wrapper. // We should factor wrappers separately from wasm codegen. - if (FLAG_wasm_no_stack_checks || !env_ || !has_runtime_exception_support_) { + if (FLAG_wasm_no_stack_checks || !env_ || !runtime_exception_support_) { return; } if (effect == nullptr) effect = effect_; @@ -830,7 +830,7 @@ Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node, } Builtins::Name WasmGraphBuilder::GetBuiltinIdForTrap(wasm::TrapReason reason) { - if (!has_runtime_exception_support_) { + if (runtime_exception_support_ == kNoRuntimeExceptionSupport) { // We use Builtins::builtin_count as a marker to tell the code generator // to generate a call to a testing c-function instead of a runtime // function. This code should only be called from a cctest. diff --git a/src/compiler/wasm-compiler.h b/src/compiler/wasm-compiler.h index b6c7f9aba4..9e535e6c44 100644 --- a/src/compiler/wasm-compiler.h +++ b/src/compiler/wasm-compiler.h @@ -78,6 +78,11 @@ struct ModuleEnv { const uintptr_t globals_start; }; +enum RuntimeExceptionSupport : bool { + kRuntimeExceptionSupport = true, + kNoRuntimeExceptionSupport = false +}; + class WasmCompilationUnit final { public: // If constructing from a background thread, pass in a Counters*, and ensure @@ -317,8 +322,8 @@ class WasmGraphBuilder { bool has_simd() const { return has_simd_; } - void SetRuntimeExceptionSupport(bool value) { - has_runtime_exception_support_ = value; + void set_runtime_exception_support(RuntimeExceptionSupport value) { + runtime_exception_support_ = value; } const wasm::WasmModule* module() { return env_ ? env_->module : nullptr; } @@ -345,7 +350,7 @@ class WasmGraphBuilder { // If the runtime doesn't support exception propagation, // we won't generate stack checks, and trap handling will also // be generated differently. - bool has_runtime_exception_support_ = true; + RuntimeExceptionSupport runtime_exception_support_ = kRuntimeExceptionSupport; wasm::FunctionSig* sig_; SetOncePointer allocate_heap_number_operator_; diff --git a/test/cctest/wasm/test-run-wasm.cc b/test/cctest/wasm/test-run-wasm.cc index 2c8fca8c73..e276d3abd9 100644 --- a/test/cctest/wasm/test-run-wasm.cc +++ b/test/cctest/wasm/test-run-wasm.cc @@ -1951,7 +1951,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast(opcode), WASM_END}; TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, - code + arraysize(code)); + code + arraysize(code), + compiler::kNoRuntimeExceptionSupport); } else { CHECK_EQ(2, sig->parameter_count()); byte code[] = {WASM_NO_LOCALS, @@ -1962,7 +1963,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { static_cast(opcode), WASM_END}; TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, - code + arraysize(code)); + code + arraysize(code), + compiler::kNoRuntimeExceptionSupport); } } diff --git a/test/cctest/wasm/test-wasm-stack.cc b/test/cctest/wasm/test-wasm-stack.cc index fb62a9633b..f06317384b 100644 --- a/test/cctest/wasm/test-wasm-stack.cc +++ b/test/cctest/wasm/test-wasm-stack.cc @@ -155,7 +155,8 @@ TEST(CollectDetailedWasmStack_WasmError) { int unreachable_pos = 1 << (8 * pos_shift); TestSignatures sigs; // Create a WasmRunner with stack checks and traps enabled. - WasmRunner r(kExecuteCompiled, "main", true); + WasmRunner r(kExecuteCompiled, "main", + compiler::kRuntimeExceptionSupport); std::vector code(unreachable_pos + 1, kExprNop); code[unreachable_pos] = kExprUnreachable; diff --git a/test/cctest/wasm/test-wasm-trap-position.cc b/test/cctest/wasm/test-wasm-trap-position.cc index 9c6c81bd79..e167cd0c47 100644 --- a/test/cctest/wasm/test-wasm-trap-position.cc +++ b/test/cctest/wasm/test-wasm-trap-position.cc @@ -68,7 +68,8 @@ void CheckExceptionInfos(v8::internal::Isolate* i_isolate, Handle exc, // Trigger a trap for executing unreachable. TEST(Unreachable) { // Create a WasmRunner with stack checks and traps enabled. - WasmRunner r(kExecuteCompiled, "main", true); + WasmRunner r(kExecuteCompiled, "main", + compiler::kRuntimeExceptionSupport); TestSignatures sigs; BUILD(r, WASM_UNREACHABLE); @@ -102,7 +103,8 @@ TEST(Unreachable) { // Trigger a trap for loading from out-of-bounds. TEST(IllegalLoad) { - WasmRunner r(kExecuteCompiled, "main", true); + WasmRunner r(kExecuteCompiled, "main", + compiler::kRuntimeExceptionSupport); TestSignatures sigs; r.builder().AddMemory(0L); diff --git a/test/cctest/wasm/wasm-run-utils.cc b/test/cctest/wasm/wasm-run-utils.cc index 5c4ed0c626..b127db9adb 100644 --- a/test/cctest/wasm/wasm-run-utils.cc +++ b/test/cctest/wasm/wasm-run-utils.cc @@ -239,15 +239,15 @@ Handle TestingModuleBuilder::InitInstanceObject() { return WasmInstanceObject::New(isolate_, compiled_module); } -void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph, - compiler::ModuleEnv* module, FunctionSig* sig, - compiler::SourcePositionTable* source_position_table, - const byte* start, const byte* end, - bool runtime_exception_support) { +void TestBuildingGraph( + Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module, + FunctionSig* sig, compiler::SourcePositionTable* source_position_table, + const byte* start, const byte* end, + compiler::RuntimeExceptionSupport runtime_exception_support) { compiler::WasmGraphBuilder builder( module, zone, jsgraph, CEntryStub(jsgraph->isolate(), 1).GetCode(), sig, source_position_table); - builder.SetRuntimeExceptionSupport(runtime_exception_support); + builder.set_runtime_exception_support(runtime_exception_support); DecodeResult result = BuildTFGraph(zone->allocator(), &builder, sig, start, end); @@ -420,10 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) { } } -WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig, - TestingModuleBuilder* builder, - const char* name, - bool runtime_exception_support) +WasmFunctionCompiler::WasmFunctionCompiler( + Zone* zone, FunctionSig* sig, TestingModuleBuilder* builder, + const char* name, + compiler::RuntimeExceptionSupport runtime_exception_support) : GraphAndBuilders(zone), jsgraph(builder->isolate(), this->graph(), this->common(), nullptr, nullptr, this->machine()), diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h index 0f3236200a..4af9440076 100644 --- a/test/cctest/wasm/wasm-run-utils.h +++ b/test/cctest/wasm/wasm-run-utils.h @@ -210,11 +210,11 @@ class TestingModuleBuilder { Handle InitInstanceObject(); }; -void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph, - compiler::ModuleEnv* module, FunctionSig* sig, - compiler::SourcePositionTable* source_position_table, - const byte* start, const byte* end, - bool runtime_exception_support = false); +void TestBuildingGraph( + Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module, + FunctionSig* sig, compiler::SourcePositionTable* source_position_table, + const byte* start, const byte* end, + compiler::RuntimeExceptionSupport runtime_exception_support); class WasmFunctionWrapper : private compiler::GraphAndBuilders { public: @@ -275,9 +275,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { private: friend class WasmRunnerBase; - WasmFunctionCompiler(Zone* zone, FunctionSig* sig, - TestingModuleBuilder* builder, const char* name, - bool runtime_exception_support); + WasmFunctionCompiler(Zone*, FunctionSig*, TestingModuleBuilder*, + const char* name, compiler::RuntimeExceptionSupport); Handle Compile(); @@ -290,7 +289,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { LocalDeclEncoder local_decls; compiler::SourcePositionTable source_position_table_; WasmInterpreter* interpreter_; - bool runtime_exception_support_ = false; + compiler::RuntimeExceptionSupport runtime_exception_support_ = + compiler::kNoRuntimeExceptionSupport; }; // A helper class to build a module around Wasm bytecode, generate machine @@ -298,7 +298,7 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders { class WasmRunnerBase : public HandleAndZoneScope { public: WasmRunnerBase(WasmExecutionMode execution_mode, int num_params, - bool runtime_exception_support) + compiler::RuntimeExceptionSupport runtime_exception_support) : zone_(&allocator_, ZONE_NAME), builder_(&zone_, execution_mode), wrapper_(&zone_, num_params), @@ -367,7 +367,8 @@ class WasmRunnerBase : public HandleAndZoneScope { WasmFunctionWrapper wrapper_; bool compiled_ = false; bool possible_nondeterminism_ = false; - bool runtime_exception_support_ = false; + compiler::RuntimeExceptionSupport runtime_exception_support_ = + compiler::kNoRuntimeExceptionSupport; public: // This field has to be static. Otherwise, gcc complains about the use in @@ -380,7 +381,8 @@ class WasmRunner : public WasmRunnerBase { public: WasmRunner(WasmExecutionMode execution_mode, const char* main_fn_name = "main", - bool runtime_exception_support = false) + compiler::RuntimeExceptionSupport runtime_exception_support = + compiler::kNoRuntimeExceptionSupport) : WasmRunnerBase(execution_mode, sizeof...(ParamTypes), runtime_exception_support) { NewFunction(main_fn_name);