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

            Bug ID: 116085
           Summary: RISC-V: Miscompile at -O2 with zbb
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

There may be a way to show the bug using a single file but I hadn't had success
in merging them yet.

Testcase:

driver.c:
int a = 2;
unsigned b = 0x80000000;
int arr_5[2][23];
void test(int, unsigned, int);
int main() {
  test(a, b, 1);
  __builtin_printf("%d\n", arr_5[1][0]);
}


func.c:
extern int arr_5[2][23];
#define c(a, b)                                                               
\
  ({                                                                          
\
    long d = a;                                                               
\
    long e = b;                                                               
\
    d > e ? d : e;                                                            
\
  })
void test(int f, unsigned g, int h) {
  for (int i = 0; i < h; i = f)
    arr_5[1][i] = h ? c(g, 7) : 0;
}


Commands:
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  -march=rv64id_zbb -O2 -c func.c -o func.o
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  -c driver.c -o driver.o
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  func.o driver.o -o user-config.out
> QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true,zbb=true
>  timeout --verbose -k 0.1 4 
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/qemu-riscv64 
> user-config.out
7

> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  -O2 -c func.c -o func.o
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  -c driver.c -o driver.o
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/riscv64-unknown-linux-gnu-gcc
>  func.o driver.o -o user-config.out
> QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true,zbb=true
>  timeout --verbose -k 0.1 4 
> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/bin/qemu-riscv64 
> user-config.out
-2147483648

Found via fuzzer.

Reply via email to