From dc511bf288450b2ca571292b7cc0e2a081d5ef78 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Feb 2021 13:11:57 -0800 Subject: [PATCH 1/3] fix --- src/wasm-stack.h | 2 ++ src/wasm/wasm-stack.cpp | 5 +++ ...nerate-stack-ir_roundtrip_all-features.txt | 32 +++++++++++++++++++ ...erate-stack-ir_roundtrip_all-features.wast | 27 ++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 test/passes/generate-stack-ir_roundtrip_all-features.txt create mode 100644 test/passes/generate-stack-ir_roundtrip_all-features.wast diff --git a/src/wasm-stack.h b/src/wasm-stack.h index 7f94573fa5f..5af9adbce4f 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -350,6 +350,8 @@ template void BinaryenIRWriter::visitTry(Try* curr) { } if (curr->isDelegate()) { emitDelegate(curr); + // Note that when we emit a delegate we do not need to also emit a scope + // ending, as the delegate ends the scope. } else { emitScopeEnd(curr); } diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index b6c0392ca04..4c4e4e9d1a3 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -1925,6 +1925,9 @@ void BinaryInstWriter::emitCatchAll(Try* curr) { } void BinaryInstWriter::emitDelegate(Try* curr) { + // The delegate ends the scope in effect, and pops the try's name. Note that + // the getBreakIndex is intentionally after that pop, as the delegate cannot + // target its own try. assert(!breakStack.empty()); breakStack.pop_back(); o << int8_t(BinaryConsts::Delegate) @@ -2333,6 +2336,8 @@ void StackIRToBinaryWriter::write() { } case StackInst::Delegate: { writer.emitDelegate(inst->origin->cast()); + // Delegates end the try, like a TryEnd. + catchIndexStack.pop_back(); break; } default: diff --git a/test/passes/generate-stack-ir_roundtrip_all-features.txt b/test/passes/generate-stack-ir_roundtrip_all-features.txt new file mode 100644 index 00000000000..3d06adff189 --- /dev/null +++ b/test/passes/generate-stack-ir_roundtrip_all-features.txt @@ -0,0 +1,32 @@ +(module + (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (event $event$0 (attr 0) (param i32)) + (func $delegate-child + (try $label$9 + (do + (try $label$7 + (do + (nop) + ) + (catch $event$0 + (drop + (pop i32) + ) + (try $label$6 + (do + (nop) + ) + (delegate 2) + ) + ) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + ) + ) + ) +) diff --git a/test/passes/generate-stack-ir_roundtrip_all-features.wast b/test/passes/generate-stack-ir_roundtrip_all-features.wast new file mode 100644 index 00000000000..1230e3cf17d --- /dev/null +++ b/test/passes/generate-stack-ir_roundtrip_all-features.wast @@ -0,0 +1,27 @@ +(module + (event $event (attr 0) (param i32)) + (func $delegate-child + (try + (do + (try + (do) + (catch $event + (drop + (pop i32) + ) + (try + (do) + (delegate 2) + ) + ) + ) + ) + (catch $event + (drop + (pop i32) + ) + ) + ) + ) +) + From d7b1576eaa7276a95aa6dd6426125a448c426132 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Feb 2021 13:14:10 -0800 Subject: [PATCH 2/3] comment --- test/passes/generate-stack-ir_roundtrip_all-features.wast | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/passes/generate-stack-ir_roundtrip_all-features.wast b/test/passes/generate-stack-ir_roundtrip_all-features.wast index 1230e3cf17d..8a04eabf8a3 100644 --- a/test/passes/generate-stack-ir_roundtrip_all-features.wast +++ b/test/passes/generate-stack-ir_roundtrip_all-features.wast @@ -11,6 +11,10 @@ ) (try (do) + ;; the binary writer must properly handle this delegate which is the + ;; child of other try's, and not get confused by their information on the + ;; stack (this is a regression test for us properly ending the scope with + ;; a delegate and popping the stack of break targets). (delegate 2) ) ) From 2fdcefadd99358cb084081cf6d90d3d6231fac6b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 23 Feb 2021 13:15:52 -0800 Subject: [PATCH 3/3] fix comment --- test/passes/generate-stack-ir_roundtrip_all-features.wast | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/passes/generate-stack-ir_roundtrip_all-features.wast b/test/passes/generate-stack-ir_roundtrip_all-features.wast index 8a04eabf8a3..dc6c68d672a 100644 --- a/test/passes/generate-stack-ir_roundtrip_all-features.wast +++ b/test/passes/generate-stack-ir_roundtrip_all-features.wast @@ -14,7 +14,7 @@ ;; the binary writer must properly handle this delegate which is the ;; child of other try's, and not get confused by their information on the ;; stack (this is a regression test for us properly ending the scope with - ;; a delegate and popping the stack of break targets). + ;; a delegate and popping the relevant stack). (delegate 2) ) )