---
# System prepended metadata

title: Untitled

---

Compiling a C program using Clang for the RISC-V architecture and simulating it using Spike causes a segmentation fault
I compiled a C program with auto-vectorization loop in llvm using Clang for the RISC-V architecture and simulated it using Spike. However, this resulted in a segmentation fault.

To be more specific, the segmentation fault occurs when the ```-mrvv-vector-bits=128``` option is added during compilation. 

Note : The -mrvv-vector-bits option was released just two weeks ago in this commit: https://github.com/llvm/llvm-project/commit/42e79d9771f96110c7f51ee5f39a76517ae44234.

The failing case (test.c):
```c
#include <stdio.h>
#include <time.h>
#include <riscv_vector.h>
#include <string.h>

int main(){
    float a __attribute__((__vector_size__(4)));
    float b __attribute__((__vector_size__(4)));
    float c __attribute__((__vector_size__(4)));

    _Pragma("clang loop vectorize(enable)")
    for(int i = 0; i < 4; i++){
        c[i] = a[i] * b[i]; 
    }
    
    for(int j = 0; j < 4; j++){
        printf("%f\n", c[j]);
    }
}
```
The compile command was : ```/mnt/c/llvm-project/install/bin/clang-17  --target=riscv64-unknown-elf --sysroot=/opt/riscv/riscv64-unknown-elf --gcc-toolchain=/opt/riscv -march=rv64gcv1_zfh_zvfh0p1 -menable-experimental-extensions -mrvv-vector-bits=128 -O1 -v -g test.c -o test.elf```

Simulating using spike : ```/opt/riscv/bin/spike /opt/riscv/riscv64-unknown-elf/bin/pk test.elf```

The result of simulation : 
```
bbl loader
0.000000
0.000000
0.000000
0.000000
z  0000000000000000 ra 0000000000000000 sp 0000003ffffffb50 gp 000000000001f110
tp 0000000000000000 t0 00000000000102dc t1 0000000000000000 t2 0000000000000000
s0 0000000000000000 s1 0000000000000000 a0 0000000000000000 a1 000000000001f920
a2 0000000000000009 a3 0000000000000009 a4 0000000000000001 a5 0000000000000000
a6 0000000000000000 a7 0000000000000040 s2 0000000000000000 s3 0000000000000000
s4 0000000000000000 s5 0000000000000000 s6 0000000000000000 s7 0000000000000000
s8 0000000000000000 s9 0000000000000000 sA 0000000000000000 sB 0000000000000000
t3 ffffffffffffffff t4 0000003ffffff580 t5 000000000001d000 t6 0000000000000000
pc 0000000000000000 va/inst 0000000000000000 sr 8000000200006620
User fetch segfault @ 0x0000000000000000
make: *** [Makefile:32: run] Error 255
```