Skip to content

Commit dcaf833

Browse files
authored
[Custom Descriptors] Fix ref.cast_desc of i31ref (#7719)
We previously hit an assertion failure when accessing the GCData of the ref literal because i31 literals do not have GCData.
1 parent 93399c3 commit dcaf833

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/wasm-interpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,10 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
16651665
trap("null descriptor");
16661666
}
16671667
Literal val = ref.getSingleValue();
1668+
if (!val.isData() && !val.isNull()) {
1669+
// For example, i31ref.
1670+
return typename Cast::Failure{val};
1671+
}
16681672
auto data = val.getGCData();
16691673
if (!data) {
16701674
// Check whether null is allowed.

test/spec/ref.cast_desc.wast

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@
164164
)
165165
(i32.const 0)
166166
)
167+
168+
(func (export "cast-i31ref")
169+
(drop
170+
(ref.cast_desc (ref $super)
171+
(ref.i31 (i32.const 0))
172+
(struct.new $super.desc)
173+
)
174+
)
175+
)
167176
)
168177

169178
(assert_return (invoke "cast-success"))
@@ -178,6 +187,7 @@
178187
(assert_trap (invoke "cast-nn-fail-null-desc") "null descriptor")
179188
(assert_return (invoke "cast-branch-ref") (i32.const 1))
180189
(assert_return (invoke "cast-branch-desc") (i32.const 1))
190+
(assert_trap (invoke "cast-i31ref") "cast error")
181191

182192
(assert_malformed
183193
;; Cast type must be a reference.

0 commit comments

Comments
 (0)