Skip to content

Commit f7752cf

Browse files
author
Remi Delmas
committed
Function contracts: performance optimisation for assigns clause checking.
- don't instrument assignments to locals and function parameters, - don't add function parameters and non-dirty locals to the write set, - remove from the local write set CARs that are provably not alive, - remove function parameters and locals from assigns clauses in tests. Sanity checks: - change GOTO instruction with false guards into SKIP instructions (removes artificial loops), - check loop-freeness before assigns clause instrumentation (required for soundness of assigns clause checking). The net effect of these changes is a better proof performance because of a reduction in the number of generated assertions and of their size, but otherwise the contract checking functionality remains unchanged. Rationale: Assigning to local variables or function parameter is always legal so we skip instrumenting these assignments. We avoid adding function parameters and local variables to the local write set, except when their address is taken at some point in the program and can later be assigned to indirectly via pointers. When generating inclusion checks for assignments, we remove from the local write set targets which are not possibly alive at the ASSIGN instruction that gets instrumented.
1 parent 4ec7d9b commit f7752cf

File tree

54 files changed

+642
-253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+642
-253
lines changed

regression/contracts/assigns_enforce_04/test.desc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ main.c
33
--enforce-contract f1
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[f1.\d+\] line \d+ Check that x2 is assignable: SUCCESS$
7-
^\[f1.\d+\] line \d+ Check that y2 is assignable: SUCCESS$
8-
^\[f1.\d+\] line \d+ Check that z2 is assignable: SUCCESS$
9-
^\[f2.\d+\] line \d+ Check that x3 is assignable: SUCCESS$
10-
^\[f2.\d+\] line \d+ Check that y3 is assignable: SUCCESS$
11-
^\[f2.\d+\] line \d+ Check that z3 is assignable: SUCCESS$
126
^\[f3.\d+\] line \d+ Check that \*x3 is assignable: SUCCESS$
137
^\[f3.\d+\] line \d+ Check that \*y3 is assignable: SUCCESS$
148
^\[f3.\d+\] line \d+ Check that \*z3 is assignable: SUCCESS$

regression/contracts/assigns_enforce_05/test.desc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ main.c
33
--enforce-contract f1 --enforce-contract f2 --enforce-contract f3
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[f1.1\] line \d+ .*: SUCCESS$
76
^VERIFICATION SUCCESSFUL$
87
--
98
--

regression/contracts/assigns_enforce_18/test.desc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ main.c
77
^\[bar.\d+\] line \d+ Check that \*b is assignable: SUCCESS$
88
^\[baz.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)c\) is assignable: FAILURE$
99
^\[baz.\d+\] line \d+ Check that \*a is assignable: SUCCESS$
10-
^\[foo.\d+\] line \d+ Check that a is assignable: SUCCESS$
11-
^\[foo.\d+\] line \d+ Check that yp is assignable: SUCCESS$
12-
^\[foo.\d+\] line \d+ Check that z is assignable: SUCCESS$
1310
^\[foo.\d+\] line \d+ Check that \*xp is assignable: SUCCESS$
1411
^\[foo.\d+\] line \d+ Check that y is assignable: FAILURE$
1512
^\[foo.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)yp\) is assignable: SUCCESS$

regression/contracts/assigns_enforce_21/test.desc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ main.c
66
main.c function bar
77
^\[bar.\d+\] line \d+ Check that \*y is assignable: SUCCESS$
88
^\[bar.\d+\] line \d+ Check that x is assignable: FAILURE$
9-
^\[baz.\d+\] line \d+ Check that w is assignable: SUCCESS$
10-
^\[foo.\d+\] line \d+ Check that w is assignable: SUCCESS$
11-
^\[foo.\d+\] line \d+ Check that z is assignable: SUCCESS$
129
^VERIFICATION FAILED$
1310
--
1411
--

regression/contracts/assigns_enforce_arrays_01/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void f1(int a[], int len) __CPROVER_assigns(a)
1+
void f1(int a[], int len) __CPROVER_assigns()
22
{
33
int b[10];
44
a = b;

regression/contracts/assigns_enforce_arrays_03/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void assign_out_under(int a[], int len) __CPROVER_assigns(a)
1+
void assign_out_under(int a[], int len) __CPROVER_assigns()
22
{
33
a[1] = 5;
44
}

regression/contracts/assigns_enforce_arrays_03/test.desc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ main.c
66
^VERIFICATION FAILED$
77
--
88
--
9-
Checks whether verification fails when an assigns clause contains pointer,
10-
but function only modifies its content.
9+
Checks whether verification fails when a function has an array
10+
as parameter, an empty assigns clause and attempts to modify the object
11+
pointed to by the pointer.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
void assigns_single(int a[], int len) __CPROVER_assigns(a)
1+
void assigns_single(int a[], int len)
22
{
3+
int i;
4+
__CPROVER_assume(0 <= i && i < len);
5+
a[i] = 0;
36
}
47

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)
8+
void uses_assigns(int a[], int len)
9+
__CPROVER_assigns(__CPROVER_POINTER_OBJECT(a))
1010
{
1111
assigns_single(a, len);
12-
assigns_range(a, len);
1312
}
1413

1514
int main()
1615
{
1716
int arr[10];
18-
assigns_big_range(arr, 10);
17+
uses_assigns(arr, 10);
1918

2019
return 0;
2120
}

regression/contracts/assigns_enforce_arrays_04/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--enforce-contract assigns_single --enforce-contract assigns_range --enforce-contract assigns_big_range
3+
--enforce-contract uses_assigns
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
void assigns_ptr(int *x) __CPROVER_assigns(*x)
1+
void assigns_ptr(int *x)
22
{
33
*x = 200;
44
}
55

6-
void assigns_range(int a[], int len) __CPROVER_assigns(a)
6+
void uses_assigns(int a[], int i, int len)
7+
// clang-format off
8+
__CPROVER_requires(0 <= i && i < len)
9+
__CPROVER_assigns(*(&a[i]))
10+
// clang-format on
711
{
8-
int *ptr = &(a[7]);
12+
int *ptr = &(a[i]);
913
assigns_ptr(ptr);
1014
}
1115

1216
int main()
1317
{
1418
int arr[10];
15-
assigns_range(arr, 10);
16-
19+
int i;
20+
__CPROVER_assume(0 <= i && i < 10);
21+
uses_assigns(arr, i, 10);
1722
return 0;
1823
}

0 commit comments

Comments
 (0)