mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Fix bad join order in Shadowing::shadows
Fixes the bad join order in `Shadowing::shadows`:
Tuple counts for Shadowing::shadows#f4fb89a3#ffff@c4b8a90j:
182915 ~0% {2} r1 = Variable::LocalVariableDecl::getCallable#dispred#f0820431#ff AND NOT Shadowing::shadows#f4fb89a3#ffff#antijoin_rhs(Lhs.0, Lhs.1)
182915 ~0% {3} r2 = JOIN r1 WITH localvars ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Rhs.2
182915 ~3% {4} r3 = JOIN r2 WITH Member::Member::getDeclaringType#dispred#f0820431#bf ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0, Lhs.2
182833 ~0% {4} r4 = JOIN r3 WITH classes ON FIRST 1 OUTPUT Lhs.1, Lhs.2, Lhs.3, Lhs.0
182833 ~3% {5} r5 = JOIN r4 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 1 OUTPUT Lhs.2, Lhs.0, Lhs.1, Lhs.3, Rhs.1
183352620 ~5% {5} r6 = JOIN r5 WITH Member::Field::getType#dispred#f0820431#bf_10#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.3, Lhs.1, Lhs.2, Lhs.4
40529 ~0% {5} r7 = JOIN r6 WITH Member::Field::getDeclaringType#dispred#f0820431#fb ON FIRST 2 OUTPUT Lhs.0, Lhs.4, Lhs.2, Lhs.3, Lhs.1
678 ~4% {4} r8 = JOIN r7 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 2 OUTPUT Lhs.2, Lhs.3, Lhs.4, Lhs.0
670 ~4% {4} r9 = r8 AND NOT Member::Field::isStatic#dispred#f0820431#b(Lhs.3)
670 ~3% {4} r10 = SCAN r9 OUTPUT In.0, In.2, In.3, In.1
return r10
After the fix:
Tuple counts for Shadowing::shadows#f4fb89a3#ffff@95ca976v:
182915 ~0% {2} r1 = Variable::LocalVariableDecl::getCallable#dispred#f0820431#ff AND NOT Shadowing::shadows#f4fb89a3#ffff#antijoin_rhs(Lhs.0, Lhs.1)
182915 ~0% {3} r2 = JOIN r1 WITH localvars ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Rhs.2
182915 ~0% {4} r3 = JOIN r2 WITH Member::Member::getDeclaringType#dispred#f0820431#bf ON FIRST 1 OUTPUT Lhs.1, Lhs.0, Lhs.2, Rhs.1
182915 ~7% {5} r4 = JOIN r3 WITH Element::Element::getName#dispred#f0820431#ff ON FIRST 1 OUTPUT Lhs.3, Rhs.1, Lhs.2, Lhs.0, Lhs.1
678 ~4% {4} r5 = JOIN r4 WITH Shadowing::getField#f4fb89a3#ffff ON FIRST 3 OUTPUT Lhs.3, Lhs.4, Lhs.0, Rhs.3
670 ~4% {4} r6 = r5 AND NOT Member::Field::isStatic#dispred#f0820431#b(Lhs.3)
670 ~3% {4} r7 = SCAN r6 OUTPUT In.0, In.2, In.3, In.1
return r7
This commit is contained in:
@@ -20,13 +20,21 @@ predicate setterFor(Method m, Field f) {
|
||||
predicate shadows(LocalVariableDecl d, Class c, Field f, Callable method) {
|
||||
d.getCallable() = method and
|
||||
method.getDeclaringType() = c and
|
||||
c.getAField() = f and
|
||||
f.getName() = d.getName() and
|
||||
f.getType() = d.getType() and
|
||||
not d.getCallable().isStatic() and
|
||||
f = getField(c, d.getName(), d.getType()) and
|
||||
not method.isStatic() and
|
||||
not f.isStatic()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the field with the given name and type from the given class, if any.
|
||||
*/
|
||||
pragma[nomagic]
|
||||
private Field getField(Class c, string name, Type t) {
|
||||
result.getDeclaringType() = c and
|
||||
result.getName() = name and
|
||||
result.getType() = t
|
||||
}
|
||||
|
||||
predicate thisAccess(LocalVariableDecl d, Field f) {
|
||||
shadows(d, _, f, _) and
|
||||
exists(VarAccess va | va.getVariable().(Field).getSourceDeclaration() = f |
|
||||
|
||||
Reference in New Issue
Block a user