File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2780,6 +2780,21 @@ void FunctionValidator::visitRefCast(RefCast* curr) {
27802780 curr->ref ->type .isRef (), curr, " ref.cast ref must have ref type" )) {
27812781 return ;
27822782 }
2783+ // If the cast is unreachable but not the ref (we ruled out the former
2784+ // earlier), then the cast is unreachable because the cast type had no
2785+ // common supertype with the ref, which is invalid. This is the same as the
2786+ // check below us, but we must do it first (as getHeapType fails otherwise).
2787+ if (!shouldBeUnequal (
2788+ curr->type ,
2789+ Type (Type::unreachable),
2790+ curr,
2791+ " ref.cast target type and ref type must have a common supertype" )) {
2792+ return ;
2793+ }
2794+ // Also error (more generically) on i32 and anything else invalid here.
2795+ if (!shouldBeTrue (curr->type .isRef (), curr, " ref.cast must have ref type" )) {
2796+ return ;
2797+ }
27832798 shouldBeEqual (
27842799 curr->type .getHeapType ().getBottom (),
27852800 curr->ref ->type .getHeapType ().getBottom (),
Original file line number Diff line number Diff line change 170170 " common supertype"
171171)
172172
173+ (assert_invalid
174+ (module
175+ (type $t0 (struct ))
176+ (func (export " test-ref-cast-extern" ) (result anyref )
177+ (ref.cast (ref extern ) (struct.new $t0 ))
178+ )
179+ )
180+ " common supertype"
181+ )
182+
173183(assert_malformed
174184 (module quote " (func (ref.cast i32 (unreachable)))" )
175185 " expected reftype"
You can’t perform that action at this time.
0 commit comments