1 // RUN: %clang_cc1 -fno-rtti %s -emit-llvm -o %t -triple=i386-pc-win32 -fdump-vtable-layouts 2>&1 | FileCheck --check-prefix=VFTABLES %s
2 // RUN: FileCheck --check-prefix=GLOBALS %s < %t
3 // RUN: FileCheck --check-prefix=CODEGEN %s < %t
7 // Some covariant types.
10 struct C
: A
, B
{ int c
; };
11 struct D
: C
{ int d
; };
12 struct E
: D
{ int e
; };
14 // One base class and two overrides, all with covariant return types.
15 struct H
{ virtual B
*foo(); };
16 struct I
: H
{ virtual C
*foo(); };
17 struct J
: I
{ virtual D
*foo(); J(); };
18 struct K
: J
{ virtual E
*foo(); K(); };
22 // VFTABLES-LABEL: VFTable for 'test1::H' in 'test1::I' in 'test1::J' (3 entries).
23 // VFTABLES-NEXT: 0 | test1::D *test1::J::foo()
24 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::B *'): 4 non-virtual]
25 // VFTABLES-NEXT: 1 | test1::D *test1::J::foo()
26 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::C *'): 0 non-virtual]
27 // VFTABLES-NEXT: 2 | test1::D *test1::J::foo()
29 // GLOBALS-LABEL: @"??_7J@test1@@6B@" = linkonce_odr unnamed_addr constant { [3 x i8*] }
30 // GLOBALS: @"?foo@J@test1@@QAEPAUB@2@XZ"
31 // GLOBALS: @"?foo@J@test1@@QAEPAUC@2@XZ"
32 // GLOBALS: @"?foo@J@test1@@UAEPAUD@2@XZ"
36 // VFTABLES-LABEL: VFTable for 'test1::H' in 'test1::I' in 'test1::J' in 'test1::K' (4 entries).
37 // VFTABLES-NEXT: 0 | test1::E *test1::K::foo()
38 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::B *'): 4 non-virtual]
39 // VFTABLES-NEXT: 1 | test1::E *test1::K::foo()
40 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::C *'): 0 non-virtual]
41 // VFTABLES-NEXT: 2 | test1::E *test1::K::foo()
42 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::D *'): 0 non-virtual]
43 // VFTABLES-NEXT: 3 | test1::E *test1::K::foo()
45 // Only B to C requires adjustment, but we get 3 thunks in K's vftable, two of
47 // GLOBALS-LABEL: @"??_7K@test1@@6B@" = linkonce_odr unnamed_addr constant { [4 x i8*] }
48 // GLOBALS: @"?foo@K@test1@@QAEPAUB@2@XZ"
49 // GLOBALS: @"?foo@K@test1@@QAEPAUC@2@XZ"
50 // GLOBALS: @"?foo@K@test1@@QAEPAUD@2@XZ"
51 // GLOBALS: @"?foo@K@test1@@UAEPAUE@2@XZ"
53 // This thunk has a return adjustment.
54 // CODEGEN-LABEL: define {{.*}} @"?foo@K@test1@@QAEPAUB@2@XZ"
55 // CODEGEN: call {{.*}} @"?foo@K@test1@@UAEPAUE@2@XZ"
56 // CODEGEN: icmp {{.*}}, null
57 // CODEGEN: getelementptr
61 // CODEGEN-LABEL: define {{.*}} @"?foo@K@test1@@QAEPAUC@2@XZ"
62 // CODEGEN: call {{.*}} @"?foo@K@test1@@UAEPAUE@2@XZ"
65 // CODEGEN-LABEL: define {{.*}} @"?foo@K@test1@@QAEPAUD@2@XZ"
66 // CODEGEN: call {{.*}} @"?foo@K@test1@@UAEPAUE@2@XZ"
73 // Covariant types. D* is not trivially convertible to C*.
76 struct C
: B
{ int c
; };
77 struct D
: A
, C
{ int d
; };
78 struct E
: D
{ int e
; };
80 // J's foo will require an adjusting thunk, and K will require a trivial thunk.
81 struct H
{ virtual B
*foo(); };
82 struct I
: H
{ virtual C
*foo(); };
83 struct J
: I
{ virtual D
*foo(); J(); };
84 struct K
: J
{ virtual E
*foo(); K(); };
88 // VFTABLES-LABEL: VFTable for 'test2::H' in 'test2::I' in 'test2::J' (2 entries).
89 // VFTABLES-NEXT: 0 | test2::D *test2::J::foo()
90 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::B *'): 4 non-virtual]
91 // VFTABLES-NEXT: 1 | test2::D *test2::J::foo()
93 // GLOBALS-LABEL: @"??_7J@test2@@6B@" = linkonce_odr unnamed_addr constant { [2 x i8*] }
97 // VFTABLES-LABEL: VFTable for 'test2::H' in 'test2::I' in 'test2::J' in 'test2::K' (3 entries).
98 // VFTABLES-NEXT: 0 | test2::E *test2::K::foo()
99 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::B *'): 4 non-virtual]
100 // VFTABLES-NEXT: 1 | test2::E *test2::K::foo()
101 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::D *'): 0 non-virtual]
102 // VFTABLES-NEXT: 2 | test2::E *test2::K::foo()
104 // GLOBALS-LABEL: @"??_7K@test2@@6B@" = linkonce_odr unnamed_addr constant { [3 x i8*] }
113 struct B
: virtual A
{
117 struct C
: virtual A
, B
{
118 // VFTABLES-LABEL: VFTable for 'pr20479::A' in 'pr20479::B' in 'pr20479::C' (2 entries).
119 // VFTABLES-NEXT: 0 | pr20479::B *pr20479::B::f()
120 // VFTABLES-NEXT: [return adjustment (to type 'struct pr20479::A *'): vbase #1, 0 non-virtual]
121 // VFTABLES-NEXT: 1 | pr20479::B *pr20479::B::f()
127 // GLOBALS-LABEL: @"??_7C@pr20479@@6B@" = linkonce_odr unnamed_addr constant { [2 x i8*] }
128 // GLOBALS: @"?f@B@pr20479@@QAEPAUA@2@XZ"
129 // GLOBALS: @"?f@B@pr20479@@UAEPAU12@XZ"
137 struct B
: virtual A
{
141 struct C
: virtual A
, virtual B
{
142 // VFTABLES-LABEL: VFTable for 'pr21073::A' in 'pr21073::B' in 'pr21073::C' (2 entries).
143 // VFTABLES-NEXT: 0 | pr21073::B *pr21073::B::f()
144 // VFTABLES-NEXT: [return adjustment (to type 'struct pr21073::A *'): vbase #1, 0 non-virtual]
145 // VFTABLES-NEXT: [this adjustment: 8 non-virtual]
146 // VFTABLES-NEXT: 1 | pr21073::B *pr21073::B::f()
147 // VFTABLES-NEXT: [return adjustment (to type 'struct pr21073::B *'): 0 non-virtual]
148 // VFTABLES-NEXT: [this adjustment: 8 non-virtual]
154 // GLOBALS-LABEL: @"??_7C@pr21073@@6B@" = linkonce_odr unnamed_addr constant { [2 x i8*] }
155 // GLOBALS: @"?f@B@pr21073@@WPPPPPPPI@AEPAUA@2@XZ"
156 // GLOBALS: @"?f@B@pr21073@@WPPPPPPPI@AEPAU12@XZ"
159 namespace pr21073_2
{
160 struct A
{ virtual A
*foo(); };
161 struct B
: virtual A
{};
162 struct C
: virtual A
{ virtual C
*foo(); };
163 struct D
: B
, C
{ D(); };
166 // VFTABLES-LABEL: VFTable for 'pr21073_2::A' in 'pr21073_2::C' in 'pr21073_2::D' (2 entries)
167 // VFTABLES-NEXT: 0 | pr21073_2::C *pr21073_2::C::foo()
168 // VFTABLES-NEXT: [return adjustment (to type 'struct pr21073_2::A *'): vbase #1, 0 non-virtual]
169 // VFTABLES-NEXT: 1 | pr21073_2::C *pr21073_2::C::foo()
171 // GLOBALS-LABEL: @"??_7D@pr21073_2@@6B@" = {{.*}} constant { [2 x i8*] }
172 // GLOBALS: @"?foo@C@pr21073_2@@QAEPAUA@2@XZ"
173 // GLOBALS: @"?foo@C@pr21073_2@@UAEPAU12@XZ"
177 struct A
{ virtual A
*fn(); };
178 struct B
: virtual A
{ virtual B
*fn(); };
179 struct X
: virtual B
{};
180 struct Y
: virtual B
{};
182 struct D
: virtual B
, virtual A
, C
{
188 // VFTABLES-LABEL: VFTable for 'test3::A' in 'test3::B' in 'test3::X' in 'test3::C' in 'test3::D' (3 entries).
189 // VFTABLES-NEXT: 0 | test3::D *test3::D::fn()
190 // VFTABLES-NEXT: [return adjustment (to type 'struct test3::A *'): vbase #1, 0 non-virtual]
191 // VFTABLES-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
192 // VFTABLES-NEXT: 1 | test3::D *test3::D::fn()
193 // VFTABLES-NEXT: [return adjustment (to type 'struct test3::B *'): vbase #2, 0 non-virtual]
194 // VFTABLES-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
195 // VFTABLES-NEXT: 2 | test3::D *test3::D::fn()
196 // VFTABLES-NEXT: [return adjustment (to type 'struct test3::D *'): 0 non-virtual]
197 // VFTABLES-NEXT: [this adjustment: vtordisp at -4, 0 non-virtual]
199 // GLOBALS-LABEL: @"??_7D@test3@@6B@" = {{.*}} constant { [3 x i8*] }
200 // GLOBALS: @"?fn@D@test3@@$4PPPPPPPM@A@AEPAUA@2@XZ"
201 // GLOBALS: @"?fn@D@test3@@$4PPPPPPPM@A@AEPAUB@2@XZ"
202 // GLOBALS: @"?fn@D@test3@@$4PPPPPPPM@A@AEPAU12@XZ"
206 // C::f is lives in the vftable inside its virtual B subobject. In the MS ABI,
207 // covariant return type virtual methods extend vftables from virtual bases,
208 // even though that can make it impossible to implement certain diamond
209 // hierarchies correctly.
210 struct A
{ virtual ~A(); };
211 struct B
: A
{ virtual B
*f(); };
212 struct C
: virtual B
{ C
*f(); };
214 // VFTABLES-LABEL: VFTable indices for 'pr34302::C' (2 entries).
215 // VFTABLES-NEXT: -- accessible via vbtable index 1, vfptr at offset 0 --
216 // VFTABLES-NEXT: 0 | pr34302::C::~C() [scalar deleting]
217 // VFTABLES-NEXT: 2 | pr34302::C *pr34302::C::f()