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