[clang] [CUDA][HIP] Mangle language address spaces by name on the device (PR #245364)

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 27 18:51:42 PST 2026


================
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple amdgpu9.00-amd-amdhsa -x hip -fcuda-is-device -emit-llvm -o - %s | FileCheck --check-prefix=DEV %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple amdgpu9.00-amd-amdhsa -x hip -emit-llvm -o - %s | FileCheck --check-prefix=HOST %s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -aux-triple amdgpu9.00-amd-amdhsa -x hip -emit-llvm -o - %s | FileCheck --check-prefix=HOST %s
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -x hip -fcuda-is-device -emit-llvm -o - %s | FileCheck --check-prefix=DEV %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple spirv64-amd-amdhsa -x hip -emit-llvm -o - %s | FileCheck --check-prefix=HOST %s
+// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -emit-llvm -o - %s | FileCheck --check-prefix=DEV %s
+// RUN: echo -n "GPU binary would be here." > %t
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -aux-triple nvptx64-nvidia-cuda -fcuda-include-gpubinary %t -emit-llvm -o - %s | FileCheck --check-prefix=HOST %s
+
+// The host registers a kernel with its device name, so both sides must mangle
+// it in the same way. A language address space is mangled by its name, and a
+// numeric one by its number.
+
+#define __global__ __attribute__((global))
+
+// DEV: define {{.*}}@_Z6kernelPU8CLglobali(
+// HOST: c"_Z6kernelPU8CLglobali\00"
+__global__ void kernel(__attribute__((opencl_global)) int *p) {}
----------------
Artem-B wrote:

Please also add test coverage for an overload pair (`__attribute__((opencl_global)) int *` vs. `__attribute__((address_space(1))) int *`, which previously collided on `_Z6kernelPU3AS1i` on the device):

```suggestion
__global__ void kernel(__attribute__((opencl_global)) int *p) {}

// DEV: define {{.*}}@_Z6kernelPU3AS1i(
// HOST: c"_Z6kernelPU3AS1i\00"
__global__ void kernel(__attribute__((address_space(1))) int *p) {}
```

And at the end of the file, a `__device__` variable template specialized on a language-AS pointer (covering registered device variable names via `getDeviceSideName`):

```cpp
template <typename T> __attribute__((device)) int var;
template __attribute__((device)) int var<__attribute__((opencl_global)) int *>;
// DEV: define {{.*}}@_Z7vkernelv(
// DEV: @_Z3varIPU8CLglobaliE
// HOST: c"_Z3varIPU8CLglobaliE\00"
__global__ void vkernel() { var<__attribute__((opencl_global)) int *> = 1; }
```

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


More information about the cfe-commits mailing list