From eca9e3429ad55bdc55fa12e69cab8c2cf54d0ccd Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 23 Jun 2017 13:32:15 +0200 Subject: [PATCH] PrimVal used to allow comparing `Undef` --- src/lvalue.rs | 2 +- src/operator.rs | 16 ++++++++++++++-- src/value.rs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lvalue.rs b/src/lvalue.rs index 9205e0c299b..8492019a9bf 100644 --- a/src/lvalue.rs +++ b/src/lvalue.rs @@ -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 { diff --git a/src/operator.rs b/src/operator.rs index ed69c804393..e5ed99b2434 100644 --- a/src/operator.rs +++ b/src/operator.rs @@ -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 diff --git a/src/value.rs b/src/value.rs index 9f7d3eafe1f..85f79b7831e 100644 --- a/src/value.rs +++ b/src/value.rs @@ -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),