Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix
  • Loading branch information
kripken committed Jul 12, 2024
commit 7530b2799933b8069aa3a4e9be522ff39769be46
8 changes: 8 additions & 0 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,14 @@ void FunctionValidator::visitRefCast(RefCast* curr) {
curr->ref->type.isRef(), curr, "ref.cast ref must have ref type")) {
return;
}
// If the cast is unreachable but not the ref (we ruled out the former
// earlier), then the cast is unreachable because the cast type had no
// common supertype with the ref, which is invalid. This is the same as the
// check below us, but we must do it first (as getHeapType fails otherwise).
if (!shouldBeUnequal(curr->type, Type(Type::unreachable), curr,
"ref.cast target type and ref type must have a common supertype")) {
return;
}
shouldBeEqual(
curr->type.getHeapType().getBottom(),
curr->ref->type.getHeapType().getBottom(),
Expand Down
10 changes: 10 additions & 0 deletions test/spec/ref_cast.wast
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@
"common supertype"
)

(assert_invalid
(module
(type $t0 (struct))
(func (export "test-ref-cast-extern") (result anyref)
(ref.cast (ref extern) (struct.new $t0))
)
)
"common supertype"
)

(assert_malformed
(module quote "(func (ref.cast i32 (unreachable)))")
"expected reftype"
Expand Down