@@ -20,51 +20,49 @@ class ConditionBlock extends BasicBlock {
2020 result = this .getConditionNode ( ) .getABranchSuccessor ( testIsTrue )
2121 }
2222
23+ /*
24+ * For this block to control the block `controlled` with `testIsTrue` the following must be true:
25+ * Execution must have passed through the test i.e. `this` must strictly dominate `controlled`.
26+ * Execution must have passed through the `testIsTrue` edge leaving `this`.
27+ *
28+ * Although "passed through the true edge" implies that `this.getATrueSuccessor()` dominates `controlled`,
29+ * the reverse is not true, as flow may have passed through another edge to get to `this.getATrueSuccessor()`
30+ * so we need to assert that `this.getATrueSuccessor()` dominates `controlled` *and* that
31+ * all predecessors of `this.getATrueSuccessor()` are either `this` or dominated by `this.getATrueSuccessor()`.
32+ *
33+ * For example, in the following java snippet:
34+ * ```
35+ * if (x)
36+ * controlled;
37+ * false_successor;
38+ * uncontrolled;
39+ * ```
40+ * `false_successor` dominates `uncontrolled`, but not all of its predecessors are `this` (`if (x)`)
41+ * or dominated by itself. Whereas in the following code:
42+ * ```
43+ * if (x)
44+ * while (controlled)
45+ * also_controlled;
46+ * false_successor;
47+ * uncontrolled;
48+ * ```
49+ * the block `while controlled` is controlled because all of its predecessors are `this` (`if (x)`)
50+ * or (in the case of `also_controlled`) dominated by itself.
51+ *
52+ * The additional constraint on the predecessors of the test successor implies
53+ * that `this` strictly dominates `controlled` so that isn't necessary to check
54+ * directly.
55+ */
56+
2357 /**
2458 * Holds if `controlled` is a basic block controlled by this condition, that
2559 * is, a basic blocks for which the condition is `testIsTrue`.
2660 */
2761 predicate controls ( BasicBlock controlled , boolean testIsTrue ) {
28- /*
29- * For this block to control the block `controlled` with `testIsTrue` the following must be true:
30- * Execution must have passed through the test i.e. `this` must strictly dominate `controlled`.
31- * Execution must have passed through the `testIsTrue` edge leaving `this`.
32- *
33- * Although "passed through the true edge" implies that `this.getATrueSuccessor()` dominates `controlled`,
34- * the reverse is not true, as flow may have passed through another edge to get to `this.getATrueSuccessor()`
35- * so we need to assert that `this.getATrueSuccessor()` dominates `controlled` *and* that
36- * all predecessors of `this.getATrueSuccessor()` are either `this` or dominated by `this.getATrueSuccessor()`.
37- *
38- * For example, in the following java snippet:
39- * ```
40- * if (x)
41- * controlled;
42- * false_successor;
43- * uncontrolled;
44- * ```
45- * `false_successor` dominates `uncontrolled`, but not all of its predecessors are `this` (`if (x)`)
46- * or dominated by itself. Whereas in the following code:
47- * ```
48- * if (x)
49- * while (controlled)
50- * also_controlled;
51- * false_successor;
52- * uncontrolled;
53- * ```
54- * the block `while controlled` is controlled because all of its predecessors are `this` (`if (x)`)
55- * or (in the case of `also_controlled`) dominated by itself.
56- *
57- * The additional constraint on the predecessors of the test successor implies
58- * that `this` strictly dominates `controlled` so that isn't necessary to check
59- * directly.
60- */
61-
6262 exists ( BasicBlock succ |
6363 succ = this .getTestSuccessor ( testIsTrue ) and
64- succ .bbDominates ( controlled ) and
65- forall ( BasicBlock pred | pred = succ .getABBPredecessor ( ) and pred != this |
66- succ .bbDominates ( pred )
67- )
64+ dominatingEdge ( this , succ ) and
65+ succ .bbDominates ( controlled )
6866 )
6967 }
7068}
@@ -183,10 +181,8 @@ private predicate preconditionBranchEdge(
183181private predicate preconditionControls ( MethodAccess ma , BasicBlock controlled , boolean branch ) {
184182 exists ( BasicBlock check , BasicBlock succ |
185183 preconditionBranchEdge ( ma , check , succ , branch ) and
186- succ .bbDominates ( controlled ) and
187- forall ( BasicBlock pred | pred = succ .getABBPredecessor ( ) and pred != check |
188- succ .bbDominates ( pred )
189- )
184+ dominatingEdge ( check , succ ) and
185+ succ .bbDominates ( controlled )
190186 )
191187}
192188
0 commit comments