blob: 5a104f7789790dc788a546b27026cfbe6f526fc8 [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 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
Vedant Kumaref8e05f2017-09-19 00:29:46 +000031// CHECK-LABEL: _Z3mazv:
32void maz() {
33 if (true)
Vedant Kumar341bf422017-10-17 07:47:39 +000034 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumaref8e05f2017-09-19 00:29:46 +000035
36 return; // CHECK-NOT: Gap
37}
38
Vedant Kumar341bf422017-10-17 07:47:39 +000039// CHECK-LABEL: _Z4maazv:
40void maaz() {
41 if (true)
42 return; // CHECK: Gap,File 0, [[@LINE]]:11
43 else
44 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
45}
46
47// CHECK-LABEL: _Z5maaazv:
48void maaaz() {
49 if (true) {
50 return;
51 } else { // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE]]:10
52 return; // CHECK-NOT: Gap,File 0, [[@LINE]]
53 }
54}
55
Vedant Kumar747b0e22017-09-08 18:44:56 +000056// CHECK-LABEL: _Z3bari:
57void bar(int x) {
58 IF (x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000059 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000060
61 IF (!x)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000062 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = ((#0 - #1) - #2)
Vedant Kumar747b0e22017-09-08 18:44:56 +000063
64 foo(x);
65}
66
67// CHECK-LABEL: _Z4quuxi:
68// Deferred regions are not emitted within macro expansions.
69void quux(int x) {
70 STMT(
71 if (x == 0)
72 return;)
73
74 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
75
76 if (x == 1)
77 STMT(return;)
78
79 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+3]]
80
81 STMT(
82 if (x == 2)
83 return;
84
85 // CHECK-NOT: [[@LINE-2]]:{{.*}} -> [[@LINE+2]]
86
87 if (x == 3)
88 return;
89 )
90}
91
92// CHECK-LABEL: _Z8weird_ifv:
93void weird_if() {
94 int i = 0;
95
96 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +000097 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +000098
99 if (false)
100 i++;
101
102 if (i + 100 > 0) { // CHECK: [[@LINE]]:20 -> [[@LINE+6]]:4 = #3
103 if (false) // CHECK: [[@LINE+1]]:7 -> [[@LINE+1]]:13 = #4
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000104 return; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = (#3 - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000105 // CHECK: [[@LINE+1]]:5 -> [[@LINE+3]]:4 = (#3 - #4)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000106 return; // CHECK: Gap,File 0, [[@LINE]]:5 -> [[@LINE+4]]:3 = ((#0 - #1) - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000107
108 }
109
110 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000111 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+1]]:2
Vedant Kumar747b0e22017-09-08 18:44:56 +0000112}
113
114// CHECK-LABEL: _Z8for_loopv:
115void for_loop() {
116 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000117 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000118
119 for (int i = 0; i < 10; ++i) {
120 if (i % 2 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000121 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000122
123 if (i % 5 == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000124 break; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:5 = ((#2 - #3) - #4)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000125
126 int x = i; // CHECK: [[@LINE]]:5 -> [[@LINE+3]]:4 = ((#2 - #3) - #4)
127 return; // CHECK-NOT: [[@LINE]]:11 -> [[@LINE+2]]
128
129 }
130}
131
132struct Error {};
133
134// CHECK-LABEL: _Z10while_loopv:
135void while_loop() {
136 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000137 return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000138
139 int x = 0;
140 while (++x < 10) {
141 if (x == 1)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000142 continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000143
144 while (++x < 4) {
145 if (x == 3)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000146 break; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:7 = (#4 - #5)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000147
148 while (++x < 5) {}
149 }
150
151 if (x == 0)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000152 throw Error(); // CHECK: Gap,File 0, [[@LINE]]:20 -> [[@LINE+2]]:5 = ((#2 - #3) - #7)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000153
154 while (++x < 9) {
155 if (x == 0)
156 break; // CHECK-NOT: [[@LINE]]:14 -> [[@LINE+2]]
157
158 }
159 }
160}
161
162// CHECK-LABEL: _Z5gotosv:
163void gotos() {
164 if (false)
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000165 goto out; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:3 = (#0 - #1)
Vedant Kumar747b0e22017-09-08 18:44:56 +0000166
167 return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1)
168
169out:
Vedant Kumara1c4deb2017-09-18 23:37:30 +0000170 return; // CHECK: Gap,File 0, [[@LINE]]:8 -> [[@LINE+1]]:2 = 0
Vedant Kumar747b0e22017-09-08 18:44:56 +0000171}
172
Vedant Kumarf9a0d442017-11-09 02:33:40 +0000173#include "deferred-region-helper.h"
174// CHECK-LABEL: _Z13included_funcv:
175// CHECK: Gap,File 0, 2:13 -> 3:5 = #1
176// CHECK: Gap,File 0, 3:11 -> 4:3 = (#0 - #1)
177
178// CHECK-LABEL: _Z7includev:
179void include() {
180 included_func();
181}
182
Vedant Kumar747b0e22017-09-08 18:44:56 +0000183int main() {
184 foo(0);
185 foo(1);
186 fooo(0);
187 fooo(1);
Vedant Kumar341bf422017-10-17 07:47:39 +0000188 maz();
189 maaz();
190 maaaz();
Vedant Kumar747b0e22017-09-08 18:44:56 +0000191 baz();
192 bar(0);
193 bar(1);
194 quux(0);
195 quux(1);
196 quux(2);
197 quux(3);
198 weird_if();
199 for_loop();
200 while_loop();
201 gotos();
Vedant Kumarf9a0d442017-11-09 02:33:40 +0000202 include();
Vedant Kumar747b0e22017-09-08 18:44:56 +0000203 return 0;
204}