1*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-STATIC-BL 2*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -emit-llvm -o - %s -Dconstexpr= | FileCheck %s --check-prefix=CHECK-DYNAMIC-BL 3*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -emit-llvm -o - %s -DUSE_END | FileCheck %s --check-prefix=CHECK-STATIC-BE 4*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -emit-llvm -o - %s -DUSE_END -Dconstexpr= | FileCheck %s --check-prefix=CHECK-DYNAMIC-BE 5*67e74705SXin Li 6*67e74705SXin Li namespace std { 7*67e74705SXin Li typedef decltype(sizeof(int)) size_t; 8*67e74705SXin Li 9*67e74705SXin Li template <class _E> 10*67e74705SXin Li class initializer_list 11*67e74705SXin Li { 12*67e74705SXin Li const _E* __begin_; 13*67e74705SXin Li #ifdef USE_END 14*67e74705SXin Li const _E* __end_; 15*67e74705SXin Li #else 16*67e74705SXin Li size_t __size_; 17*67e74705SXin Li #endif 18*67e74705SXin Li initializer_list(const _E * __b,size_t __s)19*67e74705SXin Li constexpr initializer_list(const _E* __b, size_t __s) 20*67e74705SXin Li : __begin_(__b), 21*67e74705SXin Li #ifdef USE_END 22*67e74705SXin Li __end_(__b + __s) 23*67e74705SXin Li #else 24*67e74705SXin Li __size_(__s) 25*67e74705SXin Li #endif 26*67e74705SXin Li {} 27*67e74705SXin Li 28*67e74705SXin Li public: 29*67e74705SXin Li typedef _E value_type; 30*67e74705SXin Li typedef const _E& reference; 31*67e74705SXin Li typedef const _E& const_reference; 32*67e74705SXin Li typedef size_t size_type; 33*67e74705SXin Li 34*67e74705SXin Li typedef const _E* iterator; 35*67e74705SXin Li typedef const _E* const_iterator; 36*67e74705SXin Li 37*67e74705SXin Li #ifdef USE_END initializer_list()38*67e74705SXin Li constexpr initializer_list() : __begin_(nullptr), __end_(nullptr) {} 39*67e74705SXin Li size() const40*67e74705SXin Li size_t size() const {return __end_ - __begin_;} begin() const41*67e74705SXin Li const _E* begin() const {return __begin_;} end() const42*67e74705SXin Li const _E* end() const {return __end_;} 43*67e74705SXin Li #else initializer_list()44*67e74705SXin Li constexpr initializer_list() : __begin_(nullptr), __size_(0) {} 45*67e74705SXin Li size() const46*67e74705SXin Li size_t size() const {return __size_;} begin() const47*67e74705SXin Li const _E* begin() const {return __begin_;} end() const48*67e74705SXin Li const _E* end() const {return __begin_ + __size_;} 49*67e74705SXin Li #endif 50*67e74705SXin Li }; 51*67e74705SXin Li } 52*67e74705SXin Li 53*67e74705SXin Li constexpr int a = 2, b = 4, c = 6; 54*67e74705SXin Li std::initializer_list<std::initializer_list<int>> nested = { 55*67e74705SXin Li {1, a}, {3, b}, {5, c} 56*67e74705SXin Li }; 57*67e74705SXin Li 58*67e74705SXin Li // CHECK-STATIC-BL: @_ZGR6nested0_ = internal constant [2 x i32] [i32 1, i32 2], align 4 59*67e74705SXin Li // CHECK-STATIC-BL: @_ZGR6nested1_ = internal constant [2 x i32] [i32 3, i32 4], align 4 60*67e74705SXin Li // CHECK-STATIC-BL: @_ZGR6nested2_ = internal constant [2 x i32] [i32 5, i32 6], align 4 61*67e74705SXin Li // CHECK-STATIC-BL: @_ZGR6nested_ = internal constant [3 x {{.*}}] [ 62*67e74705SXin Li // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i32 0, i32 0), i64 2 }, 63*67e74705SXin Li // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i32 0, i32 0), i64 2 }, 64*67e74705SXin Li // CHECK-STATIC-BL: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i32 0, i32 0), i64 2 } 65*67e74705SXin Li // CHECK-STATIC-BL: ], align 8 66*67e74705SXin Li // CHECK-STATIC-BL: @nested = global {{.*}} { {{.*}} getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i32 0, i32 0), i64 3 }, align 8 67*67e74705SXin Li 68*67e74705SXin Li // CHECK-DYNAMIC-BL: @nested = global 69*67e74705SXin Li // CHECK-DYNAMIC-BL: @_ZGR6nested_ = internal global [3 x 70*67e74705SXin Li // CHECK-DYNAMIC-BL: @_ZGR6nested0_ = internal global [2 x i32] zeroinitializer 71*67e74705SXin Li // CHECK-DYNAMIC-BL: @_ZGR6nested1_ = internal global [2 x i32] zeroinitializer 72*67e74705SXin Li // CHECK-DYNAMIC-BL: @_ZGR6nested2_ = internal global [2 x i32] zeroinitializer 73*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 1, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 0) 74*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 1) 75*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 0), 76*67e74705SXin Li // CHECK-DYNAMIC-BL: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0, i32 0), align 8 77*67e74705SXin Li // CHECK-DYNAMIC-BL: store i64 2, i64* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0, i32 1), align 8 78*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 3, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 0) 79*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 1) 80*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 0), 81*67e74705SXin Li // CHECK-DYNAMIC-BL: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 1, i32 0), align 8 82*67e74705SXin Li // CHECK-DYNAMIC-BL: store i64 2, i64* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 1, i32 1), align 8 83*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 5, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 0) 84*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 1) 85*67e74705SXin Li // CHECK-DYNAMIC-BL: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 0), 86*67e74705SXin Li // CHECK-DYNAMIC-BL: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 2, i32 0), align 8 87*67e74705SXin Li // CHECK-DYNAMIC-BL: store i64 2, i64* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 2, i32 1), align 8 88*67e74705SXin Li // CHECK-DYNAMIC-BL: store {{.*}}* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0), 89*67e74705SXin Li // CHECK-DYNAMIC-BL: {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* @nested, i32 0, i32 0), align 8 90*67e74705SXin Li // CHECK-DYNAMIC-BL: store i64 3, i64* getelementptr inbounds ({{.*}}, {{.*}}* @nested, i32 0, i32 1), align 8 91*67e74705SXin Li 92*67e74705SXin Li // CHECK-STATIC-BE: @_ZGR6nested0_ = internal constant [2 x i32] [i32 1, i32 2], align 4 93*67e74705SXin Li // CHECK-STATIC-BE: @_ZGR6nested1_ = internal constant [2 x i32] [i32 3, i32 4], align 4 94*67e74705SXin Li // CHECK-STATIC-BE: @_ZGR6nested2_ = internal constant [2 x i32] [i32 5, i32 6], align 4 95*67e74705SXin Li // CHECK-STATIC-BE: @_ZGR6nested_ = internal constant [3 x {{.*}}] [ 96*67e74705SXin Li // CHECK-STATIC-BE: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i32 0, i32 0), 97*67e74705SXin Li // CHECK-STATIC-BE: i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @_ZGR6nested0_ to i8*), i64 8) to i32*) } 98*67e74705SXin Li // CHECK-STATIC-BE: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i32 0, i32 0), 99*67e74705SXin Li // CHECK-STATIC-BE: i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @_ZGR6nested1_ to i8*), i64 8) to i32*) } 100*67e74705SXin Li // CHECK-STATIC-BE: {{.*}} { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i32 0, i32 0), 101*67e74705SXin Li // CHECK-STATIC-BE: i32* bitcast (i8* getelementptr (i8, i8* bitcast ([2 x i32]* @_ZGR6nested2_ to i8*), i64 8) to i32*) } 102*67e74705SXin Li // CHECK-STATIC-BE: ], align 8 103*67e74705SXin Li // CHECK-STATIC-BE: @nested = global {{.*}} { {{.*}} getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i32 0, i32 0), 104*67e74705SXin Li // CHECK-STATIC-BE: {{.*}} bitcast ({{.*}}* getelementptr (i8, i8* bitcast ([3 x {{.*}}]* @_ZGR6nested_ to i8*), i64 48) to {{.*}}*) } 105*67e74705SXin Li 106*67e74705SXin Li // CHECK-DYNAMIC-BE: @nested = global 107*67e74705SXin Li // CHECK-DYNAMIC-BE: @_ZGR6nested_ = internal global [3 x 108*67e74705SXin Li // CHECK-DYNAMIC-BE: @_ZGR6nested0_ = internal global [2 x i32] zeroinitializer 109*67e74705SXin Li // CHECK-DYNAMIC-BE: @_ZGR6nested1_ = internal global [2 x i32] zeroinitializer 110*67e74705SXin Li // CHECK-DYNAMIC-BE: @_ZGR6nested2_ = internal global [2 x i32] zeroinitializer 111*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 1, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 0) 112*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 1) 113*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 0, i64 0), 114*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0, i32 0), align 8 115*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested0_, i64 1, i64 0), 116*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0, i32 1), align 8 117*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 3, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 0) 118*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 1) 119*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 0, i64 0), 120*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 1, i32 0), align 8 121*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested1_, i64 1, i64 0), 122*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 1, i32 1), align 8 123*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 5, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 0) 124*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32 {{.*}}, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 1) 125*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 0, i64 0), 126*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 2, i32 0), align 8 127*67e74705SXin Li // CHECK-DYNAMIC-BE: store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @_ZGR6nested2_, i64 1, i64 0), 128*67e74705SXin Li // CHECK-DYNAMIC-BE: i32** getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 2, i32 1), align 8 129*67e74705SXin Li // CHECK-DYNAMIC-BE: store {{.*}}* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 0, i64 0), 130*67e74705SXin Li // CHECK-DYNAMIC-BE: {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* @nested, i32 0, i32 0), align 8 131*67e74705SXin Li // CHECK-DYNAMIC-BE: store {{.*}}* getelementptr inbounds ([3 x {{.*}}], [3 x {{.*}}]* @_ZGR6nested_, i64 1, i64 0), 132*67e74705SXin Li // CHECK-DYNAMIC-BE: {{.*}}** getelementptr inbounds ({{.*}}, {{.*}}* @nested, i32 0, i32 1), align 8 133