Merge branch 'master' into master
This commit is contained in:
commit
5edb9c915f
@ -109,6 +109,27 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
|
|||||||
err!(InvalidPointerMath)
|
err!(InvalidPointerMath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Gt | Ge if left.is_ptr() && right.is_bits() => {
|
||||||
|
// "ptr >[=] integer" can be tested if the integer is small enough.
|
||||||
|
let left = left.to_ptr().expect("we checked is_ptr");
|
||||||
|
let right = right.to_bits(self.memory().pointer_size()).expect("we checked is_bits");
|
||||||
|
let (_alloc_size, alloc_align) = self.memory()
|
||||||
|
.get_size_and_align(left.alloc_id, InboundsCheck::MaybeDead)
|
||||||
|
.expect("determining size+align of dead ptr cannot fail");
|
||||||
|
let min_ptr_val = u128::from(alloc_align.bytes()) + u128::from(left.offset.bytes());
|
||||||
|
let result = match bin_op {
|
||||||
|
Gt => min_ptr_val > right,
|
||||||
|
Ge => min_ptr_val >= right,
|
||||||
|
_ => bug!(),
|
||||||
|
};
|
||||||
|
if result {
|
||||||
|
// Definitely true!
|
||||||
|
Ok((Scalar::from_bool(true), false))
|
||||||
|
} else {
|
||||||
|
// Sorry, can't tell.
|
||||||
|
err!(InvalidPointerMath)
|
||||||
|
}
|
||||||
|
}
|
||||||
// These work if the left operand is a pointer, and the right an integer
|
// These work if the left operand is a pointer, and the right an integer
|
||||||
Add | BitAnd | Sub | Rem if left.is_ptr() && right.is_bits() => {
|
Add | BitAnd | Sub | Rem if left.is_ptr() && right.is_bits() => {
|
||||||
// Cast to i128 is fine as we checked the kind to be ptr-sized
|
// Cast to i128 is fine as we checked the kind to be ptr-sized
|
||||||
|
7
tests/compile-fail/ptr_ge_integer.rs
Normal file
7
tests/compile-fail/ptr_ge_integer.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
let b = Box::new(0);
|
||||||
|
let x = &*b as *const i32;
|
||||||
|
// We cannot test if this is >= 64. After all, depending on the base address, that
|
||||||
|
// might or might not be the case.
|
||||||
|
assert!(x >= 64 as *const i32); //~ ERROR invalid arithmetic on pointers
|
||||||
|
}
|
@ -83,4 +83,11 @@ fn main() {
|
|||||||
assert!(dangling != 5usize);
|
assert!(dangling != 5usize);
|
||||||
assert!(dangling != 6usize);
|
assert!(dangling != 6usize);
|
||||||
assert!(dangling != 7usize);
|
assert!(dangling != 7usize);
|
||||||
|
|
||||||
|
// Using inequality to do the comparison.
|
||||||
|
assert!(dangling > 0);
|
||||||
|
assert!(dangling > 1);
|
||||||
|
assert!(dangling > 2);
|
||||||
|
assert!(dangling > 3);
|
||||||
|
assert!(dangling >= 4);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user