[libcxx-commits] [libcxx] [libcxx] Undefine all supported C math functions (PR #94533)
Petr Hosek via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Jun 10 11:02:16 PDT 2024
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/94533
>From bbcf24a32f83c56df2a21b00262d12d3fb114c67 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 5 Jun 2024 13:23:56 -0700
Subject: [PATCH 1/4] [libcxx] Undefine all supported C math functions
The C standard allows these to be defined as macros which is problem
when providing the C++ versions and so we need to undefine the C macros
first. Rather than undefining these selectively, we should undefine all
of them since we have any guarantees which are going to be defined as
macros and it depeneds on the target platform.
We don't need to guard these with #ifdef since undefining a symbol
that's not defined is not an error.
This is related to issue #84879.
---
libcxx/include/math.h | 115 ++++++++++++++++++++++++----------------
libcxx/include/stdlib.h | 24 +++------
2 files changed, 74 insertions(+), 65 deletions(-)
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 4e6304a753984..893dca8dc1c17 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -307,53 +307,74 @@ long double truncl(long double x);
// back to C++ linkage before including these C++ headers.
extern "C++" {
-# ifdef fpclassify
-# undef fpclassify
-# endif
-
-# ifdef signbit
-# undef signbit
-# endif
-
-# ifdef isfinite
-# undef isfinite
-# endif
-
-# ifdef isinf
-# undef isinf
-# endif
-
-# ifdef isnan
-# undef isnan
-# endif
-
-# ifdef isnormal
-# undef isnormal
-# endif
-
-# ifdef isgreater
-# undef isgreater
-# endif
-
-# ifdef isgreaterequal
-# undef isgreaterequal
-# endif
-
-# ifdef isless
-# undef isless
-# endif
-
-# ifdef islessequal
-# undef islessequal
-# endif
-
-# ifdef islessgreater
-# undef islessgreater
-# endif
-
-# ifdef isunordered
-# undef isunordered
-# endif
+# undef acos
+# undef acosh
+# undef asin
+# undef asinh
+# undef atan
+# undef atan2
+# undef atanh
+# undef cbrt
+# undef ceil
+# undef copysign
+# undef cos
+# undef cosh
+# undef erf
+# undef erfc
+# undef exp
+# undef exp2
+# undef expm1
+# undef fabs
+# undef fdim
+# undef floor
+# undef fma
+# undef fmax
+# undef fmin
+# undef fmod
+# undef fpclassify
+# undef frexp
+# undef hypot
+# undef ilogb
+# undef isfinite
+# undef isgreater
+# undef isgreaterequal
+# undef isinf
+# undef isless
+# undef islessequal
+# undef islessgreater
+# undef isnan
+# undef isnormal
+# undef isunordered
+# undef ldexp
+# undef lgamma
+# undef llrint
+# undef llround
+# undef log
+# undef log10
+# undef log1p
+# undef log2
+# undef logb
+# undef lrint
+# undef lround
+# undef modf
+# undef nearbyint
+# undef nextafter
+# undef nexttoward
+# undef pow
+# undef remainder
+# undef remquo
+# undef rint
+# undef round
+# undef scalbln
+# undef scalbn
+# undef signbit
+# undef sin
+# undef sinh
+# undef sqrt
+# undef tan
+# undef tanh
+# undef tgamma
+# undef trunc
# include <__math/abs.h>
# include <__math/copysign.h>
diff --git a/libcxx/include/stdlib.h b/libcxx/include/stdlib.h
index a74344d49150c..b1151b58a356f 100644
--- a/libcxx/include/stdlib.h
+++ b/libcxx/include/stdlib.h
@@ -98,15 +98,9 @@ void *aligned_alloc(size_t alignment, size_t size); // C11
extern "C++" {
// abs
-# ifdef abs
-# undef abs
-# endif
-# ifdef labs
-# undef labs
-# endif
-# ifdef llabs
-# undef llabs
-# endif
+# undef abs
+# undef labs
+# undef llabs
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
# if !defined(_LIBCPP_MSVCRT)
@@ -128,15 +122,9 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __lcp
// div
-# ifdef div
-# undef div
-# endif
-# ifdef ldiv
-# undef ldiv
-# endif
-# ifdef lldiv
-# undef lldiv
-# endif
+# undef div
+# undef ldiv
+# undef lldiv
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
# if !defined(_LIBCPP_MSVCRT)
>From 745745c5df98cce4924f0fb8ef5bdffb1081953f Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 5 Jun 2024 14:09:30 -0700
Subject: [PATCH 2/4] Move undefs next to function definitions
---
libcxx/include/__math/abs.h | 2 +
libcxx/include/__math/copysign.h | 2 +
libcxx/include/__math/error_functions.h | 4 ++
libcxx/include/__math/exponential_functions.h | 16 +++++
libcxx/include/__math/fdim.h | 4 ++
libcxx/include/__math/fma.h | 4 ++
libcxx/include/__math/gamma.h | 4 ++
libcxx/include/__math/hyperbolic_functions.h | 6 ++
libcxx/include/__math/hypot.h | 4 ++
.../__math/inverse_hyperbolic_functions.h | 6 ++
.../__math/inverse_trigonometric_functions.h | 8 +++
libcxx/include/__math/logarithms.h | 12 ++++
libcxx/include/__math/min_max.h | 4 ++
libcxx/include/__math/modulo.h | 4 ++
libcxx/include/__math/remainder.h | 4 ++
libcxx/include/__math/roots.h | 4 ++
libcxx/include/__math/rounding_functions.h | 24 +++++++
libcxx/include/__math/traits.h | 22 ++++++
.../include/__math/trigonometric_functions.h | 6 ++
libcxx/include/math.h | 71 +------------------
20 files changed, 142 insertions(+), 69 deletions(-)
diff --git a/libcxx/include/__math/abs.h b/libcxx/include/__math/abs.h
index ab82a2800f53c..ddae9473effec 100644
--- a/libcxx/include/__math/abs.h
+++ b/libcxx/include/__math/abs.h
@@ -23,6 +23,8 @@ namespace __math {
// fabs
+#undef fabs
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/copysign.h b/libcxx/include/__math/copysign.h
index b38690bb581a1..fd187e95a065c 100644
--- a/libcxx/include/__math/copysign.h
+++ b/libcxx/include/__math/copysign.h
@@ -25,6 +25,8 @@ namespace __math {
// copysign
+#undef copysign
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
return ::__builtin_copysignf(__x, __y);
}
diff --git a/libcxx/include/__math/error_functions.h b/libcxx/include/__math/error_functions.h
index 6b528bb290001..4614bc59b9f70 100644
--- a/libcxx/include/__math/error_functions.h
+++ b/libcxx/include/__math/error_functions.h
@@ -23,6 +23,8 @@ namespace __math {
// erf
+#undef erf
+
inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT { return __builtin_erff(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double erf(_A1 __x) _NOEXCEPT {
// erfc
+#undef erfc
+
inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT { return __builtin_erfcf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/exponential_functions.h b/libcxx/include/__math/exponential_functions.h
index f8d611b9e486e..67caa5152805c 100644
--- a/libcxx/include/__math/exponential_functions.h
+++ b/libcxx/include/__math/exponential_functions.h
@@ -26,6 +26,8 @@ namespace __math {
// exp
+#undef exp
+
inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); }
template <class = int>
@@ -42,6 +44,8 @@ inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT {
// frexp
+#undef frexp
+
inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); }
template <class = int>
@@ -60,6 +64,8 @@ inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT {
// ldexp
+#undef ldexp
+
inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); }
template <class = int>
@@ -78,6 +84,8 @@ inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT {
// exp2
+#undef exp2
+
inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT { return __builtin_exp2f(__x); }
template <class = int>
@@ -94,6 +102,8 @@ inline _LIBCPP_HIDE_FROM_ABI double exp2(_A1 __x) _NOEXCEPT {
// expm1
+#undef expm1
+
inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT { return __builtin_expm1f(__x); }
template <class = int>
@@ -110,6 +120,8 @@ inline _LIBCPP_HIDE_FROM_ABI double expm1(_A1 __x) _NOEXCEPT {
// scalbln
+#undef scalbln
+
inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT { return __builtin_scalblnf(__x, __y); }
template <class = int>
@@ -128,6 +140,8 @@ inline _LIBCPP_HIDE_FROM_ABI double scalbln(_A1 __x, long __y) _NOEXCEPT {
// scalbn
+#undef scalbn
+
inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT { return __builtin_scalbnf(__x, __y); }
template <class = int>
@@ -146,6 +160,8 @@ inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT {
// pow
+#undef pow
+
inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/fdim.h b/libcxx/include/__math/fdim.h
index 6f90809302d7b..497c60c304c3e 100644
--- a/libcxx/include/__math/fdim.h
+++ b/libcxx/include/__math/fdim.h
@@ -23,6 +23,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
+// fdim
+
+#undef fdim
+
inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT { return __builtin_fdimf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/fma.h b/libcxx/include/__math/fma.h
index 9e14f72dcaa08..e95226c0be642 100644
--- a/libcxx/include/__math/fma.h
+++ b/libcxx/include/__math/fma.h
@@ -23,6 +23,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
+// fma
+
+#undef fma
+
inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT {
return __builtin_fmaf(__x, __y, __z);
}
diff --git a/libcxx/include/__math/gamma.h b/libcxx/include/__math/gamma.h
index 693e111a84e99..8542bfeff12f3 100644
--- a/libcxx/include/__math/gamma.h
+++ b/libcxx/include/__math/gamma.h
@@ -23,6 +23,8 @@ namespace __math {
// lgamma
+#undef lgamma
+
inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT { return __builtin_lgammaf(__x); }
template <class = int>
@@ -41,6 +43,8 @@ inline _LIBCPP_HIDE_FROM_ABI double lgamma(_A1 __x) _NOEXCEPT {
// tgamma
+#undef tgamma
+
inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT { return __builtin_tgammaf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/hyperbolic_functions.h b/libcxx/include/__math/hyperbolic_functions.h
index 78832bae70c9d..fcffb2b0d242f 100644
--- a/libcxx/include/__math/hyperbolic_functions.h
+++ b/libcxx/include/__math/hyperbolic_functions.h
@@ -23,6 +23,8 @@ namespace __math {
// cosh
+#undef cosh
+
inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT { return __builtin_coshf(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double cosh(_A1 __x) _NOEXCEPT {
// sinh
+#undef sinh
+
inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT { return __builtin_sinhf(__x); }
template <class = int>
@@ -55,6 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI double sinh(_A1 __x) _NOEXCEPT {
// tanh
+#undef tanh
+
inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT { return __builtin_tanhf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/hypot.h b/libcxx/include/__math/hypot.h
index 8e2c0f5b6b6d8..f4e34959540be 100644
--- a/libcxx/include/__math/hypot.h
+++ b/libcxx/include/__math/hypot.h
@@ -23,6 +23,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
+// hypot
+
+#undef hypot
+
inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT { return __builtin_hypotf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/inverse_hyperbolic_functions.h b/libcxx/include/__math/inverse_hyperbolic_functions.h
index 4660a58e4eba0..f2270e22893c8 100644
--- a/libcxx/include/__math/inverse_hyperbolic_functions.h
+++ b/libcxx/include/__math/inverse_hyperbolic_functions.h
@@ -23,6 +23,8 @@ namespace __math {
// acosh
+#undef acosh
+
inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT { return __builtin_acoshf(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double acosh(_A1 __x) _NOEXCEPT {
// asinh
+#undef asinh
+
inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT { return __builtin_asinhf(__x); }
template <class = int>
@@ -55,6 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI double asinh(_A1 __x) _NOEXCEPT {
// atanh
+#undef atanh
+
inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT { return __builtin_atanhf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/inverse_trigonometric_functions.h b/libcxx/include/__math/inverse_trigonometric_functions.h
index 30b1440b0b119..872c164815746 100644
--- a/libcxx/include/__math/inverse_trigonometric_functions.h
+++ b/libcxx/include/__math/inverse_trigonometric_functions.h
@@ -26,6 +26,8 @@ namespace __math {
// acos
+#undef acos
+
inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); }
template <class = int>
@@ -42,6 +44,8 @@ inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT {
// asin
+#undef asin
+
inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); }
template <class = int>
@@ -58,6 +62,8 @@ inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT {
// atan
+#undef atan
+
inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); }
template <class = int>
@@ -74,6 +80,8 @@ inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT {
// atan2
+#undef atan2
+
inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); }
template <class = int>
diff --git a/libcxx/include/__math/logarithms.h b/libcxx/include/__math/logarithms.h
index 5f5f943977a50..038d1c368a4c3 100644
--- a/libcxx/include/__math/logarithms.h
+++ b/libcxx/include/__math/logarithms.h
@@ -23,6 +23,8 @@ namespace __math {
// log
+#undef log
+
inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT {
// log10
+#undef log10
+
inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); }
template <class = int>
@@ -55,6 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT {
// ilogb
+#undef ilogb
+
inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); }
template <class = int>
@@ -71,6 +77,8 @@ inline _LIBCPP_HIDE_FROM_ABI int ilogb(_A1 __x) _NOEXCEPT {
// log1p
+#undef log1p
+
inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT { return __builtin_log1pf(__x); }
template <class = int>
@@ -87,6 +95,8 @@ inline _LIBCPP_HIDE_FROM_ABI double log1p(_A1 __x) _NOEXCEPT {
// log2
+#undef log2
+
inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT { return __builtin_log2f(__x); }
template <class = int>
@@ -103,6 +113,8 @@ inline _LIBCPP_HIDE_FROM_ABI double log2(_A1 __x) _NOEXCEPT {
// logb
+#undef logb
+
inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT { return __builtin_logbf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/min_max.h b/libcxx/include/__math/min_max.h
index c2c4f6b645609..c015c3560f21f 100644
--- a/libcxx/include/__math/min_max.h
+++ b/libcxx/include/__math/min_max.h
@@ -25,6 +25,8 @@ namespace __math {
// fmax
+#undef fmax
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {
return __builtin_fmaxf(__x, __y);
}
@@ -47,6 +49,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::typ
// fmin
+#undef fmin
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {
return __builtin_fminf(__x, __y);
}
diff --git a/libcxx/include/__math/modulo.h b/libcxx/include/__math/modulo.h
index f6cdb956cf883..c684e985eee32 100644
--- a/libcxx/include/__math/modulo.h
+++ b/libcxx/include/__math/modulo.h
@@ -25,6 +25,8 @@ namespace __math {
// fmod
+#undef fmod
+
inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); }
template <class = int>
@@ -45,6 +47,8 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmod(_A1 __x, _A
// modf
+#undef modf
+
inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT { return __builtin_modff(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/remainder.h b/libcxx/include/__math/remainder.h
index 025fb53aaa201..dd0a681351257 100644
--- a/libcxx/include/__math/remainder.h
+++ b/libcxx/include/__math/remainder.h
@@ -26,6 +26,8 @@ namespace __math {
// remainder
+#undef remainder
+
inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT { return __builtin_remainderf(__x, __y); }
template <class = int>
@@ -46,6 +48,8 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remainder(_A1 __
// remquo
+#undef remquo
+
inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT {
return __builtin_remquof(__x, __y, __z);
}
diff --git a/libcxx/include/__math/roots.h b/libcxx/include/__math/roots.h
index 359fd747cfbef..ad1d7725c67bc 100644
--- a/libcxx/include/__math/roots.h
+++ b/libcxx/include/__math/roots.h
@@ -23,6 +23,8 @@ namespace __math {
// sqrt
+#undef sqrt
+
inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT {
// cbrt
+#undef cbrt
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/rounding_functions.h b/libcxx/include/__math/rounding_functions.h
index 33e6cbc37d604..ff310e02c8e82 100644
--- a/libcxx/include/__math/rounding_functions.h
+++ b/libcxx/include/__math/rounding_functions.h
@@ -26,6 +26,8 @@ namespace __math {
// ceil
+#undef ceil
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); }
template <class = int>
@@ -44,6 +46,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT {
// floor
+#undef floor
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); }
template <class = int>
@@ -62,6 +66,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT {
// llrint
+#undef llrint
+
inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT { return __builtin_llrintf(__x); }
template <class = int>
@@ -78,6 +84,8 @@ inline _LIBCPP_HIDE_FROM_ABI long long llrint(_A1 __x) _NOEXCEPT {
// llround
+#undef llround
+
inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT { return __builtin_llroundf(__x); }
template <class = int>
@@ -94,6 +102,8 @@ inline _LIBCPP_HIDE_FROM_ABI long long llround(_A1 __x) _NOEXCEPT {
// lrint
+#undef lrint
+
inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT { return __builtin_lrintf(__x); }
template <class = int>
@@ -110,6 +120,8 @@ inline _LIBCPP_HIDE_FROM_ABI long lrint(_A1 __x) _NOEXCEPT {
// lround
+#undef lround
+
inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT { return __builtin_lroundf(__x); }
template <class = int>
@@ -126,6 +138,8 @@ inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT {
// nearbyint
+#undef nearbyint
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {
return __builtin_nearbyintf(__x);
}
@@ -146,6 +160,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCE
// nextafter
+#undef nextafter
+
inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT { return __builtin_nextafterf(__x, __y); }
template <class = int>
@@ -166,6 +182,8 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __
// nexttoward
+#undef nexttoward
+
inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {
return __builtin_nexttowardf(__x, __y);
}
@@ -186,6 +204,8 @@ inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCE
// rint
+#undef rint
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); }
template <class = int>
@@ -204,6 +224,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT {
// round
+#undef round
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); }
template <class = int>
@@ -222,6 +244,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT {
// trunc
+#undef trunc
+
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); }
template <class = int>
diff --git a/libcxx/include/__math/traits.h b/libcxx/include/__math/traits.h
index a448266797557..b4f9de50f2a20 100644
--- a/libcxx/include/__math/traits.h
+++ b/libcxx/include/__math/traits.h
@@ -28,6 +28,8 @@ namespace __math {
// signbit
+#undef signbit
+
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
return __builtin_signbit(__x);
@@ -45,6 +47,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
// isfinite
+#undef isfinite
+
template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
return __builtin_isfinite((typename __promote<_A1>::type)__x);
@@ -57,6 +61,8 @@ _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfin
// isinf
+#undef isinf
+
template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
return __builtin_isinf((typename __promote<_A1>::type)__x);
@@ -84,6 +90,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
// isnan
+#undef isnan
+
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
return __builtin_isnan(__x);
@@ -111,6 +119,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
// isnormal
+#undef isnormal
+
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
return __builtin_isnormal(__x);
@@ -123,6 +133,8 @@ _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnor
// isgreater
+#undef isgreater
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -131,6 +143,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y)
// isgreaterequal
+#undef isgreaterequal
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -139,6 +153,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2
// isless
+#undef isless
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -147,6 +163,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NO
// islessequal
+#undef islessequal
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -155,6 +173,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y
// islessgreater
+#undef islessgreater
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -163,6 +183,8 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 _
// isunordered
+#undef isunordered
+
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
diff --git a/libcxx/include/__math/trigonometric_functions.h b/libcxx/include/__math/trigonometric_functions.h
index 0ad91c7631609..49d503e0c9d75 100644
--- a/libcxx/include/__math/trigonometric_functions.h
+++ b/libcxx/include/__math/trigonometric_functions.h
@@ -23,6 +23,8 @@ namespace __math {
// cos
+#undef cos
+
inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT { return __builtin_cosf(__x); }
template <class = int>
@@ -39,6 +41,8 @@ inline _LIBCPP_HIDE_FROM_ABI double cos(_A1 __x) _NOEXCEPT {
// sin
+#undef sin
+
inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT { return __builtin_sinf(__x); }
template <class = int>
@@ -55,6 +59,8 @@ inline _LIBCPP_HIDE_FROM_ABI double sin(_A1 __x) _NOEXCEPT {
// tan
+#undef tan
+
inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT { return __builtin_tanf(__x); }
template <class = int>
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 893dca8dc1c17..af6c2b4f132f7 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -307,75 +307,6 @@ long double truncl(long double x);
// back to C++ linkage before including these C++ headers.
extern "C++" {
-# undef acos
-# undef acosh
-# undef asin
-# undef asinh
-# undef atan
-# undef atan2
-# undef atanh
-# undef cbrt
-# undef ceil
-# undef copysign
-# undef cos
-# undef cosh
-# undef erf
-# undef erfc
-# undef exp
-# undef exp2
-# undef expm1
-# undef fabs
-# undef fdim
-# undef floor
-# undef fma
-# undef fmax
-# undef fmin
-# undef fmod
-# undef fpclassify
-# undef frexp
-# undef hypot
-# undef ilogb
-# undef isfinite
-# undef isgreater
-# undef isgreaterequal
-# undef isinf
-# undef isless
-# undef islessequal
-# undef islessgreater
-# undef isnan
-# undef isnormal
-# undef isunordered
-# undef ldexp
-# undef lgamma
-# undef llrint
-# undef llround
-# undef log
-# undef log10
-# undef log1p
-# undef log2
-# undef logb
-# undef lrint
-# undef lround
-# undef modf
-# undef nearbyint
-# undef nextafter
-# undef nexttoward
-# undef pow
-# undef remainder
-# undef remquo
-# undef rint
-# undef round
-# undef scalbln
-# undef scalbn
-# undef signbit
-# undef sin
-# undef sinh
-# undef sqrt
-# undef tan
-# undef tanh
-# undef tgamma
-# undef trunc
-
# include <__math/abs.h>
# include <__math/copysign.h>
# include <__math/error_functions.h>
@@ -407,6 +338,8 @@ namespace __math {
// fpclassify
+# undef fpclassify
+
// template on non-double overloads to make them weaker than same overloads from MSVC runtime
template <class = int>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
>From 5cddd961e1e9674d82acd80c64512bbd5a15ead9 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Mon, 10 Jun 2024 10:56:13 -0700
Subject: [PATCH 3/4] Revert "Move undefs next to function definitions"
This reverts commit 745745c5df98cce4924f0fb8ef5bdffb1081953f.
---
libcxx/include/__math/abs.h | 2 -
libcxx/include/__math/copysign.h | 2 -
libcxx/include/__math/error_functions.h | 4 --
libcxx/include/__math/exponential_functions.h | 16 -----
libcxx/include/__math/fdim.h | 4 --
libcxx/include/__math/fma.h | 4 --
libcxx/include/__math/gamma.h | 4 --
libcxx/include/__math/hyperbolic_functions.h | 6 --
libcxx/include/__math/hypot.h | 4 --
.../__math/inverse_hyperbolic_functions.h | 6 --
.../__math/inverse_trigonometric_functions.h | 8 ---
libcxx/include/__math/logarithms.h | 12 ----
libcxx/include/__math/min_max.h | 4 --
libcxx/include/__math/modulo.h | 4 --
libcxx/include/__math/remainder.h | 4 --
libcxx/include/__math/roots.h | 4 --
libcxx/include/__math/rounding_functions.h | 24 -------
libcxx/include/__math/traits.h | 22 ------
.../include/__math/trigonometric_functions.h | 6 --
libcxx/include/math.h | 71 ++++++++++++++++++-
20 files changed, 69 insertions(+), 142 deletions(-)
diff --git a/libcxx/include/__math/abs.h b/libcxx/include/__math/abs.h
index ddae9473effec..ab82a2800f53c 100644
--- a/libcxx/include/__math/abs.h
+++ b/libcxx/include/__math/abs.h
@@ -23,8 +23,6 @@ namespace __math {
// fabs
-#undef fabs
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/copysign.h b/libcxx/include/__math/copysign.h
index fd187e95a065c..b38690bb581a1 100644
--- a/libcxx/include/__math/copysign.h
+++ b/libcxx/include/__math/copysign.h
@@ -25,8 +25,6 @@ namespace __math {
// copysign
-#undef copysign
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float copysign(float __x, float __y) _NOEXCEPT {
return ::__builtin_copysignf(__x, __y);
}
diff --git a/libcxx/include/__math/error_functions.h b/libcxx/include/__math/error_functions.h
index 4614bc59b9f70..6b528bb290001 100644
--- a/libcxx/include/__math/error_functions.h
+++ b/libcxx/include/__math/error_functions.h
@@ -23,8 +23,6 @@ namespace __math {
// erf
-#undef erf
-
inline _LIBCPP_HIDE_FROM_ABI float erf(float __x) _NOEXCEPT { return __builtin_erff(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double erf(_A1 __x) _NOEXCEPT {
// erfc
-#undef erfc
-
inline _LIBCPP_HIDE_FROM_ABI float erfc(float __x) _NOEXCEPT { return __builtin_erfcf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/exponential_functions.h b/libcxx/include/__math/exponential_functions.h
index 67caa5152805c..f8d611b9e486e 100644
--- a/libcxx/include/__math/exponential_functions.h
+++ b/libcxx/include/__math/exponential_functions.h
@@ -26,8 +26,6 @@ namespace __math {
// exp
-#undef exp
-
inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); }
template <class = int>
@@ -44,8 +42,6 @@ inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT {
// frexp
-#undef frexp
-
inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); }
template <class = int>
@@ -64,8 +60,6 @@ inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT {
// ldexp
-#undef ldexp
-
inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); }
template <class = int>
@@ -84,8 +78,6 @@ inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT {
// exp2
-#undef exp2
-
inline _LIBCPP_HIDE_FROM_ABI float exp2(float __x) _NOEXCEPT { return __builtin_exp2f(__x); }
template <class = int>
@@ -102,8 +94,6 @@ inline _LIBCPP_HIDE_FROM_ABI double exp2(_A1 __x) _NOEXCEPT {
// expm1
-#undef expm1
-
inline _LIBCPP_HIDE_FROM_ABI float expm1(float __x) _NOEXCEPT { return __builtin_expm1f(__x); }
template <class = int>
@@ -120,8 +110,6 @@ inline _LIBCPP_HIDE_FROM_ABI double expm1(_A1 __x) _NOEXCEPT {
// scalbln
-#undef scalbln
-
inline _LIBCPP_HIDE_FROM_ABI float scalbln(float __x, long __y) _NOEXCEPT { return __builtin_scalblnf(__x, __y); }
template <class = int>
@@ -140,8 +128,6 @@ inline _LIBCPP_HIDE_FROM_ABI double scalbln(_A1 __x, long __y) _NOEXCEPT {
// scalbn
-#undef scalbn
-
inline _LIBCPP_HIDE_FROM_ABI float scalbn(float __x, int __y) _NOEXCEPT { return __builtin_scalbnf(__x, __y); }
template <class = int>
@@ -160,8 +146,6 @@ inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT {
// pow
-#undef pow
-
inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/fdim.h b/libcxx/include/__math/fdim.h
index 497c60c304c3e..6f90809302d7b 100644
--- a/libcxx/include/__math/fdim.h
+++ b/libcxx/include/__math/fdim.h
@@ -23,10 +23,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
-// fdim
-
-#undef fdim
-
inline _LIBCPP_HIDE_FROM_ABI float fdim(float __x, float __y) _NOEXCEPT { return __builtin_fdimf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/fma.h b/libcxx/include/__math/fma.h
index e95226c0be642..9e14f72dcaa08 100644
--- a/libcxx/include/__math/fma.h
+++ b/libcxx/include/__math/fma.h
@@ -23,10 +23,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
-// fma
-
-#undef fma
-
inline _LIBCPP_HIDE_FROM_ABI float fma(float __x, float __y, float __z) _NOEXCEPT {
return __builtin_fmaf(__x, __y, __z);
}
diff --git a/libcxx/include/__math/gamma.h b/libcxx/include/__math/gamma.h
index 8542bfeff12f3..693e111a84e99 100644
--- a/libcxx/include/__math/gamma.h
+++ b/libcxx/include/__math/gamma.h
@@ -23,8 +23,6 @@ namespace __math {
// lgamma
-#undef lgamma
-
inline _LIBCPP_HIDE_FROM_ABI float lgamma(float __x) _NOEXCEPT { return __builtin_lgammaf(__x); }
template <class = int>
@@ -43,8 +41,6 @@ inline _LIBCPP_HIDE_FROM_ABI double lgamma(_A1 __x) _NOEXCEPT {
// tgamma
-#undef tgamma
-
inline _LIBCPP_HIDE_FROM_ABI float tgamma(float __x) _NOEXCEPT { return __builtin_tgammaf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/hyperbolic_functions.h b/libcxx/include/__math/hyperbolic_functions.h
index fcffb2b0d242f..78832bae70c9d 100644
--- a/libcxx/include/__math/hyperbolic_functions.h
+++ b/libcxx/include/__math/hyperbolic_functions.h
@@ -23,8 +23,6 @@ namespace __math {
// cosh
-#undef cosh
-
inline _LIBCPP_HIDE_FROM_ABI float cosh(float __x) _NOEXCEPT { return __builtin_coshf(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double cosh(_A1 __x) _NOEXCEPT {
// sinh
-#undef sinh
-
inline _LIBCPP_HIDE_FROM_ABI float sinh(float __x) _NOEXCEPT { return __builtin_sinhf(__x); }
template <class = int>
@@ -59,8 +55,6 @@ inline _LIBCPP_HIDE_FROM_ABI double sinh(_A1 __x) _NOEXCEPT {
// tanh
-#undef tanh
-
inline _LIBCPP_HIDE_FROM_ABI float tanh(float __x) _NOEXCEPT { return __builtin_tanhf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/hypot.h b/libcxx/include/__math/hypot.h
index f4e34959540be..8e2c0f5b6b6d8 100644
--- a/libcxx/include/__math/hypot.h
+++ b/libcxx/include/__math/hypot.h
@@ -23,10 +23,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace __math {
-// hypot
-
-#undef hypot
-
inline _LIBCPP_HIDE_FROM_ABI float hypot(float __x, float __y) _NOEXCEPT { return __builtin_hypotf(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/inverse_hyperbolic_functions.h b/libcxx/include/__math/inverse_hyperbolic_functions.h
index f2270e22893c8..4660a58e4eba0 100644
--- a/libcxx/include/__math/inverse_hyperbolic_functions.h
+++ b/libcxx/include/__math/inverse_hyperbolic_functions.h
@@ -23,8 +23,6 @@ namespace __math {
// acosh
-#undef acosh
-
inline _LIBCPP_HIDE_FROM_ABI float acosh(float __x) _NOEXCEPT { return __builtin_acoshf(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double acosh(_A1 __x) _NOEXCEPT {
// asinh
-#undef asinh
-
inline _LIBCPP_HIDE_FROM_ABI float asinh(float __x) _NOEXCEPT { return __builtin_asinhf(__x); }
template <class = int>
@@ -59,8 +55,6 @@ inline _LIBCPP_HIDE_FROM_ABI double asinh(_A1 __x) _NOEXCEPT {
// atanh
-#undef atanh
-
inline _LIBCPP_HIDE_FROM_ABI float atanh(float __x) _NOEXCEPT { return __builtin_atanhf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/inverse_trigonometric_functions.h b/libcxx/include/__math/inverse_trigonometric_functions.h
index 872c164815746..30b1440b0b119 100644
--- a/libcxx/include/__math/inverse_trigonometric_functions.h
+++ b/libcxx/include/__math/inverse_trigonometric_functions.h
@@ -26,8 +26,6 @@ namespace __math {
// acos
-#undef acos
-
inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); }
template <class = int>
@@ -44,8 +42,6 @@ inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT {
// asin
-#undef asin
-
inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); }
template <class = int>
@@ -62,8 +58,6 @@ inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT {
// atan
-#undef atan
-
inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); }
template <class = int>
@@ -80,8 +74,6 @@ inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT {
// atan2
-#undef atan2
-
inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); }
template <class = int>
diff --git a/libcxx/include/__math/logarithms.h b/libcxx/include/__math/logarithms.h
index 038d1c368a4c3..5f5f943977a50 100644
--- a/libcxx/include/__math/logarithms.h
+++ b/libcxx/include/__math/logarithms.h
@@ -23,8 +23,6 @@ namespace __math {
// log
-#undef log
-
inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT {
// log10
-#undef log10
-
inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); }
template <class = int>
@@ -59,8 +55,6 @@ inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT {
// ilogb
-#undef ilogb
-
inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); }
template <class = int>
@@ -77,8 +71,6 @@ inline _LIBCPP_HIDE_FROM_ABI int ilogb(_A1 __x) _NOEXCEPT {
// log1p
-#undef log1p
-
inline _LIBCPP_HIDE_FROM_ABI float log1p(float __x) _NOEXCEPT { return __builtin_log1pf(__x); }
template <class = int>
@@ -95,8 +87,6 @@ inline _LIBCPP_HIDE_FROM_ABI double log1p(_A1 __x) _NOEXCEPT {
// log2
-#undef log2
-
inline _LIBCPP_HIDE_FROM_ABI float log2(float __x) _NOEXCEPT { return __builtin_log2f(__x); }
template <class = int>
@@ -113,8 +103,6 @@ inline _LIBCPP_HIDE_FROM_ABI double log2(_A1 __x) _NOEXCEPT {
// logb
-#undef logb
-
inline _LIBCPP_HIDE_FROM_ABI float logb(float __x) _NOEXCEPT { return __builtin_logbf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/min_max.h b/libcxx/include/__math/min_max.h
index c015c3560f21f..c2c4f6b645609 100644
--- a/libcxx/include/__math/min_max.h
+++ b/libcxx/include/__math/min_max.h
@@ -25,8 +25,6 @@ namespace __math {
// fmax
-#undef fmax
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmax(float __x, float __y) _NOEXCEPT {
return __builtin_fmaxf(__x, __y);
}
@@ -49,8 +47,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::typ
// fmin
-#undef fmin
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float fmin(float __x, float __y) _NOEXCEPT {
return __builtin_fminf(__x, __y);
}
diff --git a/libcxx/include/__math/modulo.h b/libcxx/include/__math/modulo.h
index c684e985eee32..f6cdb956cf883 100644
--- a/libcxx/include/__math/modulo.h
+++ b/libcxx/include/__math/modulo.h
@@ -25,8 +25,6 @@ namespace __math {
// fmod
-#undef fmod
-
inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); }
template <class = int>
@@ -47,8 +45,6 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type fmod(_A1 __x, _A
// modf
-#undef modf
-
inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT { return __builtin_modff(__x, __y); }
template <class = int>
diff --git a/libcxx/include/__math/remainder.h b/libcxx/include/__math/remainder.h
index dd0a681351257..025fb53aaa201 100644
--- a/libcxx/include/__math/remainder.h
+++ b/libcxx/include/__math/remainder.h
@@ -26,8 +26,6 @@ namespace __math {
// remainder
-#undef remainder
-
inline _LIBCPP_HIDE_FROM_ABI float remainder(float __x, float __y) _NOEXCEPT { return __builtin_remainderf(__x, __y); }
template <class = int>
@@ -48,8 +46,6 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type remainder(_A1 __
// remquo
-#undef remquo
-
inline _LIBCPP_HIDE_FROM_ABI float remquo(float __x, float __y, int* __z) _NOEXCEPT {
return __builtin_remquof(__x, __y, __z);
}
diff --git a/libcxx/include/__math/roots.h b/libcxx/include/__math/roots.h
index ad1d7725c67bc..359fd747cfbef 100644
--- a/libcxx/include/__math/roots.h
+++ b/libcxx/include/__math/roots.h
@@ -23,8 +23,6 @@ namespace __math {
// sqrt
-#undef sqrt
-
inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT {
// cbrt
-#undef cbrt
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); }
template <class = int>
diff --git a/libcxx/include/__math/rounding_functions.h b/libcxx/include/__math/rounding_functions.h
index ff310e02c8e82..33e6cbc37d604 100644
--- a/libcxx/include/__math/rounding_functions.h
+++ b/libcxx/include/__math/rounding_functions.h
@@ -26,8 +26,6 @@ namespace __math {
// ceil
-#undef ceil
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); }
template <class = int>
@@ -46,8 +44,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT {
// floor
-#undef floor
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); }
template <class = int>
@@ -66,8 +62,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT {
// llrint
-#undef llrint
-
inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT { return __builtin_llrintf(__x); }
template <class = int>
@@ -84,8 +78,6 @@ inline _LIBCPP_HIDE_FROM_ABI long long llrint(_A1 __x) _NOEXCEPT {
// llround
-#undef llround
-
inline _LIBCPP_HIDE_FROM_ABI long long llround(float __x) _NOEXCEPT { return __builtin_llroundf(__x); }
template <class = int>
@@ -102,8 +94,6 @@ inline _LIBCPP_HIDE_FROM_ABI long long llround(_A1 __x) _NOEXCEPT {
// lrint
-#undef lrint
-
inline _LIBCPP_HIDE_FROM_ABI long lrint(float __x) _NOEXCEPT { return __builtin_lrintf(__x); }
template <class = int>
@@ -120,8 +110,6 @@ inline _LIBCPP_HIDE_FROM_ABI long lrint(_A1 __x) _NOEXCEPT {
// lround
-#undef lround
-
inline _LIBCPP_HIDE_FROM_ABI long lround(float __x) _NOEXCEPT { return __builtin_lroundf(__x); }
template <class = int>
@@ -138,8 +126,6 @@ inline _LIBCPP_HIDE_FROM_ABI long lround(_A1 __x) _NOEXCEPT {
// nearbyint
-#undef nearbyint
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float nearbyint(float __x) _NOEXCEPT {
return __builtin_nearbyintf(__x);
}
@@ -160,8 +146,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double nearbyint(_A1 __x) _NOEXCE
// nextafter
-#undef nextafter
-
inline _LIBCPP_HIDE_FROM_ABI float nextafter(float __x, float __y) _NOEXCEPT { return __builtin_nextafterf(__x, __y); }
template <class = int>
@@ -182,8 +166,6 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type nextafter(_A1 __
// nexttoward
-#undef nexttoward
-
inline _LIBCPP_HIDE_FROM_ABI float nexttoward(float __x, long double __y) _NOEXCEPT {
return __builtin_nexttowardf(__x, __y);
}
@@ -204,8 +186,6 @@ inline _LIBCPP_HIDE_FROM_ABI double nexttoward(_A1 __x, long double __y) _NOEXCE
// rint
-#undef rint
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float rint(float __x) _NOEXCEPT { return __builtin_rintf(__x); }
template <class = int>
@@ -224,8 +204,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double rint(_A1 __x) _NOEXCEPT {
// round
-#undef round
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float round(float __x) _NOEXCEPT { return __builtin_round(__x); }
template <class = int>
@@ -244,8 +222,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI double round(_A1 __x) _NOEXCEPT {
// trunc
-#undef trunc
-
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI float trunc(float __x) _NOEXCEPT { return __builtin_trunc(__x); }
template <class = int>
diff --git a/libcxx/include/__math/traits.h b/libcxx/include/__math/traits.h
index b4f9de50f2a20..a448266797557 100644
--- a/libcxx/include/__math/traits.h
+++ b/libcxx/include/__math/traits.h
@@ -28,8 +28,6 @@ namespace __math {
// signbit
-#undef signbit
-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1 __x) _NOEXCEPT {
return __builtin_signbit(__x);
@@ -47,8 +45,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool signbit(_A1) _NOEXCEPT {
// isfinite
-#undef isfinite
-
template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfinite(_A1 __x) _NOEXCEPT {
return __builtin_isfinite((typename __promote<_A1>::type)__x);
@@ -61,8 +57,6 @@ _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isfin
// isinf
-#undef isinf
-
template <class _A1, __enable_if_t<is_arithmetic<_A1>::value && numeric_limits<_A1>::has_infinity, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isinf(_A1 __x) _NOEXCEPT {
return __builtin_isinf((typename __promote<_A1>::type)__x);
@@ -90,8 +84,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
// isnan
-#undef isnan
-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnan(_A1 __x) _NOEXCEPT {
return __builtin_isnan(__x);
@@ -119,8 +111,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI boo
// isnormal
-#undef isnormal
-
template <class _A1, __enable_if_t<is_floating_point<_A1>::value, int> = 0>
_LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnormal(_A1 __x) _NOEXCEPT {
return __builtin_isnormal(__x);
@@ -133,8 +123,6 @@ _LIBCPP_NODISCARD _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI bool isnor
// isgreater
-#undef isgreater
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -143,8 +131,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreater(_A1 __x, _A2 __y)
// isgreaterequal
-#undef isgreaterequal
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -153,8 +139,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isgreaterequal(_A1 __x, _A2
// isless
-#undef isless
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -163,8 +147,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isless(_A1 __x, _A2 __y) _NO
// islessequal
-#undef islessequal
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -173,8 +155,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessequal(_A1 __x, _A2 __y
// islessgreater
-#undef islessgreater
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
@@ -183,8 +163,6 @@ _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool islessgreater(_A1 __x, _A2 _
// isunordered
-#undef isunordered
-
template <class _A1, class _A2, __enable_if_t<is_arithmetic<_A1>::value && is_arithmetic<_A2>::value, int> = 0>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI bool isunordered(_A1 __x, _A2 __y) _NOEXCEPT {
using type = typename __promote<_A1, _A2>::type;
diff --git a/libcxx/include/__math/trigonometric_functions.h b/libcxx/include/__math/trigonometric_functions.h
index 49d503e0c9d75..0ad91c7631609 100644
--- a/libcxx/include/__math/trigonometric_functions.h
+++ b/libcxx/include/__math/trigonometric_functions.h
@@ -23,8 +23,6 @@ namespace __math {
// cos
-#undef cos
-
inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT { return __builtin_cosf(__x); }
template <class = int>
@@ -41,8 +39,6 @@ inline _LIBCPP_HIDE_FROM_ABI double cos(_A1 __x) _NOEXCEPT {
// sin
-#undef sin
-
inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT { return __builtin_sinf(__x); }
template <class = int>
@@ -59,8 +55,6 @@ inline _LIBCPP_HIDE_FROM_ABI double sin(_A1 __x) _NOEXCEPT {
// tan
-#undef tan
-
inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT { return __builtin_tanf(__x); }
template <class = int>
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index af6c2b4f132f7..893dca8dc1c17 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -307,6 +307,75 @@ long double truncl(long double x);
// back to C++ linkage before including these C++ headers.
extern "C++" {
+# undef acos
+# undef acosh
+# undef asin
+# undef asinh
+# undef atan
+# undef atan2
+# undef atanh
+# undef cbrt
+# undef ceil
+# undef copysign
+# undef cos
+# undef cosh
+# undef erf
+# undef erfc
+# undef exp
+# undef exp2
+# undef expm1
+# undef fabs
+# undef fdim
+# undef floor
+# undef fma
+# undef fmax
+# undef fmin
+# undef fmod
+# undef fpclassify
+# undef frexp
+# undef hypot
+# undef ilogb
+# undef isfinite
+# undef isgreater
+# undef isgreaterequal
+# undef isinf
+# undef isless
+# undef islessequal
+# undef islessgreater
+# undef isnan
+# undef isnormal
+# undef isunordered
+# undef ldexp
+# undef lgamma
+# undef llrint
+# undef llround
+# undef log
+# undef log10
+# undef log1p
+# undef log2
+# undef logb
+# undef lrint
+# undef lround
+# undef modf
+# undef nearbyint
+# undef nextafter
+# undef nexttoward
+# undef pow
+# undef remainder
+# undef remquo
+# undef rint
+# undef round
+# undef scalbln
+# undef scalbn
+# undef signbit
+# undef sin
+# undef sinh
+# undef sqrt
+# undef tan
+# undef tanh
+# undef tgamma
+# undef trunc
+
# include <__math/abs.h>
# include <__math/copysign.h>
# include <__math/error_functions.h>
@@ -338,8 +407,6 @@ namespace __math {
// fpclassify
-# undef fpclassify
-
// template on non-double overloads to make them weaker than same overloads from MSVC runtime
template <class = int>
_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI int fpclassify(float __x) _NOEXCEPT {
>From 35cc551c5c5fb4afa4d41af107741f690fce137e Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Mon, 10 Jun 2024 11:01:53 -0700
Subject: [PATCH 4/4] Provide comment with an explanation
---
libcxx/include/math.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 893dca8dc1c17..2695be9a497bc 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -307,6 +307,11 @@ long double truncl(long double x);
// back to C++ linkage before including these C++ headers.
extern "C++" {
+// According to section 7.1.4 Use of library functions of the C standard, any
+// function declared in a header may be additionally implemented as a
+// function-like macro defined in the header, so if a library function is
+// declared explicitly when the C standard library header is included, as is
+// the case here, we need to use #undef to remove any macro definition.
# undef acos
# undef acosh
# undef asin
More information about the libcxx-commits
mailing list