Back to Program Verification Index | Previous: (y-11) Nondeterminism: Havoc and Assume | Next: (y-13) Predicate Transformers
Mental Model for Control-Flow Graphs (CFGs)

- Flattening Code: Real programs have nested structure (
ifinsidewhileinsideif). A CFG flattens this into a simple directed graph of locations and transitions. - Edges are Statements: Every edge in the graph represents a single “primitive” operation (Assignment, Havoc, or Assume).
- Paths as Executions: A program execution is just a path from the Initial Location to the Exit Location.
- Verification Ready: Most automated tools (like Ultimate Automizer) convert code into a CFG before applying any verification algorithms.
Formal Definition of a CFG

A Control-Flow Graph is a tuple where:
- : A finite set of Locations (the nodes of the graph).
- : A set of Transitions . Each transition moves the program from one location to another by executing a statement.
- : The starting point of the program.
- : The normal termination point of the program.
Types of Transition Statements

- Assignments:
x := exprora[i] := expr. - Havoc:
havoc x. - Assume:
assume P.
Translating Boostan to CFG
Complex control structures are “desugared” into Assume statements and graph edges.
1. If-Then-Else
An if (B) {st1} else {st2} statement starting at and ending at becomes:
- True Branch: An edge where is the start of .
- False Branch: An edge where is the start of .
2. While Loops

A while (B) {st} loop starting at (the loop head) becomes:
- Entry Edge: An edge where is the start of the loop body.
- Back Edge: The body of the loop eventually leads back to .
- Exit Edge: An edge where is the next statement after the loop.
3. Assert Statements (Error Locations)
To verify correctness, assert P is translated using a special Error Location ():
- If the assertion holds, the program continues normally to .
- If the assertion fails, the program transitions to the error location.
- Formal Transition:
- Goal: Prove that is unreachable from the start of the program.
Program Executions and Correctness

An Execution is a sequence of states that follows a path of transitions in the graph.
Summary
- CFGs simplify program analysis by turning structured code into a directed graph.
- Locations represent points in the program execution; Edges represent atomic actions.
- Complex Logic (if, while) is handled by branching with
assumestatements. - Verification becomes a graph-reachability problem: “Can we reach the error location?”
- Tools prefer CFGs because they provide a uniform way to represent different programming languages.
Self-Check
- What four components make up a CFG , and what does each contribute?
Answer
. is the finite set of locations (nodes), is the set of transition edges labelled with primitive statements (assignment, havoc, assume), is the unique entry, and is the normal exit. Together they describe every execution as a path from to some terminal location.
- How is
if (B) { st1 } else { st2 }translated into a CFG?
Answer
The branching node has two outgoing edges from : one labelled
assume Bleading to the start of , and one labelledassume !Bleading to the start of . Both sub-CFGs merge at the join location . The branch condition becomes anassumeon each path.
- How does a
while (B) { st }loop appear as a CFG fragment?
Answer
A loop head has two outgoing edges:
assume Binto the body andassume !Bto the post-loop location . The body’s CFG ends with a back-edge to . The loop unfolds into an arbitrary number of body traversals controlled by the guard.
- How is
assert Pmodeled in a CFG, and what does verification reduce to?
Answer
An assert at creates two edges:
assume Pto (the assertion held) andassume !Pto a special error location (the assertion failed). Verification reduces to showing is unreachable from : no path of transitions leads there in some execution.
- What is a program execution along a CFG path?
Answer
A sequence of states that follows a path of transitions , where each consecutive pair lies in . The CFG path picks which transitions fire; the state sequence is the actual data witness that those transitions are individually executable.
Back to Program Verification Index | Previous: (y-11) Nondeterminism: Havoc and Assume | Next: (y-13) Predicate Transformers | (y) Return to Notes | (y) Return to Home