Skip to content

Commit eafdbc0

Browse files
committed
Adds regression test to cover code contracts support
Code contracts now supports assigns clause with structs and array ranges. It also supports contracts specified across multiple source files. So, we added regression tests to cover these capabilites. Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent 58403c2 commit eafdbc0

File tree

31 files changed

+448
-20
lines changed

31 files changed

+448
-20
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void f1(int a[], int len) __CPROVER_assigns(a)
2+
{
3+
int b[10];
4+
a = b;
5+
int *indr = a + 2;
6+
*indr = 5;
7+
}
8+
9+
int main()
10+
{
11+
int arr[10];
12+
f1(arr, 10);
13+
14+
return 0;
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks their assigns clause behavior when it reasons (indirectly)
10+
over a freshly-allocated variable.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int idx = 4;
4+
5+
int nextIdx() __CPROVER_assigns(idx)
6+
{
7+
idx++;
8+
return idx;
9+
}
10+
11+
void f1(int a[], int len)
12+
{
13+
a[nextIdx()] = 5;
14+
}
15+
16+
int main()
17+
{
18+
int arr[10];
19+
f1(arr, 10);
20+
21+
assert(idx == 5);
22+
23+
return 0;
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether the instrumentation process does not duplicate function calls
10+
used as part of array-index operations, i.e., if a function call is used in
11+
the computation of the index of an array assignment, then instrumenting that
12+
statement with an assigns clause will not result in multiple function calls.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assign_out_under(int a[], int len) __CPROVER_assigns(a)
2+
{
3+
a[1] = 5;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assign_out_under(arr, 10);
10+
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned at an index
10+
below its lower bound.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
void assigns_single(int a[], int len) __CPROVER_assigns(a)
2+
{
3+
}
4+
5+
void assigns_range(int a[], int len) __CPROVER_assigns(a)
6+
{
7+
}
8+
9+
void assigns_big_range(int a[], int len) __CPROVER_assigns(a)
10+
{
11+
assigns_single(a, len);
12+
assigns_range(a, len);
13+
}
14+
15+
int main()
16+
{
17+
int arr[10];
18+
assigns_big_range(arr, 10);
19+
20+
return 0;
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned through
10+
calls to functions with array assigns clauses which are compatible with
11+
that of the caller.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
void assigns_ptr(int *x) __CPROVER_assigns(*x)
2+
{
3+
*x = 200;
4+
}
5+
6+
void assigns_range(int a[], int len) __CPROVER_assigns(a)
7+
{
8+
int *ptr = &(a[7]);
9+
assigns_ptr(ptr);
10+
}
11+
12+
int main()
13+
{
14+
int arr[10];
15+
assigns_range(arr, 10);
16+
17+
return 0;
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned via a
10+
function call which assigns a pointer to an element out of the
11+
allowable range.

0 commit comments

Comments
 (0)