blob: 7eba017e37f235fb4a1069d88f86773220479bc8 [file] [log] [blame]
Charles Lifad02412017-01-09 18:24:16 +00001// RUN: %clang_cc1 %s -triple=thumbv7-apple-ios6.0 -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -std=gnu++98 -o - -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK98 %s
2// RUN: %clang_cc1 %s -triple=thumbv7-apple-ios6.0 -fno-use-cxa-atexit -target-abi apcs-gnu -emit-llvm -std=gnu++11 -o - -fexceptions | FileCheck -check-prefix=CHECK -check-prefix=CHECK11 %s
John McCall8ed55a52010-09-02 09:58:18 +00003
John McCall68ff0372010-09-08 01:44:27 +00004// CHECK: @_ZZN5test74testEvE1x = internal global i32 0, align 4
5// CHECK: @_ZGVZN5test74testEvE1x = internal global i32 0
6// CHECK: @_ZZN5test84testEvE1x = internal global [[TEST8A:.*]] zeroinitializer, align 1
7// CHECK: @_ZGVZN5test84testEvE1x = internal global i32 0
8
John McCall8ed55a52010-09-02 09:58:18 +00009typedef typeof(sizeof(int)) size_t;
Chris Lattner5e8416a2010-04-26 20:35:54 +000010
11class foo {
12public:
13 foo();
14 virtual ~foo();
15};
16
17class bar : public foo {
18public:
19 bar();
20};
21
22// The global dtor needs the right calling conv with -fno-use-cxa-atexit
23// rdar://7817590
24bar baz;
25
John McCall76cc43a2012-04-06 18:21:06 +000026// PR9593
27// Make sure atexit(3) is used for global dtors.
28
29// CHECK: call [[BAR:%.*]]* @_ZN3barC1Ev(
30// CHECK-NEXT: call i32 @atexit(void ()* @__dtor_baz)
31
Nico Weber3bf77c52014-05-07 16:25:32 +000032// CHECK-NOT: @_GLOBAL__D_a()
Stephen Lin43622612013-08-15 06:47:53 +000033// CHECK-LABEL: define internal void @__dtor_baz()
John McCall76cc43a2012-04-06 18:21:06 +000034// CHECK: call [[BAR]]* @_ZN3barD1Ev([[BAR]]* @baz)
35
John McCall5d865c322010-08-31 07:33:07 +000036// Destructors and constructors must return this.
37namespace test1 {
38 void foo();
39
40 struct A {
41 A(int i) { foo(); }
42 ~A() { foo(); }
43 void bar() { foo(); }
44 };
45
Stephen Lin43622612013-08-15 06:47:53 +000046 // CHECK-LABEL: define void @_ZN5test14testEv()
John McCall5d865c322010-08-31 07:33:07 +000047 void test() {
48 // CHECK: [[AV:%.*]] = alloca [[A:%.*]], align 1
49 // CHECK: call [[A]]* @_ZN5test11AC1Ei([[A]]* [[AV]], i32 10)
50 // CHECK: invoke void @_ZN5test11A3barEv([[A]]* [[AV]])
51 // CHECK: call [[A]]* @_ZN5test11AD1Ev([[A]]* [[AV]])
52 // CHECK: ret void
53 A a = 10;
54 a.bar();
55 }
56
Stephen Lin9dc6eef2013-06-30 20:40:16 +000057 // CHECK: define linkonce_odr [[A]]* @_ZN5test11AC1Ei([[A]]* returned %this, i32 %i) unnamed_addr
John McCall5d865c322010-08-31 07:33:07 +000058 // CHECK: [[THIS:%.*]] = alloca [[A]]*, align 4
59 // CHECK: store [[A]]* {{.*}}, [[A]]** [[THIS]]
David Blaikiea953f282015-02-27 21:19:58 +000060 // CHECK: [[THIS1:%.*]] = load [[A]]*, [[A]]** [[THIS]]
Stephen Lin9dc6eef2013-06-30 20:40:16 +000061 // CHECK: {{%.*}} = call [[A]]* @_ZN5test11AC2Ei(
62 // CHECK: ret [[A]]* [[THIS1]]
John McCall5d865c322010-08-31 07:33:07 +000063
Stephen Lin9dc6eef2013-06-30 20:40:16 +000064 // CHECK: define linkonce_odr [[A]]* @_ZN5test11AD1Ev([[A]]* returned %this) unnamed_addr
John McCall5d865c322010-08-31 07:33:07 +000065 // CHECK: [[THIS:%.*]] = alloca [[A]]*, align 4
66 // CHECK: store [[A]]* {{.*}}, [[A]]** [[THIS]]
David Blaikiea953f282015-02-27 21:19:58 +000067 // CHECK: [[THIS1:%.*]] = load [[A]]*, [[A]]** [[THIS]]
Stephen Lin9dc6eef2013-06-30 20:40:16 +000068 // CHECK: {{%.*}} = call [[A]]* @_ZN5test11AD2Ev(
69 // CHECK: ret [[A]]* [[THIS1]]
John McCall5d865c322010-08-31 07:33:07 +000070}
71
72// Awkward virtual cases.
73namespace test2 {
74 void foo();
75
76 struct A {
77 int x;
78
79 A(int);
80 virtual ~A() { foo(); }
81 };
82
83 struct B {
84 int y;
85 int z;
86
87 B(int);
88 virtual ~B() { foo(); }
89 };
90
91 struct C : A, virtual B {
92 int q;
93
94 C(int i) : A(i), B(i) { foo(); }
95 ~C() { foo(); }
96 };
97
98 void test() {
99 C c = 10;
100 }
101
John McCall8ed55a52010-09-02 09:58:18 +0000102 // Tests at eof
103}
104
105namespace test3 {
106 struct A {
107 int x;
108 ~A();
109 };
110
111 void a() {
Stephen Lin43622612013-08-15 06:47:53 +0000112 // CHECK-LABEL: define void @_ZN5test31aEv()
Richard Smith351241c2016-04-07 21:46:12 +0000113 // CHECK: call i8* @_Znam(i32 48)
John McCall8ed55a52010-09-02 09:58:18 +0000114 // CHECK: store i32 4
115 // CHECK: store i32 10
116 A *x = new A[10];
117 }
118
119 void b(int n) {
Stephen Lin43622612013-08-15 06:47:53 +0000120 // CHECK-LABEL: define void @_ZN5test31bEi(
David Blaikiea953f282015-02-27 21:19:58 +0000121 // CHECK: [[N:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000122 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
123 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
Eli Friedmandb42a3e2011-04-09 19:54:33 +0000124 // CHECK: [[OR:%.*]] = or i1
125 // CHECK: [[SZ:%.*]] = select i1 [[OR]]
Richard Smith351241c2016-04-07 21:46:12 +0000126 // CHECK: call i8* @_Znam(i32 [[SZ]])
John McCall8ed55a52010-09-02 09:58:18 +0000127 // CHECK: store i32 4
128 // CHECK: store i32 [[N]]
129 A *x = new A[n];
130 }
131
132 void c() {
Stephen Lin43622612013-08-15 06:47:53 +0000133 // CHECK-LABEL: define void @_ZN5test31cEv()
Richard Smith351241c2016-04-07 21:46:12 +0000134 // CHECK: call i8* @_Znam(i32 808)
John McCall8ed55a52010-09-02 09:58:18 +0000135 // CHECK: store i32 4
136 // CHECK: store i32 200
137 A (*x)[20] = new A[10][20];
138 }
139
140 void d(int n) {
Stephen Lin43622612013-08-15 06:47:53 +0000141 // CHECK-LABEL: define void @_ZN5test31dEi(
David Blaikiea953f282015-02-27 21:19:58 +0000142 // CHECK: [[N:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000143 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
John McCall036f2f62011-05-15 07:14:44 +0000144 // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
John McCall8ed55a52010-09-02 09:58:18 +0000145 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
146 // CHECK: [[SZ:%.*]] = select
Richard Smith351241c2016-04-07 21:46:12 +0000147 // CHECK: call i8* @_Znam(i32 [[SZ]])
John McCall8ed55a52010-09-02 09:58:18 +0000148 // CHECK: store i32 4
149 // CHECK: store i32 [[NE]]
150 A (*x)[20] = new A[n][20];
151 }
152
153 void e(A *x) {
Stephen Lin43622612013-08-15 06:47:53 +0000154 // CHECK-LABEL: define void @_ZN5test31eEPNS_1AE(
John McCall8ed55a52010-09-02 09:58:18 +0000155 // CHECK: icmp eq {{.*}}, null
John McCall7f416cc2015-09-08 08:05:57 +0000156 // CHECK: getelementptr {{.*}}, i32 -8
157 // CHECK: getelementptr {{.*}}, i32 4
John McCall8ed55a52010-09-02 09:58:18 +0000158 // CHECK: bitcast {{.*}} to i32*
159 // CHECK: load
Charles Lifad02412017-01-09 18:24:16 +0000160 // CHECK98: invoke {{.*}} @_ZN5test31AD1Ev
161 // CHECK11: call {{.*}} @_ZN5test31AD1Ev
John McCall8ed55a52010-09-02 09:58:18 +0000162 // CHECK: call void @_ZdaPv
163 delete [] x;
164 }
165
166 void f(A (*x)[20]) {
Stephen Lin43622612013-08-15 06:47:53 +0000167 // CHECK-LABEL: define void @_ZN5test31fEPA20_NS_1AE(
John McCall8ed55a52010-09-02 09:58:18 +0000168 // CHECK: icmp eq {{.*}}, null
John McCall7f416cc2015-09-08 08:05:57 +0000169 // CHECK: getelementptr {{.*}}, i32 -8
170 // CHECK: getelementptr {{.*}}, i32 4
John McCall8ed55a52010-09-02 09:58:18 +0000171 // CHECK: bitcast {{.*}} to i32*
172 // CHECK: load
Charles Lifad02412017-01-09 18:24:16 +0000173 // CHECK98: invoke {{.*}} @_ZN5test31AD1Ev
174 // CHECK11: call {{.*}} @_ZN5test31AD1Ev
John McCall8ed55a52010-09-02 09:58:18 +0000175 // CHECK: call void @_ZdaPv
176 delete [] x;
177 }
178}
179
180namespace test4 {
181 struct A {
182 int x;
183 void operator delete[](void *, size_t sz);
184 };
185
186 void a() {
Stephen Lin43622612013-08-15 06:47:53 +0000187 // CHECK-LABEL: define void @_ZN5test41aEv()
Richard Smith351241c2016-04-07 21:46:12 +0000188 // CHECK: call i8* @_Znam(i32 48)
John McCall8ed55a52010-09-02 09:58:18 +0000189 // CHECK: store i32 4
190 // CHECK: store i32 10
191 A *x = new A[10];
192 }
193
194 void b(int n) {
Stephen Lin43622612013-08-15 06:47:53 +0000195 // CHECK-LABEL: define void @_ZN5test41bEi(
David Blaikiea953f282015-02-27 21:19:58 +0000196 // CHECK: [[N:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000197 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
198 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
199 // CHECK: [[SZ:%.*]] = select
Richard Smith351241c2016-04-07 21:46:12 +0000200 // CHECK: call i8* @_Znam(i32 [[SZ]])
John McCall8ed55a52010-09-02 09:58:18 +0000201 // CHECK: store i32 4
202 // CHECK: store i32 [[N]]
203 A *x = new A[n];
204 }
205
206 void c() {
Stephen Lin43622612013-08-15 06:47:53 +0000207 // CHECK-LABEL: define void @_ZN5test41cEv()
Richard Smith351241c2016-04-07 21:46:12 +0000208 // CHECK: call i8* @_Znam(i32 808)
John McCall8ed55a52010-09-02 09:58:18 +0000209 // CHECK: store i32 4
210 // CHECK: store i32 200
211 A (*x)[20] = new A[10][20];
212 }
213
214 void d(int n) {
Stephen Lin43622612013-08-15 06:47:53 +0000215 // CHECK-LABEL: define void @_ZN5test41dEi(
David Blaikiea953f282015-02-27 21:19:58 +0000216 // CHECK: [[N:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000217 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
John McCall036f2f62011-05-15 07:14:44 +0000218 // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
John McCall8ed55a52010-09-02 09:58:18 +0000219 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
220 // CHECK: [[SZ:%.*]] = select
Richard Smith351241c2016-04-07 21:46:12 +0000221 // CHECK: call i8* @_Znam(i32 [[SZ]])
John McCall8ed55a52010-09-02 09:58:18 +0000222 // CHECK: store i32 4
223 // CHECK: store i32 [[NE]]
224 A (*x)[20] = new A[n][20];
225 }
226
227 void e(A *x) {
Stephen Lin43622612013-08-15 06:47:53 +0000228 // CHECK-LABEL: define void @_ZN5test41eEPNS_1AE(
John McCall7f416cc2015-09-08 08:05:57 +0000229 // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i32 -8
230 // CHECK: getelementptr inbounds {{.*}}, i32 4
John McCall8ed55a52010-09-02 09:58:18 +0000231 // CHECK: bitcast
David Blaikiea953f282015-02-27 21:19:58 +0000232 // CHECK: [[T0:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000233 // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
234 // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
235 // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
236 delete [] x;
237 }
238
239 void f(A (*x)[20]) {
Stephen Lin43622612013-08-15 06:47:53 +0000240 // CHECK-LABEL: define void @_ZN5test41fEPA20_NS_1AE(
John McCall7f416cc2015-09-08 08:05:57 +0000241 // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i32 -8
242 // CHECK: getelementptr inbounds {{.*}}, i32 4
John McCall8ed55a52010-09-02 09:58:18 +0000243 // CHECK: bitcast
David Blaikiea953f282015-02-27 21:19:58 +0000244 // CHECK: [[T0:%.*]] = load i32, i32*
John McCall8ed55a52010-09-02 09:58:18 +0000245 // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
246 // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
247 // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
248 delete [] x;
249 }
250}
251
John McCall0d635f52010-09-03 01:26:39 +0000252// <rdar://problem/8386802>: don't crash
253namespace test5 {
254 struct A {
255 ~A();
256 };
257
Stephen Lin43622612013-08-15 06:47:53 +0000258 // CHECK-LABEL: define void @_ZN5test54testEPNS_1AE
John McCall0d635f52010-09-03 01:26:39 +0000259 void test(A *a) {
260 // CHECK: [[PTR:%.*]] = alloca [[A:%.*]]*, align 4
261 // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[PTR]], align 4
David Blaikiea953f282015-02-27 21:19:58 +0000262 // CHECK-NEXT: [[TMP:%.*]] = load [[A]]*, [[A]]** [[PTR]], align 4
John McCall0d635f52010-09-03 01:26:39 +0000263 // CHECK-NEXT: call [[A]]* @_ZN5test51AD1Ev([[A]]* [[TMP]])
264 // CHECK-NEXT: ret void
265 a->~A();
266 }
267}
268
269namespace test6 {
270 struct A {
271 virtual ~A();
272 };
273
Stephen Lin43622612013-08-15 06:47:53 +0000274 // CHECK-LABEL: define void @_ZN5test64testEPNS_1AE
John McCall0d635f52010-09-03 01:26:39 +0000275 void test(A *a) {
276 // CHECK: [[AVAR:%.*]] = alloca [[A:%.*]]*, align 4
277 // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[AVAR]], align 4
David Blaikiea953f282015-02-27 21:19:58 +0000278 // CHECK-NEXT: [[V:%.*]] = load [[A]]*, [[A]]** [[AVAR]], align 4
John McCall0d635f52010-09-03 01:26:39 +0000279 // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq [[A]]* [[V]], null
280 // CHECK-NEXT: br i1 [[ISNULL]]
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +0000281 // CHECK: [[T0:%.*]] = bitcast [[A]]* [[V]] to void ([[A]]*)***
David Blaikiea953f282015-02-27 21:19:58 +0000282 // CHECK-NEXT: [[T1:%.*]] = load void ([[A]]*)**, void ([[A]]*)*** [[T0]]
David Blaikie218b7832015-02-27 19:18:17 +0000283 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds void ([[A]]*)*, void ([[A]]*)** [[T1]], i64 1
David Blaikiea953f282015-02-27 21:19:58 +0000284 // CHECK-NEXT: [[T3:%.*]] = load void ([[A]]*)*, void ([[A]]*)** [[T2]]
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +0000285 // CHECK-NEXT: call void [[T3]]([[A]]* [[V]])
John McCall0d635f52010-09-03 01:26:39 +0000286 // CHECK-NEXT: br label
287 // CHECK: ret void
288 delete a;
289 }
290}
291
John McCall68ff0372010-09-08 01:44:27 +0000292namespace test7 {
293 int foo();
294
295 // Static and guard tested at top of file
296
David Majnemerfcbdb6e2015-06-17 20:53:19 +0000297 // CHECK-LABEL: define void @_ZN5test74testEv() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
John McCall68ff0372010-09-08 01:44:27 +0000298 void test() {
John McCall7f416cc2015-09-08 08:05:57 +0000299 // CHECK: [[T0:%.*]] = load atomic i8, i8* bitcast (i32* @_ZGVZN5test74testEvE1x to i8*) acquire, align 4
Justin Bogner0cbb6d82014-04-23 01:50:10 +0000300 // CHECK-NEXT: [[T1:%.*]] = and i8 [[T0]], 1
301 // CHECK-NEXT: [[T2:%.*]] = icmp eq i8 [[T1]], 0
John McCall68ff0372010-09-08 01:44:27 +0000302 // CHECK-NEXT: br i1 [[T2]]
303 // -> fallthrough, end
304 // CHECK: [[T3:%.*]] = call i32 @__cxa_guard_acquire(i32* @_ZGVZN5test74testEvE1x)
305 // CHECK-NEXT: [[T4:%.*]] = icmp ne i32 [[T3]], 0
306 // CHECK-NEXT: br i1 [[T4]]
307 // -> fallthrough, end
308 // CHECK: [[INIT:%.*]] = invoke i32 @_ZN5test73fooEv()
309 // CHECK: store i32 [[INIT]], i32* @_ZZN5test74testEvE1x, align 4
310 // CHECK-NEXT: call void @__cxa_guard_release(i32* @_ZGVZN5test74testEvE1x)
311 // CHECK-NEXT: br label
312 // -> end
313 // end:
314 // CHECK: ret void
315 static int x = foo();
316
David Majnemerfcbdb6e2015-06-17 20:53:19 +0000317 // CHECK: landingpad { i8*, i32 }
Bill Wendlingf0724e82011-09-19 20:31:14 +0000318 // CHECK-NEXT: cleanup
John McCall68ff0372010-09-08 01:44:27 +0000319 // CHECK: call void @__cxa_guard_abort(i32* @_ZGVZN5test74testEvE1x)
Bill Wendlingf0724e82011-09-19 20:31:14 +0000320 // CHECK: resume { i8*, i32 }
John McCall68ff0372010-09-08 01:44:27 +0000321 }
322}
323
324namespace test8 {
325 struct A {
326 A();
327 ~A();
328 };
329
330 // Static and guard tested at top of file
331
David Majnemerfcbdb6e2015-06-17 20:53:19 +0000332 // CHECK-LABEL: define void @_ZN5test84testEv() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
John McCall68ff0372010-09-08 01:44:27 +0000333 void test() {
John McCall7f416cc2015-09-08 08:05:57 +0000334 // CHECK: [[T0:%.*]] = load atomic i8, i8* bitcast (i32* @_ZGVZN5test84testEvE1x to i8*) acquire, align 4
Justin Bogner0cbb6d82014-04-23 01:50:10 +0000335 // CHECK-NEXT: [[T1:%.*]] = and i8 [[T0]], 1
336 // CHECK-NEXT: [[T2:%.*]] = icmp eq i8 [[T1]], 0
John McCall68ff0372010-09-08 01:44:27 +0000337 // CHECK-NEXT: br i1 [[T2]]
338 // -> fallthrough, end
339 // CHECK: [[T3:%.*]] = call i32 @__cxa_guard_acquire(i32* @_ZGVZN5test84testEvE1x)
340 // CHECK-NEXT: [[T4:%.*]] = icmp ne i32 [[T3]], 0
341 // CHECK-NEXT: br i1 [[T4]]
342 // -> fallthrough, end
343 // CHECK: [[INIT:%.*]] = invoke [[TEST8A]]* @_ZN5test81AC1Ev([[TEST8A]]* @_ZZN5test84testEvE1x)
344
345 // FIXME: Here we register a global destructor that
346 // unconditionally calls the destructor. That's what we've always
347 // done for -fno-use-cxa-atexit here, but that's really not
348 // semantically correct at all.
349
350 // CHECK: call void @__cxa_guard_release(i32* @_ZGVZN5test84testEvE1x)
351 // CHECK-NEXT: br label
352 // -> end
353 // end:
354 // CHECK: ret void
355 static A x;
356
David Majnemerfcbdb6e2015-06-17 20:53:19 +0000357 // CHECK: landingpad { i8*, i32 }
Bill Wendlingf0724e82011-09-19 20:31:14 +0000358 // CHECK-NEXT: cleanup
John McCall68ff0372010-09-08 01:44:27 +0000359 // CHECK: call void @__cxa_guard_abort(i32* @_ZGVZN5test84testEvE1x)
Bill Wendlingf0724e82011-09-19 20:31:14 +0000360 // CHECK: resume { i8*, i32 }
John McCall68ff0372010-09-08 01:44:27 +0000361 }
362}
363
John McCallc19c7062013-01-25 23:36:19 +0000364// rdar://12836470
365// Use a larger-than-mandated array cookie when allocating an
366// array whose type is overaligned.
367namespace test9 {
368 class __attribute__((aligned(16))) A {
369 float data[4];
370 public:
371 A();
372 ~A();
373 };
374
375 A *testNew(unsigned n) {
376 return new A[n];
377 }
378// CHECK: define [[TEST9:%.*]]* @_ZN5test97testNewEj(i32
379// CHECK: [[N_VAR:%.*]] = alloca i32, align 4
David Blaikiea953f282015-02-27 21:19:58 +0000380// CHECK: [[N:%.*]] = load i32, i32* [[N_VAR]], align 4
John McCallc19c7062013-01-25 23:36:19 +0000381// CHECK-NEXT: [[T0:%.*]] = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 [[N]], i32 16)
382// CHECK-NEXT: [[O0:%.*]] = extractvalue { i32, i1 } [[T0]], 1
383// CHECK-NEXT: [[T1:%.*]] = extractvalue { i32, i1 } [[T0]], 0
384// CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 [[T1]], i32 16)
385// CHECK-NEXT: [[O1:%.*]] = extractvalue { i32, i1 } [[T2]], 1
386// CHECK-NEXT: [[OVERFLOW:%.*]] = or i1 [[O0]], [[O1]]
387// CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 0
388// CHECK-NEXT: [[T4:%.*]] = select i1 [[OVERFLOW]], i32 -1, i32 [[T3]]
Richard Smith351241c2016-04-07 21:46:12 +0000389// CHECK-NEXT: [[ALLOC:%.*]] = call i8* @_Znam(i32 [[T4]])
John McCallc19c7062013-01-25 23:36:19 +0000390// CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[ALLOC]] to i32*
391// CHECK-NEXT: store i32 16, i32* [[T0]]
David Blaikie218b7832015-02-27 19:18:17 +0000392// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i32, i32* [[T0]], i32 1
John McCallc19c7062013-01-25 23:36:19 +0000393// CHECK-NEXT: store i32 [[N]], i32* [[T1]]
John McCall7f416cc2015-09-08 08:05:57 +0000394// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8, i8* [[ALLOC]], i32 16
John McCallc19c7062013-01-25 23:36:19 +0000395// CHECK-NEXT: bitcast i8* [[T0]] to [[TEST9]]*
396// Array allocation follows.
397
398 void testDelete(A *array) {
399 delete[] array;
400 }
Stephen Lin43622612013-08-15 06:47:53 +0000401// CHECK-LABEL: define void @_ZN5test910testDeleteEPNS_1AE(
David Blaikiea953f282015-02-27 21:19:58 +0000402// CHECK: [[BEGIN:%.*]] = load [[TEST9]]*, [[TEST9]]**
John McCallc19c7062013-01-25 23:36:19 +0000403// CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], null
404// CHECK-NEXT: br i1 [[T0]],
405// CHECK: [[T0:%.*]] = bitcast [[TEST9]]* [[BEGIN]] to i8*
John McCall7f416cc2015-09-08 08:05:57 +0000406// CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8, i8* [[T0]], i32 -16
407// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8, i8* [[ALLOC]], i32 4
John McCallc19c7062013-01-25 23:36:19 +0000408// CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i32*
David Blaikiea953f282015-02-27 21:19:58 +0000409// CHECK-NEXT: [[N:%.*]] = load i32, i32* [[T1]]
David Blaikie218b7832015-02-27 19:18:17 +0000410// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[TEST9]], [[TEST9]]* [[BEGIN]], i32 [[N]]
John McCallc19c7062013-01-25 23:36:19 +0000411// CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], [[END]]
412// CHECK-NEXT: br i1 [[T0]],
413// Array deallocation follows.
414}
415
John McCall5d865c322010-08-31 07:33:07 +0000416 // CHECK: define linkonce_odr [[C:%.*]]* @_ZTv0_n12_N5test21CD1Ev(
417 // CHECK: call [[C]]* @_ZN5test21CD1Ev(
418 // CHECK: ret [[C]]* undef
419
Stephen Lin43622612013-08-15 06:47:53 +0000420 // CHECK-LABEL: define linkonce_odr void @_ZTv0_n12_N5test21CD0Ev(
John McCall5d865c322010-08-31 07:33:07 +0000421 // CHECK: call void @_ZN5test21CD0Ev(
422 // CHECK: ret void