Definitionintro
Path condition
Also called path constraint.
The conjunction of branch conditions over symbolic inputs that an execution path takes, satisfiable exactly by inputs that follow it.
A path condition is a formula over the input symbols of a program that holds for exactly the inputs whose run follows a given path of the control flow graph. It is the conjunction of the branch conditions along the path, each one written in terms of the inputs, with the sign that the path takes. A path is feasible when its path condition is satisfiable. This page gives the exact definition for the toy IR of the compilers pages; the method that builds path conditions and uses them is symbolic execution.
Definition
Take a program in the three-address code of the toy IR, with parameters over the integers. Give each parameter a fresh input symbol . A symbolic expression is a term built from the input symbols and integer constants with the operators of the IR. A path is a sequence of block labels with the entry block and each a successor of .
Walk along and keep a symbolic store that maps each defined name to a symbolic expression. At the start, . An instruction sets , where for a constant . Copies and constants work in the same way. Each step adds conditions to a list:
- At a terminator
br a L1 L2of block , add if , and add if . (If , add nothing.) - At an instruction or , add . At a shift, add . These are the implicit conditions of the operations that can trap.
The path condition of is the conjunction of the list:
A run that traps at an instruction of has the path condition of the prefix up to that instruction, with the implicit condition of that instruction negated. An input follows if the run of on visits the blocks in this order, with no trap before the end of .
Property. For every path and every input , the input follows if and only if is true. The proof is an induction on the length of : the store gives the value of each name as a function of the input, so each recorded condition is true exactly when the run makes the same choice. The page symbolic execution gives this induction. Two consequences follow:
- The path is feasible if and only if is satisfiable. A model of is a test input for .
- Two complete paths that differ at some branch have path conditions that no input satisfies together. On a loop-free program, the path conditions of the complete paths, with the conditions of the trap outcomes, split the input space into disjoint parts.
Decidability. Whether a given path is feasible is a satisfiability question in the theory of the operations on the path, so it is as hard as that theory:
- With , , comparisons, multiplication by constants, and and by nonzero constants, over unbounded integers, the path condition is a formula of Presburger arithmetic, and feasibility is decidable. A conjunction of linear constraints is linear integer arithmetic, which is NP-complete.
- With the product of two input symbols, over unbounded integers, feasibility is undecidable in general, by the negative answer to Hilbert's tenth problem: a single branch on a polynomial equation already asks whether it has an integer root.
- On machine words of a fixed width , every operation is a bit-vector operation and feasibility is decidable and NP-complete.
The question "does some path reach this block?" over all paths of a program with loops is a different question. For programs over unbounded integers it is undecidable, by a reduction from the halting problem: put the block after the code that may run forever. Rice's theorem gives the same answer for every nontrivial property of the input and output behavior. One path condition is a finite formula, and the number of paths is what makes the whole question hard.
Examples and non-examples
A small program. The parameters are and , with the symbols and .
entry:
d = x - y
t = d < 0
br t lt ge
lt:
u = x == y
br u dead r1
ge:
q = 12 / d
v = q == 3
br v r2 r3
dead:
ret 9
r1:
ret 1
r2:
ret 2
r3:
ret 3
After entry, the store has and . The CFG has four complete paths. With the trap of the division, there are five outcomes.
| path | path condition | simplified | feasible |
|---|---|---|---|
| entry, lt, dead | false | no | |
| entry, lt, r1 | yes | ||
| entry, ge, trap | yes | ||
| entry, ge, r2 | yes | ||
| entry, ge, r3 | yes |
The simplification of the fourth row uses integer division: for , takes the values 12, 6, 4, 3, 2, 2, 1 for , and 0 or 1 above that, so holds only for . A model of each feasible row is a test: for r1, for the trap, for r2 and for r3. Over the 289 inputs with and in to , the five outcomes are taken by 136, 17, 13 and 123 inputs (r1, trap, r2, r3), and by no input for dead. The sum is 289, as the partition property says.
The path to dead is a syntactic path of the CFG with no input. A test generator that picks CFG paths and never checks the path condition wastes work on such paths, and a coverage report shows dead as not covered for a good reason.
A loop. For i = 0; while i < n: i = i + 1 with the symbol for , the path that runs the body exactly times has the path condition , which simplifies to . Each gives one path, so the program has infinitely many feasible paths. This is the root of the path explosion problem.
Non-examples.
- The branch conditions in terms of program names. The list , is not a path condition. The names change along the path, so a condition must be written over the input symbols, after the store is applied. For the r2 path, the condition on becomes .
- A condition with the implicit checks left out. The formula does not exclude the inputs with . The SMT-LIB theories make division total and leave the value of open, so a solver may pick and return the model . That input traps and never reaches r2. KLEE checks each division against the path condition for this reason.
- An over-approximation. An abstract interpretation of the program may find that holds in block
ge. That is a fact about all paths intoge, a superset of the inputs. A path condition is exact for one path. - A concretized condition. A concolic tool may replace a symbolic value by its value in the current run, for example the result of a hash function. The formula it records then implies the true path condition, but it is not equal to it: some inputs follow the path and do not satisfy the formula.
Related definitions
- Symbolic execution tree. The tree of all paths, with one path condition per node. See symbolic execution tree.
- Path explosion. The number of path conditions is exponential in the number of branches and unbounded with loops. See path explosion problem.
- Weakest precondition of a path. Turn the path into straight-line code in which each branch becomes
assume c. Then , written over the initial values, is the weakest precondition of this code for the postcondition true. The strongest postcondition of the code from the precondition "each " is together with the equations of the final store. - Verification condition. A path condition together with the negation of an assertion at the end of the path is one verification condition of that path. Bounded model checking puts all paths up to a depth into one formula instead of one formula per path.
- Path feasibility as a query. Each path condition is one query to an SMT solver. Concolic testing and generational search build the next query by negating one condition of a path condition.
References
- James C. King, Symbolic execution and program testing, Communications of the ACM 19(7), 1976, pp. 385 to 394, the definition of the path condition pc and the rule for IF statements
- Cristian Cadar and Koushik Sen, Symbolic execution for software testing, three decades later, Communications of the ACM 56(2), 2013, pp. 82 to 90, the section on classical symbolic execution (symbolic state and path constraint)
- Roberto Baldoni, Emilio Coppa, Daniele Cono D'Elia, Camil Demetrescu and Irene Finocchi, A survey of symbolic execution techniques, ACM Computing Surveys 51(3), 2018, Article 50, Section 1 (the symbolic state and the path constraint) and the section on constraint solving
- Cristian Cadar, Daniel Dunbar and Dawson Engler, KLEE, unassisted and automatic generation of high-coverage tests for complex systems programs, Proceedings of OSDI 2008, USENIX, pp. 209 to 224, the section on the architecture (checks of dangerous operations such as division by zero)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag VBG0ZZ Edit this page History Report an error Markdown