Skip to content

Commit c962dbe

Browse files
committed
Convert DoNotSubtractPointersAddressingDifferentArrays to use new dataflow library
1 parent 8080952 commit c962dbe

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

c/common/test/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.expected

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,27 @@ problems
44
| test.c:13:10:13:11 | p4 | test.c:5:14:5:15 | l2 | test.c:13:10:13:11 | p4 | Subtraction between left operand pointing to array $@ and other operand pointing to array $@. | test.c:3:7:3:8 | l2 | l2 | test.c:2:7:2:8 | l1 | l1 |
55
| test.c:13:15:13:16 | l1 | test.c:13:15:13:16 | l1 | test.c:13:15:13:16 | l1 | Subtraction between right operand pointing to array $@ and other operand pointing to array $@. | test.c:2:7:2:8 | l1 | l1 | test.c:3:7:3:8 | l2 | l2 |
66
edges
7-
| test.c:4:14:4:15 | l1 | test.c:4:14:4:18 | access to array | provenance | Config |
8-
| test.c:4:14:4:18 | access to array | test.c:10:10:10:11 | p1 | provenance | |
9-
| test.c:4:14:4:18 | access to array | test.c:12:10:12:11 | p1 | provenance | |
10-
| test.c:5:14:5:15 | l2 | test.c:5:14:5:19 | access to array | provenance | Config |
11-
| test.c:5:14:5:19 | access to array | test.c:11:10:11:11 | p2 | provenance | |
12-
| test.c:5:14:5:19 | access to array | test.c:12:15:12:16 | p2 | provenance | |
13-
| test.c:5:14:5:19 | access to array | test.c:13:10:13:11 | p4 | provenance | |
14-
| test.c:5:14:5:19 | access to array | test.c:14:10:14:11 | p4 | provenance | |
7+
| test.c:4:13:4:18 | & ... | test.c:4:13:4:18 | & ... | provenance | |
8+
| test.c:4:13:4:18 | & ... | test.c:10:10:10:11 | p1 | provenance | |
9+
| test.c:4:13:4:18 | & ... | test.c:12:10:12:11 | p1 | provenance | |
10+
| test.c:4:14:4:15 | l1 | test.c:4:13:4:18 | & ... | provenance | Config |
11+
| test.c:5:13:5:19 | & ... | test.c:5:13:5:19 | & ... | provenance | |
12+
| test.c:5:13:5:19 | & ... | test.c:6:13:6:14 | p2 | provenance | |
13+
| test.c:5:13:5:19 | & ... | test.c:11:10:11:11 | p2 | provenance | |
14+
| test.c:5:13:5:19 | & ... | test.c:12:15:12:16 | p2 | provenance | |
15+
| test.c:5:14:5:15 | l2 | test.c:5:13:5:19 | & ... | provenance | Config |
16+
| test.c:6:13:6:14 | p2 | test.c:7:13:7:14 | p3 | provenance | |
17+
| test.c:7:13:7:14 | p3 | test.c:13:10:13:11 | p4 | provenance | |
18+
| test.c:7:13:7:14 | p3 | test.c:14:10:14:11 | p4 | provenance | |
1519
nodes
20+
| test.c:4:13:4:18 | & ... | semmle.label | & ... |
21+
| test.c:4:13:4:18 | & ... | semmle.label | & ... |
1622
| test.c:4:14:4:15 | l1 | semmle.label | l1 |
17-
| test.c:4:14:4:18 | access to array | semmle.label | access to array |
23+
| test.c:5:13:5:19 | & ... | semmle.label | & ... |
24+
| test.c:5:13:5:19 | & ... | semmle.label | & ... |
1825
| test.c:5:14:5:15 | l2 | semmle.label | l2 |
19-
| test.c:5:14:5:19 | access to array | semmle.label | access to array |
26+
| test.c:6:13:6:14 | p2 | semmle.label | p2 |
27+
| test.c:7:13:7:14 | p3 | semmle.label | p3 |
2028
| test.c:10:10:10:11 | p1 | semmle.label | p1 |
2129
| test.c:10:15:10:16 | l1 | semmle.label | l1 |
2230
| test.c:11:10:11:11 | p2 | semmle.label | p2 |

cpp/autosar/src/rules/M5-0-17/PointerSubtractionOnDifferentArrays.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18-
import semmle.code.cpp.dataflow.DataFlow
18+
import semmle.code.cpp.dataflow.new.DataFlow
1919
import ArrayToPointerDiffOperandFlow::PathGraph
2020

2121
module ArrayToPointerDiffOperandConfig implements DataFlow::ConfigSig {
@@ -34,6 +34,8 @@ module ArrayToPointerDiffOperandConfig implements DataFlow::ConfigSig {
3434
// Add a flow step from the base to the array expression to track pointers to elements of the array.
3535
exists(ArrayExpr e | e.getArrayBase() = pred.asExpr() and e = succ.asExpr())
3636
}
37+
38+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
3739
}
3840

3941
module ArrayToPointerDiffOperandFlow = DataFlow::Global<ArrayToPointerDiffOperandConfig>;

