Skip to content

Commit 683b8ba

Browse files
authored
Merge pull request #7744 from qinheping/feature/do-while-loop-in-synthesizer
SYNTHESIZER: Conver do{ }while(0) to non-loop block
2 parents 0ca29d8 + 0f5e93e commit 683b8ba

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

Diff for: regression/goto-synthesizer/do_while_loop_0/main.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
int result = 0;
4+
do
5+
{
6+
result += 1;
7+
} while(0 == 1);
8+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check if synthesizer works for do {} while (0).

Diff for: src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

+22-3
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,34 @@ void enumerative_loop_contracts_synthesizert::init_candidates()
9999
if(loop_head_and_content.second.size() <= 1)
100100
continue;
101101

102-
goto_programt::const_targett loop_end =
102+
goto_programt::targett loop_end =
103103
get_loop_end_from_loop_head_and_content_mutable(
104104
loop_head_and_content.first, loop_head_and_content.second);
105105

106106
loop_idt new_id(function_p.first, loop_end->loop_number);
107107
loop_cfg_infot cfg_info(function_p.second, loop_head_and_content.second);
108108

109-
log.debug() << "Initialize candidates for the loop at "
110-
<< loop_end->source_location() << messaget::eom;
109+
log.progress() << "Initialize candidates for the loop at "
110+
<< loop_end->source_location() << messaget::eom;
111+
112+
// Turn do while loops of form
113+
//
114+
// do
115+
// { loop body }
116+
// while (0)
117+
//
118+
// into non-loop block
119+
//
120+
// { loop body }
121+
// skip
122+
//
123+
if(
124+
loop_end->is_goto() &&
125+
simplify_expr(loop_end->condition(), ns) == false_exprt())
126+
{
127+
loop_end->turn_into_skip();
128+
continue;
129+
}
111130

112131
// we only synthesize invariants and assigns for unannotated loops
113132
if(loop_end->condition().find(ID_C_spec_loop_invariant).is_nil())

0 commit comments

Comments
 (0)