blob: 41b5e6be8c277f3bd5f82da1c883b0a5cf4c316a [file] [log] [blame]
Vedant Kumar747b0e22017-09-08 18:44:56 +00001// RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -fexceptions -fcxx-exceptions -emit-llvm-only -triple %itanium_abi_triple -main-file-name deferred-region.cpp %s | FileCheck %s
2
3#define IF if
4#define STMT(S) S
5
6// CHECK-LABEL: _Z3fooi:
7void foo(int x) {
8 if (x == 0) {
9 return;
Vedant Kumara1c4deb2017-09-18 23:37:30 +000010 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000011
12}
13
14// CHECK-NEXT: _Z4foooi:
15void fooo(int x) {
16 if (x == 0) {
17 return;
Vedant Kumara1c4deb2017-09-18 23:37:30 +000018 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000019
20 if (x == 1) {
21 return;
Vedant Kumara1c4deb2017-09-18 23:37:30 +000022 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:2 = ((#0 - #1) - #2)
Vedant Kumar747b0e22017-09-08 18:44:56 +000023
24}
25
26// CHECK-LABEL: _Z3bazv:
27void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2
28 return; // CHECK-NOT: File
29}
30
31// CHECK-LABEL: _Z3bari:
32void bar(int x) {
33 IF (x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000034 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000035
36 IF (!x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000037 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
Vedant Kumar747b0e22017-09-08 18:44:56 +000038
39 foo(x);
40}
41
42// CHECK-LABEL: _Z4quuxi:
43// Deferred regions are not emitted within macro expansions.
44void quux(int x) {
45 STMT(
46 if (x == 0)
47 return;)
48
49 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
50
51 if (x == 1)
52 STMT(return;)
53
54 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+3]]
55
56 STMT(
57 if (x == 2)
58 return;
59
60 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
61
62 if (x == 3)
63 return;
64 )
65}
66
67// CHECK-LABEL: _Z8weird_ifv:
68void weird_if() {
69 int i = 0;
70
71 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000072 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000073
74 if (false)
75 i++;
76
77 if (i + 100 > 0) { // CHECK: [[@LINE]]:20 -> [[@LINE+6]]:4 = #3
78 if (false) // CHECK: [[@LINE+1]]:7 -> [[@LINE+1]]:13 = #4
Vedant Kumara1c4deb2017-09-18 23:37:30 +000079 return; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = (#3 - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +000080 // CHECK: [[@LINE+1]]:5 -> [[@LINE+3]]:4 = (#3 - #4)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000081 return; // CHECK: Gap,File 0, [[@LINE]]:5 -> [[@LINE+4]]:3 = ((#0 - #1) - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +000082
83 }
84
85 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000086 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
Vedant Kumar747b0e22017-09-08 18:44:56 +000087}
88
89// CHECK-LABEL: _Z8for_loopv:
90void for_loop() {
91 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000092 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000093
94 for (int i = 0; i < 10; ++i) {
95 if (i % 2 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000096 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +000097
98 if (i % 5 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000099 break; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:5 = ((#2 - #3) - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000100
101 int x = i; // CHECK: [[@LINE]]:5 -> [[@LINE+3]]:4 = ((#2 - #3) - #4)
102 return; // CHECK-NOT: [[@LINE]]:11 -> [[@LINE+2]]
103
104 }
105}
106
107struct Error {};
108
109// CHECK-LABEL: _Z10while_loopv:
110void while_loop() {
111 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000112 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000113
114 int x = 0;
115 while (++x < 10) {
116 if (x == 1)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000117 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000118
119 while (++x < 4) {
120 if (x == 3)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000121 break; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:7 = (#4 - #5)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000122
123 while (++x < 5) {}
124 }
125
126 if (x == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000127 throw Error(); // CHECK: Gap,File 0, [[@LINE]]:20 -> [[@LINE+2]]:5 = ((#2 - #3) - #7)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000128
129 while (++x < 9) {
130 if (x == 0)
131 break; // CHECK-NOT: [[@LINE]]:14 -> [[@LINE+2]]
132
133 }
134 }
135}
136
137// CHECK-LABEL: _Z5gotosv:
138void gotos() {
139 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000140 goto out; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000141
142 return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
143
144out:
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000145 return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0
Vedant Kumar747b0e22017-09-08 18:44:56 +0000146}
147
148int main() {
149 foo(0);
150 foo(1);
151 fooo(0);
152 fooo(1);
153 baz();
154 bar(0);
155 bar(1);
156 quux(0);
157 quux(1);
158 quux(2);
159 quux(3);
160 weird_if();
161 for_loop();
162 while_loop();
163 gotos();
164 return 0;
165}