@@ -535,14 +535,26 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
535
535
id : AllocId ,
536
536
liveness : AllocCheck ,
537
537
) -> InterpResult < ' static , ( Size , Align ) > {
538
+ // # Regular allocations
538
539
// Don't use `self.get` here as that will
539
540
// a) cause cycles in case `id` refers to a static
540
541
// b) duplicate a static's allocation in miri
541
542
if let Some ( ( _, alloc) ) = self . alloc_map . get ( id) {
542
543
return Ok ( ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align ) ) ;
543
544
}
544
- // Not a local allocation, check the global `tcx.alloc_map`.
545
545
546
+ // # Function pointers
547
+ // (both global from `alloc_map` and local from `extra_fn_ptr_map`)
548
+ if let Ok ( _) = self . get_fn_alloc ( id) {
549
+ return if let AllocCheck :: Dereferencable = liveness {
550
+ // The caller requested no function pointers.
551
+ err ! ( DerefFunctionPointer )
552
+ } else {
553
+ Ok ( ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
554
+ } ;
555
+ }
556
+
557
+ // # Statics
546
558
// Can't do this in the match argument, we may get cycle errors since the lock would
547
559
// be held throughout the match.
548
560
let alloc = self . tcx . alloc_map . lock ( ) . get ( id) ;
@@ -557,14 +569,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
557
569
// Need to duplicate the logic here, because the global allocations have
558
570
// different associated types than the interpreter-local ones.
559
571
Ok ( ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align ) ) ,
560
- Some ( GlobalAlloc :: Function ( _) ) => {
561
- if let AllocCheck :: Dereferencable = liveness {
562
- // The caller requested no function pointers.
563
- err ! ( DerefFunctionPointer )
564
- } else {
565
- Ok ( ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
566
- }
567
- } ,
572
+ Some ( GlobalAlloc :: Function ( _) ) =>
573
+ bug ! ( "We already checked function pointers above" ) ,
568
574
// The rest must be dead.
569
575
None => if let AllocCheck :: MaybeDead = liveness {
570
576
// Deallocated pointers are allowed, we should be able to find
0 commit comments