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

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

Issue 2670673002: [wasm] Implement polymorphic checking, matching the reference interpreter. (Closed)
Patch Set: Fix test-run-simd Created 3 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/mjsunit/wasm/unreachable-validation.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/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/common/wasm/test-signatures.h" 9 #include "test/common/wasm/test-signatures.h"
10 10
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 } 664 }
665 665
666 TEST_F(FunctionBodyDecoderTest, Block3_continue) { 666 TEST_F(FunctionBodyDecoderTest, Block3_continue) {
667 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); 667 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0))));
668 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); 668 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1))));
669 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); 669 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2))));
670 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); 670 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3))));
671 } 671 }
672 672
673 TEST_F(FunctionBodyDecoderTest, NestedBlock_return) { 673 TEST_F(FunctionBodyDecoderTest, NestedBlock_return) {
674 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); 674 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))), WASM_ZERO);
675 } 675 }
676 676
677 TEST_F(FunctionBodyDecoderTest, BlockBrBinop) { 677 TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
678 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))), 678 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))),
679 WASM_I32V_1(2))); 679 WASM_I32V_1(2)));
680 } 680 }
681 681
682 TEST_F(FunctionBodyDecoderTest, If_empty1) { 682 TEST_F(FunctionBodyDecoderTest, If_empty1) {
683 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); 683 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd);
684 } 684 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 } 854 }
855 855
856 TEST_F(FunctionBodyDecoderTest, Loop2_continue) { 856 TEST_F(FunctionBodyDecoderTest, Loop2_continue) {
857 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); 857 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0)));
858 } 858 }
859 859
860 TEST_F(FunctionBodyDecoderTest, Loop2_break) { 860 TEST_F(FunctionBodyDecoderTest, Loop2_break) {
861 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); 861 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1)));
862 } 862 }
863 863
864 TEST_F(FunctionBodyDecoderTest, InfiniteLoop) { 864 TEST_F(FunctionBodyDecoderTest, InfiniteLoop1) {
865 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0))); 865 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO);
866 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO))); 866 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0)), WASM_ZERO);
867 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BRV(1, WASM_ZERO)));
868 }
869
870 TEST_F(FunctionBodyDecoderTest, InfiniteLoop2) {
871 EXPECT_FAILURE(i_i, WASM_LOOP(WASM_BR(0), WASM_ZERO), WASM_ZERO);
867 } 872 }
868 873
869 TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) { 874 TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) {
870 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP)); 875 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_BR(0), WASM_NOP));
871 } 876 }
872 877
873 TEST_F(FunctionBodyDecoderTest, LoopType) { 878 TEST_F(FunctionBodyDecoderTest, LoopType) {
874 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); 879 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0)));
875 EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); 880 EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0)));
876 EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); 881 EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0)));
877 EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); 882 EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0)));
878 } 883 }
879 884
880 TEST_F(FunctionBodyDecoderTest, LoopType_void) { 885 TEST_F(FunctionBodyDecoderTest, LoopType_void) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 TEST_F(FunctionBodyDecoderTest, ReturnVoid3) { 924 TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
920 EXPECT_FAILURE(v_v, kExprI32Const, 0); 925 EXPECT_FAILURE(v_v, kExprI32Const, 0);
921 EXPECT_FAILURE(v_v, kExprI64Const, 0); 926 EXPECT_FAILURE(v_v, kExprI64Const, 0);
922 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); 927 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0);
923 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 928 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
924 929
925 EXPECT_FAILURE(v_i, kExprGetLocal, 0); 930 EXPECT_FAILURE(v_i, kExprGetLocal, 0);
926 } 931 }
927 932
928 TEST_F(FunctionBodyDecoderTest, Unreachable1) { 933 TEST_F(FunctionBodyDecoderTest, Unreachable1) {
929 EXPECT_VERIFIES(v_v, kExprUnreachable); 934 EXPECT_VERIFIES(v_v, WASM_UNREACHABLE);
930 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); 935 EXPECT_VERIFIES(v_v, WASM_UNREACHABLE, WASM_UNREACHABLE);
931 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); 936 EXPECT_VERIFIES(i_i, WASM_UNREACHABLE, WASM_ZERO);
932 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO));
933 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
934 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
935 } 937 }
936 938
937 TEST_F(FunctionBodyDecoderTest, Unreachable_binop) { 939 TEST_F(FunctionBodyDecoderTest, Unreachable2) {
940 EXPECT_FAILURE(v_v, B2(WASM_UNREACHABLE, WASM_ZERO));
941 EXPECT_FAILURE(v_v, B2(WASM_BR(0), WASM_ZERO));
942 }
943
944 TEST_F(FunctionBodyDecoderTest, UnreachableLoop1) {
945 EXPECT_FAILURE(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
946 EXPECT_FAILURE(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
947 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_NOP));
948 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_NOP));
949 }
950
951 TEST_F(FunctionBodyDecoderTest, Unreachable_binop1) {
938 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); 952 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
939 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); 953 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
940 } 954 }
941 955
942 TEST_F(FunctionBodyDecoderTest, Unreachable_select) { 956 TEST_F(FunctionBodyDecoderTest, Unreachable_binop2) {
957 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_F32(0.0), WASM_UNREACHABLE));
958 EXPECT_FAILURE(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_F32(0.0)));
959 }
960
961 TEST_F(FunctionBodyDecoderTest, Unreachable_select1) {
943 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); 962 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
944 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); 963 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO));
945 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); 964 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE));
946 } 965 }
947 966
967 TEST_F(FunctionBodyDecoderTest, Unreachable_select2) {
968 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_F32(0.0), WASM_UNREACHABLE, WASM_ZERO));
969 EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_F32(0.0), WASM_ZERO));
970 EXPECT_FAILURE(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_F32(0.0)));
971 }
972
948 TEST_F(FunctionBodyDecoderTest, If1) { 973 TEST_F(FunctionBodyDecoderTest, If1) {
949 EXPECT_VERIFIES( 974 EXPECT_VERIFIES(
950 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8))); 975 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8)));
951 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), 976 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9),
952 WASM_GET_LOCAL(0))); 977 WASM_GET_LOCAL(0)));
953 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), 978 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
954 WASM_I32V_1(8))); 979 WASM_I32V_1(8)));
955 } 980 }
956 981
957 TEST_F(FunctionBodyDecoderTest, If_off_end) { 982 TEST_F(FunctionBodyDecoderTest, If_off_end) {
(...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 byte code[] = { 2151 byte code[] = {
2127 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; 2152 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
2128 if (depth < 2) { 2153 if (depth < 2) {
2129 EXPECT_VERIFIES_C(v_i, code); 2154 EXPECT_VERIFIES_C(v_i, code);
2130 } else { 2155 } else {
2131 EXPECT_FAILURE_C(v_i, code); 2156 EXPECT_FAILURE_C(v_i, code);
2132 } 2157 }
2133 } 2158 }
2134 } 2159 }
2135 2160
2136 TEST_F(FunctionBodyDecoderTest, BrUnreachable) { 2161 TEST_F(FunctionBodyDecoderTest, BrUnreachable1) {
2137 static byte code[] = {WASM_GET_LOCAL(0), kExprBrTable, 0, 2162 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0));
2138 BR_TARGET(0), kExprSetLocal, 0}; 2163 }
2139 EXPECT_VERIFIES_C(v_i, code); 2164
2165 TEST_F(FunctionBodyDecoderTest, BrUnreachable2) {
2166 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0),
2167 WASM_NOP);
2168 EXPECT_FAILURE(v_i, WASM_GET_LOCAL(0), kExprBrTable, 0, BR_TARGET(0),
2169 WASM_ZERO);
2140 } 2170 }
2141 2171
2142 TEST_F(FunctionBodyDecoderTest, Brv1) { 2172 TEST_F(FunctionBodyDecoderTest, Brv1) {
2143 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); 2173 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO)));
2144 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO)))); 2174 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP_I(WASM_BRV(2, WASM_ZERO))));
2145 } 2175 }
2146 2176
2147 TEST_F(FunctionBodyDecoderTest, Brv1_type) { 2177 TEST_F(FunctionBodyDecoderTest, Brv1_type) {
2148 EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); 2178 EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0))));
2149 EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); 2179 EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0))));
2150 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); 2180 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0))));
2151 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); 2181 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0))));
2152 } 2182 }
2153 2183
2154 TEST_F(FunctionBodyDecoderTest, Brv1_type_n) { 2184 TEST_F(FunctionBodyDecoderTest, Brv1_type_n) {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2777 iter.next(); 2807 iter.next();
2778 EXPECT_TRUE(iter.has_next()); 2808 EXPECT_TRUE(iter.has_next());
2779 EXPECT_EQ(kExprI32Const, iter.current()); 2809 EXPECT_EQ(kExprI32Const, iter.current());
2780 iter.next(); 2810 iter.next();
2781 EXPECT_FALSE(iter.has_next()); 2811 EXPECT_FALSE(iter.has_next());
2782 } 2812 }
2783 2813
2784 } // namespace wasm 2814 } // namespace wasm
2785 } // namespace internal 2815 } // namespace internal
2786 } // namespace v8 2816 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/unreachable-validation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698