Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HIP] Fix return type in __clang_hip_cmath.h #139697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025

Conversation

jmmartinez
Copy link
Contributor

@jmmartinez jmmartinez commented May 13, 2025

Before, some functions like isgreater(float, double) would return a double instead of a bool.

I've stumbled upon this bug while trying to adapt 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), "");

@jmmartinez jmmartinez requested a review from yxsamliu May 13, 2025 09:22
@jmmartinez jmmartinez self-assigned this May 13, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels May 13, 2025
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-x86

Author: Juan Manuel Martinez Caamaño (jmmartinez)

Changes

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 to HIP.

/_llvm-test-suite/External/HIP/../CUDA/math_h.cu:617:20: error: static assertion failed due to requirement 'std::is_same&lt;double, bool&gt;::value':
617 |     static_assert((std::is_same&lt;decltype(isgreater((float)0, (double)0)), bool&gt;::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 --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)                                         \

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs header test

@jmmartinez
Copy link
Contributor Author

jmmartinez commented May 14, 2025

Added tests and created a separate PR to commit the tests before the fix in #139891

Copy link
Collaborator

@yxsamliu yxsamliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

Before, some functions like std::isgreater(double, doulbe) would return
a double instead of a bool.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request May 15, 2025
@jmmartinez jmmartinez merged commit 9893f6b into llvm:main May 15, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants