From 2446b8ba8aef6a3616c89bc28162cbd5ff1d7522 Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Fri, 11 Dec 2015 17:41:19 +0000 Subject: [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in generic address space unless address space is explicitly specified. Correct the behavior of NULL constant detection - generic AS void pointer should be accepted as a valid NULL constant. http://reviews.llvm.org/D15293 llvm-svn: 255346 --- clang/lib/AST/Expr.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'clang/lib/AST/Expr.cpp') diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 69b1121f3dc..b09824483a2 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -3293,9 +3293,20 @@ Expr::isNullPointerConstant(ASTContext &Ctx, // Check that it is a cast to void*. if (const PointerType *PT = CE->getType()->getAs()) { QualType Pointee = PT->getPointeeType(); - if (!Pointee.hasQualifiers() && - Pointee->isVoidType() && // to void* - CE->getSubExpr()->getType()->isIntegerType()) // from int. + Qualifiers Q = Pointee.getQualifiers(); + // In OpenCL v2.0 generic address space acts as a placeholder + // and should be ignored. + bool IsASValid = true; + if (Ctx.getLangOpts().OpenCLVersion >= 200) { + if (Pointee.getAddressSpace() == LangAS::opencl_generic) + Q.removeAddressSpace(); + else + IsASValid = false; + } + + if (IsASValid && !Q.hasQualifiers() && + Pointee->isVoidType() && // to void* + CE->getSubExpr()->getType()->isIntegerType()) // from int. return CE->getSubExpr()->isNullPointerConstant(Ctx, NPC); } } -- cgit v1.2.3