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