[wasm][memory64] Use i64 offset in init expressions

If memory64 is used, the offset expression in data segments needs to
have type i64 too.
This CL extends the implementation to enforce that, and adds a unittest.

R=manoskouk@chromium.org

Bug: v8:10949
Change-Id: I849483fc96849e83950f09637e62d427a19094f0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2589733
Reviewed-by: Manos Koukoutos <manoskouk@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71759}
This commit is contained in:
Clemens Backes 2020-12-14 15:05:48 +01:00 committed by Commit Bot
parent a7b73fceb4
commit c170e0cf39
2 changed files with 30 additions and 3 deletions

View File

@ -2108,11 +2108,12 @@ class ModuleDecoderImpl : public Decoder {
}
// We know now that the flag is valid. Time to read the rest.
size_t num_globals = module_.get()->globals.size();
size_t num_globals = module_->globals.size();
ValueType expected_type = module_->is_memory64 ? kWasmI64 : kWasmI32;
if (flag == SegmentFlags::kActiveNoIndex) {
*is_active = true;
*index = 0;
*offset = consume_init_expr(module_.get(), kWasmI32, num_globals);
*offset = consume_init_expr(module_.get(), expected_type, num_globals);
return;
}
if (flag == SegmentFlags::kPassive) {
@ -2122,7 +2123,7 @@ class ModuleDecoderImpl : public Decoder {
if (flag == SegmentFlags::kActiveWithIndex) {
*is_active = true;
*index = consume_u32v("memory index");
*offset = consume_init_expr(module_.get(), kWasmI32, num_globals);
*offset = consume_init_expr(module_.get(), expected_type, num_globals);
}
}

View File

@ -3282,6 +3282,32 @@ TEST_F(WasmModuleVerifyTest, IllegalPackedFields) {
EXPECT_NOT_OK(result, "invalid value type");
}
TEST_F(WasmModuleVerifyTest, Memory64DataSegment) {
WASM_FEATURE_SCOPE(memory64);
for (bool enable_memory64 : {false, true}) {
for (bool use_memory64 : {false, true}) {
byte const_opcode = use_memory64 ? kExprI64Const : kExprI32Const;
const byte data[] = {
SECTION(Memory, ENTRY_COUNT(1),
enable_memory64 ? kMemory64WithMaximum : kWithMaximum, 28,
28),
SECTION(Data, ENTRY_COUNT(1), LINEAR_MEMORY_INDEX_0, // -
const_opcode, 0, kExprEnd, // dest addr
U32V_1(3), // source size
'a', 'b', 'c') // data bytes
};
if (enable_memory64 == use_memory64) {
EXPECT_VERIFIES(data);
} else if (enable_memory64) {
EXPECT_FAILURE_WITH_MSG(data, "expected i64, got i32");
} else {
EXPECT_FAILURE_WITH_MSG(data, "expected i32, got i64");
}
}
}
}
#undef EXPECT_INIT_EXPR
#undef EXPECT_INIT_EXPR_FAIL
#undef WASM_INIT_EXPR_I32V_1