1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=HIDDEN %s
6 // Check that we emit a non-virtual thunk for C::f.
22 // CHECK: define void @_ZThn8_N5Test11C1fEv(
29 // Check that we emit a thunk for B::f since it's overriding a virtual base.
35 struct B : virtual A {
40 // CHECK: define void @_ZTv0_n24_N5Test21B1fEv(
47 // Check that we emit a covariant thunk for B::f.
50 struct V2 : virtual V1 { };
62 // CHECK: define %{{.*}}* @_ZTch0_v0_n24_N5Test31B1fEv(
63 V2 *B::f() { return 0; }
69 // Check that the thunk for 'C::f' has the same visibility as the function itself.
79 struct __attribute__((visibility("protected"))) C : A, B {
85 // CHECK: define protected void @_ZThn8_N5Test41C1fEv(
90 // Check that the thunk gets internal linkage.
109 // Force C::f to be used.
118 // Check that the thunk for 'B::f' gets the same linkage as the function itself.
123 struct B : virtual A {
136 X &operator=(const X&);
153 virtual X f() { return X(); }
159 virtual X f() { return X(); }
162 struct Thunks : Base1, Base2 {
168 // CHECK: define void @_ZThn16_N5Test66Thunks1fEv
170 // CHECK: {{call void @_ZN5Test66Thunks1fEv.*sret}}
172 X Thunks::f() { return X(); }
180 X &operator=(const X&);
184 struct Small { short s; };
191 virtual void foo() = 0;
196 virtual void bar() = 0;
201 virtual void baz(X, X&, _Complex float, Small, Small&, Large) = 0;
209 void baz(X, X&, _Complex float, Small, Small&, Large);
212 void D::baz(X, X&, _Complex float, Small, Small&, Large) { }
214 // CHECK: define void @_ZThn8_N5Test71D3bazENS_1XERS1_CfNS_5SmallERS4_NS_5LargeE(
217 void testD() { D d; }
221 struct NonPOD { ~NonPOD(); int x, y, z; };
222 struct A { virtual void foo(); };
223 struct B { virtual void bar(NonPOD); };
224 struct C : A, B { virtual void bar(NonPOD); static void helper(NonPOD); };
226 // CHECK: define void @_ZN5Test81C6helperENS_6NonPODE([[NONPODTYPE:%.*]]*
227 void C::helper(NonPOD var) {}
229 // CHECK: define void @_ZThn8_N5Test81C3barENS_6NonPODE(
230 // CHECK-NOT: load [[NONPODTYPE]]*
233 void C::bar(NonPOD var) {}
236 // PR7241: Emitting thunks for a method shouldn't require the vtable for
237 // that class to be emitted.
239 struct A { virtual ~A() { } };
240 struct B : A { virtual void test() const {} };
241 struct C : B { C(); ~C(); };
242 struct D : C { D() {} };
249 struct A { virtual void foo(); };
250 struct B { virtual void foo(); };
251 struct C : A, B { void foo() {} };
253 // CHECK-HIDDEN: define linkonce_odr void @_ZN6Test101C3fooEv
254 // CHECK-HIDDEN: define linkonce_odr hidden void @_ZThn8_N6Test101C3fooEv
263 struct A { virtual A* f(); };
264 struct B : virtual A { virtual A* f(); };
265 struct C : B { virtual C* f(); };
266 C* C::f() { return 0; }
269 // CHECK: define {{.*}} @_ZN6Test111C1fEv(
271 // The this-adjustment and return-adjustment thunk required when
272 // C::f appears in a vtable where A is at a nonzero offset from C.
273 // CHECK: define {{.*}} @_ZTcv0_n24_v0_n32_N6Test111C1fEv(
275 // The return-adjustment thunk required when C::f appears in a vtable
276 // where A is at a zero offset from C.
277 // CHECK: define {{.*}} @_ZTch0_v0_n32_N6Test111C1fEv(
280 // Varargs thunk test.
283 virtual A* f(int x, ...);
286 virtual B* f(int x, ...);
290 virtual C* f(int x, ...);
292 C* C::f(int x, ...) { return this; }
295 // CHECK: define {{.*}} @_ZN6Test121C1fEiz
297 // Varargs thunk; check that both the this and covariant adjustments
299 // CHECK: define {{.*}} @_ZTchn8_h8_N6Test121C1fEiz
300 // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
301 // CHECK: getelementptr inbounds i8* {{.*}}, i64 8
304 /**** The following has to go at the end of the file ****/
306 // This is from Test5:
307 // CHECK: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
308 // CHECK: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(