bader created this revision. bader added a reviewer: Anastasia. Herald added subscribers: cfe-commits, ebevhan, yaxunl. Herald added a project: clang. bader marked an inline comment as done. bader added inline comments.
================ Comment at: clang/lib/Sema/SemaExpr.cpp:10090 // if both are pointers check if operation is valid wrt address spaces - if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) { + if ((S.getLangOpts().OpenCL || S.getLangOpts().SYCLIsDevice) && + isLHSPointer && isRHSPointer) { ---------------- Alternative approach would be to remove `S.getLangOpts().OpenCL` to enable this check for all modes. @Anastasia, do you know if it's safe to do? This change enables OpenCL diagnostics for the pointers annotated with address space attribute SYCL mode. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80317 Files: clang/lib/Sema/SemaExpr.cpp clang/test/SemaSYCL/address-space-arithmetic.cpp Index: clang/test/SemaSYCL/address-space-arithmetic.cpp =================================================================== --- /dev/null +++ clang/test/SemaSYCL/address-space-arithmetic.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s + +int *foo(__attribute__((opencl_private)) int *p, + __attribute__((opencl_local)) int *l) { + return p - l; // expected-error {{arithmetic operation with operands of type ('__private int *' and '__local int *') which are pointers to }} +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -10087,7 +10087,8 @@ if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType(); // if both are pointers check if operation is valid wrt address spaces - if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) { + if ((S.getLangOpts().OpenCL || S.getLangOpts().SYCLIsDevice) && + isLHSPointer && isRHSPointer) { const PointerType *lhsPtr = LHSExpr->getType()->castAs<PointerType>(); const PointerType *rhsPtr = RHSExpr->getType()->castAs<PointerType>(); if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) {
Index: clang/test/SemaSYCL/address-space-arithmetic.cpp =================================================================== --- /dev/null +++ clang/test/SemaSYCL/address-space-arithmetic.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsycl -fsycl-is-device -fsyntax-only -verify %s + +int *foo(__attribute__((opencl_private)) int *p, + __attribute__((opencl_local)) int *l) { + return p - l; // expected-error {{arithmetic operation with operands of type ('__private int *' and '__local int *') which are pointers to }} +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -10087,7 +10087,8 @@ if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType(); // if both are pointers check if operation is valid wrt address spaces - if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) { + if ((S.getLangOpts().OpenCL || S.getLangOpts().SYCLIsDevice) && + isLHSPointer && isRHSPointer) { const PointerType *lhsPtr = LHSExpr->getType()->castAs<PointerType>(); const PointerType *rhsPtr = RHSExpr->getType()->castAs<PointerType>(); if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits