Skip to content

Commit 17ccb54

Browse files
committed
Shared: Elaborate qldoc.
1 parent 5e8432f commit 17ccb54

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

shared/controlflow/codeql/controlflow/Guards.qll

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,29 @@
2323
* }
2424
* ```
2525
*
26+
* The provided predicates are separated into general "controls" predicates and
27+
* "directly controls" predicates. The former use all possible implication
28+
* logic as described above, whereas the latter only use control flow dominance
29+
* of the corresponding conditional successor edges.
30+
*
31+
* In some cases, a guard may have a successor edge that can be relevant for
32+
* controlling the input to an SSA phi node, but does not dominate the
33+
* preceding block. To support this, the `hasBranchEdge` and
34+
* `controlsBranchEdge` predicates are provided, where the former only uses the
35+
* control flow graph similar to the `directlyControls` predicate, and the
36+
* latter uses the full implication logic.
37+
*
38+
* All of these predicates are also available in the more general form that refers
39+
* to `GuardValue`s instead of `boolean`s.
40+
*
2641
* The implementation is nested in two parameterized modules intended to
2742
* facilitate multiple instantiations of the nested module with different
28-
* precision levels
43+
* precision levels. For example, more implications are available if the result
44+
* of Range Analysis is available, but Range Analysis depends on Guards. This
45+
* allows an initial instantiation of the `Logic` module without Range Analysis
46+
* that can be used as input to Range Analysis, and a second instantiation
47+
* using the result of Range Analysis to provide a final and more complete
48+
* controls relation.
2949
*/
3050

3151
private import codeql.util.Boolean
@@ -178,6 +198,7 @@ signature module InputSig<LocationSig Location> {
178198
}
179199
}
180200

201+
/** Provides guards-related predicates and classes. */
181202
module Make<LocationSig Location, InputSig<Location> Input> {
182203
private import Input
183204

@@ -513,6 +534,10 @@ module Make<LocationSig Location, InputSig<Location> Input> {
513534
}
514535
}
515536

537+
/**
538+
* Provides the `Guard` class with suitable 'controls' predicates augmented
539+
* with logical implications based on SSA.
540+
*/
516541
module Logic<LogicInputSig LogicInput> {
517542
private import LogicInput
518543

@@ -1016,7 +1041,8 @@ module Make<LocationSig Location, InputSig<Location> Input> {
10161041

10171042
/**
10181043
* A guard. This may be any expression whose value determines subsequent
1019-
* control flow.
1044+
* control flow. It may also be a switch case, which as a guard is considered
1045+
* to evaluate to either true or false depending on whether the case matches.
10201046
*/
10211047
final class Guard extends PreGuard {
10221048
/**

0 commit comments

Comments
 (0)