bytecodealliance / bytecodealliance/wasmtime

Cranelift crash in riscv64 isle

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

Description

### Test Case

Reduce from libsodium `kx` using `wasm-tools shrink`

```
(module
(type (;0;) (func (param i32 i32)))
(type (;1;) (func (param i32 i32 i32)))
(memory (;0;) 2)
(func (;0;) (type 1) (param i32 i32 i32))
(func (;1;) (type 0) (param i32 i32)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
loop ;; label = @1
i32.const 0
local.get 1
i32.store8
local.get 3
br_if 0 (;@1;)
end
i32.const 1
local.get 0
i32.store8
local.get 0
local.get 0
i32.store8
loop ;; label = @1
local.get 0
local.get 0
i32.store8
local.get 1
local.get 4
i32.store8
i32.const 0
br_if 0 (;@1;)
end
loop ;; label = @1
i32.const 0
local.get 1
i32.store8
local.get 1
br_if 0 (;@1;)
end
i32.const 0
i32.const 1
i32.store8 offset=351
i32.const 1
i32.const 0
i32.const 40
memory.fill
local.get 6
i32.const 1
i32.store
local.get 6
local.get 6
local.get 6
memory.fill
local.get 6
i32.const 1
i32.store
local.get 6
i32.const 0
i32.const 0
memory.fill
loop ;; label = @1
local.get 1
local.get 1
local.get 1
call 8
local.get 5
local.get 5
local.get 5
call 7
local.get 6
i32.const 1
call 5
i32.const 0
br_if 0 (;@1;)
end
i32.const 1
local.get 6
i32.const 40
memory.copy
local.get 5
local.get 5
i32.const 1
memory.copy
local.get 5
local.get 5
i32.const 0
memory.copy
local.get 1
local.get 1
call 6
local.get 1
local.get 4
call 4
local.get 1
local.get 1
call 6
local.get 1
local.get 4
call 4
i32.const 0
i32.const 1
call 6
local.get 1
local.get 4
call 4
i32.const 1
i32.const 0
call 6
local.get 6
local.get 4
call 5
loop ;; label = @1
local.get 1
local.get 1
local.get 1
call 8
local.get 4
local.get 4
local.get 4
call 7
local.get 6
local.get 7
call 5
local.get 1
br_if 0 (;@1;)
end
nop
local.get 2
local.get 2
i32.store offset=292
i32.const 0
local.get 18
i32.store offset=288
local.get 2
local.get 2
i32.store offset=284
local.get 2
local.get 14
i32.store offset=280
i32.const 0
local.get 12
i32.store offset=276
i32.const 0
local.get 10
i32.store offset=272
local.get 8
i32.const 1
i32.store offset=268
i32.const 0
i32.const 1
i32.store offset=264
local.get 2
local.get 2
i32.store offset=260
local.get 1
local.get 1
i32.store offset=256
local.get 2
i32.const 1
i32.store offset=244
local.get 2
i32.const 0
i32.store offset=240
local.get 2
i32.const 0
i32.store offset=236
i32.const 0
i32.const 0
i32.store offset=232
local.get 2
local.get 12
i32.store offset=228
local.get 2
local.get 10
i32.store offset=224
local.get 2
local.get 8
i32.store offset=220
local.get 2
local.get 4
i32.store offset=216
i32.const 0
local.get 5
i32.store offset=212
local.get 1
local.get 1
i32.store offset=208
local.get 2
local.get 1
call 3
local.get 1
local.get 1
local.get 1
call 0
local.get 0
local.get 2
call 2
)
(func (;2;) (type 0) (param i32 i32))
(func (;3;) (type 0) (param i32 i32))
(func (;4;) (type 0) (param i32 i32))
(func (;5;) (type 0) (param i32 i32))
(func (;6;) (type 0) (param i32 i32))
(func (;7;) (type 1) (param i32 i32 i32))
(func (;8;) (type 1) (param i32 i32 i32))
)
```

### Steps to Reproduce

* `wasmtime compile --target riscv64gc-unknown-linux-gnu kx.shrunken.wasm`

### Expected Results

It should compile like wasmtime 45

### Actual Results

```
thread '' (663301) panicked at /home/han/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cranelift-codegen-0.134.2/src/isa/riscv64/inst/args.rs:1271:18:
internal error: entered unreachable code
stack backtrace:
0: __rustc::rust_begin_unwind
1: core::panicking::panic_fmt
2: core::panicking::panic
3: cranelift_codegen::isa::riscv64::lower::isle::generated_code::constructor_gen_store::>
4: cranelift_codegen::isa::riscv64::lower::isle::generated_code::constructor_lower::>
5: ::lower
6: cranelift_codegen::machinst::compile::compile::
7: ::compile_function
8: ::compile_stencil
9: ::compile
10: ::finish_with_info
11: ::finish_compiling
12: <&::run_maybe_parallel core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>, wasmtime::compile::CompileOutput, wasmtime_internal_core::error::error::Error, ::compile::{closure#0}>::{closure#0} as core::ops::function::FnMut<(alloc::boxed::Box core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>,)>>::call_mut
13: > as rayon::iter::plumbing::Folder>>::consume_iter:: core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>>, &::run_maybe_parallel core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>, wasmtime::compile::CompileOutput, wasmtime_internal_core::error::error::Error, ::compile::{closure#0}>::{closure#0}>>
14: rayon::iter::plumbing::bridge_producer_consumer::helper:: core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>>, rayon::iter::map::MapConsumer>, ::run_maybe_parallel core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>, wasmtime::compile::CompileOutput, wasmtime_internal_core::error::error::Error, ::compile::{closure#0}>::{closure#0}>>
15: >, rayon::iter::plumbing::bridge_producer_consumer::helper core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>>, rayon::iter::map::MapConsumer>, ::run_maybe_parallel core::ops::function::FnOnce<(&'a dyn wasmtime_environ::compile::Compiler + 'a,), Output = core::result::Result> + core::marker::Send>, wasmtime::compile::CompileOutput, wasmtime_internal_core::error::error::Error, ::compile::{closure#0}>::{closure#0}>>::{closure#1}>::{closure#0}, rayon::iter::collect::consumer::CollectResult>> as rayon_core::job::Job>::execute
16: ::wait_until_cold
17: ::run
```

The type entering unreachable branch is `types::I8X16`.

### Versions and Environment

Wasmtime version or commit: `wasmtime 47.0.2` or `46.0.1`

Operating system: Gentoo Linux glibc-2.43-r2 linux 7.14

Architecture: host: amd64, target: riscv64gc

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with `wasmtime compile --target riscv64gc-unknown-linux-gnu kx.shrunken.wasm`, then inspect the RISC-V ISLE lowering path and `isa/riscv64/inst/args.rs` around line 1271, where `types::I8X16` enters unreachable code. Done means the supplied module compiles for the riscv64gc target without the panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.