diff options
| author | Ralf Jung <post@ralfj.de> | 2023-07-11 15:50:11 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-07-11 21:59:01 +0200 |
| commit | e7c6db7d44b8627b9b3b1106fc08413c52fbabaa (patch) | |
| tree | c18edb10923d527549bcb661643926a9921eede0 /compiler/rustc_const_eval/src/interpret | |
| parent | 124fb1490a7894fbaa319e92d59b79817a407d44 (diff) | |
| download | rust-e7c6db7d44b8627b9b3b1106fc08413c52fbabaa.tar.gz rust-e7c6db7d44b8627b9b3b1106fc08413c52fbabaa.zip | |
fix handling of alignment for dyn-sized places
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/place.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index f1c777a077b..c2fb61753fe 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -328,7 +328,8 @@ where }; let mplace = MemPlace { ptr: ptr.to_pointer(self)?, meta }; - // When deref'ing a pointer, the *static* alignment given by the type is what matters. + // `ref_to_mplace` is called on raw pointers even if they don't actually get dereferenced; + // we hence can't call `size_and_align_of` since that asserts more validity than we want. let align = layout.align.abi; Ok(MPlaceTy { mplace, layout, align }) } @@ -379,11 +380,12 @@ where /// Check if this mplace is dereferenceable and sufficiently aligned. pub fn check_mplace(&self, mplace: MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> { - let (size, align) = self + let (size, _align) = self .size_and_align_of_mplace(&mplace)? .unwrap_or((mplace.layout.size, mplace.layout.align.abi)); - assert!(mplace.align <= align, "dynamic alignment less strict than static one?"); - let align = if M::enforce_alignment(self).should_check() { align } else { Align::ONE }; + // Due to packed places, only `mplace.align` matters. + let align = + if M::enforce_alignment(self).should_check() { mplace.align } else { Align::ONE }; self.check_ptr_access_align(mplace.ptr, size, align, CheckInAllocMsg::DerefTest)?; Ok(()) } |
