diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-11-28 06:25:06 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-11-28 06:25:06 +0000 |
| commit | dab73ce1dc5b0398b906d828e06afadae14d3c8f (patch) | |
| tree | d38f2a12866c357d930f06fbb905418c52ae558f /clang/lib/AST/Expr.cpp | |
| parent | 02a84c8d0c8274b3a44f7f0c0268ea61b21321d9 (diff) | |
| download | bcm5719-llvm-dab73ce1dc5b0398b906d828e06afadae14d3c8f.tar.gz bcm5719-llvm-dab73ce1dc5b0398b906d828e06afadae14d3c8f.zip | |
PR39809: (const void*)0 is not a null pointer constant in C.
llvm-svn: 347730
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index ec6f084aedf..d8df83def4b 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/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<PointerType>()) { 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); } } |

