[NFC][RemoveDIs] Prefer iterators over inst-pointers in InstCombine
[llvm-project.git] / llvm / test / tools / llvm-cov / Inputs / branch-c-general.c
blob2e7e773e5c3941d1e260d5b1943a5b3b3c595079
1 // Test visualization of general branch constructs in C.
7 void simple_loops() {
8 int i;
9 for (i = 0; i < 100; ++i) {
11 while (i > 0)
12 i--;
13 do {} while (i++ < 75);
17 void conditionals() {
18 for (int i = 0; i < 100; ++i) {
19 if (i % 2) {
20 if (i) {}
21 } else if (i % 3) {
22 if (i) {}
23 } else {
24 if (i) {}
27 if (1 && i) {}
28 if (0 || i) {}
33 void early_exits() {
34 int i = 0;
36 if (i) {}
38 while (i < 100) {
39 i++;
40 if (i > 50)
41 break;
42 if (i % 2)
43 continue;
46 if (i) {}
48 do {
49 if (i > 75)
50 return;
51 else
52 i++;
53 } while (i < 100);
55 if (i) {}
59 void jumps() {
60 int i;
62 for (i = 0; i < 2; ++i) {
63 goto outofloop;
64 // Never reached -> no weights
65 if (i) {}
68 outofloop:
69 if (i) {}
71 goto loop1;
73 while (i) {
74 loop1:
75 if (i) {}
78 goto loop2;
79 first:
80 second:
81 third:
82 i++;
83 if (i < 3)
84 goto loop2;
86 while (i < 3) {
87 loop2:
88 switch (i) {
89 case 0:
90 goto first;
91 case 1:
92 goto second;
93 case 2:
94 goto third;
98 for (i = 0; i < 10; ++i) {
99 goto withinloop;
100 // never reached -> no weights
101 if (i) {}
102 withinloop:
103 if (i) {}
108 void switches() {
109 static int weights[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};
111 // No cases -> no weights
112 switch (weights[0]) {
113 default:
114 break;
117 for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) {
118 switch (i[weights]) {
119 case 1:
120 if (i) {}
121 // fallthrough
122 case 2:
123 if (i) {}
124 break;
125 case 3:
126 if (i) {}
127 continue;
128 case 4:
129 if (i) {}
130 switch (i) {
131 case 6 ... 9:
132 if (i) {}
133 continue;
136 default:
137 if (i == len - 1)
138 return;
142 // Never reached -> no weights
143 if (weights[0]) {}
147 void big_switch() {
148 for (int i = 0; i < 32; ++i) {
149 switch (1 << i) {
150 case (1 << 0):
151 if (i) {}
152 // fallthrough
153 case (1 << 1):
154 if (i) {}
155 break;
156 case (1 << 2) ... (1 << 12):
157 if (i) {}
158 break;
159 // The branch for the large case range above appears after the case body.
161 case (1 << 13):
162 if (i) {}
163 break;
164 case (1 << 14) ... (1 << 28):
165 if (i) {}
166 break;
167 // The branch for the large case range above appears after the case body.
169 case (1 << 29) ... ((1 << 29) + 1):
170 if (i) {}
171 break;
172 default:
173 if (i) {}
174 break;
180 void boolean_operators() {
181 int v;
182 for (int i = 0; i < 100; ++i) {
183 v = i % 3 || i;
185 v = i % 3 && i;
187 v = i % 3 || i % 2 || i;
189 v = i % 2 && i % 3 && i;
194 void boolop_loops() {
195 int i = 100;
197 while (i && i > 50)
198 i--;
200 while ((i % 2) || (i > 0))
201 i--;
203 for (i = 100; i && i > 50; --i);
205 for (; (i % 2) || (i > 0); --i);
209 void conditional_operator() {
210 int i = 100;
212 int j = i < 50 ? i : 1;
214 int k = i ?: 0;
218 void do_fallthrough() {
219 for (int i = 0; i < 10; ++i) {
220 int j = 0;
221 do {
222 // The number of exits out of this do-loop via the break statement
223 // exceeds the counter value for the loop (which does not include the
224 // fallthrough count). Make sure that does not violate any assertions.
225 if (i < 8) break;
226 j++;
227 } while (j < 2);
231 static void static_func() {
232 for (int i = 0; i < 10; ++i) {
245 int main(int argc, const char *argv[]) {
246 simple_loops();
247 conditionals();
248 early_exits();
249 jumps();
250 switches();
251 big_switch();
252 boolean_operators();
253 boolop_loops();
254 conditional_operator();
255 do_fallthrough();
256 static_func();
257 extern void __llvm_profile_write_file();
258 __llvm_profile_write_file();
259 return 0;