Cranelift: Exception::payload() zeroes all values after the first
Describe the bug
With the Cranelift backend, when an exception with a multi-value payload is thrown by the module and escapes to the host, RuntimeError::to_exception() returns the exception but Exception::payload(&mut store) returns the first payload value correctly and 0 for every later value, whatever their types (f64, f32, i64 all affected). A single-value payload reads correctly. The LLVM backend returns the full payload.
$ wasmer -vV; rustc -vV
wasmer 7.4.2
binary: wasmer-cli
commit-hash: ca719eb81fa450a06bcd6f0dd46e0b7cca15d7a9
commit-date: 2026-09-25
host: x86_64-unknown-linux-gnu
CPU flags: sse2 sse3 ssse3 sse4.1 sse4.2 popcnt avx bmi bmi2 avx2 lzcnt fma
runtimes: Singlepass, Cranelift, LLVM
features: wasix
rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8Reproduced with the wasmer crate 7.4.2 from crates.io and with main at ca719eb (2026-09-24), Cranelift backend, Linux x86_64.
Steps to reproduce
- Create a crate with the
Cargo.tomlandsrc/main.rsbelow (the program is self-contained: the module is inline WAT, the only dependency iswasmerwith default features, i.e. thesysbackend with Cranelift). cargo run --release- See the output; the program prints what it got against what it expected and exits 1 when the bug is present.
- Optional, for comparison with the LLVM backend:
cargo run --release --features llvmwithWASMER_BACKEND=llvmin the environment (needs LLVM 22 andllvm-sys). The LLVM backend gives the expected results.
[package]
name = "wasmer-repro"
version = "0.1.0"
edition = "2021"
[dependencies]
wasmer = "7.4.2"
[features]
llvm = ["wasmer/llvm"] # optional: WASMER_BACKEND=llvm for comparison//! An exception with an (f32 f64) payload thrown by the module and escaping
//! to the host: `RuntimeError::to_exception()` gives the exception, but
//! `Exception::payload()` returns the f64 as 0.0 with the Cranelift backend
//! (the f32 is right). Expected: [F32(-1.5), F64(121894.0)], which the
//! LLVM backend and other engines give.
use wasmer::sys::{Cranelift, EngineBuilder, Features};
use wasmer::*;
const WAT: &str = r#"
(module
(tag $a (param f32 f64))
(tag $b (param f64))
(tag $c (param f64 f32))
(tag $d (param i32 f64))
(tag $e (param i64 i64))
(tag $f (param f32 f32))
(func (export "f32_f64") (throw $a (f32.const -1.5) (f64.const 121894.0)))
(func (export "f64") (throw $b (f64.const 121894.0)))
(func (export "f64_f32") (throw $c (f64.const 121894.0) (f32.const -1.5)))
(func (export "i32_f64") (throw $d (i32.const 7) (f64.const 121894.0)))
(func (export "i64_i64") (throw $e (i64.const 5) (i64.const 6)))
(func (export "f32_f32") (throw $f (f32.const -1.5) (f32.const 2.5))))
"#;
fn engine() -> Engine {
let mut features = Features::default();
features.exceptions(true);
let backend = std::env::var("WASMER_BACKEND").unwrap_or_else(|_| "cranelift".to_string());
println!("backend: {}", backend);
match backend.as_str() {
"cranelift" => EngineBuilder::new(Cranelift::default()).set_features(Some(features)).engine().into(),
#[cfg(feature = "llvm")]
"llvm" => EngineBuilder::new(wasmer::sys::LLVM::default()).set_features(Some(features)).engine().into(),
other => panic!("backend {} not available (build with --features llvm for llvm)", other),
}
}
fn main() {
let mut store = Store::new(engine());
let module = Module::new(&store, WAT).expect("module");
let instance = Instance::new(&mut store, &module, &Imports::new()).expect("instantiate");
let cases: [(&str, Vec<Value>); 6] = [
("f32_f64", vec![Value::F32(-1.5), Value::F64(121894.0)]),
("f64", vec![Value::F64(121894.0)]),
("f64_f32", vec![Value::F64(121894.0), Value::F32(-1.5)]),
("i32_f64", vec![Value::I32(7), Value::F64(121894.0)]),
("i64_i64", vec![Value::I64(5), Value::I64(6)]),
("f32_f32", vec![Value::F32(-1.5), Value::F32(2.5)]),
];
let mut ok = true;
for (name, expected) in cases {
let f = instance.exports.get_function(name).unwrap();
let err = f.call(&mut store, &[]).expect_err("the call must throw");
let exn = err.to_exception().expect("the error must be the exception");
let payload = exn.payload(&mut store);
let same = format!("{:?}", payload) == format!("{:?}", expected);
println!("{:8} payload {:?} expected {:?} {}", name, payload, expected, if same { "OK" } else { "WRONG" });
ok &= same;
}
std::process::exit(if ok { 0 } else { 1 });
}Expected behavior
Every payload reads back as thrown:
backend: llvm
f32_f64 payload [F32(-1.5), F64(121894.0)] expected [F32(-1.5), F64(121894.0)] OK
f64 payload [F64(121894.0)] expected [F64(121894.0)] OK
f64_f32 payload [F64(121894.0), F32(-1.5)] expected [F64(121894.0), F32(-1.5)] OK
i32_f64 payload [I32(7), F64(121894.0)] expected [I32(7), F64(121894.0)] OK
i64_i64 payload [I64(5), I64(6)] expected [I64(5), I64(6)] OK
f32_f32 payload [F32(-1.5), F32(2.5)] expected [F32(-1.5), F32(2.5)] OKThis is what the LLVM backend prints (WASMER_BACKEND=llvm); wasmtime's ExnRef::field and the JavaScript WebAssembly.Exception.getArg return the same values for the same module.
Actual behavior
backend: cranelift
f32_f64 payload [F32(-1.5), F64(0.0)] expected [F32(-1.5), F64(121894.0)] WRONG
f64 payload [F64(121894.0)] expected [F64(121894.0)] OK
f64_f32 payload [F64(121894.0), F32(0.0)] expected [F64(121894.0), F32(-1.5)] WRONG
i32_f64 payload [I32(7), F64(0.0)] expected [I32(7), F64(121894.0)] WRONG
i64_i64 payload [I64(5), I64(0)] expected [I64(5), I64(6)] WRONG
f32_f32 payload [F32(-1.5), F32(0.0)] expected [F32(-1.5), F32(2.5)] WRONGSame output with wasmer 7.4.2 from crates.io and with main at ca719eb.
Additional context
- The module is six tags with the parameter lists in the table and one exported function per tag that throws constants; each function is called, the
RuntimeErroris turned into anExceptionwithto_exception(), andpayload(&mut store)is compared with the thrown values. - Payloads caught inside the module (by
try_tablein Wasm code) read correctly with Cranelift in our differential runs, so the problem looks confined to the host-side read of the exception object, or to the layout Cranelift produces for it when the exception reaches the host. - The engine is built with
EngineBuilder::new(Cranelift::default()).set_features(Some(features))withfeatures.exceptions(true).
Source: wasmerio/wasmer