Академический Документы
Профессиональный Документы
Культура Документы
Overview So far we have looked at summary-based static analysis Path-Based Static Analysis
Lecture 18 CS 295 For each function f, compute description of the effect of f Mapping of inputs to outputs
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
Discussion Summaries can be hard to compute Must account for all paths through the function Summary language generally must be quite expressive
Another Approach An alternative to summaries is to peform path-based analysis Analyze just one path at a time Conceptually simpler
And often simpler to implement
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
Checking Paths
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
5/23/2011
Finite State Properties (Again) For specifications, use FSMs For this lecture, files
Two states: Open, Closed An Open file can be Closed A Closed file can be Open Other transitions are errors
A First Algorithm
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
Prof. Aiken
CS 295
Lecture 18
10
An Invalid Path
Prof. Aiken
CS 295
Lecture 18
11
Prof. Aiken
CS 295
Lecture 18
12
5/23/2011
Tracking Predicates
Requires q
A theorem prover
Something that can deduce whether a predicate is false
The Problem The main problem is there are too many paths In practice, this approach has not proven to be scalable
Exponential blow-up in number of paths is real Cant extend this approach to large programs
An Observation Some of the paths in our example are irrelevant to the property of interest Consider the test on p
Prof. Aiken
CS 295
Lecture 18
15
Prof. Aiken
CS 295
Lecture 18
16
Irrelevant Predicates
Discussion We want something in between the nave approach with no predicates and modeling all predicates Just want to model predicates relevant to the property
Prof. Aiken
CS 295
Lecture 18
17
Prof. Aiken
CS 295
Lecture 18
18
5/23/2011
The Join Operation The join operation is special New abstract states: (p1 p2 pn, S) First component is a list of predicates
Implicitly conjoined
join all abstract states where the information for the file is the same Note: number of possible abstract states is now limited by the number of FSM states
Prof. Aiken CS 295 Lecture 18 19
Prof. Aiken
CS 295
Lecture 18
20
The Join Operation (Cont.) Idea: Join drops any predicates not in common Example: Join[(p1 p2 p3, S),(p S) (p1 p4 p3, S)] = (p1 p3, S)
Example
Prof. Aiken
CS 295
Lecture 18
21
Prof. Aiken
CS 295
Lecture 18
22
What is Lost?
5/23/2011
Another Example
Prof. Aiken
CS 295
Lecture 18
25
Prof. Aiken
CS 295
Lecture 18
26
Back to Recursion Consider the following example foo(x,y) { if (x == 0) return; open(y); close(y); foo(x-1, y) }
Prof. Aiken CS 295 Lecture 18 27
Comments Like any static analysis, recursion/looping introduces recursive constraints Need an initial estimate for the solution, which can then be iteratively improved
convergence is guaranteed for ESP as there are only finitely many possibilities altogether either one of them is a solution or there is no solution
Prof. Aiken CS 295 Lecture 18 28
Comments ESP uses summary edges to capture recursive constraints Essentially, break cycle by assigning some initial value to the result of a recursive function
Iterate to find true value
Prof. Aiken
CS 295
Lecture 18
5/23/2011
Aliasing (Cont.) Like all sound analysis systems, ESP incorporates alias analysis
Context sensitive Flow-insensitive
What About Multiple Values? What if a program, say, opens 3 files? ESP is run 3 times
Once for each file Or rather, each alias equivalence class with a file
Property checking must be done for every expression in an alias equivalence class
Prof. Aiken
CS 295
Lecture 18
31
Prof. Aiken
CS 295
Lecture 18
32
Strong guarantee
Did not just fail to find any bugs Proved the program will always correctly handle files, regardless of input
Prof. Aiken
CS 295
Lecture 18
33
Prof. Aiken
CS 295
Lecture 18
34
Discussion ESP is simpler than the summary- and constraint-based systems we have discussed
Only reason about paths Simple model of program state
Discussion (Cont.) ESP is a global analysis system Much of the apparent simplicity is because p there is no need to construct sophisticated function summaries
The alias analysis is also global
But
Complexity is hidden in
Theorem prover Alias analysis Probably the two weakest links
Prof. Aiken CS 295 Lecture 18 35