cpp/common/src/codingstandards/cpp/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import cpp
77
import codingstandards.cpp.Customizations
88
import codingstandards.cpp.Exclusions
9-
import semmle.code.cpp.dataflow.DataFlow
9+
import semmle.code.cpp.dataflow.new.DataFlow
1010
import ArrayToPointerDiffOperandFlow::PathGraph
1111

1212
module ArrayToPointerDiffOperandConfig implements DataFlow::ConfigSig {
@@ -25,6 +25,8 @@ module ArrayToPointerDiffOperandConfig implements DataFlow::ConfigSig {
2525
// Add a flow step from the base to the array expression to track pointers to elements of the array.
2626
exists(ArrayExpr e | e.getArrayBase() = pred.asExpr() and e = succ.asExpr())
2727
}
28+
29+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
2830
}
2931

3032
module ArrayToPointerDiffOperandFlow = DataFlow::Global<ArrayToPointerDiffOperandConfig>;

cpp/common/test/rules/donotsubtractpointersaddressingdifferentarrays/DoNotSubtractPointersAddressingDifferentArrays.expected

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,27 @@ problems
44
| test.cpp:13:10:13:11 | p4 | test.cpp:5:14:5:15 | l2 | test.cpp:13:10:13:11 | p4 | Subtraction between left operand pointing to array $@ and other operand pointing to array $@. | test.cpp:3:7:3:8 | l2 | l2 | test.cpp:2:7:2:8 | l1 | l1 |
55
| test.cpp:13:15:13:16 | l1 | test.cpp:13:15:13:16 | l1 | test.cpp:13:15:13:16 | l1 | Subtraction between right operand pointing to array $@ and other operand pointing to array $@. | test.cpp:2:7:2:8 | l1 | l1 | test.cpp:3:7:3:8 | l2 | l2 |
66
edges
7-
| test.cpp:4:14:4:15 | l1 | test.cpp:4:14:4:18 | access to array | provenance | Config |
8-
| test.cpp:4:14:4:18 | access to array | test.cpp:10:10:10:11 | p1 | provenance | |
9-
| test.cpp:4:14:4:18 | access to array | test.cpp:12:10:12:11 | p1 | provenance | |
10-
| test.cpp:5:14:5:15 | l2 | test.cpp:5:14:5:19 | access to array | provenance | Config |
11-
| test.cpp:5:14:5:19 | access to array | test.cpp:11:10:11:11 | p2 | provenance | |
12-
| test.cpp:5:14:5:19 | access to array | test.cpp:12:15:12:16 | p2 | provenance | |
13-
| test.cpp:5:14:5:19 | access to array | test.cpp:13:10:13:11 | p4 | provenance | |
14-
| test.cpp:5:14:5:19 | access to array | test.cpp:14:10:14:11 | p4 | provenance | |
7+
| test.cpp:4:13:4:18 | & ... | test.cpp:4:13:4:18 | & ... | provenance | |
8+
| test.cpp:4:13:4:18 | & ... | test.cpp:10:10:10:11 | p1 | provenance | |
9+
| test.cpp:4:13:4:18 | & ... | test.cpp:12:10:12:11 | p1 | provenance | |
10+
| test.cpp:4:14:4:15 | l1 | test.cpp:4:13:4:18 | & ... | provenance | Config |
11+
| test.cpp:5:13:5:19 | & ... | test.cpp:5:13:5:19 | & ... | provenance | |
12+
| test.cpp:5:13:5:19 | & ... | test.cpp:6:13:6:14 | p2 | provenance | |
13+
| test.cpp:5:13:5:19 | & ... | test.cpp:11:10:11:11 | p2 | provenance | |
14+
| test.cpp:5:13:5:19 | & ... | test.cpp:12:15:12:16 | p2 | provenance | |
15+
| test.cpp:5:14:5:15 | l2 | test.cpp:5:13:5:19 | & ... | provenance | Config |
16+
| test.cpp:6:13:6:14 | p2 | test.cpp:7:13:7:14 | p3 | provenance | |
17+
| test.cpp:7:13:7:14 | p3 | test.cpp:13:10:13:11 | p4 | provenance | |
18+
| test.cpp:7:13:7:14 | p3 | test.cpp:14:10:14:11 | p4 | provenance | |
1519
nodes
20+
| test.cpp:4:13:4:18 | & ... | semmle.label | & ... |
21+
| test.cpp:4:13:4:18 | & ... | semmle.label | & ... |
1622
| test.cpp:4:14:4:15 | l1 | semmle.label | l1 |
17-
| test.cpp:4:14:4:18 | access to array | semmle.label | access to array |
23+
| test.cpp:5:13:5:19 | & ... | semmle.label | & ... |
24+
| test.cpp:5:13:5:19 | & ... | semmle.label | & ... |
1825
| test.cpp:5:14:5:15 | l2 | semmle.label | l2 |
19-
| test.cpp:5:14:5:19 | access to array | semmle.label | access to array |
26+
| test.cpp:6:13:6:14 | p2 | semmle.label | p2 |
27+
| test.cpp:7:13:7:14 | p3 | semmle.label | p3 |
2028
| test.cpp:10:10:10:11 | p1 | semmle.label | p1 |
2129
| test.cpp:10:15:10:16 | l1 | semmle.label | l1 |
2230
| test.cpp:11:10:11:11 | p2 | semmle.label | p2 |

0 commit comments

Comments
 (0)