Skip to content

Commit

Permalink
Rollup merge of rust-lang#104356 - RalfJung:interpret-check-mplace, r…
Browse files Browse the repository at this point in the history
…=oli-obk

interpret: make check_mplace public

This helps avoid code duplication in rust-lang/miri#2661.
  • Loading branch information
matthiaskrgr authored Nov 14, 2022
2 parents aa29a8b + 7982d6a commit 050ece6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ where
Ok(MPlaceTy { mplace, layout, align })
}

/// Take an operand, representing a pointer, and dereference it to a place -- that
/// will always be a MemPlace. Lives in `place.rs` because it creates a place.
/// Take an operand, representing a pointer, and dereference it to a place.
#[instrument(skip(self), level = "debug")]
pub fn deref_operand(
&self,
Expand All @@ -331,7 +330,7 @@ where
}

let mplace = self.ref_to_mplace(&val)?;
self.check_mplace_access(mplace, CheckInAllocMsg::DerefTest)?;
self.check_mplace(mplace)?;
Ok(mplace)
}

Expand All @@ -358,17 +357,18 @@ where
}

/// Check if this mplace is dereferenceable and sufficiently aligned.
fn check_mplace_access(
&self,
mplace: MPlaceTy<'tcx, M::Provenance>,
msg: CheckInAllocMsg,
) -> InterpResult<'tcx> {
pub fn check_mplace(&self, mplace: MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
let (size, align) = self
.size_and_align_of_mplace(&mplace)?
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));
assert!(mplace.align <= align, "dynamic alignment less strict than static one?");
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(())
}

Expand Down

0 comments on commit 050ece6

Please sign in to comment.