diff options
| author | Ralf Jung <post@ralfj.de> | 2024-10-12 12:14:28 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-10-12 12:14:28 +0200 |
| commit | bc4366b099e7a4d115650dcfec4aeeb62bfc3c54 (patch) | |
| tree | 92ba4772f5a6ab5b71497008b782d817d431f6af /src | |
| parent | fb20e4d3b96d1de459d086980a8b99d5060ad9fe (diff) | |
| download | rust-bc4366b099e7a4d115650dcfec4aeeb62bfc3c54.tar.gz rust-bc4366b099e7a4d115650dcfec4aeeb62bfc3c54.zip | |
miri: avoid cloning AllocExtra
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/diagnostics.rs | 4 | ||||
| -rw-r--r-- | src/tools/miri/src/eval.rs | 2 | ||||
| -rw-r--r-- | src/tools/miri/src/machine.rs | 10 |
3 files changed, 12 insertions, 4 deletions
diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index 5b1bad28c07..475139a3b51 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -473,14 +473,14 @@ pub fn report_leaks<'tcx>( leaks: Vec<(AllocId, MemoryKind, Allocation<Provenance, AllocExtra<'tcx>, MiriAllocBytes>)>, ) { let mut any_pruned = false; - for (id, kind, mut alloc) in leaks { + for (id, kind, alloc) in leaks { let mut title = format!( "memory leaked: {id:?} ({}, size: {:?}, align: {:?})", kind, alloc.size().bytes(), alloc.align.bytes() ); - let Some(backtrace) = alloc.extra.backtrace.take() else { + let Some(backtrace) = alloc.extra.backtrace else { ecx.tcx.dcx().err(title); continue; }; diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs index ece76e581f2..57b226de28c 100644 --- a/src/tools/miri/src/eval.rs +++ b/src/tools/miri/src/eval.rs @@ -476,7 +476,7 @@ pub fn eval_entry<'tcx>( } // Check for memory leaks. info!("Additional static roots: {:?}", ecx.machine.static_roots); - let leaks = ecx.find_leaked_allocations(&ecx.machine.static_roots); + let leaks = ecx.take_leaked_allocations(|ecx| &ecx.machine.static_roots); if !leaks.is_empty() { report_leaks(&ecx, leaks); tcx.dcx().note("set `MIRIFLAGS=-Zmiri-ignore-leaks` to disable this check"); diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index b9cebcfe9cd..d346cd7b03e 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -321,7 +321,7 @@ impl ProvenanceExtra { } /// Extra per-allocation data -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct AllocExtra<'tcx> { /// Global state of the borrow tracker, if enabled. pub borrow_tracker: Option<borrow_tracker::AllocState>, @@ -338,6 +338,14 @@ pub struct AllocExtra<'tcx> { pub backtrace: Option<Vec<FrameInfo<'tcx>>>, } +// We need a `Clone` impl because the machine passes `Allocation` through `Cow`... +// but that should never end up actually cloning our `AllocExtra`. +impl<'tcx> Clone for AllocExtra<'tcx> { + fn clone(&self) -> Self { + panic!("our allocations should never be cloned"); + } +} + impl VisitProvenance for AllocExtra<'_> { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { let AllocExtra { borrow_tracker, data_race, weak_memory, backtrace: _ } = self; |
