Skip to content

Commit 985b8f0

Browse files
committed
Dataflow: Add totalorder predicates to all languages.
1 parent 651d284 commit 985b8f0

File tree

8 files changed

+143
-3
lines changed

8 files changed

+143
-3
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private import DataFlowUtil
99
/**
1010
* Gets a function that might be called by `call`.
1111
*/
12-
Function viableCallable(DataFlowCall call) {
12+
DataFlowCallable viableCallable(DataFlowCall call) {
1313
result = call.(Call).getTarget()
1414
or
1515
// If the target of the call does not have a body in the snapshot, it might

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,17 @@ class CastNode extends Node {
242242
CastNode() { none() } // stub implementation
243243
}
244244

245-
class DataFlowCallable = Function;
245+
class DataFlowCallable extends Function {
246+
/** Gets a best-effort total ordering. */
247+
int totalorder() {
248+
this =
249+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
250+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
251+
|
252+
c order by file, startline, startcolumn
253+
)
254+
}
255+
}
246256

247257
class DataFlowExpr = Expr;
248258

@@ -261,7 +271,17 @@ class DataFlowCall extends Expr instanceof Call {
261271
ExprNode getNode() { result.getExpr() = this }
262272

263273
/** Gets the enclosing callable of this call. */
264-
Function getEnclosingCallable() { result = this.getEnclosingFunction() }
274+
DataFlowCallable getEnclosingCallable() { result = this.getEnclosingFunction() }
275+
276+
/** Gets a best-effort total ordering. */
277+
int totalorder() {
278+
this =
279+
rank[result](DataFlowCall c, int startline, int startcolumn |
280+
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
281+
|
282+
c order by startline, startcolumn
283+
)
284+
}
265285
}
266286

267287
class NodeRegion instanceof Unit {

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,16 @@ class DataFlowCallable extends TDataFlowCallable {
10621062
result = this.asSummarizedCallable() or // SummarizedCallable = Function (in CPP)
10631063
result = this.asSourceCallable()
10641064
}
1065+
1066+
/** Gets a best-effort total ordering. */
1067+
int totalorder() {
1068+
this =
1069+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
1070+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
1071+
|
1072+
c order by file, startline, startcolumn
1073+
)
1074+
}
10651075
}
10661076

10671077
/**
@@ -1159,6 +1169,16 @@ class DataFlowCall extends TDataFlowCall {
11591169
* Gets the location of this call.
11601170
*/
11611171
Location getLocation() { none() }
1172+
1173+
/** Gets a best-effort total ordering. */
1174+
int totalorder() {
1175+
this =
1176+
rank[result](DataFlowCall c, int startline, int startcolumn |
1177+
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
1178+
|
1179+
c order by startline, startcolumn
1180+
)
1181+
}
11621182
}
11631183

11641184
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ class DataFlowCallable extends TDataFlowCallable {
204204
or
205205
result = this.asCapturedVariable().getLocation()
206206
}
207+
208+
/** Gets a best-effort total ordering. */
209+
int totalorder() {
210+
this =
211+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
212+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
213+
|
214+
c order by file, startline, startcolumn
215+
)
216+
}
207217
}
208218

209219
/** A call relevant for data flow. */
@@ -247,6 +257,16 @@ abstract class DataFlowCall extends TDataFlowCall {
247257
) {
248258
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
249259
}
260+
261+
/** Gets a best-effort total ordering. */
262+
int totalorder() {
263+
this =
264+
rank[result](DataFlowCall c, int startline, int startcolumn |
265+
c.hasLocationInfo(_, startline, startcolumn, _, _)
266+
|
267+
c order by startline, startcolumn
268+
)
269+
}
250270
}
251271

252272
/** A non-delegate C# call relevant for data flow. */

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ class DataFlowCallable extends TDataFlowCallable {
310310
this.asSummarizedCallable()
311311
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
312312
}
313+
314+
/** Gets a best-effort total ordering. */
315+
int totalorder() {
316+
this =
317+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
318+
c.hasLocationInfo(file, startline, startcolumn, _, _)
319+
|
320+
c order by file, startline, startcolumn
321+
)
322+
}
313323
}
314324

