Iterative Program Analysis Abstract Interpretation

Slides:



Advertisements
Similar presentations
Abstract Interpretation Part II
Advertisements

Continuing Abstract Interpretation We have seen: 1.How to compile abstract syntax trees into control-flow graphs 2.Lattices, as structures that describe.
Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Some Properties of SSA Mooly Sagiv. Outline Why is it called Static Single Assignment form What does it buy us? How much does it cost us? Open questions.
1 How to transform an analyzer into a verifier. 2 OUTLINE OF THE LECTURE a verification technique which combines abstract interpretation and Park’s fixpoint.
Tutorial on Widening (and Narrowing) Hongseok Yang Seoul National University.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Program analysis Mooly Sagiv html://
Control Flow Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
From last time: live variables Set D = 2 Vars Lattice: (D, v, ?, >, t, u ) = (2 Vars, µ, ;,Vars, [, Å ) x := y op z in out F x := y op z (out) = out –
1 Iterative Program Analysis Part I Mooly Sagiv Tel Aviv University Textbook: Principles of Program.
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
Program analysis Mooly Sagiv html://
1 Control Flow Analysis Mooly Sagiv Tel Aviv University Textbook Chapter 3
1 Iterative Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
Abstract Interpretation Part I Mooly Sagiv Textbook: Chapter 4.
Interprocedural Analysis Noam Rinetzky Mooly Sagiv Tel Aviv University Textbook Chapter 2.5.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Data Flow Analysis Compiler Design Nov. 8, 2005.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
1 Systematic Domain Design Some Remarks. 2 Best (Conservative) interpretation abstract representation Set of states concretization Abstract semantics.
Overview of program analysis Mooly Sagiv html://
1 Program Analysis Systematic Domain Design Mooly Sagiv Tel Aviv University Textbook: Principles.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis: Data-flow frameworks –Classic.
1 Tentative Schedule u Today: Theory of abstract interpretation u May 5 Procedures u May 15, Orna Grumberg u May 12 Yom Hatzamaut u May.
Precision Going back to constant prop, in what cases would we lose precision?
Compiler Construction Lecture 16 Data-Flow Analysis.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 12: Abstract Interpretation IV Roman Manevich Ben-Gurion University.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Shape Analysis via 3-Valued Logic Mooly Sagiv Tel Aviv University Shape analysis with applications Chapter 4.6
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 13: Abstract Interpretation V Roman Manevich Ben-Gurion University.
1 Combining Abstract Interpreters Mooly Sagiv Tel Aviv University
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 12: Abstract Interpretation IV Roman Manevich Ben-Gurion University.
Program Analysis and Verification
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Iterative Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
1 Numeric Abstract Domains Mooly Sagiv Tel Aviv University Adapted from Antoine Mine.
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Data Flow Analysis II AModel Checking and Abstract Interpretation Feb. 2, 2011.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Iterative Program Analysis Part II Mathematical Background Mooly Sagiv Tel Aviv University
Chaotic Iterations Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Chaotic Iterations Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
Abstraction and Abstract Interpretation. Abstraction (a simplified view) Abstraction is an effective tool in verification Given a transition system, we.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 8: Static Analysis II Roman Manevich Ben-Gurion University.
Program Analysis Last Lesson Mooly Sagiv. Goals u Show the significance of set constraints for CFA of Object Oriented Programs u Sketch advanced techniques.
Spring 2017 Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Textbook: Principles of Program Analysis
Combining Abstract Interpreters
G. Ramalingam Microsoft Research, India & K. V. Raghavan
Symbolic Implementation of the Best Transformer
Program Analysis and Verification
Software analysis SET seminar.
Flow Analysis Data-flow analysis, Control-flow analysis, Abstract interpretation, AAM.
Data Flow Analysis Compiler Design
((a)) A a and c C ((c))
Presentation transcript:

Iterative Program Analysis Abstract Interpretation Mooly Sagiv http://www.cs.tau.ac.il/~msagiv/courses/pa11.html Tel Aviv University 640-6706 Textbook: Principles of Program Analysis Chapter 4 CC79, CC92

Outline Later on The abstract interpretation technique The main theorem Applications Precision Complexity Widening Later on Combining Analysis Interprocedural Analysis Shape Analysis

Soundness Theorem(1) Let (, ) form Galois connection from C to A f: C  C be a monotone function f# : A  A be a monotone function aA: f((a))  (f#(a)) lfp(f)  (lfp(f#)) (lfp(f))  lfp(f#)

Soundness Theorem(2) Let (, ) form Galois connection from C to A f: C  C be a monotone function f# : A  A be a monotone function cC: (f(c))  f#((c)) (lfp(f))  lfp(f#) lfp(f)  (lfp(f#))

Soundness Theorem(3) Let (, ) form Galois connection from C to A f: C  C be a monotone function f# : A  A be a monotone function aA: (f((a)))  f#(a) (lfp(f))  lfp(f#) lfp(f)  (lfp(f#))

Completeness (lfp(f)) = lfp(f#) lfp(f) = (lfp(f#))

Constant Propagation Local Soundness Optimality (Induced) : [Var  Z]  [Var  Z{, }] () = () : P([Var  Z])  [Var  Z{, }] (X) =  {() |  X} =  { |  X} :[Var  Z {, }]  P([Var  Z]) (#) = { | ()  # } = { |   # } Local Soundness st#(#)  ({st  |   (#) =  {st  |   # } Optimality (Induced) st#(#) = ({st  |   (#)} =  {st  |   # } Soundness Completeness

Example Interval Analysis Find a lower and an upper bound of the value of a variable Usages? Lattice L = (Z{-, }Z {-, }, , , , ,) [a, b]  [c, d] if c  a and d  b [a, b]  [c, d] = [min(a, c), max(b, d)] [a, b]  [c, d] = [max(a, c), min(b, d)]  =  =

Domains with Infinite Heights for Integers y Intervals CC’77: xi  b Octagons SKS’00, Mine’01: xi yi  b Polyhedra Cousot& Halbwachs’78: ai*xi  b x

Formal available expression Find out which expressions are available at a given program point Example program x = y + t //{(y+t)} z = y + r //{(y+t), (y+r)} while (…) { // {(y+t), (y+r)} t = t + (y + r) // {(y+t), (y+r), t + (y +r )} }

Available expression lattice P(Fexp) X  Y  X  Y X  Y = X  Y = Fexp  = 

Available expressions Computing Fexp for while s ::= skip { s.Fexp :=  } s := id = exp { s.Fexp = {exp.rep } s := s ; s { s.Fexp := s[1].Fexp  s[2].Fexp } s := while exp do s { s.Fexp := {exp.rep}  s[1].Fexp } s := if exp then s else s { s.Fexp := {exp.rep}  s[1].Fexp  s[2].Fexp }

Instrumented Semantics Available expressions S Stm  : State  P(Fexp)  State  P(Fexp) S  id := a  (, ae) = ([a  a a ], notArg(id, ae  {a} ) S  skip  (, ae) = (, ae) CS Stm  : P(State  P(Fexp))  P(State  P(Fexp)) CS s (X) ={S  s  (, ae) | (, ae)  X}

Collecting Semantics Example x = y * z; if (x == 6) y = z+ t; … r = z + t;

Formal Available Expressions Abstraction : [Var  Z]  P(Fexp)  P(Fexp) (, ae) = (ae) : P(P([Var  Z]  P(Fexp))  P(Fexp) (X) =  {() |  X} = {ae | (, ae) X} : P(Fexp)  P(P([Var  Z]  P(Fexp)) (ae#) = {(, ae) | (, ae)  ae# } = {(, ae) | ae  ae# }

Formal Available Expressions AI S Stm # : P(Fexp)  P(Fexp) S  id := a  # (ae) = notArg(id, ae  {a} ) S  skip  # (ae) = (ae) Local Soundness st#(ae#)   {(st (, ae)[1] | ae  ae# } Optimality st#(ae#) = ({st (, ae) | (, ae)  (#)} =  {(st (, ae)[1] | ae  ae# } The initial value at the entry is  Example program x = y + t //{(y+t)} z = y + r //{(y+t), (y+r)} while (…) { // {(y+t), (y+r)} t = t + (y + r) // { (y+r)} } Soundness and Completeness

Example: May-Be-Garbage A variable x may-be-garbage at a program point v if there exists a execution path leading to v in which x’s value is unpredictable: Was not assigned Was assigned using an unpredictable expression Lattice Galois connection Basic statements Soundness

The PWhile Programming Language Abstract Syntax a := x | *x | &x | n | a1 opa a2 b := true | false | not b | b1 opb b2 | a1 opr a2 S := x := a | *x := a | skip | S1 ; S2 | if b then S1 else S2 | while b do S

Concrete Semantics for PWhile State1= [LocLocZ] For every atomic statement S S  : States1 States1 x := a ()=[loc(x) Aa ] x := &y () x := *y () x := y () *x := y ()

Points-To Analysis Lattice Lpt = Galois connection Meaning of statements

t := &a; y := &b; z := &c; if x> 0 then p:= &y; else p:= &z; *p := t;

/. . / t := &a; /. {(t, a)}. / /. {(t, a)}. / y := &b; / /*  */ t := &a; /* {(t, a)}*/ /* {(t, a)}*/ y := &b; /* {(t, a), (y, b) }*/ /* {(t, a), (y, b)}*/ z := &c; /* {(t, a), (y, b), (z, c) }*/ if x> 0; then p:= &y; /* {(t, a), (y, b), (z, c), (p, y)}*/ else p:= &z; /* {(t, a), (y, b), (z, c), (p, z)}*/ /* {(t, a), (y, b), (z, c), (p, y), (p, z)}*/ *p := t; /* {(t, a), (y, b), (y, c), (p, y), (p, z), (y, a), (z, a)}*/

Abstract Semantics for PWhile State#= P(Var*  Var*) For every atomic statement S x := a () x := &y () x := *y () x := y () *x := y ()

/. . / t := &a; /. {(t, a)}. / /. {(t, a)}. / y := &b; / /*  */ t := &a; /* {(t, a)}*/ /* {(t, a)}*/ y := &b; /* {(t, a), (y, b) }*/ /* {(t, a), (y, b)}*/ z := &c; /* {(t, a), (y, b), (z, c) }*/ if x> 0; then p:= &y; /* {(t, a), (y, b), (z, c), (p, y)}*/ else p:= &z; /* {(t, a), (y, b), (z, c), (p, z)}*/ /* {(t, a), (y, b), (z, c), (p, y), (p, z)}*/ *p := t; /* {(t, a), (y, b), (y, c), (p, y), (p, z), (y, a), (z, a)}*/

Flow insensitive points-to-analysis Steengard 1996 Ignore control flow One set of points-to per program Can be represented as a directed graph Conservative approximation Accumulate pointers Can be computed in almost linear time Union find

t := &a; y := &b; z := &c; if x> 0; then p:= &y; else p:= &z; *p := t;

Precision We cannot usually have (CS) = DF on all programs But can we say something about precision in all programs?

The Join-Over-All-Paths (JOP) Let paths(v) denote the potentially infinite set paths from start to v (written as sequences of edges) For a sequence of edges [e1, e2, …, en] define f #[e1, e2, …, en]: L  L by composing the effects of basic blocks f #[e1, e2, …, en](l) = f#(en) (… (f#(e2) (f#(e1) (l)) …) JOP[v] = {f#[e1, e2, …,en]() [e1, e2, …, en]  paths(v)}

JOP vs. Least Solution The df solution obtained by Chaotic iteration satisfies for every v: JOP[v] df(v) A function f# is additive (distributive) if f#({x| x  X}) = {f#(x) |  X} If every f# (u,v) is additive (distributive) for all the edges (u,v) JOP[v] = df(v) Examples Maybe garbage Available expressions Constant Propagation Points-to

Notions of precision CS =  (df) (CS) = df Meet(Join) over all paths Using best transformers Good enough

Complexity of Chaotic Iterations Usually depends on the height of the lattice In some cases better bound exist A function f is fast if f (f(l))  l  f(l) For fast functions the Chaotic iterations can be implemented in O(nest * |V|) iterations nest is the number of nested loop |V| is the number of control flow nodes

Conclusion Chaotic iterations is a powerful technique Easy to implement Rather precise But expensive More efficient methods exist for structured programs Abstract interpretation relates runtime semantics and static information The concrete semantics serves as a tool in designing abstractions More intuition will be given in the sequel