Skip to content

Commit e303519

Browse files
committed
Regression test to check pointer havocing in loops
1 parent ffb57e8 commit e303519

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *data = malloc(1);
7+
*data = 42;
8+
9+
unsigned i;
10+
while(i > 0)
11+
__CPROVER_loop_invariant(*data == 42)
12+
{
13+
*data = 42;
14+
i--;
15+
}
16+
17+
assert(*data = 42);
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7+
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[main.assertion.1\] .* assertion \*data = 42: SUCCESS$
9+
^VERIFICATION SUCCESSFUL$
10+
--
11+
^\[main.pointer_dereference.*\] line .* dereference failure: pointer NULL in \*data: FAILURE
12+
--
13+
This test checks that modifications to deref-ed pointers are correctly handled.
14+
In such cases, pointers should not be havoc'ed, only the value should be.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
void main()
5+
{
6+
char *copy, *data = malloc(1);
7+
8+
copy = data;
9+
*data = 42;
10+
11+
unsigned i;
12+
while(i > 0)
13+
__CPROVER_loop_invariant(*data == 42)
14+
{
15+
*data = 42;
16+
i--;
17+
}
18+
19+
assert(data == copy);
20+
assert(*copy = 42);
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts --pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7+
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[main.assertion.1\] .* assertion data == copy: SUCCESS$
9+
^\[main.assertion.2\] .* assertion \*copy = 42: SUCCESS$
10+
^VERIFICATION SUCCESSFUL$
11+
--
12+
^\[main.pointer_dereference.*\] line .* dereference failure: pointer NULL in \*data: FAILURE
13+
--
14+
This test checks that modifications to aliased pointers are correctly handled.

0 commit comments

Comments
 (0)