]> git.lizzy.rs Git - rust.git/commitdiff
Array and slice projections need to update the place alignment
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 16 Nov 2018 10:46:58 +0000 (11:46 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Sat, 24 Nov 2018 10:36:32 +0000 (11:36 +0100)
src/librustc_mir/interpret/operand.rs
src/librustc_mir/interpret/place.rs

index 4ec01b6ca1032e28810b0ff5bc390ad901524aaa..9588a931c4a3519459c2b112c94f552f315ab844 100644 (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)?;
index 6317cfb94d27fc107e549544e4fa7f142864c7c6..d93aca7f4e1d9276f420bece6fa70934e4eeb76f 100644 (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