public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10740] libstdc++: Fix broken backport for std::lcm [PR105844] Date: Wed, 3 May 2023 15:16:30 +0000 (GMT) [thread overview] Message-ID: <20230503151630.510DE3858C31@sourceware.org> (raw) 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" }
reply other threads:[~2023-05-03 15:16 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230503151630.510DE3858C31@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).