From d766294a6d2351587451b84dca2bdebf7f0bbd3f Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:07:37 -0500 Subject: [PATCH] Address some review nits --- src/helpers.rs | 7 +------ src/intptrcast.rs | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 281c51e390..1d80cdd1bb 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -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(); } } diff --git a/src/intptrcast.rs b/src/intptrcast.rs index 2a24de333a..60cfca5425 100644 --- a/src/intptrcast.rs +++ b/src/intptrcast.rs @@ -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`, @@ -76,13 +68,12 @@ 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 { @@ -90,6 +81,13 @@ impl<'mir, 'tcx> GlobalStateInner { } } } + .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) {