Skip to content

Commit 0639fac

Browse files
committed
Contracts: always remove spurious do {... } while(0) loops
None of our contracts instrumentation should spuriously get confused by these pseudo-loops (suggesting to users that they need to unwind those loops). We already used to do this for non-DFCC code, now also apply it with dynamic frames.
1 parent 5002f3b commit 0639fac

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/goto-instrument/contracts/contracts.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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)