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.p0.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: call void @llvm.memset
48 // CHECK-NEXT: call void @_ZN19enum_holder_and_intC1Ev
49 enum_holder_and_int();
50 // CHECK-NEXT: ret void
53 // PR7834: don't crash.
59 A
&operator=(const A
&);
77 // CHECK-LABEL: define{{.*}} i32 @_ZN6ptrmem4testEPNS_1SE
79 // CHECK: call void @llvm.memcpy.p0.p0.i64
80 // CHECK: getelementptr
100 struct Test3
: public Test
{ };
102 // CHECK-LABEL: define{{.*}} void @_ZN6PR98011fEv
104 // CHECK-NOT: call void @llvm.memset.p0.i64
105 // CHECK: call void @_ZN6PR98014TestC1Ei
106 // CHECK-NOT: call void @llvm.memset.p0.i64
107 // CHECK: call void @_ZN6PR98014TestC1Ev
108 Test partial
[3] = { 1 };
110 // CHECK-NOT: call void @llvm.memset.p0.i64
111 // CHECK: call void @_ZN6PR98014TestC1Ev
112 // CHECK-NOT: call void @_ZN6PR98014TestC1Ev
115 // CHECK: call void @llvm.memset.p0.i64
116 // CHECK-NOT: call void @llvm.memset.p0.i64
117 // CHECK-CXX98: call void @_ZN6PR98015Test2C1Ev
118 // CHECK-CXX17: call void @_ZN6PR98014TestC1Ev
119 // CHECK-NOT: call void @_ZN6PR98015Test2C1Ev
120 Test2 empty2
[3] = {};
122 // CHECK: call void @llvm.memset.p0.i64
123 // CHECK-NOT: call void @llvm.memset.p0.i64
124 // CHECK-CXX98: call void @_ZN6PR98015Test3C1Ev
125 // CHECK-CXX17: call void @_ZN6PR98014TestC2Ev
126 // CHECK-NOT: call void @llvm.memset.p0.i64
127 // CHECK-NOT: call void @_ZN6PR98015Test3C1Ev
128 Test3 empty3
[3] = {};
136 // CHECK-LABEL: define{{.*}} i32 @_ZN8zeroinit4testEv()
138 // CHECK: call void @llvm.memset.p0.i64
153 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X1Ev
155 // CHECK: call void @llvm.memset.p0.i64
156 // CHECK-NEXT: call void @_ZN8zeroinit2X1C1Ev
157 // CHECK-NEXT: call void @_ZN8zeroinit2X11fEv
168 struct X3
: X2
<int> {
174 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X3Ev
176 // CHECK-NOT: call void @llvm.memset
177 // CHECK: call void @_ZN8zeroinit2X3IiEC1Ev
178 // CHECK: call void @_ZN8zeroinit2X2IiE1fEv
179 // CHECK-NEXT: ret void
183 // More checks at EOF
199 // rdar://problem/9355931
201 struct A
{ A(); A(int); };
204 A arr
[10][20] = { 5 };
206 // CHECK-LABEL: define{{.*}} void @_ZN5test64testEv()
207 // CHECK: [[ARR:%.*]] = alloca [10 x [20 x [[A:%.*]]]],
209 // CHECK-NEXT: [[INNER:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]], ptr [[ARR]], i64 0, i64 0
210 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [20 x [[A]]], ptr [[INNER]], i64 0, i64 0
211 // CHECK-NEXT: call void @_ZN5test61AC1Ei(ptr {{[^,]*}} [[T0]], i32 noundef 5)
212 // CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [[A]], ptr [[T0]], i64 1
213 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]], ptr [[T0]], i64 20
214 // CHECK-NEXT: br label
215 // CHECK: [[CUR:%.*]] = phi ptr [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
216 // CHECK-NEXT: call void @_ZN5test61AC1Ev(ptr {{[^,]*}} [[CUR]])
217 // CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]], ptr [[CUR]], i64 1
218 // CHECK-NEXT: [[T0:%.*]] = icmp eq ptr [[NEXT]], [[END]]
221 // CHECK: [[BEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], ptr [[INNER]], i64 1
222 // CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [20 x [[A]]], ptr [[INNER]], i64 10
223 // CHECK-NEXT: br label
224 // CHECK: [[CUR:%.*]] = phi ptr [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
227 // CHECK-NEXT: [[IBEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], ptr [[CUR]], i{{32|64}} 0, i{{32|64}} 0
228 // CHECK-NEXT: [[IEND:%.*]] = getelementptr inbounds [[A]], ptr [[IBEGIN]], i64 20
229 // CHECK-NEXT: br label
230 // CHECK: [[ICUR:%.*]] = phi ptr [ [[IBEGIN]], {{%.*}} ], [ [[INEXT:%.*]], {{%.*}} ]
231 // CHECK-NEXT: call void @_ZN5test61AC1Ev(ptr {{[^,]*}} [[ICUR]])
232 // CHECK-NEXT: [[INEXT:%.*]] = getelementptr inbounds [[A]], ptr [[ICUR]], i64 1
233 // CHECK-NEXT: [[T0:%.*]] = icmp eq ptr [[INEXT]], [[IEND]]
234 // CHECK-NEXT: br i1 [[T0]],
236 // CHECK: [[NEXT]] = getelementptr inbounds [20 x [[A]]], ptr [[CUR]], i64 1
237 // CHECK-NEXT: [[T0:%.*]] = icmp eq ptr [[NEXT]], [[END]]
238 // CHECK-NEXT: br i1 [[T0]]
243 // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
244 struct A
{ int a
; A(); A(int); };
245 struct B
: virtual A
{ int b
; };
246 struct C
: B
{ C(); };
247 C::C() : A(3), B() {}
248 // CHECK-LABEL: define{{.*}} void @_ZN7PR111241CC1Ev
249 // CHECK: call void @llvm.memset.p0.i64(ptr align 8 {{.*}}, i8 0, i64 12, i1 false)
250 // CHECK-NEXT: call void @_ZN7PR111241BC2Ev
251 // Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
253 struct B2
: virtual A
{ int B::*b
; };
254 struct C2
: B2
{ C2(); };
255 C2::C2() : A(3), B2() {}
256 // CHECK-LABEL: define{{.*}} void @_ZN7PR111242C2C1Ev
257 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 %{{.*}}, ptr align 8 {{.*}}, i64 16, i1 false)
258 // CHECK-NEXT: call void @_ZN7PR111242B2C2Ev
261 // Ensure we produce an i1 here, and don't assert.
262 // CHECK-LABEL: define{{.*}} void @_Z9r170806_bv(
263 // CHECK: call void @_Z9r170806_ab(i1 noundef zeroext false)
264 void r170806_a(bool b
= bool());
265 void r170806_b() { r170806_a(); }
268 struct data
{ int i
; };
270 template<typename T
= int>
272 data d
; // not value-init
276 // CHECK-LABEL: define {{.*}} @_ZN7PR202561gIiEENS_4dataEv(
281 template<typename
...T
>
283 data
d(t
...); // value-init
287 // CHECK-LABEL: define {{.*}} @_ZN7PR202561hIJEEENS_4dataEDpT_(
288 // CHECK: call void @llvm.memset
292 template<typename T
= int>
294 data d
= {}; // value-init
298 // CHECK-LABEL: define {{.*}} @_ZN7PR202561jIiEENS_4dataEv(
299 // CHECK: call void @llvm.memset
303 data d
; // not value-init
306 // CHECK-LABEL: define {{.*}} @_ZN7PR202561fEv(
312 data d
= {}; // value-init
315 // CHECK-LABEL: define {{.*}} @_ZN7PR202561iEv(
316 // CHECK: call void @llvm.memset
320 // CHECK-LABEL: define {{.*}}@_Z20explicitly_defaultedv
321 int explicitly_defaulted() {
322 struct A
{ A() = default; int n
; };
323 // CHECK: call void @llvm.memset
328 // CHECK-LABEL: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(ptr {{[^,]*}} %this) unnamed_addr
329 // CHECK: call void @llvm.memset.p0.i64
330 // CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev
331 // CHECK-NEXT: ret void
333 #if __cplusplus >= 201103L
334 namespace transparent_init_list
{
335 struct optional_assign_base
{};
336 struct optional_data_dtor_base
{ char dummy_
[24]; };
337 struct optional
: optional_data_dtor_base
, optional_assign_base
{};
338 optional
f(optional a
) { return {optional(a
)}; }