diff --git a/crates/debug/src/transform/expression.rs b/crates/debug/src/transform/expression.rs index e24fa7fb9f..2c3fb72392 100644 --- a/crates/debug/src/transform/expression.rs +++ b/crates/debug/src/transform/expression.rs @@ -119,16 +119,27 @@ fn map_reg(reg: RegUnit) -> Register { } fn translate_loc(loc: ValueLoc, frame_info: Option<&FunctionFrameInfo>) -> Option> { + use gimli::write::Writer; match loc { ValueLoc::Reg(reg) => { let machine_reg = map_reg(reg).0 as u8; - assert_lt!(machine_reg, 32); // FIXME - Some(vec![gimli::constants::DW_OP_reg0.0 + machine_reg]) + Some(if machine_reg < 32 { + vec![gimli::constants::DW_OP_reg0.0 + machine_reg] + } else { + let endian = gimli::RunTimeEndian::Little; + let mut writer = write::EndianVec::new(endian); + writer + .write_u8(gimli::constants::DW_OP_regx.0 as u8) + .expect("regx"); + writer + .write_uleb128(machine_reg.into()) + .expect("machine_reg"); + writer.into_vec() + }) } ValueLoc::Stack(ss) => { if let Some(frame_info) = frame_info { if let Some(ss_offset) = frame_info.stack_slots[ss].offset { - use gimli::write::Writer; let endian = gimli::RunTimeEndian::Little; let mut writer = write::EndianVec::new(endian); writer diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index 5b1b79ed5a..5fceb66b13 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -27,6 +27,16 @@ pub fn instantiate(wasm: &[u8], strategy: Strategy) { config .strategy(strategy) .expect("failed to enable lightbeam"); + instantiate_with_config(wasm, config); +} + +/// Instantiate the Wasm buffer, and implicitly fail if we have an unexpected +/// panic or segfault or anything else that can be detected "passively". +/// +/// The engine will be configured using provided config. +/// +/// See also `instantiate` functions. +pub fn instantiate_with_config(wasm: &[u8], config: Config) { let engine = Engine::new(&config); let store = Store::new(&engine); diff --git a/crates/fuzzing/tests/regressions.rs b/crates/fuzzing/tests/regressions.rs index 5ad96e689d..de29c718a0 100644 --- a/crates/fuzzing/tests/regressions.rs +++ b/crates/fuzzing/tests/regressions.rs @@ -5,7 +5,7 @@ //! use the Wasm binary by including it via //! `include_bytes!("./regressions/some-descriptive-name.wasm")`. -use wasmtime::Strategy; +use wasmtime::{Config, Strategy}; use wasmtime_fuzzing::oracles; #[test] @@ -19,3 +19,11 @@ fn instantiate_empty_module_with_memory() { let data = wat::parse_str(include_str!("./regressions/empty_with_memory.wat")).unwrap(); oracles::instantiate(&data, Strategy::Auto); } + +#[test] +fn instantiate_module_that_compiled_to_x64_has_register_32() { + let mut config = Config::new(); + config.debug_info(true); + let data = wat::parse_str(include_str!("./regressions/issue694.wat")).unwrap(); + oracles::instantiate_with_config(&data, config); +} diff --git a/crates/fuzzing/tests/regressions/issue694.wat b/crates/fuzzing/tests/regressions/issue694.wat new file mode 100644 index 0000000000..7e92aad07f --- /dev/null +++ b/crates/fuzzing/tests/regressions/issue694.wat @@ -0,0 +1,49 @@ +(module + (type (;0;) (func)) + (type (;1;) (func (param i64))) + (func (;0;) (type 0)) + (func (;1;) (type 0)) + (func (;2;) (type 0)) + (func (;3;) (type 0)) + (func (;4;) (type 1) (param i64) + (local f32 f32 f32) + loop (result i64) ;; label = @1 + global.get 0 + if ;; label = @2 + local.get 1 + return + end + block (result i64) ;; label = @2 + loop ;; label = @3 + block ;; label = @4 + global.get 0 + if ;; label = @5 + i32.const 5 + if (result f32) ;; label = @6 + block (result f32) ;; label = @7 + call 0 + i32.const 7 + if (result f32) ;; label = @8 + local.get 2 + else + f32.const 0x1p+0 (;=1;) + end + end + else + f32.const 0x1p+0 (;=1;) + end + local.tee 1 + local.set 3 + end + end + end + i32.const 8 + br_if 1 (;@1;) + i64.const 4 + end + end + return) + (memory (;0;) 1) + (global (;0;) i32 (i32.const 0)) +) +