Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
2f32447a
Commit
2f32447a
authored
4 years ago
by
Andre Maroneze
Browse files
Options
Downloads
Patches
Plain Diff
[Eva/Doc] update user manual concerning dynamic allocation
parent
307137d8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/value/main.tex
+42
-26
42 additions, 26 deletions
doc/value/main.tex
with
42 additions
and
26 deletions
doc/value/main.tex
+
42
−
26
View file @
2f32447a
...
...
@@ -2605,7 +2605,8 @@ void init_analyzable(void)
\label
{
dyn-alloc
}
Dynamic allocation is modeled by creating new bases.
Each call to
\lstinline
|malloc| and
\lstinline
|realloc| potentially creates a
Each call to
\lstinline
|malloc|/
\lstinline
|realloc|/
\lstinline
|calloc|
potentially creates a
new base, depending on the
\emph
{
builtins
}
(described in section~
\ref
{
libc
}
)
used -- possibly resulting in an unbounded number of such bases.
Dynamically allocated bases behave mostly like statically allocated ones,
...
...
@@ -4975,8 +4976,8 @@ You can also manually specify each builtin to be used with option
\lstinline
|-eva-builtin|, which takes pairs of functions:
the function to be replaced, and the name of the builtin that replaces it.
For instance, option
\lstinline
|-eva-builtin
malloc
:Frama
_
C
_
malloc
_
fresh,free
:Frama
_
C
_
free
| enables
builtins for the
\lstinline
|
malloc
| and
\lstinline
|
free
| functions of the
\lstinline
|-eva-builtin
sin
:Frama
_
C
_
sin,strlen
:Frama
_
C
_
strlen
| enables
builtins for the
\lstinline
|
sin
| and
\lstinline
|
strlen
| functions of the
standard library. Note that even if a builtin is specified this way,
the function still needs to be declared to be used.
%
...
...
@@ -5035,27 +5036,27 @@ and convergence (termination) when needed. Some differences between the
\emph
{
strong
}
and
\emph
{
weak
}
bases allocated by these builtins are
explained in section~
\ref
{
dyn-alloc
}
.
\begin{table}
[!ht]
\centering
\begin{tabular}
{
|c|c|c|
}
\hline
C library function
&
Weak (always terminates)
&
Strong (more precise)
\\
\hline
malloc
&
\lstinline
|Frama
_
C
_
malloc
_
by
_
stack|
&
\lstinline
|Frama
_
C
_
malloc
_
fresh|
\\
calloc
&
\lstinline
|Frama
_
C
_
calloc
_
by
_
stack|
&
\lstinline
|Frama
_
C
_
calloc
_
fresh|
\\
realloc
&
\lstinline
|Frama
_
C
_
realloc|
&
\lstinline
|Frama
_
C
_
realloc
_
multiple|
\\
free
&
\multicolumn
{
2
}{
c|
}{
\lstinline
|Frama
_
C
_
free|
}
\\
\hline
\end{tabular}
\label
{
tab:alloc
}
\caption
{
\FramaC
builtins for dynamic allocation functions
}
\end{table}
Option
\lstinline
|-eva-alloc-builtin| selects the behavior for allocation
builtins, among the following:
Note that function
\lstinline
|free| has a single builtin for both cases.
\begin{description}
\item
[\texttt{by\_stack}]
: create a few bases per callstack (the exact number
is given by option
\lstinline
|-eva-mlevel|, detailed later).
Always converges. This is the default value.
\item
[\texttt{fresh}]
: create a new strong base for each call. The most
precise builtin, but may not converge (e.g. when called inside a loop).
\item
[\texttt{fresh\_weak}]
: like the previous one, but using weak bases.
\item
[\texttt{imprecise}]
: use a single, imprecise base, for
{
\em
all
}
allocations. Always converges.
\end{description}
The behavior of
\lstinline
|-eva-alloc-builtin| is global, unless overridden by
{
\em
allocation annotations
}
, described below.
Generally speaking, the safest approach is to start with the
builtins on the
left (
\emph
{
wea
k
}
), to ensure that the analysis will terminate.
Generally speaking, the safest approach is to start with the
default builtin
(
\texttt
{
by
\_
stac
k
}
), to ensure that the analysis will terminate.
If the results are imprecise, and the allocation function is not called inside
a loop, then the
strong
variant may be tried. If you are mistaken, and the
a loop, then the
\texttt
{
fresh
}
variant may be tried. If you are mistaken, and the
analysis starts diverging, it will print (by default) several messages of this
form:
...
...
@@ -5068,11 +5069,21 @@ This indicates that new bases are being created.
You must then manually interrupt the analysis and either unroll the loop
entirely (see Section~
\ref
{
loop-unroll
}
) or use a weak variant.
By default,
\emph
{
weak
}
builtins are used, but usage of
\lstinline
|-eva-builtin| takes precedence over preexisting associations.
Another possibility is to call e.g.
\lstinline
|Frama
_
C
_
malloc
_
fresh| manually,
for the allocations that are guaranteed to occur a finite number of times.
\paragraph
{
Dynamic allocation annotations
}
The behavior of option
\lstinline
|-eva-alloc-builtin| can be locally overridden
via
\lstinline
|eva
_
allocate| annotations preceding calls to dynamic allocation
functions.
For instance, the following annotation ensures that the call to
\lstinline
|calloc| below will use the
\lstinline
|fresh| builtin,
regardless of the value of option
\lstinline
|-eva-alloc-builtin|:
\begin{lstlisting}
/*@ eva
_
allocate fresh; */
part = (char*)calloc(plen + 1, sizeof(*part));
\end{lstlisting}
Other calls to
\lstinline
|calloc| will be unaffected by this annotation.
\paragraph
{
Multiple locations per callstack
}
...
...
@@ -5088,11 +5099,16 @@ termination for other loops.
\paragraph
{
Memory allocation failure
}
By default, the memory allocation builtins in
\Eva
{}
consider that
By default, stdlib-related memory allocation builtins in
\Eva
{}
(that is,
\lstinline
|malloc|,
\lstinline
|calloc| and
\lstinline
|realloc|)
consider that
the allocation may fail, thus
\lstinline
|NULL| is always returned as a possible
value. To change this behavior (supposing that these functions never fail),
use option
\lstinline
|-eva-no-alloc-returns-null|.
Note that other allocation builtins, such as
\lstinline
|
__
fc
_
vla
_
alloc|
(for variable-length arrays) and
\lstinline
|alloca|,
{
\em
never
}
assume
allocation fails.
\section
{
Parameterizing the analysis
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment