From ca1a2cfb391bcf02c0a55ceab616e67f81ea5eaa Mon Sep 17 00:00:00 2001 From: Thibaud Michaud Date: Mon, 31 May 2021 11:26:42 +0200 Subject: [PATCH] [wasm][interpreter][eh] Fix unreachable ref The delegate instruction is executed when an exception is thrown, not after the last instruction of the block. Handle reachability accordingly. R=ahaas@chromium.org Bug: chromium:1212396 Change-Id: I55e342cd73da44142cfbad7e16ab65ef513e6a60 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2928499 Reviewed-by: Andreas Haas Commit-Queue: Thibaud Michaud Cr-Commit-Position: refs/heads/master@{#74855} --- test/cctest/wasm/test-run-wasm-exceptions.cc | 11 +++++++++++ test/common/wasm/wasm-interpreter.cc | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/test/cctest/wasm/test-run-wasm-exceptions.cc b/test/cctest/wasm/test-run-wasm-exceptions.cc index 284f27ec44..8188b66c1e 100644 --- a/test/cctest/wasm/test-run-wasm-exceptions.cc +++ b/test/cctest/wasm/test-run-wasm-exceptions.cc @@ -699,6 +699,17 @@ TEST(Regress1197408) { CHECK_EQ(0, r.CallInterpreter(0, 0, 0)); } +TEST(Regress1212396) { + TestSignatures sigs; + EXPERIMENTAL_FLAG_SCOPE(eh); + WasmRunner r(TestExecutionTier::kInterpreter); + uint32_t except = r.builder().AddException(sigs.v_v()); + BUILD(r, kExprTry, kVoidCode, kExprTry, kVoidCode, kExprI32Const, 0, + kExprThrow, except, kExprDelegate, 0, kExprCatch, except, kExprEnd, + kExprI32Const, 42); + CHECK_EQ(42, r.CallInterpreter()); +} + } // namespace test_run_wasm_exceptions } // namespace wasm } // namespace internal diff --git a/test/common/wasm/wasm-interpreter.cc b/test/common/wasm/wasm-interpreter.cc index cbf3e16ee4..d8563dede8 100644 --- a/test/common/wasm/wasm-interpreter.cc +++ b/test/common/wasm/wasm-interpreter.cc @@ -1005,7 +1005,7 @@ class SideTable : public ZoneObject { Control* target = &control_stack[max_depth - imm.depth]; DCHECK_EQ(*target->pc, kExprTry); DCHECK_NOT_NULL(target->else_label); - if (!unreachable) { + if (!control_parent().unreachable) { target->else_label->Ref(i.pc(), c->end_label->target_stack_height); }