Rollup merge of #104356 - RalfJung:interpret-check-mplace, r=oli-obk
interpret: make check_mplace public This helps avoid code duplication in https://github.com/rust-lang/miri/pull/2661.
This commit is contained in:
commit
050ece6765
@ -316,8 +316,7 @@ where
|
|||||||
Ok(MPlaceTy { mplace, layout, align })
|
Ok(MPlaceTy { mplace, layout, align })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take an operand, representing a pointer, and dereference it to a place -- that
|
/// Take an operand, representing a pointer, and dereference it to a place.
|
||||||
/// will always be a MemPlace. Lives in `place.rs` because it creates a place.
|
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn deref_operand(
|
pub fn deref_operand(
|
||||||
&self,
|
&self,
|
||||||
@ -331,7 +330,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mplace = self.ref_to_mplace(&val)?;
|
let mplace = self.ref_to_mplace(&val)?;
|
||||||
self.check_mplace_access(mplace, CheckInAllocMsg::DerefTest)?;
|
self.check_mplace(mplace)?;
|
||||||
Ok(mplace)
|
Ok(mplace)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,17 +357,18 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this mplace is dereferenceable and sufficiently aligned.
|
/// Check if this mplace is dereferenceable and sufficiently aligned.
|
||||||
fn check_mplace_access(
|
pub fn check_mplace(&self, mplace: MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
|
||||||
&self,
|
|
||||||
mplace: MPlaceTy<'tcx, M::Provenance>,
|
|
||||||
msg: CheckInAllocMsg,
|
|
||||||
) -> InterpResult<'tcx> {
|
|
||||||
let (size, align) = self
|
let (size, align) = self
|
||||||
.size_and_align_of_mplace(&mplace)?
|
.size_and_align_of_mplace(&mplace)?
|
||||||
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
|
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
|
||||||
assert!(mplace.align <= align, "dynamic alignment less strict than static one?");
|
assert!(mplace.align <= align, "dynamic alignment less strict than static one?");
|
||||||
let align = M::enforce_alignment(self).then_some(align);
|
let align = M::enforce_alignment(self).then_some(align);
|
||||||
self.check_ptr_access_align(mplace.ptr, size, align.unwrap_or(Align::ONE), msg)?;
|
self.check_ptr_access_align(
|
||||||
|
mplace.ptr,
|
||||||
|
size,
|
||||||
|
align.unwrap_or(Align::ONE),
|
||||||
|
CheckInAllocMsg::DerefTest,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user