@@ -13,7 +13,7 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
1313use rustc_middle:: ty:: GenericArgsRef ;
1414use rustc_middle:: ty:: { Ty , TyCtxt } ;
1515use rustc_span:: symbol:: { sym, Symbol } ;
16- use rustc_target:: abi:: { Abi , Align , Primitive , Size } ;
16+ use rustc_target:: abi:: { Abi , Primitive , Size } ;
1717
1818use super :: {
1919 util:: ensure_monomorphic_enough, CheckInAllocMsg , ImmTy , InterpCx , Machine , OpTy , PlaceTy ,
@@ -349,10 +349,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
349349 // Check that the range between them is dereferenceable ("in-bounds or one past the
350350 // end of the same allocation"). This is like the check in ptr_offset_inbounds.
351351 let min_ptr = if dist >= 0 { b } else { a } ;
352- self . check_ptr_access_align (
352+ self . check_ptr_access (
353353 min_ptr,
354354 Size :: from_bytes ( dist. unsigned_abs ( ) ) ,
355- Align :: ONE ,
356355 CheckInAllocMsg :: OffsetFromTest ,
357356 ) ?;
358357
@@ -571,16 +570,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
571570 pub fn ptr_offset_inbounds (
572571 & self ,
573572 ptr : Pointer < Option < M :: Provenance > > ,
574- pointee_ty : Ty < ' tcx > ,
575- offset_count : i64 ,
573+ offset_bytes : i64 ,
576574 ) -> InterpResult < ' tcx , Pointer < Option < M :: Provenance > > > {
577- // We cannot overflow i64 as a type's size must be <= isize::MAX.
578- let pointee_size = i64:: try_from ( self . layout_of ( pointee_ty) ?. size . bytes ( ) ) . unwrap ( ) ;
579- // The computed offset, in bytes, must not overflow an isize.
580- // `checked_mul` enforces a too small bound, but no actual allocation can be big enough for
581- // the difference to be noticeable.
582- let offset_bytes =
583- offset_count. checked_mul ( pointee_size) . ok_or ( err_ub ! ( PointerArithOverflow ) ) ?;
584575 // The offset being in bounds cannot rely on "wrapping around" the address space.
585576 // So, first rule out overflows in the pointer arithmetic.
586577 let offset_ptr = ptr. signed_offset ( offset_bytes, self ) ?;
@@ -589,10 +580,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
589580 // pointers to be properly aligned (unlike a read/write operation).
590581 let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr } ;
591582 // This call handles checking for integer/null pointers.
592- self . check_ptr_access_align (
583+ self . check_ptr_access (
593584 min_ptr,
594585 Size :: from_bytes ( offset_bytes. unsigned_abs ( ) ) ,
595- Align :: ONE ,
596586 CheckInAllocMsg :: PointerArithmeticTest ,
597587 ) ?;
598588 Ok ( offset_ptr)
@@ -621,7 +611,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
621611 let src = self . read_pointer ( src) ?;
622612 let dst = self . read_pointer ( dst) ?;
623613
624- self . mem_copy ( src, align, dst, align, size, nonoverlapping)
614+ self . check_ptr_align ( src, align) ?;
615+ self . check_ptr_align ( dst, align) ?;
616+
617+ self . mem_copy ( src, dst, size, nonoverlapping)
625618 }
626619
627620 pub ( crate ) fn write_bytes_intrinsic (
@@ -677,7 +670,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
677670 size|
678671 -> InterpResult < ' tcx , & [ u8 ] > {
679672 let ptr = this. read_pointer ( op) ?;
680- let Some ( alloc_ref) = self . get_ptr_alloc ( ptr, size, Align :: ONE ) ? else {
673+ let Some ( alloc_ref) = self . get_ptr_alloc ( ptr, size) ? else {
681674 // zero-sized access
682675 return Ok ( & [ ] ) ;
683676 } ;
0 commit comments