Skip to content

Commit bc41c26

Browse files
authored
Merge pull request #4959 from hvitved/csharp/ssa/split
C#: Split up SSA implementation
2 parents 30015ee + 0674881 commit bc41c26

File tree

14 files changed

+2042
-1930
lines changed

14 files changed

+2042
-1930
lines changed

csharp/ql/src/semmle/code/csharp/Assignable.qll

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
import csharp
6+
private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl
67

78
/**
89
* An assignable, that is, an element that can be assigned to. Either a
@@ -83,7 +84,7 @@ class AssignableRead extends AssignableAccess {
8384

8485
pragma[noinline]
8586
private ControlFlow::Node getAnAdjacentReadSameVar() {
86-
Ssa::Internal::adjacentReadPairSameVar(_, this.getAControlFlowNode(), result)
87+
SsaImpl::adjacentReadPairSameVar(_, this.getAControlFlowNode(), result)
8788
}
8889

8990
/**

csharp/ql/src/semmle/code/csharp/commons/ConsistencyChecks.qll

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ module SsaChecks {
4646
}
4747

4848
predicate notDominatedByDef(AssignableRead read, string m) {
49-
exists(Definition def, BasicBlock bb, ControlFlow::Node rnode, ControlFlow::Node dnode, int i |
49+
exists(
50+
Definition def, ControlFlow::BasicBlock bb, ControlFlow::Node rnode, ControlFlow::Node dnode,
51+
int i
52+
|
5053
def.getAReadAtNode(rnode) = read
5154
|
5255
def.definesAt(_, bb, i) and

csharp/ql/src/semmle/code/csharp/controlflow/Guards.qll

+4-3
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,7 @@ module Internal {
17231723
cached
17241724
private module Cached {
17251725
private import semmle.code.csharp.Caching
1726+
private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl
17261727

17271728
/**
17281729
* Holds if basic block `bb` only is reached when guard `g` has abstract value `v`.
@@ -1775,9 +1776,9 @@ module Internal {
17751776
private predicate adjacentReadPairSameVarUniquePredecessor(
17761777
Ssa::Definition def, ControlFlow::Node cfn1, ControlFlow::Node cfn2
17771778
) {
1778-
Ssa::Internal::adjacentReadPairSameVar(def, cfn1, cfn2) and
1779+
SsaImpl::adjacentReadPairSameVar(def, cfn1, cfn2) and
17791780
not exists(ControlFlow::Node other |
1780-
Ssa::Internal::adjacentReadPairSameVar(def, other, cfn2) and
1781+
SsaImpl::adjacentReadPairSameVar(def, other, cfn2) and
17811782
other != cfn1 and
17821783
other != cfn2
17831784
)
@@ -1831,7 +1832,7 @@ module Internal {
18311832
private predicate firstReadUniquePredecessor(Ssa::ExplicitDefinition def, ControlFlow::Node cfn) {
18321833
exists(def.getAFirstReadAtNode(cfn)) and
18331834
not exists(ControlFlow::Node other |
1834-
Ssa::Internal::adjacentReadPairSameVar(def, other, cfn) and
1835+
SsaImpl::adjacentReadPairSameVar(def, other, cfn) and
18351836
other != cfn
18361837
)
18371838
}

csharp/ql/src/semmle/code/csharp/dataflow/Nullness.qll

+10-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ private import internal.CallableReturns
2323
private import semmle.code.csharp.commons.Assertions
2424
private import semmle.code.csharp.controlflow.Guards as G
2525
private import semmle.code.csharp.controlflow.Guards::AbstractValues
26+
private import semmle.code.csharp.dataflow.internal.SsaImpl as SsaImpl
2627
private import semmle.code.csharp.frameworks.System
2728
private import semmle.code.csharp.frameworks.Test
2829

@@ -177,7 +178,7 @@ private predicate defMaybeNull(Ssa::Definition def, string msg, Element reason)
177178
exists(G::DereferenceableExpr de | de = def.getARead() |
178179
reason = de.getANullCheck(_, true) and
179180
msg = "as suggested by $@ null check" and
180-
not de = any(Ssa::PseudoDefinition pdef).getARead() and
181+
not de = any(Ssa::PhiNode phi).getARead() and
181182
strictcount(Element e | e = any(Ssa::Definition def0 | de = def0.getARead()).getElement()) = 1 and
182183
// Don't use a check as reason if there is a `null` assignment
183184
// or argument
@@ -205,7 +206,7 @@ private predicate defMaybeNull(Ssa::Definition def, string msg, Element reason)
205206
// A variable of nullable type may be null
206207
exists(Dereference d | dereferenceAt(_, _, def, d) |
207208
d.hasNullableType() and
208-
not def instanceof Ssa::PseudoDefinition and
209+
not def instanceof Ssa::PhiNode and
209210
reason = def.getSourceVariable().getAssignable() and
210211
msg = "because it has a nullable type"
211212
)
@@ -236,13 +237,13 @@ private predicate defNullImpliesStep(
236237
Ssa::Definition def1, BasicBlock bb1, Ssa::Definition def2, BasicBlock bb2
237238
) {
238239
exists(Ssa::SourceVariable v | defNullImpliesStep0(v, def1, bb1, bb2) |
239-
def2.(Ssa::PseudoDefinition).getAnInput() = def1 and
240+
def2.(Ssa::PhiNode).getAnInput() = def1 and
240241
bb2 = def2.getBasicBlock()
241242
or
242243
def2 = def1 and
243-
not exists(Ssa::PseudoDefinition def |
244-
def.getSourceVariable() = v and
245-
bb2 = def.getBasicBlock()
244+
not exists(Ssa::PhiNode phi |
245+
phi.getSourceVariable() = v and
246+
bb2 = phi.getBasicBlock()
246247
)
247248
) and
248249
not exists(SuccessorTypes::ConditionalSuccessor s, NullValue nv |
@@ -426,14 +427,14 @@ module PathGraph {
426427
}
427428

428429
private Ssa::Definition getAPseudoInput(Ssa::Definition def) {
429-
result = def.(Ssa::PseudoDefinition).getAnInput()
430+
result = def.(Ssa::PhiNode).getAnInput()
430431
}
431432

432433
// `def.getAnUltimateDefinition()` includes inputs into uncertain
433434
// definitions, but we only want inputs into pseudo nodes
434435
private Ssa::Definition getAnUltimateDefinition(Ssa::Definition def) {
435436
result = getAPseudoInput*(def) and
436-
not result instanceof Ssa::PseudoDefinition
437+
not result instanceof Ssa::PhiNode
437438
}
438439

439440
/**
@@ -446,7 +447,7 @@ private predicate defReaches(Ssa::Definition def, ControlFlow::Node cfn, boolean
446447
(always = true or always = false)
447448
or
448449
exists(ControlFlow::Node mid | defReaches(def, mid, always) |
449-
Ssa::Internal::adjacentReadPairSameVar(_, mid, cfn) and
450+
SsaImpl::adjacentReadPairSameVar(_, mid, cfn) and
450451
not mid =
451452
any(Dereference d |
452453
if always = true

0 commit comments

Comments
 (0)