aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/CodeGenCXX/cxx11-initializer-aggregate.cpp')
-rw-r--r--test/CodeGenCXX/cxx11-initializer-aggregate.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/CodeGenCXX/cxx11-initializer-aggregate.cpp b/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
index 8bf35966f5b9..325607f69fb5 100644
--- a/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
+++ b/test/CodeGenCXX/cxx11-initializer-aggregate.cpp
@@ -11,6 +11,42 @@ namespace NonAggregateCopyInAggregateInit { // PR32044
struct C { A &&p; } c{{1}};
}
+namespace NearlyZeroInit {
+ // CHECK-DAG: @_ZN14NearlyZeroInit1aE = global {{.*}} <{ i32 1, i32 2, i32 3, [120 x i32] zeroinitializer }>
+ int a[123] = {1, 2, 3};
+ // CHECK-DAG: @_ZN14NearlyZeroInit1bE = global {{.*}} { i32 1, <{ i32, [2147483647 x i32] }> <{ i32 2, [2147483647 x i32] zeroinitializer }> }
+ struct B { int n; int arr[1024 * 1024 * 1024 * 2u]; } b = {1, {2}};
+}
+
+namespace PR37560 {
+ union U {
+ char x;
+ int a;
+ };
+ // FIXME: [dcl.init]p2, the padding bits of the union object should be
+ // initialized to 0, not undef, which would allow us to collapse the tail
+ // of these arrays to zeroinitializer.
+ // CHECK-DAG: @_ZN7PR375601cE = global <{ { i8, [3 x i8] } }> <{ { i8, [3 x i8] } { i8 0, [3 x i8] undef } }>
+ U c[1] = {};
+ // CHECK-DAG: @_ZN7PR375601dE = global {{.*}} <{ { i8, [3 x i8] } { i8 97, [3 x i8] undef }, %"{{[^"]*}}" { i32 123 }, { i8, [3 x i8] } { i8 98, [3 x i8] undef }, { i8, [3 x i8] } { i8 0, [3 x i8] undef },
+ U d[16] = {'a', {.a = 123}, 'b'};
+ // CHECK-DAG: @_ZN7PR375601eE = global {{.*}} <{ %"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, { i8, [3 x i8] } { i8 0, [3 x i8] undef },
+ U e[16] = {{.a = 123}, {.a = 456}};
+
+ union V {
+ int a;
+ char x;
+ };
+ // CHECK-DAG: @_ZN7PR375601fE = global [1 x %"{{[^"]*}}"] zeroinitializer
+ V f[1] = {};
+ // CHECK-DAG: @_ZN7PR375601gE = global {{.*}} <{ { i8, [3 x i8] } { i8 97, [3 x i8] undef }, %"{{[^"]*}}" { i32 123 }, { i8, [3 x i8] } { i8 98, [3 x i8] undef }, [13 x %"{{[^"]*}}"] zeroinitializer }>
+ V g[16] = {{.x = 'a'}, {.a = 123}, {.x = 'b'}};
+ // CHECK-DAG: @_ZN7PR375601hE = global {{.*}} <{ %"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, [14 x %"{{[^"]*}}"] zeroinitializer }>
+ V h[16] = {{.a = 123}, {.a = 456}};
+ // CHECK-DAG: @_ZN7PR375601iE = global [4 x %"{{[^"]*}}"] [%"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, %"{{[^"]*}}" zeroinitializer, %"{{[^"]*}}" zeroinitializer]
+ V i[4] = {{.a = 123}, {.a = 456}};
+}
+
// CHECK-LABEL: define {{.*}}@_Z3fn1i(
int fn1(int x) {
// CHECK: %[[INITLIST:.*]] = alloca %struct.A
@@ -51,3 +87,35 @@ namespace NonTrivialInit {
// meaningful.
B b[30] = {};
}
+
+namespace ZeroInit {
+ enum { Zero, One };
+ constexpr int zero() { return 0; }
+ constexpr int *null() { return nullptr; }
+ struct Filler {
+ int x;
+ Filler();
+ };
+ struct S1 {
+ int x;
+ };
+
+ // These declarations, if implemented elementwise, require huge
+ // amout of memory and compiler time.
+ unsigned char data_1[1024 * 1024 * 1024 * 2u] = { 0 };
+ unsigned char data_2[1024 * 1024 * 1024 * 2u] = { Zero };
+ unsigned char data_3[1024][1024][1024] = {{{0}}};
+ unsigned char data_4[1024 * 1024 * 1024 * 2u] = { zero() };
+ int *data_5[1024 * 1024 * 512] = { nullptr };
+ int *data_6[1024 * 1024 * 512] = { null() };
+ struct S1 data_7[1024 * 1024 * 512] = {{0}};
+ char data_8[1000 * 1000 * 1000] = {};
+ int (&&data_9)[1000 * 1000 * 1000] = {0};
+ unsigned char data_10[1024 * 1024 * 1024 * 2u] = { 1 };
+ unsigned char data_11[1024 * 1024 * 1024 * 2u] = { One };
+ unsigned char data_12[1024][1024][1024] = {{{1}}};
+
+ // This variable must be initialized elementwise.
+ Filler data_e1[1024] = {};
+ // CHECK: getelementptr inbounds {{.*}} @_ZN8ZeroInit7data_e1E
+}