Skip to content

Commit 9147e26

Browse files
committed
Improve miri's error reporting in check_in_alloc
1 parent 32ba4bd commit 9147e26

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,11 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
224224
cx: &impl HasDataLayout,
225225
ptr: Pointer<Tag>,
226226
size: Size,
227-
msg: CheckInAllocMsg,
228227
) -> EvalResult<'tcx, &[u8]>
229228
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
230229
where Extra: AllocationExtra<Tag, MemoryExtra>
231230
{
232-
self.get_bytes_internal(cx, ptr, size, true, msg)
231+
self.get_bytes_internal(cx, ptr, size, true, CheckInAllocMsg::MemoryAccess)
233232
}
234233

235234
/// It is the caller's responsibility to handle undefined and pointer bytes.
@@ -295,7 +294,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
295294
// Go through `get_bytes` for checks and AllocationExtra hooks.
296295
// We read the null, so we include it in the request, but we want it removed
297296
// from the result!
298-
Ok(&self.get_bytes(cx, ptr, size_with_null, CheckInAllocMsg::NullPointer)?[..size])
297+
Ok(&self.get_bytes(cx, ptr, size_with_null)?[..size])
299298
}
300299
None => err!(UnterminatedCString(ptr.erase_tag())),
301300
}
@@ -379,7 +378,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
379378
{
380379
// get_bytes_unchecked tests relocation edges
381380
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size,
382-
CheckInAllocMsg::PointerArithmetic)?;
381+
CheckInAllocMsg::MemoryAccess)?;
383382
// Undef check happens *after* we established that the alignment is correct.
384383
// We must not return Ok() for unaligned pointers!
385384
if self.check_defined(ptr, size).is_err() {
@@ -456,7 +455,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
456455
};
457456

458457
let endian = cx.data_layout().endian;
459-
let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::PointerArithmetic)?;
458+
let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::MemoryAccess)?;
460459
write_target_uint(endian, dst, bytes).unwrap();
461460

462461
// See if we have to also write a relocation

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ use rustc::ty::{self, Ty, TyCtxt, TypeFoldable, Const};
172172
use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size};
173173

174174
use rustc::mir::Field;
175-
use rustc::mir::interpret::{ConstValue, Scalar, truncate, CheckInAllocMsg};
175+
use rustc::mir::interpret::{ConstValue, Scalar, truncate};
176176
use rustc::util::common::ErrorReported;
177177

178178
use syntax::attr::{SignedInt, UnsignedInt};
@@ -1418,8 +1418,7 @@ fn slice_pat_covered_by_const<'tcx>(
14181418
return Ok(false);
14191419
}
14201420
let n = n.assert_usize(tcx).unwrap();
1421-
alloc.get_bytes(&tcx, ptr, Size::from_bytes(n),
1422-
CheckInAllocMsg::OutOfBounds).unwrap()
1421+
alloc.get_bytes(&tcx, ptr, Size::from_bytes(n)).unwrap()
14231422
},
14241423
// a slice fat pointer to a zero length slice
14251424
(ConstValue::Slice(Scalar::Bits { .. }, 0), ty::Slice(t)) => {
@@ -1444,7 +1443,7 @@ fn slice_pat_covered_by_const<'tcx>(
14441443
tcx.alloc_map
14451444
.lock()
14461445
.unwrap_memory(ptr.alloc_id)
1447-
.get_bytes(&tcx, ptr, Size::from_bytes(n), CheckInAllocMsg::OutOfBounds)
1446+
.get_bytes(&tcx, ptr, Size::from_bytes(n))
14481447
.unwrap()
14491448
},
14501449
_ => bug!(

src/librustc_mir/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
606606
Ok(&[])
607607
} else {
608608
let ptr = ptr.to_ptr()?;
609-
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size, CheckInAllocMsg::MemoryAccess)
609+
self.get(ptr.alloc_id)?.get_bytes(self, ptr, size)
610610
}
611611
}
612612
}

0 commit comments

Comments
 (0)