Skip to content

Commit

Permalink
Early abort validation of arrays of zsts because there is no data to …
Browse files Browse the repository at this point in the history
…be checked
  • Loading branch information
oli-obk committed Jan 13, 2020
1 parent 2d8d559 commit 19b9b26
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,14 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
return Ok(());
}
// This is the element type size.
let ty_size = self.ecx.layout_of(tys)?.size;
let layout = self.ecx.layout_of(tys)?;
// Empty tuples and fieldless structs (the only ZSTs that allow reaching this code)
// have no data to be checked.
if layout.is_zst() {
return Ok(());
}
// This is the size in bytes of the whole array.
let size = ty_size * len;
let size = layout.size * len;
// Size is not 0, get a pointer.
let ptr = self.ecx.force_ptr(mplace.ptr)?;

Expand Down Expand Up @@ -640,7 +645,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
// Some byte was undefined, determine which
// element that byte belongs to so we can
// provide an index.
let i = (offset.bytes() / ty_size.bytes()) as usize;
let i = (offset.bytes() / layout.size.bytes()) as usize;
self.path.push(PathElem::ArrayElem(i));

throw_validation_failure!("undefined bytes", self.path)
Expand Down

0 comments on commit 19b9b26

Please sign in to comment.