Skip to content

Commit 1e6820b

Browse files
committed
Merge branch 'main' into redsun82/pkg
2 parents 336ec08 + 7756259 commit 1e6820b

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ class DataFlowCallable extends TDataFlowCallable {
311311
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
312312
}
313313

314+
/** Gets the location of this callable. */
315+
Location getLocation() {
316+
result = getCallableLocation(this.asCallable()) or
317+
result = this.asFileScope().getLocation() or
318+
result = getCallableLocation(this.asSummarizedCallable())
319+
}
320+
314321
/** Gets a best-effort total ordering. */
315322
int totalorder() {
316323
this =
@@ -322,6 +329,13 @@ class DataFlowCallable extends TDataFlowCallable {
322329
}
323330
}
324331

332+
private Location getCallableLocation(Callable c) {
333+
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
334+
c.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
335+
result.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
336+
)
337+
}
338+
325339
/** A function call relevant for data flow. */
326340
class DataFlowCall extends Expr {
327341
DataFlow::CallNode call;
@@ -344,6 +358,9 @@ class DataFlowCall extends Expr {
344358
not exists(this.getEnclosingFunction()) and result.asFileScope() = this.getFile()
345359
}
346360

361+
/** Gets the location of this call. */
362+
Location getLocation() { result = super.getLocation() }
363+
347364
/** Gets a best-effort total ordering. */
348365
int totalorder() {
349366
this =

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ signature module InputSig<LocationSig Location> {
7272
/** Gets a textual representation of this element. */
7373
string toString();
7474

75+
/** Gets the location of this call. */
76+
Location getLocation();
77+
7578
DataFlowCallable getEnclosingCallable();
7679

7780
/** Gets a best-effort total ordering. */
@@ -82,6 +85,9 @@ signature module InputSig<LocationSig Location> {
8285
/** Gets a textual representation of this element. */
8386
string toString();
8487

88+
/** Gets the location of this callable. */
89+
Location getLocation();
90+
8591
/** Gets a best-effort total ordering. */
8692
int totalorder();
8793
}

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,18 +3370,19 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
33703370
Location getLocation() { result = p.getLocation() }
33713371
}
33723372

3373+
pragma[nomagic]
3374+
private predicate stage5ConsCand(Content c, DataFlowType t, AccessPathFront apf, int len) {
3375+
Stage5::consCand(c, t, any(AccessPathApprox ap | ap.getFront() = apf and ap.len() = len - 1))
3376+
}
3377+
33733378
/**
33743379
* Gets the number of length 2 access path approximations that correspond to `apa`.
33753380
*/
33763381
private int count1to2unfold(AccessPathApproxCons1 apa) {
33773382
exists(Content c, int len |
33783383
c = apa.getHead() and
33793384
len = apa.len() and
3380-
result =
3381-
strictcount(DataFlowType t, AccessPathFront apf |
3382-
Stage5::consCand(c, t,
3383-
any(AccessPathApprox ap | ap.getFront() = apf and ap.len() = len - 1))
3384-
)
3385+
result = strictcount(DataFlowType t, AccessPathFront apf | stage5ConsCand(c, t, apf, len))
33853386
)
33863387
}
33873388

0 commit comments

Comments
 (0)