Skip to content

Commit b2e3d78

Browse files
committed
Dataflow: Share getCallContextReturn in DataFlowImplCommon::CallContextSensitivity.
1 parent 79b1cd7 commit b2e3d78

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,13 +2631,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26312631
predicate viableImplNotCallContextReducedReverse(CcNoCall ctx) {
26322632
ctx instanceof CallContextAny
26332633
}
2634-
2635-
bindingset[call, c]
2636-
CcNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call) {
2637-
if Input::reducedViableImplInReturn(c, call)
2638-
then result = TReturn(c, call)
2639-
else result = ccNone()
2640-
}
26412634
}
26422635

26432636
private module Stage2Param implements MkStage<Stage1>::StageParam {
@@ -2681,6 +2674,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26812674
import CachedCallContextSensitivity
26822675
}
26832676

2677+
import Level1CallContextInput
26842678
import Level1CallContext<Level1CallContextInput>
26852679
import NoLocalCallContext
26862680

@@ -2971,6 +2965,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
29712965
import CallContextSensitivity<CallContextSensitivityInput>
29722966
}
29732967

2968+
import Level1CallContextInput
29742969
import Level1CallContext<Level1CallContextInput>
29752970
import NoLocalCallContext
29762971

@@ -3363,6 +3358,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
33633358
import CallContextSensitivity<CallContextSensitivityInput>
33643359
}
33653360

3361+
import Level1CallContextInput
33663362
import Level1CallContext<Level1CallContextInput>
33673363
import LocalCallContext
33683364

@@ -4338,11 +4334,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
43384334
pathOutOfCallable0(mid, pos, state, innercc, apa) and
43394335
c = pos.getCallable() and
43404336
kind = pos.getKind() and
4341-
PrunedCallContextSensitivityStage5::resolveReturn(innercc, c, call)
4342-
|
4343-
if PrunedCallContextSensitivityStage5::reducedViableImplInReturn(c, call)
4344-
then cc = TReturn(c, call)
4345-
else cc = TAnyCallContext()
4337+
PrunedCallContextSensitivityStage5::resolveReturn(innercc, c, call) and
4338+
cc = PrunedCallContextSensitivityStage5::getCallContextReturn(c, call)
43464339
)
43474340
}
43484341

@@ -5409,11 +5402,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
54095402
partialPathOutOfCallable0(mid, pos, state, innercc, t, ap) and
54105403
c = pos.getCallable() and
54115404
kind = pos.getKind() and
5412-
CachedCallContextSensitivity::resolveReturn(innercc, c, call)
5413-
|
5414-
if CachedCallContextSensitivity::reducedViableImplInReturn(c, call)
5415-
then cc = TReturn(c, call)
5416-
else cc = TAnyCallContext()
5405+
CachedCallContextSensitivity::resolveReturn(innercc, c, call) and
5406+
cc = CachedCallContextSensitivity::getCallContextReturn(c, call)
54175407
)
54185408
}
54195409

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,14 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
603603
call = prunedViableImplInCallContextReverse(callable, cc)
604604
}
605605

606+
/** Gets the call context when returning from `c` to `call`. */
607+
bindingset[call, c]
608+
CallContextNoCall getCallContextReturn(DataFlowCallable c, DataFlowCall call) {
609+
if Input2::reducedViableImplInReturn(c, call)
610+
then result = TReturn(c, call)
611+
else result = TAnyCallContext()
612+
}
613+
606614
/**
607615
* Holds if the call context `call` improves virtual dispatch in `callable`.
608616
*/

0 commit comments

Comments
 (0)