1 Numeric Abstract Domains Mooly Sagiv Tel Aviv University 640-6706 Adapted from Antoine Mine.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Abstract Interpretation Part II
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.
Inferring Disjunctive Postconditions Corneliu Popeea and Wei-Ngan Chin School of Computing National University of Singapore - ASIAN
Lecture 02 – Structural Operational Semantics (SOS) Eran Yahav 1.
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.
Liveness Analysis Mooly Sagiv Schrierber Wed 10:00-12:00 html://
Data Flow Analysis Compiler Design Nov. 3, 2005.
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.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
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.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
1 Program Analysis Systematic Domain Design Mooly Sagiv Tel Aviv University Textbook: Principles.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
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.
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.
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 Noam Rinetzky Lecture 6: Abstract Interpretation 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
Toward Efficient Flow-Sensitive Induction Variable Analysis and Dependence Testing for Loop Optimization Yixin Shou, Robert A. van Engelen, Johnnie Birch,
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 14: Numerical Abstractions Roman Manevich Ben-Gurion University.
CS 363 Comparative Programming Languages Semantics.
Lecture 10 Abstract Interpretation using Fixpoints.
Application to the automatic extraction of circuit shapes Charles Hymans Modular analysis of a circuit description language by Abstract Interpretation.
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.
Representing Graphs Algebraically (Path Products, Path Expressions) © Ammann & Offutt.
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
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
1 Proving program termination Lecture 5 · February 4 th, 2008 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Program Analysis and Verification Noam Rinetzky Lecture 8: Abstract Interpretation 1 Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav.
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.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
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 2017 Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Textbook: Principles of Program Analysis
Spring 2016 Program Analysis and Verification
Combining Abstract Interpreters
Iterative Program Analysis Abstract Interpretation
Spring 2017 Program Analysis and Verification Operational Semantics
Program Analysis and Verification
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Presentation transcript:

1 Numeric Abstract Domains Mooly Sagiv Tel Aviv University Adapted from Antoine Mine

Subjects

Goals u Infer inductive invariants on numeric values u Abstract sets of points in P(R n ) u Applications: –Array bound –Termination »infer ranking functions with value in N –Cost Analysis »time, memory consumption are numeric quantities –Pointer analysis with pointer arithmetic »pointer  offest –String analysis in C »Length, index

Numeric Semantics

Arithmetic Expressions & Commands u ::= V V  Var| | - | op op  {+, -, , /}| | [c, c’]c, c’  R  {- ,  } u ::= V := V  Var | assume relop 0 | assert relop 0 relop  {=, ,, ,  } u Control Flow Graph G(N, E, s) where E  N  N is annotated with commands –s  N is the start node

Example Program 1: X := [1, 10] ; 2: Y := 100; while 3: X>= 0 do { 4: X := X – 1; 5: Y := Y + 10 } 6: X := [1, 10] Y := [100, 100] assume X  0 X := X -1 assume X<0 Y := Y +10

Concrete Operational Semantics

Semantics of Expressions u States  = Var  R u Semantics E  :    R u E  V   =  V u E  c, c’   = { x  R | c  x  c’} u E  -   = { - x | x  E    } u E  op   ={x op x’ | x  E   , x’  E    } op  {+, -,  } u E  /   =

Semantics of Commands u States  = Var  R u Semantics C  :  P(  )  P(  ) u C  V :=  Z = {  [V  x] |  Z, x  E    } u C  assume relop 0  Z ={  |  Z,  x  E    : x relop 0 } u C  assert relop 0  Z

Distributivity u C  exp  is distributive u C  exp  (  Z) =   Z C  exp  {  }

Concrete Semantics of Programs u  G(s, N, E)  : P(  )  N  P(  ) –The set of reachable states –D = <P(  ), , , , ,  ) u The smallest simultaneous solution to the set of equations  G(s, N, E)   u Uniquely defined from Tarski’s theorem but not computable CS s =  CS n =   E C  c  CS m n  s

Numeric Abstract Domains u Representation: a set D # of representable abstract values u <D #,  #,  #,  #,  #,  # ) –relating the amount of information given by abstract values u A concretization function  : D #  D = P(  ) = P(Var  R) u Required algebraic properties: –  need to be monotonic: d  # d’   d  #  d’ –Strictness   # =  –   # = Var  R u  need not be one-to-one

Numeric Abstract Domain Examples y x signs x  0 y x intervals x  [a, b] y x octagons  x  y  c y x polyhedra  a i x i  c

Requirements on abstract operators u Algorithmic requirements –For each c , c #  c  : D #  D # is computable –Algorithm for  # »Used for merging control paths and iterations –Algorithm for  »Used for assume –Algorithm for  # »Used for checking termination

Abstract Semantics of Programs u  G(s, N, E)  : D #  N  D # –The set of reachable abstract states –D # = <D #,  #,  #,  #,  #,  # ) u The smallest simultaneous solution to the set of equations  G(s, N, E)  #  # u Uniquely defined from Tarski’s theorem AS s =  # AS n =  #  E C #  c  AS m n  s

Soundness u The smallest simultaneous solution to the set of equations  G(s, N, E)   –CS u Any solution AS set of equations  G(s, N, E)  #  # u CS n  AS n for all n  N CS s =  CS n =   E C  c  CS m n  s AS s =  # AS n =  #  E C #  c  AS m n  s

Soundness requirement u     # u For each c , d  D#, c  c  (  d)   (c #  c  d) D#D# Set of states  C #  c  command c D#D#  Set of states  C  c 

Optimality (induced operation) u Requires existence of abstraction  : D  D # such that form a Galois connection u Define c  c  # = d.  (c  c  (  d) u  may not exist u c  c  # may be hard to compute

Widening u Accelerate the termination of Chaotic iterations by computing a more conservative solution u Can handle lattices of infinite heights u  : D #  D #  D # such that –d  # d’  d  d’ –For every increasing chain d # 1  d # 2  …, »The sequence s0 = d # 0 and s i+1 = s i  d # i is finite

Chaotic Iterations with widening for each n in N do AS[v] :=  # AS[s] =  # WL = {s} while (WL   ) do select and remove an element m  WL for each n, such that. (m, c, n)  E do temp = c  c  # AS[m] if m is a loop header then new := AS(n)  temp else new := AS(n)  # temp if (new  AS[n]) then AS[n] := new; WL := WL  {n}

Non-Relational Abstractions

Cartezian Abstraction (independent attribute) u Forget the relationship between variables

Example Program X := [1, 10] Y := [100, 100] assume X  0 X := X -1 assume X<0 Y := Y +10

The Interval Domain

The Interval Domain [Moore’66, Cousot’76] u D # = {[a, b] | a  b  R or a=-  or b=  }  # u  # = [- ,  ] u d  # d’ = if d =  # then d’ else if d’ =  # then d else let d=[a, b] and d’=[c, d] in [min(a, c), max(b, d)] u d  # d’ = if d =  # then  # else if d’ =  # then  # else let d=[a, b] and d’=[c, d] in let l = max(a, c) and u= min(b, d) if l > u then  # else [l, u] u d  d’ = if d =  # then d’ else else let d=[a, b] and d’=[c, d] in [if a  c then a else - , if b  d then b else  ]

Galois Connection

Abstract Expressions

Abstract Assignments

Optimality (Induced)

Abstract Assume

Example Program X := 0 assume X<40 assume X  40 X := X+1

Relational Domains

The need for relational domains u Non-relation domains cannot represent variable relationships Y :=0; while true do { X:=[-128,128]; D:=[0,16]; S:=Y; Y:=X; R:=X-S; if R<=-D then Y:=S-D fi; if R>=D then Y:=S+D fi } X: input signal Y: output signal S: last output R: Y-S D: max allowed for |R|

The need for relational domains u Infer strong enough inductive invariants X:=0; I:=1; while I<5000 do { if … then X:=X+1 else X:=X-1 fi; I:=I+1 }

The need for relational domains u Modular analysis of procedures Z :=X ; if Y > Z then Z :=Y ; if Z < 0 then Z :=0;

Weakly Relational Domains

The Zone Domain [Shacham’00, Mine’01] Constrains of the form V i – V j  c  V i  c

Machine Representation u A potential constraint has the form V i – V j  c u Represented as a directed graph G –Nodes are labeled with variables –An arc with weight c from V i to V j for each constraint V i – V j  c u Difference Bound Matrix (DBM) –Adjacency matrix m of G –mij = c <   V i – V j  c –mij =   No such constraints u Concretization

Machine Representation (cont) u Unary constraints –Add another variable V 0 –m has size n+1  n+1 –V i  c is denoted as V i -V 0  c, i.e., m i,0 = c –V i  c is denoted as V 0 - V i  -c, i.e., m 0,i = -c –  m = { (v 1, v 2, …, v n ) | (0, v 1, v 2, …, v n )  m} V0V1V2 V0 ++ 43 V1 ++ ++ V21 ++

The DBM Lattice

Relational Domains

The Polyhedra Domain [CH’78]  i  j a i, j x i, j  c i

Summary u Numerical Domains are Powerful u Infer interesting invariants u Cost is an issue u Need to combine with other domains u Next week some applications