Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / temporaries.cpp
blobc5adb42a6f17374d47a36f1ab636ecad3437b2fb
1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s -check-prefixes=CHECK,NULL-INVALID,CHECK-CXX11
2 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++17 | FileCheck %s -check-prefixes=CHECK,NULL-INVALID,CHECK-CXX17
3 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 -fno-delete-null-pointer-checks | FileCheck %s -check-prefixes=CHECK,NULL-VALID,CHECK-CXX11
5 namespace PR16263 {
6 const unsigned int n = 1234;
7 extern const int &r = (const int&)n;
8 // CHECK: @_ZGRN7PR162631rE_ = internal constant i32 1234,
9 // CHECK: @_ZN7PR162631rE ={{.*}} constant ptr @_ZGRN7PR162631rE_,
11 extern const int &s = reinterpret_cast<const int&>(n);
12 // CHECK: @_ZN7PR16263L1nE = internal constant i32 1234, align 4
13 // CHECK: @_ZN7PR162631sE ={{.*}} constant ptr @_ZN7PR16263L1nE, align 8
15 struct A { int n; };
16 struct B { int n; };
17 struct C : A, B {};
18 extern const A &&a = (A&&)(A&&)(C&&)(C{});
19 // CHECK: @_ZGRN7PR162631aE_ = internal global {{.*}} zeroinitializer,
20 // CHECK: @_ZN7PR162631aE ={{.*}} constant {{.*}} @_ZGRN7PR162631aE_
22 extern const int &&t = ((B&&)C{}).n;
23 // CHECK: @_ZGRN7PR162631tE_ = internal global {{.*}} zeroinitializer,
24 // CHECK: @_ZN7PR162631tE ={{.*}} constant ptr {{.*}} @_ZGRN7PR162631tE_, {{.*}} 4
26 struct D { double d; C c; };
27 extern const int &&u = (123, static_cast<B&&>(0, ((D&&)D{}).*&D::c).n);
28 // CHECK: @_ZGRN7PR162631uE_ = internal global {{.*}} zeroinitializer
29 // CHECK: @_ZN7PR162631uE ={{.*}} constant ptr {{.*}} @_ZGRN7PR162631uE_, {{.*}} 12
32 namespace PR20227 {
33 struct A { ~A(); };
34 struct B { virtual ~B(); };
35 struct C : B {};
37 A &&a = dynamic_cast<A&&>(A{});
38 // CHECK: @_ZGRN7PR202271aE_ = internal global
40 B &&b = dynamic_cast<C&&>(dynamic_cast<B&&>(C{}));
41 // CHECK: @_ZGRN7PR202271bE_ = internal global
43 B &&c = static_cast<C&&>(static_cast<B&&>(C{}));
44 // CHECK: @_ZGRN7PR202271cE_ = internal global
47 namespace BraceInit {
48 typedef const int &CIR;
49 CIR x = CIR{3};
50 // CHECK-CXX11: @_ZGRN9BraceInit1xE_ = internal constant i32 3
51 // FIXME: This should still be emitted as 'constant' in C++17.
52 // CHECK-CXX17: @_ZGRN9BraceInit1xE_ = internal global i32 3
53 // CHECK: @_ZN9BraceInit1xE ={{.*}} constant ptr @_ZGRN9BraceInit1xE_
56 namespace RefTempSubobject {
57 struct SelfReferential {
58 int *p = ints;
59 int ints[3] = {1, 2, 3};
62 // CHECK: @_ZGRN16RefTempSubobject2srE_ = internal global { ptr, [3 x i32] } { {{.*}} getelementptr {{.*}} @_ZGRN16RefTempSubobject2srE_, {{.*}}, [3 x i32] [i32 1, i32 2, i32 3] }
63 // CHECK: @_ZN16RefTempSubobject2srE = constant {{.*}} @_ZGRN16RefTempSubobject2srE_
64 constexpr const SelfReferential &sr = SelfReferential();
67 struct A {
68 A();
69 ~A();
70 void f();
73 void f1() {
74 // CHECK: call void @_ZN1AC1Ev
75 // CHECK: call void @_ZN1AD1Ev
76 (void)A();
78 // CHECK: call void @_ZN1AC1Ev
79 // CHECK: call void @_ZN1AD1Ev
80 A().f();
83 // Function calls
84 struct B {
85 B();
86 ~B();
89 B g();
91 void f2() {
92 // CHECK-NOT: call void @_ZN1BC1Ev
93 // CHECK: call void @_ZN1BD1Ev
94 (void)g();
97 // Member function calls
98 struct C {
99 C();
100 ~C();
102 C f();
105 void f3() {
106 // CHECK: call void @_ZN1CC1Ev
107 // CHECK: call void @_ZN1CD1Ev
108 // CHECK: call void @_ZN1CD1Ev
109 C().f();
112 // Function call operator
113 struct D {
114 D();
115 ~D();
117 D operator()();
120 void f4() {
121 // CHECK: call void @_ZN1DC1Ev
122 // CHECK: call void @_ZN1DD1Ev
123 // CHECK: call void @_ZN1DD1Ev
124 D()();
127 // Overloaded operators
128 struct E {
129 E();
130 ~E();
131 E operator+(const E&);
132 E operator!();
135 void f5() {
136 // CHECK: call void @_ZN1EC1Ev
137 // CHECK: call void @_ZN1EC1Ev
138 // CHECK: call void @_ZN1ED1Ev
139 // CHECK: call void @_ZN1ED1Ev
140 // CHECK: call void @_ZN1ED1Ev
141 E() + E();
143 // CHECK: call void @_ZN1EC1Ev
144 // CHECK: call void @_ZN1ED1Ev
145 // CHECK: call void @_ZN1ED1Ev
146 !E();
149 struct F {
150 F();
151 ~F();
152 F& f();
155 void f6() {
156 // CHECK: call void @_ZN1FC1Ev
157 // CHECK: call void @_ZN1FD1Ev
158 F().f();
161 struct G {
162 G();
163 G(A);
164 ~G();
165 operator A();
168 void a(const A&);
170 void f7() {
171 // CHECK: call void @_ZN1AC1Ev
172 // CHECK: call void @_Z1aRK1A
173 // CHECK: call void @_ZN1AD1Ev
174 a(A());
176 // CHECK: call void @_ZN1GC1Ev
177 // CHECK: call void @_ZN1Gcv1AEv
178 // CHECK: call void @_Z1aRK1A
179 // CHECK: call void @_ZN1AD1Ev
180 // CHECK: call void @_ZN1GD1Ev
181 a(G());
184 namespace PR5077 {
186 struct A {
187 A();
188 ~A();
189 int f();
192 void f();
193 int g(const A&);
195 struct B {
196 int a1;
197 int a2;
198 B();
199 ~B();
202 B::B()
203 // CHECK: call void @_ZN6PR50771AC1Ev
204 // CHECK: call noundef i32 @_ZN6PR50771A1fEv
205 // CHECK: call void @_ZN6PR50771AD1Ev
206 : a1(A().f())
207 // CHECK: call void @_ZN6PR50771AC1Ev
208 // CHECK: call noundef i32 @_ZN6PR50771gERKNS_1AE
209 // CHECK: call void @_ZN6PR50771AD1Ev
210 , a2(g(A()))
212 // CHECK: call void @_ZN6PR50771fEv
213 f();
218 A f8() {
219 // CHECK: call void @_ZN1AC1Ev
220 // CHECK-NOT: call void @_ZN1AD1Ev
221 return A();
222 // CHECK: ret void
225 struct H {
226 H();
227 ~H();
228 H(const H&);
231 void f9(H h) {
232 // CHECK: call void @_ZN1HC1Ev
233 // CHECK: call void @_Z2f91H
234 // CHECK: call void @_ZN1HD1Ev
235 f9(H());
237 // CHECK: call void @_ZN1HC1ERKS_
238 // CHECK: call void @_Z2f91H
239 // CHECK: call void @_ZN1HD1Ev
240 f9(h);
243 void f10(const H&);
245 void f11(H h) {
246 // CHECK: call void @_ZN1HC1Ev
247 // CHECK: call void @_Z3f10RK1H
248 // CHECK: call void @_ZN1HD1Ev
249 f10(H());
251 // CHECK: call void @_Z3f10RK1H
252 // CHECK-NOT: call void @_ZN1HD1Ev
253 // CHECK: ret void
254 f10(h);
257 // PR5808
258 struct I {
259 I(const char *);
260 ~I();
263 // CHECK: _Z3f12v
264 I f12() {
265 // CHECK: call void @_ZN1IC1EPKc
266 // CHECK-NOT: call void @_ZN1ID1Ev
267 // CHECK: ret void
268 return "Hello";
271 // PR5867
272 namespace PR5867 {
273 struct S {
274 S();
275 S(const S &);
276 ~S();
279 void f(S, int);
280 // CHECK-LABEL: define{{.*}} void @_ZN6PR58671gEv
281 void g() {
282 // CHECK: call void @_ZN6PR58671SC1Ev
283 // CHECK-NEXT: call void @_ZN6PR58671fENS_1SEi
284 // CHECK-NEXT: call void @_ZN6PR58671SD1Ev
285 // CHECK-NEXT: ret void
286 (f)(S(), 0);
289 // CHECK-LABEL: define linkonce_odr void @_ZN6PR58672g2IiEEvT_
290 template<typename T>
291 void g2(T) {
292 // CHECK: call void @_ZN6PR58671SC1Ev
293 // CHECK-NEXT: call void @_ZN6PR58671fENS_1SEi
294 // CHECK-NEXT: call void @_ZN6PR58671SD1Ev
295 // CHECK-NEXT: ret void
296 (f)(S(), 0);
299 void h() {
300 g2(17);
304 // PR6199
305 namespace PR6199 {
306 struct A { ~A(); };
308 struct B { operator A(); };
310 // CHECK-LABEL: define weak_odr void @_ZN6PR61992f2IiEENS_1AET_
311 template<typename T> A f2(T) {
312 B b;
313 // CHECK: call void @_ZN6PR61991BcvNS_1AEEv
314 // CHECK-NEXT: ret void
315 return b;
318 template A f2<int>(int);
322 namespace T12 {
324 struct A {
325 A();
326 ~A();
327 int f();
330 int& f(int);
332 // CHECK-LABEL: define{{.*}} void @_ZN3T121gEv
333 void g() {
334 // CHECK: call void @_ZN3T121AC1Ev
335 // CHECK-NEXT: call noundef i32 @_ZN3T121A1fEv(
336 // CHECK-NEXT: call noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN3T121fEi(
337 // CHECK-NEXT: call void @_ZN3T121AD1Ev(
338 int& i = f(A().f());
343 namespace PR6648 {
344 struct B {
345 ~B();
347 B foo;
348 struct D;
349 D& zed(B);
350 void foobar() {
351 // NULL-INVALID: call noundef nonnull align 1 ptr @_ZN6PR66483zedENS_1BE
352 // NULL-VALID: call noundef align 1 ptr @_ZN6PR66483zedENS_1BE
353 zed(foo);
357 namespace UserConvertToValue {
358 struct X {
359 X(int);
360 X(const X&);
361 ~X();
364 void f(X);
366 // CHECK: void @_ZN18UserConvertToValue1gEv()
367 void g() {
368 // CHECK: call void @_ZN18UserConvertToValue1XC1Ei
369 // CHECK: call void @_ZN18UserConvertToValue1fENS_1XE
370 // CHECK: call void @_ZN18UserConvertToValue1XD1Ev
371 // CHECK: ret void
372 f(1);
376 namespace PR7556 {
377 struct A { ~A(); };
378 struct B { int i; ~B(); };
379 struct C { int C::*pm; ~C(); };
380 // CHECK-LABEL: define{{.*}} void @_ZN6PR75563fooEv()
381 void foo() {
382 // CHECK: call void @_ZN6PR75561AD1Ev
383 A();
384 // CHECK: call void @llvm.memset.p0.i64
385 // CHECK: call void @_ZN6PR75561BD1Ev
386 B();
387 // CHECK: call void @llvm.memcpy.p0.p0.i64
388 // CHECK: call void @_ZN6PR75561CD1Ev
389 C();
390 // CHECK-NEXT: ret void
394 namespace Elision {
395 struct A {
396 A(); A(const A &); ~A();
397 void *p;
398 void foo() const;
401 void foo();
402 A fooA();
403 void takeA(A a);
405 // CHECK-LABEL: define{{.*}} void @_ZN7Elision5test0Ev()
406 void test0() {
407 // CHECK: [[I:%.*]] = alloca [[A:%.*]], align 8
408 // CHECK-NEXT: [[J:%.*]] = alloca [[A]], align 8
409 // CHECK-NEXT: [[T0:%.*]] = alloca [[A]], align 8
410 // CHECK-NEXT: [[K:%.*]] = alloca [[A]], align 8
411 // CHECK-NEXT: [[T1:%.*]] = alloca [[A]], align 8
413 // CHECK-NEXT: call void @_ZN7Elision3fooEv()
414 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[I]])
415 A i = (foo(), A());
417 // CHECK-NEXT: call void @_ZN7Elision4fooAEv(ptr sret([[A]]) align 8 [[T0]])
418 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[J]])
419 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[T0]])
420 A j = (fooA(), A());
422 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[T1]])
423 // CHECK-NEXT: call void @_ZN7Elision4fooAEv(ptr sret([[A]]) align 8 [[K]])
424 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[T1]])
425 A k = (A(), fooA());
427 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[K]])
428 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[J]])
429 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[I]])
433 // CHECK-LABEL: define{{.*}} void @_ZN7Elision5test1EbNS_1AE(
434 void test1(bool c, A x) {
435 // CHECK: [[I:%.*]] = alloca [[A]], align 8
436 // CHECK-NEXT: [[J:%.*]] = alloca [[A]], align 8
438 // CHECK: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[I]])
439 // CHECK: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[I]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[X:%.*]])
440 A i = (c ? A() : x);
442 // CHECK: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[J]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[X]])
443 // CHECK: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[J]])
444 A j = (c ? x : A());
446 // CHECK: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[J]])
447 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[I]])
450 // CHECK: define{{.*}} void @_ZN7Elision5test2Ev(ptr noalias sret([[A]]) align 8
451 A test2() {
452 // CHECK: call void @_ZN7Elision3fooEv()
453 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[RET:%.*]])
454 // CHECK-NEXT: ret void
455 return (foo(), A());
458 // CHECK: define{{.*}} void @_ZN7Elision5test3EiNS_1AE(ptr noalias sret([[A]]) align 8
459 A test3(int v, A x) {
460 if (v < 5)
461 // CHECK: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[RET:%.*]])
462 // CHECK: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[RET]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[X:%.*]])
463 return (v < 0 ? A() : x);
464 else
465 // CHECK: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[RET]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[X]])
466 // CHECK: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[RET]])
467 return (v > 10 ? x : A());
469 // CHECK: ret void
472 // CHECK-LABEL: define{{.*}} void @_ZN7Elision5test4Ev()
473 void test4() {
474 // CHECK: [[X:%.*]] = alloca [[A]], align 8
475 // CHECK-NEXT: [[XS:%.*]] = alloca [2 x [[A]]], align 16
477 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[X]])
478 A x;
480 // CHECK-NEXT: [[XS0:%.*]] = getelementptr inbounds [2 x [[A]]], ptr [[XS]], i64 0, i64 0
481 // CHECK-NEXT: call void @_ZN7Elision1AC1Ev(ptr {{[^,]*}} [[XS0]])
482 // CHECK-NEXT: [[XS1:%.*]] = getelementptr inbounds [[A]], ptr [[XS0]], i64 1
483 // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[XS1]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[X]])
484 A xs[] = { A(), x };
486 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [2 x [[A]]], ptr [[XS]], i32 0, i32 0
487 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]], ptr [[BEGIN]], i64 2
488 // CHECK-NEXT: br label
489 // CHECK: [[AFTER:%.*]] = phi ptr
490 // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]], ptr [[AFTER]], i64 -1
491 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[CUR]])
492 // CHECK-NEXT: [[T0:%.*]] = icmp eq ptr [[CUR]], [[BEGIN]]
493 // CHECK-NEXT: br i1 [[T0]],
495 // CHECK: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[X]])
498 // CHECK: define{{.*}} void @_ZN7Elision5test5Ev(ptr noalias sret([[A]]) align 8
499 struct B { A a; B(); };
500 A test5() {
501 // CHECK: [[AT0:%.*]] = alloca [[A]], align 8
502 // CHECK-NEXT: [[BT0:%.*]] = alloca [[B:%.*]], align 8
503 // CHECK-NEXT: [[X:%.*]] = alloca [[A]], align 8
504 // CHECK-NEXT: [[BT1:%.*]] = alloca [[B]], align 8
505 // CHECK-NEXT: [[BT2:%.*]] = alloca [[B]], align 8
507 // CHECK: call void @_ZN7Elision1BC1Ev(ptr {{[^,]*}} [[BT0]])
508 // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]], ptr [[BT0]], i32 0, i32 0
509 // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[AT0]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[AM]])
510 // CHECK-NEXT: call void @_ZN7Elision5takeAENS_1AE(ptr noundef [[AT0]])
511 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[AT0]])
512 // CHECK-NEXT: call void @_ZN7Elision1BD1Ev(ptr {{[^,]*}} [[BT0]])
513 takeA(B().a);
515 // CHECK-NEXT: call void @_ZN7Elision1BC1Ev(ptr {{[^,]*}} [[BT1]])
516 // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]], ptr [[BT1]], i32 0, i32 0
517 // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[X]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[AM]])
518 // CHECK-NEXT: call void @_ZN7Elision1BD1Ev(ptr {{[^,]*}} [[BT1]])
519 A x = B().a;
521 // CHECK-NEXT: call void @_ZN7Elision1BC1Ev(ptr {{[^,]*}} [[BT2]])
522 // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]], ptr [[BT2]], i32 0, i32 0
523 // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_(ptr {{[^,]*}} [[RET:%.*]], ptr noundef {{(nonnull )?}}align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[AM]])
524 // CHECK-NEXT: call void @_ZN7Elision1BD1Ev(ptr {{[^,]*}} [[BT2]])
525 return B().a;
527 // CHECK: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[X]])
530 // Reduced from webkit.
531 // CHECK: define{{.*}} void @_ZN7Elision5test6EPKNS_1CE(ptr
532 struct C { operator A() const; };
533 void test6(const C *x) {
534 // CHECK: [[T0:%.*]] = alloca [[A]], align 8
535 // CHECK: [[X:%.*]] = load ptr, ptr {{%.*}}, align 8
536 // CHECK-NEXT: call void @_ZNK7Elision1CcvNS_1AEEv(ptr sret([[A]]) align 8 [[T0]], ptr {{[^,]*}} [[X]])
537 // CHECK-NEXT: call void @_ZNK7Elision1A3fooEv(ptr {{[^,]*}} [[T0]])
538 // CHECK-NEXT: call void @_ZN7Elision1AD1Ev(ptr {{[^,]*}} [[T0]])
539 // CHECK-NEXT: ret void
540 A(*x).foo();
544 namespace PR8623 {
545 struct A { A(int); ~A(); };
547 // CHECK-LABEL: define{{.*}} void @_ZN6PR86233fooEb(
548 void foo(bool b) {
549 // CHECK: [[TMP:%.*]] = alloca [[A:%.*]], align 1
550 // CHECK-NEXT: [[LCONS:%.*]] = alloca i1
551 // CHECK-NEXT: [[RCONS:%.*]] = alloca i1
552 // CHECK: store i1 false, ptr [[LCONS]]
553 // CHECK-NEXT: store i1 false, ptr [[RCONS]]
554 // CHECK-NEXT: br i1
555 // CHECK: call void @_ZN6PR86231AC1Ei(ptr {{[^,]*}} [[TMP]], i32 noundef 2)
556 // CHECK-NEXT: store i1 true, ptr [[LCONS]]
557 // CHECK-NEXT: br label
558 // CHECK: call void @_ZN6PR86231AC1Ei(ptr {{[^,]*}} [[TMP]], i32 noundef 3)
559 // CHECK-NEXT: store i1 true, ptr [[RCONS]]
560 // CHECK-NEXT: br label
561 // CHECK: load i1, ptr [[RCONS]]
562 // CHECK-NEXT: br i1
563 // CHECK: call void @_ZN6PR86231AD1Ev(ptr {{[^,]*}} [[TMP]])
564 // CHECK-NEXT: br label
565 // CHECK: load i1, ptr [[LCONS]]
566 // CHECK-NEXT: br i1
567 // CHECK: call void @_ZN6PR86231AD1Ev(ptr {{[^,]*}} [[TMP]])
568 // CHECK-NEXT: br label
569 // CHECK: ret void
570 b ? A(2) : A(3);
574 namespace PR11365 {
575 struct A { A(); ~A(); };
577 // CHECK-LABEL: define{{.*}} void @_ZN7PR113653fooEv(
578 void foo() {
579 // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [3 x [[A:%.*]]], ptr {{.*}}, i32 0, i32 0
580 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]], ptr [[BEGIN]], i64 3
581 // CHECK-NEXT: br label
583 // CHECK: [[PHI:%.*]] = phi
584 // CHECK-NEXT: [[ELEM:%.*]] = getelementptr inbounds [[A]], ptr [[PHI]], i64 -1
585 // CHECK-NEXT: call void @_ZN7PR113651AD1Ev(ptr {{[^,]*}} [[ELEM]])
586 // CHECK-NEXT: icmp eq ptr [[ELEM]], [[BEGIN]]
587 // CHECK-NEXT: br i1
588 (void) (A [3]) {};
592 namespace AssignmentOp {
593 struct A { ~A(); };
594 struct B { A operator=(const B&); };
595 struct C : B { B b1, b2; };
596 // CHECK-LABEL: define{{.*}} void @_ZN12AssignmentOp1fE
597 void f(C &c1, const C &c2) {
598 // CHECK: call {{.*}} @_ZN12AssignmentOp1CaSERKS0_(
599 c1 = c2;
602 // Ensure that each 'A' temporary is destroyed before the next subobject is
603 // copied.
604 // CHECK: define {{.*}} @_ZN12AssignmentOp1CaSERKS0_(
605 // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
606 // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
607 // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
608 // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
609 // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
610 // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
613 namespace BindToSubobject {
614 struct A {
615 A();
616 ~A();
617 int a;
620 void f(), g();
622 // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1aE_)
623 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN15BindToSubobject1AD1Ev, ptr @_ZGRN15BindToSubobject1aE_, ptr @__dso_handle)
624 // CHECK: store ptr @_ZGRN15BindToSubobject1aE_, ptr @_ZN15BindToSubobject1aE, align 8
625 int &&a = A().a;
627 // CHECK: call void @_ZN15BindToSubobject1fEv()
628 // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1bE_)
629 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN15BindToSubobject1AD1Ev, ptr @_ZGRN15BindToSubobject1bE_, ptr @__dso_handle)
630 // CHECK: store ptr @_ZGRN15BindToSubobject1bE_, ptr @_ZN15BindToSubobject1bE, align 8
631 int &&b = (f(), A().a);
633 int A::*h();
635 // CHECK: call void @_ZN15BindToSubobject1fEv()
636 // CHECK: call void @_ZN15BindToSubobject1gEv()
637 // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1cE_)
638 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN15BindToSubobject1AD1Ev, ptr @_ZGRN15BindToSubobject1cE_, ptr @__dso_handle)
639 // CHECK: call {{.*}} @_ZN15BindToSubobject1hE
640 // CHECK: getelementptr
641 // CHECK: store ptr {{.*}}, ptr @_ZN15BindToSubobject1cE, align 8
642 int &&c = (f(), (g(), A().*h()));
644 struct B {
645 int padding;
646 A a;
649 // CHECK: call void @_ZN15BindToSubobject1BC1Ev({{.*}} @_ZGRN15BindToSubobject1dE_)
650 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN15BindToSubobject1BD1Ev, ptr @_ZGRN15BindToSubobject1dE_, ptr @__dso_handle)
651 // CHECK: call {{.*}} @_ZN15BindToSubobject1hE
652 // CHECK: getelementptr {{.*}} getelementptr
653 // CHECK: store ptr {{.*}}, ptr @_ZN15BindToSubobject1dE, align 8
654 int &&d = (B().a).*h();
657 namespace Bitfield {
658 struct S { int a : 5; ~S(); };
660 // Do not lifetime extend the S() temporary here.
661 // CHECK: alloca
662 // CHECK: call {{.*}}memset
663 // CHECK: store i32 {{.*}}, ptr @_ZGRN8Bitfield1rE_
664 // CHECK: call void @_ZN8Bitfield1SD1
665 // CHECK: store ptr @_ZGRN8Bitfield1rE_, ptr @_ZN8Bitfield1rE, align 8
666 int &&r = S().a;
669 namespace Vector {
670 typedef __attribute__((vector_size(16))) int vi4a;
671 typedef __attribute__((ext_vector_type(4))) int vi4b;
672 struct S {
673 vi4a v;
674 vi4b w;
676 // CHECK: alloca
677 // CHECK: extractelement
678 // CHECK: store i32 {{.*}}, ptr @_ZGRN6Vector1rE_
679 // CHECK: store ptr @_ZGRN6Vector1rE_, ptr @_ZN6Vector1rE,
680 int &&r = S().v[1];
682 // CHECK: alloca
683 // CHECK: extractelement
684 // CHECK: store i32 {{.*}}, ptr @_ZGRN6Vector1sE_
685 // CHECK: store ptr @_ZGRN6Vector1sE_, ptr @_ZN6Vector1sE,
686 int &&s = S().w[1];
687 // FIXME PR16204: The following code leads to an assertion in Sema.
688 //int &&s = S().w.y;
691 namespace ImplicitTemporaryCleanup {
692 struct A { A(int); ~A(); };
693 void g();
695 // CHECK-LABEL: define{{.*}} void @_ZN24ImplicitTemporaryCleanup1fEv(
696 void f() {
697 // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1AC1Ei(
698 A &&a = 0;
700 // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1gEv(
701 g();
703 // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1AD1Ev(
707 namespace MultipleExtension {
708 struct A { A(); ~A(); };
709 struct B { B(); ~B(); };
710 struct C { C(); ~C(); };
711 struct D { D(); ~D(); int n; C c; };
712 struct E { const A &a; B b; const C &c; ~E(); };
714 E &&e1 = { A(), B(), D().c };
716 // CHECK: call void @_ZN17MultipleExtension1AC1Ev({{.*}} @[[TEMPA:_ZGRN17MultipleExtension2e1E.*]])
717 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1AD1Ev, {{.*}} @[[TEMPA]]
718 // CHECK: store {{.*}} @[[TEMPA]], {{.*}} @[[TEMPE:_ZGRN17MultipleExtension2e1E.*]],
720 // CHECK: call void @_ZN17MultipleExtension1BC1Ev({{.*}} getelementptr inbounds ({{.*}} @[[TEMPE]], i32 0, i32 1))
722 // CHECK: call void @_ZN17MultipleExtension1DC1Ev({{.*}} @[[TEMPD:_ZGRN17MultipleExtension2e1E.*]])
723 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1DD1Ev, {{.*}} @[[TEMPD]]
724 // CHECK: store {{.*}} @[[TEMPD]], {{.*}} getelementptr inbounds ({{.*}} @[[TEMPE]], i32 0, i32 2)
725 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1ED1Ev, {{.*}} @[[TEMPE]]
726 // CHECK: store {{.*}} @[[TEMPE]], ptr @_ZN17MultipleExtension2e1E, align 8
728 E e2 = { A(), B(), D().c };
730 // CHECK: call void @_ZN17MultipleExtension1AC1Ev({{.*}} @[[TEMPA:_ZGRN17MultipleExtension2e2E.*]])
731 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1AD1Ev, {{.*}} @[[TEMPA]]
732 // CHECK: store {{.*}} @[[TEMPA]], {{.*}} @[[E:_ZN17MultipleExtension2e2E]]
734 // CHECK: call void @_ZN17MultipleExtension1BC1Ev({{.*}} getelementptr inbounds ({{.*}} @[[E]], i32 0, i32 1))
736 // CHECK: call void @_ZN17MultipleExtension1DC1Ev({{.*}} @[[TEMPD:_ZGRN17MultipleExtension2e2E.*]])
737 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1DD1Ev, {{.*}} @[[TEMPD]]
738 // CHECK: store {{.*}} @[[TEMPD]], {{.*}} getelementptr inbounds ({{.*}} @[[E]], i32 0, i32 2)
739 // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1ED1Ev, {{.*}} @[[E]]
742 void g();
743 // CHECK: define{{.*}} void @[[NS:_ZN17MultipleExtension]]1fEv(
744 void f() {
745 E &&e1 = { A(), B(), D().c };
746 // CHECK: %[[TEMPE1_A:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1:.*]], i32 0, i32 0
747 // CHECK: call void @[[NS]]1AC1Ev({{.*}} %[[TEMPA1:.*]])
748 // CHECK: store {{.*}} %[[TEMPA1]], {{.*}} %[[TEMPE1_A]]
749 // CHECK: %[[TEMPE1_B:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1]], i32 0, i32 1
750 // CHECK: call void @[[NS]]1BC1Ev({{.*}} %[[TEMPE1_B]])
751 // CHECK: %[[TEMPE1_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1]], i32 0, i32 2
752 // CHECK: call void @[[NS]]1DC1Ev({{.*}} %[[TEMPD1:.*]])
753 // CHECK: %[[TEMPD1_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPD1]], i32 0, i32 1
754 // CHECK: store {{.*}} %[[TEMPD1_C]], {{.*}} %[[TEMPE1_C]]
755 // CHECK: store {{.*}} %[[TEMPE1]], {{.*}} %[[E1:.*]]
757 g();
758 // CHECK: call void @[[NS]]1gEv()
760 E e2 = { A(), B(), D().c };
761 // CHECK: %[[TEMPE2_A:.*]] = getelementptr inbounds {{.*}} %[[E2:.*]], i32 0, i32 0
762 // CHECK: call void @[[NS]]1AC1Ev({{.*}} %[[TEMPA2:.*]])
763 // CHECK: store {{.*}} %[[TEMPA2]], {{.*}} %[[TEMPE2_A]]
764 // CHECK: %[[TEMPE2_B:.*]] = getelementptr inbounds {{.*}} %[[E2]], i32 0, i32 1
765 // CHECK: call void @[[NS]]1BC1Ev({{.*}} %[[TEMPE2_B]])
766 // CHECK: %[[TEMPE2_C:.*]] = getelementptr inbounds {{.*}} %[[E2]], i32 0, i32 2
767 // CHECK: call void @[[NS]]1DC1Ev({{.*}} %[[TEMPD2:.*]])
768 // CHECK: %[[TEMPD2_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPD2]], i32 0, i32 1
769 // CHECK: store {{.*}} %[[TEMPD2_C]], ptr %[[TEMPE2_C]]
771 g();
772 // CHECK: call void @[[NS]]1gEv()
774 // CHECK: call void @[[NS]]1ED1Ev({{.*}} %[[E2]])
775 // CHECK: call void @[[NS]]1DD1Ev({{.*}} %[[TEMPD2]])
776 // CHECK: call void @[[NS]]1AD1Ev({{.*}} %[[TEMPA2]])
777 // CHECK: call void @[[NS]]1ED1Ev({{.*}} %[[TEMPE1]])
778 // CHECK: call void @[[NS]]1DD1Ev({{.*}} %[[TEMPD1]])
779 // CHECK: call void @[[NS]]1AD1Ev({{.*}} %[[TEMPA1]])
783 namespace ArrayAccess {
784 struct A { A(int); ~A(); };
785 void g();
786 void f() {
787 using T = A[3];
789 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 1
790 // CHECK-NOT: @_ZN11ArrayAccess1AD
791 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 2
792 // CHECK-NOT: @_ZN11ArrayAccess1AD
793 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 3
794 // CHECK-NOT: @_ZN11ArrayAccess1AD
795 A &&a = T{1, 2, 3}[1];
797 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 4
798 // CHECK-NOT: @_ZN11ArrayAccess1AD
799 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 5
800 // CHECK-NOT: @_ZN11ArrayAccess1AD
801 // CHECK: call void @_ZN11ArrayAccess1AC1Ei({{.*}}, i32 noundef 6
802 // CHECK-NOT: @_ZN11ArrayAccess1AD
803 A &&b = 2[T{4, 5, 6}];
805 // CHECK: call void @_ZN11ArrayAccess1gEv(
806 g();
808 // CHECK: call void @_ZN11ArrayAccess1AD
809 // CHECK: call void @_ZN11ArrayAccess1AD
813 namespace PR14130 {
814 struct S { S(int); };
815 struct U { S &&s; };
816 U v { { 0 } };
817 // CHECK: call void @_ZN7PR141301SC1Ei({{.*}} @_ZGRN7PR141301vE_, i32 noundef 0)
818 // CHECK: store {{.*}} @_ZGRN7PR141301vE_, {{.*}} @_ZN7PR141301vE
821 namespace Conditional {
822 struct A {};
823 struct B : A { B(); ~B(); };
824 struct C : A { C(); ~C(); };
826 void g();
828 // CHECK-LABEL: define {{.*}} @_ZN11Conditional1fEb(
829 void f(bool b) {
830 // CHECK: store i1 false, ptr %[[CLEANUP_B:.*]],
831 // CHECK: store i1 false, ptr %[[CLEANUP_C:.*]],
832 // CHECK: br i1
834 // CHECK: call {{.*}} @_ZN11Conditional1BC1Ev(
835 // CHECK: store i1 true, ptr %[[CLEANUP_B]],
836 // CHECK: br label
838 // CHECK: call {{.*}} @_ZN11Conditional1CC1Ev(
839 // CHECK: store i1 true, ptr %[[CLEANUP_C]],
840 // CHECK: br label
841 A &&r = b ? static_cast<A&&>(B()) : static_cast<A&&>(C());
843 // CHECK: call {{.*}} @_ZN11Conditional1gEv(
844 g();
846 // CHECK: load {{.*}} %[[CLEANUP_C]]
847 // CHECK: br i1
848 // CHECK: call {{.*}} @_ZN11Conditional1CD1Ev(
849 // CHECK: br label
851 // CHECK: load {{.*}} %[[CLEANUP_B]]
852 // CHECK: br i1
853 // CHECK: call {{.*}} @_ZN11Conditional1BD1Ev(
854 // CHECK: br label
857 struct D { A &&a; };
858 // CHECK-LABEL: define {{.*}} @_ZN11Conditional10f_indirectEb(
859 void f_indirect(bool b) {
860 // CHECK: store i1 false, ptr %[[CLEANUP_B:.*]],
861 // CHECK: store i1 false, ptr %[[CLEANUP_C:.*]],
862 // CHECK: br i1
864 // CHECK: call {{.*}} @_ZN11Conditional1BC1Ev(
865 // CHECK: store i1 true, ptr %[[CLEANUP_B]],
866 // CHECK: br label
868 // CHECK: call {{.*}} @_ZN11Conditional1CC1Ev(
869 // CHECK: store i1 true, ptr %[[CLEANUP_C]],
870 // CHECK: br label
871 D d = b ? D{B()} : D{C()};
873 // In C++17, the expression D{...} directly initializes the 'd' object, so
874 // lifetime-extending the temporaries to the lifetime of the D object
875 // extends them past the call to g().
877 // In C++14 and before, D is move-constructed from the result of the
878 // conditional expression, so no lifetime extension occurs.
880 // CHECK-CXX17: call {{.*}} @_ZN11Conditional1gEv(
882 // CHECK: load {{.*}} %[[CLEANUP_C]]
883 // CHECK: br i1
884 // CHECK: call {{.*}} @_ZN11Conditional1CD1Ev(
885 // CHECK: br label
887 // CHECK: load {{.*}} %[[CLEANUP_B]]
888 // CHECK: br i1
889 // CHECK: call {{.*}} @_ZN11Conditional1BD1Ev(
890 // CHECK: br label
892 // CHECK-CXX11: call {{.*}} @_ZN11Conditional1gEv(
893 g();
896 extern bool b;
897 // CHECK: load {{.*}} @_ZN11Conditional1b
898 // CHECK: br i1
900 // CHECK: call {{.*}} @_ZN11Conditional1BC1Ev({{.*}} @_ZGRN11Conditional1rE_)
901 // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN11Conditional1BD1Ev, ptr @_ZGRN11Conditional1rE_,
902 // CHECK: br label
904 // CHECK: call {{.*}} @_ZN11Conditional1CC1Ev({{.*}} @_ZGRN11Conditional1rE0_)
905 // CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN11Conditional1CD1Ev, ptr @_ZGRN11Conditional1rE0_,
906 // CHECK: br label
907 A &&r = b ? static_cast<A&&>(B()) : static_cast<A&&>(C());
910 #if __cplusplus >= 201703L
911 namespace PR42220 {
912 struct X { X(); ~X(); };
913 struct A { X &&x; };
914 struct B : A {};
915 void g() noexcept;
916 // CHECK-CXX17-LABEL: define{{.*}} @_ZN7PR422201fEv(
917 void f() {
918 // CHECK-CXX17: call{{.*}} @_ZN7PR422201XC1Ev(
919 B &&b = {X()};
920 // CHECK-CXX17-NOT: call{{.*}} @_ZN7PR422201XD1Ev(
921 // CHECK-CXX17: call{{.*}} @_ZN7PR422201gEv(
922 g();
923 // CHECK-CXX17: call{{.*}} @_ZN7PR422201XD1Ev(
926 #endif