blob: 45113e46f02b26efae162c73959271ff6d4195e0 [file] [log] [blame]
Vedant Kumarf9a0d442017-11-09 02:33:40 +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 -I %S/Inputs %s | FileCheck %s
Vedant Kumar747b0e22017-09-08 18:44:56 +00002
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 Kumar61763b62018-05-30 23:35:44 +000010 } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
11 //< Don't complete the last deferred region in a decl, even though it may
12 //< leave some whitespace marked with the same counter as the final return.
Vedant Kumar747b0e22017-09-08 18:44:56 +000013}
14
Vedant Kumar61763b62018-05-30 23:35:44 +000015// CHECK-LABEL: _Z4foooi:
Vedant Kumar747b0e22017-09-08 18:44:56 +000016void fooo(int x) {
17 if (x == 0) {
18 return;
Vedant Kumara1c4deb2017-09-18 23:37:30 +000019 } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000020
21 if (x == 1) {
22 return;
Vedant Kumar61763b62018-05-30 23:35:44 +000023 } // CHECK-NOT: Gap,File 0, [[@LINE]]:4
Vedant Kumar747b0e22017-09-08 18:44:56 +000024
25}
26
27// CHECK-LABEL: _Z3bazv:
28void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2
29 return; // CHECK-NOT: File
30}
31
Vedant Kumaref8e05f2017-09-19 00:29:46 +000032// CHECK-LABEL: _Z3mazv:
33void maz() {
34 if (true)
Vedant Kumar341bf422017-10-17 07:47:39 +000035 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumaref8e05f2017-09-19 00:29:46 +000036
37 return; // CHECK-NOT: Gap
38}
39
Vedant Kumar341bf422017-10-17 07:47:39 +000040// CHECK-LABEL: _Z4maazv:
41void maaz() {
42 if (true)
43 return; // CHECK: Gap,File 0, [[@LINE]]:11
44 else
45 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
46}
47
48// CHECK-LABEL: _Z5maaazv:
49void maaaz() {
50 if (true) {
51 return;
52 } else { // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10
53 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
54 }
55}
56
Vedant Kumar747b0e22017-09-08 18:44:56 +000057// CHECK-LABEL: _Z3bari:
58void bar(int x) {
59 IF (x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000060 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000061
62 IF (!x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000063 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
Vedant Kumar747b0e22017-09-08 18:44:56 +000064
65 foo(x);
66}
67
68// CHECK-LABEL: _Z4quuxi:
69// Deferred regions are not emitted within macro expansions.
70void quux(int x) {
71 STMT(
72 if (x == 0)
73 return;)
74
75 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
76
77 if (x == 1)
78 STMT(return;)
79
80 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+3]]
81
82 STMT(
83 if (x == 2)
84 return;
85
86 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
87
88 if (x == 3)
89 return;
90 )
91}
92
93// CHECK-LABEL: _Z8weird_ifv:
94void weird_if() {
95 int i = 0;
96
97 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000098 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000099
100 if (false)
101 i++;
102
103 if (i + 100 > 0) { // CHECK: [[@LINE]]:20 -> [[@LINE+6]]:4 = #3
104 if (false) // CHECK: [[@LINE+1]]:7 -> [[@LINE+1]]:13 = #4
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000105 return; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = (#3 - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000106 // CHECK: [[@LINE+1]]:5 -> [[@LINE+3]]:4 = (#3 - #4)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000107 return; // CHECK: Gap,File 0, [[@LINE]]:5 -> [[@LINE+4]]:3 = ((#0 - #1) - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000108
109 }
110
111 if (false)
Vedant Kumar61763b62018-05-30 23:35:44 +0000112 return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
Vedant Kumar747b0e22017-09-08 18:44:56 +0000113}
114
115// CHECK-LABEL: _Z8for_loopv:
116void for_loop() {
117 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000118 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000119
120 for (int i = 0; i < 10; ++i) {
121 if (i % 2 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000122 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000123
124 if (i % 5 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000125 break; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:5 = ((#2 - #3) - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000126
127 int x = i; // CHECK: [[@LINE]]:5 -> [[@LINE+3]]:4 = ((#2 - #3) - #4)
128 return; // CHECK-NOT: [[@LINE]]:11 -> [[@LINE+2]]
129
130 }
131}
132
133struct Error {};
134
135// CHECK-LABEL: _Z10while_loopv:
136void while_loop() {
137 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000138 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000139
140 int x = 0;
141 while (++x < 10) {
142 if (x == 1)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000143 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000144
145 while (++x < 4) {
146 if (x == 3)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000147 break; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:7 = (#4 - #5)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000148
149 while (++x < 5) {}
150 }
151
152 if (x == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000153 throw Error(); // CHECK: Gap,File 0, [[@LINE]]:20 -> [[@LINE+2]]:5 = ((#2 - #3) - #7)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000154
155 while (++x < 9) {
156 if (x == 0)
157 break; // CHECK-NOT: [[@LINE]]:14 -> [[@LINE+2]]
158
159 }
160 }
161}
162
163// CHECK-LABEL: _Z5gotosv:
164void gotos() {
165 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000166 goto out; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000167
168 return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
169
170out:
Vedant Kumar61763b62018-05-30 23:35:44 +0000171 return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8
172}
173
174// CHECK-LABEL: _Z8switchesv:
175void switches() {
176 int x;
177 switch (x) {
178 case 0:
179 return;
180 default:
181 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
182 }
Vedant Kumar747b0e22017-09-08 18:44:56 +0000183}
184
Vedant Kumarf9a0d442017-11-09 02:33:40 +0000185#include "deferred-region-helper.h"
186// CHECK-LABEL: _Z13included_funcv:
187// CHECK: Gap,File 0, 2:13 -> 3:5 = #1
188// CHECK: Gap,File 0, 3:11 -> 4:3 = (#0 - #1)
189
190// CHECK-LABEL: _Z7includev:
191void include() {
192 included_func();
193}
194
Vedant Kumar747b0e22017-09-08 18:44:56 +0000195int main() {
196 foo(0);
197 foo(1);
198 fooo(0);
199 fooo(1);
Vedant Kumar341bf422017-10-17 07:47:39 +0000200 maz();
201 maaz();
202 maaaz();
Vedant Kumar747b0e22017-09-08 18:44:56 +0000203 baz();
204 bar(0);
205 bar(1);
206 quux(0);
207 quux(1);
208 quux(2);
209 quux(3);
210 weird_if();
211 for_loop();
212 while_loop();
213 gotos();
Vedant Kumarf9a0d442017-11-09 02:33:40 +0000214 include();
Vedant Kumar747b0e22017-09-08 18:44:56 +0000215 return 0;
216}