提交 c0c8ce80 编写于 作者: W Wesley Wiser

[const-prop] Replace `Ref` handling with use of `InterpCx`

上级 9ec928ca
......@@ -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 @@ pub fn eval_rvalue_into_place(
}
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 @@ fn const_prop(
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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册