Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e13b87

Browse files
committed
C++: Add FlowSummaryNode and test it.
1 parent e187a4a commit 6e13b87

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ private newtype TIRDataFlowNode =
5757
hasFinalParameterNode(_, p, indirectionIndex)
5858
} or
5959
TFinalGlobalValue(Ssa::GlobalUse globalUse) or
60-
TInitialGlobalValue(Ssa::GlobalDef globalUse)
60+
TInitialGlobalValue(Ssa::GlobalDef globalUse) or
61+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
6162

6263
/**
6364
* Holds if `(p, indirectionIndex)` should define a `TFinalParameterNode`
@@ -760,6 +761,31 @@ class InitialGlobalValue extends Node, TInitialGlobalValue {
760761
override string toStringImpl() { result = globalDef.toString() }
761762
}
762763

764+
/**
765+
* A data-flow node used to model flow summaries.
766+
*/
767+
class FlowSummaryNode extends Node, TFlowSummaryNode {
768+
FlowSummaryImpl::Private::SummaryNode getSummaryNode() { this = TFlowSummaryNode(result) }
769+
770+
/**
771+
* TODO: QLDoc.
772+
*/
773+
FlowSummaryImpl::Public::SummarizedCallable getSummarizedCallable() {
774+
result = this.getSummaryNode().getSummarizedCallable()
775+
}
776+
777+
/**
778+
* TODO: QLDoc.
779+
*/
780+
override DataFlowCallable getEnclosingCallable() {
781+
none() //result.asSummarizedCallable() = this.getSummarizedCallable() TODO
782+
}
783+
784+
override Location getLocationImpl() { result = this.getSummarizedCallable().getLocation() }
785+
786+
override string toStringImpl() { result = this.getSummaryNode().toString() }
787+
}
788+
763789
/**
764790
* INTERNAL: do not use.
765791
*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
| tests.cpp:115:5:115:19 | [summary param] 0 in madArg0ToReturn | | madArg0ToReturn | |
2+
| tests.cpp:115:5:115:19 | [summary] to write: ReturnValue in madArg0ToReturn | | madArg0ToReturn | |
3+
| tests.cpp:117:5:117:28 | [summary param] 0 in madArg0ToReturnValueFlow | | madArg0ToReturnValueFlow | |
4+
| tests.cpp:117:5:117:28 | [summary] to write: ReturnValue in madArg0ToReturnValueFlow | | madArg0ToReturnValueFlow | |
5+
| tests.cpp:119:6:119:18 | [summary param] 0 in madArg0ToArg1 | | madArg0ToArg1 | |
6+
| tests.cpp:119:6:119:18 | [summary param] 1 in madArg0ToArg1 | | madArg0ToArg1 | |
7+
| tests.cpp:119:6:119:18 | [summary] to write: Argument[1] in madArg0ToArg1 | | madArg0ToArg1 | |
8+
| tests.cpp:180:7:180:19 | [summary param] 0 in madArg0ToSelf | | madArg0ToSelf | |
9+
| tests.cpp:180:7:180:19 | [summary param] this in madArg0ToSelf | | madArg0ToSelf | |
10+
| tests.cpp:180:7:180:19 | [summary] to write: Argument[this] in madArg0ToSelf | | madArg0ToSelf | |
11+
| tests.cpp:181:6:181:20 | [summary param] this in madSelfToReturn | | madSelfToReturn | |
12+
| tests.cpp:181:6:181:20 | [summary] to write: ReturnValue in madSelfToReturn | | madSelfToReturn | |
13+
| tests.cpp:209:7:209:30 | [summary param] this in namespaceMadSelfToReturn | | namespaceMadSelfToReturn | |
14+
| tests.cpp:209:7:209:30 | [summary] to write: ReturnValue in namespaceMadSelfToReturn | | namespaceMadSelfToReturn | |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import testModels
2+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
3+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
4+
5+
string describe(DataFlow::Node n) {
6+
n instanceof ParameterNode and result = "ParameterNode"
7+
or
8+
n instanceof PostUpdateNode and result = "PostUpdateNode"
9+
or
10+
n instanceof ArgumentNode and result = "ArgumentNode"
11+
or
12+
n instanceof ReturnNode and result = "ReturnNode"
13+
or
14+
n instanceof OutNode and result = "OutNode"
15+
}
16+
17+
from FlowSummaryNode n
18+
select n, concat(describe(n), ", "), concat(n.getSummarizedCallable().toString(), ", "), concat(n.getEnclosingCallable().toString(), ", ")

0 commit comments

Comments
 (0)