1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 %s > %t 2>&1
2*0a6a1f1dSLionel Sambuc // RUN: FileCheck --input-file=%t %s
3f4a2713aSLionel Sambuc
4*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void checkWrap(int i)
5f4a2713aSLionel Sambuc // CHECK: ENTRY
6f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
7f4a2713aSLionel Sambuc // CHECK: [B1]
8f4a2713aSLionel Sambuc // CHECK: Succs (21): B2 B3 B4 B5 B6 B7 B8 B9
9f4a2713aSLionel Sambuc // CHECK: B10 B11 B12 B13 B14 B15 B16 B17 B18 B19
10f4a2713aSLionel Sambuc // CHECK: B20 B21 B0
11f4a2713aSLionel Sambuc // CHECK: [B0 (EXIT)]
12f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (21): B2 B3 B4 B5 B6 B7 B8 B9
13f4a2713aSLionel Sambuc // CHECK-NEXT: B10 B11 B12 B13 B14 B15 B16 B17 B18 B19
14f4a2713aSLionel Sambuc // CHECK-NEXT: B20 B21 B1
checkWrap(int i)15f4a2713aSLionel Sambuc void checkWrap(int i) {
16f4a2713aSLionel Sambuc switch(i) {
17f4a2713aSLionel Sambuc case 0: break;
18f4a2713aSLionel Sambuc case 1: break;
19f4a2713aSLionel Sambuc case 2: break;
20f4a2713aSLionel Sambuc case 3: break;
21f4a2713aSLionel Sambuc case 4: break;
22f4a2713aSLionel Sambuc case 5: break;
23f4a2713aSLionel Sambuc case 6: break;
24f4a2713aSLionel Sambuc case 7: break;
25f4a2713aSLionel Sambuc case 8: break;
26f4a2713aSLionel Sambuc case 9: break;
27f4a2713aSLionel Sambuc case 10: break;
28f4a2713aSLionel Sambuc case 11: break;
29f4a2713aSLionel Sambuc case 12: break;
30f4a2713aSLionel Sambuc case 13: break;
31f4a2713aSLionel Sambuc case 14: break;
32f4a2713aSLionel Sambuc case 15: break;
33f4a2713aSLionel Sambuc case 16: break;
34f4a2713aSLionel Sambuc case 17: break;
35f4a2713aSLionel Sambuc case 18: break;
36f4a2713aSLionel Sambuc case 19: break;
37f4a2713aSLionel Sambuc }
38f4a2713aSLionel Sambuc }
39f4a2713aSLionel Sambuc
40*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void checkDeclStmts()
41f4a2713aSLionel Sambuc // CHECK: ENTRY
42f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
43f4a2713aSLionel Sambuc // CHECK: [B1]
44f4a2713aSLionel Sambuc // CHECK-NEXT: 1: int i;
45f4a2713aSLionel Sambuc // CHECK-NEXT: 2: int j;
46f4a2713aSLionel Sambuc // CHECK-NEXT: 3: 1
47f4a2713aSLionel Sambuc // CHECK-NEXT: 4: int k = 1;
48f4a2713aSLionel Sambuc // CHECK-NEXT: 5: int l;
49f4a2713aSLionel Sambuc // CHECK-NEXT: 6: 2
50f4a2713aSLionel Sambuc // CHECK-NEXT: 7: int m = 2;
51f4a2713aSLionel Sambuc // CHECK-NEXT: CXXConstructExpr
52f4a2713aSLionel Sambuc // CHECK-NEXT: 9: struct standalone myStandalone;
53f4a2713aSLionel Sambuc // CHECK-NEXT: CXXConstructExpr
54*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 11: struct (anonymous struct at {{.*}}) myAnon;
55f4a2713aSLionel Sambuc // CHECK-NEXT: CXXConstructExpr
56f4a2713aSLionel Sambuc // CHECK-NEXT: 13: struct named myNamed;
57f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B2
58f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
checkDeclStmts()59f4a2713aSLionel Sambuc void checkDeclStmts() {
60f4a2713aSLionel Sambuc int i, j;
61f4a2713aSLionel Sambuc int k = 1, l, m = 2;
62f4a2713aSLionel Sambuc
63f4a2713aSLionel Sambuc struct standalone { int x, y; };
64f4a2713aSLionel Sambuc struct standalone myStandalone;
65f4a2713aSLionel Sambuc
66f4a2713aSLionel Sambuc struct { int x, y; } myAnon;
67f4a2713aSLionel Sambuc
68f4a2713aSLionel Sambuc struct named { int x, y; } myNamed;
69f4a2713aSLionel Sambuc
70f4a2713aSLionel Sambuc static_assert(1, "abc");
71f4a2713aSLionel Sambuc }
72f4a2713aSLionel Sambuc
73*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void F(EmptyE e)
74f4a2713aSLionel Sambuc // CHECK: ENTRY
75f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
76f4a2713aSLionel Sambuc // CHECK: [B1]
77f4a2713aSLionel Sambuc // CHECK-NEXT: 1: e
78f4a2713aSLionel Sambuc // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, enum EmptyE)
79f4a2713aSLionel Sambuc // CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, IntegralCast, int)
80f4a2713aSLionel Sambuc // CHECK-NEXT: T: switch [B1.3]
81f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B2
82f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
83f4a2713aSLionel Sambuc // CHECK: [B0 (EXIT)]
84f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B1
85f4a2713aSLionel Sambuc enum EmptyE {};
F(EmptyE e)86f4a2713aSLionel Sambuc void F(EmptyE e) {
87f4a2713aSLionel Sambuc switch (e) {}
88f4a2713aSLionel Sambuc }
89f4a2713aSLionel Sambuc
90*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void testBuiltinSize()
91f4a2713aSLionel Sambuc // CHECK: ENTRY
92f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
93f4a2713aSLionel Sambuc // CHECK: [B1]
94f4a2713aSLionel Sambuc // CHECK-NEXT: 1: __builtin_object_size
95f4a2713aSLionel Sambuc // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, BuiltinFnToFnPtr, unsigned long (*)(const void *, int))
96f4a2713aSLionel Sambuc // CHECK-NEXT: 3: [B1.2](dummy(), 0)
97f4a2713aSLionel Sambuc // CHECK-NEXT: 4: (void)[B1.3] (CStyleCastExpr, ToVoid, void)
98f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B2
99f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
100f4a2713aSLionel Sambuc // CHECK: [B0 (EXIT)]
101f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B1
testBuiltinSize()102f4a2713aSLionel Sambuc void testBuiltinSize() {
103f4a2713aSLionel Sambuc extern int *dummy();
104f4a2713aSLionel Sambuc (void)__builtin_object_size(dummy(), 0);
105f4a2713aSLionel Sambuc }
106f4a2713aSLionel Sambuc
107f4a2713aSLionel Sambuc
108f4a2713aSLionel Sambuc class A {
109f4a2713aSLionel Sambuc public:
A()110f4a2713aSLionel Sambuc A() {}
~A()111f4a2713aSLionel Sambuc ~A() {}
112f4a2713aSLionel Sambuc };
113f4a2713aSLionel Sambuc
114*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void test_deletedtor()
115f4a2713aSLionel Sambuc // CHECK: [B2 (ENTRY)]
116f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
117f4a2713aSLionel Sambuc // CHECK: [B1]
118*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: CFGNewAllocator(A *)
119*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: (CXXConstructExpr, class A)
120*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: new A([B1.2])
121*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: A *a = new A();
122*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: a
123*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 6: [B1.5] (ImplicitCastExpr, LValueToRValue, class A *)
124*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 7: [B1.6]->~A() (Implicit destructor)
125*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 8: delete [B1.6]
126f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B2
127f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
128f4a2713aSLionel Sambuc // CHECK: [B0 (EXIT)]
129f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B1
test_deletedtor()130f4a2713aSLionel Sambuc void test_deletedtor() {
131f4a2713aSLionel Sambuc A *a = new A();
132f4a2713aSLionel Sambuc delete a;
133f4a2713aSLionel Sambuc }
134f4a2713aSLionel Sambuc
135*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void test_deleteArraydtor()
136f4a2713aSLionel Sambuc // CHECK: [B2 (ENTRY)]
137f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B1
138f4a2713aSLionel Sambuc // CHECK: [B1]
139f4a2713aSLionel Sambuc // CHECK-NEXT: 1: 5
140*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: CFGNewAllocator(A *)
141*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: (CXXConstructExpr, class A)
142*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: new A {{\[\[}}B1.1]]
143*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: A *a = new A [5];
144*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 6: a
145*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, LValueToRValue, class A *)
146*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 8: [B1.7]->~A() (Implicit destructor)
147*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 9: delete [] [B1.7]
148f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B2
149f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
150f4a2713aSLionel Sambuc // CHECK: [B0 (EXIT)]
151f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1): B1
test_deleteArraydtor()152f4a2713aSLionel Sambuc void test_deleteArraydtor() {
153f4a2713aSLionel Sambuc A *a = new A[5];
154f4a2713aSLionel Sambuc delete[] a;
155f4a2713aSLionel Sambuc }
156f4a2713aSLionel Sambuc
157f4a2713aSLionel Sambuc
158f4a2713aSLionel Sambuc namespace NoReturnSingleSuccessor {
159f4a2713aSLionel Sambuc struct A {
160f4a2713aSLionel Sambuc A();
161f4a2713aSLionel Sambuc ~A();
162f4a2713aSLionel Sambuc };
163f4a2713aSLionel Sambuc
164f4a2713aSLionel Sambuc struct B : public A {
165f4a2713aSLionel Sambuc B();
166f4a2713aSLionel Sambuc ~B() __attribute__((noreturn));
167f4a2713aSLionel Sambuc };
168f4a2713aSLionel Sambuc
169*0a6a1f1dSLionel Sambuc // CHECK-LABEL: int test1(int *x)
170f4a2713aSLionel Sambuc // CHECK: 1: 1
171f4a2713aSLionel Sambuc // CHECK-NEXT: 2: return
172f4a2713aSLionel Sambuc // CHECK-NEXT: ~B() (Implicit destructor)
173f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1)
174f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
test1(int * x)175f4a2713aSLionel Sambuc int test1(int *x) {
176f4a2713aSLionel Sambuc B b;
177f4a2713aSLionel Sambuc if (x)
178f4a2713aSLionel Sambuc return 1;
179f4a2713aSLionel Sambuc }
180f4a2713aSLionel Sambuc
181*0a6a1f1dSLionel Sambuc // CHECK-LABEL: int test2(int *x)
182f4a2713aSLionel Sambuc // CHECK: 1: 1
183f4a2713aSLionel Sambuc // CHECK-NEXT: 2: return
184f4a2713aSLionel Sambuc // CHECK-NEXT: destructor
185f4a2713aSLionel Sambuc // CHECK-NEXT: Preds (1)
186f4a2713aSLionel Sambuc // CHECK-NEXT: Succs (1): B0
test2(int * x)187f4a2713aSLionel Sambuc int test2(int *x) {
188f4a2713aSLionel Sambuc const A& a = B();
189f4a2713aSLionel Sambuc if (x)
190f4a2713aSLionel Sambuc return 1;
191f4a2713aSLionel Sambuc }
192f4a2713aSLionel Sambuc }
193*0a6a1f1dSLionel Sambuc
194*0a6a1f1dSLionel Sambuc // Test CFG support for "extending" an enum.
195*0a6a1f1dSLionel Sambuc // CHECK-LABEL: int test_enum_with_extension(enum MyEnum value)
196*0a6a1f1dSLionel Sambuc // CHECK: [B7 (ENTRY)]
197*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B2
198*0a6a1f1dSLionel Sambuc // CHECK: [B1]
199*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: x
200*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
201*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: return [B1.2];
202*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (5): B3 B4 B5 B6 B2(Unreachable)
203*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B0
204*0a6a1f1dSLionel Sambuc // CHECK: [B2]
205*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 0
206*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: int x = 0;
207*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: value
208*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
209*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
210*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: switch [B2.5]
211*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B7
212*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (5): B3 B4 B5 B6 B1(Unreachable)
213*0a6a1f1dSLionel Sambuc // CHECK: [B3]
214*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case D:
215*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 4
216*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
217*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B3.2] = [B3.1]
218*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
219*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
220*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
221*0a6a1f1dSLionel Sambuc // CHECK: [B4]
222*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case C:
223*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 3
224*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
225*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B4.2] = [B4.1]
226*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
227*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
228*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
229*0a6a1f1dSLionel Sambuc // CHECK: [B5]
230*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case B:
231*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 2
232*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
233*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B5.2] = [B5.1]
234*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
235*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
236*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
237*0a6a1f1dSLionel Sambuc // CHECK: [B6]
238*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case A:
239*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 1
240*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
241*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B6.2] = [B6.1]
242*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
243*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
244*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
245*0a6a1f1dSLionel Sambuc // CHECK: [B0 (EXIT)]
246*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B1
247*0a6a1f1dSLionel Sambuc enum MyEnum { A, B, C };
248*0a6a1f1dSLionel Sambuc static const enum MyEnum D = (enum MyEnum) 32;
249*0a6a1f1dSLionel Sambuc
test_enum_with_extension(enum MyEnum value)250*0a6a1f1dSLionel Sambuc int test_enum_with_extension(enum MyEnum value) {
251*0a6a1f1dSLionel Sambuc int x = 0;
252*0a6a1f1dSLionel Sambuc switch (value) {
253*0a6a1f1dSLionel Sambuc case A: x = 1; break;
254*0a6a1f1dSLionel Sambuc case B: x = 2; break;
255*0a6a1f1dSLionel Sambuc case C: x = 3; break;
256*0a6a1f1dSLionel Sambuc case D: x = 4; break;
257*0a6a1f1dSLionel Sambuc }
258*0a6a1f1dSLionel Sambuc return x;
259*0a6a1f1dSLionel Sambuc }
260*0a6a1f1dSLionel Sambuc
261*0a6a1f1dSLionel Sambuc // CHECK-LABEL: int test_enum_with_extension_default(enum MyEnum value)
262*0a6a1f1dSLionel Sambuc // CHECK: [B7 (ENTRY)]
263*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B2
264*0a6a1f1dSLionel Sambuc // CHECK: [B1]
265*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: x
266*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
267*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: return [B1.2];
268*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (4): B3 B4 B5 B6
269*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B0
270*0a6a1f1dSLionel Sambuc // CHECK: [B2]
271*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 0
272*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: int x = 0;
273*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: value
274*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: [B2.3] (ImplicitCastExpr, LValueToRValue, enum MyEnum)
275*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: [B2.4] (ImplicitCastExpr, IntegralCast, int)
276*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: switch [B2.5]
277*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B7
278*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (4): B4 B5 B6 B3(Unreachable)
279*0a6a1f1dSLionel Sambuc // CHECK: [B3]
280*0a6a1f1dSLionel Sambuc // CHECK-NEXT: default:
281*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 4
282*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
283*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B3.2] = [B3.1]
284*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
285*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2(Unreachable)
286*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
287*0a6a1f1dSLionel Sambuc // CHECK: [B4]
288*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case C:
289*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 3
290*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
291*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B4.2] = [B4.1]
292*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
293*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
294*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
295*0a6a1f1dSLionel Sambuc // CHECK: [B5]
296*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case B:
297*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 2
298*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
299*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B5.2] = [B5.1]
300*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
301*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
302*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
303*0a6a1f1dSLionel Sambuc // CHECK: [B6]
304*0a6a1f1dSLionel Sambuc // CHECK-NEXT: case A:
305*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 1
306*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: x
307*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B6.2] = [B6.1]
308*0a6a1f1dSLionel Sambuc // CHECK-NEXT: T: break;
309*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
310*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
311*0a6a1f1dSLionel Sambuc // CHECK: [B0 (EXIT)]
312*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B1
test_enum_with_extension_default(enum MyEnum value)313*0a6a1f1dSLionel Sambuc int test_enum_with_extension_default(enum MyEnum value) {
314*0a6a1f1dSLionel Sambuc int x = 0;
315*0a6a1f1dSLionel Sambuc switch (value) {
316*0a6a1f1dSLionel Sambuc case A: x = 1; break;
317*0a6a1f1dSLionel Sambuc case B: x = 2; break;
318*0a6a1f1dSLionel Sambuc case C: x = 3; break;
319*0a6a1f1dSLionel Sambuc default: x = 4; break;
320*0a6a1f1dSLionel Sambuc }
321*0a6a1f1dSLionel Sambuc return x;
322*0a6a1f1dSLionel Sambuc }
323*0a6a1f1dSLionel Sambuc
324*0a6a1f1dSLionel Sambuc
325*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void test_placement_new()
326*0a6a1f1dSLionel Sambuc // CHECK: [B2 (ENTRY)]
327*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
328*0a6a1f1dSLionel Sambuc // CHECK: [B1]
329*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: int buffer[16];
330*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: buffer
331*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
332*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
333*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: CFGNewAllocator(MyClass *)
334*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 6: (CXXConstructExpr, class MyClass)
335*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 7: new ([B1.4]) MyClass([B1.6])
336*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 8: MyClass *obj = new (buffer) MyClass();
337*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
338*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B0
339*0a6a1f1dSLionel Sambuc // CHECK: [B0 (EXIT)]
340*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B1
341*0a6a1f1dSLionel Sambuc
342*0a6a1f1dSLionel Sambuc extern void* operator new (unsigned long sz, void* v);
343*0a6a1f1dSLionel Sambuc extern void* operator new[] (unsigned long sz, void* ptr);
344*0a6a1f1dSLionel Sambuc
345*0a6a1f1dSLionel Sambuc class MyClass {
346*0a6a1f1dSLionel Sambuc public:
MyClass()347*0a6a1f1dSLionel Sambuc MyClass() {}
~MyClass()348*0a6a1f1dSLionel Sambuc ~MyClass() {}
349*0a6a1f1dSLionel Sambuc };
350*0a6a1f1dSLionel Sambuc
test_placement_new()351*0a6a1f1dSLionel Sambuc void test_placement_new() {
352*0a6a1f1dSLionel Sambuc int buffer[16];
353*0a6a1f1dSLionel Sambuc MyClass* obj = new (buffer) MyClass();
354*0a6a1f1dSLionel Sambuc }
355*0a6a1f1dSLionel Sambuc
356*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void test_placement_new_array()
357*0a6a1f1dSLionel Sambuc // CHECK: [B2 (ENTRY)]
358*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
359*0a6a1f1dSLionel Sambuc // CHECK: [B1]
360*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: int buffer[16];
361*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: buffer
362*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
363*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
364*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: 5
365*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 6: CFGNewAllocator(MyClass *)
366*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 7: (CXXConstructExpr, class MyClass)
367*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 8: new ([B1.4]) MyClass {{\[\[}}B1.5]]
368*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 9: MyClass *obj = new (buffer) MyClass [5];
369*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
370*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B0
371*0a6a1f1dSLionel Sambuc // CHECK: [B0 (EXIT)]
372*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B1
373*0a6a1f1dSLionel Sambuc
test_placement_new_array()374*0a6a1f1dSLionel Sambuc void test_placement_new_array() {
375*0a6a1f1dSLionel Sambuc int buffer[16];
376*0a6a1f1dSLionel Sambuc MyClass* obj = new (buffer) MyClass[5];
377*0a6a1f1dSLionel Sambuc }
378*0a6a1f1dSLionel Sambuc
379*0a6a1f1dSLionel Sambuc
380*0a6a1f1dSLionel Sambuc // CHECK-LABEL: void test_lifetime_extended_temporaries()
381*0a6a1f1dSLionel Sambuc // CHECK: [B1]
382*0a6a1f1dSLionel Sambuc struct LifetimeExtend { LifetimeExtend(int); ~LifetimeExtend(); };
383*0a6a1f1dSLionel Sambuc struct Aggregate { const LifetimeExtend a; const LifetimeExtend b; };
384*0a6a1f1dSLionel Sambuc struct AggregateRef { const LifetimeExtend &a; const LifetimeExtend &b; };
test_lifetime_extended_temporaries()385*0a6a1f1dSLionel Sambuc void test_lifetime_extended_temporaries() {
386*0a6a1f1dSLionel Sambuc // CHECK: LifetimeExtend(1);
387*0a6a1f1dSLionel Sambuc // CHECK-NEXT: : 1
388*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ~LifetimeExtend()
389*0a6a1f1dSLionel Sambuc // CHECK-NOT: ~LifetimeExtend()
390*0a6a1f1dSLionel Sambuc {
391*0a6a1f1dSLionel Sambuc const LifetimeExtend &l = LifetimeExtend(1);
392*0a6a1f1dSLionel Sambuc 1;
393*0a6a1f1dSLionel Sambuc }
394*0a6a1f1dSLionel Sambuc // CHECK: LifetimeExtend(2)
395*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ~LifetimeExtend()
396*0a6a1f1dSLionel Sambuc // CHECK-NEXT: : 2
397*0a6a1f1dSLionel Sambuc // CHECK-NOT: ~LifetimeExtend()
398*0a6a1f1dSLionel Sambuc {
399*0a6a1f1dSLionel Sambuc // No life-time extension.
400*0a6a1f1dSLionel Sambuc const int &l = (LifetimeExtend(2), 2);
401*0a6a1f1dSLionel Sambuc 2;
402*0a6a1f1dSLionel Sambuc }
403*0a6a1f1dSLionel Sambuc // CHECK: LifetimeExtend(3)
404*0a6a1f1dSLionel Sambuc // CHECK-NEXT: : 3
405*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ~LifetimeExtend()
406*0a6a1f1dSLionel Sambuc // CHECK-NOT: ~LifetimeExtend()
407*0a6a1f1dSLionel Sambuc {
408*0a6a1f1dSLionel Sambuc // The last one is lifetime extended.
409*0a6a1f1dSLionel Sambuc const LifetimeExtend &l = (3, LifetimeExtend(3));
410*0a6a1f1dSLionel Sambuc 3;
411*0a6a1f1dSLionel Sambuc }
412*0a6a1f1dSLionel Sambuc // CHECK: LifetimeExtend(4)
413*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ~LifetimeExtend()
414*0a6a1f1dSLionel Sambuc // CHECK-NEXT: ~LifetimeExtend()
415*0a6a1f1dSLionel Sambuc // CHECK-NEXT: : 4
416*0a6a1f1dSLionel Sambuc // CHECK-NOT: ~LifetimeExtend()
417*0a6a1f1dSLionel Sambuc {
418*0a6a1f1dSLionel Sambuc Aggregate a{LifetimeExtend(4), LifetimeExtend(4)};
419*0a6a1f1dSLionel Sambuc 4;
420*0a6a1f1dSLionel Sambuc }
421*0a6a1f1dSLionel Sambuc // CHECK: LifetimeExtend(5)
422*0a6a1f1dSLionel Sambuc // CHECK-NEXT: : 5
423*0a6a1f1dSLionel Sambuc // FIXME: We want to emit the destructors of the lifetime
424*0a6a1f1dSLionel Sambuc // extended variables here.
425*0a6a1f1dSLionel Sambuc // CHECK-NOT: ~LifetimeExtend()
426*0a6a1f1dSLionel Sambuc {
427*0a6a1f1dSLionel Sambuc AggregateRef a{LifetimeExtend(5), LifetimeExtend(5)};
428*0a6a1f1dSLionel Sambuc 5;
429*0a6a1f1dSLionel Sambuc }
430*0a6a1f1dSLionel Sambuc // FIXME: Add tests for lifetime extension via subobject
431*0a6a1f1dSLionel Sambuc // references (LifetimeExtend().some_member).
432*0a6a1f1dSLionel Sambuc }
433*0a6a1f1dSLionel Sambuc
434*0a6a1f1dSLionel Sambuc
435*0a6a1f1dSLionel Sambuc // CHECK-LABEL: int *PR18472()
436*0a6a1f1dSLionel Sambuc // CHECK: [B2 (ENTRY)]
437*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B1
438*0a6a1f1dSLionel Sambuc // CHECK: [B1]
439*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 1: 0
440*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, PR18472_t)
441*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 3: (PR18472_t)[B1.2] (CStyleCastExpr, NoOp, PR18472_t)
442*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 4: CFGNewAllocator(int *)
443*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 5: new (([B1.3])) int
444*0a6a1f1dSLionel Sambuc // CHECK-NEXT: 6: return [B1.5];
445*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B2
446*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Succs (1): B0
447*0a6a1f1dSLionel Sambuc // CHECK: [B0 (EXIT)]
448*0a6a1f1dSLionel Sambuc // CHECK-NEXT: Preds (1): B1
449*0a6a1f1dSLionel Sambuc
450*0a6a1f1dSLionel Sambuc extern "C" typedef int *PR18472_t;
451*0a6a1f1dSLionel Sambuc void *operator new (unsigned long, PR18472_t);
PR18472()452*0a6a1f1dSLionel Sambuc template <class T> T *PR18472() {
453*0a6a1f1dSLionel Sambuc return new (((PR18472_t) 0)) T;
454*0a6a1f1dSLionel Sambuc }
PR18472_helper()455*0a6a1f1dSLionel Sambuc void PR18472_helper() {
456*0a6a1f1dSLionel Sambuc PR18472<int>();
457*0a6a1f1dSLionel Sambuc }
458*0a6a1f1dSLionel Sambuc
459