Skip to content

Adds support for range annotation in assigns clauses #5972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion regression/contracts/assigns_enforce_arrays_01/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
void f1(int a[], int len) __CPROVER_assigns(a)
/* clang-format off */
void f1(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
int b[10];
a = b;
Expand Down
4 changes: 3 additions & 1 deletion regression/contracts/assigns_enforce_arrays_02/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ int nextIdx() __CPROVER_assigns(idx)
return idx;
}

void f1(int a[], int len)
/* clang-format off */
void f1(int a[], int len) __CPROVER_assigns(idx, a[2 .. 5])
/* clang-format on */
{
a[nextIdx()] = 5;
}
Expand Down
10 changes: 7 additions & 3 deletions regression/contracts/assigns_enforce_arrays_03/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
void assign_out_under(int a[], int len) __CPROVER_assigns(a)
/* clang-format off */
void f1(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
a[1] = 5;
int *indr;
indr = a + 3;
*indr = 5;
}

int main()
{
int arr[10];
assign_out_under(arr, 10);
f1(arr, 10);

return 0;
}
8 changes: 4 additions & 4 deletions regression/contracts/assigns_enforce_arrays_03/test.desc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^EXIT=0$
^SIGNAL=0$
^VERIFICATION FAILED$
^VERIFICATION SUCCESSFUL$
--
--
Checks whether verification fails when an array is assigned at an index
below its lower bound.
Checks whether verification succeeds when an array is assigned indirectly
through a pointer.
19 changes: 13 additions & 6 deletions regression/contracts/assigns_enforce_arrays_04/main.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
void assigns_single(int a[], int len) __CPROVER_assigns(a)
void assigns_single(int a[], int len) __CPROVER_assigns(a[8])
{
a[8] = 20;
}

void assigns_range(int a[], int len) __CPROVER_assigns(a)
/* clang-format off */
void assigns_upper_bound(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
a[5] = 10;
}

