[test][wasm-gc] Replace ref.(cast|test) usages with static variant
Bug: v8:7748 Change-Id: Iec95162ec86a0d96fdd64764864604fc3e26cc39 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3771902 Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Auto-Submit: Matthias Liedtke <mliedtke@google.com> Commit-Queue: Matthias Liedtke <mliedtke@google.com> Cr-Commit-Position: refs/heads/main@{#81821}
This commit is contained in:
parent
7e93531493
commit
81bd4a559b
@ -471,7 +471,7 @@ WASM_COMPILED_EXEC_TEST(WasmBrOnNonNull) {
|
||||
tester.CheckResult(kNotTaken, 11);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(RefCast) {
|
||||
WASM_COMPILED_EXEC_TEST(RefCastStatic) {
|
||||
WasmGCTester tester(execution_tier);
|
||||
|
||||
const byte supertype_index = tester.DefineStruct({F(kWasmI32, true)});
|
||||
@ -500,59 +500,6 @@ WASM_COMPILED_EXEC_TEST(RefCast) {
|
||||
tester.AddGlobal(ValueType::RefNull(function_type_index), false,
|
||||
WasmInitExpr::RefFuncConst(function_index));
|
||||
|
||||
const byte kTestSuccessful = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(supertype_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_STRUCT_NEW_DEFAULT(subtype1_index)),
|
||||
WASM_STRUCT_GET(
|
||||
subtype1_index, 0,
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_RTT_CANON(subtype1_index))),
|
||||
WASM_END});
|
||||
|
||||
const byte kTestFailed = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(supertype_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_STRUCT_NEW_DEFAULT(subtype1_index)),
|
||||
WASM_STRUCT_GET(
|
||||
subtype2_index, 0,
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_RTT_CANON(subtype2_index))),
|
||||
WASM_END});
|
||||
|
||||
const byte kFuncTestSuccessfulSuper = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_RTT_CANON(function_type_index)),
|
||||
WASM_DROP, WASM_I32V(0), WASM_END});
|
||||
|
||||
const byte kFuncTestSuccessfulSub = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(function_subtype1_index)),
|
||||
WASM_DROP, WASM_I32V(0), WASM_END});
|
||||
|
||||
const byte kFuncTestFailed = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(function_subtype2_index)),
|
||||
WASM_DROP, WASM_I32V(1), WASM_END});
|
||||
|
||||
tester.CompileModule();
|
||||
tester.CheckResult(kTestSuccessful, 0);
|
||||
tester.CheckHasThrown(kTestFailed);
|
||||
tester.CheckResult(kFuncTestSuccessfulSuper, 0);
|
||||
tester.CheckResult(kFuncTestSuccessfulSub, 0);
|
||||
tester.CheckHasThrown(kFuncTestFailed);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(RefCastStatic) {
|
||||
WasmGCTester tester(execution_tier);
|
||||
|
||||
const byte supertype_index = tester.DefineStruct({F(kWasmI32, true)});
|
||||
const byte subtype1_index = tester.DefineStruct(
|
||||
{F(kWasmI32, true), F(kWasmF32, false)}, supertype_index);
|
||||
const byte subtype2_index = tester.DefineStruct(
|
||||
{F(kWasmI32, true), F(kWasmI64, false)}, supertype_index);
|
||||
|
||||
const byte kTestSuccessful = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(supertype_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_STRUCT_NEW_DEFAULT(subtype1_index)),
|
||||
@ -567,9 +514,30 @@ WASM_COMPILED_EXEC_TEST(RefCastStatic) {
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), subtype2_index)),
|
||||
WASM_END});
|
||||
|
||||
const byte kFuncTestSuccessfulSuper = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), function_type_index), WASM_DROP,
|
||||
WASM_I32V(0), WASM_END});
|
||||
|
||||
const byte kFuncTestSuccessfulSub = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), function_subtype1_index),
|
||||
WASM_DROP, WASM_I32V(0), WASM_END});
|
||||
|
||||
const byte kFuncTestFailed = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {ValueType::RefNull(function_type_index)},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(function_index)),
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), function_subtype2_index),
|
||||
WASM_DROP, WASM_I32V(1), WASM_END});
|
||||
|
||||
tester.CompileModule();
|
||||
tester.CheckResult(kTestSuccessful, 0);
|
||||
tester.CheckHasThrown(kTestFailed);
|
||||
tester.CheckResult(kFuncTestSuccessfulSuper, 0);
|
||||
tester.CheckResult(kFuncTestSuccessfulSub, 0);
|
||||
tester.CheckHasThrown(kFuncTestFailed);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(RefCastStaticNoChecks) {
|
||||
@ -641,7 +609,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
|
||||
WASM_LOCAL_GET(1), // Put a nullref onto the value stack.
|
||||
// Not taken for nullref.
|
||||
WASM_BR_ON_CAST(0, WASM_GLOBAL_GET(rtt_index)),
|
||||
WASM_RTT_CANON(type_index), WASM_GC_OP(kExprRefCast),
|
||||
WASM_GC_OP(kExprRefCastStatic), type_index,
|
||||
|
||||
WASM_LOCAL_SET(0, WASM_I32V(222))), // Final result.
|
||||
WASM_DROP, WASM_LOCAL_GET(0), kExprEnd});
|
||||
@ -692,7 +660,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCastFail) {
|
||||
WASM_BLOCK_R(kDataRefNull, WASM_LOCAL_GET(0), \
|
||||
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(type0)), \
|
||||
WASM_GC_OP(kExprStructGet), type0, 0, kExprReturn), \
|
||||
kExprBrOnNull, 0, WASM_RTT_CANON(type1), WASM_GC_OP(kExprRefCast), \
|
||||
kExprBrOnNull, 0, WASM_GC_OP(kExprRefCastStatic), type1, \
|
||||
WASM_GC_OP(kExprStructGet), type1, 1, kExprReturn), \
|
||||
WASM_I32V(null_value), kExprEnd
|
||||
|
||||
@ -1214,93 +1182,6 @@ WASM_COMPILED_EXEC_TEST(NewDefault) {
|
||||
tester.CheckResult(allocate_array, 0);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(RefTrivialCasts) {
|
||||
// TODO(7748): Add tests for branch_on_*.
|
||||
WasmGCTester tester(execution_tier);
|
||||
byte type_index = tester.DefineStruct({F(wasm::kWasmI32, true)});
|
||||
byte subtype_index = tester.DefineStruct(
|
||||
{F(wasm::kWasmI32, true), F(wasm::kWasmS128, false)}, type_index);
|
||||
ValueType sig_types[] = {kWasmS128, kWasmI32, kWasmF64};
|
||||
FunctionSig sig(1, 2, sig_types);
|
||||
byte sig_index = tester.DefineSignature(&sig);
|
||||
|
||||
const byte kRefTestNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_REF_NULL(type_index), WASM_RTT_CANON(subtype_index)),
|
||||
kExprEnd});
|
||||
// Upcasts should not be optimized away for structural types.
|
||||
const byte kRefTestUpcast = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_STRUCT_NEW_DEFAULT(subtype_index),
|
||||
WASM_RTT_CANON(type_index)),
|
||||
kExprEnd});
|
||||
const byte kRefTestUpcastNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_REF_NULL(subtype_index), WASM_RTT_CANON(type_index)),
|
||||
kExprEnd});
|
||||
const byte kRefTestUnrelated = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_STRUCT_NEW_DEFAULT(subtype_index),
|
||||
WASM_RTT_CANON(sig_index)),
|
||||
kExprEnd});
|
||||
const byte kRefTestUnrelatedNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_REF_NULL(subtype_index), WASM_RTT_CANON(sig_index)),
|
||||
kExprEnd});
|
||||
const byte kRefTestUnrelatedNonNullable =
|
||||
tester.DefineFunction(tester.sigs.i_v(), {},
|
||||
{WASM_REF_TEST(WASM_STRUCT_NEW_DEFAULT(type_index),
|
||||
WASM_RTT_CANON(sig_index)),
|
||||
kExprEnd});
|
||||
|
||||
const byte kRefCastNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_REF_NULL(type_index),
|
||||
WASM_RTT_CANON(subtype_index))),
|
||||
kExprEnd});
|
||||
const byte kRefCastUpcast = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_STRUCT_NEW_DEFAULT(subtype_index),
|
||||
WASM_RTT_CANON(type_index))),
|
||||
kExprEnd});
|
||||
const byte kRefCastUpcastNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_REF_NULL(subtype_index),
|
||||
WASM_RTT_CANON(type_index))),
|
||||
kExprEnd});
|
||||
const byte kRefCastUnrelated = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_STRUCT_NEW_DEFAULT(subtype_index),
|
||||
WASM_RTT_CANON(sig_index))),
|
||||
kExprEnd});
|
||||
const byte kRefCastUnrelatedNull = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_REF_NULL(subtype_index),
|
||||
WASM_RTT_CANON(sig_index))),
|
||||
kExprEnd});
|
||||
const byte kRefCastUnrelatedNonNullable = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {},
|
||||
{WASM_REF_IS_NULL(WASM_REF_CAST(WASM_STRUCT_NEW_DEFAULT(type_index),
|
||||
WASM_RTT_CANON(sig_index))),
|
||||
kExprEnd});
|
||||
|
||||
tester.CompileModule();
|
||||
|
||||
tester.CheckResult(kRefTestNull, 0);
|
||||
tester.CheckResult(kRefTestUpcast, 1);
|
||||
tester.CheckResult(kRefTestUpcastNull, 0);
|
||||
tester.CheckResult(kRefTestUnrelated, 0);
|
||||
tester.CheckResult(kRefTestUnrelatedNull, 0);
|
||||
tester.CheckResult(kRefTestUnrelatedNonNullable, 0);
|
||||
|
||||
tester.CheckResult(kRefCastNull, 1);
|
||||
tester.CheckResult(kRefCastUpcast, 0);
|
||||
tester.CheckResult(kRefCastUpcastNull, 1);
|
||||
tester.CheckHasThrown(kRefCastUnrelated);
|
||||
tester.CheckResult(kRefCastUnrelatedNull, 1);
|
||||
tester.CheckHasThrown(kRefCastUnrelatedNonNullable);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(RefTrivialCastsStatic) {
|
||||
WasmGCTester tester(execution_tier);
|
||||
byte type_index = tester.DefineStruct({F(wasm::kWasmI32, true)});
|
||||
@ -1568,33 +1449,6 @@ WASM_COMPILED_EXEC_TEST(TrivialAbstractCasts) {
|
||||
tester.CheckHasThrown(kAsArrayUnrelatedNonNullable);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(NoDepthRtt) {
|
||||
WasmGCTester tester(execution_tier);
|
||||
|
||||
const byte type_index = tester.DefineStruct({F(wasm::kWasmI32, true)});
|
||||
const byte subtype_index = tester.DefineStruct(
|
||||
{F(wasm::kWasmI32, true), F(wasm::kWasmI32, true)}, type_index);
|
||||
|
||||
ValueType kRttTypeNoDepth = ValueType::Rtt(type_index);
|
||||
FunctionSig sig_t1_v_nd(1, 0, &kRttTypeNoDepth);
|
||||
ValueType kRttSubtypeNoDepth = ValueType::Rtt(subtype_index);
|
||||
FunctionSig sig_t2_v_nd(1, 0, &kRttSubtypeNoDepth);
|
||||
|
||||
const byte kRttSubtypeCanon = tester.DefineFunction(
|
||||
&sig_t2_v_nd, {}, {WASM_RTT_CANON(subtype_index), kExprEnd});
|
||||
|
||||
const byte kTestCanon = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {refNull(type_index)},
|
||||
{WASM_LOCAL_SET(
|
||||
0, WASM_STRUCT_NEW(subtype_index, WASM_I32V(11), WASM_I32V(42))),
|
||||
WASM_REF_TEST(WASM_LOCAL_GET(0), WASM_CALL_FUNCTION0(kRttSubtypeCanon)),
|
||||
kExprEnd});
|
||||
|
||||
tester.CompileModule();
|
||||
|
||||
tester.CheckResult(kTestCanon, 1);
|
||||
}
|
||||
|
||||
WASM_COMPILED_EXEC_TEST(ArrayNewMap) {
|
||||
WasmGCTester tester(execution_tier);
|
||||
|
||||
@ -1642,7 +1496,7 @@ WASM_COMPILED_EXEC_TEST(FunctionRefs) {
|
||||
const byte cast = tester.DefineFunction(
|
||||
&sig_func, {kWasmFuncRef},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(func_index)),
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_RTT_CANON(sig_index)), kExprEnd});
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), sig_index), kExprEnd});
|
||||
|
||||
const byte cast_reference = tester.DefineFunction(
|
||||
&sig_func, {}, {WASM_REF_FUNC(sig_index), kExprEnd});
|
||||
@ -1650,13 +1504,12 @@ WASM_COMPILED_EXEC_TEST(FunctionRefs) {
|
||||
const byte test = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {kWasmFuncRef},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(func_index)),
|
||||
WASM_REF_TEST(WASM_LOCAL_GET(0), WASM_RTT_CANON(sig_index)), kExprEnd});
|
||||
WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), sig_index), kExprEnd});
|
||||
|
||||
const byte test_fail = tester.DefineFunction(
|
||||
tester.sigs.i_v(), {kWasmFuncRef},
|
||||
{WASM_LOCAL_SET(0, WASM_REF_FUNC(func_index)),
|
||||
WASM_REF_TEST(WASM_LOCAL_GET(0), WASM_RTT_CANON(other_sig_index)),
|
||||
kExprEnd});
|
||||
WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), other_sig_index), kExprEnd});
|
||||
|
||||
tester.CompileModule();
|
||||
|
||||
@ -2034,9 +1887,6 @@ WASM_COMPILED_EXEC_TEST(CastsBenchmark) {
|
||||
tester.AddGlobal(ValueType::RefNull(ListType), true,
|
||||
WasmInitExpr::RefNullConst(
|
||||
static_cast<HeapType::Representation>(ListType)));
|
||||
const byte RttSuper = tester.AddGlobal(
|
||||
ValueType::Rtt(SuperType), false,
|
||||
WasmInitExpr::RttCanon(static_cast<HeapType::Representation>(SuperType)));
|
||||
|
||||
const uint32_t kListLength = 1024;
|
||||
const uint32_t i = 0;
|
||||
@ -2089,12 +1939,12 @@ WASM_COMPILED_EXEC_TEST(CastsBenchmark) {
|
||||
WASM_LOCAL_GET(sum),
|
||||
WASM_STRUCT_GET(
|
||||
SuperType, 0,
|
||||
WASM_REF_CAST(
|
||||
WASM_REF_CAST_STATIC(
|
||||
WASM_ARRAY_GET(
|
||||
ListType, WASM_LOCAL_GET(list),
|
||||
WASM_I32_AND(WASM_LOCAL_GET(i),
|
||||
WASM_I32V(kListLength - 1))),
|
||||
WASM_GLOBAL_GET(RttSuper))))),
|
||||
SuperType)))),
|
||||
WASM_LOCAL_SET(i, WASM_I32_ADD(WASM_LOCAL_GET(i), WASM_I32V_1(1))),
|
||||
WASM_BR_IF(0,
|
||||
WASM_I32_LTS(WASM_LOCAL_GET(i), WASM_I32V(kIterations)))),
|
||||
@ -2235,9 +2085,8 @@ WASM_COMPILED_EXEC_TEST(JsAccess) {
|
||||
{WASM_STRUCT_NEW(type_index, WASM_I32V(42)), kExprEnd});
|
||||
tester.DefineExportedFunction(
|
||||
"consumer", &sig_i_super,
|
||||
{WASM_STRUCT_GET(
|
||||
type_index, 0,
|
||||
WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_RTT_CANON(type_index))),
|
||||
{WASM_STRUCT_GET(type_index, 0,
|
||||
WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), type_index)),
|
||||
kExprEnd});
|
||||
|
||||
tester.CompileModule();
|
||||
|
@ -521,10 +521,8 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
|
||||
#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
|
||||
#define WASM_REF_TEST(ref, rtt) ref, rtt, WASM_GC_OP(kExprRefTest)
|
||||
#define WASM_REF_TEST_STATIC(ref, typeidx) \
|
||||
ref, WASM_GC_OP(kExprRefTestStatic), static_cast<byte>(typeidx)
|
||||
#define WASM_REF_CAST(ref, rtt) ref, rtt, WASM_GC_OP(kExprRefCast)
|
||||
#define WASM_REF_CAST_STATIC(ref, typeidx) \
|
||||
ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx)
|
||||
// Takes a reference value from the value stack to allow sequences of
|
||||
|
@ -121,14 +121,14 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
||||
builder.addFunction("main", makeSig([wasmRefType(kWasmFuncRef)], [kWasmI32]))
|
||||
.addBody([
|
||||
// Type check the function
|
||||
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig, kGCPrefix, kExprRefCast,
|
||||
kExprLocalGet, 0, kGCPrefix, kExprRefCastStatic, sig,
|
||||
kExprDrop,
|
||||
// Introduce unknown effect
|
||||
kExprCallFunction, effect,
|
||||
// TF should be able to eliminate the second type check, and return the
|
||||
// constant 1.
|
||||
kExprLocalGet, 0, kGCPrefix, kExprRttCanon, sig,
|
||||
kGCPrefix, kExprRefTest])
|
||||
kExprLocalGet, 0,
|
||||
kGCPrefix, kExprRefTestStatic, sig])
|
||||
.exportFunc();
|
||||
|
||||
var instance = builder.instantiate({m : { f: function () {} }});
|
||||
|
@ -28,8 +28,7 @@ function createArray_i() {
|
||||
builder.addFunction("array_get", sig_i_ai)
|
||||
.addBody([
|
||||
kExprLocalGet, 0, // --
|
||||
kGCPrefix, kExprRttCanon, type_index, // --
|
||||
kGCPrefix, kExprRefCast, // --
|
||||
kGCPrefix, kExprRefCastStatic, type_index, // --
|
||||
kExprLocalGet, 1, // --
|
||||
kGCPrefix, kExprArrayGet, type_index]) // --
|
||||
.exportAs("array_get");
|
||||
@ -37,8 +36,7 @@ function createArray_i() {
|
||||
builder.addFunction("array_set", sig_v_aii)
|
||||
.addBody([
|
||||
kExprLocalGet, 0, // --
|
||||
kGCPrefix, kExprRttCanon, type_index, // --
|
||||
kGCPrefix, kExprRefCast, // --
|
||||
kGCPrefix, kExprRefCastStatic, type_index, // --
|
||||
kExprLocalGet, 1, // --
|
||||
kExprLocalGet, 2, // --
|
||||
kGCPrefix, kExprArraySet, type_index]) // --
|
||||
|
@ -504,8 +504,6 @@ let kExprI31GetU = 0x22;
|
||||
let kExprRttCanon = 0x30;
|
||||
let kExprRttSub = 0x31;
|
||||
let kExprRttFreshSub = 0x32;
|
||||
let kExprRefTest = 0x40;
|
||||
let kExprRefCast = 0x41;
|
||||
let kExprBrOnCast = 0x42;
|
||||
let kExprBrOnCastFail = 0x43;
|
||||
let kExprRefTestStatic = 0x44;
|
||||
|
@ -33,16 +33,14 @@ function createSimpleStruct(field_type, value1, value2) {
|
||||
builder.addFunction("get_field", sig_t_a)
|
||||
.addBody([
|
||||
kExprLocalGet, 0, // --
|
||||
kGCPrefix, kExprRttCanon, type_index, // --
|
||||
kGCPrefix, kExprRefCast, // --
|
||||
kGCPrefix, kExprRefCastStatic, type_index, // --
|
||||
kGCPrefix, struct_get_opcode, type_index, 0]) // --
|
||||
.exportAs("get_field");
|
||||
|
||||
builder.addFunction("set_field", sig_v_at)
|
||||
.addBody([
|
||||
kExprLocalGet, 0, // --
|
||||
kGCPrefix, kExprRttCanon, type_index, // --
|
||||
kGCPrefix, kExprRefCast, // --
|
||||
kGCPrefix, kExprRefCastStatic, type_index, // --
|
||||
kExprLocalGet, 1, // --
|
||||
kGCPrefix, kExprStructSet, type_index, 0]) // --
|
||||
.exportAs("set_field");
|
||||
|
@ -1154,16 +1154,12 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
|
||||
{WASM_UNREACHABLE, WASM_GC_OP(kExprArrayNewDefault),
|
||||
array_index, kExprDrop});
|
||||
|
||||
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTest),
|
||||
struct_index, struct_index});
|
||||
ExpectValidates(sigs.i_v(),
|
||||
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
||||
WASM_GC_OP(kExprRefTest), struct_index, struct_index});
|
||||
ExpectValidates(sigs.i_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefTestStatic),
|
||||
struct_index});
|
||||
|
||||
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCast),
|
||||
struct_index, struct_index, kExprDrop});
|
||||
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
||||
WASM_GC_OP(kExprRefCast), struct_index,
|
||||
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
|
||||
struct_index, kExprDrop});
|
||||
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic),
|
||||
struct_index, kExprDrop});
|
||||
|
||||
ExpectValidates(sigs.v_v(), {WASM_UNREACHABLE, kExprBrOnNull, 0, WASM_DROP});
|
||||
@ -1171,9 +1167,9 @@ TEST_F(FunctionBodyDecoderTest, UnreachableRefTypes) {
|
||||
ExpectValidates(&sig_v_s, {WASM_UNREACHABLE, WASM_LOCAL_GET(0), kExprBrOnNull,
|
||||
0, kExprCallFunction, struct_consumer});
|
||||
|
||||
ExpectValidates(FunctionSig::Build(zone(), {struct_type}, {}),
|
||||
{WASM_UNREACHABLE, WASM_RTT_CANON(struct_index),
|
||||
WASM_GC_OP(kExprRefCast)});
|
||||
ExpectValidates(
|
||||
FunctionSig::Build(zone(), {struct_type}, {}),
|
||||
{WASM_UNREACHABLE, WASM_GC_OP(kExprRefCastStatic), struct_index});
|
||||
|
||||
ExpectValidates(FunctionSig::Build(zone(), {kWasmDataRef}, {}),
|
||||
{WASM_UNREACHABLE, WASM_GC_OP(kExprRefAsData)});
|
||||
@ -4280,56 +4276,44 @@ TEST_F(FunctionBodyDecoderTest, RefTestCast) {
|
||||
ValueType test_reps[] = {kWasmI32, ValueType::RefNull(from_heap)};
|
||||
FunctionSig test_sig(1, 1, test_reps);
|
||||
|
||||
ValueType cast_reps_with_depth[] = {ValueType::RefNull(to_heap),
|
||||
ValueType::RefNull(from_heap)};
|
||||
FunctionSig cast_sig_with_depth(1, 1, cast_reps_with_depth);
|
||||
|
||||
ValueType cast_reps[] = {ValueType::RefNull(to_heap),
|
||||
ValueType::RefNull(from_heap),
|
||||
ValueType::Rtt(to_heap.ref_index())};
|
||||
FunctionSig cast_sig(1, 2, cast_reps);
|
||||
ValueType::RefNull(from_heap)};
|
||||
FunctionSig cast_sig(1, 1, cast_reps);
|
||||
|
||||
if (should_pass) {
|
||||
ExpectValidates(&test_sig,
|
||||
{WASM_REF_TEST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
|
||||
ExpectValidates(&cast_sig_with_depth,
|
||||
{WASM_REF_CAST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
|
||||
ExpectValidates(&cast_sig,
|
||||
{WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))});
|
||||
ExpectValidates(
|
||||
&test_sig,
|
||||
{WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
|
||||
ExpectValidates(
|
||||
&cast_sig,
|
||||
{WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))});
|
||||
} else {
|
||||
std::string error_message =
|
||||
"[0] expected subtype of (ref null func) or (ref null data), found "
|
||||
"local.get of type " +
|
||||
test_reps[1].name();
|
||||
ExpectFailure(&test_sig,
|
||||
{WASM_REF_TEST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
|
||||
kAppendEnd, ("ref.test" + error_message).c_str());
|
||||
ExpectFailure(&cast_sig_with_depth,
|
||||
{WASM_REF_CAST(WASM_LOCAL_GET(0),
|
||||
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
|
||||
kAppendEnd, ("ref.cast" + error_message).c_str());
|
||||
ExpectFailure(&cast_sig,
|
||||
{WASM_REF_CAST(WASM_LOCAL_GET(0), WASM_LOCAL_GET(1))},
|
||||
kAppendEnd, ("ref.cast" + error_message).c_str());
|
||||
ExpectFailure(
|
||||
&test_sig,
|
||||
{WASM_REF_TEST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
|
||||
kAppendEnd, ("ref.test_static" + error_message).c_str());
|
||||
ExpectFailure(
|
||||
&cast_sig,
|
||||
{WASM_REF_CAST_STATIC(WASM_LOCAL_GET(0), WASM_HEAP_TYPE(to_heap))},
|
||||
kAppendEnd, ("ref.cast_static" + error_message).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// Trivial type error.
|
||||
ExpectFailure(
|
||||
sigs.v_v(),
|
||||
{WASM_REF_TEST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
|
||||
ExpectFailure(sigs.v_v(),
|
||||
{WASM_REF_TEST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
|
||||
kAppendEnd,
|
||||
"ref.test[0] expected subtype of (ref null func) or (ref null data), "
|
||||
"found i32.const of type i32");
|
||||
ExpectFailure(
|
||||
sigs.v_v(),
|
||||
{WASM_REF_CAST(WASM_I32V(1), WASM_RTT_CANON(array_heap)), kExprDrop},
|
||||
"ref.test_static[0] expected subtype of (ref null func) or "
|
||||
"(ref null data), found i32.const of type i32");
|
||||
ExpectFailure(sigs.v_v(),
|
||||
{WASM_REF_CAST_STATIC(WASM_I32V(1), array_heap), kExprDrop},
|
||||
kAppendEnd,
|
||||
"ref.cast[0] expected subtype of (ref null func) or (ref null data), "
|
||||
"found i32.const of type i32");
|
||||
"ref.cast_static[0] expected subtype of (ref null func) or "
|
||||
"(ref null data), found i32.const of type i32");
|
||||
}
|
||||
|
||||
TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
|
||||
@ -4348,7 +4332,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
|
||||
FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0),
|
||||
WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
|
||||
WASM_RTT_CANON(sub_struct), WASM_GC_OP(kExprRefCast)});
|
||||
WASM_GC_OP(kExprRefCastStatic), sub_struct});
|
||||
ExpectValidates(
|
||||
FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}),
|
||||
{WASM_I32V(42), WASM_LOCAL_GET(0),
|
||||
@ -4383,7 +4367,7 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
|
||||
ExpectFailure(
|
||||
FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
|
||||
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
|
||||
WASM_RTT_CANON(sub_struct), WASM_GC_OP(kExprRefCast)},
|
||||
WASM_GC_OP(kExprRefCastStatic), sub_struct},
|
||||
kAppendEnd,
|
||||
"br_on_cast[0] expected subtype of (ref null func) or (ref null data), "
|
||||
"found local.get of type anyref");
|
||||
|
Loading…
Reference in New Issue
Block a user