lecture-14

lecture-14 - Analysis of programs with pointers Wednesday...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Analysis of programs with pointers Wednesday, November 30, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple example What are the dependences in this program? Problem: just looking at variable names will not give you the correct information After statement S2, program names “x” and “*ptr” are both expressions that refer to the same memory location. We say that ptr points-to x after statement S2. In a C-like language that has pointers, we must know the points-to relation to be able to determine dependences correctly x := 5 ptr := @x *ptr := 9 y := x S1 S2 S3 S4 dependences program Wednesday, November 30, 2011
Background image of page 2
Program model • For now, only types are int and int* • No heap – All pointers point to only to stack variables • No procedure or function calls • Statements involving pointer variables: – copy: x := y – load: x := *y – store: *x := y • Arbitrary computations involving ints Wednesday, November 30, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Points-to relation • Directed graph: – nodes are program variables – edge (a,b): variable a points-to variable b • Can use a special node to represent NULL • Points-to relation is different at different program points x ptr y Wednesday, November 30, 2011
Background image of page 4
• Out-degree of node may be more than one – if points-to graph has edges (a,b) and (a,c), it means that variable a may point to either b or c – depending on how we got to that point, one or the other will be true – path-sensitive analyses: track how you got to a program point (we will not do this) Points-to graph if (p) then x := &y ….. p What does x point to here? Wednesday, November 30, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Ordering on points-to relation • Subset ordering: for a given set of variables – Least element is graph with no edges – G1 <= G2 if G2 has all the edges G1 has and maybe some more • Given two points-to relations G1 and G2 – G1 U G2: least graph that contains all the edges in G1 and in G2 Wednesday, November 30, 2011
Background image of page 6
Overview We will look at three different points-to analyses. Flow-sensitive points-to analysis – Dataflow analysis – Computes a different points-to relation at each point in program Flow-insensitive points-to analysis – Computes a single points-to graph for entire program – Andersen’s algorithm • Natural simplification of flow-sensitive algorithm – Steensgard’s algorithm • Nodes in tree are equivalence classes of variables – if x may point-to either y or z, put y and z in the same equivalence class • Points-to relation is a tree with edges from children to parents rather than a general graph • Less precise than Andersen’s algorithm but faster Wednesday, November 30, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example x := &z ptr := @x y := @w ptr := @y ptr x z y w ptr x z y w ptr x,y z,w Flow-sensitive algorithm Andersen’s algorithm Steensgard’s algorithm Wednesday, November 30, 2011
Background image of page 8
• Suppose S and S1 are set-valued variables.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

lecture-14 - Analysis of programs with pointers Wednesday...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online