mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Array and slice projections need to update the place alignment
This commit is contained in:
@@ -271,13 +271,13 @@ pub(super) fn try_read_immediate_from_mplace(
|
||||
if mplace.layout.is_zst() {
|
||||
// Not all ZSTs have a layout we would handle below, so just short-circuit them
|
||||
// all here.
|
||||
self.memory.check_align(ptr, ptr_align.min(mplace.layout.align))?;
|
||||
self.memory.check_align(ptr, ptr_align)?;
|
||||
return Ok(Some(Immediate::Scalar(Scalar::zst().into())));
|
||||
}
|
||||
|
||||
// check for integer pointers before alignment to report better errors
|
||||
let ptr = ptr.to_ptr()?;
|
||||
self.memory.check_align(ptr.into(), ptr_align.min(mplace.layout.align))?;
|
||||
self.memory.check_align(ptr.into(), ptr_align)?;
|
||||
match mplace.layout.abi {
|
||||
layout::Abi::Scalar(..) => {
|
||||
let scalar = self.memory
|
||||
@@ -295,7 +295,8 @@ pub(super) fn try_read_immediate_from_mplace(
|
||||
let a_val = self.memory
|
||||
.get(ptr.alloc_id)?
|
||||
.read_scalar(self, a_ptr, a_size)?;
|
||||
self.memory.check_align(b_ptr.into(), b.align(self).min(ptr_align))?;
|
||||
let b_align = ptr_align.restrict_for_offset(b_offset);
|
||||
self.memory.check_align(b_ptr.into(), b_align)?;
|
||||
let b_val = self.memory
|
||||
.get(ptr.alloc_id)?
|
||||
.read_scalar(self, b_ptr, b_size)?;
|
||||
|
||||
@@ -393,8 +393,9 @@ pub fn mplace_array_fields(
|
||||
let dl = &self.tcx.data_layout;
|
||||
Ok((0..len).map(move |i| {
|
||||
let ptr = base.ptr.ptr_offset(i * stride, dl)?;
|
||||
let align = base.align.restrict_for_offset(i * stride);
|
||||
Ok(MPlaceTy {
|
||||
mplace: MemPlace { ptr, align: base.align, meta: None },
|
||||
mplace: MemPlace { ptr, align, meta: None },
|
||||
layout
|
||||
})
|
||||
}))
|
||||
@@ -417,6 +418,7 @@ pub fn mplace_subslice(
|
||||
_ => bug!("Unexpected layout of index access: {:#?}", base.layout),
|
||||
};
|
||||
let ptr = base.ptr.ptr_offset(from_offset, self)?;
|
||||
let align = base.align.restrict_for_offset(from_offset);
|
||||
|
||||
// Compute meta and new layout
|
||||
let inner_len = len - to - from;
|
||||
@@ -435,7 +437,7 @@ pub fn mplace_subslice(
|
||||
let layout = self.layout_of(ty)?;
|
||||
|
||||
Ok(MPlaceTy {
|
||||
mplace: MemPlace { ptr, align: base.align, meta },
|
||||
mplace: MemPlace { ptr, align, meta },
|
||||
layout
|
||||
})
|
||||
}
|
||||
@@ -741,11 +743,11 @@ fn write_immediate_to_mplace_no_validate(
|
||||
dest.layout)
|
||||
};
|
||||
let (a_size, b_size) = (a.size(self), b.size(self));
|
||||
let b_align = b.align(self).abi;
|
||||
let b_offset = a_size.align_to(b_align);
|
||||
let b_offset = a_size.align_to(b.align(self).abi);
|
||||
let b_align = ptr_align.restrict_for_offset(b_offset);
|
||||
let b_ptr = ptr.offset(b_offset, self)?;
|
||||
|
||||
self.memory.check_align(b_ptr.into(), ptr_align.min(b_align))?;
|
||||
self.memory.check_align(b_ptr.into(), b_align)?;
|
||||
|
||||
// It is tempting to verify `b_offset` against `layout.fields.offset(1)`,
|
||||
// but that does not work: We could be a newtype around a pair, then the
|
||||
|
||||
Reference in New Issue
Block a user