On Thu, 5 Mar 2026 at 09:15, Tomasz Kamiński <[email protected]> wrote:
>
> The test uses dg-require-atomic-cmpxchg-word that checks if atomic compare
> exchange is available for pointer sized integers, and then test types that
> are eight bytes in size. This causes issue for targets for which pointers
> are four byte and libatomic is not present, like arm-none-eabi.
>
> This patch addresses by using short member in TailPadding and MidPadding,
> instead of int. This reduces the size of types to four bytes, while keeping
> padding bytes present.
>
>         PR libstdc++/124124
>
> libstdc++-v3/ChangeLog:
>
>         * testsuite/29_atomics/atomic/cons/zero_padding.cc: Limit size of
>         test types to four bytes.
>
> Signed-off-by: Tomasz Kamiński <[email protected]>
> ---
> Tested on x86_64-linux and Torbjorn Svensson confirmed it fixes
> arm-none-eabi.
>
> OK for trunk and backport to 13/14/15, as I backported the test alraady?

OK for all branches.

Maybe we should add alignas(4) to the structs, because on byte-aligned
targets like cris-elf there won't be any padding. We can do that on
trunk only though, it doesn't need to be in this patch and doesn't
need to be backported.


>
>  .../testsuite/29_atomics/atomic/cons/zero_padding.cc      | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc 
> b/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> index f85ac4859ec..4418b6c07e6 100644
> --- a/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> +++ b/libstdc++-v3/testsuite/29_atomics/atomic/cons/zero_padding.cc
> @@ -6,12 +6,12 @@
>  #include <cstring>
>  #include <testsuite_hooks.h>
>
> -struct TailPadding { int i; char c; };
> +struct TailPadding { short i; char c; };
>  TailPadding ztail{1, 2}; // zeroed-padding
>  constexpr std::atomic<TailPadding> ctail(TailPadding{1,2});
>  std::atomic<TailPadding> gtail(TailPadding{1,2});
>
> -struct MidPadding { char c; int x; };
> +struct MidPadding { char c; short i; };
>  MidPadding zmid{1, 2}; // zeroed-padding
>  constexpr std::atomic<MidPadding> cmid(MidPadding{1,2});
>  std::atomic<MidPadding> gmid(MidPadding{1,2});
> @@ -25,12 +25,12 @@ struct Ctor
>  {
>    Ctor() = default;
>
> -  constexpr Ctor(char pc, char pi)
> +  constexpr Ctor(char pc, short pi)
>      : c(pc), i(pi)
>    {}
>
>    char c;
> -  int i;
> +  short i;
>  };
>
>  Ctor zctor{1, 2}; // zeroed-padding
> --
> 2.53.0
>

Reply via email to