Skip to content

Commit fae55f8

Browse files
committed
Fixed logic in assumptions
Use appropriate Boolean connectives to actually make assertions hold.
1 parent b2b61a7 commit fae55f8

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
int main()
2+
{
3+
int a[2][2];
4+
int b[2][2];
5+
int c[2][2];
6+
int d[2][2];
7+
8+
// clang-format off
9+
// clang-format would rewrite the "==>" as "== >"
10+
// NOLINTNEXTLINE(whitespace/line_length)
11+
__CPROVER_assume(!__CPROVER_exists { int i; (i>=0 && i<2) && (__CPROVER_exists{int j; (j>=0 && j<2) && a[i][j]<=10}) });
12+
13+
assert(0);
14+
15+
// NOLINTNEXTLINE(whitespace/line_length)
16+
__CPROVER_assume(__CPROVER_forall { int i; (i>=0 && i<2) ==> (!__CPROVER_exists{int j; (j>=0 && j<2) && b[i][j]>=1 && b[i][j]<=10}) });
17+
18+
assert(0);
19+
20+
// NOLINTNEXTLINE(whitespace/line_length)
21+
__CPROVER_assume(!__CPROVER_exists { int i; (i>=0 && i<2) && (!__CPROVER_exists{int j; (j>=0 && j<2) && (c[i][j]==0 || c[i][j]<=10)}) });
22+
23+
assert(0);
24+
25+
// NOLINTNEXTLINE(whitespace/line_length)
26+
__CPROVER_assume(!__CPROVER_exists { int i; (i>=0 && i<2) && (__CPROVER_forall{int j; (j>=0 && j<2) ==> d[i][j]>=1 && d[i][j]<=10}) });
27+
// clang-format on
28+
29+
assert(0);
30+
31+
assert(a[0][0] > 10);
32+
33+
assert((b[0][0] < 1 || b[0][0] > 10) && (b[0][1] < 1 || b[0][1] > 10));
34+
assert((b[1][0] < 1 || b[1][0] > 10) && (b[1][1] < 1 || b[1][1] > 10));
35+
36+
assert(c[0][0] == 0 || c[0][1] == 0 || c[1][0] <= 10 || c[1][1] <= 10);
37+
38+
assert(((d[0][0] < 1 || d[0][0] > 10) || (d[0][1] < 1 || d[0][1] > 10)));
39+
assert(((d[1][0] < 1 || d[1][0] > 10) || (d[1][1] < 1 || d[1][1] > 10)));
40+
41+
return 0;
42+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
fixed.c
3+
4+
^\*\* Results:$
5+
^\[main.assertion.5\] line 31 assertion a\[.*\]\[.*\] > 10: SUCCESS$
6+
^\[main.assertion.6\] line 33 assertion tmp_if_expr\$\d+: SUCCESS$
7+
^\[main.assertion.7\] line 34 assertion tmp_if_expr\$\d+: SUCCESS$
8+
^\[main.assertion.8\] line 36 assertion tmp_if_expr\$\d+: SUCCESS$
9+
^\[main.assertion.9\] line 38 assertion tmp_if_expr\$\d+: SUCCESS$
10+
^\[main.assertion.10\] line 39 assertion tmp_if_expr\$\d+: SUCCESS$
11+
^\*\* 4 of 10 failed
12+
^VERIFICATION FAILED$
13+
^EXIT=10$
14+
^SIGNAL=0$
15+
--
16+
^warning: ignoring
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
int main()
2+
{
3+
int a[2][2];
4+
int b[2][2];
5+
6+
// clang-format off
7+
// clang-format would rewrite the "==>" as "== >"
8+
// NOLINTNEXTLINE(whitespace/line_length)
9+
__CPROVER_assume(__CPROVER_forall { int i; (i>=0 && i<2) ==> (__CPROVER_forall{int j; (j>=0 && j<2) ==> a[i][j]==i+j}) });
10+
// NOLINTNEXTLINE(whitespace/line_length)
11+
__CPROVER_assume(__CPROVER_exists { int i; (i>=0 && i<2) && (__CPROVER_exists{int j; (j>=0 && j<2) && b[i][j]==i+j+1}) });
12+
// clang-format on
13+
14+
assert(a[0][0] == 0);
15+
assert(a[0][1] == 1);
16+
assert(a[1][0] == 1);
17+
assert(a[1][1] == 2);
18+
assert(b[0][0] == 1 || b[0][1] == 2 || b[1][0] == 2 || b[1][1] == 3);
19+
return 0;
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
fixed.c
3+
4+
^\*\* Results:$
5+
^\[main.assertion.1\] line 14 assertion a\[.*\]\[.*\] == 0: SUCCESS$
6+
^\[main.assertion.2\] line 15 assertion a\[.*\]\[.*\] == 1: SUCCESS$
7+
^\[main.assertion.3\] line 16 assertion a\[.*\]\[.*\] == 1: SUCCESS$
8+
^\[main.assertion.4\] line 17 assertion a\[.*\]\[.*\] == 2: SUCCESS$
9+
^\[main.assertion.5\] line 18 assertion tmp_if_expr\$\d+: SUCCESS$
10+
^\*\* 0 of 5 failed
11+
^VERIFICATION SUCCESSFUL$
12+
^EXIT=0$
13+
^SIGNAL=0$
14+
--
15+
^warning: ignoring

0 commit comments

Comments
 (0)