Skip to content

Commit 36dcc4a

Browse files
committed
let inverted pointer expression eval as normal. No need for special case.
1 parent 6f2f117 commit 36dcc4a

File tree

10 files changed

+175
-141
lines changed

10 files changed

+175
-141
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
int a[2];
6+
7+
int *p = &(a[0]);
8+
int *q = &(a[1]);
9+
int *r = p + 1;
10+
11+
assert(p == q || p == r);
12+
assert(q == p || q == r);
13+
14+
assert(p != q && p != r);
15+
assert(q != p && q != r);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers constants --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion p == q || p == r: FAILURE
7+
^\[main.assertion.2\] .* assertion q == p || q == r: SUCCESS
8+
^\[main.assertion.3\] .* assertion p != q && p != r: SUCCESS
9+
^\[main.assertion.4\] .* assertion q != p && q != r: FAILURE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers top-bottom --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion p == q || p == r: UNKNOWN
7+
^\[main.assertion.2\] .* assertion q == p || q == r: UNKNOWN
8+
^\[main.assertion.3\] .* assertion p != q && p != r: UNKNOWN
9+
^\[main.assertion.4\] .* assertion q != p && q != r: UNKNOWN
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers value-set --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion p == q || p == r: FAILURE
7+
^\[main.assertion.2\] .* assertion q == p || q == r: SUCCESS
8+
^\[main.assertion.3\] .* assertion p != q && p != r: SUCCESS
9+
^\[main.assertion.4\] .* assertion q != p && q != r: FAILURE

src/analyses/variable-sensitivity/abstract_environment.cpp

+5-14
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static exprt assume_greater_than(
4646
const exprt &expr,
4747
const namespacet &ns);
4848

49-
abstract_value_pointert as_value(const abstract_object_pointert &obj);
50-
bool is_value(const abstract_object_pointert &obj);
49+
static abstract_value_pointert as_value(const abstract_object_pointert &obj);
50+
static bool is_value(const abstract_object_pointert &obj);
5151

5252
std::vector<abstract_object_pointert> eval_operands(
5353
const exprt &expr,
@@ -64,12 +64,6 @@ bool is_ptr_diff(const exprt &expr)
6464
bool is_ptr_comparison(const exprt &expr)
6565
{
6666
auto const &id = expr.id();
67-
if(id == ID_not)
68-
{
69-
auto const &not_expr = to_not_expr(expr);
70-
return is_ptr_comparison(not_expr.op());
71-
}
72-
7367
bool is_comparison = id == ID_equal || id == ID_notequal || id == ID_lt ||
7468
id == ID_le || id == ID_gt || id == ID_ge;
7569

@@ -110,10 +104,7 @@ abstract_environmentt::eval(const exprt &expr, const namespacet &ns) const
110104
is_access_expr(simplified_id) || is_ptr_diff(simplified_expr) ||
111105
is_ptr_comparison(simplified_expr))
112106
{
113-
auto const &operands_expr = (simplified_id != ID_not)
114-
? simplified_expr
115-
: to_not_expr(simplified_expr).op();
116-
auto const operands = eval_operands(operands_expr, *this, ns);
107+
auto const operands = eval_operands(simplified_expr, *this, ns);
117108
auto const &target = operands.front();
118109

119110
return target->expression_transform(simplified_expr, operands, *this, ns);
@@ -560,7 +551,7 @@ static auto inverse_operations =
560551
{ID_ge, ID_lt},
561552
{ID_gt, ID_le}};
562553

563-
exprt invert_result(const exprt &result)
554+
static exprt invert_result(const exprt &result)
564555
{
565556
if(!result.is_boolean())
566557
return result;
@@ -570,7 +561,7 @@ exprt invert_result(const exprt &result)
570561
return true_exprt();
571562
}
572563

573-
exprt invert_expr(const exprt &expr)
564+
static exprt invert_expr(const exprt &expr)
574565
{
575566
auto expr_id = expr.id();
576567

src/analyses/variable-sensitivity/abstract_environment.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <analyses/variable-sensitivity/abstract_object.h>
2323

2424
exprt simplify_vsd_expr(exprt src, const namespacet &ns);
25-
exprt invert_result(const exprt &result);
2625
bool is_ptr_diff(const exprt &expr);
2726
bool is_ptr_comparison(const exprt &expr);
2827

src/analyses/variable-sensitivity/abstract_pointer_object.cpp

+1-17
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,10 @@ abstract_object_pointert abstract_pointer_objectt::eval_ptr_comparison(
116116
const abstract_environmentt &environment,
117117
const namespacet &ns) const
118118
{
119-
auto result = eval_ptr_comparison_as_expr(expr, operands, environment, ns);
119+
auto result = ptr_comparison_expr(expr, operands, environment, ns);
120120
return environment.eval(result, ns);
121121
}
122122

123-
exprt abstract_pointer_objectt::eval_ptr_comparison_as_expr(
124-
const exprt &expr,
125-
const std::vector<abstract_object_pointert> &operands,
126-
const abstract_environmentt &environment,
127-
const namespacet &ns) const
128-
{
129-
if(expr.id() == ID_not)
130-
{
131-
auto const &not_expr = to_not_expr(expr);
132-
auto result = simplify_vsd_expr(
133-
ptr_comparison_expr(not_expr.op(), operands, environment, ns), ns);
134-
return invert_result(result);
135-
}
136-
return ptr_comparison_expr(expr, operands, environment, ns);
137-
}
138-
139123
static bool is_dereference(const exprt &expr)
140124
{
141125
return expr.id() == ID_dereference;

src/analyses/variable-sensitivity/abstract_pointer_object.h

-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,6 @@ class abstract_pointer_objectt : public abstract_objectt,
129129
const std::vector<abstract_object_pointert> &operands,
130130
const abstract_environmentt &environment,
131131
const namespacet &ns) const;
132-
exprt eval_ptr_comparison_as_expr(
133-
const exprt &expr,
134-
const std::vector<abstract_object_pointert> &operands,
135-
const abstract_environmentt &environment,
136-
const namespacet &ns) const;
137132
};
138133

139134
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_ABSTRACT_POINTER_OBJECT_H

src/analyses/variable-sensitivity/context_abstract_object.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ abstract_object_pointert context_abstract_objectt::expression_transform(
8686
const abstract_environmentt &environment,
8787
const namespacet &ns) const
8888
{
89+
PRECONDITION(expr.operands().size() == operands.size());
8990
std::vector<abstract_object_pointert> child_operands;
9091

9192
std::transform(

0 commit comments

Comments
 (0)