Skip to content

Commit aa251cf

Browse files
committed
C++: Perform 6 rounds of virtual dispatch resolution like Java.
1 parent ec233de commit aa251cf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,47 @@ private module TrackVirtualDispatch<methodDispatchSig/1 lambdaDispatch0> {
279279
}
280280
}
281281

282+
private DataFlowPrivate::DataFlowCallable noDisp(DataFlowPrivate::DataFlowCall call) { none() }
283+
284+
pragma[nomagic]
285+
private DataFlowPrivate::DataFlowCallable d1(DataFlowPrivate::DataFlowCall call) {
286+
result = TrackVirtualDispatch<noDisp/1>::lambdaDispatch(call)
287+
}
288+
289+
pragma[nomagic]
290+
private DataFlowPrivate::DataFlowCallable d2(DataFlowPrivate::DataFlowCall call) {
291+
result = TrackVirtualDispatch<d1/1>::lambdaDispatch(call)
292+
}
293+
294+
pragma[nomagic]
295+
private DataFlowPrivate::DataFlowCallable d3(DataFlowPrivate::DataFlowCall call) {
296+
result = TrackVirtualDispatch<d2/1>::lambdaDispatch(call)
297+
}
298+
299+
pragma[nomagic]
300+
private DataFlowPrivate::DataFlowCallable d4(DataFlowPrivate::DataFlowCall call) {
301+
result = TrackVirtualDispatch<d3/1>::lambdaDispatch(call)
302+
}
303+
304+
pragma[nomagic]
305+
private DataFlowPrivate::DataFlowCallable d5(DataFlowPrivate::DataFlowCall call) {
306+
result = TrackVirtualDispatch<d4/1>::lambdaDispatch(call)
307+
}
308+
309+
pragma[nomagic]
310+
private DataFlowPrivate::DataFlowCallable d6(DataFlowPrivate::DataFlowCall call) {
311+
result = TrackVirtualDispatch<d5/1>::lambdaDispatch(call)
312+
}
313+
314+
/** Gets a function that might be called by `call`. */
315+
cached
316+
DataFlowPrivate::DataFlowCallable viableCallable(DataFlowPrivate::DataFlowCall call) {
317+
not exists(d6(call)) and
318+
result = nonVirtualDispatch(call)
319+
or
320+
result = d6(call)
321+
}
322+
282323
/**
283324
* Holds if the set of viable implementations that can be called by `call`
284325
* might be improved by knowing the call context.

0 commit comments

Comments
 (0)