Array and slice projections need to update the place alignment

This commit is contained in:
Oliver Scherer
2018-11-16 11:46:58 +01:00
parent 10102d1f0a
commit a5ef2d1b54
2 changed files with 11 additions and 8 deletions
+4 -3
View File
@@ -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)?;
+7 -5
View File
@@ -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