Skip to content

Commit 201bb39

Browse files
committed
Add more tests, including failing test cases for the forall case
1 parent f592f1e commit 201bb39

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

regression/cbmc-primitives/forall_6231_1/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <assert.h>
22
#include <stdlib.h>
33

4+
// clang-format off
45
int main() {
56
char *a = malloc(1);
67

@@ -14,3 +15,4 @@ int main() {
1415
}
1516
);
1617
}
18+
// clang-format on

regression/cbmc-primitives/forall_6231_2/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <assert.h>
22
#include <stdlib.h>
33

4+
// clang-format off
45
int main() {
56
char *a = malloc(128);
67

@@ -15,3 +16,4 @@ int main() {
1516
int j; !(0 <= j && j < 1) || (j == 0 && *(a+j) == *(a+j))
1617
});
1718
}
19+
// clang-format on
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+
// This is essentially the same file as in test `forall_6231_1`, with the difference
5+
// being that the forall statement contains a bigger bound, so that we are to have
6+
// more concrete instantiations of the bound variable.
7+
8+
// clang-format off
9+
int main() {
10+
char *a = malloc(10);
11+
12+
// lots of errors with `--pointer-check` enabled
13+
assert(*a == *a);
14+
15+
// no errors even with `--pointer-check` enabled
16+
assert(
17+
__CPROVER_forall {
18+
int i ; (0 <= i && i < 10) ==> *(a+i) == *(a+i)
19+
}
20+
);
21+
}
22+
// clang-format on
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test.c
3+
--pointer-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main\.assertion\.2\] line \d+ assertion __CPROVER_forall \{ int i ; \(0 <= i && i < 10\) ==> \*\(a\+i\) == \*\(a\+i\) \}: SUCCESS
7+
\[main\.pointer_dereference\.7\] line \d+ dereference failure: pointer NULL in a\[\(signed long int\)i\]: SUCCESS
8+
\[main\.pointer_dereference\.8\] line \d+ dereference failure: pointer invalid in a\[\(signed long int\)i\]: SUCCESS
9+
\[main\.pointer_dereference\.9\] line \d+ dereference failure: deallocated dynamic object in a\[\(signed long int\)i\]: SUCCESS
10+
\[main\.pointer_dereference\.10\] line \d+ dereference failure: dead object in a\[\(signed long int\)i\]: SUCCESS
11+
\[main\.pointer_dereference\.11\] line \d+ dereference failure: pointer outside object bounds in a\[\(signed long int\)i\]: SUCCESS
12+
\[main\.pointer_dereference\.12\] line \d+ dereference failure: invalid integer address in a\[\(signed long int\)i\]: SUCCESS
13+
^VERIFICATION SUCCESSFUL$
14+
--
15+
--
16+
This is fixing an issue first reported in https://github.com/diffblue/cbmc/issues/6231
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+
// Similar to our test in `test.c` of this folder, with the difference being
5+
// that the malloc size is less than the bound checked, which implies that the
6+
// check for the pointer being outside the object bounds is expected to fail.
7+
8+
// clang-format off
9+
int main() {
10+
char *a = malloc(4);
11+
12+
// lots of errors with `--pointer-check` enabled
13+
assert(*a == *a);
14+
15+
// no errors even with `--pointer-check` enabled
16+
assert(
17+
__CPROVER_forall {
18+
int i ; (0 <= i && i < 10) ==> *(a+i) == *(a+i)
19+
}
20+
);
21+
}
22+
// clang-format on
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
test_malloc_less_than_bound.c
3+
--pointer-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main\.assertion\.2\] line \d+ assertion __CPROVER_forall \{ int i ; \(0 <= i && i < 10\) ==> \*\(a\+i\) == \*\(a\+i\) \}: SUCCESS
7+
\[main\.pointer_dereference\.7\] line \d+ dereference failure: pointer NULL in a\[\(signed long int\)i\]: SUCCESS
8+
\[main\.pointer_dereference\.8\] line \d+ dereference failure: pointer invalid in a\[\(signed long int\)i\]: SUCCESS
9+
\[main\.pointer_dereference\.9\] line \d+ dereference failure: deallocated dynamic object in a\[\(signed long int\)i\]: SUCCESS
10+
\[main\.pointer_dereference\.10\] line \d+ dereference failure: dead object in a\[\(signed long int\)i\]: SUCCESS
11+
\[main\.pointer_dereference\.11\] line \d+ dereference failure: pointer outside object bounds in a\[\(signed long int\)i\]: FAILURE
12+
\[main\.pointer_dereference\.12\] line \d+ dereference failure: invalid integer address in a\[\(signed long int\)i\]: SUCCESS
13+
^VERIFICATION FAILED$
14+
--
15+
--
16+
This is fixing an issue first reported in https://github.com/diffblue/cbmc/issues/6231

0 commit comments

Comments
 (0)