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

            Bug ID: 125689
           Summary: [16/17 Regression] [RISCV] [Miscompile] GCC -
                    miscompiles at -O3 since
                    g:699287fd7b3943ac04f78c4897a38b2170d5248e
           Product: gcc
           Version: 16.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: skothadiya at whileone dot in
  Target Milestone: ---

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

Description:
The testcase code involves for loops on various datatypes, compiles correctly
on x86_64 and produces the expected output. However, when compiled for the
riscv64 architecture, the resulting binary yields an incorrect value. The
expected output is 0, but the program returns 5. This miscompilation occurs
with optimization enabled at level -O3.


COMMANDS:
/riscv-gnu-toolchain-build/bin/riscv64-unknown-linux-gnu-gcc -march=rv64gcv -O3
red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv
-Wno-unknown-warning-option -Werror -Wfatal-errors -Wall -Wformat
-Wno-int-in-bool-context -Wno-dangling-pointer
-Wno-compare-distinct-pointer-types -Wno-overflow -Wuninitialized
-Warray-bounds -Wreturn-type -Wno-unused-function -Wno-unused-variable
-Wno-unused-but-set-variable -Wno-unused-value -Wno-address -Wno-bool-compare
-Wno-pointer-sign -Wno-bool-operation -Wno-tautological-compare
-Wno-self-assign -Wno-implicit-const-int-float-conversion
-Wno-constant-conversion -Wno-unused-value
-Wno-tautological-constant-out-of-range-compare -Wno-constant-logical-operand
-Wno-parentheses-equality -Wno-pointer-sign

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
timeout --verbose -k 0.1 4 /riscv-gnu-toolchain-build/bin/qemu-riscv64
user-config.out 1
5

  //Expected Output: 0
  //Actual Output: 5


-- testcase (red.c) --
char a;
short c[8];
short d[7][17][17][17][17];
long e;
short (*f)[17][17][17][17] = d;
int printf(const char *, ...);
int main() {
  for( long g=0; g<8; ++g)
    c[g]=-27;
  for( long g=0; g<7; ++g)
    for( long i=0; i<7; ++i)
      for( long j=0; j<7; ++j)
        for( long k=0; k<17; ++k)
          d[0][g][i][j][k] = i;

  for( unsigned char m=c[1]+27; m<(e<0)+7; m+=4)
    a ^= f[m][0][0][1][1];
  printf("%u\n", a);
}


The issue is Found via fuzzer.

Reply via email to