@@ -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 (
@@ -767,37 +760,24 @@ void code_contractst::instrument_call_statement(
767
760
}
768
761
else if (called_name == " free" )
769
762
{
770
- goto_programt alias_assertion;
771
763
const exprt &lhs_dereference = dereference_exprt (
772
764
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" );
765
+ add_containment_check (
766
+ program, assigns_clause, instruction_iterator, lhs_dereference);
779
767
assigns_clause.remove_from_local_write_set (lhs_dereference);
780
768
assigns_clause.remove_from_global_write_set (lhs_dereference);
781
- insert_before_swap_and_advance (
782
- program, instruction_iterator, alias_assertion);
783
769
return ;
784
770
}
785
771
786
772
if (
787
773
instruction_iterator->call_lhs ().is_not_nil () &&
788
774
instruction_iterator->call_lhs ().id () == ID_symbol)
789
775
{
790
- const auto alias_expr = assigns_clause.generate_containment_check (
776
+ add_containment_check (
777
+ program,
778
+ assigns_clause,
779
+ instruction_iterator,
791
780
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
781
}
802
782
803
783
const symbolt &called_symbol = ns.lookup (called_name);
@@ -977,22 +957,29 @@ void code_contractst::check_frame_conditions(
977
957
instruction_it->is_other () &&
978
958
instruction_it->get_other ().get_statement () == ID_havoc_object)
979
959
{
980
- goto_programt alias_assertion;
981
960
const exprt &havoc_argument = dereference_exprt (
982
961
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" );
962
+ add_containment_check (program, assigns, instruction_it, havoc_argument);
989
963
assigns.remove_from_local_write_set (havoc_argument);
990
964
assigns.remove_from_global_write_set (havoc_argument);
991
- insert_before_swap_and_advance (program, instruction_it, alias_assertion);
992
965
}
993
966
}
994
967
}
995
968
969
+ void code_contractst::add_containment_check (
970
+ goto_programt &program,
971
+ assigns_clauset &assigns,
972
+ goto_programt::instructionst::iterator &instruction_it,
973
+ const exprt &expr)
974
+ {
975
+ goto_programt assertion;
976
+ assertion.add (goto_programt::make_assertion (
977
+ assigns.generate_containment_check (expr), instruction_it->source_location ));
978
+ assertion.instructions .back ().source_location .set_comment (
979
+ " Check that " + from_expr (ns, expr.id (), expr) + " is assignable" );
980
+ insert_before_swap_and_advance (program, instruction_it, assertion);
981
+ }
982
+
996
983
bool code_contractst::enforce_contract (const irep_idt &function)
997
984
{
998
985
// Add statements to the source function
0 commit comments