Skip to content

Commit 7b19f1d

Browse files
authored
Merge pull request #6829 from remi-delmas-3000/contracts-havoc-statics
CONTRACTS: havoc all statics by default
2 parents eea99f7 + f2935a3 commit 7b19f1d

File tree

22 files changed

+141
-52
lines changed

22 files changed

+141
-52
lines changed

doc/cprover-manual/contracts-functions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ These clauses formally describe the specification of a function.
66
CBMC also provides a series of built-in constructs to be used with functions
77
contracts (e.g., _history variables_, _quantifiers_, and _memory predicates_).
88

9+
When a function contract is checked, the tool automatically havocs all static variables
10+
of the program (to start the analysis in an arbitrary state), in the same way
11+
as using `--nondet-static` would do. If one wishes not to havoc some static variables,
12+
then `--nondet-static-exclude name-of-variable` can be used.
913
## Overview
1014

1115
Take a look at the example below.

doc/cprover-manual/contracts-loops.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ These clauses formally describe an abstraction of a loop for the purpose of a pr
99
CBMC also provides a series of built-in constructs
1010
to aid writing loop contracts (e.g., _history variables_ and _quantifiers_).
1111

12+
When a function contract is checked, the tool automatically havocs all static variables
13+
of the program (to start the analysis in an arbitrary state), in the same way
14+
as using `--nondet-static` would do. If one wishes not to havoc some static variables,
15+
then `--nondet-static-exclude name-of-variable` can be used.
16+
1217
## Overview
1318

1419
Consider an implementation of the [binary search algorithm] below.

regression/contracts/assigns_enforce_17/main.c

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

3-
int x = 0;
3+
int x;
44

55
void pure() __CPROVER_assigns()
66
{
@@ -10,6 +10,7 @@ void pure() __CPROVER_assigns()
1010

1111
int main()
1212
{
13+
x = 0;
1314
pure();
1415
assert(x == 0);
1516
return 0;

regression/contracts/assigns_enforce_17/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ main.c
77
^VERIFICATION SUCCESSFUL$
88
--
99
--
10-
Checks whether verification correctly distincts local variables
10+
Checks whether verification correctly distinguishes local variables
1111
and global variables with same name when checking frame conditions.

regression/contracts/assigns_function_pointer/main.c

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

4-
int x = 0;
4+
int x;
55

66
struct fptr_t
77
{
@@ -26,7 +26,7 @@ void bar(struct fptr_t *s, void (**f)()) __CPROVER_assigns(s->f, *f)
2626

2727
int main()
2828
{
29-
assert(x == 0);
29+
x = 0;
3030
struct fptr_t s;
3131
void (*f)();
3232
bar(&s, &f);

regression/contracts/assigns_function_pointer/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 bar
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[main.assertion.\d+\] line \d+ assertion x \=\= 0: SUCCESS$
76
^\[bar.assigns.\d+\] line \d+ Check that s->f is assignable: SUCCESS$
87
^\[bar.assigns.\d+\] line \d+ Check that \*f is assignable: SUCCESS$
98
^\[main.assertion.\d+\] line \d+ assertion x \=\= 1: SUCCESS$

regression/contracts/assigns_replace_08/main.c

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

3-
int x;
4-
int *z = &x;
3+
int *z;
54

65
void bar() __CPROVER_assigns(*z)
76
{
@@ -14,6 +13,8 @@ void foo() __CPROVER_assigns()
1413

1514
int main()
1615
{
16+
int x;
17+
z = &x;
1718
foo();
1819
return 0;
1920
}

regression/contracts/assigns_replace_08/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ main.c
1111
^VERIFICATION SUCCESSFUL$
1212
--
1313
Checks whether CBMC properly evaluates subset relationship on assigns
14-
during replacement.
14+
during replacement when the targets are global variables.

regression/contracts/assigns_replace_09/main.c

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

3-
int x;
4-
int *z = &x;
3+
int *z;
54

65
void bar() __CPROVER_assigns(*z)
76
{
@@ -14,6 +13,8 @@ static void foo() __CPROVER_assigns(*z)
1413

1514
int main()
1615
{
16+
int x;
17+
z = &x;
1718
foo();
1819
return 0;
1920
}

regression/contracts/assigns_replace_09/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ main.c
1010
^Condition: \!not\_found$
1111
--
1212
Checks whether CBMC properly evaluates subset relationship on assigns
13-
during replacement with static functions.
13+
during replacement with static functions when targets are global variables.

0 commit comments

Comments
 (0)