]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add test for atomic with padding on heap [PR123875]
authorTomasz Kamiński <tkaminsk@redhat.com>
Wed, 11 Feb 2026 14:05:00 +0000 (15:05 +0100)
committerTomasz Kamiński <tkaminsk@redhat.com>
Wed, 11 Feb 2026 14:23:06 +0000 (15:23 +0100)
C++26 makes the values of uninitialized stack object erroneous,
de-facto requiring their initialization, so adding a test for
variable on heap.

PR libstdc++/123875

libstdc++-v3/ChangeLog:

* testsuite/29_atomics/atomic/cons/static_zero_padding.cc: Move to...
* testsuite/29_atomics/atomic/cons/zero_padding.cc: ...here and
added heap tests. Also fixed trailing whitespaces.

libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc [moved from libstdc++-v3/testsuite/29_atomics/atomic/cons/static_zero_padding.cc with 79% similarity]

similarity index 79%
rename from libstdc++-v3/testsuite/29_atomics/atomic/cons/static_zero_padding.cc
rename to libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
index 506513647c6c393d0dbe6cb60b513a4ae30a9b23..0d6579b5ab6e82342e4311d2976e9e3f1f469cab 100644 (file)
@@ -44,15 +44,15 @@ void test_struct(std::atomic<T>& g, const T& zp)
   T const d{3, 4};
   T t;
 
-  std::memcpy(&t, &zp, sizeof(T)); 
+  std::memcpy(&t, &zp, sizeof(T));
   VERIFY( g.compare_exchange_strong(t, d) );
 
   static std::atomic<T> st(T{1, 2});
-  std::memcpy(&t, &zp, sizeof(T)); 
+  std::memcpy(&t, &zp, sizeof(T));
   VERIFY( st.compare_exchange_strong(t, d) );
 
   thread_local std::atomic<T> tl(T{1, 2});
-  std::memcpy(&t, &zp, sizeof(T)); 
+  std::memcpy(&t, &zp, sizeof(T));
   VERIFY( tl.compare_exchange_strong(t, d) );
 
   std::atomic<T> l(T{1, 2});
@@ -61,6 +61,13 @@ void test_struct(std::atomic<T>& g, const T& zp)
   VERIFY( l.compare_exchange_strong(t, d) );
 #endif
 
+  std::atomic<T>* h = new std::atomic<T>(T{1, 2});
+  std::memcpy(&t, &zp, sizeof(T));
+#if __cplusplus >= 201402L // Remove once PR114865 is fixed
+  VERIFY( h->compare_exchange_strong(t, d) );
+#endif
+  delete h;
+
   constexpr std::atomic<T> cl(T{1, 2});
 }
 
@@ -75,21 +82,26 @@ void test_floating(std::atomic<T>& g, const T& zp)
   T const d = T(7.5);
   T t;
 
-  std::memcpy(&t, &zp, sizeof(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)); 
+  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)); 
+  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)); 
+  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