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

Side by Side Diff: tests/language/range_analysis3_test.dart

Issue 369833005: Fix range-analysis. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/value_range_analyzer.dart ('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
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 confuse(x) {
8 if (new DateTime.now().millisecondsSinceEpoch == 0) {
9 return confuse(x + 1);
10 } else if (new DateTime.now().millisecondsSinceEpoch == 0) {
11 return confuse(x - 1);
12 }
13 return x;
14 }
15
16 test1() {
17 int x = 0;
18 // Give x a range of -1 to 0.
19 if (confuse(0) == 1) x = -1;
20
21 int y = 0;
22 // Give y a range of 0 to 1.
23 if (confuse(0) == 1) y = 1;
24
25 var zero = 0;
26
27 var status = "bad";
28 if (x < zero) {
29 Expect.fail("unreachable");
30 } else {
31 // Dart2js must not conclude that zero has a range of [-1, 0].
32 if (y <= zero) {
33 status = "good";
34 }
35 }
36 Expect.equals("good", status);
37 }
38
39 test2() {
40 int x = 0;
41 // Give x a range of -1 to 0.
42 if (confuse(0) == 1) x = -1;
43
44 int y = 0;
45 // Give y a range of -1 to 1.
46 if (confuse(0) == 1) y = 1;
47 if (confuse(1) == 2) y = -1;
48
49 var status = "good";
50 if (x < y) {
51 Expect.fail("unreachable");
52 } else {
53 // Dart2js must not conclude that y has a range of [-1, -1].
54 if (y == -1) {
55 status = "bad";
56 }
57 }
58 Expect.equals("good", status);
59 }
60
61 test3a() {
62 int x = 0;
63 // Give x a range of -1 to 1.
64 if (confuse(0) == 1) x = -1;
65 if (confuse(1) == 2) x = 1;
66
67 int y = 0;
68 // Give y a range of -1 to 1.
69 if (confuse(0) == 1) y = 1;
70 if (confuse(1) == 2) y = -1;
71
72 var status = "good";
73 if (x < y) {
74 Expect.fail("unreachable");
75 } else {
76 // Test that the range-analysis does not lose a value.
77 if (x <= -1) status = "bad";
78 if (x >= 1) status = "bad";
79 if (x < 0) status = "bad";
80 if (x > 0) status = "bad";
81 if (-1 >= x) status = "bad";
82 if (1 <= x) status = "bad";
83 if (0 > x) status = "bad";
84 if (0 < x) status = "bad";
85 if (y <= -1) status = "bad";
86 if (y >= 1) status = "bad";
87 if (y < 0) status = "bad";
88 if (y > 0) status = "bad";
89 if (-1 >= y) status = "bad";
90 if (1 <= y) status = "bad";
91 if (0 > y) status = "bad";
92 if (0 < y) status = "bad";
93 }
94 Expect.equals("good", status);
95 }
96
97 test3b() {
98 int x = 0;
99 // Give x a range of -2 to 0.
100 if (confuse(0) == 1) x = -2;
101
102 int y = 0;
103 // Give y a range of -1 to 1.
104 if (confuse(0) == 1) y = 1;
105 if (confuse(1) == 2) y = -1;
106
107 var status = "good";
108 if (x < y) {
109 Expect.fail("unreachable");
110 } else {
111 // Test that the range-analysis does not lose a value.
112 if (x <= -1) status = "bad";
113 if (x >= 1) status = "bad";
114 if (x < 0) status = "bad";
115 if (x > 0) status = "bad";
116 if (-1 >= x) status = "bad";
117 if (1 <= x) status = "bad";
118 if (0 > x) status = "bad";
119 if (0 < x) status = "bad";
120 if (y <= -1) status = "bad";
121 if (y >= 1) status = "bad";
122 if (y < 0) status = "bad";
123 if (y > 0) status = "bad";
124 if (-1 >= y) status = "bad";
125 if (1 <= y) status = "bad";
126 if (0 > y) status = "bad";
127 if (0 < y) status = "bad";
128 }
129 Expect.equals("good", status);
130 }
131
132 test4a() {
133 int x = -1;
134 // Give x a range of -1 to 1.
135 if (confuse(0) == 1) x = 1;
136
137 int y = 0;
138 // Give y a range of -1 to 1.
139 if (confuse(0) == 1) y = 1;
140 if (confuse(1) == 2) y = -1;
141
142 var status = "good";
143 if (x < y) {
144 // Test that the range-analysis does not lose a value.
145 if (x <= -2) status = "bad";
146 if (x >= 0) status = "bad";
147 if (x < -1) status = "bad";
148 if (x > -1) status = "bad";
149 if (-2 >= x) status = "bad";
150 if (0 <= x) status = "bad";
151 if (-1 > x) status = "bad";
152 if (-1 < x) status = "bad";
153 if (y <= -1) status = "bad";
154 if (y >= 1) status = "bad";
155 if (y < 0) status = "bad";
156 if (y > 0) status = "bad";
157 if (-1 >= y) status = "bad";
158 if (1 <= y) status = "bad";
159 if (0 > y) status = "bad";
160 if (0 < y) status = "bad";
161 } else {
162 Expect.fail("unreachable");
163 }
164 Expect.equals("good", status);
165 }
166
167 test4b() {
168 int x = -1;
169 // Give x a range of -2 to 0.
170 if (confuse(0) == 1) x = -2;
171 if (confuse(1) == 2) x = 0;
172
173 int y = 0;
174 // Give y a range of -1 to 1.
175 if (confuse(0) == 1) y = 1;
176 if (confuse(1) == 2) y = -1;
177
178 var status = "good";
179 if (x < y) {
180 // Test that the range-analysis does not lose a value.
181 if (x <= -2) status = "bad";
182 if (x >= 0) status = "bad";
183 if (x < -1) status = "bad";
184 if (x > -1) status = "bad";
185 if (-2 >= x) status = "bad";
186 if (0 <= x) status = "bad";
187 if (-1 > x) status = "bad";
188 if (-1 < x) status = "bad";
189 if (y <= -1) status = "bad";
190 if (y >= 1) status = "bad";
191 if (y < 0) status = "bad";
192 if (y > 0) status = "bad";
193 if (-1 >= y) status = "bad";
194 if (1 <= y) status = "bad";
195 if (0 > y) status = "bad";
196 if (0 < y) status = "bad";
197 } else {
198 Expect.fail("unreachable");
199 }
200 Expect.equals("good", status);
201 }
202
203 main() {
204 test1();
205 test2();
206 test3a();
207 test3b();
208 test4a();
209 test4b();
210 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/ssa/value_range_analyzer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698