Skip to content

Commit bb9778c

Browse files
authored
Merge pull request #22035 from github/copilot/update-switch-stmt-usage
Fix Go expression-switch CFG migration to shared library
2 parents cae623d + 66eaeeb commit bb9778c

11 files changed

Lines changed: 524 additions & 527 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,16 @@ module ControlFlow {
361361
}
362362

363363
/**
364-
* Holds if `pred` is the node for the case `testExpr` in an expression
365-
* switch statement which is switching on `switchExpr`, and `succ` is the
366-
* node to be executed next if the case test succeeds.
364+
* Holds if `pred` is the node reached when a case of the expression switch
365+
* statement switching on `switchExpr` matches, `testExpr` is one of that
366+
* case's test expressions, and `succ` is the node to be executed next when
367+
* the case matches.
368+
*
369+
* In the control-flow graph the individual case test expressions of a case
370+
* clause all funnel into a single "matched" node for the clause, from which
371+
* control transfers to the case body. Hence `pred` is that shared matched
372+
* node, and the same `(pred, succ)` pair is reported once per test
373+
* expression `testExpr` of the clause.
367374
*/
368375
predicate isSwitchCaseTestPassingEdge(
369376
ControlFlow::Node pred, ControlFlow::Node succ, Expr switchExpr, Expr testExpr
@@ -372,7 +379,7 @@ module ControlFlow {
372379
ess.getExpr() = switchExpr and
373380
cc = ess.getACase() and
374381
testExpr = cc.getExpr(i) and
375-
pred.isAfter(testExpr) and
382+
pred.isAfter(cc) and
376383
succ.isFirstNodeOf(cc.getStmt(0))
377384
)
378385
}

0 commit comments

Comments
 (0)