]> git.lizzy.rs Git - rust.git/commitdiff
Make `MaybeStorageLive` correct for all kinds of MIR bodies
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Sun, 29 Mar 2020 21:16:29 +0000 (14:16 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 9 Apr 2020 19:45:46 +0000 (12:45 -0700)
Before, it ignored the first argument and marked all variables without
`Storage*` annotations as dead.

src/librustc_mir/dataflow/impls/storage_liveness.rs

index 3dfcfe16fb51493e5f51fd32345c59e0623fd528..cc63f5f39d53cf85b8432dbf60be31ce41a40c29 100644 (file)
@@ -2,12 +2,21 @@
 
 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 @@ fn bits_per_block(&self, body: &mir::Body<'tcx>) -> usize {
     }
 
     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);
         }
     }