Skip to content

Contracts: always remove spurious do {... } while(0) loops #8459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion regression/contracts-dfcc/invar_assigns_empty/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ main.c
^\[main.loop_assigns.\d+\] line 5 Check assigns clause inclusion for loop .*: SUCCESS$
^\[main.loop_invariant_base.\d+\] line 5 Check invariant before entry for loop .*: SUCCESS$
^\[main.loop_invariant_step.\d+\] line 5 Check invariant after step for loop .*: SUCCESS$
^\[main.loop_step_unwinding.\d+\] line 5 Check step was unwound for loop .*: SUCCESS$
^VERIFICATION SUCCESSFUL$
--
--
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/contracts/contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class code_contractst
return loop_havoc_set;
}

namespacet ns;
const namespacet ns;

protected:
goto_modelt &goto_model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ dfcc_cfg_infot::dfcc_cfg_infot(
{
dfcc_loop_nesting_grapht loop_nesting_graph;
goto_programt &goto_program = goto_function.body;

// Clean up possible fake loops that are due to do { ... } while(0);
simplify_gotos(goto_program, ns);

if(loop_contract_config.apply_loop_contracts)
{
messaget log(message_handler);
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/contracts/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void insert_before_and_update_jumps(
}
}

void simplify_gotos(goto_programt &goto_program, namespacet &ns)
void simplify_gotos(goto_programt &goto_program, const namespacet &ns)
{
for(auto &instruction : goto_program.instructions)
{
Expand All @@ -270,7 +270,7 @@ void simplify_gotos(goto_programt &goto_program, namespacet &ns)

bool is_loop_free(
const goto_programt &goto_program,
namespacet &ns,
const namespacet &ns,
messaget &log)
{
// create cfg from instruction list
Expand Down
4 changes: 2 additions & 2 deletions src/goto-instrument/contracts/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ void insert_before_and_update_jumps(

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

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

/// Returns an \ref irep_idt that essentially says that
Expand Down
Loading