





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






















Thomas Reps, Akash Lal, and Nick Kidd
Comp. Sci. Dept., University of Wisconsin; {reps, akash, kidd}@cs.wisc.edu
Abstract. Pushdown systems (PDSs) are an automata-theoretic for- malism for specifying a class of infinite-state transition systems. Infinite- ness comes from the fact that each configuration 〈p, S〉 in the state space consists of a (formal) “control location” p coupled with a stack S of unbounded size. PDSs can model program paths that have matching calls and returns, and automaton-based representations allow analysis algorithms to account for the infinite control state space of recursive programs. Weighted pushdown systems (WPDSs) are a generalization of PDSs that add a general “black-box” abstraction for program data (through weights). WPDSs also generalize other frameworks for interprocedural analysis, such as the Sharir-Pnueli functional approach. This paper surveys recent work in this area, and establishes a few new connections with existing work.
Static analysis provides a way to obtain information about the possible states that a program reaches during execution, but without actually running the pro- gram on specific inputs. Static-analysis techniques explore the program’s behav- ior for all possible inputs and account for all possible states that the program can reach. In this sense, static analysis is more comprehensive than traditional testing, which tests the program’s behavior for a fixed (possibly randomly gen- erated) finite set of runs of the program. For any non-trivial program, it is im- possible to test explicitly all the possible behaviors within a reasonable amount of time; in contrast, static-analysis techniques use approximations to account for all of the actions that the program could perform [13]. To make this feasible, two techniques are used:
Analysis algorithms typically use the program’s interprocedural control-flow graph (also known as its ICFG). An ICFG consists of a collection of control-flow graphs (CFGs)—one for each procedure—one of which represents the program’s main procedure. The CFG for a procedure p has a unique enter node and a unique exit node. The other nodes represent the program’s statements and con- ditions (or, alternatively, its basic blocks), except that each procedure call in the program is represented in the ICFG by two nodes, a call node and a return-site node. Call-edges connect call nodes to enter nodes; return-edges connect exit nodes to return-site nodes. A typical analysis goal is to compute, for each ICFG node n, an overapproximation (i.e., superset) of the set of states that can hold when n is reached.
The choice of which family of data descriptors that an algorithm uses impacts which behavioral properties of the program can be observed. This, in turn, affects (i) what sets of states can be represented, and (ii) which program fragments need to be explored. For example, one might use descriptors that represent only the sign of a variable’s value: neg, zero, pos, and unknown. In a context in which it is known that both a and b are positive (i.e., when the memory descriptor is 〈a 7 → pos, b 7 → pos〉), a multiplication expression such “ab” would be performed as “pospos”.
Such memory descriptors generally represent a superset of the actual set of memory states that are reachable, because a descriptor such as 〈a 7 → pos, b 7 → pos〉 represents all states in which a and b hold positive inte- gers (whereas, for example, only combinations with odd positive a’s and even positive b’s might be reachable). At a branch-point in the program, the analyzer needs to observe the possible outcomes of the branch-point’s condition—as best it can, given the memory descriptors in use. This is used to determine an over- approximation of the paths along which control might flow. Thus, a more refined class of data descriptors can sometimes allow certain paths to be excluded from consideration.
On the other hand, certain paths can be excluded merely from consideration of the control-flow properties of the programming language. An important class of paths that can be excluded are those that violate the language’s call/return protocol; in particular, an analysis should only consider paths in which the return from a called procedure is matched with the most recent call. Fig. 1 shows a fragment of an ICFG, and an example of a path fragment that should be excluded from consideration.
Dataflow-analysis algorithms that exclude such paths have a long history [14, 47, 26]. A natural class of dataflow-analysis problems in which this issue is reduced to a pure graph-reachability problem is also known [40]. The algorithms developed for that class of problems are useful for analyzing a family of program abstractions called Boolean programs (§2.3). (Boolean programs have become well-known due to their use in SLAM [4, 5] to represent program abstractions obtained via predicate abstraction [20].)
More recently, analysis techniques based on pushdown systems (PDSs) [6, 18, 44] have been developed. PDSs are an automata-theoretic formalism for speci-
affine relations and may-alias relations. Second, the algorithms for solving path problems in WPDSs can provide a witness set of paths [42], which is useful for providing an explanation of why the answer to a dataflow query has the value reported. Two implementations of WPDSs are publicly available [45, 24], and both provide a convenient base for implementing different analyses. As a programming abstraction, these systems offer several benefits:
2.1 Background on Interprocedural Dataflow Analysis
Dataflow analysis is concerned with determining an appropriate dataflow value to associate with each node n in a program, to summarize (safely) some aspect of the possible memory configurations that hold whenever control reaches n. To define an instance of a dataflow problem, one needs
Definition 1. A path of length j from node m to node n is a (possibly empty) sequence of j edges, denoted by [e 1 , e 2 ,... , ej ], such that the source of e 1 is m, the target of ej is n, and for all i, 1 ≤ i ≤ j − 1 , the target of edge ei is the source of edge ei+1.
The path function pfq for path q = [e 1 , e 2 ,... , ej ] is the composition, in order, of q’s transfer functions: pfq = M (ej ) ◦... ◦ M (e 2 ) ◦ M (e 1 ). In intraprocedural dataflow analysis, the goal is to determine, for each node n, the “meet-over-all- paths” solution: MOPn = q∈Paths(enter,n)
pfq (v 0 ),
where Paths(enter, n) denotes the set of paths in the CFG from the enter node to n [25]. MOPn represents a summary of the possible memory configurations that can arise at n: because v 0 ∈ V represents the set of possible memory con- figurations at the beginning of the program, pfq(v 0 ) represents the contribution of path q to the memory configurations summarized at n. The soundness of the MOPn solution with respect to the programming lan- guage’s concrete semantics is established by the methodology of abstract inter- pretation [13]:
more e’s) generated by the context-free grammar shown below on the right. (In both grammars, i ranges from 1 to CallSites.)
valid → matched valid matched → matched matched | (i valid | (i matched )i | | e |
The language L(valid) is a language of partially balanced parentheses: every right parenthesis “)i” is balanced by a preceding left parenthesis “(i”, but the converse need not hold.
Example 1. In the ICFG shown in Fig. 2, the path [emain, n 1 , n 2 , n 3 , ef, n 10 , n 11 , xf, n 4 , n 5 ] is a matched path, and hence a valid path; the path [emain, n 1 , n 2 , n 3 , ef, n 10 ] is a valid path, but not a matched path, because the call-to-enter edge n 3 → ef has no matching exit-to-return-site edge; the path [emain, n 1 , n 2 , n 3 , ef, n 10 , n 11 , xf, n 8 ] is neither a matched path nor a valid path because the exit-to-return-site edge xf → n 8 does not correspond to the preceding call-to-enter edge n 3 → ef.
In interprocedural dataflow analysis, the goal shifts from finding the meet- over-all-paths solution to the more precise “meet-over-all-valid-paths”, or “context- sensitive” solution. A context-sensitive interprocedural dataflow analysis is one in which the analysis of a called procedure is “sensitive” to the context in which it is called. A context-sensitive analysis captures the fact that the results prop- agated back to each return site r should depend only on the memory configu- rations that arise at the call site that corresponds to r. More precisely, the goal of a context-sensitive analysis is to find the meet-over-all-valid-paths value for nodes of the ICFG [47, 26, 43]:
MOVPn = q∈VPaths(emain,n)
pfq(v 0 ),
where VPaths(emain, n) denotes the set of valid paths from the main procedure’s enter node to n. Although some valid paths may also be infeasible execution paths, none of the non-valid paths are feasible execution paths. By restricting attention to just the valid paths from emain, we thereby exclude some of the infeasible execution paths. In general, therefore, MOVPn characterizes the memory configurations at n more precisely than MOPn.
2.2 Pushdown Systems
In this section, we define pushdown systems and show how they can be used to encode ICFGs.
Definition 2. A pushdown system is a triple P = (P, Γ, ∆), where P is a finite set of states (also known as “control locations”), Γ is a finite set of stack
Rule Control flow modeled 〈p, u〉 ↪→ 〈p, v〉 Intraprocedural edge u → v 〈p, c〉 ↪→ 〈p, ef r〉 Call to f from c that returns to r 〈p, xf 〉 ↪→ 〈p, ε〉 Return from f at exit node xf
Fig. 3. The encoding of an ICFG’s edges as PDS rules.
symbols, and ∆ ⊆ P ×Γ ×P ×Γ ∗^ is a finite set of rules. A configuration of P is a pair 〈p, u〉 where p ∈ P and u ∈ Γ ∗. A rule r ∈ ∆ is written as 〈p, γ〉 ↪→ 〈p′, u〉, where p, p′^ ∈ P , γ ∈ Γ and u ∈ Γ ∗. These rules define a transition relation ⇒ on configurations of P as follows: If r = 〈p, γ〉 ↪→ 〈p′, u′〉, then 〈p, γu〉 ⇒ 〈p′, u′u〉 for all u ∈ Γ ∗. The reflexive transitive closure of ⇒ is denoted by ⇒∗. For a set of configurations C, we define pre∗(C) = {c′^ | ∃c ∈ C : c′^ ⇒∗^ c} and post∗(C) = {c′^ | ∃c ∈ C : c ⇒∗^ c′}, which are just backward and forward reachability under the transition relation ⇒.
Without loss of generality, we restrict the pushdown rules to have at most two stack symbols on the right-hand side [44]. A rule r = 〈p, γ〉 ↪→ 〈p′, u〉, u ∈ Γ ∗, is called a pop rule if |u| = 0, and a push rule if |u| = 2. The PDS configurations model (node, stack) pairs of the program’s state. Given a program P , we can use a PDS to model a limited portion of a P ’s be- havior in the following sense: the configurations of the PDS represent a superset of P ’s (node, stack) pairs. The standard approach for modeling a program’s control flow with a push- down system is as follows: P contains a single state p, Γ corresponds to the nodes of the program’s ICFG, and ∆ corresponds to edges of the program’s ICFG (see Fig. 3). For instance, the rules that encode the ICFG shown in Fig. 2 are
〈p, emain〉 ↪→ 〈p, n 1 〉 〈p, n 1 〉 ↪→ 〈p, n 2 〉 〈p, n 2 〉 ↪→ 〈p, n 3 〉 〈p, n 3 〉 ↪→ 〈p, ef n 4 〉 〈p, n 4 〉 ↪→ 〈p, n 5 〉 〈p, n 5 〉 ↪→ 〈p, n 6 〉
〈p, n 5 〉 ↪→ 〈p, n 9 〉 〈p, n 6 〉 ↪→ 〈p, n 7 〉 〈p, n 7 〉 ↪→ 〈p, ef n 8 〉 〈p, n 8 〉 ↪→ 〈p, n 9 〉 〈p, n 9 〉 ↪→ 〈p, xmain〉 〈p, xmain〉 ↪→ 〈p, ε〉
〈p, ef〉 ↪→ 〈p, n 10 〉 〈p, n 10 〉 ↪→ 〈p, n 11 〉 〈p, n 11 〉 ↪→ 〈p, xf〉 〈p, n 10 〉 ↪→ 〈p, n 12 〉 〈p, n 12 〉 ↪→ 〈p, xf〉 〈p, xf〉 ↪→ 〈p, ε〉
PDSs that have only a single control location, as discussed above, are also called “context-free processes” [10]. In §2.3, we will discuss how, in addition to control flow, PDSs can also be used to encode program models that involve finite abstractions of the program’s data. PDSs that have multiple control locations are used in such encodings. The problem of interest is to find the set of all reachable configurations, starting from a given set of configurations. This can then be used, for example, for assertion checking (i.e., determining if a given assertion can ever fail) or to find the set of all data values that may arise at a program point (for dataflow analysis).
emain p
emain,n 1 ,n 2 ,n 3 , n 4 ,n 5 ,n 6 ,n 7 , n 8 ,n 9 ,xmain,ε p n 4 n^ e 11 f,n,n^1012 ,,^ n 8 xf,ε (^) p ef (a) (b)
Fig. 4. (a) Automaton for the input language of configurations {〈p, emain〉}; (b) au- tomaton for post∗({〈p, emain〉}) (computed for the PDS that encodes the ICFG from Fig. 2).
program consists of a finite set of procedures. It has a finite set of global variables, and a finite set of local variables for each procedure. Each variable can only hold a value from a finite domain.^2 To simplify the discussion, we assume that procedures do not have parameters (they can be passed through global variables). The variables in scope inside a procedure are the global variables and its set of local variables. Fig. 5(a) shows a Boolean program with two procedures and two global variables x and y over a finite domain V = { 0 , 1 ,... , 7 }.
n 1
n 4 n 5
n 6
x=3 x=
y=x
n 7
n 8
n 2 n 3 bar( ) bar( )
proc foo
proc bar [[x = 3]] = {((v 1 , v 2 ), (3, v 2 )) | v 1 , v 2 ∈ V } [[x = 7]] = {((v 1 , v 2 ), (7, v 2 )) | v 1 , v 2 ∈ V } [[y = x]] = {((v 1 , v 2 ), (v 1 , v 1 )) | v 1 , v 2 ∈ V }
(a) (b)
Fig. 5. (a) A Boolean program with two procedures and two global variables x and y over a finite domain V = { 0 , 1 ,... , 7 }. (b) The (non-identity) transformers used in the Boolean program.
Notation. A binary relation on a set S is a subset of S × S. If R 1 and R 2 are binary relations on S, then their relational composition, denoted by “R 1 ; R 2 ”, is defined by {(s 1 , s 3 ) | ∃s 2 ∈ S, (s 1 , s 2 ) ∈ R 1 , (s 2 , s 3 ) ∈ R 2 }. If R is a binary relation, Ri^ is the relational composition of R with itself i times, and R^0 is the identity relation on S. R∗^ = ∪∞ i=0Ri^ is the reflexive-transitive closure of R.
(^2) An assignment to a variable v that holds a value from a finite domain can be thought of a collection of assignments to a vector of Boolean-valued variables, namely, the collection of Boolean-valued variables that holds the encoding of v’s value.
Let G be the set of valuations of the global variables, and let Vali be the set of valuations of the local variables of procedure i. Let L be the set of local states of the program; each local state consists of the value of the program counter, a valuation of local variables from some Vali, and the program stack (which, for each unfinished call to a procedure P , contains a return address and a valuation of the local variables of P ). The effect of executing an assignment or assume statement st, denoted by [[st]], is a binary relation on G × Vali that describes how values of variables in scope can change. Fig. 5(b) shows the (non-identity) transformers used in Fig. 5(a). To encode a Boolean program using a PDS, the state alphabet P is expanded to encode the values of global variables, and the stack alphabet is expanded to encode the values of local variables [44]. Let Ni be the set of control locations of the ith^ procedure. We set P to be G, and Γ to be the union of Ni × Vali over all procedures. (Note that the set of local states L equals Γ ∗.) The PDS rules for the ith^ procedure are constructed as follows: (i) an intraprocedural ICFG edge u → v with action st is encoded via a set of rules 〈g, (u, l)〉 ↪→ 〈g′, (v, l′)〉, for each ((g, l), (g′, l′)) ∈ [[st]]; (ii) a call edge c → r that calls procedure f , with enter node ef , is encoded via a set of rules 〈g, (c, l)〉 ↪→ 〈g, (ef , l 0 ) (r, l)〉, for each (g, l) ∈ G × Vali and l 0 ∈ Valf ; (iii) a procedure return at node u is encoded via a set of rules 〈g, (u, l)〉 ↪→ 〈g, ε〉, for each (g, l) ∈ G × Vali; Under such an encoding of a Boolean program as a PDS, a configuration 〈p, γ 1 γ 2 · · · γn〉 is an element of G × L that describes the instantaneous state of a program. The state p encodes the values of global variables; γ 1 encodes the current program location and the values of local variables in scope; and the rest of the stack encodes the list of unfinished calls with the values of local variables at the time the call was made. The PDS transition relation (⇒), which is essentially a transition relation on G × L, represents the semantics of the Boolean program.
A weighted pushdown system is obtained by augmenting a PDS with a weight domain that is a bounded idempotent semiring [42, 7]. Such semirings are pow- erful enough to encode finite-state data abstractions, such as the ones required for bitvector dataflow analysis, Boolean programs, and the IFDS framework of Reps et al. [40], as well as infinite-state data abstractions, such as linear-constant propagation [43] and affine-relation analysis [34, 35]. We present some of this here; additional material about using WPDSs for interprocedural analysis can be found in [42]. Weights encode the effect that each statement (or PDS rule) has on the data state of the program. They can be thought of as abstract transformers that specify how the abstract state changes when a statement is executed.
Definition 4. A bounded idempotent semiring (or weight domain) is a tuple (D, ⊕, ⊗, 0 , 1), where D is a set whose elements are called weights,
〈p, n 1 〉 ↪→ 〈p, n 2 〉 w 1 〈p, n 1 〉 ↪→ 〈p, n 3 〉 w 2 〈p, n 2 〉 ↪→ 〈p, n 7 n 4 〉 1 〈p, n 3 〉 ↪→ 〈p, n 7 n 5 〉 1 〈p, n 4 〉 ↪→ 〈p, n 6 〉 1 〈p, n 5 〉 ↪→ 〈p, n 6 〉 1 〈p, n 7 〉 ↪→ 〈p, n 8 〉 w 3 〈p, n 8 〉 ↪→ 〈p, ε〉 1
p
p n
acc
n 1 , 1 n 2 ,w 1 n 3 ,w 2 n 4 ,w 4 n 5 ,w 5 n 6 ,w 6
n 7 , 1 n 8 ,w 3 ε , w 3
n 4 ,w 4 n 5 ,w 5 7
p acc
n 7 ,w 3 n 8 , 1 n n^1 ,w^6 n^2 ,w^3 n^3 ,w^3 n^4 ,^1 5 ,^1 n 6 ,^1
w 1 = {((v 1 , v 2 ), (3, v 2 )) | v 1 , v 2 ∈ V } w 2 = {((v 1 , v 2 ), (7, v 2 )) | v 1 , v 2 ∈ V } w 3 = {((v 1 , v 2 ), (v 1 , v 1 )) | v 1 , v 2 ∈ V } w 4 = {((v 1 , v 2 ), (3, 3)) | v 1 , v 2 ∈ V } w 5 = {((v 1 , v 2 ), (7, 7)) | v 1 , v 2 ∈ V } w 6 = (^) ∪ {{((((vv^1 , v^2 ),^ (3,^ 3))^ |^ v^1 , v^2 ∈^ V^ } 1 , v 2 ),^ (7,^ 7))^ |^ v 1 , v 2 ∈^ V^ }
(a) (b) (c)
Fig. 6. (a) A WPDS that encodes the Boolean program from Fig. 5(a). (b) The result of poststar(〈p, n 1 〉) and prestar(〈p, n 6 〉). The final state in each of the automata is acc. (c) Definitions of the weights used in the figure.
3.1 Finite-State Data Abstractions
An important weight domain for WPDSs is the set of all binary relations on a finite set.
Definition 7. If G is a finite set, then the relational weight domain on G is defined as (2G×G, ∪, ; , ∅, id): weights are binary relations on G, combine is union, extend is relational composition (“;”), 0 is the empty relation, and 1 is the identity relation on G.
By instantiating G to be the set of global states of a Boolean program P , we obtain a weight domain for encoding P. This approach yields a more straightfor- ward encoding of P : the weight associated with the rule that encodes an assign- ment or assume statement st of P is exactly [[st]]—i.e., its effect on the global state of P —which, as described in §2.3, is a binary relation on G. For example, the WPDS shown in Fig. 6 encodes the Boolean program from Fig. 5(a). The Boolean program has two variables that range over the set V = { 0 , 1 ,... , 7 }, so G = V × V , where the two components represent the values of x and y, respectively. The set of all data values that reach a node n can be calculated as follows: let S be the singleton configuration consisting of the program’s enter node, and let T be the set {〈p, n u〉 | u ∈ Γ ∗}. Let w = MOVP(S, T ). If w = 0, then the node cannot be reached. Otherwise, w captures the net transformation on the global state from when the program started. The range of w, i.e., the set {g ∈ G | ∃g′^ ∈ G : (g′, g) ∈ w}, is the set of valuations that reach node n. For example, in Fig. 6, the MOVP weight to node n 6 is the weight w 6 shown in Fig. 6(c). Its range shows that either x = 3 and y = 3, or x = 7 and y = 7. Because T can be any regular set, one can also answer stack-qualified queries [42]. For example, the set of values that arise at node n when its procedure is called from call site m can be found by setting T = {〈p, n mr u〉 | u ∈ Γ ∗}, where mr is the return site for call site m.
A WPDS with a weight domain that has a finite set of weights, such as the one described above, can be encoded as a PDS. However, it is often useful to use weights because they can be symbolically encoded. Tools such as Moped and Slam use BDDs [8] to encode sets of data values, which allows them to scale to a large number of variables. (Using PDSs for Boolean program verification, without any symbolic encoding, is generally not a feasible approach.)
3.2 Infinite-State Data Abstractions
An infinite-state data abstraction is one in which the number of abstract states (or weights) is infinite. We begin with two simple examples of infinite weight domains, and then discuss the weight domain used for affine-relation analysis.
Finding Shortest Valid Paths.
Definition 8. The minpath semiring is the weight domain M = (N ∪ {∞}, min, +, ∞, 0): weights are non-negative integers including “infinity”, com- bine is minimum, and extend is addition.
If all rules of a WPDS are given the weight 1 from this semiring (different from the semiring weight 1, which is the integer 0), then the MOVP weight between two configurations is the length of the shortest path (shortest rule sequence) between them. Another infinite weight domain, which is based on the minpath semiring, is given in [28] and was shown to be useful for debugging programs.
Finding Shortest Traces. The minpath semiring can be combined with a relational weight domain, for example, to find the shortest (valid) path in a Boolean program (for finding the shortest trace that exhibits some property).
Definition 9. A weighted relation on a set S, weighted with semiring (D, ⊕, ⊗, 0 , 1), is a function from (S × S) to D. The composition of two weighted relations R 1 and R 2 is defined as (R 1 ; R 2 )(s 1 , s 3 ) = ⊕{w 1 ⊗ w 2 | ∃s 2 ∈ S : w 1 = R 1 (s 1 , s 2 ), w 2 = R 2 (s 2 , s 3 )}. The union of the two weighted relations is defined as (R 1 ∪R 2 )(s 1 , s 2 ) = R 1 (s 1 , s 2 )⊕R 2 (s 1 , s 2 ). The identity relation is the function that maps each pair (s, s) to 1 and others to 0. The reflexive transitive closure is defined in terms of these operations, as before. If → is a weighted relation and (s 1 , s 2 , w) ∈→, then we write s 1 −−w→ s 2.
Definition 10. If S is a weight domain with set of weights D and G is a finite set, then the relational weight domain on (G, S) is defined as (2G×G→D, ∪, ; , ∅, id): weights are weighted relations on G and the operations are the corresponding ones for weighted relations.
If G is the set of global states of a Boolean program, then the relational weight domain on (G, M) can be used for finding the shortest trace: for each
which may assign any integer to xj. (This is typically used for abstracting as- signments that cannot be modeled as an affine transformation of the variables.) All branch conditions in affine programs are non-deterministic.
ARA Weight Domain. We briefly describe the weight domain based on the linear-algebra formulation of ARA from [34]. An affine relation a 0 +
∑n i=1 aixi^ = 0 is represented using a column vector of size n + 1: a = (a 0 , a 1 , · · · , an)t. A valuation of program variables x is a map from the set of global variables to the integers. The value of xi under this valuation is written as x(i).
∑A valuation^ x^ satisfies an affine relation^ a^ =^ (a^0 , a^1 ,^ · · ·^ , an)t^ if^ a^0 + n i=1 aix(i) = 0. An affine relation^ a^ represents the set of all valuations that satisfy it, written as Pts(a). An affine relation a holds at a program node if the set of valuations reaching that node (in the concrete collecting semantics) is a subset of Pts(a). An important observation about affine programs is that if affine relations a 1 and a 2 hold at a program node, then so does any linear combination of a 1 and a 2. For example, one can verify that Pts(a 1 + a 2 ) ⊇ Pts(a 1 ) ∩ Pts(a 2 ), i.e., the affine relation a 1 + a 2 (componentwise addition) holds at a program node if both a 1 and a 2 hold at that node. The set of affine relations that hold at a program node forms a (finite-dimensional) vector space [34]. This implies that a (possibly infinite) set of affine relations can be represented by any of its bases; each such basis is always a finite set. For reasoning about affine programs, M¨uller-Olm and Seidl defined an ab- straction that is able to find all affine relationships in an affine program: each statement is abstracted by a set of matrices of size (n + 1) × (n + 1). This set is the weakest-precondition transformer on affine relations for that statement: if a statement is abstracted as the set {m 1 , m 2 , · · · , mr}, then the affine relation a holds after the execution of the statement if and only if the affine relations (m 1 a), (m 2 a), · · · , (mr a) held before the execution of the statement. Under such an abstraction of program statements, one can define the ex- tend operation, which is transformer composition, as elementwise matrix mul- tiplication, and the combine operation as set union. This is correct semanti- cally, but it does not give an effective algorithm because the matrix sets can grow unboundedly. However, the observation that affine relations form a vec- tor space carries over to a set of matrices as well. One can show that the transformer {m 1 , m 2 , · · · , mr } is semantically equivalent to the transformer {m 1 , m 2 , · · · , mr , m}, where m is any linear combination of the mi matrices. Thus, a set of matrices can be abstracted as the (infinite) set of matrices spanned by them. Once we have a vector space, we can represent it using any of its bases to get a finite and bounded representation: a vector space over matrices of size (n + 1) × (n + 1) cannot have more that (n + 1)^2 matrices in any basis. If M is a set of matrices, let Span(M ) be the vector space spanned by them. Let β be the basis operation that takes a set of matrices and returns a basis of their span. We can now define the weight domain. A weight w is a vector space of matrices, which can be represented using its basis. Extend of vector spaces
w 1 and w 2 is the vector space {(m 1 m 2 ) | mi ∈ wi}. Combine of w 1 and w 2 is the vector space {(m 1 + m 2 ) | mi ∈ wi}, which is the smallest vector space containing both w 1 and w 2. 0 is the empty set, and 1 is the span of the singleton set consisting of the identity matrix. The extend and combine operations, as defined above, are operations on infinite sets. They can be implemented by the corresponding operations on any basis of the weights. The following properties show that it is semantically correct to operate on the elements in the basis instead of all the elements in the vector space spanned by them:
β(w 1 ⊕ w 2 ) = β(β(w 1 ) ⊕ β(w 2 )) β(w 1 ⊗ w 2 ) = β(β(w 1 ) ⊗ β(w 2 ))
These properties are satisfied because of the linearity of extend (matrix multi- plication distributes over addition) and combine operations. Under such a weight domain, MOVP(S, T ) is a weight that is the net weakest- precondition transformer between S and T. Suppose that this weight has the ba- sis {m 1 , · · · , mr }. The affine relation that indicates that any variable valuation might hold at S is 0 = (0, 0 , · · · , 0). Thus, 0 holds at S, and the affine relation a holds at T iff m 1 a = m 2 a = · · · = mra = 0. The set of all affine relations that hold at T can be found as the intersection of the null spaces of the matrices m 1 , m 2 , · · · , mr.
Extensions to ARA. ARA can also be performed for modular arithmetic [35] to precisely model machine arithmetic (which is modulo 2 to the power of the word size). The weight domain is similar to the one described above.
3.3 Solving for the MOVP Value
There are two algorithms for solving for MOVP values, called prestar and poststar (by analogy with the algorithms for PDSs). They take as input an automaton that accepts the set of initial configurations. As output, they produce a weighted automaton:
Definition 11. Given a weighted pushdown system W = (P, S, f ), a W- automaton A is a P-automaton, where each transition in the automaton is labeled with a weight. The weight of a path in the automaton is obtained by tak- ing an extend of the weights on the transitions in the path in either a forward or backward direction. The automaton is said to accept a configuration c = 〈p, u〉 with weight w = A(c) if w is the combine of weights of all accepting paths for u starting from state p in A. We call the automaton a backward W-automaton if the weight of a path is read backwards, and a forward W-automaton other- wise.
Let A be an unweighted automaton and L(A) be the set of configurations accepted by it. Then, prestar(A) produces a forward weighted automaton Apre∗ as output, such that Apre∗ (c) = MOVP({c}, L(A)), whereas poststar(A) pro- duces a backward weighted automaton Apost∗^ as output, such that Apost∗^ (c) =
weight domains, such as M in Defn. 8, have no such finite upper bound on the height; however, WPDSs can still be used when the height is unbounded. The absence of infinite descending chains (Defn. 4, item 4) ensures that saturation- based algorithms for computing post∗^ and pre∗^ will eventually terminate.
Lemma 1. [42] Given a WPDS with PDS P = (P, Γ, ∆), if A = (Q, Γ, → , P, F ) is a P-automaton that accepts an input set of configurations, poststar produces a backward weighted automaton with at most |Q| + |∆| states in time Os(|P ||∆|(|Q 0 | + |∆|)H + |P ||λ 0 |H), where Q 0 = Q\P , λ 0 ⊆→ is the set of all transitions leading from states in Q 0 , and H is the height of the weight domain.
Approximate Analysis. Among the properties imposed by a weight domain, one important property is distributivity (Defn. 4, item 2). This is a common re- quirement for a precise analysis, which also arises in various coincidence theorems for dataflow analysis [22, 47, 26]. Sometimes this requirement is too strict and may be relaxed to monotonicity, i.e., for all a, b, c ∈ D, a⊗(b⊕c) v (a⊗b)⊕(a⊗c) and (a ⊕ b) ⊗ c v (a ⊗ c) ⊕ (b ⊗ c). In such cases, the MOVP computation may not be precise, but it will be safe under the partial order v.
3.4 Local Variables and Extended Weighted Pushdown Systems
This section discusses an extension of WPDSs that permits abstractions to track the values of local variables [30]. In WPDSs, reachability problems compute the value of a rule sequence by taking an extend of the weights of each of the rules in the sequence; when WPDSs are used for dataflow analysis of a program, rule sequences represent interpro- cedural paths in the program. To summarize the weights of such paths, we have to maintain information about local variables of all unfinished procedures that appear on the path. Extended WPDSs (EWPDSs) lift WPDSs to handle local variables in much the same way that Knoop and Steffen lifted conventional dataflow-analysis al- gorithms to handle local variables [26]: at a call site at which procedure P calls procedure Q, the local variables of P are modeled as if the current incarnations of P ’s locals are stored in locations that are inaccessible to Q and to procedures transitively called by Q—consequently, the contents of P ’s locals cannot be af- fected by the call to Q; we use special merging functions to combine them with the value returned by Q to create the state after Q returns.^3 For a semiring S on domain D, a merging function is defined as follows: (^3) Note that this model agrees with programming languages like Java, where it is not possible to have pointers to local variables (i.e., pointers into the stack). For languages such as C and C++, where the address-of operator (&) allows the address of a local variable to be obtained, if P passes such an address to Q, it is possible for Q (or a procedure transitively called from Q) to affect a local of P by making an indirect assignment through the address. Conventional interprocedural dataflow-analysis algorithms must also worry about this issue, which is usually dealt with by (i) performing a preliminary analysis to
Definition 12. A function g : D × D → D is a merging function with respect to a bounded idempotent semiring S = (D, ⊕, ⊗, 0 , 1) if it satisfies the following properties.
Definition 13. Let (P, S, f ) be a weighted pushdown system; let G be the set of all merging functions on semiring S, and let ∆ 2 denote the set of push rules of P. An extended weighted pushdown system is a quadruple We = (P, S, f, g) where g : ∆ 2 → G assigns a merging function to each rule in ∆ 2.
Note that a push rule has both a weight and a merging function associated with it. Merging functions are used to fuse the local state of the calling procedure as it existed just before the call with the effects on the global state produced by the called procedure. As an example, Fig. 2 shows an ICFG and the PDS that represents it. We can perform constant propagation (with uninterpreted expressions) by assigning a weight to each PDS rule. The weight semiring is S = (D, ⊕, ⊗, 0 , 1), where D = (Env → Env) is the set of all environment transformers, and the semiring operations and constants are defined as follows:
0 = λe.> 1 = λe.e
w 1 ⊕ w 2 = λe.(w 1 (e) u w 2 (e)) w 1 ⊗ w 2 = w 2 ◦ w 1 The weights for the EWPDS that models the program in Fig. 2 are shown as edge labels. The merging function for the rule 〈p, n 3 〉 ↪→ 〈p, ef n 4 〉, which encodes the call at n 3 , receives two environment transformers: one that summarizes the effect of the caller from its enter node to the call site (emain to n 3 ) and one that summarizes the effect of the called procedure (ef to xf). The merging function has to produce the transformer that summarizes the effect of the caller from its enter node to the return site (emain to n 4 ). The merging function is defined as follows:
g(w 1 , w 2 ) = if (w 1 = 0 or w 2 = 0) then 0 else λe.e[a 7 → w 1 (e)(a), y 7 → (w 1 ⊗ w 2 )(e)(y)]
This copies over the value of the local variable a from the call site, and gets the value of y that is returned from the called procedure. Because the merging function has access to the environment transformer just before the call, we do not have to pass the value of local variable a into procedure p. Hence the call stops tracking the value of a using the weight λe.e[a 7 → ⊥, b 7 → e(a)]. The merging function for the rule 〈p, n 7 〉 ↪→ 〈p, ef n 8 〉 is defined similarly. determine which call sites might have such effects, and (ii) using the results of the preliminary analysis to create sound transformers for the primary analysis. The pre- liminary analysis is itself an interprocedural dataflow analysis, and (E)WPDSs can be applied to this problem as well. §4 describes how one such preliminary analysis—alias analysis for single-level pointers [32]—can be expressed as a reachability problem in an EWPDS.