diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index f710b036a649..3bc8c1297462 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/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/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index d1713626ef71..3f010b17b0bc 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index fff1a84f702a..72009daef68c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/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() {