Skip to content

Commit 3d3715c

Browse files
committed
Add getAMatchingSuccessorType
1 parent 5bfeede commit 3d3715c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import go
8+
private import codeql.controlflow.SuccessorType
89

910
/** A block statement that is not the body of a `switch` or `select` statement. */
1011
class PlainBlock extends BlockStmt {
@@ -542,6 +543,30 @@ module CFG {
542543
}
543544
}
544545

546+
/**
547+
* Gets a successor type that matches completion `c`.
548+
*
549+
* Note that there isn't a 1-to-1 correspondence between completions and
550+
* successor types, so this is an approximation. For example sometimes the
551+
* completion `Done()` is used when the successor type would be
552+
* `ReturnSuccessor` or `ExitSuccessor`.
553+
*/
554+
private SuccessorType getAMatchingSuccessorType(Completion c) {
555+
c = Done() and result instanceof DirectSuccessor
556+
or
557+
exists(boolean b | c = Bool(b) | result.(BooleanSuccessor).getValue() = b)
558+
or
559+
c = Break(_) and result instanceof BreakSuccessor
560+
or
561+
c = Continue(_) and result instanceof ContinueSuccessor
562+
or
563+
c = Fallthrough() and result instanceof DirectSuccessor
564+
or
565+
c = Return() and result instanceof ReturnSuccessor
566+
or
567+
c = Panic() and result instanceof ExceptionSuccessor
568+
}
569+
545570
/**
546571
* Holds if `e` should have an evaluation node in the control-flow graph.
547572
*

0 commit comments

Comments
 (0)