Skip to content

Commit 383799c

Browse files
committed
C++: Perform 6 rounds of virtual dispatch resolution like Java.
1 parent d4188d5 commit 383799c

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
@@ -281,6 +281,47 @@ private module TrackVirtualDispatch<methodDispatchSig/1 lambdaDispatch0> {
281281
}
282282
}
283283

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

0 commit comments

Comments
 (0)