Skip to content

Commit bd93b77

Browse files
committedDec 27, 2019
Avoid memory copy logic for zsts
Closes #67539
1 parent 8f5f8f9 commit bd93b77

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎src/librustc_mir/interpret/memory.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
845845
let src_bytes =
846846
self.get_raw(src.alloc_id)?.get_bytes_with_undef_and_ptr(&tcx, src, size)?.as_ptr();
847847
let dest_bytes =
848-
self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?.as_mut_ptr();
848+
self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?;
849+
850+
// If `dest_bytes` is empty we just optimize to not run anything for zsts.
851+
// See #67539
852+
if dest_bytes.is_empty() {
853+
return Ok(());
854+
}
855+
856+
let dest_bytes = dest_bytes.as_mut_ptr();
849857

850858
// SAFE: The above indexing would have panicked if there weren't at least `size` bytes
851859
// behind `src` and `dest`. Also, we use the overlapping-safe `ptr::copy` if `src` and

0 commit comments

Comments
 (0)
Please sign in to comment.