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
5 extern "C" int printf(...);
8 M() { printf("M()\n"); }
9 M(int i
) { iM
= i
; printf("M(%d)\n", i
); }
11 void MPR() {printf("iM = %d\n", iM
); };
15 P() { printf("P()\n"); }
16 P(int i
) { iP
= i
; printf("P(%d)\n", i
); }
18 void PPR() {printf("iP = %d\n", iP
); };
22 Q() { printf("Q()\n"); }
23 Q(int i
) { iQ
= i
; printf("Q(%d)\n", i
); }
25 void QPR() {printf("iQ = %d\n", iQ
); };
29 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"); }
37 printf("f1 = %f d1 = %f i1 = %d ld = %f \n", f1
,d1
,i1
, ld
);
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
);
65 template <class T
> struct A
{
70 operator int() {return 0;}
73 // CHECK-LABEL: define{{.*}} void @_Z1fv()
75 // CHECK: call void @_ZN1AIsEC1Ei
78 // CHECK-NEXT: store i32 17
81 // CHECK-NEXT: call void @_ZN1AIsED1Ev
82 // CHECK-NOT: call void @_ZN1AIsED1Ev
86 // Make sure we initialize the vtable pointer if it's required by a
88 namespace InitVTable
{
96 // CHECK-LABEL: define{{.*}} void @_ZN10InitVTable1BC2Ev(ptr {{[^,]*}} %this) unnamed_addr
97 // CHECK: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, inrange i32 0, i32 2), ptr [[THIS:%.*]],
98 // CHECK: [[VTBL:%.*]] = load ptr, ptr {{%.*}}
99 // CHECK-NEXT: [[FNP:%.*]] = getelementptr inbounds ptr, ptr [[VTBL]], i64 0
100 // CHECK-NEXT: [[FN:%.*]] = load ptr, ptr [[FNP]]
101 // CHECK-NEXT: [[ARG:%.*]] = call noundef i32 [[FN]](ptr {{[^,]*}} [[THIS]])
102 // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei(ptr {{[^,]*}} {{%.*}}, i32 noundef [[ARG]])
103 // CHECK-NEXT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, inrange i32 0, i32 2), ptr [[THIS]]
104 // CHECK-NEXT: ret void
107 // CHECK-LABEL: define{{.*}} void @_ZN10InitVTable1BC2Ei(ptr {{[^,]*}} %this, i32 noundef %x) unnamed_addr
108 // CHECK: [[ARG:%.*]] = add nsw i32 {{%.*}}, 5
109 // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei(ptr {{[^,]*}} {{%.*}}, i32 noundef [[ARG]])
110 // CHECK-NEXT: store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, inrange i32 0, i32 2), ptr {{%.*}}
111 // CHECK-NEXT: ret void
112 B::B(int x
) : A(x
+ 5) {}
115 namespace rdar9694300
{
120 // CHECK-LABEL: define{{.*}} void @_ZN11rdar96943001fEv
124 // CHECK-NEXT: [[I:%.*]] = alloca i32
125 // CHECK-NEXT: store i32 17, ptr [[I]]
127 // CHECK-NEXT: ret void
131 // Check that we emit a zero initialization step for list-value-initialization
132 // which calls a trivial default constructor.
143 // CHECK: define {{.*}}@_ZN7PR132731fEv(
146 // CHECK: llvm.memset{{.*}}i8 0
159 template<typename T
> struct X
;
161 // Make sure that the instantiated constructor initializes start and
163 // CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %other) unnamed_addr
164 // CHECK: {{store.*null}}
165 // CHECK: {{store.*null}}
168 X
<T
>::X(const X
&other
) : start(0), end(0) { }
170 X
<int> get_X(X
<int> x
) { return x
; }
176 X
& operator=(const X
&);
184 // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSERKS0_
185 // CHECK-PR10720: load
186 // CHECK-PR10720: icmp ne
187 // CHECK-PR10720-NEXT: br i1
188 // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSERKS0_
189 // CHECK-PR10720: ret
190 pair2
&operator=(const pair2
&) = default;
192 // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSEOS0_
193 // CHECK-PR10720: load
194 // CHECK-PR10720: icmp ne
195 // CHECK-PR10720-NEXT: br i1
196 // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSEOS0_
197 // CHECK-PR10720: ret
198 pair2
&operator=(pair2
&&) = default;
200 // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107204pairC2ERKS0_
201 // CHECK-PR10720-NOT: ret
202 // CHECK-PR10720: call void @llvm.memcpy
203 // CHECK-PR10720-NEXT: ret void
205 // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2ERKS0_
206 // CHECK-PR10720-NOT: ret
207 // CHECK-PR10720: call void @_ZN7PR107201XC1ERKS0_
208 // CHECK-PR10720: icmp eq
209 // CHECK-PR10720-NEXT: br i1
210 // CHECK-PR10720: ret void
212 // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2EOS0_
213 // CHECK-PR10720-NOT: ret
214 // CHECK-PR10720: load
215 // CHECK-PR10720: call void @_ZN7PR107201XC1EOS0_
216 // CHECK-PR10720: icmp eq
217 // CHECK-PR10720-NEXT: br i1
218 // CHECK-PR10720: ret void
219 pair2(pair2
&&) = default;
221 pair2(const pair2
&) = default;
224 struct pair
: X
{ // Make the copy constructor non-trivial, so we actually generate it.
226 pair(const pair
&) = default;
229 void foo(const pair
&x
, const pair2
&x2
) {
232 pair2
y2m(static_cast<pair2
&&>(y2
));
235 y2m
= static_cast<pair2
&&>(y2
);