@@ -825,13 +825,13 @@ bool code_contractst::check_for_looped_mallocs(const goto_programt &program)
825825 return false ;
826826}
827827
828- bool code_contractst::add_pointer_checks (const std::string &function_name )
828+ bool code_contractst::check_frame_conditions_function (const irep_idt &function )
829829{
830830 // Get the function object before instrumentation.
831- auto old_function = goto_functions.function_map .find (function_name );
831+ auto old_function = goto_functions.function_map .find (function );
832832 if (old_function == goto_functions.function_map .end ())
833833 {
834- log.error () << " Could not find function '" << function_name
834+ log.error () << " Could not find function '" << function
835835 << " ' in goto-program; not enforcing contracts."
836836 << messaget::eom;
837837 return true ;
@@ -842,22 +842,25 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
842842 return false ;
843843 }
844844
845- const irep_idt function_id (function_name);
846- const symbolt &function_symbol = ns.lookup (function_id);
847- const auto &type = to_code_with_contract_type (function_symbol.type );
845+ if (check_for_looped_mallocs (program))
846+ {
847+ return true ;
848+ }
848849
849- exprt assigns_expr = type.assigns ();
850+ // Insert aliasing assertions
851+ check_frame_conditions (program, ns.lookup (function));
850852
851- assigns_clauset assigns (assigns_expr, *this , function_id, log);
853+ return false ;
854+ }
852855
853- goto_programt::instructionst::iterator instruction_it =
854- program.instructions .begin ();
856+ void code_contractst::check_frame_conditions (
857+ goto_programt &program,
858+ const symbolt &target)
859+ {
860+ const auto &type = to_code_with_contract_type (target.type );
861+ exprt assigns_expr = type.assigns ();
855862
856- // Create temporary variables to hold the assigns
857- // clause targets before they can be modified.
858- goto_programt standin_decls = assigns.init_block (function_symbol.location );
859- goto_programt mark_dead = assigns.dead_stmts (
860- function_symbol.location , function_name, function_symbol.mode );
863+ assigns_clauset assigns (assigns_expr, *this , target.name , log);
861864
862865 // Create a list of variables that are okay to assign.
863866 std::set<irep_idt> freely_assignable_symbols;
@@ -866,16 +869,19 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
866869 freely_assignable_symbols.insert (param.get_identifier ());
867870 }
868871
872+ goto_programt::instructionst::iterator instruction_it =
873+ program.instructions .begin ();
874+
875+ // Create temporary variables to hold the assigns
876+ // clause targets before they can be modified.
877+ goto_programt standin_decls = assigns.init_block (target.location );
878+ goto_programt mark_dead =
879+ assigns.dead_stmts (target.location , target.name , target.mode );
880+
869881 int lines_to_iterate = standin_decls.instructions .size ();
870882 program.insert_before_swap (instruction_it, standin_decls);
871883 std::advance (instruction_it, lines_to_iterate);
872884
873- if (check_for_looped_mallocs (program))
874- {
875- return true ;
876- }
877-
878- // Insert aliasing assertions
879885 for (; instruction_it != program.instructions .end (); ++instruction_it)
880886 {
881887 if (instruction_it->is_decl ())
@@ -909,7 +915,7 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
909915 instruction_it,
910916 program,
911917 assigns_expr,
912- function_id ,
918+ target. name ,
913919 freely_assignable_symbols,
914920 assigns);
915921 }
@@ -924,26 +930,24 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
924930 // Make sure the temporary symbols are marked dead
925931 lines_to_iterate = mark_dead.instructions .size ();
926932 program.insert_before_swap (instruction_it, mark_dead);
927-
928- return false ;
929933}
930934
931- bool code_contractst::enforce_contract (const std::string &fun_to_enforce )
935+ bool code_contractst::enforce_contract (const irep_idt &function )
932936{
933937 // Add statements to the source function
934938 // to ensure assigns clause is respected.
935- add_pointer_checks (fun_to_enforce );
939+ check_frame_conditions_function (function );
936940
937941 // Rename source function
938942 std::stringstream ss;
939- ss << CPROVER_PREFIX << " contracts_original_" << fun_to_enforce ;
943+ ss << CPROVER_PREFIX << " contracts_original_" << function ;
940944 const irep_idt mangled (ss.str ());
941- const irep_idt original (fun_to_enforce );
945+ const irep_idt original (function );
942946
943947 auto old_function = goto_functions.function_map .find (original);
944948 if (old_function == goto_functions.function_map .end ())
945949 {
946- log.error () << " Could not find function '" << fun_to_enforce
950+ log.error () << " Could not find function '" << function
947951 << " ' in goto-program; not enforcing contracts."
948952 << messaget::eom;
949953 return true ;
@@ -972,7 +976,7 @@ bool code_contractst::enforce_contract(const std::string &fun_to_enforce)
972976 auto nexist_old_function = goto_functions.function_map .find (original);
973977 INVARIANT (
974978 nexist_old_function == goto_functions.function_map .end (),
975- " There should be no function called " + fun_to_enforce +
979+ " There should be no function called " + id2string (function) +
976980 " in the function map because that function should have had its"
977981 " name mangled" );
978982
0 commit comments