Skip to content

Commit 907afdd

Browse files
committed
SSA: Tie caching of all 3 SSA modules together.
1 parent 8fb484d commit 907afdd

12 files changed

Lines changed: 67 additions & 48 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,8 @@ module IteratorFlow {
21732173
predicate variableRead(IRCfg::BasicBlock bb, int i, SourceVariable v, boolean certain) {
21742174
Ssa::variableRead(bb, i, v, certain)
21752175
}
2176+
2177+
predicate ssaCachedStageRevRef() { DataFlowIntegrationImpl::ssaCachedStageRevRef2() }
21762178
}
21772179

21782180
private module IteratorSsa = SsaImpl::Make<Location, IRCfg, SsaInput>;

‎cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImpl.qll‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,8 @@ private module SsaInput implements Ssa::InputSig<Location, IRCfg::BasicBlock> {
11041104
if use.isCertain() then certain = true else certain = false
11051105
)
11061106
}
1107+
1108+
predicate ssaCachedStageRevRef() { DataFlowIntegrationImpl::ssaCachedStageRevRef2() }
11071109
}
11081110

11091111
predicate ssaDefReachesRead(SourceVariable v, Definition def, IRBlock bb, int i) {
@@ -1163,14 +1165,6 @@ private module DataFlowIntegrationInput implements SsaImpl::DataFlowIntegrationI
11631165
predicate hasCfgNode(IRCfg::BasicBlock bb, int i) { bb.getInstruction(i) = this }
11641166
}
11651167

1166-
Expr getARead(SsaImpl::Definition def) {
1167-
exists(SourceVariable v, IRBlock bb, int i |
1168-
ssaDefReachesRead(v, def, bb, i) and
1169-
variableRead(bb, i, v, true) and
1170-
result.hasCfgNode(bb, i)
1171-
)
1172-
}
1173-
11741168
predicate ssaDefHasSource(SsaImpl::WriteDefinition def) { none() }
11751169

11761170
predicate allowFlowIntoUncertainDef(SsaImpl::UncertainWriteDefinition def) { any() }

‎csharp/ql/lib/semmle/code/csharp/dataflow/internal/BaseSSA.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ private module BaseSsaImpl {
121121
certain = true
122122
)
123123
}
124+
125+
predicate ssaCachedStageRevRef() { BaseSsa::ssaCachedStageRevRef1() }
124126
}
125127

126128
module SsaImpl = SsaImplCommon::Make<Location, Cfg, SsaImplInput>;

‎csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ private module SsaImplInput implements SsaImplCommon::InputSig<Location, BasicBl
3939
variableReadPseudo(bb, i, v) and
4040
certain = false
4141
}
42+
43+
predicate ssaCachedStageRevRef() {
44+
Ssa_::ssaCachedStageRevRef1() and DataFlowIntegrationImpl::ssaCachedStageRevRef2()
45+
}
4246
}
4347

4448
import SsaImplCommon::Make<Location, Cfg, SsaImplInput> as Impl
@@ -1012,8 +1016,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
10121016
predicate hasCfgNode(BasicBlock bb, int i) { this = bb.getNode(i) }
10131017
}
10141018

1015-
Expr getARead(Definition def) { def.(SsaDefinition).getARead().getControlFlowNode() = result }
1016-
10171019
predicate ssaDefHasSource(Impl::WriteDefinition def) {
10181020
// exclude flow directly from RHS to SSA definition, as we instead want to
10191021
// go from RHS to matching assignable definition, and from there to SSA definition

‎java/ql/lib/semmle/code/java/dataflow/internal/BaseSSA.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ private module SsaImplInput implements SsaImplCommon::InputSig<Location, BasicBl
184184
variableCapture(v, _, bb, i) and
185185
certain = false
186186
}
187+
188+
predicate ssaCachedStageRevRef() { Ssa::ssaCachedStageRevRef1() }
187189
}
188190

189191
private module Impl = SsaImplCommon::Make<Location, Cfg, SsaImplInput>;

‎java/ql/lib/semmle/code/java/dataflow/internal/SsaImpl.qll‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ private module SsaImplInput implements SsaImplCommon::InputSig<Location, BasicBl
199199
variableCapture(v, _, bb, i) and
200200
certain = false
201201
}
202+
203+
predicate ssaCachedStageRevRef() {
204+
Ssa::ssaCachedStageRevRef1() and DataFlowIntegrationImpl::ssaCachedStageRevRef2()
205+
}
202206
}
203207

