PrimVal used to allow comparing Undef
This commit is contained in:
parent
5ee4fdcd15
commit
eca9e3429a
3 changed files with 16 additions and 4 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue