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 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 // AMDGCN: @_ZGR15globalInitList1_ = internal addrspace(1) constant [3 x i32] [i32 1, i32 2, i32 3] 53 // 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 } 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 // AMDGCN: @globalInitList2 = addrspace(1) global %{{[^ ]+}} zeroinitializer 71 // AMDGCN: @_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_constant2ilE0_]] = internal global [3 x {{.*}}] zeroinitializer, align 8 77 // X86: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE1_]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4 78 // X86: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE2_]] = internal global [2 x i32] zeroinitializer, align 4 79 // X86: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE3_]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4 80 // AMDGCN: @_ZN15partly_constant1kE = addrspace(1) global i32 0, align 4 81 // AMDGCN: @_ZN15partly_constant2ilE = addrspace(4) global {{.*}} null, align 8 82 // AMDGCN: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE_]] = internal addrspace(4) global {{.*}} zeroinitializer, align 8 83 // AMDGCN: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE0_]] = internal addrspace(4) global [3 x {{.*}}] zeroinitializer, align 8 84 // AMDGCN: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE1_]] = internal addrspace(4) constant [3 x i32] [i32 1, i32 2, i32 3], align 4 85 // AMDGCN: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE2_]] = internal addrspace(4) global [2 x i32] zeroinitializer, align 4 86 // AMDGCN: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE3_]] = internal addrspace(4) 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 // AMDGCN: @[[REFTMP1:.*]] = private addrspace(4) constant [2 x i32] [i32 42, i32 43], align 4 91 // AMDGCN: @[[REFTMP2:.*]] = private addrspace(4) 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 // AMDGCN: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i{{32|64}} 0, i{{32|64}} 0 105 // AMDGCN: 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 // AMDGCN: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i64 0, i64 0), 111 // AMDGCN: %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* addrspacecast ({{[^@]+}} @globalInitList2 {{[^)]+}}), i32 0, i32 0), align 8 112 // AMDGCN: 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 // AMDGCN: [[alloca:%[^ ]+]] = alloca [3 x i32], align 4, addrspace(5) 125 // AMDGCN: [[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 void fn10(int i) { 240 // CHECK-LABEL: define void @_Z4fn10i 241 // CHECK: alloca [3 x i32] 242 // CHECK-X86: call noalias nonnull align 16 i8* @_Znw{{[jm]}} 243 // CHECK-AMDGPU: call noalias nonnull align 8 i8* @_Znw{{[jm]}} 244 // CHECK: store i32 % 245 // CHECK: store i32 2 246 // CHECK: store i32 3 247 // CHECK: store i32* 248 (void) new std::initializer_list<int> {i, 2, 3}; 249 } 250 251 void fn11() { 252 // CHECK-LABEL: define void @_Z4fn11v 253 (void) new std::initializer_list<destroyme1> {destroyme1(), destroyme1()}; 254 // CHECK: call void @_ZN10destroyme1D1Ev 255 destroyme2 dm2; 256 // CHECK: call void @_ZN10destroyme2D1Ev 257 } 258 259 namespace PR12178 { 260 struct string { 261 string(int); 262 ~string(); 263 }; 264 265 struct pair { 266 string a; 267 int b; 268 }; 269 270 struct map { 271 map(std::initializer_list<pair>); 272 }; 273 274 map m{ {1, 2}, {3, 4} }; 275 } 276 277 namespace rdar13325066 { 278 struct X { ~X(); }; 279 280 // CHECK-LABEL: define void @_ZN12rdar133250664loopERNS_1XES1_ 281 void loop(X &x1, X &x2) { 282 // CHECK: br label 283 // CHECK: br i1 284 // CHECK: br label 285 // CHECK: call void @_ZN12rdar133250661XD1Ev 286 // CHECK: br label 287 // CHECK: br label 288 // CHECK: call void @_ZN12rdar133250661XD1Ev 289 // CHECK: br i1 290 // CHECK: br label 291 // CHECK: ret void 292 for (X x : { x1, x2 }) { } 293 } 294 } 295 296 namespace dtors { 297 struct S { 298 S(); 299 ~S(); 300 }; 301 void z(); 302 303 // CHECK-LABEL: define void @_ZN5dtors1fEv( 304 void f() { 305 // CHECK: call void @_ZN5dtors1SC1Ev( 306 // CHECK: call void @_ZN5dtors1SC1Ev( 307 std::initializer_list<S>{ S(), S() }; 308 309 // Destruction loop for underlying array. 310 // CHECK: br label 311 // CHECK: call void @_ZN5dtors1SD1Ev( 312 // CHECK: br i1 313 314 // CHECK: call void @_ZN5dtors1zEv( 315 z(); 316 317 // CHECK-NOT: call void @_ZN5dtors1SD1Ev( 318 } 319 320 // CHECK-LABEL: define void @_ZN5dtors1gEv( 321 void g() { 322 // CHECK: call void @_ZN5dtors1SC1Ev( 323 // CHECK: call void @_ZN5dtors1SC1Ev( 324 auto x = std::initializer_list<S>{ S(), S() }; 325 326 // Destruction loop for underlying array. 327 // CHECK: br label 328 // CHECK: call void @_ZN5dtors1SD1Ev( 329 // CHECK: br i1 330 331 // CHECK: call void @_ZN5dtors1zEv( 332 z(); 333 334 // CHECK-NOT: call void @_ZN5dtors1SD1Ev( 335 } 336 337 // CHECK-LABEL: define void @_ZN5dtors1hEv( 338 void h() { 339 // CHECK: call void @_ZN5dtors1SC1Ev( 340 // CHECK: call void @_ZN5dtors1SC1Ev( 341 std::initializer_list<S> x = { S(), S() }; 342 343 // CHECK-NOT: call void @_ZN5dtors1SD1Ev( 344 345 // CHECK: call void @_ZN5dtors1zEv( 346 z(); 347 348 // Destruction loop for underlying array. 349 // CHECK: br label 350 // CHECK: call void @_ZN5dtors1SD1Ev( 351 // CHECK: br i1 352 } 353 } 354 355 namespace partly_constant { 356 int k; 357 std::initializer_list<std::initializer_list<int>> &&il = { { 1, 2, 3 }, { 4, k }, { 5, 6, 7, 8 } }; 358 // First init list. 359 // CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]], 360 // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_FIRST]]{{.*}}, i64 0, i64 0), 361 // CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 0) 362 // CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 1) 363 // CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]], 364 // 365 // Second init list array (non-constant). 366 // CHECK: store i32 4, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0) 367 // CHECK: load i32, i32* {{.*}}@_ZN15partly_constant1kE 368 // CHECK: store i32 {{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 1) 369 // 370 // Second init list. 371 // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0), 372 // CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 0) 373 // CHECK: store i64 2, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 1) 374 // 375 // Third init list. 376 // CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]], 377 // CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_THIRD]]{{.*}}, i64 0, i64 0), 378 // CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 2, i32 0) 379 // CHECK: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 2, i32 1) 380 // CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]], 381 // 382 // Outer init list. 383 // CHECK: store {{.*}}* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0), 384 // CHECK: {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 0) 385 // CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 1) 386 // 387 // 'il' reference. 388 // CHECK: store {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, {{.*}}** {{.*}}@_ZN15partly_constant2ilE{{.*}}, align 8 389 } 390 namespace nested { 391 struct A { A(); ~A(); }; 392 struct B { const A &a; ~B(); }; 393 struct C { std::initializer_list<B> b; ~C(); }; 394 void f(); 395 // CHECK-LABEL: define void @_ZN6nested1gEv( 396 void g() { 397 // CHECK: call void @_ZN6nested1AC1Ev( 398 // CHECK-NOT: call 399 // CHECK: call void @_ZN6nested1AC1Ev( 400 // CHECK-NOT: call 401 const C &c { { { A() }, { A() } } }; 402 403 // CHECK: call void @_ZN6nested1fEv( 404 // CHECK-NOT: call 405 f(); 406 407 // CHECK: call void @_ZN6nested1CD1Ev( 408 // CHECK-NOT: call 409 410 // Destroy B[2] array. 411 // FIXME: This isn't technically correct: reverse construction order would 412 // destroy the second B then the second A then the first B then the first A. 413 // CHECK: call void @_ZN6nested1BD1Ev( 414 // CHECK-NOT: call 415 // CHECK: br 416 417 // CHECK-NOT: call 418 // CHECK: call void @_ZN6nested1AD1Ev( 419 // CHECK-NOT: call 420 // CHECK: call void @_ZN6nested1AD1Ev( 421 // CHECK-NOT: call 422 // CHECK: } 423 } 424 } 425 426 namespace DR1070 { 427 struct A { 428 A(std::initializer_list<int>); 429 }; 430 struct B { 431 int i; 432 A a; 433 }; 434 B b = {1}; 435 struct C { 436 std::initializer_list<int> a; 437 B b; 438 std::initializer_list<double> c; 439 }; 440 C c = {}; 441 } 442 443 namespace ArrayOfInitList { 444 struct S { 445 S(std::initializer_list<int>); 446 }; 447 S x[1] = {}; 448 } 449 450 namespace PR20445 { 451 struct vector { vector(std::initializer_list<int>); }; 452 struct MyClass { explicit MyClass(const vector &v); }; 453 template<int x> void f() { new MyClass({42, 43}); } 454 template void f<0>(); 455 // CHECK-LABEL: define {{.*}} @_ZN7PR204451fILi0EEEvv( 456 // CHECK: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* {{.*}}@[[REFTMP1]]{{.*}}, i64 0, i64 0) 457 // CHECK: call void @_ZN7PR204456vectorC1ESt16initializer_listIiE( 458 // CHECK: call void @_ZN7PR204457MyClassC1ERKNS_6vectorE( 459 } 460 461 namespace ConstExpr { 462 class C { 463 int x; 464 public: 465 constexpr C(int x) : x(x) {} 466 }; 467 void f(std::initializer_list<C>); 468 void g() { 469 // CHECK-LABEL: _ZN9ConstExpr1gEv 470 // CHECK: store %"class.ConstExpr::C"* getelementptr inbounds ([3 x %"class.ConstExpr::C"], [3 x %"class.ConstExpr::C"]* {{.*}}@[[REFTMP2]]{{.*}}, i64 0, i64 0) 471 // CHECK: call void @_ZN9ConstExpr1fESt16initializer_listINS_1CEE 472 f({C(1), C(2), C(3)}); 473 } 474 } 475 476 namespace B19773010 { 477 template <class T1, class T2> struct pair { 478 T1 first; 479 T2 second; 480 constexpr pair() : first(), second() {} 481 constexpr pair(T1 a, T2 b) : first(a), second(b) {} 482 }; 483 484 enum E { ENUM_CONSTANT }; 485 struct testcase { 486 testcase(std::initializer_list<pair<const char *, E>>); 487 }; 488 void f1() { 489 // CHECK-LABEL: @_ZN9B197730102f1Ev 490 testcase a{{"", ENUM_CONSTANT}}; 491 // 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 492 // 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 493 } 494 void f2() { 495 // CHECK-LABEL: @_ZN9B197730102f2Ev 496 // 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 497 // 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 498 static std::initializer_list<pair<const char *, E>> a, p[2] = 499 {a, {{"", ENUM_CONSTANT}}}; 500 } 501 502 void PR22940_helper(const pair<void*, int>&) { } 503 void PR22940() { 504 // CHECK-LABEL: @_ZN9B197730107PR22940Ev 505 // CHECK: call {{.*}} @_ZN9B197730104pairIPviEC{{.}}Ev( 506 // CHECK: call {{.*}} @_ZN9B1977301014PR22940_helperERKNS_4pairIPviEE( 507 PR22940_helper(pair<void*, int>()); 508 } 509 } 510