Skip to content

Commit 8d11943

Browse files
committed
comparisons of pointers to symbols
1 parent d52ca36 commit 8d11943

File tree

7 files changed

+98
-7
lines changed

7 files changed

+98
-7
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
struct int_pair
6+
{
7+
int a;
8+
int b;
9+
};
10+
struct int_pair x[2];
11+
12+
int *pa = &(x[0].a);
13+
14+
assert(pa == &(x[0].a));
15+
assert(pa != &(x[0].a));
16+
assert(pa == &(x[0].b));
17+
assert(pa != &(x[0].b));
18+
assert(pa == &(x[1].a));
19+
assert(pa != &(x[1].a));
20+
assert(pa == &(x[1].b));
21+
assert(pa != &(x[1].b));
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers constants --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion pa == &\(x\[0\].a\): SUCCESS
7+
^\[main.assertion.2\] .* assertion pa != &\(x\[0\].a\): FAILURE
8+
^\[main.assertion.3\] .* assertion pa == &\(x\[0\].b\): FAILURE
9+
^\[main.assertion.4\] .* assertion pa != &\(x\[0\].b\): SUCCESS
10+
^\[main.assertion.5\] .* assertion pa == &\(x\[1\].a\): FAILURE
11+
^\[main.assertion.6\] .* assertion pa != &\(x\[1\].a\): SUCCESS
12+
^\[main.assertion.7\] .* assertion pa == &\(x\[1\].b\): FAILURE
13+
^\[main.assertion.8\] .* assertion pa != &\(x\[1\].b\): SUCCESS
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers top-bottom --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion pa == &\(x\[0\].a\): UNKNOWN
7+
^\[main.assertion.2\] .* assertion pa != &\(x\[0\].a\): UNKNOWN
8+
^\[main.assertion.3\] .* assertion pa == &\(x\[0\].b\): UNKNOWN
9+
^\[main.assertion.4\] .* assertion pa != &\(x\[0\].b\): UNKNOWN
10+
^\[main.assertion.5\] .* assertion pa == &\(x\[1\].a\): UNKNOWN
11+
^\[main.assertion.6\] .* assertion pa != &\(x\[1\].a\): UNKNOWN
12+
^\[main.assertion.7\] .* assertion pa == &\(x\[1\].b\): UNKNOWN
13+
^\[main.assertion.8\] .* assertion pa != &\(x\[1\].b\): UNKNOWN
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers value-set --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.assertion.1\] .* assertion pa == &\(x\[0\].a\): SUCCESS
7+
^\[main.assertion.2\] .* assertion pa != &\(x\[0\].a\): FAILURE
8+
^\[main.assertion.3\] .* assertion pa == &\(x\[0\].b\): FAILURE
9+
^\[main.assertion.4\] .* assertion pa != &\(x\[0\].b\): SUCCESS
10+
^\[main.assertion.5\] .* assertion pa == &\(x\[1\].a\): FAILURE
11+
^\[main.assertion.6\] .* assertion pa != &\(x\[1\].a\): SUCCESS
12+
^\[main.assertion.7\] .* assertion pa == &\(x\[1\].b\): FAILURE
13+
^\[main.assertion.8\] .* assertion pa != &\(x\[1\].b\): SUCCESS

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,16 @@ bool constant_pointer_abstract_objectt::same_target(
8181
if(value_stack.is_top_value() || cast_other->value_stack.is_top_value())
8282
return false;
8383

84-
bool matching_pointer = value_stack.target_expression() ==
85-
cast_other->value_stack.target_expression();
84+
if(value_stack.depth() != cast_other->value_stack.depth())
85+
return false;
86+
87+
for(size_t d = 0; d != value_stack.depth() - 1; ++d)
88+
if(
89+
value_stack.target_expression(d) !=
90+
cast_other->value_stack.target_expression(d))
91+
return false;
8692

87-
return matching_pointer;
93+
return true;
8894
}
8995

9096
exprt constant_pointer_abstract_objectt::offset() const
@@ -319,6 +325,21 @@ exprt struct_member_ptr_comparison_expr(
319325
return nil_exprt();
320326
}
321327

328+
exprt symbol_ptr_comparison_expr(
329+
irep_idt const &id,
330+
exprt const &lhs,
331+
exprt const &rhs)
332+
{
333+
auto const &lhs_identifier = to_symbol_expr(lhs).get_identifier();
334+
auto const &rhs_identifier = to_symbol_expr(rhs).get_identifier();
335+
336+
if(id == ID_equal)
337+
return to_bool_expr(lhs_identifier == rhs_identifier);
338+
if(id == ID_notequal)
339+
return to_bool_expr(lhs_identifier != rhs_identifier);
340+
return nil_exprt();
341+
}
342+
322343
exprt constant_pointer_abstract_objectt::ptr_comparison_expr(
323344
const exprt &expr,
324345
const std::vector<abstract_object_pointert> &operands,
@@ -347,6 +368,8 @@ exprt constant_pointer_abstract_objectt::ptr_comparison_expr(
347368
if(lhs_offset.id() == ID_member)
348369
return struct_member_ptr_comparison_expr(
349370
expr.id(), lhs_offset, rhs_offset);
371+
if(lhs_offset.id() == ID_symbol)
372+
return symbol_ptr_comparison_expr(expr.id(), lhs_offset, rhs_offset);
350373

351374
return binary_relation_exprt(lhs_offset, expr.id(), rhs_offset);
352375
}

src/analyses/variable-sensitivity/write_stack.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,23 @@ exprt write_stackt::to_expression() const
202202
return std::move(top_expr);
203203
}
204204

205-
exprt write_stackt::target_expression() const
205+
size_t write_stackt::depth() const
206+
{
207+
return stack.size();
208+
}
209+
210+
exprt write_stackt::target_expression(size_t depth) const
206211
{
207212
PRECONDITION(!is_top_value());
208-
return stack[0]->get_access_expr();
213+
return stack[depth]->get_access_expr();
209214
}
210215

211216
exprt write_stackt::offset_expression() const
212217
{
213218
PRECONDITION(!is_top_value());
214219
auto const &access = stack.back()->get_access_expr();
215220

216-
if(access.id() == ID_member)
221+
if(access.id() == ID_member || access.id() == ID_symbol)
217222
return access;
218223

219224
if(access.id() == ID_index)

src/analyses/variable-sensitivity/write_stack.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class write_stackt
2929
const namespacet &ns);
3030

3131
exprt to_expression() const;
32-
exprt target_expression() const;
32+
33+
size_t depth() const;
34+
exprt target_expression(size_t depth) const;
3335
exprt offset_expression() const;
3436
bool is_top_value() const;
3537

0 commit comments

Comments
 (0)