Skip to content

Commit 437e2b7

Browse files
committed
C#: Instantiate shared SSA wrappers.
1 parent fedf9db commit 437e2b7

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,13 +3,15 @@
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
1213
private import semmle.code.csharp.internal.Location
14+
import SsaImpl::Ssa_
1315

1416
pragma[nomagic]
1517
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
@@ -42,6 +42,39 @@ private module SsaImplInput implements SsaImplCommon::InputSig<Location, BasicBl
4242

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

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

4780
class WriteDefinition = Impl::WriteDefinition;

0 commit comments

Comments
 (0)