Factor vtable pointer setting code out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99773 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp
index 8a08492..2fa5837 100644
--- a/lib/CodeGen/CGClass.cpp
+++ b/lib/CodeGen/CGClass.cpp
@@ -139,7 +139,7 @@
V = Builder.CreateBitCast(V, ConvertType(Base)->getPointerTo());
return V;
-}
+}
llvm::Value *
CodeGenFunction::GetAddressOfBaseClass(llvm::Value *Value,
@@ -1556,6 +1556,34 @@
return VBaseOffset;
}
+void
+CodeGenFunction::InitializeVTablePointer(BaseSubobject Base,
+ bool BaseIsMorallyVirtual,
+ llvm::Constant *VTable,
+ const CXXRecordDecl *VTableClass) {
+
+ // Compute the address point.
+ const CodeGenVTables::AddrSubMap_t& AddressPoints =
+ CGM.getVTables().getAddressPoints(VTableClass);
+
+ uint64_t AddressPoint =
+ AddressPoints.lookup(std::make_pair(Base.getBase(), Base.getBaseOffset()));
+ llvm::Value *VTableAddressPoint =
+ Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
+
+ // 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);
+
+ // Finally, store the address point.
+ const llvm::Type *AddressPointPtrTy =
+ VTableAddressPoint->getType()->getPointerTo();
+ VTableField = Builder.CreateBitCast(VTableField, AddressPointPtrTy);
+ Builder.CreateStore(VTableAddressPoint, VTableField);
+}
+
void CodeGenFunction::InitializeVtablePtrs(const CXXRecordDecl *RD) {
if (!RD->isDynamicClass())
return;
@@ -1607,25 +1635,8 @@
InitializeVtablePtrs(BaseSubobject(BaseDecl, BaseOffset),
VTable, VTableClass);
}
-
- // Compute the address point.
- const CodeGenVTables::AddrSubMap_t& AddressPoints =
- CGM.getVTables().getAddressPoints(VTableClass);
-
- uint64_t AddressPoint =
- AddressPoints.lookup(std::make_pair(Base.getBase(), Base.getBaseOffset()));
- llvm::Value *VTableAddressPoint =
- Builder.CreateConstInBoundsGEP2_64(VTable, 0, AddressPoint);
- // 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);
-
- // Finally, store the address point.
- const llvm::Type *AddressPointPtrTy =
- VTableAddressPoint->getType()->getPointerTo();
- VTableField = Builder.CreateBitCast(VTableField, AddressPointPtrTy);
- Builder.CreateStore(VTableAddressPoint, VTableField);
+ // FIXME: BaseIsMorallyVirtual is not correct here.
+ InitializeVTablePointer(Base, /*BaseIsMorallyVirtual=*/false, VTable,
+ VTableClass);
}