@@ -166,9 +166,6 @@ impl Provenance for Tag {
166
166
/// Extra per-allocation data
167
167
#[ derive( Debug , Clone ) ]
168
168
pub 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 ,
172
169
/// Stacked Borrows state is only added if it is enabled.
173
170
pub stacked_borrows : Option < stacked_borrows:: AllocExtra > ,
174
171
/// Data race detection via the use of a vector-clock,
@@ -579,7 +576,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
579
576
} ;
580
577
let alloc: Allocation < Tag , Self :: AllocExtra > = alloc. convert_tag_add_extra (
581
578
& ecx. tcx ,
582
- AllocExtra { alloc_id : id , stacked_borrows : stacks, data_race : race_alloc } ,
579
+ AllocExtra { stacked_borrows : stacks, data_race : race_alloc } ,
583
580
|ptr| Evaluator :: tag_alloc_base_pointer ( ecx, ptr) ,
584
581
) ;
585
582
Cow :: Owned ( alloc)
@@ -611,15 +608,29 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
611
608
612
609
/// Convert a pointer with provenance into an allocation-offset pair,
613
610
/// or a `None` with an absolute address if that conversion is not possible.
614
- fn ptr_get_alloc (
611
+ fn ptr_reify_alloc (
615
612
ecx : & MiriEvalContext < ' mir , ' tcx > ,
616
613
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
+ } )
619
622
}
620
623
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
+ }
623
634
}
624
635
625
636
#[ inline( always) ]
@@ -630,12 +641,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
630
641
tag : Tag ,
631
642
range : AllocRange ,
632
643
) -> 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
+
633
650
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 ( ) ) ?;
635
652
}
636
653
if let Some ( stacked_borrows) = & alloc_extra. stacked_borrows {
637
654
stacked_borrows. memory_read (
638
- alloc_extra . alloc_id ,
655
+ alloc_id,
639
656
tag. sb ,
640
657
range,
641
658
machine. stacked_borrows . as_ref ( ) . unwrap ( ) ,
@@ -653,12 +670,18 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
653
670
tag : Tag ,
654
671
range : AllocRange ,
655
672
) -> 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
+
656
679
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 ( ) ) ?;
658
681
}
659
682
if let Some ( stacked_borrows) = & mut alloc_extra. stacked_borrows {
660
683
stacked_borrows. memory_written (
661
- alloc_extra . alloc_id ,
684
+ alloc_id,
662
685
tag. sb ,
663
686
range,
664
687
machine. stacked_borrows . as_mut ( ) . unwrap ( ) ,
@@ -676,19 +699,21 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
676
699
tag : Tag ,
677
700
range : AllocRange ,
678
701
) -> 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) ) ;
681
710
}
682
711
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 ( ) ) ?;
688
713
}
689
714
if let Some ( stacked_borrows) = & mut alloc_extra. stacked_borrows {
690
715
stacked_borrows. memory_deallocated (
691
- alloc_extra . alloc_id ,
716
+ alloc_id,
692
717
tag. sb ,
693
718
range,
694
719
machine. stacked_borrows . as_mut ( ) . unwrap ( ) ,
0 commit comments