Skip to content

Commit 72d21a9

Browse files
committed
C#: Instantiate shared SSA wrappers.
1 parent 7ef9e1b commit 72d21a9

3 files changed

Lines changed: 51 additions & 11 deletions

File tree

csharp/ql/lib/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
*/
44

55
import csharp
6+
private import internal.SsaImpl as SsaImpl
7+
import SsaImpl::Ssa_
68

79
/**
810
* Provides classes for working with static single assignment (SSA) form.
911
*/
1012
module Ssa {
11-
private import internal.SsaImpl as SsaImpl
13+
import SsaImpl::Ssa_
1214

1315
pragma[nomagic]
1416
private predicate assignableDefinitionLocalScopeVariable(

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1-
import csharp
1+
private import csharp as CS
22

33
/**
44
* Provides a simple SSA implementation for local scope variables.
55
*/
66
module BaseSsa {
7+
private import BaseSsaImpl
8+
9+
class SimpleLocalScopeVariable = BaseSsaImpl::SimpleLocalScopeVariable;
10+
11+
module Ssa = SsaImpl::MakeSsa<SsaInput>;
12+
13+
import Ssa
14+
}
15+
16+
private module BaseSsaImpl {
17+
private import CS
718
private import AssignableDefinitions
819
private import codeql.ssa.Ssa as SsaImplCommon
920

@@ -13,7 +24,7 @@ module BaseSsa {
1324
predicate ref() { any() }
1425

1526
cached
16-
predicate backref() { (exists(any(SsaDefinition def).getARead()) implies any()) }
27+
predicate backref() { (exists(any(BaseSsa::SsaDefinition def).getARead()) implies any()) }
1728
}
1829

1930
/**
@@ -112,11 +123,9 @@ module BaseSsa {
112123
}
113124
}
114125

115-
private module SsaImpl = SsaImplCommon::Make<Location, Cfg, SsaImplInput>;
116-
117-
private module SsaInput implements SsaImpl::SsaInputSig {
118-
private import csharp as CS
126+
module SsaImpl = SsaImplCommon::Make<Location, Cfg, SsaImplInput>;
119127

128+
module SsaInput implements SsaImpl::SsaInputSig {
120129
class Expr = CS::Expr;
121130

122131
class Parameter = CS::Parameter;
@@ -139,8 +148,4 @@ module BaseSsa {
139148
w.isParameterInit(v)
140149
}
141150
}
142-
143-
module Ssa = SsaImpl::MakeSsa<SsaInput>;
144-
145-
import Ssa
146151
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,39 @@ private module SsaImplInput implements SsaImplCommon::InputSig<Location, BasicBl
4343

4444
import SsaImplCommon::Make<Location, Cfg, SsaImplInput> as Impl
4545

46+
private module SsaInput implements Impl::SsaInputSig {
47+
private import csharp as CS
48+
49+
class Expr = CS::Expr;
50+
51+
class Parameter = CS::Parameter;
52+
53+
class VariableWrite extends AssignableDefinition {
54+
Expr asExpr() { result = this.getExpr() }
55+
56+
Expr getValue() { result = this.getSource() }
57+
58+
predicate isParameterInit(Parameter p) { this.(ImplicitParameterDefinition).getParameter() = p }
59+
}
60+
61+
predicate explicitWrite(VariableWrite w, BasicBlock bb, int i, SsaImplInput::SourceVariable v) {
62+
exists(AssignableDefinition ad | variableDefinition(bb, i, v, ad) |
63+
w = ad or
64+
w = getASameOutRefDefAfter(v, ad)
65+
)
66+
or
67+
exists(Parameter p |
68+
implicitEntryDefinition(bb, v) and
69+
i = -1 and
70+
p = v.getAssignable() and
71+
pragma[only_bind_out](p.getCallable()) = pragma[only_bind_out](v.getEnclosingCallable()) and
72+
w.isParameterInit(p)
73+
)
74+
}
75+
}
76+
77+
module Ssa_ = Impl::MakeSsa<SsaInput>;
78+
4679
class Definition = Impl::Definition;
4780

4881
class WriteDefinition = Impl::WriteDefinition;

0 commit comments

Comments
 (0)