Skip to content

Commit 15d50de

Browse files
committed
Improve miri's error reporting in check_in_alloc
1 parent 0d97ad3 commit 15d50de

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ pub enum InboundsCheck {
2525
/// Used by `check_in_alloc` to indicate context of check
2626
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
2727
pub enum CheckInAllocMsg {
28-
MemoryAccess,
28+
MemoryAccessTest,
2929
NullPointerTest,
30-
PointerArithmetic,
31-
OutOfBounds,
30+
PointerArithmeticTest,
31+
InboundsTest,
3232
}
3333

3434
impl Display for CheckInAllocMsg {
3535
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3636
write!(f, "{}", match *self {
37-
CheckInAllocMsg::MemoryAccess => "memory access",
38-
CheckInAllocMsg::NullPointer => "null pointer",
39-
CheckInAllocMsg::PointerArithmetic => "pointer arithmetic",
40-
CheckInAllocMsg::OutOfBounds => "out of bounds",
37+
CheckInAllocMsg::MemoryAccessTest => "Memory access",
38+
CheckInAllocMsg::NullPointerTest => "Null pointer",
39+
CheckInAllocMsg::PointerArithmeticTest => "Pointer arithmetic",
40+
CheckInAllocMsg::InboundsTest => "Inbounds",
4141
})
4242
}
4343
}

src/librustc/mir/interpret/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
461461
use self::InterpError::*;
462462
match *self {
463463
PointerOutOfBounds { ptr, msg, allocation_size } => {
464-
write!(f, "Pointer must be in-bounds{} at offset {}, but is outside bounds of \
464+
write!(f, "{} test failed: pointer must be in-bounds at offset {}, but is outside bounds of \
465465
allocation {} which has size {}", msg,
466466
ptr.offset.bytes(), ptr.alloc_id, allocation_size.bytes())
467467
},

src/librustc_mir/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
253253
// check this is not NULL -- which we can ensure only if this is in-bounds
254254
// of some (potentially dead) allocation.
255255
let align = self.check_bounds_ptr(ptr, InboundsCheck::MaybeDead,
256-
CheckInAllocMsg::NullPointer)?;
256+
CheckInAllocMsg::NullPointerTest)?;
257257
(ptr.offset.bytes(), align)
258258
}
259259
Scalar::Bits { bits, size } => {

src/librustc_mir/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
668668
// The niche must be just 0 (which an inbounds pointer value never is)
669669
let ptr_valid = niche_start == 0 && variants_start == variants_end &&
670670
self.memory.check_bounds_ptr(ptr, InboundsCheck::MaybeDead,
671-
CheckInAllocMsg::OutOfBounds).is_ok();
671+
CheckInAllocMsg::NullPointerTest).is_ok();
672672
if !ptr_valid {
673673
return err!(InvalidDiscriminant(raw_discr.erase_tag()));
674674
}

src/librustc_mir/interpret/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
394394
try_validation!(
395395
self.ecx.memory
396396
.get(ptr.alloc_id)?
397-
.check_bounds(self.ecx, ptr, size, CheckInAllocMsg::OutOfBounds),
397+
.check_bounds(self.ecx, ptr, size, CheckInAllocMsg::InboundsTest),
398398
"dangling (not entirely in bounds) reference", self.path);
399399
}
400400
// Check if we have encountered this pointer+layout combination

0 commit comments

Comments
 (0)