Skip to content

Commit 57c4fd6

Browse files
committed
JS: Combine phi reads and ssa input nodes into SynthReadNode class.
1 parent 22b3dc8 commit 57c4fd6

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowNode.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ private module Cached {
3434
TSsaDefNode(SsaDefinition d) or
3535
/** Use of a variable or 'this', with flow from a post-update node (from an earlier use) */
3636
TSsaUseNode(ControlFlowNode use) { use = any(Ssa2::SsaConfig::SourceVariable v).getAUse() } or
37-
/** Phi-read node (new SSA library). Ordinary phi nodes are represented by TSsaDefNode. */
38-
TSsaPhiReadNode(Ssa2::PhiReadNode phi) or
39-
/** Input to a phi node (new SSA library) */
40-
TSsaInputNode(Ssa2::SsaInputNode input) or
37+
/** A synthesized variable read (new SSA library). Definitions are represented by TSsaDefNode. */
38+
TSsaSynthReadNode(Ssa2::SsaSynthReadNode read) or
4139
TCapturedVariableNode(LocalVariable v) { v.isCaptured() } or
4240
TPropNode(@property p) or
4341
TRestPatternNode(DestructuringPattern dp, Expr rest) { rest = dp.getRest() } or

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,21 @@ class SsaUseNode extends DataFlow::Node, TSsaUseNode {
3535
override Location getLocation() { result = expr.getLocation() }
3636
}
3737

38-
class SsaPhiReadNode extends DataFlow::Node, TSsaPhiReadNode {
39-
private Ssa2::PhiReadNode phi;
38+
class SsaSynthReadNode extends DataFlow::Node, TSsaSynthReadNode {
39+
private Ssa2::SsaSynthReadNode read;
4040

41-
SsaPhiReadNode() { this = TSsaPhiReadNode(phi) }
41+
SsaSynthReadNode() { this = TSsaSynthReadNode(read) }
4242

4343
cached
44-
override string toString() { result = "[ssa-phi-read] " + phi.getSourceVariable().getName() }
45-
46-
cached
47-
override StmtContainer getContainer() { result = phi.getSourceVariable().getDeclaringContainer() }
48-
49-
cached
50-
override Location getLocation() { result = phi.getLocation() }
51-
}
52-
53-
class SsaInputNode extends DataFlow::Node, TSsaInputNode {
54-
private Ssa2::SsaInputNode input;
55-
56-
SsaInputNode() { this = TSsaInputNode(input) }
57-
58-
cached
59-
override string toString() {
60-
result = "[ssa-input] " + input.getDefinitionExt().getSourceVariable().getName()
61-
}
44+
override string toString() { result = "[ssa-synth-read] " + read.getSourceVariable().getName() }
6245

6346
cached
6447
override StmtContainer getContainer() {
65-
result = input.getDefinitionExt().getSourceVariable().getDeclaringContainer()
48+
result = read.getSourceVariable().getDeclaringContainer()
6649
}
6750

6851
cached
69-
override Location getLocation() { result = input.getLocation() }
52+
override Location getLocation() { result = read.getLocation() }
7053
}
7154

7255
class FlowSummaryNode extends DataFlow::Node, TFlowSummaryNode {
@@ -675,9 +658,7 @@ predicate nodeIsHidden(Node node) {
675658
or
676659
node instanceof SsaUseNode
677660
or
678-
node instanceof SsaPhiReadNode
679-
or
680-
node instanceof SsaInputNode
661+
node instanceof SsaSynthReadNode
681662
}
682663

683664
predicate neverSkipInPathGraph(Node node) {
@@ -1258,12 +1239,10 @@ Node getNodeFromSsa2(Ssa2::Node node) {
12581239
result = TImplicitThisUse(use, true)
12591240
)
12601241
or
1261-
result = TSsaPhiReadNode(node.(Ssa2::SsaDefinitionExtNode).getDefinitionExt())
1262-
or
1263-
result = TSsaInputNode(node.(Ssa2::SsaInputNode))
1242+
result = TSsaSynthReadNode(node)
12641243
or
12651244
exists(SsaPhiNode legacyPhi, Ssa2::PhiNode ssaPhi |
1266-
node.(Ssa2::SsaDefinitionExtNode).getDefinitionExt() = ssaPhi and
1245+
node.(Ssa2::SsaDefinitionNode).getDefinition() = ssaPhi and
12671246
samePhi(legacyPhi, ssaPhi) and
12681247
result = TSsaDefNode(legacyPhi)
12691248
)

shared/ssa/codeql/ssa/Ssa.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,13 @@ module Make<LocationSig Location, InputSig<Location> Input> {
16881688

16891689
final class SsaDefinitionNode = SsaDefinitionNodeImpl;
16901690

1691+
final class SsaSynthReadNode extends SsaNode {
1692+
SsaSynthReadNode() {
1693+
this.(SsaDefinitionExtNodeImpl).getDefinitionExt() instanceof PhiReadNode or
1694+
this instanceof SsaInputNodeImpl
1695+
}
1696+
}
1697+
16911698
/**
16921699
* A node that represents an input to an SSA phi (read) definition.
16931700
*

0 commit comments

Comments
 (0)