Skip to content

Commit 828ace9

Browse files
committed
Add tests to check semantics of pointer primitives
1 parent 9e695ef commit 828ace9

File tree

21 files changed

+220
-0
lines changed

21 files changed

+220
-0
lines changed
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(1);
7+
free(p);
8+
9+
assert(!__CPROVER_DYNAMIC_OBJECT(p));
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Check that the dynamic object property is havoc'd when dynamic objects are
10+
deallocated
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Check that the dynamic object property is havoc'd when dynamic objects are
10+
deallocated
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p;
7+
assert(!__CPROVER_DYNAMIC_OBJECT(p));
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Check that uninitialized pointers are not considered pointing to dynamic objects
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FUTURE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Check that uninitialized pointers are not considered pointing to dynamic objects

regression/cbmc/object-size-01/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
11+
{
12+
char c;
13+
p = &c;
14+
}
15+
16+
assert(__CPROVER_OBJECT_SIZE(p) == 1);
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--no-simplify --no-propagation
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+
--
9+
^warning: ignoring
10+
--
11+
Check that object size is havoc'd when objects are deallocated
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
--
9+
^warning: ignoring
10+
--
11+
Check that object size is havoc'd when objects are deallocated
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <assert.h>
2+
3+
void main()
4+
{
5+
char *p;
6+
assert(__CPROVER_POINTER_OFFSET(p) >= 0);
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
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+
--
8+
^warning: ignoring
9+
--
10+
Check that a negative offset can be chosen for uninitialized pointers
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line \d+ assertion __CPROVER_POINTER_OFFSET\(p\) >= 0: FAILURE
7+
--
8+
^warning: ignoring
9+
--
10+
Check that a negative offset can be chosen for uninitialized pointers

regression/cbmc/same-object-01/main.c

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+
assert(__CPROVER_POINTER_OBJECT(p) == 2);
8+
9+
assert(
10+
__CPROVER_same_object(p, (char *)((size_t)2 << (sizeof(char *) * 8 - 8))));
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
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

regression/cbmc/same-object-02/main.c

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
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

regression/cbmc/same-object-03/main.c

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
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

0 commit comments

Comments
 (0)