Skip to content

Commit 84fe0c4

Browse files
committed
Fix relocations to include repeated values
1 parent c431f3f commit 84fe0c4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,21 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
621621
// first copy the relocations to a temporary buffer, because
622622
// `get_bytes_mut` will clear the relocations, which is correct,
623623
// since we don't want to keep any relocations at the target.
624-
let relocations: Vec<_> = self.relocations(src, size)?
625-
.iter()
626-
.map(|&(offset, alloc_id)| {
627-
// Update relocation offsets for the new positions in the destination allocation.
628-
(offset + dest.offset - src.offset, alloc_id)
629-
})
630-
.collect();
624+
let relocations = {
625+
let relocations = self.relocations(src, size)?;
626+
let mut new_relocations = Vec::with_capacity(relocations.len() * (length as usize));
627+
for i in 0..length {
628+
new_relocations.extend(
629+
relocations
630+
.iter()
631+
.map(|&(offset, alloc_id)| {
632+
(offset + dest.offset - src.offset + (i * size * relocations.len() as u64), alloc_id)
633+
})
634+
);
635+
}
636+
637+
new_relocations
638+
};
631639

632640
let src_bytes = self.get_bytes_unchecked(src, size, src_align)?.as_ptr();
633641
let dest_bytes = self.get_bytes_mut(dest, size * length, dest_align)?.as_mut_ptr();

0 commit comments

Comments
 (0)