https://github.com/lfmeadow updated https://github.com/llvm/llvm-project/pull/225162
>From f79903201822ec0d465ee819eca4ccffba53ddb9 Mon Sep 17 00:00:00 2001 From: Larry Meadows <[email protected]> Date: Mon, 21 Sep 2026 13:40:33 -0500 Subject: [PATCH] [clang][OpenMP] Don't put HIP's ::min and ::max in an OpenMP TU __clang_hip_math.h defines templated ::min and ::max for CUDA source compatibility. The OpenMP math wrapper includes that header for the amdgcn device pass, so an OpenMP translation unit -- ordinary C++ that never opted into HIP -- gets them too, and an unqualified min(a, b) after `using namespace std` becomes ambiguous against std::min. Guard them with __OPENMP_AMDGCN__, matching the host min/max block below, which is already excluded from OpenMP for the same reason. --- clang/lib/Headers/__clang_hip_math.h | 2 ++ .../amdgcn_openmp_device_math_minmax.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 clang/test/Headers/amdgcn_openmp_device_math_minmax.cpp diff --git a/clang/lib/Headers/__clang_hip_math.h b/clang/lib/Headers/__clang_hip_math.h index f0e6d46ed0af4a..c1fc112c95a4c1 100644 --- a/clang/lib/Headers/__clang_hip_math.h +++ b/clang/lib/Headers/__clang_hip_math.h @@ -1284,6 +1284,7 @@ double __fma_rn(double __x, double __y, double __z) { #endif // !defined(__cplusplus) && __STDC_VERSION__ >= 201112L #if defined(__cplusplus) +#ifndef __OPENMP_AMDGCN__ template <class T> __DEVICE__ T min(T __arg1, T __arg2) { return (__arg1 < __arg2) ? __arg1 : __arg2; } @@ -1291,6 +1292,7 @@ template <class T> __DEVICE__ T min(T __arg1, T __arg2) { template <class T> __DEVICE__ T max(T __arg1, T __arg2) { return (__arg1 > __arg2) ? __arg1 : __arg2; } +#endif __DEVICE__ int min(int __arg1, int __arg2) { return (__arg1 < __arg2) ? __arg1 : __arg2; diff --git a/clang/test/Headers/amdgcn_openmp_device_math_minmax.cpp b/clang/test/Headers/amdgcn_openmp_device_math_minmax.cpp new file mode 100644 index 00000000000000..b84d76eaaa3de4 --- /dev/null +++ b/clang/test/Headers/amdgcn_openmp_device_math_minmax.cpp @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -internal-isystem %S/Inputs/include -x c++ -fopenmp -triple x86_64-unknown-unknown -fopenmp-targets=amdgpu-amd-amdhsa -emit-llvm-bc %s -o %t-host.bc +// RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -internal-isystem %S/Inputs/include -x c++ -fopenmp -triple amdgpu-amd-amdhsa -aux-triple x86_64-unknown-unknown -fopenmp-targets=amdgpu-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-host.bc -verify -o - + +// The OpenMP math wrapper pulls in __clang_hip_math.h, whose ::min and ::max +// are a CUDA compatibility extension for HIP. In an OpenMP translation unit +// these calls are ordinary unqualified C++ lookups and must resolve to std. + +// expected-no-diagnostics + +#include <algorithm> +#include <cmath> + +using namespace std; + +long test_min(long __a, long __b) { return min(__a, __b); } + +long test_max(long __a, long __b) { return max(__a, __b); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
