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

Side by Side Diff: test/cctest/test-asm-validator.cc

Issue 1432423003: Fix ~ operator in asm typer, add more operator tests. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix gcc Created 5 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 | « src/typing-asm.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 "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/ast.h" 7 #include "src/ast.h"
8 #include "src/ast-expression-visitor.h" 8 #include "src/ast-expression-visitor.h"
9 #include "src/parser.h" 9 #include "src/parser.h"
10 #include "src/rewriter.h" 10 #include "src/rewriter.h"
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 } 646 }
647 CHECK_EXPR(Literal, Bounds(cache.kInt32)); 647 CHECK_EXPR(Literal, Bounds(cache.kInt32));
648 } 648 }
649 } 649 }
650 CHECK_SKIP(); 650 CHECK_SKIP();
651 } 651 }
652 CHECK_FUNC_TYPES_END 652 CHECK_FUNC_TYPES_END
653 } 653 }
654 654
655 655
656 #define TEST_COMPARE_OP(name, op) \
657 TEST(name) { \
658 CHECK_FUNC_TYPES_BEGIN("function bar() { return (0 " op \
659 " 0)|0; }\n" \
660 "function foo() { bar(); }") { \
661 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { \
662 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { \
663 CHECK_EXPR(CompareOperation, Bounds(cache.kInt32)) { \
664 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
665 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
666 } \
667 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
668 } \
669 } \
670 CHECK_SKIP(); \
671 } \
672 CHECK_FUNC_TYPES_END \
673 }
674
675
676 TEST_COMPARE_OP(EqOperator, "==")
677 TEST_COMPARE_OP(LtOperator, "<")
678 TEST_COMPARE_OP(LteOperator, "<=")
679 TEST_COMPARE_OP(GtOperator, ">")
680 TEST_COMPARE_OP(GteOperator, ">=")
681
682
683 TEST(NeqOperator) {
684 CHECK_FUNC_TYPES_BEGIN(
685 "function bar() { return (0 != 0)|0; }\n"
686 "function foo() { bar(); }") {
687 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
688 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
689 CHECK_EXPR(UnaryOperation, Bounds(cache.kInt32)) {
690 CHECK_EXPR(CompareOperation, Bounds(cache.kInt32)) {
691 CHECK_EXPR(Literal, Bounds(cache.kInt32));
692 CHECK_EXPR(Literal, Bounds(cache.kInt32));
693 }
694 }
695 CHECK_EXPR(Literal, Bounds(cache.kInt32));
696 }
697 }
698 CHECK_SKIP();
699 }
700 CHECK_FUNC_TYPES_END
701 }
702
703
704 TEST(NotOperator) {
705 CHECK_FUNC_TYPES_BEGIN(
706 "function bar() { var x = 0; return (!x)|0; }\n"
707 "function foo() { bar(); }") {
708 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
709 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) {
710 CHECK_VAR(x, Bounds(cache.kInt32));
711 CHECK_EXPR(Literal, Bounds(cache.kInt32));
712 }
713 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
714 CHECK_EXPR(UnaryOperation, Bounds(cache.kInt32)) {
715 CHECK_VAR(x, Bounds(cache.kInt32));
716 }
717 CHECK_EXPR(Literal, Bounds(cache.kInt32));
718 }
719 }
720 CHECK_SKIP();
721 }
722 CHECK_FUNC_TYPES_END
723 }
724
725
726 TEST(InvertOperator) {
727 CHECK_FUNC_TYPES_BEGIN(
728 "function bar() { var x = 0; return (~x)|0; }\n"
729 "function foo() { bar(); }") {
730 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
731 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) {
732 CHECK_VAR(x, Bounds(cache.kInt32));
733 CHECK_EXPR(Literal, Bounds(cache.kInt32));
734 }
735 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
736 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
737 CHECK_VAR(x, Bounds(cache.kInt32));
738 CHECK_EXPR(Literal, Bounds(cache.kInt32));
739 }
740 CHECK_EXPR(Literal, Bounds(cache.kInt32));
741 }
742 }
743 CHECK_SKIP();
744 }
745 CHECK_FUNC_TYPES_END
746 }
747
748
749 TEST(InvertConversion) {
750 CHECK_FUNC_TYPES_BEGIN(
751 "function bar() { var x = 0.0; return (~~x)|0; }\n"
752 "function foo() { bar(); }") {
753 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
754 CHECK_EXPR(Assignment, Bounds(cache.kFloat64)) {
755 CHECK_VAR(x, Bounds(cache.kFloat64));
756 CHECK_EXPR(Literal, Bounds(cache.kFloat64));
757 }
758 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
759 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
760 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
761 CHECK_VAR(x, Bounds(cache.kFloat64));
762 CHECK_EXPR(Literal, Bounds(cache.kInt32));
763 }
764 CHECK_EXPR(Literal, Bounds(cache.kInt32));
765 }
766 CHECK_EXPR(Literal, Bounds(cache.kInt32));
767 }
768 }
769 CHECK_SKIP();
770 }
771 CHECK_FUNC_TYPES_END
772 }
773
774
775 #define TEST_INT_BIN_OP(name, op) \
776 TEST(name) { \
777 CHECK_FUNC_TYPES_BEGIN("function bar() { var x = 0; return (x " op \
778 " 123)|0; }\n" \
779 "function foo() { bar(); }") { \
780 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { \
781 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { \
782 CHECK_VAR(x, Bounds(cache.kInt32)); \
783 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
784 } \
785 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { \
786 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { \
787 CHECK_VAR(x, Bounds(cache.kInt32)); \
788 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
789 } \
790 CHECK_EXPR(Literal, Bounds(cache.kInt32)); \
791 } \
792 } \
793 CHECK_SKIP(); \
794 } \
795 CHECK_FUNC_TYPES_END \
796 }
797
798
799 TEST_INT_BIN_OP(AndOperator, "&")
800 TEST_INT_BIN_OP(OrOperator, "|")
801 TEST_INT_BIN_OP(XorOperator, "^")
802
803
656 TEST(UnsignedCompare) { 804 TEST(UnsignedCompare) {
657 CHECK_FUNC_TYPES_BEGIN( 805 CHECK_FUNC_TYPES_BEGIN(
658 "function bar() { var x = 1; var y = 1; return ((x>>>0) < (y>>>0))|0; }\n" 806 "function bar() { var x = 1; var y = 1; return ((x>>>0) < (y>>>0))|0; }\n"
659 "function foo() { bar(); }") { 807 "function foo() { bar(); }") {
660 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { 808 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
661 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { 809 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) {
662 CHECK_VAR(x, Bounds(cache.kInt32)); 810 CHECK_VAR(x, Bounds(cache.kInt32));
663 CHECK_EXPR(Literal, Bounds(cache.kInt32)); 811 CHECK_EXPR(Literal, Bounds(cache.kInt32));
664 } 812 }
665 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) { 813 CHECK_EXPR(Assignment, Bounds(cache.kInt32)) {
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1268
1121 1269
1122 TEST(UnboundVariable) { 1270 TEST(UnboundVariable) {
1123 CHECK_FUNC_ERROR( 1271 CHECK_FUNC_ERROR(
1124 "function bar() { var x = y; }\n" 1272 "function bar() { var x = y; }\n"
1125 "function foo() { bar(); }", 1273 "function foo() { bar(); }",
1126 "asm: line 39: unbound variable\n"); 1274 "asm: line 39: unbound variable\n");
1127 } 1275 }
1128 1276
1129 1277
1278 TEST(EqStrict) {
1279 CHECK_FUNC_ERROR(
1280 "function bar() { return (0 === 0)|0; }\n"
1281 "function foo() { bar(); }",
1282 "asm: line 39: illegal comparison operator\n");
1283 }
1284
1285
1286 TEST(NeStrict) {
1287 CHECK_FUNC_ERROR(
1288 "function bar() { return (0 !== 0)|0; }\n"
1289 "function foo() { bar(); }",
1290 "asm: line 39: illegal comparison operator\n");
1291 }
1292
1293
1294 TEST(InstanceOf) {
1295 CHECK_FUNC_ERROR(
1296 "function bar() { return (0 instanceof 0)|0; }\n"
1297 "function foo() { bar(); }",
1298 "asm: line 39: illegal comparison operator\n");
1299 }
1300
1301
1302 TEST(InOperator) {
1303 CHECK_FUNC_ERROR(
1304 "function bar() { return (0 in 0)|0; }\n"
1305 "function foo() { bar(); }",
1306 "asm: line 39: illegal comparison operator\n");
1307 }
1308
1309
1310 TEST(LogicalAndOperator) {
1311 CHECK_FUNC_ERROR(
1312 "function bar() { return (0 && 0)|0; }\n"
1313 "function foo() { bar(); }",
1314 "asm: line 39: illegal logical operator\n");
1315 }
1316
1317
1318 TEST(LogicalOrOperator) {
1319 CHECK_FUNC_ERROR(
1320 "function bar() { return (0 || 0)|0; }\n"
1321 "function foo() { bar(); }",
1322 "asm: line 39: illegal logical operator\n");
1323 }
1324
1325
1326 TEST(BadLiteral) {
1327 CHECK_FUNC_ERROR(
1328 "function bar() { return true | 0; }\n"
1329 "function foo() { bar(); }",
1330 "asm: line 39: illegal literal\n");
1331 }
1332
1333
1130 TEST(ForeignFunction) { 1334 TEST(ForeignFunction) {
1131 CHECK_FUNC_TYPES_BEGIN( 1335 CHECK_FUNC_TYPES_BEGIN(
1132 "var baz = foreign.baz;\n" 1336 "var baz = foreign.baz;\n"
1133 "function bar() { return baz(1, 2)|0; }\n" 1337 "function bar() { return baz(1, 2)|0; }\n"
1134 "function foo() { bar(); }") { 1338 "function foo() { bar(); }") {
1135 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { 1339 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) {
1136 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) { 1340 CHECK_EXPR(BinaryOperation, Bounds(cache.kInt32)) {
1137 CHECK_EXPR(Call, Bounds(Type::Number(zone))) { 1341 CHECK_EXPR(Call, Bounds(Type::Number(zone))) {
1138 CHECK_VAR(baz, Bounds(Type::Any())); 1342 CHECK_VAR(baz, Bounds(Type::Any()));
1139 CHECK_EXPR(Literal, Bounds(cache.kInt32)); 1343 CHECK_EXPR(Literal, Bounds(cache.kInt32));
(...skipping 24 matching lines...) Expand all
1164 "return {foo: foo, bar: 1};" 1368 "return {foo: foo, bar: 1};"
1165 "}\n"; 1369 "}\n";
1166 1370
1167 v8::V8::Initialize(); 1371 v8::V8::Initialize();
1168 HandleAndZoneScope handles; 1372 HandleAndZoneScope handles;
1169 Zone* zone = handles.main_zone(); 1373 Zone* zone = handles.main_zone();
1170 ZoneVector<ExpressionTypeEntry> types(zone); 1374 ZoneVector<ExpressionTypeEntry> types(zone);
1171 CHECK_EQ("asm: line 40: non-function in function table\n", 1375 CHECK_EQ("asm: line 40: non-function in function table\n",
1172 Validate(zone, test_function, &types)); 1376 Validate(zone, test_function, &types));
1173 } 1377 }
OLDNEW
« no previous file with comments | « src/typing-asm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698