@@ -506,15 +506,57 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
506506 }
507507
508508 #[ inline( always) ]
509- fn before_deallocation (
510- memory_extra : & mut Self :: MemoryExtra ,
511- id : AllocId ,
509+ fn memory_read (
510+ _memory_extra : & Self :: MemoryExtra ,
511+ alloc : & Allocation < Tag , AllocExtra > ,
512+ ptr : Pointer < Tag > ,
513+ size : Size ,
512514 ) -> InterpResult < ' tcx > {
513- if Some ( id ) == memory_extra . tracked_alloc_id {
514- register_diagnostic ( NonHaltingDiagnostic :: FreedAlloc ( id ) ) ;
515+ if let Some ( data_race ) = & alloc . extra . data_race {
516+ data_race . read ( ptr , size ) ? ;
515517 }
518+ if let Some ( stacked_borrows) = & alloc. extra . stacked_borrows {
519+ stacked_borrows. memory_read ( ptr, size)
520+ } else {
521+ Ok ( ( ) )
522+ }
523+ }
516524
517- Ok ( ( ) )
525+ #[ inline( always) ]
526+ fn memory_written (
527+ _memory_extra : & mut Self :: MemoryExtra ,
528+ alloc : & mut Allocation < Tag , AllocExtra > ,
529+ ptr : Pointer < Tag > ,
530+ size : Size ,
531+ ) -> InterpResult < ' tcx > {
532+ if let Some ( data_race) = & mut alloc. extra . data_race {
533+ data_race. write ( ptr, size) ?;
534+ }
535+ if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
536+ stacked_borrows. memory_written ( ptr, size)
537+ } else {
538+ Ok ( ( ) )
539+ }
540+ }
541+
542+ #[ inline( always) ]
543+ fn memory_deallocated (
544+ memory_extra : & mut Self :: MemoryExtra ,
545+ alloc : & mut Allocation < Tag , AllocExtra > ,
546+ ptr : Pointer < Tag > ,
547+ ) -> InterpResult < ' tcx > {
548+ let size = alloc. size ( ) ;
549+ if Some ( ptr. alloc_id ) == memory_extra. tracked_alloc_id {
550+ register_diagnostic ( NonHaltingDiagnostic :: FreedAlloc ( ptr. alloc_id ) ) ;
551+ }
552+ if let Some ( data_race) = & mut alloc. extra . data_race {
553+ data_race. deallocate ( ptr, size) ?;
554+ }
555+ if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
556+ stacked_borrows. memory_deallocated ( ptr, size)
557+ } else {
558+ Ok ( ( ) )
559+ }
518560 }
519561
520562 fn after_static_mem_initialized (
@@ -601,53 +643,3 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
601643 intptrcast:: GlobalState :: ptr_to_int ( ptr, memory)
602644 }
603645}
604-
605- impl AllocationExtra < Tag > for AllocExtra {
606- #[ inline( always) ]
607- fn memory_read < ' tcx > (
608- alloc : & Allocation < Tag , AllocExtra > ,
609- ptr : Pointer < Tag > ,
610- size : Size ,
611- ) -> InterpResult < ' tcx > {
612- if let Some ( data_race) = & alloc. extra . data_race {
613- data_race. read ( ptr, size) ?;
614- }
615- if let Some ( stacked_borrows) = & alloc. extra . stacked_borrows {
616- stacked_borrows. memory_read ( ptr, size)
617- } else {
618- Ok ( ( ) )
619- }
620- }
621-
622- #[ inline( always) ]
623- fn memory_written < ' tcx > (
624- alloc : & mut Allocation < Tag , AllocExtra > ,
625- ptr : Pointer < Tag > ,
626- size : Size ,
627- ) -> InterpResult < ' tcx > {
628- if let Some ( data_race) = & mut alloc. extra . data_race {
629- data_race. write ( ptr, size) ?;
630- }
631- if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
632- stacked_borrows. memory_written ( ptr, size)
633- } else {
634- Ok ( ( ) )
635- }
636- }
637-
638- #[ inline( always) ]
639- fn memory_deallocated < ' tcx > (
640- alloc : & mut Allocation < Tag , AllocExtra > ,
641- ptr : Pointer < Tag > ,
642- size : Size ,
643- ) -> InterpResult < ' tcx > {
644- if let Some ( data_race) = & mut alloc. extra . data_race {
645- data_race. deallocate ( ptr, size) ?;
646- }
647- if let Some ( stacked_borrows) = & mut alloc. extra . stacked_borrows {
648- stacked_borrows. memory_deallocated ( ptr, size)
649- } else {
650- Ok ( ( ) )
651- }
652- }
653- }
0 commit comments