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

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

Issue 2493433002: [wasm] Only immutable imported globals are valid initializer expressions (Closed)
Patch Set: Removed another test 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 unified diff | Download patch
« no previous file with comments | « test/mjsunit/wasm/data-segments.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/handles.h" 7 #include "src/handles.h"
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 EXPECT_EQ(0, result.val->signatures[0]->parameter_count()); 411 EXPECT_EQ(0, result.val->signatures[0]->parameter_count());
412 EXPECT_EQ(1, result.val->signatures[1]->parameter_count()); 412 EXPECT_EQ(1, result.val->signatures[1]->parameter_count());
413 EXPECT_EQ(2, result.val->signatures[2]->parameter_count()); 413 EXPECT_EQ(2, result.val->signatures[2]->parameter_count());
414 } 414 }
415 if (result.val) delete result.val; 415 if (result.val) delete result.val;
416 416
417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
418 } 418 }
419 419
420 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
421 // Import 2 globals so that we can initialize data with a global index != 0.
422 const byte data[] = {
423 SECTION(Import, 15), // section header
424 2, // number of imports
425 NAME_LENGTH(1), // --
426 'm', // module name
427 NAME_LENGTH(1), // --
428 'f', // global name
429 kExternalGlobal, // import kind
430 kLocalI32, // type
431 0, // mutability
432 NAME_LENGTH(1), // --
433 'n', // module name
434 NAME_LENGTH(1), // --
435 'g', // global name
436 kExternalGlobal, // import kind
437 kLocalI32, // type
438 0, // mutability
439 SECTION(Memory, 4),
440 ENTRY_COUNT(1),
441 kResizableMaximumFlag,
442 28,
443 28,
444 SECTION(Data, 9),
445 ENTRY_COUNT(1),
446 LINEAR_MEMORY_INDEX_0,
447 WASM_INIT_EXPR_GLOBAL(1), // dest addr
448 U32V_1(3), // source size
449 'a',
450 'b',
451 'c' // data bytes
452 };
453 ModuleResult result = DecodeModule(data, data + sizeof(data));
454 EXPECT_OK(result);
455 WasmInitExpr expr = result.val->data_segments.back().dest_addr;
456 EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind);
457 EXPECT_EQ(1, expr.val.global_index);
458 if (result.val) delete result.val;
459 }
460
461 TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
462 // Only an immutable imported global can be used as an init_expr.
463 const byte data[] = {
464 SECTION(Import, 8), // section header
465 1, // number of imports
466 NAME_LENGTH(1), // --
467 'm', // module name
468 NAME_LENGTH(1), // --
469 'f', // global name
470 kExternalGlobal, // import kind
471 kLocalI32, // type
472 1, // mutability
473 SECTION(Memory, 4),
474 ENTRY_COUNT(1),
475 kResizableMaximumFlag,
476 28,
477 28,
478 SECTION(Data, 9),
479 ENTRY_COUNT(1),
480 LINEAR_MEMORY_INDEX_0,
481 WASM_INIT_EXPR_GLOBAL(0), // dest addr
482 U32V_1(3), // source size
483 'a',
484 'b',
485 'c' // data bytes
486 };
487 EXPECT_FAILURE(data);
488 }
489 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableGlobal) {
490 // Only an immutable imported global can be used as an init_expr.
491 const byte data[] = {
492 SECTION(Memory, 4),
493 ENTRY_COUNT(1),
494 kResizableMaximumFlag,
495 28,
496 28,
497 SECTION(Global, 8), // --
498 1,
499 kLocalI32, // local type
500 0, // immutable
501 WASM_INIT_EXPR_I32V_3(0x9bbaa), // init
502 SECTION(Data, 9),
503 ENTRY_COUNT(1),
504 LINEAR_MEMORY_INDEX_0,
505 WASM_INIT_EXPR_GLOBAL(0), // dest addr
506 U32V_1(3), // source size
507 'a',
508 'b',
509 'c' // data bytes
510 };
511 EXPECT_FAILURE(data);
512 }
513
420 TEST_F(WasmModuleVerifyTest, OneDataSegment) { 514 TEST_F(WasmModuleVerifyTest, OneDataSegment) {
421 const byte kDataSegmentSourceOffset = 24; 515 const byte kDataSegmentSourceOffset = 24;
422 const byte data[] = { 516 const byte data[] = {
423 SECTION(Memory, 4), 517 SECTION(Memory, 4),
424 ENTRY_COUNT(1), 518 ENTRY_COUNT(1),
425 kResizableMaximumFlag, 519 kResizableMaximumFlag,
426 28, 520 28,
427 28, 521 28,
428 SECTION(Data, 11), 522 SECTION(Data, 11),
429 ENTRY_COUNT(1), 523 ENTRY_COUNT(1),
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 } 1465 }
1372 1466
1373 TEST_F(WasmModuleVerifyTest, InitExpr_illegal) { 1467 TEST_F(WasmModuleVerifyTest, InitExpr_illegal) {
1374 EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0)); 1468 EXPECT_INIT_EXPR_FAIL(WASM_I32V_1(0), WASM_I32V_1(0));
1375 EXPECT_INIT_EXPR_FAIL(WASM_GET_LOCAL(0)); 1469 EXPECT_INIT_EXPR_FAIL(WASM_GET_LOCAL(0));
1376 EXPECT_INIT_EXPR_FAIL(WASM_SET_LOCAL(0, WASM_I32V_1(0))); 1470 EXPECT_INIT_EXPR_FAIL(WASM_SET_LOCAL(0, WASM_I32V_1(0)));
1377 EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0))); 1471 EXPECT_INIT_EXPR_FAIL(WASM_I32_ADD(WASM_I32V_1(0), WASM_I32V_1(0)));
1378 EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)); 1472 EXPECT_INIT_EXPR_FAIL(WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO));
1379 } 1473 }
1380 1474
1381 TEST_F(WasmModuleVerifyTest, InitExpr_global) {
1382 static const byte data[] = {WASM_INIT_EXPR_GLOBAL(37)};
1383 WasmInitExpr expr = DecodeWasmInitExprForTesting(data, data + sizeof(data));
1384 EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind);
1385 EXPECT_EQ(37, expr.val.global_index);
1386 }
1387
1388 TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) { 1475 TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) {
1389 static const byte data[] = { 1476 static const byte data[] = {
1390 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- 1477 SECTION(Unknown, 4), 1, 'X', 17, 18, // --
1391 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- 1478 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
1392 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- 1479 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
1393 }; 1480 };
1394 EXPECT_VERIFIES(data); 1481 EXPECT_VERIFIES(data);
1395 } 1482 }
1396 1483
1397 } // namespace wasm 1484 } // namespace wasm
1398 } // namespace internal 1485 } // namespace internal
1399 } // namespace v8 1486 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/data-segments.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698