[clang] [clang][SYCL] Implement address space attributes for SYCL (PR #200849)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 3 12:53:11 PDT 2026


================
@@ -873,6 +873,107 @@ expression.
   }];
 }
 
+def SYCLAddressSpaceDocs : Documentation {
+  let Category = DocCatType;
+  let Heading = "SYCL Address Spaces";
+  let Content = [{
+.. note::
+
+   These attributes are intended for use in the implementation of SYCL run-time
+   libraries and should not be used in any other context.
+   Programmers writing code intended to conform to the SYCL specification should
+   use the address space facilities specified in the following sections of the
+   SYCL 2020 specification.
+
+   * `4.7.2, "Buffers" <SYCL-2020-4.7.2_>`_
+   * `4.7.6, "Accessors" <SYCL-2020-4.7.6_>`_.
+   * `4.7.7, "Address space classes" <SYCL-2020-4.7.7_>`_.
+   * `F.7, "sycl_khr_static_addrspace_cast" <SYCL-2020-F.7_>`_.
+   * `F.8, "sycl_khr_dynamic_addrspace_cast" <SYCL-2020-F.8_>`_.
+
+The SYCL address space attributes listed below correspond to the five address
+spaces described by
+`SYCL 2020 section 3.8.2, "SYCL device memory model" <SYCL-2020-3.8.2_>`_ and
+`SYCL 2020 section 4.7.7, "Address space classes" <SYCL-2020-4.7.7_>`_.
+
+.. list-table::
+   :header-rows: 1
+
+   * - Address space attribute
+     - SYCL address space
+     - Description
+   * - ``[[clang::sycl_global]]``
+     - global
+     - A memory region accessible by all work-items executing on a device.
+   * - ``[[clang::sycl_local]]``
+     - local
+     - A memory region accessible by all work-items of a single work-group.
+   * - ``[[clang::sycl_private]]``
+     - private
+     - A memory region that is private to a single work-item.
+   * - ``[[clang::sycl_generic]]``
+     - generic
+     - A virtual memory region from which the global, local, and private memory
+       regions may all be accessed.
+   * - ``[[clang::sycl_constant]]``
+     - constant
+     - (*deprecated*) A memory region that holds constant data for an executing
+       kernel.
+
+The SYCL address space attributes are type attributes that may be applied to
+the object type of an object pointer or object reference type.
+A type specifier with a SYCL address space specifies a distinct type from the
+otherwise unattributed type.
+For example, ``int *`` and ``int [[clang::sycl_global]]*`` designate distinct
+pointer types which participate in overload resolution and template
+specialization.
+
+Conversions between SYCL address space attributed types are permitted as
+follows.
+
+* Types attributed with the global, local, or private address space attributes
+  are implicitly convertible to matching types with the generic address space
+  attribute.
+* Types attributed with the generic address space attribute may be converted
----------------
elizabethandrews wrote:

>> My intention is that the SYCL address space attributes are consistent with the generic address space attributes, at least with regard to appertainment. The quoted sentence is intended to communicate that, e.g., [[clang::sycl_global]] int* and [[clang::sycl_global]] int& are pointer/reference types for an object of type int located in the SYCL global address space.

I read this line in context of this test you provided in an earlier comment. 

```
using global_int = int [[clang::sycl_global]]; // Ok.
using global_int_ptr = global_int*; // Ok.
global_int bad10; // Invalid.
```
 `int __attribute__((address_space(1))) bad10;` is valid code. The generic attributes accepts a namespace scope variable of an address space qualified type. Only automatic variables are rejected.  SYCL currently accepts this too. OpenCL also accepts program scope `__global` variables.  Do you expect SYCL to diverge from generic and openCL handling? 



https://github.com/llvm/llvm-project/pull/200849


More information about the cfe-commits mailing list