This commit is contained in:
Oliver Schneider 2017-09-05 17:18:48 +02:00 committed by Ralf Jung
parent ee5383fe2a
commit e9315a60e4
4 changed files with 19 additions and 23 deletions

View File

@ -467,8 +467,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
for block in mir.basic_blocks() { for block in mir.basic_blocks() {
for stmt in block.statements.iter() { for stmt in block.statements.iter() {
match stmt.kind { match stmt.kind {
StorageLive(mir::Lvalue::Local(local)) | StorageLive(local) |
StorageDead(mir::Lvalue::Local(local)) => { StorageDead(local) => {
set.insert(local); set.insert(local);
} }
_ => {} _ => {}

View File

@ -3,7 +3,7 @@ use rustc::ty::layout::{Size, Align};
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use super::{EvalResult, EvalContext, MemoryPointer, PrimVal, Value, Pointer, Machine, PtrAndAlign}; use super::{EvalResult, EvalContext, MemoryPointer, PrimVal, Value, Pointer, Machine, PtrAndAlign, ValTy};
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Lvalue { pub enum Lvalue {
@ -400,7 +400,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
&mut self, &mut self,
base: Lvalue, base: Lvalue,
base_ty: Ty<'tcx>, base_ty: Ty<'tcx>,
proj_elem: &mir::ProjectionElem<'tcx, mir::Operand<'tcx>, Ty<'tcx>>, proj_elem: &mir::ProjectionElem<'tcx, mir::Local, Ty<'tcx>>,
) -> EvalResult<'tcx, Lvalue> { ) -> EvalResult<'tcx, Lvalue> {
use rustc::mir::ProjectionElem::*; use rustc::mir::ProjectionElem::*;
let (ptr, extra) = match *proj_elem { let (ptr, extra) = match *proj_elem {
@ -439,9 +439,10 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
return self.val_to_lvalue(val, pointee_type); return self.val_to_lvalue(val, pointee_type);
} }
Index(ref operand) => { Index(local) => {
let n_ptr = self.eval_operand(operand)?; let value = self.frame().get_local(local)?;
let n = self.value_to_primval(n_ptr)?.to_u64()?; let ty = self.tcx.types.usize;
let n = self.value_to_primval(ValTy { value, ty })?.to_u64()?;
return self.lvalue_index(base, base_ty, n); return self.lvalue_index(base, base_ty, n);
} }

View File

@ -145,22 +145,15 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
} }
} }
// Mark locals as dead or alive. // Mark locals as alive
StorageLive(ref lvalue) | StorageLive(local) => {
StorageDead(ref lvalue) => { let old_val = self.frame_mut().storage_live(local)?;
let (frame, local) = self.deallocate_local(old_val)?;
match self.eval_lvalue(lvalue)? { }
Lvalue::Local { frame, local } if self.cur_frame() == frame => (
frame, // Mark locals as dead
local, StorageDead(local) => {
), let old_val = self.frame_mut().storage_dead(local)?;
_ => return err!(Unimplemented("Storage annotations must refer to locals of the topmost stack frame.".to_owned())), // FIXME maybe this should get its own error type
};
let old_val = match stmt.kind {
StorageLive(_) => self.stack[frame].storage_live(local)?,
StorageDead(_) => self.stack[frame].storage_dead(local)?,
_ => bug!("We already checked that we are a storage stmt"),
};
self.deallocate_local(old_val)?; self.deallocate_local(old_val)?;
} }

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// compile-flags: -Zmir-emit-validate=0
#![feature(unsized_tuple_coercion)] #![feature(unsized_tuple_coercion)]
use std::mem; use std::mem;