diff options
| author | LooMaclin <loo.maclin@protonmail.com> | 2019-04-10 04:18:19 +0300 |
|---|---|---|
| committer | LooMaclin <loo.maclin@protonmail.com> | 2019-04-10 04:18:19 +0300 |
| commit | 30a96267a6050c55e1f2bb1c540458a88fdb9567 (patch) | |
| tree | eca251f0010dd28c92127b8ff63e0ce7e52115df | |
| parent | 9147e26fcb8d0f140d5c7f97a6063758ff5aeac4 (diff) | |
| download | rust-30a96267a6050c55e1f2bb1c540458a88fdb9567.tar.gz rust-30a96267a6050c55e1f2bb1c540458a88fdb9567.zip | |
Improve miri's error reporting in check_in_alloc
| -rw-r--r-- | src/librustc/mir/interpret/allocation.rs | 18 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 4 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs index 61f77171ce3..433c105231e 100644 --- a/src/librustc/mir/interpret/allocation.rs +++ b/src/librustc/mir/interpret/allocation.rs @@ -239,12 +239,11 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { 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, false, msg) + self.get_bytes_internal(cx, ptr, size, false, CheckInAllocMsg::MemoryAccess) } /// Just calling this already marks everything as defined and removes relocations, @@ -254,13 +253,12 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { cx: &impl HasDataLayout, ptr: Pointer<Tag>, size: Size, - msg: CheckInAllocMsg, ) -> EvalResult<'tcx, &mut [u8]> // FIXME: Working around https://github.com/rust-lang/rust/issues/56209 where Extra: AllocationExtra<Tag, MemoryExtra> { assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`"); - self.check_bounds(cx, ptr, size, msg)?; + self.check_bounds(cx, ptr, size, CheckInAllocMsg::MemoryAccess)?; self.mark_definedness(ptr, size, true)?; self.clear_relocations(cx, ptr, size)?; @@ -314,7 +312,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { where Extra: AllocationExtra<Tag, MemoryExtra> { // Check bounds and relocations on the edges - self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::OutOfBounds)?; + self.get_bytes_with_undef_and_ptr(cx, ptr, size)?; // Check undef and ptr if !allow_ptr_and_undef { self.check_defined(ptr, size)?; @@ -335,8 +333,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { // FIXME: Working around https://github.com/rust-lang/rust/issues/56209 where Extra: AllocationExtra<Tag, MemoryExtra> { - let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64), - CheckInAllocMsg::MemoryAccess)?; + let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64))?; bytes.clone_from_slice(src); Ok(()) } @@ -352,7 +349,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { // FIXME: Working around https://github.com/rust-lang/rust/issues/56209 where Extra: AllocationExtra<Tag, MemoryExtra> { - let bytes = self.get_bytes_mut(cx, ptr, count, CheckInAllocMsg::MemoryAccess)?; + let bytes = self.get_bytes_mut(cx, ptr, count)?; for b in bytes { *b = val; } @@ -377,8 +374,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { where Extra: AllocationExtra<Tag, MemoryExtra> { // get_bytes_unchecked tests relocation edges - let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size, - CheckInAllocMsg::MemoryAccess)?; + 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() { @@ -455,7 +451,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> { }; let endian = cx.data_layout().endian; - let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::MemoryAccess)?; + let dst = self.get_bytes_mut(cx, ptr, type_size)?; write_target_uint(endian, dst, bytes).unwrap(); // See if we have to also write a relocation diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index b9e2b9d499e..e8ae7ab579b 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -731,10 +731,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { // This checks relocation edges on the src. let src_bytes = self.get(src.alloc_id)? - .get_bytes_with_undef_and_ptr(&tcx, src, size, CheckInAllocMsg::MemoryAccess)? + .get_bytes_with_undef_and_ptr(&tcx, src, size)? .as_ptr(); let dest_bytes = self.get_mut(dest.alloc_id)? - .get_bytes_mut(&tcx, dest, size * length, CheckInAllocMsg::MemoryAccess)? + .get_bytes_mut(&tcx, dest, size * length)? .as_mut_ptr(); // SAFE: The above indexing would have panicked if there weren't at least `size` bytes |
