Skip to content

Commit 19b9b26

Browse files
committedJan 13, 2020
Early abort validation of arrays of zsts because there is no data to be checked
1 parent 2d8d559 commit 19b9b26

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)
Please sign in to comment.