Algorithm 8.1 Interprocedural Context-Sensitive Whole-Program Pointer Analysis

Input: Entry method mentrym^{entry} and a context generator Select(c,l,c:oic, l, c':o_i).

Output: Pointer flow graph PFGPFG and point-to set of pt(x)pt(x) and call graph CGCG, all context-sensitive.

1:WL:=[]WL := [] // work list, initialized as empty

2:PFG:={}PFG := \{\} // context-sensitive pointer flow graph, initialized as empty

3:S:={}S := \{\} // set of reachable statements, initialized as empty

4:RM:={}RM := \{\} // set of context-sensitive reachable methods, initialized as empty

5:CG:={}CG := \{\} // context-sensitive call graph, initialized as empty

6:

7:procedure Solve(mentrym^{entry}) // main algorithm

8:AddReachable([]:mentry[]:m^{entry})

9:while WLWL is not empty do

10:remove (n,pts)(n, pts) from WLWL

11:Δ:=ptspt(n)\Delta := pts - pt(n)

12:Propagate(n,Δn, \Delta)

13:if nn represents a variable c:xc:x then

14:for each c:oiΔc':o_i \in \Delta do

15:for each x.f=ySx.f = y \in S do

16:AddEdge(c:y,c:oi.fc:y, c':o_i.f)

17:end for

18:for each y=x.fSy = x.f \in S do

19:AddEdge(c:oi.f,c:yc':o_i.f, c:y)

20:end for

21:ProcessCall(c:x,c:oic:x, c':o_i)

22:end for

23:end if

24:end while

25:end procedure

26:

27:procedure AddReachable(c:mc:m)

28:if c:mRMc:m \notin RM then

29:add c:mc:m to RMRM

30:S=SSmS = S \cup S_{m} // SmS_m is the set of statements in method mm.

31:for each pointer xSmx \in S_{m} do

32:pt(c:x):={}pt(c:x) := \{\} // point-to set of each context-sensitive pointer, initialized as empty

33:end for

34:for each i:x=new T()Smi:x=new\ T()\in S_{m} do

35:add (c:x,{c:oi})(c:x, \{c:o_i\}) to WLWL

36:end for

37:for each x=ySmx=y\in S_{m} do

38:AddEdge(c:y,c:xc:y, c:x)

39:end for

40:end if

41:end procedure

42:

43:procedure ProcessCall(c:x,c:oic:x, c':o_i)

44:for each l:r=x.k(a1,...,an)Sl: r = x.k(a_1, ..., a_n) \in S do

45:m:=m := Dispatch(oi,ko_i, k)

46:ct:=c^t := Select(c,l,c:oic, l, c':o_i)

47:add (ct:mthis,{c:oi})(c^t: m_{this}, \{c':o_i\}) to WLWL

48:if c:lct:mCGc:l \to c^t:m \notin CG then

49:add c:lct:mc:l \to c^t:m to CGCG

50:AddReachable(ct:mc^t:m)

51:for each parameter pip_i of mm do

52:AddEdge(c:ai,ct:pic:a_i, c^t:p_i)

53:end for

54:AddEdge(ct:mret,c:rc^t:m_{ret}, c:r)

55:end if

56:end for

57:end procedure