about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-13 17:39:01 +0000
committerbors <bors@rust-lang.org>2020-01-13 17:39:01 +0000
commit31dd4f4acbcbdb02b0745d2136399ed664a28050 (patch)
treef23b2164b102686755c4bd7ac1cf7f2204b103a2
parentbf84eb538fd16743240434b3e837b36c35719fee (diff)
parent19b9b26986246b92e1f686a9a7b29da42a79ed9f (diff)
downloadrust-31dd4f4acbcbdb02b0745d2136399ed664a28050.tar.gz
rust-31dd4f4acbcbdb02b0745d2136399ed664a28050.zip
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 https://github.com/rust-lang/rust/pull/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.
-rw-r--r--src/librustc_mir/interpret/validity.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs
index 12e8cb6071d..2f0fb81fffd 100644
--- a/src/librustc_mir/interpret/validity.rs
+++ b/src/librustc_mir/interpret/validity.rs
@@ -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)?;
 
@@ -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)