about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-09-06 11:36:50 +0000
committerbors <bors@rust-lang.org>2019-09-06 11:36:50 +0000
commit4894123d21ed4b153a2e5c32c0870cb2d97f9b46 (patch)
treeb59ff1cc43012f6cebd0ecd61b0b0b534fe4ec44 /src/librustc
parent1fb3c4ec7ca37d33bd1e68cce669d171c2752615 (diff)
parent39bfb3626c04fe03d50864e13a6baeed1c0378f4 (diff)
downloadrust-4894123d21ed4b153a2e5c32c0870cb2d97f9b46.tar.gz
rust-4894123d21ed4b153a2e5c32c0870cb2d97f9b46.zip
Auto merge of #64211 - oli-obk:miri, r=eddyb
Fix miri

fixes  #64109

cc @HeroicKatora
cc @RalfJung
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/mir/interpret/allocation.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index df1d9a98701..13552a61acb 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -130,6 +130,34 @@ impl<Tag> Allocation<Tag> {
     }
 }
 
+impl Allocation<()> {
+    /// Add Tag and Extra fields
+    pub fn retag<T, E>(
+        self,
+        mut tagger: impl FnMut(AllocId) -> T,
+        extra: E,
+    ) -> Allocation<T, E> {
+        Allocation {
+            bytes: self.bytes,
+            size: self.size,
+            relocations: Relocations::from_presorted(
+                self.relocations.iter()
+                    // The allocations in the relocations (pointers stored *inside* this allocation)
+                    // all get the base pointer tag.
+                    .map(|&(offset, ((), alloc))| {
+                        let tag = tagger(alloc);
+                        (offset, (tag, alloc))
+                    })
+                    .collect()
+            ),
+            undef_mask: self.undef_mask,
+            align: self.align,
+            mutability: self.mutability,
+            extra,
+        }
+    }
+}
+
 /// Raw accessors. Provide access to otherwise private bytes.
 impl<Tag, Extra> Allocation<Tag, Extra> {
     pub fn len(&self) -> usize {