@@ -42,6 +42,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
42
42
use rustc:: ty:: TyCtxt ;
43
43
use rustc:: mir:: * ;
44
44
use rustc:: mir:: visit:: { MutVisitor , Visitor , PlaceContext } ;
45
+ use rustc:: session:: config:: FullDebugInfo ;
45
46
use std:: borrow:: Cow ;
46
47
use transform:: { MirPass , MirSource } ;
47
48
@@ -281,16 +282,24 @@ pub struct SimplifyLocals;
281
282
282
283
impl MirPass for SimplifyLocals {
283
284
fn run_pass < ' a , ' tcx > ( & self ,
284
- _ : TyCtxt < ' a , ' tcx , ' tcx > ,
285
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
285
286
_: MirSource ,
286
287
mir : & mut Mir < ' tcx > ) {
287
288
let mut marker = DeclMarker { locals : BitVector :: new ( mir. local_decls . len ( ) ) } ;
288
289
marker. visit_mir ( mir) ;
289
290
// 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 ( ) ) ;
293
294
}
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
+
294
303
let map = make_local_map ( & mut mir. local_decls , marker. locals ) ;
295
304
// Update references to all vars and tmps now
296
305
LocalUpdater { map : map } . visit_mir ( mir) ;
0 commit comments