// { dg-do run { target c++11 } } // { dg-require-atomic-cmpxchg-word "" } // { dg-add-options libatomic } #include #include #include struct TailPadding { short i; char c; }; TailPadding ztail{1, 2}; // zeroed-padding constexpr std::atomic ctail(TailPadding{1,2}); std::atomic gtail(TailPadding{1,2}); struct MidPadding { char c; short i; }; MidPadding zmid{1, 2}; // zeroed-padding constexpr std::atomic cmid(MidPadding{1,2}); std::atomic gmid(MidPadding{1,2}); struct BitPadding { int : 4; int i : 5; int : 4; int j : 5; int : 4; }; BitPadding zbit{1, 2}; // zeroed-padding constexpr std::atomic cbit(BitPadding{1,2}); std::atomic gbit(BitPadding{1,2}); struct Ctor { Ctor() = default; constexpr Ctor(char pc, short pi) : c(pc), i(pi) {} char c; short i; }; Ctor zctor{1, 2}; // zeroed-padding constexpr std::atomic cctor(Ctor{1,2}); std::atomic gctor(Ctor{1,2}); template void test_struct(std::atomic& g, const T& zp) { T const d{3, 4}; T t; std::memcpy(&t, &zp, sizeof(T)); VERIFY( g.compare_exchange_strong(t, d) ); static std::atomic st(T{1, 2}); std::memcpy(&t, &zp, sizeof(T)); VERIFY( st.compare_exchange_strong(t, d) ); thread_local std::atomic tl(T{1, 2}); std::memcpy(&t, &zp, sizeof(T)); VERIFY( tl.compare_exchange_strong(t, d) ); std::atomic l(T{1, 2}); std::memcpy(&t, &zp, sizeof(T)); VERIFY( l.compare_exchange_strong(t, d) ); std::atomic* h = new std::atomic(T{1, 2}); std::memcpy(&t, &zp, sizeof(T)); VERIFY( h->compare_exchange_strong(t, d) ); delete h; constexpr std::atomic cl(T{1, 2}); } int main() { test_struct(gtail, ztail); test_struct(gmid, zmid); test_struct(gbit, zbit); test_struct(gctor, zctor); }