• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*#pragma settings SkVMDebugTrace*/
2
3uniform half4 colorRed, colorGreen;
4
5// Should return 5
6const int kZero = 0;
7int return_loop(int five) {
8    for (int i = kZero; i < 10; ++i) {
9        if (i == five) { return i; }
10    }
11    return 0;
12}
13
14// Should return 35
15const int kTen = kZero + 10;
16int continue_loop(int five) {
17    int sum = 0;
18    for (int i = 0; i < kTen; ++i) {
19        if (i < five) { continue; }
20        sum += i;
21    }
22    return sum;
23}
24
25// Should return 15
26int break_loop(int five) {
27    int sum = 0;
28    const int kOne = 1;
29    for (int i = 0; i < 10; i += kOne) {
30        if (i > five) { break; }
31        sum += i;
32    }
33    return sum;
34}
35
36bool loop_operator_le() {
37    // These loops are inside-out and execute zero times.
38    for (int i = 3; i <= 1; ++i) { return false; }
39    for (int i = 3; i <= 1; --i) { return false; }
40
41    int4 result = int4(9);
42    for (int i = 1; i <= 3; ++i) {
43        result = int4(result.yzw, i);
44    }
45    return result == int4(9, 1, 2, 3);
46}
47
48bool loop_operator_lt() {
49    // These loops are inside-out and execute zero times.
50    for (int i = 4; i < 1; ++i) { return false; }
51    for (int i = 4; i < 1; --i) { return false; }
52
53    int4 result = int4(9);
54    for (int i = 1; i < 4; ++i) {
55        result = int4(result.yzw, i);
56    }
57    return result == int4(9, 1, 2, 3);
58}
59
60bool loop_operator_ge() {
61    // These loops are inside-out and execute zero times.
62    for (int i = 1; i >= 3; ++i) { return false; }
63    for (int i = 1; i >= 3; --i) { return false; }
64
65    int4 result = int4(9);
66    for (int i = 3; i >= 1; --i) {
67        result = int4(result.yzw, i);
68    }
69    return result == int4(9, 3, 2, 1);
70}
71
72bool loop_operator_gt() {
73    // These loops are inside-out and execute zero times.
74    for (int i = 0; i > 3; ++i) { return false; }
75    for (int i = 0; i > 3; --i) { return false; }
76
77    int4 result = int4(9);
78    for (int i = 3; i > 0; --i) {
79        result = int4(result.yzw, i);
80    }
81    return result == int4(9, 3, 2, 1);
82}
83
84bool loop_operator_ne() {
85    // This loop executes zero times.
86    for (int i = 1; i != 1; ++i) { return false; }
87
88    int4 result = int4(9);
89    for (int i = 1; i != 4; ++i) {
90        result = int4(result.yzw, i);
91    }
92    return result == int4(9, 1, 2, 3);
93}
94
95bool loop_operator_eq() {
96    // This loop executes zero times.
97    for (int i = 1; i == 2; ++i) { return false; }
98
99    int4 result = int4(9);
100    for (int i = 1; i == 1; ++i) {
101        result = int4(result.yzw, i);
102    }
103    return result == int4(9, 9, 9, 1);
104}
105
106half4 main(float2 pos) {
107    int five = int(clamp(pos.x, colorGreen.g, colorGreen.a)) * 5;
108    return (return_loop(five) == 5 && continue_loop(five) == 35 && break_loop(five) == 15 &&
109            loop_operator_le() && loop_operator_lt() &&
110            loop_operator_ge() && loop_operator_gt() &&
111            loop_operator_eq() && loop_operator_ne()) ? colorGreen : colorRed;
112}
113