Skip to content

Commit dd6a9ae

Browse files
committed
Address some review nits
1 parent 30d72f5 commit dd6a9ae

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

src/helpers.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -788,12 +788,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
788788
let this = self.eval_context_mut();
789789
// This got just allocated, so there definitely is a pointer here.
790790
let provenance = mplace.ptr.into_pointer_or_addr().unwrap().provenance;
791-
792-
if let Tag::Concrete(concrete) = provenance {
793-
this.alloc_mark_immutable(concrete.alloc_id).unwrap();
794-
} else {
795-
bug!("Machine allocation that was just created should have concrete provenance");
796-
}
791+
this.alloc_mark_immutable(provenance.get_alloc_id().unwrap()).unwrap();
797792
}
798793

799794
fn item_link_name(&self, def_id: DefId) -> Symbol {

src/intptrcast.rs

+14-16
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)