Commit 0034015b authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Remove immediate of ref.is_null

Due to recent spec changes, this CL removes the type immediate of
ref.is_null again. Instead we check if the type of the input parameter
is nullable.

R=jkummerow@chromium.org

Bug: v8:10556
Change-Id: If07d30fe4dd27664be7774422573b2ab2b0dfa20
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2247654
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68484}
parent 462f3f46
......@@ -1487,8 +1487,7 @@ class WasmDecoder : public Decoder {
return 1 + imm.length;
}
case kExprRefIsNull: {
RefNullImmediate<validate> imm(WasmFeatures::All(), decoder, pc);
return 1 + imm.length;
return 1;
}
case kExprRefFunc: {
FunctionIndexImmediate<validate> imm(decoder, pc);
......@@ -2424,12 +2423,22 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
case kExprRefIsNull: {
CHECK_PROTOTYPE_OPCODE(reftypes);
RefNullImmediate<validate> imm(this->enabled_, this, this->pc_);
if (!this->Validate(this->pc_, imm)) break;
Value value = Pop(0, imm.type);
Value value = Pop();
Value* result = Push(kWasmI32);
CALL_INTERFACE_IF_REACHABLE(UnOp, opcode, value, result);
len = 1 + imm.length;
len = 1;
if (value.type.is_nullable()) {
CALL_INTERFACE_IF_REACHABLE(UnOp, opcode, value, result);
break;
}
if (value.type.is_reference_type()) {
// Due to the check above, we know that the value is not null.
CALL_INTERFACE_IF_REACHABLE(I32Const, result, 0);
break;
}
this->errorf(this->pc_,
"invalid argument type to ref.is_null. Expected "
"reference type, got %s",
value.type.type_name().c_str());
break;
}
case kExprRefFunc: {
......
......@@ -347,21 +347,20 @@ TEST(MemoryGrowInvalidSize) {
TEST(ReferenceTypeLocals) {
{
WasmRunner<int32_t> r(ExecutionTier::kInterpreter);
BUILD(r, WASM_REF_IS_NULL(kLocalExternRef, WASM_REF_NULL(kLocalExternRef)));
BUILD(r, WASM_REF_IS_NULL(WASM_REF_NULL(kLocalExternRef)));
CHECK_EQ(1, r.Call());
}
{
WasmRunner<int32_t> r(ExecutionTier::kInterpreter);
r.AllocateLocal(kWasmExternRef);
BUILD(r, WASM_REF_IS_NULL(kLocalExternRef, WASM_GET_LOCAL(0)));
BUILD(r, WASM_REF_IS_NULL(WASM_GET_LOCAL(0)));
CHECK_EQ(1, r.Call());
}
{
WasmRunner<int32_t> r(ExecutionTier::kInterpreter);
r.AllocateLocal(kWasmExternRef);
BUILD(r,
WASM_REF_IS_NULL(kLocalExternRef,
WASM_TEE_LOCAL(0, WASM_REF_NULL(kLocalExternRef))));
WASM_REF_IS_NULL(WASM_TEE_LOCAL(0, WASM_REF_NULL(kLocalExternRef))));
CHECK_EQ(1, r.Call());
}
}
......
......@@ -3493,9 +3493,7 @@ class WasmInterpreterInternals {
SIGN_EXTENSION_CASE(I64SExtendI32, int64_t, int32_t);
#undef SIGN_EXTENSION_CASE
case kExprRefIsNull: {
RefNullImmediate<Decoder::kNoValidate> imm(WasmFeatures::All(),
&decoder, code->at(pc));
len = 1 + imm.length;
len = 1;
HandleScope handle_scope(isolate_); // Avoid leaking handles.
uint32_t result = Pop().to_externref()->IsNull() ? 1 : 0;
Push(WasmValue(result));
......
......@@ -442,7 +442,7 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
#define WASM_REF_NULL_GC(type) \
kExprRefNull, kLocalOptRef, static_cast<byte>(type)
#define WASM_REF_FUNC(val) kExprRefFunc, val
#define WASM_REF_IS_NULL(type, val) val, kExprRefIsNull, static_cast<byte>(type)
#define WASM_REF_IS_NULL(val) val, kExprRefIsNull
#define WASM_REF_AS_NON_NULL(val) val, kExprRefAsNonNull
#define WASM_REF_EQ(lhs, rhs) lhs, rhs, kExprRefEq
......
......@@ -14,7 +14,7 @@ function create_builder(i) {
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_r)
.addBody([
kExprLocalGet, 0, kExprRefIsNull, kWasmExternRef, ...wasmI32Const(i),
kExprLocalGet, 0, kExprRefIsNull, ...wasmI32Const(i),
kExprI32Add
])
.exportFunc();
......
......@@ -24,7 +24,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testExternRefIsNull() {
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_r)
.addBody([kExprLocalGet, 0, kExprRefIsNull, kWasmExternRef])
.addBody([kExprLocalGet, 0, kExprRefIsNull])
.exportFunc();
var wire_bytes = builder.toBuffer();
......
......@@ -43,7 +43,7 @@ load("test/mjsunit/wasm/exceptions-utils.js");
kExprBrOnExn, 0, except,
kExprRethrow,
kExprEnd,
kExprRefIsNull, kWasmExternRef,
kExprRefIsNull,
kExprIf, kWasmI32,
kExprI32Const, 23,
kExprElse,
......
......@@ -177,7 +177,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
print(arguments.callee.name);
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_r)
.addBody([kExprLocalGet, 0, kExprRefIsNull, kWasmExternRef])
.addBody([kExprLocalGet, 0, kExprRefIsNull])
.exportFunc();
const instance = builder.instantiate();
......@@ -196,10 +196,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
const builder = new WasmModuleBuilder();
builder.addFunction('main', kSig_i_v)
.addBody([
kExprRefNull, kWasmExternRef, // --
kExprRefIsNull, kWasmExternRef // --
])
.addBody([kExprRefNull, kWasmExternRef, kExprRefIsNull])
.exportFunc();
const instance = builder.instantiate();
......
......@@ -2976,6 +2976,15 @@ TEST_F(FunctionBodyDecoderTest, IfParam) {
WASM_I32_ADD(WASM_NOP, WASM_NOP)});
}
TEST_F(FunctionBodyDecoderTest, RefIsNull) {
WASM_FEATURE_SCOPE(reftypes);
ExpectValidates(sigs.i_i(),
{WASM_REF_IS_NULL(WASM_REF_NULL(kLocalExternRef))});
ExpectFailure(
sigs.i_i(), {WASM_REF_IS_NULL(WASM_GET_LOCAL(0))}, kAppendEnd,
"invalid argument type to ref.is_null. Expected reference type, got i32");
}
TEST_F(FunctionBodyDecoderTest, Regression709741) {
AddLocals(kWasmI32, kV8MaxWasmFunctionLocals - 1);
ExpectValidates(sigs.v_v(), {WASM_NOP});
......
......@@ -4,13 +4,6 @@
[
[ALWAYS, {
# TODO(v8:10556): Remove sub-typing in the reference-types implementation
'proposals/reference-types/table_grow': [FAIL],
'proposals/reference-types/table_set': [FAIL],
'proposals/reference-types/table_get': [FAIL],
'proposals/reference-types/ref_is_null': [FAIL],
'proposals/reference-types/ref_func': [FAIL],
#TODO(ahaas): Add additional stack checks on mips.
'skip-stack-guard-page': [PASS, ['arch == mipsel or arch == mips64el or ((arch == ppc or arch == ppc64 or arch == s390 or arch == s390x) and simulator_run)', SKIP]],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment