C++: Fix join order in getAnAssignedValue

This commit is contained in:
Mathias Vorreiter Pedersen
2020-04-23 11:04:40 +02:00
parent 471f536326
commit 0fb534c79e

View File

@@ -115,6 +115,10 @@ class Variable extends Declaration, @variable {
else result = this.getADeclarationLocation()
}
/** Pulled out of `getAnAssignedValue` to fix a bad join order */
pragma[noinline]
private predicate aggregateLiteralHasType(AggregateLiteral lit, Class c) { lit.getType() = c }
/**
* Gets an expression that is assigned to this variable somewhere in the
* program.
@@ -126,8 +130,9 @@ class Variable extends Declaration, @variable {
or
exists(AssignExpr ae | ae.getLValue().(Access).getTarget() = this and result = ae.getRValue())
or
exists(AggregateLiteral l |
this.getDeclaringType() = l.getType() and
exists(AggregateLiteral l, Class c |
this.(Field).getDeclaringType() = c and
aggregateLiteralHasType(l, c) and
result = l.getChild(this.(Field).getInitializationOrder())
)
}