Skip to content

Commit 402ec71

Browse files
author
thk123
committed
Use the write_stack in the constant_pointer_abstract_object
1 parent 7e5aab0 commit 402ec71

File tree

7 files changed

+61
-97
lines changed

7 files changed

+61
-97
lines changed

regression/goto-analyzer/sensitivity-test-common-files/pointer_to_array_sensitivity_tests.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ int main(int argc, char *argv[])
88
int *p=a;
99
__CPROVER_assert(p==&a[0], "p==&a[0]");
1010

11+
// Read through pointer
1112
__CPROVER_assert(*p==1, "*p==1");
1213

14+
// Read through offset pointer
1315
__CPROVER_assert(p[1]==2, "p[1]==2");
1416
__CPROVER_assert(1[p]==2, "1[p]==2");
1517

1618
__CPROVER_assert(*(p+1)==2, "*(p+1)==2");
1719
__CPROVER_assert(*(1+p)==2, "*(1+p)==2");
1820

19-
__CPROVER_assert(*(p-1)==1, "*(p-1)==1");
20-
2121
// Test pointer arithmetic
2222
int *q=&a[1];
2323
__CPROVER_assert(q==p+1, "q==p+1");
2424
__CPROVER_assert(*q==2, "*q==2");
25+
__CPROVER_assert(*(q-1)==1, "*(q-1)==1");
2526

2627
// Test pointer diffs
2728
ptrdiff_t x=1;

regression/goto-analyzer/sensitivity-test-constants-array-of-constants-pointer/test.desc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ sensitivity_test_constants_array_of_constants_pointer.c
1313
^\[main.assertion.8\] .* \*b\[1\]==13: Failure \(if reachable\)$
1414
^\[main.assertion.9\] .* \*\(b\+1\)==&b1: Success$
1515
^\[main.assertion.10\] .* \*\(b\+1\)==&b3: Failure \(if reachable\)$
16-
^\[main.assertion.11\] .* \*\(1\+b\)==&b1: Unknown$
17-
^\[main.assertion.12\] .* \*\(1\+b\)==&b3: Unknown$
16+
^\[main.assertion.11\] .* \*\(1\+b\)==&b1: Success$
17+
^\[main.assertion.12\] .* \*\(1\+b\)==&b3: Failure \(if reachable\)$
1818
^\[main.assertion.13\] .* 1\[b\]==&b1: Success$
1919
^\[main.assertion.14\] .* 1\[b\]==&b3: Failure \(if reachable\)$
2020
^\[main.assertion.15\] .* \*\*\(b\+1\)==11: Success$
2121
^\[main.assertion.16\] .* \*\*\(b\+1\)==13: Failure \(if reachable\)$
22-
^\[main.assertion.17\] .* \*\*\(1\+b\)==11: Unknown$
23-
^\[main.assertion.18\] .* \*\*\(1\+b\)==13: Unknown$
22+
^\[main.assertion.17\] .* \*\*\(1\+b\)==11: Success$
23+
^\[main.assertion.18\] .* \*\*\(1\+b\)==13: Failure \(if reachable\)$
2424
^\[main.assertion.19\] .* \*1\[b\]==11: Success$
2525
^\[main.assertion.20\] .* \*1\[b\]==13: Failure \(if reachable\)$
2626
^\[main.assertion.21\] .* c\[0\]==&c0: Unknown$

