Skip to content

Commit 7d27113

Browse files
authored
[Unsubtyping] Handle table.grow (#9327)
SubtypingDiscoverer did not previously note the constraint that TableGrow's `value` operand had to be a subtype of the table's element type. This would cause Unsubtyping to incorrectly remove that subtyping, leading to validation failures. This is included in #9263, but split it out to make the fuzzer happy.
1 parent 62f073f commit 7d27113

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎src/ir/subtype-exprs.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
252252
self()->getModule()->getTable(curr->table)->type);
253253
}
254254
void visitTableSize(TableSize* curr) {}
255-
void visitTableGrow(TableGrow* curr) {}
255+
void visitTableGrow(TableGrow* curr) {
256+
self()->noteSubtype(curr->value,
257+
self()->getModule()->getTable(curr->table)->type);
258+
}
256259
void visitTableFill(TableFill* curr) {
257260
self()->noteSubtype(curr->value,
258261
self()->getModule()->getTable(curr->table)->type);

‎test/lit/passes/unsubtyping.wast‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,37 @@
762762
)
763763
)
764764

765+
(module
766+
;; CHECK: (rec
767+
;; CHECK-NEXT: (type $super (sub (struct)))
768+
(type $super (sub (struct)))
769+
;; CHECK: (type $sub (sub $super (struct)))
770+
(type $sub (sub $super (struct)))
771+
772+
;; CHECK: (type $2 (func))
773+
774+
;; CHECK: (table $t 1 1 (ref null $super))
775+
(table $t 1 1 (ref null $super))
776+
777+
;; CHECK: (func $table-grow (type $2)
778+
;; CHECK-NEXT: (drop
779+
;; CHECK-NEXT: (table.grow $t
780+
;; CHECK-NEXT: (struct.new_default $sub)
781+
;; CHECK-NEXT: (i32.const 0)
782+
;; CHECK-NEXT: )
783+
;; CHECK-NEXT: )
784+
;; CHECK-NEXT: )
785+
(func $table-grow
786+
;; This requires $sub <: $super.
787+
(drop
788+
(table.grow $t
789+
(struct.new $sub)
790+
(i32.const 0)
791+
)
792+
)
793+
)
794+
)
795+
765796
(module
766797
;; CHECK: (rec
767798
;; CHECK-NEXT: (type $super (sub (struct)))

0 commit comments

Comments
 (0)