Skip to content

Commit 72f9431

Browse files
Long PhamLong Pham
authored andcommitted
Implemented parsing and type checking for loop variants
1 parent f9be0eb commit 72f9431

File tree

21 files changed

+146
-17
lines changed

21 files changed

+146
-17
lines changed

regression/contracts/invar_check_break_pass/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ int main()
66
__CPROVER_assume(r >= 0);
77

88
while(r > 0)
9+
// clang-format off
910
__CPROVER_loop_invariant(r >= 0)
11+
__CPROVER_decreases(r)
12+
// clang-format on
1013
{
1114
--r;
1215
if(r <= 1)

regression/contracts/invar_check_continue/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ int main()
66
__CPROVER_assume(r >= 0);
77

88
while(r > 0)
9+
// clang-format off
910
__CPROVER_loop_invariant(r >= 0)
11+
__CPROVER_decreases(r)
12+
// clang-format on
1013
{
1114
--r;
1215
if(r < 5)

regression/contracts/invar_check_large/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ int main()
2222
int l = 0;
2323
int r = 1;
2424
while(h > l)
25+
// clang-format off
2526
__CPROVER_loop_invariant(
2627
// Turn off `clang-format` because it breaks the `==>` operator.
27-
/* clang-format off */
2828
h >= l &&
2929
0 <= l && l < 5 &&
3030
0 <= h && h < 5 &&
@@ -44,8 +44,9 @@ int main()
4444
(2 > h ==> arr2 >= pivot) &&
4545
(3 > h ==> arr3 >= pivot) &&
4646
(4 > h ==> arr4 >= pivot)
47-
/* clang-format on */
4847
)
48+
__CPROVER_decreases(h - l)
49+
// clang-format on
4950
{
5051
if(*(arr[h]) <= pivot && *(arr[l]) >= pivot)
5152
{

regression/contracts/invar_check_multiple_loops/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ int main()
66
__CPROVER_assume(n > 0 && x == y);
77

88
for(r = 0; r < n; ++r)
9+
// clang-format off
910
__CPROVER_loop_invariant(0 <= r && r <= n && x == y + r)
11+
__CPROVER_decreases(n - r)
12+
// clang-format on
1013
{
1114
x++;
1215
}
1316
while(r > 0)
17+
// clang-format off
1418
__CPROVER_loop_invariant(r >= 0 && x == y + n + (n - r))
19+
__CPROVER_decreases(r)
20+
// clang-format on
1521
{
1622
y--;
1723
r--;

regression/contracts/invar_check_nested_loops/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ int main()
66
__CPROVER_assume(n >= 0);
77

88
for(int i = 0; i < n; ++i)
9+
// clang-format off
910
__CPROVER_loop_invariant(i <= n && s == i)
11+
__CPROVER_decreases(n - i)
12+
// clang-format on
1013
{
1114
int a, b;
1215
__CPROVER_assume(b >= 0 && a == b);
1316

1417
while(a > 0)
18+
// clang-format off
1519
__CPROVER_loop_invariant(a >= 0 && s == i + (b - a))
20+
__CPROVER_decreases(a)
21+
// clang-format on
1622
{
1723
s++;
1824
a--;

regression/contracts/invar_check_pointer_modifies-01/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ void main()
88

99
unsigned i;
1010
while(i > 0)
11+
// clang-format off
1112
__CPROVER_loop_invariant(*data == 42)
13+
__CPROVER_decreases(i)
14+
// clang-format on
1215
{
1316
*data = 42;
1417
i--;

regression/contracts/invar_check_pointer_modifies-02/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ void main()
1010

1111
unsigned i;
1212
while(i > 0)
13+
// clang-format off
1314
__CPROVER_loop_invariant(*data == 42)
15+
__CPROVER_decreases(i)
16+
// clang-format on
1417
{
1518
*data = 42;
1619
i--;

regression/contracts/invar_check_sufficiency/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ int main()
66
__CPROVER_assume(r >= 0);
77

88
while(r > 0)
9+
// clang-format off
910
__CPROVER_loop_invariant(r >= 0)
11+
__CPROVER_decreases(r)
12+
// clang-format on
1013
{
1114
--r;
1215
}

regression/contracts/invar_loop_constant_no_modify/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ int main()
66
int s = 1;
77
__CPROVER_assume(r >= 0);
88
while(r > 0)
9+
// clang-format off
910
__CPROVER_loop_invariant(r >= 0)
11+
__CPROVER_decreases(r)
12+
// clang-format on
1013
{
1114
r--;
1215
}

regression/contracts/invar_loop_constant_pass/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ int main()
55
int r, s = 1;
66
__CPROVER_assume(r >= 0);
77
while(r > 0)
8+
// clang-format off
89
__CPROVER_loop_invariant(r >= 0 && s == 1)
10+
__CPROVER_decreases(r)
11+
// clang-format on
912
{
1013
s = 1;
1114
r--;

0 commit comments

Comments
 (0)