[PATCH] libstdc++: Clear padding bits in atomic compare_exchange

Jonathan Wakely jwakely.gcc@gmail.com
Thu Sep 23 20:15:41 GMT 2021


On Thu, 23 Sep 2021, 20:07 Jakub Jelinek via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:

> On Thu, Sep 23, 2021 at 11:08:37AM -0700, Thomas Rodgers wrote:
> > From: Thomas Rodgers <rodgert@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 <trodgers@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
>
>


More information about the Libstdc++ mailing list