Skip to content

Commit c516d1f

Browse files
committed
python: forward rather implement subtle predicates
1 parent c11b491 commit c516d1f

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

  • python/ql/lib/semmle/python/controlflow/internal

python/ql/lib/semmle/python/controlflow/internal/Cfg.qll

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,7 @@ class BasicBlock extends CfgImpl::BasicBlock {
280280
* doesn't currently expose a `dominanceFrontier` predicate at this
281281
* level.
282282
*/
283-
predicate inDominanceFrontier(BasicBlock df) {
284-
this = df.getAPredecessor() and not this = df.getImmediateDominator()
285-
or
286-
exists(BasicBlock prev | prev.inDominanceFrontier(df) |
287-
this = prev.getImmediateDominator() and
288-
not this = df.getImmediateDominator()
289-
)
290-
}
283+
predicate inDominanceFrontier(BasicBlock df) { super.inDominanceFrontier(df) }
291284

292285
/** Holds if this basic block strictly reaches `other`. */
293286
predicate strictlyReaches(BasicBlock other) { super.getASuccessor+() = other }
@@ -326,22 +319,7 @@ class BasicBlock extends CfgImpl::BasicBlock {
326319
* This mirrors the legacy `ConditionBlock.controls(BB, branch)`.
327320
*/
328321
predicate controls(BasicBlock other, boolean branch) {
329-
exists(BasicBlock succ |
330-
branch = true and succ = this.getATrueSuccessor()
331-
or
332-
branch = false and succ = this.getAFalseSuccessor()
333-
|
334-
succ.dominates(other) and
335-
// The other branch must not also reach `other` — otherwise
336-
// `other` is not actually controlled by `branch`.
337-
not exists(BasicBlock otherSucc |
338-
branch = true and otherSucc = this.getAFalseSuccessor()
339-
or
340-
branch = false and otherSucc = this.getATrueSuccessor()
341-
|
342-
otherSucc.reaches(other)
343-
)
344-
)
322+
super.edgeDominates(other, any(BooleanSuccessor t | t.getValue() = branch))
345323
}
346324
}
347325

0 commit comments

Comments
 (0)