Skip to content

Commit 0988340

Browse files
committed
Simplify revFlowThrough
Observations: * revFlowThrough can be much larger than the other reverse-flow predicates, presumably when there are many different innerReturnAps. * It is only ever used in conjunction with flowThroughIntoCall, which can therefore be pushed in, and several of its parameters can thereby be dropped in exchange for exposing `arg`. * `revFlowThroughArg` can then be trivially inlined. Result: on repository `go-gitea/gitea` with PR #17701 producing a wider selection of access paths than are seen on `main`, `revFlowThrough` drops in size from ~120m tuples to ~4m, and the runtime of the reverse-flow computation for dataflow stage 4 goes from dominating the forward-flow cost to relatively insignificant. Overall runtime falls from 3 minutes to 2 with substantial ram available, and presumably falls much more under GHA-style memory pressure.
1 parent 9861af8 commit 0988340

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

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

+9-20
Original file line numberDiff line numberDiff line change
@@ -2261,10 +2261,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
22612261
returnAp = apNone()
22622262
or
22632263
// flow through a callable
2264-
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
2265-
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp) and
2266-
flowThroughIntoCall(call, node, p, ap, innerReturnAp)
2267-
)
2264+
revFlowThrough(_, returnCtx, state, returnAp, ap, node)
22682265
or
22692266
// flow out of a callable
22702267
exists(ReturnPosition pos |
@@ -2413,11 +2410,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
24132410

24142411
pragma[nomagic]
24152412
private predicate revFlowThrough(
2416-
DataFlowCall call, ReturnCtx returnCtx, ParamNodeEx p, FlowState state,
2417-
ReturnPosition pos, ApOption returnAp, Ap ap, Ap innerReturnAp
2413+
DataFlowCall call, ReturnCtx returnCtx, FlowState state, ApOption returnAp, Ap ap,
2414+
ArgNodeEx arg
24182415
) {
2419-
revFlowParamToReturn(p, state, pos, innerReturnAp, ap) and
2420-
revFlowIsReturned(call, returnCtx, returnAp, pos, innerReturnAp)
2416+
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
2417+
flowThroughIntoCall(call, arg, p, ap, innerReturnAp) and
2418+
revFlowParamToReturn(p, state, pos, innerReturnAp, ap) and
2419+
revFlowIsReturned(call, returnCtx, returnAp, pos, innerReturnAp)
2420+
)
24212421
}
24222422

24232423
/**
@@ -2543,22 +2543,11 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25432543
)
25442544
}
25452545

2546-
pragma[nomagic]
2547-
private predicate revFlowThroughArg(
2548-
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
2549-
Ap ap
2550-
) {
2551-
exists(ParamNodeEx p, Ap innerReturnAp |
2552-
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp) and
2553-
flowThroughIntoCall(call, arg, p, ap, innerReturnAp)
2554-
)
2555-
}
2556-
25572546
pragma[nomagic]
25582547
predicate callMayFlowThroughRev(DataFlowCall call) {
25592548
exists(ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap |
25602549
revFlow(arg, state, returnCtx, returnAp, ap) and
2561-
revFlowThroughArg(call, arg, state, returnCtx, returnAp, ap)
2550+
revFlowThrough(call, returnCtx, state, returnAp, ap, arg)
25622551
)
25632552
}
25642553

0 commit comments

Comments
 (0)