diff --git a/compiler/rustc_mir/src/interpret/machine.rs b/compiler/rustc_mir/src/interpret/machine.rs index e6b3b1daf5a..e7d7c38cc8f 100644 --- a/compiler/rustc_mir/src/interpret/machine.rs +++ b/compiler/rustc_mir/src/interpret/machine.rs @@ -313,7 +313,7 @@ fn init_allocation_extra<'b>( #[inline(always)] fn memory_read( _memory_extra: &Self::MemoryExtra, - _alloc: &Allocation, + _alloc_extra: &Self::AllocExtra, _ptr: Pointer, _size: Size, ) -> InterpResult<'tcx> { @@ -324,7 +324,7 @@ fn memory_read( #[inline(always)] fn memory_written( _memory_extra: &mut Self::MemoryExtra, - _alloc: &mut Allocation, + _alloc_extra: &mut Self::AllocExtra, _ptr: Pointer, _size: Size, ) -> InterpResult<'tcx> { @@ -335,8 +335,9 @@ fn memory_written( #[inline(always)] fn memory_deallocated( _memory_extra: &mut Self::MemoryExtra, - _alloc: &mut Allocation, + _alloc_extra: &mut Self::AllocExtra, _ptr: Pointer, + _size: Size, ) -> InterpResult<'tcx> { Ok(()) } diff --git a/compiler/rustc_mir/src/interpret/memory.rs b/compiler/rustc_mir/src/interpret/memory.rs index 37aaa834aff..7fb7c51b0b5 100644 --- a/compiler/rustc_mir/src/interpret/memory.rs +++ b/compiler/rustc_mir/src/interpret/memory.rs @@ -343,10 +343,11 @@ pub fn deallocate( } // Let the machine take some extra action - M::memory_deallocated(&mut self.extra, &mut alloc, ptr)?; + let size = alloc.size(); + M::memory_deallocated(&mut self.extra, &mut alloc.extra, ptr, size)?; // Don't forget to remember size and align of this now-dead allocation - let old = self.dead_alloc_map.insert(ptr.alloc_id, (alloc.size(), alloc.align)); + let old = self.dead_alloc_map.insert(ptr.alloc_id, (size, alloc.align)); if old.is_some() { bug!("Nothing can be deallocated twice"); } @@ -591,7 +592,7 @@ pub fn get<'a>( }, )?; if let Some((ptr, alloc)) = ptr_and_alloc { - M::memory_read(&self.extra, alloc, ptr, size)?; + M::memory_read(&self.extra, &alloc.extra, ptr, size)?; let range = alloc_range(ptr.offset, size); Ok(Some(AllocRef { alloc, range, tcx: self.tcx, alloc_id: ptr.alloc_id })) } else { @@ -660,7 +661,7 @@ pub fn get_mut<'a>( // FIXME: can we somehow avoid looking up the allocation twice here? // We cannot call `get_raw_mut` inside `check_and_deref_ptr` as that would duplicate `&mut self`. let (alloc, extra) = self.get_raw_mut(ptr.alloc_id)?; - M::memory_written(extra, alloc, ptr, size)?; + M::memory_written(extra, &mut alloc.extra, ptr, size)?; let range = alloc_range(ptr.offset, size); Ok(Some(AllocRefMut { alloc, range, tcx, alloc_id: ptr.alloc_id })) } else { @@ -1029,7 +1030,7 @@ pub fn copy_repeatedly( Some(src_ptr) => src_ptr, }; let src_alloc = self.get_raw(src.alloc_id)?; - M::memory_read(&self.extra, src_alloc, src, size)?; + M::memory_read(&self.extra, &src_alloc.extra, src, size)?; // We need the `dest` ptr for the next operation, so we get it now. // We already did the source checks and called the hooks so we are good to return early. let dest = match dest { @@ -1058,7 +1059,7 @@ pub fn copy_repeatedly( // Destination alloc preparations and access hooks. let (dest_alloc, extra) = self.get_raw_mut(dest.alloc_id)?; - M::memory_written(extra, dest_alloc, dest, size * num_copies)?; + M::memory_written(extra, &mut dest_alloc.extra, dest, size * num_copies)?; let dest_bytes = dest_alloc .get_bytes_mut_ptr(&tcx, alloc_range(dest.offset, size * num_copies)) .as_mut_ptr();