@@ -69,15 +69,12 @@ static void check_apply_invariants(
6969 PRECONDITION (!loop.empty ());
7070
7171 // find the last back edge
72- goto_programt::targett loop_end=loop_head;
73- for (loopt::const_iterator
74- it=loop.begin ();
75- it!=loop.end ();
76- ++it)
77- if ((*it)->is_goto () &&
78- (*it)->get_target ()==loop_head &&
79- (*it)->location_number >loop_end->location_number )
80- loop_end=*it;
72+ goto_programt::targett loop_end = loop_head;
73+ for (const auto &t : loop)
74+ if (
75+ t->is_goto () && t->get_target () == loop_head &&
76+ t->location_number > loop_end->location_number )
77+ loop_end = t;
8178
8279 // see whether we have an invariant
8380 exprt invariant = static_cast <const exprt &>(
@@ -107,7 +104,7 @@ static void check_apply_invariants(
107104 {
108105 goto_programt::targett a = havoc_code.add (
109106 goto_programt::make_assertion (invariant, loop_head->source_location ));
110- a->source_location .set_comment (" Loop invariant violated before entry" );
107+ a->source_location .set_comment (" Check loop invariant before entry" );
111108 }
112109
113110 // havoc variables being written to
@@ -125,15 +122,15 @@ static void check_apply_invariants(
125122 side_effect_expr_nondett (bool_typet (), loop_head->source_location )));
126123 }
127124
128- // Now havoc at the loop head. Use insert_swap to
129- // preserve jumps to loop head.
125+ // Now havoc at the loop head.
126+ // Use insert_before_swap to preserve jumps to loop head.
130127 goto_function.body .insert_before_swap (loop_head, havoc_code);
131128
132129 // assert the invariant at the end of the loop body
133130 {
134131 goto_programt::instructiont a =
135132 goto_programt::make_assertion (invariant, loop_end->source_location );
136- a.source_location .set_comment (" Loop invariant not preserved" );
133+ a.source_location .set_comment (" Check that loop invariant is preserved" );
137134 goto_function.body .insert_before_swap (loop_end, a);
138135 ++loop_end;
139136 }
@@ -306,12 +303,9 @@ void code_contractst::apply_loop_contract(
306303 natural_loops_mutablet natural_loops (goto_function.body );
307304
308305 // iterate over the (natural) loops in the function
309- for (natural_loops_mutablet::loop_mapt::const_iterator l_it =
310- natural_loops.loop_map .begin ();
311- l_it != natural_loops.loop_map .end ();
312- l_it++)
306+ for (const auto &loop : natural_loops.loop_map )
313307 check_apply_invariants (
314- goto_function, local_may_alias, l_it-> first , l_it-> second );
308+ goto_function, local_may_alias, loop. first , loop. second );
315309}
316310
317311const symbolt &code_contractst::new_tmp_symbol (
@@ -959,7 +953,7 @@ bool code_contractst::enforce_contracts(
959953 }
960954
961955 if (!fail)
962- fail | = enforce_contract (fun);
956+ fail = enforce_contract (fun);
963957 }
964958 return fail;
965959}
0 commit comments