84 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -triple x86_64 -emit-llvm -o - %s | FileCheck %s2 3namespace 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_list9 {10 const _E* __begin_;11 const _E* __end_;12 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 27 initializer_list() : __begin_(nullptr), __end_(nullptr) {}28 29 size_t size() const {return __end_ - __begin_;}30 const _E* begin() const {return __begin_;}31 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_, ptr37std::initializer_list<int> globalInitList1 = {1, 2, 3};38 39void fn1(int i) {40 // CHECK-LABEL: define{{.*}} void @_Z3fn1i41 // temporary array42 // CHECK: [[array:%[^ ]+]] = alloca [3 x i32]43 // CHECK: store i32 1, ptr44 // CHECK-NEXT: getelementptr45 // CHECK-NEXT: store46 // CHECK-NEXT: getelementptr47 // CHECK-NEXT: load48 // CHECK-NEXT: store49 // init the list50 // CHECK-NEXT: getelementptr51 // CHECK-NEXT: store ptr52 // CHECK-NEXT: getelementptr53 // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr [[array]], i{{32|64}} 0, i{{32|64}} 354 // CHECK-NEXT: store ptr55 std::initializer_list<int> intlist{1, 2, i};56}57 58struct destroyme1 {59 ~destroyme1();60};61struct destroyme2 {62 ~destroyme2();63};64 65 66void fn2() {67 // CHECK-LABEL: define{{.*}} void @_Z3fn2v68 void target(std::initializer_list<destroyme1>);69 // objects should be destroyed before dm2, after call returns70 target({ destroyme1(), destroyme1() });71 // CHECK: call void @_ZN10destroyme1D1Ev72 destroyme2 dm2;73 // CHECK: call void @_ZN10destroyme2D1Ev74}75 76void fn3() {77 // CHECK-LABEL: define{{.*}} void @_Z3fn3v78 // objects should be destroyed after dm279 auto list = { destroyme1(), destroyme1() };80 destroyme2 dm2;81 // CHECK: call void @_ZN10destroyme2D1Ev82 // CHECK: call void @_ZN10destroyme1D1Ev83}84