[cfe-commits] r97304 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp
Anders Carlsson
andersca at mac.com
Fri Feb 26 20:12:52 PST 2010
Author: andersca
Date: Fri Feb 26 22:12:52 2010
New Revision: 97304
URL: http://llvm.org/viewvc/llvm-project?rev=97304&view=rev
Log:
Handle vcall offset sharing between destructors.
Modified:
cfe/trunk/lib/CodeGen/CGVtable.cpp
cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=97304&r1=97303&r2=97304&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Fri Feb 26 22:12:52 2010
@@ -835,16 +835,20 @@
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<CXXDestructorDecl>(LHS))
+ return isa<CXXDestructorDecl>(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,
Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=97304&r1=97303&r2=97304&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Fri Feb 26 22:12:52 2010
@@ -569,3 +569,43 @@
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() { }
+
+}
More information about the cfe-commits
mailing list