public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10740] libstdc++: Fix broken backport for std::lcm [PR105844]
@ 2023-05-03 15:16 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-05-03 15:16 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:ad076469c00af1fbe2f848844ab5937587772a70
commit r11-10740-gad076469c00af1fbe2f848844ab5937587772a70
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed May 3 16:05:23 2023 +0100
libstdc++: Fix broken backport for std::lcm [PR105844]
The backport for gcc-11 was incomplete and should have replaced all uses
of std::__is_constant_evaluated with __builtin_is_constant_evaluated.
We also need to prune some additional output for the new tests, because
the r12-4425-g1595fe44e11a96 change to always prune those lines is not
present on the branch.
libstdc++-v3/ChangeLog:
PR libstdc++/105844
* include/experimental/numeric (lcm): Use built-in instead of
__is_constant_evaluated.
* include/std/numeric (__abs_r, lcm): Likewise.
* testsuite/26_numerics/gcd/105844.cc: Add dg-prune-output.
* testsuite/26_numerics/lcm/105844.cc: Likewise.
Diff:
---
libstdc++-v3/include/experimental/numeric | 4 +++-
libstdc++-v3/include/std/numeric | 4 +++-
libstdc++-v3/testsuite/26_numerics/gcd/105844.cc | 2 ++
libstdc++-v3/testsuite/26_numerics/lcm/105844.cc | 2 ++
4 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/experimental/numeric b/libstdc++-v3/include/experimental/numeric
index 3d34e2f2125..51cdfb4d2fe 100644
--- a/libstdc++-v3/include/experimental/numeric
+++ b/libstdc++-v3/include/experimental/numeric
@@ -84,9 +84,11 @@ inline namespace fundamentals_v2
return 0;
_Ct __r = __m2 / __detail::__gcd<make_unsigned_t<_Ct>>(__m2, __n2);
+#if defined _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
if _GLIBCXX17_CONSTEXPR (is_signed_v<_Ct>)
- if (__is_constant_evaluated())
+ if (__builtin_is_constant_evaluated())
return __r * __n2; // constant evaluation can detect overflow here.
+#endif
bool __overflow = __builtin_mul_overflow(__r, __n2, &__r);
__glibcxx_assert(!__overflow);
diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric
index 0091ee17ac2..2828e16b8ea 100644
--- a/libstdc++-v3/include/std/numeric
+++ b/libstdc++-v3/include/std/numeric
@@ -189,9 +189,11 @@ namespace __detail
return 0;
_Ct __r = __m2 / __detail::__gcd<make_unsigned_t<_Ct>>(__m2, __n2);
+#if defined _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
if constexpr (is_signed_v<_Ct>)
- if (__is_constant_evaluated())
+ if (__builtin_is_constant_evaluated())
return __r * __n2; // constant evaluation can detect overflow here.
+#endif
bool __overflow = __builtin_mul_overflow(__r, __n2, &__r);
__glibcxx_assert(!__overflow);
diff --git a/libstdc++-v3/testsuite/26_numerics/gcd/105844.cc b/libstdc++-v3/testsuite/26_numerics/gcd/105844.cc
index 5b6fea7b560..3be18330a0f 100644
--- a/libstdc++-v3/testsuite/26_numerics/gcd/105844.cc
+++ b/libstdc++-v3/testsuite/26_numerics/gcd/105844.cc
@@ -19,3 +19,5 @@ constexpr int b = std::gcd(1, INT_MIN); // { dg-error "overflow" }
// And |LLONG_MIN| cannot be represented in long.
constexpr long long c = std::gcd(LLONG_MIN, 1); // { dg-error "overflow" }
constexpr long long d = std::gcd(1, LLONG_MIN); // { dg-error "overflow" }
+
+// { dg-prune-output "in 'constexpr' expansion" }
diff --git a/libstdc++-v3/testsuite/26_numerics/lcm/105844.cc b/libstdc++-v3/testsuite/26_numerics/lcm/105844.cc
index d0e032e03e0..0b5ef5ae5e9 100644
--- a/libstdc++-v3/testsuite/26_numerics/lcm/105844.cc
+++ b/libstdc++-v3/testsuite/26_numerics/lcm/105844.cc
@@ -20,3 +20,5 @@ constexpr int d = std::lcm(49999, 50000); // { dg-error "overflow" }
constexpr int e = std::lcm(500000u, 499999); // { dg-error "in 'constexpr'" }
constexpr int f = std::lcm(499999u, 500000); // { dg-error "in 'constexpr'" }
// { dg-error "unreachable" "" { target *-*-* } 0 }
+
+// { dg-prune-output "in 'constexpr' expansion" }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-03 15:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-03 15:16 [gcc r11-10740] libstdc++: Fix broken backport for std::lcm [PR105844] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).