[cfe-commits] r99807 - /cfe/trunk/lib/CodeGen/CGVtable.cpp
Anders Carlsson
andersca at mac.com
Sun Mar 28 22:40:51 PDT 2010
Author: andersca
Date: Mon Mar 29 00:40:50 2010
New Revision: 99807
URL: http://llvm.org/viewvc/llvm-project?rev=99807&view=rev
Log:
Handle pure virtual member functions.
Modified:
cfe/trunk/lib/CodeGen/CGVtable.cpp
Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=99807&r1=99806&r2=99807&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Mon Mar 29 00:40:50 2010
@@ -4049,6 +4049,8 @@
unsigned NextVTableThunkIndex = 0;
+ llvm::Constant* PureVirtualFn = 0;
+
for (unsigned I = 0; I != NumComponents; ++I) {
VtableComponent Component =
VtableComponent::getFromOpaqueInteger(Components[I]);
@@ -4091,22 +4093,37 @@
break;
}
- // Check if we should use a thunk.
- if (NextVTableThunkIndex < VTableThunks.size() &&
- VTableThunks[NextVTableThunkIndex].first == I) {
- const ThunkInfo &Thunk = VTableThunks[NextVTableThunkIndex].second;
-
- Init = CGM.GetAddrOfThunk(GD, Thunk);
+ if (cast<CXXMethodDecl>(GD.getDecl())->isPure()) {
+ // We have a pure virtual member function.
+ if (!PureVirtualFn) {
+ const llvm::FunctionType *Ty =
+ llvm::FunctionType::get(llvm::Type::getVoidTy(CGM.getLLVMContext()),
+ /*isVarArg=*/false);
+ PureVirtualFn =
+ CGM.CreateRuntimeFunction(Ty, "__cxa_pure_virtual");
+ PureVirtualFn = llvm::ConstantExpr::getBitCast(PureVirtualFn,
+ Int8PtrTy);
+ }
- NextVTableThunkIndex++;
+ Init = PureVirtualFn;
} else {
- const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
- const llvm::Type *Ty = CGM.getTypes().GetFunctionTypeForVtable(MD);
+ // Check if we should use a thunk.
+ if (NextVTableThunkIndex < VTableThunks.size() &&
+ VTableThunks[NextVTableThunkIndex].first == I) {
+ const ThunkInfo &Thunk = VTableThunks[NextVTableThunkIndex].second;
+
+ Init = CGM.GetAddrOfThunk(GD, Thunk);
+
+ NextVTableThunkIndex++;
+ } else {
+ const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
+ const llvm::Type *Ty = CGM.getTypes().GetFunctionTypeForVtable(MD);
- Init = CGM.GetAddrOfFunction(GD, Ty);
+ Init = CGM.GetAddrOfFunction(GD, Ty);
+ }
+
+ Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
}
-
- Init = llvm::ConstantExpr::getBitCast(Init, Int8PtrTy);
break;
}
@@ -4137,11 +4154,8 @@
if (GV) {
// Check if the variable has the right type.
- if (GV->getType()->getElementType() == Ty) {
- // Set the correct linkage.
- GV->setLinkage(Linkage);
+ if (GV->getType()->getElementType() == Ty)
return GV;
- }
assert(GV->isDeclaration() && "Declaration has wrong type!");
@@ -4221,6 +4235,9 @@
CreateVTableInitializer(RD, getVTableComponentsData(RD),
getNumVTableComponents(RD), Thunks);
VTable->setInitializer(Init);
+
+ // Set the correct linkage.
+ VTable->setLinkage(Linkage);
}
llvm::GlobalVariable *
More information about the cfe-commits
mailing list