Skip to content

Commit f398247

Browse files
committed
JS: Step through rephinements in getImmediatePredecessor
1 parent a30f991 commit f398247

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/SSA.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,29 @@ class SsaPhiNode extends SsaPseudoDefinition, TPhi {
662662
endcolumn = startcolumn and
663663
getBasicBlock().getLocation().hasLocationInfo(filepath, startline, startcolumn, _, _)
664664
}
665+
666+
/**
667+
* If all inputs to this phi node are (transitive) refinements of the same variable,
668+
* gets that variable.
669+
*/
670+
SsaVariable getRephinedVariable() {
671+
forex(SsaVariable input | input = getAnInput() |
672+
result = getRefinedVariable(input)
673+
)
674+
}
675+
}
676+
677+
/**
678+
* Gets the input to the given refinement node or rephinement node.
679+
*/
680+
private SsaVariable getRefinedVariable(SsaVariable v) {
681+
result = getRefinedVariable(v.(SsaRefinementNode).getAnInput())
682+
or
683+
result = getRefinedVariable(v.(SsaPhiNode).getRephinedVariable())
684+
or
685+
not v instanceof SsaRefinementNode and
686+
not v instanceof SsaPhiNode and
687+
result = v
665688
}
666689

667690
/**

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ module DataFlow {
208208
result = TSsaDefNode(refinement.getAnInput())
209209
)
210210
or
211+
exists(SsaPhiNode phi |
212+
this = TSsaDefNode(phi) and
213+
result = TSsaDefNode(phi.getRephinedVariable())
214+
)
215+
or
211216
// IIFE call -> return value of IIFE
212217
exists(Function fun |
213218
localCall(this.asExpr(), fun) and

0 commit comments

Comments
 (0)