Skip to content

Commit 0fb534c

Browse files
committed
C++: Fix join order in getAnAssignedValue
1 parent 471f536 commit 0fb534c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ class Variable extends Declaration, @variable {
115115
else result = this.getADeclarationLocation()
116116
}
117117

118+
/** Pulled out of `getAnAssignedValue` to fix a bad join order */
119+
pragma[noinline]
120+
private predicate aggregateLiteralHasType(AggregateLiteral lit, Class c) { lit.getType() = c }
121+
118122
/**
119123
* Gets an expression that is assigned to this variable somewhere in the
120124
* program.
@@ -126,8 +130,9 @@ class Variable extends Declaration, @variable {
126130
or
127131
exists(AssignExpr ae | ae.getLValue().(Access).getTarget() = this and result = ae.getRValue())
128132
or
129-
exists(AggregateLiteral l |
130-
this.getDeclaringType() = l.getType() and
133+
exists(AggregateLiteral l, Class c |
134+
this.(Field).getDeclaringType() = c and
135+
aggregateLiteralHasType(l, c) and
131136
result = l.getChild(this.(Field).getInitializationOrder())
132137
)
133138
}

0 commit comments

Comments
 (0)