Skip to content

Commit

Permalink
Rearrange the check for dead allocs in expose_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Nov 13, 2023
1 parent fb2f7e0 commit 8559971
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/intptrcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,20 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir,
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
fn expose_ptr(&mut self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> {
let ecx = self.eval_context_mut();
// Make sure we aren't trying to expose a dead allocation; this is part of justifying the
// way we treat the exposed set in VisitProvenance.
assert!(!matches!(ecx.get_alloc_info(alloc_id).2, AllocKind::Dead));
// Exposing a dead alloc is a no-op, because it's not possible to get a dead allocation
// via int2ptr.
if matches!(ecx.get_alloc_info(alloc_id).2, AllocKind::Dead) {
return Ok(());
}
let global_state = ecx.machine.intptrcast.get_mut();
// In strict mode, we don't need this, so we can save some cycles by not tracking it.
if global_state.provenance_mode != ProvenanceMode::Strict {
trace!("Exposing allocation id {alloc_id:?}");
global_state.exposed.insert(alloc_id);
if ecx.machine.borrow_tracker.is_some() {
ecx.expose_tag(alloc_id, tag)?;
}
if global_state.provenance_mode == ProvenanceMode::Strict {
return Ok(());
}
trace!("Exposing allocation id {alloc_id:?}");
global_state.exposed.insert(alloc_id);
if ecx.machine.borrow_tracker.is_some() {
ecx.expose_tag(alloc_id, tag)?;
}
Ok(())
}
Expand Down

0 comments on commit 8559971

Please sign in to comment.