Skip to content

[RISC-V] Miscompile at -O[23] #149335

@ewlu

Description

@ewlu

Testcase:

unsigned short a[10];
void b(short c, short i[]) {
  for (short k = 1; k < 9; k += 2)
    a[k] = c ? i[k] : i[k + 1];
}
long long m;
short c;
short i[10];
void checksum() {
  for (int k = 0; k < 10; ++k)
    m ^= a[k] + (m < 6) + (m > 2);
}
int main() {
  for (int k = 0; k < 10; ++k)
    a[k] = 3;
  b(c, i);
  checksum();
  __builtin_printf("%llu\n", m);
}

Commands

# -O3
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -O3 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ 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 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
65541

# -O2
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -O2 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ 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 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
65541

# -O1
$ /scratch/ewlu/daily-upstream-build/build-gcv/bin/clang -march=rv64gcv -O1 red.c -o user-config.out -fsigned-char -fno-strict-aliasing -fwrapv 
$ 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 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1
0

Bisected to 60ad6e3 as the first bad commit.

Found via fuzzer

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions