@@ -308,16 +308,8 @@ where
308308 ) -> InterpResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
309309 let val = self . read_immediate ( src) ?;
310310 trace ! ( "deref to {} on {:?}" , val. layout. ty, * val) ;
311- let mut place = self . ref_to_mplace ( val) ?;
312- let ( size, align) = self . size_and_align_of_mplace ( place) ?
313- . unwrap_or ( ( place. layout . size , place. layout . align . abi ) ) ;
314- assert ! ( place. mplace. align <= align, "dynamic alignment less strict than static one?" ) ;
315- place. mplace . align = align; // maximally strict checking
316- // When dereferencing a pointer, it must be non-NULL, aligned, and live.
317- if let Some ( ptr) = self . check_mplace_access ( place, Some ( size) ) ? {
318- place. mplace . ptr = ptr. into ( ) ;
319- }
320- Ok ( place)
311+ let place = self . ref_to_mplace ( val) ?;
312+ self . mplace_access_checked ( place)
321313 }
322314
323315 /// Check if the given place is good for memory access with the given
@@ -340,6 +332,23 @@ where
340332 self . memory . check_ptr_access ( place. ptr , size, place. align )
341333 }
342334
335+ /// Return the "access-checked" version of this `MPlace`, where for non-ZST
336+ /// this is definitely a `Pointer`.
337+ pub fn mplace_access_checked (
338+ & self ,
339+ mut place : MPlaceTy < ' tcx , M :: PointerTag > ,
340+ ) -> InterpResult < ' tcx , MPlaceTy < ' tcx , M :: PointerTag > > {
341+ let ( size, align) = self . size_and_align_of_mplace ( place) ?
342+ . unwrap_or ( ( place. layout . size , place. layout . align . abi ) ) ;
343+ assert ! ( place. mplace. align <= align, "dynamic alignment less strict than static one?" ) ;
344+ place. mplace . align = align; // maximally strict checking
345+ // When dereferencing a pointer, it must be non-NULL, aligned, and live.
346+ if let Some ( ptr) = self . check_mplace_access ( place, Some ( size) ) ? {
347+ place. mplace . ptr = ptr. into ( ) ;
348+ }
349+ Ok ( place)
350+ }
351+
343352 /// Force `place.ptr` to a `Pointer`.
344353 /// Can be helpful to avoid lots of `force_ptr` calls later, if this place is used a lot.
345354 pub fn force_mplace_ptr (
0 commit comments