From d98c46ce57d562ebcfb01ec814ff8d90d47ff7ea Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Mon, 12 Nov 2018 08:35:32 +0100 Subject: Move undef mask methods from `Memory` to `Allocation` --- src/librustc/mir/interpret/allocation.rs | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/librustc') 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 { } } + +/// Undefined bytes +impl<'tcx, Tag, Extra> Allocation { + /// 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, 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, + 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: ::std::fmt::Debug + Default + Clone { /// Hook for performing extra checks on a memory read access. /// -- cgit 1.4.1-3-g733a5