Improve miri's error reporting in check_in_alloc
This commit is contained in:
parent
0d97ad3834
commit
15d50deeb4
5 changed files with 11 additions and 11 deletions
|
|
@ -25,19 +25,19 @@ pub enum InboundsCheck {
|
|||
/// Used by `check_in_alloc` to indicate context of check
|
||||
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
|
||||
pub enum CheckInAllocMsg {
|
||||
MemoryAccess,
|
||||
MemoryAccessTest,
|
||||
NullPointerTest,
|
||||
PointerArithmetic,
|
||||
OutOfBounds,
|
||||
PointerArithmeticTest,
|
||||
InboundsTest,
|
||||
}
|
||||
|
||||
impl Display for CheckInAllocMsg {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", match *self {
|
||||
CheckInAllocMsg::MemoryAccess => "memory access",
|
||||
CheckInAllocMsg::NullPointer => "null pointer",
|
||||
CheckInAllocMsg::PointerArithmetic => "pointer arithmetic",
|
||||
CheckInAllocMsg::OutOfBounds => "out of bounds",
|
||||
CheckInAllocMsg::MemoryAccessTest => "Memory access",
|
||||
CheckInAllocMsg::NullPointerTest => "Null pointer",
|
||||
CheckInAllocMsg::PointerArithmeticTest => "Pointer arithmetic",
|
||||
CheckInAllocMsg::InboundsTest => "Inbounds",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -461,7 +461,7 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
|
|||
use self::InterpError::*;
|
||||
match *self {
|
||||
PointerOutOfBounds { ptr, msg, allocation_size } => {
|
||||
write!(f, "Pointer must be in-bounds{} at offset {}, but is outside bounds of \
|
||||
write!(f, "{} test failed: pointer must be in-bounds at offset {}, but is outside bounds of \
|
||||
allocation {} which has size {}", msg,
|
||||
ptr.offset.bytes(), ptr.alloc_id, allocation_size.bytes())
|
||||
},
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
|
|||
// check this is not NULL -- which we can ensure only if this is in-bounds
|
||||
// of some (potentially dead) allocation.
|
||||
let align = self.check_bounds_ptr(ptr, InboundsCheck::MaybeDead,
|
||||
CheckInAllocMsg::NullPointer)?;
|
||||
CheckInAllocMsg::NullPointerTest)?;
|
||||
(ptr.offset.bytes(), align)
|
||||
}
|
||||
Scalar::Bits { bits, size } => {
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
|
|||
// The niche must be just 0 (which an inbounds pointer value never is)
|
||||
let ptr_valid = niche_start == 0 && variants_start == variants_end &&
|
||||
self.memory.check_bounds_ptr(ptr, InboundsCheck::MaybeDead,
|
||||
CheckInAllocMsg::OutOfBounds).is_ok();
|
||||
CheckInAllocMsg::NullPointerTest).is_ok();
|
||||
if !ptr_valid {
|
||||
return err!(InvalidDiscriminant(raw_discr.erase_tag()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
|
|||
try_validation!(
|
||||
self.ecx.memory
|
||||
.get(ptr.alloc_id)?
|
||||
.check_bounds(self.ecx, ptr, size, CheckInAllocMsg::OutOfBounds),
|
||||
.check_bounds(self.ecx, ptr, size, CheckInAllocMsg::InboundsTest),
|
||||
"dangling (not entirely in bounds) reference", self.path);
|
||||
}
|
||||
// Check if we have encountered this pointer+layout combination
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue