Skip to content

Commit 826326f

Browse files
committed
Reimplemented assume_greater_than in terms of assume_less_than
These operations are symmetric, so we can rewrite x > y as y < x, and x >= y as y <= x. As a consequence of rewriting, greater than assumptions now also prune.
1 parent b4e2353 commit 826326f

File tree

11 files changed

+330
-155
lines changed

11 files changed

+330
-155
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
int main()
2+
{
3+
int x = 0;
4+
if(nondet())
5+
{
6+
x = 30;
7+
}
8+
9+
if(x > 20)
10+
{
11+
assert(x > 10);
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-values constants --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.1\] line .* assertion x > 10: UNKNOWN
7+
8+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-values intervals --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.1\] line .* assertion x > 10: SUCCESS
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-values set-of-constants --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.1\] line .* assertion x > 10: SUCCESS
7+
--
File renamed without changes.

regression/goto-analyzer/pruning-le/test-constants.desc renamed to regression/goto-analyzer/pruning-lt/test-constants.desc

File renamed without changes.

regression/goto-analyzer/pruning-le/test-intervals.desc renamed to regression/goto-analyzer/pruning-lt/test-intervals.desc

File renamed without changes.

regression/goto-analyzer/pruning-le/test-value-sets.desc renamed to regression/goto-analyzer/pruning-lt/test-value-sets.desc

File renamed without changes.

src/analyses/variable-sensitivity/abstract_environment.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -743,19 +743,19 @@ exprt assume_less_than(
743743
return result;
744744
}
745745

746+
static auto symmetric_operations =
747+
std::map<irep_idt, irep_idt>{{ID_ge, ID_le}, {ID_gt, ID_lt}};
748+
746749
exprt assume_greater_than(
747750
abstract_environmentt &env,
748751
const exprt &expr,
749752
const namespacet &ns)
750753
{
751-
auto operands = eval_operands_as_values(env, expr, ns);
752-
if(!operands.are_good())
753-
return nil_exprt();
754+
auto const &gt_expr = to_binary_expr(expr);
754755

755-
auto left_upper = operands.left_interval().get_upper();
756-
auto right_lower = operands.right_interval().get_lower();
756+
auto symmetric_op = symmetric_operations[gt_expr.id()];
757+
auto symmetric_expr =
758+
binary_relation_exprt(gt_expr.rhs(), symmetric_op, gt_expr.lhs());
757759

758-
auto reduced_ge_expr =
759-
binary_relation_exprt(left_upper, expr.id(), right_lower);
760-
return env.eval(reduced_ge_expr, ns)->to_constant();
760+
return assume_less_than(env, symmetric_expr, ns);
761761
}

src/analyses/variable-sensitivity/interval_abstract_value.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ abstract_value_pointert interval_abstract_valuet::constrain(
455455
auto upper_bound =
456456
constant_interval_exprt::get_min(upper, interval.get_upper());
457457

458+
if(constant_interval_exprt::greater_than(lower_bound, upper_bound))
459+
return as_value(mutable_clone());
460+
461+
auto constrained_interval = constant_interval_exprt(lower_bound, upper_bound);
458462
return as_value(
459463
make_interval(constant_interval_exprt(lower_bound, upper_bound)));
460464
}

0 commit comments

Comments
 (0)