blob: 5ecaacb16a9e6ef8dc44986c4ea61e846c166c72 [file] [log] [blame]
Anders Carlssond63fed42010-03-24 00:41:37 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2
3namespace Test1 {
4
5// Check that we emit a non-virtual thunk for C::f.
6
7struct A {
8 virtual void f();
9};
10
11struct B {
12 virtual void f();
13};
14
15struct C : A, B {
16 virtual void c();
17
18 virtual void f();
19};
20
Anders Carlssonada087c2010-03-27 20:50:27 +000021// CHECK: define void @_ZThn8_N5Test11C1fEv(
Anders Carlssond63fed42010-03-24 00:41:37 +000022void C::f() { }
23
24}
25
26namespace Test2 {
27
28// Check that we emit a thunk for B::f since it's overriding a virtual base.
29
30struct A {
31 virtual void f();
32};
33
34struct B : virtual A {
35 virtual void b();
36 virtual void f();
37};
38
Anders Carlssonada087c2010-03-27 20:50:27 +000039// CHECK: define void @_ZTv0_n24_N5Test21B1fEv(
Anders Carlssond63fed42010-03-24 00:41:37 +000040void B::f() { }
41
42}
43
44namespace Test3 {
45
46// Check that we emit a covariant thunk for B::f.
47
48struct V1 { };
49struct V2 : virtual V1 { };
50
51struct A {
52 virtual V1 *f();
53};
54
55struct B : A {
56 virtual void b();
57
58 virtual V2 *f();
59};
60
Anders Carlssonada087c2010-03-27 20:50:27 +000061// CHECK: define %{{.*}}* @_ZTch0_v0_n24_N5Test31B1fEv(
Anders Carlssond63fed42010-03-24 00:41:37 +000062V2 *B::f() { return 0; }
63
64}
65
66namespace Test4 {
67
68// Check that the thunk for 'C::f' has the same visibility as the function itself.
69
70struct A {
71 virtual void f();
72};
73
74struct B {
75 virtual void f();
76};
77
78struct __attribute__((visibility("protected"))) C : A, B {
79 virtual void c();
80
81 virtual void f();
82};
83
Anders Carlssonada087c2010-03-27 20:50:27 +000084// CHECK: define protected void @_ZThn8_N5Test41C1fEv(
Anders Carlssond63fed42010-03-24 00:41:37 +000085void C::f() { }
86
87}
88
89// Check that the thunk gets internal linkage.
90namespace {
91
92struct A {
93 virtual void f();
94};
95
96struct B {
97 virtual void f();
98};
99
100struct C : A, B {
101 virtual void c();
102
103 virtual void f();
104};
105
Anders Carlssond63fed42010-03-24 00:41:37 +0000106void C::f() { }
107
108}
109
110// Force C::f to be used.
111void f() {
112 C c;
113
114 c.f();
115}
Anders Carlssonada087c2010-03-27 20:50:27 +0000116
117namespace Test5 {
118
119// Check that the thunk for 'B::f' gets the same linkage as the function itself.
120struct A {
121 virtual void f();
122};
123
124struct B : virtual A {
125 virtual void f() { }
126};
127
128void f(B b) {
129 b.f();
130}
131}
132
Douglas Gregorcb359df2010-05-20 05:54:35 +0000133namespace Test6 {
134 struct X {
135 X();
136 X(const X&);
137 X &operator=(const X&);
138 ~X();
139 };
Anders Carlssonada087c2010-03-27 20:50:27 +0000140
Douglas Gregorcb359df2010-05-20 05:54:35 +0000141 struct P {
142 P();
143 P(const P&);
144 ~P();
145 X first;
146 X second;
147 };
148
149 P getP();
150
151 struct Base1 {
152 int i;
153
154 virtual X f() { return X(); }
155 };
156
157 struct Base2 {
158 float real;
159
160 virtual X f() { return X(); }
161 };
162
163 struct Thunks : Base1, Base2 {
164 long l;
165
166 virtual X f();
167 };
168
169 // CHECK: define void @_ZThn16_N5Test66Thunks1fEv
170 // CHECK-NOT: memcpy
171 // CHECK: {{call void @_ZN5Test66Thunks1fEv.*sret}}
172 // CHECK: ret void
173 X Thunks::f() { return X(); }
174}
175
Douglas Gregor663218b2010-05-21 17:55:12 +0000176namespace Test7 {
177 // PR7188
178 struct X {
179 X();
180 X(const X&);
181 X &operator=(const X&);
182 ~X();
183 };
184
185 struct Small { short s; };
186 struct Large {
187 char array[1024];
188 };
189
190 class A {
191 protected:
192 virtual void foo() = 0;
193 };
194
195 class B : public A {
196 protected:
197 virtual void bar() = 0;
198 };
199
200 class C : public A {
201 protected:
202 virtual void baz(X, X&, _Complex float, Small, Small&, Large) = 0;
203 };
204
205 class D : public B,
206 public C {
207
208 void foo() {}
209 void bar() {}
210 void baz(X, X&, _Complex float, Small, Small&, Large);
211 };
212
213 void D::baz(X, X&, _Complex float, Small, Small&, Large) { }
214
215 // CHECK: define void @_ZThn8_N5Test71D3bazENS_1XERS1_CfNS_5SmallERS4_NS_5LargeE(
216 // CHECK-NOT: memcpy
217 // CHECK: ret void
218 void testD() { D d; }
219}
220
John McCall27360712010-05-26 22:34:26 +0000221namespace Test8 {
222 struct NonPOD { ~NonPOD(); int x, y, z; };
223 struct A { virtual void foo(); };
224 struct B { virtual void bar(NonPOD); };
225 struct C : A, B { virtual void bar(NonPOD); static void helper(NonPOD); };
226
227 // CHECK: define void @_ZN5Test81C6helperENS_6NonPODE([[NONPODTYPE:%.*]]*
228 void C::helper(NonPOD var) {}
229
230 // CHECK: define void @_ZThn8_N5Test81C3barENS_6NonPODE(
231 // CHECK-NOT: load [[NONPODTYPE]]*
232 // CHECK-NOT: memcpy
233 // CHECK: ret void
234 void C::bar(NonPOD var) {}
235}
236
John McCalle2132352010-06-02 21:22:02 +0000237// PR7241: Emitting thunks for a method shouldn't require the vtable for
238// that class to be emitted.
239namespace Test9 {
240 struct A { virtual ~A() { } };
241 struct B : A { virtual void test() const {} };
242 struct C : B { C(); ~C(); };
243 struct D : C { D() {} };
244 void test() {
245 D d;
246 }
247}
248
John McCall65005532010-08-04 23:46:35 +0000249namespace Test10 {
250 struct A { virtual void foo(); };
251 struct B { virtual void foo(); };
252 struct C : A, B { void foo() {} };
253
254 // CHECK: define linkonce_odr void @_ZN6Test101C3fooEv
255 // CHECK: define linkonce_odr hidden void @_ZThn8_N6Test101C3fooEv
256
257 void test() {
258 C c;
259 }
260}
261
John McCall27360712010-05-26 22:34:26 +0000262/**** The following has to go at the end of the file ****/
263
Douglas Gregorcb359df2010-05-20 05:54:35 +0000264// This is from Test5:
John McCall65005532010-08-04 23:46:35 +0000265// CHECK: define linkonce_odr hidden void @_ZTv0_n24_N5Test51B1fEv
Douglas Gregorcb359df2010-05-20 05:54:35 +0000266// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(