Skip to content

Commit f68cf8c

Browse files
authored
Merge pull request #8459 from tautschnig/contracts-remove-do-while-0
Contracts: always remove spurious do {... } while(0) loops
2 parents 46c1b0f + d4afdd2 commit f68cf8c

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

regression/contracts-dfcc/invar_assigns_empty/test.desc

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ main.c
66
^\[main.loop_assigns.\d+\] line 5 Check assigns clause inclusion for loop .*: SUCCESS$
77
^\[main.loop_invariant_base.\d+\] line 5 Check invariant before entry for loop .*: SUCCESS$
88
^\[main.loop_invariant_step.\d+\] line 5 Check invariant after step for loop .*: SUCCESS$
9-
^\[main.loop_step_unwinding.\d+\] line 5 Check step was unwound for loop .*: SUCCESS$
109
^VERIFICATION SUCCESSFUL$
1110
--
1211
--

src/goto-instrument/contracts/contracts.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class code_contractst
147147
return loop_havoc_set;
148148
}
149149

150-
namespacet ns;
150+
const namespacet ns;
151151

152152
protected:
153153
goto_modelt &goto_model;

src/goto-instrument/contracts/dynamic-frames/dfcc_cfg_info.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ dfcc_cfg_infot::dfcc_cfg_infot(
503503
{
504504
dfcc_loop_nesting_grapht loop_nesting_graph;
505505
goto_programt &goto_program = goto_function.body;
506+
507+
// Clean up possible fake loops that are due to do { ... } while(0);
508+
simplify_gotos(goto_program, ns);
509+
506510
if(loop_contract_config.apply_loop_contracts)
507511
{
508512
messaget log(message_handler);

src/goto-instrument/contracts/utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void insert_before_and_update_jumps(
257257
}
258258
}
259259

260-
void simplify_gotos(goto_programt &goto_program, namespacet &ns)
260+
void simplify_gotos(goto_programt &goto_program, const namespacet &ns)
261261
{
262262
for(auto &instruction : goto_program.instructions)
263263
{
@@ -270,7 +270,7 @@ void simplify_gotos(goto_programt &goto_program, namespacet &ns)
270270

271271
bool is_loop_free(
272272
const goto_programt &goto_program,
273-
namespacet &ns,
273+
const namespacet &ns,
274274
messaget &log)
275275
{
276276
// create cfg from instruction list

src/goto-instrument/contracts/utils.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ void insert_before_and_update_jumps(
199199

200200
/// Turns goto instructions `IF cond GOTO label` where the condition
201201
/// statically simplifies to `false` into SKIP instructions.
202-
void simplify_gotos(goto_programt &goto_program, namespacet &ns);
202+
void simplify_gotos(goto_programt &goto_program, const namespacet &ns);
203203

204204
/// Returns true iff the given program is loop-free,
205205
/// i.e. if each SCC of its CFG contains a single element.
206206
bool is_loop_free(
207207
const goto_programt &goto_program,
208-
namespacet &ns,
208+
const namespacet &ns,
209209
messaget &log);
210210

211211
/// Returns an \ref irep_idt that essentially says that

0 commit comments

Comments
 (0)