@@ -317,7 +317,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
317
317
kind = "static_mem"
318
318
)
319
319
}
320
- None => err_ub ! ( PointerUseAfterFree ( alloc_id) ) ,
320
+ None => err_ub ! ( PointerUseAfterFree ( alloc_id, CheckInAllocMsg :: MemoryAccessTest ) ) ,
321
321
}
322
322
. into ( ) ) ;
323
323
} ;
@@ -380,7 +380,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
380
380
M :: enforce_alignment ( self ) ,
381
381
CheckInAllocMsg :: MemoryAccessTest ,
382
382
|alloc_id, offset, prov| {
383
- let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id) ?;
383
+ let ( size, align) = self
384
+ . get_live_alloc_size_and_align ( alloc_id, CheckInAllocMsg :: MemoryAccessTest ) ?;
384
385
Ok ( ( size, align, ( alloc_id, offset, prov) ) )
385
386
} ,
386
387
)
@@ -404,7 +405,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
404
405
CheckAlignment :: Error ,
405
406
msg,
406
407
|alloc_id, _, _| {
407
- let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id) ?;
408
+ let ( size, align) = self . get_live_alloc_size_and_align ( alloc_id, msg ) ?;
408
409
Ok ( ( size, align, ( ) ) )
409
410
} ,
410
411
) ?;
@@ -414,7 +415,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
414
415
/// Low-level helper function to check if a ptr is in-bounds and potentially return a reference
415
416
/// to the allocation it points to. Supports both shared and mutable references, as the actual
416
417
/// checking is offloaded to a helper closure. `align` defines whether and which alignment check
417
- /// is done. Returns `None` for size 0, and otherwise `Some` of what `alloc_size` returned.
418
+ /// is done.
419
+ ///
420
+ /// If this returns `None`, the size is 0; it can however return `Some` even for size 0.
418
421
fn check_and_deref_ptr < T > (
419
422
& self ,
420
423
ptr : Pointer < Option < M :: Provenance > > ,
@@ -515,7 +518,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
515
518
}
516
519
Some ( GlobalAlloc :: Function ( ..) ) => throw_ub ! ( DerefFunctionPointer ( id) ) ,
517
520
Some ( GlobalAlloc :: VTable ( ..) ) => throw_ub ! ( DerefVTablePointer ( id) ) ,
518
- None => throw_ub ! ( PointerUseAfterFree ( id) ) ,
521
+ None => throw_ub ! ( PointerUseAfterFree ( id, CheckInAllocMsg :: MemoryAccessTest ) ) ,
519
522
Some ( GlobalAlloc :: Static ( def_id) ) => {
520
523
assert ! ( self . tcx. is_static( def_id) ) ;
521
524
assert ! ( !self . tcx. is_thread_local_static( def_id) ) ;
@@ -761,11 +764,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
761
764
}
762
765
}
763
766
764
- /// Obtain the size and alignment of a live allocation.
765
- pub fn get_live_alloc_size_and_align ( & self , id : AllocId ) -> InterpResult < ' tcx , ( Size , Align ) > {
767
+ /// Obtain the size and alignment of a *live* allocation.
768
+ fn get_live_alloc_size_and_align (
769
+ & self ,
770
+ id : AllocId ,
771
+ msg : CheckInAllocMsg ,
772
+ ) -> InterpResult < ' tcx , ( Size , Align ) > {
766
773
let ( size, align, kind) = self . get_alloc_info ( id) ;
767
774
if matches ! ( kind, AllocKind :: Dead ) {
768
- throw_ub ! ( PointerUseAfterFree ( id) )
775
+ throw_ub ! ( PointerUseAfterFree ( id, msg ) )
769
776
}
770
777
Ok ( ( size, align) )
771
778
}
0 commit comments