Skip to content

Commit dc7fb2c

Browse files
committed
Create new symbol for each heap-allocation
1 parent 4acb533 commit dc7fb2c

File tree

9 files changed

+51
-8
lines changed

9 files changed

+51
-8
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
int main() {
3+
int *p = malloc(sizeof(int) * 5);
4+
int* q = malloc(sizeof(int) * 10);
5+
6+
int* pp = p;
7+
8+
*p = 10;
9+
++p;
10+
*p = 20;
11+
12+
q[0] = 100;
13+
q[99] = 101;
14+
15+
assert(pp[0] == 10);
16+
assert(pp[1] == 20);
17+
assert(q[0] == 100);
18+
assert(q[99] == 101);
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers constants --vsd-arrays every-element --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .*p\[.*0\] == 10: SUCCESS
7+
\[main.assertion.2\] .*p\[.*1\] == 20: SUCCESS
8+
\[main.assertion.3\] .*q\[.*0\] == 100: SUCCESS
9+
\[main.assertion.4\] .*q\[.*99\] == 101: SUCCESS
10+
--
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--variable-sensitivity --vsd-pointers top-bottom --vsd-arrays every-element --verify
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] .*p\[.*0\] == 10: UNKNOWN
7+
\[main.assertion.2\] .*p\[.*1\] == 20: UNKNOWN
8+
\[main.assertion.3\] .*q\[.*0\] == 100: UNKNOWN
9+
\[main.assertion.4\] .*q\[.*99\] == 101: UNKNOWN
10+
--
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
int main()
33
{
4-
int *i_was_malloced = malloc(sizeof(int) * 10);
5-
6-
// q[0] = 99;
4+
int *p = malloc(sizeof(int) * 10);
5+
int *q = malloc(sizeof(int) * 5);
76
}

regression/goto-analyzer/heap-allocation/test-constant-pointers.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ main.c
33
--variable-sensitivity --vsd-pointers constants --show
44
^EXIT=0$
55
^SIGNAL=0$
6-
main::1::i_was_malloced \(\) -> ptr ->\(allocated-on-heap\[0\]\)
6+
main::1::p \(\) -> ptr ->\(heap-allocation-0\[0\]\)
7+
main::1::q \(\) -> ptr ->\(heap-allocation-1\[0\]\)
78
--

regression/goto-analyzer/heap-allocation/test-two-value-pointers.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ main.c
33
--variable-sensitivity --vsd-pointers top-bottom --show
44
^EXIT=0$
55
^SIGNAL=0$
6-
main::1::i_was_malloced \(\) -> TOP
6+
main::1::p \(\) -> TOP
7+
main::1::q \(\) -> TOP
78
--

regression/goto-analyzer/heap-allocation/test-value-set-pointers.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ main.c
33
--variable-sensitivity --vsd-pointers value-set --show
44
^EXIT=0$
55
^SIGNAL=0$
6-
main::1::i_was_malloced \(\) -> value-set-begin: ptr ->\(allocated-on-heap\) :value-set-end
6+
main::1::p \(\) -> value-set-begin: ptr ->\(heap-allocation-0\) :value-set-end
7+
main::1::q \(\) -> value-set-begin: ptr ->\(heap-allocation-1\) :value-set-end
78
--

src/analyses/variable-sensitivity/variable_sensitivity_object_factory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ variable_sensitivity_object_factoryt::get_abstract_object(
181181
case HEAP_ALLOCATION:
182182
{
183183
auto dynamic_object = exprt(ID_dynamic_object);
184-
dynamic_object.set(ID_identifier, "allocated-on-heap");
184+
dynamic_object.set(
185+
ID_identifier, "heap-allocation-" + std::to_string(heap_allocations++));
185186
auto heap_symbol = unary_exprt(ID_address_of, dynamic_object, e.type());
186187
auto heap_pointer =
187188
get_abstract_object(e.type(), false, false, heap_symbol, environment, ns);

src/analyses/variable-sensitivity/variable_sensitivity_object_factory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class variable_sensitivity_object_factoryt
4444
}
4545

4646
explicit variable_sensitivity_object_factoryt(const vsd_configt &options)
47-
: configuration{options}
47+
: configuration{options}, heap_allocations(0)
4848
{
4949
}
5050

@@ -87,6 +87,7 @@ class variable_sensitivity_object_factoryt
8787
ABSTRACT_OBJECT_TYPET get_abstract_object_type(const typet &type) const;
8888

8989
vsd_configt configuration;
90+
mutable size_t heap_allocations;
9091
};
9192

9293
#endif // CPROVER_ANALYSES_VARIABLE_SENSITIVITY_VARIABLE_SENSITIVITY_OBJECT_FACTORY_H // NOLINT(*)

0 commit comments

Comments
 (0)