From 5640304c63c5c77b721424be88791503a0e0ea3d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Apr 2022 17:26:15 -0400 Subject: [PATCH 1/3] add log warnings for when we overwrite parts of a pointer, and de-init the rest --- compiler/rustc_middle/src/mir/interpret/allocation.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 438f356f072c6..357e67de7575a 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -509,6 +509,9 @@ impl Allocation { if Tag::ERR_ON_PARTIAL_PTR_OVERWRITE { return Err(AllocError::PartialPointerOverwrite(first)); } + warn!( + "Partial pointer overwrite! De-initializing memory at offsets {first:?}..{start:?}." + ); self.init_mask.set_range(first, start, false); } if last > end { @@ -517,10 +520,15 @@ impl Allocation { last - cx.data_layout().pointer_size, )); } + warn!( + "Partial pointer overwrite! De-initializing memory at offsets {end:?}..{last:?}." + ); self.init_mask.set_range(end, last, false); } // Forget all the relocations. + // Since relocations do not overlap, we know that removing until `last` (exclusive) is fine, + // i.e., this will not remove any other relocations just after the ones we care about. self.relocations.0.remove_range(first..last); Ok(()) From 989e7479d9cbd285c8104a5bbd9159ff2d66188f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Apr 2022 18:07:19 -0400 Subject: [PATCH 2/3] interpret: more debug logging for read_scalar and write_scalar --- .../rustc_const_eval/src/interpret/memory.rs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index a165fa23f30ac..6504624ad67c5 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -877,9 +877,17 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> { range: AllocRange, val: ScalarMaybeUninit, ) -> InterpResult<'tcx> { + let range = self.range.subrange(range); + debug!( + "write_scalar in {} at {:#x}, size {}: {:?}", + self.alloc_id, + range.start.bytes(), + range.size.bytes(), + val + ); Ok(self .alloc - .write_scalar(&self.tcx, self.range.subrange(range), val) + .write_scalar(&self.tcx, range, val) .map_err(|e| e.to_interp_error(self.alloc_id))?) } @@ -899,10 +907,19 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> { impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> { pub fn read_scalar(&self, range: AllocRange) -> InterpResult<'tcx, ScalarMaybeUninit> { - Ok(self + let range = self.range.subrange(range); + let res = self .alloc - .read_scalar(&self.tcx, self.range.subrange(range)) - .map_err(|e| e.to_interp_error(self.alloc_id))?) + .read_scalar(&self.tcx, range) + .map_err(|e| e.to_interp_error(self.alloc_id))?; + debug!( + "read_scalar in {} at {:#x}, size {}: {:?}", + self.alloc_id, + range.start.bytes(), + range.size.bytes(), + res + ); + Ok(res) } pub fn read_ptr_sized(&self, offset: Size) -> InterpResult<'tcx, ScalarMaybeUninit> { From f3bdcfb8b08a14a556caa3d1adae835c8bfd8c58 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 17 Apr 2022 18:45:01 -0400 Subject: [PATCH 3/3] downgrade really verbose logging to trace --- compiler/rustc_const_eval/src/interpret/eval_context.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index f0fff602fe4cf..827959113b907 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -679,7 +679,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return_place: Option<&PlaceTy<'tcx, M::PointerTag>>, return_to_block: StackPopCleanup, ) -> InterpResult<'tcx> { - debug!("body: {:#?}", body); + trace!("body: {:#?}", body); // first push a stack frame so we have access to the local substs let pre_frame = Frame { body, @@ -836,7 +836,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { return Ok(()); } - debug!("locals: {:#?}", frame.locals); + trace!("locals: {:#?}", frame.locals); // Cleanup: deallocate all locals that are backed by an allocation. for local in &frame.locals {