1 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-optzns | FileCheck %s
6 // Check that we emit a non-virtual thunk for C::f.
22 // CHECK-LABEL: 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-LABEL: 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-LABEL: 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-LABEL: 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-LABEL: 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-LABEL: define void @_ZThn8_N5Test81C3barENS_6NonPODE(
230 // CHECK-NOT: load [[NONPODTYPE]], [[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() {} };
261 struct A { virtual A* f(); };
262 struct B : virtual A { virtual A* f(); };
263 struct C : B { virtual C* f(); };
264 C* C::f() { return 0; }
267 // CHECK: define {{.*}} @_ZN6Test111C1fEv(
269 // The this-adjustment and return-adjustment thunk required when
270 // C::f appears in a vtable where A is at a nonzero offset from C.
271 // CHECK: define {{.*}} @_ZTcv0_n24_v0_n32_N6Test111C1fEv(
273 // The return-adjustment thunk required when C::f appears in a vtable
274 // where A is at a zero offset from C.
275 // CHECK: define {{.*}} @_ZTch0_v0_n32_N6Test111C1fEv(
278 // Varargs thunk test.
281 virtual A* f(int x, ...);
284 virtual B* f(int x, ...);
288 virtual C* f(int x, ...);
290 C* C::f(int x, ...) { return this; }
293 // CHECK: define {{.*}} @_ZN6Test121C1fEiz
295 // Varargs thunk; check that both the this and covariant adjustments
297 // CHECK: define {{.*}} @_ZTchn8_h8_N6Test121C1fEiz
298 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -8
299 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 8
310 struct Proxy1 : Pad1, B1 {
313 struct D : virtual Proxy1 {
320 // CHECK: define {{.*}} @_ZTcvn8_n32_v8_n24_N6Test131D4foo1Ev
321 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -8
322 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -32
323 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 -24
324 // CHECK: getelementptr inbounds i8, i8* {{.*}}, i64 8
325 // CHECK: ret %"struct.Test13::D"*
335 class C : public A, public B {
340 // CHECK: define void @_ZThn8_N6Test141C1fEv({{.*}}) unnamed_addr [[NUW:#[0-9]+]]
343 // Varargs non-covariant thunk test.
350 virtual void f(int x, ...);
354 virtual void f(int x, ...);
359 // CHECK: declare void @_ZN6Test151C1fEiz
360 // non-virtual thunk to C::f
361 // CHECK: declare void @_ZThn8_N6Test151C1fEiz
364 /**** The following has to go at the end of the file ****/
366 // This is from Test5:
367 // CHECK-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(
368 // CHECK-LABEL: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
370 // This is from Test10:
371 // CHECK-LABEL: define linkonce_odr void @_ZN6Test101C3fooEv
372 // CHECK-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
374 // CHECK: attributes [[NUW]] = { nounwind uwtable{{.*}} }