diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-30 11:19:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-30 11:19:14 +0100 |
| commit | e0e96a18294ddbe74d0a64470e419b56e1e75965 (patch) | |
| tree | 891c3330e576b938d49f8424f82d95fb6aff7bda /compiler/rustc_const_eval | |
| parent | bc84452d495148aa248d8e4719149a9a1daa0872 (diff) | |
| parent | bdfb9172c187e5f3527c3a4aba3741badc279515 (diff) | |
| download | rust-e0e96a18294ddbe74d0a64470e419b56e1e75965.tar.gz rust-e0e96a18294ddbe74d0a64470e419b56e1e75965.zip | |
Rollup merge of #120387 - RalfJung:large-array-followup, r=oli-obk
interpret/memory: fix safety comment for large array memset optimization Also fix the doc comment for `check_and_deref_ptr`.
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/memory.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 3afd14eb574..38ad8cbf3a6 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -396,7 +396,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// to the allocation it points to. Supports both shared and mutable references, as the actual /// checking is offloaded to a helper closure. /// - /// If this returns `None`, the size is 0; it can however return `Some` even for size 0. + /// Returns `None` if and only if the size is 0. fn check_and_deref_ptr<T>( &self, ptr: Pointer<Option<M::Provenance>>, @@ -1214,10 +1214,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let size_in_bytes = size.bytes_usize(); // For particularly large arrays (where this is perf-sensitive) it's common that // we're writing a single byte repeatedly. So, optimize that case to a memset. - if size_in_bytes == 1 && num_copies >= 1 { - // SAFETY: `src_bytes` would be read from anyway by copies below (num_copies >= 1). - // Since size_in_bytes = 1, then the `init.no_bytes_init()` check above guarantees - // that this read at type `u8` is OK -- it must be an initialized byte. + if size_in_bytes == 1 { + debug_assert!(num_copies >= 1); // we already handled the zero-sized cases above. + // SAFETY: `src_bytes` would be read from anyway by `copy` below (num_copies >= 1). let value = *src_bytes; dest_bytes.write_bytes(value, (size * num_copies).bytes_usize()); } else if src_alloc_id == dest_alloc_id { |
