https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/169252

>From 9dddf5de8a06b30bfb2647045a328e9d12fd9567 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Sun, 23 Nov 2025 14:50:16 -0800
Subject: [PATCH 1/3] [OpenCL] Add cl_khr_fp64 guard for atomic_double/double
 in cl_ext_float_atomics functions

Fix kernel build when cl_khr_fp64 is not enabled:
opencl-c.h:13785:50: error: unknown type name 'atomic_double'
 13785 | double __ovld atomic_fetch_min(volatile __global atomic_double *, 
double);
opencl-c.h:13785:67: error: use of type 'double' requires cl_khr_fp64 and 
__opencl_c_fp64 support
 13785 | double __ovld atomic_fetch_min(volatile __global atomic_double *, 
double);

This is a regression introduced by 423bdb2b. Before that commit,
__opencl_c_ext_fp64_global_atomic_add was guarded by cl_khr_fp64 in 
opencl-c-base.h.
---
 clang/lib/Headers/opencl-c.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index f65b4b314cffd..39f91c139496e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13781,6 +13781,7 @@ float __ovld atomic_fetch_max_explicit(volatile 
atomic_float *,
     defined(__opencl_c_ext_fp32_local_atomic_min_max)
 
 #if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
+#ifdef cl_khr_fp64
 #if defined(__opencl_c_ext_fp64_global_atomic_min_max)
 double __ovld atomic_fetch_min(volatile __global atomic_double *, double);
 double __ovld atomic_fetch_max(volatile __global atomic_double *, double);
@@ -13821,6 +13822,7 @@ double __ovld atomic_fetch_max_explicit(volatile 
atomic_double *,
                                         double, memory_order, memory_scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_min_max) &&                
\
     defined(__opencl_c_ext_fp64_local_atomic_min_max)
+#endif // cl_khr_fp64
 #endif // defined(cl_khr_int64_base_atomics) &&                                
\
     defined(cl_khr_int64_extended_atomics)
 
@@ -13907,6 +13909,7 @@ float __ovld atomic_fetch_sub_explicit(volatile 
atomic_float *,
     defined(__opencl_c_ext_fp32_local_atomic_add)
 
 #if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
+#ifdef cl_khr_fp64
 #if defined(__opencl_c_ext_fp64_global_atomic_add)
 double __ovld atomic_fetch_add(volatile __global atomic_double *, double);
 double __ovld atomic_fetch_sub(volatile __global atomic_double *, double);
@@ -13947,6 +13950,7 @@ double __ovld atomic_fetch_sub_explicit(volatile 
atomic_double *,
                                         double, memory_order, memory_scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_add) &&                    
\
     defined(__opencl_c_ext_fp64_local_atomic_add)
+#endif // cl_khr_fp64
 #endif // defined(cl_khr_int64_base_atomics) &&                                
\
     defined(cl_khr_int64_extended_atomics)
 

>From 1c7bc3db1124ee650b4482faca3f47f237f17b80 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Sun, 23 Nov 2025 21:51:05 -0800
Subject: [PATCH 2/3] Revert "[OpenCL] Add cl_khr_fp64 guard for
 atomic_double/double in cl_ext_float_atomics functions"

This reverts commit 9dddf5de8a06b30bfb2647045a328e9d12fd9567.
---
 clang/lib/Headers/opencl-c.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 39f91c139496e..f65b4b314cffd 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13781,7 +13781,6 @@ float __ovld atomic_fetch_max_explicit(volatile 
atomic_float *,
     defined(__opencl_c_ext_fp32_local_atomic_min_max)
 
 #if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
-#ifdef cl_khr_fp64
 #if defined(__opencl_c_ext_fp64_global_atomic_min_max)
 double __ovld atomic_fetch_min(volatile __global atomic_double *, double);
 double __ovld atomic_fetch_max(volatile __global atomic_double *, double);
@@ -13822,7 +13821,6 @@ double __ovld atomic_fetch_max_explicit(volatile 
atomic_double *,
                                         double, memory_order, memory_scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_min_max) &&                
\
     defined(__opencl_c_ext_fp64_local_atomic_min_max)
-#endif // cl_khr_fp64
 #endif // defined(cl_khr_int64_base_atomics) &&                                
\
     defined(cl_khr_int64_extended_atomics)
 
@@ -13909,7 +13907,6 @@ float __ovld atomic_fetch_sub_explicit(volatile 
atomic_float *,
     defined(__opencl_c_ext_fp32_local_atomic_add)
 
 #if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
-#ifdef cl_khr_fp64
 #if defined(__opencl_c_ext_fp64_global_atomic_add)
 double __ovld atomic_fetch_add(volatile __global atomic_double *, double);
 double __ovld atomic_fetch_sub(volatile __global atomic_double *, double);
@@ -13950,7 +13947,6 @@ double __ovld atomic_fetch_sub_explicit(volatile 
atomic_double *,
                                         double, memory_order, memory_scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_add) &&                    
\
     defined(__opencl_c_ext_fp64_local_atomic_add)
-#endif // cl_khr_fp64
 #endif // defined(cl_khr_int64_base_atomics) &&                                
\
     defined(cl_khr_int64_extended_atomics)
 

>From 9f397aa93a29ede5fce75f75fb74b5e2dda88dcc Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Sun, 23 Nov 2025 22:03:24 -0800
Subject: [PATCH 3/3] disable dependent features

---
 clang/include/clang/Basic/TargetInfo.h |  3 +++
 clang/lib/Basic/TargetInfo.cpp         | 11 +++++++++++
 clang/lib/Basic/Targets.cpp            |  1 +
 3 files changed, 15 insertions(+)

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 39af84c8d0872..1f5932225d31e 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1848,6 +1848,9 @@ class TargetInfo : public TransferrableTargetInfo,
     }
   }
 
+  /// Set features that depend on other features.
+  virtual void setDependentOpenCLOpts();
+
   /// Get supported OpenCL extensions and optional core features.
   llvm::StringMap<bool> &getSupportedOpenCLOpts() {
     return getTargetOpts().OpenCLFeaturesMap;
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 9a5db6e164f66..c0ed900ebd45c 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -640,6 +640,17 @@ bool TargetInfo::areDefaultedSMFStillPOD(const LangOptions 
&LangOpts) const {
   return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
 }
 
+void TargetInfo::setDependentOpenCLOpts() {
+  auto &Opts = getSupportedOpenCLOpts();
+  if (!hasFeatureEnabled(Opts, "cl_khr_fp64") ||
+      !hasFeatureEnabled(Opts, "__opencl_c_fp64")) {
+    setFeatureEnabled(Opts, "__opencl_c_ext_fp64_global_atomic_add", false);
+    setFeatureEnabled(Opts, "__opencl_c_ext_fp64_local_atomic_add", false);
+    setFeatureEnabled(Opts, "__opencl_c_ext_fp64_global_atomic_min_max", 
false);
+    setFeatureEnabled(Opts, "__opencl_c_ext_fp64_local_atomic_min_max", false);
+  }
+}
+
 LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
   switch (TK) {
   case OCLTK_Image:
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index f39c698b5d734..38eb1edd4bfb7 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -862,6 +862,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine 
&Diags,
 
   Target->setSupportedOpenCLOpts();
   Target->setCommandLineOpenCLOpts();
+  Target->setDependentOpenCLOpts();
   Target->setMaxAtomicWidth();
 
   if (!Opts->DarwinTargetVariantTriple.empty())

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

Reply via email to