File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,32 @@ longer change (the fixpoint will be top).
109109 state. Each basic block's entry state is initialized to bottom before the
110110 analysis starts.
111111
112+ ## A Brief Example
113+
114+ This section provides a brief example of a simple data-flow analysis at a high
115+ level. It doesn't explain everything you need to know, but hopefully it will
116+ make the rest of this page clearer.
117+
118+ Let's say we want to do a simple analysis to find if ` mem::transmute ` may have
119+ been called by a certain point in the program. Our analysis domain will just
120+ be a ` bool ` that records whether ` transmute ` has been called so far. The bottom
121+ value will be ` false ` , since by default ` transmute ` has not been called. The top
122+ value will be ` true ` , since our analysis is done as soon as we determine that
123+ ` transmute ` has been called. Our join operator will just be the boolean OR (` || ` )
124+ operator. We use OR and not AND because of this case:
125+
126+ ```
127+ let x = if some_cond {
128+ std::mem::transmute<i32, u32>(0_i32); // transmute was called!
129+ } else {
130+ 1_u32; // transmute was not called
131+ };
132+
133+ // Has transmute been called by this point? We conservatively approximate that
134+ // as yes, and that is why we use the OR operator.
135+ println!("x: {}", x);
136+ ```
137+
112138## Inspecting the Results of a Dataflow Analysis
113139
114140Once you have constructed an analysis, you must pass it to an [ ` Engine ` ] , which
You can’t perform that action at this time.
0 commit comments