Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/cranelift/src/debug/transform/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,15 @@ pub fn generate_simulated_dwarf(
out_strings: &mut write::StringTable,
isa: &dyn TargetIsa,
) -> Result<(), Error> {
// A component without any core modules has no functions to describe, and
// the compilation unit below names itself after the first translation's
// wasm file. There is nothing to simulate, so leave the DWARF empty.
let Some((_, first_translation)) = compilation.translations.iter().next() else {
return Ok(());
};

let (wasm_file, path) = {
let di = &compilation.translations.iter().next().unwrap().1.debuginfo;
let di = &first_translation.debuginfo;
let path = di
.wasm_file
.path
Expand Down
18 changes: 18 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3716,3 +3716,21 @@ fn non_utf8_raises_error() -> Result<()> {
}
Ok(())
}

#[test]
fn compile_empty_component_with_debug_info() -> Result<()> {
// A component with no core modules reached simulated-DWARF generation with
// nothing to describe, which used to panic instead of compiling.
let td = TempDir::new()?;
let cwasm = td.path().join("empty-component.cwasm");
let stdout = run_wasmtime(&[
"compile",
"-D",
"debug-info=y",
"tests/all/cli_tests/empty_component.wat",
"-o",
cwasm.to_str().unwrap(),
])?;
assert_eq!(stdout, "");
Ok(())
}
1 change: 1 addition & 0 deletions tests/all/cli_tests/empty_component.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(component)
Loading