Skip to content

Commit f553001

Browse files
committed
C#: Update CIL SSA library to use parameterized module
1 parent 0d81a64 commit f553001

File tree

5 files changed

+41
-836
lines changed

5 files changed

+41
-836
lines changed

config/identical-files.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@
464464
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImplCommon.qll",
465465
"csharp/ql/lib/semmle/code/csharp/controlflow/internal/pressa/SsaImplCommon.qll",
466466
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/basessa/SsaImplCommon.qll",
467-
"csharp/ql/lib/semmle/code/cil/internal/SsaImplCommon.qll",
468467
"ruby/ql/lib/codeql/ruby/dataflow/internal/SsaImplCommon.qll",
469468
"cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaImplCommon.qll",
470469
"swift/ql/lib/codeql/swift/dataflow/internal/SsaImplCommon.qll"
@@ -602,4 +601,4 @@
602601
"javascript/ql/lib/semmle/javascript/security/IncompleteMultiCharacterSanitizationQuery.qll",
603602
"ruby/ql/lib/codeql/ruby/security/IncompleteMultiCharacterSanitizationQuery.qll"
604603
]
605-
}
604+
}

csharp/ql/lib/semmle/code/cil/Ssa.qll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ private import CIL
88
* Provides classes for working with static single assignment (SSA) form.
99
*/
1010
module Ssa {
11-
private import internal.SsaImplCommon as SsaImpl
12-
private import internal.SsaImpl
11+
private import internal.SsaImpl as SsaImpl
1312

1413
/** An SSA definition. */
1514
class Definition extends SsaImpl::Definition {
1615
/** Gets a read of this SSA definition. */
17-
final ReadAccess getARead() { result = getARead(this) }
16+
final ReadAccess getARead() { result = SsaImpl::getARead(this) }
1817

1918
/** Gets the underlying variable update, if any. */
2019
final VariableUpdate getVariableUpdate() {
@@ -25,11 +24,11 @@ module Ssa {
2524
}
2625

2726
/** Gets a first read of this SSA definition. */
28-
final ReadAccess getAFirstRead() { result = getAFirstRead(this) }
27+
final ReadAccess getAFirstRead() { result = SsaImpl::getAFirstRead(this) }
2928

3029
/** Holds if `first` and `second` are adjacent reads of this SSA definition. */
3130
final predicate hasAdjacentReads(ReadAccess first, ReadAccess second) {
32-
hasAdjacentReads(this, first, second)
31+
SsaImpl::hasAdjacentReads(this, first, second)
3332
}
3433

3534
private Definition getAPhiInput() { result = this.(PhiNode).getAnInput() }
@@ -52,15 +51,15 @@ module Ssa {
5251
final override Location getLocation() { result = this.getBasicBlock().getLocation() }
5352

5453
/** Gets an input to this phi node. */
55-
final Definition getAnInput() { result = getAPhiInput(this) }
54+
final Definition getAnInput() { result = SsaImpl::getAPhiInput(this) }
5655

5756
/**
5857
* Holds if if `def` is an input to this phi node, and a reference to `def` at
5958
* index `i` in basic block `bb` can reach this phi node without going through
6059
* other references.
6160
*/
6261
final predicate hasLastInputRef(Definition def, BasicBlock bb, int i) {
63-
hasLastInputRef(this, def, bb, i)
62+
SsaImpl::hasLastInputRef(this, def, bb, i)
6463
}
6564
}
6665
}

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
1-
private import semmle.code.cil.CIL
2-
private import SsaImplCommon
1+
private import cil
2+
private import semmle.code.csharp.dataflow.internal.SsaImplCommon as SsaImplCommon
3+
4+
private module SsaInput implements SsaImplCommon::InputSig {
5+
class BasicBlock = CIL::BasicBlock;
6+
7+
BasicBlock getImmediateBasicBlockDominator(BasicBlock bb) { result = bb.getImmediateDominator() }
8+
9+
BasicBlock getABasicBlockSuccessor(BasicBlock bb) { result = bb.getASuccessor() }
10+
11+
class ExitBasicBlock = CIL::ExitBasicBlock;
12+
13+
class SourceVariable = CIL::StackVariable;
14+
15+
predicate variableWrite(BasicBlock bb, int i, SourceVariable v, boolean certain) {
16+
forceCachingInSameStage() and
17+
exists(CIL::VariableUpdate vu |
18+
vu.updatesAt(bb, i) and
19+
v = vu.getVariable() and
20+
certain = true
21+
)
22+
}
23+
24+
predicate variableRead(BasicBlock bb, int i, SourceVariable v, boolean certain) {
25+
exists(CIL::ReadAccess ra | bb.getNode(i) = ra |
26+
ra.getTarget() = v and
27+
certain = true
28+
)
29+
}
30+
}
31+
32+
import SsaImplCommon::Make<SsaInput>
333

434
cached
535
private module Cached {
36+
private import CIL
37+
638
cached
739
predicate forceCachingInSameStage() { any() }
840

0 commit comments

Comments
 (0)