Skip to content

Commit 9f611d7

Browse files
committed
C#: Rank summaries and source code such that only one is used.
1 parent 5119de8 commit 9f611d7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,26 @@ newtype TReturnKind =
8383
)
8484
}
8585

86+
/**
87+
* Holds if the summary for `c` should be used for dataflow analysis.
88+
*/
89+
predicate useFlowSummary(FlowSummary::SummarizedCallable c) {
90+
not c.fromSource()
91+
or
92+
c.fromSource() and not c.isAutoGenerated()
93+
}
94+
8695
private module Cached {
96+
/**
97+
* The following heuristic is used to rank when to use source code or when to use summaries for DataFlowCallables.
98+
* 1. Use hand written summaries.
99+
* 2. Use source code.
100+
* 3. Use auto generated summaries.
101+
*/
87102
cached
88103
newtype TDataFlowCallable =
89-
TDotNetCallable(DotNet::Callable c) {
90-
c.isUnboundDeclaration() and not c instanceof FlowSummary::SummarizedCallable
91-
} or
92-
TSummarizedCallable(FlowSummary::SummarizedCallable c)
104+
TDotNetCallable(DotNet::Callable c) { c.isUnboundDeclaration() and not useFlowSummary(c) } or
105+
TSummarizedCallable(FlowSummary::SummarizedCallable c) { useFlowSummary(c) }
93106

94107
cached
95108
newtype TDataFlowCall =

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,11 @@ private module Cached {
743743
FlowSummaryImpl::Public::SummarizedCallable c,
744744
FlowSummaryImpl::Private::SummaryNodeState state
745745
) {
746+
useFlowSummary(c) and
746747
FlowSummaryImpl::Private::summaryNodeRange(c, state)
747748
} or
748749
TSummaryParameterNode(FlowSummaryImpl::Public::SummarizedCallable c, ParameterPosition pos) {
750+
useFlowSummary(c) and
749751
FlowSummaryImpl::Private::summaryParameterNodeRange(c, pos)
750752
} or
751753
TParamsArgumentNode(ControlFlow::Node callCfn) {

0 commit comments

Comments
 (0)