public inbox for gcc-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 r12-5848] libstdc++: Fix undefined shift when _Atomic_word is 64-bit Date: Wed, 8 Dec 2021 23:47:12 +0000 (GMT) [thread overview] Message-ID: <20211208234712.026E23858C27@sourceware.org> (raw) https://gcc.gnu.org/g:c15aa46cca0649b68613d3292cf71c7cc57ef78f commit r12-5848-gc15aa46cca0649b68613d3292cf71c7cc57ef78f Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Dec 8 19:36:24 2021 +0000 libstdc++: Fix undefined shift when _Atomic_word is 64-bit The check for _Atomic_word being 32-bit is just a normal runtime condition for C++11 and C++14, because it doesn't use if-constexpr. That means the 1LL << (CHAR_BIT * sizeof(_Atomic_word)) expression expands to 1LL << 64 on Solaris, which is ill-formed. This adds another indirection so that the shift width is zero if the code is unreachable. libstdc++-v3/ChangeLog: * include/bits/shared_ptr_base.h (_Sp_counted_base::_M_release()): Make shift width conditional on __double_word condition. Diff: --- libstdc++-v3/include/bits/shared_ptr_base.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 90ad30947b0..f315d8f354f 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -325,8 +325,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr bool __aligned = __alignof(long long) <= alignof(void*); if _GLIBCXX17_CONSTEXPR (__lock_free && __double_word && __aligned) { - constexpr long long __unique_ref - = 1LL + (1LL << (__CHAR_BIT__ * sizeof(_Atomic_word))); + constexpr int __wordbits = __CHAR_BIT__ * sizeof(_Atomic_word); + constexpr int __shiftbits = __double_word ? __wordbits : 0; + constexpr long long __unique_ref = 1LL + (1LL << __shiftbits); auto __both_counts = reinterpret_cast<long long*>(&_M_use_count); _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
reply other threads:[~2021-12-08 23:47 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=20211208234712.026E23858C27@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).