[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / CodeGenCXX / value-init.cpp
blobbdcc20c5d752d71e1c4bed919dfb54cadd58dad8
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
4 struct A {
5 virtual ~A();
6 };
8 struct B : A { };
10 struct C {
11 int i;
12 B b;
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.
19 // PR5800
21 // CHECK: store i32 17
22 // CHECK: call void @llvm.memset.p0i8.i64
23 // CHECK: call void @_ZN1BC1Ev
24 C c = { 17 } ;
25 // CHECK: call void @_ZN1CD1Ev
28 enum enum_type { negative_number = -1, magic_number = 42 };
30 class enum_holder
32 enum_type m_enum;
34 public:
35 enum_holder() : m_enum(magic_number) { }
38 struct enum_holder_and_int
40 enum_holder e;
41 int i;
44 // CHECK: _Z24test_enum_holder_and_intv()
45 void test_enum_holder_and_int() {
46 // CHECK: alloca
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.
55 namespace test1 {
56 struct A {
57 int A::*f;
58 A();
59 A(const A&);
60 A &operator=(const A &);
63 struct B {
64 A base;
67 void foo() {
68 B();
72 namespace ptrmem {
73 struct S {
74 int mem1;
75 int S::*mem2;
78 // CHECK-LABEL: define{{.*}} i32 @_ZN6ptrmem4testEPNS_1SE
79 int test(S *s) {
80 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
81 // CHECK: getelementptr
82 // CHECK: ret
83 return s->*S().mem2;
87 namespace PR9801 {
89 struct Test {
90 Test() : i(10) {}
91 Test(int i) : i(i) {}
92 int i;
93 private:
94 int j;
97 struct Test2 {
98 Test t;
101 struct Test3 : public Test { };
103 // CHECK-LABEL: define{{.*}} void @_ZN6PR98011fEv
104 void f() {
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
114 Test empty[3] = {};
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] = {};
134 namespace zeroinit {
135 struct S { int i; };
137 // CHECK-LABEL: define{{.*}} i32 @_ZN8zeroinit4testEv()
138 int test() {
139 // CHECK: call void @llvm.memset.p0i8.i64
140 // CHECK: ret i32 0
141 return S().i;
144 struct X0 {
145 X0() { }
146 int x;
149 struct X1 : X0 {
150 int x1;
151 void f();
154 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X1Ev
155 void testX0_X1() {
156 // CHECK: call void @llvm.memset.p0i8.i64
157 // CHECK-NEXT: call void @_ZN8zeroinit2X1C1Ev
158 // CHECK-NEXT: call void @_ZN8zeroinit2X11fEv
159 X1().f();
162 template<typename>
163 struct X2 : X0 {
164 int x2;
165 void f();
168 template<typename>
169 struct X3 : X2<int> {
170 X3() : X2<int>() { }
171 int i;
175 // CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X3Ev
176 void testX0_X3() {
177 // CHECK-NOT: call void @llvm.memset
178 // CHECK: call void @_ZN8zeroinit2X3IiEC1Ev
179 // CHECK: call void @_ZN8zeroinit2X2IiE1fEv
180 // CHECK-NEXT: ret void
181 X3<int>().f();
184 // More checks at EOF
187 namespace PR8726 {
188 class C;
189 struct S {
190 const C &c1;
191 int i;
192 const C &c2;
194 void f(const C& c) {
195 S s = {c, 42, c};
200 // rdar://problem/9355931
201 namespace test6 {
202 struct A { A(); A(int); };
204 void test() {
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]]
220 // CHECK-NEXT: br i1
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:%.*]], {{%.*}} ]
227 // Inner loop.
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]]
240 // CHECK: ret void
243 namespace PR11124 {
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(); }
268 namespace PR20256 {
269 struct data { int i; };
271 template<typename T = int>
272 data g() {
273 data d; // not value-init
274 return d;
276 template data g();
277 // CHECK-LABEL: define {{.*}} @_ZN7PR202561gIiEENS_4dataEv(
278 // CHECK-NOT: store
279 // CHECK-NOT: memset
280 // CHECK: }
282 template<typename ...T>
283 data h(T ...t) {
284 data d(t...); // value-init
285 return d;
287 template data h();
288 // CHECK-LABEL: define {{.*}} @_ZN7PR202561hIJEEENS_4dataEDpT_(
289 // CHECK: call void @llvm.memset
290 // CHECK: }
293 template<typename T = int>
294 data j() {
295 data d = {}; // value-init
296 return d;
298 template data j();
299 // CHECK-LABEL: define {{.*}} @_ZN7PR202561jIiEENS_4dataEv(
300 // CHECK: call void @llvm.memset
301 // CHECK: }
303 data f() {
304 data d; // not value-init
305 return d;
307 // CHECK-LABEL: define {{.*}} @_ZN7PR202561fEv(
308 // CHECK-NOT: store
309 // CHECK-NOT: memset
310 // CHECK: }
312 data i() {
313 data d = {}; // value-init
314 return d;
316 // CHECK-LABEL: define {{.*}} @_ZN7PR202561iEv(
317 // CHECK: call void @llvm.memset
318 // CHECK: }
321 // CHECK-LABEL: define {{.*}}@_Z20explicitly_defaultedv
322 int explicitly_defaulted() {
323 struct A { A() = default; int n; };
324 // CHECK: call void @llvm.memset
325 A a = A();
326 return a.n;
327 } // CHECK-LABEL: }
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)}; }
341 #endif