Skip to content

Commit e15e121

Browse files
committed
Fix loop-to-assume transformation in goto-symex
The previous implementation (from e672e0d) would not account for loop heads with side effects. Also, no tests existed for this transformation, which are now added. Fixes: #5450
1 parent 7d30335 commit e15e121

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

regression/cbmc/while2/main.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "assert.h"
2+
3+
int main()
4+
{
5+
int count = 0;
6+
do
7+
{
8+
count = count + 1;
9+
} while(count < 5);
10+
11+
do
12+
{
13+
} while(count < 5);
14+
15+
while(count < 5)
16+
;
17+
18+
assert(count == 5);
19+
assert(count == 17);
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "assert.h"
2+
3+
int main()
4+
{
5+
int count;
6+
7+
do
8+
{
9+
} while(count < 5);
10+
11+
while(count < 5)
12+
;
13+
14+
assert(count >= 5);
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
requires-transform.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
This test will only terminate, if the transformation of loops to assumes by
11+
goto-symex is applied.

regression/cbmc/while2/test.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] line 18 assertion count == 5: SUCCESS$
7+
^\[main.assertion.2\] line 19 assertion count == 17: FAILURE$
8+
^VERIFICATION FAILED$
9+
--
10+
^warning: ignoring

src/goto-symex/symex_goto.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ void goto_symext::symex_goto(statet &state)
252252
// is it label: goto label; or while(cond); - popular in SV-COMP
253253
if(
254254
symex_config.self_loops_to_assumptions &&
255+
// label: goto label; or do {} while(cond);
255256
(goto_target == state.source.pc ||
257+
// while(cond);
256258
(instruction.incoming_edges.size() == 1 &&
257-
*instruction.incoming_edges.begin() == goto_target)))
259+
*instruction.incoming_edges.begin() == goto_target &&
260+
goto_target->is_goto() && new_guard.is_true())))
258261
{
259262
// generate assume(false) or a suitable negation if this
260263
// instruction is a conditional goto

0 commit comments

Comments
 (0)