static program analysis
play

Static Program Analysis Foundations of Abstract Interpretation - PowerPoint PPT Presentation

Static Program Analysis Foundations of Abstract Interpretation Sebastian Hack, Christian Hammer, Jan Reineke Advanced Lecture, Winter 2014/15 Abstract Interpretation Semantics-based approach to program analysis Framework to develop


  1. Static Program Analysis Foundations of Abstract Interpretation Sebastian Hack, Christian Hammer, Jan Reineke Advanced Lecture, Winter 2014/15

  2. Abstract Interpretation  Semantics-based approach to program analysis  Framework to develop provably correct and terminating analyses Ingredients:  Concrete semantics: Formalizes meaning of a program  Abstract semantics  Both semantics defined as fixpoints of monotone functions over some domain  Relation between the two semantics establishing correctness

  3. Concrete Semantics start Different semantics are required for x = x % 5 different properties: 1 y = 42  “Is there an execution in which 2 Neg(x < y) 8 the value of x alternates between Pos(x < y) 3 and 5?”  Trace Semantics 3  “Is the final value of x always the a = M[x] same as the initial value of x?” 4 b = M[x+1]  “Input/Output” Semantics 5  “May x ever assume the value 45 Neg(a<b) Pos(a<b) at program point 7?” 6 7  Reachability Semantics x = x+2 x = x+1

  4. Concrete Semantics  Trace Semantics: Captures set of traces of states that the program may execute.  Input/Output Semantics: Captures the pairs of initial and final states of execution traces.  Abstraction of Trace Semantics  Reachability Semantics: Captures the set of reachable states at each program point  Abstraction of Trace Semantics

  5. Reachability Semantics Captures the set of reachable states at each program point. Formally: Example: x \ in {…, -2, - 1, 0, 1, 2, …} start x = 0 x \ in {0, …, 100} x \in {101} 1 Neg(x < 100) 3 Pos(x < 100) x = x+1 2

  6. Reachability Semantics Can be captured as the least solution of: start x = 0 1 Neg(x < 100) 3 Pos(x < 100) x = x+1 2

  7. Questions  Why the least solution?  Is there more than one solution?  Is there a unique least solution?  Can we systematically compute it? start x = 0 1 Neg(x < 100) 3 Pos(x < 100) x = x+1 2

  8. Answers  Is there more than one solution? Often  Is there a unique least solution? Yes  Can we systematically compute it? Yes and No start x = 0 1 Neg(x < 100) 3 Pos(x < 100) x = x+1 2

  9. Why? Knaster-Tarski Fixpoint Theorem Raises more questions:  What is a complete lattice?  What is a monotonic function?  What is a fixed point?

  10. Monotone Functions Examples: Which of these are monotone? Need to know what the order is.

  11. Partial Orders

  12. Partial Orders: Examples I

  13. Partial Orders: Examples II What about ?

  14. Complete Lattices What is an upper bound of a set A? What is the least upper bound (also: join, supremum) of a set A?

  15. Least Upper Bounds: Examples I Which of these are complete lattices?

  16. Least Upper Bounds: Examples II Which of these are complete lattices?

  17. Properties of Complete Lattices

  18. Generic Lattice Constructions: Power-set Lattice Graphical representation (Hasse diagram):

  19. Generic Lattice Constructions: Total Function Space What about ?

  20. Generic Lattice Constructions: Flat Lattice Graphical representation (Hasse diagram) with : … … -3 -2 -1 0 1 2 3

  21. Fixed Points Example: But a unique least fixed point. Has multiple fixed points:

  22. Knaster-Tarski Fixpoint Theorem Raises more questions:  What is a complete lattice? ✓  What is a monotonic function? ✓  What is a fixed point? ✓

  23. Back to the Reachability Semantics Can be captured as the least fixed point of: start x = 0 1 Neg(x < 100) 3 Monotone? Pos(x < 100) x = x+1 2

  24. How to Compute the Least Fixed Point Kleene Iteration: Why is this increasing? start Will this reach the fixed point? It will here: x = 0 But in general? start 1 Neg(x < 100) 3 x = 0 Pos(x < 100) x = x+1 No! 2 1 Neg(true) 3 Pos(true) x = x+1 Lattice has infinite ascending chains. 2

  25. Ascending Chain Condition  Length of longest ascending chain determines worst-case complexity of Kleene Iteration. Power set lattice Flat lattice … 1 … -1 0 How about total function space lattice?

  26. Recap: Abstract Interpretation  Semantics-based approach to program analysis  Framework to develop provably correct and terminating analyses Ingredients: ✓  Concrete semantics: Formalizes meaning of a program  Abstract semantics  Both semantics defined as fixpoints of monotone ( ✓ ) functions over some domain  Relation between the two semantics establishing correctness

  27. Abstract Semantics Similar to concrete semantics:  A complete lattice (L # , ≤ ) as the domain for abstract elements  A monotone function F # corresponding to the concrete function F  Then the abstract semantics is the least fixed point of F # , lfp F # If F # “correctly approximates” F, then lfp F # “ correctly approximates” lfp F.

  28. An Example Abstract Domain for Values of Variables How to relate the two?  Concretization function, specifying “meaning” of abstract values .  Abstraction function: determines best representation concrete values.

  29. Relation between Abstract and Concrete Are these functions monotone? Why should they be? What is the meaning of the partial order in the abstract domain? What if we first abstract and then concretize?

  30. How to Compute in the Abstract Domain Example: Multiplication on Flat Lattice # a 0 * Denotes abstract version of operator b 0

  31. How to Compute in the Abstract Domain? Formally Local Correctness Condition: Correct by construction (if concretization and abstraction have certain properties):

  32. From Local to Global Correctness

  33. Fixpoint Transfer Theorem

Recommend


More recommend