Scalar::Ptr(ptr) => {
// check this is not NULL -- which we can ensure only if this is in-bounds
// of some (potentially dead) allocation.
- let align = self.check_bounds_ptr_maybe_dead(ptr)?;
+ let align = self.check_bounds_ptr(ptr, InboundsCheck::MaybeDead)?;
(ptr.offset.bytes(), align)
}
Scalar::Bits { bits, size } => {
/// Check if the pointer is "in-bounds". Notice that a pointer pointing at the end
/// of an allocation (i.e., at the first *inaccessible* location) *is* considered
/// in-bounds! This follows C's/LLVM's rules.
- /// This function also works for deallocated allocations.
- /// Use `.get(ptr.alloc_id)?.check_bounds_ptr(ptr)` if you want to force the allocation
- /// to still be live.
/// If you want to check bounds before doing a memory access, better first obtain
/// an `Allocation` and call `check_bounds`.
- pub fn check_bounds_ptr_maybe_dead(
+ pub fn check_bounds_ptr(
&self,
ptr: Pointer<M::PointerTag>,
+ liveness: InboundsCheck,
) -> EvalResult<'tcx, Align> {
let (allocation_size, align) = self.get_size_and_align(ptr.alloc_id);
- ptr.check_in_alloc(allocation_size, InboundsCheck::MaybeDead)?;
+ ptr.check_in_alloc(allocation_size, liveness)?;
Ok(align)
}
}