@@ -535,6 +535,19 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
535535 id : AllocId ,
536536 liveness : AllocCheck ,
537537 ) -> 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+ }
538551 // Regular allocations.
539552 if let Ok ( alloc) = self . get ( id) {
540553 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> {
548561 Ok ( ( Size :: ZERO , Align :: from_bytes ( 1 ) . unwrap ( ) ) )
549562 } ;
550563 }
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- }
565564 // The rest must be dead.
566565 if let AllocCheck :: MaybeDead = liveness {
567566 // Deallocated pointers are allowed, we should be able to find
0 commit comments