mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Treat drop_in_place as nounwind with -Z panic-in-drop=abort
The AbortUnwindCalls MIR pass will eliminate any unnecessary cleanups and will prevent any unwinds from leaking out by forcing an abort.
This commit is contained in:
parent
c1bcf5c548
commit
8c7a05a23f
@ -5,6 +5,7 @@ use rustc_middle::mir::*;
|
|||||||
use rustc_middle::ty::layout;
|
use rustc_middle::ty::layout;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
use rustc_target::spec::PanicStrategy;
|
||||||
|
|
||||||
/// A pass that runs which is targeted at ensuring that codegen guarantees about
|
/// A pass that runs which is targeted at ensuring that codegen guarantees about
|
||||||
/// unwinding are upheld for compilations of panic=abort programs.
|
/// unwinding are upheld for compilations of panic=abort programs.
|
||||||
@ -82,10 +83,11 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
|
|||||||
};
|
};
|
||||||
layout::fn_can_unwind(tcx, flags, sig.abi())
|
layout::fn_can_unwind(tcx, flags, sig.abi())
|
||||||
}
|
}
|
||||||
TerminatorKind::Drop { .. }
|
TerminatorKind::Drop { .. } | TerminatorKind::DropAndReplace { .. } => {
|
||||||
| TerminatorKind::DropAndReplace { .. }
|
tcx.sess.opts.debugging_opts.panic_in_drop == PanicStrategy::Unwind
|
||||||
| TerminatorKind::Assert { .. }
|
&& layout::fn_can_unwind(tcx, CodegenFnAttrFlags::empty(), Abi::Rust)
|
||||||
| TerminatorKind::FalseUnwind { .. } => {
|
}
|
||||||
|
TerminatorKind::Assert { .. } | TerminatorKind::FalseUnwind { .. } => {
|
||||||
layout::fn_can_unwind(tcx, CodegenFnAttrFlags::empty(), Abi::Rust)
|
layout::fn_can_unwind(tcx, CodegenFnAttrFlags::empty(), Abi::Rust)
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
|
@ -46,7 +46,7 @@ use rustc_session::lint;
|
|||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::spec::{abi, SanitizerSet};
|
use rustc_target::spec::{abi, PanicStrategy, SanitizerSet};
|
||||||
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
|
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
@ -2683,6 +2683,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
|
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// With -Z panic-in-drop=abort, drop_in_place never unwinds.
|
||||||
|
if tcx.sess.opts.debugging_opts.panic_in_drop == PanicStrategy::Abort {
|
||||||
|
if Some(id) == tcx.lang_items().drop_in_place_fn() {
|
||||||
|
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
|
let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
|
||||||
|
|
||||||
let mut inline_span = None;
|
let mut inline_span = None;
|
||||||
|
Loading…
Reference in New Issue
Block a user