Skip to content

Commit d036a3b

Browse files
authored
Add missing visit to descriptor in LinearExecutionWalker (#9060)
1 parent 6531a98 commit d036a3b

2 files changed

Lines changed: 77 additions & 1 deletion

File tree

src/ir/linear-execution.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ struct LinearExecutionWalker : public PostWalker<SubType, VisitorType> {
251251
if (!self->connectAdjacentBlocks) {
252252
self->pushTask(SubType::doNoteNonLinear, currp);
253253
}
254+
self->maybePushTask(SubType::scan, &curr->cast<BrOn>()->desc);
254255
self->pushTask(SubType::scan, &curr->cast<BrOn>()->ref);
255256
break;
256257
}

test/lit/passes/simplify-locals-desc.wast

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
(type $desc (describes $struct) (struct))
1212
)
1313

14-
;; CHECK: (func $test (type $2) (param $ref (ref null $struct)) (result (ref $struct))
14+
;; CHECK: (type $none (func))
15+
(type $none (func))
16+
17+
;; CHECK: (tag $tag (type $none))
18+
(tag $tag (type $none))
19+
20+
;; CHECK: (func $test (type $3) (param $ref (ref null $struct)) (result (ref $struct))
1521
;; CHECK-NEXT: (local $temp (ref $desc))
1622
;; CHECK-NEXT: (block $block (result (ref none))
1723
;; CHECK-NEXT: (drop
@@ -49,5 +55,74 @@
4955
(unreachable)
5056
)
5157
)
58+
59+
;; CHECK: (func $br_on_cast_desc_eq_in_block (type $4) (result (ref $struct))
60+
;; CHECK-NEXT: (local $0 (ref null $desc))
61+
;; CHECK-NEXT: (local $1 i32)
62+
;; CHECK-NEXT: (block $out (result (ref $struct))
63+
;; CHECK-NEXT: (if
64+
;; CHECK-NEXT: (i32.const 0)
65+
;; CHECK-NEXT: (then
66+
;; CHECK-NEXT: (block $block
67+
;; CHECK-NEXT: (drop
68+
;; CHECK-NEXT: (block (result i32)
69+
;; CHECK-NEXT: (drop
70+
;; CHECK-NEXT: (br_on_cast_desc_eq_fail $out (ref (exact $struct)) (ref $struct)
71+
;; CHECK-NEXT: (struct.new_default_desc $struct
72+
;; CHECK-NEXT: (ref.null none)
73+
;; CHECK-NEXT: )
74+
;; CHECK-NEXT: (try_table (result (ref $desc)) (catch $tag $block)
75+
;; CHECK-NEXT: (ref.as_non_null
76+
;; CHECK-NEXT: (local.get $0)
77+
;; CHECK-NEXT: )
78+
;; CHECK-NEXT: )
79+
;; CHECK-NEXT: )
80+
;; CHECK-NEXT: )
81+
;; CHECK-NEXT: (i32.const 0)
82+
;; CHECK-NEXT: )
83+
;; CHECK-NEXT: )
84+
;; CHECK-NEXT: )
85+
;; CHECK-NEXT: )
86+
;; CHECK-NEXT: )
87+
;; CHECK-NEXT: (unreachable)
88+
;; CHECK-NEXT: )
89+
;; CHECK-NEXT: )
90+
(func $br_on_cast_desc_eq_in_block (result (ref $struct))
91+
(local $0 (ref null $desc))
92+
(local $1 i32)
93+
;; While simplifying locals here, we must be aware that the br_on
94+
;; instruction has a descriptor, and must visit it. If we do not, then we'd
95+
;; see no branches to $block, and move the tee out of it, breaking
96+
;; validation.
97+
(block $out (result (ref $struct))
98+
(if
99+
(i32.const 0)
100+
(then
101+
(block $block
102+
(drop
103+
(local.tee $1
104+
(block (result i32)
105+
(drop
106+
(br_on_cast_desc_eq_fail $out (ref (exact $struct)) (ref $struct)
107+
(struct.new_default_desc $struct
108+
(ref.null none)
109+
)
110+
(try_table (result (ref $desc)) (catch $tag $block)
111+
(ref.as_non_null
112+
(local.get $0)
113+
)
114+
)
115+
)
116+
)
117+
(i32.const 0)
118+
)
119+
)
120+
)
121+
)
122+
)
123+
)
124+
(unreachable)
125+
)
126+
)
52127
)
53128

0 commit comments

Comments
 (0)