Vedant Kumar | f9a0d44 | 2017-11-09 02:33:40 +0000 | [diff] [blame] | 1 | // 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 Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 2 | |
| 3 | #define IF if |
| 4 | #define STMT(S) S |
| 5 | |
| 6 | // CHECK-LABEL: _Z3fooi: |
| 7 | void foo(int x) { |
| 8 | if (x == 0) { |
| 9 | return; |
Vedant Kumar | 61763b6 | 2018-05-30 23:35:44 +0000 | [diff] [blame] | 10 | } // 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 Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 13 | } |
| 14 | |
Vedant Kumar | 61763b6 | 2018-05-30 23:35:44 +0000 | [diff] [blame] | 15 | // CHECK-LABEL: _Z4foooi: |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 16 | void fooo(int x) { |
| 17 | if (x == 0) { |
| 18 | return; |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 19 | } // CHECK: Gap,File 0, [[@LINE]]:4 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 20 | |
| 21 | if (x == 1) { |
| 22 | return; |
Vedant Kumar | 61763b6 | 2018-05-30 23:35:44 +0000 | [diff] [blame] | 23 | } // CHECK-NOT: Gap,File 0, [[@LINE]]:4 |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 24 | |
| 25 | } |
| 26 | |
| 27 | // CHECK-LABEL: _Z3bazv: |
| 28 | void baz() { // CHECK: [[@LINE]]:12 -> [[@LINE+2]]:2 |
| 29 | return; // CHECK-NOT: File |
| 30 | } |
| 31 | |
Vedant Kumar | ef8e05f | 2017-09-19 00:29:46 +0000 | [diff] [blame] | 32 | // CHECK-LABEL: _Z3mazv: |
| 33 | void maz() { |
| 34 | if (true) |
Vedant Kumar | 341bf42 | 2017-10-17 07:47:39 +0000 | [diff] [blame] | 35 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | ef8e05f | 2017-09-19 00:29:46 +0000 | [diff] [blame] | 36 | |
| 37 | return; // CHECK-NOT: Gap |
| 38 | } |
| 39 | |
Vedant Kumar | 341bf42 | 2017-10-17 07:47:39 +0000 | [diff] [blame] | 40 | // CHECK-LABEL: _Z4maazv: |
| 41 | void 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: |
| 49 | void 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 Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 57 | // CHECK-LABEL: _Z3bari: |
| 58 | void bar(int x) { |
| 59 | IF (x) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 60 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 61 | |
| 62 | IF (!x) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 63 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = ((#0 - #1) - #2) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 64 | |
| 65 | foo(x); |
| 66 | } |
| 67 | |
| 68 | // CHECK-LABEL: _Z4quuxi: |
| 69 | // Deferred regions are not emitted within macro expansions. |
| 70 | void 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: |
| 94 | void weird_if() { |
| 95 | int i = 0; |
| 96 | |
| 97 | if (false) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 98 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 99 | |
| 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 Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 105 | return; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:5 = (#3 - #4) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 106 | // CHECK: [[@LINE+1]]:5 -> [[@LINE+3]]:4 = (#3 - #4) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 107 | return; // CHECK: Gap,File 0, [[@LINE]]:5 -> [[@LINE+4]]:3 = ((#0 - #1) - #3) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 108 | |
| 109 | } |
| 110 | |
| 111 | if (false) |
Vedant Kumar | 61763b6 | 2018-05-30 23:35:44 +0000 | [diff] [blame] | 112 | return; // CHECK-NOT: Gap,File 0, [[@LINE]]:11 |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | // CHECK-LABEL: _Z8for_loopv: |
| 116 | void for_loop() { |
| 117 | if (false) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 118 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 119 | |
| 120 | for (int i = 0; i < 10; ++i) { |
| 121 | if (i % 2 == 0) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 122 | continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 123 | |
| 124 | if (i % 5 == 0) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 125 | break; // CHECK: Gap,File 0, [[@LINE]]:12 -> [[@LINE+2]]:5 = ((#2 - #3) - #4) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 126 | |
| 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 | |
| 133 | struct Error {}; |
| 134 | |
| 135 | // CHECK-LABEL: _Z10while_loopv: |
| 136 | void while_loop() { |
| 137 | if (false) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 138 | return; // CHECK: Gap,File 0, [[@LINE]]:11 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 139 | |
| 140 | int x = 0; |
| 141 | while (++x < 10) { |
| 142 | if (x == 1) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 143 | continue; // CHECK: Gap,File 0, [[@LINE]]:15 -> [[@LINE+2]]:5 = (#2 - #3) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 144 | |
| 145 | while (++x < 4) { |
| 146 | if (x == 3) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 147 | break; // CHECK: Gap,File 0, [[@LINE]]:14 -> [[@LINE+2]]:7 = (#4 - #5) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 148 | |
| 149 | while (++x < 5) {} |
| 150 | } |
| 151 | |
| 152 | if (x == 0) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 153 | throw Error(); // CHECK: Gap,File 0, [[@LINE]]:20 -> [[@LINE+2]]:5 = ((#2 - #3) - #7) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 154 | |
| 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: |
| 164 | void gotos() { |
| 165 | if (false) |
Vedant Kumar | a1c4deb | 2017-09-18 23:37:30 +0000 | [diff] [blame] | 166 | goto out; // CHECK: Gap,File 0, [[@LINE]]:13 -> [[@LINE+2]]:3 = (#0 - #1) |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 167 | |
| 168 | return; // CHECK: [[@LINE]]:3 -> [[@LINE+4]]:2 = (#0 - #1) |
| 169 | |
| 170 | out: |
Vedant Kumar | 61763b6 | 2018-05-30 23:35:44 +0000 | [diff] [blame] | 171 | return; // CHECK-NOT: Gap,File 0, [[@LINE]]:8 |
| 172 | } |
| 173 | |
| 174 | // CHECK-LABEL: _Z8switchesv: |
| 175 | void switches() { |
| 176 | int x; |
| 177 | switch (x) { |
| 178 | case 0: |
| 179 | return; |
| 180 | default: |
| 181 | return; // CHECK-NOT: Gap,File 0, [[@LINE]] |
| 182 | } |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Vedant Kumar | f9a0d44 | 2017-11-09 02:33:40 +0000 | [diff] [blame] | 185 | #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: |
| 191 | void include() { |
| 192 | included_func(); |
| 193 | } |
| 194 | |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 195 | int main() { |
| 196 | foo(0); |
| 197 | foo(1); |
| 198 | fooo(0); |
| 199 | fooo(1); |
Vedant Kumar | 341bf42 | 2017-10-17 07:47:39 +0000 | [diff] [blame] | 200 | maz(); |
| 201 | maaz(); |
| 202 | maaaz(); |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 203 | 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 Kumar | f9a0d44 | 2017-11-09 02:33:40 +0000 | [diff] [blame] | 214 | include(); |
Vedant Kumar | 747b0e2 | 2017-09-08 18:44:56 +0000 | [diff] [blame] | 215 | return 0; |
| 216 | } |