Improve miri's error reporting in check_in_alloc

This commit is contained in:
LooMaclin 2019-04-02 06:16:11 +03:00
parent 725199ce65
commit 7b4bc6974a
2 changed files with 4 additions and 5 deletions

View file

@ -22,8 +22,7 @@ pub enum InboundsCheck {
MaybeDead,
}
/// Used by `check_in_alloc` to indicate whether the pointer needs to be just inbounds
/// or also inbounds of a *live* allocation.
/// Used by `check_in_alloc` to indicate context of check
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub enum CheckInAllocMsg {
ReadCStr,

View file

@ -20,7 +20,7 @@ use syntax::ast::Mutability;
use super::{
Pointer, AllocId, Allocation, GlobalId, AllocationExtra,
EvalResult, Scalar, EvalErrorKind, AllocKind, PointerArithmetic,
Machine, AllocMap, MayLeak, ErrorHandled, InboundsCheck, CheckInAllocMsg,
Machine, AllocMap, MayLeak, ErrorHandled, CheckInAllocMsg,
};
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
@ -440,13 +440,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
Ok((layout.size, layout.align.abi))
}
_ => match msg {
InboundsCheck::MaybeDead => {
CheckInAllocMsg::CheckAlign | CheckInAllocMsg::ReadDiscriminant => {
// Must be a deallocated pointer
Ok(*self.dead_alloc_map.get(&id).expect(
"allocation missing in dead_alloc_map"
))
},
InboundsCheck::Live => err!(DanglingPointerDeref),
_ => err!(DanglingPointerDeref),
},
}
}