{"id":"6c2d3f4f9c946d6c","repo":"rust-lang/rust","slug":"epilogue-noreturn-for","errorCode":null,"errorMessage":"epilogue_noreturn for {:?}","messagePattern":"epilogue_noreturn for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_cranelift/src/inline_asm.rs","lineNumber":723,"sourceCode":"                generated_asm.push_str(\"    addi sp, sp, 16\\n\");\n                generated_asm.push_str(\"    ret\\n\");\n            }\n            _ => unimplemented!(\"epilogue for {:?}\", arch),\n        }\n    }\n\n    fn epilogue_noreturn(generated_asm: &mut String, arch: InlineAsmArch) {\n        match arch {\n            InlineAsmArch::X86_64 => {\n                generated_asm.push_str(\"    ud2\\n\");\n            }\n            InlineAsmArch::AArch64 => {\n                generated_asm.push_str(\"    brk     #0x1\\n\");\n            }\n            InlineAsmArch::RiscV64 => {\n                generated_asm.push_str(\"    ebreak\\n\");\n            }\n            _ => unimplemented!(\"epilogue_noreturn for {:?}\", arch),\n        }\n    }\n\n    fn save_register(\n        generated_asm: &mut String,\n        arch: InlineAsmArch,\n        reg: InlineAsmReg,\n        offset: Size,\n    ) {\n        match arch {\n            InlineAsmArch::X86_64 => {\n                match reg {\n                    InlineAsmReg::X86(reg)\n                        if matches!(\n                            reg.reg_class(),\n                            X86InlineAsmRegClass::xmm_reg\n                                | X86InlineAsmRegClass::ymm_reg\n                                | X86InlineAsmRegClass::zmm_reg","sourceCodeStart":705,"sourceCodeEnd":741,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_cranelift/src/inline_asm.rs#L705-L741","documentation":"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)`.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nunsafe fn abort() -> ! { asm!(\"ud2\", options(noreturn)); }\n\n// after - portable across arches, no inline asm needed\nunsafe fn abort() -> ! { core::intrinsics::abort(); }","handlingStrategy":"validation","validationCode":"// Flag `asm!(..., options(noreturn))` — the noreturn epilogue path is\n// explicitly unimplemented in cg_clif.\nlet src = std::fs::read_to_string(&path)?;\nif src.contains(\"asm!\") && src.contains(\"options(noreturn)\") {\n    return Err(\"noreturn inline asm not supported by cranelift backend\");\n}","typeGuard":null,"tryCatchPattern":"// Process-abort panic; cannot be caught in user code.\n// Mitigate by removing `options(noreturn)` from asm! or compiling with LLVM.","preventionTips":["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."],"tags":["rustc","cranelift","inline-asm","codegen","unimplemented","noreturn","target-arch"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}