Skip to content

Commit bbdcd3f

Browse files
committed
Add a test for checks in the antecedent of a forall quantifier
1 parent c884116 commit bbdcd3f

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

regression/cbmc-primitives/forall_6231_1/test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
int main() {
66
char *a = malloc(1);
77

8-
// lots of errors with `--pointer-check` enabled
98
assert(*a == *a);
109

11-
// no errors even with `--pointer-check` enabled
10+
// BUG: no errors even with `--pointer-check` enabled -- now fixed.
1211
assert(
1312
__CPROVER_forall {
1413
int i ; (0 <= i && i < 1) ==> *(a+i) == *(a+i)

regression/cbmc-primitives/forall_6231_3/test.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
int main() {
1010
char *a = malloc(10);
1111

12-
// lots of errors with `--pointer-check` enabled
1312
assert(*a == *a);
1413

15-
// no errors even with `--pointer-check` enabled
14+
// BUG: no errors even with `--pointer-check` enabled -- now fixed.
1615
assert(
1716
__CPROVER_forall {
1817
int i ; (0 <= i && i < 10) ==> *(a+i) == *(a+i)

regression/cbmc-primitives/forall_6231_3/test_malloc_less_than_bound.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
int main() {
1010
char *a = malloc(4);
1111

12-
// lots of errors with `--pointer-check` enabled
1312
assert(*a == *a);
1413

15-
// no errors even with `--pointer-check` enabled
14+
// BUG: no errors even with `--pointer-check` enabled -- now fixed.
1615
assert(
1716
__CPROVER_forall {
1817
int i ; (0 <= i && i < 10) ==> *(a+i) == *(a+i)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
// Similar to the previous tests in forall_6231_1 but this one aims to check
5+
// the antecedent of the forall expression to make sure that checks are being
6+
// generated correctly for it.
7+
8+
// clang-format off
9+
int main() {
10+
char *a = malloc(10);
11+
int n;
12+
13+
assert(
14+
__CPROVER_forall {
15+
int i ; (0 <= i && i < (n / 0)) /* (n / 0) should be caught by --div-by-zero-check */
16+
==> *(a+i) == *(a+i)
17+
}
18+
);
19+
}
20+
// clang-format on
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
test.c
3+
--div-by-zero-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
\[main\.division-by-zero\.1] line \d+ division by zero in n / 0: FAILURE
7+
^VERIFICATION FAILED$
8+
--
9+
--
10+
--div-by-zero-check should catch the failure in the antecedent.
11+
--pointer-check doesn't but gives an pointer outside object bounds issue.

0 commit comments

Comments
 (0)