diff options
| author | Anastasia Stulova <anastasia.stulova@arm.com> | 2015-12-11 17:41:19 +0000 | 
|---|---|---|
| committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2015-12-11 17:41:19 +0000 | 
| commit | 2446b8ba8aef6a3616c89bc28162cbd5ff1d7522 (patch) | |
| tree | dacc6497b7050bba7df71f4edfda914299c048fe | |
| parent | eaf11626874bf79cd87d4f8cae642144f354aa73 (diff) | |
| download | bcm5719-llvm-2446b8ba8aef6a3616c89bc28162cbd5ff1d7522.tar.gz bcm5719-llvm-2446b8ba8aef6a3616c89bc28162cbd5ff1d7522.zip  | |
[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
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 17 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaOpenCL/null_literal.cl | 29 | 
3 files changed, 45 insertions, 4 deletions
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<PointerType>()) {          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);        }      } diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b479ee497f2..9bbc304e2e2 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -8806,7 +8806,8 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,        diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, /*isError*/false);      }      if (LCanPointeeTy != RCanPointeeTy) { -      if (getLangOpts().OpenCL) { +      // Treat NULL constant as a special case in OpenCL. +      if (getLangOpts().OpenCL && !LHSIsNull && !RHSIsNull) {          const PointerType *LHSPtr = LHSType->getAs<PointerType>();          if (!LHSPtr->isAddressSpaceOverlapping(*RHSType->getAs<PointerType>())) {            Diag(Loc, diff --git a/clang/test/SemaOpenCL/null_literal.cl b/clang/test/SemaOpenCL/null_literal.cl new file mode 100644 index 00000000000..2fb287270f4 --- /dev/null +++ b/clang/test/SemaOpenCL/null_literal.cl @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -verify %s +// RUN: %clang_cc1 -cl-std=CL2.0 -DCL20 -verify %s + +#define NULL ((void*)0) + +void foo(){ + +global int* ptr1 = NULL; + +global int* ptr2 = (global void*)0; + +constant int* ptr3 = NULL; + +constant int* ptr4 = (global void*)0; // expected-error{{initializing '__constant int *' with an expression of type '__global void *' changes address space of pointer}} + +#ifdef CL20 +// Accept explicitly pointer to generic address space in OpenCL v2.0. +global int* ptr5 = (generic void*)0; +#endif + +global int* ptr6 = (local void*)0; // expected-error{{initializing '__global int *' with an expression of type '__local void *' changes address space of pointer}} + +bool cmp = ptr1 == NULL; + +cmp = ptr1 == (local void*)0; // expected-error{{comparison between  ('__global int *' and '__local void *') which are pointers to non-overlapping address spaces}} + +cmp = ptr3 == NULL; + +}  | 

