From 404cd1669c3ba138a9ae0a619bd689cce5aae271 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 13 Nov 2010 01:35:44 +0000 Subject: Introduce a null-to-pointer implicit cast kind. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118966 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/CodeGen/CGExprScalar.cpp') diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 39f25f916b..d07d20395d 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -48,6 +48,13 @@ struct BinOpInfo { const Expr *E; // Entire expr, for error unsupported. May not be binop. }; +static bool MustVisitNullValue(const Expr *E) { + // If a null pointer expression's type is the C++0x nullptr_t, then + // it's not necessarily a simple constant and it must be evaluated + // for its potential side effects. + return E->getType()->isNullPtrType(); +} + class ScalarExprEmitter : public StmtVisitor { CodeGenFunction &CGF; @@ -1044,10 +1051,15 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { case CK_FunctionToPointerDecay: return EmitLValue(E).getAddress(); + case CK_NullToPointer: + if (MustVisitNullValue(E)) + (void) Visit(E); + + return llvm::ConstantPointerNull::get( + cast(ConvertType(DestTy))); + case CK_NullToMemberPointer: { - // If the subexpression's type is the C++0x nullptr_t, emit the - // subexpression, which may have side effects. - if (E->getType()->isNullPtrType()) + if (MustVisitNullValue(E)) (void) Visit(E); const MemberPointerType *MPT = CE->getType()->getAs(); -- cgit v1.2.3