Docsity

Program Slicing: Utilizing Program Dependence Graphs for Analysis and Debugging, Papers of Computer Science

Toggle sidebar
bg1
Program Slicing
David W. Binkley
Keith Brian Gallagher
Ahundred times every day, I remind myself that my inner and outer life depends
on the labors of other men, living and dead, and that I must exert myself in order
to give in the measure as I have received and am still receiving.
A. Einstein
1 Introduction
At the fteenth International Conference on Software Engineering (ICSE), in 1993, Mark Weiser
received recognition for the best paper at the fth ICSE. Weiser reported that \Program
Slicing"[94], the conference paper, and its journal incarnation of the same name[97], were cited
about 10 times a year from 1984 to 1989 and about 20 times a year in 1990 and 1991. Our
subsequent search of the \Science Citation Index" found 9 citations in 1992; 9 citations in 1993;
and 15 citations in 1994. This is clearly a lower bound. Our bibliography of 94 items (91,
excluding Weiser's original work) has only 12 that do not cite it, 5 of whichwere published
prior to the original paper. The references included universities in 10 countries and 8 industrial
laboratories. Since so many researchers and practitioners have been citing this seminal work,
herein we attempt to collate, summarize and organize the edice of results that have followed.
Program slicing is a decomposition technique that extracts from program statements rele-
vant to a particular computation. Informally, a slice provides the answer to the question \What
program statements potentially aect the computation of variable
v
at statement
s
?" An ob-
server viewing the execution of a program and its slice cannot determine which is which when
attention if focused on statement
s
. It is as if the observer has a window through which only
part of the program state can be seen as illustrated by the \clear window" in Figure 1.
The utility and power of program slicing comes from the ability to assist in tedious and
error prone tasks such as program debugging [1,50,54,64,65,66,88,95], testing [3,11,
17,20,31,51,54, 57, 87], parallelization [23,96], integration [82,43,80,81,83], software
safety [33], understanding [24,56,69,75], software maintenance [32,58,70,74,77,78], and
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34

Partial preview of the text

Download Program Slicing: Utilizing Program Dependence Graphs for Analysis and Debugging and more Papers Computer Science in PDF only on Docsity!

Program Slicing

David W. Binkley

Keith Brian Gallagher

A hundred times every day, I remind myself that my inner and outer life dep ends on the lab ors of other men, living and dead, and that I must exert myself in order to give in the measure as I have received and am still receiving. A. Einstein

1 Intro duction

At the fteenth International Conference on Software Engineering (ICSE), in 1993, Mark Weiser received recognition for the b est pap er at the fth ICSE. Weiser rep orted that \Program Slicing"[94], the conference pap er, and its journal incarnation of the same name[97], were cited ab out 10 times a year from 1984 to 1989 and ab out 20 times a year in 1990 and 1991. Our subsequent search of the \Science Citation Index" found 9 citations in 1992; 9 citations in 1993; and 15 citations in 1994. This is clearly a lower b ound. Our bibliography of 94 items (91, excluding Weiser's original work) has only 12 that do not cite it, 5 of which were published prior to the original pap er. The references included universities in 10 countries and 8 industrial lab oratories. Since so many researchers and practitioners have b een citing this seminal work, herein we attempt to collate, summarize and organize the edi ce of results that have followed. Program slicing is a decomp osition technique that extracts from program statements rele- vant to a particular computation. Informally, a slice provides the answer to the question \What program statements p otentially a ect the computation of variable v at statement s?" An ob- server viewing the execution of a program and its slice cannot determine which is which when attention if fo cused on statement s. It is as if the observer has a window through which only part of the program state can b e seen as illustrated by the \clear window" in Figure 1. The utility and p ower of program slicing comes from the ability to assist in tedious and error prone tasks such as program debugging [1, 50 , 54 , 64 , 65 , 66 , 88 , 95 ], testing [3, 11 , 17 , 20 , 31 , 51 , 54 , 57, 87 ], parallelization [23, 96 ], integration [82, 43 , 80 , 81 , 83 ], software safety [33], understanding [24, 56 , 69 , 75 ], software maintenance [32, 58 , 70 , 74 , 77 , 78 ], and

Figure 1: The Programmer's View of a Slice

software metrics [62, 63 , 72, 71]. Slicing do es this by extracting an algorithm whose computation may b e scattered through out a program from intervening irrelevant statements. Consequently, it should b e easier for a programmer interested in a subset of the program's b ehavior to understand the slice.

1.1 A Brief History

This section provides a brief history of program slicing and intro duces the principal terminology. A slice is taken with resp ect to a slicing criterion < s; v >, which sp eci es a lo cation (statement s) and a variable (v ). This can b e easily extended to slicing with resp ect to a collection of lo cations and a collection of variables at each lo cation by taking the union of the individual slices. However, to simplify the exp osition, we present de nitions for the single statement and single variable case. Program slices, as originally intro duced by Weiser [93, 94 , 97 ], are now called executable backward static slices. Executable b ecause the slice is required to b e an executable program. Backwards b ecause of the direction edges are traversed when the slice is computed using a dependence graph. And nally, static b ecause they are computed as the solution to a static analysis problem (i.e., without considering the programs input). Weiser's requirement that a slice b e executable provided an empirical validation of the con- cept. Although this seems reasonable, many applications of program slicing (e.g., debugging) do not require executable slices. This issue is considered in Section 2. Weiser originally used a control- ow graph as an intermediate representation for his slicing

n statement 1 c = 0 2 while ( TRUE ) 3 c = 1 4 endwhile 5 c = 2

n statement 5 c = 2

Figure 2: \Sliceable" Divergent Program and the convergent Slice taken with resp ect to < 5 ; c >

De nition 4 Executable Program Slice. For statement s and variable v , the slice S of program P with resp ect to the slicing criterion < s; v > is any executable program with the following prop erties:

  1. S can b e obtained by deleting zero or more statements from P.
  2. If P halts on input I , then the value of v at statement n each time n is executed in P is the same in P and S. If P fails to terminate normally^1 n may execute more times in S that in P , but P and S compute the same values each time n is executed by P.

Note that every program has itself as a slice on any criteria. Example. The program of Figure 2 never executes Statement 5, while the slice on < 5 ; c > includes only Statement 5, which is executed once.

2.1 Slicing Control Flow Graphs

This section describ es computing a slice as the solution to a data- ow problem using a control- ow graph as an intermediate representation. It considers a progression of harder slicing prob- lems b eginning with slicing straight-line programs, then considering structured control ow, unstructured control ow, data structures, and nally, pro cedures. Computing a slice from a control- ow graph is a two step pro cess: rst requisite data ow information is computed and then this information is used to extract the slice. The data- ow information is the set of relevant variables at each no de n. For the slice with resp ect to < s; v >, the relevant set for each no de contains the variables whose values (transitively) a ect the computation of v at s. The second step identi es the statements of the slice. These include all no des (statements) n that assign to a variable relevant at n and the slice taken with resp ect to any predicate no de that directly controls n's execution.

(^1) A program fails to terminate normally if it diverges or terminates abnormally, for example, with a division

by zero error.

n statement r ef s(n) def s(n) r el ev ant(n) 1 b = 1 b 2 c = 2 c b 3 d = 3 d b; c 4 a = d d a b; c 5 d = b + d b; d d b; c 6 b = b + 1 b b b; c 7 a = b + c b; c a b; c 8 pr int a a a

Figure 3: Relevant Sets for < 8 ; a >.

2.1.1 Slicing Flow Graphs of Straight Line Programs

Straight-line co de contains only assignment statements executed one after the other. For such co de the additional slices with resp ect to predicate no des are not required. We b egin by assuming that expression evaluation do es not alter the values of its op erands. Relevant sets for the slice taken with resp ect to < n; v > are computed as follows [64]:

  1. Initialize all relevant sets to the empty set.
  2. Insert v into r el ev ant(n).
  3. For m, n's immediate predecessor, assign r el ev ant(m) the value (r el ev ant(n) D E F (m)) [ (R E F (m) if r el ev ant(n) \ D E F (m) 6 = ;)
  4. Working backwards, rep eat Step (3) for m's immediate predecessors until ninitial is reached.

Example. Figure 3 shows the relevant sets for a slice taken with resp ect to < 8 ; a >. The relevant sets are computed from Line 8 to Line 1. For example, r el ev ant(7) = (r el ev ant(8) D E F (7)) [ (R E F (7) if r el ev ant(8) \ D E F (7) 6 = ;) = (fag fag) [ (fb; cg if fag \ fag 6 = ;) = fb; cg, and r el ev ant(2) = (fb; cg fcg) [ (; if fb; cg \ fcg 6 = ;) = fbg. If we were interested in some variable other than a, the computation of the relevant sets would b e di erent; thus, di erent relevant sets must b e computed for di erent slices. The relevant sets may b e viewed as a ow of sets of variables; the slice is the set of statements that disturb this ow. If no relevant variables are def ined at a statement, then the relevant set ows through unp erturb ed. On the other hand, if a relevant variable is def ined then the statement is added to the slice. In Figure 3, for example, the slice with resp ect to < 8 ; a > includes Lines 7, 6, 2 and 1 (Line 6 changes the b that is in the relevant set). Note that, in practice, the relevant sets and the statements in the slice are computed in a single pass.

n r ef s(n) r ef s(n) contr ol (n) r el ev ant(n) 1 b a 2 c a; b 3 d a; b 4 d a a; b 5 a b; c; d 6 b; d d 5 b; d 7 b; d c 5 b; c 8 5 c; d 9 b b 8 c; d 10 b d 8 c; d 11 b; c 12 b; c a b; c 13 a a

Figure 5: Relevant Sets on a at 13

n statement 0 w hil e (a) 1 xn = xn 1 2 xn 1 = xn 2 : : : n x 2 = x 1 n + 1 endw hil e

Figure 6: A while statement that needs n passesto compute a slice when x 1 is in the criteria.

relevant sets: Working backwards from Line 13, since D E F (12)

T

R el ev ant(13) 6 = ;, Line 12 is included in the slice and its relevant set is assigned fb, cg. No change o ccurs at Line 11. Line 10 is included in the slice b ecause D E F (10)

T

R el ev ant(11) 6 = ;; r el ev ant(10) is assigned fc, dg. Next, Lines 5 and 8 are included in the slice b ecause contr ol (10) includes 8 and contr ol (8) includes Line 5. Along with these lines, the lines in the slices with resp ect to < 8 ; R E F (8) > = < 8 ; ; > and < 5 ; R E F (5) > = < 5 ; a > are also included. These add to the slice Lines 4 and 3. Finally, Line 6 completes the slice. The third change is required to handle lo ops. The absence of lo ops allows a slice to b e computed in a single pass over the control- ow graph; the presence of lo ops requires iterating over parts of the graph. In particular, iteration over each lo op until the relevant sets and slice stabilize. Hausler [39] has shown that the maximum numb er of iterations is the same as the numb er of assignment statements in the lo op. Figure 6 shows how the upp er b ound is reached.

2.1.3 Slicing Un-Structured Programs

The addition of goto statements, and its restricted forms such as return, exit, break, and continue complicate the construction of the control sets. One solution is to restructure the program as goto-less [60] and then slice. The drawback to this metho d is that the structured version may b e signi cantly textually dissimilar from the original. Lyle [64] prop osed a simple and conservative solution to slicing over unstructured control ows: if a goto statement has a non-empty relevant set, include it the slice. The targets of the goto are included, and so on until the slice stabilizes. An alternative approach [29] is to note that goto statements are asso ciated with labels. Rather than lo ok for goto statements to include in the slice, lo ok for lab eled statements that are included in the slice. Then include only the goto statements that branch to these lab els. This algorithm was devised for a language in which the only lab els are targets of goto's, a lab eled statement do es no computation, and do es not have explicit comp ound statements. That is, statements of the form

if ( b ) then { /* compute X / } else { / compute Y */ }

are replaced by the semantically equivalent:

one may naively assume that D E F (n) = fag and R E F (n) = fi; xg. But the new value of a also dep ends and the old value of a, so a must also b e included. The correct value for R E F (n) is fa; i; xg. However, this approach leads to correct, but unnecessary large slices. To more precisely determine if there is a dep endence b etween a statement that contains an assignment to a[f (i)] and a statement that contains a use of a[g (j )] requires answering the question \Can f (i) = g (j )?" In general this question is unanswerable, although it can b e solved for some common index expression typ es. These solutions are often one sided: algorithms exist to determine if the answer to the question is \no." Otherwise, no information is obtained. To illustrate this, consider the Greatest Common Divisor (GCD) Test applied to the following lo op

i = 0 while (i < N) f X[a 1 * i + a 0 ] = : : : : : : = X[b 1 * i + b 0 ] i = i + 1 g

If g cd(a 1 ; b 1 ) do es not divide (b 0 a 0 ) then the GCD test demonstrates the absence of a dep endence b etween s 1 and s 2 , but if g cd(a 1 ; b 1 ) divides (b 0 a 0 ), the solution may lay outside the range 0 :::N. Other tests [68, 76 ] are similarly one sided. If none of these tests can prove the absence of a ow dep endence then one is assumed to exist. This provides a more precise, yet safe, approximation to the correct data relationships. Once this has b een done, the slicing algorithm pro ceeds as in the absence of arrays. Records are simple, if not tedious, to treat in a slicing algorithm. Unlike arrays, each eld of a record is identi ed by a constant (the eld's name). This allows o ccurrences of r ecor d:f iel d to b e treated as o ccurrences of the simple variable r ecor d f iel d. The assignment of one record to another is mo deled as a sequence of eld assignment. The multiple levels of indirection for b oth assignment and reference of p ointers create dicult problems. One must obtain every p ossible lo cation to which a p ointer could p oint. If a variable is defined or referenced through a chain of p ointers (e.g., *****a), then all intermediate lo cations in the accessing of the variable must b e considered as refed lo cations. Lyle, et al. [67] construct, then prune a pointer state graph (PSS) for expression k^ a. The P S Sk (a) is a directed graph with single source a and de ned recursively as

P S Sk (a) =

a; if k = 0 fv j  a = v g; if k = 1 & edg e(a; v ) 2 P S Sk (a) fv j v 2 P S S 1 (u) ^ u 2 P S Si 1 (a)g; other w ise & edg e(u; v ) 2 P S Sk (a)

P S Sk (a) gives the p ossible references of k^ a. It is then pruned: RP S Sk (a) (w ) = fv 2 P S Sk (a) ^ dist(v ; w )  k g, where dist(w ; v ) is the distance, measured in edges, b etween v and w. RP S Sk (a) (w )

is used to compute D E F (n) by eliminating the indirect de nitions of w that cannot reached via k levels of indirection from a. See [67] for a detailed discussion.

2.1.5 Interpro cedural Slicing

Slicing across pro cedures^3 complicates the situation due to the necessity of translating and passing the criteria into and out of calling and called pro cedures. When pro cedure P calls pro cedure Q at statement i, the active criteria must rst b e translated into the context of Q and then recovered once Q has b een sliced. To translate a set of criteria, C , into a called pro cedure, for each v 2 r el ev ant(succ(Q))
actual par ameter (Q) map v!! , the corresp onding formal parameter of Q. Then generate new criteria < nQf inal ;! >. If v 2 r el ev ant(succ(Q)) \ l ocal def inition(Q), i.e., a lo cal rede nition

of v o ccurs, change the line numb er of criteria involving v to i, the call-site of Q. When nQinitial is reached, unmap!! v , and replace nQinitial with i. Weiser called this new set of criteria DOWN 0 (C ). This is essentially an in-line replacement of each pro cedure o ccurrence, with appropriate substitutions. Globals pass into the called pro cedure undisturb ed if their visibility is not blo cked by a variable in Q; thus references to them inside the pro cedures are captured correctly. This metho d was intro duced early in the development of the idea of slicing and do es not address hard questions ab out p ointers, aliasing, function parameters, etc. When P is called from statement j of Q, criteria must b e generated to slice up into Q. The new criteria are generated in similar fashion to the calling context. Criteria involving lo cal variables are discarded, so that no unde ned references are passed out. Criteria involving formal parameters are mapp ed into the corresp onding actual of Q with new line numb er j. Weiser called this set U P 0 (C ). The sets DOWN 0 (C ) and U P 0 (C ) are then mapp ed to functions from criteria to criteria: DOWN(C C ) = [C 2 C C DOWN 0 (C ) and U P (C C ) = [C 2 C C U P 0 (C ). Union and transitive closure are de ned in the usual way for these relations. Thus (DOWN[U P )^ (C ) will give a complete set of criteria to obtain the interpro cedural slice for any criteria. This conservative, but correct, approximation was improved by [48].

2.2 Slicing as a Graph-Reachability Problem

Ottenstein and Ottenstein [73] observed that the program dep endence graph (PDG), used in vectorizing and parallelizing compilers and program development environments, would b e an ideal representation for constructing program slices: \Explicit data and control dep endence make the PDG ideal for constructing program slices" [73].

(^3) This section follows closely that of Weiser [97].

A ow dep endence edge from vertex u to vertex v means that the program's computation might b e changed if the relative order of the comp onents represented by u and v were reversed. The ow-dep endence edges of a PDG are computed using data- ow analysis. A PDG contains a ow dep endence edge from vertex u to vertex v , denoted by u !f v , i all of the following hold:

  1. u is a vertex that de nes variable x.
  2. v is a vertex that uses x.
  3. Control can reach v after u via an execution path along which there is no intervening de nition of x.

Flow dep endences can b e further classi ed as loop carried or loop independent. A ow dep endence u !f v is carried by lo op L, denoted by u!l c(L) v , if in addition to 1, 2, 3 ab ove, the following also hold:

  1. There is an execution path that b oth satis es the conditions of (3) ab ove and includes a backedge to the predicate of lo op L.
  2. Both u and v are enclosed in lo op L.

A ow dep endence u !f v is lo op indep endent, denoted by u!l i v , if in addition to 1, 2, 3 ab ove, there is an execution path that satis es 3 ab ove and includes no backedge to the predicate of a lo op that encloses b oth u and v. It is p ossible to have b oth u !l c(L) v and u!l i v. When there is more than one lo op-carried ow dep endence edge b etween two vertices, each is lab eled by a di erent lo op that carries the dep endence. Figure 7 shows an example program and its PDG. For vertex s of PDG G, the slice of G with resp ect to s, denoted by S l ice(G; s), is a graph containing all vertices on which s has a transitive ow or control dep endence (i.e., all vertices that can reach s via ow and/or control edges): V (S l ice(G; s)) = fv 2 V (G) j v ! c;f sg. The edges of S l ice(G; s) are those in the subgraph of G induced by V (S l ice(G; s)):

E (S l ice(G; S )) = fv !f u 2 E (G) j v ; u 2 V (S l ice(G; S ))g [fv !c u 2 E (G) j v ; u 2 V (S l ice(G; S ))g

The vertices of the slice of the PDG shown in Figure 7 taken with resp ect to the output vertex for i are highlighted in Figure 7. Slicing programs with comp osite data structures involves changing the computation of the ow dep endence edge only. Two metho ds for slicing in the presence of arbitrary control ow (programs containing gotos) require mo difying the control dep endence subgraph of the PDG, but not the slicing algorithm. Choi and Ferrante [22] augment the the control ow graph that

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh program Main SUM := 0 i := 1 while i < 11 do SUM := SUM + i i := i + 1 od print ( SUM ) print ( i ) end

Edge Key control dependence loop-independent flow dependence | loop-carried flow dependence

ENTRY

SUM := 0 i := 1 while i < 11

SUM := SUM + i i := i + 1

Output( i ) Output( SUM )

T T T T T

T T

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

Figure 7: An example program, which sums the integers from 1 to 10 and leaves the result in the variable sum, and its program dep endence graph. The vertices of the slice of this PDG taken with resp ect to the nal use of i is shown in b old.

  1. A complete system consists of a single main pro cedure and a collection of auxiliary pro ce- dures.
  2. Parameters are passed by value-result.

Techniques for handling parameters passed by reference and for dealing with aliasing as discussed at the end of this section. Horwitz, et al. [48] make the further assumption that there are no call sites of the form P (x; x) or P (g ), where g is a global variable. The former restriction sidesteps p otential copy-back con icts. The latter restriction p ermits global variables to b e treated as additional parameters to each pro cedure; thus, they are not discussed explicitly. An SDG is made up of a collection of pro cedure dep endence graphs connected by interpro ce- dural control- and ow-dep endence edges. Pro cedure dep endence graphs are similar to program dep endence graphs except that they include vertices and edges representing call statements, pa- rameter passing, and transitive ow dep endences due to calls (we will abbreviate b oth pro cedure dep endence graph and program dep endence graph by \PDG"). A call statement is represented using a cal l vertex; parameter passing is represented using four kinds of parameter vertices: on the calling side, parameter passing is represented by actual-in and actual-out vertices, which are control dep endent on the call vertex; in the called pro cedure, parameter passing is represented by formal-in and formal-out vertices, which are control dep endent on the pro cedure's entry ver- tex. Actual-in and formal-in vertices are included for every global variable that may b e used or mo di ed as a result of the call and for every parameter; formal-out and actual-out vertices are included only for global variables and parameters that may b e mo di ed as a result of the call. Interpro cedural data- ow analysis is used to determine the parameter vertices included for each pro cedure [8, 10 ]. Transitive dep endence edges, called summary edges, are added from actual-in vertices to actual-out vertices to represent transitive ow dep endences due to called pro cedures. These edges were originally computed using a variation on the technique used to compute the sub or- dinate characteristic graphs of an attribute grammar's nonterminals [48]. Recently, Reps et. al. describ ed a faster algorithm for computing summary edges [84]. A summary edge is added if a path of control, ow and summary edges exists in the called pro cedure from the corresp onding formal-in vertex to the corresp onding formal-out vertex. Note that the addition of a summary edge in pro cedure Q may complete a path from a formal-in vertex to a formal-out vertex in Q's PDG, which in turn may enable the addition of further summary edges in pro cedures that call Q. Pro cedure dep endence graphs are connected to form an SDG using three new kinds of edges:

  1. a cal l edge is added from each call-site vertex to the corresp onding pro cedure-entry vertex;
  2. a parameter-in edge is added from each actual-in vertex at a call site to the corresp onding formal-in vertex in the called pro cedure; and
  1. a parameter-out edge is added from each formal-out vertex in the called pro cedure to the corresp onding actual-out vertex at the call site.

Figure 8 shows an example system and the corresp onding SDG. (In Figure 8, as well as in the remaining gures of the pap er, the edges representing control dep endences are shown unlab eled; all such edges would b e lab eled true.) Interpro cedural slicing can b e de ned as a reachability problem using the SDG, just as intra- pro cedural slicing is de ned as a reachability problem using the PDG. The slices obtained using this approach are the same as those obtained using Weiser's interpro cedural-slicing metho d [97]. However, his approach do es not pro duce slices that are as precise as p ossible, b ecause it considers paths in the graph that are not p ossible execution paths. For example, there is a path in the graph shown in Figure 8 from the vertex of pro cedure M ain lab eled \xin := sum" to the vertex of M ain lab eled \i := yout ." However, this path corresp onds to pro cedure Add b eing called by pro cedure A, but returning to pro cedure I ncr ement, which is not p ossible. The value of i after the call to pro cedure A is indep endent of the value of sum b efore the call, and so the vertex lab eled \xin := sum" should not b e included in the slice with resp ect to the vertex lab eled \i := yout " Figure 9 shows this slice). To achieve more precise interpro cedural slices, an interpro cedural slice with resp ect to vertex s is computed using two passes over the graph. Summary edges p ermit moving across a call site without having to descend into the called pro cedure; thus, there is no need to keep track of calling context explicitly to ensure that only legal execution paths are traversed. Both passes op erate on the SDG, traversing edges to nd the set of vertices that can reach a given set of vertices along certain kinds of edges. Informally, if s is in pro cedure P then pass 1 identi es vertices that reach s and are either in P itself or pro cedures that (transitively) call P. The traversal in pass 1 do es not descend into pro cedures called by P or its callers. Pass 2 identi es vertices in called pro cedures that induce the summary edges used to move across call sites in pass 1. The traversal in pass 1 starts from s and go es backwards (from target to source) along ow edges, control edges, call edges, summary edges, and parameter-in edges, but not along parameter-out edges. The traversal in pass 2 starts from all vertices reached in pass 1 and go es backwards along ow edges, control edges, summary edges, and parameter-out edges, but not along call, or parameter-in edges. The result of an interpro cedural slice consists of the sets of vertices encountered during by pass 1 and pass 2, and the set of edges induced by this vertex set. A worklist algorithm for nding the vertices of an interpro cedural slice is stated in [48]. The (full backward) interpro cedural slice of graph G with resp ect to vertex set S , denoted by S l ice(G; S ), consists of the sets of vertices identi ed by pass 1 and pass 2, and the set of edges induced by this vertex set. S l ice(G; S ) is a subgraph of G. However, unlike intrapro cedural slicing, it may b e infeasible (i.e., it may not b e the SDG of any system). The problem arises when S l ice(G; S ) includes mismatched parameters: di erent call-sites on a pro cedure include di erence parameters. There

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh procedure Main i := 1 while i < 11 do call A ( i ) od end ()

procedure A ( y ) call Increment ( y ) return

procedure Add ( a , b ) a := a + b return

procedure Increment ( z ) call Add ( z , 1) return

ENTER Main

i := 1 while i < 11

call A

yin := i i := yout

ENTER A

y := yin call Inc yout := y

z (^) in := y y := z (^) out

ENTER Inc

z := z (^) in call Add z (^) out := z

ain := z bin := 1 z := a (^) out

ENTER Add

a := a (^) in b := b (^) in a := a + b aout := a

Edge Key control intraprocedural flow (loop-independent) | intraprocedural flow(loop-carried) summary call,parameter-in, parameter-out

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

Figure 9: The SDG from gure 8 sliced with resp ect to the formal-out vertex for parameter z in pro cedure I ncr ement, together with the system to which it corresp onds. Note that this slice correctly excludes the vertex lab eled xin := sum 19 in gure 8

are two causes of mismatches: missing actual-in vertices and missing actual-out vertices. Mak- ing such systems syntactically legal by simply adding missing parameters leaves semantically unsatisfactory systems [19]. In order to include the program comp onents necessary to compute a safe value for the parameter represented at missing actual-in vertex v , the vertices in the Pass 2 slice of G taken with resp ect to v must b e added to the original slice. A Pass 2 slice includes the minimal numb er of comp onents necessary to pro duce a semantically correct system. The addition of Pass 2 slices is rep eated until no further actual-in vertex mismatches exist. The second cause of parameter mismatches is missing actual-out vertices. Because missing actual-out vertices represent dead-co de no additional slicing is necessary. Actual-out mismatches are removed by simply adding missing actual-out vertices to the slice. A system can now b e obtained by pro jecting the statements of the original system that are in the original slice or added by the ab ove two steps. These statements app ear in the same order and at the same nesting level as in the original system. The details of this algorithm are given in [19].

2.2.3 Interpro cedural Slicing in the Presence of Call-By-Reference Parameter Pass- ing and Aliasing

The de nitions of the system dep endence graph and interpro cedural slicing assume that param- eters are passed by using value-result parameter passing. The same de nitions hold for call-by- reference parameter passing in the absence of aliasing; however, in the presence of aliasing, some mo di cations are required. Two extreme metho ds for handling aliasing include transforming the system into an aliasing-free system and generalizing the de nition of ow dep endence. Trans- lation is done by creating a copy of a pro cedure for each p ossible aliasing con guration that it may b e called under. Because the numb er of aliasing con gurations is p otentially exp onential, the cost of this transformation may, in the worst case, b e exp onential in the maximum numb er of formal parameters asso ciated with any one pro cedure. Generalizing the de nition of ow dep endence makes the p essimistic assumption that any aliases that exist during a particular call to a pro cedure may exist during all calls to the pro ce- dure. Such aliases are referred to as may aliases. This requires the use of generalized de nitions for ow dep endence. For example, a ow dep endence edge connects vertex v to vertex u i all of the following hold:

  1. v is a vertex that de nes variable x.
  2. u is a vertex that uses variable y.
  3. x and y are p otential aliases.
  4. Control can reach u after v via a path in the control- ow graph along which there is no intervening de nition of x or y.