Skip to content

Commit d6a4080

Browse files
committed
Dataflow: Address review comment.
1 parent da17970 commit d6a4080

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

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

+17-19
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,11 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
14271427
)
14281428
}
14291429

1430+
bindingset[ap]
1431+
private boolean isNil(Ap ap) {
1432+
if ap instanceof ApNil then result = true else result = false
1433+
}
1434+
14301435
/* Begin: Stage logic. */
14311436
pragma[nomagic]
14321437
private Typ getNodeTyp(NodeEx node) {
@@ -1719,7 +1724,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
17191724
) {
17201725
fwdFlow(arg, state, outercc, summaryCtx, t, ap, stored) and
17211726
(if instanceofCcCall(outercc) then cc = true else cc = false) and
1722-
if ap instanceof ApNil then emptyAp = true else emptyAp = false
1727+
emptyAp = isNil(ap)
17231728
}
17241729

17251730
private signature predicate flowThroughSig();
@@ -2161,25 +2166,21 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21612166
private predicate flowThroughIntoCall(
21622167
DataFlowCall call, ArgNodeEx arg, ParamNodeEx p, Ap argAp, Ap ap
21632168
) {
2164-
exists(Typ argT, TypOption argStored, boolean emptyArgAp |
2169+
exists(Typ argT, TypOption argStored |
21652170
returnFlowsThrough(_, _, _, _, pragma[only_bind_into](p), pragma[only_bind_into](argT),
21662171
pragma[only_bind_into](argAp), pragma[only_bind_into](argStored), ap) and
2167-
flowIntoCallApaTaken(call, _, pragma[only_bind_into](arg), p, emptyArgAp) and
2172+
flowIntoCallApaTaken(call, _, pragma[only_bind_into](arg), p, isNil(argAp)) and
21682173
fwdFlow(arg, _, _, _, pragma[only_bind_into](argT), pragma[only_bind_into](argAp),
2169-
pragma[only_bind_into](argStored)) and
2170-
if argAp instanceof ApNil then emptyArgAp = true else emptyArgAp = false
2174+
pragma[only_bind_into](argStored))
21712175
)
21722176
}
21732177

21742178
pragma[nomagic]
21752179
private predicate flowIntoCallAp(
21762180
DataFlowCall call, DataFlowCallable c, ArgNodeEx arg, ParamNodeEx p, Ap ap
21772181
) {
2178-
exists(boolean emptyAp |
2179-
flowIntoCallApaTaken(call, c, arg, p, emptyAp) and
2180-
fwdFlow(arg, _, _, _, _, ap, _) and
2181-
if ap instanceof ApNil then emptyAp = true else emptyAp = false
2182-
)
2182+
flowIntoCallApaTaken(call, c, arg, p, isNil(ap)) and
2183+
fwdFlow(arg, _, _, _, _, ap, _)
21832184
}
21842185

21852186
pragma[nomagic]
@@ -2405,13 +2406,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
24052406
private predicate revFlowParamToReturn(
24062407
ParamNodeEx p, FlowState state, ReturnPosition pos, Ap returnAp, Ap ap
24072408
) {
2408-
exists(boolean emptyAp |
2409-
revFlow(pragma[only_bind_into](p), state, TReturnCtxMaybeFlowThrough(pos),
2410-
apSome(returnAp), pragma[only_bind_into](ap)) and
2411-
parameterFlowThroughAllowed(p, pos.getKind()) and
2412-
PrevStage::parameterMayFlowThrough(p, emptyAp) and
2413-
if ap instanceof ApNil then emptyAp = true else emptyAp = false
2414-
)
2409+
revFlow(pragma[only_bind_into](p), state, TReturnCtxMaybeFlowThrough(pos),
2410+
apSome(returnAp), pragma[only_bind_into](ap)) and
2411+
parameterFlowThroughAllowed(p, pos.getKind()) and
2412+
PrevStage::parameterMayFlowThrough(p, isNil(ap))
24152413
}
24162414

24172415
pragma[nomagic]
@@ -2512,7 +2510,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25122510
predicate parameterMayFlowThrough(ParamNodeEx p, boolean emptyAp) {
25132511
exists(Ap ap |
25142512
parameterMayFlowThroughAp(p, ap) and
2515-
if ap instanceof ApNil then emptyAp = true else emptyAp = false
2513+
emptyAp = isNil(ap)
25162514
)
25172515
}
25182516

@@ -2572,7 +2570,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25722570
flowIntoCallAp(call, c, arg, p, ap) and
25732571
revFlow(arg, pragma[only_bind_into](state), pragma[only_bind_into](ap)) and
25742572
revFlow(p, pragma[only_bind_into](state), pragma[only_bind_into](ap)) and
2575-
if ap instanceof ApNil then emptyAp = true else emptyAp = false
2573+
emptyAp = isNil(ap)
25762574
|
25772575
// both directions are needed for flow-through
25782576
RevTypeFlowInput::dataFlowTakenCallEdgeIn(call, c, _) or

0 commit comments

Comments
 (0)