diff options
author | Anders Carlsson <andersca@mac.com> | 2010-04-20 16:22:16 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2010-04-20 16:22:16 +0000 |
commit | 36fd6beef1ffaf93217d8ce96d900d4ed817e463 (patch) | |
tree | 23f7f9f4744507e22b022889ddd19d458edaf431 /lib/CodeGen/CGClass.cpp | |
parent | 9dc228a1b971aa884766a9bdfdf5fa8ee4730b5b (diff) |
Fix a bug which triggered the assertion I added yesterday. Basically, when we initialize the vtable pointer for a virtual base, and there was another path from the most derived class to another base with the same class type, we would use the wrong base.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101911 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGClass.cpp')
-rw-r--r-- | lib/CodeGen/CGClass.cpp | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index a21af413fd..b2991ade43 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -1549,6 +1549,7 @@ CodeGenFunction::GetVirtualBaseClassOffset(llvm::Value *This, void CodeGenFunction::InitializeVTablePointer(BaseSubobject Base, const CXXRecordDecl *NearestVBase, + uint64_t BaseOffsetFromNearestVBase, llvm::Constant *VTable, const CXXRecordDecl *VTableClass) { const CXXRecordDecl *RD = Base.getBase(); @@ -1576,22 +1577,32 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base, Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint); } + llvm::Value *VTableField = LoadCXXThis(); + // Compute where to store the address point. - llvm::Value *VTableField; - - if (CodeGenVTables::needsVTTParameter(CurGD) && NearestVBase) { - // We need to use the virtual base offset offset because the virtual base - // might have a different offset in the most derived class. - VTableField = GetAddressOfBaseClass(LoadCXXThis(), VTableClass, RD, - /*NullCheckValue=*/false); - } else { - const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext()); + uint64_t NonVirtualOffset = BaseOffsetFromNearestVBase; - VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy); - VTableField = - Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8); + llvm::Value *VirtualOffset = 0; + if (NearestVBase) { + if (!CodeGenVTables::needsVTTParameter(CurGD)) { + // Just get the vbase offset in the complete class. + const ASTRecordLayout &Layout = + getContext().getASTRecordLayout(VTableClass); + + NonVirtualOffset += Layout.getVBaseClassOffset(NearestVBase); + } else { + // We need to use the virtual base offset offset because the virtual base + // might have a different offset in the most derived class. + VirtualOffset = GetVirtualBaseClassOffset(VTableField, + VTableClass, NearestVBase); + } } + if (NonVirtualOffset || VirtualOffset) + VTableField = + ApplyNonVirtualAndVirtualOffset(*this, VTableField, + NonVirtualOffset, VirtualOffset); + // Finally, store the address point. const llvm::Type *AddressPointPtrTy = VTableAddressPoint->getType()->getPointerTo(); @@ -1602,6 +1613,7 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base, void CodeGenFunction::InitializeVTablePointers(BaseSubobject Base, const CXXRecordDecl *NearestVBase, + uint64_t BaseOffsetFromNearestVBase, bool BaseIsNonVirtualPrimaryBase, llvm::Constant *VTable, const CXXRecordDecl *VTableClass, @@ -1610,7 +1622,8 @@ CodeGenFunction::InitializeVTablePointers(BaseSubobject Base, // been set. if (!BaseIsNonVirtualPrimaryBase) { // Initialize the vtable pointer for this base. - InitializeVTablePointer(Base, NearestVBase, VTable, VTableClass); + InitializeVTablePointer(Base, NearestVBase, BaseOffsetFromNearestVBase, + VTable, VTableClass); } const CXXRecordDecl *RD = Base.getBase(); @@ -1647,6 +1660,7 @@ CodeGenFunction::InitializeVTablePointers(BaseSubobject Base, InitializeVTablePointers(BaseSubobject(BaseDecl, BaseOffset), I->isVirtual() ? BaseDecl : NearestVBase, + I->isVirtual() ? 0 : BaseOffsetFromNearestVBase, BaseDeclIsNonVirtualPrimaryBase, VTable, VTableClass, VBases); } @@ -1663,6 +1677,7 @@ void CodeGenFunction::InitializeVTablePointers(const CXXRecordDecl *RD) { // Initialize the vtable pointers for this class and all of its bases. VisitedVirtualBasesSetTy VBases; InitializeVTablePointers(BaseSubobject(RD, 0), /*NearestVBase=*/0, + /*BaseOffsetFromNearestVBase=*/0, /*BaseIsNonVirtualPrimaryBase=*/false, VTable, RD, VBases); } |