Module Eval

module Eval: sig .. end

Types and functions related to evaluations. Heavily used by abstract values and domains, evaluation of expressions, transfer functions of instructions and the dataflow analysis.

Lattice structure

include Bottom.Type
type 'a or_top = [ `Top | `Value of 'a ] 

For some functions, the special value top (denoting no information) is managed separately.

type 'a or_top_or_bottom = [ `Bottom | `Top | `Value of 'a ] 

Types for the evaluations

type 't with_alarms = 't * Alarmset.t 

A type and a set of alarms.

type 't evaluated = 't or_bottom with_alarms 

Most forward evaluation functions return the set of alarms resulting from the operations, and a result which can be `Bottom, if the evaluation fails, or the expected value.

val (>>=) : 'a evaluated -> ('a -> 'b evaluated) -> 'b evaluated

This monad propagates the `Bottom value if needed, and join the alarms of each evaluation.

val (>>=.) : 'a evaluated -> ('a -> 'b or_bottom) -> 'b evaluated

Use this monad of the following function returns no alarms.

val (>>=:) : 'a evaluated -> ('a -> 'b) -> 'b evaluated

Use this monad if the following function returns a simple value.

type 'a reduced = [ `Bottom | `Unreduced | `Value of 'a ] 

Most backward evaluation function returns `Bottom if the reduction leads to an invalid state, `Unreduced if no reduction can be performed, or the reduced value.

Cache for the evaluations

The evaluation of an expression stores in a cache the result of all intermediate computation. This cache is the outcome of the evaluation, and is used by abstract domains for transfer functions. It contains

The evaluation queries the abstract domain the value of some sub-expressions.

The origin of an abstract value is then provided by the abstract domain, and kept in the cache. The origin is None if the value has been internally computed without calling the domain.

Also, a value provided by the domain may be reduced by the internal computation of the forward and backward evaluation. Such a reduction is tracked by the evaluator and reported to the domain, in the cache. States of reduction are:

type reductness = 
| Unreduced (*

No reduction.

*)
| Reduced (*

A reduction has been performed for this expression.

*)
| Created (*

The abstract value has been created.

*)
| Dull (*

Reduction is pointless for this expression.

*)

State of reduction of an abstract value.

type 'a flagged_value = {
   v : 'a or_bottom;
   initialized : bool;
   escaping : bool;
}

Right values with 'undefined' and 'escaping addresses' flags.

module Flagged_Value: sig .. end
type ('a, 'origin) record_val = {
   value : 'a flagged_value; (*

The resulting abstract value

*)
   origin : 'origin option; (*

The origin of the abstract value

*)
   reductness : reductness; (*

The state of reduction.

*)
   val_alarms : Alarmset.t; (*

The emitted alarms during the evaluation.

*)
}

Data record associated to each evaluated expression.

type 'a record_loc = {
   loc : 'a; (*

The location of the left-value.

*)
   typ : Cil_types.typ; (*
*)
   loc_alarms : Alarmset.t; (*

The emitted alarms during the evaluation.

*)
}

Data record associated to each evaluated left-value.

module type Valuation = sig .. end

Results of an evaluation: the results of all intermediate calculation (the value of each expression and the location of each lvalue) are cached in a map.

module Clear_Valuation: 
functor (Valuation : Valuation-> sig .. end

Types of assignments

type 'loc left_value = {
   lval : Cil_types.lval;
   lloc : 'loc;
   ltyp : Cil_types.typ;
}

Lvalue with its location and type.

type ('loc, 'value) assigned = 
| Assign of 'value (*

Default assignment of a value.

*)
| Copy of 'loc left_value * 'value flagged_value (*

Copy of the location of a lvalue, that contains the given flagged value. The value is copied exactly, with possible indeterminateness.

*)

Assigned values.

val value_assigned : ('loc, 'value) assigned -> 'value or_bottom
type 'location logic_dependency = {
   term : Cil_types.identified_term; (*

The ACSL term of the dependency, expressed in a \from clause.

*)
   direct : bool; (*

Whether the dependency is direct (default case), or has been declared as "indirect", meaning that its value is only used in a conditional or to compute an address.

*)
   location : 'location option; (*

The location of the dependency. None if the location could not be evaluated, in which case a warning has been emitted.

*)
}

The logic dependency of an ACSL assigns clause.

type 'location logic_assign = 
| Assigns of Cil_types.identified_term * 'location logic_dependency list (*

assigns clause, with the dependencies of the \from clause. An empty list means \nothing.

*)
| Allocates of Cil_types.identified_term
| Frees of Cil_types.identified_term

Interprocedural Analysis

type ('loc, 'value) argument = {
   formal : Cil_types.varinfo; (*

The formal argument of the called function.

*)
   concrete : Cil_types.exp; (*

The concrete argument at the call site

*)
   avalue : ('loc, 'value) assigned; (*

The value of the concrete argument.

*)
}

Argument of a function call.

A call_stack is a list, telling which function was called at which site. The head of the list tells about the latest call.

type call_site = Cil_types.kernel_function * Cil_types.kinstr 

A call site: the function called, and the call statement (or Kglobal for the main function.

type callstack = call_site list 
type ('loc, 'value) call = {
   kf : Cil_types.kernel_function; (*

The called function.

*)
   callstack : callstack; (*

The current callstack (without this call).

*)
   arguments : ('loc, 'value) argument list; (*

The arguments of the call.

*)
   rest : (Cil_types.exp * ('loc, 'value) assigned) list; (*

Extra-arguments.

*)
   return : Cil_types.varinfo option; (*

Fake varinfo to store the return value of the call. Same varinfo for every call to a given function.

*)
}

A function call.

type recursion = {
   depth : int; (*

Depth of the recursive call, i.e. the number of previous call to the called function in the current callstack.

*)
   substitution : (Cil_types.varinfo * Cil_types.varinfo) list; (*

List of variables substitutions to be performed by the domains: for each pair, the first variable must be replaced by the second one in the domain state.

*)
   base_substitution : Base.substitution; (*

Same substitution as the previous field, for bases.

*)
   withdrawal : Cil_types.varinfo list; (*

List of variables to be temporary removed from the state at the start of a new recursive call (by the function start_call of the abstract domains), or to be put back in the state at the end of a recursive call (by the function finalize_call of the abstract domains).

*)
   base_withdrawal : Base.Hptset.t; (*

Same withdrawal as the previous field, for bases.

*)
}

Information needed to interpret a recursive call. The local variables and formal parameters of different recursive calls should not be mixed up. Those of the current call must be temporary withdraw or replaced from the domain states before starting the new recursive call, and the inverse transformation must be made at the end of the call.

type cacheable = 
| Cacheable (*

Functions whose result can be safely cached

*)
| NoCache (*

Functions whose result should not be cached, but for which the caller can still be cached. Typically, functions printing something during the analysis.

*)
| NoCacheCallers (*

Functions for which neither the call, neither the callers, can be cached

*)

Can the results of a function call be cached with memexec?