Skip to content

Commit

Permalink
Improve miri's error reporting in check_in_alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
LooMaclin committed Apr 2, 2019
1 parent 7b4bc69 commit 705d75e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/librustc/mir/interpret/allocation.rs
Expand Up @@ -353,7 +353,8 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
// FIXME: Working around https://github.com/rust-lang/rust/issues/56209
where Extra: AllocationExtra<Tag, MemoryExtra>
{
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64), CheckInAllocMsg::WriteBytes)?;
let bytes = self.get_bytes_mut(cx, ptr, Size::from_bytes(src.len() as u64),
CheckInAllocMsg::WriteBytes)?;
bytes.clone_from_slice(src);
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/hair/pattern/_match.rs
Expand Up @@ -1418,7 +1418,8 @@ fn slice_pat_covered_by_const<'tcx>(
return Ok(false);
}
let n = n.assert_usize(tcx).unwrap();
alloc.get_bytes(&tcx, ptr, Size::from_bytes(n), CheckInAllocMsg::SlicePatCoveredByConst).unwrap()
alloc.get_bytes(&tcx, ptr, Size::from_bytes(n),
CheckInAllocMsg::SlicePatCoveredByConst).unwrap()
},
// a slice fat pointer to a zero length slice
(ConstValue::Slice(Scalar::Bits { .. }, 0), ty::Slice(t)) => {
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/interpret/operand.rs
Expand Up @@ -667,7 +667,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) => {
// 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, CheckInAllocMsg::ReadDiscriminant).is_ok();
self.memory.check_bounds_ptr(ptr,
CheckInAllocMsg::ReadDiscriminant).is_ok();
if !ptr_valid {
return err!(InvalidDiscriminant(raw_discr.erase_tag()));
}
Expand Down

0 comments on commit 705d75e

Please sign in to comment.