Skip to content

[RISC-V] Miscompile on rv64gcv with -O3 #134126

@ewlu

Description

@ewlu

Testcase:

long a;
long c;
signed char d = 2;
char e;
unsigned f;
short j;
long long ac;
int i = 2320478;
_Bool l = 1;
_Bool m;
int n = 9;
int q = 18004875;
unsigned u[15][15][15];
long long w[5][15];
void g(int i, short j, _Bool l, _Bool m, int n, int q,
       unsigned u[][15][15], long long w[][15]) {
  if (n) {
    for (signed char x = 0; x < (char)q + 132; x += i - 90)
      for (signed y = 0; y < 14; y += ~50 + 54) {
        c = w[x][x];
        d *= l && u[x][y][y];
        e = u[x][x][y];
      }
  }
  f += a ? m : 0;
}
int main() {
  for (int x = 0; x < 15; ++x)
    for (int y = 0; y < 15; ++y)
      for (int z = 0; z < 15; ++z)
        u[x][y][z] = 807197787;
  g(i, j, l, m, n, q, u, w);
  ac = d;
  __builtin_printf("%llu\n", ac);
}

Commands

# riscv
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv_zvl256b -flto -O3 ./red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv
$ QEMU_CPU=rv64,vlen=256,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 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
0

$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv_zvl256b -flto -O2 ./red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ QEMU_CPU=rv64,vlen=256,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 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
2

# x86
$ ./native.out
2

bisected to 25e4333 as the first bad commit

Tried reducing testcase more by eliminating dead code but that causes the failure to disappear. Also at some point during manual reduction, -O2 also started to fail but now it's generating expected output. If anyone wants, I can provide the unreduced testcase with the -O2 failure as well.

Found via fuzzer.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions