https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122267
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Tomasz KamiĆski from comment #5)
> I have realized that I have unintionally changed
> atomic_ref<double>::required_aligment from __alignof__(double) is 8 to
> alignof(double) which is 4.
>
> The atomic_ref<double> constructor requires that the object is aligned to
> required_aligment, so you cannot bind atomic_ref to s.b in your example if
> it's aligment is not 4.
In the above case s.b has alignment of 4, but that is still not enough for
64-bit atomics which require 8 byte alignment for atomicity.
Anyway, better testcase would be
struct alignas (8) S { char a; double b; } s;
because the earlier struct S could have s.b actually aligned, in this case it
can't.
I think __atomic_compare_exchange (&s.b, ...) etc. will not crash at least in
the usual CPU setting where non-aligned loads/stores are ok, but the CPU
doesn't guarantee the operation is actually atomic even when LOCK prefix is
used if it is not appropriately aligned.