Skip to content

Commit ff53e53

Browse files
authored
Merge pull request github#12236 from MathiasVP/language-specific-field-flow-branch-limit-term
Dataflow: Add a language specific term to `join` and `branch`
2 parents 56b6441 + 92ad099 commit ff53e53

File tree

18 files changed

+198
-0
lines changed

18 files changed

+198
-0
lines changed

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,17 @@ module Impl<FullStateConfigSig Config> {
959959
not inBarrier(p)
960960
}
961961

962+
/**
963+
* Gets an additional term that is added to `branch` and `join` when deciding whether
964+
* the amount of forward or backward branching is within the limit specified by the
965+
* configuration.
966+
*/
967+
pragma[nomagic]
968+
private int getLanguageSpecificFlowIntoCallNodeCand1(ArgNodeEx arg, ParamNodeEx p) {
969+
flowIntoCallNodeCand1(_, arg, p) and
970+
result = getAdditionalFlowIntoCallNodeTerm(arg.projectToNode(), p.projectToNode())
971+
}
972+
962973
/**
963974
* Gets the amount of forward branching on the origin of a cross-call path
964975
* edge in the graph of paths between sources and sinks that ignores call
@@ -968,6 +979,7 @@ module Impl<FullStateConfigSig Config> {
968979
private int branch(NodeEx n1) {
969980
result =
970981
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n1, _, n) or flowIntoCallNodeCand1(_, n1, n))
982+
+ sum(ParamNodeEx p1 | | getLanguageSpecificFlowIntoCallNodeCand1(n1, p1))
971983
}
972984

973985
/**
@@ -979,6 +991,7 @@ module Impl<FullStateConfigSig Config> {
979991
private int join(NodeEx n2) {
980992
result =
981993
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n, _, n2) or flowIntoCallNodeCand1(_, n, n2))
994+
+ sum(ArgNodeEx arg2 | | getLanguageSpecificFlowIntoCallNodeCand1(arg2, n2))
982995
}
983996

984997
/**

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,12 @@ private class MyConsistencyConfiguration extends Consistency::ConsistencyConfigu
565565
any()
566566
}
567567
}
568+
569+
/**
570+
* Gets an additional term that is added to the `join` and `branch` computations to reflect
571+
* an additional forward or backwards branching factor that is not taken into account
572+
* when calculating the (virtual) dispatch cost.
573+
*
574+
* Argument `arg` is part of a path from a source to a sink, and `p` is the target parameter.
575+
*/
576+
int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,17 @@ module Impl<FullStateConfigSig Config> {
959959
not inBarrier(p)
960960
}
961961

962+
/**
963+
* Gets an additional term that is added to `branch` and `join` when deciding whether
964+
* the amount of forward or backward branching is within the limit specified by the
965+
* configuration.
966+
*/
967+
pragma[nomagic]
968+
private int getLanguageSpecificFlowIntoCallNodeCand1(ArgNodeEx arg, ParamNodeEx p) {
969+
flowIntoCallNodeCand1(_, arg, p) and
970+
result = getAdditionalFlowIntoCallNodeTerm(arg.projectToNode(), p.projectToNode())
971+
}
972+
962973
/**
963974
* Gets the amount of forward branching on the origin of a cross-call path
964975
* edge in the graph of paths between sources and sinks that ignores call
@@ -968,6 +979,7 @@ module Impl<FullStateConfigSig Config> {
968979
private int branch(NodeEx n1) {
969980
result =
970981
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n1, _, n) or flowIntoCallNodeCand1(_, n1, n))
982+
+ sum(ParamNodeEx p1 | | getLanguageSpecificFlowIntoCallNodeCand1(n1, p1))
971983
}
972984

973985
/**
@@ -979,6 +991,7 @@ module Impl<FullStateConfigSig Config> {
979991
private int join(NodeEx n2) {
980992
result =
981993
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n, _, n2) or flowIntoCallNodeCand1(_, n, n2))
994+
+ sum(ArgNodeEx arg2 | | getLanguageSpecificFlowIntoCallNodeCand1(arg2, n2))
982995
}
983996

984997
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,12 @@ private class MyConsistencyConfiguration extends Consistency::ConsistencyConfigu
318318
// consistency alerts enough that most of them are interesting.
319319
}
320320
}
321+
322+
/**
323+
* Gets an additional term that is added to the `join` and `branch` computations to reflect
324+
* an additional forward or backwards branching factor that is not taken into account
325+
* when calculating the (virtual) dispatch cost.
326+
*
327+
* Argument `arg` is part of a path from a source to a sink, and `p` is the target parameter.
328+
*/
329+
int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,17 @@ module Impl<FullStateConfigSig Config> {
959959
not inBarrier(p)
960960
}
961961

