Skip to content

Commit 2f95851

Browse files
authored
Merge pull request #16603 from aschackmull/dataflow/location
Dataflow/Go: Add getLocation to DataFlowCall and DataFlowCallable for easier debugging.
2 parents 06fd16b + 3b12f69 commit 2f95851

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
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
}

0 commit comments

Comments
 (0)