Skip to content

Commit

Permalink
Rollup merge of #64419 - wesleywiser:const_prop_use_ecx, r=oli-obk
Browse files Browse the repository at this point in the history
Deduplicate some code between miri and const prop

r? @oli-obk
  • Loading branch information
Centril authored Sep 14, 2019
2 parents 1fb2f4a + 0b333ef commit 8e00329
Show file tree
Hide file tree
Showing 22 changed files with 218 additions and 221 deletions.
6 changes: 6 additions & 0 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ pub enum UnsupportedOpInfo<'tcx> {
InvalidPointerMath,
ReadUndefBytes(Size),
DeadLocal,
UninitializedLocal,
InvalidBoolOp(mir::BinOp),
UnimplementedTraitSelection,
CalledClosureAsFunction,
Expand Down Expand Up @@ -420,6 +421,7 @@ pub enum UnsupportedOpInfo<'tcx> {
HeapAllocNonPowerOfTwoAlignment(u64),
ReadFromReturnPointer,
PathNotFound(Vec<String>),
ReadOfStaticInConst,
}

impl fmt::Debug for UnsupportedOpInfo<'tcx> {
Expand Down Expand Up @@ -491,6 +493,8 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> {
addresses, e.g., comparing pointers into different allocations"),
DeadLocal =>
write!(f, "tried to access a dead local variable"),
UninitializedLocal =>
write!(f, "tried to access an uninitialized local variable"),
DerefFunctionPointer =>
write!(f, "tried to dereference a function pointer"),
ExecuteMemory =>
Expand Down Expand Up @@ -532,6 +536,8 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> {
not a power of two"),
Unsupported(ref msg) =>
write!(f, "{}", msg),
ReadOfStaticInConst =>
write!(f, "tried to read from a static during const evaluation"),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ impl<'tcx, Tag: Copy + 'static> LocalState<'tcx, Tag> {
match self.value {
LocalValue::Dead => throw_unsup!(DeadLocal),
LocalValue::Uninitialized =>
bug!("The type checker should prevent reading from a never-written local"),
// this is reachable from ConstProp
throw_unsup!(UninitializedLocal),
LocalValue::Live(val) => Ok(val),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

// Evaluate a place with the goal of reading from it. This lets us sometimes
// avoid allocations.
pub(super) fn eval_place_to_op(
pub fn eval_place_to_op(
&self,
place: &mir::Place<'tcx>,
layout: Option<TyLayout<'tcx>>,
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_mir/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ where
}

StaticKind::Static => {
//if the first frame on the stack isn't a static item, then we shouldn't
//eval any static places
if let ty::InstanceDef::Item(item_def_id) = self.stack[0].instance.def {
if !self.tcx.is_static(item_def_id) {
trace!("eval_static_to_mplace: can't eval static in constant");
throw_unsup!(ReadOfStaticInConst);
}
}
let ty = place_static.ty;
assert!(!ty.needs_subst());
let layout = self.layout_of(ty)?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
///
/// There is no separate `eval_rvalue` function. Instead, the code for handling each rvalue
/// type writes its results directly into the memory specified by the place.
fn eval_rvalue_into_place(
pub fn eval_rvalue_into_place(
&mut self,
rvalue: &mir::Rvalue<'tcx>,
place: &mir::Place<'tcx>,
Expand Down
Loading

0 comments on commit 8e00329

Please sign in to comment.