aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-09-16 17:50:21 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-09-16 21:19:09 +0100
commit47deb1ef874c078ac51bc1970a3324f5c8002815 (patch)
tree482f8d9f56a6fcfcc882b49b02336609e387670d
parent7107ea6fb933f1e928593c7e92edfd64ccf0df63 (diff)
downloadgcc-47deb1ef874c078ac51bc1970a3324f5c8002815.zip
gcc-47deb1ef874c078ac51bc1970a3324f5c8002815.tar.gz
gcc-47deb1ef874c078ac51bc1970a3324f5c8002815.tar.bz2
libstdc++: Fix compare_exchange_padding.cc test for std::atomic_ref
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.
-rw-r--r--libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc
index 1b1a12d..e9f8a4b 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/compare_exchange_padding.cc
@@ -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