Skip to content

Commit f09d4e5

Browse files
committed
wip
1 parent e8472c0 commit f09d4e5

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

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

Lines changed: 23 additions & 15 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,17 @@ 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
191-
// 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)
198-
or
199-
not exists(numberOfPrimaryConstructorParameters(bb)) and i = -1
200-
)
198+
exists(Callable c, Location l, ControlFlowElement body |
199+
c = n.(InstanceParameterNode).getCallable(l) and
200+
body = c.getBody() and
201+
// In case `c` has multiple bodies, we want each body to gets its own implicit
202+
// entry definition.
203+
bb.getANode().isBefore(body) and
204+
NearestLocation<BodyNearestLocationInput>::nearestLocation(body, l, _)
205+
|
206+
i = -1 - numberOfPrimaryConstructorParameters(bb)
207+
or
208+
not exists(numberOfPrimaryConstructorParameters(bb)) and i = -1
201209
)
202210
}
203211

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, BasicBlock bb, 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)