Skip to content

Commit

Permalink
Rollup merge of #91303 - RalfJung:array-init-align, r=oli-obk
Browse files Browse the repository at this point in the history
Miri: fix alignment check in array initialization

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

r? `@oli-obk`
Fixes rust-lang/miri#1919
Fixes rust-lang/miri#1925
  • Loading branch information
matthiaskrgr authored Nov 28, 2021
2 parents 9e8dfcf + f8e3b31 commit 7134ae0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7134ae0

Please sign in to comment.