Fast Computation of Arbitrary Control Dependencies

. In 2011, Danicic et al. introduced an elegant generalization of the notion of control dependence for any directed graph. They also proposed an algorithm computing the weak control-closure of a subset of graph vertices and performed a paper-and-pencil proof of its correctness. We have performed its proof in the Coq proof assistant. This paper also presents a novel, more eﬃcient algorithm to compute weak control-closure taking beneﬁt of intermediate propagation results of previous iterations in order to accelerate the following ones. This optimization makes the design and proof of the algorithm more complex and requires subtle loop invariants. The new algorithm has been formalized and mechanically proven in the Why3 veriﬁcation tool. Experiments on arbitrary generated graphs with up to thousands of vertices demonstrate that the proposed algorithm remains practical for real-life programs and signiﬁ-cantly outperforms Danicic’s initial technique.


Introduction
Context.Control dependence is a fundamental notion in software engineering and analysis (e.g.[6,12,13,21,22,27]).It reflects structural relationships between different program statements and is intensively used in many software analysis techniques and tools, such as compilers, verification tools, test generators, program transformation tools, simulators, debuggers, etc.Along with data dependence, it is one of the key notions used in program slicing [25,27], a program transformation technique allowing to decompose a given program into a simpler one, called a program slice.
In 2011, Danicic et al. [11] proposed an elegant generalization of the notions of closure under non-termination insensitive (weak ) and non-termination sensitive (strong) control dependence.They introduced the notions of weak and strong control-closures, that can be defined on any directed graph, and no longer only on control flow graphs.They proved that weak and strong control-closures subsume the closures under all forms of control dependence previously known in the literature.In the present paper, we are interested in the non-termination insensitive form, i.e. weak control-closure.

Contributions. The contributions of this paper include:
-A formalization of Danicic's algorithm and proof of its correctness in Coq; -A new algorithm computing weak control-closure and taking benefit from preserving some intermediary results between iterations; -A mechanized correctness proof of this new algorithm in the Why3 tool including a formalization of the basic concepts and results of Danicic et al.; -An implementation of Danicic's and our algorithms in OCaml, their evaluation on random graphs and a comparison of their execution times.
The Coq, Why3 and OCaml implementations are all available in [17].
Outline.We present our motivation and a running example in Sect. 2.Then, we recall the definitions of some important concepts introduced by [11] in Sect. 3 and state two important lemmas in Sect. 4. Next, we describe Danicic's algorithm in Sect. 5 and our algorithm along with a sketch of the proof of its correctness in Sect.6.Experiments are presented in Sect.7. Finally, Sect.8 presents some related work and concludes.

Motivation and Running Example
This section informally presents weak control-closure using a running example.
The inputs of our problem are a directed graph G = (V, E) with set of vertices (or nodes) V and set of edges E, and a subset of vertices V ⊆ V .The property of interest of such a subset is called weakly control-closed in [11] (cf. Definition 3).V is said to be weakly control-closed if the nodes reachable from V are V -weakly committing (cf.Definition 2), i.e. always lead the flow to at most one node in V .Since V does not necessarily satisfy this property, we want to build a superset of V satisfying it, and more particularly the smallest one, called the weak control-closure of V in G (cf. Definition 5).For that, as it will be proved by Lemma 2, we need to add to V the points of divergence closest to V , called the V -weakly deciding vertices, that are reachable from V .Formally, vertex u is V -weakly deciding if there exist two non-trivial paths starting from u and reaching V that have no common vertex except u (cf.Definition 4).
Let us illustrate these ideas on an example graph G 0 shown in Fig. 1.V 0 = {u 1 , u 3 } is the subset of interest represented with dashed double circles ( u i ) in Fig. 1. u 5 is reachable from V 0 and is not V 0 -weakly committing, since it is the origin of two paths u 5 , u 6 , u 0 , u 1 and u 5 , u 6 , u 0 , u 2 , u 3 that can lead the flow to two different nodes u 1 and u 3 in V 0 .Therefore, V 0 is not weakly control-closed.To build the weak control-closure, we need to add to V 0 all V 0 -weakly deciding nodes reachable from V 0 .u 0 is such a node.Indeed, it is reachable from V 0 and we can build two non-trivial paths u 0 , u 1 and u 0 , u 2 , u 3 starting from u 0 , ending in V 0 (respectively in u 1 and u 3 ) and sharing no other vertex than u 0 .Similarly, nodes u 2 , u 4 and u 6 must be added as well.On the contrary, u 5 must not be added, since every non-empty path starting from u 5 has u 6 as second vertex.More generally, a node with only one child cannot be a "divergence point closest to V " and must never be added to build the weak control-closure.The weak control-closure of V 0 in G 0 is thus {u 0 , u 1 , u 2 , u 3 , u 4 , u 6 }.
To build the closure, Danicic's algorithm, like the one we propose, does not directly try to build the two paths sharing only one node.Both algorithms rely on a concept called observable vertex.Given a vertex u ∈ V , the set of observable vertices in V from u contains all nodes reachable from u in V without using edges starting in V .The important property about this object is that, as it will be proved by Lemma 4, if there exists an edge (u, v) ∈ E such that u is not in V , u is reachable from V , v can reach V and there exists a vertex w Fig. 2. Example graph G0 annotated with observable sets observable from u but not from v, then u must be added to V to build the weak control-closure.Figure 2a shows our example graph G 0 , each node being annotated with its set of observables in V 0 .
(u 0 , u 1 ) is an edge such that u 0 is reachable from V 0 , u 1 can reach V 0 and u 3 is an observable vertex from u 0 in V 0 but not from u 1 .u 0 is thus a node to be added in the weak control-closure.Likewise, from the edges (u 2 , u 3 ) and (u 4 , u 3 ), we can deduce that u 2 and u 4 belong to the closure.However, we have seen that u 6 belongs to the closure, but it is not possible to apply the same reasoning to (u 6 , u 0 ), (u 6 , u 4 ) or (u 6 , u 5 ).We need another technique.As Lemma 3 will establish, the technique is actually iterative.We can add to the initial V 0 the nodes that we have already detected and apply our technique to this new set V 0 .The vertices that will be detected this way will also be in the closure of the initial set V 0 .The observable sets w.r.t. to V 0 = V 0 ∪ {u 0 , u 2 , u 4 } are shown in Fig. 2b.This time, both edges (u 6 , u 4 ) and (u 6 , u 0 ) allow us to add u 6 to the closure.Applying again the technique with the augmented set V 0 = V 0 ∪ {u 6 } (cf.Fig. 2c) does not reveal new vertices.This means that all the nodes have already been found.We obtain the same set as before for the weak control-closure of V 0 , i.e. {u 0 , u 1 , u 2 , u 3 , u 4 , u 6 }.

Basic Concepts
This section introduces basic definitions and properties needed to define the notion of weak control-closure.They have been formalized in Coq [17], including in particular Property 3 whose proof in [11] was inaccurate.
From now on, let G = (V, E) denote a directed graph, and V a subset of V .We define a path in G in the usual way.We write v} be the set of nodes reachable from V .In our example (cf.Fig. 1), u 6 , u 0 , u 1 , u 3 is a (4-node) path in G 0 , u 1 is a trivial one-node path in G 0 from u 1 to itself, and Example.In G 0 , u 3 ; u 2 , u 3 ; u 0 , u 1 ; u 0 , u 2 , u 3 are V 0 -paths and thus V 0 -disjoint paths.u 6 , u 0 is a V 0 -disjoint path but not a V 0 -path.
Remark 1. Definition 1 and the following ones are slightly different from [11], where a V -path must contain at least two vertices and there is no constraint on its first vertex, which can be in V or not.Our definitions lead to the same notion of weak control-closure.

Definition 2 (V -weakly committing vertex).
A vertex u in G is V -weakly committing if all the V -paths from u have the same end point (in V ).In particular, any vertex u ∈ V is V -weakly committing.
Example.In G 0 , u 1 and u 3 are the only V 0 -weakly committing nodes.

