[const-prop] Replace Ref
handling with use of InterpCx
This commit is contained in:
parent
9ec928ca06
commit
c0c8ce80b3
@ -2,11 +2,11 @@
|
||||
//!
|
||||
//! The main entry point is the `step` method.
|
||||
|
||||
use rustc::mir;
|
||||
use rustc::mir::{self, Place, PlaceBase};
|
||||
use rustc::ty::layout::LayoutOf;
|
||||
use rustc::mir::interpret::{InterpResult, Scalar, PointerArithmetic};
|
||||
|
||||
use super::{InterpCx, Machine};
|
||||
use super::{InterpCx, LocalValue, Machine};
|
||||
|
||||
/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
|
||||
/// same type as the result.
|
||||
@ -240,6 +240,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
|
||||
Ref(_, _, ref place) => {
|
||||
// FIXME(wesleywiser) we don't currently handle the case where we try to make a ref
|
||||
// from a function argument that hasn't been assigned to in this function. So just
|
||||
// report those as uninitialized for now.
|
||||
if let Place {
|
||||
base: PlaceBase::Local(local),
|
||||
projection: None
|
||||
} = place {
|
||||
let alive =
|
||||
if let LocalValue::Live(_) = self.frame().locals[*local].value {
|
||||
true
|
||||
} else { false };
|
||||
|
||||
if local.as_usize() <= self.frame().body.arg_count && !alive {
|
||||
trace!("skipping Ref({:?})", place);
|
||||
throw_unsup!(UninitializedLocal);
|
||||
}
|
||||
}
|
||||
let src = self.eval_place(place)?;
|
||||
let place = self.force_allocation(src)?;
|
||||
if place.layout.size.bytes() > 0 {
|
||||
|
@ -313,17 +313,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||
Rvalue::Len(_) |
|
||||
Rvalue::Cast(..) |
|
||||
Rvalue::NullaryOp(..) |
|
||||
Rvalue::CheckedBinaryOp(..) => {
|
||||
Rvalue::CheckedBinaryOp(..) |
|
||||
Rvalue::Ref(..) => {
|
||||
self.use_ecx(source_info, |this| {
|
||||
this.ecx.eval_rvalue_into_place(rvalue, place)?;
|
||||
this.ecx.eval_place_to_op(place, Some(place_layout))
|
||||
})
|
||||
},
|
||||
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::UnaryOp(op, ref arg) => {
|
||||
let overflow_check = self.tcx.sess.overflow_checks();
|
||||
|
Loading…
Reference in New Issue
Block a user