2014-06-03 16:26:00 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck %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();
|
|
|
|
};
|
|
|
|
|
2015-02-20 03:25:17 +08:00
|
|
|
// CHECK: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: @globalInitList1 = global %{{[^ ]+}} { i32* getelementptr inbounds ([3 x i32], [3 x i32]* @_ZGR15globalInitList1_, i32 0, i32 0), i{{32|64}} 3 }
|
2012-02-26 04:51:20 +08:00
|
|
|
std::initializer_list<int> globalInitList1 = {1, 2, 3};
|
|
|
|
|
2013-04-15 07:01:42 +08:00
|
|
|
namespace thread_local_global_array {
|
2013-06-13 06:31:48 +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).
|
|
|
|
//
|
|
|
|
// CHECK: @_ZN25thread_local_global_array1xE = thread_local global
|
2015-02-20 03:25:17 +08:00
|
|
|
// CHECK: @_ZGRN25thread_local_global_array1xE_ = internal thread_local constant [4 x i32] [i32 1, i32 2, i32 3, i32 4]
|
2013-04-15 07:01:42 +08:00
|
|
|
std::initializer_list<int> thread_local x = { 1, 2, 3, 4 };
|
|
|
|
}
|
|
|
|
|
2013-06-13 06:31:48 +08:00
|
|
|
// CHECK: @globalInitList2 = global %{{[^ ]+}} zeroinitializer
|
2015-02-20 03:25:17 +08:00
|
|
|
// CHECK: @_ZGR15globalInitList2_ = internal global [2 x %[[WITHARG:[^ ]*]]] zeroinitializer
|
2013-06-14 11:07:01 +08:00
|
|
|
|
|
|
|
// CHECK: @_ZN15partly_constant1kE = global i32 0, align 4
|
|
|
|
// CHECK: @_ZN15partly_constant2ilE = global {{.*}} null, align 8
|
2015-02-20 03:25:17 +08:00
|
|
|
// CHECK: @[[PARTLY_CONSTANT_OUTER:_ZGRN15partly_constant2ilE.*]] = internal global {{.*}} zeroinitializer, align 8
|
|
|
|
// CHECK: @[[PARTLY_CONSTANT_INNER:_ZGRN15partly_constant2ilE.*]] = internal global [3 x {{.*}}] zeroinitializer, align 8
|
|
|
|
// CHECK: @[[PARTLY_CONSTANT_FIRST:_ZGRN15partly_constant2ilE.*]] = internal constant [3 x i32] [i32 1, i32 2, i32 3], align 4
|
|
|
|
// CHECK: @[[PARTLY_CONSTANT_SECOND:_ZGRN15partly_constant2ilE.*]] = internal global [2 x i32] zeroinitializer, align 4
|
|
|
|
// CHECK: @[[PARTLY_CONSTANT_THIRD:_ZGRN15partly_constant2ilE.*]] = internal constant [4 x i32] [i32 5, i32 6, i32 7, i32 8], align 4
|
2013-06-14 11:07:01 +08:00
|
|
|
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK: @[[REFTMP1:.*]] = private constant [2 x i32] [i32 42, i32 43], align 4
|
|
|
|
// CHECK: @[[REFTMP2:.*]] = private constant [3 x %{{.*}}] [%{{.*}} { i32 1 }, %{{.*}} { i32 2 }, %{{.*}} { i32 3 }], align 4
|
|
|
|
|
2012-02-26 04:51:20 +08:00
|
|
|
// CHECK: appending global
|
2013-06-13 06:31:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
// thread_local initializer:
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: store i32* getelementptr inbounds ([4 x i32], [4 x i32]* @_ZGRN25thread_local_global_array1xE_, i64 0, i64 0),
|
|
|
|
// CHECK: i32** getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 0), align 8
|
|
|
|
// CHECK: store i64 4, i64* getelementptr inbounds ({{.*}}, {{.*}}* @_ZN25thread_local_global_array1xE, i32 0, i32 1), align 8
|
2013-06-13 06:31:48 +08:00
|
|
|
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 0
|
|
|
|
// CHECK: call void @_ZN8witharg1C1ERK10destroyme1(%[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i{{32|64}} 0, i{{32|64}} 1
|
2012-02-26 04:51:20 +08:00
|
|
|
// CHECK: __cxa_atexit
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: store %[[WITHARG]]* getelementptr inbounds ([2 x %[[WITHARG]]], [2 x %[[WITHARG]]]* @_ZGR15globalInitList2_, i64 0, i64 0),
|
|
|
|
// CHECK: %[[WITHARG]]** getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 0), align 8
|
|
|
|
// CHECK: store i64 2, i64* getelementptr inbounds (%{{.*}}, %{{.*}}* @globalInitList2, i32 0, i32 1), align 8
|
2012-02-26 04:51:20 +08:00
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
// CHECK: call void @_ZN10destroyme1D1Ev
|
|
|
|
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
|
|
|
|
// CHECK: [[array:%[^ ]+]] = alloca [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]],
|
2015-03-14 02:21:46 +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).
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: store i32 4, i32* getelementptr inbounds ({{.*}}, {{.*}}* @[[PARTLY_CONSTANT_SECOND]], i64 0, i64 0)
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32* @_ZN15partly_constant1kE
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: store i32 {{.*}}, i32* getelementptr inbounds ({{.*}}, {{.*}}* @[[PARTLY_CONSTANT_SECOND]], i64 0, i64 1)
|
2013-06-14 11:07:01 +08:00
|
|
|
//
|
|
|
|
// Second init list.
|
2015-03-14 02:21:46 +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]],
|
2015-03-14 02:21:46 +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.
|
2015-03-14 02:21:46 +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.
|
|
|
|
// CHECK: store {{.*}}* @[[PARTLY_CONSTANT_OUTER]], {{.*}}** @_ZN15partly_constant2ilE, align 8
|
|
|
|
}
|
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(
|
2015-03-14 02:21:46 +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() {
|
|
|
|
// CHECK-LABEL: _ZN9ConstExpr1gEv
|
2015-03-14 02:21:46 +08:00
|
|
|
// CHECK: store %"class.ConstExpr::C"* getelementptr inbounds ([3 x %"class.ConstExpr::C"], [3 x %"class.ConstExpr::C"]* @[[REFTMP2]], i64 0, i64 0)
|
2015-03-07 21:37:13 +08:00
|
|
|
// CHECK: call void @_ZN9ConstExpr1fESt16initializer_listINS_1CEE
|
|
|
|
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}};
|
2015-03-18 09:41:58 +08:00
|
|
|
// CHECK: 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
|
2015-03-18 09:06:24 +08:00
|
|
|
}
|
|
|
|
void f2() {
|
|
|
|
// CHECK-LABEL: @_ZN9B197730102f2Ev
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK: 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
|
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>());
|
|
|
|
}
|
|
|
|
}
|