From 16e869a678312b16c2e97461f144ce63ef5309bc Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Mar 2024 13:50:39 +0100 Subject: [PATCH] interpret: pass Size and Align to before_memory_deallocation --- compiler/rustc_const_eval/src/interpret/machine.rs | 3 ++- compiler/rustc_const_eval/src/interpret/memory.rs | 3 ++- src/tools/miri/src/borrow_tracker/mod.rs | 6 +++--- src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs | 6 +++--- src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs | 4 ++-- src/tools/miri/src/concurrency/data_race.rs | 4 ++-- src/tools/miri/src/machine.rs | 7 ++++--- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index ee5de44a651..1b9a96ec321 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -433,7 +433,8 @@ fn before_memory_deallocation( _machine: &mut Self, _alloc_extra: &mut Self::AllocExtra, _prov: (AllocId, Self::ProvenanceExtra), - _range: AllocRange, + _size: Size, + _align: Align, ) -> InterpResult<'tcx> { Ok(()) } diff --git a/compiler/rustc_const_eval/src/interpret/memory.rs b/compiler/rustc_const_eval/src/interpret/memory.rs index 3b2208b8caa..0df724f29c4 100644 --- a/compiler/rustc_const_eval/src/interpret/memory.rs +++ b/compiler/rustc_const_eval/src/interpret/memory.rs @@ -345,7 +345,8 @@ pub fn deallocate_ptr( &mut self.machine, &mut alloc.extra, (alloc_id, prov), - alloc_range(Size::ZERO, size), + size, + alloc.align, )?; // Don't forget to remember size and align of this now-dead allocation diff --git a/src/tools/miri/src/borrow_tracker/mod.rs b/src/tools/miri/src/borrow_tracker/mod.rs index 262f7c449d2..8d76a488269 100644 --- a/src/tools/miri/src/borrow_tracker/mod.rs +++ b/src/tools/miri/src/borrow_tracker/mod.rs @@ -472,14 +472,14 @@ pub fn before_memory_deallocation<'tcx>( &mut self, alloc_id: AllocId, prov_extra: ProvenanceExtra, - range: AllocRange, + size: Size, machine: &MiriMachine<'_, 'tcx>, ) -> InterpResult<'tcx> { match self { AllocState::StackedBorrows(sb) => - sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, range, machine), + sb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine), AllocState::TreeBorrows(tb) => - tb.get_mut().before_memory_deallocation(alloc_id, prov_extra, range, machine), + tb.get_mut().before_memory_deallocation(alloc_id, prov_extra, size, machine), } } diff --git a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs index 86d22229714..7ca2bc76f1e 100644 --- a/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs @@ -574,13 +574,13 @@ pub fn before_memory_deallocation<'tcx>( &mut self, alloc_id: AllocId, tag: ProvenanceExtra, - range: AllocRange, + size: Size, machine: &MiriMachine<'_, 'tcx>, ) -> InterpResult<'tcx> { - trace!("deallocation with tag {:?}: {:?}, size {}", tag, alloc_id, range.size.bytes()); + trace!("deallocation with tag {:?}: {:?}, size {}", tag, alloc_id, size.bytes()); let dcx = DiagnosticCxBuilder::dealloc(machine, tag); let state = machine.borrow_tracker.as_ref().unwrap().borrow(); - self.for_each(range, dcx, |stack, dcx, exposed_tags| { + self.for_each(alloc_range(Size::ZERO, size), dcx, |stack, dcx, exposed_tags| { stack.dealloc(tag, &state, dcx, exposed_tags) })?; Ok(()) diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index 4b944ea88f5..9dd147af424 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -80,7 +80,7 @@ pub fn before_memory_deallocation( &mut self, alloc_id: AllocId, prov: ProvenanceExtra, - range: AllocRange, + size: Size, machine: &MiriMachine<'_, 'tcx>, ) -> InterpResult<'tcx> { // TODO: for now we bail out on wildcard pointers. Eventually we should @@ -91,7 +91,7 @@ pub fn before_memory_deallocation( }; let global = machine.borrow_tracker.as_ref().unwrap(); let span = machine.current_span(); - self.dealloc(tag, range, global, alloc_id, span) + self.dealloc(tag, alloc_range(Size::ZERO, size), global, alloc_id, span) } pub fn expose_tag(&mut self, _tag: BorTag) { diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index e3044884083..4a1c3ac868e 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -1071,10 +1071,10 @@ pub fn write<'tcx>( pub fn deallocate<'tcx>( &mut self, alloc_id: AllocId, - range: AllocRange, + size: Size, machine: &mut MiriMachine<'_, '_>, ) -> InterpResult<'tcx> { - self.unique_access(alloc_id, range, NaWriteType::Deallocate, machine) + self.unique_access(alloc_id, alloc_range(Size::ZERO, size), NaWriteType::Deallocate, machine) } } diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index c3c3a815856..fda7e6f4449 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -1288,16 +1288,17 @@ fn before_memory_deallocation( machine: &mut Self, alloc_extra: &mut AllocExtra<'tcx>, (alloc_id, prove_extra): (AllocId, Self::ProvenanceExtra), - range: AllocRange, + size: Size, + _align: Align, ) -> InterpResult<'tcx> { if machine.tracked_alloc_ids.contains(&alloc_id) { machine.emit_diagnostic(NonHaltingDiagnostic::FreedAlloc(alloc_id)); } if let Some(data_race) = &mut alloc_extra.data_race { - data_race.deallocate(alloc_id, range, machine)?; + data_race.deallocate(alloc_id, size, machine)?; } if let Some(borrow_tracker) = &mut alloc_extra.borrow_tracker { - borrow_tracker.before_memory_deallocation(alloc_id, prove_extra, range, machine)?; + borrow_tracker.before_memory_deallocation(alloc_id, prove_extra, size, machine)?; } if let Some((_, deallocated_at)) = machine.allocation_spans.borrow_mut().get_mut(&alloc_id) {