diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-16 11:46:58 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-24 11:36:32 +0100 |
| commit | a5ef2d1b54c833783a64a98d5d585bb44218497a (patch) | |
| tree | 9af44b381fa0b8aab63f173aad350d737dc3df8b | |
| parent | 10102d1f0aa0e7e612ea2a51d5329af928b07f03 (diff) | |
| download | rust-a5ef2d1b54c833783a64a98d5d585bb44218497a.tar.gz rust-a5ef2d1b54c833783a64a98d5d585bb44218497a.zip | |
Array and slice projections need to update the place alignment
| -rw-r--r-- | src/librustc_mir/interpret/operand.rs | 7 | ||||
| -rw-r--r-- | src/librustc_mir/interpret/place.rs | 12 |
2 files changed, 11 insertions, 8 deletions
diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 4ec01b6ca10..9588a931c4a 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -271,13 +271,13 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> 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 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> 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)?; diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 6317cfb94d2..d93aca7f4e1 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -393,8 +393,9 @@ where 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 @@ where _ => 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 @@ where 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 @@ where 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 |
