@@ -381,7 +381,7 @@ fn collect_items_rec<'tcx>(
381381 debug_assert ! ( should_codegen_locally( tcx, & instance) ) ;
382382
383383 let ty = instance. ty ( tcx, ty:: ParamEnv :: reveal_all ( ) ) ;
384- visit_drop_use ( tcx, ty, true , starting_item. span , & mut used_items) ;
384+ visit_drop_use ( tcx, ty, None , true , starting_item. span , & mut used_items) ;
385385
386386 recursion_depth_reset = None ;
387387
@@ -855,7 +855,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
855855 mir:: TerminatorKind :: Drop { ref place, .. } => {
856856 let ty = place. ty ( self . body , self . tcx ) . ty ;
857857 let ty = self . monomorphize ( ty) ;
858- visit_drop_use ( self . tcx , ty, true , source, self . output ) ;
858+ visit_drop_use ( self . tcx , ty, None , true , source, self . output ) ;
859859 }
860860 mir:: TerminatorKind :: InlineAsm { ref operands, .. } => {
861861 for op in operands {
@@ -917,11 +917,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
917917fn visit_drop_use < ' tcx > (
918918 tcx : TyCtxt < ' tcx > ,
919919 ty : Ty < ' tcx > ,
920+ invoke_trait : Option < ty:: PolyTraitRef < ' tcx > > ,
920921 is_direct_call : bool ,
921922 source : Span ,
922923 output : & mut MonoItems < ' tcx > ,
923924) {
924- let instance = Instance :: resolve_drop_in_place ( tcx, ty) ;
925+ let mut instance = Instance :: resolve_drop_in_place ( tcx, ty) ;
926+ if tcx. sess . cfi_shims ( ) && !is_direct_call {
927+ // The CFI shim may generate a direct call to the unshimmed drop
928+ visit_drop_use ( tcx, ty, None , true , source, output) ;
929+ instance = instance. cfi_shim ( tcx, invoke_trait) ;
930+ }
925931 visit_instance_use ( tcx, instance, is_direct_call, source, output) ;
926932}
927933
@@ -1188,8 +1194,10 @@ fn create_mono_items_for_vtable_methods<'tcx>(
11881194 assert ! ( !trait_ty. has_escaping_bound_vars( ) && !impl_ty. has_escaping_bound_vars( ) ) ;
11891195
11901196 if let ty:: Dynamic ( trait_ty, ..) = trait_ty. kind ( ) {
1191- if let Some ( principal) = trait_ty. principal ( ) {
1192- let poly_trait_ref = principal. with_self_ty ( tcx, impl_ty) ;
1197+ let invoke_trait =
1198+ trait_ty. principal ( ) . map ( |principal| principal. with_self_ty ( tcx, impl_ty) ) ;
1199+
1200+ if let Some ( poly_trait_ref) = invoke_trait {
11931201 assert ! ( !poly_trait_ref. has_escaping_bound_vars( ) ) ;
11941202
11951203 // Walk all methods of the trait, including those of its supertraits
@@ -1211,10 +1219,10 @@ fn create_mono_items_for_vtable_methods<'tcx>(
12111219 } )
12121220 . map ( |item| create_fn_mono_item ( tcx, item, source) ) ;
12131221 output. extend ( methods) ;
1214- }
1222+ } ;
12151223
12161224 // Also add the destructor.
1217- visit_drop_use ( tcx, impl_ty, false , source, output) ;
1225+ visit_drop_use ( tcx, impl_ty, invoke_trait , false , source, output) ;
12181226 }
12191227}
12201228
@@ -1239,7 +1247,7 @@ impl<'v> RootCollector<'_, 'v> {
12391247 debug ! ( "RootCollector: ADT drop-glue for `{id:?}`" , ) ;
12401248
12411249 let ty = self . tcx . type_of ( id. owner_id . to_def_id ( ) ) . no_bound_vars ( ) . unwrap ( ) ;
1242- visit_drop_use ( self . tcx , ty, true , DUMMY_SP , self . output ) ;
1250+ visit_drop_use ( self . tcx , ty, None , true , DUMMY_SP , self . output ) ;
12431251 }
12441252 }
12451253 DefKind :: GlobalAsm => {
0 commit comments