Improve support for member function pointers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83039 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index f710b03..3bc8c12 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -198,6 +198,21 @@
"Implicit cast types must be compatible");
Visit(E->getSubExpr());
break;
+
+ case CastExpr::CK_NullToMemberPointer: {
+ QualType T = E->getType();
+ const llvm::Type *PtrDiffTy =
+ CGF.ConvertType(CGF.getContext().getPointerDiffType());
+
+ llvm::Value *NullValue = llvm::Constant::getNullValue(PtrDiffTy);
+ llvm::Value *Ptr = Builder.CreateStructGEP(DestPtr, 0, "ptr");
+ Builder.CreateStore(NullValue, Ptr, VolatileDest);
+
+ llvm::Value *Adj = Builder.CreateStructGEP(DestPtr, 1, "adj");
+ Builder.CreateStore(NullValue, Adj, VolatileDest);
+
+ break;
+ }
}
}
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index d171362..3f010b1 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -785,6 +785,13 @@
return C;
}
+static inline bool isDataMemberPointerType(QualType T) {
+ if (const MemberPointerType *MPT = T->getAs<MemberPointerType>())
+ return !MPT->getPointeeType()->isFunctionType();
+
+ return false;
+}
+
llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) {
// No need to check for member pointers when not compiling C++.
if (!getContext().getLangOptions().CPlusPlus)
@@ -795,7 +802,7 @@
QualType ElementTy = CAT->getElementType();
// FIXME: Handle arrays of structs that contain member pointers.
- if (Context.getBaseElementType(ElementTy)->isMemberPointerType()) {
+ if (isDataMemberPointerType(Context.getBaseElementType(ElementTy))) {
llvm::Constant *Element = EmitNullConstant(ElementTy);
uint64_t NumElements = CAT->getSize().getZExtValue();
std::vector<llvm::Constant *> Array(NumElements);
@@ -821,7 +828,7 @@
}
// FIXME: Handle structs that contain member pointers.
- if (T->isMemberPointerType())
+ if (isDataMemberPointerType(T))
return llvm::Constant::getAllOnesValue(getTypes().ConvertTypeForMem(T));
return llvm::Constant::getNullValue(getTypes().ConvertTypeForMem(T));
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index fff1a84..72009da 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -66,7 +66,8 @@
}
bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
- return T->isRecordType() || T->isArrayType() || T->isAnyComplexType();
+ return T->isRecordType() || T->isArrayType() || T->isAnyComplexType() ||
+ T->isMemberFunctionPointerType();
}
void CodeGenFunction::EmitReturnBlock() {