regression/goto-analyzer/sensitivity-test-constants-pointer-to-constants-array/test.desc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ sensitivity_test_constants_pointer_to_constants_array.c
55
^SIGNAL=0$
66
^\[main.assertion.1\] .* p==&a\[0\]: Success$
77
^\[main.assertion.2\] .* \*p==1: Success$
8-
^\[main\.assertion\.3\] .* p\[1\]==2: Unknown$
9-
^\[main\.assertion\.4\] .* 1\[p\]==2: Unknown$
10-
^\[main\.assertion\.5\] .* \*\(p\+1\)==2: Unknown$
11-
^\[main\.assertion\.6\] .* \*\(1\+p\)==2: Unknown$
12-
^\[main\.assertion\.7\] .* \*\(p-1\)==1: Unknown$
13-
^\[main\.assertion\.8\] .* q==p\+1: Unknown$
14-
^\[main\.assertion\.9\] .* \*q==2: Unknown$
8+
^\[main\.assertion\.3\] .* p\[1\]==2: Success$
9+
^\[main\.assertion\.4\] .* 1\[p\]==2: Success$
10+
^\[main\.assertion\.5\] .* \*\(p\+1\)==2: Success$
11+
^\[main\.assertion\.6\] .* \*\(1\+p\)==2: Success$
12+
^\[main\.assertion\.7\] .* q==p\+1: Success$
13+
^\[main\.assertion\.8\] .* \*q==2: Success$
14+
^\[main\.assertion\.9\] .* \*\(q-1\)==1: Success$
1515
^\[main\.assertion\.10\] .* q-p==x: Unknown$
16-
^\[main\.assertion\.11\] .* a\[1\]==4: Unknown$
17-
^\[main\.assertion\.12\] .* a\[1\]==5: Unknown$
18-
^\[main\.assertion\.13\] .* a\[1\]==6: Unknown$
19-
^\[main\.assertion\.14\] .* a\[1\]==7: Unknown$
16+
^\[main\.assertion\.11\] .* a\[1\]==4: Success$
17+
^\[main\.assertion\.12\] .* a\[1\]==5: Success$
18+
^\[main\.assertion\.13\] .* a\[1\]==6: Success$
19+
^\[main\.assertion\.14\] .* a\[1\]==7: Success$
2020
^\[main\.assertion\.15\] .* \*r==2: Unknown$
2121
^\[main\.assertion\.16\] .* \*r==1: Unknown$
2222
^\[main\.assertion\.17\] .* \*s==0: Unknown$

regression/goto-analyzer/sensitivity-test-constants-pointer-to-two-value-array/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ sensitivity_test_constants_pointer_to_two_value_array.c
99
^\[main\.assertion\.4\] .* 1\[p\]==2: Unknown$
1010
^\[main\.assertion\.5\] .* \*\(p\+1\)==2: Unknown$
1111
^\[main\.assertion\.6\] .* \*\(1\+p\)==2: Unknown$
12-
^\[main\.assertion\.7\] .* \*\(p-1\)==1: Unknown$
13-
^\[main.assertion.8\] .* q==p\+1: Unknown$
14-
^\[main.assertion.9\] .* \*q==2: Unknown$
12+
^\[main.assertion\.7\] .* q==p\+1: Success$
13+
^\[main.assertion\.8\] .* \*q==2: Unknown$
14+
^\[main\.assertion\.9\] .* \*\(q-1\)==1: Unknown$
1515
^\[main.assertion.10\] .* q-p==x: Unknown$
1616
^\[main.assertion.11\] .* a\[1\]==4: Unknown$
1717
^\[main.assertion.12\] .* a\[1\]==5: Unknown$

regression/goto-analyzer/sensitivity-test-two-value-pointer-to-two-value-array/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ sensitivity_test_two_value_pointer_to_two_value_array.c
99
^\[main\.assertion\.4\] .* 1\[p\]==2: Unknown$
1010
^\[main\.assertion\.5\] .* \*\(p\+1\)==2: Unknown$
1111
^\[main\.assertion\.6\] .* \*\(1\+p\)==2: Unknown$
12-
^\[main\.assertion\.7\] .* \*\(p-1\)==1: Unknown$
13-
^\[main\.assertion\.8\] .* q==p\+1: Unknown$
14-
^\[main\.assertion\.9\] .* \*q==2: Unknown$
12+
^\[main\.assertion\.7\] .* q==p\+1: Unknown$
13+
^\[main\.assertion\.8\] .* \*q==2: Unknown$
14+
^\[main\.assertion\.9\] .* \*\(q-1\)==1: Unknown$
1515
^\[main\.assertion\.10\] .* q-p==x: Unknown$
1616
^\[main\.assertion\.11\] .* a\[1\]==4: Unknown$
1717
^\[main\.assertion\.12\] .* a\[1\]==5: Unknown$

src/analyses/variable-sensitivity/constant_pointer_abstract_object.cpp

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
3232
pointer_abstract_objectt(t)
3333
{
3434
assert(t.id()==ID_pointer);
35-
value=nil_exprt();
3635
}
3736

