On Thu, 23 Sep 2021, 20:07 Jakub Jelinek via Libstdc++, < libstd...@gcc.gnu.org> wrote:
> On Thu, Sep 23, 2021 at 11:08:37AM -0700, Thomas Rodgers wrote: > > From: Thomas Rodgers <rodg...@twrodgers.com> > > > > This change implements P0528 which requires that padding bits not > > participate in atomic compare exchange operations. All arguments to the > > Thanks for working on this. > > > generic template are 'sanitized' by the __builtin_clear_padding intrinsic > > before they are used in atomic compare_exchange. This alrequires that any > > stores also sanitize the incoming value. > > Not a review, just random nit. > Shouldn't the __builtin_clear_padding calls be guarded with > #if __has_builtin(__builtin_clear_padding) > or #ifdef _GLIBCXX_HAVE_BUILTIN_CLEAR_PADDING defined based on that? > Yes. It can just use __has_builtin directly. All the compilers we care about support that now. I think clang doesn't support it (yet?), and it doesn't support the MSVC > __builtin_zero_non_value_bits (with very similar, but slightly different, > behavior). > > > Signed-off-by: Thomas Rodgers <trodg...@redhat.com> > > > > libstdc++=v3/ChangeLog: > > > > * include/std/atomic (atomic<T>::atomic(_Tp) clear padding for > > __cplusplus > 201703L. > > (atomic<T>::store()) Clear padding. > > (atomic<T>::exchange()) Likewise. > > (atomic<T>::compare_exchange_weak()) Likewise. > > (atomic<T>::compare_exchange_strong()) Likewise. > > * testsuite/29_atomics/atomic/compare_exchange_padding.cc: New > > test. > > Jakub > >