[PATCH] D80317: [SYCL] Prohibit arithmetic operations for incompatible pointers

Alexey Bader via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 20 13:11:17 PDT 2020


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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80317.265328.patch
Type: text/x-patch
Size: 1247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200520/529a5b1b/attachment-0001.bin>


More information about the cfe-commits mailing list