@@ -557,9 +557,7 @@ bool code_contractst::apply_function_contract(
557
557
assertion.instructions .back ().source_location .set_property_class (
558
558
ID_precondition);
559
559
is_fresh.update_requires (assertion);
560
- auto lines_to_iterate = assertion.instructions .size ();
561
- goto_program.insert_before_swap (target, assertion);
562
- std::advance (target, lines_to_iterate);
560
+ insert_before_swap_and_advance (goto_program, target, assertion);
563
561
}
564
562
565
563
// Gather all the instructions required to handle history variables
@@ -579,9 +577,7 @@ bool code_contractst::apply_function_contract(
579
577
580
578
// add all the history variable initialization instructions
581
579
// to the goto program
582
- auto lines_to_iterate = ensures_pair.second .instructions .size ();
583
- goto_program.insert_before_swap (target, ensures_pair.second );
584
- std::advance (target, lines_to_iterate);
580
+ insert_before_swap_and_advance (goto_program, target, ensures_pair.second );
585
581
}
586
582
587
583
// Create a series of non-deterministic assignments to havoc the variables
@@ -592,19 +588,15 @@ bool code_contractst::apply_function_contract(
592
588
goto_programt assigns_havoc = assigns_cause.havoc_code ();
593
589
594
590
// Insert the non-deterministic assignment immediately before the call site.
595
- std::size_t lines_to_iterate = assigns_havoc.instructions .size ();
596
- goto_program.insert_before_swap (target, assigns_havoc);
597
- std::advance (target, lines_to_iterate);
591
+ insert_before_swap_and_advance (goto_program, target, assigns_havoc);
598
592
}
599
593
600
594
// To remove the function call, insert statements related to the assumption.
601
595
// Then, replace the function call with a SKIP statement.
602
596
if (!ensures.is_false ())
603
597
{
604
598
is_fresh.update_ensures (ensures_pair.first );
605
- auto lines_to_iterate = ensures_pair.first .instructions .size ();
606
- goto_program.insert_before_swap (target, ensures_pair.first );
607
- std::advance (target, lines_to_iterate);
599
+ insert_before_swap_and_advance (goto_program, target, ensures_pair.first );
608
600
}
609
601
*target = goto_programt::make_skip ();
610
602
@@ -690,9 +682,8 @@ void code_contractst::instrument_assign_statement(
690
682
instruction_iterator->source_location ));
691
683
alias_assertion.instructions .back ().source_location .set_comment (
692
684
" Check that " + from_expr (ns, lhs.id (), lhs) + " is assignable" );
693
- size_t lines_to_iterate = alias_assertion.instructions .size ();
694
- program.insert_before_swap (instruction_iterator, alias_assertion);
695
- std::advance (instruction_iterator, lines_to_iterate);
685
+ insert_before_swap_and_advance (
686
+ program, instruction_iterator, alias_assertion);
696
687
}
697
688
698
689
void code_contractst::instrument_call_statement (
@@ -721,15 +712,13 @@ void code_contractst::instrument_call_statement(
721
712
722
713
if (called_name == " malloc" )
723
714
{
724
- goto_programt::instructionst::iterator local_instruction_iterator =
725
- instruction_iterator;
726
715
// malloc statments return a void pointer, which is then cast and assigned
727
716
// to a result variable. We iterate one line forward to grab the result of
728
717
// the malloc once it is cast.
729
- local_instruction_iterator ++;
730
- if (local_instruction_iterator ->is_assign ())
718
+ instruction_iterator ++;
719
+ if (instruction_iterator ->is_assign ())
731
720
{
732
- const exprt &rhs = local_instruction_iterator ->assign_rhs ();
721
+ const exprt &rhs = instruction_iterator ->assign_rhs ();
733
722
INVARIANT (
734
723
rhs.id () == ID_typecast,
735
724
" malloc is called but the result is not cast. Excluding result from "
@@ -740,10 +729,8 @@ void code_contractst::instrument_call_statement(
740
729
assigns_clause_targett *new_target =
741
730
assigns_clause.add_target (dereference_exprt (rhs));
742
731
goto_programt &pointer_capture = new_target->get_init_block ();
743
-
744
- size_t lines_to_iterate = pointer_capture.instructions .size ();
745
- program.insert_before_swap (local_instruction_iterator, pointer_capture);
746
- std::advance (instruction_iterator, lines_to_iterate + 1 );
732
+ insert_before_swap_and_advance (
733
+ program, instruction_iterator, pointer_capture);
747
734
}
748
735
return ; // assume malloc edits no pre-existing memory objects.
749
736
}
@@ -924,12 +911,8 @@ void code_contractst::check_frame_conditions(
924
911
goto_programt mark_dead = assigns.dead_stmts ();
925
912
926
913
// Skip lines with temporary variable declarations
927
- size_t lines_to_iterate = standin_decls.instructions .size ();
928
-
929
- goto_programt::instructionst::iterator instruction_it =
930
- program.instructions .begin ();
931
- program.insert_before_swap (instruction_it, standin_decls);
932
- std::advance (instruction_it, lines_to_iterate);
914
+ auto instruction_it = program.instructions .begin ();
915
+ insert_before_swap_and_advance (program, instruction_it, standin_decls);
933
916
934
917
for (; instruction_it != program.instructions .end (); ++instruction_it)
935
918
{
@@ -942,7 +925,6 @@ void code_contractst::check_frame_conditions(
942
925
assigns.add_target (instruction_it->get_decl ().symbol ());
943
926
goto_programt &pointer_capture = new_target->get_init_block ();
944
927
945
- lines_to_iterate = pointer_capture.instructions .size ();
946
928
for (auto in : pointer_capture.instructions )
947
929
{
948
930
program.insert_after (instruction_it, in);
0 commit comments