aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGVtable.cpp10
-rw-r--r--test/CodeGenCXX/vtable-layout.cpp40
2 files changed, 47 insertions, 3 deletions
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<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,
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() { }
+
+}