@@ -166,9 +166,6 @@ impl Provenance for Tag {
166166/// Extra per-allocation data
167167#[ derive( Debug , Clone ) ]
168168pub struct AllocExtra {
169- // TODO: this really doesn't need to be here,
170- // but we're forced to bodge it here for now
171- pub alloc_id : AllocId ,
172169 /// Stacked Borrows state is only added if it is enabled.
173170 pub stacked_borrows : Option < stacked_borrows:: AllocExtra > ,
174171 /// Data race detection via the use of a vector-clock,
@@ -579,7 +576,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
579576 } ;
580577 let alloc: Allocation < Tag , Self :: AllocExtra > = alloc. convert_tag_add_extra (
581578 & ecx. tcx ,
582- AllocExtra { alloc_id : id , stacked_borrows : stacks, data_race : race_alloc } ,
579+ AllocExtra { stacked_borrows : stacks, data_race : race_alloc } ,
583580 |ptr| Evaluator :: tag_alloc_base_pointer ( ecx, ptr) ,
584581 ) ;
585582 Cow :: Owned ( alloc)
@@ -611,15 +608,29 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
611608
612609 /// Convert a pointer with provenance into an allocation-offset pair,
613610 /// or a `None` with an absolute address if that conversion is not possible.
614- fn ptr_get_alloc (
611+ fn ptr_reify_alloc (
615612 ecx : & MiriEvalContext < ' mir , ' tcx > ,
616613 ptr : Pointer < Self :: PointerTag > ,
617- ) -> Option < ( AllocId , Size ) > {
618- intptrcast:: GlobalStateInner :: abs_ptr_to_rel ( ecx, ptr)
614+ ) -> Option < ( AllocId , Size , Pointer < Self :: PointerTag > ) > {
615+ let rel_ptr = intptrcast:: GlobalStateInner :: abs_ptr_to_rel ( ecx, ptr) ;
616+ rel_ptr. map ( |( alloc_id, size) | {
617+ let new_ptr =
618+ ptr. map_provenance ( |t| Tag { alloc_id : AllocType :: Concrete ( alloc_id) , ..t } ) ;
619+
620+ ( alloc_id, size, new_ptr)
621+ } )
619622 }
620623
621- fn expose_addr ( ecx : & MiriEvalContext < ' mir , ' tcx > , ptr : Pointer < Self :: PointerTag > ) {
622- intptrcast:: GlobalStateInner :: expose_addr ( ecx, ptr)
624+ fn expose_ptr ( ecx : & InterpCx < ' mir , ' tcx , Self > , ptr : Pointer < Self :: PointerTag > ) {
625+ let ( tag, _) = ptr. into_parts ( ) ;
626+
627+ if let AllocType :: Concrete ( alloc_id) = tag. alloc_id {
628+ intptrcast:: GlobalStateInner :: expose_addr ( ecx, alloc_id) ;
629+
630+ if let Some ( stacked_borrows) = & ecx. machine . stacked_borrows {
631+ stacked_borrows. borrow_mut ( ) . expose_ptr ( tag. sb )
632+ }
633+ }
623634 }
624635
625636 #[ inline( always) ]
@@ -630,12 +641,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
630641 tag : Tag ,
631642 range : AllocRange ,
632643 ) -> InterpResult < ' tcx > {
644+ let alloc_id = if let AllocType :: Concrete ( alloc_id) = tag. alloc_id {
645+ alloc_id
646+ } else {
647+ bug ! ( "`memory_read` called with non-concrete tag" )
648+ } ;
649+
633650 if let Some ( data_race) = & alloc_extra. data_race {
634- data_race. read ( alloc_extra . alloc_id , range, machine. data_race . as_ref ( ) . unwrap ( ) ) ?;
651+ data_race. read ( alloc_id, range, machine. data_race . as_ref ( ) . unwrap ( ) ) ?;
635652 }
636653 if let Some ( stacked_borrows) = & alloc_extra. stacked_borrows {
637654 stacked_borrows. memory_read (
638- alloc_extra . alloc_id ,
655+ alloc_id,
639656 tag. sb ,
640657 range,
641658 machine. stacked_borrows . as_ref ( ) . unwrap ( ) ,
@@ -653,12 +670,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
653670 tag : Tag ,
654671 range : AllocRange ,
655672 ) -> InterpResult < ' tcx > {
673+ let alloc_id = if let AllocType :: Concrete ( alloc_id) = tag. alloc_id {
674+ alloc_id
675+ } else {
676+ bug ! ( "`memory_written` called with non-concrete tag" )
677+ } ;
678+
656679 if let Some ( data_race) = & mut alloc_extra. data_race {
657- data_race. write ( alloc_extra . alloc_id , range, machine. data_race . as_mut ( ) . unwrap ( ) ) ?;
680+ data_race. write ( alloc_id, range, machine. data_race . as_mut ( ) . unwrap ( ) ) ?;
658681 }
659682 if let Some ( stacked_borrows) = & mut alloc_extra. stacked_borrows {
660683 stacked_borrows. memory_written (
661- alloc_extra . alloc_id ,
684+ alloc_id,
662685 tag. sb ,
663686 range,
664687 machine. stacked_borrows . as_mut ( ) . unwrap ( ) ,
@@ -676,19 +699,21 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
676699 tag : Tag ,
677700 range : AllocRange ,
678701 ) -> InterpResult < ' tcx > {
679- if Some ( alloc_extra. alloc_id ) == machine. tracked_alloc_id {
680- register_diagnostic ( NonHaltingDiagnostic :: FreedAlloc ( alloc_extra. alloc_id ) ) ;
702+ let alloc_id = if let AllocType :: Concrete ( alloc_id) = tag. alloc_id {
703+ alloc_id
704+ } else {
705+ bug ! ( "`memory_deallocated` called with non-concrete tag" )
706+ } ;
707+
708+ if Some ( alloc_id) == machine. tracked_alloc_id {
709+ register_diagnostic ( NonHaltingDiagnostic :: FreedAlloc ( alloc_id) ) ;
681710 }
682711 if let Some ( data_race) = & mut alloc_extra. data_race {
683- data_race. deallocate (
684- alloc_extra. alloc_id ,
685- range,
686- machine. data_race . as_mut ( ) . unwrap ( ) ,
687- ) ?;
712+ data_race. deallocate ( alloc_id, range, machine. data_race . as_mut ( ) . unwrap ( ) ) ?;
688713 }
689714 if let Some ( stacked_borrows) = & mut alloc_extra. stacked_borrows {
690715 stacked_borrows. memory_deallocated (
691- alloc_extra . alloc_id ,
716+ alloc_id,
692717 tag. sb ,
693718 range,
694719 machine. stacked_borrows . as_mut ( ) . unwrap ( ) ,
0 commit comments