Skip to content

Commit 4053b00

Browse files
committed
Use -Z force-dropflag-checks=on/off for emitting sanity-check.
(That is, added config and debugflag a la check-overflow but for drop flag sanity-check.) Remove now-unused import of NoDebugInfo from trans::glue.
1 parent 601eca3 commit 4053b00

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
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
@@ -3029,6 +3029,12 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
30293029
tcx.sess.opts.debug_assertions
30303030
};
30313031

3032+
let check_dropflag = if let Some(v) = tcx.sess.opts.debugging_opts.force_dropflag_checks {
3033+
v
3034+
} else {
3035+
tcx.sess.opts.debug_assertions
3036+
};
3037+
30323038
// Before we touch LLVM, make sure that multithreading is enabled.
30333039
unsafe {
30343040
use std::sync::{Once, ONCE_INIT};
@@ -3057,7 +3063,8 @@ pub fn trans_crate<'tcx>(analysis: ty::CrateAnalysis<'tcx>)
30573063
Sha256::new(),
30583064
link_meta.clone(),
30593065
reachable,
3060-
check_overflow);
3066+
check_overflow,
3067+
check_dropflag);
30613068

30623069
{
30633070
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> {

src/librustc_trans/trans/glue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use util::ppaux;
4040

4141
use arena::TypedArena;
4242
use libc::c_uint;
43-
use session::config::NoDebugInfo;
4443
use syntax::ast;
4544

4645
pub fn trans_exchange_free_dyn<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
@@ -237,7 +236,7 @@ fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
237236
let drop_flag_llty = type_of(bcx.fcx.ccx, bcx.tcx().dtor_type());
238237
let init_val = C_integral(drop_flag_llty, adt::DTOR_NEEDED as u64, false);
239238

240-
let bcx = if bcx.tcx().sess.opts.debuginfo == NoDebugInfo {
239+
let bcx = if !bcx.ccx().check_drop_flag_for_sanity() {
241240
bcx
242241
} else {
243242
let drop_flag_llty = type_of(bcx.fcx.ccx, bcx.tcx().dtor_type());

0 commit comments

Comments
 (0)