Skip to content

Commit bf4dc00

Browse files
committed
C#: Use Gvn comparison instead of StructuralComparisonConfiguration in Guards.
1 parent 90b4eb9 commit bf4dc00

File tree

1 file changed

+25
-27
lines changed
  • csharp/ql/lib/semmle/code/csharp/controlflow

1 file changed

+25
-27
lines changed

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

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private import dotnet
88
private import ControlFlow::SuccessorTypes
99
private import semmle.code.csharp.commons.Assertions
1010
private import semmle.code.csharp.commons.ComparisonTest
11-
private import semmle.code.csharp.commons.StructuralComparison::Internal
11+
private import semmle.code.csharp.commons.StructuralComparison as SC
1212
private import semmle.code.csharp.controlflow.BasicBlocks
1313
private import semmle.code.csharp.controlflow.internal.Completion
1414
private import semmle.code.csharp.frameworks.System
@@ -1798,32 +1798,30 @@ module Internal {
17981798
}
17991799

18001800
/**
1801-
* A helper class for calculating structurally equal access/call expressions.
1801+
* Holds if access/call expression `e` (targeting declaration `target`)
1802+
* is a sub expression of a guard that controls whether basic block
1803+
* `bb` is reached.
18021804
*/
1803-
private class ConditionOnExprComparisonConfig extends InternalStructuralComparisonConfiguration {
1804-
ConditionOnExprComparisonConfig() { this = "ConditionOnExprComparisonConfig" }
1805-
1806-
override predicate candidate(ControlFlowElement x, ControlFlowElement y) {
1807-
exists(BasicBlock bb, Declaration d |
1808-
this.candidateAux(x, d, bb) and
1809-
y =
1810-
any(AccessOrCallExpr e |
1811-
e.getAControlFlowNode().getBasicBlock() = bb and
1812-
e.getTarget() = d
1813-
)
1814-
)
1815-
}
1805+
pragma[noinline]
1806+
private predicate candidateAux(AccessOrCallExpr e, Declaration target, BasicBlock bb) {
1807+
target = e.getTarget() and
1808+
guardControlsSub(_, bb, e)
1809+
}
18161810

1817-
/**
1818-
* Holds if access/call expression `e` (targeting declaration `target`)
1819-
* is a sub expression of a guard that controls whether basic block
1820-
* `bb` is reached.
1821-
*/
1822-
pragma[noinline]
1823-
private predicate candidateAux(AccessOrCallExpr e, Declaration target, BasicBlock bb) {
1824-
target = e.getTarget() and
1825-
guardControlsSub(_, bb, e)
1826-
}
1811+
private predicate candidate(AccessOrCallExpr x, AccessOrCallExpr y) {
1812+
exists(BasicBlock bb, Declaration d |
1813+
candidateAux(x, d, bb) and
1814+
y =
1815+
any(AccessOrCallExpr e |
1816+
e.getAControlFlowNode().getBasicBlock() = bb and
1817+
e.getTarget() = d
1818+
)
1819+
)
1820+
}
1821+
1822+
private predicate same(AccessOrCallExpr x, AccessOrCallExpr y) {
1823+
candidate(x, y) and
1824+
SC::sameGvn(x, y)
18271825
}
18281826

18291827
cached
@@ -1849,7 +1847,7 @@ module Internal {
18491847
pragma[nomagic]
18501848
private predicate guardControlsSubSame(Guard g, BasicBlock bb, ControlGuardDescendant sub) {
18511849
guardControlsSub(g, bb, sub) and
1852-
any(ConditionOnExprComparisonConfig c).same(sub, _)
1850+
same(sub, _)
18531851
}
18541852

18551853
pragma[nomagic]
@@ -1862,7 +1860,7 @@ module Internal {
18621860
guardedBB = guardedCfn.getBasicBlock() and
18631861
guardControls(g, guardedBB, v) and
18641862
guardControlsSubSame(g, guardedBB, sub) and
1865-
any(ConditionOnExprComparisonConfig c).same(sub, guarded)
1863+
same(sub, guarded)
18661864
}
18671865

18681866
pragma[nomagic]

0 commit comments

Comments
 (0)