Skip to content

Commit 796e7a8

Browse files
committed
Address review comments
1 parent 3bc1d01 commit 796e7a8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/librustc_mir/interpret/memory.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
541541
match self.alloc_map.get_or(id, || Err(())) {
542542
Ok((_, alloc)) => Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)),
543543
Err(()) => {
544+
// Not a local allocation, check the global `tcx.alloc_map`.
545+
544546
// Can't do this in the match argument, we may get cycle errors since the lock would
545547
// be held throughout the match.
546548
let alloc = self.tcx.alloc_map.lock().get(id);
@@ -549,20 +551,22 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
549551
// Use size and align of the type
550552
let ty = self.tcx.type_of(did);
551553
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
552-
return Ok((layout.size, layout.align.abi));
554+
Ok((layout.size, layout.align.abi))
553555
},
554556
Some(GlobalAlloc::Memory(alloc)) =>
555557
// Need to duplicate the logic here, because the global allocations have
556558
// different associated types than the interpreter-local ones
557559
Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)),
558-
Some(GlobalAlloc::Function(_)) => if let AllocCheck::Dereferencable = liveness {
559-
// The caller requested no function pointers.
560-
return err!(DerefFunctionPointer);
561-
} else {
562-
return Ok((Size::ZERO, Align::from_bytes(1).unwrap()));
560+
Some(GlobalAlloc::Function(_)) => {
561+
if let AllocCheck::Dereferencable = liveness {
562+
// The caller requested no function pointers.
563+
err!(DerefFunctionPointer)
564+
} else {
565+
Ok((Size::ZERO, Align::from_bytes(1).unwrap()))
566+
}
563567
},
564568
// The rest must be dead.
565-
None => return if let AllocCheck::MaybeDead = liveness {
569+
None => if let AllocCheck::MaybeDead = liveness {
566570
// Deallocated pointers are allowed, we should be able to find
567571
// them in the map.
568572
Ok(*self.dead_alloc_map.get(&id)

0 commit comments

Comments
 (0)