@@ -384,7 +384,7 @@ fn collect_items_rec<'tcx>(
384384 // Nested statics have no type.
385385 if !nested {
386386 let ty = instance. ty ( tcx, ty:: ParamEnv :: reveal_all ( ) ) ;
387- visit_drop_use ( tcx, ty, true , starting_item. span , & mut used_items) ;
387+ visit_drop_use ( tcx, ty, None , true , starting_item. span , & mut used_items) ;
388388 }
389389
390390 recursion_depth_reset = None ;
@@ -863,7 +863,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
863863 mir:: TerminatorKind :: Drop { ref place, .. } => {
864864 let ty = place. ty ( self . body , self . tcx ) . ty ;
865865 let ty = self . monomorphize ( ty) ;
866- visit_drop_use ( self . tcx , ty, true , source, self . output ) ;
866+ visit_drop_use ( self . tcx , ty, None , true , source, self . output ) ;
867867 }
868868 mir:: TerminatorKind :: InlineAsm { ref operands, .. } => {
869869 for op in operands {
@@ -925,11 +925,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
925925fn visit_drop_use < ' tcx > (
926926 tcx : TyCtxt < ' tcx > ,
927927 ty : Ty < ' tcx > ,
928+ invoke_trait : Option < ty:: PolyTraitRef < ' tcx > > ,
928929 is_direct_call : bool ,
929930 source : Span ,
930931 output : & mut MonoItems < ' tcx > ,
931932) {
932- let instance = Instance :: resolve_drop_in_place ( tcx, ty) ;
933+ let mut instance = Instance :: resolve_drop_in_place ( tcx, ty) ;
934+ if tcx. sess . cfi_shims ( ) && !is_direct_call {
935+ // The CFI shim may generate a direct call to the unshimmed drop
936+ visit_drop_use ( tcx, ty, None , true , source, output) ;
937+ instance = instance. cfi_shim ( tcx, invoke_trait) ;
938+ }
933939 visit_instance_use ( tcx, instance, is_direct_call, source, output) ;
934940}
935941
@@ -1201,8 +1207,10 @@ fn create_mono_items_for_vtable_methods<'tcx>(
12011207 assert ! ( !trait_ty. has_escaping_bound_vars( ) && !impl_ty. has_escaping_bound_vars( ) ) ;
12021208
12031209 if let ty:: Dynamic ( trait_ty, ..) = trait_ty. kind ( ) {
1204- if let Some ( principal) = trait_ty. principal ( ) {
1205- let poly_trait_ref = principal. with_self_ty ( tcx, impl_ty) ;
1210+ let invoke_trait =
1211+ trait_ty. principal ( ) . map ( |principal| principal. with_self_ty ( tcx, impl_ty) ) ;
1212+
1213+ if let Some ( poly_trait_ref) = invoke_trait {
12061214 assert ! ( !poly_trait_ref. has_escaping_bound_vars( ) ) ;
12071215
12081216 // Walk all methods of the trait, including those of its supertraits
@@ -1224,10 +1232,10 @@ fn create_mono_items_for_vtable_methods<'tcx>(
12241232 } )
12251233 . map ( |item| create_fn_mono_item ( tcx, item, source) ) ;
12261234 output. extend ( methods) ;
1227- }
1235+ } ;
12281236
12291237 // Also add the destructor.
1230- visit_drop_use ( tcx, impl_ty, false , source, output) ;
1238+ visit_drop_use ( tcx, impl_ty, invoke_trait , false , source, output) ;
12311239 }
12321240}
12331241
@@ -1252,7 +1260,7 @@ impl<'v> RootCollector<'_, 'v> {
12521260 debug ! ( "RootCollector: ADT drop-glue for `{id:?}`" , ) ;
12531261
12541262 let ty = self . tcx . type_of ( id. owner_id . to_def_id ( ) ) . no_bound_vars ( ) . unwrap ( ) ;
1255- visit_drop_use ( self . tcx , ty, true , DUMMY_SP , self . output ) ;
1263+ visit_drop_use ( self . tcx , ty, None , true , DUMMY_SP , self . output ) ;
12561264 }
12571265 }
12581266 DefKind :: GlobalAsm => {
0 commit comments