Merge branch 'master' into env-logger

This commit is contained in:
Ralf Jung 2018-12-27 12:21:53 +01:00 committed by GitHub
commit ef9e18e628
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -303,10 +303,9 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
if let Scalar::Ptr(ptr) = ptr {
// Both old and new pointer must be in-bounds of a *live* allocation.
// (Of the same allocation, but that part is trivial with our representation.)
let alloc = self.memory().get(ptr.alloc_id)?;
alloc.check_bounds_ptr(ptr)?;
self.memory().check_bounds_ptr(ptr, InboundsCheck::Live)?;
let ptr = ptr.signed_offset(offset, self)?;
alloc.check_bounds_ptr(ptr)?;
self.memory().check_bounds_ptr(ptr, InboundsCheck::Live)?;
Ok(Scalar::Ptr(ptr))
} else {
// An integer pointer. They can only be offset by 0, and we pretend there

View file

@ -1,6 +1,16 @@
fn f() -> i32 { 42 }
fn main() {
let v = [1i16, 2];
let x = &v as *const i16;
let x = unsafe { x.offset(1) };
assert_eq!(unsafe { *x }, 2);
// fn ptr offset
unsafe {
let p = f as fn() -> i32 as usize;
let x = (p as *mut u32).offset(0) as usize;
let f: fn() -> i32 = std::mem::transmute(x);
assert_eq!(f(), 42);
}
}