@@ -271,8 +271,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
271
271
/// Visits the memory covered by `place`, sensitive to freezing: the 2nd parameter
272
272
/// of `action` will be true if this is frozen, false if this is in an `UnsafeCell`.
273
273
/// The range is relative to `place`.
274
- ///
275
- /// Assumes that the `place` has a proper pointer in it.
276
274
fn visit_freeze_sensitive (
277
275
& self ,
278
276
place : & MPlaceTy < ' tcx , Tag > ,
@@ -290,33 +288,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
290
288
// Store how far we proceeded into the place so far. Everything to the left of
291
289
// this offset has already been handled, in the sense that the frozen parts
292
290
// have had `action` called on them.
293
- let ptr = place. ptr . into_pointer_or_addr ( ) . unwrap ( ) ;
294
- let start_offset = ptr. into_parts ( ) . 1 as Size ; // we just compare offsets, the abs. value never matters
295
- let mut cur_offset = start_offset;
291
+ let start_addr = place. ptr . addr ( ) ;
292
+ let mut cur_addr = start_addr;
296
293
// Called when we detected an `UnsafeCell` at the given offset and size.
297
294
// Calls `action` and advances `cur_ptr`.
298
- let mut unsafe_cell_action = |unsafe_cell_ptr : Pointer < Option < Tag > > ,
295
+ let mut unsafe_cell_action = |unsafe_cell_ptr : & Pointer < Option < Tag > > ,
299
296
unsafe_cell_size : Size | {
300
- let unsafe_cell_ptr = unsafe_cell_ptr. into_pointer_or_addr ( ) . unwrap ( ) ;
301
- debug_assert_eq ! ( unsafe_cell_ptr. provenance, ptr. provenance) ;
302
297
// We assume that we are given the fields in increasing offset order,
303
298
// and nothing else changes.
304
- let unsafe_cell_offset = unsafe_cell_ptr. into_parts ( ) . 1 as Size ; // we just compare offsets, the abs. value never matters
305
- assert ! ( unsafe_cell_offset >= cur_offset ) ;
306
- let frozen_size = unsafe_cell_offset - cur_offset ;
299
+ let unsafe_cell_addr = unsafe_cell_ptr. addr ( ) ;
300
+ assert ! ( unsafe_cell_addr >= cur_addr ) ;
301
+ let frozen_size = unsafe_cell_addr - cur_addr ;
307
302
// Everything between the cur_ptr and this `UnsafeCell` is frozen.
308
303
if frozen_size != Size :: ZERO {
309
- action ( alloc_range ( cur_offset - start_offset , frozen_size) , /*frozen*/ true ) ?;
304
+ action ( alloc_range ( cur_addr - start_addr , frozen_size) , /*frozen*/ true ) ?;
310
305
}
311
- cur_offset += frozen_size;
306
+ cur_addr += frozen_size;
312
307
// This `UnsafeCell` is NOT frozen.
313
308
if unsafe_cell_size != Size :: ZERO {
314
309
action (
315
- alloc_range ( cur_offset - start_offset , unsafe_cell_size) ,
310
+ alloc_range ( cur_addr - start_addr , unsafe_cell_size) ,
316
311
/*frozen*/ false ,
317
312
) ?;
318
313
}
319
- cur_offset += unsafe_cell_size;
314
+ cur_addr += unsafe_cell_size;
320
315
// Done
321
316
Ok ( ( ) )
322
317
} ;
@@ -334,7 +329,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
334
329
. unwrap_or_else ( || place. layout . size ) ;
335
330
// Now handle this `UnsafeCell`, unless it is empty.
336
331
if unsafe_cell_size != Size :: ZERO {
337
- unsafe_cell_action ( place. ptr , unsafe_cell_size)
332
+ unsafe_cell_action ( & place. ptr , unsafe_cell_size)
338
333
} else {
339
334
Ok ( ( ) )
340
335
}
@@ -344,7 +339,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
344
339
}
345
340
// The part between the end_ptr and the end of the place is also frozen.
346
341
// So pretend there is a 0-sized `UnsafeCell` at the end.
347
- unsafe_cell_action ( place. ptr . wrapping_offset ( size, this) , Size :: ZERO ) ?;
342
+ unsafe_cell_action ( & place. ptr . offset ( size, this) ? , Size :: ZERO ) ?;
348
343
// Done!
349
344
return Ok ( ( ) ) ;
350
345
@@ -428,9 +423,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
428
423
let mut places =
429
424
fields. collect :: < InterpResult < ' tcx , Vec < MPlaceTy < ' tcx , Tag > > > > ( ) ?;
430
425
// we just compare offsets, the abs. value never matters
431
- places. sort_by_key ( |place| {
432
- place. ptr . into_pointer_or_addr ( ) . unwrap ( ) . into_parts ( ) . 1 as Size
433
- } ) ;
426
+ places. sort_by_key ( |place| place. ptr . addr ( ) ) ;
434
427
self . walk_aggregate ( place, places. into_iter ( ) . map ( Ok ) )
435
428
}
436
429
FieldsShape :: Union { .. } | FieldsShape :: Primitive => {
@@ -777,6 +770,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
777
770
/// Mark a machine allocation that was just created as immutable.
778
771
fn mark_immutable ( & mut self , mplace : & MemPlace < Tag > ) {
779
772
let this = self . eval_context_mut ( ) ;
773
+ // This got just allocated, so there definitely is a pointer here.
780
774
this. alloc_mark_immutable ( mplace. ptr . into_pointer_or_addr ( ) . unwrap ( ) . provenance . alloc_id )
781
775
. unwrap ( ) ;
782
776
}
0 commit comments