Skip to content

Commit 8c0725e

Browse files
authored
Python: Fix bad join in ESSA getInput
Before: ``` Tuple counts for Essa::EssaEdgeRefinement::getInput#dispred#f0820431#ff/2@b84afc77 after 20.3s: 873421 ~0% {3} r1 = JOIN Essa::TEssaEdgeDefinition#24e22a14#ffff_31#join_rhs WITH Essa::TEssaEdgeDefinition#24e22a14#ffff_30#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0 'this' 181627951 ~0% {3} r2 = JOIN r1 WITH Essa::EssaDefinition::getSourceVariable#dispred#f0820431#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'result', Lhs.1, Lhs.2 'this' 873418 ~0% {2} r3 = JOIN r2 WITH Essa::EssaDefinition::reachesEndOfBlock#dispred#f0820431#ff ON FIRST 2 OUTPUT Lhs.2 'this', Lhs.0 'result' return r3 ``` It's perhaps not immediately obvious what's going on here (because of the `...join_rhs` indirection), but basically we're joining together `this` and `def` and their `getSourceVariable`, and only then actually relating `this` and `def` through `reachesEndOfBlock`. By unbinding `var`, we prevent this early join, which now encourages the `reachesEndOfBlock` join to happen earlier: ``` Tuple counts for Essa::EssaEdgeRefinement::getInput#dispred#f0820431#ff/2@2d63e5lb after 2s 873421 ~0% {2} r1 = SCAN Essa::TEssaEdgeDefinition#24e22a14#ffff OUTPUT In.3 'this', In.1 873421 ~0% {3} r2 = JOIN r1 WITH Essa::TEssaEdgeDefinition#24e22a14#ffff_30#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1, Lhs.0 'this' 873421 ~0% {3} r3 = JOIN r2 WITH Definitions::SsaSourceVariable#class#486534ab#f ON FIRST 1 OUTPUT Lhs.1, Lhs.2 'this', Lhs.0 8758877 ~0% {3} r4 = JOIN r3 WITH Essa::EssaDefinition::reachesEndOfBlock#dispred#f0820431#ff_10#join_rhs ON FIRST 1 OUTPUT Rhs.1 'result', Lhs.2, Lhs.1 'this' 873418 ~0% {2} r5 = JOIN r4 WITH Essa::EssaDefinition::getSourceVariable#dispred#f0820431#ff ON FIRST 2 OUTPUT Lhs.2 'this', Lhs.0 'result' return r5 ```
1 parent 4101676 commit 8c0725e

File tree

1 file changed

+2
-2
lines changed
  • python/ql/lib/semmle/python/essa

1 file changed

+2
-2
lines changed

python/ql/lib/semmle/python/essa/Essa.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ class EssaEdgeRefinement extends EssaDefinition, TEssaEdgeDefinition {
212212
/** Gets the SSA variable to which this refinement applies. */
213213
EssaVariable getInput() {
214214
exists(SsaSourceVariable var, EssaDefinition def |
215-
var = this.getSourceVariable() and
216-
var = def.getSourceVariable() and
215+
pragma[only_bind_into](var) = this.getSourceVariable() and
216+
pragma[only_bind_into](var) = def.getSourceVariable() and
217217
def.reachesEndOfBlock(this.getPredecessor()) and
218218
result.getDefinition() = def
219219
)

0 commit comments

Comments
 (0)