xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -S -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc namespace std {
4f4a2713aSLionel Sambuc   typedef decltype(sizeof(int)) size_t;
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc   // libc++'s implementation with __size_ replaced by __end_
7f4a2713aSLionel Sambuc   template <class _E>
8f4a2713aSLionel Sambuc   class initializer_list
9f4a2713aSLionel Sambuc   {
10f4a2713aSLionel Sambuc     const _E* __begin_;
11f4a2713aSLionel Sambuc     const _E* __end_;
12f4a2713aSLionel Sambuc 
initializer_list(const _E * __b,const _E * __e)13f4a2713aSLionel Sambuc     initializer_list(const _E* __b, const _E* __e)
14f4a2713aSLionel Sambuc       : __begin_(__b),
15f4a2713aSLionel Sambuc         __end_(__e)
16f4a2713aSLionel Sambuc     {}
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc   public:
19f4a2713aSLionel Sambuc     typedef _E        value_type;
20f4a2713aSLionel Sambuc     typedef const _E& reference;
21f4a2713aSLionel Sambuc     typedef const _E& const_reference;
22f4a2713aSLionel Sambuc     typedef size_t    size_type;
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc     typedef const _E* iterator;
25f4a2713aSLionel Sambuc     typedef const _E* const_iterator;
26f4a2713aSLionel Sambuc 
initializer_list()27f4a2713aSLionel Sambuc     initializer_list() : __begin_(nullptr), __end_(nullptr) {}
28f4a2713aSLionel Sambuc 
size() const29f4a2713aSLionel Sambuc     size_t    size()  const {return __end_ - __begin_;}
begin() const30f4a2713aSLionel Sambuc     const _E* begin() const {return __begin_;}
end() const31f4a2713aSLionel Sambuc     const _E* end()   const {return __end_;}
32f4a2713aSLionel Sambuc   };
33f4a2713aSLionel Sambuc }
34f4a2713aSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc // CHECK: @_ZGR15globalInitList1_ = private constant [3 x i32] [i32 1, i32 2, i32 3]
36*0a6a1f1dSLionel Sambuc // CHECK: @globalInitList1 = global {{[^ ]+}} { i32* getelementptr inbounds ([3 x i32]* @_ZGR15globalInitList1_, {{[^)]*}}), i32*
37f4a2713aSLionel Sambuc std::initializer_list<int> globalInitList1 = {1, 2, 3};
38f4a2713aSLionel Sambuc 
fn1(int i)39f4a2713aSLionel Sambuc void fn1(int i) {
40f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_Z3fn1i
41f4a2713aSLionel Sambuc   // temporary array
42f4a2713aSLionel Sambuc   // CHECK: [[array:%[^ ]+]] = alloca [3 x i32]
43f4a2713aSLionel Sambuc   // CHECK: getelementptr inbounds [3 x i32]* [[array]], i{{32|64}} 0
44f4a2713aSLionel Sambuc   // CHECK-NEXT: store i32 1, i32*
45f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr
46f4a2713aSLionel Sambuc   // CHECK-NEXT: store
47f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr
48f4a2713aSLionel Sambuc   // CHECK-NEXT: load
49f4a2713aSLionel Sambuc   // CHECK-NEXT: store
50f4a2713aSLionel Sambuc   // init the list
51f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr
52f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr inbounds [3 x i32]*
53f4a2713aSLionel Sambuc   // CHECK-NEXT: store i32*
54f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr
55f4a2713aSLionel Sambuc   // CHECK-NEXT: getelementptr inbounds [3 x i32]* [[array]], i{{32|64}} 0, i{{32|64}} 3
56f4a2713aSLionel Sambuc   // CHECK-NEXT: store i32*
57f4a2713aSLionel Sambuc   std::initializer_list<int> intlist{1, 2, i};
58f4a2713aSLionel Sambuc }
59f4a2713aSLionel Sambuc 
60f4a2713aSLionel Sambuc struct destroyme1 {
61f4a2713aSLionel Sambuc   ~destroyme1();
62f4a2713aSLionel Sambuc };
63f4a2713aSLionel Sambuc struct destroyme2 {
64f4a2713aSLionel Sambuc   ~destroyme2();
65f4a2713aSLionel Sambuc };
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc 
fn2()68f4a2713aSLionel Sambuc void fn2() {
69f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_Z3fn2v
70f4a2713aSLionel Sambuc   void target(std::initializer_list<destroyme1>);
71f4a2713aSLionel Sambuc   // objects should be destroyed before dm2, after call returns
72f4a2713aSLionel Sambuc   target({ destroyme1(), destroyme1() });
73f4a2713aSLionel Sambuc   // CHECK: call void @_ZN10destroyme1D1Ev
74f4a2713aSLionel Sambuc   destroyme2 dm2;
75f4a2713aSLionel Sambuc   // CHECK: call void @_ZN10destroyme2D1Ev
76f4a2713aSLionel Sambuc }
77f4a2713aSLionel Sambuc 
fn3()78f4a2713aSLionel Sambuc void fn3() {
79f4a2713aSLionel Sambuc   // CHECK-LABEL: define void @_Z3fn3v
80f4a2713aSLionel Sambuc   // objects should be destroyed after dm2
81f4a2713aSLionel Sambuc   auto list = { destroyme1(), destroyme1() };
82f4a2713aSLionel Sambuc   destroyme2 dm2;
83f4a2713aSLionel Sambuc   // CHECK: call void @_ZN10destroyme2D1Ev
84f4a2713aSLionel Sambuc   // CHECK: call void @_ZN10destroyme1D1Ev
85f4a2713aSLionel Sambuc }
86