]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix undefined shift when _Atomic_word is 64-bit
authorJonathan Wakely <jwakely@redhat.com>
Wed, 8 Dec 2021 19:36:24 +0000 (19:36 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 8 Dec 2021 23:41:03 +0000 (23:41 +0000)
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.

libstdc++-v3/include/bits/shared_ptr_base.h

index 90ad30947b0499952ef9eb4006c2e1e596266816..f315d8f354fa3c946f89fad99c6841535ddca019 100644 (file)
@@ -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);