File tree Expand file tree Collapse file tree
go/ql/lib/semmle/go/controlflow Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,22 @@ module IR {
5858 n .isAfterValue ( cc , any ( MatchingSuccessor t | t .isMatch ( ) ) )
5959 }
6060
61+ /**
62+ * Holds if `n` is a genuine boolean condition-guard node: an "after" node
63+ * that records exactly one of the true/false outcomes of a boolean
64+ * condition.
65+ *
66+ * The shared CFG library's `isAfterTrue`/`isAfterFalse` are deliberately
67+ * permissive when used for step-endpoint matching: a plain "after" node (or
68+ * a merged leaf node) satisfies both of them. A real guard node is
69+ * distinguished by satisfying exactly one of them.
70+ */
71+ private predicate isConditionGuardNode ( ControlFlow:: Node n ) {
72+ n .isAfterTrue ( _) and not n .isAfterFalse ( _)
73+ or
74+ n .isAfterFalse ( _) and not n .isAfterTrue ( _)
75+ }
76+
6177 /**
6278 * An IR instruction.
6379 */
@@ -67,9 +83,7 @@ module IR {
6783 or
6884 this .isAdditional ( _, _)
6985 or
70- this .isAfterTrue ( _)
71- or
72- this .isAfterFalse ( _)
86+ isConditionGuardNode ( this )
7387 or
7488 // The successful-match node of a type-switch case that binds an implicit
7589 // variable hosts that variable's declaration/assignment (see
@@ -201,11 +215,7 @@ module IR {
201215
202216 /** A condition guard instruction, representing a known boolean outcome for a condition. */
203217 private class ConditionGuardInstruction extends Instruction {
204- ConditionGuardInstruction ( ) {
205- this .isAfterTrue ( _)
206- or
207- this .isAfterFalse ( _)
208- }
218+ ConditionGuardInstruction ( ) { isConditionGuardNode ( this ) }
209219 }
210220
211221 /**
You can’t perform that action at this time.
0 commit comments