diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-12-27 08:56:52 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2019-12-27 09:33:22 -0300 |
| commit | bd93b7718efc4267e1106abb42b19c84ab0d5a86 (patch) | |
| tree | a9af5e0a6df47f77dbaa0ba6d83e9ada8a0b1fce | |
| parent | 8f5f8f916f00f7989a4ebf7b7dbfe1afd605f828 (diff) | |
| download | rust-bd93b7718efc4267e1106abb42b19c84ab0d5a86.tar.gz rust-bd93b7718efc4267e1106abb42b19c84ab0d5a86.zip | |
Avoid memory copy logic for zsts
Closes #67539
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index 71e6d3e8ca1..3d59b33c15d 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -845,7 +845,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { let src_bytes = self.get_raw(src.alloc_id)?.get_bytes_with_undef_and_ptr(&tcx, src, size)?.as_ptr(); let dest_bytes = - self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?.as_mut_ptr(); + self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?; + + // If `dest_bytes` is empty we just optimize to not run anything for zsts. + // See #67539 + if dest_bytes.is_empty() { + return Ok(()); + } + + let dest_bytes = dest_bytes.as_mut_ptr(); // SAFE: The above indexing would have panicked if there weren't at least `size` bytes // behind `src` and `dest`. Also, we use the overlapping-safe `ptr::copy` if `src` and |
