@@ -150,7 +150,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
150150 /// through a pointer that was created by the program.
151151 #[ inline]
152152 pub fn tag_static_base_pointer ( & self , ptr : Pointer ) -> Pointer < M :: PointerTag > {
153- ptr. with_tag ( M :: tag_static_base_pointer ( & self . extra , ptr. alloc_id ) )
153+ let id = M :: canonical_alloc_id ( self , ptr. alloc_id ) ;
154+ ptr. with_tag ( M :: tag_static_base_pointer ( & self . extra , id) )
154155 }
155156
156157 pub fn create_fn_alloc (
@@ -421,6 +422,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
421422 /// The `GlobalAlloc::Memory` branch here is still reachable though; when a static
422423 /// contains a reference to memory that was created during its evaluation (i.e., not to
423424 /// another static), those inner references only exist in "resolved" form.
425+ ///
426+ /// Assumes `id` is already canonical.
424427 fn get_static_alloc (
425428 memory_extra : & M :: MemoryExtra ,
426429 tcx : TyCtxtAt < ' tcx > ,
@@ -434,31 +437,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
434437 Some ( GlobalAlloc :: Static ( def_id) ) => {
435438 // We got a "lazy" static that has not been computed yet.
436439 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)
440+ trace ! ( "get_static_alloc: foreign item {:?}" , def_id) ;
441+ throw_unsup ! ( ReadForeignStatic )
461442 }
443+ trace ! ( "get_static_alloc: Need to compute {:?}" , def_id) ;
444+ let instance = Instance :: mono ( tcx. tcx , def_id) ;
445+ let gid = GlobalId { instance, promoted : None } ;
446+ // use the raw query here to break validation cycles. Later uses of the static
447+ // will call the full query anyway
448+ let raw_const =
449+ tcx. const_eval_raw ( ty:: ParamEnv :: reveal_all ( ) . and ( gid) ) . map_err ( |err| {
450+ // no need to report anything, the const_eval call takes care of that
451+ // for statics
452+ assert ! ( tcx. is_static( def_id) ) ;
453+ match err {
454+ ErrorHandled :: Reported => err_inval ! ( ReferencedConstant ) ,
455+ ErrorHandled :: TooGeneric => err_inval ! ( TooGeneric ) ,
456+ }
457+ } ) ?;
458+ // Make sure we use the ID of the resolved memory, not the lazy one!
459+ let id = raw_const. alloc_id ;
460+ let allocation = tcx. alloc_map . lock ( ) . unwrap_memory ( id) ;
461+
462+ M :: before_access_static ( memory_extra, allocation) ?;
463+ Cow :: Borrowed ( allocation)
462464 }
463465 } ;
464466 // We got tcx memory. Let the machine initialize its "extra" stuff.
@@ -478,6 +480,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
478480 & self ,
479481 id : AllocId ,
480482 ) -> InterpResult < ' tcx , & Allocation < M :: PointerTag , M :: AllocExtra > > {
483+ let id = M :: canonical_alloc_id ( self , id) ;
481484 // The error type of the inner closure here is somewhat funny. We have two
482485 // ways of "erroring": An actual error, or because we got a reference from
483486 // `get_static_alloc` that we can actually use directly without inserting anything anywhere.
@@ -513,6 +516,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
513516 & mut self ,
514517 id : AllocId ,
515518 ) -> InterpResult < ' tcx , & mut Allocation < M :: PointerTag , M :: AllocExtra > > {
519+ let id = M :: canonical_alloc_id ( self , id) ;
516520 let tcx = self . tcx ;
517521 let memory_extra = & self . extra ;
518522 let a = self . alloc_map . get_mut_or ( id, || {
@@ -550,6 +554,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
550554 id : AllocId ,
551555 liveness : AllocCheck ,
552556 ) -> InterpResult < ' static , ( Size , Align ) > {
557+ let id = M :: canonical_alloc_id ( self , id) ;
553558 // # Regular allocations
554559 // Don't use `self.get_raw` here as that will
555560 // a) cause cycles in case `id` refers to a static
@@ -602,6 +607,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
602607 }
603608 }
604609
610+ /// Assumes `id` is already canonical.
605611 fn get_fn_alloc ( & self , id : AllocId ) -> Option < FnVal < ' tcx , M :: ExtraFnVal > > {
606612 trace ! ( "reading fn ptr: {}" , id) ;
607613 if let Some ( extra) = self . extra_fn_ptr_map . get ( & id) {
@@ -622,7 +628,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
622628 if ptr. offset . bytes ( ) != 0 {
623629 throw_unsup ! ( InvalidFunctionPointer )
624630 }
625- self . get_fn_alloc ( ptr. alloc_id ) . ok_or_else ( || err_unsup ! ( ExecuteMemory ) . into ( ) )
631+ let id = M :: canonical_alloc_id ( self , ptr. alloc_id ) ;
632+ self . get_fn_alloc ( id) . ok_or_else ( || err_unsup ! ( ExecuteMemory ) . into ( ) )
626633 }
627634
628635 pub fn mark_immutable ( & mut self , id : AllocId ) -> InterpResult < ' tcx > {
0 commit comments