Skip to content

Commit e69141a

Browse files
authored
Rollup merge of #71280 - RalfJung:mplace-check-align, r=oli-obk
Miri: mplace_access_checked: offer option to force different alignment on place Required to solve rust-lang/miri#1339 in rust-lang/miri#1348. r? @oli-obk
2 parents 00f677d + 5449e0f commit e69141a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/librustc_mir/interpret/place.rs

+7-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
@@ -358,15 +358,20 @@ where
358358

359359
/// Return the "access-checked" version of this `MPlace`, where for non-ZST
360360
/// this is definitely a `Pointer`.
361+
///
362+
/// `force_align` must only be used when correct alignment does not matter,
363+
/// like in Stacked Borrows.
361364
pub fn mplace_access_checked(
362365
&self,
363366
mut place: MPlaceTy<'tcx, M::PointerTag>,
367+
force_align: Option<Align>,
364368
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
365369
let (size, align) = self
366370
.size_and_align_of_mplace(place)?
367371
.unwrap_or((place.layout.size, place.layout.align.abi));
368372
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
369-
place.mplace.align = align; // maximally strict checking
373+
// Check (stricter) dynamic alignment, unless forced otherwise.
374+
place.mplace.align = force_align.unwrap_or(align);
370375
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
371376
if let Some(ptr) = self.check_mplace_access(place, Some(size))? {
372377
place.mplace.ptr = ptr.into();

0 commit comments

Comments
 (0)