@@ -95,7 +95,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
95
95
/// to ZSTs (where pointers may dangle), we keep track of the size even for allocations
96
96
/// that do not exist any more.
97
97
// FIXME: this should not be public, but interning currently needs access to it
98
- pub ( super ) dead_alloc_map : FxHashMap < AllocId , ( Size , Align ) > ,
98
+ pub ( super ) dead_alloc_map : FxHashMap < AllocId , MemoryPosition > ,
99
99
100
100
/// Extra data added by the machine.
101
101
pub extra : M :: MemoryExtra ,
@@ -278,13 +278,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
278
278
}
279
279
280
280
// Let the machine take some extra action
281
- let size = alloc. mem_pos . size ;
282
- AllocationExtra :: memory_deallocated ( & mut alloc, ptr, size) ?;
281
+ AllocationExtra :: memory_deallocated ( & mut alloc, ptr, bytes_mem_pos. size ) ?;
283
282
284
283
// Don't forget to remember size and align of this now-dead allocation
285
284
let old = self . dead_alloc_map . insert (
286
285
ptr. alloc_id ,
287
- ( alloc . mem_pos . size , alloc . mem_pos . align )
286
+ bytes_mem_pos
288
287
) ;
289
288
if old. is_some ( ) {
290
289
bug ! ( "Nothing can be deallocated twice" ) ;
@@ -364,8 +363,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
364
363
None
365
364
}
366
365
Err ( ptr) => {
367
- let ( allocation_size , alloc_align ) =
366
+ let alloc_mem_pos =
368
367
self . get_size_and_align ( ptr. alloc_id , AllocCheck :: Dereferencable ) ?;
368
+ let ( allocation_size, alloc_align) = ( alloc_mem_pos. size , alloc_mem_pos. align ) ;
369
369
// Test bounds. This also ensures non-NULL.
370
370
// It is sufficient to check this for the end pointer. The addition
371
371
// checks for overflow.
@@ -400,9 +400,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
400
400
& self ,
401
401
ptr : Pointer < M :: PointerTag > ,
402
402
) -> bool {
403
- let ( size , _align ) = self . get_size_and_align ( ptr. alloc_id , AllocCheck :: MaybeDead )
403
+ let mem_pos = self . get_size_and_align ( ptr. alloc_id , AllocCheck :: MaybeDead )
404
404
. expect ( "alloc info with MaybeDead cannot fail" ) ;
405
- ptr. check_inbounds_alloc ( size, CheckInAllocMsg :: NullPointerTest ) . is_err ( )
405
+ ptr. check_inbounds_alloc ( mem_pos . size , CheckInAllocMsg :: NullPointerTest ) . is_err ( )
406
406
}
407
407
}
408
408
@@ -557,13 +557,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
557
557
& self ,
558
558
id : AllocId ,
559
559
liveness : AllocCheck ,
560
- ) -> InterpResult < ' static , ( Size , Align ) > {
560
+ ) -> InterpResult < ' static , MemoryPosition > {
561
561
// # Regular allocations
562
562
// Don't use `self.get_raw` here as that will
563
563
// a) cause cycles in case `id` refers to a static
564
564
// b) duplicate a static's allocation in miri
565
565
if let Some ( ( _, alloc) ) = self . alloc_map . get ( id) {
566
- return Ok ( ( alloc. mem_pos . size , alloc . mem_pos . align ) ) ;
566
+ return Ok ( alloc. mem_pos ) ;
567
567
}
568
568
569
569
// # Function pointers
@@ -573,7 +573,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
573
573
// The caller requested no function pointers.
574
574
throw_unsup ! ( DerefFunctionPointer )
575
575
} else {
576
- Ok ( ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
576
+ Ok ( MemoryPosition :: new ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
577
577
} ;
578
578
}
579
579
@@ -586,12 +586,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
586
586
// Use size and align of the type.
587
587
let ty = self . tcx . type_of ( did) ;
588
588
let layout = self . tcx . layout_of ( ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) ;
589
- Ok ( ( layout. pref_pos . size , layout . pref_pos . align . abi ) )
589
+ Ok ( layout. pref_pos . mem_pos ( ) )
590
590
} ,
591
591
Some ( GlobalAlloc :: Memory ( alloc) ) =>
592
592
// Need to duplicate the logic here, because the global allocations have
593
593
// different associated types than the interpreter-local ones.
594
- Ok ( ( alloc. mem_pos . size , alloc . mem_pos . align ) ) ,
594
+ Ok ( alloc. mem_pos ) ,
595
595
Some ( GlobalAlloc :: Function ( _) ) =>
596
596
bug ! ( "We already checked function pointers above" ) ,
597
597
// The rest must be dead.
0 commit comments