Skip to content

Commit 260bfe7

Browse files
committed
C++: Manual magic in inStaticInitializer
Since `runtimeExprInStaticInitializer` only looks at expressions at the top level of an initializer or directly below some number of top-level aggregate literals, there is no need for `inStaticInitializer` to include expressions strictly below those in the AST. I tested this on Wireshark, which has very large static initializers, but found no measureable difference in run time. There are some differences in tuple counts and iteration counts, though: - `inStaticInitializer` changes from 6,241,153 rows (86 iterations) to 5,031,617 rows (7 iterations). - `runtimeExprInStaticInitializer` changes from 386,350 rows to 4,705 rows. - `hasDynamicInitialization` has 410 rows both before and after, which suggests that this change does not affect results. Even though there is no impact on this snapshot at this time, things might look different if/when the restriction on aggregate literals to 100 children is removed in the extractor.
1 parent 93c6f8f commit 260bfe7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cpp/ql/src/semmle/code/cpp/Variable.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,14 @@ private predicate runtimeExprInStaticInitializer(Expr e) {
402402
else not e.getFullyConverted().isConstant()
403403
}
404404

405-
/** Holds if `e` is part of the initializer of a `StaticStorageDurationVariable`. */
405+
/**
406+
* Holds if `e` is the initializer of a `StaticStorageDurationVariable`, either
407+
* directly or below some top-level `AggregateLiteral`s.
408+
*/
406409
private predicate inStaticInitializer(Expr e) {
407410
exists(StaticStorageDurationVariable var | e = var.getInitializer().getExpr())
408411
or
409-
inStaticInitializer(e.getParent())
412+
inStaticInitializer(e.getParent().(AggregateLiteral))
410413
}
411414

412415
/**

0 commit comments

Comments
 (0)