Skip to content

Commit

Permalink
Address some review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
carbotaniuman committed Apr 21, 2022
1 parent cd86199 commit d766294
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
7 changes: 1 addition & 6 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
let this = self.eval_context_mut();
// This got just allocated, so there definitely is a pointer here.
let provenance = mplace.ptr.into_pointer_or_addr().unwrap().provenance;

if let Tag::Concrete(concrete) = provenance {
this.alloc_mark_immutable(concrete.alloc_id).unwrap();
} else {
bug!("Machine allocation that was just created should have concrete provenance");
}
this.alloc_mark_immutable(provenance.get_alloc_id().unwrap()).unwrap();
}
}

Expand Down
30 changes: 14 additions & 16 deletions src/intptrcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ impl<'mir, 'tcx> GlobalStateInner {
let pos = global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr);

match pos {
Ok(pos) => {
let (_, alloc_id) = global_state.int_to_ptr_map[pos];

if !global_state.permissive_provenance || global_state.exposed.contains(&alloc_id) {
Some(global_state.int_to_ptr_map[pos].1)
} else {
None
}
}
Ok(pos) => Some(global_state.int_to_ptr_map[pos].1),
Err(0) => None,
Err(pos) => {
// This is the largest of the adresses smaller than `int`,
Expand All @@ -76,20 +68,26 @@ impl<'mir, 'tcx> GlobalStateInner {
let offset = addr - glb;
// If the offset exceeds the size of the allocation, don't use this `alloc_id`.

if (!global_state.permissive_provenance || global_state.exposed.contains(&alloc_id))
&& offset
<= ecx
.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)
.unwrap()
.0
.bytes()
if offset
<= ecx
.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)
.unwrap()
.0
.bytes()
{
Some(alloc_id)
} else {
None
}
}
}
.and_then(|alloc_id| {
if global_state.permissive_provenance && !global_state.exposed.contains(&alloc_id) {
None
} else {
Some(alloc_id)
}
})
}

pub fn expose_addr(ecx: &MiriEvalContext<'mir, 'tcx>, alloc_id: AllocId) {
Expand Down

0 comments on commit d766294

Please sign in to comment.