Skip to content

Commit d766294

Browse files
committed
Address some review nits
1 parent cd86199 commit d766294

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/helpers.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
772772
let this = self.eval_context_mut();
773773
// This got just allocated, so there definitely is a pointer here.
774774
let provenance = mplace.ptr.into_pointer_or_addr().unwrap().provenance;
775-
776-
if let Tag::Concrete(concrete) = provenance {
777-
this.alloc_mark_immutable(concrete.alloc_id).unwrap();
778-
} else {
779-
bug!("Machine allocation that was just created should have concrete provenance");
780-
}
775+
this.alloc_mark_immutable(provenance.get_alloc_id().unwrap()).unwrap();
781776
}
782777
}
783778

src/intptrcast.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ impl<'mir, 'tcx> GlobalStateInner {
5858
let pos = global_state.int_to_ptr_map.binary_search_by_key(&addr, |(addr, _)| *addr);
5959

6060
match pos {
61-
Ok(pos) => {
62-
let (_, alloc_id) = global_state.int_to_ptr_map[pos];
63-
64-
if !global_state.permissive_provenance || global_state.exposed.contains(&alloc_id) {
65-
Some(global_state.int_to_ptr_map[pos].1)
66-
} else {
67-
None
68-
}
69-
}
61+
Ok(pos) => Some(global_state.int_to_ptr_map[pos].1),
7062
Err(0) => None,
7163
Err(pos) => {
7264
// This is the largest of the adresses smaller than `int`,
@@ -76,20 +68,26 @@ impl<'mir, 'tcx> GlobalStateInner {
7668
let offset = addr - glb;
7769
// If the offset exceeds the size of the allocation, don't use this `alloc_id`.
7870

79-
if (!global_state.permissive_provenance || global_state.exposed.contains(&alloc_id))
80-
&& offset
81-
<= ecx
82-
.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)
83-
.unwrap()
84-
.0
85-
.bytes()
71+
if offset
72+
<= ecx
73+
.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)
74+
.unwrap()
75+
.0
76+
.bytes()
8677
{
8778
Some(alloc_id)
8879
} else {
8980
None
9081
}
9182
}
9283
}
84+
.and_then(|alloc_id| {
85+
if global_state.permissive_provenance && !global_state.exposed.contains(&alloc_id) {
86+
None
87+
} else {
88+
Some(alloc_id)
89+
}
90+
})
9391
}
9492

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

0 commit comments

Comments
 (0)