Skip to content

Commit

Permalink
[const-prop] Handle Rvalue::Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Jun 6, 2019
1 parent 529b94e commit 9f4d94b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/librustc_mir/interpret/place.rs
Expand Up @@ -663,6 +663,23 @@ where
Ok(())
}

/// Write an `Immediate` to memory.
#[inline(always)]
pub fn write_immediate_to_mplace(
&mut self,
src: Immediate<M::PointerTag>,
dest: MPlaceTy<'tcx, M::PointerTag>,
) -> EvalResult<'tcx> {
self.write_immediate_to_mplace_no_validate(src, dest)?;

if M::enforce_validity(self) {
// Data got changed, better make sure it matches the type!
self.validate_operand(dest.into(), vec![], None, /*const_mode*/ false)?;
}

Ok(())
}

/// Write an immediate to a place.
/// If you use this you are responsible for validating that things got copied at the
/// right type.
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_mir/transform/const_prop.rs
Expand Up @@ -363,8 +363,12 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
Rvalue::Use(ref op) => {
self.eval_operand(op, source_info)
},
Rvalue::Ref(_, _, ref place) => {
let src = self.eval_place(place, source_info)?;
let mplace = src.try_as_mplace().ok()?;
Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
},
Rvalue::Repeat(..) |
Rvalue::Ref(..) |
Rvalue::Aggregate(..) |
Rvalue::NullaryOp(NullOp::Box, _) |
Rvalue::Discriminant(..) => None,
Expand Down

0 comments on commit 9f4d94b

Please sign in to comment.