about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-11-28 10:42:40 +0100
committerGitHub <noreply@github.com>2021-11-28 10:42:40 +0100
commit7134ae0a8dbab6fbf9920b489a37093643e3aa0c (patch)
tree073f57da23c74c44c518b2a6f19f206888847aa3 /compiler
parent9e8dfcffb7a84c01c0210f2c3a6b812e6be00743 (diff)
parentf8e3b31858219e84dad358e7b9ee4a96b6ee4b5f (diff)
downloadrust-7134ae0a8dbab6fbf9920b489a37093643e3aa0c.tar.gz
rust-7134ae0a8dbab6fbf9920b489a37093643e3aa0c.zip
Rollup merge of #91303 - RalfJung:array-init-align, r=oli-obk
Miri: fix alignment check in array initialization

https://github.com/rust-lang/rust/pull/85376 introduced a regression in Miri, reported at https://github.com/rust-lang/miri/issues/1919 and https://github.com/rust-lang/miri/issues/1925. This PR fixes that. I will add tests to Miri once this lands.

r? `@oli-obk`
Fixes https://github.com/rust-lang/miri/issues/1919
Fixes https://github.com/rust-lang/miri/issues/1925
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_const_eval/src/interpret/step.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs
index e6037d561de..9299ae2b2b9 100644
--- a/compiler/rustc_const_eval/src/interpret/step.rs
+++ b/compiler/rustc_const_eval/src/interpret/step.rs
@@ -242,11 +242,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                     let elem_size = first.layout.size;
                     let first_ptr = first.ptr;
                     let rest_ptr = first_ptr.offset(elem_size, self)?;
+                    // For the alignment of `rest_ptr`, we crucially do *not* use `first.align` as
+                    // that place might be more aligned than its type mandates (a `u8` array could
+                    // be 4-aligned if it sits at the right spot in a struct). Instead we use
+                    // `first.layout.align`, i.e., the alignment given by the type.
                     self.memory.copy_repeatedly(
                         first_ptr,
                         first.align,
                         rest_ptr,
-                        first.align,
+                        first.layout.align.abi,
                         elem_size,
                         length - 1,
                         /*nonoverlapping:*/ true,