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) {
#define WASM_GC_OP(op) kGCPrefix, static_cast<byte>(op)
#define WASM_STRUCT_NEW(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) \
WASM_GC_OP(kExprStructNewDefault), static_cast<byte>(index)
#define WASM_STRUCT_NEW_DEFAULT_WITH_RTT(index, rtt) \
......
......@@ -3583,13 +3583,11 @@ TEST_F(FunctionBodyDecoderTest, UnpackPackedTypes) {
TestModuleBuilder builder;
byte type_index = builder.AddStruct({F(kWasmI8, true), F(kWasmI16, false)});
module = builder.module();
ExpectValidates(
sigs.v_v(),
{WASM_STRUCT_SET(
type_index, 0,
WASM_STRUCT_NEW_WITH_RTT(type_index, WASM_I32V(1), WASM_I32V(42),
WASM_RTT_CANON(type_index)),
WASM_I32V(-1))});
ExpectValidates(sigs.v_v(),
{WASM_STRUCT_SET(type_index, 0,
WASM_STRUCT_NEW(type_index, WASM_I32V(1),
WASM_I32V(42)),
WASM_I32V(-1))});
}
{
TestModuleBuilder builder;
......@@ -3913,49 +3911,30 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
const FunctionSig sig_r_v(1, 0, &struct_type);
const FunctionSig sig_f_r(1, 1, reps_f_r);
/** struct.new_with_rtt **/
ExpectValidates(
&sig_r_v, {WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0),
WASM_RTT_CANON(struct_type_index))});
/** struct.new **/
ExpectValidates(&sig_r_v, {WASM_STRUCT_NEW(struct_type_index, WASM_I32V(0))});
// Too few arguments.
ExpectFailure(&sig_r_v,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index,
WASM_RTT_CANON(struct_type_index))},
ExpectFailure(&sig_r_v, {WASM_GC_OP(kExprStructNew), struct_type_index},
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)");
// Too many arguments.
ExpectFailure(
&sig_r_v,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(0), WASM_I32V(1),
WASM_RTT_CANON(struct_type_index))},
{WASM_STRUCT_NEW(struct_type_index, WASM_I32V(0), WASM_I32V(1))},
kAppendEnd, "expected 1 elements on the stack for fallthru, found 2");
// Mistyped arguments.
ExpectFailure(&sig_v_r,
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_LOCAL_GET(0),
WASM_RTT_CANON(struct_type_index))},
{WASM_STRUCT_NEW(struct_type_index, WASM_LOCAL_GET(0))},
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)");
// Wrongly typed index.
ExpectFailure(sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(array_type_index, WASM_I32V(0),
WASM_RTT_CANON(struct_type_index)),
kExprDrop},
{WASM_STRUCT_NEW(array_type_index, WASM_I32V(0)), kExprDrop},
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.
ExpectFailure(sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(42, WASM_I32V(0),
WASM_RTT_CANON(struct_type_index)),
kExprDrop},
ExpectFailure(sigs.v_v(), {WASM_STRUCT_NEW(42, WASM_I32V(0)), kExprDrop},
kAppendEnd, "invalid struct index: 42");
/** struct.get **/
......@@ -4003,14 +3982,12 @@ TEST_F(FunctionBodyDecoderTest, GCStruct) {
kAppendEnd,
"expected 1 elements on the stack for fallthru, found 0");
// Setting immutable field.
ExpectFailure(
sigs.v_v(),
{WASM_STRUCT_SET(
immutable_struct_type_index, field_index,
WASM_STRUCT_NEW_WITH_RTT(immutable_struct_type_index, WASM_I32V(42),
WASM_RTT_CANON(immutable_struct_type_index)),
WASM_I32V(0))},
kAppendEnd, "struct.set: Field 0 of type 2 is immutable.");
ExpectFailure(sigs.v_v(),
{WASM_STRUCT_SET(
immutable_struct_type_index, field_index,
WASM_STRUCT_NEW(immutable_struct_type_index, WASM_I32V(42)),
WASM_I32V(0))},
kAppendEnd, "struct.set: Field 0 of type 2 is immutable.");
// struct.get_s/u fail
ExpectFailure(
......@@ -4200,10 +4177,9 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
array_type_index, WASM_I32V(0), WASM_I32V(5),
WASM_RTT_CANON(array_type_index)),
kExprDrop});
ExpectValidates(sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I32V(42),
WASM_RTT_CANON(struct_type_index)),
kExprDrop});
ExpectValidates(
sigs.v_v(),
{WASM_STRUCT_NEW(struct_type_index, WASM_I32V(42)), kExprDrop});
// It can't unpack types other that i32.
ExpectFailure(
sigs.v_v(),
......@@ -4212,13 +4188,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
kExprDrop},
kAppendEnd,
"array.new_with_rtt[0] expected type i32, found i64.const of type i64");
ExpectFailure(
sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, WASM_I64V(42),
WASM_RTT_CANON(struct_type_index)),
kExprDrop},
kAppendEnd,
"struct.new_with_rtt[0] expected type i32, found i64.const of type i64");
ExpectFailure(sigs.v_v(),
{WASM_STRUCT_NEW(struct_type_index, WASM_I64V(42)), kExprDrop},
kAppendEnd,
"struct.new[0] expected type i32, found i64.const of type i64");
// *.set with packed fields works.
ExpectValidates(sigs.v_v(), {WASM_ARRAY_SET(array_type_index,
......@@ -4236,11 +4209,10 @@ TEST_F(FunctionBodyDecoderTest, PackedFields) {
"array.set[2] expected type i32, found i64.const of type i64");
ExpectFailure(
sigs.v_v(),
{WASM_STRUCT_NEW_WITH_RTT(struct_type_index, field_index,
WASM_REF_NULL(struct_type_index), WASM_I64V(42),
WASM_RTT_CANON(struct_type_index))},
{WASM_STRUCT_NEW(struct_type_index, field_index,
WASM_REF_NULL(struct_type_index), WASM_I64V(42))},
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.
ExpectValidates(sigs.i_v(), {WASM_ARRAY_GET_S(array_type_index,
......
......@@ -36,7 +36,7 @@ namespace module_decoder_unittest {
#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_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, ...) \
WASM_ARRAY_NEW_FIXED(index, length, __VA_ARGS__), kExprEnd
#define WASM_INIT_EXPR_ARRAY_NEW_FIXED_STATIC(index, length, ...) \
......@@ -823,20 +823,17 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))),
SECTION(Global, ENTRY_COUNT(1), // --
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);
static const byte global_args[] = {
SECTION(Type, ENTRY_COUNT(1), // --
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI32Code, true))),
SECTION(Global, ENTRY_COUNT(3), // --
kI32Code, 0, // type, mutability
WASM_INIT_EXPR_I32V_1(10), // --
kRttCode, 0, 0, // type, mutability
WASM_RTT_CANON(0), kExprEnd, // --
kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_GLOBAL_GET(0),
WASM_GLOBAL_GET(1)))};
SECTION(Global, ENTRY_COUNT(2), // --
kI32Code, 0, // type, mutability
WASM_INIT_EXPR_I32V_1(10), // --
kRefCode, 0, 0, // type, mutability
WASM_INIT_EXPR_STRUCT_NEW(0, WASM_GLOBAL_GET(0)))};
EXPECT_VERIFIES(global_args);
static const byte type_error[] = {
......@@ -845,21 +842,10 @@ TEST_F(WasmModuleVerifyTest, StructNewInitExpr) {
WASM_STRUCT_DEF(FIELD_COUNT(1), STRUCT_FIELD(kI64Code, true))),
SECTION(Global, ENTRY_COUNT(1), // --
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(
type_error,
"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) {
......
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