diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-03-29 14:16:29 -0700 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2020-04-09 12:45:46 -0700 |
| commit | fcd1f5bc0a1090f295667dc0fdb7f238672b0302 (patch) | |
| tree | e1e64058e6aa0520711cf2215e6382a0d77f1ed4 | |
| parent | 444ad6255b3324a7dd3c4d852808336d39a09ab3 (diff) | |
| download | rust-fcd1f5bc0a1090f295667dc0fdb7f238672b0302.tar.gz rust-fcd1f5bc0a1090f295667dc0fdb7f238672b0302.zip | |
Make `MaybeStorageLive` correct for all kinds of MIR bodies
Before, it ignored the first argument and marked all variables without `Storage*` annotations as dead.
| -rw-r--r-- | src/librustc_mir/dataflow/impls/storage_liveness.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/librustc_mir/dataflow/impls/storage_liveness.rs b/src/librustc_mir/dataflow/impls/storage_liveness.rs index 3dfcfe16fb5..cc63f5f39d5 100644 --- a/src/librustc_mir/dataflow/impls/storage_liveness.rs +++ b/src/librustc_mir/dataflow/impls/storage_liveness.rs @@ -2,12 +2,21 @@ pub use super::*; use crate::dataflow::BottomValue; use crate::dataflow::{self, GenKill, Results, ResultsRefCursor}; +use crate::util::storage::AlwaysLiveLocals; use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use std::cell::RefCell; -#[derive(Copy, Clone)] -pub struct MaybeStorageLive; +#[derive(Clone)] +pub struct MaybeStorageLive { + always_live_locals: AlwaysLiveLocals, +} + +impl MaybeStorageLive { + pub fn new(always_live_locals: AlwaysLiveLocals) -> Self { + MaybeStorageLive { always_live_locals } + } +} impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive { type Idx = Local; @@ -19,9 +28,12 @@ impl dataflow::AnalysisDomain<'tcx> for MaybeStorageLive { } fn initialize_start_block(&self, body: &mir::Body<'tcx>, on_entry: &mut BitSet<Self::Idx>) { - // The resume argument is live on function entry (we don't care about - // the `self` argument) - for arg in body.args_iter().skip(1) { + assert_eq!(body.local_decls.len(), self.always_live_locals.domain_size()); + for local in self.always_live_locals.iter() { + on_entry.insert(local); + } + + for arg in body.args_iter() { on_entry.insert(arg); } } |
