From 21b1bd69b0fcd4861aad98ed2fef37a71cb70850 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 3 Jun 2019 17:49:14 +0200 Subject: [PATCH] Prevent cyclic locks of `alloc_map` --- src/librustc_mir/interpret/memory.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index a78c5a64894b..ff33dccdfeaf 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -453,8 +453,11 @@ pub fn get_size_and_align( if let Ok(alloc) = self.get(id) { return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align)); } + // can't do this in the match argument, we may get cycle errors since the lock would get + // dropped after the match. + let alloc = self.tcx.alloc_map.lock().get(id); // Could also be a fn ptr or extern static - match self.tcx.alloc_map.lock().get(id) { + match alloc { Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())), // `self.get` would also work, but can cause cycles if a static refers to itself Some(GlobalAlloc::Static(did)) => {