Miri: let machine hook dynamically decide about alignment checks
This commit is contained in:
parent
a00bd29e01
commit
28e6b1a602
@ -179,9 +179,12 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {
|
|||||||
|
|
||||||
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
|
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
|
||||||
|
|
||||||
// We do not check for alignment to avoid having to carry an `Align`
|
#[inline(always)]
|
||||||
// in `ConstValue::ByRef`.
|
fn enforce_alignment(_memory_extra: &Self::MemoryExtra) -> bool {
|
||||||
const CHECK_ALIGN: bool = false;
|
// We do not check for alignment to avoid having to carry an `Align`
|
||||||
|
// in `ConstValue::ByRef`.
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
|
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
|
||||||
|
@ -118,7 +118,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
|||||||
const GLOBAL_KIND: Option<Self::MemoryKind>;
|
const GLOBAL_KIND: Option<Self::MemoryKind>;
|
||||||
|
|
||||||
/// Whether memory accesses should be alignment-checked.
|
/// Whether memory accesses should be alignment-checked.
|
||||||
const CHECK_ALIGN: bool;
|
fn enforce_alignment(memory_extra: &Self::MemoryExtra) -> bool;
|
||||||
|
|
||||||
/// Whether to enforce the validity invariant
|
/// Whether to enforce the validity invariant
|
||||||
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
||||||
|
@ -323,12 +323,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||||||
size: Size,
|
size: Size,
|
||||||
align: Align,
|
align: Align,
|
||||||
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
|
) -> InterpResult<'tcx, Option<Pointer<M::PointerTag>>> {
|
||||||
let align = M::CHECK_ALIGN.then_some(align);
|
let align = M::enforce_alignment(&self.extra).then_some(align);
|
||||||
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
|
self.check_ptr_access_align(sptr, size, align, CheckInAllocMsg::MemoryAccessTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
|
/// Like `check_ptr_access`, but *definitely* checks alignment when `align`
|
||||||
/// is `Some` (overriding `M::CHECK_ALIGN`). Also lets the caller control
|
/// is `Some` (overriding `M::enforce_alignment`). Also lets the caller control
|
||||||
/// the error message for the out-of-bounds case.
|
/// the error message for the out-of-bounds case.
|
||||||
pub fn check_ptr_access_align(
|
pub fn check_ptr_access_align(
|
||||||
&self,
|
&self,
|
||||||
|
@ -173,7 +173,10 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
|
|||||||
|
|
||||||
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
|
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
|
||||||
|
|
||||||
const CHECK_ALIGN: bool = false;
|
#[inline(always)]
|
||||||
|
fn enforce_alignment(_memory_extra: &Self::MemoryExtra) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
|
fn enforce_validity(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user