Commit b9768c0d authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[test][wasm-gc] replace remaining new and cast instructions using rtt

Bug: v8:7748
Change-Id: I09e9d919751945e99e0178168358a3f269fa34a3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3776679
Auto-Submit: Matthias Liedtke <mliedtke@google.com>
Commit-Queue: Matthias Liedtke <mliedtke@google.com>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81850}
parent 9b913366
...@@ -574,10 +574,6 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) { ...@@ -574,10 +574,6 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
ValueType kDataRefNull = ValueType::RefNull(HeapType::kData); ValueType kDataRefNull = ValueType::RefNull(HeapType::kData);
const byte type_index = tester.DefineStruct({F(kWasmI32, true)}); const byte type_index = tester.DefineStruct({F(kWasmI32, true)});
const byte other_type_index = tester.DefineStruct({F(kWasmF32, true)}); const byte other_type_index = tester.DefineStruct({F(kWasmF32, true)});
const byte rtt_index =
tester.AddGlobal(ValueType::Rtt(type_index), false,
WasmInitExpr::RttCanon(
static_cast<HeapType::Representation>(type_index)));
const byte kTestStructStatic = tester.DefineFunction( const byte kTestStructStatic = tester.DefineFunction(
tester.sigs.i_v(), {kWasmI32, kDataRefNull}, tester.sigs.i_v(), {kWasmI32, kDataRefNull},
...@@ -608,7 +604,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) { ...@@ -608,7 +604,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
WASM_LOCAL_SET(0, WASM_I32V(111)), WASM_LOCAL_SET(0, WASM_I32V(111)),
WASM_LOCAL_GET(1), // Put a nullref onto the value stack. WASM_LOCAL_GET(1), // Put a nullref onto the value stack.
// Not taken for nullref. // Not taken for nullref.
WASM_BR_ON_CAST(0, WASM_GLOBAL_GET(rtt_index)), WASM_BR_ON_CAST_STATIC(0, type_index),
WASM_GC_OP(kExprRefCastStatic), type_index, WASM_GC_OP(kExprRefCastStatic), type_index,
WASM_LOCAL_SET(0, WASM_I32V(222))), // Final result. WASM_LOCAL_SET(0, WASM_I32V(222))), // Final result.
...@@ -621,7 +617,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) { ...@@ -621,7 +617,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCast) {
// The inner block should take the early branch with a struct // The inner block should take the early branch with a struct
// on the stack. // on the stack.
WASM_BLOCK_R(ValueType::Ref(type_index), WASM_LOCAL_GET(1), WASM_BLOCK_R(ValueType::Ref(type_index), WASM_LOCAL_GET(1),
WASM_BR_ON_CAST(0, WASM_GLOBAL_GET(rtt_index)), WASM_BR_ON_CAST_STATIC(0, type_index),
// Returning 123 is the unreachable failure case. // Returning 123 is the unreachable failure case.
WASM_I32V(123), WASM_BR(1)), WASM_I32V(123), WASM_BR(1)),
// The outer block catches the struct left behind by the inner block // The outer block catches the struct left behind by the inner block
...@@ -658,7 +654,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCastFail) { ...@@ -658,7 +654,7 @@ WASM_COMPILED_EXEC_TEST(BrOnCastFail) {
WASM_LOCAL_SET(0, WASM_SEQ(value)), \ WASM_LOCAL_SET(0, WASM_SEQ(value)), \
WASM_BLOCK( \ WASM_BLOCK( \
WASM_BLOCK_R(kDataRefNull, WASM_LOCAL_GET(0), \ WASM_BLOCK_R(kDataRefNull, WASM_LOCAL_GET(0), \
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(type0)), \ WASM_BR_ON_CAST_STATIC_FAIL(0, type0), \
WASM_GC_OP(kExprStructGet), type0, 0, kExprReturn), \ WASM_GC_OP(kExprStructGet), type0, 0, kExprReturn), \
kExprBrOnNull, 0, WASM_GC_OP(kExprRefCastStatic), type1, \ kExprBrOnNull, 0, WASM_GC_OP(kExprRefCastStatic), type1, \
WASM_GC_OP(kExprStructGet), type1, 1, kExprReturn), \ WASM_GC_OP(kExprStructGet), type1, 1, kExprReturn), \
...@@ -850,16 +846,15 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -850,16 +846,15 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
const byte kInit = tester.DefineFunction( const byte kInit = tester.DefineFunction(
&sig_q_v, {}, &sig_q_v, {},
{WASM_ARRAY_NEW_FIXED(type_index, 3, WASM_I32V(10), WASM_I32V(20), {WASM_ARRAY_NEW_FIXED_STATIC(type_index, 3, WASM_I32V(10), WASM_I32V(20),
WASM_I32V(30), WASM_RTT_CANON(type_index)), WASM_I32V(30)),
kExprEnd}); kExprEnd});
const byte kImmutable = tester.DefineFunction( const byte kImmutable = tester.DefineFunction(
tester.sigs.i_v(), {}, tester.sigs.i_v(), {},
{WASM_ARRAY_GET(immut_type_index, {WASM_ARRAY_GET(immut_type_index,
WASM_ARRAY_NEW_FIXED(immut_type_index, 2, WASM_I32V(42), WASM_ARRAY_NEW_FIXED_STATIC(immut_type_index, 2,
WASM_I32V(43), WASM_I32V(42), WASM_I32V(43)),
WASM_RTT_CANON(immut_type_index)),
WASM_I32V(0)), WASM_I32V(0)),
kExprEnd}); kExprEnd});
......
...@@ -527,13 +527,9 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) { ...@@ -527,13 +527,9 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx) ref, WASM_GC_OP(kExprRefCastStatic), static_cast<byte>(typeidx)
// Takes a reference value from the value stack to allow sequences of // Takes a reference value from the value stack to allow sequences of
// conditional branches. // conditional branches.
#define WASM_BR_ON_CAST(depth, rtt) \
rtt, WASM_GC_OP(kExprBrOnCast), static_cast<byte>(depth)
#define WASM_BR_ON_CAST_STATIC(depth, typeidx) \ #define WASM_BR_ON_CAST_STATIC(depth, typeidx) \
WASM_GC_OP(kExprBrOnCastStatic), static_cast<byte>(depth), \ WASM_GC_OP(kExprBrOnCastStatic), static_cast<byte>(depth), \
static_cast<byte>(typeidx) static_cast<byte>(typeidx)
#define WASM_BR_ON_CAST_FAIL(depth, rtt) \
rtt, WASM_GC_OP(kExprBrOnCastFail), static_cast<byte>(depth)
#define WASM_BR_ON_CAST_STATIC_FAIL(depth, typeidx) \ #define WASM_BR_ON_CAST_STATIC_FAIL(depth, typeidx) \
WASM_GC_OP(kExprBrOnCastStaticFail), static_cast<byte>(depth), \ WASM_GC_OP(kExprBrOnCastStaticFail), static_cast<byte>(depth), \
static_cast<byte>(typeidx) static_cast<byte>(typeidx)
...@@ -581,9 +577,6 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) { ...@@ -581,9 +577,6 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
dst_array, dst_index, src_array, src_index, length, \ dst_array, dst_index, src_array, src_index, length, \
WASM_GC_OP(kExprArrayCopy), static_cast<byte>(dst_idx), \ WASM_GC_OP(kExprArrayCopy), static_cast<byte>(dst_idx), \
static_cast<byte>(src_idx) static_cast<byte>(src_idx)
#define WASM_ARRAY_NEW_FIXED(index, length, ...) \
__VA_ARGS__, WASM_GC_OP(kExprArrayNewFixed), static_cast<byte>(index), \
static_cast<byte>(length)
#define WASM_ARRAY_NEW_FIXED_STATIC(index, length, ...) \ #define WASM_ARRAY_NEW_FIXED_STATIC(index, length, ...) \
__VA_ARGS__, WASM_GC_OP(kExprArrayNewFixedStatic), static_cast<byte>(index), \ __VA_ARGS__, WASM_GC_OP(kExprArrayNewFixedStatic), static_cast<byte>(index), \
static_cast<byte>(length) static_cast<byte>(length)
......
...@@ -125,8 +125,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -125,8 +125,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
let global = builder.addGlobal( let global = builder.addGlobal(
wasmRefType(array_type_index), true, wasmRefType(array_type_index), true,
[...wasmI32Const(1), ...wasmI32Const(2), [...wasmI32Const(1), ...wasmI32Const(2),
kGCPrefix, kExprRttCanon, array_type_index, kGCPrefix, kExprArrayNewDataStatic, array_type_index, data_segment],
kGCPrefix, kExprArrayNewData, array_type_index, data_segment],
builder); builder);
builder.addFunction("global_get", kSig_i_i) builder.addFunction("global_get", kSig_i_i)
...@@ -140,8 +139,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -140,8 +139,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("init_from_data", kSig_i_iii) builder.addFunction("init_from_data", kSig_i_iii)
.addBody([ .addBody([
kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 0, kExprLocalGet, 1,
kGCPrefix, kExprRttCanon, array_type_index, kGCPrefix, kExprArrayNewDataStatic, array_type_index, data_segment,
kGCPrefix, kExprArrayNewData, array_type_index, data_segment,
kExprLocalGet, 2, kExprLocalGet, 2,
kGCPrefix, kExprArrayGetS, array_type_index]) kGCPrefix, kExprArrayGetS, array_type_index])
.exportFunc(); .exportFunc();
......
...@@ -200,8 +200,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -200,8 +200,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
var global = builder.addGlobal( var global = builder.addGlobal(
wasmRefType(array_index), false, wasmRefType(array_index), false,
[kExprGlobalGet, global0.index, ...wasmI32Const(element1_value), [kExprGlobalGet, global0.index, ...wasmI32Const(element1_value),
kGCPrefix, kExprRttCanon, array_index, kGCPrefix, kExprArrayNewFixedStatic, array_index, 2]);
kGCPrefix, kExprArrayNewFixed, array_index, 2]);
builder.addFunction("get_element", kSig_i_i) builder.addFunction("get_element", kSig_i_i)
.addBody([ .addBody([
...@@ -236,8 +235,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -236,8 +235,7 @@ d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
[kExprGlobalGet, global0.index, kExprRefNull, struct_index, [kExprGlobalGet, global0.index, kExprRefNull, struct_index,
...wasmI32Const(element2_value), ...wasmI32Const(element2_value),
kGCPrefix, kExprStructNew, struct_index, kGCPrefix, kExprStructNew, struct_index,
kGCPrefix, kExprRttCanon, array_index, kGCPrefix, kExprArrayNewFixedStatic, array_index, 3]);
kGCPrefix, kExprArrayNewFixed, array_index, 3]);
builder.addFunction("element0", kSig_i_v) builder.addFunction("element0", kSig_i_v)
.addBody([ .addBody([
......
...@@ -491,11 +491,9 @@ let kExprArrayGetU = 0x15; ...@@ -491,11 +491,9 @@ let kExprArrayGetU = 0x15;
let kExprArraySet = 0x16; let kExprArraySet = 0x16;
let kExprArrayLen = 0x17; let kExprArrayLen = 0x17;
let kExprArrayCopy = 0x18; let kExprArrayCopy = 0x18;
let kExprArrayNewFixed = 0x19;
let kExprArrayNewFixedStatic = 0x1a; let kExprArrayNewFixedStatic = 0x1a;
let kExprArrayNew = 0x1b; let kExprArrayNew = 0x1b;
let kExprArrayNewDefault = 0x1c; let kExprArrayNewDefault = 0x1c;
let kExprArrayNewData = 0x1e;
let kExprArrayNewDataStatic = 0x1d; let kExprArrayNewDataStatic = 0x1d;
let kExprArrayNewElemStatic = 0x1f; let kExprArrayNewElemStatic = 0x1f;
let kExprI31New = 0x20; let kExprI31New = 0x20;
...@@ -504,8 +502,6 @@ let kExprI31GetU = 0x22; ...@@ -504,8 +502,6 @@ let kExprI31GetU = 0x22;
let kExprRttCanon = 0x30; let kExprRttCanon = 0x30;
let kExprRttSub = 0x31; let kExprRttSub = 0x31;
let kExprRttFreshSub = 0x32; let kExprRttFreshSub = 0x32;
let kExprBrOnCast = 0x42;
let kExprBrOnCastFail = 0x43;
let kExprRefTestStatic = 0x44; let kExprRefTestStatic = 0x44;
let kExprRefCastStatic = 0x45; let kExprRefCastStatic = 0x45;
let kExprBrOnCastStatic = 0x46; let kExprBrOnCastStatic = 0x46;
......
...@@ -4125,11 +4125,10 @@ TEST_F(FunctionBodyDecoderTest, GCArray) { ...@@ -4125,11 +4125,10 @@ TEST_F(FunctionBodyDecoderTest, GCArray) {
// Allocating and reading is OK: // Allocating and reading is OK:
ExpectValidates( ExpectValidates(
sigs.i_v(), sigs.i_v(),
{WASM_ARRAY_GET( {WASM_ARRAY_GET(immutable_array_type_index,
immutable_array_type_index, WASM_ARRAY_NEW_FIXED_STATIC(immutable_array_type_index, 1,
WASM_ARRAY_NEW_FIXED(immutable_array_type_index, 1, WASM_I32V(42), WASM_I32V(42)),
WASM_RTT_CANON(immutable_array_type_index)), WASM_I32V(0))});
WASM_I32V(0))});
// Writing fails: // Writing fails:
ExpectFailure(&sig_v_r2, ExpectFailure(&sig_v_r2,
{WASM_ARRAY_SET(immutable_array_type_index, WASM_LOCAL_GET(0), {WASM_ARRAY_SET(immutable_array_type_index, WASM_LOCAL_GET(0),
...@@ -4330,59 +4329,49 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) { ...@@ -4330,59 +4329,49 @@ TEST_F(FunctionBodyDecoderTest, BrOnCastOrCastFail) {
ExpectValidates( ExpectValidates(
FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}), FunctionSig::Build(this->zone(), {kWasmI32, subtype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0), {WASM_I32V(42), WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)),
WASM_GC_OP(kExprRefCastStatic), sub_struct}); WASM_GC_OP(kExprRefCastStatic), sub_struct});
ExpectValidates( ExpectValidates(
FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}), FunctionSig::Build(this->zone(), {kWasmI32, supertype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0), {WASM_I32V(42), WASM_LOCAL_GET(0),
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))}); WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)});
// Wrong branch type. // Wrong branch type.
ExpectFailure( ExpectFailure(FunctionSig::Build(this->zone(), {}, {supertype}),
FunctionSig::Build(this->zone(), {}, {supertype}), {WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)), WASM_UNREACHABLE},
WASM_UNREACHABLE}, kAppendEnd,
kAppendEnd, "br_on_cast must target a branch of arity at least 1"); "br_on_cast must target a branch of arity at least 1");
ExpectFailure( ExpectFailure(
FunctionSig::Build(this->zone(), {subtype}, {supertype}), FunctionSig::Build(this->zone(), {subtype}, {supertype}),
{WASM_I32V(42), WASM_LOCAL_GET(0), {WASM_I32V(42), WASM_LOCAL_GET(0),
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))}, WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)},
kAppendEnd, kAppendEnd,
"type error in branch[0] (expected (ref null 1), got (ref null 0))"); "type error in branch[0] (expected (ref null 1), got (ref null 0))");
// Wrong fallthrough type. // Wrong fallthrough type.
ExpectFailure( ExpectFailure(
FunctionSig::Build(this->zone(), {subtype}, {supertype}), FunctionSig::Build(this->zone(), {subtype}, {supertype}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct))}, {WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct)}, kAppendEnd,
kAppendEnd,
"type error in fallthru[0] (expected (ref null 1), got (ref null 0))"); "type error in fallthru[0] (expected (ref null 1), got (ref null 0))");
ExpectFailure( ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {supertype}),
FunctionSig::Build(this->zone(), {supertype}, {supertype}), {WASM_BLOCK_I(WASM_LOCAL_GET(0),
{WASM_BLOCK_I(WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct))},
WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct)))}, kAppendEnd,
kAppendEnd, "type error in branch[0] (expected i32, got (ref null 0))"); "type error in branch[0] (expected i32, got (ref null 0))");
// Argument type error. // Argument type error.
ExpectFailure( ExpectFailure(FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}),
FunctionSig::Build(this->zone(), {subtype}, {kWasmAnyRef}), {WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC(0, sub_struct),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST(0, WASM_RTT_CANON(sub_struct)), WASM_GC_OP(kExprRefCastStatic), sub_struct},
WASM_GC_OP(kExprRefCastStatic), sub_struct}, kAppendEnd,
kAppendEnd, "br_on_cast_static[0] expected subtype of (ref null func) or "
"br_on_cast[0] expected subtype of (ref null func) or (ref null data), " "(ref null data), found local.get of type anyref");
"found local.get of type anyref"); ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {kWasmAnyRef}),
ExpectFailure( {WASM_LOCAL_GET(0), WASM_BR_ON_CAST_STATIC_FAIL(0, sub_struct)},
FunctionSig::Build(this->zone(), {supertype}, {kWasmAnyRef}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_FAIL(0, WASM_RTT_CANON(sub_struct))},
kAppendEnd,
"br_on_cast_fail[0] expected subtype of (ref null func) or (ref null "
"data), found local.get of type anyref");
// Trivial rtt type error.
ExpectFailure(FunctionSig::Build(this->zone(), {supertype}, {supertype}),
{WASM_LOCAL_GET(0), WASM_BR_ON_CAST_FAIL(0, WASM_I64V(42))},
kAppendEnd, kAppendEnd,
"br_on_cast_fail[1] expected rtt, found i64.const of type i64"); "br_on_cast_static_fail[0] expected subtype of (ref null func) "
"or (ref null data), found local.get of type anyref");
} }
TEST_F(FunctionBodyDecoderTest, BrOnAbstractType) { TEST_F(FunctionBodyDecoderTest, BrOnAbstractType) {
......
...@@ -37,11 +37,8 @@ namespace module_decoder_unittest { ...@@ -37,11 +37,8 @@ namespace module_decoder_unittest {
#define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd #define WASM_INIT_EXPR_GLOBAL(index) WASM_GLOBAL_GET(index), kExprEnd
#define WASM_INIT_EXPR_STRUCT_NEW(index, ...) \ #define WASM_INIT_EXPR_STRUCT_NEW(index, ...) \
WASM_STRUCT_NEW(index, __VA_ARGS__), kExprEnd WASM_STRUCT_NEW(index, __VA_ARGS__), kExprEnd
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED(index, length, ...) \
WASM_ARRAY_NEW_FIXED(index, length, __VA_ARGS__), kExprEnd
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(index, length, ...) \ #define WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(index, length, ...) \
WASM_ARRAY_NEW_FIXED_STATIC(index, length, __VA_ARGS__), kExprEnd WASM_ARRAY_NEW_FIXED_STATIC(index, length, __VA_ARGS__), kExprEnd
#define WASM_INIT_EXPR_RTT_CANON(index) WASM_RTT_CANON(index), kExprEnd
#define REF_NULL_ELEMENT kExprRefNull, kFuncRefCode, kExprEnd #define REF_NULL_ELEMENT kExprRefNull, kFuncRefCode, kExprEnd
#define REF_FUNC_ELEMENT(v) kExprRefFunc, U32V_1(v), kExprEnd #define REF_FUNC_ELEMENT(v) kExprRefFunc, U32V_1(v), kExprEnd
...@@ -854,11 +851,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) { ...@@ -854,11 +851,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
static const byte basic[] = { static const byte basic[] = {
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)), SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)),
SECTION( SECTION(Global, ENTRY_COUNT(1), // --
Global, ENTRY_COUNT(1), // -- kRefCode, 0, 0, // type, mutability
kRefCode, 0, 0, // type, mutability WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 3, WASM_I32V(10), WASM_I32V(20), 0, 3, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
WASM_I32V(30), WASM_RTT_CANON(0)))};
EXPECT_VERIFIES(basic); EXPECT_VERIFIES(basic);
static const byte basic_nominal[] = { static const byte basic_nominal[] = {
...@@ -871,11 +867,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) { ...@@ -871,11 +867,10 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
static const byte basic_immutable[] = { static const byte basic_immutable[] = {
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI32Code, false)), SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI32Code, false)),
SECTION( SECTION(Global, ENTRY_COUNT(1), // --
Global, ENTRY_COUNT(1), // -- kRefCode, 0, 0, // type, mutability
kRefCode, 0, 0, // type, mutability WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 3, WASM_I32V(10), WASM_I32V(20), 0, 3, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
WASM_I32V(30), WASM_RTT_CANON(0)))};
EXPECT_VERIFIES(basic_immutable); EXPECT_VERIFIES(basic_immutable);
static const byte type_error[] = { static const byte type_error[] = {
...@@ -884,8 +879,7 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) { ...@@ -884,8 +879,7 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
WASM_ARRAY_DEF(WASM_SEQ(kRefCode, 0), true)), WASM_ARRAY_DEF(WASM_SEQ(kRefCode, 0), true)),
SECTION(Global, ENTRY_COUNT(1), // -- SECTION(Global, ENTRY_COUNT(1), // --
kRefCode, 1, 0, // type, mutability kRefCode, 1, 0, // type, mutability
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 1, WASM_I32V(42), WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(0, 1, WASM_I32V(42)))};
WASM_RTT_CANON(0)))};
EXPECT_FAILURE_WITH_MSG( EXPECT_FAILURE_WITH_MSG(
type_error, type_error,
"type error in constant expression[0] (expected (ref 1), got (ref 0))"); "type error in constant expression[0] (expected (ref 1), got (ref 0))");
...@@ -894,22 +888,21 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) { ...@@ -894,22 +888,21 @@ TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI64Code, true)), SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI64Code, true)),
SECTION(Global, ENTRY_COUNT(1), // -- SECTION(Global, ENTRY_COUNT(1), // --
kRefCode, 0, 0, // type, mutability kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_ARRAY_NEW_FIXED( WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(0, 2, WASM_I64V(42),
0, 2, WASM_I64V(42), WASM_I32V(142), WASM_RTT_CANON(0)))}; WASM_I32V(142)))};
EXPECT_FAILURE_WITH_MSG( EXPECT_FAILURE_WITH_MSG(subexpr_type_error,
subexpr_type_error, "array.new_fixed_static[1] expected type i64, found "
"array.new_fixed[1] expected type i64, found i32.const of type i32"); "i32.const of type i32");
static const byte length_error[] = { static const byte length_error[] = {
SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)), SECTION(Type, ENTRY_COUNT(1), WASM_ARRAY_DEF(kI16Code, true)),
SECTION( SECTION(Global, ENTRY_COUNT(1), // --
Global, ENTRY_COUNT(1), // -- kRefCode, 0, 0, // type, mutability
kRefCode, 0, 0, // type, mutability WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(
WASM_INIT_EXPR_ARRAY_NEW_FIXED(0, 10, WASM_I32V(10), WASM_I32V(20), 0, 10, WASM_I32V(10), WASM_I32V(20), WASM_I32V(30)))};
WASM_I32V(30), WASM_RTT_CANON(0)))}; EXPECT_FAILURE_WITH_MSG(length_error,
EXPECT_FAILURE_WITH_MSG( "not enough arguments on the stack for "
length_error, "array.new_fixed_static (need 11, got 4)");
"not enough arguments on the stack for array.new_fixed (need 11, got 4)");
} }
TEST_F(WasmModuleVerifyTest, EmptyStruct) { TEST_F(WasmModuleVerifyTest, EmptyStruct) {
......
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