diff options
author | Anders Carlsson <andersca@mac.com> | 2010-02-23 03:14:49 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-02-23 03:14:49 +0000 |
commit | cc6bcbb8a77aec056d29f1843b636841ae2a629c (patch) | |
tree | ca2dbd71459ab667382dc03823582c91ad9b29b0 /lib | |
parent | e5064ab8a8be7fbb8bb9727bea954c9fea7b40ab (diff) |
Simplify the vcall offset calculation and make it give the correct answers :) My test case now has the right values but in the wrong order.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96877 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGVtable.cpp | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index d8ecd0c4e5..52e82d9669 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -967,7 +967,7 @@ private: VisitedVirtualBasesSetTy &VBases); /// AddVCallOffsets - Add vcall offsets for the given base subobject. - void AddVCallOffsets(BaseSubobject Base); + void AddVCallOffsets(BaseSubobject Base, uint64_t VBaseOffset); /// AddVBaseOffsets - Add vbase offsets for the given class. void AddVBaseOffsets(const CXXRecordDecl *Base, int64_t OffsetToTop, @@ -1108,10 +1108,13 @@ VtableBuilder::AddVCallAndVBaseOffsets(BaseSubobject Base, // We only want to add vcall offsets for virtual bases. if (BaseIsVirtual && OffsetToTop != 0) - AddVCallOffsets(Base); + AddVCallOffsets(Base, Base.getBaseOffset()); } -void VtableBuilder::AddVCallOffsets(BaseSubobject Base) { +void VtableBuilder::AddVCallOffsets(BaseSubobject Base, uint64_t VBaseOffset) { + printf("adding call offsets for (%s, %llu) vbase offset %llu\n", + Base.getBase()->getQualifiedNameAsString().c_str(), + Base.getBaseOffset(), VBaseOffset); const CXXRecordDecl *RD = Base.getBase(); const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD); @@ -1122,7 +1125,8 @@ void VtableBuilder::AddVCallOffsets(BaseSubobject Base) { uint64_t PrimaryBaseOffset = Base.getBaseOffset() + Layout.getBaseClassOffset(PrimaryBase); - AddVCallOffsets(BaseSubobject(PrimaryBase, PrimaryBaseOffset)); + AddVCallOffsets(BaseSubobject(PrimaryBase, PrimaryBaseOffset), + VBaseOffset); } // Add the vcall offsets. @@ -1147,28 +1151,15 @@ void VtableBuilder::AddVCallOffsets(BaseSubobject Base) { // signature. if (!VCallOffsets.AddVCallOffset(MD, OffsetOffset)) continue; - - // Get the 'this' pointer adjustment offset. - BaseOffset ThisAdjustmentOffset = - Overriders.getThisAdjustmentOffset(Base, MD); - - int64_t Offset = 0; - if (const CXXRecordDecl *VBaseDecl = ThisAdjustmentOffset.VirtualBase) { - const ASTRecordLayout &MostDerivedClassLayout = - Context.getASTRecordLayout(MostDerivedClass); - - FinalOverriders::OverriderInfo Overrider = - Overriders.getOverrider(Base, MD); - Offset = - -(int64_t)MostDerivedClassLayout.getVBaseClassOffset(VBaseDecl); - - // The base offset should be relative to the final overrider. - Offset += Overrider.BaseOffset; - - // FIXME: We should not use / 8 here. - Offset = Offset / 8; - } + // Get the final overrider. + FinalOverriders::OverriderInfo Overrider = + Overriders.getOverrider(Base, MD); + + /// The vcall offset is the offset from the virtual base to the object where + /// the function was overridden. + // FIXME: We should not use / 8 here. + int64_t Offset = (int64_t)(Overrider.BaseOffset - VBaseOffset) / 8; VCallAndVBaseOffsets.push_back(VtableComponent::MakeVCallOffset(Offset)); } @@ -1187,7 +1178,7 @@ void VtableBuilder::AddVCallOffsets(BaseSubobject Base) { uint64_t BaseOffset = Base.getBaseOffset() + Layout.getBaseClassOffset(BaseDecl); - AddVCallOffsets(BaseSubobject(BaseDecl, BaseOffset)); + AddVCallOffsets(BaseSubobject(BaseDecl, BaseOffset), VBaseOffset); } } |