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