add method to get absolute address of a pointer (useful only for Miri)
This commit is contained in:
parent
c9e568f72e
commit
3236092503
3 changed files with 14 additions and 6 deletions
|
@ -126,6 +126,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
|
|||
|
||||
/// Whether, when checking alignment, we should `force_int` and thus support
|
||||
/// custom alignment logic based on whatever the integer address happens to be.
|
||||
///
|
||||
/// Requires PointerTag::OFFSET_IS_ADDR to be true.
|
||||
fn force_int_for_alignment_check(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
|
||||
|
||||
/// Whether to enforce the validity invariant
|
||||
|
|
|
@ -446,12 +446,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
// we want the error to be about the bounds.
|
||||
if let Some(align) = align {
|
||||
if M::force_int_for_alignment_check(self) {
|
||||
assert!(
|
||||
M::PointerTag::OFFSET_IS_ADDR,
|
||||
"ptr-to-int cast for align check should never fail"
|
||||
);
|
||||
let (_, addr) = ptr.into_parts(); // we checked that offset is absolute
|
||||
check_offset_align(addr.bytes(), align)?;
|
||||
// `force_int_for_alignment_check` can only be true if `OFFSET_IS_ADDR` is true.
|
||||
check_offset_align(ptr.addr().bytes(), align)?;
|
||||
} else {
|
||||
// Check allocation alignment and offset alignment.
|
||||
if alloc_align.bytes() < align.bytes() {
|
||||
|
|
|
@ -207,6 +207,16 @@ impl<Tag> Pointer<Option<Tag>> {
|
|||
None => Err(self.offset),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the absolute address the pointer points to.
|
||||
/// Only works if Tag::OFFSET_IS_ADDR is true!
|
||||
pub fn addr(self) -> Size
|
||||
where
|
||||
Tag: Provenance,
|
||||
{
|
||||
assert!(Tag::OFFSET_IS_ADDR);
|
||||
self.offset
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tag> Pointer<Option<Tag>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue