Skip to content

Commit f8e3b31

Browse files
committed
Miri: fix alignment check in array initialization
1 parent 686e313 commit f8e3b31

File tree

1 file changed

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

1 file changed

+5
-1
lines changed

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)