https://github.com/jmmartinez created 
https://github.com/llvm/llvm-project/pull/172293

Allows for type checking depending on the builtin signature.

From 85116001e0eed56e047717b0d25d1e9898b9898e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
 <[email protected]>
Date: Mon, 15 Dec 2025 12:32:32 +0100
Subject: [PATCH 1/2] [NFC][Clang] Add HIP Sema test for
 __builtin_amdgcn_ds_atomic_fadd_f32/f64

---
 clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip

diff --git a/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip 
b/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip
new file mode 100644
index 0000000000000..c13cb2b103853
--- /dev/null
+++ b/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx90a -verify %s 
-fcuda-is-device
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn -verify %s
+// expected-no-diagnostics
+
+#define __device__ __attribute__((device))
+#define __shared__ __attribute__((shared))
+
+__device__ void test_ds_atomic_fadd_f32_valid(__shared__ float *lds_ptr, float 
val) {
+  float result;
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr, val);
+}
+
+__device__ void test_ds_atomic_fadd_f32_errors(__shared__ float *lds_ptr, 
float val, 
+                                                __shared__ double *lds_ptr_d,
+                                                float *global_ptr) {
+  float result;
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr, val, 0);
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(global_ptr, val);
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr_d, val);
+}
+
+__device__ void test_ds_atomic_fadd_f64_valid(__shared__ double *lds_ptr, 
double val) {
+  double result;
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr, val);
+}
+
+__device__ void test_ds_atomic_fadd_f64_errors(__shared__ double *lds_ptr, 
double val,
+                                                __shared__ float *lds_ptr_f,
+                                                double *global_ptr) {
+  double result;
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr, val, 0);
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(global_ptr, val);
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr_f, val);
+}

From 46ff53debe6f1e63a7bc28ce037d0df060da75c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?=
 <[email protected]>
Date: Mon, 15 Dec 2025 12:38:23 +0100
Subject: [PATCH 2/2] [Clang] Remove 't' from
 __builtin_amdgcn_ds_atomic_fadd_f32/f64

---
 clang/include/clang/Basic/BuiltinsAMDGPU.def |  4 ++--
 clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip | 13 ++++++-------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index a867144d83928..88b306462a92c 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -276,8 +276,8 @@ TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f64, 
"dd*0d", "t", "gfx90a-inst
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fmin_f64, "dd*0d", "t", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fmax_f64, "dd*0d", "t", 
"gfx90a-insts")
 
-TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f64, "dd*3d", "t", 
"gfx90a-insts")
-TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f32, "ff*3f", "t", "gfx8-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f64, "dd*3d", "", 
"gfx90a-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f32, "ff*3f", "", "gfx8-insts")
 
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f32, "ff*0f", "t", 
"gfx940-insts")
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2f16, "V2hV2h*0V2h", "t", 
"atomic-flat-pk-add-16-insts")
diff --git a/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip 
b/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip
index c13cb2b103853..840b26e52cc25 100644
--- a/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip
+++ b/clang/test/SemaHIP/amdgpu-ds-atomic-fadd.hip
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx90a -verify %s 
-fcuda-is-device
-// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn -verify %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -triple amdgcn -target-cpu gfx90a 
-verify=device,both %s -fcuda-is-device
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64 -aux-triple amdgcn 
-verify=host,both %s
 
 #define __device__ __attribute__((device))
 #define __shared__ __attribute__((shared))
@@ -14,9 +13,9 @@ __device__ void test_ds_atomic_fadd_f32_errors(__shared__ 
float *lds_ptr, float
                                                 __shared__ double *lds_ptr_d,
                                                 float *global_ptr) {
   float result;
-  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr, val, 0);
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr, val, 0); // 
both-error{{too many arguments to function call, expected 2, have 3}}
   result = __builtin_amdgcn_ds_atomic_fadd_f32(global_ptr, val);
-  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr_d, val);
+  result = __builtin_amdgcn_ds_atomic_fadd_f32(lds_ptr_d, val); // 
device-error{{cannot initialize a parameter of type '__shared__ float *' with 
an rvalue of type '__shared__ double *'}} host-error{{cannot initialize a 
parameter of type '__attribute__((address_space(3))) float *' with an rvalue of 
type '__attribute__((address_space(3))) double *'}}
 }
 
 __device__ void test_ds_atomic_fadd_f64_valid(__shared__ double *lds_ptr, 
double val) {
@@ -28,7 +27,7 @@ __device__ void test_ds_atomic_fadd_f64_errors(__shared__ 
double *lds_ptr, doubl
                                                 __shared__ float *lds_ptr_f,
                                                 double *global_ptr) {
   double result;
-  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr, val, 0);
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr, val, 0); // 
both-error{{too many arguments to function call, expected 2, have 3}}
   result = __builtin_amdgcn_ds_atomic_fadd_f64(global_ptr, val);
-  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr_f, val);
+  result = __builtin_amdgcn_ds_atomic_fadd_f64(lds_ptr_f, val); // 
device-error{{cannot initialize a parameter of type '__shared__ double *' with 
an rvalue of type '__shared__ float *'}} host-error{{cannot initialize a 
parameter of type '__attribute__((address_space(3))) double *' with an rvalue 
of type '__attribute__((address_space(3))) float *'}}
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to