@@ -421,6 +421,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
421
421
/// The `GlobalAlloc::Memory` branch here is still reachable though; when a static
422
422
/// contains a reference to memory that was created during its evaluation (i.e., not to
423
423
/// another static), those inner references only exist in "resolved" form.
424
+ ///
425
+ /// Assumes `id` is already canonical.
424
426
fn get_static_alloc (
425
427
memory_extra : & M :: MemoryExtra ,
426
428
tcx : TyCtxtAt < ' tcx > ,
@@ -434,31 +436,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
434
436
Some ( GlobalAlloc :: Static ( def_id) ) => {
435
437
// We got a "lazy" static that has not been computed yet.
436
438
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 )
461
441
}
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)
462
463
}
463
464
} ;
464
465
// 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> {
478
479
& self ,
479
480
id : AllocId ,
480
481
) -> InterpResult < ' tcx , & Allocation < M :: PointerTag , M :: AllocExtra > > {
482
+ let id = M :: canonical_alloc_id ( self , id) ;
481
483
// The error type of the inner closure here is somewhat funny. We have two
482
484
// ways of "erroring": An actual error, or because we got a reference from
483
485
// `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> {
513
515
& mut self ,
514
516
id : AllocId ,
515
517
) -> InterpResult < ' tcx , & mut Allocation < M :: PointerTag , M :: AllocExtra > > {
518
+ let id = M :: canonical_alloc_id ( self , id) ;
516
519
let tcx = self . tcx ;
517
520
let memory_extra = & self . extra ;
518
521
let a = self . alloc_map . get_mut_or ( id, || {
@@ -550,6 +553,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
550
553
id : AllocId ,
551
554
liveness : AllocCheck ,
552
555
) -> InterpResult < ' static , ( Size , Align ) > {
556
+ let id = M :: canonical_alloc_id ( self , id) ;
553
557
// # Regular allocations
554
558
// Don't use `self.get_raw` here as that will
555
559
// 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> {
602
606
}
603
607
}
604
608
609
+ /// Assumes `id` is already canonical.
605
610
fn get_fn_alloc ( & self , id : AllocId ) -> Option < FnVal < ' tcx , M :: ExtraFnVal > > {
606
611
trace ! ( "reading fn ptr: {}" , id) ;
607
612
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> {
622
627
if ptr. offset . bytes ( ) != 0 {
623
628
throw_unsup ! ( InvalidFunctionPointer )
624
629
}
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 ( ) )
626
632
}
627
633
628
634
pub fn mark_immutable ( & mut self , id : AllocId ) -> InterpResult < ' tcx > {
0 commit comments