rust-lang/rust · error
epilogue_noreturn for {:?}
Error message
epilogue_noreturn for {:?} What it means
Thrown by rustc_codegen_cranelift for the noreturn variant of the inline-asm epilogue. For non-returning asm! blocks (e.g. options(noreturn) or asm that ends in an unconditional trap/unreachable), the backend emits an architecture-specific trap instruction (ud2 on x86_64, brk on aarch64, ebreak on riscv64). Any other InlineAsmArch panics via `_ => unimplemented!("epilogue_noreturn for {:?}", arch)`.
Source
Thrown at compiler/rustc_codegen_cranelift/src/inline_asm.rs:723
generated_asm.push_str(" addi sp, sp, 16\n");
generated_asm.push_str(" ret\n");
}
_ => unimplemented!("epilogue for {:?}", arch),
}
}
fn epilogue_noreturn(generated_asm: &mut String, arch: InlineAsmArch) {
match arch {
InlineAsmArch::X86_64 => {
generated_asm.push_str(" ud2\n");
}
InlineAsmArch::AArch64 => {
generated_asm.push_str(" brk #0x1\n");
}
InlineAsmArch::RiscV64 => {
generated_asm.push_str(" ebreak\n");
}
_ => unimplemented!("epilogue_noreturn for {:?}", arch),
}
}
fn save_register(
generated_asm: &mut String,
arch: InlineAsmArch,
reg: InlineAsmReg,
offset: Size,
) {
match arch {
InlineAsmArch::X86_64 => {
match reg {
InlineAsmReg::X86(reg)
if matches!(
reg.reg_class(),
X86InlineAsmRegClass::xmm_reg
| X86InlineAsmRegClass::ymm_reg
| X86InlineAsmRegClass::zmm_regView on GitHub (pinned to 22057b88b0)
Solutions
- Use the LLVM backend for the unsupported target.
- Restrict the noreturn asm! to x86_64/aarch64/riscv64 via cfg, providing a portable Rust-level trap (core::intrinsics::abort() / core::hint::unreachable_unchecked()) on other arches.
- Add the missing trap instruction for the arch in epilogue_noreturn() upstream.
Example fix
// before
unsafe fn abort() -> ! { asm!("ud2", options(noreturn)); }
// after - portable across arches, no inline asm needed
unsafe fn abort() -> ! { core::intrinsics::abort(); } Defensive patterns
Strategy: validation
Validate before calling
// Flag `asm!(..., options(noreturn))` — the noreturn epilogue path is
// explicitly unimplemented in cg_clif.
let src = std::fs::read_to_string(&path)?;
if src.contains("asm!") && src.contains("options(noreturn)") {
return Err("noreturn inline asm not supported by cranelift backend");
} Try / catch
// Process-abort panic; cannot be caught in user code. // Mitigate by removing `options(noreturn)` from asm! or compiling with LLVM.
Prevention
- Do not combine `asm!` with `options(noreturn)` when targeting cg_clif.
- Replace noreturn asm with a normal function that calls `std::process::abort()` or `unreachable!()`.
- Document any `noreturn` asm in the crate so downstream cg_clif users are warned.
When it happens
Trigger: Compiling an asm! block marked options(noreturn) (or otherwise not returning) on a target whose InlineAsmArch is not X86_64/AArch64/RiscV64 with the Cranelift backend. Common in panic handlers, abort paths, or low-level boot code that uses asm to halt/trap.
Common situations: A #![no_std] binary or kernel using cg_clif that issues a noreturn asm trap (asm!("ud2", options(noreturn))) on an unsupported arch; cross-compiling panic handlers to LoongArch/PowerPC/S390x with the cranelift backend selected.
Related errors
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/6c2d3f4f9c946d6c.json.
Report an issue: GitHub.