Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2230,10 +2230,19 @@ void FunctionValidator::visitRefIsNull(RefIsNull* curr) {
}

void FunctionValidator::visitRefAs(RefAs* curr) {
if (curr->value->type != Type::unreachable &&
!shouldBeTrue(
curr->value->type.isRef(), curr, "ref.as value must be reference")) {
return;
}
switch (curr->op) {
default:
// TODO: validate all the other ref.as_*
case RefAsNonNull: {
shouldBeTrue(
getModule()->features.hasReferenceTypes(),
curr,
"ref.as requires reference-types [--enable-reference-types]");
break;
}
case AnyConvertExtern: {
shouldBeTrue(getModule()->features.hasGC(),
curr,
Expand Down
8 changes: 7 additions & 1 deletion src/wasm/wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,13 @@ void ArrayInitElem::finalize() {
}

void RefAs::finalize() {
if (value->type == Type::unreachable) {
// An unreachable child means we are unreachable. Also set ourselves to
// unreachable when the child is invalid (say, it is an i32 or some other non-
// reference), which avoids getHeapType() erroring right after us (in this
// situation, the validator will report an error later).
// TODO: Remove that part when we solve the validation issue more generally,
// see https://github.com/WebAssembly/binaryen/issues/6781
if (!value->type.isRef()) {
type = Type::unreachable;
return;
}
Expand Down
13 changes: 13 additions & 0 deletions test/lit/validation/non-ref.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;; RUN: not wasm-opt %s -all 2>&1 | filecheck %s

;; CHECK: ref.as value must be reference

(module
(func $test
(drop
(ref.as_non_null
(i32.const 42)
)
)
)
)