Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ffdc292

Browse files
committed
Don't begin defining a function when codegening a naked function
While LLVM is rather permissive in this regards, some other codegen backends demand that once you declare a function for definition you actually define contents of the function, which doesn't happen for naked functions as we actually generate assembly for them.
1 parent 03f4e88 commit ffdc292

File tree

1 file changed

+7
-7
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+7
-7
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
170170
) {
171171
assert!(!instance.args.has_infer());
172172

173+
let mut mir = cx.tcx().instance_mir(instance.def);
174+
175+
if cx.tcx().codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
176+
crate::mir::naked_asm::codegen_naked_asm::<Bx>(cx, &mir, instance);
177+
return;
178+
}
179+
173180
let tcx = cx.tcx();
174181
let llfn = cx.get_fn(instance);
175182

176-
let mut mir = tcx.instance_mir(instance.def);
177-
178183
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
179184
debug!("fn_abi: {:?}", fn_abi);
180185

181-
if tcx.codegen_fn_attrs(instance.def_id()).flags.contains(CodegenFnAttrFlags::NAKED) {
182-
crate::mir::naked_asm::codegen_naked_asm::<Bx>(cx, &mir, instance);
183-
return;
184-
}
185-
186186
if tcx.features().ergonomic_clones() {
187187
let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions(
188188
tcx,

0 commit comments

Comments
 (0)