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

[wasm][test] Replace struct.new_with_rtt with struct.new

in unit tests:
- function-body-decoder-unittest.cc
- module-decoder-unittest.cc

    Bug: v8:7748

Change-Id: I1f782bb7292ecd1206a921daccde23b1d314d325
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3751198Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Matthias Liedtke <mliedtke@google.com>
Auto-Submit: Matthias Liedtke <mliedtke@google.com>
Cr-Commit-Position: refs/heads/main@{#81601}
parent 9662376a
...@@ -504,8 +504,6 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) { ...@@ -504,8 +504,6 @@ inline uint16_t ExtractPrefixedOpcodeBytes(WasmOpcode opcode) {
#define WASM_GC_OP(op) kGCPrefix, static_cast<byte>(op) #define WASM_GC_OP(op) kGCPrefix, static_cast<byte>(op)
#define WASM_STRUCT_NEW(index, ...) \ #define WASM_STRUCT_NEW(index, ...) \
__VA_ARGS__, WASM_GC_OP(kExprStructNew), static_cast<byte>(index) __VA_ARGS__, WASM_GC_OP(kExprStructNew), static_cast<byte>(index)
#define WASM_STRUCT_NEW_WITH_RTT(index, ...) \
__VA_ARGS__, WASM_GC_OP(kExprStructNewWithRtt), static_cast<byte>(index)
#define WASM_STRUCT_NEW_DEFAULT(index) \ #define WASM_STRUCT_NEW_DEFAULT(index) \
WASM_GC_OP(kExprStructNewDefault), static_cast<byte>(index) WASM_GC_OP(kExprStructNewDefault), static_cast<byte>(index)
#define WASM_STRUCT_NEW_DEFAULT_WITH_RTT(index, rtt) \ #define WASM_STRUCT_NEW_DEFAULT_WITH_RTT(index, rtt) \
......
...@@ -3583,13 +3583,11 @@ TEST_F(FunctionBodyDecoderTest, UnpackPackedTypes) { ...@@ -3583,13 +3583,11 @@ TEST_F(FunctionBodyDecoderTest, UnpackPackedTypes) {
TestModuleBuilder builder; TestModuleBuilder builder;
byte type_index = builder.AddStruct({F(kWasmI8, true), F(kWasmI16, false)}); byte type_index = builder.AddStruct({F(kWasmI8, true), F(kWasmI16, false)});
module = builder.module(); module = builder.module();
ExpectValidates( ExpectValidates(sigs.v_v(),
sigs.v_v(), {WASM_STRUCT_SET(type_index, 0,
{WASM_STRUCT_SET( WASM_STRUCT_NEW(type_index, WASM_I32V(1),
type_index, 0, WASM_I32V(42)),
WASM_STRUCT_NEW_WITH_RTT(type_index, WASM_I32V(1), WASM_I32V(42), WASM_I32V(-1))});
WASM_RTT_CANON(type_index)),
WASM_I32V(-1))});
} }
{ {
TestModuleBuilder builder; TestModuleBuilder builder;
...@@ -3913,49 +3911,30 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) { ...@@ -3913,49 +3911,30 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
const FunctionSig sig_r_v(1, 0, &struct_type); const FunctionSig sig_r_v(1, 0, &struct_type);
const FunctionSig sig_f_r(1, 1, reps_f_r); const FunctionSig sig_f_r(1, 1, reps_f_r);
/** struct.new_with_rtt **/ /** struct.new **/
ExpectValidates( ExpectValidates(&sig_r_v, {WASM_STRUCT_NEW(struct_type_index, WASM_I32V(0))});
&sig_r_v, {WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0),
WASM_RTT_CANON(struct_type_index))});
// Too few arguments. // Too few arguments.
ExpectFailure(&sig_r_v, ExpectFailure(&sig_r_v, {WASM_GC_OP(kExprStructNew), struct_type_index},
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index,
WASM_RTT_CANON(struct_type_index))},
kAppendEnd, kAppendEnd,
"not enough arguments on the stack for struct.new_with_rtt " "not enough arguments on the stack for struct.new "
"(need 2, got 1)"); "(need 2, got 1)");
// Too many arguments. // Too many arguments.
ExpectFailure( ExpectFailure(
&sig_r_v, &sig_r_v,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0), WASM_I32V(1), {WASM_STRUCT_NEW(struct_type_index, WASM_I32V(0), WASM_I32V(1))},
WASM_RTT_CANON(struct_type_index))},
kAppendEnd, "expected 1 elements on the stack for fallthru, found 2"); kAppendEnd, "expected 1 elements on the stack for fallthru, found 2");
// Mistyped arguments. // Mistyped arguments.
ExpectFailure(&sig_v_r, ExpectFailure(&sig_v_r,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_LOCAL_GET(0), {WASM_STRUCT_NEW(struct_type_index, WASM_LOCAL_GET(0))},
WASM_RTT_CANON(struct_type_index))},
kAppendEnd, kAppendEnd,
"struct.new_with_rtt[0] expected type i32, found local.get of " "struct.new[0] expected type i32, found local.get of "
"type (ref 0)"); "type (ref 0)");
// Wrongly typed index. // Wrongly typed index.
ExpectFailure(sigs.v_v(), ExpectFailure(sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(array_type_index, WASM_I32V(0), {WASM_STRUCT_NEW(array_type_index, WASM_I32V(0)), kExprDrop},
WASM_RTT_CANON(struct_type_index)),
kExprDrop},
kAppendEnd, "invalid struct index: 1"); kAppendEnd, "invalid struct index: 1");
// Wrongly typed rtt.
ExpectFailure(sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0),
WASM_RTT_CANON(array_type_index)),
kExprDrop},
kAppendEnd,
"struct.new_with_rtt[1] expected type (rtt 0), found "
"rtt.canon of type (rtt 1)");
// Out-of-bounds index. // Out-of-bounds index.
ExpectFailure(sigs.v_v(), ExpectFailure(sigs.v_v(), {WASM_STRUCT_NEW(42, WASM_I32V(0)), kExprDrop},
{WASM_STRUCT_NEW_WITH_RTT(42, WASM_I32V(0),
WASM_RTT_CANON(struct_type_index)),
kExprDrop},
kAppendEnd, "invalid struct index: 42"); kAppendEnd, "invalid struct index: 42");
/** struct.get **/ /** struct.get **/
...@@ -4003,14 +3982,12 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) { ...@@ -4003,14 +3982,12 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
kAppendEnd, kAppendEnd,
"expected 1 elements on the stack for fallthru, found 0"); "expected 1 elements on the stack for fallthru, found 0");
// Setting immutable field. // Setting immutable field.
ExpectFailure( ExpectFailure(sigs.v_v(),
sigs.v_v(), {WASM_STRUCT_SET(
{WASM_STRUCT_SET( immutable_struct_type_index, field_index,
immutable_struct_type_index, field_index, WASM_STRUCT_NEW(immutable_struct_type_index, WASM_I32V(42)),
WASM_STRUCT_NEW_WITH_RTT(immutable_struct_type_index, WASM_I32V(42), WASM_I32V(0))},
WASM_RTT_CANON(immutable_struct_type_index)), kAppendEnd, "struct.set: Field 0 of type 2 is immutable.");
WASM_I32V(0))},
kAppendEnd, "struct.set: Field 0 of type 2 is immutable.");
// struct.get_s/u fail // struct.get_s/u fail
ExpectFailure( ExpectFailure(
...@@ -4200,10 +4177,9 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) { ...@@ -4200,10 +4177,9 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
array_type_index, WASM_I32V(0), WASM_I32V(5), array_type_index, WASM_I32V(0), WASM_I32V(5),
WASM_RTT_CANON(array_type_index)), WASM_RTT_CANON(array_type_index)),
kExprDrop}); kExprDrop});
ExpectValidates(sigs.v_v(), ExpectValidates(
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(42), sigs.v_v(),
WASM_RTT_CANON(struct_type_index)), {WASM_STRUCT_NEW(struct_type_index, WASM_I32V(42)), kExprDrop});
kExprDrop});
// It can't unpack types other that i32. // It can't unpack types other that i32.
ExpectFailure( ExpectFailure(
sigs.v_v(), sigs.v_v(),
...@@ -4212,13 +4188,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) { ...@@ -4212,13 +4188,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
kExprDrop}, kExprDrop},
kAppendEnd, kAppendEnd,
"array.new_with_rtt[0] expected type i32, found i64.const of type i64"); "array.new_with_rtt[0] expected type i32, found i64.const of type i64");
ExpectFailure( ExpectFailure(sigs.v_v(),
sigs.v_v(), {WASM_STRUCT_NEW(struct_type_index, WASM_I64V(42)), kExprDrop},
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I64V(42), kAppendEnd,
WASM_RTT_CANON(struct_type_index)), "struct.new[0] expected type i32, found i64.const of type i64");
kExprDrop},
kAppendEnd,
"struct.new_with_rtt[0] expected type i32, found i64.const of type i64");
// *.set with packed fields works. // *.set with packed fields works.
ExpectValidates(sigs.v_v(), {WASM_ARRAY_SET(array_type_index, ExpectValidates(sigs.v_v(), {WASM_ARRAY_SET(array_type_index,
...@@ -4236,11 +4209,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) { ...@@ -4236,11 +4209,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
"array.set[2] expected type i32, found i64.const of type i64"); "array.set[2] expected type i32, found i64.const of type i64");
ExpectFailure( ExpectFailure(
sigs.v_v(), sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, field_index, {WASM_STRUCT_NEW(struct_type_index, field_index,
WASM_REF_NULL(struct_type_index), WASM_I64V(42), WASM_REF_NULL(struct_type_index), WASM_I64V(42))},
WASM_RTT_CANON(struct_type_index))},
kAppendEnd, kAppendEnd,
"struct.new_with_rtt[0] expected type i32, found i64.const of type i64"); "struct.new[0] expected type i32, found i64.const of type i64");
// *.get_s/u works. // *.get_s/u works.
ExpectValidates(sigs.i_v(), {WASM_ARRAY_GET_S(array_type_index, ExpectValidates(sigs.i_v(), {WASM_ARRAY_GET_S(array_type_index,
......
...@@ -36,7 +36,7 @@ namespace module_decoder_unittest { ...@@ -36,7 +36,7 @@ namespace module_decoder_unittest {
#define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd #define WASM_INIT_EXPR_REF_FUNC(val) WASM_REF_FUNC(val), kExprEnd
#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_WITH_RTT(index, __VA_ARGS__), kExprEnd WASM_STRUCT_NEW(index, __VA_ARGS__), kExprEnd
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED(index, length, ...) \ #define WASM_INIT_EXPR_ARRAY_NEW_FIXED(index, length, ...) \
WASM_ARRAY_NEW_FIXED(index, length, __VA_ARGS__), kExprEnd 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, ...) \
...@@ -823,20 +823,17 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) { ...@@ -823,20 +823,17 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))), WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))),
SECTION(Global, ENTRY_COUNT(1), // -- SECTION(Global, ENTRY_COUNT(1), // --
kRefCode, 0, 0, // type, mutability kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42), WASM_RTT_CANON(0)))}; WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42)))};
EXPECT_VERIFIES(basic); EXPECT_VERIFIES(basic);
static const byte global_args[] = { static const byte global_args[] = {
SECTION(Type, ENTRY_COUNT(1), // -- SECTION(Type, ENTRY_COUNT(1), // --
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))), WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))),
SECTION(Global, ENTRY_COUNT(3), // -- SECTION(Global, ENTRY_COUNT(2), // --
kI32Code, 0, // type, mutability kI32Code, 0, // type, mutability
WASM_INIT_EXPR_I32V_1(10), // -- WASM_INIT_EXPR_I32V_1(10), // --
kRttCode, 0, 0, // type, mutability kRefCode, 0, 0, // type, mutability
WASM_RTT_CANON(0), kExprEnd, // -- WASM_INIT_EXPR_STRUCT_NEW(0, WASM_GLOBAL_GET(0)))};
kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_GLOBAL_GET(0),
WASM_GLOBAL_GET(1)))};
EXPECT_VERIFIES(global_args); EXPECT_VERIFIES(global_args);
static const byte type_error[] = { static const byte type_error[] = {
...@@ -845,21 +842,10 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) { ...@@ -845,21 +842,10 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI64Code, true))), WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI64Code, true))),
SECTION(Global, ENTRY_COUNT(1), // -- SECTION(Global, ENTRY_COUNT(1), // --
kRefCode, 1, 0, // type, mutability kRefCode, 1, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42), WASM_RTT_CANON(0)))}; WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42)))};
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))");
static const byte subexpr_type_error[] = {
SECTION(Type, ENTRY_COUNT(2), // --
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true)),
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI64Code, true))),
SECTION(Global, ENTRY_COUNT(1), // --
kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_I32V(42), WASM_RTT_CANON(1)))};
EXPECT_FAILURE_WITH_MSG(subexpr_type_error,
"struct.new_with_rtt[1] expected type (rtt 0), found "
"rtt.canon of type (rtt 1)");
} }
TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) { TEST_F(WasmModuleVerifyTest, ArrayNewFixedInitExpr) {
......
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