Skip to content

Commit fcd1f5b

Browse files
Make MaybeStorageLive correct for all kinds of MIR bodies
Before, it ignored the first argument and marked all variables without `Storage*` annotations as dead.
1 parent 444ad62 commit fcd1f5b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/librustc_mir/dataflow/impls/storage_liveness.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@ pub use super::*;
22

33
use crate::dataflow::BottomValue;
44
use crate::dataflow::{self, GenKill, Results, ResultsRefCursor};
5+
use crate::util::storage::AlwaysLiveLocals;
56
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
67
use rustc_middle::mir::*;
78
use std::cell::RefCell;
89

9-
#[derive(Copy, Clone)]
10-
pub struct MaybeStorageLive;
10+
#[derive(Clone)]
11+
pub struct MaybeStorageLive {
12+
always_live_locals: AlwaysLiveLocals,
13+
}
14+
15+
impl MaybeStorageLive {
16+
pub fn new(always_live_locals: AlwaysLiveLocals) -> Self {
17+
MaybeStorageLive { always_live_locals }
18+
}
19+
}
1120

1221
impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
1322
type Idx = Local;
@@ -19,9 +28,12 @@ impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive {
1928
}
2029

2130
fn initialize_start_block(&self, body: &mir::Body<'tcx>, on_entry: &mut BitSet<Self::Idx>) {
22-
// The resume argument is live on function entry (we don't care about
23-
// the `self` argument)
24-
for arg in body.args_iter().skip(1) {
31+
assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size());
32+
for local in self.always_live_locals.iter() {
33+
on_entry.insert(local);
34+
}
35+
36+
for arg in body.args_iter() {
2537
on_entry.insert(arg);
2638
}
2739
}

0 commit comments

Comments
 (0)