Skip to content

Commit c5e762f

Browse files
committed
Intern allocations during constant propagation
1 parent 8c406dc commit c5e762f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/librustc_mir/transform/const_prop.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::interpret::{
3030
self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
3131
StackPopCleanup, LocalValue, LocalState, AllocId, Frame,
3232
Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy,
33-
Operand as InterpOperand,
33+
Operand as InterpOperand, intern_const_alloc_recursive,
3434
};
3535
use crate::const_eval::error_to_const_error;
3636
use crate::transform::{MirPass, MirSource};
@@ -655,14 +655,27 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
655655
return false;
656656
}
657657

658-
match *op {
658+
let is_scalar = match *op {
659659
interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) =>
660660
s.is_bits(),
661661
interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l),
662662
ScalarMaybeUndef::Scalar(r))) =>
663663
l.is_bits() && r.is_bits(),
664664
_ => false
665+
};
666+
667+
if let interpret::Operand::Indirect(_) = *op {
668+
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
669+
intern_const_alloc_recursive(
670+
&mut self.ecx,
671+
None,
672+
op.assert_mem_place()
673+
).expect("failed to intern alloc");
674+
return true;
675+
}
665676
}
677+
678+
return is_scalar;
666679
}
667680
}
668681

0 commit comments

Comments
 (0)