@@ -131,7 +131,14 @@ void instrument_spec_assignst::track_heap_allocated(
131131 const exprt &expr,
132132 goto_programt &dest)
133133{
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);
135142}
136143
137144void instrument_spec_assignst::check_inclusion_assignment (
@@ -416,7 +423,7 @@ void instrument_spec_assignst::track_spec_target_group(
416423 cleanert cleaner (st, log.get_message_handler ());
417424 exprt condition (group.condition ());
418425 if (has_subexpr (condition, ID_side_effect))
419- cleaner.clean (condition, dest, st. lookup_ref (function_id). mode );
426+ cleaner.clean (condition, dest, mode);
420427
421428 // create conditional address ranges by distributing the condition
422429 for (const auto &target : group.targets ())
@@ -451,8 +458,7 @@ const symbolt instrument_spec_assignst::create_fresh_symbol(
451458 const typet &type,
452459 const source_locationt &location) const
453460{
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);
456462}
457463
458464car_exprt instrument_spec_assignst::create_car_expr (
@@ -714,12 +720,25 @@ exprt instrument_spec_assignst::inclusion_check_full(
714720
715721 // Build a disjunction over all tracked locations
716722 exprt::operandst disjuncts;
723+ log.debug () << LOG_HEADER << " inclusion check: \n "
724+ << from_expr_using_mode (ns, mode, car.target ()) << " in {"
725+ << messaget::eom;
717726
718727 for (const auto &pair : from_spec_assigns)
728+ {
719729 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+ }
720734
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+ }
723742
724743 if (include_stack_allocated)
725744 {
@@ -732,12 +751,21 @@ exprt instrument_spec_assignst::inclusion_check_full(
732751 continue ;
733752
734753 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;
735757 }
736758
737759 // static locals are stack allocated and can never be DEAD
738760 for (const auto &pair : from_static_local)
761+ {
739762 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+ }
740767 }
768+ log.debug () << " }" << messaget::eom;
741769
742770 if (allow_null_lhs)
743771 return or_exprt{
@@ -793,21 +821,10 @@ const car_exprt &instrument_spec_assignst::create_car_from_stack_alloc(
793821const car_exprt &
794822instrument_spec_assignst::create_car_from_heap_alloc (const exprt &target)
795823{
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 ();
811828}
812829
813830const car_exprt &instrument_spec_assignst::create_car_from_static_local (
@@ -854,8 +871,8 @@ void instrument_spec_assignst::invalidate_heap_and_spec_aliases(
854871 for (const auto &pair : from_spec_assigns)
855872 invalidate_car (pair.second , freed_car, dest);
856873
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);
859876}
860877
861878// / Returns true iff an `ASSIGN lhs := rhs` instruction must be instrumented.
0 commit comments