sifive / freedom-tools

Tools for SiFive's Freedom Platform
217 stars 52 forks source link

Possible compiler bug #76

Closed jan-wassenberg closed 1 year ago

jan-wassenberg commented 3 years ago

Hi, we encountered what appears to be a compiler bug.

echo "#include <riscv_vector.h>

#include <random>

// Removing attribute hides the bug.
__attribute__((noinline)) void NestedFunc(vbool32_t a, vbool32_t b) {
  if (vpopc_m_b32(a) != vpopc_m_b32(b)) abort();
}

__attribute__((noinline)) void Crash() {
  std::mt19937 rng;
  const vuint32m1_t v0 = vmv_v_x_u32m1(0);
  const vbool32_t mask = vmseq_vv_u32m1_b32(v0, v0);
  NestedFunc(mask, mask);
}

int main(int, char**) {
  Crash();
  return 0;
}
" >> crash.cc

$RVVCC --version && $RVVCC -O0 -march=rv64gcv crash.cc -o crash.o && qemu-riscv64 --version && qemu-riscv64 -cpu rv64,x-v=true,vlen=512,elen=64,vext_spec=v1.0 crash.o

Output:

riscv64-unknown-elf-g++ (SiFive GCC 10.1.0-2020.08.2) 10.1.0
qemu-riscv64 version 5.1.0 (v5.0.0-2894-g73537b968d)
Segmentation fault

It looks like the stack is being corrupted in connection with the rng object (2504 bytes). Commenting it out prevents the problem.

Please let me know if there is a more appropriate way to report this issue.

kito-cheng commented 3 years ago

Ooops, I can reproduce that, the info is enough to debug, thanks for your report!