about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-11-22 20:48:18 -0500
committerWesley Wiser <wwiser@gmail.com>2019-11-23 15:11:56 -0500
commitc5e762fd8845658bf5d70dc714d16f2a1ec75c3f (patch)
treec99aec79d02a9568babea0061933b5033695fb3e
parent8c406dc29cd49402609700469a313735622ec80c (diff)
downloadrust-c5e762fd8845658bf5d70dc714d16f2a1ec75c3f.tar.gz
rust-c5e762fd8845658bf5d70dc714d16f2a1ec75c3f.zip
Intern allocations during constant propagation
-rw-r--r--src/librustc_mir/transform/const_prop.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index da11a7446bb..4333e5c5142 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -30,7 +30,7 @@ use crate::interpret::{
     self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
     StackPopCleanup, LocalValue, LocalState, AllocId, Frame,
     Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy,
-    Operand as InterpOperand,
+    Operand as InterpOperand, intern_const_alloc_recursive,
 };
 use crate::const_eval::error_to_const_error;
 use crate::transform::{MirPass, MirSource};
@@ -655,14 +655,27 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
             return false;
         }
 
-        match *op {
+        let is_scalar = match *op {
             interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) =>
                 s.is_bits(),
             interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l),
                                                                 ScalarMaybeUndef::Scalar(r))) =>
                 l.is_bits() && r.is_bits(),
             _ => false
+        };
+
+        if let interpret::Operand::Indirect(_) = *op {
+            if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
+                intern_const_alloc_recursive(
+                    &mut self.ecx,
+                    None,
+                    op.assert_mem_place()
+                ).expect("failed to intern alloc");
+                return true;
+            }
         }
+
+        return is_scalar;
     }
 }