https://github.com/jhuber6 updated 
https://github.com/llvm/llvm-project/pull/67981

>From 3ce25920eb83ed2e859050fd24dada7b232e0431 Mon Sep 17 00:00:00 2001
From: Joseph Huber <jhub...@vols.utk.edu>
Date: Mon, 2 Oct 2023 07:25:03 -0500
Subject: [PATCH] [Clang] Fix HIP wrapper inclusion of 'algorithm' when using
 libc++

Summary:
The `algorithm` header included here sometimes caused issues when using
`libc++` over `libstdc++`. This was primarily because  of the order they
were included in. This patch just gets rid of this dependency as it was
only used for min and max which are trivial to reimplement.

Fixes: https://github.com/llvm/llvm-project/issues/67938
---
 clang/lib/Headers/__clang_hip_math.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Headers/__clang_hip_math.h 
b/clang/lib/Headers/__clang_hip_math.h
index 58aa55d74769031..11e1e7d032586f8 100644
--- a/clang/lib/Headers/__clang_hip_math.h
+++ b/clang/lib/Headers/__clang_hip_math.h
@@ -14,9 +14,6 @@
 #endif
 
 #if !defined(__HIPCC_RTC__)
-#if defined(__cplusplus)
-#include <algorithm>
-#endif
 #include <limits.h>
 #include <stdint.h>
 #ifdef __OPENMP_AMDGCN__
@@ -1311,11 +1308,11 @@ double min(double __x, double __y) { return 
__builtin_fmin(__x, __y); }
 
 #if !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 __host__ inline static int min(int __arg1, int __arg2) {
-  return std::min(__arg1, __arg2);
+  return __arg1 < __arg2 ? __arg1 : __arg2;
 }
 
 __host__ inline static int max(int __arg1, int __arg2) {
-  return std::max(__arg1, __arg2);
+  return __arg1 > __arg2 ? __arg1 : __arg2;
 }
 #endif // !defined(__HIPCC_RTC__) && !defined(__OPENMP_AMDGCN__)
 #endif

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to