about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-06-03 17:49:14 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-06-19 09:52:35 +0200
commit21b1bd69b0fcd4861aad98ed2fef37a71cb70850 (patch)
treee3799223b3fa01381123a9d0e7e82662eb3903a3
parent4b6f3868b3e1bdb5193cc240664f046bc18ca6a4 (diff)
downloadrust-21b1bd69b0fcd4861aad98ed2fef37a71cb70850.tar.gz
rust-21b1bd69b0fcd4861aad98ed2fef37a71cb70850.zip
Prevent cyclic locks of `alloc_map`
-rw-r--r--src/librustc_mir/interpret/memory.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs
index a78c5a64894..ff33dccdfea 100644
--- a/src/librustc_mir/interpret/memory.rs
+++ b/src/librustc_mir/interpret/memory.rs
@@ -453,8 +453,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
         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)) => {