pub fn ptr_offset_inbounds(
        &self,
        ptr: Scalar<M::PointerTag>,
        pointee_ty: Ty<'tcx>,
        offset_count: i64,
    ) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
        // We cannot overflow i64 as a type's size must be <= isize::MAX.
        let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
        // The computed offset, in bytes, cannot overflow an isize.
        let offset_bytes =
            offset_count.checked_mul(pointee_size).ok_or(err_ub!(PointerArithOverflow))?;
        // The offset being in bounds cannot rely on "wrapping around" the address space.
        // So, first rule out overflows in the pointer arithmetic.
        let offset_ptr = ptr.ptr_signed_offset(offset_bytes, self)?;
        // ptr and offset_ptr must be in bounds of the same allocated object. This means all of the
        // memory between these pointers must be accessible. Note that we do not require the
        // pointers to be properly aligned (unlike a read/write operation).
        let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
        let size = offset_bytes.unsigned_abs();
        // This call handles checking for integer/null pointers.
        self.memory.check_ptr_access_align(
            min_ptr,
            Size::from_bytes(size),
            Align::ONE,
            CheckInAllocMsg::PointerArithmeticTest,
        )?;
        Ok(offset_ptr)
    }
/// Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its
/// allocation. For integer pointers, we consider each of them their own tiny allocation of size
/// 0, so offset-by-0 (and only 0) is okay -- except that null cannot be offset by _any_ value.
Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its
allocation. For integer pointers, we consider each of them their own tiny allocation of size
0, so offset-by-0 (and only 0) is okay -- except that null cannot be offset by _any_ value.
Offsets a pointer by some multiple of its type returning an error if the pointer leaves its allocation . For integer pointers we consider each of them their own tiny allocation of size 0 so offset - by - 0 ( and only 0 ) is okay -- except that null cannot be offset by _any_ value .
pub fn ptr_offset_inbounds(
        &self,
        ptr: Scalar<M::PointerTag>,
        pointee_ty: Ty<'tcx>,
        offset_count: i64,
    ) -> InterpResult<'tcx, Scalar<M::PointerTag>> {
        // We cannot overflow i64 as a type's size must be <= isize::MAX.
        let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
        // The computed offset, in bytes, cannot overflow an isize.
        let offset_bytes =
            offset_count.checked_mul(pointee_size).ok_or(err_ub!(PointerArithOverflow))?;
        // The offset being in bounds cannot rely on "wrapping around" the address space.
        // So, first rule out overflows in the pointer arithmetic.
        let offset_ptr = ptr.ptr_signed_offset(offset_bytes, self)?;
        // ptr and offset_ptr must be in bounds of the same allocated object. This means all of the
        // memory between these pointers must be accessible. Note that we do not require the
        // pointers to be properly aligned (unlike a read/write operation).
        let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr };
        let size = offset_bytes.unsigned_abs();
        // This call handles checking for integer/null pointers.
        self.memory.check_ptr_access_align(
            min_ptr,
            Size::from_bytes(size),
            Align::ONE,
            CheckInAllocMsg::PointerArithmeticTest,
        )?;
        Ok(offset_ptr)
    }
pub fn ptr_offset_inbounds ( & self , ptr : Scalar < M :: PointerTag > , pointee_ty : Ty < ' tcx > , offset_count : i64 , ) -> InterpResult < ' tcx , Scalar < M :: PointerTag > > { // We cannot overflow i64 as a type's size must be <= isize::MAX. let pointee_size = i64 :: try_from ( self . layout_of ( pointee_ty ) ? . size . bytes ( ) ) . unwrap ( ) ; // The computed offset, in bytes, cannot overflow an isize. let offset_bytes = offset_count . checked_mul ( pointee_size ) . ok_or ( err_ub ! ( PointerArithOverflow ) ) ? ; // The offset being in bounds cannot rely on "wrapping around" the address space. // So, first rule out overflows in the pointer arithmetic. let offset_ptr = ptr . ptr_signed_offset ( offset_bytes , self ) ? ; // ptr and offset_ptr must be in bounds of the same allocated object. This means all of the // memory between these pointers must be accessible. Note that we do not require the // pointers to be properly aligned (unlike a read/write operation). let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr } ; let size = offset_bytes . unsigned_abs ( ) ; // This call handles checking for integer/null pointers. self . memory . check_ptr_access_align ( min_ptr , Size :: from_bytes ( size ) , Align :: ONE , CheckInAllocMsg :: PointerArithmeticTest , ) ? ; Ok ( offset_ptr ) }
Offsets a pointer by some multiple of its type, returning an error if the pointer leaves its
allocation.
Offsets a pointer by some multiple of its type returning an error if the pointer leaves its allocation .
&self
ptr
Scalar<M::PointerTag>
pointee_ty
Ty<'tcx>
offset_count
i64
&self
ptr
Scalar<M::PointerTag>
pointee_ty
Ty<'tcx>
offset_count
i64