Skip to content

Commit 5d91f2e

Browse files
committed
C++: Change countNumberOfBranchesUsingParameter to match qldoc closer.
1 parent ee08e8b commit 5d91f2e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,16 +1520,17 @@ private EdgeKind caseOrDefaultEdge() {
15201520
private int countNumberOfBranchesUsingParameter(SwitchInstruction switch, ParameterNode p) {
15211521
exists(Ssa::SourceVariable sv |
15221522
parameterNodeHasSourceVariable(p, sv) and
1523-
// Count the number of cases that use the parameter. We do this by finding the phi node
1524-
// that merges the uses/defs of the parameter. There might be multiple such phi nodes, so
1525-
// we pick the one with the highest edge count.
1523+
// Count the number of cases that use the parameter.
15261524
result =
1527-
max(SsaPhiNode phi |
1528-
switch.getSuccessor(caseOrDefaultEdge()).getBlock().dominanceFrontier() =
1529-
phi.getBasicBlock() and
1530-
phi.getSourceVariable() = sv
1531-
|
1532-
strictcount(phi.getAnInput())
1525+
strictcount(IRBlock caseblock |
1526+
exists(IRBlock useblock |
1527+
switch.getSuccessor(caseOrDefaultEdge()).getBlock() = caseblock and
1528+
caseblock.dominates(useblock)
1529+
|
1530+
exists(Ssa::UseImpl use | use.hasIndexInBlock(useblock, _, sv))
1531+
or
1532+
exists(Ssa::DefImpl def | def.hasIndexInBlock(useblock, _, sv))
1533+
)
15331534
)
15341535
)
15351536
}

0 commit comments

Comments
 (0)