Skip to content

Commit b740cdc

Browse files
committed
Mark naked functions as never inline in codegen_fn_attrs
Use code generation attributes to ensure that naked functions are never inline, replacing separate checks in MIR inliner and LLVM code generation.
1 parent c955add commit b740cdc

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ pub fn from_fn_attrs<'ll, 'tcx>(
258258
OptimizeAttr::Speed => {}
259259
}
260260

261-
let inline = if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
262-
InlineAttr::Never
263-
} else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
264-
InlineAttr::Hint
265-
} else {
266-
codegen_fn_attrs.inline
267-
};
261+
let inline =
262+
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
263+
InlineAttr::Hint
264+
} else {
265+
codegen_fn_attrs.inline
266+
};
268267
to_add.extend(inline_attr(cx, inline));
269268

270269
// The `uwtable` attribute according to LLVM is:

compiler/rustc_hir_analysis/src/collect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
20752075

20762076
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
20772077
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
2078+
codegen_fn_attrs.inline = InlineAttr::Never;
20782079
}
20792080

20802081
// Weak lang items have the same semantics as "std internal" symbols in the

compiler/rustc_mir_transform/src/inline.rs

-4
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,6 @@ impl<'tcx> Inliner<'tcx> {
363363
return Err("C variadic");
364364
}
365365

366-
if callee_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
367-
return Err("naked");
368-
}
369-
370366
if callee_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
371367
return Err("cold");
372368
}

0 commit comments

Comments
 (0)