Skip to content

Commit

Permalink
Reading undef local/globals gets PrimVal::Undef.
Browse files Browse the repository at this point in the history
This fixes rust-lang#95.
  • Loading branch information
solson committed Dec 17, 2016
1 parent 6b7c68b commit 459a27d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
substs: substs,
promoted: None,
};
self.read_lvalue(Lvalue::Global(cid))?
self.read_lvalue(Lvalue::Global(cid))
}
}

Expand All @@ -784,7 +784,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
substs: self.substs(),
promoted: Some(index),
};
self.read_lvalue(Lvalue::Global(cid))?
self.read_lvalue(Lvalue::Global(cid))
}
};

Expand Down
27 changes: 15 additions & 12 deletions src/lvalue.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::ty::{self, Ty};
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty};
use rustc_data_structures::indexed_vec::Idx;

use error::{EvalError, EvalResult};
use error::EvalResult;
use eval_context::{EvalContext};
use memory::Pointer;
use eval_context::{EvalContext, Value};
use value::{PrimVal, Value};

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Lvalue<'tcx> {
Expand Down Expand Up @@ -117,23 +118,25 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}
}
let lvalue = self.eval_lvalue(lvalue)?;
self.read_lvalue(lvalue)
Ok(self.read_lvalue(lvalue))
}

pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> EvalResult<'tcx, Value> {
pub fn read_lvalue(&self, lvalue: Lvalue<'tcx>) -> Value {
match lvalue {
Lvalue::Ptr { ptr, extra } => {
assert_eq!(extra, LvalueExtra::None);
Ok(Value::ByRef(ptr))
Value::ByRef(ptr)
}
Lvalue::Local { frame, local } => {
self.stack[frame].get_local(local).ok_or(EvalError::ReadUndefBytes)
self.stack[frame].get_local(local).unwrap_or(Value::ByVal(PrimVal::Undef))
}
Lvalue::Global(cid) => {
self.globals
.get(&cid)
.expect("global not cached")
.data
.unwrap_or(Value::ByVal(PrimVal::Undef))
}
Lvalue::Global(cid) => self.globals
.get(&cid)
.expect("global not cached")
.data
.ok_or(EvalError::ReadUndefBytes),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/terminator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
match ty.sty {
// special case `Box` to deallocate the inner allocation
ty::TyBox(contents_ty) => {
let val = self.read_lvalue(lval)?;
let val = self.read_lvalue(lval);
// we are going through the read_value path, because that already does all the
// checks for the trait object types. We'd only be repeating ourselves here.
let val = self.follow_by_ref_value(val, ty)?;
Expand Down

0 comments on commit 459a27d

Please sign in to comment.