1 // RUN: %clang_cc1 -std=c++11 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name macro-expressions.cpp %s | FileCheck %s
2
3 #define EXPR(x) (x)
4 #define NEXPR(x) (!x)
5 #define DECL(T, x) T x
6 #define ASSIGN(x, y) x = y
7 #define LT(x, y) x < y
8 #define INC(x) ++x
9 #define ARR(T, x, y, z) (T[3]){x, y, z}
10
11 #define PRI_64_LENGTH_MODIFIER "ll"
12 #define PRIo64 PRI_64_LENGTH_MODIFIER "o"
13 #define PRIu64 PRI_64_LENGTH_MODIFIER "u"
14
15 #define STMT(s) s
16
fn1()17 void fn1() {
18 STMT(if (1));
19 STMT(while (1));
20 STMT(for (;;));
21 STMT(if) (1);
22 STMT(while) (1);
23 STMT(for) (;;);
24 if (1)
25 STMT(if (1)
26 STMT(if (1)));
27 if (1)
28 STMT(if (1)) 0;
29 if (1)
30 STMT(while (1)) 0;
31 if (1)
32 STMT(for (;;)) 0;
33 while (1)
34 STMT(if (1)) 0;
35 while (1)
36 STMT(while (1)) 0;
37 while (1)
38 STMT(for (;;)) 0;
39 for (;;)
40 STMT(if (1)) 0;
41 for (;;)
42 STMT(while (1)) 0;
43 for (;;)
44 STMT(for (;;)) 0;
45 }
46
STMT(fn2 ())47 void STMT(fn2()) {
48 }
49
STMT(fn3)50 void STMT(fn3)() {
51 }
52
53 // CHECK: foo
54 // CHECK-NEXT: File 0, [[@LINE+1]]:17 -> {{[0-9]+}}:2 = #0
foo(int i)55 void foo(int i) {
56 // CHECK-NEXT: File 0, [[@LINE+2]]:7 -> [[@LINE+2]]:8 = #0
57 // CHECK-NEXT: File 0, [[@LINE+1]]:10 -> [[@LINE+1]]:12 = #1
58 if (0) {}
59
60 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:7 -> [[@LINE+2]]:11 = #0
61 // CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+1]]:18 = #2
62 if (EXPR(i)) {}
63 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:9 -> [[@LINE+2]]:14 = (#0 + #3)
64 // CHECK-NEXT: File 0, [[@LINE+1]]:20 -> [[@LINE+1]]:22 = #3
65 for (;NEXPR(i);) {}
66 // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:8 -> [[@LINE+4]]:14 = #0
67 // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:33 -> [[@LINE+3]]:35 = (#0 + #4)
68 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:43 -> [[@LINE+2]]:46 = #4
69 // CHECK-NEXT: File 0, [[@LINE+1]]:51 -> [[@LINE+1]]:53 = #4
70 for (ASSIGN(DECL(int, j), 0); LT(j, i); INC(j)) {}
71 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:9 = #0
72 ASSIGN(DECL(int, k), 0);
73 // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:10 -> [[@LINE+3]]:12 = (#0 + #5)
74 // CHECK-NEXT: File 0, [[@LINE+2]]:20 -> [[@LINE+2]]:31 = #5
75 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:22 -> [[@LINE+1]]:25 = #5
76 while (LT(k, i)) { INC(k); }
77 // CHECK-NEXT: File 0, [[@LINE+2]]:6 -> [[@LINE+2]]:8 = (#0 + #6)
78 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:16 -> [[@LINE+1]]:21 = (#0 + #6)
79 do {} while (NEXPR(i));
80 // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:8 -> [[@LINE+3]]:12 = #0
81 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:23 -> [[@LINE+2]]:26 = #0
82 // CHECK-NEXT: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7
83 for (DECL(int, j) : ARR(int, 1, 2, 3)) {}
84
85 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:20 = #0
86 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:23 -> [[@LINE+1]]:29 = #0
87 (void)(i ? PRIo64 : PRIu64);
88
89 // CHECK-NEXT: File 0, [[@LINE+5]]:14 -> [[@LINE+5]]:15 = #9
90 // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:18 -> [[@LINE+4]]:22 = (#0 - #9)
91 // CHECK-NEXT: File 0, [[@LINE+3]]:22 -> [[@LINE+3]]:33 = (#0 - #9)
92 // CHECK-NEXT: File 0, [[@LINE+2]]:28 -> [[@LINE+2]]:29 = #10
93 // CHECK-NEXT: File 0, [[@LINE+1]]:32 -> [[@LINE+1]]:33 = ((#0 - #9) - #10)
94 (void)(i ? i : EXPR(i) ? i : 0);
95 // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:15 -> [[@LINE+3]]:19 = (#0 - #11)
96 // CHECK-NEXT: File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:27 = (#0 - #11)
97 // CHECK-NEXT: File 0, [[@LINE+1]]:26 -> [[@LINE+1]]:27 = ((#0 - #11) - #12)
98 (void)(i ?: EXPR(i) ?: 0);
99 }
100
101 // CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = #0
102 // CHECK-NEXT: File {{[0-9]+}}, 4:18 -> 4:22 = (#0 + #3)
103 // CHECK-NEXT: File {{[0-9]+}}, 6:22 -> 6:27 = #0
104 // CHECK-NEXT: File {{[0-9]+}}, 8:16 -> 8:19 = #4
105 // CHECK-NEXT: File {{[0-9]+}}, 7:18 -> 7:23 = (#0 + #4)
106 // CHECK-NEXT: File {{[0-9]+}}, 6:22 -> 6:27 = #0
107 // CHECK-NEXT: File {{[0-9]+}}, 8:16 -> 8:19 = #5
108 // CHECK-NEXT: File {{[0-9]+}}, 7:18 -> 7:23 = (#0 + #5)
109 // CHECK-NEXT: File {{[0-9]+}}, 4:18 -> 4:22 = (#0 + #6)
110 // CHECK-NEXT: File {{[0-9]+}}, 5:20 -> 5:23 = #0
111 // CHECK-NEXT: File {{[0-9]+}}, 9:25 -> 9:40 = #0
112 // CHECK-NEXT: File {{[0-9]+}}, 12:16 -> 12:42 = #0
113 // CHECK-NEXT: Expansion,File {{[0-9]+}}, 12:16 -> 12:38 = #8
114 // CHECK-NEXT: File {{[0-9]+}}, 12:38 -> 12:42 = #8
115 // CHECK-NEXT: File {{[0-9]+}}, 13:16 -> 13:42 = #0
116 // CHECK-NEXT: Expansion,File {{[0-9]+}}, 13:16 -> 13:38 = (#0 - #8)
117 // CHECK-NEXT: File {{[0-9]+}}, 13:38 -> 13:42 = (#0 - #8)
118 // CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = (#0 - #9)
119 // CHECK-NEXT: File {{[0-9]+}}, 3:17 -> 3:20 = (#0 - #11)
120 // CHECK-NEXT: File {{[0-9]+}}, 11:32 -> 11:36 = #8
121 // CHECK-NEXT: File {{[0-9]+}}, 11:32 -> 11:36 = (#0 - #8)
122
123 // CHECK-NOT: File {{[0-9]+}},
124 // CHECK: main
125
main(int argc,const char * argv[])126 int main(int argc, const char *argv[]) {
127 foo(10);
128 }
129