Definition 3 (Weakly control-closed set
Example.Since in particular u 2 is not V 0 -weakly committing and reachable from V 0 , V 0 is not weakly control-closed in G 0 .∅, singletons and the set of all nodes V 0 are trivially weakly control-closed.Less trivial weakly control-closed sets include {u 0 , u 1 }, {u 4 , u 5 , u 6 } and {u 0 , u 1 , u 2 , u 3 , u 4 , u 6 }.
Definition 3 characterizes a weakly control-closed set, but does not explain how to build one.It would be particularly interesting to build the smallest weakly control-closed set containing a given set V .The notion of weakly deciding vertex will help us to give an explicit expression to that set.

Definition 4 (V -weakly deciding vertex).
A vertex u is V -weakly deciding if there exist at least two non-trivial V -paths from u that share no vertex except u.Let WD G (V ) denote the set of V -weakly deciding vertices in G. Definitions 1,4).

Lemma 1 (Characterization of being weakly control-closed). V is weakly control-closed in G if and only if there is no V -weakly deciding vertex in
Example.In G 0 , u 2 is reachable from V 0 and is V 0 -weakly deciding.This gives another proof that V 0 is not weakly control-closed.
Here are two other useful properties of WD G .
We can prove that adding to a given set V the V -weakly deciding nodes that are reachable from V gives a weakly control-closed set in G.This set is the smallest superset of V weakly control-closed in G.

Main Lemmas
This section gives two lemmas used to justify both Danicic's algorithm and ours.
from the previous result by intersecting with R G (V ) by Property 4a.
Lemma 3 allows to design iterative algorithms to compute the closure.Indeed, assume that we have a procedure which, for any non-weakly control-closed set V , can return one or more elements of the weak control-closure of V not in V .If we apply such a procedure to V once, we get a set W that satisfies To compute the weak control-closure of V , it is thus sufficient to build the weak controlclosure of W .We can apply our procedure again, this time to W , and repetitively on all the successively computed sets.Since each set is a strict superset of the previous one, this iterative procedure terminates because graph G is finite.
Before stating the second lemma, we introduce a key concept.It is called Θ in [11].We use the name "observable" as in [26].
The concept of observable set was illustrated in Fig. 2 (cf.Sect.2).

Lemma 4 (Sufficient condition for being V -weakly deciding). Let (u, v) be an edge in
Proof.We need to exhibit two V -paths from u ending in V that share no vertex except u.We take the V -path from u to u as the first one, and a V -path connecting u to V through v as the second one (we construct it by prepending u to the smallest prefix of the path from v ending in V which is a V -path).If these V -paths intersected at a node y different from u, we would have a V -path from v to u by concatenating the paths from v to y and from y to u , which is contradictory.2a).Since u 1 is a child of u 0 , we can apply Lemma 4, and deduce that u 0 is V 0 -weakly deciding.obs G0 (u 5 , V 0 ) = {u 1 , u 3 } and obs G0 (u 6 , V 0 ) = {u 1 , u 3 }.We cannot apply Lemma 4 to u 5 , and for good reason, since u 5 is not V 0 -weakly deciding.But we cannot apply Lemma 4 to u 6 either, since u 6 and all its children u 0 , u 4 and u 5 have observable sets {u 1 , u 3 } w.r.t.V 0 , while u 6 is V 0 -weakly deciding.This shows that with Lemma 4, we have a sufficient condition, but not a necessary one, for proving that a vertex is weakly deciding.

