]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Correct requirements for atomic/cons/zero_padding.cc tests again [PR124124]
authorTomasz Kamiński <tkaminsk@redhat.com>
Tue, 17 Feb 2026 12:35:39 +0000 (13:35 +0100)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 17 Feb 2026 16:33:35 +0000 (17:33 +0100)
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 <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
libstdc++-v3/testsuite/29_atomics/atomic_float/zero_padding.cc [new file with mode: 0644]

index 3c8a4a8f428ad2772986d12d74b7fd1adf30a937..f85ac4859ec5c48d7518f4ae9d12e199985025c8 100644 (file)
@@ -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 (file)
index 0000000..26e9d11
--- /dev/null
@@ -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);
+}