@@ -825,13 +825,13 @@ bool code_contractst::check_for_looped_mallocs(const goto_programt &program)
825
825
return false ;
826
826
}
827
827
828
- bool code_contractst::add_pointer_checks (const std::string &function_name )
828
+ bool code_contractst::check_frame_conditions_function (const irep_idt &function )
829
829
{
830
830
// 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 );
832
832
if (old_function == goto_functions.function_map .end ())
833
833
{
834
- log .error () << " Could not find function '" << function_name
834
+ log .error () << " Could not find function '" << function
835
835
<< " ' in goto-program; not enforcing contracts."
836
836
<< messaget::eom;
837
837
return true ;
@@ -842,22 +842,25 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
842
842
return false ;
843
843
}
844
844
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
+ }
848
849
849
- exprt assigns_expr = type.assigns ();
850
+ // Insert aliasing assertions
851
+ check_frame_conditions (program, ns.lookup (function));
850
852
851
- assigns_clauset assigns (assigns_expr, *this , function_id, log );
853
+ return false ;
854
+ }
852
855
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 ();
855
862
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 );
861
864
862
865
// Create a list of variables that are okay to assign.
863
866
std::set<irep_idt> freely_assignable_symbols;
@@ -866,16 +869,19 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
866
869
freely_assignable_symbols.insert (param.get_identifier ());
867
870
}
868
871
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
+
869
881
int lines_to_iterate = standin_decls.instructions .size ();
870
882
program.insert_before_swap (instruction_it, standin_decls);
871
883
std::advance (instruction_it, lines_to_iterate);
872
884
873
- if (check_for_looped_mallocs (program))
874
- {
875
- return true ;
876
- }
877
-
878
- // Insert aliasing assertions
879
885
for (; instruction_it != program.instructions .end (); ++instruction_it)
880
886
{
881
887
if (instruction_it->is_decl ())
@@ -909,7 +915,7 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
909
915
instruction_it,
910
916
program,
911
917
assigns_expr,
912
- function_id ,
918
+ target. name ,
913
919
freely_assignable_symbols,
914
920
assigns);
915
921
}
@@ -924,26 +930,24 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
924
930
// Make sure the temporary symbols are marked dead
925
931
lines_to_iterate = mark_dead.instructions .size ();
926
932
program.insert_before_swap (instruction_it, mark_dead);
927
-
928
- return false ;
929
933
}
930
934
931
- bool code_contractst::enforce_contract (const std::string &fun_to_enforce )
935
+ bool code_contractst::enforce_contract (const irep_idt &function )
932
936
{
933
937
// Add statements to the source function
934
938
// to ensure assigns clause is respected.
935
- add_pointer_checks (fun_to_enforce );
939
+ check_frame_conditions_function (function );
936
940
937
941
// Rename source function
938
942
std::stringstream ss;
939
- ss << CPROVER_PREFIX << " contracts_original_" << fun_to_enforce ;
943
+ ss << CPROVER_PREFIX << " contracts_original_" << function ;
940
944
const irep_idt mangled (ss.str ());
941
- const irep_idt original (fun_to_enforce );
945
+ const irep_idt original (function );
942
946
943
947
auto old_function = goto_functions.function_map .find (original);
944
948
if (old_function == goto_functions.function_map .end ())
945
949
{
946
- log .error () << " Could not find function '" << fun_to_enforce
950
+ log .error () << " Could not find function '" << function
947
951
<< " ' in goto-program; not enforcing contracts."
948
952
<< messaget::eom;
949
953
return true ;
@@ -972,7 +976,7 @@ bool code_contractst::enforce_contract(const std::string &fun_to_enforce)
972
976
auto nexist_old_function = goto_functions.function_map .find (original);
973
977
INVARIANT (
974
978
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) +
976
980
" in the function map because that function should have had its"
977
981
" name mangled" );
978
982
0 commit comments