Skip to content

Commit 21b1bd6

Browse files
committed
Prevent cyclic locks of alloc_map
1 parent 4b6f386 commit 21b1bd6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/librustc_mir/interpret/memory.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
453453
if let Ok(alloc) = self.get(id) {
454454
return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align));
455455
}
456+
// can't do this in the match argument, we may get cycle errors since the lock would get
457+
// dropped after the match.
458+
let alloc = self.tcx.alloc_map.lock().get(id);
456459
// Could also be a fn ptr or extern static
457-
match self.tcx.alloc_map.lock().get(id) {
460+
match alloc {
458461
Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())),
459462
// `self.get` would also work, but can cause cycles if a static refers to itself
460463
Some(GlobalAlloc::Static(did)) => {

0 commit comments

Comments
 (0)