Skip to content

Commit a309545

Browse files
authored
Merge pull request github#3085 from jbj/inStaticInitializer-AggregateLiteral
C++: Manual magic in inStaticInitializer
2 parents 9a0b2b1 + a23077a commit a309545

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,21 @@ class StaticStorageDurationVariable extends Variable {
397397
*/
398398
private predicate runtimeExprInStaticInitializer(Expr e) {
399399
inStaticInitializer(e) and
400-
if e instanceof AggregateLiteral
400+
if e instanceof AggregateLiteral // in sync with the cast in `inStaticInitializer`
401401
then runtimeExprInStaticInitializer(e.getAChild())
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+
// The cast to `AggregateLiteral` ensures we only compute what'll later be
413+
// needed by `runtimeExprInStaticInitializer`.
414+
inStaticInitializer(e.getParent().(AggregateLiteral))
410415
}
411416

412417
/**

0 commit comments

Comments
 (0)