Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / cxx0x-initializer-stdinitializerlist-startend.cpp
blob36c46fdcb86edada904545d3deeeef542c2da582
1 // RUN: %clang_cc1 -std=c++11 -S -triple x86_64-none-linux-gnu -emit-llvm -o - %s | FileCheck %s
3 namespace std {
4 typedef decltype(sizeof(int)) size_t;
6 // libc++'s implementation with __size_ replaced by __end_
7 template <class _E>
8 class initializer_list
10 const _E* __begin_;
11 const _E* __end_;
13 initializer_list(const _E* __b, const _E* __e)
14 : __begin_(__b),
15 __end_(__e)
18 public:
19 typedef _E value_type;
20 typedef const _E& reference;
21 typedef const _E& const_reference;
22 typedef size_t size_type;
24 typedef const _E* iterator;
25 typedef const _E* const_iterator;
27 initializer_list() : __begin_(nullptr), __end_(nullptr) {}
29 size_t size() const {return __end_ - __begin_;}
30 const _E* begin() const {return __begin_;}
31 const _E* end() const {return __end_;}
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};
39 void fn1(int i) {
40 // CHECK-LABEL: define{{.*}} void @_Z3fn1i
41 // temporary array
42 // CHECK: [[array:%[^ ]+]] = alloca [3 x i32]
43 // CHECK: getelementptr inbounds [3 x i32], ptr [[array]], i{{32|64}} 0
44 // CHECK-NEXT: store i32 1, ptr
45 // CHECK-NEXT: getelementptr
46 // CHECK-NEXT: store
47 // CHECK-NEXT: getelementptr
48 // CHECK-NEXT: load
49 // CHECK-NEXT: store
50 // init the list
51 // CHECK-NEXT: getelementptr
52 // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr
53 // CHECK-NEXT: store ptr
54 // CHECK-NEXT: getelementptr
55 // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr [[array]], i{{32|64}} 0, i{{32|64}} 3
56 // CHECK-NEXT: store ptr
57 std::initializer_list<int> intlist{1, 2, i};
60 struct destroyme1 {
61 ~destroyme1();
63 struct destroyme2 {
64 ~destroyme2();
68 void fn2() {
69 // CHECK-LABEL: define{{.*}} void @_Z3fn2v
70 void target(std::initializer_list<destroyme1>);
71 // objects should be destroyed before dm2, after call returns
72 target({ destroyme1(), destroyme1() });
73 // CHECK: call void @_ZN10destroyme1D1Ev
74 destroyme2 dm2;
75 // CHECK: call void @_ZN10destroyme2D1Ev
78 void fn3() {
79 // CHECK-LABEL: define{{.*}} void @_Z3fn3v
80 // objects should be destroyed after dm2
81 auto list = { destroyme1(), destroyme1() };
82 destroyme2 dm2;
83 // CHECK: call void @_ZN10destroyme2D1Ev
84 // CHECK: call void @_ZN10destroyme1D1Ev