1 // RUN: %clang_cc1 -std=c++98 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX98
2 // RUN: %clang_cc1 -std=c++17 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX17
15 // CHECK: _Z15test_value_initv
16 void test_value_init() {
17 // This value initialization requires zero initialization of the 'B'
18 // subobject followed by a call to its constructor.
21 // CHECK: store i32 17
22 // CHECK: call void @llvm.memset.p0i8.i64
23 // CHECK: call void @_ZN1BC1Ev
25 // CHECK: call void @_ZN1CD1Ev
28 enum enum_type
{ negative_number
= -1, magic_number
= 42 };
35 enum_holder() : m_enum(magic_number
) { }
38 struct enum_holder_and_int
44 // CHECK: _Z24test_enum_holder_and_intv()
45 void test_enum_holder_and_int() {
47 // CHECK-NEXT: bitcast
48 // CHECK-NEXT: call void @llvm.memset
49 // CHECK-NEXT: call void @_ZN19enum_holder_and_intC1Ev
50 enum_holder_and_int();
51 // CHECK-NEXT: ret void
54 // PR7834: don't crash.
60 A
&operator=(const A
&);
78 // CHECK-LABEL: define{{.*}} i32 @_ZN6ptrmem4testEPNS_1SE
80 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
81 // CHECK: getelementptr
101 struct Test3
: public Test
{ };
103 // CHECK-LABEL: define{{.*}} void @_ZN6PR98011fEv
105 // CHECK-NOT: call void @llvm.memset.p0i8.i64
106 // CHECK: call void @_ZN6PR98014TestC1Ei
107 // CHECK-NOT: call void @llvm.memset.p0i8.i64
108 // CHECK: call void @_ZN6PR98014TestC1Ev
109 Test partial
[3] = { 1 };
111 // CHECK-NOT: call void @llvm.memset.p0i8.i64
112 // CHECK: call void @_ZN6PR98014TestC1Ev
113 // CHECK-NOT: call void @_ZN6PR98014TestC1Ev
116 // CHECK: call void @llvm.memset.p0i8.i64
117 // CHECK-NOT: call void @llvm.memset.p0i8.i64
118 // CHECK-CXX98: call void @_ZN6PR98015Test2C1Ev
119 // CHECK-CXX17: call void @_ZN6PR98014TestC1Ev
120 // CHECK-NOT: call void @_ZN6PR98015Test2C1Ev
121 Test2 empty2
[3] = {};
123 // CHECK: call void @llvm.memset.p0i8.i64
124 // CHECK-NOT: call void @llvm.memset.p0i8.i64
125 // CHECK-CXX98: call void @_ZN6PR98015Test3C1Ev
126 // CHECK-CXX17: call void @_ZN6PR98014TestC2Ev
127 // CHECK-NOT: call void @llvm.memset.p0i8.i64
128 // CHECK-NOT: call void @_ZN6PR98015Test3C1Ev
129 Test3 empty3
[3] = {};
137 // CHECK-LABEL: define{{.*}} i32 @_ZN8zeroinit4testEv()
139 // CHECK: call void @llvm.memset.p0i8.i64
154 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X1Ev
156 // CHECK: call void @llvm.memset.p0i8.i64
157 // CHECK-NEXT: call void @_ZN8zeroinit2X1C1Ev
158 // CHECK-NEXT: call void @_ZN8zeroinit2X11fEv
169 struct X3
: X2
<int> {
175 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X3Ev
177 // CHECK-NOT: call void @llvm.memset
178 // CHECK: call void @_ZN8zeroinit2X3IiEC1Ev
179 // CHECK: call void @_ZN8zeroinit2X2IiE1fEv
180 // CHECK-NEXT: ret void
184 // More checks at EOF
200 // rdar://problem/9355931
202 struct A
{ A(); A(int); };
205 A arr
[10][20] = { 5 };
207 // CHECK-LABEL: define{{.*}} void @_ZN5test64testEv()
208 // CHECK: [[ARR:%.*]] = alloca [10 x [20 x [[A:%.*]]]],
210 // CHECK-NEXT: [[INNER:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]], [10 x [20 x [[A]]]]* [[ARR]], i64 0, i64 0
211 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 0, i64 0
212 // CHECK-NEXT: call void @_ZN5test61AC1Ei([[A]]* {{[^,]*}} [[T0]], i32 noundef 5)
213 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [[A]], [[A]]* [[T0]], i64 1
214 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]], [[A]]* [[T0]], i64 20
215 // CHECK-NEXT: br label
216 // CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
217 // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* {{[^,]*}} [[CUR]])
218 // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]], [[A]]* [[CUR]], i64 1
219 // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]]
222 // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 1
223 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 10
224 // CHECK-NEXT: br label
225 // CHECK: [[CUR:%.*]] = phi [20 x [[A]]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
228 // CHECK-NEXT: [[IBEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[CUR]], i{{32|64}} 0, i{{32|64}} 0
229 // CHECK-NEXT: [[IEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[IBEGIN]], i64 20
230 // CHECK-NEXT: br label
231 // CHECK: [[ICUR:%.*]] = phi [[A]]* [ [[IBEGIN]], {{%.*}} ], [ [[INEXT:%.*]], {{%.*}} ]
232 // CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* {{[^,]*}} [[ICUR]])
233 // CHECK-NEXT: [[INEXT:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ICUR]], i64 1
234 // CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[INEXT]], [[IEND]]
235 // CHECK-NEXT: br i1 [[T0]],
237 // CHECK: [[NEXT]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[CUR]], i64 1
238 // CHECK-NEXT: [[T0:%.*]] = icmp eq [20 x [[A]]]* [[NEXT]], [[END]]
239 // CHECK-NEXT: br i1 [[T0]]
244 // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
245 struct A
{ int a
; A(); A(int); };
246 struct B
: virtual A
{ int b
; };
247 struct C
: B
{ C(); };
248 C::C() : A(3), B() {}
249 // CHECK-LABEL: define{{.*}} void @_ZN7PR111241CC1Ev
250 // CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 {{.*}}, i8 0, i64 12, i1 false)
251 // CHECK-NEXT: call void @_ZN7PR111241BC2Ev
252 // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
254 struct B2
: virtual A
{ int B::*b
; };
255 struct C2
: B2
{ C2(); };
256 C2::C2() : A(3), B2() {}
257 // CHECK-LABEL: define{{.*}} void @_ZN7PR111242C2C1Ev
258 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 {{.*}}, i64 16, i1 false)
259 // CHECK-NEXT: call void @_ZN7PR111242B2C2Ev
262 // Ensure we produce an i1 here, and don't assert.
263 // CHECK-LABEL: define{{.*}} void @_Z9r170806_bv(
264 // CHECK: call void @_Z9r170806_ab(i1 noundef zeroext false)
265 void r170806_a(bool b
= bool());
266 void r170806_b() { r170806_a(); }
269 struct data
{ int i
; };
271 template<typename T
= int>
273 data d
; // not value-init
277 // CHECK-LABEL: define {{.*}} @_ZN7PR202561gIiEENS_4dataEv(
282 template<typename
...T
>
284 data
d(t
...); // value-init
288 // CHECK-LABEL: define {{.*}} @_ZN7PR202561hIJEEENS_4dataEDpT_(
289 // CHECK: call void @llvm.memset
293 template<typename T
= int>
295 data d
= {}; // value-init
299 // CHECK-LABEL: define {{.*}} @_ZN7PR202561jIiEENS_4dataEv(
300 // CHECK: call void @llvm.memset
304 data d
; // not value-init
307 // CHECK-LABEL: define {{.*}} @_ZN7PR202561fEv(
313 data d
= {}; // value-init
316 // CHECK-LABEL: define {{.*}} @_ZN7PR202561iEv(
317 // CHECK: call void @llvm.memset
321 // CHECK-LABEL: define {{.*}}@_Z20explicitly_defaultedv
322 int explicitly_defaulted() {
323 struct A
{ A() = default; int n
; };
324 // CHECK: call void @llvm.memset
329 // CHECK-LABEL: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* {{[^,]*}} %this) unnamed_addr
330 // CHECK: call void @llvm.memset.p0i8.i64
331 // CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev
332 // CHECK-NEXT: ret void
334 #if __cplusplus >= 201103L
335 namespace transparent_init_list
{
336 struct optional_assign_base
{};
337 struct optional_data_dtor_base
{ char dummy_
[24]; };
338 struct optional
: optional_data_dtor_base
, optional_assign_base
{};
339 optional
f(optional a
) { return {optional(a
)}; }