204208
import SsaImplCommon::Make<Location, Cfg, SsaImplInput> as Impl
@@ -642,8 +646,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
642646
}
643647
}
644648

645-
Expr getARead(Definition def) { result = def.(SsaDefinition).getARead() }
646-
647649
predicate ssaDefHasSource(WriteDefinition def) { def instanceof SsaExplicitWrite }
648650

649651
predicate allowFlowIntoUncertainDef(UncertainWriteDefinition def) {

‎javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/Ssa.qll‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module SsaConfig implements InputSig<js::Location, js::Cfg::BasicBlock> {
3838
certain = true and
3939
bb.getNode(i).(ThisUse).getBindingContainer() = v.asThisContainer()
4040
}
41+
42+
predicate ssaCachedStageRevRef() { DataFlowIntegrationImpl::ssaCachedStageRevRef2() }
4143
}
4244

4345
import Make<js::Location, js::Cfg, SsaConfig>
@@ -56,16 +58,6 @@ module SsaDataflowInput implements DataFlowIntegrationInputSig {
5658
none()
5759
}
5860

59-
cached
60-
Expr getARead(Definition def) {
61-
// Copied from implementation so we can cache it here
62-
exists(SsaConfig::SourceVariable v, js::BasicBlock bb, int i |
63-
ssaDefReachesRead(v, def, bb, i) and
64-
SsaConfig::variableRead(bb, i, v, true) and
65-
result.hasCfgNode(bb, i)
66-
)
67-
}
68-
6961
class GuardValue = Boolean;
7062

7163
class Guard extends js::ControlFlowNode {
@@ -107,4 +99,6 @@ module SsaDataflowInput implements DataFlowIntegrationInputSig {
10799
}
108100
}
109101

110-
import DataFlowIntegration<SsaDataflowInput>
102+
module DataFlowIntegrationImpl = DataFlowIntegration<SsaDataflowInput>;
103+
104+
import DataFlowIntegrationImpl

‎ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImpl.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlock> {
5656
namespaceSelfExitRead(bb, i, v) and
5757
certain = false
5858
}
59+
60+
predicate ssaCachedStageRevRef() { DataFlowIntegrationImpl::ssaCachedStageRevRef2() }
5961
}
6062

6163
import SsaImplCommon::Make<Location, Cfg::Cfg, SsaInput> as Impl
@@ -436,8 +438,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
436438
predicate hasCfgNode(BasicBlock bb, int i) { this = bb.getNode(i) }
437439
}
438440

439-
Expr getARead(Definition def) { result = Cached::getARead(def) }
440-
441441
predicate ssaDefHasSource(WriteDefinition def) {
442442
any(ParameterExt p).isInitializedBy(def) or def.(Ssa::WriteDefinition).assigns(_)
443443
}

‎rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ module SsaInput implements SsaImplCommon::InputSig<Location, BasicBlock> {
7979
or
8080
capturedExitRead(bb, i, v) and certain = false
8181
}
82+
83+
predicate ssaCachedStageRevRef() { DataFlowIntegrationImpl::ssaCachedStageRevRef2() }
8284
}
8385

8486
import SsaImplCommon::Make<Location, BasicBlocks::Cfg, SsaInput> as Impl
@@ -336,8 +338,6 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
336338
predicate hasCfgNode(BasicBlock bb, int i) { this.getACfgNode() = bb.getNode(i) }
337339
}
338340

339-
Expr getARead(Definition def) { result = Cached::getARead(def) }
340-
341341
predicate ssaDefHasSource(WriteDefinition def) { none() } // handled in `DataFlowImpl.qll` instead
342342

343343
private predicate isArg(Call call, Expr e) {

‎shared/dataflow/codeql/dataflow/VariableCapture.qll‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ module Flow<
739739
) and
740740
certain = true
741741
}
742+
743+
predicate ssaCachedStageRevRef() { SsaFlow::ssaCachedStageRevRef2() }
742744
}
743745

744746
private module CaptureSsa = Ssa::Make<Location, Cfg, CaptureSsaInput>;

0 commit comments

Comments
 (0)