Skip to content

Commit eca9e34

Browse files
committed
PrimVal used to allow comparing Undef
1 parent 5ee4fdc commit eca9e34

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/lvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use eval_context::{EvalContext};
88
use memory::Pointer;
99
use value::{PrimVal, Value};
1010

11-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
11+
#[derive(Copy, Clone, Debug)]
1212
pub enum Lvalue<'tcx> {
1313
/// An lvalue referring to a value allocated in the `Memory` system.
1414
Ptr {

src/operator.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,22 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
159159
},
160160
// These work on anything
161161
Eq if left_kind == right_kind => {
162-
return Ok((PrimVal::from_bool(left == right), false));
162+
let result = match (left, right) {
163+
(PrimVal::Bytes(left), PrimVal::Bytes(right)) => left == right,
164+
(PrimVal::Ptr(left), PrimVal::Ptr(right)) => left == right,
165+
(PrimVal::Undef, _) | (_, PrimVal::Undef) => return Err(EvalError::ReadUndefBytes),
166+
_ => false,
167+
};
168+
return Ok((PrimVal::from_bool(result), false));
163169
}
164170
Ne if left_kind == right_kind => {
165-
return Ok((PrimVal::from_bool(left != right), false));
171+
let result = match (left, right) {
172+
(PrimVal::Bytes(left), PrimVal::Bytes(right)) => left != right,
173+
(PrimVal::Ptr(left), PrimVal::Ptr(right)) => left != right,
174+
(PrimVal::Undef, _) | (_, PrimVal::Undef) => return Err(EvalError::ReadUndefBytes),
175+
_ => true,
176+
};
177+
return Ok((PrimVal::from_bool(result), false));
166178
}
167179
// These need both pointers to be in the same allocation
168180
Lt | Le | Gt | Ge | Sub

src/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum Value {
4242
/// `memory::Allocation`. It is in many ways like a small chunk of a `Allocation`, up to 8 bytes in
4343
/// size. Like a range of bytes in an `Allocation`, a `PrimVal` can either represent the raw bytes
4444
/// of a simple value, a pointer into another `Allocation`, or be undefined.
45-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
45+
#[derive(Clone, Copy, Debug)]
4646
pub enum PrimVal {
4747
/// The raw bytes of a simple value.
4848
Bytes(u128),

0 commit comments

Comments
 (0)