Skip to content

Commit e20ea41

Browse files
authored
[Custom Descriptors] Fix ref.cast_desc branching descriptors (#7717)
The interpreter was returning the wrong value when evaluating a branching descriptor operand to a descriptor cast. Adding tests for this fix also exposed a bug where the validator did not allow for unreachable descriptor operands without also having unreachable ref operands.
1 parent 025ed9f commit e20ea41

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/wasm-interpreter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
16581658
}
16591659
Flow desc = self()->visit(curr->desc);
16601660
if (desc.breaking()) {
1661-
return typename Cast::Breaking{ref};
1661+
return typename Cast::Breaking{desc};
16621662
}
16631663
auto expected = desc.getSingleValue().getGCData();
16641664
if (!expected) {

src/wasm/wasm-validator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ void FunctionValidator::visitRefTest(RefTest* curr) {
29362936
void FunctionValidator::visitRefCast(RefCast* curr) {
29372937
shouldBeTrue(
29382938
getModule()->features.hasGC(), curr, "ref.cast requires gc [--enable-gc]");
2939-
if (curr->ref->type == Type::unreachable) {
2939+
if (curr->type == Type::unreachable) {
29402940
return;
29412941
}
29422942
if (!shouldBeTrue(

test/spec/ref.cast_desc.wast

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@
145145
)
146146
)
147147
)
148+
149+
(func (export "cast-branch-ref") (result i32)
150+
(drop
151+
(ref.cast_desc (ref $super)
152+
(return (i32.const 1))
153+
(ref.null none)
154+
)
155+
)
156+
(i32.const 0)
157+
)
158+
(func (export "cast-branch-desc") (result i32)
159+
(drop
160+
(ref.cast_desc (ref $super)
161+
(ref.null none)
162+
(return (i32.const 1))
163+
)
164+
)
165+
(i32.const 0)
166+
)
148167
)
149168

150169
(assert_return (invoke "cast-success"))
@@ -157,6 +176,8 @@
157176
(assert_trap (invoke "cast-nn-fail-null") "cast error")
158177
(assert_trap (invoke "cast-nn-fail-wrong-desc") "cast error")
159178
(assert_trap (invoke "cast-nn-fail-null-desc") "null descriptor")
179+
(assert_return (invoke "cast-branch-ref") (i32.const 1))
180+
(assert_return (invoke "cast-branch-desc") (i32.const 1))
160181

161182
(assert_malformed
162183
;; Cast type must be a reference.

0 commit comments

Comments
 (0)