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

            Bug ID: 114202
           Summary: [14] RISC-V rv64gcv: miscompile at -O3
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick at rivosinc dot com
  Target Milestone: ---

Testcase:
int printf(const char *, ...);
signed char a, d;
_Bool b;
signed char c[324];
int e;
int main() {
  c[63] = 50;
  for (int f = 0; f < 9; f++) {
    for (unsigned g = 0; g < 12; g++)
      for (char h = 0; h < 8; h++)
        e = a += c[g * 9];
    b = e ? d : 0;
  }
  printf("%d\n", a);
}

Commands:
> /scratch/tc-testing/tc-feb-20/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc 
> -march=rv64gcv -O3 -fwrapv red.c -o red.out
> /scratch/tc-testing/tc-feb-20-llvm/build/bin/qemu-riscv64 red.out
32
> /scratch/tc-testing/tc-feb-20/build-rv64gcv/bin/riscv64-unknown-linux-gnu-gcc 
> -march=rv64gcv -O2 -fwrapv red.c -o red.out
> /scratch/tc-testing/tc-feb-20-llvm/build/bin/qemu-riscv64 red.out
16

With the overflows (-fwrapv) the expected value is 16.

Tested/found using r14-9084-g61ab046a327 (not bisected)

Found via fuzzer.

Reply via email to