1 // RUN: %clang_cc1 -std=c++11 -triple x86_64 -emit-llvm -o - %s | FileCheck %s
2
3 namespace std {
4 typedef decltype(sizeof(int)) size_t;
5
6 // libc++'s implementation with __size_ replaced by __end_
7 template <class _E>
8 class initializer_list
9 {
10 const _E* __begin_;
11 const _E* __end_;
12
initializer_list(const _E * __b,const _E * __e)13 initializer_list(const _E* __b, const _E* __e)
14 : __begin_(__b),
15 __end_(__e)
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
initializer_list()27 initializer_list() : __begin_(nullptr), __end_(nullptr) {}
28
size() const29 size_t size() const {return __end_ - __begin_;}
begin() const30 const _E* begin() const {return __begin_;}
end() const31 const _E* end() const {return __end_;}
32 };
33 }
34
35 // CHECK: @_ZGR15globalInitList1_ = internal constant [3 x i32] [i32 1, i32 2, i32 3]
36 // CHECK: @globalInitList1 ={{.*}} global {{[^ ]+}} { ptr @_ZGR15globalInitList1_, ptr
37 std::initializer_list<int> globalInitList1 = {1, 2, 3};
38
fn1(int i)39 void fn1(int i) {
40 // CHECK-LABEL: define{{.*}} void @_Z3fn1i
41 // temporary array
42 // CHECK: [[array:%[^ ]+]] = alloca [3 x i32]
43 // CHECK: store i32 1, ptr
44 // CHECK-NEXT: getelementptr
45 // CHECK-NEXT: store
46 // CHECK-NEXT: getelementptr
47 // CHECK-NEXT: load
48 // CHECK-NEXT: store
49 // init the list
50 // CHECK-NEXT: getelementptr
51 // CHECK-NEXT: store ptr
52 // CHECK-NEXT: getelementptr
53 // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr [[array]], i{{32|64}} 0, i{{32|64}} 3
54 // CHECK-NEXT: store ptr
55 std::initializer_list<int> intlist{1, 2, i};
56 }
57
58 struct destroyme1 {
59 ~destroyme1();
60 };
61 struct destroyme2 {
62 ~destroyme2();
63 };
64
65
fn2()66 void fn2() {
67 // CHECK-LABEL: define{{.*}} void @_Z3fn2v
68 void target(std::initializer_list<destroyme1>);
69 // objects should be destroyed before dm2, after call returns
70 target({ destroyme1(), destroyme1() });
71 // CHECK: call void @_ZN10destroyme1D1Ev
72 destroyme2 dm2;
73 // CHECK: call void @_ZN10destroyme2D1Ev
74 }
75
fn3()76 void fn3() {
77 // CHECK-LABEL: define{{.*}} void @_Z3fn3v
78 // objects should be destroyed after dm2
79 auto list = { destroyme1(), destroyme1() };
80 destroyme2 dm2;
81 // CHECK: call void @_ZN10destroyme2D1Ev
82 // CHECK: call void @_ZN10destroyme1D1Ev
83 }
84