initializers-cfg-output.cpp
10.4 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s 2>&1 | FileCheck -check-prefixes=CHECK,WARNINGS %s
// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s 2>&1 | FileCheck -check-prefixes=CHECK,ANALYZER %s
// This file tests how we construct two different flavors of the Clang CFG -
// the CFG used by the Sema analysis-based warnings and the CFG used by the
// static analyzer. The difference in the behavior is checked via FileCheck
// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
// flags, no new run lines should be added - just these flags would go to the
// respective line depending on where is it turned on and where is it turned
// off. Feel free to add tests that test only one of the CFG flavors if you're
// not sure how the other flavor is supposed to work in your case.
class A {
public:
// CHECK: A()
// CHECK: [B1 (ENTRY)]
// CHECK-NEXT: Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
A() {}
// CHECK: A(int i)
// CHECK: [B1 (ENTRY)]
// CHECK-NEXT: Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
A(int i) {}
};
class B : public virtual A {
public:
// CHECK: B()
// CHECK: [B3 (ENTRY)]
// CHECK-NEXT: Succs (1): B2
// CHECK: [B1]
// WARNINGS-NEXT: 1: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 1: (CXXConstructExpr, A() (Base initializer), class A)
// CHECK-NEXT: 2: A([B1.1]) (Base initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B3
// CHECK-NEXT: Succs (2): B0 B1
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (2): B1 B2
B() {}
// CHECK: B(int i)
// CHECK: [B3 (ENTRY)]
// CHECK-NEXT: Succs (1): B2
// CHECK: [B1]
// CHECK-NEXT: 1: i
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// WARNINGS-NEXT: 3: [B1.2] (CXXConstructExpr, class A)
// ANALYZER-NEXT: 3: [B1.2] (CXXConstructExpr, A([B1.2]) (Base initializer), class A)
// CHECK-NEXT: 4: A([B1.3]) (Base initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B3
// CHECK-NEXT: Succs (2): B0 B1
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (2): B1 B2
B(int i) : A(i) {}
};
class C : public virtual A {
public:
// CHECK: C()
// CHECK: [B3 (ENTRY)]
// CHECK-NEXT: Succs (1): B2
// CHECK: [B1]
// WARNINGS-NEXT: 1: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 1: (CXXConstructExpr, A() (Base initializer), class A)
// CHECK-NEXT: 2: A([B1.1]) (Base initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B3
// CHECK-NEXT: Succs (2): B0 B1
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (2): B1 B2
C() {}
// CHECK: C(int i)
// CHECK: [B3 (ENTRY)]
// CHECK-NEXT: Succs (1): B2
// CHECK: [B1]
// CHECK-NEXT: 1: i
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// WARNINGS-NEXT: 3: [B1.2] (CXXConstructExpr, class A)
// ANALYZER-NEXT: 3: [B1.2] (CXXConstructExpr, A([B1.2]) (Base initializer), class A)
// CHECK-NEXT: 4: A([B1.3]) (Base initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B3
// CHECK-NEXT: Succs (2): B0 B1
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (2): B1 B2
C(int i) : A(i) {}
};
class TestOrder : public C, public B, public A {
int i;
int& r;
public:
TestOrder();
};
// CHECK: TestOrder::TestOrder()
// CHECK: [B4 (ENTRY)]
// CHECK-NEXT: Succs (1): B3
// CHECK: [B1]
// WARNINGS-NEXT: 1: (CXXConstructExpr, class C)
// ANALYZER-NEXT: 1: (CXXConstructExpr, C() (Base initializer), class C)
// CHECK-NEXT: 2: C([B1.1]) (Base initializer)
// WARNINGS-NEXT: 3: (CXXConstructExpr, class B)
// ANALYZER-NEXT: 3: (CXXConstructExpr, B() (Base initializer), class B)
// CHECK-NEXT: 4: B([B1.3]) (Base initializer)
// WARNINGS-NEXT: 5: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 5: (CXXConstructExpr, A() (Base initializer), class A)
// CHECK-NEXT: 6: A([B1.5]) (Base initializer)
// CHECK-NEXT: 7: i(/*implicit*/(int)0) (Member initializer)
// CHECK-NEXT: 8: this
// CHECK-NEXT: 9: [B1.8]->i
// CHECK-NEXT: 10: r([B1.9]) (Member initializer)
// WARNINGS-NEXT: 11: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 11: (CXXConstructExpr, [B1.12], class A)
// CHECK-NEXT: 12: A a;
// CHECK-NEXT: Preds (2): B2 B3
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// WARNINGS-NEXT: 1: (CXXConstructExpr, class A)
// ANALYZER-NEXT: 1: (CXXConstructExpr, A() (Base initializer), class A)
// CHECK-NEXT: 2: A([B2.1]) (Base initializer)
// CHECK-NEXT: Preds (1): B3
// CHECK-NEXT: Succs (1): B1
// CHECK: [B3]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B4
// CHECK-NEXT: Succs (2): B1 B2
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
TestOrder::TestOrder()
: r(i), B(), i(), C() {
A a;
}
class TestControlFlow {
int x, y, z;
public:
TestControlFlow(bool b);
};
// CHECK: TestControlFlow::TestControlFlow(bool b)
// CHECK: [B5 (ENTRY)]
// CHECK-NEXT: Succs (1): B4
// CHECK: [B1]
// CHECK-NEXT: 1: [B4.4] ? [B2.1] : [B3.1]
// CHECK-NEXT: 2: y([B1.1]) (Member initializer)
// CHECK-NEXT: 3: this
// CHECK-NEXT: 4: [B1.3]->y
// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT: 6: z([B1.5]) (Member initializer)
// CHECK-NEXT: 7: int v;
// CHECK-NEXT: Preds (2): B2 B3
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: 1: 0
// CHECK-NEXT: Preds (1): B4
// CHECK-NEXT: Succs (1): B1
// CHECK: [B3]
// CHECK-NEXT: 1: 1
// CHECK-NEXT: Preds (1): B4
// CHECK-NEXT: Succs (1): B1
// CHECK: [B4]
// CHECK-NEXT: 1: 0
// CHECK-NEXT: 2: x([B4.1]) (Member initializer)
// CHECK-NEXT: 3: b
// CHECK-NEXT: 4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool)
// CHECK-NEXT: T: [B4.4] ? ... : ...
// CHECK-NEXT: Preds (1): B5
// CHECK-NEXT: Succs (2): B2 B3
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
TestControlFlow::TestControlFlow(bool b)
: y(b ? 0 : 1)
, x(0)
, z(y) {
int v;
}
class TestDelegating {
int x, z;
public:
// CHECK: TestDelegating()
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT: Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT: 1: 2
// CHECK-NEXT: 2: 3
// WARNINGS-NEXT: 3: [B1.1], [B1.2] (CXXConstructExpr, class TestDelegating)
// ANALYZER-NEXT: 3: [B1.1], [B1.2] (CXXConstructExpr, TestDelegating([B1.1], [B1.2]) (Delegating initializer), class TestDelegating)
// CHECK-NEXT: 4: TestDelegating([B1.3]) (Delegating initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
TestDelegating() : TestDelegating(2, 3) {}
// CHECK: TestDelegating(int x, int z)
// CHECK: [B2 (ENTRY)]
// CHECK-NEXT: Succs (1): B1
// CHECK: [B1]
// CHECK-NEXT: 1: x
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT: 3: x([B1.2]) (Member initializer)
// CHECK-NEXT: 4: z
// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
// CHECK-NEXT: 6: z([B1.5]) (Member initializer)
// CHECK-NEXT: Preds (1): B2
// CHECK-NEXT: Succs (1): B0
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
TestDelegating(int x, int z) : x(x), z(z) {}
};
class TestMoreControlFlow : public virtual A {
A a;
public:
TestMoreControlFlow(bool coin);
};
// CHECK: TestMoreControlFlow::TestMoreControlFlow(bool coin)
// CHECK: [B10 (ENTRY)]
// CHECK-NEXT: Succs (1): B9
// CHECK: [B1]
// CHECK-NEXT: 1: [B4.2] ? [B2.1] : [B3.1]
// WARNINGS-NEXT: 2: [B1.1] (CXXConstructExpr, class A)
// ANALYZER-NEXT: 2: [B1.1] (CXXConstructExpr, a([B1.1]) (Member initializer), class A)
// CHECK-NEXT: 3: a([B1.2]) (Member initializer)
// CHECK-NEXT: Preds (2): B2 B3
// CHECK-NEXT: Succs (1): B0
// CHECK: [B2]
// CHECK-NEXT: 1: 3
// CHECK-NEXT: Preds (1): B4
// CHECK-NEXT: Succs (1): B1
// CHECK: [B3]
// CHECK-NEXT: 1: 4
// CHECK-NEXT: Preds (1): B4
// CHECK-NEXT: Succs (1): B1
// CHECK: [B4]
// CHECK-NEXT: 1: coin
// CHECK-NEXT: 2: [B4.1] (ImplicitCastExpr, LValueToRValue, _Bool)
// CHECK-NEXT: T: [B4.2] ? ... : ...
// CHECK-NEXT: Preds (2): B5 B9
// CHECK-NEXT: Succs (2): B2 B3
// CHECK: [B5]
// CHECK-NEXT: 1: [B8.2] ? [B6.1] : [B7.1]
// WARNINGS-NEXT: 2: [B5.1] (CXXConstructExpr, class A)
// ANALYZER-NEXT: 2: [B5.1] (CXXConstructExpr, A([B5.1]) (Base initializer), class A)
// CHECK-NEXT: 3: A([B5.2]) (Base initializer)
// CHECK-NEXT: Preds (2): B6 B7
// CHECK-NEXT: Succs (1): B4
// CHECK: [B6]
// CHECK-NEXT: 1: 1
// CHECK-NEXT: Preds (1): B8
// CHECK-NEXT: Succs (1): B5
// CHECK: [B7]
// CHECK-NEXT: 1: 2
// CHECK-NEXT: Preds (1): B8
// CHECK-NEXT: Succs (1): B5
// CHECK: [B8]
// CHECK-NEXT: 1: coin
// CHECK-NEXT: 2: [B8.1] (ImplicitCastExpr, LValueToRValue, _Bool)
// CHECK-NEXT: T: [B8.2] ? ... : ...
// CHECK-NEXT: Preds (1): B9
// CHECK-NEXT: Succs (2): B6 B7
// CHECK: [B9]
// CHECK-NEXT: T: (See if most derived ctor has already initialized vbases)
// CHECK-NEXT: Preds (1): B10
// CHECK-NEXT: Succs (2): B4 B8
// CHECK: [B0 (EXIT)]
// CHECK-NEXT: Preds (1): B1
TestMoreControlFlow::TestMoreControlFlow(bool coin)
: A(coin ? 1 : 2), a(coin ? 3 : 4) {}