]> git.lizzy.rs Git - rust.git/commitdiff
Early abort validation of arrays of zsts because there is no data to be checked
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 13 Jan 2020 15:12:10 +0000 (16:12 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Mon, 13 Jan 2020 15:12:10 +0000 (16:12 +0100)
src/librustc_mir/interpret/validity.rs

index 12e8cb6071d92b31453da434edddfc1b29bf5d65..2f0fb81fffd13db3322a64153e465dfdfa4d4fc5 100644 (file)
@@ -608,9 +608,14 @@ fn visit_aggregate(
                     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 @@ fn visit_aggregate(
                                 // 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)