diff options
| author | Ralf Jung <post@ralfj.de> | 2021-11-27 18:17:09 -0500 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2021-11-27 18:18:48 -0500 |
| commit | f8e3b31858219e84dad358e7b9ee4a96b6ee4b5f (patch) | |
| tree | b59ff148bb424535e10b1fbd498b217117560c26 /compiler/rustc_const_eval/src | |
| parent | 686e313a9aa14107c8631ffe48fa09110a7692db (diff) | |
| download | rust-f8e3b31858219e84dad358e7b9ee4a96b6ee4b5f.tar.gz rust-f8e3b31858219e84dad358e7b9ee4a96b6ee4b5f.zip | |
Miri: fix alignment check in array initialization
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/step.rs | 6 |
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, |
