1 // RUN: %clang_cc1 -no-opaque-pointers -no-enable-noundef-analysis %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 -no-opaque-pointers -no-enable-noundef-analysis %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
4 // 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
9 typedef typeof(sizeof(int)) size_t;
17 class bar
: public foo
{
22 // The global dtor needs the right calling conv with -fno-use-cxa-atexit
27 // Make sure atexit(3) is used for global dtors.
29 // CHECK: call [[BAR:%.*]]* @_ZN3barC1Ev(
30 // CHECK-NEXT: call i32 @atexit(void ()* @__dtor_baz)
32 // CHECK-NOT: @_GLOBAL__D_a()
33 // CHECK-LABEL: define internal void @__dtor_baz()
34 // CHECK: call [[BAR]]* @_ZN3barD1Ev([[BAR]]* @baz)
36 // Destructors and constructors must return this.
46 // CHECK-LABEL: define{{.*}} void @_ZN5test14testEv()
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]])
57 // CHECK: define linkonce_odr [[A]]* @_ZN5test11AC1Ei([[A]]* {{[^,]*}} returned {{[^,]*}} %this, i32 %i) unnamed_addr
58 // CHECK: [[THIS:%.*]] = alloca [[A]]*, align 4
59 // CHECK: store [[A]]* {{.*}}, [[A]]** [[THIS]]
60 // CHECK: [[THIS1:%.*]] = load [[A]]*, [[A]]** [[THIS]]
61 // CHECK: {{%.*}} = call [[A]]* @_ZN5test11AC2Ei(
62 // CHECK: ret [[A]]* [[THIS1]]
64 // CHECK: define linkonce_odr [[A]]* @_ZN5test11AD1Ev([[A]]* {{[^,]*}} returned {{[^,]*}} %this) unnamed_addr
65 // CHECK: [[THIS:%.*]] = alloca [[A]]*, align 4
66 // CHECK: store [[A]]* {{.*}}, [[A]]** [[THIS]]
67 // CHECK: [[THIS1:%.*]] = load [[A]]*, [[A]]** [[THIS]]
68 // CHECK: {{%.*}} = call [[A]]* @_ZN5test11AD2Ev(
69 // CHECK: ret [[A]]* [[THIS1]]
72 // Awkward virtual cases.
80 virtual ~A() { foo(); }
88 virtual ~B() { foo(); }
91 struct C
: A
, virtual B
{
94 C(int i
) : A(i
), B(i
) { foo(); }
112 // CHECK-LABEL: define{{.*}} void @_ZN5test31aEv()
113 // CHECK: call noalias nonnull i8* @_Znam(i32 48)
114 // CHECK: store i32 4
115 // CHECK: store i32 10
120 // CHECK-LABEL: define{{.*}} void @_ZN5test31bEi(
121 // CHECK: [[N:%.*]] = load i32, i32*
122 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
123 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
124 // CHECK: [[OR:%.*]] = or i1
125 // CHECK: [[SZ:%.*]] = select i1 [[OR]]
126 // CHECK: call noalias nonnull i8* @_Znam(i32 [[SZ]])
127 // CHECK: store i32 4
128 // CHECK: store i32 [[N]]
133 // CHECK-LABEL: define{{.*}} void @_ZN5test31cEv()
134 // CHECK: call noalias nonnull i8* @_Znam(i32 808)
135 // CHECK: store i32 4
136 // CHECK: store i32 200
137 A (*x
)[20] = new A
[10][20];
141 // CHECK-LABEL: define{{.*}} void @_ZN5test31dEi(
142 // CHECK: [[N:%.*]] = load i32, i32*
143 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
144 // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
145 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
146 // CHECK: [[SZ:%.*]] = select
147 // CHECK: call noalias nonnull i8* @_Znam(i32 [[SZ]])
148 // CHECK: store i32 4
149 // CHECK: store i32 [[NE]]
150 A (*x
)[20] = new A
[n
][20];
154 // CHECK-LABEL: define{{.*}} void @_ZN5test31eEPNS_1AE(
155 // CHECK: icmp eq {{.*}}, null
156 // CHECK: getelementptr {{.*}}, i32 -8
157 // CHECK: getelementptr {{.*}}, i32 4
158 // CHECK: bitcast {{.*}} to i32*
160 // CHECK98: invoke {{.*}} @_ZN5test31AD1Ev
161 // CHECK11: call {{.*}} @_ZN5test31AD1Ev
162 // CHECK: call void @_ZdaPv
167 // CHECK-LABEL: define{{.*}} void @_ZN5test31fEPA20_NS_1AE(
168 // CHECK: icmp eq {{.*}}, null
169 // CHECK: getelementptr {{.*}}, i32 -8
170 // CHECK: getelementptr {{.*}}, i32 4
171 // CHECK: bitcast {{.*}} to i32*
173 // CHECK98: invoke {{.*}} @_ZN5test31AD1Ev
174 // CHECK11: call {{.*}} @_ZN5test31AD1Ev
175 // CHECK: call void @_ZdaPv
183 void operator delete[](void *, size_t sz
);
187 // CHECK-LABEL: define{{.*}} void @_ZN5test41aEv()
188 // CHECK: call noalias nonnull i8* @_Znam(i32 48)
189 // CHECK: store i32 4
190 // CHECK: store i32 10
195 // CHECK-LABEL: define{{.*}} void @_ZN5test41bEi(
196 // CHECK: [[N:%.*]] = load i32, i32*
197 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 4)
198 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
199 // CHECK: [[SZ:%.*]] = select
200 // CHECK: call noalias nonnull i8* @_Znam(i32 [[SZ]])
201 // CHECK: store i32 4
202 // CHECK: store i32 [[N]]
207 // CHECK-LABEL: define{{.*}} void @_ZN5test41cEv()
208 // CHECK: call noalias nonnull i8* @_Znam(i32 808)
209 // CHECK: store i32 4
210 // CHECK: store i32 200
211 A (*x
)[20] = new A
[10][20];
215 // CHECK-LABEL: define{{.*}} void @_ZN5test41dEi(
216 // CHECK: [[N:%.*]] = load i32, i32*
217 // CHECK: @llvm.umul.with.overflow.i32(i32 [[N]], i32 80)
218 // CHECK: [[NE:%.*]] = mul i32 [[N]], 20
219 // CHECK: @llvm.uadd.with.overflow.i32(i32 {{.*}}, i32 8)
220 // CHECK: [[SZ:%.*]] = select
221 // CHECK: call noalias nonnull i8* @_Znam(i32 [[SZ]])
222 // CHECK: store i32 4
223 // CHECK: store i32 [[NE]]
224 A (*x
)[20] = new A
[n
][20];
228 // CHECK-LABEL: define{{.*}} void @_ZN5test41eEPNS_1AE(
229 // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i32 -8
230 // CHECK: getelementptr inbounds {{.*}}, i32 4
232 // CHECK: [[T0:%.*]] = load i32, i32*
233 // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
234 // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
235 // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
240 // CHECK-LABEL: define{{.*}} void @_ZN5test41fEPA20_NS_1AE(
241 // CHECK: [[ALLOC:%.*]] = getelementptr inbounds {{.*}}, i32 -8
242 // CHECK: getelementptr inbounds {{.*}}, i32 4
244 // CHECK: [[T0:%.*]] = load i32, i32*
245 // CHECK: [[T1:%.*]] = mul i32 4, [[T0]]
246 // CHECK: [[T2:%.*]] = add i32 [[T1]], 8
247 // CHECK: call void @_ZN5test41AdaEPvm(i8* [[ALLOC]], i32 [[T2]])
252 // <rdar://problem/8386802>: don't crash
258 // CHECK-LABEL: define{{.*}} void @_ZN5test54testEPNS_1AE
260 // CHECK: [[PTR:%.*]] = alloca [[A:%.*]]*, align 4
261 // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[PTR]], align 4
262 // CHECK-NEXT: [[TMP:%.*]] = load [[A]]*, [[A]]** [[PTR]], align 4
263 // CHECK-NEXT: call [[A]]* @_ZN5test51AD1Ev([[A]]* {{[^,]*}} [[TMP]])
264 // CHECK-NEXT: ret void
274 // CHECK-LABEL: define{{.*}} void @_ZN5test64testEPNS_1AE
276 // CHECK: [[AVAR:%.*]] = alloca [[A:%.*]]*, align 4
277 // CHECK-NEXT: store [[A]]* {{.*}}, [[A]]** [[AVAR]], align 4
278 // CHECK-NEXT: [[V:%.*]] = load [[A]]*, [[A]]** [[AVAR]], align 4
279 // CHECK-NEXT: [[ISNULL:%.*]] = icmp eq [[A]]* [[V]], null
280 // CHECK-NEXT: br i1 [[ISNULL]]
281 // CHECK: [[T0:%.*]] = bitcast [[A]]* [[V]] to void ([[A]]*)***
282 // CHECK-NEXT: [[T1:%.*]] = load void ([[A]]*)**, void ([[A]]*)*** [[T0]]
283 // CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds void ([[A]]*)*, void ([[A]]*)** [[T1]], i64 1
284 // CHECK-NEXT: [[T3:%.*]] = load void ([[A]]*)*, void ([[A]]*)** [[T2]]
285 // CHECK-NEXT: call void [[T3]]([[A]]* {{[^,]*}} [[V]])
286 // CHECK-NEXT: br label
295 // Static and guard tested at top of file
297 // CHECK-LABEL: define{{.*}} void @_ZN5test74testEv() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
299 // CHECK: [[T0:%.*]] = load atomic i8, i8* bitcast (i32* @_ZGVZN5test74testEvE1x to i8*) acquire, align 4
300 // CHECK-NEXT: [[T1:%.*]] = and i8 [[T0]], 1
301 // CHECK-NEXT: [[T2:%.*]] = icmp eq i8 [[T1]], 0
302 // 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
315 static int x
= foo();
317 // CHECK: landingpad { i8*, i32 }
318 // CHECK-NEXT: cleanup
319 // CHECK: call void @__cxa_guard_abort(i32* @_ZGVZN5test74testEvE1x)
320 // CHECK: resume { i8*, i32 }
330 // Static and guard tested at top of file
332 // CHECK-LABEL: define{{.*}} void @_ZN5test84testEv() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
334 // CHECK: [[T0:%.*]] = load atomic i8, i8* bitcast (i32* @_ZGVZN5test84testEvE1x to i8*) acquire, align 4
335 // CHECK-NEXT: [[T1:%.*]] = and i8 [[T0]], 1
336 // CHECK-NEXT: [[T2:%.*]] = icmp eq i8 [[T1]], 0
337 // 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)
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.
350 // CHECK: call void @__cxa_guard_release(i32* @_ZGVZN5test84testEvE1x)
351 // CHECK-NEXT: br label
357 // CHECK: landingpad { i8*, i32 }
358 // CHECK-NEXT: cleanup
359 // CHECK: call void @__cxa_guard_abort(i32* @_ZGVZN5test84testEvE1x)
360 // CHECK: resume { i8*, i32 }
365 // Use a larger-than-mandated array cookie when allocating an
366 // array whose type is overaligned.
368 class __attribute__((aligned(16))) A
{
375 A
*testNew(unsigned n
) {
378 // CHECK: define{{.*}} [[TEST9:%.*]]* @_ZN5test97testNewEj(i32
379 // CHECK: [[N_VAR:%.*]] = alloca i32, align 4
380 // CHECK: [[N:%.*]] = load i32, i32* [[N_VAR]], align 4
381 // 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]]
389 // CHECK-NEXT: [[ALLOC:%.*]] = call noalias nonnull i8* @_Znam(i32 [[T4]])
390 // CHECK-NEXT: [[T0:%.*]] = bitcast i8* [[ALLOC]] to i32*
391 // CHECK-NEXT: store i32 16, i32* [[T0]]
392 // CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds i32, i32* [[T0]], i32 1
393 // CHECK-NEXT: store i32 [[N]], i32* [[T1]]
394 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8, i8* [[ALLOC]], i32 16
395 // CHECK-NEXT: bitcast i8* [[T0]] to [[TEST9]]*
396 // Array allocation follows.
398 void testDelete(A
*array
) {
401 // CHECK-LABEL: define{{.*}} void @_ZN5test910testDeleteEPNS_1AE(
402 // CHECK: [[BEGIN:%.*]] = load [[TEST9]]*, [[TEST9]]**
403 // CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], null
404 // CHECK-NEXT: br i1 [[T0]],
405 // CHECK: [[T0:%.*]] = bitcast [[TEST9]]* [[BEGIN]] to i8*
406 // CHECK-NEXT: [[ALLOC:%.*]] = getelementptr inbounds i8, i8* [[T0]], i32 -16
407 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds i8, i8* [[ALLOC]], i32 4
408 // CHECK-NEXT: [[T1:%.*]] = bitcast i8* [[T0]] to i32*
409 // CHECK-NEXT: [[N:%.*]] = load i32, i32* [[T1]]
410 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[TEST9]], [[TEST9]]* [[BEGIN]], i32 [[N]]
411 // CHECK-NEXT: [[T0:%.*]] = icmp eq [[TEST9]]* [[BEGIN]], [[END]]
412 // CHECK-NEXT: br i1 [[T0]],
413 // Array deallocation follows.
416 // CHECK: define linkonce_odr [[C:%.*]]* @_ZTv0_n12_N5test21CD1Ev(
417 // CHECK: call [[C]]* @_ZN5test21CD1Ev(
418 // CHECK: ret [[C]]* undef
420 // CHECK-LABEL: define linkonce_odr void @_ZTv0_n12_N5test21CD0Ev(
421 // CHECK: call void @_ZN5test21CD0Ev(