@@ -170,20 +170,22 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
170
170
// This ensures the interpreted program and native code have the same view of memory.
171
171
let base_ptr = match info. kind {
172
172
AllocKind :: LiveData => {
173
- if this . tcx . try_get_global_alloc ( alloc_id ) . is_some ( ) {
173
+ if memory_kind == MiriMemoryKind :: Global . into ( ) {
174
174
// For new global allocations, we always pre-allocate the memory to be able use the machine address directly.
175
175
let prepared_bytes = MiriAllocBytes :: zeroed ( info. size , info. align )
176
176
. unwrap_or_else ( || {
177
177
panic ! ( "Miri ran out of memory: cannot create allocation of {size:?} bytes" , size = info. size)
178
178
} ) ;
179
179
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.
181
181
global_state
182
182
. prepared_alloc_bytes
183
183
. try_insert ( alloc_id, prepared_bytes)
184
184
. unwrap ( ) ;
185
185
ptr
186
186
} 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.
187
189
this. get_alloc_bytes_unchecked_raw ( alloc_id) ?
188
190
}
189
191
}
@@ -382,6 +384,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
382
384
align : Align ,
383
385
) -> InterpResult < ' tcx , MiriAllocBytes > {
384
386
let this = self . eval_context_ref ( ) ;
387
+ assert ! ( this. tcx. try_get_global_alloc( id) . is_some( ) ) ;
385
388
if this. machine . native_lib . is_some ( ) {
386
389
// In native lib mode, MiriAllocBytes for global allocations are handled via `prepared_alloc_bytes`.
387
390
// This additional call ensures that some `MiriAllocBytes` are always prepared, just in case
0 commit comments