https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123414
Bug ID: 123414
Summary: [16 Regression] [RISCV] [Miscompile] GCC - riscv64
target, miscompiles at -O3 since
https://gcc.gnu.org/cgit/gcc/commit/?h=trunk&id=f5ddd4
ba0ba
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: skothadiya at whileone dot in
Target Milestone: ---
Description:
The C code involve for loops on an unsigned, int, long & signed char, 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 34, but the program returns 0. This miscompilation
occurs specifically with optimization enabled at level -O3.
Compiler flags:
-march=rv64gcv_zvl1024b -flto -mrvv-max-lmul=m8 -O3
Reproduction Steps:
1. Compile the test case with GCC for riscv64 using the -O3 flag.
2. Execute the compiled binary.
3. Observe the output.
COMMANDS:
/mnt/data1/sujayk/cifuzz-pad/riscv-gnu-toolchain-build/bin/riscv64-unknown-linux-gnu-gcc
-march=rv64gcv_zvl1024b -flto -mrvv-max-lmul=m8 -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
gcc -O1 red.c -o native.out -fno-strict-aliasing -fwrapv -w
QEMU_CPU=rv64,vlen=1024,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
/mnt/data1/sujayk/cifuzz-pad/riscv-gnu-toolchain-build/bin/qemu-riscv64
user-config.out 1
0
timeout --verbose -k 0.1 1 ./native.out 1
34
//Expected Output: 34
//Actual Output: 0
-- testcase (red.c) --
int printf( const char *, ...);
signed char a=2;
long long b;
long c = 93;
int e[1][9];
void g( long cc, int ee[][9]) {
for (int i=0; i<4; i++)
for (int j=0; j<5; j++)
for (unsigned k=0; k<9; k++) {
a *= cc;
for (int l=0; l<6; l+=(ee[k]<=0)+2)
;
}
}
int main() {
g( c, e);
b = (int)a;
printf("%llu\n", b);
}