]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix compare_exchange_padding.cc test for std::atomic_ref
authorJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 16:50:21 +0000 (17:50 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 20:19:09 +0000 (21:19 +0100)
This test was written assuming that std::atomic_ref clears its target's
padding on construction, but that could introduce data races. Change the
test to store a value after construction and check that its padding is
cleared by the store.

libstdc++-v3/ChangeLog:

* testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc:
Store value with non-zero padding bits after construction.

libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc

index 1b1a12dddda581a9353ed104ca28d0c56dc618bf..e9f8a4bdf2ac66d54f8540fccd2efa6c4719e717 100644 (file)
@@ -20,14 +20,15 @@ int
 main ()
 {
   S s;
-  fill_struct(s);
-  s.c = 'a';
-  s.s = 42;
-
   S ss{ s };
+  fill_struct(ss);
+  ss.c = 'a';
+  ss.s = 42;
+
   std::atomic_ref<S> as{ s };
+  as.store(ss);
   auto ts = as.load();
-  VERIFY( !compare_struct(ss, ts) ); // padding cleared on construction
+  VERIFY( !compare_struct(ss, ts) ); // padding cleared on store
   as.exchange(ss);
   auto es = as.load();
   VERIFY( compare_struct(ts, es) ); // padding cleared on exchange