deferred-region.cpp
4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -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
#define IF if
#define STMT(S) S
// CHECK-LABEL: _Z3fooi:
void foo(int x) {
if (x == 0) {
return;
} // CHECK-NOT: Gap,File 0, [[@LINE]]:4
//< Don't complete the last deferred region in a decl, even though it may
//< leave some whitespace marked with the same counter as the final return.
}
// CHECK-LABEL: _Z4foooi:
void fooo(int x) {
if (x == 0) {
return;
} // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1)
if (x == 1) {
return;
} // CHECK-NOT: Gap,File 0, [[@LINE]]:4
}
// CHECK-LABEL: _Z3bazv:
void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2
return; // CHECK-NOT: File
}
// CHECK-LABEL: _Z3mazv:
void maz() {
if (true)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
return; // CHECK-NOT: Gap
}
// CHECK-LABEL: _Z4maazv:
void maaz() {
if (true)
return; // CHECK: Gap,File 0, [[@LINE]]:11
else
return; // CHECK-NOT: Gap,File 0, [[@LINE]]
}
// CHECK-LABEL: _Z5maaazv:
void maaaz() {
if (true) {
return;
} else { // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10
return; // CHECK-NOT: Gap,File 0, [[@LINE]]
}
}
// CHECK-LABEL: _Z3bari:
void bar(int x) {
IF (x)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
IF (!x)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
foo(x);
}
// CHECK-LABEL: _Z4quuxi:
// Deferred regions are not emitted within macro expansions.
void quux(int x) {
STMT(
if (x == 0)
return;)
// CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
if (x == 1)
STMT(return;)
// CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+3]]
STMT(
if (x == 2)
return;
// CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
if (x == 3)
return;
)
}
// CHECK-LABEL: _Z8weird_ifv:
void weird_if() {
int i = 0;
if (false)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
if (false)
i++;
if (i + 100 > 0) { // CHECK: [[@LINE]]:20 -> [[@LINE+6]]:4 = #3
if (false) // CHECK: [[@LINE+1]]:7 -> [[@LINE+1]]:13 = #4
return; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = (#3 - #4)
// CHECK: [[@LINE+1]]:5 -> [[@LINE+3]]:4 = (#3 - #4)
return; // CHECK: Gap,File 0, [[@LINE]]:5 -> [[@LINE+4]]:3 = ((#0 - #1) - #3)
}
if (false)
return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11
}
// CHECK-LABEL: _Z8for_loopv:
void for_loop() {
if (false)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
for (int i = 0; i < 10; ++i) {
if (i % 2 == 0)
continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
if (i % 5 == 0)
break; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:5 = ((#2 - #3) - #4)
int x = i; // CHECK: [[@LINE]]:5 -> [[@LINE+3]]:4 = ((#2 - #3) - #4)
return; // CHECK-NOT: [[@LINE]]:11 -> [[@LINE+2]]
}
}
struct Error {};
// CHECK-LABEL: _Z10while_loopv:
void while_loop() {
if (false)
return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
int x = 0;
while (++x < 10) {
if (x == 1)
continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
while (++x < 4) {
if (x == 3)
break; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:7 = (#4 - #5)
while (++x < 5) {}
}
if (x == 0)
throw Error(); // CHECK: Gap,File 0, [[@LINE]]:20 -> [[@LINE+2]]:5 = ((#2 - #3) - #7)
while (++x < 9) {
if (x == 0)
break; // CHECK-NOT: [[@LINE]]:14 -> [[@LINE+2]]
}
}
}
// CHECK-LABEL: _Z5gotosv:
void gotos() {
if (false)
goto out; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:3 = (#0 - #1)
return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
out:
return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8
}
// CHECK-LABEL: _Z8switchesv:
void switches() {
int x;
switch (x) {
case 0:
return;
default:
return; // CHECK-NOT: Gap,File 0, [[@LINE]]
}
}
#include "deferred-region-helper.h"
// CHECK-LABEL: _Z13included_funcv:
// CHECK: Gap,File 0, 2:13 -> 3:5 = #1
// CHECK: Gap,File 0, 3:11 -> 4:3 = (#0 - #1)
// CHECK-LABEL: _Z7includev:
void include() {
included_func();
}
int main() {
foo(0);
foo(1);
fooo(0);
fooo(1);
maz();
maaz();
maaaz();
baz();
bar(0);
bar(1);
quux(0);
quux(1);
quux(2);
quux(3);
weird_if();
for_loop();
while_loop();
gotos();
include();
return 0;
}