Algorithm 7.1 Intraprocedural Context-Insensitive Whole-Program Pointer Analysis

Input: Set of statements of the input program SS.

Output: Pointer flow graph PFGPFG and point-to set of each pointer xx denoted by pt(x)pt(x).

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

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

3:for each pointer xSx \in S do

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

5:end for

6:

7:procedure Solve(SS) // main algorithm

8:for each i:x=new T()Si:x = new\ T() \in S do

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

10:end for

11:for each x=ySx = y \in S do

12:AddEdge(y,xy, x)

13:end for

14:while WLWL is not empty do

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

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

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

18:if nn represents a variable xx then

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

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

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

22:end for

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

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

25:end for

26:end for

27:end if

28:end while

29:end procedure

30:

31:procedure AddEdge(s,ts, t)

32:if stPFGs \to t \notin PFG then

33:add sts \to t to PFGPFG

34:if pt(s)pt(s) is not empty then

35:add (t,pt(s))(t, pt(s)) to WLWL

36:end if

37:end if

38:end procedure

39:

40:procedure Propagate(n,ptsn, pts)

41:if ptspts is not empty then

42:pt(n)=pt(n)ptspt(n) = pt(n) \cup pts

43:for each nsPFGn\to s\in PFG do

44:add (s,pts)(s, pts) to WLWL

45:end for

46:end if

47:end procedure