about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-12 08:35:32 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-24 11:36:31 +0100
commitd98c46ce57d562ebcfb01ec814ff8d90d47ff7ea (patch)
tree2e4ba7e63f3c751c885c61513eace34f8e39d322 /src/librustc
parenteb30ce8acb6617fbe6182a3b5b9078dea4027a90 (diff)
downloadrust-d98c46ce57d562ebcfb01ec814ff8d90d47ff7ea.tar.gz
rust-d98c46ce57d562ebcfb01ec814ff8d90d47ff7ea.zip
Move undef mask methods from `Memory` to `Allocation`
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/mir/interpret/allocation.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index 2334ca2f91a..ad4bf415b8d 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -206,6 +206,39 @@ impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
     }
 }
 
+
+/// Undefined bytes
+impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
+    /// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
+    /// error which will report the first byte which is undefined.
+    #[inline]
+    fn check_defined(&self, ptr: Pointer<M::PointerTag>, size: Size) -> EvalResult<'tcx> {
+        let alloc = self.get(ptr.alloc_id)?;
+        alloc.undef_mask.is_range_defined(
+            ptr.offset,
+            ptr.offset + size,
+        ).or_else(|idx| err!(ReadUndefBytes(idx)))
+    }
+
+    pub fn mark_definedness(
+        &mut self,
+        ptr: Pointer<M::PointerTag>,
+        size: Size,
+        new_state: bool,
+    ) -> EvalResult<'tcx> {
+        if size.bytes() == 0 {
+            return Ok(());
+        }
+        let alloc = self.get_mut(ptr.alloc_id)?;
+        alloc.undef_mask.set_range(
+            ptr.offset,
+            ptr.offset + size,
+            new_state,
+        );
+        Ok(())
+    }
+}
+
 pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
     /// Hook for performing extra checks on a memory read access.
     ///