@@ -594,6 +594,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
594
594
dest_align : Align ,
595
595
size : Size ,
596
596
nonoverlapping : bool ,
597
+ ) -> EvalResult < ' tcx > {
598
+ self . copy_repeatedly ( src, src_align, dest, dest_align, size, 1 , nonoverlapping)
599
+ }
600
+
601
+ pub fn copy_repeatedly (
602
+ & mut self ,
603
+ src : Scalar ,
604
+ src_align : Align ,
605
+ dest : Scalar ,
606
+ dest_align : Align ,
607
+ size : Size ,
608
+ length : u64 ,
609
+ nonoverlapping : bool ,
597
610
) -> EvalResult < ' tcx > {
598
611
// Empty accesses don't need to be valid pointers, but they should still be aligned
599
612
self . check_align ( src, src_align) ?;
@@ -617,7 +630,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
617
630
. collect ( ) ;
618
631
619
632
let src_bytes = self . get_bytes_unchecked ( src, size, src_align) ?. as_ptr ( ) ;
620
- let dest_bytes = self . get_bytes_mut ( dest, size, dest_align) ?. as_mut_ptr ( ) ;
633
+ let dest_bytes = self . get_bytes_mut ( dest, size * length , dest_align) ?. as_mut_ptr ( ) ;
621
634
622
635
// SAFE: The above indexing would have panicked if there weren't at least `size` bytes
623
636
// behind `src` and `dest`. Also, we use the overlapping-safe `ptr::copy` if `src` and
@@ -634,13 +647,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
634
647
) ) ;
635
648
}
636
649
}
637
- ptr:: copy ( src_bytes, dest_bytes, size. bytes ( ) as usize ) ;
650
+
651
+ for i in 0 ..length {
652
+ ptr:: copy ( src_bytes, dest_bytes. offset ( ( size. bytes ( ) * i) as isize ) , size. bytes ( ) as usize ) ;
653
+ }
638
654
} else {
639
- ptr:: copy_nonoverlapping ( src_bytes, dest_bytes, size. bytes ( ) as usize ) ;
655
+ for i in 0 ..length {
656
+ ptr:: copy_nonoverlapping ( src_bytes, dest_bytes. offset ( ( size. bytes ( ) * i) as isize ) , size. bytes ( ) as usize ) ;
657
+ }
640
658
}
641
659
}
642
660
643
- self . copy_undef_mask ( src, dest, size) ?;
661
+ self . copy_undef_mask ( src, dest, size * length ) ?;
644
662
// copy back the relocations
645
663
self . get_mut ( dest. alloc_id ) ?. relocations . insert_presorted ( relocations) ;
646
664
0 commit comments