diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp --- a/clang/lib/Sema/SemaExpr.cpp +++ b/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(); const PointerType *rhsPtr = RHSExpr->getType()->castAs(); if (!lhsPtr->isAddressSpaceOverlapping(*rhsPtr)) { diff --git a/clang/test/SemaSYCL/address-space-arithmetic.cpp b/clang/test/SemaSYCL/address-space-arithmetic.cpp new file mode 100644 --- /dev/null +++ b/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 }} +}