@@ -13,7 +13,7 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
13
13
use rustc_middle:: ty:: GenericArgsRef ;
14
14
use rustc_middle:: ty:: { Ty , TyCtxt } ;
15
15
use rustc_span:: symbol:: { sym, Symbol } ;
16
- use rustc_target:: abi:: { Abi , Align , Primitive , Size } ;
16
+ use rustc_target:: abi:: { Abi , Primitive , Size } ;
17
17
18
18
use super :: {
19
19
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> {
349
349
// Check that the range between them is dereferenceable ("in-bounds or one past the
350
350
// end of the same allocation"). This is like the check in ptr_offset_inbounds.
351
351
let min_ptr = if dist >= 0 { b } else { a } ;
352
- self . check_ptr_access_align (
352
+ self . check_ptr_access (
353
353
min_ptr,
354
354
Size :: from_bytes ( dist. unsigned_abs ( ) ) ,
355
- Align :: ONE ,
356
355
CheckInAllocMsg :: OffsetFromTest ,
357
356
) ?;
358
357
@@ -565,16 +564,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
565
564
pub fn ptr_offset_inbounds (
566
565
& self ,
567
566
ptr : Pointer < Option < M :: Provenance > > ,
568
- pointee_ty : Ty < ' tcx > ,
569
- offset_count : i64 ,
567
+ offset_bytes : i64 ,
570
568
) -> InterpResult < ' tcx , Pointer < Option < M :: Provenance > > > {
571
- // We cannot overflow i64 as a type's size must be <= isize::MAX.
572
- let pointee_size = i64:: try_from ( self . layout_of ( pointee_ty) ?. size . bytes ( ) ) . unwrap ( ) ;
573
- // The computed offset, in bytes, must not overflow an isize.
574
- // `checked_mul` enforces a too small bound, but no actual allocation can be big enough for
575
- // the difference to be noticeable.
576
- let offset_bytes =
577
- offset_count. checked_mul ( pointee_size) . ok_or ( err_ub ! ( PointerArithOverflow ) ) ?;
578
569
// The offset being in bounds cannot rely on "wrapping around" the address space.
579
570
// So, first rule out overflows in the pointer arithmetic.
580
571
let offset_ptr = ptr. signed_offset ( offset_bytes, self ) ?;
@@ -583,10 +574,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
583
574
// pointers to be properly aligned (unlike a read/write operation).
584
575
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr } ;
585
576
// This call handles checking for integer/null pointers.
586
- self . check_ptr_access_align (
577
+ self . check_ptr_access (
587
578
min_ptr,
588
579
Size :: from_bytes ( offset_bytes. unsigned_abs ( ) ) ,
589
- Align :: ONE ,
590
580
CheckInAllocMsg :: PointerArithmeticTest ,
591
581
) ?;
592
582
Ok ( offset_ptr)
@@ -615,7 +605,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
615
605
let src = self . read_pointer ( src) ?;
616
606
let dst = self . read_pointer ( dst) ?;
617
607
618
- self . mem_copy ( src, align, dst, align, size, nonoverlapping)
608
+ self . check_ptr_align ( src, align) ?;
609
+ self . check_ptr_align ( dst, align) ?;
610
+
611
+ self . mem_copy ( src, dst, size, nonoverlapping)
619
612
}
620
613
621
614
pub ( crate ) fn write_bytes_intrinsic (
@@ -671,7 +664,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
671
664
size|
672
665
-> InterpResult < ' tcx , & [ u8 ] > {
673
666
let ptr = this. read_pointer ( op) ?;
674
- let Some ( alloc_ref) = self . get_ptr_alloc ( ptr, size, Align :: ONE ) ? else {
667
+ let Some ( alloc_ref) = self . get_ptr_alloc ( ptr, size) ? else {
675
668
// zero-sized access
676
669
return Ok ( & [ ] ) ;
677
670
} ;
0 commit comments