@@ -715,14 +715,7 @@ void code_contractst::instrument_assign_statement(
715
715
assigns_clause.add_to_local_write_set (lhs);
716
716
}
717
717
718
- goto_programt alias_assertion;
719
- alias_assertion.add (goto_programt::make_assertion (
720
- assigns_clause.generate_containment_check (lhs),
721
- instruction_iterator->source_location ));
722
- alias_assertion.instructions .back ().source_location .set_comment (
723
- " Check that " + from_expr (ns, lhs.id (), lhs) + " is assignable" );
724
- insert_before_swap_and_advance (
725
- program, instruction_iterator, alias_assertion);
718
+ add_containment_check (program, assigns_clause, instruction_iterator, lhs);
726
719
}
727
720
728
721
void code_contractst::instrument_call_statement (
@@ -748,8 +741,7 @@ void code_contractst::instrument_call_statement(
748
741
called_name =
749
742
to_symbol_expr (instruction_iterator->call_function ()).get_identifier ();
750
743
}
751
- log.warning () << " called function: " << id2string (called_name)
752
- << messaget::eom;
744
+
753
745
if (called_name == " malloc" )
754
746
{
755
747
// malloc statments return a void pointer, which is then cast and assigned
@@ -767,37 +759,24 @@ void code_contractst::instrument_call_statement(
767
759
}
768
760
else if (called_name == " free" )
769
761
{
770
- goto_programt alias_assertion;
771
762
const exprt &lhs_dereference = dereference_exprt (
772
763
to_typecast_expr (instruction_iterator->call_arguments ().front ()).op ());
773
- alias_assertion.add (goto_programt::make_assertion (
774
- assigns_clause.generate_containment_check (lhs_dereference),
775
- instruction_iterator->source_location ));
776
- alias_assertion.instructions .back ().source_location .set_comment (
777
- " Check that " + from_expr (ns, lhs_dereference.id (), lhs_dereference) +
778
- " is assignable" );
764
+ add_containment_check (
765
+ program, assigns_clause, instruction_iterator, lhs_dereference);
779
766
assigns_clause.remove_from_local_write_set (lhs_dereference);
780
767
assigns_clause.remove_from_global_write_set (lhs_dereference);
781
- insert_before_swap_and_advance (
782
- program, instruction_iterator, alias_assertion);
783
768
return ;
784
769
}
785
770
786
771
if (
787
772
instruction_iterator->call_lhs ().is_not_nil () &&
788
773
instruction_iterator->call_lhs ().id () == ID_symbol)
789
774
{
790
- const auto alias_expr = assigns_clause.generate_containment_check (
775
+ add_containment_check (
776
+ program,
777
+ assigns_clause,
778
+ instruction_iterator,
791
779
instruction_iterator->call_lhs ());
792
-
793
- goto_programt alias_assertion;
794
- alias_assertion.add (goto_programt::make_assertion (
795
- alias_expr, instruction_iterator->source_location ));
796
- alias_assertion.instructions .back ().source_location .set_comment (
797
- " Check that " + from_expr (ns, alias_expr.id (), alias_expr) +
798
- " is assignable" );
799
- insert_before_swap_and_advance (
800
- program, instruction_iterator, alias_assertion);
801
780
}
802
781
803
782
const symbolt &called_symbol = ns.lookup (called_name);
@@ -977,22 +956,29 @@ void code_contractst::check_frame_conditions(
977
956
instruction_it->is_other () &&
978
957
instruction_it->get_other ().get_statement () == ID_havoc_object)
979
958
{
980
- goto_programt alias_assertion;
981
959
const exprt &havoc_argument = dereference_exprt (
982
960
to_typecast_expr (instruction_it->get_other ().operands ().front ()).op ());
983
- alias_assertion.add (goto_programt::make_assertion (
984
- assigns.generate_containment_check (havoc_argument),
985
- instruction_it->source_location ));
986
- alias_assertion.instructions .back ().source_location .set_comment (
987
- " Check that " + from_expr (ns, havoc_argument.id (), havoc_argument) +
988
- " is assignable" );
961
+ add_containment_check (program, assigns, instruction_it, havoc_argument);
989
962
assigns.remove_from_local_write_set (havoc_argument);
990
963
assigns.remove_from_global_write_set (havoc_argument);
991
- insert_before_swap_and_advance (program, instruction_it, alias_assertion);
992
964
}
993
965
}
994
966
}
995
967
968
+ void code_contractst::add_containment_check (
969
+ goto_programt &program,
970
+ const assigns_clauset &assigns,
971
+ goto_programt::instructionst::iterator &instruction_it,
972
+ const exprt &expr)
973
+ {
974
+ goto_programt assertion;
975
+ assertion.add (goto_programt::make_assertion (
976
+ assigns.generate_containment_check (expr), instruction_it->source_location ));
977
+ assertion.instructions .back ().source_location .set_comment (
978
+ " Check that " + from_expr (ns, expr.id (), expr) + " is assignable" );
979
+ insert_before_swap_and_advance (program, instruction_it, assertion);
980
+ }
981
+
996
982
bool code_contractst::enforce_contract (const irep_idt &function)
997
983
{
998
984
// Add statements to the source function
0 commit comments