Skip to content

Commit a004c12

Browse files
authored
Merge pull request #4225 from RalfJung/alloc_addresses
alloc_addresses: use MemoryKind instead of tcx query to determine global allocations
2 parents fe5235e + 0346e92 commit a004c12

File tree

1 file changed

+5
-2
lines changed
  • src/tools/miri/src/alloc_addresses

1 file changed

+5
-2
lines changed

src/tools/miri/src/alloc_addresses/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,22 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
170170
// This ensures the interpreted program and native code have the same view of memory.
171171
let base_ptr = match info.kind {
172172
AllocKind::LiveData => {
173-
if this.tcx.try_get_global_alloc(alloc_id).is_some() {
173+
if memory_kind == MiriMemoryKind::Global.into() {
174174
// For new global allocations, we always pre-allocate the memory to be able use the machine address directly.
175175
let prepared_bytes = MiriAllocBytes::zeroed(info.size, info.align)
176176
.unwrap_or_else(|| {
177177
panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes", size = info.size)
178178
});
179179
let ptr = prepared_bytes.as_ptr();
180-
// Store prepared allocation space to be picked up for use later.
180+
// Store prepared allocation to be picked up for use later.
181181
global_state
182182
.prepared_alloc_bytes
183183
.try_insert(alloc_id, prepared_bytes)
184184
.unwrap();
185185
ptr
186186
} else {
187+
// Non-global allocations are already in memory at this point so
188+
// we can just get a pointer to where their data is stored.
187189
this.get_alloc_bytes_unchecked_raw(alloc_id)?
188190
}
189191
}
@@ -382,6 +384,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
382384
align: Align,
383385
) -> InterpResult<'tcx, MiriAllocBytes> {
384386
let this = self.eval_context_ref();
387+
assert!(this.tcx.try_get_global_alloc(id).is_some());
385388
if this.machine.native_lib.is_some() {
386389
// In native lib mode, MiriAllocBytes for global allocations are handled via `prepared_alloc_bytes`.
387390
// This additional call ensures that some `MiriAllocBytes` are always prepared, just in case

0 commit comments

Comments
 (0)