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