Skip to content

Commit 8478001

Browse files
committed
Apply constexpr only when builtin is
1 parent f160b6a commit 8478001

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

libcxx/include/__math/traits.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ namespace __math {
2828
// signbit
2929

3030
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
31-
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
32-
// TODO(LLVM 22): Remove `__builtin_copysign`-workaround once support for Clang 19 is dropped.
33-
#if !__has_constexpr_builtin(__builtin_signbit) && _LIBCPP_STD_VER >= 23
34-
return __builtin_copysign(1.0, __x) == -1.0;
35-
#else
36-
return __builtin_signbit(__x);
31+
_LIBCPP_NODISCARD inline
32+
// TODO(LLVM 22): Remove conditional once support for Clang 19 is dropped.
33+
#if !defined(__clang__) || __has_constexpr_builtin(__builtin_signbit)
34+
_LIBCPP_CONSTEXPR_SINCE_CXX23
3735
#endif
36+
_LIBCPP_HIDE_FROM_ABI bool
37+
signbit(_A1 __x) _NOEXCEPT {
38+
return __builtin_signbit(__x);
3839
}
3940

4041
_LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI

libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,16 @@ int main(int, char**) {
220220
ASSERT_CONSTEXPR_CXX23(std::isnormal(-1.0) == 1);
221221
ASSERT_CONSTEXPR_CXX23(std::isnormal(-1.0L) == 1);
222222

223+
// TODO(LLVM 22): Remove `__has_constexpr_builtin` conditional once support for Clang 19 is dropped.
224+
#if !__has_constexpr_builtin(__builtin_signbit)
225+
ASSERT_NOT_CONSTEXPR_CXX23(std::signbit(-1.0f) == 1);
226+
ASSERT_NOT_CONSTEXPR_CXX23(std::signbit(-1.0) == 1);
227+
ASSERT_NOT_CONSTEXPR_CXX23(std::signbit(-1.0L) == 1);
228+
#else
223229
ASSERT_CONSTEXPR_CXX23(std::signbit(-1.0f) == 1);
224230
ASSERT_CONSTEXPR_CXX23(std::signbit(-1.0) == 1);
225231
ASSERT_CONSTEXPR_CXX23(std::signbit(-1.0L) == 1);
232+
#endif
226233

227234
ASSERT_NOT_CONSTEXPR_CXX23(std::isgreater(-1.0f, 0.0f) == 0);
228235
ASSERT_NOT_CONSTEXPR_CXX23(std::isgreater(-1.0, 0.0) == 0);

libcxx/test/std/numerics/c.math/signbit.pass.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
// We don't control the implementation on windows
1212
// UNSUPPORTED: windows
1313

14+
// These compilers don't support constexpr `__builtin_signbit` yet.
15+
// UNSUPPORTED: clang-17, clang-18, clang-19, apple-clang-16, apple-clang-17
16+
1417
#include <cassert>
1518
#include <cmath>
1619
#include <limits>

0 commit comments

Comments
 (0)