Skip to content

Commit 74963e7

Browse files
authored
Merge pull request diffblue#6434 from NlightNFotis/implication_statement_checks
Refinement of guard based on antecedent of implication statement
2 parents 6dfd3f7 + 4c40cd0 commit 74963e7

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// clang-format off
2+
int main(int argc, char **argv)
3+
{
4+
int y;
5+
6+
__CPROVER_assert(
7+
y != 0 ==> 10 / y <= 10,
8+
"10 / y is expected to succeed");
9+
}
10+
// clang-format on
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
--div-by-zero-check
3+
test.c
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.1\] line \d 10 / y is expected to succeed: SUCCESS
7+
\[main\.division-by-zero\.1\] line \d division by zero in 10 / y: SUCCESS
8+
^VERIFICATION SUCCESSFUL$
9+
--
10+
\[main\.division-by-zero\.1\] line \d division by zero in 10 / y: FAILURE
11+
--
12+
Without the change that drives the refinement of the guard for a `ID_implies`
13+
statement in `goto-check`, this will fail with a counterexample of `y = 0`.
14+
With the bug fix, the `--div-by-zero-check` will succeed because the
15+
antecedent of the conditional is becoming the guard for the consequent,
16+
guarding any checks performed there.

src/analyses/goto_check.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,8 @@ void goto_checkt::check_rec_address(const exprt &expr, guardt &guard)
16061606

16071607
void goto_checkt::check_rec_logical_op(const exprt &expr, guardt &guard)
16081608
{
1609+
PRECONDITION(
1610+
expr.id() == ID_and || expr.id() == ID_or || expr.id() == ID_implies);
16091611
INVARIANT(
16101612
expr.is_boolean(),
16111613
"'" + expr.id_string() + "' must be Boolean, but got " + expr.pretty());
@@ -1736,7 +1738,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
17361738
check_rec_address(to_address_of_expr(expr).object(), guard);
17371739
return;
17381740
}
1739-
else if(expr.id() == ID_and || expr.id() == ID_or)
1741+
else if(expr.id() == ID_and || expr.id() == ID_or || expr.id() == ID_implies)
17401742
{
17411743
check_rec_logical_op(expr, guard);
17421744
return;

0 commit comments

Comments
 (0)