Skip to content

Commit

Permalink
c-writer.cc: Correctly handle label names when branching out of try b…
Browse files Browse the repository at this point in the history
…lock (#2208)
  • Loading branch information
keithw committed May 8, 2023
1 parent ab2f184 commit e04107f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/c-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,9 @@ void CWriter::WriteTryCatch(const TryExpr& tryexpr) {
Write(CloseBrace(), Newline()); /* end of try-catch */

ResetTypeStack(mark);
Write(LabelDecl(label_stack_.back().name));
assert(!label_stack_.empty());
assert(label_stack_.back().name == tryexpr.block.label);
Write(LabelDecl(GetLocalName(tryexpr.block.label, true)));
PopLabel();
PushTypes(tryexpr.block.decl.sig.result_types);
}
Expand Down Expand Up @@ -2939,7 +2941,9 @@ void CWriter::WriteTryDelegate(const TryExpr& tryexpr) {

PopTryCatch();
ResetTypeStack(mark);
Write(LabelDecl(label_stack_.back().name));
assert(!label_stack_.empty());
assert(label_stack_.back().name == tryexpr.block.label);
Write(LabelDecl(GetLocalName(tryexpr.block.label, true)));
PopLabel();
PushTypes(tryexpr.block.decl.sig.result_types);
}
Expand Down
12 changes: 12 additions & 0 deletions test/regress/wasm2c-try-br.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;;; TOOL: run-spec-wasm2c
;;; ARGS: --debug-names --enable-exceptions
(module
(func (export "break-try")
(try (do (br 0)) (delegate 0))
)
)

(assert_return (invoke "break-try"))
(;; STDOUT ;;;
1/1 tests passed.
;;; STDOUT ;;)

0 comments on commit e04107f

Please sign in to comment.