1
Fork 0

Rustc changes for permissive provenance

This commit is contained in:
carbotaniuman 2022-05-13 12:30:25 -05:00
parent 0034bbca26
commit bd5fce65c6
12 changed files with 142 additions and 45 deletions

View file

@ -120,9 +120,11 @@ pub trait Provenance: Copy + fmt::Debug {
where
Self: Sized;
/// Provenance must always be able to identify the allocation this ptr points to.
/// If `OFFSET_IS_ADDR == false`, provenance must always be able to
/// identify the allocation this ptr points to (i.e., this must return `Some`).
/// Otherwise this function is best-effort (but must agree with `Machine::ptr_get_alloc`).
/// (Identifying the offset in that allocation, however, is harder -- use `Memory::ptr_get_alloc` for that.)
fn get_alloc_id(self) -> AllocId;
fn get_alloc_id(self) -> Option<AllocId>;
}
impl Provenance for AllocId {
@ -147,8 +149,8 @@ impl Provenance for AllocId {
Ok(())
}
fn get_alloc_id(self) -> AllocId {
self
fn get_alloc_id(self) -> Option<AllocId> {
Some(self)
}
}

View file

@ -344,7 +344,8 @@ impl<'tcx, Tag: Provenance> Scalar<Tag> {
} else {
// We know `offset` is relative, since `OFFSET_IS_ADDR == false`.
let (tag, offset) = ptr.into_parts();
Err(Scalar::Ptr(Pointer::new(tag.get_alloc_id(), offset), sz))
// Because `OFFSET_IS_ADDR == false`, this unwrap can never fail.
Err(Scalar::Ptr(Pointer::new(tag.get_alloc_id().unwrap(), offset), sz))
}
}
}