From: Tomasz Kamiński Date: Tue, 17 Feb 2026 12:35:39 +0000 (+0100) Subject: libstdc++: Correct requirements for atomic/cons/zero_padding.cc tests again [PR124124] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3ba5ad088cebe117f857329a35b95d18d97a808;p=thirdparty%2Fgcc.git libstdc++: Correct requirements for atomic/cons/zero_padding.cc tests again [PR124124] 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 to... * testsuite/29_atomics/atomic_float/zero_padding.cc: Extracted test_floating. Reviewed-by: Jonathan Wakely Signed-off-by: Tomasz Kamiński --- 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& g, const T& zp) constexpr std::atomic cl(T{1, 2}); } -#if __cplusplus >= 202002L -long double zld(10.5); -constexpr std::atomic cld(10.5); -std::atomic gld(10.5); - -template -void test_floating(std::atomic& 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 st(T(10.5)); - std::memcpy(&t, &zp, sizeof(T)); - VERIFY( st.compare_exchange_strong(t, d) ); - - thread_local std::atomic tl(T(10.5)); - std::memcpy(&t, &zp, sizeof(T)); - VERIFY( tl.compare_exchange_strong(t, d) ); - - std::atomic l(T(10.5)); - std::memcpy(&t, &zp, sizeof(T)); - VERIFY( l.compare_exchange_strong(t, d) ); - - std::atomic* h = new std::atomic(T(10.5)); - std::memcpy(&t, &zp, sizeof(T)); - VERIFY( h->compare_exchange_strong(t, d) ); - delete h; - - constexpr std::atomic 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 +#include +#include + +long double zld(10.5); +constexpr std::atomic cld(10.5); +std::atomic gld(10.5); + +template +void test_floating(std::atomic& 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 st(T(10.5)); + std::memcpy(&t, &zp, sizeof(T)); + VERIFY( st.compare_exchange_strong(t, d) ); + + thread_local std::atomic tl(T(10.5)); + std::memcpy(&t, &zp, sizeof(T)); + VERIFY( tl.compare_exchange_strong(t, d) ); + + std::atomic l(T(10.5)); + std::memcpy(&t, &zp, sizeof(T)); + VERIFY( l.compare_exchange_strong(t, d) ); + + std::atomic* h = new std::atomic(T(10.5)); + std::memcpy(&t, &zp, sizeof(T)); + VERIFY( h->compare_exchange_strong(t, d) ); + delete h; + + constexpr std::atomic cl(T(10.5)); +} + +int main() +{ + test_floating(gld, zld); +}