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 (if inside while inside if). 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

  1. Assignments: x := expr or a[i] := expr.
  2. Havoc: havoc x.
  3. 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

  1. CFGs simplify program analysis by turning structured code into a directed graph.
  2. Locations represent points in the program execution; Edges represent atomic actions.
  3. Complex Logic (if, while) is handled by branching with assume statements.
  4. Verification becomes a graph-reachability problem: “Can we reach the error location?”
  5. Tools prefer CFGs because they provide a uniform way to represent different programming languages.

Self-Check

  1. What four components make up a CFG , and what does each contribute?
  1. How is if (B) { st1 } else { st2 } translated into a CFG?
  1. How does a while (B) { st } loop appear as a CFG fragment?
  1. How is assert P modeled in a CFG, and what does verification reduce to?
  1. What is a program execution along a CFG path?

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