Skip to content

Commit 7c41628

Browse files
committed
Memory::dead_alloc_map
1 parent b1926e7 commit 7c41628

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct Memory<'mir, 'tcx, M: Machine<'mir, 'tcx>> {
9595
/// to ZSTs (where pointers may dangle), we keep track of the size even for allocations
9696
/// that do not exist any more.
9797
// 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>,
9999

100100
/// Extra data added by the machine.
101101
pub extra: M::MemoryExtra,
@@ -278,13 +278,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
278278
}
279279

280280
// 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)?;
283282

284283
// Don't forget to remember size and align of this now-dead allocation
285284
let old = self.dead_alloc_map.insert(
286285
ptr.alloc_id,
287-
(alloc.mem_pos.size, alloc.mem_pos.align)
286+
bytes_mem_pos
288287
);
289288
if old.is_some() {
290289
bug!("Nothing can be deallocated twice");
@@ -364,8 +363,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
364363
None
365364
}
366365
Err(ptr) => {
367-
let (allocation_size, alloc_align) =
366+
let alloc_mem_pos =
368367
self.get_size_and_align(ptr.alloc_id, AllocCheck::Dereferencable)?;
368+
let (allocation_size, alloc_align) = (alloc_mem_pos.size, alloc_mem_pos.align);
369369
// Test bounds. This also ensures non-NULL.
370370
// It is sufficient to check this for the end pointer. The addition
371371
// checks for overflow.
@@ -400,9 +400,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
400400
&self,
401401
ptr: Pointer<M::PointerTag>,
402402
) -> 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)
404404
.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()
406406
}
407407
}
408408

@@ -557,13 +557,13 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
557557
&self,
558558
id: AllocId,
559559
liveness: AllocCheck,
560-
) -> InterpResult<'static, (Size, Align)> {
560+
) -> InterpResult<'static, MemoryPosition> {
561561
// # Regular allocations
562562
// Don't use `self.get_raw` here as that will
563563
// a) cause cycles in case `id` refers to a static
564564
// b) duplicate a static's allocation in miri
565565
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);
567567
}
568568

569569
// # Function pointers
@@ -573,7 +573,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
573573
// The caller requested no function pointers.
574574
throw_unsup!(DerefFunctionPointer)
575575
} else {
576-
Ok((Size::ZERO, Align::from_bytes(1).unwrap()))
576+
Ok(MemoryPosition::new(Size::ZERO, Align::from_bytes(1).unwrap()))
577577
};
578578
}
579579

@@ -586,12 +586,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
586586
// Use size and align of the type.
587587
let ty = self.tcx.type_of(did);
588588
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())
590590
},
591591
Some(GlobalAlloc::Memory(alloc)) =>
592592
// Need to duplicate the logic here, because the global allocations have
593593
// different associated types than the interpreter-local ones.
594-
Ok((alloc.mem_pos.size, alloc.mem_pos.align)),
594+
Ok(alloc.mem_pos),
595595
Some(GlobalAlloc::Function(_)) =>
596596
bug!("We already checked function pointers above"),
597597
// The rest must be dead.

0 commit comments

Comments
 (0)