From b358814a25a75657f7f80ee9e198834da873c76e Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Mon, 29 Mar 2010 01:14:25 +0000 Subject: [PATCH] When generating base ctors/dtors, we need to lookup virtual bases using the vtable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99790 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGClass.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index 4b5cffae85..ba66c91145 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -1595,11 +1595,22 @@ CodeGenFunction::InitializeVTablePointer(BaseSubobject Base, } // Compute where to store the address point. - const llvm::Type *Int8PtrTy = llvm::Type::getInt8PtrTy(CGM.getLLVMContext()); - llvm::Value *VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy); - VTableField = - Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8); + llvm::Value *VTableField; + if (UseNewVTableCode && + CodeGenVTables::needsVTTParameter(CurGD) && BaseIsMorallyVirtual) { + // 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()); + + VTableField = Builder.CreateBitCast(LoadCXXThis(), Int8PtrTy); + VTableField = + Builder.CreateConstInBoundsGEP1_64(VTableField, Base.getBaseOffset() / 8); + } + // Finally, store the address point. const llvm::Type *AddressPointPtrTy = VTableAddressPoint->getType()->getPointerTo(); -- 2.40.0