blob: b91ba3239b1e12c649440c47b99fe30dfc42e92b [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
Anders Carlssonada087c2010-03-27 20:50:27 +000089// This is from Test5:
90// CHECK: define linkonce_odr void @_ZTv0_n24_N5Test51B1fEv
91
Anders Carlssond63fed42010-03-24 00:41:37 +000092// Check that the thunk gets internal linkage.
93namespace {
94
95struct A {
96 virtual void f();
97};
98
99struct B {
100 virtual void f();
101};
102
103struct C : A, B {
104 virtual void c();
105
106 virtual void f();
107};
108
109// CHECK: define internal void @_ZThn8_N12_GLOBAL__N_11C1fEv(
110void C::f() { }
111
112}
113
114// Force C::f to be used.
115void f() {
116 C c;
117
118 c.f();
119}
Anders Carlssonada087c2010-03-27 20:50:27 +0000120
121namespace Test5 {
122
123// Check that the thunk for 'B::f' gets the same linkage as the function itself.
124struct A {
125 virtual void f();
126};
127
128struct B : virtual A {
129 virtual void f() { }
130};
131
132void f(B b) {
133 b.f();
134}
135}
136
137