Skip to content

Commit 8ac826a

Browse files
committed
C++: Factor out base case of normalGroupMember
This recursive predicate is made faster by working around a known optimizer problem (QL-796) that causes the optimizer to insert extra type checks in recursive case even when they are only needed in the base case.
1 parent c74b891 commit 8ac826a

File tree

1 file changed

+10
-5
lines changed
  • cpp/ql/src/semmle/code/cpp/controlflow/internal

1 file changed

+10
-5
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/internal/CFG.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,17 +1287,22 @@ private predicate conditionJumps(Expr test, boolean truth, Node n2, Pos p2) {
12871287
)
12881288
}
12891289

1290+
// Factored out for performance. See QL-796.
1291+
private predicate normalGroupMemberBaseCase(Node memberNode, Pos memberPos, Node atNode) {
1292+
memberNode = atNode and
1293+
memberPos.isAt() and
1294+
// We check for excludeNode here as it's slower to check in all the leaf
1295+
// cases during construction of the sub-graph.
1296+
not excludeNode(atNode)
1297+
}
1298+
12901299
/**
12911300
* Holds if the sub-node `(memberNode, memberPos)` can reach `at(atNode)` by
12921301
* following sub-edges forward without crossing another "at" node. Here,
12931302
* `memberPos.isAt()` holds only when `memberNode = atNode`.
12941303
*/
12951304
private predicate normalGroupMember(Node memberNode, Pos memberPos, Node atNode) {
1296-
memberNode = atNode and
1297-
memberPos.isAt() and
1298-
// We check for excludeNode here as it's slower to check in all the leaf
1299-
// cases during construction of the sub-graph.
1300-
not excludeNode(atNode)
1305+
normalGroupMemberBaseCase(memberNode, memberPos, atNode)
13011306
or
13021307
exists(Node succNode, Pos succPos |
13031308
normalGroupMember(succNode, succPos, atNode) and

0 commit comments

Comments
 (0)