Skip to content

Commit 285e880

Browse files
Codegen const panic messages as function calls
This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting binary.
1 parent fe6ce8a commit 285e880

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/shims/panic.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
256256
}
257257

258258
_ => {
259-
// Forward everything else to `panic` lang item.
260-
this.start_panic(msg.description(), unwind)?;
259+
// Call the lang item associated with this message.
260+
let fn_item = this.tcx.require_lang_item(msg.panic_function(), None);
261+
let instance = ty::Instance::mono(this.tcx.tcx, fn_item);
262+
this.call_function(
263+
instance,
264+
Abi::Rust,
265+
&[],
266+
None,
267+
StackPopCleanup::Goto { ret: None, unwind },
268+
)?;
261269
}
262270
}
263271
Ok(())

0 commit comments

Comments
 (0)