[cfe-commits] r98191 - in /cfe/trunk: lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-layout.cpp
Anders Carlsson
andersca at mac.com
Wed Mar 10 13:25:38 PST 2010
Author: andersca
Date: Wed Mar 10 15:25:37 2010
New Revision: 98191
URL: http://llvm.org/viewvc/llvm-project?rev=98191&view=rev
Log:
Fix calculation of whether a member function needs a thunk in construction vtables.
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=98191&r1=98190&r2=98191&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Wed Mar 10 15:25:37 2010
@@ -1127,14 +1127,21 @@
/// BaseOffset - The base offset of this method.
const uint64_t BaseOffset;
+ /// BaseOffsetInLayoutClass - The base offset in the layout class of this
+ /// method.
+ const uint64_t BaseOffsetInLayoutClass;
+
/// VtableIndex - The index in the vtable that this method has.
/// (For destructors, this is the index of the complete destructor).
const uint64_t VtableIndex;
- MethodInfo(uint64_t BaseOffset, uint64_t VtableIndex)
- : BaseOffset(BaseOffset), VtableIndex(VtableIndex) { }
+ MethodInfo(uint64_t BaseOffset, uint64_t BaseOffsetInLayoutClass,
+ uint64_t VtableIndex)
+ : BaseOffset(BaseOffset),
+ BaseOffsetInLayoutClass(BaseOffsetInLayoutClass),
+ VtableIndex(VtableIndex) { }
- MethodInfo() : BaseOffset(0), VtableIndex(0) { }
+ MethodInfo() : BaseOffset(0), BaseOffsetInLayoutClass(0), VtableIndex(0) { }
};
typedef llvm::DenseMap<const CXXMethodDecl *, MethodInfo> MethodInfoMapTy;
@@ -1305,15 +1312,13 @@
const CXXMethodDecl *MD = I->first;
const MethodInfo &MethodInfo = I->second;
- BaseSubobject OverriddenBaseSubobject(MD->getParent(),
- MethodInfo.BaseOffset);
-
// Get the final overrider for this method.
FinalOverriders::OverriderInfo Overrider =
- Overriders.getOverrider(OverriddenBaseSubobject, MD);
+ Overriders.getOverrider(BaseSubobject(MD->getParent(),
+ MethodInfo.BaseOffset), MD);
// Check if we need an adjustment.
- if (Overrider.OldOffset == (int64_t)MethodInfo.BaseOffset)
+ if (Overrider.Offset == MethodInfo.BaseOffsetInLayoutClass)
continue;
uint64_t VtableIndex = MethodInfo.VtableIndex;
@@ -1327,8 +1332,11 @@
VtableComponent::CK_UnusedFunctionPointer)
continue;
+ BaseSubobject OverriddenBaseSubobject(MD->getParent(),
+ MethodInfo.BaseOffsetInLayoutClass);
+
BaseSubobject OverriderBaseSubobject(Overrider.Method->getParent(),
- Overrider.OldOffset);
+ Overrider.Offset);
// Compute the adjustment offset.
BaseOffset ThisAdjustmentOffset =
@@ -1406,13 +1414,13 @@
if (Offset.VirtualBase) {
// If we have a virtual base class, the non-virtual offset is relative
// to the virtual base class offset.
- const ASTRecordLayout &MostDerivedClassLayout =
- Context.getASTRecordLayout(MostDerivedClass);
+ const ASTRecordLayout &LayoutClassLayout =
+ Context.getASTRecordLayout(LayoutClass);
/// Get the virtual base offset, relative to the most derived class
/// layout.
OffsetToBaseSubobject +=
- MostDerivedClassLayout.getVBaseClassOffset(Offset.VirtualBase);
+ LayoutClassLayout.getVBaseClassOffset(Offset.VirtualBase);
} else {
// Otherwise, the non-virtual offset is relative to the derived class
// offset.
@@ -1669,6 +1677,7 @@
MethodInfo &OverriddenMethodInfo = MethodInfoMap[OverriddenMD];
MethodInfo MethodInfo(Base.getBaseOffset(),
+ BaseOffsetInLayoutClass,
OverriddenMethodInfo.VtableIndex);
assert(!MethodInfoMap.count(MD) &&
@@ -1681,7 +1690,8 @@
}
// Insert the method info for this method.
- MethodInfo MethodInfo(Base.getBaseOffset(), Components.size());
+ MethodInfo MethodInfo(Base.getBaseOffset(), BaseOffsetInLayoutClass,
+ Components.size());
assert(!MethodInfoMap.count(MD) &&
"Should not have method info for this method yet!");
Modified: cfe/trunk/test/CodeGenCXX/vtable-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-layout.cpp?rev=98191&r1=98190&r2=98191&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-layout.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-layout.cpp Wed Mar 10 15:25:37 2010
@@ -698,6 +698,65 @@
// CHECK-NEXT: 22 | void Test18::D::f()
// CHECK-NEXT: [this adjustment: -8 non-virtual, -32 vcall offset offset]
// CHECK-NEXT: 23 | [unused] void Test18::C::g()
+
+// CHECK: Construction vtable for ('Test18::B', 0) in 'Test18::D' (7 entries).
+// CHECK-NEXT: 0 | vbase_offset (0)
+// CHECK-NEXT: 1 | vcall_offset (0)
+// CHECK-NEXT: 2 | vcall_offset (0)
+// CHECK-NEXT: 3 | offset_to_top (0)
+// CHECK-NEXT: 4 | Test18::B RTTI
+// CHECK-NEXT: -- (Test18::A, 0) vtable address --
+// CHECK-NEXT: -- (Test18::B, 0) vtable address --
+// CHECK-NEXT: 5 | void Test18::B::f()
+// CHECK-NEXT: 6 | void Test18::A::g()
+
+// CHECK: Construction vtable for ('Test18::C', 8) in 'Test18::D' (20 entries).
+// CHECK-NEXT: 0 | vcall_offset (0)
+// CHECK-NEXT: 1 | vcall_offset (0)
+// CHECK-NEXT: 2 | vbase_offset (-8)
+// CHECK-NEXT: 3 | offset_to_top (0)
+// CHECK-NEXT: 4 | Test18::C RTTI
+// CHECK-NEXT: -- (Test18::A, 8) vtable address --
+// CHECK-NEXT: -- (Test18::C, 8) vtable address --
+// CHECK-NEXT: 5 | void Test18::A::f()
+// CHECK-NEXT: 6 | void Test18::C::g()
+// CHECK-NEXT: 7 | vbase_offset (-16)
+// CHECK-NEXT: 8 | vcall_offset (-8)
+// CHECK-NEXT: 9 | vcall_offset (0)
+// CHECK-NEXT: 10 | offset_to_top (-8)
+// CHECK-NEXT: 11 | Test18::C RTTI
+// CHECK-NEXT: -- (Test18::A, 16) vtable address --
+// CHECK-NEXT: -- (Test18::B, 16) vtable address --
+// CHECK-NEXT: 12 | void Test18::B::f()
+// CHECK-NEXT: 13 | [unused] void Test18::C::g()
+// CHECK-NEXT: 14 | vcall_offset (8)
+// CHECK-NEXT: 15 | vcall_offset (16)
+// CHECK-NEXT: 16 | offset_to_top (8)
+// CHECK-NEXT: 17 | Test18::C RTTI
+// CHECK-NEXT: -- (Test18::A, 0) vtable address --
+// CHECK-NEXT: 18 | void Test18::B::f()
+// CHECK-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
+// CHECK-NEXT: 19 | void Test18::C::g()
+// CHECK-NEXT: [this adjustment: 0 non-virtual, -32 vcall offset offset]
+
+// CHECK: Construction vtable for ('Test18::B', 16) in 'Test18::D' (13 entries).
+// CHECK-NEXT: 0 | vbase_offset (-16)
+// CHECK-NEXT: 1 | vcall_offset (-16)
+// CHECK-NEXT: 2 | vcall_offset (0)
+// CHECK-NEXT: 3 | offset_to_top (0)
+// CHECK-NEXT: 4 | Test18::B RTTI
+// CHECK-NEXT: -- (Test18::A, 16) vtable address --
+// CHECK-NEXT: -- (Test18::B, 16) vtable address --
+// CHECK-NEXT: 5 | void Test18::B::f()
+// CHECK-NEXT: 6 | [unused] void Test18::A::g()
+// CHECK-NEXT: 7 | vcall_offset (0)
+// CHECK-NEXT: 8 | vcall_offset (16)
+// CHECK-NEXT: 9 | offset_to_top (16)
+// CHECK-NEXT: 10 | Test18::B RTTI
+// CHECK-NEXT: -- (Test18::A, 0) vtable address --
+// CHECK-NEXT: 11 | void Test18::B::f()
+// CHECK-NEXT: [this adjustment: 0 non-virtual, -24 vcall offset offset]
+// CHECK-NEXT: 12 | void Test18::A::g()
struct D : virtual B, virtual C, virtual A
{
virtual void f();
More information about the cfe-commits
mailing list