Skip to content

Commit 558b7e5

Browse files
committed
add config and debugflag a la check-overflow but for drop flag sanity-check.
1 parent 1ae2efb commit 558b7e5

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
605605
"Print the size of enums and their variants"),
606606
force_overflow_checks: Option<bool> = (None, parse_opt_bool,
607607
"Force overflow checks on or off"),
608+
force_dropflag_checks: Option<bool> = (None, parse_opt_bool,
609+
"Force drop flag checks on or off"),
608610
}
609611

610612
pub fn default_lib_output() -> CrateType {

src/librustc_trans/trans/base.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3082,6 +3082,12 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
30823082
tcx.sess.opts.debug_assertions
30833083
};
30843084

3085+
let check_dropflag = if let Some(v) = tcx.sess.opts.debugging_opts.force_dropflag_checks {
3086+
v
3087+
} else {
3088+
tcx.sess.opts.debug_assertions
3089+
};
3090+
30853091
// Before we touch LLVM, make sure that multithreading is enabled.
30863092
unsafe {
30873093
use std::sync::{Once, ONCE_INIT};
@@ -3110,7 +3116,8 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
31103116
Sha256::new(),
31113117
link_meta.clone(),
31123118
reachable,
3113-
check_overflow);
3119+
check_overflow,
3120+
check_dropflag);
31143121

31153122
{
31163123
let ccx = shared_ccx.get_ccx(0);

src/librustc_trans/trans/context.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub struct SharedCrateContext<'tcx> {
6969
tcx: ty::ctxt<'tcx>,
7070
stats: Stats,
7171
check_overflow: bool,
72+
check_drop_flag_for_sanity: bool,
7273

7374
available_monomorphizations: RefCell<FnvHashSet<String>>,
7475
available_drop_glues: RefCell<FnvHashMap<Ty<'tcx>, String>>,
@@ -242,7 +243,8 @@ impl<'tcx> SharedCrateContext<'tcx> {
242243
symbol_hasher: Sha256,
243244
link_meta: LinkMeta,
244245
reachable: NodeSet,
245-
check_overflow: bool)
246+
check_overflow: bool,
247+
check_drop_flag_for_sanity: bool)
246248
-> SharedCrateContext<'tcx> {
247249
let (metadata_llcx, metadata_llmod) = unsafe {
248250
create_context_and_module(&tcx.sess, "metadata")
@@ -271,6 +273,7 @@ impl<'tcx> SharedCrateContext<'tcx> {
271273
fn_stats: RefCell::new(Vec::new()),
272274
},
273275
check_overflow: check_overflow,
276+
check_drop_flag_for_sanity: check_drop_flag_for_sanity,
274277
available_monomorphizations: RefCell::new(FnvHashSet()),
275278
available_drop_glues: RefCell::new(FnvHashMap()),
276279
};
@@ -727,6 +730,13 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
727730
pub fn check_overflow(&self) -> bool {
728731
self.shared.check_overflow
729732
}
733+
734+
pub fn check_drop_flag_for_sanity(&self) -> bool {
735+
// This controls whether we emit a conditional llvm.debugtrap
736+
// guarded on whether the dropflag is one of its (two) valid
737+
// values.
738+
self.shared.check_drop_flag_for_sanity
739+
}
730740
}
731741

732742
fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef> {

0 commit comments

Comments
 (0)