@@ -232,8 +232,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
232
232
M :: GLOBAL_KIND . map( MemoryKind :: Machine ) ,
233
233
"dynamically allocating global memory"
234
234
) ;
235
- let alloc =
236
- M :: init_allocation_extra ( self , id, Cow :: Owned ( alloc) , Some ( kind) ) ;
235
+ let alloc = M :: init_allocation_extra ( self , id, Cow :: Owned ( alloc) , Some ( kind) ) ;
237
236
self . alloc_map . insert ( id, ( kind, alloc. into_owned ( ) ) ) ;
238
237
M :: tag_alloc_base_pointer ( self , Pointer :: from ( id) )
239
238
}
@@ -372,7 +371,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
372
371
)
373
372
}
374
373
375
- /// Check if the given pointer is allowed to do a memory access of given `size` and `align`
374
+ /// Check if the given pointerpoints to live memory of given `size` and `align`
376
375
/// (ignoring `M::enforce_alignment`). The caller can control the error message for the
377
376
/// out-of-bounds case.
378
377
#[ inline( always) ]
@@ -384,7 +383,15 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
384
383
msg : CheckInAllocMsg ,
385
384
) -> InterpResult < ' tcx > {
386
385
self . check_and_deref_ptr ( ptr, size, Some ( align) , msg, |alloc_id, _, _| {
387
- let ( size, align) = self . get_size_and_align ( alloc_id, AllocCheck :: Dereferenceable ) ?;
386
+ let check = match msg {
387
+ CheckInAllocMsg :: DerefTest | CheckInAllocMsg :: MemoryAccessTest => {
388
+ AllocCheck :: Dereferenceable
389
+ }
390
+ CheckInAllocMsg :: PointerArithmeticTest | CheckInAllocMsg :: InboundsTest => {
391
+ AllocCheck :: Live
392
+ }
393
+ } ;
394
+ let ( size, align) = self . get_size_and_align ( alloc_id, check) ?;
388
395
Ok ( ( size, align, ( ) ) )
389
396
} ) ?;
390
397
Ok ( ( ) )
@@ -551,8 +558,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
551
558
// `get_global_alloc` that we can actually use directly without inserting anything anywhere.
552
559
// So the error type is `InterpResult<'tcx, &Allocation<M::PointerTag>>`.
553
560
let a = self . alloc_map . get_or ( id, || {
554
- let alloc = self . get_global_alloc ( id, /*is_write*/ false )
555
- . map_err ( Err ) ?;
561
+ let alloc = self . get_global_alloc ( id, /*is_write*/ false ) . map_err ( Err ) ?;
556
562
match alloc {
557
563
Cow :: Borrowed ( alloc) => {
558
564
// We got a ref, cheaply return that as an "error" so that the
0 commit comments