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
3 changes: 2 additions & 1 deletion src/passes/Flatten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ struct Flatten
// we don't know which break target will be hit - assign to them all
auto names = BranchUtils::getUniqueTargets(sw);
for (auto name : names) {
Type blockType = findBreakTarget(name)->type;
ourPreludes.push_back(
builder.makeLocalSet(getTempForBreakTarget(name, type),
builder.makeLocalSet(getTempForBreakTarget(name, blockType),
builder.makeLocalGet(temp, type)));
}
sw->value = nullptr;
Expand Down
35 changes: 35 additions & 0 deletions test/lit/passes/flatten.wast
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,39 @@
;; modified
(local.get $0)
)

;; CHECK: (func $switch_subtype (type $2) (result funcref)
;; CHECK-NEXT: (local $0 nullfuncref)
;; CHECK-NEXT: (local $1 funcref)
;; CHECK-NEXT: (local $2 funcref)
;; CHECK-NEXT: (block $b
;; CHECK-NEXT: (local.set $0
;; CHECK-NEXT: (ref.null nofunc)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $1
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (br_table $b
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $2
;; CHECK-NEXT: (local.get $1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (return
;; CHECK-NEXT: (local.get $2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $switch_subtype (result funcref)
;; A br_table sending a subtype of its target block's result type should
;; allocate the break target local with the target block's type, not the
;; narrower sent value type.
(block $b (result funcref)
(br_table $b
(ref.null nofunc)
(i32.const 0)
)
)
)
)
Loading