diff options
| author | Ralf Jung <post@ralfj.de> | 2025-03-12 18:06:50 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-12 18:06:50 +0000 |
| commit | a004c12a7b0b35b9dfd69decd90d2e282d7e7c20 (patch) | |
| tree | 49a6782eba45fd28e6fbd4d8828d75495aec46d8 /src | |
| parent | fe5235ee0f90f41d6a10cc68e4f1adc3fed45235 (diff) | |
| parent | 0346e926a805a338754a192714cd7f11b29ba816 (diff) | |
| download | rust-a004c12a7b0b35b9dfd69decd90d2e282d7e7c20.tar.gz rust-a004c12a7b0b35b9dfd69decd90d2e282d7e7c20.zip | |
Merge pull request #4225 from RalfJung/alloc_addresses
alloc_addresses: use MemoryKind instead of tcx query to determine global allocations
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/miri/src/alloc_addresses/mod.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/tools/miri/src/alloc_addresses/mod.rs b/src/tools/miri/src/alloc_addresses/mod.rs index ff3a25e94bd..26d71dca360 100644 --- a/src/tools/miri/src/alloc_addresses/mod.rs +++ b/src/tools/miri/src/alloc_addresses/mod.rs @@ -170,20 +170,22 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { // This ensures the interpreted program and native code have the same view of memory. let base_ptr = match info.kind { AllocKind::LiveData => { - if this.tcx.try_get_global_alloc(alloc_id).is_some() { + if memory_kind == MiriMemoryKind::Global.into() { // For new global allocations, we always pre-allocate the memory to be able use the machine address directly. let prepared_bytes = MiriAllocBytes::zeroed(info.size, info.align) .unwrap_or_else(|| { panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes", size = info.size) }); let ptr = prepared_bytes.as_ptr(); - // Store prepared allocation space to be picked up for use later. + // Store prepared allocation to be picked up for use later. global_state .prepared_alloc_bytes .try_insert(alloc_id, prepared_bytes) .unwrap(); ptr } else { + // Non-global allocations are already in memory at this point so + // we can just get a pointer to where their data is stored. this.get_alloc_bytes_unchecked_raw(alloc_id)? } } @@ -382,6 +384,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { align: Align, ) -> InterpResult<'tcx, MiriAllocBytes> { let this = self.eval_context_ref(); + assert!(this.tcx.try_get_global_alloc(id).is_some()); if this.machine.native_lib.is_some() { // In native lib mode, MiriAllocBytes for global allocations are handled via `prepared_alloc_bytes`. // This additional call ensures that some `MiriAllocBytes` are always prepared, just in case |
