Skip to content

Commit 72050c8

Browse files
committed
[const-prop] Replace Ref handling with use of InterpCx
1 parent a1053a9 commit 72050c8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/librustc_mir/interpret/step.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//!
33
//! The main entry point is the `step` method.
44
5-
use rustc::mir;
5+
use rustc::mir::{self, Place, PlaceBase};
66
use rustc::ty::layout::LayoutOf;
77
use rustc::mir::interpret::{InterpResult, Scalar, PointerArithmetic};
88

9-
use super::{InterpCx, Machine};
9+
use super::{InterpCx, LocalValue, Machine};
1010

1111
/// Classify whether an operator is "left-homogeneous", i.e., the LHS has the
1212
/// same type as the result.
@@ -240,6 +240,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
240240
}
241241

242242
Ref(_, _, ref place) => {
243+
// FIXME(wesleywiser) we don't currently handle the case where we try to make a ref
244+
// from a function argument that hasn't been assigned to in this function. So just
245+
// report those as uninitialized for now.
246+
if let Place {
247+
base: PlaceBase::Local(local),
248+
projection: None
249+
} = place {
250+
let alive =
251+
if let LocalValue::Live(_) = self.frame().locals[*local].value {
252+
true
253+
} else { false };
254+
255+
if local.as_usize() <= self.frame().body.arg_count && !alive {
256+
trace!("skipping Ref({:?})", place);
257+
throw_unsup!(UninitializedLocal);
258+
}
259+
}
243260
let src = self.eval_place(place)?;
244261
let place = self.force_allocation(src)?;
245262
if place.layout.size.bytes() > 0 {

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
313313
Rvalue::Len(_) |
314314
Rvalue::Cast(..) |
315315
Rvalue::NullaryOp(..) |
316-
Rvalue::CheckedBinaryOp(..) => {
316+
Rvalue::CheckedBinaryOp(..) |
317+
Rvalue::Ref(..) => {
317318
self.use_ecx(source_info, |this| {
318319
this.ecx.eval_rvalue_into_place(rvalue, place)?;
319320
this.ecx.eval_place_to_op(place, Some(place_layout))
320321
})
321322
},
322-
Rvalue::Ref(_, _, ref place) => {
323-
let src = self.eval_place(place, source_info)?;
324-
let mplace = src.try_as_mplace().ok()?;
325-
Some(ImmTy::from_scalar(mplace.ptr.into(), place_layout).into())
326-
},
327323

328324
Rvalue::UnaryOp(op, ref arg) => {
329325
let overflow_check = self.tcx.sess.overflow_checks();

0 commit comments

Comments
 (0)