@@ -6,6 +6,7 @@ use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable};
66use rustc_ast as ast;
77use rustc_attr as attr;
88use rustc_hir as hir;
9+ use rustc_hir:: def_id:: DefId ;
910use rustc_hir:: lang_items:: LangItem ;
1011use rustc_index:: bit_set:: BitSet ;
1112use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -2762,14 +2763,22 @@ impl<'tcx> ty::Instance<'tcx> {
27622763/// with `-Cpanic=abort` will look like they can't unwind when in fact they
27632764/// might (from a foreign exception or similar).
27642765#[ inline]
2765- pub fn fn_can_unwind < ' tcx > (
2766- tcx : TyCtxt < ' tcx > ,
2767- codegen_fn_attr_flags : CodegenFnAttrFlags ,
2768- abi : SpecAbi ,
2769- ) -> bool {
2770- // Special attribute for functions which can't unwind.
2771- if codegen_fn_attr_flags. contains ( CodegenFnAttrFlags :: NEVER_UNWIND ) {
2772- return false ;
2766+ pub fn fn_can_unwind < ' tcx > ( tcx : TyCtxt < ' tcx > , fn_def_id : Option < DefId > , abi : SpecAbi ) -> bool {
2767+ if let Some ( did) = fn_def_id {
2768+ // Special attribute for functions which can't unwind.
2769+ if tcx. codegen_fn_attrs ( did) . flags . contains ( CodegenFnAttrFlags :: NEVER_UNWIND ) {
2770+ return false ;
2771+ }
2772+
2773+ // With -Z panic-in-drop=abort, drop_in_place never unwinds.
2774+ //
2775+ // This is not part of `codegen_fn_attrs` as it can differ between crates
2776+ // and therefore cannot be computed in core.
2777+ if tcx. sess . opts . debugging_opts . panic_in_drop == PanicStrategy :: Abort {
2778+ if Some ( did) == tcx. lang_items ( ) . drop_in_place_fn ( ) {
2779+ return false ;
2780+ }
2781+ }
27732782 }
27742783
27752784 // Otherwise if this isn't special then unwinding is generally determined by
@@ -2991,13 +3000,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
29913000) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , FnAbiError < ' tcx > > {
29923001 let ( param_env, ( sig, extra_args) ) = query. into_parts ( ) ;
29933002
2994- LayoutCx { tcx, param_env } . fn_abi_new_uncached (
2995- sig,
2996- extra_args,
2997- None ,
2998- CodegenFnAttrFlags :: empty ( ) ,
2999- false ,
3000- )
3003+ LayoutCx { tcx, param_env } . fn_abi_new_uncached ( sig, extra_args, None , None , false )
30013004}
30023005
30033006fn fn_abi_of_instance < ' tcx > (
@@ -3014,13 +3017,11 @@ fn fn_abi_of_instance<'tcx>(
30143017 None
30153018 } ;
30163019
3017- let attrs = tcx. codegen_fn_attrs ( instance. def_id ( ) ) . flags ;
3018-
30193020 LayoutCx { tcx, param_env } . fn_abi_new_uncached (
30203021 sig,
30213022 extra_args,
30223023 caller_location,
3023- attrs ,
3024+ Some ( instance . def_id ( ) ) ,
30243025 matches ! ( instance. def, ty:: InstanceDef :: Virtual ( ..) ) ,
30253026 )
30263027}
@@ -3033,7 +3034,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
30333034 sig : ty:: PolyFnSig < ' tcx > ,
30343035 extra_args : & [ Ty < ' tcx > ] ,
30353036 caller_location : Option < Ty < ' tcx > > ,
3036- codegen_fn_attr_flags : CodegenFnAttrFlags ,
3037+ fn_def_id : Option < DefId > ,
30373038 // FIXME(eddyb) replace this with something typed, like an `enum`.
30383039 force_thin_self_ptr : bool ,
30393040 ) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , FnAbiError < ' tcx > > {
@@ -3205,7 +3206,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
32053206 c_variadic : sig. c_variadic ,
32063207 fixed_count : inputs. len ( ) ,
32073208 conv,
3208- can_unwind : fn_can_unwind ( self . tcx ( ) , codegen_fn_attr_flags , sig. abi ) ,
3209+ can_unwind : fn_can_unwind ( self . tcx ( ) , fn_def_id , sig. abi ) ,
32093210 } ;
32103211 self . fn_abi_adjust_for_abi ( & mut fn_abi, sig. abi ) ?;
32113212 debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
0 commit comments