Skip to content

Commit 616c93f

Browse files
committed
C#: Delete CFG for static assignables.
1 parent 5a65282 commit 616c93f

File tree

4 files changed

+6
-56
lines changed

4 files changed

+6
-56
lines changed

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import csharp
2-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl as ControlFlowGraphImpl
32
private import semmle.code.csharp.dataflow.internal.DataFlowImplSpecific
43
private import semmle.code.csharp.dataflow.internal.TaintTrackingImplSpecific
54
private import codeql.dataflow.internal.DataFlowImplConsistency
65

76
private module Input implements InputSig<Location, CsharpDataFlow> {
87
private import CsharpDataFlow
98

10-
private predicate isStaticAssignable(Assignable a) { a.(Modifiable).isStatic() }
11-
12-
predicate uniqueEnclosingCallableExclude(Node node) {
13-
// TODO: Remove once static initializers are folded into the
14-
// static constructors
15-
isStaticAssignable(ControlFlowGraphImpl::getNodeCfgScope(node.getControlFlowNode()))
16-
}
17-
18-
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
19-
// TODO: Remove once static initializers are folded into the
20-
// static constructors
21-
isStaticAssignable(ControlFlowGraphImpl::getNodeCfgScope(call.getControlFlowNode()))
22-
}
23-
249
predicate uniqueNodeLocationExclude(Node n) {
2510
// Methods with multiple implementations
2611
n instanceof ParameterNode

csharp/ql/consistency-queries/VariableCaptureConsistency.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import csharp
22
import semmle.code.csharp.dataflow.internal.DataFlowPrivate::VariableCapture::Flow::ConsistencyChecks
33
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate::VariableCapture::Flow::ConsistencyChecks as ConsistencyChecks
44
private import semmle.code.csharp.controlflow.BasicBlocks
5-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl
65

76
query predicate uniqueEnclosingCallable(BasicBlock bb, string msg) {
8-
ConsistencyChecks::uniqueEnclosingCallable(bb, msg) and
9-
getNodeCfgScope(bb.getFirstNode()) instanceof Callable
7+
ConsistencyChecks::uniqueEnclosingCallable(bb, msg)
108
}
119

1210
query predicate consistencyOverview(string msg, int n) { none() }

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,15 @@ private module Initializers {
6666
}
6767

6868
/** An element that defines a new CFG scope. */
69-
class CfgScope extends Element, @top_level_exprorstmt_parent {
69+
class CfgScope extends Callable {
7070
CfgScope() {
7171
this.getFile().fromSource() and
7272
(
73-
this =
74-
any(Callable c |
75-
c.(Constructor).hasInitializer()
76-
or
77-
Initializers::obinitInitializes(c, _)
78-
or
79-
c.hasBody()
80-
)
73+
this.(Constructor).hasInitializer()
8174
or
82-
// For now, static initializer values have their own scope. Eventually, they
83-
// should be treated like instance initializers.
84-
this.(Assignable).(Modifiable).isStatic() and
85-
expr_parent_top_level_adjusted2(_, _, this)
75+
Initializers::obinitInitializes(this, _)
76+
or
77+
this.hasBody()
8678
)
8779
}
8880
}
@@ -189,24 +181,6 @@ CompilationExt getCompilation(File f) {
189181
result = TBuildless()
190182
}
191183

192-
/**
193-
* The `expr_parent_top_level_adjusted()` relation restricted to exclude relations
194-
* between properties and their getters' expression bodies in properties such as
195-
* `int P => 0`.
196-
*
197-
* This is in order to only associate the expression body with one CFG scope, namely
198-
* the getter (and not the declaration itself).
199-
*/
200-
private predicate expr_parent_top_level_adjusted2(
201-
Expr child, int i, @top_level_exprorstmt_parent parent
202-
) {
203-
expr_parent_top_level_adjusted(child, i, parent) and
204-
not exists(Getter g |
205-
g.getDeclaration() = parent and
206-
i = 0
207-
)
208-
}
209-
210184
/** Holds if `first` is first executed when entering `scope`. */
211185
predicate scopeFirst(CfgScope scope, AstNode first) {
212186
scope =
@@ -220,9 +194,6 @@ predicate scopeFirst(CfgScope scope, AstNode first) {
220194
)
221195
or
222196
first(Initializers::initializedInstanceMemberOrder(scope, _, 0), first)
223-
or
224-
expr_parent_top_level_adjusted2(any(Expr e | first(e, first)), _, scope) and
225-
not scope instanceof Callable
226197
}
227198

228199
/** Holds if `scope` is exited when `last` finishes with completion `c`. */
@@ -244,9 +215,6 @@ predicate scopeLast(CfgScope scope, AstNode last, Completion c) {
244215
)
245216
or
246217
last(Initializers::lastInitializer(scope, _), last, c)
247-
or
248-
expr_parent_top_level_adjusted2(any(Expr e | last(e, last, c)), _, scope) and
249-
not scope instanceof Callable
250218
}
251219

252220
private class ObjectInitTree extends ControlFlowTree instanceof ObjectInitMethod {

csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/ModulusAnalysisSpecific.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module Private {
44
private import semmle.code.csharp.dataflow.internal.rangeanalysis.RangeUtils as RU
55
private import SsaUtils as SU
66
private import SsaReadPositionCommon
7-
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl as CfgImpl
87

98
class BasicBlock = CS::ControlFlow::BasicBlock;
109

0 commit comments

Comments
 (0)