diff options
Diffstat (limited to 'src/librustc/mir/interpret')
| -rw-r--r-- | src/librustc/mir/interpret/allocation.rs | 33 |
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. /// |
