| Version 2 (modified by , 10 years ago) ( diff ) |
|---|
The contracts specification of CIVL-C is based on ACSL, with additional primitives and constructs for various purposes, such as function guard, function dependency, MPI function behavior, etc.
overview
The grammar for the contract specification of a function is as follows:
contract: requires* terminates? decreases? simple* behavior* completeness* ;
requires: 'Requires' e ';' ;
...
simple: ensures | assumes | assigns | reads | guards | depends | ... ;
ensures: 'Ensures' e ';' ;
assumes: 'Assumes' e ';' ;
assigns: 'Assigns' e (',' e)* ';' ;
reads: 'Reads' e (',' e)* ';' ;
depends: 'Depends' e (',' e)* ';' ;
...
behavior: 'Behavior' id ':' behaviorBody ;
behaviorBody: behaviorClause+;
behaviorClause: assumes | requires | simple ;
completeness: 'Complete' (id (',' id)*)?
| 'Disjoint' (id (',' id)*)?
;
contract clauses
Requires e;: precondition,ehasBooltype and should hold at the entry of the functionTerminates e;:ehasBooltype and ifeholds then the function should terminate eventuallyDecreases e ;orDecreases e for r;: decreases clause, whereeis an expression of typeTandris an relation overT- simple clauses:
Ensures e;: postcondition,ehasBooltype and should hold when the function terminatesAssumes e;: assumption,ehasBooltypeAssigns e0, e1, ...;: side-effects,e0, e1, ...haveMemtype- absence of
Assignsclause does NOT mean that the function has no side-effects Assigns \nothing: means that the function has no side-effects
- absence of
Allocates e0, e1, ...;: memory units allocated by the function,e0, e1, ...haveMemtypeFrees e0, e1, ...;: memory units deallocated by the function,e0, e1, ...haveMemtypeGuards e;: guard of the function, whereehasBooltypeReads e0, e1, ...;: memory access, wheree0, e1, ...haveMemtype- similar to
Assigns - absence of
Readsclause does NOT mean that the function does NOT read anything Reads \nothing: means that the function does NOT read the memory
- similar to
Depends e0, e1, ...;: dependency relation, wheree0, e1, ...haveMemtype- Note:
Guards,DependsandReadsare CIVL extension for ACSL
- action expressions:
read(e):ehas typeMem. The function reads the memory units specified bye.write(e):ehas typeMem. The function writes the memory units specified bye.call(f, <e1, ...>):fhas typeFunction. The function callsfwith parameterse1, ....noaction: no actionanyaction: all actionsact_union(ma0, ma1): the union of the two memory set actionsma0andma1.act_comp(ma0, ma1): action complement (everything not inma1)act_isect(ma0, ma1): action intersection
- depends clause:
depends action0, action1, action2, ...- Example:
depends act_union(act_comp(read(n), call(inc, <x>))), call(dec, <y>)) - absence of depends clause: there is no information about the dependency of the function, which means that the analysis needs to figure it out by itself.
- Example:
- some facts about assigns-or-reads clause
- absence of
reads/assignsclause: there is no assumption about the read/assign access of the function, i.e., the function could read/assign anything- absence of
assignsclause: similar to the absence ofreadsclause
- absence of
reads/assigns nothingdoesn’t necessarily means that the function never reads or assigns any variable. The function could still reads/assigns its “local” variables, including function parameters and any variable declared inside the function body. check it
- absence of
- For an independent function which has
depends coaction, usually we also need to specifyreads nothing, for the purpose of reachability analysis.
e.g.,
/* Returns the size of the given bundle b. */ bundle_size(Bundle b): Integer depends nothing reads b ;
- Example of a function declaration with contracts:
fun[atomic] sendRecv(Int cmd, Pointer buf): Integer reads deref(buf); behavior send: depends writes(buf); assigns nothing; behavior receive: depends access(deref(buf)); assigns deref(buf); { begin choose when eq(cmd, 0) do CALL send, <buf, ...>; goto L1; when eq(cmd, 1) do CALL recv, <buf, ...>; goto L1; when and(neq(cmd, 0), neq(cmd, 1)) do NOOP; goto L1; end choose L1: }
Note:
See TracWiki
for help on using the wiki.
