[clang] [HIP] Fix return type in __clang_hip_cmath.h (PR #139697)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 02:22:44 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Juan Manuel Martinez CaamaƱo (jmmartinez)
<details>
<summary>Changes</summary>
Before, some functions like `isgreater(double, double)` would return a `double` instead of a `bool`.
I've stumbled upon this bug while trying to adapt [`External/CUDA/cmath.cu`](https://github.com/llvm/llvm-test-suite/blob/main/External/CUDA/cmath.cu) to HIP.
```
/_llvm-test-suite/External/HIP/../CUDA/math_h.cu:617:20: error: static assertion failed due to requirement 'std::is_same<double, bool>::value':
617 | static_assert((std::is_same<decltype(isgreater((float)0, (double)0)), bool>::value), "");
```
---
Full diff: https://github.com/llvm/llvm-project/pull/139697.diff
1 Files Affected:
- (modified) clang/lib/Headers/__clang_hip_cmath.h (+7-6)
``````````diff
diff --git a/clang/lib/Headers/__clang_hip_cmath.h b/clang/lib/Headers/__clang_hip_cmath.h
index 7d982ad9af7ee..8039d0e12d7c9 100644
--- a/clang/lib/Headers/__clang_hip_cmath.h
+++ b/clang/lib/Headers/__clang_hip_cmath.h
@@ -464,12 +464,13 @@ class __promote : public __promote_imp<_A1, _A2, _A3> {};
#if __cplusplus >= 201103L
#define __HIP_OVERLOAD2(__retty, __fn) \
template <typename __T1, typename __T2> \
- __DEVICE__ __CONSTEXPR__ typename __hip_enable_if< \
- __hip::is_arithmetic<__T1>::value && __hip::is_arithmetic<__T2>::value, \
- typename __hip::__promote<__T1, __T2>::type>::type \
- __fn(__T1 __x, __T2 __y) { \
- typedef typename __hip::__promote<__T1, __T2>::type __result_type; \
- return __fn((__result_type)__x, (__result_type)__y); \
+ __DEVICE__ __CONSTEXPR__ \
+ typename __hip_enable_if<__hip::is_arithmetic<__T1>::value && \
+ __hip::is_arithmetic<__T2>::value, \
+ __retty>::type \
+ __fn(__T1 __x, __T2 __y) { \
+ typedef typename __hip::__promote<__T1, __T2>::type __arg_type; \
+ return __fn((__arg_type)__x, (__arg_type)__y); \
}
#else
#define __HIP_OVERLOAD2(__retty, __fn) \
``````````
</details>
https://github.com/llvm/llvm-project/pull/139697
More information about the cfe-commits
mailing list