@@ -421,6 +421,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
421421 /// The `GlobalAlloc::Memory` branch here is still reachable though; when a static
422422 /// contains a reference to memory that was created during its evaluation (i.e., not to
423423 /// another static), those inner references only exist in "resolved" form.
424+ ///
425+ /// Assumes `id` is already canonical.
424426 fn get_static_alloc (
425427 memory_extra : & M :: MemoryExtra ,
426428 tcx : TyCtxtAt < ' tcx > ,
@@ -434,31 +436,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
434436 Some ( GlobalAlloc :: Static ( def_id) ) => {
435437 // We got a "lazy" static that has not been computed yet.
436438 if tcx. is_foreign_item ( def_id) {
437- trace ! ( "static_alloc: foreign item {:?}" , def_id) ;
438- M :: find_foreign_static ( tcx. tcx , def_id) ?
439- } else {
440- trace ! ( "static_alloc: Need to compute {:?}" , def_id) ;
441- let instance = Instance :: mono ( tcx. tcx , def_id) ;
442- let gid = GlobalId { instance, promoted : None } ;
443- // use the raw query here to break validation cycles. Later uses of the static
444- // will call the full query anyway
445- let raw_const =
446- tcx. const_eval_raw ( ty:: ParamEnv :: reveal_all ( ) . and ( gid) ) . map_err ( |err| {
447- // no need to report anything, the const_eval call takes care of that
448- // for statics
449- assert ! ( tcx. is_static( def_id) ) ;
450- match err {
451- ErrorHandled :: Reported => err_inval ! ( ReferencedConstant ) ,
452- ErrorHandled :: TooGeneric => err_inval ! ( TooGeneric ) ,
453- }
454- } ) ?;
455- // Make sure we use the ID of the resolved memory, not the lazy one!
456- let id = raw_const. alloc_id ;
457- let allocation = tcx. alloc_map . lock ( ) . unwrap_memory ( id) ;
458-
459- M :: before_access_static ( memory_extra, allocation) ?;
460- Cow :: Borrowed ( allocation)
439+ trace ! ( "get_static_alloc: foreign item {:?}" , def_id) ;
440+ throw_unsup ! ( ReadForeignStatic )
461441 }
442+ trace ! ( "get_static_alloc: Need to compute {:?}" , def_id) ;
443+ let instance = Instance :: mono ( tcx. tcx , def_id) ;
444+ let gid = GlobalId { instance, promoted : None } ;
445+ // use the raw query here to break validation cycles. Later uses of the static
446+ // will call the full query anyway
447+ let raw_const =
448+ tcx. const_eval_raw ( ty:: ParamEnv :: reveal_all ( ) . and ( gid) ) . map_err ( |err| {
449+ // no need to report anything, the const_eval call takes care of that
450+ // for statics
451+ assert ! ( tcx. is_static( def_id) ) ;
452+ match err {
453+ ErrorHandled :: Reported => err_inval ! ( ReferencedConstant ) ,
454+ ErrorHandled :: TooGeneric => err_inval ! ( TooGeneric ) ,
455+ }
456+ } ) ?;
457+ // Make sure we use the ID of the resolved memory, not the lazy one!
458+ let id = raw_const. alloc_id ;
459+ let allocation = tcx. alloc_map . lock ( ) . unwrap_memory ( id) ;
460+
461+ M :: before_access_static ( memory_extra, allocation) ?;
462+ Cow :: Borrowed ( allocation)
462463 }
463464 } ;
464465 // We got tcx memory. Let the machine initialize its "extra" stuff.
@@ -478,6 +479,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
478479 & self ,
479480 id : AllocId ,
480481 ) -> InterpResult < ' tcx , & Allocation < M :: PointerTag , M :: AllocExtra > > {
482+ let id = M :: canonical_alloc_id ( self , id) ;
481483 // The error type of the inner closure here is somewhat funny. We have two
482484 // ways of "erroring": An actual error, or because we got a reference from
483485 // `get_static_alloc` that we can actually use directly without inserting anything anywhere.
@@ -513,6 +515,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
513515 & mut self ,
514516 id : AllocId ,
515517 ) -> InterpResult < ' tcx , & mut Allocation < M :: PointerTag , M :: AllocExtra > > {
518+ let id = M :: canonical_alloc_id ( self , id) ;
516519 let tcx = self . tcx ;
517520 let memory_extra = & self . extra ;
518521 let a = self . alloc_map . get_mut_or ( id, || {
@@ -550,6 +553,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
550553 id : AllocId ,
551554 liveness : AllocCheck ,
552555 ) -> InterpResult < ' static , ( Size , Align ) > {
556+ let id = M :: canonical_alloc_id ( self , id) ;
553557 // # Regular allocations
554558 // Don't use `self.get_raw` here as that will
555559 // a) cause cycles in case `id` refers to a static
@@ -602,6 +606,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
602606 }
603607 }
604608
609+ /// Assumes `id` is already canonical.
605610 fn get_fn_alloc ( & self , id : AllocId ) -> Option < FnVal < ' tcx , M :: ExtraFnVal > > {
606611 trace ! ( "reading fn ptr: {}" , id) ;
607612 if let Some ( extra) = self . extra_fn_ptr_map . get ( & id) {
@@ -622,7 +627,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
622627 if ptr. offset . bytes ( ) != 0 {
623628 throw_unsup ! ( InvalidFunctionPointer )
624629 }
625- self . get_fn_alloc ( ptr. alloc_id ) . ok_or_else ( || err_unsup ! ( ExecuteMemory ) . into ( ) )
630+ let id = M :: canonical_alloc_id ( self , ptr. alloc_id ) ;
631+ self . get_fn_alloc ( id) . ok_or_else ( || err_unsup ! ( ExecuteMemory ) . into ( ) )
626632 }
627633
628634 pub fn mark_immutable ( & mut self , id : AllocId ) -> InterpResult < ' tcx > {
0 commit comments