Skip to content

[RISC-V] rv64gcv miscompile with pass --riscv-gather-scatter-lowering #89833

@patrick-rivos

Description

@patrick-rivos

Testcase:

short a;
long long b;
int c = 4;
signed char d[10], e[10];
int main() {
  for (long h = 0; h < 10; ++h)
    d[h] = 1;
  for (int h = 0; h < 10; h += c || a)
    e[h] = 256 / d[h];
  __builtin_printf("%d\n", e[1]);
}

Commands:

> /scratch/tc-testing/tc-apr-23/build-rv64gcv/build-llvm-linux/bin/clang -fwrapv -march=rv64gcv -flto -O2 red.c -o red.out
> /scratch/tc-testing/tc-apr-23/build-rv64gcv/bin/qemu-riscv64 red.out
1
> /scratch/tc-testing/tc-apr-23/build-rv64gcv/build-llvm-linux/bin/clang -fwrapv red.c -o red.out
> /scratch/tc-testing/tc-apr-23/build-rv64gcv/bin/qemu-riscv64 red.out
0

Discovered/tested using cebc960 (not bisected)

Found via fuzzer.

-Wl,-mllvm,-opt-bisect-limit points to pass (70) RISC-V gather/scatter lowering on function (main)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions