Skip to content

Commit fa60778

Browse files
committed
Add regression tests to for inconsistent assumptions involving __CPROVER_r_ok()
Adds tests to check that inconsistent assumptions involving __CPROVER_r_ok() can be detected by checking if a subsequent assert(0) fails.
1 parent d3f1fc4 commit fa60778

40 files changed

+593
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char *p;
5+
6+
void test_global_pointer()
7+
{
8+
{
9+
char c;
10+
p = &c;
11+
}
12+
13+
__CPROVER_assume(__CPROVER_r_ok(p, 1));
14+
assert(0); // fails
15+
*p; // succeeds
16+
}
17+
18+
void test_local_pointer()
19+
{
20+
char *q;
21+
22+
{
23+
char c;
24+
q = &c;
25+
}
26+
27+
__CPROVER_assume(__CPROVER_r_ok(q, 1));
28+
assert(0); // fails
29+
*q; // succeeds
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer to an out of scope
10+
variable and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer to an out of scope
10+
variable and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer to an out of scope
10+
variable and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer to an out of scope
10+
variable and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char *p;
5+
6+
void test_global_pointer()
7+
{
8+
p = malloc(1);
9+
free(p);
10+
11+
__CPROVER_assume(__CPROVER_r_ok(p, 1));
12+
assert(0); // fails
13+
*p; // succeeds
14+
}
15+
16+
void test_local_pointer()
17+
{
18+
char *q;
19+
20+
q = malloc(1);
21+
free(q);
22+
23+
__CPROVER_assume(__CPROVER_r_ok(q, 1));
24+
assert(0); // fails
25+
*q; // succeeds
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char *p;
5+
6+
void test_global_pointer()
7+
{
8+
p = (size_t)123 << (sizeof(char *) * 8 - 1) | 123;
9+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
10+
assert(0); // fails without constant propagator
11+
*p; // succeeds
12+
}
13+
14+
void test_local_pointer()
15+
{
16+
char *q;
17+
18+
q = (size_t)123 << (sizeof(char *) * 8 - 1) | 123;;
19+
__CPROVER_assume(__CPROVER_r_ok(q, 10));
20+
assert(0); // fails without constant propagator
21+
*q; // succeeds
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--function test_local_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer initialized to an
10+
integer address not pointing to memory and __CPROVER_r_ok() can be detected via
11+
assert(0).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char *p;
5+
6+
void test_global_pointer()
7+
{
8+
// special value of invalid pointer
9+
p = (size_t)1 << (sizeof(char *) * 8 - 8);
10+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
11+
assert(0); // fails
12+
*p; // succeeds
13+
}
14+
15+
void test_local_pointer()
16+
{
17+
char *q;
18+
19+
// special value of invalid pointer
20+
q = (size_t)1 << (sizeof(char *) * 8 - 8);
21+
__CPROVER_assume(__CPROVER_r_ok(q, 10));
22+
assert(0); // fails
23+
*q; // succeeds
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving the special invalid pointer
10+
value and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving the special invalid pointer
10+
value and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function test_local_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving the special invalid pointer
10+
value and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function test_local_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving the special invalid pointer
10+
value and __CPROVER_r_ok() can be detected via assert(0).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <assert.h>
2+
3+
char *p;
4+
5+
void test_global_pointer()
6+
{
7+
p = nondet();
8+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
9+
assert(0); // fails
10+
*p; // succeeds
11+
}
12+
13+
void test_local_pointer()
14+
{
15+
char *q;
16+
17+
q = nondet();
18+
__CPROVER_assume(__CPROVER_r_ok(q, 10));
19+
assert(0); // fails
20+
*q; // succeeds
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a nondet pointer and
10+
__CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_global_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a nondet pointer and
10+
__CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a nondet pointer and
10+
__CPROVER_r_ok() can be detected via assert(0).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--function test_local_pointer --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a nondet pointer and
10+
__CPROVER_r_ok() can be detected via assert(0).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char *p;
5+
6+
void test_global_pointer()
7+
{
8+
p = NULL;
9+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
10+
assert(0); // succeeds
11+
*p; // succeeds
12+
}
13+
14+
void test_local_pointer()
15+
{
16+
char *q;
17+
18+
q = NULL;
19+
__CPROVER_assume(__CPROVER_r_ok(q, 10));
20+
assert(0); // succeeds
21+
*q; // succeeds
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function test_global_pointer --pointer-check --no-simplify --no-propagation
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a null pointer and
10+
__CPROVER_r_ok() can be detected via assert(0).

0 commit comments

Comments
 (0)