@@ -627,7 +627,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
627
627
if size. bytes ( ) == 0 {
628
628
Ok ( & [ ] )
629
629
} else {
630
- let ptr = ptr . to_ptr ( ) ?;
630
+ let ptr = self . force_ptr ( ptr ) ?;
631
631
self . get ( ptr. alloc_id ) ?. get_bytes ( self , ptr, size)
632
632
}
633
633
}
@@ -714,8 +714,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
714
714
// non-NULLness which already happened.
715
715
return Ok ( ( ) ) ;
716
716
}
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 ) ?;
719
719
720
720
// first copy the relocations to a temporary buffer, because
721
721
// `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> {
874
874
}
875
875
Ok ( ( ) )
876
876
}
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
+ }
877
898
}
0 commit comments