From 703a08605f7f1972d8742c91dba4dbf8c2fb23f9 Mon Sep 17 00:00:00 2001 From: Anders Carlsson <andersca@mac.com> Date: Wed, 10 Mar 2010 19:15:26 +0000 Subject: [PATCH] Ignore non-interesting bases when emitting construction vtables. llvm-svn: 98177 --- clang/lib/CodeGen/CGVtable.cpp | 11 +++++ clang/test/CodeGenCXX/vtable-layout.cpp | 60 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp index 4500ec033cd8..caf1e1f93e48 100644 --- a/clang/lib/CodeGen/CGVtable.cpp +++ b/clang/lib/CodeGen/CGVtable.cpp @@ -1800,6 +1800,17 @@ void VtableBuilder::LayoutSecondaryVtables(BaseSubobject Base, if (!BaseDecl->isDynamicClass()) continue; + if (isBuildingConstructorVtable()) { + // Itanium C++ ABI 2.6.4: + // Some of the base class subobjects may not need construction virtual + // tables, which will therefore not be present in the construction + // virtual table group, even though the subobject virtual tables are + // present in the main virtual table group for the complete object. + if (!BaseDecl->getNumVBases()) { + continue; + } + } + // Get the base offset of this base. uint64_t RelativeBaseOffset = Layout.getBaseClassOffset(BaseDecl); uint64_t BaseOffset = Base.getBaseOffset() + RelativeBaseOffset; diff --git a/clang/test/CodeGenCXX/vtable-layout.cpp b/clang/test/CodeGenCXX/vtable-layout.cpp index 5c783f1f23dc..19619d0f2b8e 100644 --- a/clang/test/CodeGenCXX/vtable-layout.cpp +++ b/clang/test/CodeGenCXX/vtable-layout.cpp @@ -1091,3 +1091,63 @@ class D : virtual B, virtual C { void D::d() { } } + +namespace Test27 { + +// Test that we don't generate a secondary vtable for C in the D-in-E vtable, since +// C doesn't have any virtual bases. + +struct A { + virtual void a(); +}; + +struct B { + virtual void b(); +}; + +struct C { + virtual void c(); +}; + +struct D : A, virtual B, C { + virtual void d(); +}; + +// CHECK: Vtable for 'Test27::E' (13 entries). +// CHECK-NEXT: 0 | vbase_offset (16) +// CHECK-NEXT: 1 | offset_to_top (0) +// CHECK-NEXT: 2 | Test27::E RTTI +// CHECK-NEXT: -- (Test27::A, 0) vtable address -- +// CHECK-NEXT: -- (Test27::D, 0) vtable address -- +// CHECK-NEXT: -- (Test27::E, 0) vtable address -- +// CHECK-NEXT: 3 | void Test27::A::a() +// CHECK-NEXT: 4 | void Test27::D::d() +// CHECK-NEXT: 5 | void Test27::E::e() +// CHECK-NEXT: 6 | offset_to_top (-8) +// CHECK-NEXT: 7 | Test27::E RTTI +// CHECK-NEXT: -- (Test27::C, 8) vtable address -- +// CHECK-NEXT: 8 | void Test27::C::c() +// CHECK-NEXT: 9 | vcall_offset (0) +// CHECK-NEXT: 10 | offset_to_top (-16) +// CHECK-NEXT: 11 | Test27::E RTTI +// CHECK-NEXT: -- (Test27::B, 16) vtable address -- +// CHECK-NEXT: 12 | void Test27::B::b() + +// CHECK: Construction vtable for ('Test27::D', 0) in 'Test27::E' (9 entries). +// CHECK-NEXT: 0 | vbase_offset (16) +// CHECK-NEXT: 1 | offset_to_top (0) +// CHECK-NEXT: 2 | Test27::D RTTI +// CHECK-NEXT: -- (Test27::A, 0) vtable address -- +// CHECK-NEXT: -- (Test27::D, 0) vtable address -- +// CHECK-NEXT: 3 | void Test27::A::a() +// CHECK-NEXT: 4 | void Test27::D::d() +// CHECK-NEXT: 5 | vcall_offset (0) +// CHECK-NEXT: 6 | offset_to_top (-16) +// CHECK-NEXT: 7 | Test27::D RTTI +// CHECK-NEXT: -- (Test27::B, 16) vtable address -- +// CHECK-NEXT: 8 | void Test27::B::b() +struct E : D { + virtual void e(); +}; +void E::e() { } +} -- GitLab