diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-06 03:28:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-06 03:28:12 +0100 |
| commit | 76311a8db9708a016c713dcd71ec8de4153b1491 (patch) | |
| tree | 1dfe68d63634bdbd5ff2079e359a4908e46c9903 | |
| parent | f5c54896b9ff6bd62ffd3c8b9d2b2c4e7461d380 (diff) | |
| parent | b4dde363446e29005331b9ac295d07d12c89d458 (diff) | |
| download | rust-76311a8db9708a016c713dcd71ec8de4153b1491.tar.gz rust-76311a8db9708a016c713dcd71ec8de4153b1491.zip | |
Rollup merge of #66081 - RalfJung:ptr-offset, r=zackmdavis
let caller of check_ptr_access_align control the error message This is needed for https://github.com/rust-lang/miri/pull/1031
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/validity.rs | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index d113ee33162..47b91824833 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { align: Align, ) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> { let align = if M::CHECK_ALIGN { Some(align) } else { None }; - self.check_ptr_access_align(sptr, size, align) + self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest) } /// Like `check_ptr_access`, but *definitely* checks alignment when `align` - /// is `Some` (overriding `M::CHECK_ALIGN`). - pub(super) fn check_ptr_access_align( + /// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control + /// the error message for the out-of-bounds case. + pub fn check_ptr_access_align( &self, sptr: Scalar<M::PointerTag>, size: Size, align: Option<Align>, + msg: CheckInAllocMsg, ) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> { fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> { if offset % align.bytes() == 0 { @@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // It is sufficient to check this for the end pointer. The addition // checks for overflow. let end_ptr = ptr.offset(size, self)?; - end_ptr.check_inbounds_alloc(allocation_size, CheckInAllocMsg::MemoryAccessTest)?; + end_ptr.check_inbounds_alloc(allocation_size, msg)?; // Test align. Check this last; if both bounds and alignment are violated // we want the error to be about the bounds. if let Some(align) = align { diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 3444fb60f33..82b8b28d72b 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet; use std::hash::Hash; use super::{ - GlobalAlloc, InterpResult, + GlobalAlloc, InterpResult, CheckInAllocMsg, Scalar, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy, }; @@ -424,7 +424,12 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> // alignment should take attributes into account). .unwrap_or_else(|| (layout.size, layout.align.abi)); let ptr: Option<_> = match - self.ecx.memory.check_ptr_access_align(ptr, size, Some(align)) + self.ecx.memory.check_ptr_access_align( + ptr, + size, + Some(align), + CheckInAllocMsg::InboundsTest, + ) { Ok(ptr) => ptr, Err(err) => { |
