From ec1dc749a344522b080ec8162b9fd24fce0c507e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 18 Apr 2022 10:20:11 -0400 Subject: [PATCH] adjust for provenance cleanup --- src/data_race.rs | 6 +++--- src/machine.rs | 36 +++++++++++++++++++----------------- src/shims/backtrace.rs | 2 +- src/stacked_borrows.rs | 3 +-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/data_race.rs b/src/data_race.rs index 4a79d9e99047..7625763a3bb4 100644 --- a/src/data_race.rs +++ b/src/data_race.rs @@ -999,7 +999,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { if let Some(data_race) = &this.machine.data_race { if data_race.multi_threaded.get() { let size = place.layout.size; - let (alloc_id, base_offset, ptr) = this.ptr_get_alloc_id(place.ptr)?; + let (alloc_id, base_offset, _tag) = this.ptr_get_alloc_id(place.ptr)?; // Load and log the atomic operation. // Note that atomic loads are possible even from read-only allocations, so `get_alloc_extra_mut` is not an option. let alloc_meta = &this.get_alloc_extra(alloc_id)?.data_race.as_ref().unwrap(); @@ -1007,7 +1007,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { "Atomic op({}) with ordering {:?} on {:?} (size={})", description, &atomic, - ptr, + place.ptr, size.bytes() ); @@ -1039,7 +1039,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> { { log::trace!( "Updated atomic memory({:?}, size={}) to {:#?}", - ptr, + place.ptr, size.bytes(), range.atomic_ops ); diff --git a/src/machine.rs b/src/machine.rs index 532aeeece07e..df53d90b05c5 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -431,11 +431,13 @@ impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> /// Machine hook implementations. impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { type MemoryKind = MiriMemoryKind; + type ExtraFnVal = Dlsym; type FrameExtra = FrameData<'tcx>; type AllocExtra = AllocExtra; + type PointerTag = Tag; - type ExtraFnVal = Dlsym; + type TagExtra = SbTag; type MemoryMap = MonoHashMap, Allocation)>; @@ -607,9 +609,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { fn ptr_get_alloc( ecx: &MiriEvalContext<'mir, 'tcx>, ptr: Pointer, - ) -> (AllocId, Size) { + ) -> (AllocId, Size, Self::TagExtra) { let rel = intptrcast::GlobalStateInner::abs_ptr_to_rel(ecx, ptr); - (ptr.provenance.alloc_id, rel) + (ptr.provenance.alloc_id, rel, ptr.provenance.sb) } #[inline(always)] @@ -617,16 +619,16 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { _tcx: TyCtxt<'tcx>, machine: &Self, alloc_extra: &AllocExtra, - tag: Tag, + (alloc_id, tag): (AllocId, Self::TagExtra), range: AllocRange, ) -> InterpResult<'tcx> { if let Some(data_race) = &alloc_extra.data_race { - data_race.read(tag.alloc_id, range, machine.data_race.as_ref().unwrap())?; + data_race.read(alloc_id, range, machine.data_race.as_ref().unwrap())?; } if let Some(stacked_borrows) = &alloc_extra.stacked_borrows { stacked_borrows.memory_read( - tag.alloc_id, - tag.sb, + alloc_id, + tag, range, machine.stacked_borrows.as_ref().unwrap(), ) @@ -640,16 +642,16 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { _tcx: TyCtxt<'tcx>, machine: &mut Self, alloc_extra: &mut AllocExtra, - tag: Tag, + (alloc_id, tag): (AllocId, Self::TagExtra), range: AllocRange, ) -> InterpResult<'tcx> { if let Some(data_race) = &mut alloc_extra.data_race { - data_race.write(tag.alloc_id, range, machine.data_race.as_mut().unwrap())?; + data_race.write(alloc_id, range, machine.data_race.as_mut().unwrap())?; } if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows { stacked_borrows.memory_written( - tag.alloc_id, - tag.sb, + alloc_id, + tag, range, machine.stacked_borrows.as_mut().unwrap(), ) @@ -663,19 +665,19 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { _tcx: TyCtxt<'tcx>, machine: &mut Self, alloc_extra: &mut AllocExtra, - tag: Tag, + (alloc_id, tag): (AllocId, Self::TagExtra), range: AllocRange, ) -> InterpResult<'tcx> { - if Some(tag.alloc_id) == machine.tracked_alloc_id { - register_diagnostic(NonHaltingDiagnostic::FreedAlloc(tag.alloc_id)); + if Some(alloc_id) == machine.tracked_alloc_id { + register_diagnostic(NonHaltingDiagnostic::FreedAlloc(alloc_id)); } if let Some(data_race) = &mut alloc_extra.data_race { - data_race.deallocate(tag.alloc_id, range, machine.data_race.as_mut().unwrap())?; + data_race.deallocate(alloc_id, range, machine.data_race.as_mut().unwrap())?; } if let Some(stacked_borrows) = &mut alloc_extra.stacked_borrows { stacked_borrows.memory_deallocated( - tag.alloc_id, - tag.sb, + alloc_id, + tag, range, machine.stacked_borrows.as_mut().unwrap(), ) diff --git a/src/shims/backtrace.rs b/src/shims/backtrace.rs index 2ec4bbb32e02..3ada61abbd29 100644 --- a/src/shims/backtrace.rs +++ b/src/shims/backtrace.rs @@ -124,7 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let ptr = this.read_pointer(ptr)?; // Take apart the pointer, we need its pieces. - let (alloc_id, offset, ptr) = this.ptr_get_alloc_id(ptr)?; + let (alloc_id, offset, _tag) = this.ptr_get_alloc_id(ptr)?; let fn_instance = if let Some(GlobalAlloc::Function(instance)) = this.tcx.get_global_alloc(alloc_id) { diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index a365d909981b..0029de3b5a9c 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -702,8 +702,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ); return Ok(()); } - let (alloc_id, base_offset, ptr) = this.ptr_get_alloc_id(place.ptr)?; - let orig_tag = ptr.provenance.sb; + let (alloc_id, base_offset, orig_tag) = this.ptr_get_alloc_id(place.ptr)?; // Ensure we bail out if the pointer goes out-of-bounds (see miri#1050). let (alloc_size, _) =