Message ID | CACb0b4kFPDWmG-u-QMznjWwbCn53etpq16X2F0=Lr3ftQzX-6w@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | [committed] libstdc++: Fix undefined shift when _Atomic_word is 64-bit | expand |
Hi Jonathan, >> > Ah yes, so we need to disable this optimization. Patch coming up ... >> >> Gah, I remembered to check that: >> >> constexpr bool __double_word >> = sizeof(long long) == 2 * sizeof(_Atomic_word); >> // The ref-count members follow the vptr, so are aligned to >> // alignof(void*). >> constexpr bool __aligned = __alignof(long long) <= alignof(void*); >> if _GLIBCXX17_CONSTEXPR (__lock_free && __double_word && __aligned) >> >> >> But for C++11 and C++14 that is a normal runtime condition not >> if-constexpr, so the undefined shift still gets compiled, even though >> it can never be reached at runtime. > > Fixed like so. Tested sparc-sun-solaris2.11, pushed to trunk. great, thanks a lot. Rainer
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);