void assigns_big_range(int a[], int len) __CPROVER_assigns(a)
/* clang-format off */
void assigns_lower_bound(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format oon */
{
assigns_single(a, len);
assigns_range(a, len);
a[2] = 10;
}

int main()
{
int arr[10];
assigns_big_range(arr, 10);
assigns_upper_bound(arr, 10);
assigns_lower_bound(arr, 10);
assigns_single(arr, 10);

return 0;
}
6 changes: 3 additions & 3 deletions regression/contracts/assigns_enforce_arrays_04/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ main.c
^VERIFICATION SUCCESSFUL$
--
--
Checks whether verification succeeds when an array is assigned through
calls to functions with array assigns clauses which are compatible with
that of the caller.
Checks whether verification succeeds when an array is assigned at both upper
and lower bounds of its assignable array range. Single-value array range
assignment is checked as well.
14 changes: 5 additions & 9 deletions regression/contracts/assigns_enforce_arrays_05/main.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
void assigns_ptr(int *x) __CPROVER_assigns(*x)
/* clang-format off */
void assign_out_under(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
*x = 200;
}

void assigns_range(int a[], int len) __CPROVER_assigns(a)
{
int *ptr = &(a[7]);
assigns_ptr(ptr);
a[1] = 5;
}

int main()
{
int arr[10];
assigns_range(arr, 10);
assign_out_under(arr, 10);

return 0;
}
5 changes: 2 additions & 3 deletions regression/contracts/assigns_enforce_arrays_05/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ main.c
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned via a
function call which assigns a pointer to an element out of the
allowable range.
Checks whether verification fails when an array is assigned at an index
below its lower bound.
12 changes: 12 additions & 0 deletions regression/contracts/assigns_enforce_arrays_06/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void assign_out_under(int a[], int len) __CPROVER_assigns(a[8])
{
a[7] = 5;
}

int main()
{
int arr[10];
assign_out_under(arr, 10);

return 0;
}
11 changes: 11 additions & 0 deletions regression/contracts/assigns_enforce_arrays_06/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned at an index below
its allowed index and specification contains only a single cell
instead of a range.
14 changes: 14 additions & 0 deletions regression/contracts/assigns_enforce_arrays_07/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* clang-format off */
void assign_out_over(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
a[6] = 5;
}

int main()
{
int arr[10];
assign_out_over(arr, 10);

return 0;
}
10 changes: 10 additions & 0 deletions regression/contracts/assigns_enforce_arrays_07/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned at an index
above its upper bound.
12 changes: 12 additions & 0 deletions regression/contracts/assigns_enforce_arrays_08/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
void assign_out_under(int a[], int len) __CPROVER_assigns(a[8])
{
a[9] = 5;
}

int main()
{
int arr[10];
assign_out_under(arr, 10);

return 0;
}
10 changes: 10 additions & 0 deletions regression/contracts/assigns_enforce_arrays_08/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned at an index
above its allowed index.
14 changes: 14 additions & 0 deletions regression/contracts/assigns_enforce_arrays_09/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* clang-format off */
void assigns_in_range(int a[], int last_idx) __CPROVER_assigns(a[2 .. last_idx])
/* clang-format on */
{
a[last_idx] = 6;
}

int main()
{
int arr[10];
assigns_in_range(arr, 9);

return 0;
}
10 changes: 10 additions & 0 deletions regression/contracts/assigns_enforce_arrays_09/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Checks whether verification succeeds when an array is assigned at the upper
bounds of its assignable array range, when the range has a non-constant bound.
15 changes: 15 additions & 0 deletions regression/contracts/assigns_enforce_arrays_10/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* clang-format off */
void assigns_in_range(int a[], int last_idx) __CPROVER_assigns(a[2 .. last_idx])
/* clang-format on */
{
last_idx++;
a[last_idx] = 6;
}

int main()
{
int arr[10];
assigns_in_range(arr, 9);

return 0;
}
12 changes: 12 additions & 0 deletions regression/contracts/assigns_enforce_arrays_10/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned past the upper
bound of its assignable array range, using the symbol of the upper bound,
after it has been incremented. This is intended to show that the bounds
are determined at the time the function is called.
25 changes: 25 additions & 0 deletions regression/contracts/assigns_enforce_arrays_11/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
void assigns_single(int a[], int len) __CPROVER_assigns(a[7])
{
}

/* clang-format off */
void assigns_range(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
}

/* clang-format off */
void assigns_big_range(int a[], int len) __CPROVER_assigns(a[2 .. 7])
/* clang-format on */
{
assigns_single(a, len);
assigns_range(a, len);
}

int main()
{
int arr[10];
assigns_big_range(arr, 10);

return 0;
}
11 changes: 11 additions & 0 deletions regression/contracts/assigns_enforce_arrays_11/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--enforce-all-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Checks whether verification succeeds when an array is assigned through
calls to functions with array assigns clauses which are compatible with
that of the caller.
20 changes: 20 additions & 0 deletions regression/contracts/assigns_enforce_arrays_12/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* clang-format off */
void assign_25(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
}

/* clang-format off */
void assign_37(int a[], int len) __CPROVER_assigns(a[3 .. 7])
/* clang-format on */
{
assign_25(a, len);
}

int main()
{
int arr[10];
assign_37(arr, 10);

return 0;
}
10 changes: 10 additions & 0 deletions regression/contracts/assigns_enforce_arrays_12/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when a function with an array assigns target
calls a function which may assign below the allowable range.
20 changes: 20 additions & 0 deletions regression/contracts/assigns_enforce_arrays_13/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void assigns_ptr(int *x) __CPROVER_assigns(*x)
{
*x = 200;
}

/* clang-format off */
void assigns_range(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
int *ptr = &(a[3]);
assigns_ptr(ptr);
}

int main()
{
int arr[10];
assigns_range(arr, 10);

return 0;
}
10 changes: 10 additions & 0 deletions regression/contracts/assigns_enforce_arrays_13/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--enforce-all-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
--
Checks whether verification succeeds when an array is assigned via a
function call which assigns a pointer to one of its elements.
20 changes: 20 additions & 0 deletions regression/contracts/assigns_enforce_arrays_14/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
void assigns_ptr(int *x) __CPROVER_assigns(*x)
{
*x = 200;
}

/* clang-format off */
void assigns_range(int a[], int len) __CPROVER_assigns(a[2 .. 5])
/* clang-format on */
{
int *ptr = &(a[7]);
assigns_ptr(ptr);
}

int main()
{
int arr[10];
assigns_range(arr, 10);

return 0;
}
11 changes: 11 additions & 0 deletions regression/contracts/assigns_enforce_arrays_14/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--enforce-all-contracts
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
--
Checks whether verification fails when an array is assigned via a
function call which assigns a pointer to an element out of the
allowable range.
Loading