@@ -111,7 +111,7 @@ pub struct GlobalState {
111111pub type MemoryExtra = RefCell < GlobalState > ;
112112
113113/// Indicates which kind of access is being performed.
114- #[ derive( Copy , Clone , Hash , PartialEq , Eq ) ]
114+ #[ derive( Copy , Clone , Hash , PartialEq , Eq , Debug ) ]
115115pub enum AccessKind {
116116 Read ,
117117 Write ,
@@ -296,19 +296,26 @@ impl<'tcx> Stack {
296296 }
297297
298298 /// Check if the given item is protected.
299+ ///
300+ /// The `provoking_access` argument is only used to produce diagnostics.
301+ /// It is `Some` when we are granting the contained access for said tag, and it is
302+ /// `None` during a deallocation.
299303 fn check_protector (
300304 item : & Item ,
301- tag : Option < SbTag > ,
305+ provoking_access : Option < ( SbTag , AccessKind ) > ,
302306 global : & GlobalState ,
303307 ) -> InterpResult < ' tcx > {
304308 if let SbTag :: Tagged ( id) = item. tag {
305309 if Some ( id) == global. tracked_pointer_tag {
306- register_diagnostic ( NonHaltingDiagnostic :: PoppedPointerTag ( item. clone ( ) ) ) ;
310+ register_diagnostic ( NonHaltingDiagnostic :: PoppedPointerTag (
311+ item. clone ( ) ,
312+ provoking_access,
313+ ) ) ;
307314 }
308315 }
309316 if let Some ( call) = item. protector {
310317 if global. is_active ( call) {
311- if let Some ( tag) = tag {
318+ if let Some ( ( tag, _ ) ) = provoking_access {
312319 Err ( err_sb_ub ( format ! (
313320 "not granting access to tag {:?} because incompatible item is protected: {:?}" ,
314321 tag, item
@@ -348,7 +355,7 @@ impl<'tcx> Stack {
348355 let first_incompatible_idx = self . find_first_write_incompatible ( granting_idx) ;
349356 for item in self . borrows . drain ( first_incompatible_idx..) . rev ( ) {
350357 trace ! ( "access: popping item {:?}" , item) ;
351- Stack :: check_protector ( & item, Some ( tag) , global) ?;
358+ Stack :: check_protector ( & item, Some ( ( tag, access ) ) , global) ?;
352359 }
353360 } else {
354361 // On a read, *disable* all `Unique` above the granting item. This ensures U2 for read accesses.
@@ -363,7 +370,7 @@ impl<'tcx> Stack {
363370 let item = & mut self . borrows [ idx] ;
364371 if item. perm == Permission :: Unique {
365372 trace ! ( "access: disabling item {:?}" , item) ;
366- Stack :: check_protector ( item, Some ( tag) , global) ?;
373+ Stack :: check_protector ( item, Some ( ( tag, access ) ) , global) ?;
367374 item. perm = Permission :: Disabled ;
368375 }
369376 }
0 commit comments