Skip to content

Commit 260fdfc

Browse files
authored
[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`
1 parent 4acd476 commit 260fdfc

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

src/passes/Print.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ struct PrintExpressionContents
20182018
printMedium(o, "rethrow ");
20192019
printName(curr->target, o);
20202020
}
2021-
void visitThrowRef(ThrowRef* curr) { printMedium(o, "throw_ref "); }
2021+
void visitThrowRef(ThrowRef* curr) { printMedium(o, "throw_ref"); }
20222022
void visitNop(Nop* curr) { printMinor(o, "nop"); }
20232023
void visitUnreachable(Unreachable* curr) { printMinor(o, "unreachable"); }
20242024
void visitPop(Pop* curr) {

src/wasm-builder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,12 @@ class Builder {
836836
ret->finalize();
837837
return ret;
838838
}
839+
ThrowRef* makeThrowRef(Expression* exnref) {
840+
auto* ret = wasm.allocator.alloc<ThrowRef>();
841+
ret->exnref = exnref;
842+
ret->finalize();
843+
return ret;
844+
}
839845
Unreachable* makeUnreachable() { return wasm.allocator.alloc<Unreachable>(); }
840846
Pop* makePop(Type type) {
841847
auto* ret = wasm.allocator.alloc<Pop>();

src/wasm-traversal.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ using ExpressionStack = SmallVector<Expression*, 10>;
403403

404404
template<typename SubType, typename VisitorType = Visitor<SubType>>
405405
struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
406-
ExpressionStack controlFlowStack; // contains blocks, loops, and ifs
406+
// contains blocks, loops, ifs, trys, and try_tables
407+
ExpressionStack controlFlowStack;
407408

408409
// Uses the control flow stack to find the target of a break to a name
409410
Expression* findBreakTarget(Name name) {
@@ -420,8 +421,9 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
420421
return curr;
421422
}
422423
} else {
423-
// an if or try, ignorable
424-
assert(curr->template is<If>() || curr->template is<Try>());
424+
// an if, try, or try_table, ignorable
425+
assert(curr->template is<If>() || curr->template is<Try>() ||
426+
curr->template is<TryTable>());
425427
}
426428
if (i == 0) {
427429
return nullptr;
@@ -447,7 +449,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
447449
case Expression::Id::BlockId:
448450
case Expression::Id::IfId:
449451
case Expression::Id::LoopId:
450-
case Expression::Id::TryId: {
452+
case Expression::Id::TryId:
453+
case Expression::Id::TryTableId: {
451454
self->pushTask(SubType::doPostVisitControlFlow, currp);
452455
break;
453456
}
@@ -461,7 +464,8 @@ struct ControlFlowWalker : public PostWalker<SubType, VisitorType> {
461464
case Expression::Id::BlockId:
462465
case Expression::Id::IfId:
463466
case Expression::Id::LoopId:
464-
case Expression::Id::TryId: {
467+
case Expression::Id::TryId:
468+
case Expression::Id::TryTableId: {
465469
self->pushTask(SubType::doPreVisitControlFlow, currp);
466470
break;
467471
}

test/lit/basic/exception-handling.wast

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
)
163163

164164
;; CHECK-TEXT: (func $try-table-and-throw-ref (type $0)
165-
;; CHECK-TEXT-NEXT: (throw_ref
165+
;; CHECK-TEXT-NEXT: (throw_ref
166166
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
167167
;; CHECK-TEXT-NEXT: (try_table (catch_all_ref $l-catch-all-ref)
168168
;; CHECK-TEXT-NEXT: (throw $e-i64
@@ -173,7 +173,7 @@
173173
;; CHECK-TEXT-NEXT: )
174174
;; CHECK-TEXT-NEXT: )
175175
;; CHECK-BIN: (func $try-table-and-throw-ref (type $0)
176-
;; CHECK-BIN-NEXT: (throw_ref
176+
;; CHECK-BIN-NEXT: (throw_ref
177177
;; CHECK-BIN-NEXT: (block $label$1 (result exnref)
178178
;; CHECK-BIN-NEXT: (try_table (catch_all_ref $label$1)
179179
;; CHECK-BIN-NEXT: (throw $e-i64
@@ -300,7 +300,7 @@
300300
;; CHECK-TEXT-NEXT: (drop
301301
;; CHECK-TEXT-NEXT: (block $l-catch-ref (result exnref)
302302
;; CHECK-TEXT-NEXT: (block $l-catch-all
303-
;; CHECK-TEXT-NEXT: (throw_ref
303+
;; CHECK-TEXT-NEXT: (throw_ref
304304
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
305305
;; 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)
306306
;; CHECK-TEXT-NEXT: (call $foo)
@@ -323,7 +323,7 @@
323323
;; CHECK-BIN-NEXT: (drop
324324
;; CHECK-BIN-NEXT: (block $label$3 (result exnref)
325325
;; CHECK-BIN-NEXT: (block $label$4
326-
;; CHECK-BIN-NEXT: (throw_ref
326+
;; CHECK-BIN-NEXT: (throw_ref
327327
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
328328
;; 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)
329329
;; CHECK-BIN-NEXT: (call $foo)
@@ -376,7 +376,7 @@
376376
;; CHECK-TEXT-NEXT: (tuple.drop 2
377377
;; CHECK-TEXT-NEXT: (block $l-catch-ref (type $5) (result i32 exnref)
378378
;; CHECK-TEXT-NEXT: (block $l-catch-all
379-
;; CHECK-TEXT-NEXT: (throw_ref
379+
;; CHECK-TEXT-NEXT: (throw_ref
380380
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
381381
;; 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)
382382
;; CHECK-TEXT-NEXT: (call $foo)
@@ -403,7 +403,7 @@
403403
;; CHECK-BIN-NEXT: (local.set $0
404404
;; CHECK-BIN-NEXT: (block $label$3 (type $5) (result i32 exnref)
405405
;; CHECK-BIN-NEXT: (block $label$4
406-
;; CHECK-BIN-NEXT: (throw_ref
406+
;; CHECK-BIN-NEXT: (throw_ref
407407
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
408408
;; 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)
409409
;; CHECK-BIN-NEXT: (call $foo)
@@ -474,7 +474,7 @@
474474
;; CHECK-TEXT-NEXT: (tuple.drop 3
475475
;; CHECK-TEXT-NEXT: (block $l-catch-ref (type $2) (result i32 i64 exnref)
476476
;; CHECK-TEXT-NEXT: (block $l-catch-all
477-
;; CHECK-TEXT-NEXT: (throw_ref
477+
;; CHECK-TEXT-NEXT: (throw_ref
478478
;; CHECK-TEXT-NEXT: (block $l-catch-all-ref (result exnref)
479479
;; 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)
480480
;; CHECK-TEXT-NEXT: (call $foo)
@@ -504,7 +504,7 @@
504504
;; CHECK-BIN-NEXT: (local.set $0
505505
;; CHECK-BIN-NEXT: (block $label$3 (type $2) (result i32 i64 exnref)
506506
;; CHECK-BIN-NEXT: (block $label$4
507-
;; CHECK-BIN-NEXT: (throw_ref
507+
;; CHECK-BIN-NEXT: (throw_ref
508508
;; CHECK-BIN-NEXT: (block $label$5 (result exnref)
509509
;; 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)
510510
;; CHECK-BIN-NEXT: (call $foo)
@@ -754,7 +754,7 @@
754754
;; CHECK-BIN-NODEBUG-NEXT: )
755755

756756
;; CHECK-BIN-NODEBUG: (func $4 (type $0)
757-
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
757+
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
758758
;; CHECK-BIN-NODEBUG-NEXT: (block $label$1 (result exnref)
759759
;; CHECK-BIN-NODEBUG-NEXT: (try_table (catch_all_ref $label$1)
760760
;; CHECK-BIN-NODEBUG-NEXT: (throw $tag$1
@@ -836,7 +836,7 @@
836836
;; CHECK-BIN-NODEBUG-NEXT: (drop
837837
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (result exnref)
838838
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
839-
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
839+
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
840840
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
841841
;; 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)
842842
;; CHECK-BIN-NODEBUG-NEXT: (call $0)
@@ -863,7 +863,7 @@
863863
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0
864864
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (type $5) (result i32 exnref)
865865
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
866-
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
866+
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
867867
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
868868
;; 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)
869869
;; CHECK-BIN-NODEBUG-NEXT: (call $0)
@@ -909,7 +909,7 @@
909909
;; CHECK-BIN-NODEBUG-NEXT: (local.set $0
910910
;; CHECK-BIN-NODEBUG-NEXT: (block $label$3 (type $2) (result i32 i64 exnref)
911911
;; CHECK-BIN-NODEBUG-NEXT: (block $label$4
912-
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
912+
;; CHECK-BIN-NODEBUG-NEXT: (throw_ref
913913
;; CHECK-BIN-NODEBUG-NEXT: (block $label$5 (result exnref)
914914
;; 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)
915915
;; CHECK-BIN-NODEBUG-NEXT: (call $0)

0 commit comments

Comments
 (0)