Skip to content

Commit

Permalink
Mark naked functions as never inline in codegen_fn_attrs
Browse files Browse the repository at this point in the history
Use code generation attributes to ensure that naked functions are never
inline, replacing separate checks in MIR inliner and LLVM code
generation.
  • Loading branch information
tmiasko committed Dec 3, 2022
1 parent c955add commit b740cdc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
13 changes: 6 additions & 7 deletions compiler/rustc_codegen_llvm/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,12 @@ pub fn from_fn_attrs<'ll, 'tcx>(
OptimizeAttr::Speed => {}
}

let inline = if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
InlineAttr::Never
} else if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
InlineAttr::Hint
} else {
codegen_fn_attrs.inline
};
let inline =
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
InlineAttr::Hint
} else {
codegen_fn_attrs.inline
};
to_add.extend(inline_attr(cx, inline));

// The `uwtable` attribute according to LLVM is:
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {

if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE;
codegen_fn_attrs.inline = InlineAttr::Never;
}

// Weak lang items have the same semantics as "std internal" symbols in the
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ impl<'tcx> Inliner<'tcx> {
return Err("C variadic");
}

if callee_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
return Err("naked");
}

if callee_attrs.flags.contains(CodegenFnAttrFlags::COLD) {
return Err("cold");
}
Expand Down

0 comments on commit b740cdc

Please sign in to comment.