Skip field retagging on ZSTs, it can take forever

This commit is contained in:
Ben Kimock 2022-08-28 13:07:33 -04:00
parent 88665133b7
commit 70b960b879
2 changed files with 13 additions and 0 deletions

View File

@ -973,6 +973,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
fn visit_value(&mut self, place: &PlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
// If this place is smaller than a pointer, we know that it can't contain any
// pointers we need to retag, so we can stop recursion early.
// This optimization is crucial for ZSTs, because they can contain way more fields
// than we can ever visit.
if !place.layout.is_unsized() && place.layout.size < self.ecx.pointer_size() {
return Ok(());
}
if let Some((ref_kind, protector)) = qualify(place.layout.ty, self.kind) {
self.retag_place(place, ref_kind, self.retag_cause, protector)?;
} else if matches!(place.layout.ty.kind(), ty::RawPtr(..)) {

View File

@ -0,0 +1,5 @@
//@compile-flags: -Zmiri-retag-fields
fn main() {
let array = [(); usize::MAX];
drop(array); // Pass the array to a function, retagging its fields
}