Commit 65530e72 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Test improvements/additions.

Changes:
- Fix error message typo in function-body-decoder.
- Generalize wasm test macros related to reference types.
- Change wasm-gc test API to return bytes.
- Add unittests for ref.test/cast.

Bug: v8:7748
Change-Id: I361987e0b6ac90c4e89a49a8abc125757a5fc8d0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2317319
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69220}
parent 09fcc062
......@@ -3646,7 +3646,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
ValueType::Ref(obj_type.type, kNonNullable),
this->module_))) {
this->errorf(this->pc_,
"ret.cast: rtt type must be subtype of object type");
"ref.cast: rtt type must be subtype of object type");
return 0;
}
Value rtt = Pop(1);
......
This diff is collapsed.
......@@ -83,12 +83,11 @@
#define DEPTH_2 2
#define ARITY_2 2
#define WASM_HEAP_TYPE(heap_type) static_cast<byte>(0x7F & heap_type.code())
#define WASM_HEAP_TYPE(heap_type) static_cast<byte>((heap_type).code() & 0x7f)
#define WASM_REF_TYPE(type) \
static_cast<byte>(type.kind() == ValueType::kRef ? kLocalRef \
: kLocalOptRef), \
WASM_HEAP_TYPE(type.heap_type())
#define WASM_REF_TYPE(type) \
(type).kind() == ValueType::kRef ? kLocalRef : kLocalOptRef, \
WASM_HEAP_TYPE((type).heap_type())
#define WASM_BLOCK(...) kExprBlock, kLocalVoid, __VA_ARGS__, kExprEnd
#define WASM_BLOCK_I(...) kExprBlock, kLocalI32, __VA_ARGS__, kExprEnd
......@@ -447,12 +446,10 @@ inline WasmOpcode LoadStoreOpcodeOf(MachineType type, bool store) {
#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(obj_type, rtt_type, ref, rtt) \
ref, rtt, WASM_GC_OP(kExprRefTest), static_cast<byte>(obj_type), \
static_cast<byte>(rtt_type)
#define WASM_REF_CAST(obj_type, rtt_type, ref, rtt) \
ref, rtt, WASM_GC_OP(kExprRefCast), static_cast<byte>(obj_type), \
static_cast<byte>(rtt_type)
#define WASM_REF_TEST(obj_type, rtt_type, ref, rtt) \
ref, rtt, WASM_GC_OP(kExprRefTest), obj_type, rtt_type
#define WASM_REF_CAST(obj_type, rtt_type, ref, rtt) \
ref, rtt, WASM_GC_OP(kExprRefCast), obj_type, rtt_type
// Takes a reference value from the value stack to allow sequences of
// conditional branches.
#define WASM_BR_ON_CAST(depth, rtt) \
......
......@@ -4061,6 +4061,111 @@ TEST_F(FunctionBodyDecoderTest, RttSub) {
}
}
TEST_F(FunctionBodyDecoderTest, RefTestCast) {
WASM_FEATURE_SCOPE(reftypes);
WASM_FEATURE_SCOPE(typed_funcref);
WASM_FEATURE_SCOPE(gc);
WASM_FEATURE_SCOPE(eh);
TestModuleBuilder builder;
module = builder.module();
HeapType::Representation array_heap =
static_cast<HeapType::Representation>(builder.AddArray(kWasmI8, true));
HeapType::Representation super_struct_heap =
static_cast<HeapType::Representation>(
builder.AddStruct({F(kWasmI16, true)}));
HeapType::Representation sub_struct_heap =
static_cast<HeapType::Representation>(
builder.AddStruct({F(kWasmI16, true), F(kWasmI32, false)}));
// Passing/failing tests due to static subtyping.
std::pair<HeapType::Representation, HeapType::Representation> valid_pairs[] =
{{HeapType::kEq, HeapType::kI31},
{HeapType::kFunc, HeapType::kFunc},
{HeapType::kEq, array_heap},
{HeapType::kEq, super_struct_heap},
{super_struct_heap, sub_struct_heap}};
for (auto pair : valid_pairs) {
HeapType from_heap = HeapType(pair.first);
HeapType to_heap = HeapType(pair.second);
ValueType test_reps[] = {kWasmI32, ValueType::Ref(from_heap, kNullable)};
FunctionSig test_sig(1, 1, test_reps);
ValueType cast_reps[] = {ValueType::Ref(to_heap, kNonNullable),
ValueType::Ref(from_heap, kNullable)};
FunctionSig cast_sig(1, 1, cast_reps);
ExpectValidates(&test_sig,
{WASM_REF_TEST(WASM_HEAP_TYPE(from_heap),
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
ExpectValidates(&cast_sig,
{WASM_REF_CAST(WASM_HEAP_TYPE(from_heap),
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))});
}
std::pair<HeapType::Representation, HeapType::Representation>
invalid_pairs[] = {{HeapType::kI31, HeapType::kEq},
{array_heap, super_struct_heap},
{array_heap, HeapType::kEq},
{HeapType::kExtern, HeapType::kExn}};
for (auto pair : invalid_pairs) {
HeapType from_heap = HeapType(pair.first);
HeapType to_heap = HeapType(pair.second);
ValueType test_reps[] = {kWasmI32, ValueType::Ref(from_heap, kNullable)};
FunctionSig test_sig(1, 1, test_reps);
ValueType cast_reps[] = {ValueType::Ref(to_heap, kNonNullable),
ValueType::Ref(from_heap, kNullable)};
FunctionSig cast_sig(1, 1, cast_reps);
ExpectFailure(&test_sig,
{WASM_REF_TEST(WASM_HEAP_TYPE(from_heap),
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
kAppendEnd,
"ref.test: rtt type must be subtype of object type");
ExpectFailure(&cast_sig,
{WASM_REF_CAST(WASM_HEAP_TYPE(from_heap),
WASM_HEAP_TYPE(to_heap), WASM_GET_LOCAL(0),
WASM_RTT_CANON(WASM_HEAP_TYPE(to_heap)))},
kAppendEnd,
"ref.cast: rtt type must be subtype of object type");
}
// Trivial type error.
ExpectFailure(sigs.v_v(),
{WASM_REF_TEST(kLocalEqRef, kLocalI31Ref, WASM_I32V(1),
WASM_RTT_CANON(kLocalI31Ref)),
kExprDrop},
kAppendEnd,
"ref.test[0] expected type eqref, found i32.const of type i32");
ExpectFailure(sigs.v_v(),
{WASM_REF_CAST(kLocalEqRef, kLocalI31Ref, WASM_I32V(1),
WASM_RTT_CANON(kLocalI31Ref)),
kExprDrop},
kAppendEnd,
"ref.cast[0] expected type eqref, found i32.const of type i32");
// Mismached object heap immediate.
{
ValueType arg_type = ValueType::Ref(HeapType::kEq, kNonNullable);
FunctionSig sig(0, 1, &arg_type);
ExpectFailure(
&sig,
{WASM_REF_TEST(kLocalEqRef, static_cast<byte>(array_heap),
WASM_GET_LOCAL(0), WASM_RTT_CANON(kLocalI31Ref)),
kExprDrop},
kAppendEnd, "ref.test: expected rtt for type 0 but got (rtt 1 i31)");
ExpectFailure(
&sig,
{WASM_REF_CAST(kLocalEqRef, static_cast<byte>(array_heap),
WASM_GET_LOCAL(0), WASM_RTT_CANON(kLocalI31Ref)),
kExprDrop},
kAppendEnd, "ref.cast: expected rtt for type 0 but got (rtt 1 i31)");
}
}
class BranchTableIteratorTest : public TestWithZone {
public:
BranchTableIteratorTest() : TestWithZone() {}
......
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