xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/arm.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=thumbv7-apple-ios3.0 -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -o - -fexceptions | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // CHECK: @_ZZN5test74testEvE1x = internal global i32 0, align 4
4*f4a2713aSLionel Sambuc // CHECK: @_ZGVZN5test74testEvE1x = internal global i32 0
5*f4a2713aSLionel Sambuc // CHECK: @_ZZN5test84testEvE1x = internal global [[TEST8A:.*]] zeroinitializer, align 1
6*f4a2713aSLionel Sambuc // CHECK: @_ZGVZN5test84testEvE1x = internal global i32 0
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc typedef typeof(sizeof(int)) size_t;
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc class foo {
11*f4a2713aSLionel Sambuc public:
12*f4a2713aSLionel Sambuc     foo();
13*f4a2713aSLionel Sambuc     virtual ~foo();
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc class bar : public foo {
17*f4a2713aSLionel Sambuc public:
18*f4a2713aSLionel Sambuc 	bar();
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc // The global dtor needs the right calling conv with -fno-use-cxa-atexit
22*f4a2713aSLionel Sambuc // rdar://7817590
23*f4a2713aSLionel Sambuc bar baz;
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc // PR9593
26*f4a2713aSLionel Sambuc // Make sure atexit(3) is used for global dtors.
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // CHECK:      call [[BAR:%.*]]* @_ZN3barC1Ev(
29*f4a2713aSLionel Sambuc // CHECK-NEXT: call i32 @atexit(void ()* @__dtor_baz)
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__dtor_baz()
32*f4a2713aSLionel Sambuc // CHECK: call [[BAR]]* @_ZN3barD1Ev([[BAR]]* @baz)
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc // Destructors and constructors must return this.
35*f4a2713aSLionel Sambuc namespace test1 {
36*f4a2713aSLionel Sambuc   void foo();
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc   struct A {
39*f4a2713aSLionel Sambuc     A(int i) { foo(); }
40*f4a2713aSLionel Sambuc     ~A() { foo(); }
41*f4a2713aSLionel Sambuc     void bar() { foo(); }
42*f4a2713aSLionel Sambuc   };
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test14testEv()
45*f4a2713aSLionel Sambuc   void test() {
46*f4a2713aSLionel Sambuc     // CHECK: [[AV:%.*]] = alloca [[A:%.*]], align 1
47*f4a2713aSLionel Sambuc     // CHECK: call [[A]]* @_ZN5test11AC1Ei([[A]]* [[AV]], i32 10)
48*f4a2713aSLionel Sambuc     // CHECK: invoke void @_ZN5test11A3barEv([[A]]* [[AV]])
49*f4a2713aSLionel Sambuc     // CHECK: call [[A]]* @_ZN5test11AD1Ev([[A]]* [[AV]])
50*f4a2713aSLionel Sambuc     // CHECK: ret void
51*f4a2713aSLionel Sambuc     A a = 10;
52*f4a2713aSLionel Sambuc     a.bar();
53*f4a2713aSLionel Sambuc   }
54*f4a2713aSLionel Sambuc 
55*f4a2713aSLionel Sambuc   // CHECK: define linkonce_odr [[A]]* @_ZN5test11AC1Ei([[A]]* returned %this, i32 %i) unnamed_addr
56*f4a2713aSLionel Sambuc   // CHECK:   [[THIS:%.*]] = alloca [[A]]*, align 4
57*f4a2713aSLionel Sambuc   // CHECK:   store [[A]]* {{.*}}, [[A]]** [[THIS]]
58*f4a2713aSLionel Sambuc   // CHECK:   [[THIS1:%.*]] = load [[A]]** [[THIS]]
59*f4a2713aSLionel Sambuc   // CHECK:   {{%.*}} = call [[A]]* @_ZN5test11AC2Ei(
60*f4a2713aSLionel Sambuc   // CHECK:   ret [[A]]* [[THIS1]]
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc   // CHECK: define linkonce_odr [[A]]* @_ZN5test11AD1Ev([[A]]* returned %this) unnamed_addr
63*f4a2713aSLionel Sambuc   // CHECK:   [[THIS:%.*]] = alloca [[A]]*, align 4
64*f4a2713aSLionel Sambuc   // CHECK:   store [[A]]* {{.*}}, [[A]]** [[THIS]]
65*f4a2713aSLionel Sambuc   // CHECK:   [[THIS1:%.*]] = load [[A]]** [[THIS]]
66*f4a2713aSLionel Sambuc   // CHECK:   {{%.*}} = call [[A]]* @_ZN5test11AD2Ev(
67*f4a2713aSLionel Sambuc   // CHECK:   ret [[A]]* [[THIS1]]
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc // Awkward virtual cases.
71*f4a2713aSLionel Sambuc namespace test2 {
72*f4a2713aSLionel Sambuc   void foo();
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc   struct A {
75*f4a2713aSLionel Sambuc     int x;
76*f4a2713aSLionel Sambuc 
77*f4a2713aSLionel Sambuc     A(int);
78*f4a2713aSLionel Sambuc     virtual ~A() { foo(); }
79*f4a2713aSLionel Sambuc   };
80*f4a2713aSLionel Sambuc 
81*f4a2713aSLionel Sambuc   struct B {
82*f4a2713aSLionel Sambuc     int y;
83*f4a2713aSLionel Sambuc     int z;
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc     B(int);
86*f4a2713aSLionel Sambuc     virtual ~B() { foo(); }
87*f4a2713aSLionel Sambuc   };
88*f4a2713aSLionel Sambuc 
89*f4a2713aSLionel Sambuc   struct C : A, virtual B {
90*f4a2713aSLionel Sambuc     int q;
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc     C(int i) : A(i), B(i) { foo(); }
93*f4a2713aSLionel Sambuc     ~C() { foo(); }
94*f4a2713aSLionel Sambuc   };
95*f4a2713aSLionel Sambuc 
96*f4a2713aSLionel Sambuc   void test() {
97*f4a2713aSLionel Sambuc     C c = 10;
98*f4a2713aSLionel Sambuc   }
99*f4a2713aSLionel Sambuc 
100*f4a2713aSLionel Sambuc   // Tests at eof
101*f4a2713aSLionel Sambuc }
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc namespace test3 {
104*f4a2713aSLionel Sambuc   struct A {
105*f4a2713aSLionel Sambuc     int x;
106*f4a2713aSLionel Sambuc     ~A();
107*f4a2713aSLionel Sambuc   };
108*f4a2713aSLionel Sambuc 
109*f4a2713aSLionel Sambuc   void a() {
110*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31aEv()
111*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 48)
112*f4a2713aSLionel Sambuc     // CHECK: store i32 4
113*f4a2713aSLionel Sambuc     // CHECK: store i32 10
114*f4a2713aSLionel Sambuc     A *x = new A[10];
115*f4a2713aSLionel Sambuc   }
116*f4a2713aSLionel Sambuc 
117*f4a2713aSLionel Sambuc   void b(int n) {
118*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31bEi(
119*f4a2713aSLionel Sambuc     // CHECK: [[N:%.*]] = load i32*
120*f4a2713aSLionel Sambuc     // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
121*f4a2713aSLionel Sambuc     // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
122*f4a2713aSLionel Sambuc     // CHECK: [[OR:%.*]] = or i1
123*f4a2713aSLionel Sambuc     // CHECK: [[SZ:%.*]] = select i1 [[OR]]
124*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 [[SZ]])
125*f4a2713aSLionel Sambuc     // CHECK: store i32 4
126*f4a2713aSLionel Sambuc     // CHECK: store i32 [[N]]
127*f4a2713aSLionel Sambuc     A *x = new A[n];
128*f4a2713aSLionel Sambuc   }
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc   void c() {
131*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31cEv()
132*f4a2713aSLionel Sambuc     // CHECK: call  noalias i8* @_Znam(i32 808)
133*f4a2713aSLionel Sambuc     // CHECK: store i32 4
134*f4a2713aSLionel Sambuc     // CHECK: store i32 200
135*f4a2713aSLionel Sambuc     A (*x)[20] = new A[10][20];
136*f4a2713aSLionel Sambuc   }
137*f4a2713aSLionel Sambuc 
138*f4a2713aSLionel Sambuc   void d(int n) {
139*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31dEi(
140*f4a2713aSLionel Sambuc     // CHECK: [[N:%.*]] = load i32*
141*f4a2713aSLionel Sambuc     // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
142*f4a2713aSLionel Sambuc     // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
143*f4a2713aSLionel Sambuc     // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
144*f4a2713aSLionel Sambuc     // CHECK: [[SZ:%.*]] = select
145*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 [[SZ]])
146*f4a2713aSLionel Sambuc     // CHECK: store i32 4
147*f4a2713aSLionel Sambuc     // CHECK: store i32 [[NE]]
148*f4a2713aSLionel Sambuc     A (*x)[20] = new A[n][20];
149*f4a2713aSLionel Sambuc   }
150*f4a2713aSLionel Sambuc 
151*f4a2713aSLionel Sambuc   void e(A *x) {
152*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31eEPNS_1AE(
153*f4a2713aSLionel Sambuc     // CHECK: icmp eq {{.*}}, null
154*f4a2713aSLionel Sambuc     // CHECK: getelementptr {{.*}}, i64 -8
155*f4a2713aSLionel Sambuc     // CHECK: getelementptr {{.*}}, i64 4
156*f4a2713aSLionel Sambuc     // CHECK: bitcast {{.*}} to i32*
157*f4a2713aSLionel Sambuc     // CHECK: load
158*f4a2713aSLionel Sambuc     // CHECK: invoke {{.*}} @_ZN5test31AD1Ev
159*f4a2713aSLionel Sambuc     // CHECK: call void @_ZdaPv
160*f4a2713aSLionel Sambuc     delete [] x;
161*f4a2713aSLionel Sambuc   }
162*f4a2713aSLionel Sambuc 
163*f4a2713aSLionel Sambuc   void f(A (*x)[20]) {
164*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test31fEPA20_NS_1AE(
165*f4a2713aSLionel Sambuc     // CHECK: icmp eq {{.*}}, null
166*f4a2713aSLionel Sambuc     // CHECK: getelementptr {{.*}}, i64 -8
167*f4a2713aSLionel Sambuc     // CHECK: getelementptr {{.*}}, i64 4
168*f4a2713aSLionel Sambuc     // CHECK: bitcast {{.*}} to i32*
169*f4a2713aSLionel Sambuc     // CHECK: load
170*f4a2713aSLionel Sambuc     // CHECK: invoke {{.*}} @_ZN5test31AD1Ev
171*f4a2713aSLionel Sambuc     // CHECK: call void @_ZdaPv
172*f4a2713aSLionel Sambuc     delete [] x;
173*f4a2713aSLionel Sambuc   }
174*f4a2713aSLionel Sambuc }
175*f4a2713aSLionel Sambuc 
176*f4a2713aSLionel Sambuc namespace test4 {
177*f4a2713aSLionel Sambuc   struct A {
178*f4a2713aSLionel Sambuc     int x;
179*f4a2713aSLionel Sambuc     void operator delete[](void *, size_t sz);
180*f4a2713aSLionel Sambuc   };
181*f4a2713aSLionel Sambuc 
182*f4a2713aSLionel Sambuc   void a() {
183*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41aEv()
184*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 48)
185*f4a2713aSLionel Sambuc     // CHECK: store i32 4
186*f4a2713aSLionel Sambuc     // CHECK: store i32 10
187*f4a2713aSLionel Sambuc     A *x = new A[10];
188*f4a2713aSLionel Sambuc   }
189*f4a2713aSLionel Sambuc 
190*f4a2713aSLionel Sambuc   void b(int n) {
191*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41bEi(
192*f4a2713aSLionel Sambuc     // CHECK: [[N:%.*]] = load i32*
193*f4a2713aSLionel Sambuc     // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
194*f4a2713aSLionel Sambuc     // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
195*f4a2713aSLionel Sambuc     // CHECK: [[SZ:%.*]] = select
196*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 [[SZ]])
197*f4a2713aSLionel Sambuc     // CHECK: store i32 4
198*f4a2713aSLionel Sambuc     // CHECK: store i32 [[N]]
199*f4a2713aSLionel Sambuc     A *x = new A[n];
200*f4a2713aSLionel Sambuc   }
201*f4a2713aSLionel Sambuc 
202*f4a2713aSLionel Sambuc   void c() {
203*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41cEv()
204*f4a2713aSLionel Sambuc     // CHECK: call  noalias i8* @_Znam(i32 808)
205*f4a2713aSLionel Sambuc     // CHECK: store i32 4
206*f4a2713aSLionel Sambuc     // CHECK: store i32 200
207*f4a2713aSLionel Sambuc     A (*x)[20] = new A[10][20];
208*f4a2713aSLionel Sambuc   }
209*f4a2713aSLionel Sambuc 
210*f4a2713aSLionel Sambuc   void d(int n) {
211*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41dEi(
212*f4a2713aSLionel Sambuc     // CHECK: [[N:%.*]] = load i32*
213*f4a2713aSLionel Sambuc     // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
214*f4a2713aSLionel Sambuc     // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
215*f4a2713aSLionel Sambuc     // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
216*f4a2713aSLionel Sambuc     // CHECK: [[SZ:%.*]] = select
217*f4a2713aSLionel Sambuc     // CHECK: call noalias i8* @_Znam(i32 [[SZ]])
218*f4a2713aSLionel Sambuc     // CHECK: store i32 4
219*f4a2713aSLionel Sambuc     // CHECK: store i32 [[NE]]
220*f4a2713aSLionel Sambuc     A (*x)[20] = new A[n][20];
221*f4a2713aSLionel Sambuc   }
222*f4a2713aSLionel Sambuc 
223*f4a2713aSLionel Sambuc   void e(A *x) {
224*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41eEPNS_1AE(
225*f4a2713aSLionel Sambuc     // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i64 -8
226*f4a2713aSLionel Sambuc     // CHECK: getelementptr inbounds {{.*}}, i64 4
227*f4a2713aSLionel Sambuc     // CHECK: bitcast
228*f4a2713aSLionel Sambuc     // CHECK: [[T0:%.*]] = load i32*
229*f4a2713aSLionel Sambuc     // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
230*f4a2713aSLionel Sambuc     // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
231*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
232*f4a2713aSLionel Sambuc     delete [] x;
233*f4a2713aSLionel Sambuc   }
234*f4a2713aSLionel Sambuc 
235*f4a2713aSLionel Sambuc   void f(A (*x)[20]) {
236*f4a2713aSLionel Sambuc     // CHECK-LABEL: define void @_ZN5test41fEPA20_NS_1AE(
237*f4a2713aSLionel Sambuc     // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i64 -8
238*f4a2713aSLionel Sambuc     // CHECK: getelementptr inbounds {{.*}}, i64 4
239*f4a2713aSLionel Sambuc     // CHECK: bitcast
240*f4a2713aSLionel Sambuc     // CHECK: [[T0:%.*]] = load i32*
241*f4a2713aSLionel Sambuc     // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
242*f4a2713aSLionel Sambuc     // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
243*f4a2713aSLionel Sambuc     // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
244*f4a2713aSLionel Sambuc     delete [] x;
245*f4a2713aSLionel Sambuc   }
246*f4a2713aSLionel Sambuc }
247*f4a2713aSLionel Sambuc 
248*f4a2713aSLionel Sambuc // <rdar://problem/8386802>: don't crash
249*f4a2713aSLionel Sambuc namespace test5 {
250*f4a2713aSLionel Sambuc   struct A {
251*f4a2713aSLionel Sambuc     ~A();
252*f4a2713aSLionel Sambuc   };
253*f4a2713aSLionel Sambuc 
254*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test54testEPNS_1AE
255*f4a2713aSLionel Sambuc   void test(A *a) {
256*f4a2713aSLionel Sambuc     // CHECK:      [[PTR:%.*]] = alloca [[A:%.*]]*, align 4
257*f4a2713aSLionel Sambuc     // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[PTR]], align 4
258*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[TMP:%.*]] = load [[A]]** [[PTR]], align 4
259*f4a2713aSLionel Sambuc     // CHECK-NEXT: call [[A]]* @_ZN5test51AD1Ev([[A]]* [[TMP]])
260*f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
261*f4a2713aSLionel Sambuc     a->~A();
262*f4a2713aSLionel Sambuc   }
263*f4a2713aSLionel Sambuc }
264*f4a2713aSLionel Sambuc 
265*f4a2713aSLionel Sambuc namespace test6 {
266*f4a2713aSLionel Sambuc   struct A {
267*f4a2713aSLionel Sambuc     virtual ~A();
268*f4a2713aSLionel Sambuc   };
269*f4a2713aSLionel Sambuc 
270*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test64testEPNS_1AE
271*f4a2713aSLionel Sambuc   void test(A *a) {
272*f4a2713aSLionel Sambuc     // CHECK:      [[AVAR:%.*]] = alloca [[A:%.*]]*, align 4
273*f4a2713aSLionel Sambuc     // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[AVAR]], align 4
274*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[V:%.*]] = load [[A]]** [[AVAR]], align 4
275*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq [[A]]* [[V]], null
276*f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[ISNULL]]
277*f4a2713aSLionel Sambuc     // CHECK:      [[T0:%.*]] = bitcast [[A]]* [[V]] to void ([[A]]*)***
278*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T1:%.*]] = load void ([[A]]*)*** [[T0]]
279*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds void ([[A]]*)** [[T1]], i64 1
280*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T3:%.*]] = load void ([[A]]*)** [[T2]]
281*f4a2713aSLionel Sambuc     // CHECK-NEXT: call void [[T3]]([[A]]* [[V]])
282*f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
283*f4a2713aSLionel Sambuc     // CHECK:      ret void
284*f4a2713aSLionel Sambuc     delete a;
285*f4a2713aSLionel Sambuc   }
286*f4a2713aSLionel Sambuc }
287*f4a2713aSLionel Sambuc 
288*f4a2713aSLionel Sambuc namespace test7 {
289*f4a2713aSLionel Sambuc   int foo();
290*f4a2713aSLionel Sambuc 
291*f4a2713aSLionel Sambuc   // Static and guard tested at top of file
292*f4a2713aSLionel Sambuc 
293*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test74testEv()
294*f4a2713aSLionel Sambuc   void test() {
295*f4a2713aSLionel Sambuc     // CHECK:      [[T0:%.*]] = load i32* @_ZGVZN5test74testEvE1x
296*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], 1
297*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
298*f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[T2]]
299*f4a2713aSLionel Sambuc     //   -> fallthrough, end
300*f4a2713aSLionel Sambuc     // CHECK:      [[T3:%.*]] = call i32 @__cxa_guard_acquire(i32* @_ZGVZN5test74testEvE1x)
301*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T4:%.*]] = icmp ne i32 [[T3]], 0
302*f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[T4]]
303*f4a2713aSLionel Sambuc     //   -> fallthrough, end
304*f4a2713aSLionel Sambuc     // CHECK:      [[INIT:%.*]] = invoke i32 @_ZN5test73fooEv()
305*f4a2713aSLionel Sambuc     // CHECK:      store i32 [[INIT]], i32* @_ZZN5test74testEvE1x, align 4
306*f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @__cxa_guard_release(i32* @_ZGVZN5test74testEvE1x)
307*f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
308*f4a2713aSLionel Sambuc     //   -> end
309*f4a2713aSLionel Sambuc     // end:
310*f4a2713aSLionel Sambuc     // CHECK:      ret void
311*f4a2713aSLionel Sambuc     static int x = foo();
312*f4a2713aSLionel Sambuc 
313*f4a2713aSLionel Sambuc     // CHECK:      landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
314*f4a2713aSLionel Sambuc     // CHECK-NEXT:   cleanup
315*f4a2713aSLionel Sambuc     // CHECK:      call void @__cxa_guard_abort(i32* @_ZGVZN5test74testEvE1x)
316*f4a2713aSLionel Sambuc     // CHECK:      resume { i8*, i32 }
317*f4a2713aSLionel Sambuc   }
318*f4a2713aSLionel Sambuc }
319*f4a2713aSLionel Sambuc 
320*f4a2713aSLionel Sambuc namespace test8 {
321*f4a2713aSLionel Sambuc   struct A {
322*f4a2713aSLionel Sambuc     A();
323*f4a2713aSLionel Sambuc     ~A();
324*f4a2713aSLionel Sambuc   };
325*f4a2713aSLionel Sambuc 
326*f4a2713aSLionel Sambuc   // Static and guard tested at top of file
327*f4a2713aSLionel Sambuc 
328*f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN5test84testEv()
329*f4a2713aSLionel Sambuc   void test() {
330*f4a2713aSLionel Sambuc     // CHECK:      [[T0:%.*]] = load i32* @_ZGVZN5test84testEvE1x
331*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T1:%.*]] = and i32 [[T0]], 1
332*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
333*f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[T2]]
334*f4a2713aSLionel Sambuc     //   -> fallthrough, end
335*f4a2713aSLionel Sambuc     // CHECK:      [[T3:%.*]] = call i32 @__cxa_guard_acquire(i32* @_ZGVZN5test84testEvE1x)
336*f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T4:%.*]] = icmp ne i32 [[T3]], 0
337*f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[T4]]
338*f4a2713aSLionel Sambuc     //   -> fallthrough, end
339*f4a2713aSLionel Sambuc     // CHECK:      [[INIT:%.*]] = invoke [[TEST8A]]* @_ZN5test81AC1Ev([[TEST8A]]* @_ZZN5test84testEvE1x)
340*f4a2713aSLionel Sambuc 
341*f4a2713aSLionel Sambuc     // FIXME: Here we register a global destructor that
342*f4a2713aSLionel Sambuc     // unconditionally calls the destructor.  That's what we've always
343*f4a2713aSLionel Sambuc     // done for -fno-use-cxa-atexit here, but that's really not
344*f4a2713aSLionel Sambuc     // semantically correct at all.
345*f4a2713aSLionel Sambuc 
346*f4a2713aSLionel Sambuc     // CHECK:      call void @__cxa_guard_release(i32* @_ZGVZN5test84testEvE1x)
347*f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
348*f4a2713aSLionel Sambuc     //   -> end
349*f4a2713aSLionel Sambuc     // end:
350*f4a2713aSLionel Sambuc     // CHECK:      ret void
351*f4a2713aSLionel Sambuc     static A x;
352*f4a2713aSLionel Sambuc 
353*f4a2713aSLionel Sambuc     // CHECK:      landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
354*f4a2713aSLionel Sambuc     // CHECK-NEXT:   cleanup
355*f4a2713aSLionel Sambuc     // CHECK:      call void @__cxa_guard_abort(i32* @_ZGVZN5test84testEvE1x)
356*f4a2713aSLionel Sambuc     // CHECK:      resume { i8*, i32 }
357*f4a2713aSLionel Sambuc   }
358*f4a2713aSLionel Sambuc }
359*f4a2713aSLionel Sambuc 
360*f4a2713aSLionel Sambuc //   rdar://12836470
361*f4a2713aSLionel Sambuc // Use a larger-than-mandated array cookie when allocating an
362*f4a2713aSLionel Sambuc // array whose type is overaligned.
363*f4a2713aSLionel Sambuc namespace test9 {
364*f4a2713aSLionel Sambuc   class __attribute__((aligned(16))) A {
365*f4a2713aSLionel Sambuc     float data[4];
366*f4a2713aSLionel Sambuc   public:
367*f4a2713aSLionel Sambuc     A();
368*f4a2713aSLionel Sambuc     ~A();
369*f4a2713aSLionel Sambuc   };
370*f4a2713aSLionel Sambuc 
371*f4a2713aSLionel Sambuc   A *testNew(unsigned n) {
372*f4a2713aSLionel Sambuc     return new A[n];
373*f4a2713aSLionel Sambuc   }
374*f4a2713aSLionel Sambuc // CHECK:    define [[TEST9:%.*]]* @_ZN5test97testNewEj(i32
375*f4a2713aSLionel Sambuc // CHECK:      [[N_VAR:%.*]] = alloca i32, align 4
376*f4a2713aSLionel Sambuc // CHECK:      [[N:%.*]] = load i32* [[N_VAR]], align 4
377*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 16)
378*f4a2713aSLionel Sambuc // CHECK-NEXT: [[O0:%.*]] = extractvalue { i32, i1 } [[T0]], 1
379*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 0
380*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[T1]], i32 16)
381*f4a2713aSLionel Sambuc // CHECK-NEXT: [[O1:%.*]] = extractvalue { i32, i1 } [[T2]], 1
382*f4a2713aSLionel Sambuc // CHECK-NEXT: [[OVERFLOW:%.*]] = or i1 [[O0]], [[O1]]
383*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
384*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T4:%.*]] = select i1 [[OVERFLOW]], i32 -1, i32 [[T3]]
385*f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = call noalias i8* @_Znam(i32 [[T4]])
386*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[ALLOC]] to i32*
387*f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 16, i32* [[T0]]
388*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i32* [[T0]], i32 1
389*f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 [[N]], i32* [[T1]]
390*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8* [[ALLOC]], i64 16
391*f4a2713aSLionel Sambuc // CHECK-NEXT: bitcast i8* [[T0]] to [[TEST9]]*
392*f4a2713aSLionel Sambuc //   Array allocation follows.
393*f4a2713aSLionel Sambuc 
394*f4a2713aSLionel Sambuc   void testDelete(A *array) {
395*f4a2713aSLionel Sambuc     delete[] array;
396*f4a2713aSLionel Sambuc   }
397*f4a2713aSLionel Sambuc // CHECK-LABEL:    define void @_ZN5test910testDeleteEPNS_1AE(
398*f4a2713aSLionel Sambuc // CHECK:      [[BEGIN:%.*]] = load [[TEST9]]**
399*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], null
400*f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T0]],
401*f4a2713aSLionel Sambuc // CHECK:      [[T0:%.*]] = bitcast [[TEST9]]* [[BEGIN]] to i8*
402*f4a2713aSLionel Sambuc // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8* [[T0]], i64 -16
403*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8* [[ALLOC]], i64 4
404*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i32*
405*f4a2713aSLionel Sambuc // CHECK-NEXT: [[N:%.*]] = load i32* [[T1]]
406*f4a2713aSLionel Sambuc // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[TEST9]]* [[BEGIN]], i32 [[N]]
407*f4a2713aSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], [[END]]
408*f4a2713aSLionel Sambuc // CHECK-NEXT: br i1 [[T0]],
409*f4a2713aSLionel Sambuc //   Array deallocation follows.
410*f4a2713aSLionel Sambuc }
411*f4a2713aSLionel Sambuc 
412*f4a2713aSLionel Sambuc   // CHECK: define linkonce_odr [[C:%.*]]* @_ZTv0_n12_N5test21CD1Ev(
413*f4a2713aSLionel Sambuc   // CHECK:   call [[C]]* @_ZN5test21CD1Ev(
414*f4a2713aSLionel Sambuc   // CHECK:   ret [[C]]* undef
415*f4a2713aSLionel Sambuc 
416*f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr void @_ZTv0_n12_N5test21CD0Ev(
417*f4a2713aSLionel Sambuc   // CHECK:   call void @_ZN5test21CD0Ev(
418*f4a2713aSLionel Sambuc   // CHECK:   ret void
419*f4a2713aSLionel Sambuc 
420*f4a2713aSLionel Sambuc // CH_ECK: @_GLOBAL__D_a()
421*f4a2713aSLionel Sambuc // CH_ECK: call %class.bar* @_ZN3barD1Ev(%class.bar* @baz)
422