Algorithm 7.2 Interprocedural Context-Insensitive Whole-Program Pointer Analysis

Input: Entry method mentrym^{entry}.

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

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

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

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

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

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

6:

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

8:AddReachable(mentrym^{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 xx then

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

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

16:AddEdge(y,oi.fy, o_i.f)

17:end for

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

19:AddEdge(oi.f,yo_i.f, y)

20:end for

21:ProcessCall(x,oix, o_i)

22:end for

23:end if

24:end while

25:end procedure

26:

27:procedure AddReachable(mm)

28:if mRMm \notin RM then

29:add mm 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(x):={}pt(x) := \{\} // poinrt-to set of each pointer, initialized as empty

33:end for

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

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

36:end for

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

38:AddEdge(y,xy, x)

39:end for

40:end if

41:end procedure

42:

43:procedure ProcessCall(x,oix, 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:add (mthis,{oi})(m_{this}, \{o_i\}) to WLWL

47:if lmCGl \to m \notin CG then

48:add lml \to m to CGCG

49:AddReachable(mm)

50:for each parameter pip_i of mm do

51:AddEdge(ai,pia_i, p_i)

52:end for

53:AddEdge(mret,rm_{ret}, r)

54:end if

55:end for

56:end procedure