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

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

Issue 1644023002: [wasm] Fix misaligned accesses and endianness issues in decoders. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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/cctest/wasm/test-run-wasm.cc ('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/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0}; 244 byte code[] = {kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0};
245 int64_t* ptr = reinterpret_cast<int64_t*>(code + 1); 245 int64_t* ptr = reinterpret_cast<int64_t*>(code + 1);
246 const int kInc = 4498211; 246 const int kInc = 4498211;
247 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { 247 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
248 *ptr = (static_cast<int64_t>(i) << 32) | i; 248 *ptr = (static_cast<int64_t>(i) << 32) | i;
249 EXPECT_VERIFIES(&env_l_l, code); 249 EXPECT_VERIFIES(&env_l_l, code);
250 } 250 }
251 } 251 }
252 252
253 253
254 // TODO(tizer): Fix on arm and reenable.
255 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
256
257 TEST_F(WasmDecoderTest, Float32Const) { 254 TEST_F(WasmDecoderTest, Float32Const) {
258 byte code[] = {kExprF32Const, 0, 0, 0, 0}; 255 byte code[] = {kExprF32Const, 0, 0, 0, 0};
259 float* ptr = reinterpret_cast<float*>(code + 1); 256 float* ptr = reinterpret_cast<float*>(code + 1);
260 for (int i = 0; i < 30; i++) { 257 for (int i = 0; i < 30; i++) {
261 *ptr = i * -7.75f; 258 *ptr = i * -7.75f;
262 EXPECT_VERIFIES(&env_f_ff, code); 259 EXPECT_VERIFIES(&env_f_ff, code);
263 } 260 }
264 } 261 }
265 262
266 263
267 TEST_F(WasmDecoderTest, Float64Const) { 264 TEST_F(WasmDecoderTest, Float64Const) {
268 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; 265 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0};
269 double* ptr = reinterpret_cast<double*>(code + 1); 266 double* ptr = reinterpret_cast<double*>(code + 1);
270 for (int i = 0; i < 30; i++) { 267 for (int i = 0; i < 30; i++) {
271 *ptr = i * 33.45; 268 *ptr = i * 33.45;
272 EXPECT_VERIFIES(&env_d_dd, code); 269 EXPECT_VERIFIES(&env_d_dd, code);
273 } 270 }
274 } 271 }
275 272
276 #endif
277
278 273
279 TEST_F(WasmDecoderTest, Int32Const_off_end) { 274 TEST_F(WasmDecoderTest, Int32Const_off_end) {
280 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; 275 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44};
281 276
282 for (int size = 1; size <= 4; size++) { 277 for (int size = 1; size <= 4; size++) {
283 Verify(kError, &env_i_i, code, code + size); 278 Verify(kError, &env_i_i, code, code + size);
284 } 279 }
285 } 280 }
286 281
287 282
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 EXPECT_VERIFIES(&env_i_i, code); 520 EXPECT_VERIFIES(&env_i_i, code);
526 } 521 }
527 522
528 523
529 TEST_F(WasmDecoderTest, ExprBlock1b) { 524 TEST_F(WasmDecoderTest, ExprBlock1b) {
530 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; 525 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0};
531 EXPECT_FAILURE(&env_f_ff, code); 526 EXPECT_FAILURE(&env_f_ff, code);
532 } 527 }
533 528
534 529
535 // TODO(tizer): Fix on arm and reenable.
536 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
537
538 TEST_F(WasmDecoderTest, ExprBlock1c) { 530 TEST_F(WasmDecoderTest, ExprBlock1c) {
539 static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0}; 531 static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0};
540 EXPECT_VERIFIES(&env_f_ff, code); 532 EXPECT_VERIFIES(&env_f_ff, code);
541 } 533 }
542 534
543 #endif
544
545 535
546 TEST_F(WasmDecoderTest, IfEmpty) { 536 TEST_F(WasmDecoderTest, IfEmpty) {
547 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop}; 537 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop};
548 EXPECT_VERIFIES(&env_v_i, code); 538 EXPECT_VERIFIES(&env_v_i, code);
549 } 539 }
550 540
551 541
552 TEST_F(WasmDecoderTest, IfSet) { 542 TEST_F(WasmDecoderTest, IfSet) {
553 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal, 543 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal,
554 0, kExprI8Const, 0, kExprNop}; 544 0, kExprI8Const, 0, kExprNop};
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 687
698 688
699 TEST_F(WasmDecoderTest, ReturnVoid2) { 689 TEST_F(WasmDecoderTest, ReturnVoid2) {
700 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; 690 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
701 EXPECT_VERIFIES(&env_v_v, code); 691 EXPECT_VERIFIES(&env_v_v, code);
702 EXPECT_FAILURE(&env_i_i, code); 692 EXPECT_FAILURE(&env_i_i, code);
703 EXPECT_FAILURE(&env_i_f, code); 693 EXPECT_FAILURE(&env_i_f, code);
704 } 694 }
705 695
706 696
707 // TODO(tizer): Fix on arm and reenable.
708 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
709
710 TEST_F(WasmDecoderTest, ReturnVoid3) { 697 TEST_F(WasmDecoderTest, ReturnVoid3) {
711 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI8Const, 0); 698 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI8Const, 0);
712 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI32Const, 0, 0, 0, 0); 699 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI32Const, 0, 0, 0, 0);
713 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0); 700 EXPECT_VERIFIES_INLINE(&env_v_v, kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0);
714 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF32Const, 0, 0, 0, 0); 701 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF32Const, 0, 0, 0, 0);
715 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 702 EXPECT_VERIFIES_INLINE(&env_v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
716 703
717 EXPECT_VERIFIES_INLINE(&env_v_i, kExprGetLocal, 0); 704 EXPECT_VERIFIES_INLINE(&env_v_i, kExprGetLocal, 0);
718 } 705 }
719 706
720 #endif
721
722 707
723 TEST_F(WasmDecoderTest, Unreachable1) { 708 TEST_F(WasmDecoderTest, Unreachable1) {
724 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable); 709 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable);
725 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable, kExprUnreachable); 710 EXPECT_VERIFIES_INLINE(&env_v_v, kExprUnreachable, kExprUnreachable);
726 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO)); 711 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO));
727 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_BR(0), WASM_ZERO)); 712 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(2, WASM_BR(0), WASM_ZERO));
728 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO)); 713 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO));
729 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_BR(0), WASM_ZERO)); 714 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(2, WASM_BR(0), WASM_ZERO));
730 } 715 }
731 716
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 859 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
875 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 860 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
876 VERIFY(WASM_NOP); 861 VERIFY(WASM_NOP);
877 VERIFY(WASM_BLOCK(1, WASM_NOP)); 862 VERIFY(WASM_BLOCK(1, WASM_NOP));
878 VERIFY(WASM_LOOP(1, WASM_NOP)); 863 VERIFY(WASM_LOOP(1, WASM_NOP));
879 VERIFY(WASM_LOOP(1, WASM_BREAK(0))); 864 VERIFY(WASM_LOOP(1, WASM_BREAK(0)));
880 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0))); 865 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0)));
881 } 866 }
882 867
883 868
884 // TODO(tizer): Fix on arm and reenable.
885 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
886
887 TEST_F(WasmDecoderTest, MacrosBreak) { 869 TEST_F(WasmDecoderTest, MacrosBreak) {
888 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0))); 870 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BREAK(0)));
889 871
890 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO))); 872 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
891 EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0)))); 873 EXPECT_VERIFIES_INLINE(&env_l_l, WASM_LOOP(1, WASM_BREAKV(0, WASM_I64(0))));
892 EXPECT_VERIFIES_INLINE(&env_f_ff, 874 EXPECT_VERIFIES_INLINE(&env_f_ff,
893 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0)))); 875 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
894 EXPECT_VERIFIES_INLINE(&env_d_dd, 876 EXPECT_VERIFIES_INLINE(&env_d_dd,
895 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0)))); 877 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0))));
896 } 878 }
897 879
898 #endif
899
900 880
901 TEST_F(WasmDecoderTest, MacrosContinue) { 881 TEST_F(WasmDecoderTest, MacrosContinue) {
902 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_CONTINUE(0))); 882 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_CONTINUE(0)));
903 } 883 }
904 884
905 885
906 TEST_F(WasmDecoderTest, MacrosVariadic) { 886 TEST_F(WasmDecoderTest, MacrosVariadic) {
907 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP)); 887 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP));
908 VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP)); 888 VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP));
909 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP)); 889 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP));
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 module_env.AddFunction(sigs.i_i()); 1236 module_env.AddFunction(sigs.i_i());
1257 module_env.AddFunction(sigs.i_ii()); 1237 module_env.AddFunction(sigs.i_ii());
1258 module_env.AddFunction(sigs.f_ff()); 1238 module_env.AddFunction(sigs.f_ff());
1259 1239
1260 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION0(0)); 1240 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION0(0));
1261 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_ZERO)); 1241 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_ZERO));
1262 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); 1242 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0)));
1263 } 1243 }
1264 1244
1265 1245
1266 // TODO(tizer): Fix on arm and reenable.
1267 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1268
1269 TEST_F(WasmDecoderTest, CallsWithSpilloverArgs) { 1246 TEST_F(WasmDecoderTest, CallsWithSpilloverArgs) {
1270 static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32}; 1247 static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32};
1271 FunctionSig sig_i_ff(1, 2, a_i_ff); 1248 FunctionSig sig_i_ff(1, 2, a_i_ff);
1272 FunctionEnv env_i_ff; 1249 FunctionEnv env_i_ff;
1273 init_env(&env_i_ff, &sig_i_ff); 1250 init_env(&env_i_ff, &sig_i_ff);
1274 1251
1275 TestModuleEnv module_env; 1252 TestModuleEnv module_env;
1276 env_i_ff.module = &module_env; 1253 env_i_ff.module = &module_env;
1277 env_i_i.module = &module_env; 1254 env_i_i.module = &module_env;
1278 env_f_ff.module = &module_env; 1255 env_f_ff.module = &module_env;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27))); 1299 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_I64(27)));
1323 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); 1300 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
1324 1301
1325 module_env.AddFunction(sigs.i_d()); 1302 module_env.AddFunction(sigs.i_d());
1326 1303
1327 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16))); 1304 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I8(16)));
1328 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16))); 1305 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_I64(16)));
1329 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); 1306 EXPECT_FAILURE_INLINE(env, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
1330 } 1307 }
1331 1308
1332 #endif
1333
1334 1309
1335 TEST_F(WasmDecoderTest, SimpleIndirectCalls) { 1310 TEST_F(WasmDecoderTest, SimpleIndirectCalls) {
1336 FunctionEnv* env = &env_i_i; 1311 FunctionEnv* env = &env_i_i;
1337 TestModuleEnv module_env; 1312 TestModuleEnv module_env;
1338 env->module = &module_env; 1313 env->module = &module_env;
1339 1314
1340 byte f0 = module_env.AddSignature(sigs.i_v()); 1315 byte f0 = module_env.AddSignature(sigs.i_v());
1341 byte f1 = module_env.AddSignature(sigs.i_i()); 1316 byte f1 = module_env.AddSignature(sigs.i_i());
1342 byte f2 = module_env.AddSignature(sigs.i_ii()); 1317 byte f2 = module_env.AddSignature(sigs.i_ii());
1343 1318
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 1, WASM_BLOCK(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)))))}; 1541 1, WASM_BLOCK(1, WASM_IF(WASM_GET_LOCAL(0), WASM_BREAK(i)))))};
1567 if (i < 3) { 1542 if (i < 3) {
1568 EXPECT_VERIFIES(&env_v_v, code); 1543 EXPECT_VERIFIES(&env_v_v, code);
1569 } else { 1544 } else {
1570 EXPECT_FAILURE(&env_v_v, code); 1545 EXPECT_FAILURE(&env_v_v, code);
1571 } 1546 }
1572 } 1547 }
1573 } 1548 }
1574 1549
1575 1550
1576 // TODO(tizer): Fix on arm and reenable.
1577 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1578
1579 TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) { 1551 TEST_F(WasmDecoderTest, BreaksWithMultipleTypes) {
1580 EXPECT_FAILURE_INLINE( 1552 EXPECT_FAILURE_INLINE(
1581 &env_i_i, 1553 &env_i_i,
1582 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)), WASM_F32(7.7))); 1554 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)), WASM_F32(7.7)));
1583 EXPECT_FAILURE_INLINE(&env_i_i, 1555 EXPECT_FAILURE_INLINE(&env_i_i,
1584 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)), 1556 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(7)),
1585 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)))); 1557 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7))));
1586 EXPECT_FAILURE_INLINE(&env_i_i, 1558 EXPECT_FAILURE_INLINE(&env_i_i,
1587 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(8)), 1559 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(8)),
1588 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(0)), 1560 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(0)),
1589 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)))); 1561 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7))));
1590 EXPECT_FAILURE_INLINE(&env_i_i, 1562 EXPECT_FAILURE_INLINE(&env_i_i,
1591 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(9)), 1563 WASM_BLOCK(3, WASM_BRV_IF(0, WASM_ZERO, WASM_I8(9)),
1592 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)), 1564 WASM_BRV_IF(0, WASM_ZERO, WASM_F32(7.7)),
1593 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(11)))); 1565 WASM_BRV_IF(0, WASM_ZERO, WASM_I8(11))));
1594 } 1566 }
1595 1567
1596 #endif
1597
1598 1568
1599 TEST_F(WasmDecoderTest, BreakNesting_6_levels) { 1569 TEST_F(WasmDecoderTest, BreakNesting_6_levels) {
1600 for (int mask = 0; mask < 64; mask++) { 1570 for (int mask = 0; mask < 64; mask++) {
1601 for (int i = 0; i < 14; i++) { 1571 for (int i = 0; i < 14; i++) {
1602 byte code[] = { 1572 byte code[] = {
1603 kExprBlock, 1, // -- 1573 kExprBlock, 1, // --
1604 kExprBlock, 1, // -- 1574 kExprBlock, 1, // --
1605 kExprBlock, 1, // -- 1575 kExprBlock, 1, // --
1606 kExprBlock, 1, // -- 1576 kExprBlock, 1, // --
1607 kExprBlock, 1, // -- 1577 kExprBlock, 1, // --
(...skipping 13 matching lines...) Expand all
1621 if (i < depth) { 1591 if (i < depth) {
1622 EXPECT_VERIFIES(&env_v_v, code); 1592 EXPECT_VERIFIES(&env_v_v, code);
1623 } else { 1593 } else {
1624 EXPECT_FAILURE(&env_v_v, code); 1594 EXPECT_FAILURE(&env_v_v, code);
1625 } 1595 }
1626 } 1596 }
1627 } 1597 }
1628 } 1598 }
1629 1599
1630 1600
1631 // TODO(tizer): Fix on arm and reenable.
1632 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1633
1634 TEST_F(WasmDecoderTest, ExprBreak_TypeCheck) { 1601 TEST_F(WasmDecoderTest, ExprBreak_TypeCheck) {
1635 FunctionEnv* envs[] = {&env_i_i, &env_l_l, &env_f_ff, &env_d_dd}; 1602 FunctionEnv* envs[] = {&env_i_i, &env_l_l, &env_f_ff, &env_d_dd};
1636 for (size_t i = 0; i < arraysize(envs); i++) { 1603 for (size_t i = 0; i < arraysize(envs); i++) {
1637 FunctionEnv* env = envs[i]; 1604 FunctionEnv* env = envs[i];
1638 // unify X and X => OK 1605 // unify X and X => OK
1639 EXPECT_VERIFIES_INLINE( 1606 EXPECT_VERIFIES_INLINE(
1640 env, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1607 env, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1641 WASM_GET_LOCAL(0))); 1608 WASM_GET_LOCAL(0)));
1642 } 1609 }
1643 1610
1644 // unify i32 and f32 => fail 1611 // unify i32 and f32 => fail
1645 EXPECT_FAILURE_INLINE( 1612 EXPECT_FAILURE_INLINE(
1646 &env_i_i, 1613 &env_i_i,
1647 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); 1614 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2)));
1648 1615
1649 // unify f64 and f64 => OK 1616 // unify f64 and f64 => OK
1650 EXPECT_VERIFIES_INLINE( 1617 EXPECT_VERIFIES_INLINE(
1651 &env_d_dd, 1618 &env_d_dd,
1652 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1619 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1653 WASM_F64(1.2))); 1620 WASM_F64(1.2)));
1654 } 1621 }
1655 1622
1656 #endif
1657
1658 1623
1659 TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) { 1624 TEST_F(WasmDecoderTest, ExprBreak_TypeCheckAll) {
1660 byte code1[] = {WASM_BLOCK(2, 1625 byte code1[] = {WASM_BLOCK(2,
1661 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1626 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1662 WASM_GET_LOCAL(1))}; 1627 WASM_GET_LOCAL(1))};
1663 byte code2[] = {WASM_BLOCK( 1628 byte code2[] = {WASM_BLOCK(
1664 2, WASM_IF(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_GET_LOCAL(0))), 1629 2, WASM_IF(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_GET_LOCAL(0))),
1665 WASM_GET_LOCAL(1))}; 1630 WASM_GET_LOCAL(1))};
1666 1631
1667 1632
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 static byte code[] = { 1793 static byte code[] = {
1829 WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1794 WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1830 WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))}; 1795 WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))};
1831 EXPECT_VERIFIES(&env_i_i, code); 1796 EXPECT_VERIFIES(&env_i_i, code);
1832 EXPECT_VERIFIES(&env_v_v, code); 1797 EXPECT_VERIFIES(&env_v_v, code);
1833 EXPECT_FAILURE(&env_f_ff, code); 1798 EXPECT_FAILURE(&env_f_ff, code);
1834 EXPECT_FAILURE(&env_d_dd, code); 1799 EXPECT_FAILURE(&env_d_dd, code);
1835 } 1800 }
1836 1801
1837 1802
1838 // TODO(tizer): Fix on arm and reenable.
1839 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1840
1841 TEST_F(WasmDecoderTest, TableSwitch1b) { 1803 TEST_F(WasmDecoderTest, TableSwitch1b) {
1842 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1804 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1843 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO)); 1805 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1844 1806
1845 EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1807 EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1846 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0))); 1808 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0)));
1847 1809
1848 EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1810 EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1849 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0))); 1811 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0)));
1850 } 1812 }
1851 1813
1852 #endif
1853
1854 TEST_F(WasmDecoderTest, TableSwitch_br1) { 1814 TEST_F(WasmDecoderTest, TableSwitch_br1) {
1855 for (int depth = 0; depth < 2; depth++) { 1815 for (int depth = 0; depth < 2; depth++) {
1856 byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)), 1816 byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
1857 WASM_GET_LOCAL(0))}; 1817 WASM_GET_LOCAL(0))};
1858 EXPECT_VERIFIES(&env_v_i, code); 1818 EXPECT_VERIFIES(&env_v_i, code);
1859 EXPECT_FAILURE(&env_i_i, code); 1819 EXPECT_FAILURE(&env_i_i, code);
1860 } 1820 }
1861 } 1821 }
1862 1822
1863 1823
(...skipping 11 matching lines...) Expand all
1875 1835
1876 1836
1877 TEST_F(WasmDecoderTest, TableSwitch_invalid_case_ref) { 1837 TEST_F(WasmDecoderTest, TableSwitch_invalid_case_ref) {
1878 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)), 1838 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)),
1879 WASM_GET_LOCAL(0)); 1839 WASM_GET_LOCAL(0));
1880 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)), 1840 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)),
1881 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO)); 1841 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1882 } 1842 }
1883 1843
1884 1844
1885 // TODO(tizer): Fix on arm and reenable.
1886 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1887
1888 TEST_F(WasmDecoderTest, TableSwitch1_br) { 1845 TEST_F(WasmDecoderTest, TableSwitch1_br) {
1889 EXPECT_VERIFIES_INLINE( 1846 EXPECT_VERIFIES_INLINE(
1890 &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1847 &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1891 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO))); 1848 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO)));
1892 } 1849 }
1893 1850
1894 #endif
1895
1896 1851
1897 TEST_F(WasmDecoderTest, TableSwitch2_br) { 1852 TEST_F(WasmDecoderTest, TableSwitch2_br) {
1898 EXPECT_VERIFIES_INLINE( 1853 EXPECT_VERIFIES_INLINE(
1899 &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1854 &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1900 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)), 1855 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)),
1901 WASM_BRV(0, WASM_I8(1)))); 1856 WASM_BRV(0, WASM_I8(1))));
1902 1857
1903 EXPECT_FAILURE_INLINE( 1858 EXPECT_FAILURE_INLINE(
1904 &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1859 &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1905 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)), 1860 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)),
1906 WASM_BRV(0, WASM_I8(4)))); 1861 WASM_BRV(0, WASM_I8(4))));
1907 } 1862 }
1908 1863
1909 1864
1910 TEST_F(WasmDecoderTest, TableSwitch2x2) { 1865 TEST_F(WasmDecoderTest, TableSwitch2x2) {
1911 EXPECT_VERIFIES_INLINE( 1866 EXPECT_VERIFIES_INLINE(
1912 &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1), 1867 &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1),
1913 WASM_CASE(0), WASM_CASE(1)), 1868 WASM_CASE(0), WASM_CASE(1)),
1914 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)), 1869 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)),
1915 WASM_BRV(0, WASM_I8(4)))); 1870 WASM_BRV(0, WASM_I8(4))));
1916 } 1871 }
1917 1872
1918 1873
1919 // TODO(tizer): Fix on arm and reenable.
1920 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1921
1922 TEST_F(WasmDecoderTest, ExprBreakNesting1) { 1874 TEST_F(WasmDecoderTest, ExprBreakNesting1) {
1923 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO))); 1875 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO)));
1924 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0))); 1876 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0)));
1925 EXPECT_VERIFIES_INLINE(&env_v_v, 1877 EXPECT_VERIFIES_INLINE(&env_v_v,
1926 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1878 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1927 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO))); 1879 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
1928 1880
1929 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 1881 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
1930 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0))); 1882 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0)));
1931 EXPECT_VERIFIES_INLINE(&env_v_v, 1883 EXPECT_VERIFIES_INLINE(&env_v_v,
1932 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1884 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1933 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO))); 1885 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO)));
1934 1886
1935 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 1887 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
1936 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(1))); 1888 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(1)));
1937 } 1889 }
1938 1890
1939 #endif
1940
1941 1891
1942 TEST_F(WasmDecoderTest, Select) { 1892 TEST_F(WasmDecoderTest, Select) {
1943 EXPECT_VERIFIES_INLINE( 1893 EXPECT_VERIFIES_INLINE(
1944 &env_i_i, 1894 &env_i_i,
1945 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 1895 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
1946 } 1896 }
1947 1897
1948 1898
1949 // TODO(tizer): Fix on arm and reenable.
1950 #if !V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_ARM64
1951
1952 TEST_F(WasmDecoderTest, Select_TypeCheck) { 1899 TEST_F(WasmDecoderTest, Select_TypeCheck) {
1953 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), 1900 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0),
1954 WASM_GET_LOCAL(0))); 1901 WASM_GET_LOCAL(0)));
1955 1902
1956 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), 1903 EXPECT_FAILURE_INLINE(&env_i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25),
1957 WASM_GET_LOCAL(0))); 1904 WASM_GET_LOCAL(0)));
1958 1905
1959 EXPECT_FAILURE_INLINE( 1906 EXPECT_FAILURE_INLINE(
1960 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0))); 1907 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0)));
1961 } 1908 }
1962 1909
1963 #endif
1964
1965 1910
1966 class WasmOpcodeLengthTest : public TestWithZone { 1911 class WasmOpcodeLengthTest : public TestWithZone {
1967 public: 1912 public:
1968 WasmOpcodeLengthTest() : TestWithZone() {} 1913 WasmOpcodeLengthTest() : TestWithZone() {}
1969 }; 1914 };
1970 1915
1971 1916
1972 #define EXPECT_LENGTH(expected, opcode) \ 1917 #define EXPECT_LENGTH(expected, opcode) \
1973 { \ 1918 { \
1974 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ 1919 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 EXPECT_ARITY(1, kExprF64SConvertI64); 2377 EXPECT_ARITY(1, kExprF64SConvertI64);
2433 EXPECT_ARITY(1, kExprF64UConvertI64); 2378 EXPECT_ARITY(1, kExprF64UConvertI64);
2434 EXPECT_ARITY(1, kExprF64ConvertF32); 2379 EXPECT_ARITY(1, kExprF64ConvertF32);
2435 EXPECT_ARITY(1, kExprF64ReinterpretI64); 2380 EXPECT_ARITY(1, kExprF64ReinterpretI64);
2436 EXPECT_ARITY(1, kExprI32ReinterpretF32); 2381 EXPECT_ARITY(1, kExprI32ReinterpretF32);
2437 EXPECT_ARITY(1, kExprI64ReinterpretF64); 2382 EXPECT_ARITY(1, kExprI64ReinterpretF64);
2438 } 2383 }
2439 } // namespace wasm 2384 } // namespace wasm
2440 } // namespace internal 2385 } // namespace internal
2441 } // namespace v8 2386 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698