Skip to content

Commit 2580ea2

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 github#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 01db675 commit 2580ea2

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,10 +2285,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
22852285
returnAp = apNone()
22862286
or
22872287
// flow through a callable
2288-
exists(DataFlowCall call, ParamNodeEx p, Ap innerReturnAp |
2289-
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp) and
2290-
flowThroughIntoCall(call, node, p, ap, innerReturnAp)
2291-
)
2288+
revFlowThrough(_, returnCtx, state, returnAp, ap, node)
22922289
or
22932290
// flow out of a callable
22942291
exists(ReturnPosition pos |
@@ -2437,11 +2434,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
24372434

24382435
pragma[nomagic]
24392436
private predicate revFlowThrough(
2440-
DataFlowCall call, ReturnCtx returnCtx, ParamNodeEx p, FlowState state,
2441-
ReturnPosition pos, ApOption returnAp, Ap ap, Ap innerReturnAp
2437+
DataFlowCall call, ReturnCtx returnCtx, FlowState state, ApOption returnAp, Ap ap,
2438+
ArgNodeEx arg
24422439
) {
2443-
revFlowParamToReturn(p, state, pos, innerReturnAp, ap) and
2444-
revFlowIsReturned(call, returnCtx, returnAp, pos, innerReturnAp)
2440+
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
2441+
flowThroughIntoCall(call, arg, p, ap, innerReturnAp) and
2442+
revFlowParamToReturn(p, state, pos, innerReturnAp, ap) and
2443+
revFlowIsReturned(call, returnCtx, returnAp, pos, innerReturnAp)
2444+
)
24452445
}
24462446

24472447
/**
@@ -2562,22 +2562,11 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25622562
)
25632563
}
25642564

2565-
pragma[nomagic]
2566-
private predicate revFlowThroughArg(
2567-
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
2568-
Ap ap
2569-
) {
2570-
exists(ParamNodeEx p, Ap innerReturnAp |
2571-
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp) and
2572-
flowThroughIntoCall(call, arg, p, ap, innerReturnAp)
2573-
)
2574-
}
2575-
25762565
pragma[nomagic]
25772566
predicate callMayFlowThroughRev(DataFlowCall call) {
25782567
exists(ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap |
25792568
revFlow(arg, state, returnCtx, returnAp, ap) and
2580-
revFlowThroughArg(call, arg, state, returnCtx, returnAp, ap)
2569+
revFlowThrough(call, returnCtx, state, returnAp, ap, arg)
25812570
)
25822571
}
25832572

0 commit comments

Comments
 (0)