bytecodealliance / bytecodealliance/wasmtime

Cranelift: Crash when compiling pinned reg on `x86_64`

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

Description

👋 Hey,

When implementing #4375 I found some crashes when compiling some examples that use the pinned reg on `x86_64`.

### `.clif` Test Case

```
test run
set enable_pinned_reg
target x86_64

function %read_write_iadd(i64) -> i64 {
block0(v0: i64):
set_pinned_reg v0
v1 = get_pinned_reg.i64
v2 = iadd_imm.i64 v1, 1
return v2
}
; run: %read_write_iadd(0) == 1
; run: %read_write_iadd(-1) == 0
; run: %read_write_iadd(0xDEADBEEF_C0FFEEEE) == 0xDEADBEEF_C0FFEEEF
```

### Steps to Reproduce

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

### Expected Results

The tests to pass

### Actual Results

`clif-util` crashes seemingly with a regalloc issue.

```
Running `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\lmao.clif`
thread 'worker #0' panicked at 'assertion failed: `(left == right)`
left: `p15i`,
right: `p0i`', cranelift\codegen\src\machinst\reg.rs:469:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
FAIL .\lmao.clif: panicked in worker #0: assertion failed: `(left == right)`
left: `p15i`,
right: `p0i`
1 tests
Error: 1 failure
error: process didn't exit successfully: `C:\Users\Afonso\CLionProjects\wasmtime\target\debug\clif-util.exe test .\lmao.clif` (exit code: 1)

```

### Versions and Environment

Cranelift version or commit: `a2197ebbeb207f72b0a26b0fedcc81b43486cd99` (main as of writing)
Operating system: Windows
Architecture: x86_64

### Extra Info

In my machine the above fails, but the simplified test commited in #4375 works.
```
function %read_write(i64) -> i64 {
block0(v0: i64):
set_pinned_reg v0
v1 = get_pinned_reg.i64
return v1
}
```

But it looks like in CI it [failed](https://github.com/bytecodealliance/wasmtime/runs/7184639820?check_suite_focus=true#step:12:680) with:
```
running 1 test
error: test failed, to rerun pass '-p cranelift-tools --test filetests'
Caused by:
process didn't exit successfully: `/home/runner/work/wasmtime/wasmtime/target/debug/deps/filetests-28b9c918e0c0996e` (signal: 11, SIGSEGV: invalid memory reference)
```

cc @cfallin since this looks like a regalloc issue

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.