315325
/** A function call relevant for data flow. */
@@ -333,6 +343,16 @@ class DataFlowCall extends Expr {
333343
or
334344
not exists(this.getEnclosingFunction()) and result.asFileScope() = this.getFile()
335345
}
346+
347+
/** Gets a best-effort total ordering. */
348+
int totalorder() {
349+
this =
350+
rank[result](DataFlowCall c, int startline, int startcolumn |
351+
c.getLocation().hasLocationInfo(_, startline, startcolumn, _, _)
352+
|
353+
c order by startline, startcolumn
354+
)
355+
}
336356
}
337357

338358
/** Holds if `e` is an expression that always has the same Boolean value `val`. */

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,16 @@ abstract class DataFlowCallable extends TDataFlowCallable {
344344

345345
/** Gets the location of this dataflow callable. */
346346
abstract Location getLocation();
347+
348+
/** Gets a best-effort total ordering. */
349+
int totalorder() {
350+
this =
351+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
352+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
353+
|
354+
c order by file, startline, startcolumn
355+
)
356+
}
347357
}
348358

349359
/** A callable function. */
@@ -1419,6 +1429,16 @@ abstract class DataFlowCall extends TDataFlowCall {
14191429
) {
14201430
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
14211431
}
1432+
1433+
/** Gets a best-effort total ordering. */
1434+
int totalorder() {
1435+
this =
1436+
rank[result](DataFlowCall c, int startline, int startcolumn |
1437+
c.hasLocationInfo(_, startline, startcolumn, _, _)
1438+
|
1439+
c order by startline, startcolumn
1440+
)
1441+
}
14221442
}
14231443

14241444
/** A call found in the program source (as opposed to a synthesised call). */

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ class DataFlowCallable extends TDataFlowCallable {
113113
this instanceof TLibraryCallable and
114114
result instanceof EmptyLocation
115115
}
116+
117+
/** Gets a best-effort total ordering. */
118+
int totalorder() {
119+
this =
120+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
121+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
122+
|
123+
c order by file, startline, startcolumn
124+
)
125+
}
116126
}
117127

118128
/**
@@ -144,6 +154,16 @@ abstract class DataFlowCall extends TDataFlowCall {
144154
) {
145155
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
146156
}
157+
158+
/** Gets a best-effort total ordering. */
159+
int totalorder() {
160+
this =
161+
rank[result](DataFlowCall c, int startline, int startcolumn |
162+
c.hasLocationInfo(_, startline, startcolumn, _, _)
163+
|
164+
c order by startline, startcolumn
165+
)
166+
}
147167
}
148168

149169
/**

swift/ql/lib/codeql/swift/dataflow/internal/DataFlowDispatch.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class DataFlowCallable extends TDataFlowCallable {
6565
Callable::TypeRange getUnderlyingCallable() {
6666
result = this.asSummarizedCallable() or result = this.asSourceCallable()
6767
}
68+
69+
/** Gets a best-effort total ordering. */
70+
int totalorder() {
71+
this =
72+
rank[result](DataFlowCallable c, string file, int startline, int startcolumn |
73+
c.getLocation().hasLocationInfo(file, startline, startcolumn, _, _)
74+
|
75+
c order by file, startline, startcolumn
76+
)
77+
}
6878
}
6979

7080
cached
@@ -120,6 +130,16 @@ class DataFlowCall extends TDataFlowCall {
120130
) {
121131
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
122132
}
133+
134+
/** Gets a best-effort total ordering. */
135+
int totalorder() {
136+
this =
137+
rank[result](DataFlowCall c, int startline, int startcolumn |
138+
c.hasLocationInfo(_, startline, startcolumn, _, _)
139+
|
140+
c order by startline, startcolumn
141+
)
142+
}
123143
}
124144

125145
private class NormalCall extends DataFlowCall, TNormalCall {

0 commit comments

Comments
 (0)