@@ -131,7 +131,14 @@ void instrument_spec_assignst::track_heap_allocated(
131
131
const exprt &expr,
132
132
goto_programt &dest)
133
133
{
134
- create_snapshot (create_car_from_heap_alloc (expr), dest);
134
+ // insert in tracking set
135
+ const auto &car = create_car_from_heap_alloc (expr);
136
+
137
+ // generate target validity check for this target.
138
+ target_validity_assertion (car, true , dest);
139
+
140
+ // generate snapshot instructions for this target.
141
+ create_snapshot (car, dest);
135
142
}
136
143
137
144
void instrument_spec_assignst::check_inclusion_assignment (
@@ -416,7 +423,7 @@ void instrument_spec_assignst::track_spec_target_group(
416
423
cleanert cleaner (st, log .get_message_handler ());
417
424
exprt condition (group.condition ());
418
425
if (has_subexpr (condition, ID_side_effect))
419
- cleaner.clean (condition, dest, st. lookup_ref (function_id). mode );
426
+ cleaner.clean (condition, dest, mode);
420
427
421
428
// create conditional address ranges by distributing the condition
422
429
for (const auto &target : group.targets ())
@@ -451,8 +458,7 @@ const symbolt instrument_spec_assignst::create_fresh_symbol(
451
458
const typet &type,
452
459
const source_locationt &location) const
453
460
{
454
- return new_tmp_symbol (
455
- type, location, st.lookup_ref (function_id).mode , st, suffix);
461
+ return new_tmp_symbol (type, location, mode, st, suffix);
456
462
}
457
463
458
464
car_exprt instrument_spec_assignst::create_car_expr (
@@ -714,12 +720,25 @@ exprt instrument_spec_assignst::inclusion_check_full(
714
720
715
721
// Build a disjunction over all tracked locations
716
722
exprt::operandst disjuncts;
723
+ log .debug () << LOG_HEADER << " inclusion check: \n "
724
+ << from_expr_using_mode (ns, mode, car.target ()) << " in {"
725
+ << messaget::eom;
717
726
718
727
for (const auto &pair : from_spec_assigns)
728
+ {
719
729
disjuncts.push_back (inclusion_check_single (car, pair.second ));
730
+ log .debug () << " \t (spec) "
731
+ << from_expr_using_mode (ns, mode, pair.second .target ())
732
+ << messaget::eom;
733
+ }
720
734
721
- for (const auto &pair : from_heap_alloc)
722
- disjuncts.push_back (inclusion_check_single (car, pair.second ));
735
+ for (const auto &heap_car : from_heap_alloc)
736
+ {
737
+ disjuncts.push_back (inclusion_check_single (car, heap_car));
738
+ log .debug () << " \t (heap) "
739
+ << from_expr_using_mode (ns, mode, heap_car.target ())
740
+ << messaget::eom;
741
+ }
723
742
724
743
if (include_stack_allocated)
725
744
{
@@ -732,12 +751,21 @@ exprt instrument_spec_assignst::inclusion_check_full(
732
751
continue ;
733
752
734
753
disjuncts.push_back (inclusion_check_single (car, pair.second ));
754
+ log .debug () << " \t (stack) "
755
+ << from_expr_using_mode (ns, mode, pair.second .target ())
756
+ << messaget::eom;
735
757
}
736
758
737
759
// static locals are stack allocated and can never be DEAD
738
760
for (const auto &pair : from_static_local)
761
+ {
739
762
disjuncts.push_back (inclusion_check_single (car, pair.second ));
763
+ log .debug () << " \t (static) "
764
+ << from_expr_using_mode (ns, mode, pair.second .target ())
765
+ << messaget::eom;
766
+ }
740
767
}
768
+ log .debug () << " }" << messaget::eom;
741
769
742
770
if (allow_null_lhs)
743
771
return or_exprt{
@@ -793,21 +821,10 @@ const car_exprt &instrument_spec_assignst::create_car_from_stack_alloc(
793
821
const car_exprt &
794
822
instrument_spec_assignst::create_car_from_heap_alloc (const exprt &target)
795
823
{
796
- const auto &found = from_heap_alloc.find (target);
797
- if (found != from_heap_alloc.end ())
798
- {
799
- log .warning () << " Ignored duplicate heap-allocated target '"
800
- << from_expr (ns, target.id (), target) << " ' at "
801
- << target.source_location ().as_string () << messaget::eom;
802
- return found->second ;
803
- }
804
- else
805
- {
806
- log .debug () << LOG_HEADER << " creating CAR for heap-allocated target "
807
- << format (target) << messaget::eom;
808
- from_heap_alloc.insert ({target, create_car_expr (true_exprt{}, target)});
809
- return from_heap_alloc.find (target)->second ;
810
- }
824
+ log .debug () << LOG_HEADER << " creating CAR for heap-allocated target "
825
+ << format (target) << messaget::eom;
826
+ from_heap_alloc.emplace_back (create_car_expr (true_exprt{}, target));
827
+ return from_heap_alloc.back ();
811
828
}
812
829
813
830
const car_exprt &instrument_spec_assignst::create_car_from_static_local (
@@ -854,8 +871,8 @@ void instrument_spec_assignst::invalidate_heap_and_spec_aliases(
854
871
for (const auto &pair : from_spec_assigns)
855
872
invalidate_car (pair.second , freed_car, dest);
856
873
857
- for (const auto &pair : from_heap_alloc)
858
- invalidate_car (pair. second , freed_car, dest);
874
+ for (const auto &car : from_heap_alloc)
875
+ invalidate_car (car , freed_car, dest);
859
876
}
860
877
861
878
// / Returns true iff an `ASSIGN lhs := rhs` instruction must be instrumented.
0 commit comments