Skip to content

Commit 57f1772

Browse files
rakudramaCommit Queue
authored andcommitted
[dart2js] Test for complex condition strengthening
Bug: #26835 #28330 Change-Id: Ic3bc05f1b5525e58173c335c5f3f4f91dd09e2f3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417329 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Stephen Adams <[email protected]>
1 parent 05b2e7b commit 57f1772

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright (c) 2025, 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+
// Examples where primitive checks should be removed.
6+
//
7+
// In all these examples, the loop bound `a + b + c + d` should be hoisted out
8+
// of the loop.
9+
10+
/*member: test1:function(a, b, c, d) {
11+
var t1, s, i;
12+
if (a == null || b == null || c == null || d == null)
13+
return 0;
14+
if (typeof a !== "number")
15+
return a.$add();
16+
if (typeof b !== "number")
17+
return A.iae(b);
18+
if (typeof c !== "number")
19+
return A.iae(c);
20+
t1 = a + b + c + d;
21+
s = 0;
22+
i = 1;
23+
for (; i <= t1; ++i)
24+
s += i;
25+
return s;
26+
}*/
27+
int test1(int? a, int? b, int? c, int? d) {
28+
if (a == null || b == null || c == null || d == null) return 0;
29+
int s = 0;
30+
for (int i = 1; i <= a + b + c + d; i++) s += i;
31+
return s;
32+
}
33+
34+
/*member: test2:function(a, b, c, d) {
35+
var t1, s, i;
36+
if (!A._isInt(a) || !A._isInt(b) || !A._isInt(c) || !A._isInt(d))
37+
return 0;
38+
if (typeof a !== "number")
39+
return a.$add();
40+
if (typeof b !== "number")
41+
return A.iae(b);
42+
if (typeof c !== "number")
43+
return A.iae(c);
44+
t1 = a + b + c + d;
45+
s = 0;
46+
i = 1;
47+
for (; i <= t1; ++i)
48+
s += i;
49+
return s;
50+
}*/
51+
int test2(int? a, int? b, int? c, int? d) {
52+
if (a is! int || b is! int || c is! int || d is! int) return 0;
53+
int s = 0;
54+
for (int i = 1; i <= a + b + c + d; i++) s += i;
55+
return s;
56+
}
57+
58+
/*member: test3:function(a, b, c, d) {
59+
var t1, i, s = 0;
60+
if (a != null && b != null && c != null && d != null) {
61+
if (typeof a !== "number")
62+
return a.$add();
63+
if (typeof b !== "number")
64+
return A.iae(b);
65+
if (typeof c !== "number")
66+
return A.iae(c);
67+
t1 = a + b + c + d;
68+
i = 1;
69+
for (; i <= t1; ++i)
70+
s += i;
71+
}
72+
return s;
73+
}*/
74+
int test3(int? a, int? b, int? c, int? d) {
75+
int s = 0;
76+
if (a != null && b != null && c != null && d != null) {
77+
for (int i = 1; i <= a + b + c + d; i++) s += i;
78+
}
79+
return s;
80+
}
81+
82+
/*member: test4:function(a, b, c, d) {
83+
var t1, i, s = 0;
84+
if (A._isInt(a) && A._isInt(b) && A._isInt(c) && A._isInt(d)) {
85+
if (typeof a !== "number")
86+
return a.$add();
87+
if (typeof b !== "number")
88+
return A.iae(b);
89+
if (typeof c !== "number")
90+
return A.iae(c);
91+
t1 = a + b + c + d;
92+
i = 1;
93+
for (; i <= t1; ++i)
94+
s += i;
95+
}
96+
return s;
97+
}*/
98+
int test4(int? a, int? b, int? c, int? d) {
99+
int s = 0;
100+
if (a is int && b is int && c is int && d is int) {
101+
for (int i = 1; i <= a + b + c + d; i++) s += i;
102+
}
103+
return s;
104+
}
105+
106+
/*member: main:ignore*/
107+
main() {
108+
for (final a in [null, -1, 2]) {
109+
for (final b in [null, -1, 2]) {
110+
for (final c in [null, -1, 2]) {
111+
for (final d in [null, -1, 2]) {
112+
print(test1(a, b, c, d));
113+
print(test2(a, b, c, d));
114+
print(test3(a, b, c, d));
115+
print(test4(a, b, c, d));
116+
}
117+
}
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)