Skip to content

Commit 4421fad

Browse files
authored
Unrolled build for rust-lang#120387
Rollup merge of rust-lang#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`.
2 parents c401f09 + bdfb917 commit 4421fad

File tree

1 file changed

+4
-5
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+4
-5
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
396396
/// to the allocation it points to. Supports both shared and mutable references, as the actual
397397
/// checking is offloaded to a helper closure.
398398
///
399-
/// If this returns `None`, the size is 0; it can however return `Some` even for size 0.
399+
/// Returns `None` if and only if the size is 0.
400400
fn check_and_deref_ptr<T>(
401401
&self,
402402
ptr: Pointer<Option<M::Provenance>>,
@@ -1214,10 +1214,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
12141214
let size_in_bytes = size.bytes_usize();
12151215
// For particularly large arrays (where this is perf-sensitive) it's common that
12161216
// we're writing a single byte repeatedly. So, optimize that case to a memset.
1217-
if size_in_bytes == 1 && num_copies >= 1 {
1218-
// SAFETY: `src_bytes` would be read from anyway by copies below (num_copies >= 1).
1219-
// Since size_in_bytes = 1, then the `init.no_bytes_init()` check above guarantees
1220-
// that this read at type `u8` is OK -- it must be an initialized byte.
1217+
if size_in_bytes == 1 {
1218+
debug_assert!(num_copies >= 1); // we already handled the zero-sized cases above.
1219+
// SAFETY: `src_bytes` would be read from anyway by `copy` below (num_copies >= 1).
12211220
let value = *src_bytes;
12221221
dest_bytes.write_bytes(value, (size * num_copies).bytes_usize());
12231222
} else if src_alloc_id == dest_alloc_id {

0 commit comments

Comments
 (0)