1
Fork 0

PrimVal used to allow comparing Undef

This commit is contained in:
Oliver Schneider 2017-06-23 13:32:15 +02:00
parent 5ee4fdcd15
commit eca9e3429a
3 changed files with 16 additions and 4 deletions

View file

@ -8,7 +8,7 @@ use eval_context::{EvalContext};
use memory::Pointer;
use value::{PrimVal, Value};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug)]
pub enum Lvalue<'tcx> {
/// An lvalue referring to a value allocated in the `Memory` system.
Ptr {

View file

@ -159,10 +159,22 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
},
// These work on anything
Eq if left_kind == right_kind => {
return Ok((PrimVal::from_bool(left == right), false));
let result = match (left, right) {
(PrimVal::Bytes(left), PrimVal::Bytes(right)) => left == right,
(PrimVal::Ptr(left), PrimVal::Ptr(right)) => left == right,
(PrimVal::Undef, _) | (_, PrimVal::Undef) => return Err(EvalError::ReadUndefBytes),
_ => false,
};
return Ok((PrimVal::from_bool(result), false));
}
Ne if left_kind == right_kind => {
return Ok((PrimVal::from_bool(left != right), false));
let result = match (left, right) {
(PrimVal::Bytes(left), PrimVal::Bytes(right)) => left != right,
(PrimVal::Ptr(left), PrimVal::Ptr(right)) => left != right,
(PrimVal::Undef, _) | (_, PrimVal::Undef) => return Err(EvalError::ReadUndefBytes),
_ => true,
};
return Ok((PrimVal::from_bool(result), false));
}
// These need both pointers to be in the same allocation
Lt | Le | Gt | Ge | Sub

View file

@ -42,7 +42,7 @@ pub enum Value {
/// `memory::Allocation`. It is in many ways like a small chunk of a `Allocation`, up to 8 bytes in
/// size. Like a range of bytes in an `Allocation`, a `PrimVal` can either represent the raw bytes
/// of a simple value, a pointer into another `Allocation`, or be undefined.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug)]
pub enum PrimVal {
/// The raw bytes of a simple value.
Bytes(u128),