Skip to content

Commit da33ac2

Browse files
committed
rustc_mir: do not remove dead user variables if debuginfo needs them.
1 parent dd9a526 commit da33ac2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_mir/transform/simplify.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
4242
use rustc::ty::TyCtxt;
4343
use rustc::mir::*;
4444
use rustc::mir::visit::{MutVisitor, Visitor, PlaceContext};
45+
use rustc::session::config::FullDebugInfo;
4546
use std::borrow::Cow;
4647
use transform::{MirPass, MirSource};
4748

@@ -281,16 +282,24 @@ pub struct SimplifyLocals;
281282

282283
impl MirPass for SimplifyLocals {
283284
fn run_pass<'a, 'tcx>(&self,
284-
_: TyCtxt<'a, 'tcx, 'tcx>,
285+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
285286
_: MirSource,
286287
mir: &mut Mir<'tcx>) {
287288
let mut marker = DeclMarker { locals: BitVector::new(mir.local_decls.len()) };
288289
marker.visit_mir(mir);
289290
// Return pointer and arguments are always live
290-
marker.locals.insert(0);
291-
for idx in mir.args_iter() {
292-
marker.locals.insert(idx.index());
291+
marker.locals.insert(RETURN_PLACE.index());
292+
for arg in mir.args_iter() {
293+
marker.locals.insert(arg.index());
293294
}
295+
296+
// We may need to keep dead user variables live for debuginfo.
297+
if tcx.sess.opts.debuginfo == FullDebugInfo {
298+
for local in mir.vars_iter() {
299+
marker.locals.insert(local.index());
300+
}
301+
}
302+
294303
let map = make_local_map(&mut mir.local_decls, marker.locals);
295304
// Update references to all vars and tmps now
296305
LocalUpdater { map: map }.visit_mir(mir);

0 commit comments

Comments
 (0)