Skip to content

Commit

Permalink
Simplification towards singleton intervals requires single variable
Browse files Browse the repository at this point in the history
We must not blindly assume that that <exprA> and <exprB> in
<exprA> >= C1 && !(<exprB> >= C2) are the same.

Fixes: #7953
  • Loading branch information
tautschnig committed Oct 12, 2023
1 parent f840cd0 commit 439bb2c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions regression/cbmc/simplify_singleton_interval_7953/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <assert.h>
extern void __VERIFIER_assume(int cond);
extern int __VERIFIER_nondet_int(void);
int main()
{
int z = __VERIFIER_nondet_int();
int k = __VERIFIER_nondet_int();
__VERIFIER_assume(1 < z);
__VERIFIER_assume(1 <= z && k <= 1);
assert(0);
}
10 changes: 10 additions & 0 deletions regression/cbmc/simplify_singleton_interval_7953/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE new-smt-backend
main.c

^VERIFICATION FAILED$
^EXIT=10$
^SIGNAL=0$
--
^warning: ignoring
--
Simplification must not spuriously turn the second assumption into an equality.
4 changes: 4 additions & 0 deletions src/util/simplify_expr_boolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_boolean(const exprt &expr)
{
mp_integer lower;
mp_integer higher;
exprt non_const_value;
};
boundst bounds;

Expand All @@ -177,6 +178,7 @@ simplify_exprt::resultt<> simplify_exprt::simplify_boolean(const exprt &expr)
auto int_opt =
numeric_cast<mp_integer>(to_constant_expr(ge_expr->rhs())))
{
bounds.non_const_value = ge_expr->lhs();
bounds.lower = *int_opt;
return true;
}
Expand All @@ -199,6 +201,8 @@ simplify_exprt::resultt<> simplify_exprt::simplify_boolean(const exprt &expr)
// (e.g. i >= j)
if(!ge_expr->rhs().is_constant())
return false;
if(ge_expr->lhs() != bounds.non_const_value)
return false;
if(
auto int_opt =
numeric_cast<mp_integer>(to_constant_expr(ge_expr->rhs())))
Expand Down

0 comments on commit 439bb2c

Please sign in to comment.