From e9d34dc7afe06c9adaacad7a678a0cbbf749ea75 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 29 Sep 2009 02:09:01 +0000 Subject: [PATCH] Improve support for member function pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@83039 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprAgg.cpp | 15 +++++++++++++++ lib/CodeGen/CGExprConstant.cpp | 11 +++++++++-- lib/CodeGen/CodeGenFunction.cpp | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index f710b036a6..3bc8c12974 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -198,6 +198,21 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { "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 d1713626ef..3f010b17b0 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -785,6 +785,13 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E, return C; } +static inline bool isDataMemberPointerType(QualType T) { + if (const MemberPointerType *MPT = T->getAs()) + 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 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { 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 Array(NumElements); @@ -821,7 +828,7 @@ llvm::Constant *CodeGenModule::EmitNullConstant(QualType T) { } // 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 fff1a84f70..72009daef6 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -66,7 +66,8 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) { } bool CodeGenFunction::hasAggregateLLVMType(QualType T) { - return T->isRecordType() || T->isArrayType() || T->isAnyComplexType(); + return T->isRecordType() || T->isArrayType() || T->isAnyComplexType() || + T->isMemberFunctionPointerType(); } void CodeGenFunction::EmitReturnBlock() { -- 2.40.0