https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122000

            Bug ID: 122000
           Summary: [13/14/15/16 Regression] __sync_add_and_fetch(long
                    long) on armv7a ignores the lower 32 bits
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: armv7a-hardfloat-linux-gnueabi

Created attachment 62418
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62418&action=edit
reduced testcase

Output:
$ armv7a-hardfloat-linux-gnueabi-gcc testcase.c -static -O
$ qemu-arm -- ./a.out 
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted


It the asm output on gcc-16:
...
main:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        push    {r4, r5, r6, lr}
        movw    r3, #:lower16:.LANCHOR0
        movt    r3, #:upper16:.LANCHOR0
        movw    r2, #47768
        movt    r2, 65244
        mov     r0, #0
        mov     r1, r2
        dmb     ish
.L3:
        ldrexd  r4, r5, [r3]
        adds    r4, r4, r0
        adc     r5, r5, r1
        strexd  ip, r4, r5, [r3]
...

any value in 'c' is not read at all; r0 is set to 0

At least __sync_sub_and_fetch() has the same issue.

$ armv7a-hardfloat-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-armv7a-hardfloat/bin/armv7a-hardfloat-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-20250916055605-r16-3901-g41d8c4e150f21a-checking-yes-rtl-df-extra-armv7a-hardfloat/bin/../libexec/gcc/armv7a-hardfloat-linux-gnueabi/16.0.0/lto-wrapper
Target: armv7a-hardfloat-linux-gnueabi
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--enable-libsanitizer --with-float=hard --with-fpu=vfpv4 --with-arch=armv7-a
--with-sysroot=/usr/armv7a-hardfloat-linux-gnueabi --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=armv7a-hardfloat-linux-gnueabi
--with-ld=/usr/bin/armv7a-hardfloat-linux-gnueabi-ld
--with-as=/usr/bin/armv7a-hardfloat-linux-gnueabi-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-20250916055605-r16-3901-g41d8c4e150f21a-checking-yes-rtl-df-extra-armv7a-hardfloat
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 16.0.0 20250916 (experimental) (GCC)

Reply via email to