1 // RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
2 // RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa-amdgiz -DNO_TLS -emit-llvm -o - %s | FileCheck -check-prefixes=AMD,CHECK %s
3 
4 namespace std {
5   typedef decltype(sizeof(int)) size_t;
6 
7   // libc++'s implementation
8   template <class _E>
9   class initializer_list
10   {
11     const _E* __begin_;
12     size_t    __size_;
13 
14     initializer_list(const _E* __b, size_t __s)
15       : __begin_(__b),
16         __size_(__s)
17     {}
18 
19   public:
20     typedef _E        value_type;
21     typedef const _E& reference;
22     typedef const _E& const_reference;
23     typedef size_t    size_type;
24 
25     typedef const _E* iterator;
26     typedef const _E* const_iterator;
27 
28     initializer_list() : __begin_(nullptr), __size_(0) {}
29 
30     size_t    size()  const {return __size_;}
31     const _E* begin() const {return __begin_;}
32     const _E* end()   const {return __begin_ + __size_;}
33   };
34 }
35 
36 struct destroyme1 {
37   ~destroyme1();
38 };
39 struct destroyme2 {
40   ~destroyme2();
41 };
42 struct witharg1 {
43   witharg1(const destroyme1&);
44   ~witharg1();
45 };
46 struct wantslist1 {
47   wantslist1(std::initializer_list<destroyme1>);
48   ~wantslist1();
49 };
50 // X86: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
51 // X86: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
52 // AMD: @_ZGR15globalInitList1_ = internal addrspace(1) constant [3 x i32] [i32 1, i32 2, i32 3]
53 // AMD: @globalInitList1 = addrspace(1) global %{{[^ ]+}} { i32* addrspacecast (i32 addrspace(1)* getelementptr inbounds ([3 x i32], [3 x i32] addrspace(1)* @_ZGR15globalInitList1_, i32 0, i32 0) to i32*), i{{32|64}} 3 }
54 std::initializer_list<int> globalInitList1 = {1, 2, 3};
55 
56 #ifndef NO_TLS
57 namespace thread_local_global_array {
58 // FIXME: We should be able to constant-evaluate this even though the
59 // initializer is not a constant expression (pointers to thread_local
60 // objects aren't really a problem).
61 //
62 // X86: @_ZN25thread_local_global_array1xE = thread_local global
63 // X86: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
64 std::initializer_list<int> thread_local x = {1, 2, 3, 4};
65 }
66 #endif
67 
68 // X86: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
69 // X86: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
70 // AMD: @globalInitList2 = addrspace(1) global %{{[^ ]+}} zeroinitializer
71 // AMD: @_ZGR15globalInitList2_ = internal addrspace(1) global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
72 
73 // X86: @_ZN15partly_constant1kE = global i32 0, align 4
74 // X86: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
75 // X86: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
76 // X86: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
77 // X86: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
78 // X86: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
79 // X86: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
80 // AMD: @_ZN15partly_constant1kE = addrspace(1) global i32 0, align 4
81 // AMD: @_ZN15partly_constant2ilE = addrspace(2) global {{.*}} null, align 8
82 // AMD: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal addrspace(2) global {{.*}} zeroinitializer, align 8
83 // AMD: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal addrspace(2) global [3 x {{.*}}] zeroinitializer, align 8
84 // AMD: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal addrspace(2) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
85 // AMD: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal addrspace(2) global [2 x i32] zeroinitializer, align 4
86 // AMD: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal addrspace(2) constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
87 
88 // X86: @[[REFTMP1:.*]] = private constant [2 x i32] [i32 42, i32 43], align 4
89 // X86: @[[REFTMP2:.*]] = private constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
90 // AMD: @[[REFTMP1:.*]] = private addrspace(2) constant [2 x i32] [i32 42, i32 43], align 4
91 // AMD: @[[REFTMP2:.*]] = private addrspace(2) constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
92 
93 // CHECK: appending global
94 
95 // thread_local initializer:
96 // X86-LABEL: define internal void @__cxx_global_var_init
97 // X86: store i32* getelementptr inbounds ([4 x i32], [4 x i32]* @_ZGRN25thread_local_global_array1xE_, i64 0, i64 0),
98 // X86:       i32** getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 0), align 8
99 // X86: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 1), align 8
100 
101 // CHECK-LABEL: define internal void @__cxx_global_var_init
102 // X86: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 0
103 // X86: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 1
104 // AMD: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i{{32|64}} 0, i{{32|64}} 0
105 // AMD: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i{{32|64}} 0, i{{32|64}} 1
106 // CHECK: call i32 @__cxa_atexit
107 // X86: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i64 0, i64 0),
108 // X86:       %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 0), align 8
109 // X86: store i64 2, i64* getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 1), align 8
110 // AMD: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i64 0, i64 0),
111 // AMD:       %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* addrspacecast ({{[^@]+}} @globalInitList2 {{[^)]+}}), i32 0, i32 0), align 8
112 // AMD: store i64 2, i64* getelementptr inbounds (%{{.*}}, %{{.*}}* addrspacecast ({{[^@]+}} @globalInitList2 {{[^)]+}}), i32 0, i32 1), align 8
113 // CHECK: call void @_ZN10destroyme1D1Ev
114 // CHECK-NEXT: call void @_ZN10destroyme1D1Ev
115 // CHECK-NEXT: ret void
116 std::initializer_list<witharg1> globalInitList2 = {
117   witharg1(destroyme1()), witharg1(destroyme1())
118 };
119 
120 void fn1(int i) {
121   // CHECK-LABEL: define void @_Z3fn1i
122   // temporary array
123   // X86: [[array:%[^ ]+]] = alloca [3 x i32]
124   // AMD: [[alloca:%[^ ]+]] = alloca [3 x i32], align 4, addrspace(5)
125   // AMD: [[array:%[^ ]+]] = addrspacecast [3 x i32] addrspace(5)* [[alloca]] to [3 x i32]*
126   // CHECK: getelementptr inbounds [3 x i32], [3 x i32]* [[array]], i{{32|64}} 0
127   // CHECK-NEXT: store i32 1, i32*
128   // CHECK-NEXT: getelementptr
129   // CHECK-NEXT: store
130   // CHECK-NEXT: getelementptr
131   // CHECK-NEXT: load
132   // CHECK-NEXT: store
133   // init the list
134   // CHECK-NEXT: getelementptr
135   // CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]*
136   // CHECK-NEXT: store i32*
137   // CHECK-NEXT: getelementptr
138   // CHECK-NEXT: store i{{32|64}} 3
139   std::initializer_list<int> intlist{1, 2, i};
140 }
141 
142 void fn2() {
143   // CHECK-LABEL: define void @_Z3fn2v
144   void target(std::initializer_list<destroyme1>);
145   // objects should be destroyed before dm2, after call returns
146   // CHECK: call void @_Z6targetSt16initializer_listI10destroyme1E
147   target({ destroyme1(), destroyme1() });
148   // CHECK: call void @_ZN10destroyme1D1Ev
149   destroyme2 dm2;
150   // CHECK: call void @_ZN10destroyme2D1Ev
151 }
152 
153 void fn3() {
154   // CHECK-LABEL: define void @_Z3fn3v
155   // objects should be destroyed after dm2
156   auto list = { destroyme1(), destroyme1() };
157   destroyme2 dm2;
158   // CHECK: call void @_ZN10destroyme2D1Ev
159   // CHECK: call void @_ZN10destroyme1D1Ev
160 }
161 
162 void fn4() {
163   // CHECK-LABEL: define void @_Z3fn4v
164   void target(std::initializer_list<witharg1>);
165   // objects should be destroyed before dm2, after call returns
166   // CHECK: call void @_ZN8witharg1C1ERK10destroyme1
167   // CHECK: call void @_Z6targetSt16initializer_listI8witharg1E
168   target({ witharg1(destroyme1()), witharg1(destroyme1()) });
169   // CHECK: call void @_ZN8witharg1D1Ev
170   // CHECK: call void @_ZN10destroyme1D1Ev
171   destroyme2 dm2;
172   // CHECK: call void @_ZN10destroyme2D1Ev
173 }
174 
175 void fn5() {
176   // CHECK-LABEL: define void @_Z3fn5v
177   // temps should be destroyed before dm2
178   // objects should be destroyed after dm2
179   // CHECK: call void @_ZN8witharg1C1ERK10destroyme1
180   auto list = { witharg1(destroyme1()), witharg1(destroyme1()) };
181   // CHECK: call void @_ZN10destroyme1D1Ev
182   destroyme2 dm2;
183   // CHECK: call void @_ZN10destroyme2D1Ev
184   // CHECK: call void @_ZN8witharg1D1Ev
185 }
186 
187 void fn6() {
188   // CHECK-LABEL: define void @_Z3fn6v
189   void target(const wantslist1&);
190   // objects should be destroyed before dm2, after call returns
191   // CHECK: call void @_ZN10wantslist1C1ESt16initializer_listI10destroyme1E
192   // CHECK: call void @_Z6targetRK10wantslist1
193   target({ destroyme1(), destroyme1() });
194   // CHECK: call void @_ZN10wantslist1D1Ev
195   // CHECK: call void @_ZN10destroyme1D1Ev
196   destroyme2 dm2;
197   // CHECK: call void @_ZN10destroyme2D1Ev
198 }
199 void fn7() {
200   // CHECK-LABEL: define void @_Z3fn7v
201   // temps should be destroyed before dm2
202   // object should be destroyed after dm2
203   // CHECK: call void @_ZN10wantslist1C1ESt16initializer_listI10destroyme1E
204   wantslist1 wl = { destroyme1(), destroyme1() };
205   // CHECK: call void @_ZN10destroyme1D1Ev
206   destroyme2 dm2;
207   // CHECK: call void @_ZN10destroyme2D1Ev
208   // CHECK: call void @_ZN10wantslist1D1Ev
209 }
210 
211 void fn8() {
212   // CHECK-LABEL: define void @_Z3fn8v
213   void target(std::initializer_list<std::initializer_list<destroyme1>>);
214   // objects should be destroyed before dm2, after call returns
215   // CHECK: call void @_Z6targetSt16initializer_listIS_I10destroyme1EE
216   std::initializer_list<destroyme1> inner;
217   target({ inner, { destroyme1() } });
218   // CHECK: call void @_ZN10destroyme1D1Ev
219   // Only one destroy loop, since only one inner init list is directly inited.
220   // CHECK-NOT: call void @_ZN10destroyme1D1Ev
221   destroyme2 dm2;
222   // CHECK: call void @_ZN10destroyme2D1Ev
223 }
224 
225 void fn9() {
226   // CHECK-LABEL: define void @_Z3fn9v
227   // objects should be destroyed after dm2
228   std::initializer_list<destroyme1> inner;
229   std::initializer_list<std::initializer_list<destroyme1>> list =
230       { inner, { destroyme1() } };
231   destroyme2 dm2;
232   // CHECK: call void @_ZN10destroyme2D1Ev
233   // CHECK: call void @_ZN10destroyme1D1Ev
234   // Only one destroy loop, since only one inner init list is directly inited.
235   // CHECK-NOT: call void @_ZN10destroyme1D1Ev
236   // CHECK: ret void
237 }
238 
239 struct haslist1 {
240   std::initializer_list<int> il;
241   haslist1(int i);
242 };
243 
244 // CHECK-LABEL: define void @_ZN8haslist1C2Ei
245 haslist1::haslist1(int i)
246 // CHECK: alloca [3 x i32]
247 // CHECK: store i32 %
248 // CHECK: store i32 2
249 // CHECK: store i32 3
250   : il{i, 2, 3}
251 {
252   destroyme2 dm2;
253 }
254 
255 struct haslist2 {
256   std::initializer_list<destroyme1> il;
257   haslist2();
258 };
259 
260 // CHECK-LABEL: define void @_ZN8haslist2C2Ev
261 haslist2::haslist2()
262   : il{destroyme1(), destroyme1()}
263 {
264   destroyme2 dm2;
265   // CHECK: call void @_ZN10destroyme2D1Ev
266   // CHECK: call void @_ZN10destroyme1D1Ev
267 }
268 
269 void fn10(int i) {
270   // CHECK-LABEL: define void @_Z4fn10i
271   // CHECK: alloca [3 x i32]
272   // CHECK: call i8* @_Znw{{[jm]}}
273   // CHECK: store i32 %
274   // CHECK: store i32 2
275   // CHECK: store i32 3
276   // CHECK: store i32*
277   (void) new std::initializer_list<int> {i, 2, 3};
278 }
279 
280 void fn11() {
281   // CHECK-LABEL: define void @_Z4fn11v
282   (void) new std::initializer_list<destroyme1> {destroyme1(), destroyme1()};
283   // CHECK: call void @_ZN10destroyme1D1Ev
284   destroyme2 dm2;
285   // CHECK: call void @_ZN10destroyme2D1Ev
286 }
287 
288 namespace PR12178 {
289   struct string {
290     string(int);
291     ~string();
292   };
293 
294   struct pair {
295     string a;
296     int b;
297   };
298 
299   struct map {
300     map(std::initializer_list<pair>);
301   };
302 
303   map m{ {1, 2}, {3, 4} };
304 }
305 
306 namespace rdar13325066 {
307   struct X { ~X(); };
308 
309   // CHECK-LABEL: define void @_ZN12rdar133250664loopERNS_1XES1_
310   void loop(X &x1, X &x2) {
311     // CHECK: br label
312     // CHECK: br i1
313     // CHECK: br label
314     // CHECK: call void @_ZN12rdar133250661XD1Ev
315     // CHECK: br label
316     // CHECK: br label
317     // CHECK: call void @_ZN12rdar133250661XD1Ev
318     // CHECK: br i1
319     // CHECK: br label
320     // CHECK: ret void
321     for (X x : { x1, x2 }) { }
322   }
323 }
324 
325 namespace dtors {
326   struct S {
327     S();
328     ~S();
329   };
330   void z();
331 
332   // CHECK-LABEL: define void @_ZN5dtors1fEv(
333   void f() {
334     // CHECK: call void @_ZN5dtors1SC1Ev(
335     // CHECK: call void @_ZN5dtors1SC1Ev(
336     std::initializer_list<S>{ S(), S() };
337 
338     // Destruction loop for underlying array.
339     // CHECK: br label
340     // CHECK: call void @_ZN5dtors1SD1Ev(
341     // CHECK: br i1
342 
343     // CHECK: call void @_ZN5dtors1zEv(
344     z();
345 
346     // CHECK-NOT: call void @_ZN5dtors1SD1Ev(
347   }
348 
349   // CHECK-LABEL: define void @_ZN5dtors1gEv(
350   void g() {
351     // CHECK: call void @_ZN5dtors1SC1Ev(
352     // CHECK: call void @_ZN5dtors1SC1Ev(
353     auto x = std::initializer_list<S>{ S(), S() };
354 
355     // Destruction loop for underlying array.
356     // CHECK: br label
357     // CHECK: call void @_ZN5dtors1SD1Ev(
358     // CHECK: br i1
359 
360     // CHECK: call void @_ZN5dtors1zEv(
361     z();
362 
363     // CHECK-NOT: call void @_ZN5dtors1SD1Ev(
364   }
365 
366   // CHECK-LABEL: define void @_ZN5dtors1hEv(
367   void h() {
368     // CHECK: call void @_ZN5dtors1SC1Ev(
369     // CHECK: call void @_ZN5dtors1SC1Ev(
370     std::initializer_list<S> x = { S(), S() };
371 
372     // CHECK-NOT: call void @_ZN5dtors1SD1Ev(
373 
374     // CHECK: call void @_ZN5dtors1zEv(
375     z();
376 
377     // Destruction loop for underlying array.
378     // CHECK: br label
379     // CHECK: call void @_ZN5dtors1SD1Ev(
380     // CHECK: br i1
381   }
382 }
383 
384 namespace partly_constant {
385   int k;
386   std::initializer_list<std::initializer_list<int>> &&il = { { 1, 2, 3 }, { 4, k }, { 5, 6, 7, 8 } };
387   // First init list.
388   // CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]],
389   // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_FIRST]]{{.*}}, i64 0, i64 0),
390   // CHECK:       i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 0)
391   // CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 1)
392   // CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]],
393   //
394   // Second init list array (non-constant).
395   // CHECK: store i32 4, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0)
396   // CHECK: load i32, i32* {{.*}}@_ZN15partly_constant1kE
397   // CHECK: store i32 {{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 1)
398   //
399   // Second init list.
400   // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0),
401   // CHECK:       i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 0)
402   // CHECK: store i64 2, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 1)
403   //
404   // Third init list.
405   // CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]],
406   // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_THIRD]]{{.*}}, i64 0, i64 0),
407   // CHECK:       i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 2, i32 0)
408   // CHECK: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@_ZGRN15partly_constant2ilE4_{{.*}}, i64 0, i64 2, i32 1)
409   // CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]],
410   //
411   // Outer init list.
412   // CHECK: store {{.*}}* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0),
413   // CHECK:       {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 0)
414   // CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 1)
415   //
416   // 'il' reference.
417   // CHECK: store {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, {{.*}}** {{.*}}@_ZN15partly_constant2ilE{{.*}}, align 8
418 }
419 namespace nested {
420   struct A { A(); ~A(); };
421   struct B { const A &a; ~B(); };
422   struct C { std::initializer_list<B> b; ~C(); };
423   void f();
424   // CHECK-LABEL: define void @_ZN6nested1gEv(
425   void g() {
426     // CHECK: call void @_ZN6nested1AC1Ev(
427     // CHECK-NOT: call
428     // CHECK: call void @_ZN6nested1AC1Ev(
429     // CHECK-NOT: call
430     const C &c { { { A() }, { A() } } };
431 
432     // CHECK: call void @_ZN6nested1fEv(
433     // CHECK-NOT: call
434     f();
435 
436     // CHECK: call void @_ZN6nested1CD1Ev(
437     // CHECK-NOT: call
438 
439     // Destroy B[2] array.
440     // FIXME: This isn't technically correct: reverse construction order would
441     // destroy the second B then the second A then the first B then the first A.
442     // CHECK: call void @_ZN6nested1BD1Ev(
443     // CHECK-NOT: call
444     // CHECK: br
445 
446     // CHECK-NOT: call
447     // CHECK: call void @_ZN6nested1AD1Ev(
448     // CHECK-NOT: call
449     // CHECK: call void @_ZN6nested1AD1Ev(
450     // CHECK-NOT: call
451     // CHECK: }
452   }
453 }
454 
455 namespace DR1070 {
456   struct A {
457     A(std::initializer_list<int>);
458   };
459   struct B {
460     int i;
461     A a;
462   };
463   B b = {1};
464   struct C {
465     std::initializer_list<int> a;
466     B b;
467     std::initializer_list<double> c;
468   };
469   C c = {};
470 }
471 
472 namespace ArrayOfInitList {
473   struct S {
474     S(std::initializer_list<int>);
475   };
476   S x[1] = {};
477 }
478 
479 namespace PR20445 {
480   struct vector { vector(std::initializer_list<int>); };
481   struct MyClass { explicit MyClass(const vector &v); };
482   template<int x> void f() { new MyClass({42, 43}); }
483   template void f<0>();
484   // CHECK-LABEL: define {{.*}} @_ZN7PR204451fILi0EEEvv(
485   // CHECK: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* {{.*}}@[[REFTMP1]]{{.*}}, i64 0, i64 0)
486   // CHECK: call void @_ZN7PR204456vectorC1ESt16initializer_listIiE(
487   // CHECK: call void @_ZN7PR204457MyClassC1ERKNS_6vectorE(
488 }
489 
490 namespace ConstExpr {
491   class C {
492     int x;
493   public:
494     constexpr C(int x) : x(x) {}
495   };
496   void f(std::initializer_list<C>);
497   void g() {
498     // CHECK-LABEL: _ZN9ConstExpr1gEv
499     // CHECK: store %"class.ConstExpr::C"* getelementptr inbounds ([3 x %"class.ConstExpr::C"], [3 x %"class.ConstExpr::C"]* {{.*}}@[[REFTMP2]]{{.*}}, i64 0, i64 0)
500     // CHECK: call void @_ZN9ConstExpr1fESt16initializer_listINS_1CEE
501     f({C(1), C(2), C(3)});
502   }
503 }
504 
505 namespace B19773010 {
506   template <class T1, class T2> struct pair {
507     T1 first;
508     T2 second;
509     constexpr pair() : first(), second() {}
510     constexpr pair(T1 a, T2 b) : first(a), second(b) {}
511   };
512 
513   enum E { ENUM_CONSTANT };
514   struct testcase {
515     testcase(std::initializer_list<pair<const char *, E>>);
516   };
517   void f1() {
518     // CHECK-LABEL: @_ZN9B197730102f1Ev
519     testcase a{{"", ENUM_CONSTANT}};
520     // X86: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* bitcast ([1 x { i8*, i32 }]* @.ref.tmp{{.*}} to [1 x %"struct.B19773010::pair"]*), i64 0, i64 0), %"struct.B19773010::pair"** %{{.*}}, align 8
521     // AMD: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* addrspacecast{{.*}} bitcast ([1 x { i8*, i32 }] addrspace(2)* @.ref.tmp{{.*}} to [1 x %"struct.B19773010::pair"] addrspace(2)*){{.*}}, i64 0, i64 0), %"struct.B19773010::pair"** %{{.*}}, align 8
522   }
523   void f2() {
524     // CHECK-LABEL: @_ZN9B197730102f2Ev
525     // X86: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* bitcast ([1 x { i8*, i32 }]* @_ZGRZN9B197730102f2EvE1p_ to [1 x %"struct.B19773010::pair"]*), i64 0, i64 0), %"struct.B19773010::pair"** getelementptr inbounds ([2 x %"class.std::initializer_list.10"], [2 x %"class.std::initializer_list.10"]* @_ZZN9B197730102f2EvE1p, i64 0, i64 1, i32 0), align 16
526     // AMD: store %"struct.B19773010::pair"* getelementptr inbounds ([1 x %"struct.B19773010::pair"], [1 x %"struct.B19773010::pair"]* addrspacecast{{.*}} bitcast ([1 x { i8*, i32 }] addrspace(1)* @_ZGRZN9B197730102f2EvE1p_ to [1 x %"struct.B19773010::pair"] addrspace(1)*){{.*}}, i64 0, i64 0), %"struct.B19773010::pair"** getelementptr inbounds ([2 x %"class.std::initializer_list.10"], [2 x %"class.std::initializer_list.10"]* addrspacecast{{.*}}@_ZZN9B197730102f2EvE1p{{.*}}, i64 0, i64 1, i32 0), align 8
527     static std::initializer_list<pair<const char *, E>> a, p[2] =
528         {a, {{"", ENUM_CONSTANT}}};
529   }
530 
531   void PR22940_helper(const pair<void*, int>&) { }
532   void PR22940() {
533     // CHECK-LABEL: @_ZN9B197730107PR22940Ev
534     // CHECK: call {{.*}} @_ZN9B197730104pairIPviEC{{.}}Ev(
535     // CHECK: call {{.*}} @_ZN9B1977301014PR22940_helperERKNS_4pairIPviEE(
536     PR22940_helper(pair<void*, int>());
537   }
538 }
539