xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/temporaries.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-apple-darwin9 -std=c++11 | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc namespace PR16263 {
4f4a2713aSLionel Sambuc   const unsigned int n = 1234;
5f4a2713aSLionel Sambuc   extern const int &r = (const int&)n;
6*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR162631rE_ = private constant i32 1234,
7*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN7PR162631rE = constant i32* @_ZGRN7PR162631rE_,
8f4a2713aSLionel Sambuc 
9f4a2713aSLionel Sambuc   extern const int &s = reinterpret_cast<const int&>(n);
10f4a2713aSLionel Sambuc   // CHECK: @_ZN7PR16263L1nE = internal constant i32 1234, align 4
11f4a2713aSLionel Sambuc   // CHECK: @_ZN7PR162631sE = constant i32* @_ZN7PR16263L1nE, align 8
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc   struct A { int n; };
14f4a2713aSLionel Sambuc   struct B { int n; };
15f4a2713aSLionel Sambuc   struct C : A, B {};
16f4a2713aSLionel Sambuc   extern const A &&a = (A&&)(A&&)(C&&)(C{});
17*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR162631aE_ = private global {{.*}} zeroinitializer,
18*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN7PR162631aE = constant {{.*}} bitcast ({{.*}}* @_ZGRN7PR162631aE_ to
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc   extern const int &&t = ((B&&)C{}).n;
21*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR162631tE_ = private global {{.*}} zeroinitializer,
22*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN7PR162631tE = constant i32* {{.*}}* @_ZGRN7PR162631tE_ {{.*}} 4
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc   struct D { double d; C c; };
25f4a2713aSLionel Sambuc   extern const int &&u = (123, static_cast<B&&>(0, ((D&&)D{}).*&D::c).n);
26*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR162631uE_ = private global {{.*}} zeroinitializer
27*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN7PR162631uE = constant i32* {{.*}} @_ZGRN7PR162631uE_ {{.*}} 12
28*0a6a1f1dSLionel Sambuc }
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc namespace PR20227 {
31*0a6a1f1dSLionel Sambuc   struct A { ~A(); };
32*0a6a1f1dSLionel Sambuc   struct B { virtual ~B(); };
33*0a6a1f1dSLionel Sambuc   struct C : B {};
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc   A &&a = dynamic_cast<A&&>(A{});
36*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR202271aE_ = private global
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc   B &&b = dynamic_cast<C&&>(dynamic_cast<B&&>(C{}));
39*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR202271bE_ = private global
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc   B &&c = static_cast<C&&>(static_cast<B&&>(C{}));
42*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN7PR202271cE_ = private global
43*0a6a1f1dSLionel Sambuc }
44*0a6a1f1dSLionel Sambuc 
45*0a6a1f1dSLionel Sambuc namespace BraceInit {
46*0a6a1f1dSLionel Sambuc   typedef const int &CIR;
47*0a6a1f1dSLionel Sambuc   CIR x = CIR{3};
48*0a6a1f1dSLionel Sambuc   // CHECK: @_ZGRN9BraceInit1xE_ = private constant i32 3
49*0a6a1f1dSLionel Sambuc   // CHECK: @_ZN9BraceInit1xE = constant i32* @_ZGRN9BraceInit1xE_
50f4a2713aSLionel Sambuc }
51f4a2713aSLionel Sambuc 
52f4a2713aSLionel Sambuc struct A {
53f4a2713aSLionel Sambuc   A();
54f4a2713aSLionel Sambuc   ~A();
55f4a2713aSLionel Sambuc   void f();
56f4a2713aSLionel Sambuc };
57f4a2713aSLionel Sambuc 
f1()58f4a2713aSLionel Sambuc void f1() {
59f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AC1Ev
60f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AD1Ev
61f4a2713aSLionel Sambuc   (void)A();
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AC1Ev
64f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AD1Ev
65f4a2713aSLionel Sambuc   A().f();
66f4a2713aSLionel Sambuc }
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc // Function calls
69f4a2713aSLionel Sambuc struct B {
70f4a2713aSLionel Sambuc   B();
71f4a2713aSLionel Sambuc   ~B();
72f4a2713aSLionel Sambuc };
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc B g();
75f4a2713aSLionel Sambuc 
f2()76f4a2713aSLionel Sambuc void f2() {
77f4a2713aSLionel Sambuc   // CHECK-NOT: call void @_ZN1BC1Ev
78f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1BD1Ev
79f4a2713aSLionel Sambuc   (void)g();
80f4a2713aSLionel Sambuc }
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc // Member function calls
83f4a2713aSLionel Sambuc struct C {
84f4a2713aSLionel Sambuc   C();
85f4a2713aSLionel Sambuc   ~C();
86f4a2713aSLionel Sambuc 
87f4a2713aSLionel Sambuc   C f();
88f4a2713aSLionel Sambuc };
89f4a2713aSLionel Sambuc 
f3()90f4a2713aSLionel Sambuc void f3() {
91f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1CC1Ev
92f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1CD1Ev
93f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1CD1Ev
94f4a2713aSLionel Sambuc   C().f();
95f4a2713aSLionel Sambuc }
96f4a2713aSLionel Sambuc 
97f4a2713aSLionel Sambuc // Function call operator
98f4a2713aSLionel Sambuc struct D {
99f4a2713aSLionel Sambuc   D();
100f4a2713aSLionel Sambuc   ~D();
101f4a2713aSLionel Sambuc 
102f4a2713aSLionel Sambuc   D operator()();
103f4a2713aSLionel Sambuc };
104f4a2713aSLionel Sambuc 
f4()105f4a2713aSLionel Sambuc void f4() {
106f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1DC1Ev
107f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1DD1Ev
108f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1DD1Ev
109f4a2713aSLionel Sambuc   D()();
110f4a2713aSLionel Sambuc }
111f4a2713aSLionel Sambuc 
112f4a2713aSLionel Sambuc // Overloaded operators
113f4a2713aSLionel Sambuc struct E {
114f4a2713aSLionel Sambuc   E();
115f4a2713aSLionel Sambuc   ~E();
116f4a2713aSLionel Sambuc   E operator+(const E&);
117f4a2713aSLionel Sambuc   E operator!();
118f4a2713aSLionel Sambuc };
119f4a2713aSLionel Sambuc 
f5()120f4a2713aSLionel Sambuc void f5() {
121f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1EC1Ev
122f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1EC1Ev
123f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1ED1Ev
124f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1ED1Ev
125f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1ED1Ev
126f4a2713aSLionel Sambuc   E() + E();
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1EC1Ev
129f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1ED1Ev
130f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1ED1Ev
131f4a2713aSLionel Sambuc   !E();
132f4a2713aSLionel Sambuc }
133f4a2713aSLionel Sambuc 
134f4a2713aSLionel Sambuc struct F {
135f4a2713aSLionel Sambuc   F();
136f4a2713aSLionel Sambuc   ~F();
137f4a2713aSLionel Sambuc   F& f();
138f4a2713aSLionel Sambuc };
139f4a2713aSLionel Sambuc 
f6()140f4a2713aSLionel Sambuc void f6() {
141f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1FC1Ev
142f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1FD1Ev
143f4a2713aSLionel Sambuc   F().f();
144f4a2713aSLionel Sambuc }
145f4a2713aSLionel Sambuc 
146f4a2713aSLionel Sambuc struct G {
147f4a2713aSLionel Sambuc   G();
148f4a2713aSLionel Sambuc   G(A);
149f4a2713aSLionel Sambuc   ~G();
150f4a2713aSLionel Sambuc   operator A();
151f4a2713aSLionel Sambuc };
152f4a2713aSLionel Sambuc 
153f4a2713aSLionel Sambuc void a(const A&);
154f4a2713aSLionel Sambuc 
f7()155f4a2713aSLionel Sambuc void f7() {
156f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AC1Ev
157f4a2713aSLionel Sambuc   // CHECK: call void @_Z1aRK1A
158f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AD1Ev
159f4a2713aSLionel Sambuc   a(A());
160f4a2713aSLionel Sambuc 
161f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1GC1Ev
162f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1Gcv1AEv
163f4a2713aSLionel Sambuc   // CHECK: call void @_Z1aRK1A
164f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AD1Ev
165f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1GD1Ev
166f4a2713aSLionel Sambuc   a(G());
167f4a2713aSLionel Sambuc }
168f4a2713aSLionel Sambuc 
169f4a2713aSLionel Sambuc namespace PR5077 {
170f4a2713aSLionel Sambuc 
171f4a2713aSLionel Sambuc struct A {
172f4a2713aSLionel Sambuc   A();
173f4a2713aSLionel Sambuc   ~A();
174f4a2713aSLionel Sambuc   int f();
175f4a2713aSLionel Sambuc };
176f4a2713aSLionel Sambuc 
177f4a2713aSLionel Sambuc void f();
178f4a2713aSLionel Sambuc int g(const A&);
179f4a2713aSLionel Sambuc 
180f4a2713aSLionel Sambuc struct B {
181f4a2713aSLionel Sambuc   int a1;
182f4a2713aSLionel Sambuc   int a2;
183f4a2713aSLionel Sambuc   B();
184f4a2713aSLionel Sambuc   ~B();
185f4a2713aSLionel Sambuc };
186f4a2713aSLionel Sambuc 
B()187f4a2713aSLionel Sambuc B::B()
188f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771AC1Ev
189f4a2713aSLionel Sambuc   // CHECK: call i32 @_ZN6PR50771A1fEv
190f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771AD1Ev
191f4a2713aSLionel Sambuc   : a1(A().f())
192f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771AC1Ev
193f4a2713aSLionel Sambuc   // CHECK: call i32 @_ZN6PR50771gERKNS_1AE
194f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771AD1Ev
195f4a2713aSLionel Sambuc   , a2(g(A()))
196f4a2713aSLionel Sambuc {
197f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771fEv
198f4a2713aSLionel Sambuc   f();
199f4a2713aSLionel Sambuc }
200f4a2713aSLionel Sambuc 
201f4a2713aSLionel Sambuc struct C {
202f4a2713aSLionel Sambuc   C();
203f4a2713aSLionel Sambuc 
204f4a2713aSLionel Sambuc   const B& b;
205f4a2713aSLionel Sambuc };
206f4a2713aSLionel Sambuc 
C()207f4a2713aSLionel Sambuc C::C()
208f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771BC1Ev
209f4a2713aSLionel Sambuc   : b(B()) {
210f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771fEv
211f4a2713aSLionel Sambuc   f();
212f4a2713aSLionel Sambuc 
213f4a2713aSLionel Sambuc   // CHECK: call void @_ZN6PR50771BD1Ev
214f4a2713aSLionel Sambuc }
215f4a2713aSLionel Sambuc }
216f4a2713aSLionel Sambuc 
f8()217f4a2713aSLionel Sambuc A f8() {
218f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1AC1Ev
219f4a2713aSLionel Sambuc   // CHECK-NOT: call void @_ZN1AD1Ev
220f4a2713aSLionel Sambuc   return A();
221f4a2713aSLionel Sambuc   // CHECK: ret void
222f4a2713aSLionel Sambuc }
223f4a2713aSLionel Sambuc 
224f4a2713aSLionel Sambuc struct H {
225f4a2713aSLionel Sambuc   H();
226f4a2713aSLionel Sambuc   ~H();
227f4a2713aSLionel Sambuc   H(const H&);
228f4a2713aSLionel Sambuc };
229f4a2713aSLionel Sambuc 
f9(H h)230f4a2713aSLionel Sambuc void f9(H h) {
231f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HC1Ev
232f4a2713aSLionel Sambuc   // CHECK: call void @_Z2f91H
233f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HD1Ev
234f4a2713aSLionel Sambuc   f9(H());
235f4a2713aSLionel Sambuc 
236f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HC1ERKS_
237f4a2713aSLionel Sambuc   // CHECK: call void @_Z2f91H
238f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HD1Ev
239f4a2713aSLionel Sambuc   f9(h);
240f4a2713aSLionel Sambuc }
241f4a2713aSLionel Sambuc 
242f4a2713aSLionel Sambuc void f10(const H&);
243f4a2713aSLionel Sambuc 
f11(H h)244f4a2713aSLionel Sambuc void f11(H h) {
245f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HC1Ev
246f4a2713aSLionel Sambuc   // CHECK: call void @_Z3f10RK1H
247f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1HD1Ev
248f4a2713aSLionel Sambuc   f10(H());
249f4a2713aSLionel Sambuc 
250f4a2713aSLionel Sambuc   // CHECK: call void @_Z3f10RK1H
251f4a2713aSLionel Sambuc   // CHECK-NOT: call void @_ZN1HD1Ev
252f4a2713aSLionel Sambuc   // CHECK: ret void
253f4a2713aSLionel Sambuc   f10(h);
254f4a2713aSLionel Sambuc }
255f4a2713aSLionel Sambuc 
256f4a2713aSLionel Sambuc // PR5808
257f4a2713aSLionel Sambuc struct I {
258f4a2713aSLionel Sambuc   I(const char *);
259f4a2713aSLionel Sambuc   ~I();
260f4a2713aSLionel Sambuc };
261f4a2713aSLionel Sambuc 
262f4a2713aSLionel Sambuc // CHECK: _Z3f12v
f12()263f4a2713aSLionel Sambuc I f12() {
264f4a2713aSLionel Sambuc   // CHECK: call void @_ZN1IC1EPKc
265f4a2713aSLionel Sambuc   // CHECK-NOT: call void @_ZN1ID1Ev
266f4a2713aSLionel Sambuc   // CHECK: ret void
267f4a2713aSLionel Sambuc   return "Hello";
268f4a2713aSLionel Sambuc }
269f4a2713aSLionel Sambuc 
270f4a2713aSLionel Sambuc // PR5867
271f4a2713aSLionel Sambuc namespace PR5867 {
272f4a2713aSLionel Sambuc   struct S {
273f4a2713aSLionel Sambuc     S();
274f4a2713aSLionel Sambuc     S(const S &);
275f4a2713aSLionel Sambuc     ~S();
276f4a2713aSLionel Sambuc   };
277f4a2713aSLionel Sambuc 
278f4a2713aSLionel Sambuc   void f(S, int);
279f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN6PR58671gEv
g()280f4a2713aSLionel Sambuc   void g() {
281f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR58671SC1Ev
282f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN6PR58671fENS_1SEi
283f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN6PR58671SD1Ev
284f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
285f4a2713aSLionel Sambuc     (f)(S(), 0);
286f4a2713aSLionel Sambuc   }
287f4a2713aSLionel Sambuc 
288f4a2713aSLionel Sambuc   // CHECK-LABEL: define linkonce_odr void @_ZN6PR58672g2IiEEvT_
289f4a2713aSLionel Sambuc   template<typename T>
g2(T)290f4a2713aSLionel Sambuc   void g2(T) {
291f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR58671SC1Ev
292f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN6PR58671fENS_1SEi
293f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN6PR58671SD1Ev
294f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
295f4a2713aSLionel Sambuc     (f)(S(), 0);
296f4a2713aSLionel Sambuc   }
297f4a2713aSLionel Sambuc 
h()298f4a2713aSLionel Sambuc   void h() {
299f4a2713aSLionel Sambuc     g2(17);
300f4a2713aSLionel Sambuc   }
301f4a2713aSLionel Sambuc }
302f4a2713aSLionel Sambuc 
303f4a2713aSLionel Sambuc // PR6199
304f4a2713aSLionel Sambuc namespace PR6199 {
305f4a2713aSLionel Sambuc   struct A { ~A(); };
306f4a2713aSLionel Sambuc 
307f4a2713aSLionel Sambuc   struct B { operator A(); };
308f4a2713aSLionel Sambuc 
309f4a2713aSLionel Sambuc   // CHECK-LABEL: define weak_odr void @_ZN6PR61992f2IiEENS_1AET_
f2(T)310f4a2713aSLionel Sambuc   template<typename T> A f2(T) {
311f4a2713aSLionel Sambuc     B b;
312f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR61991BcvNS_1AEEv
313f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
314f4a2713aSLionel Sambuc     return b;
315f4a2713aSLionel Sambuc   }
316f4a2713aSLionel Sambuc 
317f4a2713aSLionel Sambuc   template A f2<int>(int);
318f4a2713aSLionel Sambuc 
319f4a2713aSLionel Sambuc }
320f4a2713aSLionel Sambuc 
321f4a2713aSLionel Sambuc namespace T12 {
322f4a2713aSLionel Sambuc 
323f4a2713aSLionel Sambuc struct A {
324f4a2713aSLionel Sambuc   A();
325f4a2713aSLionel Sambuc   ~A();
326f4a2713aSLionel Sambuc   int f();
327f4a2713aSLionel Sambuc };
328f4a2713aSLionel Sambuc 
329f4a2713aSLionel Sambuc int& f(int);
330f4a2713aSLionel Sambuc 
331f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN3T121gEv
g()332f4a2713aSLionel Sambuc void g() {
333f4a2713aSLionel Sambuc   // CHECK: call void @_ZN3T121AC1Ev
334f4a2713aSLionel Sambuc   // CHECK-NEXT: call i32 @_ZN3T121A1fEv(
335*0a6a1f1dSLionel Sambuc   // CHECK-NEXT: call dereferenceable({{[0-9]+}}) i32* @_ZN3T121fEi(
336f4a2713aSLionel Sambuc   // CHECK-NEXT: call void @_ZN3T121AD1Ev(
337f4a2713aSLionel Sambuc   int& i = f(A().f());
338f4a2713aSLionel Sambuc }
339f4a2713aSLionel Sambuc 
340f4a2713aSLionel Sambuc }
341f4a2713aSLionel Sambuc 
342f4a2713aSLionel Sambuc namespace PR6648 {
343f4a2713aSLionel Sambuc   struct B {
344f4a2713aSLionel Sambuc     ~B();
345f4a2713aSLionel Sambuc   };
346f4a2713aSLionel Sambuc   B foo;
347f4a2713aSLionel Sambuc   struct D;
348f4a2713aSLionel Sambuc   D& zed(B);
foobar()349f4a2713aSLionel Sambuc   void foobar() {
350*0a6a1f1dSLionel Sambuc     // CHECK: call nonnull %"struct.PR6648::D"* @_ZN6PR66483zedENS_1BE
351f4a2713aSLionel Sambuc     zed(foo);
352f4a2713aSLionel Sambuc   }
353f4a2713aSLionel Sambuc }
354f4a2713aSLionel Sambuc 
355f4a2713aSLionel Sambuc namespace UserConvertToValue {
356f4a2713aSLionel Sambuc   struct X {
357f4a2713aSLionel Sambuc     X(int);
358f4a2713aSLionel Sambuc     X(const X&);
359f4a2713aSLionel Sambuc     ~X();
360f4a2713aSLionel Sambuc   };
361f4a2713aSLionel Sambuc 
362f4a2713aSLionel Sambuc   void f(X);
363f4a2713aSLionel Sambuc 
364f4a2713aSLionel Sambuc   // CHECK: void @_ZN18UserConvertToValue1gEv()
g()365f4a2713aSLionel Sambuc   void g() {
366f4a2713aSLionel Sambuc     // CHECK: call void @_ZN18UserConvertToValue1XC1Ei
367f4a2713aSLionel Sambuc     // CHECK: call void @_ZN18UserConvertToValue1fENS_1XE
368f4a2713aSLionel Sambuc     // CHECK: call void @_ZN18UserConvertToValue1XD1Ev
369f4a2713aSLionel Sambuc     // CHECK: ret void
370f4a2713aSLionel Sambuc     f(1);
371f4a2713aSLionel Sambuc   }
372f4a2713aSLionel Sambuc }
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc namespace PR7556 {
375f4a2713aSLionel Sambuc   struct A { ~A(); };
376f4a2713aSLionel Sambuc   struct B { int i; ~B(); };
377f4a2713aSLionel Sambuc   struct C { int C::*pm; ~C(); };
378f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN6PR75563fooEv()
foo()379f4a2713aSLionel Sambuc   void foo() {
380f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR75561AD1Ev
381f4a2713aSLionel Sambuc     A();
382f4a2713aSLionel Sambuc     // CHECK: call void @llvm.memset.p0i8.i64
383f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR75561BD1Ev
384f4a2713aSLionel Sambuc     B();
385f4a2713aSLionel Sambuc     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
386f4a2713aSLionel Sambuc     // CHECK: call void @_ZN6PR75561CD1Ev
387f4a2713aSLionel Sambuc     C();
388f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
389f4a2713aSLionel Sambuc   }
390f4a2713aSLionel Sambuc }
391f4a2713aSLionel Sambuc 
392f4a2713aSLionel Sambuc namespace Elision {
393f4a2713aSLionel Sambuc   struct A {
394f4a2713aSLionel Sambuc     A(); A(const A &); ~A();
395f4a2713aSLionel Sambuc     void *p;
396f4a2713aSLionel Sambuc     void foo() const;
397f4a2713aSLionel Sambuc   };
398f4a2713aSLionel Sambuc 
399f4a2713aSLionel Sambuc   void foo();
400f4a2713aSLionel Sambuc   A fooA();
401f4a2713aSLionel Sambuc   void takeA(A a);
402f4a2713aSLionel Sambuc 
403f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN7Elision5test0Ev()
test0()404f4a2713aSLionel Sambuc   void test0() {
405f4a2713aSLionel Sambuc     // CHECK:      [[I:%.*]] = alloca [[A:%.*]], align 8
406f4a2713aSLionel Sambuc     // CHECK-NEXT: [[J:%.*]] = alloca [[A]], align 8
407f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T0:%.*]] = alloca [[A]], align 8
408f4a2713aSLionel Sambuc     // CHECK-NEXT: [[K:%.*]] = alloca [[A]], align 8
409f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T1:%.*]] = alloca [[A]], align 8
410f4a2713aSLionel Sambuc 
411f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision3fooEv()
412f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[I]])
413f4a2713aSLionel Sambuc     A i = (foo(), A());
414f4a2713aSLionel Sambuc 
415f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision4fooAEv([[A]]* sret [[T0]])
416f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[J]])
417f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[T0]])
418f4a2713aSLionel Sambuc     A j = (fooA(), A());
419f4a2713aSLionel Sambuc 
420f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[T1]])
421f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision4fooAEv([[A]]* sret [[K]])
422f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[T1]])
423f4a2713aSLionel Sambuc     A k = (A(), fooA());
424f4a2713aSLionel Sambuc 
425f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[K]])
426f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[J]])
427f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[I]])
428f4a2713aSLionel Sambuc   }
429f4a2713aSLionel Sambuc 
430f4a2713aSLionel Sambuc 
431f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN7Elision5test1EbNS_1AE(
test1(bool c,A x)432f4a2713aSLionel Sambuc   void test1(bool c, A x) {
433f4a2713aSLionel Sambuc     // CHECK:      [[I:%.*]] = alloca [[A]], align 8
434f4a2713aSLionel Sambuc     // CHECK-NEXT: [[J:%.*]] = alloca [[A]], align 8
435f4a2713aSLionel Sambuc 
436f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1Ev([[A]]* [[I]])
437*0a6a1f1dSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1ERKS0_([[A]]* [[I]], [[A]]* dereferenceable({{[0-9]+}}) [[X:%.*]])
438f4a2713aSLionel Sambuc     A i = (c ? A() : x);
439f4a2713aSLionel Sambuc 
440*0a6a1f1dSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1ERKS0_([[A]]* [[J]], [[A]]* dereferenceable({{[0-9]+}}) [[X]])
441f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1Ev([[A]]* [[J]])
442f4a2713aSLionel Sambuc     A j = (c ? x : A());
443f4a2713aSLionel Sambuc 
444f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AD1Ev([[A]]* [[J]])
445f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[I]])
446f4a2713aSLionel Sambuc   }
447f4a2713aSLionel Sambuc 
448f4a2713aSLionel Sambuc   // CHECK: define void @_ZN7Elision5test2Ev([[A]]* noalias sret
test2()449f4a2713aSLionel Sambuc   A test2() {
450f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision3fooEv()
451f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[RET:%.*]])
452f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
453f4a2713aSLionel Sambuc     return (foo(), A());
454f4a2713aSLionel Sambuc   }
455f4a2713aSLionel Sambuc 
456f4a2713aSLionel Sambuc   // CHECK: define void @_ZN7Elision5test3EiNS_1AE([[A]]* noalias sret
test3(int v,A x)457f4a2713aSLionel Sambuc   A test3(int v, A x) {
458f4a2713aSLionel Sambuc     if (v < 5)
459f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1Ev([[A]]* [[RET:%.*]])
460*0a6a1f1dSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1ERKS0_([[A]]* [[RET]], [[A]]* dereferenceable({{[0-9]+}}) [[X:%.*]])
461f4a2713aSLionel Sambuc       return (v < 0 ? A() : x);
462f4a2713aSLionel Sambuc     else
463*0a6a1f1dSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1ERKS0_([[A]]* [[RET]], [[A]]* dereferenceable({{[0-9]+}}) [[X]])
464f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AC1Ev([[A]]* [[RET]])
465f4a2713aSLionel Sambuc       return (v > 10 ? x : A());
466f4a2713aSLionel Sambuc 
467f4a2713aSLionel Sambuc     // CHECK:      ret void
468f4a2713aSLionel Sambuc   }
469f4a2713aSLionel Sambuc 
470f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN7Elision5test4Ev()
test4()471f4a2713aSLionel Sambuc   void test4() {
472f4a2713aSLionel Sambuc     // CHECK:      [[X:%.*]] = alloca [[A]], align 8
473f4a2713aSLionel Sambuc     // CHECK-NEXT: [[XS:%.*]] = alloca [2 x [[A]]], align 16
474f4a2713aSLionel Sambuc 
475f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[X]])
476f4a2713aSLionel Sambuc     A x;
477f4a2713aSLionel Sambuc 
478f4a2713aSLionel Sambuc     // CHECK-NEXT: [[XS0:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i64 0, i64 0
479f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1Ev([[A]]* [[XS0]])
480f4a2713aSLionel Sambuc     // CHECK-NEXT: [[XS1:%.*]] = getelementptr inbounds [[A]]* [[XS0]], i64 1
481*0a6a1f1dSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_([[A]]* [[XS1]], [[A]]* dereferenceable({{[0-9]+}}) [[X]])
482f4a2713aSLionel Sambuc     A xs[] = { A(), x };
483f4a2713aSLionel Sambuc 
484f4a2713aSLionel Sambuc     // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [2 x [[A]]]* [[XS]], i32 0, i32 0
485f4a2713aSLionel Sambuc     // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 2
486f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
487f4a2713aSLionel Sambuc     // CHECK:      [[AFTER:%.*]] = phi [[A]]*
488f4a2713aSLionel Sambuc     // CHECK-NEXT: [[CUR:%.*]] = getelementptr inbounds [[A]]* [[AFTER]], i64 -1
489f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[CUR]])
490f4a2713aSLionel Sambuc     // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[CUR]], [[BEGIN]]
491f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1 [[T0]],
492f4a2713aSLionel Sambuc 
493f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AD1Ev([[A]]* [[X]])
494f4a2713aSLionel Sambuc   }
495f4a2713aSLionel Sambuc 
496f4a2713aSLionel Sambuc   // rdar://problem/8433352
497f4a2713aSLionel Sambuc   // CHECK: define void @_ZN7Elision5test5Ev([[A]]* noalias sret
498f4a2713aSLionel Sambuc   struct B { A a; B(); };
test5()499f4a2713aSLionel Sambuc   A test5() {
500f4a2713aSLionel Sambuc     // CHECK:      [[AT0:%.*]] = alloca [[A]], align 8
501f4a2713aSLionel Sambuc     // CHECK-NEXT: [[BT0:%.*]] = alloca [[B:%.*]], align 8
502f4a2713aSLionel Sambuc     // CHECK-NEXT: [[X:%.*]] = alloca [[A]], align 8
503f4a2713aSLionel Sambuc     // CHECK-NEXT: [[BT1:%.*]] = alloca [[B]], align 8
504f4a2713aSLionel Sambuc     // CHECK-NEXT: [[BT2:%.*]] = alloca [[B]], align 8
505f4a2713aSLionel Sambuc 
506f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1BC1Ev([[B]]* [[BT0]])
507f4a2713aSLionel Sambuc     // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]]* [[BT0]], i32 0, i32 0
508*0a6a1f1dSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_([[A]]* [[AT0]], [[A]]* dereferenceable({{[0-9]+}}) [[AM]])
509f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision5takeAENS_1AE([[A]]* [[AT0]])
510f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[AT0]])
511f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1BD1Ev([[B]]* [[BT0]])
512f4a2713aSLionel Sambuc     takeA(B().a);
513f4a2713aSLionel Sambuc 
514f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1BC1Ev([[B]]* [[BT1]])
515f4a2713aSLionel Sambuc     // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]]* [[BT1]], i32 0, i32 0
516*0a6a1f1dSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_([[A]]* [[X]], [[A]]* dereferenceable({{[0-9]+}}) [[AM]])
517f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1BD1Ev([[B]]* [[BT1]])
518f4a2713aSLionel Sambuc     A x = B().a;
519f4a2713aSLionel Sambuc 
520f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1BC1Ev([[B]]* [[BT2]])
521f4a2713aSLionel Sambuc     // CHECK-NEXT: [[AM:%.*]] = getelementptr inbounds [[B]]* [[BT2]], i32 0, i32 0
522*0a6a1f1dSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AC1ERKS0_([[A]]* [[RET:%.*]], [[A]]* dereferenceable({{[0-9]+}}) [[AM]])
523f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1BD1Ev([[B]]* [[BT2]])
524f4a2713aSLionel Sambuc     return B().a;
525f4a2713aSLionel Sambuc 
526f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN7Elision1AD1Ev([[A]]* [[X]])
527f4a2713aSLionel Sambuc   }
528f4a2713aSLionel Sambuc 
529f4a2713aSLionel Sambuc   // Reduced from webkit.
530f4a2713aSLionel Sambuc   // CHECK: define void @_ZN7Elision5test6EPKNS_1CE([[C:%.*]]*
531f4a2713aSLionel Sambuc   struct C { operator A() const; };
test6(const C * x)532f4a2713aSLionel Sambuc   void test6(const C *x) {
533f4a2713aSLionel Sambuc     // CHECK:      [[T0:%.*]] = alloca [[A]], align 8
534f4a2713aSLionel Sambuc     // CHECK:      [[X:%.*]] = load [[C]]** {{%.*}}, align 8
535f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZNK7Elision1CcvNS_1AEEv([[A]]* sret [[T0]], [[C]]* [[X]])
536f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZNK7Elision1A3fooEv([[A]]* [[T0]])
537f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7Elision1AD1Ev([[A]]* [[T0]])
538f4a2713aSLionel Sambuc     // CHECK-NEXT: ret void
539f4a2713aSLionel Sambuc     A(*x).foo();
540f4a2713aSLionel Sambuc   }
541f4a2713aSLionel Sambuc }
542f4a2713aSLionel Sambuc 
543f4a2713aSLionel Sambuc namespace PR8623 {
544f4a2713aSLionel Sambuc   struct A { A(int); ~A(); };
545f4a2713aSLionel Sambuc 
546f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN6PR86233fooEb(
foo(bool b)547f4a2713aSLionel Sambuc   void foo(bool b) {
548f4a2713aSLionel Sambuc     // CHECK:      [[TMP:%.*]] = alloca [[A:%.*]], align 1
549f4a2713aSLionel Sambuc     // CHECK-NEXT: [[LCONS:%.*]] = alloca i1
550f4a2713aSLionel Sambuc     // CHECK-NEXT: [[RCONS:%.*]] = alloca i1
551f4a2713aSLionel Sambuc     // CHECK:      store i1 false, i1* [[LCONS]]
552f4a2713aSLionel Sambuc     // CHECK-NEXT: store i1 false, i1* [[RCONS]]
553f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1
554f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN6PR86231AC1Ei([[A]]* [[TMP]], i32 2)
555f4a2713aSLionel Sambuc     // CHECK-NEXT: store i1 true, i1* [[LCONS]]
556f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
557f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN6PR86231AC1Ei([[A]]* [[TMP]], i32 3)
558f4a2713aSLionel Sambuc     // CHECK-NEXT: store i1 true, i1* [[RCONS]]
559f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
560f4a2713aSLionel Sambuc     // CHECK:      load i1* [[RCONS]]
561f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1
562f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN6PR86231AD1Ev([[A]]* [[TMP]])
563f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
564f4a2713aSLionel Sambuc     // CHECK:      load i1* [[LCONS]]
565f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1
566f4a2713aSLionel Sambuc     // CHECK:      call void @_ZN6PR86231AD1Ev([[A]]* [[TMP]])
567f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
568f4a2713aSLionel Sambuc     // CHECK:      ret void
569f4a2713aSLionel Sambuc     b ? A(2) : A(3);
570f4a2713aSLionel Sambuc   }
571f4a2713aSLionel Sambuc }
572f4a2713aSLionel Sambuc 
573f4a2713aSLionel Sambuc namespace PR11365 {
574f4a2713aSLionel Sambuc   struct A { A(); ~A(); };
575f4a2713aSLionel Sambuc 
576f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN7PR113653fooEv(
foo()577f4a2713aSLionel Sambuc   void foo() {
578f4a2713aSLionel Sambuc     // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [3 x [[A:%.*]]]* {{.*}}, i32 0, i32 0
579f4a2713aSLionel Sambuc     // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]]* [[BEGIN]], i64 3
580f4a2713aSLionel Sambuc     // CHECK-NEXT: br label
581f4a2713aSLionel Sambuc 
582f4a2713aSLionel Sambuc     // CHECK: [[PHI:%.*]] = phi
583f4a2713aSLionel Sambuc     // CHECK-NEXT: [[ELEM:%.*]] = getelementptr inbounds [[A]]* [[PHI]], i64 -1
584f4a2713aSLionel Sambuc     // CHECK-NEXT: call void @_ZN7PR113651AD1Ev([[A]]* [[ELEM]])
585f4a2713aSLionel Sambuc     // CHECK-NEXT: icmp eq [[A]]* [[ELEM]], [[BEGIN]]
586f4a2713aSLionel Sambuc     // CHECK-NEXT: br i1
587f4a2713aSLionel Sambuc     (void) (A [3]) {};
588f4a2713aSLionel Sambuc   }
589f4a2713aSLionel Sambuc }
590f4a2713aSLionel Sambuc 
591f4a2713aSLionel Sambuc namespace AssignmentOp {
592f4a2713aSLionel Sambuc   struct A { ~A(); };
593f4a2713aSLionel Sambuc   struct B { A operator=(const B&); };
594f4a2713aSLionel Sambuc   struct C : B { B b1, b2; };
595f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN12AssignmentOp1fE
f(C & c1,const C & c2)596f4a2713aSLionel Sambuc   void f(C &c1, const C &c2) {
597f4a2713aSLionel Sambuc     // CHECK: call {{.*}} @_ZN12AssignmentOp1CaSERKS0_(
598f4a2713aSLionel Sambuc     c1 = c2;
599f4a2713aSLionel Sambuc   }
600f4a2713aSLionel Sambuc 
601f4a2713aSLionel Sambuc   // Ensure that each 'A' temporary is destroyed before the next subobject is
602f4a2713aSLionel Sambuc   // copied.
603f4a2713aSLionel Sambuc   // CHECK: define {{.*}} @_ZN12AssignmentOp1CaSERKS0_(
604f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
605f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
606f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
607f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
608f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1BaSERKS
609f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN12AssignmentOp1AD1Ev(
610f4a2713aSLionel Sambuc }
611f4a2713aSLionel Sambuc 
612f4a2713aSLionel Sambuc namespace BindToSubobject {
613f4a2713aSLionel Sambuc   struct A {
614f4a2713aSLionel Sambuc     A();
615f4a2713aSLionel Sambuc     ~A();
616f4a2713aSLionel Sambuc     int a;
617f4a2713aSLionel Sambuc   };
618f4a2713aSLionel Sambuc 
619f4a2713aSLionel Sambuc   void f(), g();
620f4a2713aSLionel Sambuc 
621*0a6a1f1dSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1aE_)
622*0a6a1f1dSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} bitcast ({{.*}} @_ZN15BindToSubobject1AD1Ev to void (i8*)*), i8* bitcast ({{.*}} @_ZGRN15BindToSubobject1aE_ to i8*), i8* @__dso_handle)
623*0a6a1f1dSLionel Sambuc   // CHECK: store i32* getelementptr inbounds ({{.*}} @_ZGRN15BindToSubobject1aE_, i32 0, i32 0), i32** @_ZN15BindToSubobject1aE, align 8
624f4a2713aSLionel Sambuc   int &&a = A().a;
625f4a2713aSLionel Sambuc 
626f4a2713aSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1fEv()
627*0a6a1f1dSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1bE_)
628*0a6a1f1dSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} bitcast ({{.*}} @_ZN15BindToSubobject1AD1Ev to void (i8*)*), i8* bitcast ({{.*}} @_ZGRN15BindToSubobject1bE_ to i8*), i8* @__dso_handle)
629*0a6a1f1dSLionel Sambuc   // CHECK: store i32* getelementptr inbounds ({{.*}} @_ZGRN15BindToSubobject1bE_, i32 0, i32 0), i32** @_ZN15BindToSubobject1bE, align 8
630f4a2713aSLionel Sambuc   int &&b = (f(), A().a);
631f4a2713aSLionel Sambuc 
632f4a2713aSLionel Sambuc   int A::*h();
633f4a2713aSLionel Sambuc 
634f4a2713aSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1fEv()
635f4a2713aSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1gEv()
636*0a6a1f1dSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1AC1Ev({{.*}} @_ZGRN15BindToSubobject1cE_)
637*0a6a1f1dSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} bitcast ({{.*}} @_ZN15BindToSubobject1AD1Ev to void (i8*)*), i8* bitcast ({{.*}} @_ZGRN15BindToSubobject1cE_ to i8*), i8* @__dso_handle)
638f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN15BindToSubobject1hE
639f4a2713aSLionel Sambuc   // CHECK: getelementptr
640f4a2713aSLionel Sambuc   // CHECK: store i32* {{.*}}, i32** @_ZN15BindToSubobject1cE, align 8
641f4a2713aSLionel Sambuc   int &&c = (f(), (g(), A().*h()));
642f4a2713aSLionel Sambuc 
643f4a2713aSLionel Sambuc   struct B {
644f4a2713aSLionel Sambuc     int padding;
645f4a2713aSLionel Sambuc     A a;
646f4a2713aSLionel Sambuc   };
647f4a2713aSLionel Sambuc 
648*0a6a1f1dSLionel Sambuc   // CHECK: call void @_ZN15BindToSubobject1BC1Ev({{.*}} @_ZGRN15BindToSubobject1dE_)
649*0a6a1f1dSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} bitcast ({{.*}} @_ZN15BindToSubobject1BD1Ev to void (i8*)*), i8* bitcast ({{.*}} @_ZGRN15BindToSubobject1dE_ to i8*), i8* @__dso_handle)
650f4a2713aSLionel Sambuc   // CHECK: call {{.*}} @_ZN15BindToSubobject1hE
651f4a2713aSLionel Sambuc   // CHECK: getelementptr {{.*}} getelementptr
652f4a2713aSLionel Sambuc   // CHECK: store i32* {{.*}}, i32** @_ZN15BindToSubobject1dE, align 8
653f4a2713aSLionel Sambuc   int &&d = (B().a).*h();
654f4a2713aSLionel Sambuc }
655f4a2713aSLionel Sambuc 
656f4a2713aSLionel Sambuc namespace Bitfield {
657f4a2713aSLionel Sambuc   struct S { int a : 5; ~S(); };
658f4a2713aSLionel Sambuc 
659f4a2713aSLionel Sambuc   // Do not lifetime extend the S() temporary here.
660f4a2713aSLionel Sambuc   // CHECK: alloca
661f4a2713aSLionel Sambuc   // CHECK: call {{.*}}memset
662*0a6a1f1dSLionel Sambuc   // CHECK: store i32 {{.*}}, i32* @_ZGRN8Bitfield1rE_
663f4a2713aSLionel Sambuc   // CHECK: call void @_ZN8Bitfield1SD1
664*0a6a1f1dSLionel Sambuc   // CHECK: store i32* @_ZGRN8Bitfield1rE_, i32** @_ZN8Bitfield1rE, align 8
665f4a2713aSLionel Sambuc   int &&r = S().a;
666f4a2713aSLionel Sambuc }
667f4a2713aSLionel Sambuc 
668f4a2713aSLionel Sambuc namespace Vector {
669f4a2713aSLionel Sambuc   typedef __attribute__((vector_size(16))) int vi4a;
670f4a2713aSLionel Sambuc   typedef __attribute__((ext_vector_type(4))) int vi4b;
671f4a2713aSLionel Sambuc   struct S {
672f4a2713aSLionel Sambuc     vi4a v;
673f4a2713aSLionel Sambuc     vi4b w;
674f4a2713aSLionel Sambuc   };
675f4a2713aSLionel Sambuc   // CHECK: alloca
676f4a2713aSLionel Sambuc   // CHECK: extractelement
677*0a6a1f1dSLionel Sambuc   // CHECK: store i32 {{.*}}, i32* @_ZGRN6Vector1rE_
678*0a6a1f1dSLionel Sambuc   // CHECK: store i32* @_ZGRN6Vector1rE_, i32** @_ZN6Vector1rE,
679f4a2713aSLionel Sambuc   int &&r = S().v[1];
680f4a2713aSLionel Sambuc 
681f4a2713aSLionel Sambuc   // CHECK: alloca
682f4a2713aSLionel Sambuc   // CHECK: extractelement
683*0a6a1f1dSLionel Sambuc   // CHECK: store i32 {{.*}}, i32* @_ZGRN6Vector1sE_
684*0a6a1f1dSLionel Sambuc   // CHECK: store i32* @_ZGRN6Vector1sE_, i32** @_ZN6Vector1sE,
685f4a2713aSLionel Sambuc   int &&s = S().w[1];
686f4a2713aSLionel Sambuc   // FIXME PR16204: The following code leads to an assertion in Sema.
687f4a2713aSLionel Sambuc   //int &&s = S().w.y;
688f4a2713aSLionel Sambuc }
689f4a2713aSLionel Sambuc 
690f4a2713aSLionel Sambuc namespace ImplicitTemporaryCleanup {
691f4a2713aSLionel Sambuc   struct A { A(int); ~A(); };
692f4a2713aSLionel Sambuc   void g();
693f4a2713aSLionel Sambuc 
694f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_ZN24ImplicitTemporaryCleanup1fEv(
f()695f4a2713aSLionel Sambuc   void f() {
696f4a2713aSLionel Sambuc     // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1AC1Ei(
697f4a2713aSLionel Sambuc     A &&a = 0;
698f4a2713aSLionel Sambuc 
699f4a2713aSLionel Sambuc     // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1gEv(
700f4a2713aSLionel Sambuc     g();
701f4a2713aSLionel Sambuc 
702f4a2713aSLionel Sambuc     // CHECK: call {{.*}} @_ZN24ImplicitTemporaryCleanup1AD1Ev(
703f4a2713aSLionel Sambuc   }
704f4a2713aSLionel Sambuc }
705f4a2713aSLionel Sambuc 
706f4a2713aSLionel Sambuc namespace MultipleExtension {
707f4a2713aSLionel Sambuc   struct A { A(); ~A(); };
708f4a2713aSLionel Sambuc   struct B { B(); ~B(); };
709f4a2713aSLionel Sambuc   struct C { C(); ~C(); };
710f4a2713aSLionel Sambuc   struct D { D(); ~D(); int n; C c; };
711f4a2713aSLionel Sambuc   struct E { const A &a; B b; const C &c; ~E(); };
712f4a2713aSLionel Sambuc 
713f4a2713aSLionel Sambuc   E &&e1 = { A(), B(), D().c };
714f4a2713aSLionel Sambuc 
715f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1AC1Ev({{.*}} @[[TEMPA:_ZGRN17MultipleExtension2e1E.*]])
716f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1AD1Ev {{.*}} @[[TEMPA]]
717f4a2713aSLionel Sambuc   // CHECK: store {{.*}} @[[TEMPA]], {{.*}} getelementptr inbounds ({{.*}} @[[TEMPE:_ZGRN17MultipleExtension2e1E.*]], i32 0, i32 0)
718f4a2713aSLionel Sambuc 
719f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1BC1Ev({{.*}} getelementptr inbounds ({{.*}} @[[TEMPE]], i32 0, i32 1))
720f4a2713aSLionel Sambuc 
721f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1DC1Ev({{.*}} @[[TEMPD:_ZGRN17MultipleExtension2e1E.*]])
722f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1DD1Ev {{.*}} @[[TEMPD]]
723f4a2713aSLionel Sambuc   // CHECK: store {{.*}} @[[TEMPD]], {{.*}} getelementptr inbounds ({{.*}} @[[TEMPE]], i32 0, i32 2)
724f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1ED1Ev {{.*}} @[[TEMPE]]
725f4a2713aSLionel Sambuc   // CHECK: store {{.*}} @[[TEMPE]], %"struct.MultipleExtension::E"** @_ZN17MultipleExtension2e1E, align 8
726f4a2713aSLionel Sambuc 
727f4a2713aSLionel Sambuc   E e2 = { A(), B(), D().c };
728f4a2713aSLionel Sambuc 
729f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1AC1Ev({{.*}} @[[TEMPA:_ZGRN17MultipleExtension2e2E.*]])
730f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1AD1Ev {{.*}} @[[TEMPA]]
731f4a2713aSLionel Sambuc   // CHECK: store {{.*}} @[[TEMPA]], {{.*}} getelementptr inbounds ({{.*}} @[[E:_ZN17MultipleExtension2e2E]], i32 0, i32 0)
732f4a2713aSLionel Sambuc 
733f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1BC1Ev({{.*}} getelementptr inbounds ({{.*}} @[[E]], i32 0, i32 1))
734f4a2713aSLionel Sambuc 
735f4a2713aSLionel Sambuc   // CHECK: call void @_ZN17MultipleExtension1DC1Ev({{.*}} @[[TEMPD:_ZGRN17MultipleExtension2e2E.*]])
736f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1DD1Ev {{.*}} @[[TEMPD]]
737f4a2713aSLionel Sambuc   // CHECK: store {{.*}} @[[TEMPD]], {{.*}} getelementptr inbounds ({{.*}} @[[E]], i32 0, i32 2)
738f4a2713aSLionel Sambuc   // CHECK: call i32 @__cxa_atexit({{.*}} @_ZN17MultipleExtension1ED1Ev {{.*}} @[[E]]
739f4a2713aSLionel Sambuc 
740f4a2713aSLionel Sambuc 
741f4a2713aSLionel Sambuc   void g();
742f4a2713aSLionel Sambuc   // CHECK: define void @[[NS:_ZN17MultipleExtension]]1fEv(
f()743f4a2713aSLionel Sambuc   void f() {
744f4a2713aSLionel Sambuc     E &&e1 = { A(), B(), D().c };
745f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE1_A:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1:.*]], i32 0, i32 0
746f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1AC1Ev({{.*}} %[[TEMPA1:.*]])
747f4a2713aSLionel Sambuc     // CHECK: store {{.*}} %[[TEMPA1]], {{.*}} %[[TEMPE1_A]]
748f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE1_B:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1]], i32 0, i32 1
749f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1BC1Ev({{.*}} %[[TEMPE1_B]])
750f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE1_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPE1]], i32 0, i32 2
751f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1DC1Ev({{.*}} %[[TEMPD1:.*]])
752f4a2713aSLionel Sambuc     // CHECK: %[[TEMPD1_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPD1]], i32 0, i32 1
753f4a2713aSLionel Sambuc     // CHECK: store {{.*}} %[[TEMPD1_C]], {{.*}} %[[TEMPE1_C]]
754f4a2713aSLionel Sambuc     // CHECK: store {{.*}} %[[TEMPE1]], {{.*}} %[[E1:.*]]
755f4a2713aSLionel Sambuc 
756f4a2713aSLionel Sambuc     g();
757f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1gEv()
758f4a2713aSLionel Sambuc 
759f4a2713aSLionel Sambuc     E e2 = { A(), B(), D().c };
760f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE2_A:.*]] = getelementptr inbounds {{.*}} %[[E2:.*]], i32 0, i32 0
761f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1AC1Ev({{.*}} %[[TEMPA2:.*]])
762f4a2713aSLionel Sambuc     // CHECK: store {{.*}} %[[TEMPA2]], {{.*}} %[[TEMPE2_A]]
763f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE2_B:.*]] = getelementptr inbounds {{.*}} %[[E2]], i32 0, i32 1
764f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1BC1Ev({{.*}} %[[TEMPE2_B]])
765f4a2713aSLionel Sambuc     // CHECK: %[[TEMPE2_C:.*]] = getelementptr inbounds {{.*}} %[[E2]], i32 0, i32 2
766f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1DC1Ev({{.*}} %[[TEMPD2:.*]])
767f4a2713aSLionel Sambuc     // CHECK: %[[TEMPD2_C:.*]] = getelementptr inbounds {{.*}} %[[TEMPD2]], i32 0, i32 1
768f4a2713aSLionel Sambuc     // CHECK: store {{.*}} %[[TEMPD2_C]], {{.*}}* %[[TEMPE2_C]]
769f4a2713aSLionel Sambuc 
770f4a2713aSLionel Sambuc     g();
771f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1gEv()
772f4a2713aSLionel Sambuc 
773f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1ED1Ev({{.*}} %[[E2]])
774f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1DD1Ev({{.*}} %[[TEMPD2]])
775f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1AD1Ev({{.*}} %[[TEMPA2]])
776f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1ED1Ev({{.*}} %[[TEMPE1]])
777f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1DD1Ev({{.*}} %[[TEMPD1]])
778f4a2713aSLionel Sambuc     // CHECK: call void @[[NS]]1AD1Ev({{.*}} %[[TEMPA1]])
779f4a2713aSLionel Sambuc   }
780f4a2713aSLionel Sambuc }
781f4a2713aSLionel Sambuc 
782f4a2713aSLionel Sambuc namespace PR14130 {
783f4a2713aSLionel Sambuc   struct S { S(int); };
784f4a2713aSLionel Sambuc   struct U { S &&s; };
785f4a2713aSLionel Sambuc   U v { { 0 } };
786*0a6a1f1dSLionel Sambuc   // CHECK: call void @_ZN7PR141301SC1Ei({{.*}} @_ZGRN7PR141301vE_, i32 0)
787*0a6a1f1dSLionel Sambuc   // CHECK: store {{.*}} @_ZGRN7PR141301vE_, {{.*}} @_ZN7PR141301vE
788f4a2713aSLionel Sambuc }
789f4a2713aSLionel Sambuc 
790f4a2713aSLionel Sambuc namespace Ctor {
791f4a2713aSLionel Sambuc   struct A { A(); ~A(); };
792f4a2713aSLionel Sambuc   void f();
793f4a2713aSLionel Sambuc   struct B {
794f4a2713aSLionel Sambuc     A &&a;
BCtor::B795f4a2713aSLionel Sambuc     B() : a{} { f(); }
796f4a2713aSLionel Sambuc   } b;
797f4a2713aSLionel Sambuc   // CHECK: define {{.*}}void @_ZN4Ctor1BC1Ev(
798f4a2713aSLionel Sambuc   // CHECK: call void @_ZN4Ctor1AC1Ev(
799f4a2713aSLionel Sambuc   // CHECK: call void @_ZN4Ctor1fEv(
800f4a2713aSLionel Sambuc   // CHECK: call void @_ZN4Ctor1AD1Ev(
801f4a2713aSLionel Sambuc }
802