Skip to content

Commit 30a9626

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

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,11 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
239239
cx: &impl HasDataLayout,
240240
ptr: Pointer<Tag>,
241241
size: Size,
242-
msg: CheckInAllocMsg,
243242
) -> EvalResult<'tcx, &[u8]>
244243
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
245244
where Extra: AllocationExtra<Tag, MemoryExtra>
246245
{
247-
self.get_bytes_internal(cx, ptr, size, false, msg)
246+
self.get_bytes_internal(cx, ptr, size, false, CheckInAllocMsg::MemoryAccess)
248247
}
249248

250249
/// Just calling this already marks everything as defined and removes relocations,
@@ -254,13 +253,12 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
254253
cx: &impl HasDataLayout,
255254
ptr: Pointer<Tag>,
256255
size: Size,
257-
msg: CheckInAllocMsg,
258256
) -> EvalResult<'tcx, &mut [u8]>
259257
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
260258
where Extra: AllocationExtra<Tag, MemoryExtra>
261259
{
262260
assert_ne!(size.bytes(), 0, "0-sized accesses should never even get a `Pointer`");
263-
self.check_bounds(cx, ptr, size, msg)?;
261+
self.check_bounds(cx, ptr, size, CheckInAllocMsg::MemoryAccess)?;
264262

265263
self.mark_definedness(ptr, size, true)?;
266264
self.clear_relocations(cx, ptr, size)?;
@@ -314,7 +312,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
314312
where Extra: AllocationExtra<Tag, MemoryExtra>
315313
{
316314
// Check bounds and relocations on the edges
317-
self.get_bytes_with_undef_and_ptr(cx, ptr, size, CheckInAllocMsg::OutOfBounds)?;
315+
self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
318316
// Check undef and ptr
319317
if !allow_ptr_and_undef {
320318
self.check_defined(ptr, size)?;
@@ -335,8 +333,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
335333
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
336334
where Extra: AllocationExtra<Tag, MemoryExtra>
337335
{
338-
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64),
339-
CheckInAllocMsg::MemoryAccess)?;
336+
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64))?;
340337
bytes.clone_from_slice(src);
341338
Ok(())
342339
}
@@ -352,7 +349,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
352349
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
353350
where Extra: AllocationExtra<Tag, MemoryExtra>
354351
{
355-
let bytes = self.get_bytes_mut(cx, ptr, count, CheckInAllocMsg::MemoryAccess)?;
352+
let bytes = self.get_bytes_mut(cx, ptr, count)?;
356353
for b in bytes {
357354
*b = val;
358355
}
@@ -377,8 +374,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
377374
where Extra: AllocationExtra<Tag, MemoryExtra>
378375
{
379376
// get_bytes_unchecked tests relocation edges
380-
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size,
381-
CheckInAllocMsg::MemoryAccess)?;
377+
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
382378
// Undef check happens *after* we established that the alignment is correct.
383379
// We must not return Ok() for unaligned pointers!
384380
if self.check_defined(ptr, size).is_err() {
@@ -455,7 +451,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
455451
};
456452

457453
let endian = cx.data_layout().endian;
458-
let dst = self.get_bytes_mut(cx, ptr, type_size, CheckInAllocMsg::MemoryAccess)?;
454+
let dst = self.get_bytes_mut(cx, ptr, type_size)?;
459455
write_target_uint(endian, dst, bytes).unwrap();
460456

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

src/librustc_mir/interpret/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
731731

732732
// This checks relocation edges on the src.
733733
let src_bytes = self.get(src.alloc_id)?
734-
.get_bytes_with_undef_and_ptr(&tcx, src, size, CheckInAllocMsg::MemoryAccess)?
734+
.get_bytes_with_undef_and_ptr(&tcx, src, size)?
735735
.as_ptr();
736736
let dest_bytes = self.get_mut(dest.alloc_id)?
737-
.get_bytes_mut(&tcx, dest, size * length, CheckInAllocMsg::MemoryAccess)?
737+
.get_bytes_mut(&tcx, dest, size * length)?
738738
.as_mut_ptr();
739739

740740
// SAFE: The above indexing would have panicked if there weren't at least `size` bytes

0 commit comments

Comments
 (0)