Commit 0dc1a2d8 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Add tests for array/struct index checks.

This was postponed until the changes to struct and array types
were implemented
(https://chromium-review.googlesource.com/c/v8/v8/+/2215049).

Bug: v8:7748
Change-Id: I2c7a7d6bcbc1b93f82240f5e245ac1a066d74511
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2214832
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68036}
parent aad9bf8c
......@@ -942,6 +942,126 @@ TEST(MemoryWithOOBEmptyDataSegment) {
Cleanup();
}
TEST(GcStructIdsPass) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(anyref);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcStructIdsPass");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(23), // Section size
U32V_1(3), // type count
kWasmStructTypeCode, // index 0 = struct(i32, type(0), type(1))
U32V_1(3), // field count
kLocalI32, // field 0
U32V_1(1), // mutability
kLocalRef, // field 1
U32V_1(0), // --
U32V_1(1), // mutability
kLocalRef, // field 2
U32V_1(1), // --
U32V_1(1), // mutability
kWasmStructTypeCode, // index 1 = struct(type(0), type(2))
U32V_1(2), // field count
kLocalRef, // field 0
U32V_1(0), // --
U32V_1(1), // mutability
kLocalRef, // field 1
U32V_1(2), // --
U32V_1(1), // mutability
kWasmArrayTypeCode, // index 2 = array(type(0))
kLocalRef, // element type
U32V_1(0), // --
U32V_1(1) // mutability
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// This module is valid.
if (thrower.error()) {
FATAL("%s", thrower.error_msg());
}
}
Cleanup();
}
TEST(GcStructIdsUndefinedIndex) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(anyref);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcStructIdsUndefinedIndex");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(6), // Section size
U32V_1(1), // type count
kWasmStructTypeCode, // index 0 = struct(type(1))
U32V_1(1), // field count
kLocalRef, // field 0
U32V_1(1), // --
U32V_1(1) // mutability
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// There should be an error reflecting an undeclared index.
CHECK(thrower.error());
CHECK_NE(std::string(thrower.error_msg())
.find("reference to undeclared struct/array"),
std::string::npos);
}
Cleanup();
}
TEST(GcStructIdsIllegalIndex) {
{
EXPERIMENTAL_FLAG_SCOPE(gc);
EXPERIMENTAL_FLAG_SCOPE(anyref);
Isolate* isolate = CcTest::InitIsolateOnce();
HandleScope scope(isolate);
testing::SetupIsolateForWasmModule(isolate);
ErrorThrower thrower(isolate, "GcStructIdsIllegalIndex");
const byte data[] = {
WASM_MODULE_HEADER, // --
kTypeSectionCode, // --
U32V_1(11), // Section size
U32V_1(2), // type count
kWasmStructTypeCode, // index 0 = struct(type(1))
U32V_1(1), // field count
kLocalRef, // field 0
U32V_1(1), // --
U32V_1(1), // mutability
kWasmFunctionTypeCode, // index 1 = int32 -> int32
U32V_1(1), // param count
kLocalI32, // param 0
U32V_1(1), // returns count
kLocalI32 // return 0
};
CompileAndInstantiateForTesting(
isolate, &thrower, ModuleWireBytes(data, data + arraysize(data)));
// There should be an error reflecting an invalid index.
CHECK(thrower.error());
CHECK_NE(std::string(thrower.error_msg())
.find("array element type or struct "
"field references non-type index"),
std::string::npos);
}
Cleanup();
}
#undef EMIT_CODE_WITH_END
} // namespace test_run_wasm_module
......
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