@@ -627,7 +627,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
627627 if size. bytes ( ) == 0 {
628628 Ok ( & [ ] )
629629 } else {
630- let ptr = ptr . to_ptr ( ) ?;
630+ let ptr = self . force_ptr ( ptr ) ?;
631631 self . get ( ptr. alloc_id ) ?. get_bytes ( self , ptr, size)
632632 }
633633 }
@@ -714,8 +714,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
714714 // non-NULLness which already happened.
715715 return Ok ( ( ) ) ;
716716 }
717- let src = src . to_ptr ( ) ?;
718- let dest = dest . to_ptr ( ) ?;
717+ let src = self . force_ptr ( src ) ?;
718+ let dest = self . force_ptr ( dest ) ?;
719719
720720 // first copy the relocations to a temporary buffer, because
721721 // `get_bytes_mut` will clear the relocations, which is correct,
@@ -874,4 +874,25 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
874874 }
875875 Ok ( ( ) )
876876 }
877+
878+ pub fn force_ptr (
879+ & self ,
880+ scalar : Scalar < M :: PointerTag > ,
881+ ) -> InterpResult < ' tcx , Pointer < M :: PointerTag > > {
882+ match scalar {
883+ Scalar :: Ptr ( ptr) => Ok ( ptr) ,
884+ _ => M :: int_to_ptr ( scalar. to_usize ( self ) ?, & self . extra )
885+ }
886+ }
887+
888+ pub fn force_bits (
889+ & self ,
890+ scalar : Scalar < M :: PointerTag > ,
891+ size : Size
892+ ) -> InterpResult < ' tcx , u128 > {
893+ match scalar. to_bits_or_ptr ( size, self ) {
894+ Ok ( bits) => Ok ( bits) ,
895+ Err ( ptr) => Ok ( M :: ptr_to_int ( ptr, & self . extra ) ? as u128 )
896+ }
897+ }
877898}
0 commit comments