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

Skip to content

Commit e11b4b6

Browse files
C++: Fix IR Dataflow PR feedback
1 parent 2822d14 commit e11b4b6

5 files changed

Lines changed: 58 additions & 196 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/DataFlow.qll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/**
22
* Provides a library for local (intra-procedural) and global (inter-procedural)
33
* data flow analysis: deciding whether data can flow from a _source_ to a
4-
* _sink_.
4+
* _sink_. This library differs from the one in `semmle.code.cpp.dataflow` in that
5+
* this library uses the IR (Intermediate Representation) library, which provides
6+
* a more precise semantic representation of the program, whereas the other dataflow
7+
* library uses the more syntax-oriented ASTs. This library should provide more accurate
8+
* results than the AST-based library in most scenarios.
59
*
610
* Unless configured otherwise, _flow_ means that the exact value of
711
* the source may reach the sink. We do not track flow across pointer
8-
* dereferences or array indexing. To track these types of flow, where the
9-
* exact value may not be preserved, import
10-
* `semmle.code.cpp.dataflow.TaintTracking`.
12+
* dereferences or array indexing.
1113
*
1214
* To use global (interprocedural) data flow, extend the class
1315
* `DataFlow::Configuration` as documented on that class. To use local

cpp/ql/src/semmle/code/cpp/ir/dataflow/TaintTracking.qll

Lines changed: 0 additions & 189 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ private import DataFlowUtil
33

44
/**
55
* A data flow node that occurs as the argument of a call and is passed as-is
6-
* to the callable. Arguments that are wrapped in an implicit varargs array
7-
* creation are not included, but the implicitly created array is.
8-
* Instance arguments are also included.
6+
* to the callable. Instance arguments (`this` pointer) are also included.
97
*/
108
class ArgumentNode extends Node {
119
ArgumentNode() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
| test.cpp:6:12:6:17 | test.cpp:21:8:21:9 | IR only |
2+
| test.cpp:66:30:66:36 | test.cpp:71:8:71:9 | AST only |
3+
| test.cpp:89:28:89:34 | test.cpp:92:8:92:14 | IR only |
4+
| test.cpp:100:13:100:18 | test.cpp:103:10:103:12 | AST only |
5+
| test.cpp:120:9:120:20 | test.cpp:126:8:126:19 | AST only |
6+
| test.cpp:122:18:122:30 | test.cpp:132:22:132:23 | IR only |
7+
| test.cpp:122:18:122:30 | test.cpp:140:22:140:23 | IR only |
8+
| test.cpp:136:27:136:32 | test.cpp:137:27:137:28 | AST only |
9+
| test.cpp:136:27:136:32 | test.cpp:140:22:140:23 | AST only |
10+
| test.cpp:395:17:395:22 | test.cpp:397:10:397:18 | AST only |
11+
| test.cpp:421:13:421:18 | test.cpp:423:10:423:14 | AST only |
12+
| true_upon_entry.cpp:9:11:9:16 | true_upon_entry.cpp:13:8:13:8 | IR only |
13+
| true_upon_entry.cpp:62:11:62:16 | true_upon_entry.cpp:66:8:66:8 | IR only |
14+
| true_upon_entry.cpp:98:11:98:16 | true_upon_entry.cpp:105:8:105:8 | IR only |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import cpp
2+
import DataflowTestCommon as ASTCommon
3+
import IRDataflowTestCommon as IRCommon
4+
import semmle.code.cpp.dataflow.DataFlow as ASTDataFlow
5+
import semmle.code.cpp.ir.dataflow.DataFlow as IRDataFlow
6+
7+
predicate astFlow(Location sourceLocation, Location sinkLocation) {
8+
exists(ASTDataFlow::DataFlow::Node source, ASTDataFlow::DataFlow::Node sink,
9+
ASTCommon::TestAllocationConfig cfg |
10+
cfg.hasFlow(source, sink) and
11+
sourceLocation = source.getLocation() and
12+
sinkLocation = sink.getLocation()
13+
)
14+
}
15+
16+
predicate irFlow(Location sourceLocation, Location sinkLocation) {
17+
exists(IRDataFlow::DataFlow::Node source, IRDataFlow::DataFlow::Node sink,
18+
IRCommon::TestAllocationConfig cfg |
19+
cfg.hasFlow(source, sink) and
20+
sourceLocation = source.getLocation() and
21+
sinkLocation = sink.getLocation()
22+
)
23+
}
24+
25+
from Location sourceLocation, Location sinkLocation, string note
26+
where
27+
(
28+
astFlow(sourceLocation, sinkLocation) and
29+
not irFlow(sourceLocation, sinkLocation) and
30+
note = "AST only"
31+
) or
32+
(
33+
irFlow(sourceLocation, sinkLocation) and
34+
not astFlow(sourceLocation, sinkLocation) and
35+
note = "IR only"
36+
)
37+
select sourceLocation.toString(), sinkLocation.toString(), note

0 commit comments

Comments
 (0)