let caller of check_ptr_access_align control the error message
This commit is contained in:
parent
f49f388713
commit
b4dde36344
2 changed files with 13 additions and 6 deletions
|
@ -314,16 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
align: Align,
|
||||
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
|
||||
let align = if M::CHECK_ALIGN { Some(align) } else { None };
|
||||
self.check_ptr_access_align(sptr, size, align)
|
||||
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
|
||||
}
|
||||
|
||||
/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
|
||||
/// is `Some` (overriding `M::CHECK_ALIGN`).
|
||||
pub(super) fn check_ptr_access_align(
|
||||
/// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
|
||||
/// the error message for the out-of-bounds case.
|
||||
pub fn check_ptr_access_align(
|
||||
&self,
|
||||
sptr: Scalar<M::PointerTag>,
|
||||
size: Size,
|
||||
align: Option<Align>,
|
||||
msg: CheckInAllocMsg,
|
||||
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
|
||||
fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> {
|
||||
if offset % align.bytes() == 0 {
|
||||
|
@ -368,7 +370,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
// It is sufficient to check this for the end pointer. The addition
|
||||
// checks for overflow.
|
||||
let end_ptr = ptr.offset(size, self)?;
|
||||
end_ptr.check_inbounds_alloc(allocation_size, CheckInAllocMsg::MemoryAccessTest)?;
|
||||
end_ptr.check_inbounds_alloc(allocation_size, msg)?;
|
||||
// Test align. Check this last; if both bounds and alignment are violated
|
||||
// we want the error to be about the bounds.
|
||||
if let Some(align) = align {
|
||||
|
|
|
@ -16,7 +16,7 @@ use rustc_data_structures::fx::FxHashSet;
|
|||
use std::hash::Hash;
|
||||
|
||||
use super::{
|
||||
GlobalAlloc, InterpResult,
|
||||
GlobalAlloc, InterpResult, CheckInAllocMsg,
|
||||
Scalar, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
|
||||
};
|
||||
|
||||
|
@ -424,7 +424,12 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
|||
// alignment should take attributes into account).
|
||||
.unwrap_or_else(|| (layout.size, layout.align.abi));
|
||||
let ptr: Option<_> = match
|
||||
self.ecx.memory.check_ptr_access_align(ptr, size, Some(align))
|
||||
self.ecx.memory.check_ptr_access_align(
|
||||
ptr,
|
||||
size,
|
||||
Some(align),
|
||||
CheckInAllocMsg::InboundsTest,
|
||||
)
|
||||
{
|
||||
Ok(ptr) => ptr,
|
||||
Err(err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue