bytecodealliance / bytecodealliance/wasmtime

Cranelift: `bus error` with unaligned atomics on RISC-V backend

Open
#5,882 0 comments 0 reactions 0 assignees View on GitHub
bug cranelift cranelift:area:riscv64
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

👋 Hey,

### `.clif` Test Case

```
test interpret
test run
target riscv64gc

function %a() -> i32 system_v {
ss0 = explicit_slot 7

block0:
v10 = iconst.i8 0
v11 = iconst.i16 0
v12 = iconst.i32 0
v13 = iconst.i64 0
v14 = uextend.i128 v13 ; v13 = 0
stack_store v12, ss0 ; v12 = 0
stack_store v11, ss0+4 ; v11 = 0
stack_store v10, ss0+6 ; v10 = 0

v22 = stack_addr.i64 ss0+3
v24 = atomic_rmw.i32 and v22, v12
return v24
}

; run: %a() == 0
```

### Steps to Reproduce

* `clif-util test ./the-above.clif`

### Expected Results

The test to pass

### Actual Results

```
afonso@DESKTOP-VSTS4BC:~/git/wasmtime/cranelift$ cargo run --target=riscv64gc-unknown-linux-gnu -- test ./lmao.clif
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
Running `/home/afonso/git/qemu/qemu-7.2.0/build/qemu-riscv64 -cpu any,zba=true,zbb=true,zbc=true,zbs=true,zbkb=true,zbkc=true,zbkx=true,zknd=true,zkne=true,zknh=true,zksed=true,zksh=true,zkr=true -L /usr/riscv64-linux-gnu -E LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib /home/afonso/git/wasmtime/target/riscv64gc-unknown-linux-gnu/debug/clif-util test ./lmao.clif`
Bus error
```

### Versions and Environment

Cranelift version or commit: main

Operating system: Linux

Architecture: RISC-V 64

### Extra Info

We've had a similar issue in the past with AArch64: #5483

We should restrict the current lowering to only if the memflags indicate it is aligned, or if the target implements the [`Zam` extension](https://five-embeddev.com/riscv-isa-manual/latest/zam.html). Although that is not ratified yet.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.