Skip to content

Commit da7edc5

Browse files
authored
Merge pull request #6815 from NlightNFotis/pointer_objects_smt
Conversion of `pointer_object_exprt` and `pointer_offset_exprt` for new SMT backend
2 parents 91e6220 + e5f91f2 commit da7edc5

File tree

12 files changed

+295
-4
lines changed

12 files changed

+295
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
int main()
2+
{
3+
int a = 10;
4+
int nondet_bool;
5+
int flag = 1;
6+
7+
int *b = &a;
8+
int *c = nondet_bool ? &a : 0;
9+
int *d = flag ? &a : 0;
10+
int *e;
11+
12+
// __CPROVER_same_object is True when
13+
// `__CPROVER_pointer_object(a) == __CPROVER_pointer_object(b)`
14+
__CPROVER_assert(
15+
__CPROVER_same_object(b, c), "expected fail as c can be null");
16+
__CPROVER_assert(
17+
__CPROVER_same_object(b, d), "expected success because d is &a");
18+
__CPROVER_assert(
19+
__CPROVER_same_object(b, e), "expected fail as e can be null");
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
pointer_object.c
3+
--trace --verbosity 10
4+
\[main\.assertion\.1\] line \d+ expected fail as c can be null: FAILURE
5+
\[main\.assertion\.2\] line \d+ expected success because d is &a: SUCCESS
6+
\[main\.assertion\.3\] line \d+ expected fail as e can be null: FAILURE
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <assert.h>
2+
#include <stdbool.h>
3+
4+
int main()
5+
{
6+
int x;
7+
int y;
8+
int z;
9+
bool nondet1;
10+
bool nondet2;
11+
int *a = nondet1 ? &x : &y;
12+
int *b = nondet2 ? &y : &z;
13+
__CPROVER_assert(!__CPROVER_same_object(a, b), "Can be violated.");
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
pointer_object2.c
3+
--trace --verbosity 10
4+
\[main\.assertion\.1\] line 13 Can be violated.: FAILURE
5+
nondet1=FALSE
6+
nondet2=TRUE
7+
^VERIFICATION FAILED$
8+
^EXIT=10$
9+
^SIGNAL=0$
10+
--
11+
--
12+
Ensure that two variables which can get assigned the address of the
13+
same object satisfy the __CPROVER_same_object predicate. In the code
14+
under test, we negate the predicate to be able to get a failure and a
15+
trace which we can then match against expected values which guide
16+
through the path that leads to the two variables getting assigned the
17+
same object.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#define NULL (void *)0
2+
3+
int main()
4+
{
5+
int foo;
6+
7+
// The identifiers are allocated deterministically, so we want to check the
8+
// following properties hold:
9+
10+
// The pointer object of NULL is always going to be zero.
11+
__CPROVER_assert(
12+
__CPROVER_POINTER_OBJECT(NULL) != 0,
13+
"expected to fail with object ID == 0");
14+
// In the case where the program contains a single address of operation,
15+
// the pointer object is going to be 1.
16+
__CPROVER_assert(
17+
__CPROVER_POINTER_OBJECT(&foo) != 1,
18+
"expected to fail with object ID == 1");
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
pointer_object3.c
3+
4+
\[main\.assertion\.1] line \d+ expected to fail with object ID == 0: FAILURE
5+
\[main\.assertion\.2] line \d+ expected to fail with object ID == 1: FAILURE
6+
^VERIFICATION FAILED$
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
--
10+
--
11+
Test that the assignment of object IDs to objects is deterministic:
12+
* 0 for the NULL object, and
13+
* 1 for the single object which is the result of an address of operation
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
int main()
2+
{
3+
int a;
4+
int *p = &a;
5+
int *q = &a;
6+
7+
__CPROVER_assert(
8+
__CPROVER_POINTER_OFFSET(p) != __CPROVER_POINTER_OFFSET(q),
9+
"expected failure because offsets should be the same");
10+
11+
// TODO: Remove comments once pointer arithmetic works:
12+
13+
// *q = p + 2;
14+
15+
// __CPROVER_assert(__CPROVER_POINTER_OFFSET(p) != __CPROVER_POINTER_OFFSET(q), "expected failure");
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
pointer_offset.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ expected failure because offsets should be the same: FAILURE
5+
^VERIFICATION FAILED$
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
--
9+
--
10+
Test that the pointer offset bits of two pointers pointing to
11+
the same object are equal.
12+
13+
The test also contains a fragment of the test which doesn't work
14+
for now, but would be good to be added as soon as we get pointer
15+
arithmetic to work, so we can make sure that pointer offset fails
16+
appropriately.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int main()
2+
{
3+
int a = 10;
4+
int *b = &a;
5+
int c;
6+
7+
*b = 12;
8+
9+
__CPROVER_assert(a != *b, "a should be different than b");
10+
__CPROVER_assert(a == *b, "a should not be different than b");
11+
__CPROVER_assert(
12+
*b != c,
13+
"c can get assigned a value that makes it the same what b points to");
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
pointers_simple.c
3+
--trace
4+
Passing problem to incremental SMT2 solving
5+
\[main\.assertion.\d\] line \d a should be different than b: FAILURE
6+
\[main\.assertion.\d\] line \d+ a should not be different than b: SUCCESS
7+
\[main\.assertion.\d\] line \d+ c can get assigned a value that makes it the same what b points to: FAILURE
8+
c=12
9+
^EXIT=10$
10+
^SIGNAL=0$
11+
--
12+
--

0 commit comments

Comments
 (0)