From 8bad1cc33ed6653ba116a33ad85d29ce3e34d5d9 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 28 Nov 2018 06:25:06 +0000 Subject: PR39809: (const void*)0 is not a null pointer constant in C. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347730 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index ec6f084aed..d8df83def4 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -3441,20 +3441,20 @@ Expr::isNullPointerConstant(ASTContext &Ctx, // Check that it is a cast to void*. if (const PointerType *PT = CE->getType()->getAs()) { QualType Pointee = PT->getPointeeType(); + Qualifiers Qs = Pointee.getQualifiers(); // Only (void*)0 or equivalent are treated as nullptr. If pointee type // has non-default address space it is not treated as nullptr. // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr // since it cannot be assigned to a pointer to constant address space. - bool PointeeHasDefaultAS = - Pointee.getAddressSpace() == LangAS::Default || - (Ctx.getLangOpts().OpenCLVersion >= 200 && + if ((Ctx.getLangOpts().OpenCLVersion >= 200 && Pointee.getAddressSpace() == LangAS::opencl_generic) || (Ctx.getLangOpts().OpenCL && Ctx.getLangOpts().OpenCLVersion < 200 && - Pointee.getAddressSpace() == LangAS::opencl_private); + Pointee.getAddressSpace() == LangAS::opencl_private)) + Qs.removeAddressSpace(); - if (PointeeHasDefaultAS && Pointee->isVoidType() && // to void* - CE->getSubExpr()->getType()->isIntegerType()) // from int. + if (Pointee->isVoidType() && Qs.empty() && // to void* + CE->getSubExpr()->getType()->isIntegerType()) // from int return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); } } -- cgit v1.2.1