Static Program Analysis Foundations of Abstract Interpretation - - PowerPoint PPT Presentation

static program analysis
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Static Program Analysis

Foundations of Abstract Interpretation

Sebastian Hack, Christian Hammer, Jan Reineke Advanced Lecture, Winter 2014/15

slide-2
SLIDE 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

slide-3
SLIDE 3

Concrete Semantics

Different semantics are required for different properties:

 “Is there an execution in which

the value of x alternates between 3 and 5?”  Trace Semantics

 “Is the final value of x always the

same as the initial value of x?”  “Input/Output” Semantics

 “May x ever assume the value 45

at program point 7?”  Reachability Semantics

start 1 2 5 6 7 8 x = x % 5 y = 42 Pos(x < y) Pos(a<b) Neg(a<b) Neg(x < y) x = x+2 x = x+1 3 4 a = M[x] b = M[x+1]

slide-4
SLIDE 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

slide-5
SLIDE 5

Reachability Semantics

Captures the set of reachable states at each program point. Formally: Example:

start 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2

x \in {…, -2, -1, 0, 1, 2, …} x \in {0, …, 100} x \in {101}

slide-6
SLIDE 6

Reachability Semantics

Can be captured as the least solution of:

start 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2

slide-7
SLIDE 7

Questions

 Why the least solution?  Is there more than one solution?  Is there a unique least solution?  Can we systematically compute it?

start 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2

slide-8
SLIDE 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 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2

slide-9
SLIDE 9

Why? Knaster-Tarski Fixpoint Theorem

Raises more questions:

 What is a complete lattice?  What is a monotonic function?  What is a fixed point?

slide-10
SLIDE 10

Monotone Functions

Examples:

Which of these are monotone? Need to know what the order is.

slide-11
SLIDE 11

Partial Orders

slide-12
SLIDE 12

Partial Orders: Examples I

slide-13
SLIDE 13

Partial Orders: Examples II

What about ?

slide-14
SLIDE 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?

slide-15
SLIDE 15

Least Upper Bounds: Examples I

Which of these are complete lattices?

slide-16
SLIDE 16

Least Upper Bounds: Examples II

Which of these are complete lattices?

slide-17
SLIDE 17

Properties of Complete Lattices

slide-18
SLIDE 18

Generic Lattice Constructions: Power-set Lattice

Graphical representation (Hasse diagram):

slide-19
SLIDE 19

Generic Lattice Constructions: Total Function Space

What about ?

slide-20
SLIDE 20

Generic Lattice Constructions: Flat Lattice

Graphical representation (Hasse diagram) with : …

  • 3
  • 2
  • 1

1 2 3 …

slide-21
SLIDE 21

Fixed Points

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

slide-22
SLIDE 22

Knaster-Tarski Fixpoint Theorem

Raises more questions:

 What is a complete lattice? ✓  What is a monotonic function? ✓  What is a fixed point? ✓

slide-23
SLIDE 23

Back to the Reachability Semantics

Can be captured as the least fixed point of:

start 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2

Monotone?

slide-24
SLIDE 24

How to Compute the Least Fixed Point

Kleene Iteration: Why is this increasing? Will this reach the fixed point? It will here: But in general?

start 1 3 x = 0 Pos(x < 100) Neg(x < 100) x = x+1 2 start 1 3 x = 0 Pos(true) Neg(true) x = x+1 2

No!

Lattice has infinite ascending chains.

slide-25
SLIDE 25

Ascending Chain Condition

 Length of longest ascending chain determines worst-case complexity

  • f Kleene Iteration.

  • 1

1 … Power set lattice Flat lattice How about total function space lattice?

slide-26
SLIDE 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

✓ (✓)

slide-27
SLIDE 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.

slide-28
SLIDE 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.

slide-29
SLIDE 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?

slide-30
SLIDE 30

How to Compute in the Abstract Domain Example: Multiplication on Flat Lattice

a b *

#

Denotes abstract version of operator

slide-31
SLIDE 31

How to Compute in the Abstract Domain? Formally

Local Correctness Condition: Correct by construction (if concretization and abstraction have certain properties):

slide-32
SLIDE 32

From Local to Global Correctness

slide-33
SLIDE 33

Fixpoint Transfer Theorem