Danicic's Algorithm
We present here the algorithm described in [11].This algorithm and a proof of its correctness have been formalized in Coq [17].The algorithm is nearly completely justified by a following lemma (Lemma 5, equivalent to [11,Lemma 60]).
We first need to introduce a new concept, which captures edges that are of particular interest when searching for weakly deciding vertices.This concept is taken from [11], where it was not given a name.We call such edges critical edges.
Let u be the last vertex on π with at least two observable nodes in V and v its successor on π.Then (u, v) is a V -critical edge.
Assume there exists a V -critical edge (u, v).
Remark 3. We can see in the proof above that we do not need the exact values 2 and 1.We just need strictly more observable vertices for u than for v and at least one observable for v, to satisfy the hypotheses of Lemma 4.
As described in Sect.4, we can build an iterative algorithm constructing the weak control-closure of V by searching for critical edges on the intermediate sets built successively.This is the idea of Danicic's algorithm shown as Algorithm 1.
Proof of Algorithm 1.To establish the correction of the algorithm, we can prove that W i , the value of W before iteration i + 1, satisfies both V ⊆ W i and W i ⊆ WCC G (V ) for any i by induction.If i = 0, W 0 = V , and both relations trivially hold.Let i be a natural number such that V ⊆ W i , W i ⊆ WCC G (V ) and there exists a W i -critical edge (u, v).We have W i+1 = W i ∪ {u}.V ⊆ W i+1 is straightforward.By Lemma 5, u ∈ WCC G (W i ).Therefore, by Lemma 3, u ∈ WCC G (V ), and thus, W i+1 ⊆ WCC G (V ).At the end of the algorithm, there is no W -critical edge, therefore W is weakly control-closed by Lemma 5. Since V ⊆ W and W ⊆ WCC G (V ), W = WCC G (V ) by Lemma 3. Termination follows from the fact that W strictly increases in the loop and is upper-bounded by WCC G (V ).
In terms of complexity, [11] shows that, assuming that the degree of each vertex is at most -at each step, consider all critical edges rather than only one; -use the weaker definition of critical edge suggested in Remark 3.
Example.We can replay Algorithm 1 using the first optimization.This run corresponds to the steps shown in Fig. 2. Initially, The optimized version computes the weak control-closure of V 0 in G 0 in only 2 iterations instead of 4. This run also demonstrates that the algorithm is necessarily iterative: even when considering all V 0 -critical edges in the first step, u 6 is not detected before the second step.

