@@ -535,6 +535,19 @@ 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
+ // Allocations of `static` items
539
+ // Can't do this in the match argument, we may get cycle errors since the lock would
540
+ // be held throughout the match.
541
+ let alloc = self . tcx . alloc_map . lock ( ) . get ( id) ;
542
+ match alloc {
543
+ Some ( GlobalAlloc :: Static ( did) ) => {
544
+ // Use size and align of the type
545
+ let ty = self . tcx . type_of ( did) ;
546
+ let layout = self . tcx . layout_of ( ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) ;
547
+ return Ok ( ( layout. size , layout. align . abi ) ) ;
548
+ }
549
+ _ => { }
550
+ }
538
551
// Regular allocations.
539
552
if let Ok ( alloc) = self . get ( id) {
540
553
return Ok ( ( Size :: from_bytes ( alloc. bytes . len ( ) as u64 ) , alloc. align ) ) ;
@@ -548,20 +561,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
548
561
Ok ( ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
549
562
} ;
550
563
}
551
- // Foreign statics.
552
- // Can't do this in the match argument, we may get cycle errors since the lock would
553
- // be held throughout the match.
554
- let alloc = self . tcx . alloc_map . lock ( ) . get ( id) ;
555
- match alloc {
556
- Some ( GlobalAlloc :: Static ( did) ) => {
557
- assert ! ( self . tcx. is_foreign_item( did) ) ;
558
- // Use size and align of the type
559
- let ty = self . tcx . type_of ( did) ;
560
- let layout = self . tcx . layout_of ( ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) ;
561
- return Ok ( ( layout. size , layout. align . abi ) ) ;
562
- }
563
- _ => { }
564
- }
565
564
// The rest must be dead.
566
565
if let AllocCheck :: MaybeDead = liveness {
567
566
// Deallocated pointers are allowed, we should be able to find
0 commit comments