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

            Bug ID: 91635
           Summary: wrong code at -O2 with __builtin_add_overflow()
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: riscv64-unknown-linux-gnu

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

Output:
$ /repo/gcc-trunk/binary-latest-riscv64/bin/riscv64-unknown-linux-gnu-gcc -O2
testcase.c -static
$ qemu-riscv64 ./a.out 
Aborted

At the assembly level:
foo:
# testcase.c:6:   c <<= __builtin_add_overflow (-c, -1, &b);
        not     a0,a0   # tmp84, tmp89
        lui     a5,%hi(b)       # tmp81,
        sh      a0,%lo(b)(a5)   # tmp84, b
# testcase.c:9: }
        li      a0,0            #,
        ret

Constant 0 is loaded to the register; that is wrong.

$ riscv64-unknown-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-riscv64/bin/riscv64-unknown-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-275299-checking-yes-rtl-df-extra-riscv64/bin/../libexec/gcc/riscv64-unknown-linux-gnu/10.0.0/lto-wrapper
Target: riscv64-unknown-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--with-cloog --with-ppl --with-isl
--with-sysroot=/usr/riscv64-unknown-linux-gnu --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=riscv64-unknown-linux-gnu
--with-ld=/usr/bin/riscv64-unknown-linux-gnu-ld
--with-as=/usr/bin/riscv64-unknown-linux-gnu-as --disable-multilib
--disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-275299-checking-yes-rtl-df-extra-riscv64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.0 20190902 (experimental) (GCC)

Reply via email to