The Optimized Algorithm
Overview.A potential source of inefficiency in Danicic's algorithm is the fact that no information is shared between the iterations.The observable sets are recomputed at each iteration since the target set changes.This is the reason why the first optimization proposed in Remark 4 is interesting, because it allows to work longer on the same set and thus to reuse the observable sets.
We propose now to go even further: to store some information about the paths in the graph and reuse it in the following iterations.The main idea of the proposed algorithm is to label each processed node u with a node v ∈ W observable from u in the resulting set W being progressively constructed by the algorithm.Labels survive through iterations and can be reused.Unlike Danicic's algorithm, ours does not directly compute the weak controlclosure.It actually computes the set W = V ∪ WD G (V ).To obtain the closure , W is then simply filtered to keep only vertices reachable from V (cf.Property 4a).
In addition to speeding up the algorithm, the usage of labels brings another benefit: for each node of G, its label indicates its observable vertex in W (when it exists) at the end of the algorithm.Recall that since WD G (W ) = ∅ (by Property 3), each node in the graph has at most one observable vertex in W .
One difficult point with this approach is that the labels of the nodes need to be refreshed with care at each iteration so that they remain up-to-date.Actually, our algorithm does not ensure that at each iteration the label of each node is an observable vertex from this node in W .This state is only ensured at the beginning and at the end of the algorithm.Meanwhile, some nodes are still in the worklist and some labels are wrong, but this does not prevent the algorithm from working.
Informal Description.Our algorithm is given a directed graph G and a subset of vertices V in G.It manipulates three objects: a set W which is equal to V initially, which grows during the algorithm and which at the end contains the result, V ∪ WD G (V ); a partial mapping obs associating at most one label obs [u] to each node u in the graph, this label being a vertex in W reachable from this node (and which is the observable from u in V ∪WD G (V ) at the end); a worklist L of nodes of the closure not processed yet.Each iteration proceeds as follows.If the worklist is not empty, a vertex u is extracted from it.All the vertices that transitively precede vertex u in the graph and that are not hidden by vertices in W are labeled with u.During the propagation, nodes that are good candidates to be V -weakly deciding are accumulated.After the propagation, we filter them so that only true V -weakly deciding nodes are kept.Each of these vertices is associated to itself in obs, and is added to W and L. If L is not empty, a new iteration begins.Otherwise, W is equal to V ∪WD G (V ) and obs associates each node in the graph with its observable vertex in the closure (when it exists).
Note that each iteration consists in two steps: a complete backward propagation in the graph, which collects potential V -weakly deciding vertices, and a filtering step.The set of predecessors of the propagated node are thus filtered twice: once during the propagation and once afterwards.We can try to filter as much as possible in the first step or, at the opposite, to avoid filtering during the first step and do all the work in the second step.For the sake of simplicity of mechanized proof, the version we chose does only simple filtering during the first step.We accumulate in our candidate V -weakly deciding nodes all nodes that have at least two children and a label different from the one currently propagated, and we eliminate the false positives in the second step, once the propagation is done.
Example.Let us use our running example (cf.Fig. 1) to illustrate the algorithm.The successive steps are represented in Fig. 3.In the different figures, nodes in W already processed (that is, in W \L) are represented using a solid double circle ( u i ), while nodes in W not already processed (that is, still in worklist L) are represented using a dashed double circle ( u i ).A label u j next to a node u i ( u i u j ) means that u j is associated to u i , i.e. obs[u i ] = u j .Let us detail the first steps of the algorithm.Initially, W 0 = V 0 = {u 1 , u 3 } (cf.Fig. 1).
1. u 1 is selected and is propagated backwards from u 1 (cf.Fig. 3a).We find no candidate, the first iteration is finished, W 1 = {u 1 , u 3 }.2. u 3 is selected and is propagated backwards from u 3 (cf.Fig. 3b).u 0 , u 2 , u 4 and u 6 are candidates, but only u 0 is confirmed as a V 0 -weakly deciding node.It is stored in worklist L and its label is set to u 0 .Now W 2 = {u 0 , u 1 , u 3 }.3-6.u 0 , u 2 , u 4 and u 6 are processed similarly (cf.Fig. 3c, d, e, f).At the end, we get As all nodes in W 6 are already reachable from V 0 , W 6 = WCC G (V 0 ).We can make two remarks on this example.First, as we can see in Fig. 3f, each node is labeled with its observable in W at the end of the algorithm.Second, in Fig. 3e, we have the case of a node labeled with an obsolete label, since u 5 is labeled u 4 while its only observable node in W is u 6 .

