Skip to content

Commit 9a4bf75

Browse files
committed
Shared: Add more detailed documentation for immediatelyControls
1 parent f7e9049 commit 9a4bf75

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

shared/controlflow/codeql/controlflow/BasicBlock.qll

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,25 @@ module Make<LocationSig Location, InputSig<Location> Input> {
162162

163163
/**
164164
* Holds if basic block `succ` is immediately controlled by this basic
165-
* block with conditional value `s`. That is, `succ` is an immediate
166-
* successor of this block, and `succ` can only be reached from
167-
* the callable entry point by going via the `s` edge out of this basic block.
165+
* block with successor type `s`. That is, `succ` is an immediate successor
166+
* of this block, and `succ` can only be reached from the entry block by
167+
* going via the `s` edge out of this basic block.
168+
*
169+
* The above implies that this block immediately dominates `succ`. But
170+
* "controls" is a stronger notion than "dominates". It is not the case
171+
* that any immediate successor that is immediately dominated by this block
172+
* is also immediately controlled by this block. To see why, consider this
173+
* example corresponding to an `if`-statement without an `else` block:
174+
* ```
175+
* ... --> cond --[true]--> ... --> if stmt
176+
* \ /
177+
* ----[false]-----------
178+
* ```
179+
* The basic block for `cond` immediately dominates the immediately
180+
* succeeding basic block for the `if` statement. But the `if` statement
181+
* is not immediately controlled by the `cond` basic block and the `false`
182+
* edge since it is also possible to reach the `if` statement via a path
183+
* through the `true` edge.
168184
*/
169185
pragma[nomagic]
170186
predicate immediatelyControls(BasicBlock succ, SuccessorType s) {
@@ -176,8 +192,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
176192

177193
/**
178194
* Holds if basic block `controlled` is controlled by this basic block with
179-
* conditional value `s`. That is, `controlled` can only be reached from
180-
* the callable entry point by going via the `s` edge out of this basic block.
195+
* successor type `s`. That is, `controlled` can only be reached from the
196+
* entry point by going via the `s` edge out of this basic block.
181197
*/
182198
predicate controls(BasicBlock controlled, SuccessorType s) {
183199
// For this block to control the block `controlled` with `s` the following must be true:

0 commit comments

Comments
 (0)