diff --git a/src/wasm/function-body-decoder-impl.h b/src/wasm/function-body-decoder-impl.h index c52a26a547..9cb7f84722 100644 --- a/src/wasm/function-body-decoder-impl.h +++ b/src/wasm/function-body-decoder-impl.h @@ -5128,27 +5128,29 @@ class WasmFullDecoder : public WasmDecoder { // Temporary non-standard instruction, for performance experiments. if (!VALIDATE(this->enabled_.has_ref_cast_nop())) { this->DecodeError( - "Invalid opcode 0xfb48 (enable with " + "Invalid opcode 0xfb4c (enable with " "--experimental-wasm-ref-cast-nop)"); return 0; } - IndexImmediate imm(this, this->pc_ + opcode_length, "type index", - validate); - if (!this->ValidateType(this->pc_ + opcode_length, imm)) return 0; + HeapTypeImmediate imm(this->enabled_, this, this->pc_ + opcode_length, + validate); + if (!this->Validate(this->pc_ + opcode_length, imm)) return 0; opcode_length += imm.length; + HeapType target_type = imm.type; Value obj = Peek(0); - if (!VALIDATE(IsSubtypeOf(obj.type, kWasmFuncRef, this->module_) || - IsSubtypeOf(obj.type, kWasmStructRef, this->module_) || - IsSubtypeOf(obj.type, kWasmArrayRef, this->module_) || + if (!VALIDATE((obj.type.is_object_reference() && + IsSameTypeHierarchy(obj.type.heap_type(), target_type, + this->module_)) || obj.type.is_bottom())) { - PopTypeError(0, obj, - "subtype of (ref null func), (ref null struct) or (ref " - "null array)"); + this->DecodeError( + obj.pc(), + "Invalid types for %s: %s of type %s has to " + "be in the same reference type hierarchy as (ref %s)", + WasmOpcodes::OpcodeName(opcode), SafeOpcodeNameAt(obj.pc()), + obj.type.name().c_str(), target_type.name().c_str()); return 0; } - Value value = CreateValue(ValueType::RefMaybeNull( - imm.index, - obj.type.is_bottom() ? kNonNullable : obj.type.nullability())); + Value value = CreateValue(ValueType::Ref(target_type)); CALL_INTERFACE_IF_OK_AND_REACHABLE(Forward, obj, &value); Drop(obj); Push(value);