@@ -16,7 +16,7 @@ use rustc_middle::middle::codegen_fn_attrs::{
1616use rustc_middle:: mir:: mono:: Linkage ;
1717use rustc_middle:: query:: Providers ;
1818use rustc_middle:: span_bug;
19- use rustc_middle:: ty:: { self as ty, TyCtxt } ;
19+ use rustc_middle:: ty:: { self as ty, InstanceKind , TyCtxt } ;
2020use rustc_session:: lint;
2121use rustc_session:: parse:: feature_err;
2222use rustc_span:: { Ident , Span , sym} ;
@@ -54,6 +54,12 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
5454}
5555
5656fn codegen_fn_attrs ( tcx : TyCtxt < ' _ > , did : LocalDefId ) -> CodegenFnAttrs {
57+ codegen_instance_attrs ( tcx, InstanceKind :: Item ( did. to_def_id ( ) ) )
58+ }
59+
60+ fn codegen_instance_attrs ( tcx : TyCtxt < ' _ > , instance_kind : InstanceKind < ' _ > ) -> CodegenFnAttrs {
61+ let did = instance_kind. def_id ( ) . expect_local ( ) ;
62+
5763 if cfg ! ( debug_assertions) {
5864 let def_kind = tcx. def_kind ( did) ;
5965 assert ! (
@@ -121,7 +127,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
121127 AttributeKind :: ExportName { name, .. } => {
122128 codegen_fn_attrs. export_name = Some ( * name) ;
123129 }
124- AttributeKind :: Naked ( _) => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED ,
130+ AttributeKind :: Naked ( _) => {
131+ // Drop the `#[naked]` attribute on other `InstanceKind`s, like the shims that
132+ // are generated for indirect function calls.
133+ if let InstanceKind :: Item ( _) = instance_kind {
134+ codegen_fn_attrs. flags |= CodegenFnAttrFlags :: NAKED
135+ }
136+ }
137+
125138 AttributeKind :: Align { align, .. } => codegen_fn_attrs. alignment = Some ( * align) ,
126139 AttributeKind :: LinkName { name, .. } => codegen_fn_attrs. link_name = Some ( * name) ,
127140 AttributeKind :: LinkSection { name, .. } => {
@@ -739,6 +752,11 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
739752}
740753
741754pub ( crate ) fn provide ( providers : & mut Providers ) {
742- * providers =
743- Providers { codegen_fn_attrs, should_inherit_track_caller, inherited_align, ..* providers } ;
755+ * providers = Providers {
756+ codegen_fn_attrs,
757+ codegen_instance_attrs,
758+ should_inherit_track_caller,
759+ inherited_align,
760+ ..* providers
761+ } ;
744762}
0 commit comments