C#: Fix enclosing DataFlowCallable of ObjectInitMethods with multiple bodies.

This commit is contained in:
Anders Schack-Mulligen
2025-12-02 13:11:00 +01:00
parent ba7b517a4a
commit 2eb2a50ccd

View File

@@ -27,6 +27,12 @@ newtype TReturnKind =
private predicate hasMultipleSourceLocations(Callable c) { strictcount(getASourceLocation(c)) > 1 }
private predicate objectInitEntry(ObjectInitMethod m, ControlFlowElement first) {
exists(ControlFlow::Nodes::EntryNode en |
en.getCallable() = m and first.getControlFlowNode() = en.getASuccessor()
)
}
private module NearestBodyLocationInput implements NearestLocationInputSig {
class C = ControlFlowElement;
@@ -34,7 +40,7 @@ private module NearestBodyLocationInput implements NearestLocationInputSig {
exists(Callable c |
hasMultipleSourceLocations(c) and
l1 = getASourceLocation(c) and
body = c.getBody() and
(body = c.getBody() or objectInitEntry(c, body)) and
l2 = body.getLocation()
)
}
@@ -207,7 +213,9 @@ class DataFlowCallable extends TDataFlowCallable {
private ControlFlow::Nodes::ElementNode getAMultiBodyEntryNode(ControlFlow::BasicBlock bb, int i) {
this.isMultiBodied() and
exists(ControlFlowElement body, Location l |
body = this.asCallable(l).getBody() and
body = this.asCallable(l).getBody() or
objectInitEntry(this.asCallable(l), body)
|
NearestLocation<NearestBodyLocationInput>::nearestLocation(body, l, _) and
result = body.getAControlFlowEntryNode()
) and