[clang-tidy][modernize-use-starts-ends-with] Fix operator rewriting false negative...
[llvm-project.git] / clang / test / CoverageMapping / terminate-statements.cpp
blob0067185fee8e6b5b425862b20f394aec8e6f616a
1 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name terminate-statements.cpp -I %S/Inputs %s | FileCheck %s
3 int f1() {
4 return 0;
5 return 0; // CHECK: Gap,File 0, [[@LINE-1]]:12 -> [[@LINE]]:3 = 0
8 int f2(int i) {
9 if (i)
10 return 0;
11 else
12 ; // CHECK: Gap,File 0, [[@LINE]]:6 -> [[@LINE+1]]:3 = (#0 - #1)
13 return 1; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
16 int f3() {
17 for (int a = 1; a < 9; a--)
18 return a; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = (#0 - #1)
19 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
22 int f4(int i) {
23 while (i > 0) {
24 i++;
25 return i;
26 } // CHECK: File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #1)
27 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
30 int f5(int i) {
31 do {
32 return i;
33 } while (i > 0); // CHECK: Gap,File 0, [[@LINE]]:19 -> [[@LINE+1]]:3 = (0 - #1)
34 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (0 - #1)
37 int f6() {
38 int arr[] = {1, 2, 3, 4};
39 for (int i : arr) {
40 return i;
41 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #1)
42 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
45 int f7() {
48 return 0;
50 return 0; // CHECK: Gap,File 0, [[@LINE-1]]:6 -> [[@LINE]]:5 = 0
52 return 0; // CHECK: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE]]:3 = 0
55 int f8(int i) {
56 if (i == 1)
57 return 1; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = (#0 - #1)
58 if (i == 2) // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+5]]:2 = (#0 - #1)
59 return 2; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = ((#0 - #1) - #2)
60 if (i == 3) // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:2 = ((#0 - #1) - #2)
61 return 3; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = (((#0 - #1) - #2) - #3)
62 return 4; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (((#0 - #1) - #2) - #3)
65 int f9(int i) {
66 if (i == 1)
67 return 1; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:8 = (#0 - #1)
68 else if (i == 2) // CHECK-NEXT: File 0, [[@LINE]]:8 -> [[@LINE+1]]:13 = (#0 - #1)
69 return 2; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = ((#0 - #1) - #2)
70 return 3; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = ((#0 - #1) - #2)
73 int f10(int i) {
74 if (i == 1) {
75 return 0;
76 if (i == 2) // CHECK: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE]]:5 = 0
77 return 0;
78 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = ((#0 - #1) - #2)
79 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = ((#0 - #1) - #2)
82 int f11(int i) {
83 if (i == 1)
84 i = 2;
85 else
86 return 0; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:3 = #1
87 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = #1
90 int f12(int i) {
91 int x = 1;
92 if (x == 1) {
93 if (x == 1) {
94 return 0;
96 } else if (x == 2) {
97 x = 2;
98 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #2)
99 return 1; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #2)
102 int f13(int i) {
103 if (i == 1) {
104 return 0; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:5 = 0
105 if (i == 2) { // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+3]]:4 = 0
106 i++;
108 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #1)
109 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
112 int f14(int i) {
113 while (i == 0) {
114 while (i < 10) {
115 i++;
116 return 0;
118 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #2)
119 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #2)
122 int f15(int i) {
123 while (i == 0) {
124 return 0; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+1]]:5 = 0
125 while (i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+3]]:4 = 0
126 i++;
128 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#0 - #1)
129 return 0; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:11 = (#0 - #1)
132 int f16(int i) {
133 while (i == 0) {
134 break;
135 return 0;
137 return 0; // CHECK-NOT: Gap,File 0, [[@LINE-1]]
140 #define IF if
141 #define STMT(S) S
143 // CHECK-LABEL: _Z3fooi:
144 void foo(int x) {
145 if (x == 0) {
146 return;
147 } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
148 //< Don't complete the last deferred region in a decl, even though it may
149 //< leave some whitespace marked with the same counter as the final return.
152 // CHECK-LABEL: _Z4foooi:
153 void fooo(int x) {
154 if (x == 0) {
155 return;
156 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
158 if (x == 1) {
159 return;
160 } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
164 // CHECK-LABEL: _Z3bazv:
165 void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2
166 return; // CHECK-NOT: File
169 // CHECK-LABEL: _Z4maazv:
170 void maaz() {
171 if (true)
172 return; // CHECK: Gap,File 0, [[@LINE]]:12
173 else
174 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
177 // CHECK-LABEL: _Z5maaazv:
178 void maaaz() {
179 if (true) {
180 return;
181 } else { // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10
182 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
186 // CHECK-LABEL: _Z3bari:
187 void bar(int x) {
188 IF (x)
189 return; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:3 = (#0 - #1)
191 IF (!x)
192 return; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
194 foo(x);
197 // CHECK-LABEL: _Z4quuxi:
198 void quux(int x) {
199 STMT(
200 if (x == 0)
201 return;)
203 // CHECK: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+2]]:3 = (#0 - #1)
205 if (x == 1)
206 STMT(return;)
208 // CHECK: Gap,File 0, [[@LINE-2]]:18 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
210 STMT(
211 if (x == 2)
212 return;
214 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
216 if (x == 3)
217 return;
221 // CHECK-LABEL: _Z8weird_ifv:
222 void weird_if() {
223 int i = 0;
225 if (false)
226 return; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:3 = (#0 - #1)
228 if (false)
229 i++;
231 if (i + 100 > 0) { // CHECK: [[@LINE]]:20 -> [[@LINE+6]]:4 = #3
232 if (false) // CHECK: [[@LINE+1]]:7 -> [[@LINE+1]]:13 = #4
233 return; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:5 = (#3 - #4)
234 // CHECK: [[@LINE+1]]:5 -> [[@LINE+1]]:11 = (#3 - #4)
235 return;
237 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = ((#0 - #1) - #3)
239 if (false)
240 return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
243 // CHECK-LABEL: _Z8for_loopv:
244 void for_loop() {
245 if (false)
246 return; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:3 = (#0 - #1)
248 for (int i = 0; i < 10; ++i) {
249 if (i % 2 == 0)
250 continue; // CHECK: Gap,File 0, [[@LINE]]:16 -> [[@LINE+2]]:5 = (#2 - #3)
252 if (i % 5 == 0)
253 break; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = ((#2 - #3) - #4)
255 int x = i; // CHECK: [[@LINE]]:5 -> [[@LINE+1]]:11 = ((#2 - #3) - #4)
256 return; // CHECK-NOT: [[@LINE]]:11 -> [[@LINE+2]]
261 struct Error {};
263 // CHECK-LABEL: _Z10while_loopv:
264 void while_loop() {
265 if (false)
266 return; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:3 = (#0 - #1)
268 int x = 0;
269 while (++x < 10) {
270 if (x == 1)
271 continue; // CHECK: Gap,File 0, [[@LINE]]:16 -> [[@LINE+2]]:5 = (#2 - #3)
273 while (++x < 4) {
274 if (x == 3)
275 break; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:7 = (#4 - #5)
277 while (++x < 5) {}
280 if (x == 0)
281 throw Error(); // CHECK: Gap,File 0, [[@LINE]]:21 -> [[@LINE+2]]:5 = ((#2 - #3) - #7)
283 while (++x < 9) {
284 if (x == 0)
285 break; // CHECK-NOT: [[@LINE]]:14 -> [[@LINE+2]]
291 // CHECK-LABEL: _Z5gotosv:
292 void gotos() {
293 if (false)
294 goto out; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:3 = (#0 - #1)
296 return; // CHECK: [[@LINE]]:3 -> [[@LINE]]:9 = (#0 - #1)
298 out:
299 return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8
302 // CHECK-LABEL: _Z8switchesv:
303 void switches() {
304 int x;
305 switch (x) {
306 case 0:
307 return;
308 default:
309 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
313 #include "deferred-region-helper.h"
314 // CHECK-LABEL: _Z13included_funcv:
315 // CHECK: Gap,File 0, 2:13 -> 3:5 = #1
316 // CHECK: Gap,File 0, 3:12 -> 4:3 = (#0 - #1)
318 // CHECK-LABEL: _Z7includev:
319 void include() {
320 included_func();
323 // CHECK-LABEL: _Z7ornoretv:
324 void abort() __attribute__((noreturn));
326 int ornoret(void) {
327 ( true || (abort(), 0) ); // CHECK: Gap,File 0, [[@LINE]]:28 -> [[@LINE+1]]:3 = #0
328 ( false || (abort(), 0) ); // CHECK: Gap,File 0, [[@LINE]]:29 -> [[@LINE+1]]:3 = 0
329 return 0;
332 // CHECK-LABEL: _Z17abstractcondnoretv:
333 int abstractcondnoret(void) {
334 ( true ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:33 -> [[@LINE+1]]:3 = #1
335 ( false ? void (0) : abort() ); // CHECK: Gap,File 0, [[@LINE]]:34 -> [[@LINE+1]]:3 = #2
336 ( true ? abort() : void (0) ); // CHECK: Gap,File 0, [[@LINE]]:33 -> [[@LINE+1]]:3 = (#2 - #3)
337 ( false ? abort() : void (0) ); // CHECK: Gap,File 0, [[@LINE]]:34 -> [[@LINE+1]]:3 = ((#2 - #3) - #4)
338 return 0;
341 // CHECK-LABEL: _Z13elsecondnoretv:
342 int elsecondnoret(void) {
343 if (true) {} else {
344 true ? void (0) : abort();
345 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+1]]:3 = (#1 + #2)
346 return 0;
349 int main() {
350 foo(0);
351 foo(1);
352 fooo(0);
353 fooo(1);
354 maaz();
355 maaaz();
356 baz();
357 bar(0);
358 bar(1);
359 quux(0);
360 quux(1);
361 quux(2);
362 quux(3);
363 weird_if();
364 for_loop();
365 while_loop();
366 gotos();
367 include();
368 ornoret();
369 abstractcondnoret();
370 elsecondnoret();
371 return 0;