]> git.lizzy.rs Git - rust.git/commitdiff
Improve miri's error reporting in check_in_alloc
authorLooMaclin <loo.maclin@protonmail.com>
Tue, 9 Apr 2019 09:38:14 +0000 (12:38 +0300)
committerLooMaclin <loo.maclin@protonmail.com>
Tue, 9 Apr 2019 09:38:14 +0000 (12:38 +0300)
src/librustc/mir/interpret/allocation.rs
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/interpret/memory.rs

index 19f28b96c3a70d48fb87e27dffed374d264bd42b..61f77171ce354561cfbd551771f6da4c71421156 100644 (file)
@@ -224,12 +224,11 @@ pub fn get_bytes<MemoryExtra>(
         cx: &impl HasDataLayout,
         ptr: Pointer<Tag>,
         size: Size,
-        msg: CheckInAllocMsg,
     ) -> EvalResult<'tcx, &[u8]>
         // FIXME: Working around https://github.com/rust-lang/rust/issues/56209
         where Extra: AllocationExtra<Tag, MemoryExtra>
     {
-        self.get_bytes_internal(cx, ptr, size, true, msg)
+        self.get_bytes_internal(cx, ptr, size, true, CheckInAllocMsg::MemoryAccess)
     }
 
     /// It is the caller's responsibility to handle undefined and pointer bytes.
@@ -295,7 +294,7 @@ pub fn read_c_str<MemoryExtra>(
                 // Go through `get_bytes` for checks and AllocationExtra hooks.
                 // We read the null, so we include it in the request, but we want it removed
                 // from the result!
-                Ok(&self.get_bytes(cx, ptr, size_with_null, CheckInAllocMsg::NullPointer)?[..size])
+                Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
             }
             None => err!(UnterminatedCString(ptr.erase_tag())),
         }
@@ -379,7 +378,7 @@ pub fn read_scalar<MemoryExtra>(
     {
         // get_bytes_unchecked tests relocation edges
         let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size,
-                                                      CheckInAllocMsg::PointerArithmetic)?;
+                                                      CheckInAllocMsg::MemoryAccess)?;
         // 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() {
@@ -456,7 +455,7 @@ pub fn write_scalar<MemoryExtra>(
         };
 
         let endian = cx.data_layout().endian;
-        let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::PointerArithmetic)?;
+        let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::MemoryAccess)?;
         write_target_uint(endian, dst, bytes).unwrap();
 
         // See if we have to also write a relocation
index 1e2ffa5db440b41fa181df41baed7c3bac746bef..303ffcb3bfb3ab653a5d17137982f0c59bb8add8 100644 (file)
 use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size};
 
 use rustc::mir::Field;
-use rustc::mir::interpret::{ConstValue, Scalar, truncate, CheckInAllocMsg};
+use rustc::mir::interpret::{ConstValue, Scalar, truncate};
 use rustc::util::common::ErrorReported;
 
 use syntax::attr::{SignedInt, UnsignedInt};
@@ -1418,8 +1418,7 @@ fn slice_pat_covered_by_const<'tcx>(
                 return Ok(false);
             }
             let n = n.assert_usize(tcx).unwrap();
-            alloc.get_bytes(&tcx, ptr, Size::from_bytes(n),
-                            CheckInAllocMsg::OutOfBounds).unwrap()
+            alloc.get_bytes(&tcx, ptr, Size::from_bytes(n)).unwrap()
         },
         // a slice fat pointer to a zero length slice
         (ConstValue::Slice(Scalar::Bits { .. }, 0), ty::Slice(t)) => {
@@ -1444,7 +1443,7 @@ fn slice_pat_covered_by_const<'tcx>(
             tcx.alloc_map
                 .lock()
                 .unwrap_memory(ptr.alloc_id)
-                .get_bytes(&tcx, ptr, Size::from_bytes(n), CheckInAllocMsg::OutOfBounds)
+                .get_bytes(&tcx, ptr, Size::from_bytes(n))
                 .unwrap()
         },
         _ => bug!(
index cc8bed770c460680a18ac47b4940ef85aecffc32..b9e2b9d499e551472cd8116e94e13ed91d23925c 100644 (file)
@@ -606,7 +606,7 @@ pub fn read_bytes(
             Ok(&[])
         } else {
             let ptr = ptr.to_ptr()?;
-            self.get(ptr.alloc_id)?.get_bytes(self, ptr, size, CheckInAllocMsg::MemoryAccess)
+            self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
         }
     }
 }