Skip to content

Commit 004fd96

Browse files
authored
Merge pull request #5324 from danpoe/tests/cprover-memory-primitives
Add tests to check semantics of pointer primitives
2 parents 90afd47 + 175d74f commit 004fd96

File tree

24 files changed

+296
-0
lines changed

24 files changed

+296
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(1);
7+
free(p);
8+
9+
assert(__CPROVER_DYNAMIC_OBJECT(p));
10+
assert(!__CPROVER_DYNAMIC_OBJECT(p));
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
7+
\[main.assertion.2\] line \d+ assertion !__CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that the dynamic object property is havoc'd when dynamic objects are
12+
deallocated. We use --no-simplify and --no-propagation to ensure that the case
13+
is not solved by the constant propagation and thus tests the constraint
14+
encoding. Recorded as ADA-526.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
7+
\[main.assertion.2\] line \d+ assertion !__CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that the dynamic object property is havoc'd when dynamic objects are
12+
deallocated. Recorded as ADA-526.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p;
7+
8+
assert(__CPROVER_DYNAMIC_OBJECT(p));
9+
assert(!__CPROVER_DYNAMIC_OBJECT(p));
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
7+
\[main.assertion.2\] line \d+ assertion !__CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that the dynamic object property is nondet for uninitialized pointers. We
12+
use --no-simplify and --no-propagation to ensure that the case is not solved by
13+
the constant propagation and thus tests the constraint encoding. Recorded as
14+
ADA-526.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
7+
\[main.assertion.2\] line \d+ assertion !__CPROVER_DYNAMIC_OBJECT\(p\): FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that the dynamic object property is nondet for uninitialized pointers.
12+
Recorded as ADA-526.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(1);
7+
free(p);
8+
9+
assert(__CPROVER_OBJECT_SIZE(p) == 1);
10+
assert(__CPROVER_OBJECT_SIZE(p) != 1);
11+
12+
{
13+
char c;
14+
p = &c;
15+
}
16+
17+
assert(__CPROVER_OBJECT_SIZE(p) == 1);
18+
assert(__CPROVER_OBJECT_SIZE(p) != 1);
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) == 1: FAILURE
7+
\[main.assertion.2\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) != 1: FAILURE
8+
\[main.assertion.3\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) == 1: FAILURE
9+
\[main.assertion.4\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) != 1: FAILURE
10+
--
11+
^warning: ignoring
12+
--
13+
Check that object size is havoc'd when objects are deallocated. We use
14+
--no-simplify and --no-propagation to ensure that the case is not solved by the
15+
constant propagation and thus tests the constraint encoding. Recorded as
16+
ADA-527.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) == 1: FAILURE
7+
\[main.assertion.2\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) != 1: FAILURE
8+
\[main.assertion.3\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) == 1: FAILURE
9+
\[main.assertion.4\] line \d+ assertion __CPROVER_OBJECT_SIZE\(p\) != 1: FAILURE
10+
--
11+
^warning: ignoring
12+
--
13+
Check that object size is havoc'd when objects are deallocated. Recorded as
14+
ADA-527.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <assert.h>
2+
3+
void main()
4+
{
5+
char *p;
6+
assert(__CPROVER_POINTER_OFFSET(p) >= 0);
7+
assert(__CPROVER_POINTER_OFFSET(p) < 0);
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: FAILURE
7+
\[main.assertion.2\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) < 0: FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that both positive and negative offsets can be chosen for uninitialized
12+
pointers. We use --no-simplify and --no-propagation to ensure that the case is
13+
not solved by the constant propagation and thus tests the constraint encoding.
14+
Recorded as ADA-528.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: FAILURE
7+
\[main.assertion.2\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) < 0: FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
Check that both positive and negative offsets can be chosen for uninitialized
12+
pointers. Recorded as ADA-528.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(1);
7+
assert(__CPROVER_POINTER_OBJECT(p) == 2);
8+
9+
assert(
10+
__CPROVER_same_object(p, (char *)((size_t)2 << (sizeof(char *) * 8 - 8))));
11+
assert(
12+
!__CPROVER_same_object(p, (char *)((size_t)3 << (sizeof(char *) * 8 - 8))));
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is true when given a pointer variable, and an
11+
integer address pointing to the same object. We use --no-simplify and
12+
--no-propagation to ensure that the case is not solved by the constant
13+
propagation and thus tests the constraint encoding.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is true when given a pointer variable, and an
11+
integer address pointing to the same object
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p1 = malloc(1);
7+
char *p2 = malloc(1);
8+
9+
assert(!__CPROVER_same_object(p1, p2));
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is false when given two pointers to different
11+
malloc'd objects. We use --no-simplify and --no-propagation to ensure that the
12+
case is not solved by the constant propagation and thus tests the constraint
13+
encoding.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is false when given two pointers to different
11+
malloc'd objects
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p1 = malloc(1);
7+
free(p1);
8+
char *p2 = malloc(1);
9+
10+
assert(!__CPROVER_same_object(p1, p2));
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is false when given two pointers, with one
11+
of them being freed before the other is allocated. We use --no-simplify and
12+
--no-propagation to ensure that the case is not solved by the constant
13+
propagation and thus tests the constraint encoding.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is false when given two pointers, with one
11+
of them being freed before the other is allocated
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(10);
7+
char *q = p + 5;
8+
9+
assert(__CPROVER_same_object(p, q));
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is true when given a pointer to the start of
11+
a memory block, and a pointer to within the memory block. We use --no-simplify
12+
and --no-propagation to ensure that the case is not solved by the constant
13+
propagation and thus tests the constraint encoding.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
9+
--
10+
Check that __CPROVER_same_object() is true when given a pointer to the start of
11+
a memory block, and a pointer to within the memory block.

0 commit comments

Comments
 (0)