Skip to content

Commit f514175

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 f514175

File tree

24 files changed

+288
-0
lines changed

24 files changed

+288
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p;
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+
}
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = malloc(1);
7+
free(p);
8+
9+
__CPROVER_assume(__CPROVER_r_ok(p, 1));
10+
assert(0); // fails
11+
*p; // succeeds
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--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+
--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: 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 test_global_pointer()
5+
{
6+
char *p = (size_t)123 << (sizeof(char *) * 8 - 1) | 123;
7+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
8+
assert(0); // fails without constant propagator
9+
*p; // succeeds
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FUTURE
2+
main.c
3+
--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+
--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+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
// special value of invalid pointer
7+
char *p = (size_t)1 << (sizeof(char *) * 8 - 8);
8+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
9+
assert(0); // fails
10+
*p; // succeeds
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--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+
--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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
3+
void main()
4+
{
5+
char *p = nondet();
6+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
7+
assert(0); // fails
8+
*p; // succeeds
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FUTURE
2+
main.c
3+
--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+
--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+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *p = NULL;
7+
__CPROVER_assume(__CPROVER_r_ok(p, 10));
8+
assert(0); // succeeds
9+
*p; // succeeds
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+
--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).
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--pointer-check
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).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char c1;
5+
6+
void main()
7+
{
8+
char c2;
9+
10+
char *p1 = &c1;
11+
char *p2 = &c2;
12+
char *p3 = malloc(1);
13+
14+
__CPROVER_assume(
15+
__CPROVER_r_ok(p1, 2) ||
16+
__CPROVER_r_ok(p1 - 1, 1) ||
17+
__CPROVER_r_ok(p1 + 1, 1) ||
18+
__CPROVER_r_ok(p2, 2) ||
19+
__CPROVER_r_ok(p2 - 1, 1) ||
20+
__CPROVER_r_ok(p2 + 1, 1) ||
21+
__CPROVER_r_ok(p3, 2) ||
22+
__CPROVER_r_ok(p3 - 1, 1) ||
23+
__CPROVER_r_ok(p3 + 1, 1));
24+
25+
assert(0); // succeeds
26+
*p1; // succeeds
27+
*p2; // succeeds
28+
*p3; // succeeds
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
KNOWNBUG
2+
main.c
3+
--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 a valid memory
10+
object (though potentially with an offset that is out of bounds) and
11+
__CPROVER_r_ok() can be detected via 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+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a pointer to a valid memory
10+
object (though potentially with an offset that is out of bounds) and
11+
__CPROVER_r_ok() can be detected via assert(0).
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
char c1;
5+
6+
void main()
7+
{
8+
char c2;
9+
10+
char *p1 = &c1;
11+
char *p2 = &c2;
12+
13+
char *p3 = malloc(1);
14+
__CPROVER_assume(p1 != NULL);
15+
16+
__CPROVER_assume(
17+
!__CPROVER_r_ok(p1, 1) ||
18+
!__CPROVER_r_ok(p2, 1) ||
19+
!__CPROVER_r_ok(p3, 1));
20+
21+
assert(0);
22+
*p1;
23+
*p2;
24+
*p3;
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--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 valid pointer and a negated
10+
use of __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+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
--
9+
Tests that an inconsistent assumption involving a valid pointer and a negated
10+
use of __CPROVER_r_ok() can be detected via assert(0).

0 commit comments

Comments
 (0)