Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/wasm-stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ template<typename SubType> void BinaryenIRWriter<SubType>::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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2333,6 +2336,8 @@ void StackIRToBinaryWriter::write() {
}
case StackInst::Delegate: {
writer.emitDelegate(inst->origin->cast<Try>());
// Delegates end the try, like a TryEnd.
catchIndexStack.pop_back();
break;
}
default:
Expand Down
32 changes: 32 additions & 0 deletions test/passes/generate-stack-ir_roundtrip_all-features.txt
Original file line number Diff line number Diff line change
@@ -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)
)
)
)
)
)
31 changes: 31 additions & 0 deletions test/passes/generate-stack-ir_roundtrip_all-features.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(module
(event $event (attr 0) (param i32))
(func $delegate-child
(try
(do
(try
(do)
(catch $event
(drop
(pop i32)
)
(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 relevant stack).
(delegate 2)
)
)
)
)
(catch $event
(drop
(pop i32)
)
)
)
)
)