]> git.lizzy.rs Git - rust.git/commitdiff
avoid catching InterpError
authorRalf Jung <post@ralfj.de>
Tue, 24 Mar 2020 23:12:49 +0000 (00:12 +0100)
committerRalf Jung <post@ralfj.de>
Wed, 25 Mar 2020 23:16:05 +0000 (00:16 +0100)
src/librustc/mir/interpret/allocation.rs

index 26b9e1be2f5d4542d1896f3e77fe6098356c3b1e..ada02ceb5cbf3cc910d319039ef80e1ab628fa5c 100644 (file)
@@ -367,7 +367,7 @@ pub fn read_scalar(
         let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
         // Undef check happens *after* we established that the alignment is correct.
         // We must not return `Ok()` for unaligned pointers!
-        if self.check_defined(ptr, size).is_err() {
+        if self.is_defined(ptr, size).is_err() {
             // This inflates undefined bytes to the entire scalar, even if only a few
             // bytes are undefined.
             return Ok(ScalarMaybeUndef::Undef);
@@ -552,13 +552,19 @@ fn check_relocation_edges(
 }
 
 /// Undefined bytes.
-impl<'tcx, Tag, Extra> Allocation<Tag, Extra> {
+impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
+    /// Checks whether the given range  is entirely defined.
+    ///
+    /// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
+    /// at which the first undefined access begins.
+    fn is_defined(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Size> {
+        self.undef_mask.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
+    }
+
     /// 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<Tag>, size: Size) -> InterpResult<'tcx> {
-        self.undef_mask
-            .is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
+        self.is_defined(ptr, size)
             .or_else(|idx| throw_ub!(InvalidUndefBytes(Some(Pointer::new(ptr.alloc_id, idx)))))
     }