Skip to content

Commit

Permalink
remove some now-unnecessary parameters from check_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 26, 2022
1 parent da13935 commit 2e52fe0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 31 deletions.
9 changes: 2 additions & 7 deletions compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,15 +962,10 @@ impl<'tcx, 'a, Prov: Provenance, Extra> AllocRef<'a, 'tcx, Prov, Extra> {
}

/// `range` is relative to this allocation reference, not the base of the allocation.
pub fn check_bytes(
&self,
range: AllocRange,
allow_uninit: bool,
allow_ptr: bool,
) -> InterpResult<'tcx> {
pub fn check_bytes(&self, range: AllocRange) -> InterpResult<'tcx> {
Ok(self
.alloc
.check_bytes(&self.tcx, self.range.subrange(range), allow_uninit, allow_ptr)
.check_bytes(&self.tcx, self.range.subrange(range))
.map_err(|e| e.to_interp_error(self.alloc_id))?)
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// We also accept uninit, for consistency with the slow path.
let alloc = self.ecx.get_ptr_alloc(mplace.ptr, size, mplace.align)?.expect("we already excluded size 0");

match alloc.check_bytes(
alloc_range(Size::ZERO, size),
/*allow_uninit*/ false,
/*allow_ptr*/ false,
) {
match alloc.check_bytes(alloc_range(Size::ZERO, size)) {
// In the happy case, we needn't check anything else.
Ok(()) => {}
// Some error happened, try to provide a more detailed description.
Expand Down
23 changes: 4 additions & 19 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,25 +415,10 @@ impl<Prov: Provenance, Extra> Allocation<Prov, Extra> {

/// Reading and writing.
impl<Prov: Provenance, Extra> Allocation<Prov, Extra> {
/// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
/// relocation. If `allow_uninit`/`allow_ptr` is `false`, also enforces that the memory in the
/// given range contains no uninitialized bytes/relocations.
pub fn check_bytes(
&self,
cx: &impl HasDataLayout,
range: AllocRange,
allow_uninit: bool,
allow_ptr: bool,
) -> AllocResult {
// Check bounds and relocations on the edges.
self.get_bytes_with_uninit_and_ptr(cx, range)?;
// Check uninit and ptr.
if !allow_uninit {
self.check_init(range)?;
}
if !allow_ptr {
self.check_relocations(cx, range)?;
}
/// Validates that this memory range is initiailized and contains no relocations.
pub fn check_bytes(&self, cx: &impl HasDataLayout, range: AllocRange) -> AllocResult {
// This implicitly does all the checking we are asking for.
self.get_bytes(cx, range)?;
Ok(())
}

Expand Down

0 comments on commit 2e52fe0

Please sign in to comment.