@@ -131,20 +131,27 @@ private predicate bbLoopEntryConditionAlwaysTrueAt(BasicBlock bb, int i, Control
131131}
132132
133133/**
134- * Basic block `pred` ends with a condition belonging to a loop, and that
135- * condition is provably true upon entry. Basic block `succ` is a successor
136- * of `pred`, and `skipsLoop` indicates whether `succ` is the false-successor
137- * of `pred`.
134+ * Basic block `pred` contains all or part of the condition belonging to a loop,
135+ * and there is an edge from `pred` to `succ` that concludes the condition.
136+ * If the edge corrseponds with the loop condition being found to be `true`, then
137+ * `skipsLoop` is `false`. Otherwise the edge corresponds with the loop condition
138+ * being found to be `false` and `skipsLoop` is `true`. Non-concluding edges
139+ * within a complex loop condition are not matched by this predicate.
138140 */
139141private predicate bbLoopConditionAlwaysTrueUponEntrySuccessor ( BasicBlock pred , BasicBlock succ , boolean skipsLoop ) {
140- succ = pred .getASuccessor ( ) and
141- exists ( ControlFlowNode last |
142- last = pred .getEnd ( ) and
143- loopConditionAlwaysTrueUponEntry ( _, last ) and
144- if succ = pred .getAFalseSuccessor ( ) then
145- skipsLoop = true
146- else
147- skipsLoop = false
142+ exists ( ControlFlowNode loop |
143+ loopConditionAlwaysTrueUponEntry ( loop , _) and
144+ (
145+ (
146+ succ = loop .( Loop ) .getFollowingStmt ( ) and
147+ pred .getAFalseSuccessor ( ) = succ and
148+ skipsLoop = true
149+ ) or (
150+ succ = loop .( Loop ) .getStmt ( ) and
151+ pred .getATrueSuccessor ( ) = succ and
152+ skipsLoop = false
153+ )
154+ )
148155 )
149156}
150157
@@ -176,7 +183,7 @@ predicate bbSuccessorEntryReachesLoopInvariant(BasicBlock pred, BasicBlock succ,
176183 // The edge from `pred` to `succ` is _not_ from a loop condition provably
177184 // true upon entry, so the values of `predSkipsFirstLoopAlwaysTrueUponEntry`
178185 // and `succSkipsFirstLoopAlwaysTrueUponEntry` must be the same.
179- not bbLoopConditionAlwaysTrueUponEntrySuccessor ( pred , _ , _) and
186+ not bbLoopConditionAlwaysTrueUponEntrySuccessor ( pred , succ , _) and
180187 succSkipsFirstLoopAlwaysTrueUponEntry = predSkipsFirstLoopAlwaysTrueUponEntry and
181188 // Moreover, if `pred` contains the entry point of a loop where the
182189 // condition is provably true upon entry, then `succ` is not allowed
0 commit comments