summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2024-01-02 17:30:55 -0800
committerGitHub <noreply@github.com>2024-01-02 17:30:55 -0800
commit260fdfcdaaeba3f4a47ef057db28c61203c8d3b1 (patch)
tree18f30c1331e88d43b07acbf89a9aa79295b25844
parent4acd47676c0eb91550a448920395ce45bd86ec50 (diff)
downloadbinaryen-260fdfcdaaeba3f4a47ef057db28c61203c8d3b1.tar.gz
binaryen-260fdfcdaaeba3f4a47ef057db28c61203c8d3b1.tar.bz2
binaryen-260fdfcdaaeba3f4a47ef057db28c61203c8d3b1.zip
[EH] Misc. fixes for EH (#6195)
- Deletes a stray whitespace after `throw_ref` - Adds missing `makeThrowRef` to `wasm-builder.h` - Adds a case for `TryTable` in `ControlFlowWalker`
-rw-r--r--src/passes/Print.cpp2
-rw-r--r--src/wasm-builder.h6
-rw-r--r--src/wasm-traversal.h14
-rw-r--r--test/lit/basic/exception-handling.wast24
4 files changed, 28 insertions, 18 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 5ea62c9f2..5e290ebca 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -2018,7 +2018,7 @@ struct PrintExpressionContents
printMedium(o, "rethrow ");
printName(curr->target, o);
}
- void visitThrowRef(ThrowRef* curr) { printMedium(o, "throw_ref "); }
+ void visitThrowRef(ThrowRef* curr) { printMedium(o, "throw_ref"); }
void visitNop(Nop* curr) { printMinor(o, "nop"); }
void visitUnreachable(Unreachable* curr) { printMinor(o, "unreachable"); }
void visitPop(Pop* curr) {
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index dd5b498be..a873a7309 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -836,6 +836,12 @@ public:
ret->finalize();
return ret;
}
+ ThrowRef* makeThrowRef(Expression* exnref) {
+ auto* ret = wasm.allocator.alloc<ThrowRef>();
+ ret->exnref = exnref;
+ ret->finalize();
+ return ret;
+ }
Unreachable* makeUnreachable() { return wasm.allocator.alloc<Unreachable>(); }
Pop* makePop(Type type) {
auto* ret = wasm.allocator.alloc<Pop>();
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h
index 1a458bdf7..f5f25dd1f 100644
--- a/src/wasm-traversal.h
+++ b/src/wasm-traversal.h
@@ -403,7 +403,8 @@ using ExpressionStack = SmallVector<Expression*, 10>;
template<typename SubType, typename VisitorType = Visitor<SubType>>
struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
- ExpressionStack controlFlowStack; // contains blocks, loops, and ifs
+ // contains blocks, loops, ifs, trys, and try_tables
+ ExpressionStack controlFlowStack;
// Uses the control flow stack to find the target of a break to a name
Expression* findBreakTarget(Name name) {
@@ -420,8 +421,9 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
return curr;
}
} else {
- // an if or try, ignorable
- assert(curr->template is<If>() || curr->template is<Try>());
+ // an if, try, or try_table, ignorable
+ assert(curr->template is<If>() || curr->template is<Try>() ||
+ curr->template is<TryTable>());
}
if (i == 0) {
return nullptr;
@@ -447,7 +449,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
case Expression::Id::BlockId:
case Expression::Id::IfId:
case Expression::Id::LoopId:
- case Expression::Id::TryId: {
+ case Expression::Id::TryId:
+ case Expression::Id::TryTableId: {
self->pushTask(SubType::doPostVisitControlFlow, currp);
break;
}
@@ -461,7 +464,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
case Expression::Id::BlockId:
case Expression::Id::IfId:
case Expression::Id::LoopId:
- case Expression::Id::TryId: {
+ case Expression::Id::TryId:
+ case Expression::Id::TryTableId: {
self->pushTask(SubType::doPreVisitControlFlow, currp);
break;
}
diff --git a/test/lit/basic/exception-handling.wast b/test/lit/basic/exception-handling.wast
index cf0e8a62e..b94f89e1a 100644
--- a/test/lit/basic/exception-handling.wast
+++ b/test/lit/basic/exception-handling.wast
@@ -162,7 +162,7 @@
)
;; CHECK-TEXT: (func $try-table-and-throw-ref (type $0)
- ;; CHECK-TEXT-NEXT: (throw_ref
+ ;; CHECK-TEXT-NEXT: (throw_ref
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
;; CHECK-TEXT-NEXT: (try_table (catch_all_ref $l-catch-all-ref)
;; CHECK-TEXT-NEXT: (throw $e-i64
@@ -173,7 +173,7 @@
;; CHECK-TEXT-NEXT: )
;; CHECK-TEXT-NEXT: )
;; CHECK-BIN: (func $try-table-and-throw-ref (type $0)
- ;; CHECK-BIN-NEXT: (throw_ref
+ ;; CHECK-BIN-NEXT: (throw_ref
;; CHECK-BIN-NEXT: (block $label$1 (result exnref)
;; CHECK-BIN-NEXT: (try_table (catch_all_ref $label$1)
;; CHECK-BIN-NEXT: (throw $e-i64
@@ -300,7 +300,7 @@
;; CHECK-TEXT-NEXT: (drop
;; CHECK-TEXT-NEXT: (block $l-catch-ref (result exnref)
;; CHECK-TEXT-NEXT: (block $l-catch-all
- ;; CHECK-TEXT-NEXT: (throw_ref
+ ;; CHECK-TEXT-NEXT: (throw_ref
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
;; CHECK-TEXT-NEXT: (try_table (catch $e-empty $l-catch) (catch_ref $e-empty $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref)
;; CHECK-TEXT-NEXT: (call $foo)
@@ -323,7 +323,7 @@
;; CHECK-BIN-NEXT: (drop
;; CHECK-BIN-NEXT: (block $label$3 (result exnref)
;; CHECK-BIN-NEXT: (block $label$4
- ;; CHECK-BIN-NEXT: (throw_ref
+ ;; CHECK-BIN-NEXT: (throw_ref
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NEXT: (try_table (catch $e-empty $label$2) (catch_ref $e-empty $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NEXT: (call $foo)
@@ -376,7 +376,7 @@
;; CHECK-TEXT-NEXT: (tuple.drop 2
;; CHECK-TEXT-NEXT: (block $l-catch-ref (type $5) (result i32 exnref)
;; CHECK-TEXT-NEXT: (block $l-catch-all
- ;; CHECK-TEXT-NEXT: (throw_ref
+ ;; CHECK-TEXT-NEXT: (throw_ref
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
;; CHECK-TEXT-NEXT: (try_table (catch $e-i32 $l-catch) (catch_ref $e-i32 $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref)
;; CHECK-TEXT-NEXT: (call $foo)
@@ -403,7 +403,7 @@
;; CHECK-BIN-NEXT: (local.set $0
;; CHECK-BIN-NEXT: (block $label$3 (type $5) (result i32 exnref)
;; CHECK-BIN-NEXT: (block $label$4
- ;; CHECK-BIN-NEXT: (throw_ref
+ ;; CHECK-BIN-NEXT: (throw_ref
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NEXT: (try_table (catch $e-i32 $label$2) (catch_ref $e-i32 $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NEXT: (call $foo)
@@ -474,7 +474,7 @@
;; CHECK-TEXT-NEXT: (tuple.drop 3
;; CHECK-TEXT-NEXT: (block $l-catch-ref (type $2) (result i32 i64 exnref)
;; CHECK-TEXT-NEXT: (block $l-catch-all
- ;; CHECK-TEXT-NEXT: (throw_ref
+ ;; CHECK-TEXT-NEXT: (throw_ref
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
;; CHECK-TEXT-NEXT: (try_table (catch $e-i32-i64 $l-catch) (catch_ref $e-i32-i64 $l-catch-ref) (catch_all $l-catch-all) (catch_all_ref $l-catch-all-ref)
;; CHECK-TEXT-NEXT: (call $foo)
@@ -504,7 +504,7 @@
;; CHECK-BIN-NEXT: (local.set $0
;; CHECK-BIN-NEXT: (block $label$3 (type $2) (result i32 i64 exnref)
;; CHECK-BIN-NEXT: (block $label$4
- ;; CHECK-BIN-NEXT: (throw_ref
+ ;; CHECK-BIN-NEXT: (throw_ref
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NEXT: (try_table (catch $e-i32-i64 $label$2) (catch_ref $e-i32-i64 $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NEXT: (call $foo)
@@ -754,7 +754,7 @@
;; CHECK-BIN-NODEBUG-NEXT: )
;; CHECK-BIN-NODEBUG: (func $4 (type $0)
-;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
+;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1 (result exnref)
;; CHECK-BIN-NODEBUG-NEXT: (try_table (catch_all_ref $label$1)
;; CHECK-BIN-NODEBUG-NEXT: (throw $tag$1
@@ -836,7 +836,7 @@
;; CHECK-BIN-NODEBUG-NEXT: (drop
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (result exnref)
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
-;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
+;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NODEBUG-NEXT: (try_table (catch $tag$4 $label$2) (catch_ref $tag$4 $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NODEBUG-NEXT: (call $0)
@@ -863,7 +863,7 @@
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (type $5) (result i32 exnref)
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
-;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
+;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NODEBUG-NEXT: (try_table (catch $tag$0 $label$2) (catch_ref $tag$0 $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NODEBUG-NEXT: (call $0)
@@ -909,7 +909,7 @@
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (type $2) (result i32 i64 exnref)
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
-;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
+;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
;; CHECK-BIN-NODEBUG-NEXT: (try_table (catch $tag$2 $label$2) (catch_ref $tag$2 $label$3) (catch_all $label$4) (catch_all_ref $label$5)
;; CHECK-BIN-NODEBUG-NEXT: (call $0)