1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 %s -emit-llvm -o %t
2f4a2713aSLionel Sambuc // RUN: FileCheck %s < %t
3f4a2713aSLionel Sambuc // RUN: FileCheck -check-prefix=CHECK-PR10720 %s < %t
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc extern "C" int printf(...);
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc struct M {
MM8f4a2713aSLionel Sambuc M() { printf("M()\n"); }
MM9f4a2713aSLionel Sambuc M(int i) { iM = i; printf("M(%d)\n", i); }
10f4a2713aSLionel Sambuc int iM;
MPRM11f4a2713aSLionel Sambuc void MPR() {printf("iM = %d\n", iM); };
12f4a2713aSLionel Sambuc };
13f4a2713aSLionel Sambuc
14f4a2713aSLionel Sambuc struct P {
PP15f4a2713aSLionel Sambuc P() { printf("P()\n"); }
PP16f4a2713aSLionel Sambuc P(int i) { iP = i; printf("P(%d)\n", i); }
17f4a2713aSLionel Sambuc int iP;
PPRP18f4a2713aSLionel Sambuc void PPR() {printf("iP = %d\n", iP); };
19f4a2713aSLionel Sambuc };
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc struct Q {
QQ22f4a2713aSLionel Sambuc Q() { printf("Q()\n"); }
QQ23f4a2713aSLionel Sambuc Q(int i) { iQ = i; printf("Q(%d)\n", i); }
24f4a2713aSLionel Sambuc int iQ;
QPRQ25f4a2713aSLionel Sambuc void QPR() {printf("iQ = %d\n", iQ); };
26f4a2713aSLionel Sambuc };
27f4a2713aSLionel Sambuc
28f4a2713aSLionel Sambuc struct N : M , P, Q {
NN29f4a2713aSLionel Sambuc N() : f1(1.314), P(2000), ld(00.1234+f1), M(1000), Q(3000),
30f4a2713aSLionel Sambuc d1(3.4567), i1(1234), m1(100) { printf("N()\n"); }
31f4a2713aSLionel Sambuc M m1;
32f4a2713aSLionel Sambuc M m2;
33f4a2713aSLionel Sambuc float f1;
34f4a2713aSLionel Sambuc int i1;
35f4a2713aSLionel Sambuc float d1;
PRN36f4a2713aSLionel Sambuc void PR() {
37f4a2713aSLionel Sambuc printf("f1 = %f d1 = %f i1 = %d ld = %f \n", f1,d1,i1, ld);
38f4a2713aSLionel Sambuc MPR();
39f4a2713aSLionel Sambuc PPR();
40f4a2713aSLionel Sambuc QPR();
41f4a2713aSLionel Sambuc printf("iQ = %d\n", iQ);
42f4a2713aSLionel Sambuc printf("iP = %d\n", iP);
43f4a2713aSLionel Sambuc printf("iM = %d\n", iM);
44f4a2713aSLionel Sambuc // FIXME. We don't yet support this syntax.
45f4a2713aSLionel Sambuc // printf("iQ = %d\n", (*this).iQ);
46f4a2713aSLionel Sambuc printf("iQ = %d\n", this->iQ);
47f4a2713aSLionel Sambuc printf("iP = %d\n", this->iP);
48f4a2713aSLionel Sambuc printf("iM = %d\n", this->iM);
49f4a2713aSLionel Sambuc }
50f4a2713aSLionel Sambuc float ld;
51f4a2713aSLionel Sambuc float ff;
52f4a2713aSLionel Sambuc M arr_m[3];
53f4a2713aSLionel Sambuc P arr_p[1][3];
54f4a2713aSLionel Sambuc Q arr_q[2][3][4];
55f4a2713aSLionel Sambuc };
56f4a2713aSLionel Sambuc
main()57f4a2713aSLionel Sambuc int main() {
58f4a2713aSLionel Sambuc M m1;
59f4a2713aSLionel Sambuc
60f4a2713aSLionel Sambuc N n1;
61f4a2713aSLionel Sambuc n1.PR();
62f4a2713aSLionel Sambuc }
63f4a2713aSLionel Sambuc
64f4a2713aSLionel Sambuc // PR5826
65f4a2713aSLionel Sambuc template <class T> struct A {
AA66f4a2713aSLionel Sambuc A() {}
AA67f4a2713aSLionel Sambuc A(int) {}
AA68f4a2713aSLionel Sambuc A(const A&) {}
~AA69f4a2713aSLionel Sambuc ~A() {}
operator intA70f4a2713aSLionel Sambuc operator int() {return 0;}
71f4a2713aSLionel Sambuc };
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_Z1fv()
f()74f4a2713aSLionel Sambuc void f() {
75f4a2713aSLionel Sambuc // CHECK: call void @_ZN1AIsEC1Ei
76f4a2713aSLionel Sambuc A<short> a4 = 97;
77f4a2713aSLionel Sambuc
78f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 17
79f4a2713aSLionel Sambuc int i = 17;
80f4a2713aSLionel Sambuc
81f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN1AIsED1Ev
82f4a2713aSLionel Sambuc // CHECK-NOT: call void @_ZN1AIsED1Ev
83f4a2713aSLionel Sambuc // CHECK: ret void
84f4a2713aSLionel Sambuc }
85f4a2713aSLionel Sambuc
86f4a2713aSLionel Sambuc // Make sure we initialize the vtable pointer if it's required by a
87f4a2713aSLionel Sambuc // base initializer.
88f4a2713aSLionel Sambuc namespace InitVTable {
89f4a2713aSLionel Sambuc struct A { A(int); };
90f4a2713aSLionel Sambuc struct B : A {
91f4a2713aSLionel Sambuc virtual int foo();
92f4a2713aSLionel Sambuc B();
93f4a2713aSLionel Sambuc B(int);
94f4a2713aSLionel Sambuc };
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN10InitVTable1BC2Ev(%"struct.InitVTable::B"* %this) unnamed_addr
97*0a6a1f1dSLionel Sambuc // CHECK: [[T0:%.*]] = bitcast [[B:%.*]]* [[THIS:%.*]] to i32 (...)***
98*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2) to i32 (...)**), i32 (...)*** [[T0]]
99f4a2713aSLionel Sambuc // CHECK: [[VTBL:%.*]] = load i32 ([[B]]*)*** {{%.*}}
100f4a2713aSLionel Sambuc // CHECK-NEXT: [[FNP:%.*]] = getelementptr inbounds i32 ([[B]]*)** [[VTBL]], i64 0
101f4a2713aSLionel Sambuc // CHECK-NEXT: [[FN:%.*]] = load i32 ([[B]]*)** [[FNP]]
102f4a2713aSLionel Sambuc // CHECK-NEXT: [[ARG:%.*]] = call i32 [[FN]]([[B]]* [[THIS]])
103f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei({{.*}}* {{%.*}}, i32 [[ARG]])
104*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* [[THIS]] to i32 (...)***
105*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2) to i32 (...)**), i32 (...)*** [[T0]]
106f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
B()107f4a2713aSLionel Sambuc B::B() : A(foo()) {}
108f4a2713aSLionel Sambuc
109f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN10InitVTable1BC2Ei(%"struct.InitVTable::B"* %this, i32 %x) unnamed_addr
110f4a2713aSLionel Sambuc // CHECK: [[ARG:%.*]] = add nsw i32 {{%.*}}, 5
111f4a2713aSLionel Sambuc // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei({{.*}}* {{%.*}}, i32 [[ARG]])
112*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[T0:%.*]] = bitcast [[B]]* {{%.*}} to i32 (...)***
113*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ([3 x i8*]* @_ZTVN10InitVTable1BE, i64 0, i64 2) to i32 (...)**), i32 (...)*** [[T0]]
114f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
B(int x)115f4a2713aSLionel Sambuc B::B(int x) : A(x + 5) {}
116f4a2713aSLionel Sambuc }
117f4a2713aSLionel Sambuc
118f4a2713aSLionel Sambuc namespace rdar9694300 {
119f4a2713aSLionel Sambuc struct X {
120f4a2713aSLionel Sambuc int x;
121f4a2713aSLionel Sambuc };
122f4a2713aSLionel Sambuc
123f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN11rdar96943001fEv
f()124f4a2713aSLionel Sambuc void f() {
125f4a2713aSLionel Sambuc // CHECK: alloca
126f4a2713aSLionel Sambuc X x;
127f4a2713aSLionel Sambuc // CHECK-NEXT: [[I:%.*]] = alloca i32
128f4a2713aSLionel Sambuc // CHECK-NEXT: store i32 17, i32* [[I]]
129f4a2713aSLionel Sambuc int i = 17;
130f4a2713aSLionel Sambuc // CHECK-NEXT: ret void
131f4a2713aSLionel Sambuc }
132f4a2713aSLionel Sambuc }
133f4a2713aSLionel Sambuc
134f4a2713aSLionel Sambuc // Check that we emit a zero initialization step for list-value-initialization
135f4a2713aSLionel Sambuc // which calls a trivial default constructor.
136f4a2713aSLionel Sambuc namespace PR13273 {
137f4a2713aSLionel Sambuc struct U {
138f4a2713aSLionel Sambuc int t;
139f4a2713aSLionel Sambuc U() = default;
140f4a2713aSLionel Sambuc };
141f4a2713aSLionel Sambuc
142f4a2713aSLionel Sambuc struct S : U {
143f4a2713aSLionel Sambuc S() = default;
144f4a2713aSLionel Sambuc };
145f4a2713aSLionel Sambuc
146f4a2713aSLionel Sambuc // CHECK: define {{.*}}@_ZN7PR132731fEv(
f()147f4a2713aSLionel Sambuc int f() {
148f4a2713aSLionel Sambuc // CHECK-NOT: }
149f4a2713aSLionel Sambuc // CHECK: llvm.memset{{.*}}i8 0
150f4a2713aSLionel Sambuc return (new S{})->t;
151f4a2713aSLionel Sambuc }
152f4a2713aSLionel Sambuc }
153f4a2713aSLionel Sambuc
154f4a2713aSLionel Sambuc template<typename T>
155f4a2713aSLionel Sambuc struct X {
156f4a2713aSLionel Sambuc X(const X &);
157f4a2713aSLionel Sambuc
158f4a2713aSLionel Sambuc T *start;
159f4a2713aSLionel Sambuc T *end;
160f4a2713aSLionel Sambuc };
161f4a2713aSLionel Sambuc
162f4a2713aSLionel Sambuc template<typename T> struct X;
163f4a2713aSLionel Sambuc
164f4a2713aSLionel Sambuc // Make sure that the instantiated constructor initializes start and
165f4a2713aSLionel Sambuc // end properly.
166*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(%struct.X* %this, %struct.X* dereferenceable({{[0-9]+}}) %other) unnamed_addr
167f4a2713aSLionel Sambuc // CHECK: {{store.*null}}
168f4a2713aSLionel Sambuc // CHECK: {{store.*null}}
169f4a2713aSLionel Sambuc // CHECK: ret
170f4a2713aSLionel Sambuc template<typename T>
X(const X & other)171f4a2713aSLionel Sambuc X<T>::X(const X &other) : start(0), end(0) { }
172f4a2713aSLionel Sambuc
get_X(X<int> x)173f4a2713aSLionel Sambuc X<int> get_X(X<int> x) { return x; }
174f4a2713aSLionel Sambuc
175f4a2713aSLionel Sambuc namespace PR10720 {
176f4a2713aSLionel Sambuc struct X {
177f4a2713aSLionel Sambuc X(const X&);
178f4a2713aSLionel Sambuc X(X&&);
179f4a2713aSLionel Sambuc X& operator=(const X&);
180f4a2713aSLionel Sambuc X& operator=(X&&);
181f4a2713aSLionel Sambuc ~X();
182f4a2713aSLionel Sambuc };
183f4a2713aSLionel Sambuc
184f4a2713aSLionel Sambuc struct pair2 {
185f4a2713aSLionel Sambuc X second[4];
186f4a2713aSLionel Sambuc
187f4a2713aSLionel Sambuc // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSERKS0_
188f4a2713aSLionel Sambuc // CHECK-PR10720: load
189f4a2713aSLionel Sambuc // CHECK-PR10720: icmp ne
190f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br i1
191f4a2713aSLionel Sambuc // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSERKS0_
192f4a2713aSLionel Sambuc // CHECK-PR10720: ret
193f4a2713aSLionel Sambuc pair2 &operator=(const pair2&) = default;
194f4a2713aSLionel Sambuc
195f4a2713aSLionel Sambuc // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSEOS0_
196f4a2713aSLionel Sambuc // CHECK-PR10720: load
197f4a2713aSLionel Sambuc // CHECK-PR10720: icmp ne
198f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br i1
199f4a2713aSLionel Sambuc // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSEOS0_
200f4a2713aSLionel Sambuc // CHECK-PR10720: ret
201f4a2713aSLionel Sambuc pair2 &operator=(pair2&&) = default;
202f4a2713aSLionel Sambuc
203f4a2713aSLionel Sambuc // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2EOS0_
204f4a2713aSLionel Sambuc // CHECK-PR10720-NOT: ret
205f4a2713aSLionel Sambuc // CHECK-PR10720: load
206f4a2713aSLionel Sambuc // CHECK-PR10720: icmp ult
207f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br i1
208f4a2713aSLionel Sambuc // CHECK-PR10720: call void @_ZN7PR107201XC1EOS0_
209f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br label
210f4a2713aSLionel Sambuc // CHECK-PR10720: ret void
211f4a2713aSLionel Sambuc pair2(pair2&&) = default;
212f4a2713aSLionel Sambuc
213f4a2713aSLionel Sambuc // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2ERKS0_
214f4a2713aSLionel Sambuc // CHECK-PR10720-NOT: ret
215f4a2713aSLionel Sambuc // CHECK-PR10720: load
216f4a2713aSLionel Sambuc // CHECK-PR10720: icmp ult
217f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br i1
218f4a2713aSLionel Sambuc // CHECK-PR10720: call void @_ZN7PR107201XC1ERKS0_
219f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: br label
220f4a2713aSLionel Sambuc // CHECK-PR10720: ret void
221f4a2713aSLionel Sambuc pair2(const pair2&) = default;
222f4a2713aSLionel Sambuc };
223f4a2713aSLionel Sambuc
224f4a2713aSLionel Sambuc struct pair : X { // Make the copy constructor non-trivial, so we actually generate it.
225f4a2713aSLionel Sambuc int second[4];
226f4a2713aSLionel Sambuc // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107204pairC2ERKS0_
227f4a2713aSLionel Sambuc // CHECK-PR10720-NOT: ret
228f4a2713aSLionel Sambuc // CHECK-PR10720: call void @llvm.memcpy
229f4a2713aSLionel Sambuc // CHECK-PR10720-NEXT: ret void
230f4a2713aSLionel Sambuc pair(const pair&) = default;
231f4a2713aSLionel Sambuc };
232f4a2713aSLionel Sambuc
foo(const pair & x,const pair2 & x2)233f4a2713aSLionel Sambuc void foo(const pair &x, const pair2 &x2) {
234f4a2713aSLionel Sambuc pair y(x);
235f4a2713aSLionel Sambuc pair2 y2(x2);
236f4a2713aSLionel Sambuc pair2 y2m(static_cast<pair2&&>(y2));
237f4a2713aSLionel Sambuc
238f4a2713aSLionel Sambuc y2 = x2;
239f4a2713aSLionel Sambuc y2m = static_cast<pair2&&>(y2);
240f4a2713aSLionel Sambuc }
241f4a2713aSLionel Sambuc
242f4a2713aSLionel Sambuc }
243