Skip to content

Commit b3e8087

Browse files
committed
interpret: pass MemoryKind to adjust_alloc_base_pointer
1 parent 10b6685 commit b3e8087

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/alloc_addresses/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
141141
}
142142
}
143143

144-
fn addr_from_alloc_id(&self, alloc_id: AllocId) -> InterpResult<'tcx, u64> {
144+
fn addr_from_alloc_id(
145+
&self,
146+
alloc_id: AllocId,
147+
_kind: MemoryKind,
148+
) -> InterpResult<'tcx, u64> {
145149
let ecx = self.eval_context_ref();
146150
let mut global_state = ecx.machine.alloc_addresses.borrow_mut();
147151
let global_state = &mut *global_state;
@@ -283,16 +287,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
283287
}
284288

285289
/// Convert a relative (tcx) pointer to a Miri pointer.
286-
fn ptr_from_rel_ptr(
290+
fn adjust_alloc_base_pointer(
287291
&self,
288292
ptr: Pointer<CtfeProvenance>,
289293
tag: BorTag,
294+
kind: MemoryKind,
290295
) -> InterpResult<'tcx, Pointer<Provenance>> {
291296
let ecx = self.eval_context_ref();
292297

293298
let (prov, offset) = ptr.into_parts(); // offset is relative (AllocId provenance)
294299
let alloc_id = prov.alloc_id();
295-
let base_addr = ecx.addr_from_alloc_id(alloc_id)?;
300+
let base_addr = ecx.addr_from_alloc_id(alloc_id, kind)?;
296301

297302
// Add offset with the right kind of pointer-overflowing arithmetic.
298303
let dl = ecx.data_layout();
@@ -314,9 +319,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
314319
ecx.alloc_id_from_addr(addr.bytes())?
315320
};
316321

317-
// This cannot fail: since we already have a pointer with that provenance, rel_ptr_to_addr
322+
// This cannot fail: since we already have a pointer with that provenance, adjust_alloc_base_pointer
318323
// must have been called in the past, so we can just look up the address in the map.
319-
let base_addr = ecx.addr_from_alloc_id(alloc_id).unwrap();
324+
let base_addr = *ecx.machine.alloc_addresses.borrow().base_addr.get(&alloc_id).unwrap();
320325

321326
// Wrapping "addr - base_addr"
322327
#[allow(clippy::cast_possible_wrap)] // we want to wrap here

src/machine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
10901090
alloc: Cow<'b, Allocation>,
10911091
kind: Option<MemoryKind>,
10921092
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra>>> {
1093-
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
1093+
let kind = kind.expect("we set our GLOBAL_KIND so this cannot be None");
10941094
if ecx.machine.tracked_alloc_ids.contains(&id) {
10951095
ecx.emit_diagnostic(NonHaltingDiagnostic::CreatedAlloc(
10961096
id,
@@ -1151,7 +1151,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11511151
fn adjust_alloc_base_pointer(
11521152
ecx: &MiriInterpCx<'mir, 'tcx>,
11531153
ptr: Pointer<CtfeProvenance>,
1154+
kind: Option<MemoryKind>,
11541155
) -> InterpResult<'tcx, Pointer<Provenance>> {
1156+
let kind = kind.expect("we set our GLOBAL_KIND so this cannot be None");
11551157
let alloc_id = ptr.provenance.alloc_id();
11561158
if cfg!(debug_assertions) {
11571159
// The machine promises to never call us on thread-local or extern statics.
@@ -1172,7 +1174,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
11721174
// Value does not matter, SB is disabled
11731175
BorTag::default()
11741176
};
1175-
ecx.ptr_from_rel_ptr(ptr, tag)
1177+
ecx.adjust_alloc_base_pointer(ptr, tag, kind)
11761178
}
11771179

11781180
/// Called on `usize as ptr` casts.

0 commit comments

Comments
 (0)