Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Unified Diff: test/unittests/wasm/module-decoder-unittest.cc

Issue 2493433002: [wasm] Only immutable imported globals are valid initializer expressions (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/module-decoder-unittest.cc
diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc
index f254358fc90dfbb8923d199289eca95ff0f57cdd..588cec52a8a8d2874360da408274d52c3bcc656c 100644
--- a/test/unittests/wasm/module-decoder-unittest.cc
+++ b/test/unittests/wasm/module-decoder-unittest.cc
@@ -417,6 +417,86 @@ TEST_F(WasmModuleVerifyTest, MultipleSignatures) {
EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
}
+TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
+ const byte data[] = {
+ SECTION(Import, 8), // section header
+ 1, // number of imports
+ NAME_LENGTH(1), // --
+ 'm', // module name
+ NAME_LENGTH(1), // --
+ 'f', // global name
+ kExternalGlobal, // import kind
+ kLocalI32, // type
+ 0, // mutability
+ SECTION(Memory, 4),
+ ENTRY_COUNT(1),
+ kResizableMaximumFlag,
+ 28,
+ 28,
+ SECTION(Data, 9),
+ ENTRY_COUNT(1),
+ LINEAR_MEMORY_INDEX_0,
+ WASM_INIT_EXPR_GLOBAL(0), // dest addr
+ U32V_1(3), // source size
+ 'a',
+ 'b',
+ 'c' // data bytes
+ };
+ EXPECT_VERIFIES(data);
+}
+TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
+ // Only an immutable imported global can be used as an init_expr.
+ const byte data[] = {
+ SECTION(Import, 8), // section header
+ 1, // number of imports
+ NAME_LENGTH(1), // --
+ 'm', // module name
+ NAME_LENGTH(1), // --
+ 'f', // global name
+ kExternalGlobal, // import kind
+ kLocalI32, // type
+ 1, // mutability
+ SECTION(Memory, 4),
+ ENTRY_COUNT(1),
+ kResizableMaximumFlag,
+ 28,
+ 28,
+ SECTION(Data, 9),
+ ENTRY_COUNT(1),
+ LINEAR_MEMORY_INDEX_0,
+ WASM_INIT_EXPR_GLOBAL(0), // dest addr
+ U32V_1(3), // source size
+ 'a',
+ 'b',
+ 'c' // data bytes
+ };
+ EXPECT_FAILURE(data);
+}
+TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
+ // Only an immutable imported global can be used as an init_expr.
+ const byte data[] = {
+ SECTION(Memory, 4),
+ ENTRY_COUNT(1),
+ kResizableMaximumFlag,
+ 28,
+ 28,
+ SECTION(Global, 8), // --
+ 1,
+ kLocalI32, // local type
+ 0, // immutable
+ WASM_INIT_EXPR_I32V_3(0x9bbaa), // init
+ SECTION(Data, 9),
+ ENTRY_COUNT(1),
+ LINEAR_MEMORY_INDEX_0,
+ WASM_INIT_EXPR_GLOBAL(0), // dest addr
+ U32V_1(3), // source size
+ 'a',
+ 'b',
+ 'c' // data bytes
+ };
+ EXPECT_FAILURE(data);
+}
+
TEST_F(WasmModuleVerifyTest, OneDataSegment) {
const byte kDataSegmentSourceOffset = 24;
const byte data[] = {
« src/wasm/module-decoder.cc ('K') | « src/wasm/module-decoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698