Skip to content

Commit fd86ead

Browse files
authored
[EH][GC] Add missing subtyping constraints from TryTable (WebAssembly#7012)
Similar to Break, BrOn, etc., we must apply subtyping constraints of the types we send to blocks, so that Unsubtyping will not remove subtypings that are actually needed.
1 parent d13c262 commit fd86ead

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/ir/subtype-exprs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,13 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
249249
self()->noteSubtype(body, curr);
250250
}
251251
}
252-
void visitTryTable(TryTable* curr) { self()->noteSubtype(curr->body, curr); }
252+
void visitTryTable(TryTable* curr) {
253+
self()->noteSubtype(curr->body, curr);
254+
for (Index i = 0; i < curr->catchTags.size(); i++) {
255+
self()->noteSubtype(curr->sentTypes[i],
256+
self()->findBreakTarget(curr->catchDests[i]));
257+
}
258+
}
253259
void visitThrow(Throw* curr) {
254260
Type params = self()->getModule()->getTag(curr->tag)->sig.params;
255261
assert(params.size() == curr->operands.size());

test/lit/passes/unsubtyping.wast

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,3 +1779,39 @@
17791779
)
17801780
)
17811781
)
1782+
1783+
;; try_table
1784+
(module
1785+
(rec
1786+
;; CHECK: (rec
1787+
;; CHECK-NEXT: (type $super (sub (func)))
1788+
(type $super (sub (func)))
1789+
;; CHECK: (type $sub (sub $super (func)))
1790+
(type $sub (sub $super (func)))
1791+
)
1792+
1793+
;; CHECK: (type $2 (func (result (ref $super))))
1794+
1795+
;; CHECK: (type $3 (func (param (ref $sub))))
1796+
1797+
;; CHECK: (type $4 (func (param (ref $sub))))
1798+
1799+
;; CHECK: (tag $tag (param (ref $sub)))
1800+
(tag $tag (param (ref $sub)))
1801+
1802+
;; CHECK: (func $test (type $2) (result (ref $super))
1803+
;; CHECK-NEXT: (block $label (result (ref $sub))
1804+
;; CHECK-NEXT: (try_table (catch $tag $label)
1805+
;; CHECK-NEXT: (unreachable)
1806+
;; CHECK-NEXT: )
1807+
;; CHECK-NEXT: )
1808+
;; CHECK-NEXT: )
1809+
(func $test (result (ref $super))
1810+
(block $label (result (ref $super))
1811+
;; Sending the contents of $tag to $label cause us to require $sub <: $super
1812+
(try_table (catch $tag $label)
1813+
(unreachable)
1814+
)
1815+
)
1816+
)
1817+
)

0 commit comments

Comments
 (0)