Skip to content

Commit bedc532

Browse files
committed
Documentation: updates goto-symex/README.md
Specifically, this commit modifies goto-symex/README.md by elaborating on the roles played by symex_target_equationt and symex_targett.
1 parent dbd6988 commit bedc532

File tree

1 file changed

+95
-32
lines changed

1 file changed

+95
-32
lines changed

src/goto-symex/README.md

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ when analysis is incomplete. The symbolic execution includes constant
1515
folding so loops that have a constant number of iterations will be
1616
handled completely (assuming the unwinding limit is sufficient).
1717

18-
The output of the symbolic execution is a system of equations; an object
19-
containing a list of `symex_target_elements`, each of which are
20-
equalities between `expr` expressions. See `symex_target_equation.h`.
21-
The output is in static, single assignment (SSA) form, which is *not*
22-
the case for goto-programs.
18+
The output of symbolic execution is a system of equations, asserations and
19+
assumptions; an object of type `symex_target_equationt`, containing a list of
20+
`symex_target_equationt::SSA_stept`, each of which are equalities between
21+
`exprt` expressions. This list is constructed incrementally as the symbolic
22+
execution engine walks through the goto-program using the `symex_targett`
23+
interface. This interface (implemented by `symex_target_equationt`) exposes
24+
functions that append SSA steps into the aforementioned list while transforming
25+
expressions into Static Single Assignment (SSA) form. For more details on this
26+
process see `symex_target_equation.h`, for an overview of SSA see \ref
27+
static-single-assignment.
28+
29+
At a later stage, BMC will convert the generated SSA steps into an
30+
equation that can be passed to the solver.
2331

32+
---
2433
\section symbolic-execution Symbolic Execution
2534

2635
In the \ref goto-symex directory.
@@ -95,47 +104,80 @@ execution run does not add any paths to the workqueue but rather merges
95104
all the paths together, so the additional path-exploration loop is
96105
skipped over.
97106

98-
\subsection ssa-renaming SSA renaming levels
99-
100-
In goto-programs, variable names get a prefix to indicate their scope
101-
(like `main::1::%foo` or whatever). At symbolic execution level, variables
102-
also get a _suffix_ because we’re doing single-static assignment. There
103-
are three “levels” of renaming. At Level 2, variables are renamed every
104-
time they are encountered in a function. At Level 1, variables are
105-
renamed every time the functions that contain those variables are
106-
called. At Level 0, variables are renamed every time a new thread
107-
containing those variables are spawned. We can inspect the renamed
108-
variable names with the –show-vcc flag, which prints a string with the
109-
following format: `%%s!%%d@%%d#%%d`. The string field is the variable name,
110-
and the numbers after the !, @, and # are the L0, L1, and L2 suffixes
111-
respectively. The following examples illustrate Level 1 and 2 renaming:
107+
---
108+
\section static-single-assignment Static Single Assignment (SSA) Form
109+
110+
**Key classes:**
111+
* \ref symex_targett
112+
* \ref symex_target_equationt
113+
114+
*Static Single Assignment (SSA)* form is an intermediate
115+
representation that satisfies the following properties:
116+
117+
1. Every variable is *assigned exactly once*.
118+
2. Every variable must be *defined* before use.
119+
120+
In-order to convert a goto-program to SSA form all variables are
121+
indexed (renamed) through the addition of a _suffix_.
122+
123+
There are three “levels” of indexing:
124+
125+
**Level 2 (L2):** variables are indexed every time they are
126+
encountered in a function.
127+
128+
**Level 1 (L1):** variables are indexed every time the functions that
129+
contain those variables are called.
130+
131+
**Level 0 (L0):** variables are indexed every time a new thread
132+
containing those variables are spawned.
133+
134+
We can inspect the indexed variable names with the **--show-vcc** or
135+
**--program-only** flags. Variables in SSA form are printed in the
136+
following format: `%%s!%%d@%%d#%%d`. Where the string field is the
137+
variable name, and the numbers after the !, @, and # are the L0, L1,
138+
and L2 suffixes respectively.
139+
140+
> Note: **--program-only** prints all the SSA steps in-order. In
141+
> contrast, **--show-vcc** will for each assertion print the SSA steps
142+
> (assumes, assignments and constraints only) that synthetically
143+
> precede the assertion. In the presence of multiple threads it will
144+
> also print SSA steps that succeed the assertion.
145+
146+
\subsection L1-L2 Level 1 and level 2 indexing
147+
148+
The following examples illustrate Level 1 and 2 indexing.
112149

113150
$ cat l1.c
114-
int main() {
151+
int main()
152+
{
115153
int x=7;
116154
x=8;
117155
assert(0);
118156
}
157+
119158
$ cbmc --show-vcc l1.c
120159
...
121160
{-12} x!0@1#2 == 7
122161
{-13} x!0@1#3 == 8
123162

124-
That is, the L0 names for both xs are 0; the L1 names for both xs are 1;
125-
but each occurrence of x within main() gets a fresh L2 suffix (2 and 3,
126-
respectively).
163+
That is, the L0 names for both x's are 0; the L1 names for both x's
164+
are 1; but each occurrence of x within main() gets a fresh L2 suffix
165+
(2 and 3, respectively).
127166

128167
$ cat l2.c
129-
void foo(){
168+
void foo()
169+
{
130170
int x=7;
131171
x=8;
132172
x=9;
133173
}
134-
int main(){
174+
int main()
175+
{
135176
foo();
136177
foo();
137178
assert(0);
138179
}
180+
139181
$ cbmc --show-vcc l2.c
140182
...
141183
{-12} x!0@1#2 == 7
@@ -146,21 +188,42 @@ respectively).
146188
{-17} x!0@2#4 == 9
147189

148190
That is, every time we enter function foo, the L1 counter of x is
149-
incremented (from 1 to 2) and the L0 counter is reset (back to 2, after
150-
having been incremented up to 4). The L0 counter then increases every
151-
time we access x as we walk through the function.
191+
incremented (from 1 to 2) and the L2 counter is reset (back to 2,
192+
after having been incremented up to 4). The L2 counter then increases
193+
every time we access x as we walk through the function.
194+
195+
\subsection L0 Level 0 indexing (threads only)
196+
197+
TODO: describe and give a concrete example
198+
199+
\subsection PL Relevant Primary Literature
200+
201+
Thread indexing is based on the following paper:
202+
203+
> Lee, J., Midkiff, S.P. and Padua, D.A., 1997, August. Concurrent
204+
> static single assignment form and constant propagation for
205+
> explicitly parallel programs. In International Workshop on Languages
206+
> and Compilers for Parallel Computing (pp. 114-130). Springer,
207+
> Berlin, Heidelberg.
208+
209+
Seminal paper on SSA:
210+
211+
> Rosen, B.K., Wegman, M.N. and Zadeck, F.K., 1988, January. Global
212+
> value numbers and redundant computations. In Proceedings of the 15th
213+
> ACM SIGPLAN-SIGACT symposium on Principles of programming languages
214+
> (pp. 12-27). ACM.
152215
153216
---
154217
\section counter-example-production Counter Example Production
155218

156219
In the \ref goto-symex directory.
157220

158221
**Key classes:**
159-
* symex_target_equationt
160-
* prop_convt
222+
* \ref symex_target_equationt
223+
* \ref prop_convt
161224
* \ref bmct
162-
* fault_localizationt
163-
* counterexample_beautificationt
225+
* \ref fault_localizationt
226+
* \ref counterexample_beautificationt
164227

165228
\dot
166229
digraph G {

0 commit comments

Comments
 (0)