[clang] [clang][SYCL] Implement address space attributes for SYCL (PR #200849)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 09:52:15 PDT 2026
================
@@ -1,24 +1,48 @@
// RUN: %clang_cc1 -triple spir64 -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s --check-prefix=SPIR
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsycl-is-host -emit-llvm %s -o - | FileCheck %s --check-prefix=ITANIUM
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsycl-is-host -emit-llvm %s -o - | FileCheck %s --check-prefix=MS
// REQUIRES: x86-registered-target
-void foo(__attribute__((opencl_global)) int *);
-void foo(__attribute__((opencl_local)) int *);
-void foo(__attribute__((opencl_private)) int *);
+void foo(int [[clang::sycl_global]] *);
+void foo(int [[clang::sycl_local]] *);
+void foo(int [[clang::sycl_private]] *);
+void foo(int [[clang::sycl_generic]] *);
+void foo(int [[clang::sycl_constant]] *);
void foo(int *);
// SPIR: declare spir_func void @_Z3fooPU3AS1i(ptr addrspace(1) noundef) #1
// SPIR: declare spir_func void @_Z3fooPU3AS3i(ptr addrspace(3) noundef) #1
// SPIR: declare spir_func void @_Z3fooPU3AS0i(ptr noundef) #1
+// SPIR: declare spir_func void @_Z3fooPU3AS4i(ptr addrspace(4) noundef) #1
+// SPIR: declare spir_func void @_Z3fooPU3AS2i(ptr addrspace(2) noundef) #1
// SPIR: declare spir_func void @_Z3fooPi(ptr addrspace(4) noundef) #1
----------------
tahonermann wrote:
Thank you for identifying that commit! I wasn't aware of the `-faddress-space-map-mangling=` option and have decided I don't like it because it affects ABI :)
> For example `sycl_private` and `opencl_private` would mangle the same way if mapped to same number.
That's an interesting example. As is in this PR, we allow overloading based on address space qualifier, so the following example declares two distinct functions. However, if `sycl_private` and `opencl_private` are mapped to the same address space (as we would expect them to be when targeting OpenCL), then `-faddress-space-map-mangling=yes` would result in a symbol name collision. See https://godbolt.org/z/K43oesGEM for a similar example.
```c++
void f(int [[clang::sycl_private]] *) { ... }
void f(int [[clang::opencl_private]] *) { ... }
```
The conservative thing to do would be to disallow overloading based on the SYCL address space attributes for now. I think that could be done fairly easily in `Sema::MergeFunctionDecl()`. That seems ok to do as a follow up PR; I don't see a reason to hold this one up further.
https://github.com/llvm/llvm-project/pull/200849
More information about the cfe-commits
mailing list