Skip to content

Commit 7134ae0

Browse files
authored
Rollup merge of #91303 - RalfJung:array-init-align, r=oli-obk
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
2 parents 9e8dfcf + f8e3b31 commit 7134ae0

File tree

1 file changed

+5
-1
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+5
-1
lines changed

Diff for: compiler/rustc_const_eval/src/interpret/step.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
242242
let elem_size = first.layout.size;
243243
let first_ptr = first.ptr;
244244
let rest_ptr = first_ptr.offset(elem_size, self)?;
245+
// For the alignment of `rest_ptr`, we crucially do *not* use `first.align` as
246+
// that place might be more aligned than its type mandates (a `u8` array could
247+
// be 4-aligned if it sits at the right spot in a struct). Instead we use
248+
// `first.layout.align`, i.e., the alignment given by the type.
245249
self.memory.copy_repeatedly(
246250
first_ptr,
247251
first.align,
248252
rest_ptr,
249-
first.align,
253+
first.layout.align.abi,
250254
elem_size,
251255
length - 1,
252256
/*nonoverlapping:*/ true,

0 commit comments

Comments
 (0)