Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm-only -fdump-vtable-layouts > %t 2>&1 |
| 2 | // RUN: FileCheck --check-prefix=CHECK-1 %s < %t |
| 3 | // RUN: FileCheck --check-prefix=CHECK-2 %s < %t |
| 4 | // RUN: FileCheck --check-prefix=CHECK-3 %s < %t |
| 5 | // RUN: FileCheck --check-prefix=CHECK-4 %s < %t |
| 6 | // RUN: FileCheck --check-prefix=CHECK-5 %s < %t |
| 7 | // RUN: FileCheck --check-prefix=CHECK-6 %s < %t |
| 8 | // RUN: FileCheck --check-prefix=CHECK-7 %s < %t |
| 9 | // RUN: FileCheck --check-prefix=CHECK-8 %s < %t |
| 10 | // RUN: FileCheck --check-prefix=CHECK-9 %s < %t |
| 11 | // RUN: FileCheck --check-prefix=CHECK-10 %s < %t |
| 12 | // RUN: FileCheck --check-prefix=CHECK-11 %s < %t |
| 13 | // RUN: FileCheck --check-prefix=CHECK-12 %s < %t |
| 14 | // RUN: FileCheck --check-prefix=CHECK-13 %s < %t |
| 15 | // RUN: FileCheck --check-prefix=CHECK-14 %s < %t |
| 16 | // RUN: FileCheck --check-prefix=CHECK-15 %s < %t |
| 17 | // RUN: FileCheck --check-prefix=CHECK-16 %s < %t |
| 18 | // RUN: FileCheck --check-prefix=CHECK-17 %s < %t |
| 19 | // RUN: FileCheck --check-prefix=CHECK-18 %s < %t |
| 20 | // RUN: FileCheck --check-prefix=CHECK-19 %s < %t |
| 21 | // RUN: FileCheck --check-prefix=CHECK-20 %s < %t |
| 22 | // RUN: FileCheck --check-prefix=CHECK-21 %s < %t |
| 23 | // RUN: FileCheck --check-prefix=CHECK-22 %s < %t |
| 24 | // RUN: FileCheck --check-prefix=CHECK-23 %s < %t |
| 25 | // RUN: FileCheck --check-prefix=CHECK-24 %s < %t |
| 26 | // RUN: FileCheck --check-prefix=CHECK-25 %s < %t |
| 27 | // RUN: FileCheck --check-prefix=CHECK-26 %s < %t |
| 28 | // RUN: FileCheck --check-prefix=CHECK-27 %s < %t |
| 29 | // RUN: FileCheck --check-prefix=CHECK-28 %s < %t |
| 30 | // RUN: FileCheck --check-prefix=CHECK-29 %s < %t |
| 31 | // RUN: FileCheck --check-prefix=CHECK-30 %s < %t |
| 32 | // RUN: FileCheck --check-prefix=CHECK-31 %s < %t |
| 33 | // RUN: FileCheck --check-prefix=CHECK-32 %s < %t |
| 34 | // RUN: FileCheck --check-prefix=CHECK-33 %s < %t |
| 35 | // RUN: FileCheck --check-prefix=CHECK-34 %s < %t |
| 36 | // RUN: FileCheck --check-prefix=CHECK-35 %s < %t |
| 37 | // RUN: FileCheck --check-prefix=CHECK-36 %s < %t |
| 38 | // RUN: FileCheck --check-prefix=CHECK-37 %s < %t |
| 39 | // RUN: FileCheck --check-prefix=CHECK-38 %s < %t |
| 40 | // RUN: FileCheck --check-prefix=CHECK-39 %s < %t |
| 41 | // RUN: FileCheck --check-prefix=CHECK-40 %s < %t |
| 42 | // RUN: FileCheck --check-prefix=CHECK-41 %s < %t |
| 43 | // RUN: FileCheck --check-prefix=CHECK-42 %s < %t |
Anders Carlsson | b8bced0 | 2011-04-10 18:00:32 +0000 | [diff] [blame^] | 44 | // RUN: FileCheck --check-prefix=CHECK-43 %s < %t |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 45 | |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 46 | // For now, just verify this doesn't crash. |
| 47 | namespace test0 { |
| 48 | struct Obj {}; |
| 49 | |
| 50 | struct Base { virtual const Obj *foo() = 0; }; |
| 51 | struct Derived : Base { virtual Obj *foo() { return new Obj(); } }; |
| 52 | |
| 53 | void test(Derived *D) { D->foo(); } |
| 54 | } |
| 55 | |
| 56 | namespace Test1 { |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 57 | // CHECK-1: Vtable for 'Test1::A' (3 entries). |
| 58 | // CHECK-1-NEXT: 0 | offset_to_top (0) |
| 59 | // CHECK-1-NEXT: 1 | Test1::A RTTI |
| 60 | // CHECK-1-NEXT: -- (Test1::A, 0) vtable address -- |
| 61 | // CHECK-1-NEXT: 2 | void Test1::A::f() |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 62 | struct A { |
| 63 | virtual void f(); |
| 64 | }; |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 65 | void A::f() { } |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 66 | |
Anders Carlsson | 824d7ea | 2010-02-11 08:02:13 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 69 | namespace Test2 { |
| 70 | |
| 71 | // This is a smoke test of the vtable dumper. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 72 | // CHECK-2: Vtable for 'Test2::A' (9 entries). |
| 73 | // CHECK-2-NEXT: 0 | offset_to_top (0) |
| 74 | // CHECK-2-NEXT: 1 | Test2::A RTTI |
| 75 | // CHECK-2-NEXT: -- (Test2::A, 0) vtable address -- |
| 76 | // CHECK-2-NEXT: 2 | void Test2::A::f() |
| 77 | // CHECK-2-NEXT: 3 | void Test2::A::f() const |
| 78 | // CHECK-2-NEXT: 4 | Test2::A *Test2::A::g(int) |
| 79 | // CHECK-2-NEXT: 5 | Test2::A::~A() [complete] |
| 80 | // CHECK-2-NEXT: 6 | Test2::A::~A() [deleting] |
| 81 | // CHECK-2-NEXT: 7 | void Test2::A::h() |
Chris Lattner | 0c42bb6 | 2010-09-05 00:17:29 +0000 | [diff] [blame] | 82 | // CHECK-2-NEXT: 8 | Test2::A &Test2::A::operator=(const Test2::A &) |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 83 | struct A { |
| 84 | virtual void f(); |
| 85 | virtual void f() const; |
| 86 | |
| 87 | virtual A* g(int a); |
| 88 | virtual ~A(); |
| 89 | virtual void h(); |
Anders Carlsson | bac7271 | 2010-02-11 18:21:49 +0000 | [diff] [blame] | 90 | virtual A& operator=(const A&); |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 91 | }; |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 92 | void A::f() { } |
| 93 | |
Anders Carlsson | 9824142 | 2010-02-12 02:38:13 +0000 | [diff] [blame] | 94 | // Another simple vtable dumper test. |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 95 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 96 | // CHECK-3: Vtable for 'Test2::B' (6 entries). |
| 97 | // CHECK-3-NEXT: 0 | offset_to_top (0) |
| 98 | // CHECK-3-NEXT: 1 | Test2::B RTTI |
| 99 | // CHECK-3-NEXT: -- (Test2::B, 0) vtable address -- |
| 100 | // CHECK-3-NEXT: 2 | void Test2::B::f() |
| 101 | // CHECK-3-NEXT: 3 | void Test2::B::g() [pure] |
| 102 | // CHECK-3-NEXT: 4 | Test2::B::~B() [complete] [pure] |
| 103 | // CHECK-3-NEXT: 5 | Test2::B::~B() [deleting] [pure] |
Anders Carlsson | 9824142 | 2010-02-12 02:38:13 +0000 | [diff] [blame] | 104 | struct B { |
| 105 | virtual void f(); |
| 106 | virtual void g() = 0; |
| 107 | virtual ~B() = 0; |
| 108 | }; |
Anders Carlsson | 9824142 | 2010-02-12 02:38:13 +0000 | [diff] [blame] | 109 | void B::f() { } |
| 110 | |
Anders Carlsson | 848fa64 | 2010-02-11 18:20:28 +0000 | [diff] [blame] | 111 | } |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 112 | |
| 113 | namespace Test3 { |
| 114 | |
| 115 | // If a function in a derived class overrides a function in a primary base, |
| 116 | // then the function should not have an entry in the derived class (unless the return |
| 117 | // value requires adjusting). |
| 118 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 119 | // CHECK-4: Vtable for 'Test3::A' (3 entries). |
| 120 | // CHECK-4-NEXT: 0 | offset_to_top (0) |
| 121 | // CHECK-4-NEXT: 1 | Test3::A RTTI |
| 122 | // CHECK-4-NEXT: -- (Test3::A, 0) vtable address -- |
| 123 | // CHECK-4-NEXT: 2 | void Test3::A::f() |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 124 | struct A { |
| 125 | virtual void f(); |
| 126 | }; |
| 127 | void A::f() { } |
| 128 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 129 | // CHECK-5: Vtable for 'Test3::B' (4 entries). |
| 130 | // CHECK-5-NEXT: 0 | offset_to_top (0) |
| 131 | // CHECK-5-NEXT: 1 | Test3::B RTTI |
| 132 | // CHECK-5-NEXT: -- (Test3::A, 0) vtable address -- |
| 133 | // CHECK-5-NEXT: -- (Test3::B, 0) vtable address -- |
| 134 | // CHECK-5-NEXT: 2 | void Test3::B::f() |
| 135 | // CHECK-5-NEXT: 3 | void Test3::B::g() |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 136 | struct B : A { |
| 137 | virtual void f(); |
| 138 | virtual void g(); |
| 139 | }; |
| 140 | void B::f() { } |
| 141 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 142 | // CHECK-6: Vtable for 'Test3::C' (5 entries). |
| 143 | // CHECK-6-NEXT: 0 | offset_to_top (0) |
| 144 | // CHECK-6-NEXT: 1 | Test3::C RTTI |
| 145 | // CHECK-6-NEXT: -- (Test3::A, 0) vtable address -- |
| 146 | // CHECK-6-NEXT: -- (Test3::C, 0) vtable address -- |
| 147 | // CHECK-6-NEXT: 2 | void Test3::A::f() |
| 148 | // CHECK-6-NEXT: 3 | void Test3::C::g() |
| 149 | // CHECK-6-NEXT: 4 | void Test3::C::h() |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 150 | struct C : A { |
| 151 | virtual void g(); |
| 152 | virtual void h(); |
| 153 | }; |
| 154 | void C::g() { } |
| 155 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 156 | // CHECK-7: Vtable for 'Test3::D' (5 entries). |
| 157 | // CHECK-7-NEXT: 0 | offset_to_top (0) |
| 158 | // CHECK-7-NEXT: 1 | Test3::D RTTI |
| 159 | // CHECK-7-NEXT: -- (Test3::A, 0) vtable address -- |
| 160 | // CHECK-7-NEXT: -- (Test3::B, 0) vtable address -- |
| 161 | // CHECK-7-NEXT: -- (Test3::D, 0) vtable address -- |
| 162 | // CHECK-7-NEXT: 2 | void Test3::D::f() |
| 163 | // CHECK-7-NEXT: 3 | void Test3::D::g() |
| 164 | // CHECK-7-NEXT: 4 | void Test3::D::h() |
Anders Carlsson | 57071e2 | 2010-02-12 05:25:12 +0000 | [diff] [blame] | 165 | struct D : B { |
| 166 | virtual void f(); |
| 167 | virtual void g(); |
| 168 | virtual void h(); |
| 169 | }; |
| 170 | |
| 171 | void D::f() { } |
| 172 | } |
John McCall | 9605895 | 2010-02-12 06:15:07 +0000 | [diff] [blame] | 173 | |
Anders Carlsson | 7dbf47a | 2010-02-13 20:11:51 +0000 | [diff] [blame] | 174 | namespace Test4 { |
| 175 | |
Anders Carlsson | 60db0ee | 2010-02-13 21:07:32 +0000 | [diff] [blame] | 176 | // Test non-virtual result adjustments. |
Anders Carlsson | 7dbf47a | 2010-02-13 20:11:51 +0000 | [diff] [blame] | 177 | |
| 178 | struct R1 { int r1; }; |
| 179 | struct R2 { int r2; }; |
| 180 | struct R3 : R1, R2 { int r3; }; |
| 181 | |
| 182 | struct A { |
| 183 | virtual R2 *f(); |
| 184 | }; |
| 185 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 186 | // CHECK-8: Vtable for 'Test4::B' (4 entries). |
| 187 | // CHECK-8-NEXT: 0 | offset_to_top (0) |
| 188 | // CHECK-8-NEXT: 1 | Test4::B RTTI |
| 189 | // CHECK-8-NEXT: -- (Test4::A, 0) vtable address -- |
| 190 | // CHECK-8-NEXT: -- (Test4::B, 0) vtable address -- |
| 191 | // CHECK-8-NEXT: 2 | Test4::R3 *Test4::B::f() |
| 192 | // CHECK-8-NEXT: [return adjustment: 4 non-virtual] |
| 193 | // CHECK-8-NEXT: 3 | Test4::R3 *Test4::B::f() |
Anders Carlsson | 7dbf47a | 2010-02-13 20:11:51 +0000 | [diff] [blame] | 194 | |
| 195 | struct B : A { |
| 196 | virtual R3 *f(); |
| 197 | }; |
Anders Carlsson | 7dbf47a | 2010-02-13 20:11:51 +0000 | [diff] [blame] | 198 | R3 *B::f() { return 0; } |
Anders Carlsson | 60db0ee | 2010-02-13 21:07:32 +0000 | [diff] [blame] | 199 | |
| 200 | // Test virtual result adjustments. |
| 201 | struct V1 { int v1; }; |
| 202 | struct V2 : virtual V1 { int v1; }; |
| 203 | |
| 204 | struct C { |
| 205 | virtual V1 *f(); |
| 206 | }; |
| 207 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 208 | // CHECK-9: Vtable for 'Test4::D' (4 entries). |
| 209 | // CHECK-9-NEXT: 0 | offset_to_top (0) |
| 210 | // CHECK-9-NEXT: 1 | Test4::D RTTI |
| 211 | // CHECK-9-NEXT: -- (Test4::C, 0) vtable address -- |
| 212 | // CHECK-9-NEXT: -- (Test4::D, 0) vtable address -- |
| 213 | // CHECK-9-NEXT: 2 | Test4::V2 *Test4::D::f() |
| 214 | // CHECK-9-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset] |
| 215 | // CHECK-9-NEXT: 3 | Test4::V2 *Test4::D::f() |
Anders Carlsson | 60db0ee | 2010-02-13 21:07:32 +0000 | [diff] [blame] | 216 | struct D : C { |
| 217 | virtual V2 *f(); |
| 218 | }; |
| 219 | V2 *D::f() { return 0; }; |
| 220 | |
| 221 | // Virtual result adjustments with an additional non-virtual adjustment. |
| 222 | struct V3 : virtual R3 { int r3; }; |
| 223 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 224 | // CHECK-10: Vtable for 'Test4::E' (4 entries). |
| 225 | // CHECK-10-NEXT: 0 | offset_to_top (0) |
| 226 | // CHECK-10-NEXT: 1 | Test4::E RTTI |
| 227 | // CHECK-10-NEXT: -- (Test4::A, 0) vtable address -- |
| 228 | // CHECK-10-NEXT: -- (Test4::E, 0) vtable address -- |
| 229 | // CHECK-10-NEXT: 2 | Test4::V3 *Test4::E::f() |
| 230 | // CHECK-10-NEXT: [return adjustment: 4 non-virtual, -24 vbase offset offset] |
| 231 | // CHECK-10-NEXT: 3 | Test4::V3 *Test4::E::f() |
Anders Carlsson | 60db0ee | 2010-02-13 21:07:32 +0000 | [diff] [blame] | 232 | |
| 233 | struct E : A { |
| 234 | virtual V3 *f(); |
| 235 | }; |
| 236 | V3 *E::f() { return 0;} |
| 237 | |
Anders Carlsson | 1d05be5 | 2010-02-13 21:16:54 +0000 | [diff] [blame] | 238 | // Test that a pure virtual member doesn't get a thunk. |
| 239 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 240 | // CHECK-11: Vtable for 'Test4::F' (5 entries). |
| 241 | // CHECK-11-NEXT: 0 | offset_to_top (0) |
| 242 | // CHECK-11-NEXT: 1 | Test4::F RTTI |
| 243 | // CHECK-11-NEXT: -- (Test4::A, 0) vtable address -- |
| 244 | // CHECK-11-NEXT: -- (Test4::F, 0) vtable address -- |
| 245 | // CHECK-11-NEXT: 2 | Test4::R3 *Test4::F::f() [pure] |
| 246 | // CHECK-11-NEXT: 3 | void Test4::F::g() |
| 247 | // CHECK-11-NEXT: 4 | Test4::R3 *Test4::F::f() [pure] |
Anders Carlsson | 1d05be5 | 2010-02-13 21:16:54 +0000 | [diff] [blame] | 248 | struct F : A { |
| 249 | virtual void g(); |
| 250 | virtual R3 *f() = 0; |
| 251 | }; |
Anders Carlsson | 1d05be5 | 2010-02-13 21:16:54 +0000 | [diff] [blame] | 252 | void F::g() { } |
| 253 | |
Anders Carlsson | 7dbf47a | 2010-02-13 20:11:51 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Anders Carlsson | 76f1aa7 | 2010-02-13 22:05:23 +0000 | [diff] [blame] | 256 | namespace Test5 { |
| 257 | |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 258 | // Simple secondary vtables without 'this' pointer adjustments. |
Anders Carlsson | 76f1aa7 | 2010-02-13 22:05:23 +0000 | [diff] [blame] | 259 | struct A { |
| 260 | virtual void f(); |
| 261 | virtual void g(); |
| 262 | int a; |
| 263 | }; |
| 264 | |
| 265 | struct B1 : A { |
| 266 | virtual void f(); |
| 267 | int b1; |
| 268 | }; |
| 269 | |
| 270 | struct B2 : A { |
| 271 | virtual void g(); |
| 272 | int b2; |
| 273 | }; |
| 274 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 275 | // CHECK-12: Vtable for 'Test5::C' (9 entries). |
| 276 | // CHECK-12-NEXT: 0 | offset_to_top (0) |
| 277 | // CHECK-12-NEXT: 1 | Test5::C RTTI |
| 278 | // CHECK-12-NEXT: -- (Test5::A, 0) vtable address -- |
| 279 | // CHECK-12-NEXT: -- (Test5::B1, 0) vtable address -- |
| 280 | // CHECK-12-NEXT: -- (Test5::C, 0) vtable address -- |
| 281 | // CHECK-12-NEXT: 2 | void Test5::B1::f() |
| 282 | // CHECK-12-NEXT: 3 | void Test5::A::g() |
| 283 | // CHECK-12-NEXT: 4 | void Test5::C::h() |
| 284 | // CHECK-12-NEXT: 5 | offset_to_top (-16) |
| 285 | // CHECK-12-NEXT: 6 | Test5::C RTTI |
| 286 | // CHECK-12-NEXT: -- (Test5::A, 16) vtable address -- |
| 287 | // CHECK-12-NEXT: -- (Test5::B2, 16) vtable address -- |
| 288 | // CHECK-12-NEXT: 7 | void Test5::A::f() |
| 289 | // CHECK-12-NEXT: 8 | void Test5::B2::g() |
Anders Carlsson | 76f1aa7 | 2010-02-13 22:05:23 +0000 | [diff] [blame] | 290 | struct C : B1, B2 { |
| 291 | virtual void h(); |
| 292 | }; |
| 293 | void C::h() { } |
| 294 | } |
| 295 | |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 296 | namespace Test6 { |
John McCall | 9605895 | 2010-02-12 06:15:07 +0000 | [diff] [blame] | 297 | |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 298 | // Simple non-virtual 'this' pointer adjustments. |
| 299 | struct A1 { |
| 300 | virtual void f(); |
| 301 | int a; |
| 302 | }; |
John McCall | 9605895 | 2010-02-12 06:15:07 +0000 | [diff] [blame] | 303 | |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 304 | struct A2 { |
| 305 | virtual void f(); |
| 306 | int a; |
| 307 | }; |
| 308 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 309 | // CHECK-13: Vtable for 'Test6::C' (6 entries). |
| 310 | // CHECK-13-NEXT: 0 | offset_to_top (0) |
| 311 | // CHECK-13-NEXT: 1 | Test6::C RTTI |
| 312 | // CHECK-13-NEXT: -- (Test6::A1, 0) vtable address -- |
| 313 | // CHECK-13-NEXT: -- (Test6::C, 0) vtable address -- |
| 314 | // CHECK-13-NEXT: 2 | void Test6::C::f() |
| 315 | // CHECK-13-NEXT: 3 | offset_to_top (-16) |
| 316 | // CHECK-13-NEXT: 4 | Test6::C RTTI |
| 317 | // CHECK-13-NEXT: -- (Test6::A2, 16) vtable address -- |
| 318 | // CHECK-13-NEXT: 5 | void Test6::C::f() |
| 319 | // CHECK-13-NEXT: [this adjustment: -16 non-virtual] |
Anders Carlsson | 49bac9a | 2010-02-13 23:40:17 +0000 | [diff] [blame] | 320 | struct C : A1, A2 { |
| 321 | virtual void f(); |
| 322 | }; |
| 323 | void C::f() { } |
| 324 | |
Anders Carlsson | e67dc30 | 2010-02-14 00:16:19 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | namespace Test7 { |
| 328 | |
| 329 | // Test that the D::f overrider for A::f have different 'this' pointer |
| 330 | // adjustments in the two A base subobjects. |
| 331 | |
| 332 | struct A { |
| 333 | virtual void f(); |
| 334 | int a; |
| 335 | }; |
| 336 | |
| 337 | struct B1 : A { }; |
| 338 | struct B2 : A { }; |
| 339 | |
| 340 | struct C { virtual void c(); }; |
| 341 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 342 | // CHECK-14: Vtable for 'Test7::D' (10 entries). |
| 343 | // CHECK-14-NEXT: 0 | offset_to_top (0) |
| 344 | // CHECK-14-NEXT: 1 | Test7::D RTTI |
| 345 | // CHECK-14-NEXT: -- (Test7::C, 0) vtable address -- |
| 346 | // CHECK-14-NEXT: -- (Test7::D, 0) vtable address -- |
| 347 | // CHECK-14-NEXT: 2 | void Test7::C::c() |
| 348 | // CHECK-14-NEXT: 3 | void Test7::D::f() |
| 349 | // CHECK-14-NEXT: 4 | offset_to_top (-8) |
| 350 | // CHECK-14-NEXT: 5 | Test7::D RTTI |
| 351 | // CHECK-14-NEXT: -- (Test7::A, 8) vtable address -- |
| 352 | // CHECK-14-NEXT: -- (Test7::B1, 8) vtable address -- |
| 353 | // CHECK-14-NEXT: 6 | void Test7::D::f() |
| 354 | // CHECK-14-NEXT: [this adjustment: -8 non-virtual] |
| 355 | // CHECK-14-NEXT: 7 | offset_to_top (-24) |
| 356 | // CHECK-14-NEXT: 8 | Test7::D RTTI |
| 357 | // CHECK-14-NEXT: -- (Test7::A, 24) vtable address -- |
| 358 | // CHECK-14-NEXT: -- (Test7::B2, 24) vtable address -- |
| 359 | // CHECK-14-NEXT: 9 | void Test7::D::f() |
| 360 | // CHECK-14-NEXT: [this adjustment: -24 non-virtual] |
Anders Carlsson | e67dc30 | 2010-02-14 00:16:19 +0000 | [diff] [blame] | 361 | struct D : C, B1, B2 { |
| 362 | virtual void f(); |
| 363 | }; |
| 364 | void D::f() { } |
| 365 | |
| 366 | } |
Anders Carlsson | b828afa | 2010-02-14 17:05:59 +0000 | [diff] [blame] | 367 | |
| 368 | namespace Test8 { |
| 369 | |
| 370 | // Test that we don't try to layout vtables for classes that don't have |
| 371 | // virtual bases or virtual member functions. |
| 372 | |
| 373 | struct A { }; |
| 374 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 375 | // CHECK-15: Vtable for 'Test8::B' (3 entries). |
| 376 | // CHECK-15-NEXT: 0 | offset_to_top (0) |
| 377 | // CHECK-15-NEXT: 1 | Test8::B RTTI |
| 378 | // CHECK-15-NEXT: -- (Test8::B, 0) vtable address -- |
| 379 | // CHECK-15-NEXT: 2 | void Test8::B::f() |
Anders Carlsson | b828afa | 2010-02-14 17:05:59 +0000 | [diff] [blame] | 380 | struct B : A { |
| 381 | virtual void f(); |
| 382 | }; |
| 383 | void B::f() { } |
| 384 | |
| 385 | } |
Anders Carlsson | 852213e | 2010-02-16 04:59:55 +0000 | [diff] [blame] | 386 | |
| 387 | namespace Test9 { |
| 388 | |
| 389 | // Simple test of vbase offsets. |
| 390 | |
| 391 | struct A1 { int a1; }; |
| 392 | struct A2 { int a2; }; |
| 393 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 394 | // CHECK-16: Vtable for 'Test9::B' (5 entries). |
| 395 | // CHECK-16-NEXT: 0 | vbase_offset (16) |
| 396 | // CHECK-16-NEXT: 1 | vbase_offset (12) |
| 397 | // CHECK-16-NEXT: 2 | offset_to_top (0) |
| 398 | // CHECK-16-NEXT: 3 | Test9::B RTTI |
| 399 | // CHECK-16-NEXT: -- (Test9::B, 0) vtable address -- |
| 400 | // CHECK-16-NEXT: 4 | void Test9::B::f() |
Anders Carlsson | 852213e | 2010-02-16 04:59:55 +0000 | [diff] [blame] | 401 | struct B : virtual A1, virtual A2 { |
| 402 | int b; |
| 403 | |
| 404 | virtual void f(); |
| 405 | }; |
| 406 | |
| 407 | |
| 408 | void B::f() { } |
| 409 | |
| 410 | } |
Anders Carlsson | c7b6316 | 2010-02-16 16:02:57 +0000 | [diff] [blame] | 411 | |
| 412 | namespace Test10 { |
| 413 | |
| 414 | // Test for a bug where we would not emit secondary vtables for bases |
| 415 | // of a primary base. |
| 416 | struct A1 { virtual void a1(); }; |
| 417 | struct A2 { virtual void a2(); }; |
| 418 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 419 | // CHECK-17: Vtable for 'Test10::C' (7 entries). |
| 420 | // CHECK-17-NEXT: 0 | offset_to_top (0) |
| 421 | // CHECK-17-NEXT: 1 | Test10::C RTTI |
| 422 | // CHECK-17-NEXT: -- (Test10::A1, 0) vtable address -- |
| 423 | // CHECK-17-NEXT: -- (Test10::B, 0) vtable address -- |
| 424 | // CHECK-17-NEXT: -- (Test10::C, 0) vtable address -- |
| 425 | // CHECK-17-NEXT: 2 | void Test10::A1::a1() |
| 426 | // CHECK-17-NEXT: 3 | void Test10::C::f() |
| 427 | // CHECK-17-NEXT: 4 | offset_to_top (-8) |
| 428 | // CHECK-17-NEXT: 5 | Test10::C RTTI |
| 429 | // CHECK-17-NEXT: -- (Test10::A2, 8) vtable address -- |
| 430 | // CHECK-17-NEXT: 6 | void Test10::A2::a2() |
Anders Carlsson | c7b6316 | 2010-02-16 16:02:57 +0000 | [diff] [blame] | 431 | struct B : A1, A2 { |
| 432 | int b; |
| 433 | }; |
| 434 | |
| 435 | struct C : B { |
| 436 | virtual void f(); |
| 437 | }; |
| 438 | void C::f() { } |
| 439 | |
| 440 | } |
Anders Carlsson | 69dc04e | 2010-02-16 16:49:35 +0000 | [diff] [blame] | 441 | |
| 442 | namespace Test11 { |
| 443 | |
| 444 | // Very simple test of vtables for virtual bases. |
| 445 | struct A1 { int a; }; |
| 446 | struct A2 { int b; }; |
| 447 | |
| 448 | struct B : A1, virtual A2 { |
| 449 | int b; |
| 450 | }; |
| 451 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 452 | // CHECK-18: Vtable for 'Test11::C' (8 entries). |
| 453 | // CHECK-18-NEXT: 0 | vbase_offset (24) |
| 454 | // CHECK-18-NEXT: 1 | vbase_offset (8) |
| 455 | // CHECK-18-NEXT: 2 | offset_to_top (0) |
| 456 | // CHECK-18-NEXT: 3 | Test11::C RTTI |
| 457 | // CHECK-18-NEXT: -- (Test11::C, 0) vtable address -- |
| 458 | // CHECK-18-NEXT: 4 | void Test11::C::f() |
| 459 | // CHECK-18-NEXT: 5 | vbase_offset (16) |
| 460 | // CHECK-18-NEXT: 6 | offset_to_top (-8) |
| 461 | // CHECK-18-NEXT: 7 | Test11::C RTTI |
Anders Carlsson | 69dc04e | 2010-02-16 16:49:35 +0000 | [diff] [blame] | 462 | struct C : virtual B { |
| 463 | virtual void f(); |
| 464 | }; |
| 465 | void C::f() { } |
| 466 | |
| 467 | } |
Anders Carlsson | 92f5432 | 2010-02-23 03:26:17 +0000 | [diff] [blame] | 468 | |
| 469 | namespace Test12 { |
| 470 | |
| 471 | // Test that the right vcall offsets are generated in the right order. |
| 472 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 473 | // CHECK-19: Vtable for 'Test12::B' (19 entries). |
| 474 | // CHECK-19-NEXT: 0 | vbase_offset (8) |
| 475 | // CHECK-19-NEXT: 1 | offset_to_top (0) |
| 476 | // CHECK-19-NEXT: 2 | Test12::B RTTI |
| 477 | // CHECK-19-NEXT: -- (Test12::B, 0) vtable address -- |
| 478 | // CHECK-19-NEXT: 3 | void Test12::B::f() |
| 479 | // CHECK-19-NEXT: 4 | void Test12::B::a() |
| 480 | // CHECK-19-NEXT: 5 | vcall_offset (32) |
| 481 | // CHECK-19-NEXT: 6 | vcall_offset (16) |
| 482 | // CHECK-19-NEXT: 7 | vcall_offset (-8) |
| 483 | // CHECK-19-NEXT: 8 | vcall_offset (0) |
| 484 | // CHECK-19-NEXT: 9 | offset_to_top (-8) |
| 485 | // CHECK-19-NEXT: 10 | Test12::B RTTI |
| 486 | // CHECK-19-NEXT: -- (Test12::A, 8) vtable address -- |
| 487 | // CHECK-19-NEXT: -- (Test12::A1, 8) vtable address -- |
| 488 | // CHECK-19-NEXT: 11 | void Test12::A1::a1() |
| 489 | // CHECK-19-NEXT: 12 | void Test12::B::a() |
| 490 | // CHECK-19-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset] |
| 491 | // CHECK-19-NEXT: 13 | offset_to_top (-24) |
| 492 | // CHECK-19-NEXT: 14 | Test12::B RTTI |
| 493 | // CHECK-19-NEXT: -- (Test12::A2, 24) vtable address -- |
| 494 | // CHECK-19-NEXT: 15 | void Test12::A2::a2() |
| 495 | // CHECK-19-NEXT: 16 | offset_to_top (-40) |
| 496 | // CHECK-19-NEXT: 17 | Test12::B RTTI |
| 497 | // CHECK-19-NEXT: -- (Test12::A3, 40) vtable address -- |
| 498 | // CHECK-19-NEXT: 18 | void Test12::A3::a3() |
Anders Carlsson | 92f5432 | 2010-02-23 03:26:17 +0000 | [diff] [blame] | 499 | struct A1 { |
| 500 | virtual void a1(); |
| 501 | int a; |
| 502 | }; |
| 503 | |
| 504 | struct A2 { |
| 505 | virtual void a2(); |
| 506 | int a; |
| 507 | }; |
| 508 | |
| 509 | struct A3 { |
| 510 | virtual void a3(); |
| 511 | int a; |
| 512 | }; |
| 513 | |
| 514 | struct A : A1, A2, A3 { |
| 515 | virtual void a(); |
| 516 | int i; |
| 517 | }; |
| 518 | |
| 519 | struct B : virtual A { |
| 520 | virtual void f(); |
| 521 | |
| 522 | virtual void a(); |
| 523 | }; |
| 524 | void B::f() { } |
| 525 | |
| 526 | } |
Anders Carlsson | af280c0 | 2010-02-23 03:48:14 +0000 | [diff] [blame] | 527 | |
| 528 | namespace Test13 { |
| 529 | |
| 530 | // Test that we don't try to emit a vtable for 'A' twice. |
| 531 | struct A { |
| 532 | virtual void f(); |
| 533 | }; |
| 534 | |
| 535 | struct B : virtual A { |
| 536 | virtual void f(); |
| 537 | }; |
| 538 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 539 | // CHECK-20: Vtable for 'Test13::C' (6 entries). |
| 540 | // CHECK-20-NEXT: 0 | vbase_offset (0) |
| 541 | // CHECK-20-NEXT: 1 | vbase_offset (0) |
| 542 | // CHECK-20-NEXT: 2 | vcall_offset (0) |
| 543 | // CHECK-20-NEXT: 3 | offset_to_top (0) |
| 544 | // CHECK-20-NEXT: 4 | Test13::C RTTI |
| 545 | // CHECK-20-NEXT: -- (Test13::A, 0) vtable address -- |
| 546 | // CHECK-20-NEXT: -- (Test13::B, 0) vtable address -- |
| 547 | // CHECK-20-NEXT: -- (Test13::C, 0) vtable address -- |
| 548 | // CHECK-20-NEXT: 5 | void Test13::C::f() |
Anders Carlsson | af280c0 | 2010-02-23 03:48:14 +0000 | [diff] [blame] | 549 | struct C : virtual B, virtual A { |
| 550 | virtual void f(); |
| 551 | }; |
| 552 | void C::f() { } |
| 553 | |
| 554 | } |
| 555 | |
Anders Carlsson | bf554f6 | 2010-02-25 22:18:35 +0000 | [diff] [blame] | 556 | namespace Test14 { |
| 557 | |
| 558 | // Verify that we handle A being a non-virtual base of B, which is a virtual base. |
| 559 | |
| 560 | struct A { |
| 561 | virtual void f(); |
| 562 | }; |
| 563 | |
| 564 | struct B : A { }; |
| 565 | |
| 566 | struct C : virtual B { }; |
| 567 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 568 | // CHECK-21: Vtable for 'Test14::D' (5 entries). |
| 569 | // CHECK-21-NEXT: 0 | vbase_offset (0) |
| 570 | // CHECK-21-NEXT: 1 | vcall_offset (0) |
| 571 | // CHECK-21-NEXT: 2 | offset_to_top (0) |
| 572 | // CHECK-21-NEXT: 3 | Test14::D RTTI |
| 573 | // CHECK-21-NEXT: -- (Test14::A, 0) vtable address -- |
| 574 | // CHECK-21-NEXT: -- (Test14::B, 0) vtable address -- |
| 575 | // CHECK-21-NEXT: -- (Test14::C, 0) vtable address -- |
| 576 | // CHECK-21-NEXT: -- (Test14::D, 0) vtable address -- |
| 577 | // CHECK-21-NEXT: 4 | void Test14::D::f() |
Anders Carlsson | bf554f6 | 2010-02-25 22:18:35 +0000 | [diff] [blame] | 578 | struct D : C, virtual B { |
| 579 | virtual void f(); |
| 580 | }; |
| 581 | void D::f() { } |
| 582 | |
| 583 | } |
| 584 | |
Anders Carlsson | 08c2675 | 2010-02-27 04:05:52 +0000 | [diff] [blame] | 585 | namespace Test15 { |
| 586 | |
| 587 | // Test that we don't emit an extra vtable for B since it's a primary base of C. |
| 588 | struct A { virtual void a(); }; |
| 589 | struct B { virtual void b(); }; |
| 590 | |
| 591 | struct C : virtual B { }; |
| 592 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 593 | // CHECK-22: Vtable for 'Test15::D' (11 entries). |
| 594 | // CHECK-22-NEXT: 0 | vbase_offset (8) |
| 595 | // CHECK-22-NEXT: 1 | vbase_offset (8) |
| 596 | // CHECK-22-NEXT: 2 | offset_to_top (0) |
| 597 | // CHECK-22-NEXT: 3 | Test15::D RTTI |
| 598 | // CHECK-22-NEXT: -- (Test15::A, 0) vtable address -- |
| 599 | // CHECK-22-NEXT: -- (Test15::D, 0) vtable address -- |
| 600 | // CHECK-22-NEXT: 4 | void Test15::A::a() |
| 601 | // CHECK-22-NEXT: 5 | void Test15::D::f() |
| 602 | // CHECK-22-NEXT: 6 | vbase_offset (0) |
| 603 | // CHECK-22-NEXT: 7 | vcall_offset (0) |
| 604 | // CHECK-22-NEXT: 8 | offset_to_top (-8) |
| 605 | // CHECK-22-NEXT: 9 | Test15::D RTTI |
| 606 | // CHECK-22-NEXT: -- (Test15::B, 8) vtable address -- |
| 607 | // CHECK-22-NEXT: -- (Test15::C, 8) vtable address -- |
| 608 | // CHECK-22-NEXT: 10 | void Test15::B::b() |
Anders Carlsson | 08c2675 | 2010-02-27 04:05:52 +0000 | [diff] [blame] | 609 | struct D : A, virtual B, virtual C { |
| 610 | virtual void f(); |
| 611 | }; |
| 612 | void D::f() { } |
| 613 | |
| 614 | } |
Anders Carlsson | 5560969 | 2010-02-27 04:12:52 +0000 | [diff] [blame] | 615 | |
| 616 | namespace Test16 { |
| 617 | |
| 618 | // Test that destructors share vcall offsets. |
| 619 | |
| 620 | struct A { virtual ~A(); }; |
| 621 | struct B { virtual ~B(); }; |
| 622 | |
| 623 | struct C : A, B { virtual ~C(); }; |
| 624 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 625 | // CHECK-23: Vtable for 'Test16::D' (15 entries). |
| 626 | // CHECK-23-NEXT: 0 | vbase_offset (8) |
| 627 | // CHECK-23-NEXT: 1 | offset_to_top (0) |
| 628 | // CHECK-23-NEXT: 2 | Test16::D RTTI |
| 629 | // CHECK-23-NEXT: -- (Test16::D, 0) vtable address -- |
| 630 | // CHECK-23-NEXT: 3 | void Test16::D::f() |
| 631 | // CHECK-23-NEXT: 4 | Test16::D::~D() [complete] |
| 632 | // CHECK-23-NEXT: 5 | Test16::D::~D() [deleting] |
| 633 | // CHECK-23-NEXT: 6 | vcall_offset (-8) |
| 634 | // CHECK-23-NEXT: 7 | offset_to_top (-8) |
| 635 | // CHECK-23-NEXT: 8 | Test16::D RTTI |
| 636 | // CHECK-23-NEXT: -- (Test16::A, 8) vtable address -- |
| 637 | // CHECK-23-NEXT: -- (Test16::C, 8) vtable address -- |
| 638 | // CHECK-23-NEXT: 9 | Test16::D::~D() [complete] |
| 639 | // CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
| 640 | // CHECK-23-NEXT: 10 | Test16::D::~D() [deleting] |
| 641 | // CHECK-23-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
| 642 | // CHECK-23-NEXT: 11 | offset_to_top (-16) |
| 643 | // CHECK-23-NEXT: 12 | Test16::D RTTI |
| 644 | // CHECK-23-NEXT: -- (Test16::B, 16) vtable address -- |
| 645 | // CHECK-23-NEXT: 13 | Test16::D::~D() [complete] |
| 646 | // CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset] |
| 647 | // CHECK-23-NEXT: 14 | Test16::D::~D() [deleting] |
| 648 | // CHECK-23-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset] |
Anders Carlsson | 5560969 | 2010-02-27 04:12:52 +0000 | [diff] [blame] | 649 | struct D : virtual C { |
| 650 | virtual void f(); |
| 651 | }; |
| 652 | void D::f() { } |
| 653 | |
| 654 | } |
Anders Carlsson | c784ba2 | 2010-02-27 06:38:03 +0000 | [diff] [blame] | 655 | |
| 656 | namespace Test17 { |
| 657 | |
| 658 | // Test that we don't mark E::f in the C-in-E vtable as unused. |
| 659 | struct A { virtual void f(); }; |
| 660 | struct B : virtual A { virtual void f(); }; |
| 661 | struct C : virtual A { virtual void f(); }; |
| 662 | struct D : virtual B, virtual C { virtual void f(); }; |
| 663 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 664 | // CHECK-24: Vtable for 'Test17::E' (13 entries). |
| 665 | // CHECK-24-NEXT: 0 | vbase_offset (0) |
| 666 | // CHECK-24-NEXT: 1 | vbase_offset (8) |
| 667 | // CHECK-24-NEXT: 2 | vbase_offset (0) |
| 668 | // CHECK-24-NEXT: 3 | vbase_offset (0) |
| 669 | // CHECK-24-NEXT: 4 | vcall_offset (0) |
| 670 | // CHECK-24-NEXT: 5 | offset_to_top (0) |
| 671 | // CHECK-24-NEXT: 6 | Test17::E RTTI |
| 672 | // CHECK-24-NEXT: -- (Test17::A, 0) vtable address -- |
| 673 | // CHECK-24-NEXT: -- (Test17::B, 0) vtable address -- |
| 674 | // CHECK-24-NEXT: -- (Test17::D, 0) vtable address -- |
| 675 | // CHECK-24-NEXT: -- (Test17::E, 0) vtable address -- |
| 676 | // CHECK-24-NEXT: 7 | void Test17::E::f() |
| 677 | // CHECK-24-NEXT: 8 | vbase_offset (-8) |
| 678 | // CHECK-24-NEXT: 9 | vcall_offset (-8) |
| 679 | // CHECK-24-NEXT: 10 | offset_to_top (-8) |
| 680 | // CHECK-24-NEXT: 11 | Test17::E RTTI |
| 681 | // CHECK-24-NEXT: -- (Test17::C, 8) vtable address -- |
| 682 | // CHECK-24-NEXT: 12 | void Test17::E::f() |
| 683 | // CHECK-24-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
Anders Carlsson | c784ba2 | 2010-02-27 06:38:03 +0000 | [diff] [blame] | 684 | class E : virtual D { |
| 685 | virtual void f(); |
| 686 | }; |
| 687 | void E::f() {} |
| 688 | |
| 689 | } |
Anders Carlsson | 2ef9d6b | 2010-02-27 16:52:49 +0000 | [diff] [blame] | 690 | |
| 691 | namespace Test18 { |
| 692 | |
| 693 | // Test that we compute the right 'this' adjustment offsets. |
| 694 | |
| 695 | struct A { |
| 696 | virtual void f(); |
| 697 | virtual void g(); |
| 698 | }; |
| 699 | |
| 700 | struct B : virtual A { |
| 701 | virtual void f(); |
| 702 | }; |
| 703 | |
| 704 | struct C : A, B { |
| 705 | virtual void g(); |
| 706 | }; |
| 707 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 708 | // CHECK-25: Vtable for 'Test18::D' (24 entries). |
| 709 | // CHECK-25-NEXT: 0 | vbase_offset (8) |
| 710 | // CHECK-25-NEXT: 1 | vbase_offset (0) |
| 711 | // CHECK-25-NEXT: 2 | vbase_offset (0) |
| 712 | // CHECK-25-NEXT: 3 | vcall_offset (8) |
| 713 | // CHECK-25-NEXT: 4 | vcall_offset (0) |
| 714 | // CHECK-25-NEXT: 5 | offset_to_top (0) |
| 715 | // CHECK-25-NEXT: 6 | Test18::D RTTI |
| 716 | // CHECK-25-NEXT: -- (Test18::A, 0) vtable address -- |
| 717 | // CHECK-25-NEXT: -- (Test18::B, 0) vtable address -- |
| 718 | // CHECK-25-NEXT: -- (Test18::D, 0) vtable address -- |
| 719 | // CHECK-25-NEXT: 7 | void Test18::D::f() |
| 720 | // CHECK-25-NEXT: 8 | void Test18::C::g() |
| 721 | // CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset] |
| 722 | // CHECK-25-NEXT: 9 | void Test18::D::h() |
| 723 | // CHECK-25-NEXT: 10 | vcall_offset (0) |
| 724 | // CHECK-25-NEXT: 11 | vcall_offset (-8) |
| 725 | // CHECK-25-NEXT: 12 | vbase_offset (-8) |
| 726 | // CHECK-25-NEXT: 13 | offset_to_top (-8) |
| 727 | // CHECK-25-NEXT: 14 | Test18::D RTTI |
| 728 | // CHECK-25-NEXT: -- (Test18::A, 8) vtable address -- |
| 729 | // CHECK-25-NEXT: -- (Test18::C, 8) vtable address -- |
| 730 | // CHECK-25-NEXT: 15 | void Test18::D::f() |
| 731 | // CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset] |
| 732 | // CHECK-25-NEXT: 16 | void Test18::C::g() |
| 733 | // CHECK-25-NEXT: 17 | vbase_offset (-16) |
| 734 | // CHECK-25-NEXT: 18 | vcall_offset (-8) |
| 735 | // CHECK-25-NEXT: 19 | vcall_offset (-16) |
| 736 | // CHECK-25-NEXT: 20 | offset_to_top (-16) |
| 737 | // CHECK-25-NEXT: 21 | Test18::D RTTI |
| 738 | // CHECK-25-NEXT: -- (Test18::B, 16) vtable address -- |
| 739 | // CHECK-25-NEXT: 22 | void Test18::D::f() |
| 740 | // CHECK-25-NEXT: [this adjustment: -8 non-virtual, -32 vcall offset offset] |
| 741 | // CHECK-25-NEXT: 23 | [unused] void Test18::C::g() |
Anders Carlsson | 2bc1d3a | 2010-03-10 21:25:37 +0000 | [diff] [blame] | 742 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 743 | // CHECK-25: Construction vtable for ('Test18::B', 0) in 'Test18::D' (7 entries). |
| 744 | // CHECK-25-NEXT: 0 | vbase_offset (0) |
| 745 | // CHECK-25-NEXT: 1 | vcall_offset (0) |
| 746 | // CHECK-25-NEXT: 2 | vcall_offset (0) |
| 747 | // CHECK-25-NEXT: 3 | offset_to_top (0) |
| 748 | // CHECK-25-NEXT: 4 | Test18::B RTTI |
| 749 | // CHECK-25-NEXT: -- (Test18::A, 0) vtable address -- |
| 750 | // CHECK-25-NEXT: -- (Test18::B, 0) vtable address -- |
| 751 | // CHECK-25-NEXT: 5 | void Test18::B::f() |
| 752 | // CHECK-25-NEXT: 6 | void Test18::A::g() |
Anders Carlsson | 2bc1d3a | 2010-03-10 21:25:37 +0000 | [diff] [blame] | 753 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 754 | // CHECK-25: Construction vtable for ('Test18::C', 8) in 'Test18::D' (20 entries). |
| 755 | // CHECK-25-NEXT: 0 | vcall_offset (0) |
| 756 | // CHECK-25-NEXT: 1 | vcall_offset (0) |
| 757 | // CHECK-25-NEXT: 2 | vbase_offset (-8) |
| 758 | // CHECK-25-NEXT: 3 | offset_to_top (0) |
| 759 | // CHECK-25-NEXT: 4 | Test18::C RTTI |
| 760 | // CHECK-25-NEXT: -- (Test18::A, 8) vtable address -- |
| 761 | // CHECK-25-NEXT: -- (Test18::C, 8) vtable address -- |
| 762 | // CHECK-25-NEXT: 5 | void Test18::A::f() |
| 763 | // CHECK-25-NEXT: 6 | void Test18::C::g() |
| 764 | // CHECK-25-NEXT: 7 | vbase_offset (-16) |
| 765 | // CHECK-25-NEXT: 8 | vcall_offset (-8) |
| 766 | // CHECK-25-NEXT: 9 | vcall_offset (0) |
| 767 | // CHECK-25-NEXT: 10 | offset_to_top (-8) |
| 768 | // CHECK-25-NEXT: 11 | Test18::C RTTI |
| 769 | // CHECK-25-NEXT: -- (Test18::B, 16) vtable address -- |
| 770 | // CHECK-25-NEXT: 12 | void Test18::B::f() |
| 771 | // CHECK-25-NEXT: 13 | [unused] void Test18::C::g() |
| 772 | // CHECK-25-NEXT: 14 | vcall_offset (8) |
| 773 | // CHECK-25-NEXT: 15 | vcall_offset (16) |
| 774 | // CHECK-25-NEXT: 16 | offset_to_top (8) |
| 775 | // CHECK-25-NEXT: 17 | Test18::C RTTI |
| 776 | // CHECK-25-NEXT: -- (Test18::A, 0) vtable address -- |
| 777 | // CHECK-25-NEXT: 18 | void Test18::B::f() |
| 778 | // CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
| 779 | // CHECK-25-NEXT: 19 | void Test18::C::g() |
| 780 | // CHECK-25-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset] |
Anders Carlsson | 2bc1d3a | 2010-03-10 21:25:37 +0000 | [diff] [blame] | 781 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 782 | // CHECK-25: Construction vtable for ('Test18::B', 16) in 'Test18::D' (13 entries). |
| 783 | // CHECK-25-NEXT: 0 | vbase_offset (-16) |
| 784 | // CHECK-25-NEXT: 1 | vcall_offset (-16) |
| 785 | // CHECK-25-NEXT: 2 | vcall_offset (0) |
| 786 | // CHECK-25-NEXT: 3 | offset_to_top (0) |
| 787 | // CHECK-25-NEXT: 4 | Test18::B RTTI |
| 788 | // CHECK-25-NEXT: -- (Test18::B, 16) vtable address -- |
| 789 | // CHECK-25-NEXT: 5 | void Test18::B::f() |
| 790 | // CHECK-25-NEXT: 6 | [unused] void Test18::A::g() |
| 791 | // CHECK-25-NEXT: 7 | vcall_offset (0) |
| 792 | // CHECK-25-NEXT: 8 | vcall_offset (16) |
| 793 | // CHECK-25-NEXT: 9 | offset_to_top (16) |
| 794 | // CHECK-25-NEXT: 10 | Test18::B RTTI |
| 795 | // CHECK-25-NEXT: -- (Test18::A, 0) vtable address -- |
| 796 | // CHECK-25-NEXT: 11 | void Test18::B::f() |
| 797 | // CHECK-25-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
| 798 | // CHECK-25-NEXT: 12 | void Test18::A::g() |
Anders Carlsson | 2ef9d6b | 2010-02-27 16:52:49 +0000 | [diff] [blame] | 799 | struct D : virtual B, virtual C, virtual A |
| 800 | { |
| 801 | virtual void f(); |
| 802 | virtual void h(); |
| 803 | }; |
| 804 | void D::f() {} |
| 805 | |
Anders Carlsson | 3504475 | 2010-02-27 16:55:58 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | namespace Test19 { |
| 809 | |
| 810 | // Another 'this' adjustment test. |
| 811 | |
| 812 | struct A { |
| 813 | int a; |
| 814 | |
| 815 | virtual void f(); |
| 816 | }; |
| 817 | |
| 818 | struct B : A { |
| 819 | int b; |
| 820 | |
| 821 | virtual void g(); |
| 822 | }; |
| 823 | |
| 824 | struct C { |
| 825 | virtual void c(); |
| 826 | }; |
| 827 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 828 | // CHECK-26: Vtable for 'Test19::D' (13 entries). |
| 829 | // CHECK-26-NEXT: 0 | vbase_offset (24) |
| 830 | // CHECK-26-NEXT: 1 | offset_to_top (0) |
| 831 | // CHECK-26-NEXT: 2 | Test19::D RTTI |
| 832 | // CHECK-26-NEXT: -- (Test19::C, 0) vtable address -- |
| 833 | // CHECK-26-NEXT: -- (Test19::D, 0) vtable address -- |
| 834 | // CHECK-26-NEXT: 3 | void Test19::C::c() |
| 835 | // CHECK-26-NEXT: 4 | void Test19::D::f() |
| 836 | // CHECK-26-NEXT: 5 | offset_to_top (-8) |
| 837 | // CHECK-26-NEXT: 6 | Test19::D RTTI |
| 838 | // CHECK-26-NEXT: -- (Test19::A, 8) vtable address -- |
| 839 | // CHECK-26-NEXT: -- (Test19::B, 8) vtable address -- |
| 840 | // CHECK-26-NEXT: 7 | void Test19::D::f() |
| 841 | // CHECK-26-NEXT: [this adjustment: -8 non-virtual] |
| 842 | // CHECK-26-NEXT: 8 | void Test19::B::g() |
| 843 | // CHECK-26-NEXT: 9 | vcall_offset (-24) |
| 844 | // CHECK-26-NEXT: 10 | offset_to_top (-24) |
| 845 | // CHECK-26-NEXT: 11 | Test19::D RTTI |
| 846 | // CHECK-26-NEXT: -- (Test19::A, 24) vtable address -- |
| 847 | // CHECK-26-NEXT: 12 | void Test19::D::f() |
| 848 | // CHECK-26-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
Anders Carlsson | 3504475 | 2010-02-27 16:55:58 +0000 | [diff] [blame] | 849 | struct D : C, B, virtual A { |
| 850 | virtual void f(); |
| 851 | }; |
| 852 | void D::f() { } |
| 853 | |
Anders Carlsson | 8bc68f7 | 2010-02-27 18:16:50 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | namespace Test20 { |
| 857 | |
| 858 | // pure virtual member functions should never have 'this' adjustments. |
| 859 | |
| 860 | struct A { |
| 861 | virtual void f() = 0; |
| 862 | virtual void g(); |
| 863 | }; |
| 864 | |
| 865 | struct B : A { }; |
| 866 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 867 | // CHECK-27: Vtable for 'Test20::C' (9 entries). |
| 868 | // CHECK-27-NEXT: 0 | offset_to_top (0) |
| 869 | // CHECK-27-NEXT: 1 | Test20::C RTTI |
| 870 | // CHECK-27-NEXT: -- (Test20::A, 0) vtable address -- |
| 871 | // CHECK-27-NEXT: -- (Test20::C, 0) vtable address -- |
| 872 | // CHECK-27-NEXT: 2 | void Test20::C::f() [pure] |
| 873 | // CHECK-27-NEXT: 3 | void Test20::A::g() |
| 874 | // CHECK-27-NEXT: 4 | void Test20::C::h() |
| 875 | // CHECK-27-NEXT: 5 | offset_to_top (-8) |
| 876 | // CHECK-27-NEXT: 6 | Test20::C RTTI |
| 877 | // CHECK-27-NEXT: -- (Test20::A, 8) vtable address -- |
| 878 | // CHECK-27-NEXT: -- (Test20::B, 8) vtable address -- |
| 879 | // CHECK-27-NEXT: 7 | void Test20::C::f() [pure] |
| 880 | // CHECK-27-NEXT: 8 | void Test20::A::g() |
Anders Carlsson | 8bc68f7 | 2010-02-27 18:16:50 +0000 | [diff] [blame] | 881 | struct C : A, B { |
| 882 | virtual void f() = 0; |
| 883 | virtual void h(); |
| 884 | }; |
| 885 | void C::h() { } |
| 886 | |
| 887 | } |
Anders Carlsson | 6a8c5b2 | 2010-02-27 19:21:58 +0000 | [diff] [blame] | 888 | |
| 889 | namespace Test21 { |
| 890 | |
| 891 | // Test that we get vbase offsets right in secondary vtables. |
| 892 | struct A { |
| 893 | virtual void f(); |
| 894 | }; |
| 895 | |
| 896 | struct B : virtual A { }; |
| 897 | class C : virtual B { }; |
| 898 | class D : virtual C { }; |
| 899 | |
| 900 | class E : virtual C { }; |
| 901 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 902 | // CHECK-28: Vtable for 'Test21::F' (16 entries). |
| 903 | // CHECK-28-NEXT: 0 | vbase_offset (8) |
| 904 | // CHECK-28-NEXT: 1 | vbase_offset (0) |
| 905 | // CHECK-28-NEXT: 2 | vbase_offset (0) |
| 906 | // CHECK-28-NEXT: 3 | vbase_offset (0) |
| 907 | // CHECK-28-NEXT: 4 | vbase_offset (0) |
| 908 | // CHECK-28-NEXT: 5 | vcall_offset (0) |
| 909 | // CHECK-28-NEXT: 6 | offset_to_top (0) |
| 910 | // CHECK-28-NEXT: 7 | Test21::F RTTI |
| 911 | // CHECK-28-NEXT: -- (Test21::A, 0) vtable address -- |
| 912 | // CHECK-28-NEXT: -- (Test21::B, 0) vtable address -- |
| 913 | // CHECK-28-NEXT: -- (Test21::C, 0) vtable address -- |
| 914 | // CHECK-28-NEXT: -- (Test21::D, 0) vtable address -- |
| 915 | // CHECK-28-NEXT: -- (Test21::F, 0) vtable address -- |
| 916 | // CHECK-28-NEXT: 8 | void Test21::F::f() |
| 917 | // CHECK-28-NEXT: 9 | vbase_offset (-8) |
| 918 | // CHECK-28-NEXT: 10 | vbase_offset (-8) |
| 919 | // CHECK-28-NEXT: 11 | vbase_offset (-8) |
| 920 | // CHECK-28-NEXT: 12 | vcall_offset (-8) |
| 921 | // CHECK-28-NEXT: 13 | offset_to_top (-8) |
| 922 | // CHECK-28-NEXT: 14 | Test21::F RTTI |
| 923 | // CHECK-28-NEXT: -- (Test21::E, 8) vtable address -- |
| 924 | // CHECK-28-NEXT: 15 | [unused] void Test21::F::f() |
Anders Carlsson | 127e467 | 2010-03-11 06:44:31 +0000 | [diff] [blame] | 925 | // |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 926 | // CHECK-28: Virtual base offset offsets for 'Test21::F' (5 entries). |
| 927 | // CHECK-28-NEXT: Test21::A | -32 |
| 928 | // CHECK-28-NEXT: Test21::B | -40 |
| 929 | // CHECK-28-NEXT: Test21::C | -48 |
| 930 | // CHECK-28-NEXT: Test21::D | -56 |
| 931 | // CHECK-28-NEXT: Test21::E | -64 |
Anders Carlsson | 6a8c5b2 | 2010-02-27 19:21:58 +0000 | [diff] [blame] | 932 | class F : virtual D, virtual E { |
| 933 | virtual void f(); |
| 934 | }; |
| 935 | void F::f() { } |
| 936 | |
| 937 | } |
Anders Carlsson | 0041a64 | 2010-02-27 21:09:00 +0000 | [diff] [blame] | 938 | |
| 939 | namespace Test22 { |
| 940 | |
| 941 | // Very simple construction vtable test. |
| 942 | struct V1 { |
| 943 | int v1; |
| 944 | }; |
| 945 | |
| 946 | struct V2 : virtual V1 { |
| 947 | int v2; |
| 948 | }; |
| 949 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 950 | // CHECK-29: Vtable for 'Test22::C' (8 entries). |
| 951 | // CHECK-29-NEXT: 0 | vbase_offset (16) |
| 952 | // CHECK-29-NEXT: 1 | vbase_offset (12) |
| 953 | // CHECK-29-NEXT: 2 | offset_to_top (0) |
| 954 | // CHECK-29-NEXT: 3 | Test22::C RTTI |
| 955 | // CHECK-29-NEXT: -- (Test22::C, 0) vtable address -- |
| 956 | // CHECK-29-NEXT: 4 | void Test22::C::f() |
| 957 | // CHECK-29-NEXT: 5 | vbase_offset (-4) |
| 958 | // CHECK-29-NEXT: 6 | offset_to_top (-16) |
| 959 | // CHECK-29-NEXT: 7 | Test22::C RTTI |
| 960 | // CHECK-29-NEXT: -- (Test22::V2, 16) vtable address -- |
Anders Carlsson | 0041a64 | 2010-02-27 21:09:00 +0000 | [diff] [blame] | 961 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 962 | // CHECK-29: Construction vtable for ('Test22::V2', 16) in 'Test22::C' (3 entries). |
| 963 | // CHECK-29-NEXT: 0 | vbase_offset (-4) |
| 964 | // CHECK-29-NEXT: 1 | offset_to_top (0) |
| 965 | // CHECK-29-NEXT: 2 | Test22::V2 RTTI |
Anders Carlsson | 0041a64 | 2010-02-27 21:09:00 +0000 | [diff] [blame] | 966 | |
| 967 | struct C : virtual V1, virtual V2 { |
| 968 | int c; |
| 969 | virtual void f(); |
| 970 | }; |
| 971 | void C::f() { } |
| 972 | |
| 973 | } |
Anders Carlsson | 530c40c | 2010-02-28 01:43:58 +0000 | [diff] [blame] | 974 | |
| 975 | namespace Test23 { |
| 976 | |
| 977 | struct A { |
| 978 | int a; |
| 979 | }; |
| 980 | |
| 981 | struct B : virtual A { |
| 982 | int b; |
| 983 | }; |
| 984 | |
| 985 | struct C : A, virtual B { |
| 986 | int c; |
| 987 | }; |
| 988 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 989 | // CHECK-30: Vtable for 'Test23::D' (7 entries). |
| 990 | // CHECK-30-NEXT: 0 | vbase_offset (20) |
| 991 | // CHECK-30-NEXT: 1 | vbase_offset (24) |
| 992 | // CHECK-30-NEXT: 2 | offset_to_top (0) |
| 993 | // CHECK-30-NEXT: 3 | Test23::D RTTI |
| 994 | // CHECK-30-NEXT: -- (Test23::C, 0) vtable address -- |
| 995 | // CHECK-30-NEXT: -- (Test23::D, 0) vtable address -- |
| 996 | // CHECK-30-NEXT: 4 | vbase_offset (-4) |
| 997 | // CHECK-30-NEXT: 5 | offset_to_top (-24) |
| 998 | // CHECK-30-NEXT: 6 | Test23::D RTTI |
| 999 | // CHECK-30-NEXT: -- (Test23::B, 24) vtable address -- |
Anders Carlsson | 530c40c | 2010-02-28 01:43:58 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1001 | // CHECK-30: Construction vtable for ('Test23::C', 0) in 'Test23::D' (7 entries). |
| 1002 | // CHECK-30-NEXT: 0 | vbase_offset (20) |
| 1003 | // CHECK-30-NEXT: 1 | vbase_offset (24) |
| 1004 | // CHECK-30-NEXT: 2 | offset_to_top (0) |
| 1005 | // CHECK-30-NEXT: 3 | Test23::C RTTI |
| 1006 | // CHECK-30-NEXT: -- (Test23::C, 0) vtable address -- |
| 1007 | // CHECK-30-NEXT: 4 | vbase_offset (-4) |
| 1008 | // CHECK-30-NEXT: 5 | offset_to_top (-24) |
| 1009 | // CHECK-30-NEXT: 6 | Test23::C RTTI |
| 1010 | // CHECK-30-NEXT: -- (Test23::B, 24) vtable address -- |
Anders Carlsson | 530c40c | 2010-02-28 01:43:58 +0000 | [diff] [blame] | 1011 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1012 | // CHECK-30: Construction vtable for ('Test23::B', 24) in 'Test23::D' (3 entries). |
| 1013 | // CHECK-30-NEXT: 0 | vbase_offset (-4) |
| 1014 | // CHECK-30-NEXT: 1 | offset_to_top (0) |
| 1015 | // CHECK-30-NEXT: 2 | Test23::B RTTI |
| 1016 | // CHECK-30-NEXT: -- (Test23::B, 24) vtable address -- |
Anders Carlsson | 530c40c | 2010-02-28 01:43:58 +0000 | [diff] [blame] | 1017 | |
| 1018 | struct D : virtual A, virtual B, C { |
| 1019 | int d; |
| 1020 | |
| 1021 | void f(); |
| 1022 | }; |
| 1023 | void D::f() { } |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1024 | D d; |
Anders Carlsson | 530c40c | 2010-02-28 01:43:58 +0000 | [diff] [blame] | 1025 | } |
Anders Carlsson | 293126b | 2010-02-28 17:59:36 +0000 | [diff] [blame] | 1026 | |
| 1027 | namespace Test24 { |
| 1028 | |
| 1029 | // Another construction vtable test. |
| 1030 | |
Anders Carlsson | 0378bf0 | 2010-02-28 18:08:38 +0000 | [diff] [blame] | 1031 | struct A { |
| 1032 | virtual void f(); |
| 1033 | }; |
| 1034 | |
| 1035 | struct B : virtual A { }; |
| 1036 | struct C : virtual A { }; |
| 1037 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1038 | // CHECK-31: Vtable for 'Test24::D' (10 entries). |
| 1039 | // CHECK-31-NEXT: 0 | vbase_offset (0) |
| 1040 | // CHECK-31-NEXT: 1 | vcall_offset (0) |
| 1041 | // CHECK-31-NEXT: 2 | offset_to_top (0) |
| 1042 | // CHECK-31-NEXT: 3 | Test24::D RTTI |
| 1043 | // CHECK-31-NEXT: -- (Test24::A, 0) vtable address -- |
| 1044 | // CHECK-31-NEXT: -- (Test24::B, 0) vtable address -- |
| 1045 | // CHECK-31-NEXT: -- (Test24::D, 0) vtable address -- |
| 1046 | // CHECK-31-NEXT: 4 | void Test24::D::f() |
| 1047 | // CHECK-31-NEXT: 5 | vbase_offset (-8) |
| 1048 | // CHECK-31-NEXT: 6 | vcall_offset (-8) |
| 1049 | // CHECK-31-NEXT: 7 | offset_to_top (-8) |
| 1050 | // CHECK-31-NEXT: 8 | Test24::D RTTI |
| 1051 | // CHECK-31-NEXT: -- (Test24::C, 8) vtable address -- |
| 1052 | // CHECK-31-NEXT: 9 | [unused] void Test24::D::f() |
Anders Carlsson | 293126b | 2010-02-28 17:59:36 +0000 | [diff] [blame] | 1053 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1054 | // CHECK-31: Construction vtable for ('Test24::B', 0) in 'Test24::D' (5 entries). |
| 1055 | // CHECK-31-NEXT: 0 | vbase_offset (0) |
| 1056 | // CHECK-31-NEXT: 1 | vcall_offset (0) |
| 1057 | // CHECK-31-NEXT: 2 | offset_to_top (0) |
| 1058 | // CHECK-31-NEXT: 3 | Test24::B RTTI |
| 1059 | // CHECK-31-NEXT: -- (Test24::A, 0) vtable address -- |
| 1060 | // CHECK-31-NEXT: -- (Test24::B, 0) vtable address -- |
| 1061 | // CHECK-31-NEXT: 4 | void Test24::A::f() |
Anders Carlsson | 293126b | 2010-02-28 17:59:36 +0000 | [diff] [blame] | 1062 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1063 | // CHECK-31: Construction vtable for ('Test24::C', 8) in 'Test24::D' (9 entries). |
| 1064 | // CHECK-31-NEXT: 0 | vbase_offset (-8) |
| 1065 | // CHECK-31-NEXT: 1 | vcall_offset (-8) |
| 1066 | // CHECK-31-NEXT: 2 | offset_to_top (0) |
| 1067 | // CHECK-31-NEXT: 3 | Test24::C RTTI |
| 1068 | // CHECK-31-NEXT: -- (Test24::C, 8) vtable address -- |
| 1069 | // CHECK-31-NEXT: 4 | [unused] void Test24::A::f() |
| 1070 | // CHECK-31-NEXT: 5 | vcall_offset (0) |
| 1071 | // CHECK-31-NEXT: 6 | offset_to_top (8) |
| 1072 | // CHECK-31-NEXT: 7 | Test24::C RTTI |
| 1073 | // CHECK-31-NEXT: -- (Test24::A, 0) vtable address -- |
| 1074 | // CHECK-31-NEXT: 8 | void Test24::A::f() |
Anders Carlsson | 293126b | 2010-02-28 17:59:36 +0000 | [diff] [blame] | 1075 | struct D : B, C { |
| 1076 | virtual void f(); |
| 1077 | }; |
| 1078 | void D::f() { } |
Anders Carlsson | dad0f99 | 2010-02-28 18:37:33 +0000 | [diff] [blame] | 1079 | |
Anders Carlsson | 293126b | 2010-02-28 17:59:36 +0000 | [diff] [blame] | 1080 | } |
Anders Carlsson | ce57dd5 | 2010-03-03 04:58:02 +0000 | [diff] [blame] | 1081 | |
| 1082 | namespace Test25 { |
| 1083 | |
| 1084 | // This mainly tests that we don't assert on this class hierarchy. |
| 1085 | |
| 1086 | struct V { |
| 1087 | virtual void f(); |
| 1088 | }; |
| 1089 | |
| 1090 | struct A : virtual V { }; |
| 1091 | struct B : virtual V { }; |
| 1092 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1093 | // CHECK-32: Vtable for 'Test25::C' (11 entries). |
| 1094 | // CHECK-32-NEXT: 0 | vbase_offset (0) |
| 1095 | // CHECK-32-NEXT: 1 | vcall_offset (0) |
| 1096 | // CHECK-32-NEXT: 2 | offset_to_top (0) |
| 1097 | // CHECK-32-NEXT: 3 | Test25::C RTTI |
| 1098 | // CHECK-32-NEXT: -- (Test25::A, 0) vtable address -- |
| 1099 | // CHECK-32-NEXT: -- (Test25::C, 0) vtable address -- |
| 1100 | // CHECK-32-NEXT: -- (Test25::V, 0) vtable address -- |
| 1101 | // CHECK-32-NEXT: 4 | void Test25::V::f() |
| 1102 | // CHECK-32-NEXT: 5 | void Test25::C::g() |
| 1103 | // CHECK-32-NEXT: 6 | vbase_offset (-8) |
| 1104 | // CHECK-32-NEXT: 7 | vcall_offset (-8) |
| 1105 | // CHECK-32-NEXT: 8 | offset_to_top (-8) |
| 1106 | // CHECK-32-NEXT: 9 | Test25::C RTTI |
| 1107 | // CHECK-32-NEXT: -- (Test25::B, 8) vtable address -- |
| 1108 | // CHECK-32-NEXT: 10 | [unused] void Test25::V::f() |
Anders Carlsson | ce57dd5 | 2010-03-03 04:58:02 +0000 | [diff] [blame] | 1109 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1110 | // CHECK-32: Construction vtable for ('Test25::A', 0) in 'Test25::C' (5 entries). |
| 1111 | // CHECK-32-NEXT: 0 | vbase_offset (0) |
| 1112 | // CHECK-32-NEXT: 1 | vcall_offset (0) |
| 1113 | // CHECK-32-NEXT: 2 | offset_to_top (0) |
| 1114 | // CHECK-32-NEXT: 3 | Test25::A RTTI |
| 1115 | // CHECK-32-NEXT: -- (Test25::A, 0) vtable address -- |
| 1116 | // CHECK-32-NEXT: -- (Test25::V, 0) vtable address -- |
| 1117 | // CHECK-32-NEXT: 4 | void Test25::V::f() |
Anders Carlsson | ce57dd5 | 2010-03-03 04:58:02 +0000 | [diff] [blame] | 1118 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1119 | // CHECK-32: Construction vtable for ('Test25::B', 8) in 'Test25::C' (9 entries). |
| 1120 | // CHECK-32-NEXT: 0 | vbase_offset (-8) |
| 1121 | // CHECK-32-NEXT: 1 | vcall_offset (-8) |
| 1122 | // CHECK-32-NEXT: 2 | offset_to_top (0) |
| 1123 | // CHECK-32-NEXT: 3 | Test25::B RTTI |
| 1124 | // CHECK-32-NEXT: -- (Test25::B, 8) vtable address -- |
| 1125 | // CHECK-32-NEXT: 4 | [unused] void Test25::V::f() |
| 1126 | // CHECK-32-NEXT: 5 | vcall_offset (0) |
| 1127 | // CHECK-32-NEXT: 6 | offset_to_top (8) |
| 1128 | // CHECK-32-NEXT: 7 | Test25::B RTTI |
| 1129 | // CHECK-32-NEXT: -- (Test25::V, 0) vtable address -- |
| 1130 | // CHECK-32-NEXT: 8 | void Test25::V::f() |
Anders Carlsson | ce57dd5 | 2010-03-03 04:58:02 +0000 | [diff] [blame] | 1131 | struct C : A, virtual V, B { |
| 1132 | virtual void g(); |
| 1133 | }; |
| 1134 | void C::g() { } |
| 1135 | |
| 1136 | } |
Anders Carlsson | 6039661 | 2010-03-10 06:51:42 +0000 | [diff] [blame] | 1137 | |
| 1138 | namespace Test26 { |
| 1139 | |
| 1140 | // Test that we generate the right number of entries in the C-in-D construction vtable, and that |
| 1141 | // we don't mark A::a as unused. |
| 1142 | |
| 1143 | struct A { |
| 1144 | virtual void a(); |
| 1145 | }; |
| 1146 | |
| 1147 | struct B { |
| 1148 | virtual void c(); |
| 1149 | }; |
| 1150 | |
| 1151 | struct C : virtual A { |
| 1152 | virtual void b(); |
| 1153 | }; |
| 1154 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1155 | // CHECK-33: Vtable for 'Test26::D' (15 entries). |
| 1156 | // CHECK-33-NEXT: 0 | vbase_offset (8) |
| 1157 | // CHECK-33-NEXT: 1 | vbase_offset (8) |
| 1158 | // CHECK-33-NEXT: 2 | vbase_offset (0) |
| 1159 | // CHECK-33-NEXT: 3 | vcall_offset (0) |
| 1160 | // CHECK-33-NEXT: 4 | offset_to_top (0) |
| 1161 | // CHECK-33-NEXT: 5 | Test26::D RTTI |
| 1162 | // CHECK-33-NEXT: -- (Test26::B, 0) vtable address -- |
| 1163 | // CHECK-33-NEXT: -- (Test26::D, 0) vtable address -- |
| 1164 | // CHECK-33-NEXT: 6 | void Test26::B::c() |
| 1165 | // CHECK-33-NEXT: 7 | void Test26::D::d() |
| 1166 | // CHECK-33-NEXT: 8 | vcall_offset (0) |
| 1167 | // CHECK-33-NEXT: 9 | vbase_offset (0) |
| 1168 | // CHECK-33-NEXT: 10 | vcall_offset (0) |
| 1169 | // CHECK-33-NEXT: 11 | offset_to_top (-8) |
| 1170 | // CHECK-33-NEXT: 12 | Test26::D RTTI |
| 1171 | // CHECK-33-NEXT: -- (Test26::A, 8) vtable address -- |
| 1172 | // CHECK-33-NEXT: -- (Test26::C, 8) vtable address -- |
| 1173 | // CHECK-33-NEXT: 13 | void Test26::A::a() |
| 1174 | // CHECK-33-NEXT: 14 | void Test26::C::b() |
Anders Carlsson | 6039661 | 2010-03-10 06:51:42 +0000 | [diff] [blame] | 1175 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1176 | // CHECK-33: Construction vtable for ('Test26::C', 8) in 'Test26::D' (7 entries). |
| 1177 | // CHECK-33-NEXT: 0 | vcall_offset (0) |
| 1178 | // CHECK-33-NEXT: 1 | vbase_offset (0) |
| 1179 | // CHECK-33-NEXT: 2 | vcall_offset (0) |
| 1180 | // CHECK-33-NEXT: 3 | offset_to_top (0) |
| 1181 | // CHECK-33-NEXT: 4 | Test26::C RTTI |
| 1182 | // CHECK-33-NEXT: -- (Test26::A, 8) vtable address -- |
| 1183 | // CHECK-33-NEXT: -- (Test26::C, 8) vtable address -- |
| 1184 | // CHECK-33-NEXT: 5 | void Test26::A::a() |
| 1185 | // CHECK-33-NEXT: 6 | void Test26::C::b() |
Anders Carlsson | 6039661 | 2010-03-10 06:51:42 +0000 | [diff] [blame] | 1186 | class D : virtual B, virtual C { |
| 1187 | virtual void d(); |
| 1188 | }; |
| 1189 | void D::d() { } |
| 1190 | |
Anders Carlsson | e35b768 | 2010-03-10 06:51:56 +0000 | [diff] [blame] | 1191 | } |
Anders Carlsson | f2c98ce | 2010-03-10 19:15:26 +0000 | [diff] [blame] | 1192 | |
| 1193 | namespace Test27 { |
| 1194 | |
| 1195 | // Test that we don't generate a secondary vtable for C in the D-in-E vtable, since |
| 1196 | // C doesn't have any virtual bases. |
| 1197 | |
| 1198 | struct A { |
| 1199 | virtual void a(); |
| 1200 | }; |
| 1201 | |
| 1202 | struct B { |
| 1203 | virtual void b(); |
| 1204 | }; |
| 1205 | |
| 1206 | struct C { |
| 1207 | virtual void c(); |
| 1208 | }; |
| 1209 | |
| 1210 | struct D : A, virtual B, C { |
| 1211 | virtual void d(); |
| 1212 | }; |
| 1213 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1214 | // CHECK-34: Vtable for 'Test27::E' (13 entries). |
| 1215 | // CHECK-34-NEXT: 0 | vbase_offset (16) |
| 1216 | // CHECK-34-NEXT: 1 | offset_to_top (0) |
| 1217 | // CHECK-34-NEXT: 2 | Test27::E RTTI |
| 1218 | // CHECK-34-NEXT: -- (Test27::A, 0) vtable address -- |
| 1219 | // CHECK-34-NEXT: -- (Test27::D, 0) vtable address -- |
| 1220 | // CHECK-34-NEXT: -- (Test27::E, 0) vtable address -- |
| 1221 | // CHECK-34-NEXT: 3 | void Test27::A::a() |
| 1222 | // CHECK-34-NEXT: 4 | void Test27::D::d() |
| 1223 | // CHECK-34-NEXT: 5 | void Test27::E::e() |
| 1224 | // CHECK-34-NEXT: 6 | offset_to_top (-8) |
| 1225 | // CHECK-34-NEXT: 7 | Test27::E RTTI |
| 1226 | // CHECK-34-NEXT: -- (Test27::C, 8) vtable address -- |
| 1227 | // CHECK-34-NEXT: 8 | void Test27::C::c() |
| 1228 | // CHECK-34-NEXT: 9 | vcall_offset (0) |
| 1229 | // CHECK-34-NEXT: 10 | offset_to_top (-16) |
| 1230 | // CHECK-34-NEXT: 11 | Test27::E RTTI |
| 1231 | // CHECK-34-NEXT: -- (Test27::B, 16) vtable address -- |
| 1232 | // CHECK-34-NEXT: 12 | void Test27::B::b() |
Anders Carlsson | f2c98ce | 2010-03-10 19:15:26 +0000 | [diff] [blame] | 1233 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1234 | // CHECK-34: Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries). |
| 1235 | // CHECK-34-NEXT: 0 | vbase_offset (16) |
| 1236 | // CHECK-34-NEXT: 1 | offset_to_top (0) |
| 1237 | // CHECK-34-NEXT: 2 | Test27::D RTTI |
| 1238 | // CHECK-34-NEXT: -- (Test27::A, 0) vtable address -- |
| 1239 | // CHECK-34-NEXT: -- (Test27::D, 0) vtable address -- |
| 1240 | // CHECK-34-NEXT: 3 | void Test27::A::a() |
| 1241 | // CHECK-34-NEXT: 4 | void Test27::D::d() |
| 1242 | // CHECK-34-NEXT: 5 | vcall_offset (0) |
| 1243 | // CHECK-34-NEXT: 6 | offset_to_top (-16) |
| 1244 | // CHECK-34-NEXT: 7 | Test27::D RTTI |
| 1245 | // CHECK-34-NEXT: -- (Test27::B, 16) vtable address -- |
| 1246 | // CHECK-34-NEXT: 8 | void Test27::B::b() |
Anders Carlsson | f2c98ce | 2010-03-10 19:15:26 +0000 | [diff] [blame] | 1247 | struct E : D { |
| 1248 | virtual void e(); |
| 1249 | }; |
| 1250 | void E::e() { } |
Anders Carlsson | a96a2e9 | 2010-03-10 19:39:11 +0000 | [diff] [blame] | 1251 | |
| 1252 | } |
| 1253 | |
| 1254 | namespace Test28 { |
| 1255 | |
| 1256 | // Check that we do include the vtable for B in the D-in-E construction vtable, since |
| 1257 | // B is a base class of a virtual base (C). |
| 1258 | |
| 1259 | struct A { |
| 1260 | virtual void a(); |
| 1261 | }; |
| 1262 | |
| 1263 | struct B { |
| 1264 | virtual void b(); |
| 1265 | }; |
| 1266 | |
| 1267 | struct C : A, B { |
| 1268 | virtual void c(); |
| 1269 | }; |
| 1270 | |
| 1271 | struct D : virtual C { |
| 1272 | }; |
| 1273 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1274 | // CHECK-35: Vtable for 'Test28::E' (14 entries). |
| 1275 | // CHECK-35-NEXT: 0 | vbase_offset (8) |
| 1276 | // CHECK-35-NEXT: 1 | offset_to_top (0) |
| 1277 | // CHECK-35-NEXT: 2 | Test28::E RTTI |
| 1278 | // CHECK-35-NEXT: -- (Test28::D, 0) vtable address -- |
| 1279 | // CHECK-35-NEXT: -- (Test28::E, 0) vtable address -- |
| 1280 | // CHECK-35-NEXT: 3 | void Test28::E::e() |
| 1281 | // CHECK-35-NEXT: 4 | vcall_offset (8) |
| 1282 | // CHECK-35-NEXT: 5 | vcall_offset (0) |
| 1283 | // CHECK-35-NEXT: 6 | vcall_offset (0) |
| 1284 | // CHECK-35-NEXT: 7 | offset_to_top (-8) |
| 1285 | // CHECK-35-NEXT: 8 | Test28::E RTTI |
| 1286 | // CHECK-35-NEXT: -- (Test28::A, 8) vtable address -- |
| 1287 | // CHECK-35-NEXT: -- (Test28::C, 8) vtable address -- |
| 1288 | // CHECK-35-NEXT: 9 | void Test28::A::a() |
| 1289 | // CHECK-35-NEXT: 10 | void Test28::C::c() |
| 1290 | // CHECK-35-NEXT: 11 | offset_to_top (-16) |
| 1291 | // CHECK-35-NEXT: 12 | Test28::E RTTI |
| 1292 | // CHECK-35-NEXT: -- (Test28::B, 16) vtable address -- |
| 1293 | // CHECK-35-NEXT: 13 | void Test28::B::b() |
Anders Carlsson | a96a2e9 | 2010-03-10 19:39:11 +0000 | [diff] [blame] | 1294 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1295 | // CHECK-35: Construction vtable for ('Test28::D', 0) in 'Test28::E' (13 entries). |
| 1296 | // CHECK-35-NEXT: 0 | vbase_offset (8) |
| 1297 | // CHECK-35-NEXT: 1 | offset_to_top (0) |
| 1298 | // CHECK-35-NEXT: 2 | Test28::D RTTI |
| 1299 | // CHECK-35-NEXT: -- (Test28::D, 0) vtable address -- |
| 1300 | // CHECK-35-NEXT: 3 | vcall_offset (8) |
| 1301 | // CHECK-35-NEXT: 4 | vcall_offset (0) |
| 1302 | // CHECK-35-NEXT: 5 | vcall_offset (0) |
| 1303 | // CHECK-35-NEXT: 6 | offset_to_top (-8) |
| 1304 | // CHECK-35-NEXT: 7 | Test28::D RTTI |
| 1305 | // CHECK-35-NEXT: -- (Test28::A, 8) vtable address -- |
| 1306 | // CHECK-35-NEXT: -- (Test28::C, 8) vtable address -- |
| 1307 | // CHECK-35-NEXT: 8 | void Test28::A::a() |
| 1308 | // CHECK-35-NEXT: 9 | void Test28::C::c() |
| 1309 | // CHECK-35-NEXT: 10 | offset_to_top (-16) |
| 1310 | // CHECK-35-NEXT: 11 | Test28::D RTTI |
| 1311 | // CHECK-35-NEXT: -- (Test28::B, 16) vtable address -- |
| 1312 | // CHECK-35-NEXT: 12 | void Test28::B::b() |
Anders Carlsson | a96a2e9 | 2010-03-10 19:39:11 +0000 | [diff] [blame] | 1313 | struct E : D { |
| 1314 | virtual void e(); |
| 1315 | }; |
| 1316 | void E::e() { } |
| 1317 | |
Anders Carlsson | f2c98ce | 2010-03-10 19:15:26 +0000 | [diff] [blame] | 1318 | } |
Anders Carlsson | adb507d | 2010-03-29 15:08:41 +0000 | [diff] [blame] | 1319 | |
| 1320 | namespace Test29 { |
| 1321 | |
| 1322 | // Test that the covariant return thunk for B::f will have a virtual 'this' adjustment, |
| 1323 | // matching gcc. |
| 1324 | |
| 1325 | struct V1 { }; |
| 1326 | struct V2 : virtual V1 { }; |
| 1327 | |
| 1328 | struct A { |
| 1329 | virtual V1 *f(); |
| 1330 | }; |
| 1331 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1332 | // CHECK-36: Vtable for 'Test29::B' (6 entries). |
| 1333 | // CHECK-36-NEXT: 0 | vbase_offset (0) |
| 1334 | // CHECK-36-NEXT: 1 | vcall_offset (0) |
| 1335 | // CHECK-36-NEXT: 2 | offset_to_top (0) |
| 1336 | // CHECK-36-NEXT: 3 | Test29::B RTTI |
| 1337 | // CHECK-36-NEXT: -- (Test29::A, 0) vtable address -- |
| 1338 | // CHECK-36-NEXT: -- (Test29::B, 0) vtable address -- |
| 1339 | // CHECK-36-NEXT: 4 | Test29::V2 *Test29::B::f() |
| 1340 | // CHECK-36-NEXT: [return adjustment: 0 non-virtual, -24 vbase offset offset] |
| 1341 | // CHECK-36-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
| 1342 | // CHECK-36-NEXT: 5 | Test29::V2 *Test29::B::f() |
Anders Carlsson | adb507d | 2010-03-29 15:08:41 +0000 | [diff] [blame] | 1343 | struct B : virtual A { |
| 1344 | virtual V2 *f(); |
| 1345 | }; |
| 1346 | V2 *B::f() { return 0; } |
| 1347 | |
| 1348 | } |
Anders Carlsson | bdda6c1 | 2010-04-10 18:42:27 +0000 | [diff] [blame] | 1349 | |
| 1350 | namespace Test30 { |
| 1351 | |
| 1352 | // Test that we don't assert when generating a vtable for F. |
| 1353 | struct A { }; |
| 1354 | |
| 1355 | struct B : virtual A { |
| 1356 | int i; |
| 1357 | }; |
| 1358 | |
| 1359 | struct C { |
| 1360 | virtual void f(); |
| 1361 | }; |
| 1362 | |
| 1363 | struct D : virtual C, B { }; |
| 1364 | struct E : virtual D { }; |
| 1365 | |
| 1366 | struct F : E { |
| 1367 | virtual void f(); |
| 1368 | }; |
| 1369 | void F::f() { } |
| 1370 | |
| 1371 | } |
Anders Carlsson | f622b45 | 2010-04-10 20:39:29 +0000 | [diff] [blame] | 1372 | |
| 1373 | namespace Test31 { |
| 1374 | |
| 1375 | // Test that we don't add D::f twice to the primary vtable. |
| 1376 | struct A { |
| 1377 | int a; |
| 1378 | }; |
| 1379 | |
| 1380 | struct B { |
| 1381 | virtual void f(); |
| 1382 | }; |
| 1383 | |
| 1384 | struct C : A, virtual B { |
| 1385 | virtual void f(); |
| 1386 | }; |
| 1387 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1388 | // CHECK-37: Vtable for 'Test31::D' (11 entries). |
| 1389 | // CHECK-37-NEXT: 0 | vbase_offset (0) |
| 1390 | // CHECK-37-NEXT: 1 | vbase_offset (8) |
| 1391 | // CHECK-37-NEXT: 2 | vcall_offset (0) |
| 1392 | // CHECK-37-NEXT: 3 | offset_to_top (0) |
| 1393 | // CHECK-37-NEXT: 4 | Test31::D RTTI |
| 1394 | // CHECK-37-NEXT: -- (Test31::B, 0) vtable address -- |
| 1395 | // CHECK-37-NEXT: -- (Test31::D, 0) vtable address -- |
| 1396 | // CHECK-37-NEXT: 5 | void Test31::D::f() |
| 1397 | // CHECK-37-NEXT: 6 | vbase_offset (-8) |
| 1398 | // CHECK-37-NEXT: 7 | vcall_offset (-8) |
| 1399 | // CHECK-37-NEXT: 8 | offset_to_top (-8) |
| 1400 | // CHECK-37-NEXT: 9 | Test31::D RTTI |
| 1401 | // CHECK-37-NEXT: -- (Test31::C, 8) vtable address -- |
| 1402 | // CHECK-37-NEXT: 10 | void Test31::D::f() |
| 1403 | // CHECK-37-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
Anders Carlsson | f622b45 | 2010-04-10 20:39:29 +0000 | [diff] [blame] | 1404 | struct D : virtual C { |
| 1405 | virtual void f(); |
| 1406 | }; |
| 1407 | void D::f() { } |
| 1408 | |
| 1409 | } |
Anders Carlsson | 573021f | 2010-04-10 21:35:33 +0000 | [diff] [blame] | 1410 | |
| 1411 | namespace Test32 { |
| 1412 | |
| 1413 | // Check that we correctly lay out the virtual bases of 'Test32::D'. |
| 1414 | |
| 1415 | struct A { |
| 1416 | virtual void f(); |
| 1417 | }; |
| 1418 | |
| 1419 | struct B : virtual A { }; |
| 1420 | struct C : A, virtual B { }; |
| 1421 | struct D : virtual B { }; |
| 1422 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1423 | // CHECK-38: Virtual base offset offsets for 'Test32::E' (3 entries). |
| 1424 | // CHECK-38-NEXT: Test32::A | -32 |
| 1425 | // CHECK-38-NEXT: Test32::B | -24 |
| 1426 | // CHECK-38-NEXT: Test32::D | -40 |
Anders Carlsson | 573021f | 2010-04-10 21:35:33 +0000 | [diff] [blame] | 1427 | struct E : C, virtual D { |
| 1428 | virtual void f(); |
| 1429 | }; |
| 1430 | void E::f() { } |
| 1431 | |
| 1432 | } |
Anders Carlsson | af6ddf2 | 2010-04-11 20:04:11 +0000 | [diff] [blame] | 1433 | |
| 1434 | namespace Test33 { |
| 1435 | |
| 1436 | // Test that we don't emit too many vcall offsets in 'Test32::F'. |
| 1437 | |
| 1438 | struct A { |
| 1439 | virtual void a(); |
| 1440 | }; |
| 1441 | |
| 1442 | struct B { |
| 1443 | virtual void b(); |
| 1444 | }; |
| 1445 | |
| 1446 | struct C : virtual A, virtual B { |
| 1447 | virtual void c(); |
| 1448 | }; |
| 1449 | |
| 1450 | struct D : virtual C { }; |
| 1451 | |
| 1452 | struct E : A, D { |
| 1453 | virtual void e(); |
| 1454 | }; |
| 1455 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1456 | // CHECK-39: Vtable for 'Test33::F' (30 entries). |
| 1457 | // CHECK-39-NEXT: 0 | vbase_offset (24) |
| 1458 | // CHECK-39-NEXT: 1 | vbase_offset (16) |
| 1459 | // CHECK-39-NEXT: 2 | vbase_offset (16) |
| 1460 | // CHECK-39-NEXT: 3 | vbase_offset (8) |
| 1461 | // CHECK-39-NEXT: 4 | offset_to_top (0) |
| 1462 | // CHECK-39-NEXT: 5 | Test33::F RTTI |
| 1463 | // CHECK-39-NEXT: -- (Test33::A, 0) vtable address -- |
| 1464 | // CHECK-39-NEXT: -- (Test33::F, 0) vtable address -- |
| 1465 | // CHECK-39-NEXT: 6 | void Test33::A::a() |
| 1466 | // CHECK-39-NEXT: 7 | void Test33::F::f() |
| 1467 | // CHECK-39-NEXT: 8 | vcall_offset (0) |
| 1468 | // CHECK-39-NEXT: 9 | vcall_offset (0) |
| 1469 | // CHECK-39-NEXT: 10 | vbase_offset (16) |
| 1470 | // CHECK-39-NEXT: 11 | vbase_offset (8) |
| 1471 | // CHECK-39-NEXT: 12 | vbase_offset (8) |
| 1472 | // CHECK-39-NEXT: 13 | offset_to_top (-8) |
| 1473 | // CHECK-39-NEXT: 14 | Test33::F RTTI |
| 1474 | // CHECK-39-NEXT: -- (Test33::A, 8) vtable address -- |
| 1475 | // CHECK-39-NEXT: -- (Test33::E, 8) vtable address -- |
| 1476 | // CHECK-39-NEXT: 15 | void Test33::A::a() |
| 1477 | // CHECK-39-NEXT: 16 | void Test33::E::e() |
| 1478 | // CHECK-39-NEXT: 17 | vbase_offset (0) |
| 1479 | // CHECK-39-NEXT: 18 | vcall_offset (0) |
| 1480 | // CHECK-39-NEXT: 19 | vbase_offset (8) |
| 1481 | // CHECK-39-NEXT: 20 | vbase_offset (0) |
| 1482 | // CHECK-39-NEXT: 21 | vcall_offset (0) |
| 1483 | // CHECK-39-NEXT: 22 | offset_to_top (-16) |
| 1484 | // CHECK-39-NEXT: 23 | Test33::F RTTI |
| 1485 | // CHECK-39-NEXT: -- (Test33::A, 16) vtable address -- |
| 1486 | // CHECK-39-NEXT: -- (Test33::C, 16) vtable address -- |
| 1487 | // CHECK-39-NEXT: -- (Test33::D, 16) vtable address -- |
| 1488 | // CHECK-39-NEXT: 24 | void Test33::A::a() |
| 1489 | // CHECK-39-NEXT: 25 | void Test33::C::c() |
| 1490 | // CHECK-39-NEXT: 26 | vcall_offset (0) |
| 1491 | // CHECK-39-NEXT: 27 | offset_to_top (-24) |
| 1492 | // CHECK-39-NEXT: 28 | Test33::F RTTI |
| 1493 | // CHECK-39-NEXT: -- (Test33::B, 24) vtable address -- |
| 1494 | // CHECK-39-NEXT: 29 | void Test33::B::b() |
Anders Carlsson | af6ddf2 | 2010-04-11 20:04:11 +0000 | [diff] [blame] | 1495 | struct F : virtual E, A { |
| 1496 | virtual void f(); |
| 1497 | }; |
| 1498 | void F::f() { } |
| 1499 | |
| 1500 | } |
Anders Carlsson | 73e6fa0 | 2010-04-11 22:20:36 +0000 | [diff] [blame] | 1501 | |
| 1502 | namespace Test34 { |
| 1503 | |
Nick Lewycky | 69c05d5 | 2010-04-12 05:32:01 +0000 | [diff] [blame] | 1504 | // Test that we lay out the construction vtable for 'Test34::E' in 'Test34::F' correctly. |
Anders Carlsson | 73e6fa0 | 2010-04-11 22:20:36 +0000 | [diff] [blame] | 1505 | |
| 1506 | struct A { |
| 1507 | virtual void a(); |
| 1508 | }; |
| 1509 | struct B : virtual A { }; |
| 1510 | |
| 1511 | struct C : B, A { |
| 1512 | virtual void c(); |
| 1513 | }; |
| 1514 | |
| 1515 | struct D : A, C { }; |
| 1516 | |
| 1517 | struct E : virtual D { |
| 1518 | virtual void e(); |
| 1519 | }; |
| 1520 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1521 | // CHECK-40: Construction vtable for ('Test34::E', 0) in 'Test34::F' (22 entries). |
| 1522 | // CHECK-40-NEXT: 0 | vbase_offset (0) |
| 1523 | // CHECK-40-NEXT: 1 | vbase_offset (8) |
| 1524 | // CHECK-40-NEXT: 2 | vcall_offset (0) |
| 1525 | // CHECK-40-NEXT: 3 | offset_to_top (0) |
| 1526 | // CHECK-40-NEXT: 4 | Test34::E RTTI |
| 1527 | // CHECK-40-NEXT: -- (Test34::A, 0) vtable address -- |
| 1528 | // CHECK-40-NEXT: -- (Test34::E, 0) vtable address -- |
| 1529 | // CHECK-40-NEXT: 5 | void Test34::A::a() |
| 1530 | // CHECK-40-NEXT: 6 | void Test34::E::e() |
| 1531 | // CHECK-40-NEXT: 7 | vcall_offset (8) |
| 1532 | // CHECK-40-NEXT: 8 | vcall_offset (0) |
| 1533 | // CHECK-40-NEXT: 9 | vbase_offset (-8) |
| 1534 | // CHECK-40-NEXT: 10 | offset_to_top (-8) |
| 1535 | // CHECK-40-NEXT: 11 | Test34::E RTTI |
| 1536 | // CHECK-40-NEXT: -- (Test34::A, 8) vtable address -- |
| 1537 | // CHECK-40-NEXT: -- (Test34::D, 8) vtable address -- |
| 1538 | // CHECK-40-NEXT: 12 | void Test34::A::a() |
| 1539 | // CHECK-40-NEXT: 13 | vbase_offset (-16) |
| 1540 | // CHECK-40-NEXT: 14 | vcall_offset (-16) |
| 1541 | // CHECK-40-NEXT: 15 | offset_to_top (-16) |
| 1542 | // CHECK-40-NEXT: 16 | Test34::E RTTI |
| 1543 | // CHECK-40-NEXT: -- (Test34::B, 16) vtable address -- |
| 1544 | // CHECK-40-NEXT: -- (Test34::C, 16) vtable address -- |
| 1545 | // CHECK-40-NEXT: 17 | [unused] void Test34::A::a() |
| 1546 | // CHECK-40-NEXT: 18 | void Test34::C::c() |
| 1547 | // CHECK-40-NEXT: 19 | offset_to_top (-24) |
| 1548 | // CHECK-40-NEXT: 20 | Test34::E RTTI |
| 1549 | // CHECK-40-NEXT: -- (Test34::A, 24) vtable address -- |
| 1550 | // CHECK-40-NEXT: 21 | void Test34::A::a() |
Anders Carlsson | 73e6fa0 | 2010-04-11 22:20:36 +0000 | [diff] [blame] | 1551 | struct F : E { |
| 1552 | virtual void f(); |
| 1553 | }; |
| 1554 | void F::f() { } |
| 1555 | |
| 1556 | } |
Anders Carlsson | 9791357 | 2010-04-15 16:12:58 +0000 | [diff] [blame] | 1557 | |
| 1558 | namespace Test35 { |
| 1559 | |
| 1560 | // Test that we lay out the virtual bases of 'Test35::H' in the correct order. |
| 1561 | |
| 1562 | struct A { |
| 1563 | virtual void a(); |
| 1564 | |
| 1565 | int i; |
| 1566 | }; |
| 1567 | |
| 1568 | struct B : virtual A { |
| 1569 | virtual void b(); |
| 1570 | }; |
| 1571 | |
| 1572 | struct C { |
| 1573 | virtual void c(); |
| 1574 | }; |
| 1575 | |
| 1576 | struct D : C, virtual B { |
| 1577 | virtual void d(); |
| 1578 | }; |
| 1579 | |
| 1580 | struct E : D { |
| 1581 | virtual void e(); |
| 1582 | |
| 1583 | bool b; |
| 1584 | }; |
| 1585 | |
| 1586 | struct F : virtual D { }; |
| 1587 | struct G : virtual E { }; |
| 1588 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1589 | // CHECK-41: Vtable for 'Test35::H' (32 entries). |
| 1590 | // CHECK-41-NEXT: 0 | vbase_offset (32) |
| 1591 | // CHECK-41-NEXT: 1 | vbase_offset (0) |
| 1592 | // CHECK-41-NEXT: 2 | vcall_offset (0) |
| 1593 | // CHECK-41-NEXT: 3 | vcall_offset (0) |
| 1594 | // CHECK-41-NEXT: 4 | vbase_offset (16) |
| 1595 | // CHECK-41-NEXT: 5 | vbase_offset (8) |
| 1596 | // CHECK-41-NEXT: 6 | offset_to_top (0) |
| 1597 | // CHECK-41-NEXT: 7 | Test35::H RTTI |
| 1598 | // CHECK-41-NEXT: -- (Test35::C, 0) vtable address -- |
| 1599 | // CHECK-41-NEXT: -- (Test35::D, 0) vtable address -- |
| 1600 | // CHECK-41-NEXT: -- (Test35::F, 0) vtable address -- |
| 1601 | // CHECK-41-NEXT: -- (Test35::H, 0) vtable address -- |
| 1602 | // CHECK-41-NEXT: 8 | void Test35::C::c() |
| 1603 | // CHECK-41-NEXT: 9 | void Test35::D::d() |
| 1604 | // CHECK-41-NEXT: 10 | void Test35::H::h() |
| 1605 | // CHECK-41-NEXT: 11 | vbase_offset (0) |
| 1606 | // CHECK-41-NEXT: 12 | vbase_offset (24) |
| 1607 | // CHECK-41-NEXT: 13 | vcall_offset (0) |
| 1608 | // CHECK-41-NEXT: 14 | vbase_offset (8) |
| 1609 | // CHECK-41-NEXT: 15 | offset_to_top (-8) |
| 1610 | // CHECK-41-NEXT: 16 | Test35::H RTTI |
| 1611 | // CHECK-41-NEXT: -- (Test35::B, 8) vtable address -- |
| 1612 | // CHECK-41-NEXT: -- (Test35::G, 8) vtable address -- |
| 1613 | // CHECK-41-NEXT: 17 | void Test35::B::b() |
| 1614 | // CHECK-41-NEXT: 18 | vcall_offset (0) |
| 1615 | // CHECK-41-NEXT: 19 | offset_to_top (-16) |
| 1616 | // CHECK-41-NEXT: 20 | Test35::H RTTI |
| 1617 | // CHECK-41-NEXT: -- (Test35::A, 16) vtable address -- |
| 1618 | // CHECK-41-NEXT: 21 | void Test35::A::a() |
| 1619 | // CHECK-41-NEXT: 22 | vcall_offset (0) |
| 1620 | // CHECK-41-NEXT: 23 | vcall_offset (0) |
| 1621 | // CHECK-41-NEXT: 24 | vcall_offset (0) |
| 1622 | // CHECK-41-NEXT: 25 | vbase_offset (-16) |
| 1623 | // CHECK-41-NEXT: 26 | vbase_offset (-24) |
| 1624 | // CHECK-41-NEXT: 27 | offset_to_top (-32) |
| 1625 | // CHECK-41-NEXT: 28 | Test35::H RTTI |
| 1626 | // CHECK-41-NEXT: -- (Test35::C, 32) vtable address -- |
| 1627 | // CHECK-41-NEXT: -- (Test35::D, 32) vtable address -- |
| 1628 | // CHECK-41-NEXT: -- (Test35::E, 32) vtable address -- |
| 1629 | // CHECK-41-NEXT: 29 | void Test35::C::c() |
| 1630 | // CHECK-41-NEXT: 30 | void Test35::D::d() |
| 1631 | // CHECK-41-NEXT: 31 | void Test35::E::e() |
Anders Carlsson | 9791357 | 2010-04-15 16:12:58 +0000 | [diff] [blame] | 1632 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1633 | // CHECK-41: Virtual base offset offsets for 'Test35::H' (4 entries). |
| 1634 | // CHECK-41-NEXT: Test35::A | -32 |
| 1635 | // CHECK-41-NEXT: Test35::B | -24 |
| 1636 | // CHECK-41-NEXT: Test35::D | -56 |
| 1637 | // CHECK-41-NEXT: Test35::E | -64 |
Anders Carlsson | 9791357 | 2010-04-15 16:12:58 +0000 | [diff] [blame] | 1638 | struct H : F, G { |
| 1639 | virtual void h(); |
| 1640 | }; |
| 1641 | void H::h() { } |
| 1642 | |
| 1643 | } |
Anders Carlsson | fbf0561 | 2010-04-17 17:24:33 +0000 | [diff] [blame] | 1644 | |
| 1645 | namespace Test36 { |
| 1646 | |
| 1647 | // Test that we don't mark B::f as unused in the vtable for D. |
| 1648 | |
| 1649 | struct A { |
| 1650 | virtual void f(); |
| 1651 | }; |
| 1652 | |
| 1653 | struct B : virtual A { }; |
| 1654 | |
| 1655 | struct C : virtual A { |
| 1656 | virtual void f(); |
| 1657 | }; |
| 1658 | |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 1659 | // CHECK-42: Vtable for 'Test36::D' (12 entries). |
| 1660 | // CHECK-42-NEXT: 0 | vbase_offset (8) |
| 1661 | // CHECK-42-NEXT: 1 | vbase_offset (8) |
| 1662 | // CHECK-42-NEXT: 2 | vcall_offset (0) |
| 1663 | // CHECK-42-NEXT: 3 | offset_to_top (0) |
| 1664 | // CHECK-42-NEXT: 4 | Test36::D RTTI |
| 1665 | // CHECK-42-NEXT: -- (Test36::C, 0) vtable address -- |
| 1666 | // CHECK-42-NEXT: -- (Test36::D, 0) vtable address -- |
| 1667 | // CHECK-42-NEXT: 5 | void Test36::C::f() |
| 1668 | // CHECK-42-NEXT: 6 | void Test36::D::g() |
| 1669 | // CHECK-42-NEXT: 7 | vbase_offset (0) |
| 1670 | // CHECK-42-NEXT: 8 | vcall_offset (-8) |
| 1671 | // CHECK-42-NEXT: 9 | offset_to_top (-8) |
| 1672 | // CHECK-42-NEXT: 10 | Test36::D RTTI |
| 1673 | // CHECK-42-NEXT: -- (Test36::A, 8) vtable address -- |
| 1674 | // CHECK-42-NEXT: -- (Test36::B, 8) vtable address -- |
| 1675 | // CHECK-42-NEXT: 11 | void Test36::C::f() |
| 1676 | // CHECK-42-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] |
Anders Carlsson | fbf0561 | 2010-04-17 17:24:33 +0000 | [diff] [blame] | 1677 | struct D : virtual B, C { |
| 1678 | virtual void g(); |
| 1679 | }; |
| 1680 | void D::g() { } |
| 1681 | |
| 1682 | } |
Anders Carlsson | b8bced0 | 2011-04-10 18:00:32 +0000 | [diff] [blame^] | 1683 | |
| 1684 | namespace Test37 { |
| 1685 | |
| 1686 | // Test that we give C::f the right vtable index. (PR9660). |
| 1687 | struct A { |
| 1688 | virtual A* f() = 0; |
| 1689 | }; |
| 1690 | |
| 1691 | struct B : virtual A { |
| 1692 | virtual B* f(); |
| 1693 | }; |
| 1694 | |
| 1695 | // CHECK-43: VTable indices for 'Test37::C' (1 entries). |
| 1696 | // CHECK-43-NEXT: 1 | Test37::C *Test37::C::f() |
| 1697 | struct C : B { |
| 1698 | virtual C* f(); |
| 1699 | }; |
| 1700 | |
| 1701 | C* C::f() { return 0; } |
| 1702 | |
| 1703 | } |