Skip to content

Commit 3f03433

Browse files
committed
goto-symex: print status note and conditional warning for self-loops
Unless CBMC is invoked with --no-self-loops-to-assumptions, self-loops are replaced by assumptions. This commit now introduces a status output that such replacement is happening, and also a warning when --unwinding-assertions is set: as the loop is replaced by an assumption, no unwinding assertions can possible be generated. This behaviour may be unexpected by the user, and we should therefore let them know what is going on. Fixes: #6433
1 parent f2240be commit 3f03433

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

regression/cbmc/self_loops_to_assumptions1/default.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CORE
22
main.c
33
--unwind 1 --unwinding-assertions
4+
^replacing self-loop at file main.c line 3 function main by assume\(FALSE\)$
5+
^no unwinding assertion will be generated for self-loop at file main.c line 3 function main$
46
^EXIT=0$
57
^SIGNAL=0$
68
^VERIFICATION SUCCESSFUL$

regression/cbmc/self_loops_to_assumptions1/no-assume.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ main.c
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
77
--
8+
^replacing self-loop

src/goto-symex/symex_goto.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ Author: Daniel Kroening, [email protected]
99
/// \file
1010
/// Symbolic Execution
1111

12-
#include "goto_symex.h"
13-
#include "goto_symex_is_constant.h"
14-
15-
#include <algorithm>
16-
1712
#include <util/exception_utils.h>
1813
#include <util/expr_util.h>
1914
#include <util/invariant.h>
@@ -22,11 +17,16 @@ Author: Daniel Kroening, [email protected]
2217
#include <util/simplify_expr.h>
2318
#include <util/std_expr.h>
2419

20+
#include <langapi/language_util.h>
2521
#include <pointer-analysis/add_failed_symbols.h>
2622
#include <pointer-analysis/value_set_dereference.h>
2723

24+
#include "goto_symex.h"
25+
#include "goto_symex_is_constant.h"
2826
#include "path_storage.h"
2927

28+
#include <algorithm>
29+
3030
void goto_symext::apply_goto_condition(
3131
goto_symex_statet &current_state,
3232
goto_statet &jump_taken_state,
@@ -279,10 +279,19 @@ void goto_symext::symex_goto(statet &state)
279279
{
280280
// generate assume(false) or a suitable negation if this
281281
// instruction is a conditional goto
282-
if(new_guard.is_true())
283-
symex_assume_l2(state, false_exprt());
284-
else
285-
symex_assume_l2(state, not_exprt(new_guard));
282+
exprt negated_guard = not_exprt{new_guard};
283+
do_simplify(negated_guard);
284+
log.statistics() << "replacing self-loop at "
285+
<< state.source.pc->source_location() << " by assume("
286+
<< from_expr(ns, state.source.function_id, negated_guard)
287+
<< ")" << messaget::eom;
288+
if(symex_config.unwinding_assertions)
289+
{
290+
log.warning()
291+
<< "no unwinding assertion will be generated for self-loop at "
292+
<< state.source.pc->source_location() << messaget::eom;
293+
}
294+
symex_assume_l2(state, negated_guard);
286295

287296
// next instruction
288297
symex_transition(state);

0 commit comments

Comments
 (0)