Skip to content

Commit 9626a00

Browse files
committed
Fixes regression tests for function contracts
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
1 parent 0b54050 commit 9626a00

File tree

13 files changed

+51
-13
lines changed

13 files changed

+51
-13
lines changed

regression/contracts/assigns_enforce_arrays_01/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ void f1(int a[], int len) __CPROVER_assigns(a)
44
a = b;
55
int *indr = a + 2;
66
*indr = 5;
7+
a[5] = 2;
78
}
89

910
int main()

regression/contracts/assigns_enforce_arrays_02/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ int nextIdx() __CPROVER_assigns(idx)
88
return idx;
99
}
1010

11-
void f1(int a[], int len)
11+
void f1(int a[], int len) __CPROVER_assigns(*a, idx)
1212
{
1313
a[nextIdx()] = 5;
1414
}

regression/contracts/assigns_enforce_arrays_02/test.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ Checks whether the instrumentation process does not duplicate function calls
1010
used as part of array-index operations, i.e., if a function call is used in
1111
the computation of the index of an array assignment, then instrumenting that
1212
statement with an assigns clause will not result in multiple function calls.
13+
This test also ensures that assigns clauses correctly check for global
14+
variables modified by subcalls.

regression/contracts/assigns_enforce_arrays_03/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ main.c
66
^VERIFICATION FAILED$
77
--
88
--
9-
Checks whether verification fails when an array is assigned at an index
10-
below its lower bound.
9+
Checks whether verification fails when an assigns clause contains pointer,
10+
but function only modifies its content.

regression/contracts/assigns_enforce_arrays_05/test.desc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ main.c
66
^VERIFICATION FAILED$
77
--
88
--
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.
9+
Checks whether verification fails when an assigns clause of a function
10+
indicates the pointer might change, but one of its internal function only
11+
modified its content.
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) __CPROVER_assigns(*a)
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: 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+
This test also ensures that assigns clauses correctly check for global
10+
variables modified by subcalls. In this case, since the assigns clause
11+
doesn't include the modified global variable, the verification should failed.

regression/contracts/assigns_enforce_malloc_01/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
22

3-
int f1(int *a, int *b) __CPROVER_assigns(*a)
3+
int f1(int *a, int *b) __CPROVER_assigns(*a, b)
44
{
55
b = (int *)malloc(sizeof(int));
66
*b = 5;

regression/contracts/assigns_enforce_malloc_02/main.c

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

3-
int f1(int *a, int *b) __CPROVER_assigns(*a)
3+
int f1(int *a, int *b) __CPROVER_assigns(*a, b)
44
{
55
while(*a > 0)
66
{
7-
int *b = (int *)malloc(sizeof(int));
7+
b = (int *)malloc(sizeof(int));
88
*b = 5;
99
}
1010
}

regression/contracts/assigns_enforce_multi_file_02/header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct pair_of_pairs
1414

1515
int f1(int *a, struct pair *b);
1616

17-
int f1(int *a, struct pair *b) __CPROVER_assigns(*a)
17+
int f1(int *a, struct pair *b) __CPROVER_assigns(*a, b)
1818
{
1919
struct pair_of_pairs *pop =
2020
(struct pair_of_pairs *)malloc(sizeof(struct pair_of_pairs));

0 commit comments

Comments
 (0)