Skip to content

Commit 3b34de4

Browse files
committed
wip
1 parent e8472c0 commit 3b34de4

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ private module ThisFlow {
175175
result = strictcount(int primaryParamPos | primaryConstructorThisAccess(_, bb, primaryParamPos))
176176
}
177177

178+
private module BodyNearestLocationInput implements NearestLocationInputSig {
179+
class C = ControlFlowElement;
180+
181+
predicate relevantLocations(ControlFlowElement body, Location l1, Location l2) {
182+
exists(DataFlowCallable c |
183+
any(InstanceParameterNode p).isParameterOf(c, _) and
184+
body = c.asCallable(l1).getBody() and
185+
l2 = body.getLocation()
186+
)
187+
}
188+
}
189+
178190
private predicate thisAccess(Node n, BasicBlock bb, int i) {
179191
thisAccess(n, bb.getNode(i))
180192
or
@@ -183,21 +195,24 @@ private module ThisFlow {
183195
i = ppos - numberOfPrimaryConstructorParameters(bb)
184196
)
185197
or
186-
exists(DataFlowCallable c, EntryBasicBlock entry |
187-
n.(InstanceParameterNode).isParameterOf(c, _) and
188-
exists(ControlFlowNode succ |
189-
succ = c.getAControlFlowNode() and
190-
succ = entry.getFirstNode().getASuccessor() and
198+
exists(Callable c, Location l |
199+
c = n.(InstanceParameterNode).getCallable(l) and
200+
(
191201
// In case `c` has multiple bodies, we want each body to gets its own implicit
192-
// entry definition. In case `c` doesn't have multiple bodies, the line below
193-
// is simply the same as `bb = entry`, because `entry.getFirstNode().getASuccessor()`
194-
// will be in the entry block.
195-
bb = succ.getBasicBlock()
196-
|
197-
i = -1 - numberOfPrimaryConstructorParameters(bb)
202+
// entry definition.
203+
exists(ControlFlowElement body |
204+
body = c.getBody() and
205+
bb.getANode().isBefore(body) and
206+
NearestLocation<BodyNearestLocationInput>::nearestLocation(body, l, _)
207+
)
198208
or
199-
not exists(numberOfPrimaryConstructorParameters(bb)) and i = -1
209+
not c.hasBody() and
210+
bb.(EntryBasicBlock).getEnclosingCallable() = c
200211
)
212+
|
213+
i = -1 - numberOfPrimaryConstructorParameters(bb)
214+
or
215+
not exists(numberOfPrimaryConstructorParameters(bb)) and i = -1
201216
)
202217
}
203218

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,12 @@ private module MultiBodyNearestLocationInput implements NearestLocationInputSig
10151015
class C = MultiBodyParameterDefinition;
10161016

10171017
predicate relevantLocations(MultiBodyParameterDefinition def, Location l1, Location l2) {
1018-
l1 = def.getParameter().getALocation() and
1019-
l2 = def.getBasicBlock().getLocation()
1018+
exists(Callable c, ControlFlowNode n |
1019+
l1 = def.getParameter().getALocation() and
1020+
n = def.getBasicBlock().getANode() and
1021+
n.isBefore(c.getBody()) and
1022+
l2 = n.getLocation()
1023+
)
10201024
}
10211025
}
10221026

0 commit comments

Comments
 (0)