3837
/*******************************************************************\
@@ -56,7 +55,6 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
5655
pointer_abstract_objectt(t, tp, bttm)
5756
{
5857
assert(t.id()==ID_pointer);
59-
value=nil_exprt();
6058
}
6159

6260
/*******************************************************************\
@@ -74,7 +72,7 @@ Function: constant_pointer_abstract_objectt::constant_pointer_abstract_objectt
7472

7573
constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
7674
const constant_pointer_abstract_objectt &old):
77-
pointer_abstract_objectt(old), value(old.value)
75+
pointer_abstract_objectt(old), value_stack(old.value_stack)
7876
{}
7977

8078
/*******************************************************************\
@@ -94,26 +92,11 @@ constant_pointer_abstract_objectt::constant_pointer_abstract_objectt(
9492
const exprt &e,
9593
const abstract_environmentt &environment,
9694
const namespacet &ns):
97-
pointer_abstract_objectt(e, environment, ns)
95+
pointer_abstract_objectt(e, environment, ns),
96+
value_stack(e, environment, ns)
9897
{
9998
assert(e.type().id()==ID_pointer);
100-
value=nil_exprt();
101-
102-
if(e.id()==ID_address_of)
103-
{
104-
value=e;
105-
top=false;
106-
}
107-
else if(e.id()==ID_constant)
108-
{
109-
constant_exprt constant_expr(to_constant_expr(e));
110-
if(constant_expr.get_value()==ID_NULL)
111-
{
112-
value=e;
113-
top=false;
114-
}
115-
}
116-
// Else unknown expression type - possibly we should handle more
99+
top=value_stack.is_top_value();
117100
}
118101

119102
/*******************************************************************\
@@ -174,8 +157,10 @@ abstract_object_pointert
174157
}
175158
else
176159
{
177-
// Can we actually merge these value
178-
if(value==other->value)
160+
bool matching_pointer=
161+
value_stack.to_expression()==other->value_stack.to_expression();
162+
163+
if(matching_pointer)
179164
{
180165
return shared_from_this();
181166
}
@@ -213,7 +198,7 @@ exprt constant_pointer_abstract_objectt::to_constant() const
213198
{
214199
// TODO(tkiley): I think we would like to eval this before using it
215200
// in the to_constant.
216-
return value;
201+
return value_stack.to_expression();
217202
}
218203
}
219204

@@ -236,33 +221,27 @@ Function: constant_pointer_abstract_objectt::output
236221
void constant_pointer_abstract_objectt::output(
237222
std::ostream &out, const ai_baset &ai, const namespacet &ns) const
238223
{
239-
if(is_top() || is_bottom())
224+
if(is_top() || is_bottom() || value_stack.is_top_value())
240225
{
241226
pointer_abstract_objectt::output(out, ai, ns);
242227
}
243228
else
244229
{
245-
if(value.id()==ID_constant && value.get(ID_value)==ID_NULL)
246-
{
247-
out << "NULL";
248-
}
249-
else
230+
out << "ptr ->(";
231+
const exprt &value=value_stack.to_expression();
232+
if(value.id()==ID_address_of)
250233
{
251-
out << "ptr ->(";
252-
if(value.id()==ID_address_of)
234+
const address_of_exprt &address_expr(to_address_of_expr(value));
235+
if(address_expr.object().id()==ID_symbol)
253236
{
254-
const address_of_exprt &address_expr(to_address_of_expr(value));
255-
if(address_expr.object().id()==ID_symbol)
256-
{
257-
const symbol_exprt &symbol_pointed_to(
258-
to_symbol_expr(address_expr.object()));
259-
260-
out << symbol_pointed_to.get_identifier();
261-
}
262-
}
237+
const symbol_exprt &symbol_pointed_to(
238+
to_symbol_expr(address_expr.object()));
263239

264-
out << ")";
240+
out << symbol_pointed_to.get_identifier();
241+
}
265242
}
243+
244+
out << ")";
266245
}
267246
}
268247

@@ -286,28 +265,16 @@ Function: constant_pointer_abstract_objectt::read_dereference
286265
abstract_object_pointert constant_pointer_abstract_objectt::read_dereference(
287266
const abstract_environmentt &env, const namespacet &ns) const
288267
{
289-
if(is_top() || is_bottom() || value.id()==ID_nil)
268+
if(is_top() || is_bottom() || value_stack.is_top_value())
290269
{
291270
// Return top if dereferencing a null pointer or we are top
292-
bool is_value_top = is_top() || value.id()==ID_nil;
271+
bool is_value_top = is_top() || value_stack.is_top_value();
293272
return env.abstract_object_factory(
294273
type().subtype(), ns, is_value_top, !is_value_top);
295274
}
296275
else
297276
{
298-
if(value.id()==ID_address_of)
299-
{
300-
return env.eval(value.op0(), ns);
301-
}
302-
else if(value.id()==ID_constant)
303-
{
304-
// Reading a null pointer, return top
305-
return env.abstract_object_factory(type().subtype(), ns, true, false);
306-
}
307-
else
308-
{
309-
return env.abstract_object_factory(type().subtype(), ns, true, false);
310-
}
277+
return env.eval(value_stack.to_expression().op0(), ns);
311278
}
312279
}
313280

@@ -344,22 +311,13 @@ sharing_ptrt<pointer_abstract_objectt>
344311
const abstract_object_pointert new_value,
345312
bool merging_write) const
346313
{
347-
if(is_top() || is_bottom())
314+
if(is_top() || is_bottom() || value_stack.is_top_value())
348315
{
349316
return pointer_abstract_objectt::write_dereference(
350317
environment, ns, stack, new_value, merging_write);
351318
}
352319
else
353320
{
354-
// If not an address, we don't know what we are pointing to
355-
if(value.id()!=ID_address_of)
356-
{
357-
return pointer_abstract_objectt::write_dereference(
358-
environment, ns, stack, new_value, merging_write);
359-
}
360-
361-
const address_of_exprt &address_expr=to_address_of_expr(value);
362-
363321
sharing_ptrt<constant_pointer_abstract_objectt> copy=
364322
sharing_ptrt<constant_pointer_abstract_objectt>(
365323
new constant_pointer_abstract_objectt(*this));
@@ -369,26 +327,30 @@ sharing_ptrt<pointer_abstract_objectt>
369327
// We should not be changing the type of an abstract object
370328
assert(new_value->type()==type().subtype());
371329

372-
330+
// Get an expression that we can assign to
331+
exprt value=value_stack.to_expression().op0();
373332
if(merging_write)
374333
{
375334
abstract_object_pointert pointed_value=
376-
environment.eval(address_expr.object(), ns);
335+
environment.eval(value, ns);
377336
bool modifications;
378337
abstract_object_pointert merged_value=
379338
abstract_objectt::merge(pointed_value, new_value, modifications);
380-
environment.assign(address_expr.object(), merged_value, ns);
339+
environment.assign(value, merged_value, ns);
381340
}
382341
else
383342
{
384-
environment.assign(address_expr.object(), new_value, ns);
343+
environment.assign(value, new_value, ns);
385344
}
386345
}
387346
else
388347
{
348+
exprt value=value_stack.to_expression().op0();
389349
abstract_object_pointert pointed_value=
390-
environment.eval(address_expr.object(), ns);
391-
environment.write(pointed_value, new_value, stack, ns, merging_write);
350+
environment.eval(value, ns);
351+
abstract_object_pointert modified_value=
352+
environment.write(pointed_value, new_value, stack, ns, merging_write);
353+
environment.assign(value, modified_value, ns);
392354

393355
// but the pointer itself does not change!
394356
}

src/analyses/variable-sensitivity/constant_pointer_abstract_object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <iosfwd>
1212

1313
#include <analyses/variable-sensitivity/pointer_abstract_object.h>
14+
#include <analyses/variable-sensitivity/write_stack.h>
1415

1516
class constant_pointer_abstract_objectt:public pointer_abstract_objectt
1617
{
@@ -57,7 +58,7 @@ class constant_pointer_abstract_objectt:public pointer_abstract_objectt
5758
abstract_object_pointert merge_constant_pointers(
5859
const constant_pointer_abstract_pointert other) const;
5960

60-
exprt value;
61+
write_stackt value_stack;
6162
};
6263

6364
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_CONSTANT_POINTER_ABSTRACT_OBJECT_H // NOLINT(*)

0 commit comments

Comments
 (0)