@@ -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
@@ -571,16 +570,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
571
570
pub fn ptr_offset_inbounds (
572
571
& self ,
573
572
ptr : Pointer < Option < M :: Provenance > > ,
574
- pointee_ty : Ty < ' tcx > ,
575
- offset_count : i64 ,
573
+ offset_bytes : i64 ,
576
574
) -> 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 ) ) ?;
584
575
// The offset being in bounds cannot rely on "wrapping around" the address space.
585
576
// So, first rule out overflows in the pointer arithmetic.
586
577
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> {
589
580
// pointers to be properly aligned (unlike a read/write operation).
590
581
let min_ptr = if offset_bytes >= 0 { ptr } else { offset_ptr } ;
591
582
// This call handles checking for integer/null pointers.
592
- self . check_ptr_access_align (
583
+ self . check_ptr_access (
593
584
min_ptr,
594
585
Size :: from_bytes ( offset_bytes. unsigned_abs ( ) ) ,
595
- Align :: ONE ,
596
586
CheckInAllocMsg :: PointerArithmeticTest ,
597
587
) ?;
598
588
Ok ( offset_ptr)
@@ -621,7 +611,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
621
611
let src = self . read_pointer ( src) ?;
622
612
let dst = self . read_pointer ( dst) ?;
623
613
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)
625
618
}
626
619
627
620
pub ( crate ) fn write_bytes_intrinsic (
@@ -677,7 +670,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
677
670
size|
678
671
-> InterpResult < ' tcx , & [ u8 ] > {
679
672
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 {
681
674
// zero-sized access
682
675
return Ok ( & [ ] ) ;
683
676
} ;
0 commit comments