Skip to content

Commit bbc5787

Browse files
committed
C++: Performance fix for large basic blocks
The code is now quadratic in the number of statements in a basic block, whereas before it was quadratic in the number of _control-flow nodes_ in a basic block.
1 parent dfe1a7e commit bbc5787

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cpp/ql/src/semmle/code/cpp/security/Overflow.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ predicate guardedAbs(Operation e, Expr use) {
1313
)
1414
}
1515

16+
/** This is `BasicBlock.getNode`, restricted to `Stmt` for performance. */
17+
pragma[noinline]
18+
private int getStmtIndexInBlock(BasicBlock block, Stmt stmt) { block.getNode(result) = stmt }
19+
1620
pragma[inline]
1721
private predicate stmtDominates(Stmt dominator, Stmt dominated) {
1822
// In same block
1923
exists(BasicBlock block, int dominatorIndex, int dominatedIndex |
20-
block.getNode(dominatorIndex) = dominator and
21-
block.getNode(dominatedIndex) = dominated and
24+
dominatorIndex = getStmtIndexInBlock(block, dominator) and
25+
dominatedIndex = getStmtIndexInBlock(block, dominated) and
2226
dominatedIndex >= dominatorIndex
2327
)
2428
or

0 commit comments

Comments
 (0)