https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126230
Tomasz Kamiński <tkaminsk at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tkaminsk at gcc dot gnu.org
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #5 from Tomasz Kamiński <tkaminsk at gcc dot gnu.org> ---
The program in the example is not required to return zero, prior the
implementation of the C++20 P0528: The Curious Case of Padding Bits, Featuring
Atomic Compare-and-Exchange. This is because prior the paper, the
compare_exchange is defined in terms of comparison of object representation
(https://timsong-cpp.github.io/cppwp/n4659/atomics.types.operations#18),
including padding bits, and the values of padding bits are not preserved when
to object is stored, including:
* when it is stored in atomic, by awp.store(wp);
* when it is returned by value from load, auto expected =
atomic_padding.load();
This is not only theoretical concern, as the example code does not work on
GCC-12 with optimization enabled (see https://godbolt.org/z/Y8KEcTchK). This is
because the load of WithPadding is decomposed (by scalar replacement of
aggreates) into two separate loads:
mov WORD PTR [rsp+14], dx // load short big
movzx edx, al
mov BYTE PTR [rsp+12], al // load char small
In consequence, the code that was not working when compiled with GCC 12, remain
not working when linking GCC 12 and GCC 13, this is not regression nor the ABI
break.
Note that we have decide to implement P0528 (and later fixed) as DR to all
previous standards in GCC 13, as we recognize this is something that
programmers expect to just work. However, to benefit from that the whole
program needs to be compiled with GCC 13.