cxx0x-initializer-stdinitializerlist.cpp 21 KB

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