From ff38a95ea22ce57db2b7c84b5fa965c85451b779 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Tue, 28 Jan 2025 11:36:12 +0100 Subject: [PATCH] reallocate_ptr comment Co-authored-by: Ralf Jung --- compiler/rustc_const_eval/src/interpret/memory.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 625ae503e4d6..ffd79cd6f43a 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -291,6 +291,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // For simplicities' sake, we implement reallocate as "alloc, copy, dealloc". // This happens so rarely, the perf advantage is outweighed by the maintenance cost. + // If requested, we zero-init the entire allocation, to ensure that a growing + // allocation has its new bytes properly set. For the part that is copied, + // `mem_copy` below will de-initialize things as necessary. let new_ptr = self.allocate_ptr(new_size, new_align, kind, init)?; let old_size = match old_size_and_align { Some((size, _align)) => size,