Skip to content

Commit 31dd4f4

Browse files
committed
Auto merge of #68088 - oli-obk:fix_miri, r=RalfJung
Don't try to force_ptr pointers to zsts r? @RalfJung cc @wesleywiser This is required to fix miri after #67501 broke it. The reason only miri sees this is that it uses validation on values during interpretation and not just on the final value of constants, which never contain such values.
2 parents bf84eb5 + 19b9b26 commit 31dd4f4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/librustc_mir/interpret/validity.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,14 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
608608
return Ok(());
609609
}
610610
// This is the element type size.
611-
let ty_size = self.ecx.layout_of(tys)?.size;
611+
let layout = self.ecx.layout_of(tys)?;
612+
// Empty tuples and fieldless structs (the only ZSTs that allow reaching this code)
613+
// have no data to be checked.
614+
if layout.is_zst() {
615+
return Ok(());
616+
}
612617
// This is the size in bytes of the whole array.
613-
let size = ty_size * len;
618+
let size = layout.size * len;
614619
// Size is not 0, get a pointer.
615620
let ptr = self.ecx.force_ptr(mplace.ptr)?;
616621

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

646651
throw_validation_failure!("undefined bytes", self.path)

0 commit comments

Comments
 (0)