2017-07-08 21:24:52 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefixes=X86,CHECK %s
|
2018-02-16 03:12:41 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple amdgcn-amd-amdhsa -DNO_TLS -emit-llvm -o - %s | FileCheck -check-prefixes=AMDGCN,CHECK %s
|
2012-02-17 16:42:25 +08:00
|
|
|
|
|
|
|
namespace std {
|
|
|
|
typedef decltype(sizeof(int)) size_t;
|
|
|
|
|
|
|
|
// libc++'s implementation
|
|
|
|
template <class _E>
|
|
|
|
class initializer_list
|
|
|
|
{
|
|
|
|
const _E* __begin_;
|
|
|
|
size_t __size_;
|
|
|
|
|
|
|
|
initializer_list(const _E* __b, size_t __s)
|
|
|
|
: __begin_(__b),
|
|
|
|
__size_(__s)
|
|
|
|
{}
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef _E value_type;
|
|
|
|
typedef const _E& reference;
|
|
|
|
typedef const _E& const_reference;
|
|
|
|
typedef size_t size_type;
|
|
|
|
|
|
|
|
typedef const _E* iterator;
|
|
|
|
typedef const _E* const_iterator;
|
|
|
|
|
|
|
|
initializer_list() : __begin_(nullptr), __size_(0) {}
|
|
|
|
|
|
|
|
size_t size() const {return __size_;}
|
|
|
|
const _E* begin() const {return __begin_;}
|
|
|
|
const _E* end() const {return __begin_ + __size_;}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-02-26 04:51:20 +08:00
|
|
|
struct destroyme1 {
|
|
|
|
~destroyme1();
|
|
|
|
};
|
|
|
|
struct destroyme2 {
|
|
|
|
~destroyme2();
|
|
|
|
};
|
|
|
|
struct witharg1 {
|
|
|
|
witharg1(const destroyme1&);
|
|
|
|
~witharg1();
|
|
|
|
};
|
|
|
|
struct wantslist1 {
|
|
|
|
wantslist1(std::initializer_list<destroyme1>);
|
|
|
|
~wantslist1();
|
|
|
|
};
|
2017-07-08 21:24:52 +08:00
|
|
|
// X86: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
|
|
|
|
// X86: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: @_ZGR15globalInitList1_ = internal addrspace(1) constant [3 x i32] [i32 1, i32 2, i32 3]
|
|
|
|
// 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 }
|
2012-02-26 04:51:20 +08:00
|
|
|
std::initializer_list<int> globalInitList1 = {1, 2, 3};
|
|
|
|
|
2017-07-08 21:24:52 +08:00
|
|
|
#ifndef NO_TLS
|
2013-04-15 07:01:42 +08:00
|
|
|
namespace thread_local_global_array {
|
2017-07-08 21:24:52 +08:00
|
|
|
// FIXME: We should be able to constant-evaluate this even though the
|
|
|
|
// initializer is not a constant expression (pointers to thread_local
|
|
|
|
// objects aren't really a problem).
|
|
|
|
//
|
|
|
|
// X86: @_ZN25thread_local_global_array1xE = thread_local global
|
|
|
|
// X86: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
|
|
|
|
std::initializer_list<int> thread_local x = {1, 2, 3, 4};
|
2013-04-15 07:01:42 +08:00
|
|
|
}
|
2017-07-08 21:24:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// X86: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
|
|
|
|
// X86: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: @globalInitList2 = addrspace(1) global %{{[^ ]+}} zeroinitializer
|
|
|
|
// AMDGCN: @_ZGR15globalInitList2_ = internal addrspace(1) global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
|
2017-07-08 21:24:52 +08:00
|
|
|
|
|
|
|
// X86: @_ZN15partly_constant1kE = global i32 0, align 4
|
|
|
|
// X86: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
|
|
|
|
// X86: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
|
|
|
|
// X86: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
|
|
|
|
// X86: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
|
|
|
|
// X86: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
|
|
|
|
// X86: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: @_ZN15partly_constant1kE = addrspace(1) global i32 0, align 4
|
2018-03-06 01:50:10 +08:00
|
|
|
// AMDGCN: @_ZN15partly_constant2ilE = addrspace(4) global {{.*}} null, align 8
|
|
|
|
// AMDGCN: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal addrspace(4) global {{.*}} zeroinitializer, align 8
|
|
|
|
// AMDGCN: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal addrspace(4) global [3 x {{.*}}] zeroinitializer, align 8
|
|
|
|
// AMDGCN: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal addrspace(4) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
|
|
|
|
// AMDGCN: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal addrspace(4) global [2 x i32] zeroinitializer, align 4
|
|
|
|
// AMDGCN: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal addrspace(4) constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
|
2017-07-08 21:24:52 +08:00
|
|
|
|
|
|
|
// X86: @[[REFTMP1:.*]] = private constant [2 x i32] [i32 42, i32 43], align 4
|
|
|
|
// X86: @[[REFTMP2:.*]] = private constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
|
2018-03-06 01:50:10 +08:00
|
|
|
// AMDGCN: @[[REFTMP1:.*]] = private addrspace(4) constant [2 x i32] [i32 42, i32 43], align 4
|
|
|
|
// AMDGCN: @[[REFTMP2:.*]] = private addrspace(4) constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
|
2015-03-07 21:37:13 +08:00
|
|
|
|
2012-02-26 04:51:20 +08:00
|
|
|
// CHECK: appending global
|
2013-06-13 06:31:48 +08:00
|
|
|
|
|
|
|
// thread_local initializer:
|
2017-07-08 21:24:52 +08:00
|
|
|
// X86-LABEL: define internal void @__cxx_global_var_init
|
|
|
|
// X86: store i32* getelementptr inbounds ([4 x i32], [4 x i32]* @_ZGRN25thread_local_global_array1xE_, i64 0, i64 0),
|
|
|
|
// X86: i32** getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 0), align 8
|
|
|
|
// X86: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 1), align 8
|
|
|
|
|
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
|
|
|
// X86: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 0
|
|
|
|
// X86: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 1
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i{{32|64}} 0, i{{32|64}} 0
|
|
|
|
// AMDGCN: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i{{32|64}} 0, i{{32|64}} 1
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: call i32 @__cxa_atexit
|
|
|
|
// X86: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i64 0, i64 0),
|
|
|
|
// X86: %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 0), align 8
|
|
|
|
// X86: store i64 2, i64* getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 1), align 8
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* addrspacecast ({{[^@]+}} @_ZGR15globalInitList2_ {{[^)]+}}), i64 0, i64 0),
|
|
|
|
// AMDGCN: %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* addrspacecast ({{[^@]+}} @globalInitList2 {{[^)]+}}), i32 0, i32 0), align 8
|
|
|
|
// AMDGCN: store i64 2, i64* getelementptr inbounds (%{{.*}}, %{{.*}}* addrspacecast ({{[^@]+}} @globalInitList2 {{[^)]+}}), i32 0, i32 1), align 8
|
2012-02-26 04:51:20 +08:00
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN10destroyme1D1Ev
|
|
|
|
// CHECK-NEXT: ret void
|
2012-02-26 04:51:20 +08:00
|
|
|
std::initializer_list<witharg1> globalInitList2 = {
|
|
|
|
witharg1(destroyme1()), witharg1(destroyme1())
|
|
|
|
};
|
|
|
|
|
2012-02-17 16:42:25 +08:00
|
|
|
void fn1(int i) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn1i
|
2012-02-17 16:42:25 +08:00
|
|
|
// temporary array
|
2017-07-08 21:24:52 +08:00
|
|
|
// X86: [[array:%[^ ]+]] = alloca [3 x i32]
|
2018-02-16 03:12:41 +08:00
|
|
|
// AMDGCN: [[alloca:%[^ ]+]] = alloca [3 x i32], align 4, addrspace(5)
|
|
|
|
// AMDGCN: [[array:%[^ ]+]] = addrspacecast [3 x i32] addrspace(5)* [[alloca]] to [3 x i32]*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: getelementptr inbounds [3 x i32], [3 x i32]* [[array]], i{{32|64}} 0
|
2012-02-17 16:42:25 +08:00
|
|
|
// CHECK-NEXT: store i32 1, i32*
|
|
|
|
// CHECK-NEXT: getelementptr
|
|
|
|
// CHECK-NEXT: store
|
|
|
|
// CHECK-NEXT: getelementptr
|
|
|
|
// CHECK-NEXT: load
|
|
|
|
// CHECK-NEXT: store
|
|
|
|
// init the list
|
|
|
|
// CHECK-NEXT: getelementptr
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]*
|
2012-02-17 16:42:25 +08:00
|
|
|
// CHECK-NEXT: store i32*
|
|
|
|
// CHECK-NEXT: getelementptr
|
|
|
|
// CHECK-NEXT: store i{{32|64}} 3
|
|
|
|
std::initializer_list<int> intlist{1, 2, i};
|
|
|
|
}
|
|
|
|
|
|
|
|
void fn2() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn2v
|
2012-02-17 16:42:25 +08:00
|
|
|
void target(std::initializer_list<destroyme1>);
|
|
|
|
// objects should be destroyed before dm2, after call returns
|
2012-02-19 20:27:51 +08:00
|
|
|
// CHECK: call void @_Z6targetSt16initializer_listI10destroyme1E
|
2012-02-17 16:42:25 +08:00
|
|
|
target({ destroyme1(), destroyme1() });
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
}
|
|
|
|
|
|
|
|
void fn3() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn3v
|
2012-02-17 16:42:25 +08:00
|
|
|
// objects should be destroyed after dm2
|
|
|
|
auto list = { destroyme1(), destroyme1() };
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
}
|
2012-02-19 20:27:51 +08:00
|
|
|
|
|
|
|
void fn4() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn4v
|
2012-02-19 20:27:51 +08:00
|
|
|
void target(std::initializer_list<witharg1>);
|
|
|
|
// objects should be destroyed before dm2, after call returns
|
|
|
|
// CHECK: call void @_ZN8witharg1C1ERK10destroyme1
|
|
|
|
// CHECK: call void @_Z6targetSt16initializer_listI8witharg1E
|
|
|
|
target({ witharg1(destroyme1()), witharg1(destroyme1()) });
|
|
|
|
// CHECK: call void @_ZN8witharg1D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
}
|
|
|
|
|
|
|
|
void fn5() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn5v
|
2012-02-19 20:27:51 +08:00
|
|
|
// temps should be destroyed before dm2
|
|
|
|
// objects should be destroyed after dm2
|
|
|
|
// CHECK: call void @_ZN8witharg1C1ERK10destroyme1
|
|
|
|
auto list = { witharg1(destroyme1()), witharg1(destroyme1()) };
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
// CHECK: call void @_ZN8witharg1D1Ev
|
|
|
|
}
|
2012-02-19 20:27:56 +08:00
|
|
|
|
|
|
|
void fn6() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn6v
|
2012-02-19 20:27:56 +08:00
|
|
|
void target(const wantslist1&);
|
|
|
|
// objects should be destroyed before dm2, after call returns
|
|
|
|
// CHECK: call void @_ZN10wantslist1C1ESt16initializer_listI10destroyme1E
|
|
|
|
// CHECK: call void @_Z6targetRK10wantslist1
|
|
|
|
target({ destroyme1(), destroyme1() });
|
|
|
|
// CHECK: call void @_ZN10wantslist1D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
}
|
|
|
|
void fn7() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn7v
|
2012-02-19 20:27:56 +08:00
|
|
|
// temps should be destroyed before dm2
|
|
|
|
// object should be destroyed after dm2
|
|
|
|
// CHECK: call void @_ZN10wantslist1C1ESt16initializer_listI10destroyme1E
|
|
|
|
wantslist1 wl = { destroyme1(), destroyme1() };
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
// CHECK: call void @_ZN10wantslist1D1Ev
|
|
|
|
}
|
2012-02-19 20:28:02 +08:00
|
|
|
|
|
|
|
void fn8() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn8v
|
2012-02-19 20:28:02 +08:00
|
|
|
void target(std::initializer_list<std::initializer_list<destroyme1>>);
|
|
|
|
// objects should be destroyed before dm2, after call returns
|
|
|
|
// CHECK: call void @_Z6targetSt16initializer_listIS_I10destroyme1EE
|
|
|
|
std::initializer_list<destroyme1> inner;
|
|
|
|
target({ inner, { destroyme1() } });
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
// Only one destroy loop, since only one inner init list is directly inited.
|
|
|
|
// CHECK-NOT: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
}
|
|
|
|
|
|
|
|
void fn9() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z3fn9v
|
2012-02-19 20:28:02 +08:00
|
|
|
// objects should be destroyed after dm2
|
|
|
|
std::initializer_list<destroyme1> inner;
|
|
|
|
std::initializer_list<std::initializer_list<destroyme1>> list =
|
|
|
|
{ inner, { destroyme1() } };
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
// Only one destroy loop, since only one inner init list is directly inited.
|
|
|
|
// CHECK-NOT: call void @_ZN10destroyme1D1Ev
|
|
|
|
// CHECK: ret void
|
|
|
|
}
|
2012-02-19 23:41:54 +08:00
|
|
|
|
|
|
|
struct haslist1 {
|
|
|
|
std::initializer_list<int> il;
|
2015-03-07 21:37:13 +08:00
|
|
|
haslist1(int i);
|
2012-02-19 23:41:54 +08:00
|
|
|
};
|
|
|
|
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN8haslist1C2Ei
|
|
|
|
haslist1::haslist1(int i)
|
2012-02-19 23:41:54 +08:00
|
|
|
// CHECK: alloca [3 x i32]
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK: store i32 %
|
2012-02-19 23:41:54 +08:00
|
|
|
// CHECK: store i32 2
|
|
|
|
// CHECK: store i32 3
|
2015-03-07 21:37:13 +08:00
|
|
|
: il{i, 2, 3}
|
2012-02-19 23:41:54 +08:00
|
|
|
{
|
|
|
|
destroyme2 dm2;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct haslist2 {
|
|
|
|
std::initializer_list<destroyme1> il;
|
|
|
|
haslist2();
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN8haslist2C2Ev
|
2012-02-19 23:41:54 +08:00
|
|
|
haslist2::haslist2()
|
|
|
|
: il{destroyme1(), destroyme1()}
|
|
|
|
{
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
}
|
2012-02-20 00:03:09 +08:00
|
|
|
|
2015-03-07 21:37:13 +08:00
|
|
|
void fn10(int i) {
|
|
|
|
// CHECK-LABEL: define void @_Z4fn10i
|
2012-02-20 00:03:09 +08:00
|
|
|
// CHECK: alloca [3 x i32]
|
2016-04-08 05:46:12 +08:00
|
|
|
// CHECK: call i8* @_Znw{{[jm]}}
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK: store i32 %
|
2012-02-20 00:03:09 +08:00
|
|
|
// CHECK: store i32 2
|
|
|
|
// CHECK: store i32 3
|
|
|
|
// CHECK: store i32*
|
2015-03-07 21:37:13 +08:00
|
|
|
(void) new std::initializer_list<int> {i, 2, 3};
|
2012-02-20 00:03:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void fn11() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z4fn11v
|
2012-02-20 00:03:09 +08:00
|
|
|
(void) new std::initializer_list<destroyme1> {destroyme1(), destroyme1()};
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
destroyme2 dm2;
|
|
|
|
// CHECK: call void @_ZN10destroyme2D1Ev
|
|
|
|
}
|
2012-03-06 03:35:43 +08:00
|
|
|
|
|
|
|
namespace PR12178 {
|
|
|
|
struct string {
|
|
|
|
string(int);
|
|
|
|
~string();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pair {
|
|
|
|
string a;
|
|
|
|
int b;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct map {
|
|
|
|
map(std::initializer_list<pair>);
|
|
|
|
};
|
|
|
|
|
|
|
|
map m{ {1, 2}, {3, 4} };
|
|
|
|
}
|
2013-04-06 08:46:20 +08:00
|
|
|
|
|
|
|
namespace rdar13325066 {
|
|
|
|
struct X { ~X(); };
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN12rdar133250664loopERNS_1XES1_
|
2013-04-06 08:46:20 +08:00
|
|
|
void loop(X &x1, X &x2) {
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: br i1
|
|
|
|
// CHECK: br label
|
2015-03-14 09:10:19 +08:00
|
|
|
// CHECK: call void @_ZN12rdar133250661XD1Ev
|
2013-04-06 08:46:20 +08:00
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: call void @_ZN12rdar133250661XD1Ev
|
|
|
|
// CHECK: br i1
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: ret void
|
|
|
|
for (X x : { x1, x2 }) { }
|
|
|
|
}
|
|
|
|
}
|
2013-05-24 05:54:14 +08:00
|
|
|
|
|
|
|
namespace dtors {
|
|
|
|
struct S {
|
|
|
|
S();
|
|
|
|
~S();
|
|
|
|
};
|
2013-06-13 06:31:48 +08:00
|
|
|
void z();
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5dtors1fEv(
|
2013-05-24 05:54:14 +08:00
|
|
|
void f() {
|
2013-06-14 02:07:12 +08:00
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
2013-05-24 05:54:14 +08:00
|
|
|
std::initializer_list<S>{ S(), S() };
|
2013-06-13 06:31:48 +08:00
|
|
|
|
|
|
|
// Destruction loop for underlying array.
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: call void @_ZN5dtors1SD1Ev(
|
|
|
|
// CHECK: br i1
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN5dtors1zEv(
|
|
|
|
z();
|
|
|
|
|
|
|
|
// CHECK-NOT: call void @_ZN5dtors1SD1Ev(
|
2013-05-24 05:54:14 +08:00
|
|
|
}
|
2013-06-13 06:31:48 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5dtors1gEv(
|
2013-06-05 08:46:14 +08:00
|
|
|
void g() {
|
2013-06-14 02:07:12 +08:00
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
2013-06-05 08:46:14 +08:00
|
|
|
auto x = std::initializer_list<S>{ S(), S() };
|
2013-06-13 06:31:48 +08:00
|
|
|
|
|
|
|
// Destruction loop for underlying array.
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: call void @_ZN5dtors1SD1Ev(
|
|
|
|
// CHECK: br i1
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN5dtors1zEv(
|
|
|
|
z();
|
|
|
|
|
|
|
|
// CHECK-NOT: call void @_ZN5dtors1SD1Ev(
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5dtors1hEv(
|
2013-06-13 06:31:48 +08:00
|
|
|
void h() {
|
2013-06-14 02:07:12 +08:00
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
|
|
|
// CHECK: call void @_ZN5dtors1SC1Ev(
|
2013-06-13 06:31:48 +08:00
|
|
|
std::initializer_list<S> x = { S(), S() };
|
|
|
|
|
|
|
|
// CHECK-NOT: call void @_ZN5dtors1SD1Ev(
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN5dtors1zEv(
|
|
|
|
z();
|
|
|
|
|
|
|
|
// Destruction loop for underlying array.
|
|
|
|
// CHECK: br label
|
|
|
|
// CHECK: call void @_ZN5dtors1SD1Ev(
|
|
|
|
// CHECK: br i1
|
2013-06-05 08:46:14 +08:00
|
|
|
}
|
2013-05-24 05:54:14 +08:00
|
|
|
}
|
2013-06-14 11:07:01 +08:00
|
|
|
|
|
|
|
namespace partly_constant {
|
|
|
|
int k;
|
|
|
|
std::initializer_list<std::initializer_list<int>> &&il = { { 1, 2, 3 }, { 4, k }, { 5, 6, 7, 8 } };
|
|
|
|
// First init list.
|
|
|
|
// CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]],
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_FIRST]]{{.*}}, i64 0, i64 0),
|
|
|
|
// CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 0)
|
|
|
|
// CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0, i32 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
// CHECK-NOT: @[[PARTLY_CONSTANT_FIRST]],
|
|
|
|
//
|
|
|
|
// Second init list array (non-constant).
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store i32 4, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0)
|
|
|
|
// CHECK: load i32, i32* {{.*}}@_ZN15partly_constant1kE
|
|
|
|
// CHECK: store i32 {{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
//
|
|
|
|
// Second init list.
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_SECOND]]{{.*}}, i64 0, i64 0),
|
|
|
|
// CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 0)
|
|
|
|
// CHECK: store i64 2, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 1, i32 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
//
|
|
|
|
// Third init list.
|
|
|
|
// CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]],
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store i32* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_THIRD]]{{.*}}, i64 0, i64 0),
|
|
|
|
// CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 2, i32 0)
|
|
|
|
// CHECK: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@_ZGRN15partly_constant2ilE4_{{.*}}, i64 0, i64 2, i32 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
// CHECK-NOT: @[[PARTLY_CONSTANT_THIRD]],
|
|
|
|
//
|
|
|
|
// Outer init list.
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store {{.*}}* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_INNER]]{{.*}}, i64 0, i64 0),
|
|
|
|
// CHECK: {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 0)
|
|
|
|
// CHECK: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, i32 0, i32 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
//
|
|
|
|
// 'il' reference.
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store {{.*}}* {{.*}}@[[PARTLY_CONSTANT_OUTER]]{{.*}}, {{.*}}** {{.*}}@_ZN15partly_constant2ilE{{.*}}, align 8
|
2013-06-14 11:07:01 +08:00
|
|
|
}
|
2013-06-28 06:54:33 +08:00
|
|
|
namespace nested {
|
|
|
|
struct A { A(); ~A(); };
|
|
|
|
struct B { const A &a; ~B(); };
|
|
|
|
struct C { std::initializer_list<B> b; ~C(); };
|
|
|
|
void f();
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN6nested1gEv(
|
2013-06-28 06:54:33 +08:00
|
|
|
void g() {
|
|
|
|
// CHECK: call void @_ZN6nested1AC1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: call void @_ZN6nested1AC1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
const C &c { { { A() }, { A() } } };
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN6nested1fEv(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
f();
|
|
|
|
|
|
|
|
// CHECK: call void @_ZN6nested1CD1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
|
|
|
|
// Destroy B[2] array.
|
|
|
|
// FIXME: This isn't technically correct: reverse construction order would
|
|
|
|
// destroy the second B then the second A then the first B then the first A.
|
|
|
|
// CHECK: call void @_ZN6nested1BD1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: br
|
|
|
|
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: call void @_ZN6nested1AD1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: call void @_ZN6nested1AD1Ev(
|
|
|
|
// CHECK-NOT: call
|
|
|
|
// CHECK: }
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 16:26:00 +08:00
|
|
|
|
|
|
|
namespace DR1070 {
|
|
|
|
struct A {
|
|
|
|
A(std::initializer_list<int>);
|
|
|
|
};
|
|
|
|
struct B {
|
|
|
|
int i;
|
|
|
|
A a;
|
|
|
|
};
|
|
|
|
B b = {1};
|
|
|
|
struct C {
|
|
|
|
std::initializer_list<int> a;
|
|
|
|
B b;
|
|
|
|
std::initializer_list<double> c;
|
|
|
|
};
|
|
|
|
C c = {};
|
|
|
|
}
|
2014-06-03 16:40:27 +08:00
|
|
|
|
|
|
|
namespace ArrayOfInitList {
|
|
|
|
struct S {
|
|
|
|
S(std::initializer_list<int>);
|
|
|
|
};
|
|
|
|
S x[1] = {};
|
|
|
|
}
|
2014-07-25 09:12:44 +08:00
|
|
|
|
|
|
|
namespace PR20445 {
|
|
|
|
struct vector { vector(std::initializer_list<int>); };
|
|
|
|
struct MyClass { explicit MyClass(const vector &v); };
|
|
|
|
template<int x> void f() { new MyClass({42, 43}); }
|
|
|
|
template void f<0>();
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR204451fILi0EEEvv(
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* {{.*}}@[[REFTMP1]]{{.*}}, i64 0, i64 0)
|
2014-07-25 09:12:44 +08:00
|
|
|
// CHECK: call void @_ZN7PR204456vectorC1ESt16initializer_listIiE(
|
|
|
|
// CHECK: call void @_ZN7PR204457MyClassC1ERKNS_6vectorE(
|
|
|
|
}
|
2015-03-07 21:37:13 +08:00
|
|
|
|
|
|
|
namespace ConstExpr {
|
|
|
|
class C {
|
|
|
|
int x;
|
|
|
|
public:
|
|
|
|
constexpr C(int x) : x(x) {}
|
|
|
|
};
|
|
|
|
void f(std::initializer_list<C>);
|
|
|
|
void g() {
|
2017-07-08 21:24:52 +08:00
|
|
|
// CHECK-LABEL: _ZN9ConstExpr1gEv
|
|
|
|
// CHECK: store %"class.ConstExpr::C"* getelementptr inbounds ([3 x %"class.ConstExpr::C"], [3 x %"class.ConstExpr::C"]* {{.*}}@[[REFTMP2]]{{.*}}, i64 0, i64 0)
|
|
|
|
// CHECK: call void @_ZN9ConstExpr1fESt16initializer_listINS_1CEE
|
2015-03-07 21:37:13 +08:00
|
|
|
f({C(1), C(2), C(3)});
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 09:06:24 +08:00
|
|
|
|
|
|
|
namespace B19773010 {
|
|
|
|
template <class T1, class T2> struct pair {
|
|
|
|
T1 first;
|
|
|
|
T2 second;
|
|
|
|
constexpr pair() : first(), second() {}
|
|
|
|
constexpr pair(T1 a, T2 b) : first(a), second(b) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum E { ENUM_CONSTANT };
|
|
|
|
struct testcase {
|
|
|
|
testcase(std::initializer_list<pair<const char *, E>>);
|
|
|
|
};
|
|
|
|
void f1() {
|
|
|
|
// CHECK-LABEL: @_ZN9B197730102f1Ev
|
|
|
|
testcase a{{"", ENUM_CONSTANT}};
|
2017-07-08 21:24:52 +08:00
|
|
|
// 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
|
2018-03-06 01:50:10 +08:00
|
|
|
// 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
|
2015-03-18 09:06:24 +08:00
|
|
|
}
|
|
|
|
void f2() {
|
|
|
|
// CHECK-LABEL: @_ZN9B197730102f2Ev
|
2017-07-08 21:24:52 +08:00
|
|
|
// 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
|
2018-02-16 03:12:41 +08:00
|
|
|
// 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
|
2015-03-18 09:06:24 +08:00
|
|
|
static std::initializer_list<pair<const char *, E>> a, p[2] =
|
|
|
|
{a, {{"", ENUM_CONSTANT}}};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PR22940_helper(const pair<void*, int>&) { }
|
|
|
|
void PR22940() {
|
|
|
|
// CHECK-LABEL: @_ZN9B197730107PR22940Ev
|
2015-04-10 06:50:07 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN9B197730104pairIPviEC{{.}}Ev(
|
2015-03-18 09:06:24 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN9B1977301014PR22940_helperERKNS_4pairIPviEE(
|
|
|
|
PR22940_helper(pair<void*, int>());
|
|
|
|
}
|
|
|
|
}
|