Author: stulova
Date: Wed Sep 30 08:49:55 2015
New Revision: 248902

URL: http://llvm.org/viewvc/llvm-project?rev=248902&view=rev
Log:
[OpenCL] Add missing OpenCL LangOpts in address space compatibility checks

and test checking broken (due to CL specific diagnostics) C functionality

M    test/Sema/address_spaces.c
M    lib/Sema/SemaExpr.cpp

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/Sema/address_spaces.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=248902&r1=248901&r2=248902&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 30 08:49:55 2015
@@ -7754,7 +7754,7 @@ static bool checkArithmeticBinOpPointerO
   if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType();
 
   // if both are pointers check if operation is valid wrt address spaces
-  if (isLHSPointer && isRHSPointer) {
+  if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) {
     const PointerType *lhsPtr = LHSExpr->getType()->getAs<PointerType>();
     const PointerType *rhsPtr = RHSExpr->getType()->getAs<PointerType>();
     if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) {
@@ -8783,12 +8783,14 @@ QualType Sema::CheckCompareOperands(Expr
       diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, 
/*isError*/false);
     }
     if (LCanPointeeTy != RCanPointeeTy) {
-      const PointerType *lhsPtr = LHSType->getAs<PointerType>();
-      if (!lhsPtr->isAddressSpaceOverlapping(*RHSType->getAs<PointerType>())) {
-        Diag(Loc,
-             diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
-            << LHSType << RHSType << 0 /* comparison */
-            << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+      if (getLangOpts().OpenCL) {
+        const PointerType *LHSPtr = LHSType->getAs<PointerType>();
+        if 
(!LHSPtr->isAddressSpaceOverlapping(*RHSType->getAs<PointerType>())) {
+          Diag(Loc,
+               diag::err_typecheck_op_on_nonoverlapping_address_space_pointers)
+              << LHSType << RHSType << 0 /* comparison */
+              << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
+        }
       }
       unsigned AddrSpaceL = LCanPointeeTy.getAddressSpace();
       unsigned AddrSpaceR = RCanPointeeTy.getAddressSpace();

Modified: cfe/trunk/test/Sema/address_spaces.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=248902&r1=248901&r2=248902&view=diff
==============================================================================
--- cfe/trunk/test/Sema/address_spaces.c (original)
+++ cfe/trunk/test/Sema/address_spaces.c Wed Sep 30 08:49:55 2015
@@ -67,3 +67,8 @@ void access_as_field()
 
 typedef int PR4997 __attribute__((address_space(Foobar))); // expected-error 
{{use of undeclared identifier 'Foobar'}}
 __attribute__((address_space("12"))) int *i; // expected-error 
{{'address_space' attribute requires an integer constant}}
+
+// Clang extension doesn't forbid operations on pointers to different address 
spaces.
+char* cmp(_AS1 char *x,  _AS2 char *y) {
+  return x < y ? x : y; // expected-warning {{pointer type mismatch 
('__attribute__((address_space(1))) char *' and 
'__attribute__((address_space(2))) char *')}}
+}
\ No newline at end of file


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to