Skip to content

Commit ace369f

Browse files
committed
Dataflow: Share getCallContextCall in DataFlowImplCommon::CallContextSensitivity.
1 parent b2e3d78 commit ace369f

File tree

2 files changed

+37
-47
lines changed

2 files changed

+37
-47
lines changed

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

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,10 +2558,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25582558
bindingset[call, ctx]
25592559
predicate noPrunedViableImplInCallContext(DataFlowCall call, CallContext ctx);
25602560

2561-
predicate recordDataFlowCallSiteDispatch(DataFlowCall call, DataFlowCallable callable);
2562-
2563-
predicate recordDataFlowCallSiteUnreachable(DataFlowCall call, DataFlowCallable callable);
2564-
25652561
predicate reducedViableImplInReturn(DataFlowCallable c, DataFlowCall call);
25662562

25672563
DataFlowCall prunedViableImplInCallContextReverse(
@@ -2592,38 +2588,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25922588
Input::noPrunedViableImplInCallContext(call, ctx)
25932589
}
25942590

2595-
module NoLocalCallContext {
2596-
class LocalCc = Unit;
2597-
2598-
bindingset[c, cc]
2599-
LocalCc getLocalCc(DataFlowCallable c, Cc cc) { any() }
2600-
2601-
bindingset[call, c]
2602-
CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c) {
2603-
if Input::recordDataFlowCallSiteDispatch(call, c)
2604-
then result = TSpecificCall(call)
2605-
else result = TSomeCall()
2606-
}
2607-
}
2608-
2609-
module LocalCallContext {
2610-
class LocalCc = LocalCallContext;
2611-
2612-
bindingset[c, cc]
2613-
LocalCc getLocalCc(DataFlowCallable c, Cc cc) {
2614-
result = getLocalCallContext(pragma[only_bind_into](pragma[only_bind_out](cc)), c)
2615-
}
2616-
2617-
bindingset[call, c]
2618-
CcCall getCallContextCall(DataFlowCall call, DataFlowCallable c) {
2619-
if
2620-
Input::recordDataFlowCallSiteDispatch(call, c) or
2621-
Input::recordDataFlowCallSiteUnreachable(call, c)
2622-
then result = TSpecificCall(call)
2623-
else result = TSomeCall()
2624-
}
2625-
}
2626-
26272591
DataFlowCall viableImplCallContextReducedReverse(DataFlowCallable c, CcNoCall ctx) {
26282592
result = Input::prunedViableImplInCallContextReverse(c, ctx)
26292593
}
@@ -4323,6 +4287,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
43234287
}
43244288

43254289
import CallContextSensitivity<CallContextSensitivityInput>
4290+
import LocalCallContext
43264291
}
43274292

43284293
pragma[nomagic]
@@ -4421,11 +4386,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
44214386
// never any reason to enter a callable except to find a summary. See also
44224387
// the comment in `PathNodeMid::isAtSink`.
44234388
not Config::getAFeature() instanceof FeatureEqualSourceSinkCallContext
4424-
)
4425-
|
4426-
if PrunedCallContextSensitivityStage5::recordDataFlowCallSite(call, callable)
4427-
then innercc = TSpecificCall(call)
4428-
else innercc = TSomeCall()
4389+
) and
4390+
innercc = PrunedCallContextSensitivityStage5::getCallContextCall(call, callable)
44294391
)
44304392
}
44314393

@@ -5454,11 +5416,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
54545416
sc1 = TSummaryCtx1Param(p) and
54555417
sc2 = TSummaryCtx2Some(state) and
54565418
sc3 = TSummaryCtx3Some(t) and
5457-
sc4 = TSummaryCtx4Some(ap)
5458-
|
5459-
if CachedCallContextSensitivity::recordDataFlowCallSite(call, callable)
5460-
then innercc = TSpecificCall(call)
5461-
else innercc = TSomeCall()
5419+
sc4 = TSummaryCtx4Some(ap) and
5420+
innercc =
5421+
CachedCallContextSensitivity::LocalCallContext::getCallContextCall(call, callable)
54625422
)
54635423
}
54645424

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
615615
* Holds if the call context `call` improves virtual dispatch in `callable`.
616616
*/
617617
pragma[nomagic]
618-
predicate recordDataFlowCallSiteDispatch(DataFlowCall call, DataFlowCallable callable) {
618+
private predicate recordDataFlowCallSiteDispatch(DataFlowCall call, DataFlowCallable callable) {
619619
Input2::reducedViableImplInCallContext(_, callable, call)
620620
}
621621

@@ -627,6 +627,36 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
627627
Input2::recordDataFlowCallSiteUnreachable(call, c) or
628628
recordDataFlowCallSiteDispatch(call, c)
629629
}
630+
631+
module NoLocalCallContext {
632+
class LocalCc = Unit;
633+
634+
bindingset[c, cc]
635+
LocalCc getLocalCc(DataFlowCallable c, CallContext cc) { any() }
636+
637+
bindingset[call, c]
638+
CallContextCall getCallContextCall(DataFlowCall call, DataFlowCallable c) {
639+
if recordDataFlowCallSiteDispatch(call, c)
640+
then result = TSpecificCall(call)
641+
else result = TSomeCall()
642+
}
643+
}
644+
645+
module LocalCallContext {
646+
class LocalCc = LocalCallContext;
647+
648+
bindingset[c, cc]
649+
LocalCc getLocalCc(DataFlowCallable c, CallContext cc) {
650+
result = getLocalCallContext(pragma[only_bind_into](pragma[only_bind_out](cc)), c)
651+
}
652+
653+
bindingset[call, c]
654+
CallContextCall getCallContextCall(DataFlowCall call, DataFlowCallable c) {
655+
if recordDataFlowCallSite(call, c)
656+
then result = TSpecificCall(call)
657+
else result = TSomeCall()
658+
}
659+
}
630660
}
631661

632662
private predicate reducedViableImplInCallContextAlias = reducedViableImplInCallContext/3;

0 commit comments

Comments
 (0)