From: Anders Carlsson Date: Sat, 27 Feb 2010 04:12:52 +0000 (+0000) Subject: Handle vcall offset sharing between destructors. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5560969d73e3e72747972d0f0f37ca4e3b042186;p=clang Handle vcall offset sharing between destructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97304 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 3c8ddfaed5..89676d4343 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -835,16 +835,20 @@ bool VCallOffsetMap::MethodsCanShareVCallOffset(const CXXMethodDecl *LHS, assert(LHS->isVirtual() && "LHS must be virtual!"); assert(RHS->isVirtual() && "LHS must be virtual!"); + // A destructor can share a vcall offset with another destructor. + if (isa(LHS)) + return isa(RHS); + // FIXME: We need to check more things here. - // Must have the same name. - // FIXME: are destructors an exception to this? + // The methods must have the same name. DeclarationName LHSName = LHS->getDeclName(); DeclarationName RHSName = RHS->getDeclName(); if (LHSName != RHSName) return false; - return (HasSameVirtualSignature(LHS, RHS)); + // And the same signatures. + return HasSameVirtualSignature(LHS, RHS); } bool VCallOffsetMap::AddVCallOffset(const CXXMethodDecl *MD, diff --git a/test/CodeGenCXX/vtable-layout.cpp b/test/CodeGenCXX/vtable-layout.cpp index abf9d13097..e3a0e8aaac 100644 --- a/test/CodeGenCXX/vtable-layout.cpp +++ b/test/CodeGenCXX/vtable-layout.cpp @@ -569,3 +569,43 @@ struct D : A, virtual B, virtual C { void D::f() { } } + +namespace Test16 { + +// Test that destructors share vcall offsets. + +struct A { virtual ~A(); }; +struct B { virtual ~B(); }; + +struct C : A, B { virtual ~C(); }; + +// CHECK: Vtable for 'Test16::D' (15 entries). +// CHECK-NEXT: 0 | vbase_offset (8) +// CHECK-NEXT: 1 | offset_to_top (0) +// CHECK-NEXT: 2 | Test16::D RTTI +// CHECK-NEXT: -- (Test16::D, 0) vtable address -- +// CHECK-NEXT: 3 | void Test16::D::f() +// CHECK-NEXT: 4 | Test16::D::~D() [complete] +// CHECK-NEXT: 5 | Test16::D::~D() [deleting] +// CHECK-NEXT: 6 | vcall_offset (-8) +// CHECK-NEXT: 7 | offset_to_top (-8) +// CHECK-NEXT: 8 | Test16::D RTTI +// CHECK-NEXT: -- (Test16::A, 8) vtable address -- +// CHECK-NEXT: -- (Test16::C, 8) vtable address -- +// CHECK-NEXT: 9 | Test16::D::~D() [complete] +// CHECK-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] +// CHECK-NEXT: 10 | Test16::D::~D() [deleting] +// CHECK-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset] +// CHECK-NEXT: 11 | offset_to_top (-16) +// CHECK-NEXT: 12 | Test16::D RTTI +// CHECK-NEXT: -- (Test16::B, 16) vtable address -- +// CHECK-NEXT: 13 | Test16::D::~D() [complete] +// CHECK-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset] +// CHECK-NEXT: 14 | Test16::D::~D() [deleting] +// CHECK-NEXT: [this adjustment: -8 non-virtual, -24 vcall offset offset] +struct D : virtual C { + virtual void f(); +}; +void D::f() { } + +}