1 // RUN: %clang_cc1 -std=c++11 -S -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck %s
2 // RUN: %clang_cc1 -std=c++17 -S -emit-llvm -o - %s -triple x86_64-linux-gnu | FileCheck %s
4 struct A
{ int a
, b
; int f(); };
6 namespace NonAggregateCopyInAggregateInit
{ // PR32044
7 struct A
{ constexpr A(int n
) : x(n
), y() {} int x
, y
; } extern a
;
8 // CHECK-DAG: @_ZN31NonAggregateCopyInAggregateInit1bE ={{.*}} global %{{.*}} { ptr @_ZN31NonAggregateCopyInAggregateInit1aE }
9 struct B
{ A
&p
; } b
{{a
}};
10 // CHECK-DAG: @_ZGRN31NonAggregateCopyInAggregateInit1cE_ = internal global %[[A:.*]] { i32 1, i32 0 }
11 // CHECK-DAG: @_ZN31NonAggregateCopyInAggregateInit1cE ={{.*}} global %{{.*}} { ptr @_ZGRN31NonAggregateCopyInAggregateInit1cE_ }
12 struct C
{ A
&&p
; } c
{{1}};
15 namespace NearlyZeroInit
{
16 // CHECK-DAG: @_ZN14NearlyZeroInit1aE ={{.*}} global {{.*}} <{ i32 1, i32 2, i32 3, [120 x i32] zeroinitializer }>
17 int a
[123] = {1, 2, 3};
18 // CHECK-DAG: @_ZN14NearlyZeroInit1bE ={{.*}} global {{.*}} { i32 1, <{ i32, [2147483647 x i32] }> <{ i32 2, [2147483647 x i32] zeroinitializer }> }
19 struct B
{ int n
; int arr
[1024 * 1024 * 1024 * 2u]; } b
= {1, {2}};
27 // FIXME: [dcl.init]p2, the padding bits of the union object should be
28 // initialized to 0, not undef, which would allow us to collapse the tail
29 // of these arrays to zeroinitializer.
30 // CHECK-DAG: @_ZN7PR375601cE ={{.*}} global <{ { i8, [3 x i8] } }> <{ { i8, [3 x i8] } { i8 0, [3 x i8] undef } }>
32 // 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 },
33 U d
[16] = {'a', {.a
= 123}, 'b'};
34 // CHECK-DAG: @_ZN7PR375601eE ={{.*}} global {{.*}} <{ %"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, { i8, [3 x i8] } { i8 0, [3 x i8] undef },
35 U e
[16] = {{.a
= 123}, {.a
= 456}};
41 // CHECK-DAG: @_ZN7PR375601fE ={{.*}} global [1 x %"{{[^"]*}}"] zeroinitializer
43 // 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 }>
44 V g
[16] = {{.x
= 'a'}, {.a
= 123}, {.x
= 'b'}};
45 // CHECK-DAG: @_ZN7PR375601hE ={{.*}} global {{.*}} <{ %"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, [14 x %"{{[^"]*}}"] zeroinitializer }>
46 V h
[16] = {{.a
= 123}, {.a
= 456}};
47 // CHECK-DAG: @_ZN7PR375601iE ={{.*}} global [4 x %"{{[^"]*}}"] [%"{{[^"]*}}" { i32 123 }, %"{{[^"]*}}" { i32 456 }, %"{{[^"]*}}" zeroinitializer, %"{{[^"]*}}" zeroinitializer]
48 V i
[4] = {{.a
= 123}, {.a
= 456}};
51 // CHECK-LABEL: define {{.*}}@_Z3fn1i(
53 // CHECK: %[[INITLIST:.*]] = alloca %struct.A
54 // CHECK: %[[A:.*]] = getelementptr inbounds %struct.A, ptr %[[INITLIST]], i32 0, i32 0
55 // CHECK: store i32 %{{.*}}, ptr %[[A]], align 4
56 // CHECK: %[[B:.*]] = getelementptr inbounds %struct.A, ptr %[[INITLIST]], i32 0, i32 1
57 // CHECK: store i32 5, ptr %[[B]], align 4
58 // CHECK: call noundef i32 @_ZN1A1fEv(ptr {{[^,]*}} %[[INITLIST]])
62 struct B
{ int &r
; int &f() { return r
; } };
64 // CHECK-LABEL: define {{.*}}@_Z3fn2Ri(
66 // CHECK: %[[INITLIST2:.*]] = alloca %struct.B, align 8
67 // CHECK: %[[R:.*]] = getelementptr inbounds %struct.B, ptr %[[INITLIST2:.*]], i32 0, i32 0
68 // CHECK: store ptr %{{.*}}, ptr %[[R]], align 8
69 // CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN1B1fEv(ptr {{[^,]*}} %[[INITLIST2:.*]])
73 // CHECK-LABEL: define {{.*}}@__cxx_global_var_init(
75 // CHECK: call {{.*}}@_ZN14NonTrivialInit1AC1Ev(
76 // CHECK: getelementptr inbounds {{.*}}, i64 1
79 // CHECK: getelementptr inbounds {{.*}}, i64 1
80 // CHECK: icmp eq {{.*}}, getelementptr inbounds {{.*}}, i64 30
83 // CHECK: call i32 @__cxa_atexit(
84 namespace NonTrivialInit
{
85 struct A
{ A(); A(const A
&) = delete; ~A(); };
86 struct B
{ A a
[20]; };
87 // NB, this must be large enough to be worth memsetting for this test to be
94 constexpr int zero() { return 0; }
95 constexpr int *null() { return nullptr; }
104 // These declarations, if implemented elementwise, require huge
105 // amout of memory and compiler time.
106 unsigned char data_1
[1024 * 1024 * 1024 * 2u] = { 0 };
107 unsigned char data_2
[1024 * 1024 * 1024 * 2u] = { Zero
};
108 unsigned char data_3
[1024][1024][1024] = {{{0}}};
109 unsigned char data_4
[1024 * 1024 * 1024 * 2u] = { zero() };
110 int *data_5
[1024 * 1024 * 512] = { nullptr };
111 int *data_6
[1024 * 1024 * 512] = { null() };
112 struct S1 data_7
[1024 * 1024 * 512] = {{0}};
113 char data_8
[1000 * 1000 * 1000] = {};
114 int (&&data_9
)[1000 * 1000 * 1000] = {0};
115 unsigned char data_10
[1024 * 1024 * 1024 * 2u] = { 1 };
116 unsigned char data_11
[1024 * 1024 * 1024 * 2u] = { One
};
117 unsigned char data_12
[1024][1024][1024] = {{{1}}};
119 // This variable must be initialized elementwise.
120 Filler data_e1
[1024] = {};
121 // CHECK: getelementptr inbounds {{.*}} @_ZN8ZeroInit7data_e1E
126 // CHECK: define {{.*}}@_ZN8ZeroInit9largeish1Ev(
128 // CHECK: call {{.*}}memset
129 Largeish
largeish1() { return {}; }
130 // CHECK: define {{.*}}@_ZN8ZeroInit9largeish2Ev(
132 // CHECK: call {{.*}}memset
133 Largeish
largeish2() { return Largeish(); }
134 // CHECK: define {{.*}}@_ZN8ZeroInit9largeish3Ev(
136 // CHECK: call {{.*}}memset
137 Largeish
largeish3() { return Largeish
{}; }
138 // CHECK: define {{.*}}@_ZN8ZeroInit9largeish4Ev(
140 // CHECK: call {{.*}}memset
141 Largeish
largeish4() { return (Largeish
){}; }
142 // CHECK: define {{.*}}@_ZN8ZeroInit9largeish5Ev(
144 // CHECK: call {{.*}}memset
145 Largeish
largeish5() { return {0, 0, 0}; }
147 typedef __attribute__((ext_vector_type(4))) char CI4
;
159 // CHECK: define {{.*}}@_ZN8ZeroInit11conversionsEv(
161 // CHECK: call {{.*}}memset
162 Conversions
conversions() {
168 static_cast<char>(0.0),
170 reinterpret_cast<int *>(0),
171 reinterpret_cast<long>((int *)nullptr)};