Skip to content

Commit 41d5a77

Browse files
committed
Miri: mplace_access_checked: offer option to force different alignment on place
1 parent 8d67f57 commit 41d5a77

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/librustc_mir/interpret/place.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ where
333333
let val = self.read_immediate(src)?;
334334
trace!("deref to {} on {:?}", val.layout.ty, *val);
335335
let place = self.ref_to_mplace(val)?;
336-
self.mplace_access_checked(place)
336+
self.mplace_access_checked(place, None)
337337
}
338338

339339
/// Check if the given place is good for memory access with the given
@@ -361,12 +361,14 @@ where
361361
pub fn mplace_access_checked(
362362
&self,
363363
mut place: MPlaceTy<'tcx, M::PointerTag>,
364+
force_align: Option<Align>,
364365
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
365366
let (size, align) = self
366367
.size_and_align_of_mplace(place)?
367368
.unwrap_or((place.layout.size, place.layout.align.abi));
368369
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
369-
place.mplace.align = align; // maximally strict checking
370+
// Check (stricter) dynamic alignment, unless forced otherwise.
371+
place.mplace.align = force_align.unwrap_or(align);
370372
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
371373
if let Some(ptr) = self.check_mplace_access(place, Some(size))? {
372374
place.mplace.ptr = ptr.into();

0 commit comments

Comments
 (0)