Detailed Description. Our algorithm is split into three functions:
confirm is used to check if a given node is V -weakly deciding by trying to find a child with a different label from its own label given as an argument.
propagate takes a vertex and propagates backwards a label over its predecessors.It returns a set of candidate V -weakly-deciding nodes.-main calls propagate on a node of the closure not yet processed, gets candidate V -weakly deciding nodes, calls confirm to keep only true V -weakly deciding nodes, adds them to the closure and updates their labels, and loops until no more V -weakly deciding nodes are found.
Function Confirm.A call to confirm(G, obs, u, v) takes four arguments: a graph G, a labeling of graph vertices obs, and two vertices u and v.It returns true if and only if at least one child u of u in G has a label in obs different from v, which can be written u ∈ obs ∧ obs[u ] = v.This simple function is left abstract here for lack of space.The Why3 formalization [17] contains a complete proof.Its contract is given as Algorithm 2. Function Propagate.A call to propagate(G, W, obs, u, v) takes five arguments: a graph G, a subset W of nodes of G, a labeling of nodes obs, and two vertices u and v.It traverses G backwards from u (stopping at nodes in W ) and updates obs so that all predecessors not hidden by vertices in W have label v at the end of the function.It returns a set of potential V -weakly deciding vertices.Again, this function is left abstract here but is proved in the Why3 development [17].Its contract is given as Algorithm 3.
propagate requires that, when called, only u is labeled with v (P 1 ) and that u ∈ W (P 2 ).It ensures that, after the call, all the predecessors of u not hidden by a vertex in W are labeled v (Q 1 ), the labels of the other nodes are unchanged (Q 2 ), C contains only predecessors of u but not u itself (Q 3 ), and all the predecessors that had a label before the call (different from v due to P 1 ) and that have at least two children are in C (Q 4 ).
Proof of the Optimized Algorithm.We opted for Why3 instead of Coq for this proof to take advantage of Why3's automation.Indeed, most of the goals could be discharged in less than a minute using Alt-Ergo, CVC4, Z3 and E. Some of them still needed to be proved manually in Coq, resulting in 330 lines of Coq proof.The Why3 development [17] focuses on the proof of the algorithm, not on the concepts presented in Sects.3 and 4. Most of the concepts are proved, one of them is assumed in Why3 but was proved in Coq previously.Due to lack of space, we detail here only the main invariants necessary to prove main (cf.Algorithm 4).The proofs of I 1 , I 2 , I 3 , I 4 are rather simple.while those of I 5 and I 6 are more complex.
I 1 states that each node in W has itself as a label.It is true initially for all nodes in V and is preserved by the updates.
I 2 states that all labels are in W .This is true initially since all labels are in V .The preservation is verified, since all updates are realized using labels in W .
I 3 states that labels in L have not been already propagated.Given a node y in L, y is the only node whose label is y.It is true initially since every vertex in V has itself as a label.After an update, the new nodes obey the same rule, so I 3 is preserved.
I 4 states that if label z is associated to a node y then there exists a path between y and z.Initially, there exist trivial paths from each node in V to itself.When obs is updated, there exists a W -path, thus in particular a path.
I 5 states that W remains between V and V ∪WD G (V ) during the execution of the algorithm.The first part V ⊆ W is easy to prove, because it is true initially and W is growing.For the second part, we need to prove that after the filtering, Δ ⊆ WD G (V ).For that, we will prove that Δ ⊆ WD G (W ) thanks to Lemma 3. Let v be a node in Δ.Since Δ ⊆ C, we know that v ∈ W and u ∈ obs G (v, W ).Moreover, we have confirm(G, obs, v, u) = true, i.e. v has a child v such that v ∈ obs, hence v can reach W by I 4 , and obs[v ] = u, hence u ∈ obs G (v , W ). We can apply Lemma 4 and deduce that v ∈ WD G (W ).
I 6 is the most complicated invariant.I 6 states that if there is a path between two vertices y and z that does not intersect W , and z has a label already processed, then y and z have the same label.Let us give a sketch of the proof of preservation of I 6 after an iteration of the main loop.Let us note obs the map at the end of the iteration.Let y, z, z ∈ V such that y Let us show that obs [y] = z .First, observe that neither y nor z can be in Δ, otherwise z would be in Δ, which would be contradictory.We examine four cases depending on whether the conditions z -H 1 ∧ H 2 : Both z and y were given the label u during the last iteration, thus obs [z] = obs [y] = u as expected.
-H 1 ∧ (¬H 2 ): This case is impossible, since y ) ∧ (¬H 2 ): Both z and y have the same label as before the iteration.We can therefore conclude by I 6 at the beginning of the iteration.-(¬H 1 ) ∧ H 2 : This is the only complicated case.We show that it is contradictory.For that, we introduce v 1 as the last vertex on the (W ∪ Δ)-disjoint path connecting y and z which is also the origin of a W -path to u, and v 2 as its successor on this (W ∪ Δ)-disjoint path.We can show that v 1 ∈ Δ, which contradicts the fact that it lives on a (W ∪ Δ)-disjoint path.
We can now prove the assertions A 1 , A 2 , A 3 and A 4 at the end of main.A 1 is a direct consequence of I 6 since at the end L = ∅.A 1 implies that each vertex u has at most one observable in W : obs[u] if u ∈ obs.A W -weakly deciding vertex would have two observables, thus WD G (W ) = ∅.A 3 is a direct consequence of I 5 .A 4 can be deduced from A 2 and Lemma 3 applied to A 3 .This proves that at the end W = V ∪ WD G (V ).To prove the other post-condition, we must prove that if there are two nodes u, v such that obs[u] = v, then v ∈ obs G (u, W ). By I 4 , there is a path from u to v. Let w be the first element in W on this path.We have implemented Danicic's algorithm (additionally improved by the two optimizations proposed in Remark 4) and ours in OCaml [17] using the OCamlgraph library [9], taking care to add a filtering step at the end of our algorithm to preserve only nodes reachable from the initial subset.To be confident in their correctness, we have tested both implementations on small examples w.r.t. a certified but slow Coqextracted implementation as an oracle.
We have also carefully checked that the results returned by both implementations were the same in all experiments.
We have experimentally evaluated both implementations on thousands of random graphs with up to thousands of vertices, generated by OCamlgraph.For every number of vertices between 10 and 1000 (resp.6500) that is a multiple of 10, we generate 10 graphs with twice as many edges as vertices and randomly select three vertices to form the initial subset V and run both algorithms (resp.only our algorithm) on them.Although the initial subsets are small, the resulting closures nearly always represent a significant part of the set of vertices of the graph.To avoid the trivial case, we have discarded the examples where the closure is restricted to the initial subset itself (where execution time is insignificant), and computed the average time of the remaining tests.Results are presented in Fig. 4. Experiments have been performed on an Intel Core i7 4810MQ with 8 cores at 2.80 GHz and 16 GB RAM.
We observe that Danicic's algorithm explodes for a few hundreds of vertices, while our algorithm remains efficient for graphs with thousands of nodes.

