@@ -705,6 +705,30 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
705
705
protect : bool ,
706
706
) -> InterpResult < ' tcx > {
707
707
let this = self . eval_context_mut ( ) ;
708
+ let current_span = & mut this. machine . current_span ( ) ;
709
+
710
+ let log_creation = |this : & MiriEvalContext < ' mir , ' tcx > ,
711
+ current_span : & mut CurrentSpan < ' _ , ' mir , ' tcx > ,
712
+ alloc_id,
713
+ base_offset,
714
+ orig_tag|
715
+ -> InterpResult < ' tcx > {
716
+ let extra = this. get_alloc_extra ( alloc_id) ?;
717
+ let stacked_borrows =
718
+ extra. stacked_borrows . as_ref ( ) . expect ( "we should have Stacked Borrows data" ) ;
719
+ let mut alloc_history = stacked_borrows. history . borrow_mut ( ) ;
720
+ alloc_history. log_creation (
721
+ Some ( orig_tag) ,
722
+ new_tag,
723
+ alloc_range ( base_offset, size) ,
724
+ current_span,
725
+ ) ;
726
+ if protect {
727
+ alloc_history. log_protector ( orig_tag, new_tag, current_span) ;
728
+ }
729
+ Ok ( ( ) )
730
+ } ;
731
+
708
732
if size == Size :: ZERO {
709
733
// Don't update any stacks for a zero-sized access; borrow stacks are per-byte and this
710
734
// touches no bytes so there is no stack to put this tag in.
@@ -714,16 +738,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
714
738
// Dangling slices are a common case here; it's valid to get their length but with raw
715
739
// pointer tagging for example all calls to get_unchecked on them are invalid.
716
740
if let Ok ( ( alloc_id, base_offset, orig_tag) ) = this. ptr_try_get_alloc_id ( place. ptr ) {
717
- let extra = this. get_alloc_extra ( alloc_id) ?;
718
- let stacked_borrows =
719
- extra. stacked_borrows . as_ref ( ) . expect ( "we should have Stacked Borrows data" ) ;
720
- let mut alloc_history = stacked_borrows. history . borrow_mut ( ) ;
721
- alloc_history. log_creation (
722
- Some ( orig_tag) ,
723
- new_tag,
724
- alloc_range ( base_offset, Size :: ZERO ) ,
725
- & mut this. machine . current_span ( ) ,
726
- ) ;
741
+ log_creation ( this, current_span, alloc_id, base_offset, orig_tag) ?;
727
742
}
728
743
729
744
trace ! (
@@ -736,23 +751,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
736
751
return Ok ( ( ) ) ;
737
752
}
738
753
let ( alloc_id, base_offset, orig_tag) = this. ptr_get_alloc_id ( place. ptr ) ?;
739
-
740
- let mut current_span = this. machine . current_span ( ) ;
741
- {
742
- let extra = this. get_alloc_extra ( alloc_id) ?;
743
- let stacked_borrows =
744
- extra. stacked_borrows . as_ref ( ) . expect ( "we should have Stacked Borrows data" ) ;
745
- let mut alloc_history = stacked_borrows. history . borrow_mut ( ) ;
746
- alloc_history. log_creation (
747
- Some ( orig_tag) ,
748
- new_tag,
749
- alloc_range ( base_offset, size) ,
750
- & mut current_span,
751
- ) ;
752
- if protect {
753
- alloc_history. log_protector ( orig_tag, new_tag, & mut current_span) ;
754
- }
755
- }
754
+ log_creation ( this, current_span, alloc_id, base_offset, orig_tag) ?;
756
755
757
756
// Ensure we bail out if the pointer goes out-of-bounds (see miri#1050).
758
757
let ( alloc_size, _) =
@@ -819,7 +818,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
819
818
item,
820
819
( alloc_id, range, offset) ,
821
820
& mut * global,
822
- & mut current_span,
821
+ current_span,
823
822
history,
824
823
)
825
824
} )
@@ -836,14 +835,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
836
835
let item = Item { perm, tag : new_tag, protector } ;
837
836
let range = alloc_range ( base_offset, size) ;
838
837
let mut global = machine. stacked_borrows . as_ref ( ) . unwrap ( ) . borrow_mut ( ) ;
839
- let mut current_span = machine. current_span ( ) ;
838
+ let current_span = & mut machine. current_span ( ) ; // `get_alloc_extra_mut` invalidated our old `current_span`
840
839
stacked_borrows. for_each_mut ( range, |offset, stack, history| {
841
840
stack. grant (
842
841
orig_tag,
843
842
item,
844
843
( alloc_id, range, offset) ,
845
844
& mut global,
846
- & mut current_span,
845
+ current_span,
847
846
history,
848
847
)
849
848
} ) ?;
0 commit comments