962+
/**
963+
* Gets an additional term that is added to `branch` and `join` when deciding whether
964+
* the amount of forward or backward branching is within the limit specified by the
965+
* configuration.
966+
*/
967+
pragma[nomagic]
968+
private int getLanguageSpecificFlowIntoCallNodeCand1(ArgNodeEx arg, ParamNodeEx p) {
969+
flowIntoCallNodeCand1(_, arg, p) and
970+
result = getAdditionalFlowIntoCallNodeTerm(arg.projectToNode(), p.projectToNode())
971+
}
972+
962973
/**
963974
* Gets the amount of forward branching on the origin of a cross-call path
964975
* edge in the graph of paths between sources and sinks that ignores call
@@ -968,6 +979,7 @@ module Impl<FullStateConfigSig Config> {
968979
private int branch(NodeEx n1) {
969980
result =
970981
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n1, _, n) or flowIntoCallNodeCand1(_, n1, n))
982+
+ sum(ParamNodeEx p1 | | getLanguageSpecificFlowIntoCallNodeCand1(n1, p1))
971983
}
972984

973985
/**
@@ -979,6 +991,7 @@ module Impl<FullStateConfigSig Config> {
979991
private int join(NodeEx n2) {
980992
result =
981993
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n, _, n2) or flowIntoCallNodeCand1(_, n, n2))
994+
+ sum(ArgNodeEx arg2 | | getLanguageSpecificFlowIntoCallNodeCand1(arg2, n2))
982995
}
983996

984997
/**

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,12 @@ private class MyConsistencyConfiguration extends Consistency::ConsistencyConfigu
414414
any()
415415
}
416416
}
417+
418+
/**
419+
* Gets an additional term that is added to the `join` and `branch` computations to reflect
420+
* an additional forward or backwards branching factor that is not taken into account
421+
* when calculating the (virtual) dispatch cost.
422+
*
423+
* Argument `arg` is part of a path from a source to a sink, and `p` is the target parameter.
424+
*/
425+
int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,17 @@ module Impl<FullStateConfigSig Config> {
959959
not inBarrier(p)
960960
}
961961

962+
/**
963+
* Gets an additional term that is added to `branch` and `join` when deciding whether
964+
* the amount of forward or backward branching is within the limit specified by the
965+
* configuration.
966+
*/
967+
pragma[nomagic]
968+
private int getLanguageSpecificFlowIntoCallNodeCand1(ArgNodeEx arg, ParamNodeEx p) {
969+
flowIntoCallNodeCand1(_, arg, p) and
970+
result = getAdditionalFlowIntoCallNodeTerm(arg.projectToNode(), p.projectToNode())
971+
}
972+
962973
/**
963974
* Gets the amount of forward branching on the origin of a cross-call path
964975
* edge in the graph of paths between sources and sinks that ignores call
@@ -968,6 +979,7 @@ module Impl<FullStateConfigSig Config> {
968979
private int branch(NodeEx n1) {
969980
result =
970981
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n1, _, n) or flowIntoCallNodeCand1(_, n1, n))
982+
+ sum(ParamNodeEx p1 | | getLanguageSpecificFlowIntoCallNodeCand1(n1, p1))
971983
}
972984

973985
/**
@@ -979,6 +991,7 @@ module Impl<FullStateConfigSig Config> {
979991
private int join(NodeEx n2) {
980992
result =
981993
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n, _, n2) or flowIntoCallNodeCand1(_, n, n2))
994+
+ sum(ArgNodeEx arg2 | | getLanguageSpecificFlowIntoCallNodeCand1(arg2, n2))
982995
}
983996

984997
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,3 +2374,12 @@ module Csv {
23742374
)
23752375
}
23762376
}
2377+
2378+
/**
2379+
* Gets an additional term that is added to the `join` and `branch` computations to reflect
2380+
* an additional forward or backwards branching factor that is not taken into account
2381+
* when calculating the (virtual) dispatch cost.
2382+
*
2383+
* Argument `arg` is part of a path from a source to a sink, and `p` is the target parameter.
2384+
*/
2385+
int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }

go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,17 @@ module Impl<FullStateConfigSig Config> {
959959
not inBarrier(p)
960960
}
961961

962+
/**
963+
* Gets an additional term that is added to `branch` and `join` when deciding whether
964+
* the amount of forward or backward branching is within the limit specified by the
965+
* configuration.
966+
*/
967+
pragma[nomagic]
968+
private int getLanguageSpecificFlowIntoCallNodeCand1(ArgNodeEx arg, ParamNodeEx p) {
969+
flowIntoCallNodeCand1(_, arg, p) and
970+
result = getAdditionalFlowIntoCallNodeTerm(arg.projectToNode(), p.projectToNode())
971+
}
972+
962973
/**
963974
* Gets the amount of forward branching on the origin of a cross-call path
964975
* edge in the graph of paths between sources and sinks that ignores call
@@ -968,6 +979,7 @@ module Impl<FullStateConfigSig Config> {
968979
private int branch(NodeEx n1) {
969980
result =
970981
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n1, _, n) or flowIntoCallNodeCand1(_, n1, n))
982+
+ sum(ParamNodeEx p1 | | getLanguageSpecificFlowIntoCallNodeCand1(n1, p1))
971983
}
972984

973985
/**
@@ -979,6 +991,7 @@ module Impl<FullStateConfigSig Config> {
979991
private int join(NodeEx n2) {
980992
result =
981993
strictcount(NodeEx n | flowOutOfCallNodeCand1(_, n, _, n2) or flowIntoCallNodeCand1(_, n, n2))
994+
+ sum(ArgNodeEx arg2 | | getLanguageSpecificFlowIntoCallNodeCand1(arg2, n2))
982995
}
983996

984997
/**

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,12 @@ class ContentApprox = Unit;
390390
/** Gets an approximated value for content `c`. */
391391
pragma[inline]
392392
ContentApprox getContentApprox(Content c) { any() }
393+
394+
/**
395+
* Gets an additional term that is added to the `join` and `branch` computations to reflect
396+
* an additional forward or backwards branching factor that is not taken into account
397+
* when calculating the (virtual) dispatch cost.
398+
*
399+
* Argument `arg` is part of a path from a source to a sink, and `p` is the target parameter.
400+
*/
401+
int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }

0 commit comments

Comments
 (0)