Skip to content

Commit 119ce60

Browse files
committed
Add a description of the new feature in the manual
1 parent f4a6f43 commit 119ce60

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doc/cprover-manual/cbmc-assertions.md

+28
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,34 @@ for(i=0; i<100; i++)
5959
assert(a[i]==0);
6060
```
6161

62+
CPROVER also supports writing function pre and postconditions, using
63+
the built-in functions `__CPROVER_precondition` and
64+
`__CPROVER_postcondition`. They can be used to express intent, and at
65+
the moment they are just transformed to assertions in the goto
66+
program. As such, they can be used as simple assertions in
67+
code. However, it is advised to use `__CPROVER_precondition` at the
68+
beginning of a function's body, and `__CPROVER_postcondition` before
69+
the exit points in a function (either the return statements, or the
70+
end of the body if the function returns void). The following is an
71+
example usage:
72+
73+
```C
74+
int foo(int a, int b) {
75+
__CPROVER_precondition(a >= 0);
76+
__CPROVER_precondition(b > 0);
77+
78+
int rval = a / b;
79+
80+
__CPROVER_postcondition(rval >= 0);
81+
return rval;
82+
}
83+
```
84+
85+
A future release of CPROVER will support using these pre and
86+
postconditions to create a function contract, which can be used for
87+
modular verification.
88+
89+
6290
Future CPROVER releases will support explicit quantifiers with a syntax
6391
that resembles Spec\#:
6492

0 commit comments

Comments
 (0)