@@ -222,11 +222,9 @@ impl GlobalStateInner {
222
222
}
223
223
}
224
224
225
+ /// Generates a new pointer tag. Remember to also check track_pointer_tags and log its creation!
225
226
fn new_ptr ( & mut self ) -> SbTag {
226
227
let id = self . next_ptr_tag ;
227
- if self . tracked_pointer_tags . contains ( & id) {
228
- register_diagnostic ( NonHaltingDiagnostic :: CreatedPointerTag ( id. 0 ) ) ;
229
- }
230
228
self . next_ptr_tag = SbTag ( NonZeroU64 :: new ( id. 0 . get ( ) + 1 ) . unwrap ( ) ) ;
231
229
id
232
230
}
@@ -253,6 +251,9 @@ impl GlobalStateInner {
253
251
pub fn base_ptr_tag ( & mut self , id : AllocId ) -> SbTag {
254
252
self . base_ptr_tags . get ( & id) . copied ( ) . unwrap_or_else ( || {
255
253
let tag = self . new_ptr ( ) ;
254
+ if self . tracked_pointer_tags . contains ( & tag) {
255
+ register_diagnostic ( NonHaltingDiagnostic :: CreatedPointerTag ( tag. 0 , None ) ) ;
256
+ }
256
257
trace ! ( "New allocation {:?} has base tag {:?}" , id, tag) ;
257
258
self . base_ptr_tags . try_insert ( id, tag) . unwrap ( ) ;
258
259
tag
@@ -802,16 +803,28 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
802
803
let this = self . eval_context_mut ( ) ;
803
804
let current_span = & mut this. machine . current_span ( ) ;
804
805
806
+ // It is crucial that this gets called on all code paths, to ensure we track tag creation.
805
807
let log_creation = |this : & MiriEvalContext < ' mir , ' tcx > ,
806
808
current_span : & mut CurrentSpan < ' _ , ' mir , ' tcx > ,
807
809
alloc_id,
808
810
base_offset,
809
811
orig_tag|
810
812
-> InterpResult < ' tcx > {
813
+ let global = this. machine . stacked_borrows . as_ref ( ) . unwrap ( ) . borrow ( ) ;
814
+ if global. tracked_pointer_tags . contains ( & new_tag) {
815
+ register_diagnostic ( NonHaltingDiagnostic :: CreatedPointerTag (
816
+ new_tag. 0 ,
817
+ Some ( ( alloc_id, alloc_range ( base_offset, size) ) ) ,
818
+ ) ) ;
819
+ }
820
+ drop ( global) ; // don't hold that reference any longer than we have to
821
+
822
+ // The SB history tracking needs a parent tag, so skip if we come from a wildcard.
811
823
let SbTagExtra :: Concrete ( orig_tag) = orig_tag else {
812
824
// FIXME: should we log this?
813
825
return Ok ( ( ) )
814
826
} ;
827
+
815
828
let extra = this. get_alloc_extra ( alloc_id) ?;
816
829
let mut stacked_borrows = extra
817
830
. stacked_borrows
@@ -850,6 +863,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
850
863
return Ok ( Some ( alloc_id) ) ;
851
864
}
852
865
// This pointer doesn't come with an AllocId. :shrug:
866
+ register_diagnostic ( NonHaltingDiagnostic :: CreatedPointerTag ( new_tag. 0 , None ) ) ;
853
867
return Ok ( None ) ;
854
868
}
855
869
let ( alloc_id, base_offset, orig_tag) = this. ptr_get_alloc_id ( place. ptr ) ?;
0 commit comments