Related Work and Conclusion
Related Work.The last decades have seen various definitions of control dependence given for larger and larger classes of programs [6,12,13,21,22,27].To consider programs with exceptions and potentially infinite loops, Ranganath et al. [23] and then Amtoft [2] introduced non-termination sensitive and nontermination insensitive control dependence on arbitrary program structures.Danicic et al. [11] further generalized control dependence to arbitrary directed graphs, by defining weak and strong control-closure, which subsume the previous non-termination insensitive and sensitive control dependence relations.They also gave a control dependence semantics in terms of projections of paths in the graph, allowing to define new control dependence relations as long as they are compatible with it.This elegant framework was reused for slicing extended finite state machines [3] and probabilistic programs [4].In both works, an algorithm computing weak control-closure, working differently from ours, was designed and integrated in a rather efficient slicing algorithm.
While there exist efficient algorithms to compute the dominator tree in a graph [8,10,16,19], and even certified ones [15], and thus efficient algorithms computing control dependence when defined in terms of post-dominance, algorithms in the general case [2,11,23] are at least cubic.
Mechanized verification of control dependence computation was done in formalizations of program slicing.Wasserrab [26] formalized language-independent slicing in Isabelle/HOL, but did not provide an algorithm.Blazy et al. [7] and our previous work [18] formalized control dependence in Coq, respectively, for an intermediate language of the CompCert C compiler [20] and on a WHILE language with possible errors.
Conclusion and Future Work.Danicic et al. claim that weak control-closure subsumes all other non-termination insensitive variants.It was thus a natural candidate for mechanized formalization.We used the Coq proof assistant to formalize it.A certified implementation of the algorithm can be extracted from the Coq development.During formalization in Coq of the algorithm and its proof, we have detected an inconsistency in a secondary proof, which highlights how useful proof assistants are to detect otherwise overlooked cases.To the best of our knowledge, the present work is the first mechanized formalization of weak control-closure and of an algorithm to compute it.In addition to formalizing Danicic's algorithm in Coq, we have designed, formalized and proved a new one, that is experimentally shown to be faster than the original one.Short-term future work includes considering further optimizations.Long-term future work is to build a verified generic slicer.Indeed, generic control dependence is a first step towards it.Adding data dependence is the next step in this direction.
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/),which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material.If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.

3 while 5 WAlgorithm 1 .
there exists a W -critical edge in E do 4 choose such a W -critical edge (u, v) Danicic's original algorithm for weak control-closure[11] 2 (and thus that O(|V |) = O(|E|)), the complexity of the algorithm is O(|V | 3 ).Indeed, the main loop of Algorithm 1 is run at most O(|V |) times, and each loop body computes obs in O(|V |) for at most O(|V |) edges.Remark 4. We propose two optimizations for Algorithm 1: