Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India & K. V. Raghavan.

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Pointer Analysis B. Steensgaard: Points-to Analysis in Almost Linear Time. POPL 1996 M. Hind: Pointer analysis: haven't we solved this problem yet? PASTE.
Advanced Compiler Techniques LIU Xianhua School of EECS, Peking University Pointer Analysis.
Shape Analysis by Graph Decomposition R. Manevich M. Sagiv Tel Aviv University G. Ramalingam MSR India J. Berdine B. Cook MSR Cambridge.
Context-Sensitive Interprocedural Points-to Analysis in the Presence of Function Pointers Presentation by Patrick Kaleem Justin.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Data-Flow Analysis Framework Domain – What kind of solution is the analysis looking for? Ex. Variables have not yet been defined – Algorithm assigns a.
Type-Based Flow Analysis: From Polymorphic Subtyping to CFL-Reachability Jakob Rehof and Manuel Fähndrich Microsoft Research.
Demand-driven Alias Analysis Implementation Based on Open64 Xiaomi An
School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Pointer Analysis.
A survey of techniques for precise program slicing Komondoor V. Raghavan Indian Institute of Science, Bangalore.
Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India.
Parallel Inclusion-based Points-to Analysis Mario Méndez-Lojo Augustine Mathew Keshav Pingali The University of Texas at Austin (USA) 1.
1 Practical Object-sensitive Points-to Analysis for Java Ana Milanova Atanas Rountev Barbara Ryder Rutgers University.
Automated Soundness Proofs for Dataflow Analyses and Transformations via Local Rules Sorin Lerner* Todd Millstein** Erika Rice* Craig Chambers* * University.
Parameterized Object Sensitivity for Points-to Analysis for Java Presented By: - Anand Bahety Dan Bucatanschi.
The Ant and The Grasshopper Fast and Accurate Pointer Analysis for Millions of Lines of Code Ben Hardekopf and Calvin Lin PLDI 2007 (Best Paper & Best.
Semi-Sparse Flow-Sensitive Pointer Analysis Ben Hardekopf Calvin Lin The University of Texas at Austin POPL ’09 Simplified by Eric Villasenor.
Pointer and Shape Analysis Seminar Context-sensitive points-to analysis: is it worth it? Article by Ondřej Lhoták & Laurie Hendren from McGill University.
Establishing Local Temporal Heap Safety Properties with Applications to Compile-Time Memory Management Ran Shaham Eran Yahav Elliot Kolodner Mooly Sagiv.
Next Section: Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis (Wilson & Lam) –Unification.
Program analysis Mooly Sagiv html://
Purity Analysis : Abstract Interpretation Formulation Ravichandhran Madhavan, G. Ramalingam, Kapil Vaswani Microsoft Research, India.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Interprocedural pointer analysis for C We’ll look at Wilson & Lam PLDI 95, and focus on two problems solved by this paper: –how to represent pointer information.
Set Constraint-Based Program Analysis Manuel Fähndrich CS590 UW Spring 2001.
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
1 Refinement-Based Context-Sensitive Points-To Analysis for Java Manu Sridharan, Rastislav Bodík UC Berkeley PLDI 2006.
Intraprocedural Points-to Analysis Flow functions:
Java Alias Analysis for Online Environments Manu Sridharan 2004 OSQ Retreat Joint work with Rastislav Bodik, Denis Gopan, Jong-Deok Choi.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Swerve: Semester in Review. Topics  Symbolic pointer analysis  Model checking –C programs –Abstract counterexamples  Symbolic simulation and execution.
Comparison Caller precisionCallee precisionCode bloat Inlining context-insensitive interproc Context sensitive interproc Specialization.
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Pointer and Shape Analysis Seminar Mooly Sagiv Schriber 317 Office Hours Thursday
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
An Efficient Inclusion-Based Points-To Analysis for Strictly-Typed Languages John Whaley Monica S. Lam Computer Systems Laboratory Stanford University.
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
Abstract Interpretation (Cousot, Cousot 1977) also known as Data-Flow Analysis.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Fast Points-to Analysis for Languages with Structured Types Michael Jung and Sorin A. Huss Integrated Circuits and Systems Lab. Department of Computer.
Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India.
Convergence of Model Checking & Program Analysis Philippe Giabbanelli CMPT 894 – Spring 2008.
Adapting Side-Effects Analysis for Modular Program Model Checking M.S. Defense Oksana Tkachuk Major Professor: Matthew Dwyer Support US National Science.
ESEC/FSE-99 1 Data-Flow Analysis of Program Fragments Atanas Rountev 1 Barbara G. Ryder 1 William Landi 2 1 Department of Computer Science, Rutgers University.
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Merging Equivalent Contexts for Scalable Heap-cloning-based Points-to.
Pointer Analysis Survey. Rupesh Nasre. Aug 24, 2007.
Pointer Analysis for Multithreaded Programs Radu Rugina and Martin Rinard M I T Laboratory for Computer Science.
Points-To Analysis in Almost Linear Time Josh Bauman Jason Bartkowiak CSCI 3294 OCTOBER 9, 2001.
Random Interpretation Sumit Gulwani UC-Berkeley. 1 Program Analysis Applications in all aspects of software development, e.g. Program correctness Compiler.
CS 343 presentation Concrete Type Inference Department of Computer Science Stanford University.
Pointer Analysis. Rupesh Nasre. Advisor: Prof R Govindarajan. Apr 05, 2008.
Pointer Analysis – Part I CS Pointer Analysis Answers which pointers can point to which memory locations at run-time Central to many program optimization.
Quantified Data Automata on Skinny Trees: an Abstract Domain for Lists Pranav Garg 1, P. Madhusudan 1 and Gennaro Parlato 2 1 University of Illinois at.
1 Iterative Program Analysis Abstract Interpretation Mooly Sagiv Tel Aviv University Textbook:
Points-to Analysis as a System of Linear Equations Rupesh Nasre. Computer Science and Automation Indian Institute of Science Advisor: Prof. R. Govindarajan.
1PLDI 2000 Off-line Variable Substitution for Scaling Points-to Analysis Atanas (Nasko) Rountev PROLANGS Group Rutgers University Satish Chandra Bell Labs.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 15: Alias Analysis Roman Manevich Ben-Gurion University.
Spring 2017 Program Analysis and Verification
Simone Campanoni Dependences Simone Campanoni
Pointer Analysis Lecture 2
Topic 17: Memory Analysis
G. Ramalingam Microsoft Research, India & K. V. Raghavan
Pointer Analysis Lecture 2
Pointer analysis.
Pointer analysis John Rollinson & Kaiyuan Li
Spring 2016 Program Analysis and Verification
Presentation transcript:

Pointer Analysis Lecture 2 G. Ramalingam Microsoft Research, India & K. V. Raghavan

Andersen’s Analysis A flow-insensitive analysis –computes a single points-to solution, which over-approximates points-to solutions at all program points –ignores control-flow – treats program as a set of statements –equivalent to collapsing the given program to have a single program point, and then applying Algorithm A on it.

Andersen’s Analysis If program has statements s1, s2, …, sn, then create collapsed CFG as follows:  s1 s2 sn …… Initial fact Single program point that Kildall updates After Algorithm A terminates, final solution at the single program point over-approximates result computed by flow-sensitive analysis

Example: Andersen’s Analysis x = &a; *x = &w; y = x; x = &b; *x = &t; z = x;

Notes about Andersen’s Analysis Strong updates never happen in Andersen’s analysis! –If x->{y} and y->{w} before we process statement “*x = &z”, then even if transfer function returns y->{z}, due to subsequent join, y will point to {w,z} after this step. Flow-insensitive style can be adopted for any analysis, not just for pointer analysis

Why Flow-Insensitive Analysis? Reduced space requirements –a single points-to solution Reduced time complexity –no copying of points-to facts individual updates more efficient –a cubic-time algorithm Scales to millions of lines of code –most popular points-to analysis

Andersen’s Analysis: An alternative formulation 1.Introduce a constraint variable PT x for each program variable x 2.Create a constraint from each assignment statement, as follows: x = y: PT x ⊆ PT y *x = y: PT v ⊆ PT y, forall variables v in PT x x = &y: PT x ⊆ {y} x = *y: PT x ⊆ PT v, forall variables v in PT y 3.Find least solution to set of all constraints that were generated above. (A solution is a mapping from constraint variables to sets of program variables.) Emit this least solution as the final solution. –Note: Solution s1 dominates Solution s2 if for each program variable v, s2(PT v ) ⊆ s1(PT v ) Note: This approach computes exact same result as previous approach that collapses program and then uses Algorithm A.

May-Point-To Analyses Ideal-May-Point-To Algorithm A Andersen’s ??? more efficient / less precise

Correctness and precision of Algorithm A

Enter: The French Recipe (Abstract Interpretation) C ≡ 2 DataState A ≡ AbsDataState  

Points-To Analysis (Abstract Interpretation)  (Y) = \p. {x | exists s in Y. s(p) == x }  (a) = {{p->v,q->w} | v ∊ a(p), w ∊ a(q)} (assuming p, q are the pointer variables in the program)

Approximating Transformers: Correctness Criterion It can be shown that for any statement st, and for any a1 ∊ A AS[st](a1) ≥  (CS’[st](  (a1))

Transfer function illustration x: {&y}y: {&x,&z}z: {&a} x: &by: &xz: &a x: &yy: &zz: &b x: {&y,&b}y: {&x,&z}z: {&a,&b} x: &yy: &xz: &a x: &yy: &zz: &a *y = &b; AS *y = &b; CS’  

Transfer function illustration x: {&y}y: {&x,&z}z: {&a} x: &yy: &bz: &a x: &yy: &bz: &a x: {&y}y: {&b}z: {&a} x: &yy: &xz: &a x: &yy: &zz: &a *x = &b; AS *x = &b; CS’  

Transfer function illustration x: {&y}y: {&x,&z}z: {&a} x: &cy: &xz: &a x: &yy: &zz: &c x: {&y,&b,&c}y: {&x,&z}z: {&a,&b,&c} x: &yy: &xz: &a x: &yy: &zz: &a *y = &b; *y = &c AS CS’   *y = &b; *y = &c x: {&y,&c}y: {&x,&z}z: {&a,&c}

Is The Precise Solution Computable? Claim: The set RS(u) of reachable concrete states (for our language) is computable. Note: This is true for any collecting semantics with a finite state space.

Precise Points-To Analysis: Decidability Corollary: Precise may-point-to analysis is computable. Corollary: Precise (demand) may-alias analysis is computable. –Given ptr-exp1, ptr-exp2, and a program point u, identify if there exists some reachable state at u where ptr-exp1 and ptr-exp2 are aliases. Ditto for must-point-to and must-alias … for our restricted language!

Precise Points-To Analysis: Computational Complexity What’s the complexity of the least-fixed point computation using the collecting semantics? The worst-case complexity of computing reachable states is exponential in the number of variables. –Can we do better? Theorem: Computing precise may-point-to is PSPACE-hard even if we have only two-level pointers.

May-Point-To Analyses Ideal-May-Point-To Algorithm A Andersen’s more efficient / less precise

Precise Points-To Analysis: Caveats Theorem: Precise may-alias analysis is undecidable in the presence of dynamic memory allocation. –Add “x = new/malloc ()” to language –State-space becomes infinite Digression: Integer variables + conditional- branching involving integer variables also makes any precise analysis undecidable.

Dynamic Memory Allocation s: x = new () / malloc () Assume, for now, that allocated object stores one pointer –s: x = malloc ( sizeof(void*) ) Introduce a pseudo-variable V s to represent objects allocated at statement s, and use previous algorithm –treat s as if it were “x = &V s ” –also track possible values of V s –allocation-site based approach

Dynamic Memory Allocation: Example x = new; y = x; *y = &b; *y = &a; x = new y = x 4 5 *y = &b *y = &a

Example illustrating need for weak updates on summary objects do { s : x = new; x -> {V s } is correct here *x = &a; V s ->{a} is correct here } x -> {V s } is correct here *x = &b; V s ->{a,b} is correct answer here! Key aspect: V s represents a set of objects (locations), not a single object –referred to as a summary object (node) –if x->{V s }, to be safe “*x =..” still needs weak update!

Other Aspects Field sensitivity –Concrete state maps each variable to a variable or address of an object or null, and for each object o and each field f of o, maps (o,f) to the address of some other object (or to null) –Let PseudoVar be the set of pseudo-variables, let Var’ = Var ⋃ PseudoVar ⋃ {null} –Each AbsDataState maps each variable to a subset of Var’. Also, for each V s, and for each field f in the object allocated at site s, maps (V s,f) to a subset of Var’. Context-sensitivity can be achieved using standard techniques Indirect (virtual) function call sites need to be resolved to candidate functions using points-to analysis. And points-to analysis needs calls to be resolved! Therefore, the two have to happen hand in hand.

Andersen’s Analysis: Further Optimizations and Extensions Fahndrich et al., Partial online cycle elimination in inclusion constraint graphs, PLDI Rountev and Chandra, Offline variable substitution for scaling points-to analysis, Heintze and Tardieu, Ultra-fast aliasing analysis using CLA: a million lines of C code in a second, PLDI M. Hind, Pointer analysis: Haven’t we solved this problem yet?, PASTE Hardekopf and Lin, The ant and the grasshopper: fast and accurate pointer analysis for millions of lines of code, PLDI Hardekopf and Lin, Exploiting pointer and location equivalence to optimize pointer analysis, SAS Hardekopf and Lin, Semi-sparse flow-sensitive pointer analysis, POPL 2009.

Context-Sensitivity Etc. Liang & Harrold, Efficient computation of parameterized pointer information for interprocedural analyses. SAS Lattner et al., Making context-sensitive points-to analysis with heap cloning practical for the real world, PLDI Zhu & Calman, Symbolic pointer analysis revisited. PLDI Whaley & Lam, Cloning-based context-sensitive pointer alias analysis using BDD, PLDI Rountev et al. Points-to analysis for Java using annotated constraints. OOPSLA Milanova et al. Parameterized object sensitivity for points-to and side-effect analyses for Java. ISSTA 2002.

Applications Compiler optimizations Verification & Bug Finding –use in preliminary phases –use in verification itself