On Tue, 17 Feb 2026 at 14:37, Tomasz Kamiński <[email protected]> wrote:
>
> The requirements introduced in previous patch r16-7548-g060d7c2a9c1fe1,
> were not sufficient for types of size bigger than 64B (Ctor or long double),
> as dg-add-options of libatomic, links libatomic only if it is required to
> handle atomics of 64B types or pointers.
>
> This patch addresses above, by reducing the size of Ctor struct to fit in
> 64 bytes, and moving long double test to separate file, that requires and
> links with libatomic.
>
> PR libstdc++/124124
>
> libstdc++-v3/ChangeLog:
>
> * testsuite/29_atomics/atomic/cons/zero_padding.cc: Updated
> Ctor class and move test_floating...
> * testsuite/29_atomics/atomic_float/zero_padding.cc: Extracted
> test_floating.
> ---
> Tested on x86_64-linux and Rainer Orth confirmed that the patch
> now works on Solaris. OK for trunk.
OK
We should look into linking the tests to libatomic_asneeded.so instead
of libatomic, but that will only work for targets using GNU ld, or
with equivalent linker script support.
Maybe the dg-add-options libatomic should decide if we have
libatomic_asneeded and if we do, just link to that unconditionally.
That would mean that it's not a no-op for x86, and we would get
working atomics for all object sizes (I'm not sure why g++ doesn't add
that for the testsuite automatically).
>
> For GCC-15 and earield branches, I plan to squash the initial commit
> and follow up changes to this test (heap and fixes) into single commit,
> with four cherry-picked from lines. Does that sound OK?
Yes, that's cleaner, thanks.
>
> .../29_atomics/atomic/cons/zero_padding.cc | 41 +----------------
> .../29_atomics/atomic_float/zero_padding.cc | 45 +++++++++++++++++++
> 2 files changed, 46 insertions(+), 40 deletions(-)
> create mode 100644
> libstdc++-v3/testsuite/29_atomics/atomic_float/zero_padding.cc
>
> diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> b/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> index 3c8a4a8f428..f85ac4859ec 100644
> --- a/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> @@ -26,12 +26,11 @@ struct Ctor
> Ctor() = default;
>
> constexpr Ctor(char pc, char pi)
> - : c(pc), i(pi), d(pc)
> + : c(pc), i(pi)
> {}
>
> char c;
> int i;
> - char d;
> };
>
> Ctor zctor{1, 2}; // zeroed-padding
> @@ -67,48 +66,10 @@ void test_struct(std::atomic<T>& g, const T& zp)
> constexpr std::atomic<T> cl(T{1, 2});
> }
>
> -#if __cplusplus >= 202002L
> -long double zld(10.5);
> -constexpr std::atomic<long double> cld(10.5);
> -std::atomic<long double> gld(10.5);
> -
> -template<typename T>
> -void test_floating(std::atomic<T>& g, const T& zp)
> -{
> - T const d = T(7.5);
> - T t;
> -
> - std::memcpy(&t, &zp, sizeof(T));
> - VERIFY( g.compare_exchange_strong(t, d) );
> -
> - static std::atomic<T> st(T(10.5));
> - std::memcpy(&t, &zp, sizeof(T));
> - VERIFY( st.compare_exchange_strong(t, d) );
> -
> - thread_local std::atomic<T> tl(T(10.5));
> - std::memcpy(&t, &zp, sizeof(T));
> - VERIFY( tl.compare_exchange_strong(t, d) );
> -
> - std::atomic<T> l(T(10.5));
> - std::memcpy(&t, &zp, sizeof(T));
> - VERIFY( l.compare_exchange_strong(t, d) );
> -
> - std::atomic<T>* h = new std::atomic<T>(T(10.5));
> - std::memcpy(&t, &zp, sizeof(T));
> - VERIFY( h->compare_exchange_strong(t, d) );
> - delete h;
> -
> - constexpr std::atomic<T> cl(T(10.5));
> -}
> -#endif
> -
> int main()
> {
> test_struct(gtail, ztail);
> test_struct(gmid, zmid);
> test_struct(gbit, zbit);
> test_struct(gctor, zctor);
> -#if __cplusplus >= 202002L
> - test_floating(gld, zld);
> -#endif
> }
> diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_float/zero_padding.cc
> b/libstdc++-v3/testsuite/29_atomics/atomic_float/zero_padding.cc
> new file mode 100644
> index 00000000000..26e9d11b574
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/29_atomics/atomic_float/zero_padding.cc
> @@ -0,0 +1,45 @@
> +// { dg-do run { target c++20 } }
> +// { dg-require-effective-target libatomic_available }
> +// { dg-additional-options "[atomic_link_flags [get_multilibs]] -latomic" }
> +
> +#include <atomic>
> +#include <cstring>
> +#include <testsuite_hooks.h>
> +
> +long double zld(10.5);
> +constexpr std::atomic<long double> cld(10.5);
> +std::atomic<long double> gld(10.5);
> +
> +template<typename T>
> +void test_floating(std::atomic<T>& g, const T& zp)
> +{
> + T const d = T(7.5);
> + T t;
> +
> + std::memcpy(&t, &zp, sizeof(T));
> + VERIFY( g.compare_exchange_strong(t, d) );
> +
> + static std::atomic<T> st(T(10.5));
> + std::memcpy(&t, &zp, sizeof(T));
> + VERIFY( st.compare_exchange_strong(t, d) );
> +
> + thread_local std::atomic<T> tl(T(10.5));
> + std::memcpy(&t, &zp, sizeof(T));
> + VERIFY( tl.compare_exchange_strong(t, d) );
> +
> + std::atomic<T> l(T(10.5));
> + std::memcpy(&t, &zp, sizeof(T));
> + VERIFY( l.compare_exchange_strong(t, d) );
> +
> + std::atomic<T>* h = new std::atomic<T>(T(10.5));
> + std::memcpy(&t, &zp, sizeof(T));
> + VERIFY( h->compare_exchange_strong(t, d) );
> + delete h;
> +
> + constexpr std::atomic<T> cl(T(10.5));
> +}
> +
> +int main()
> +{
> + test_floating(gld, zld);
> +}
> --
> 2.53.0
>