Make eval_place_to_mplace take PlaceBase::Static

This commit is contained in:
Santiago Pastorino 2019-05-24 22:35:32 +02:00
parent 8173febf93
commit 6d7a36231a
2 changed files with 21 additions and 19 deletions

View file

@ -469,12 +469,14 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> { ) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
use rustc::mir::Place::*; use rustc::mir::Place::*;
use rustc::mir::PlaceBase; use rustc::mir::PlaceBase;
let op = match *mir_place { let op = match mir_place {
Base(PlaceBase::Local(mir::RETURN_PLACE)) => return err!(ReadFromReturnPointer), Base(PlaceBase::Local(mir::RETURN_PLACE)) => return err!(ReadFromReturnPointer),
Base(PlaceBase::Local(local)) => self.access_local(self.frame(), local, layout)?, Base(PlaceBase::Local(local)) => self.access_local(self.frame(), *local, layout)?,
Base(PlaceBase::Static(_)) => self.eval_place_to_mplace(mir_place)?.into(), Base(PlaceBase::Static(place_static)) => {
self.eval_static_to_mplace(place_static)?.into()
}
Projection(ref proj) => { Projection(proj) => {
let op = self.eval_place_to_op(&proj.base, None)?; let op = self.eval_place_to_op(&proj.base, None)?;
self.operand_projection(op, &proj.elem)? self.operand_projection(op, &proj.elem)?
} }

View file

@ -562,15 +562,14 @@ where
/// Evaluate statics and promoteds to an `MPlace`. Used to share some code between /// Evaluate statics and promoteds to an `MPlace`. Used to share some code between
/// `eval_place` and `eval_place_to_op`. /// `eval_place` and `eval_place_to_op`.
pub(super) fn eval_place_to_mplace( pub(super) fn eval_static_to_mplace(
&self, &self,
mir_place: &mir::Place<'tcx> place_static: &mir::Static<'tcx>
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> { ) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
use rustc::mir::Place::*; use rustc::mir::StaticKind;
use rustc::mir::PlaceBase;
use rustc::mir::{Static, StaticKind}; Ok(match place_static.kind {
Ok(match *mir_place { StaticKind::Promoted(promoted) => {
Base(PlaceBase::Static(box Static { kind: StaticKind::Promoted(promoted), .. })) => {
let instance = self.frame().instance; let instance = self.frame().instance;
self.const_eval_raw(GlobalId { self.const_eval_raw(GlobalId {
instance, instance,
@ -578,7 +577,8 @@ where
})? })?
} }
Base(PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), ty })) => { StaticKind::Static(def_id) => {
let ty = place_static.ty;
assert!(!ty.needs_subst()); assert!(!ty.needs_subst());
let layout = self.layout_of(ty)?; let layout = self.layout_of(ty)?;
let instance = ty::Instance::mono(*self.tcx, def_id); let instance = ty::Instance::mono(*self.tcx, def_id);
@ -600,8 +600,6 @@ where
let alloc = self.tcx.alloc_map.lock().intern_static(cid.instance.def_id()); let alloc = self.tcx.alloc_map.lock().intern_static(cid.instance.def_id());
MPlaceTy::from_aligned_ptr(Pointer::from(alloc).with_default_tag(), layout) MPlaceTy::from_aligned_ptr(Pointer::from(alloc).with_default_tag(), layout)
} }
_ => bug!("eval_place_to_mplace called on {:?}", mir_place),
}) })
} }
@ -613,7 +611,7 @@ where
) -> EvalResult<'tcx, PlaceTy<'tcx, M::PointerTag>> { ) -> EvalResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
use rustc::mir::Place::*; use rustc::mir::Place::*;
use rustc::mir::PlaceBase; use rustc::mir::PlaceBase;
let place = match *mir_place { let place = match mir_place {
Base(PlaceBase::Local(mir::RETURN_PLACE)) => match self.frame().return_place { Base(PlaceBase::Local(mir::RETURN_PLACE)) => match self.frame().return_place {
Some(return_place) => Some(return_place) =>
// We use our layout to verify our assumption; caller will validate // We use our layout to verify our assumption; caller will validate
@ -628,17 +626,19 @@ where
// This works even for dead/uninitialized locals; we check further when writing // This works even for dead/uninitialized locals; we check further when writing
place: Place::Local { place: Place::Local {
frame: self.cur_frame(), frame: self.cur_frame(),
local, local: *local,
}, },
layout: self.layout_of_local(self.frame(), local, None)?, layout: self.layout_of_local(self.frame(), *local, None)?,
}, },
Projection(ref proj) => { Projection(proj) => {
let place = self.eval_place(&proj.base)?; let place = self.eval_place(&proj.base)?;
self.place_projection(place, &proj.elem)? self.place_projection(place, &proj.elem)?
} }
_ => self.eval_place_to_mplace(mir_place)?.into(), Base(PlaceBase::Static(place_static)) => {
self.eval_static_to_mplace(place_static)?.into()
}
}; };
self.dump_place(place.place); self.dump_place(place.place);