Skip to content

Commit b1b236d

Browse files
authored
Merge pull request github#15410 from MathiasVP/less-dataflow-duplication
C++: Remove more `asExpr` duplication
2 parents 0e866a5 + 8b172c1 commit b1b236d

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -1394,11 +1394,21 @@ abstract private class ExprNodeBase extends Node {
13941394
final Expr getExpr(int n) { result = this.getConvertedExpr(n).getUnconverted() }
13951395
}
13961396

1397+
/**
1398+
* Holds if there exists a dataflow node whose `asExpr(n)` should evaluate
1399+
* to `e`.
1400+
*/
1401+
private predicate exprNodeShouldBe(Expr e, int n) {
1402+
exprNodeShouldBeInstruction(_, e, n) or
1403+
exprNodeShouldBeOperand(_, e, n) or
1404+
exprNodeShouldBeIndirectOutNode(_, e, n)
1405+
}
1406+
13971407
private class InstructionExprNode extends ExprNodeBase, InstructionNode {
13981408
InstructionExprNode() {
13991409
exists(Expr e, int n |
14001410
exprNodeShouldBeInstruction(this, e, n) and
1401-
not exprNodeShouldBeInstruction(_, e, n + 1)
1411+
not exprNodeShouldBe(e, n + 1)
14021412
)
14031413
}
14041414

@@ -1409,7 +1419,7 @@ private class OperandExprNode extends ExprNodeBase, OperandNode {
14091419
OperandExprNode() {
14101420
exists(Expr e, int n |
14111421
exprNodeShouldBeOperand(this, e, n) and
1412-
not exprNodeShouldBeOperand(_, e, n + 1)
1422+
not exprNodeShouldBe(e, n + 1)
14131423
)
14141424
}
14151425

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

-13
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ edges
1212
| A.cpp:31:20:31:20 | c | A.cpp:31:14:31:21 | call to B [c] |
1313
| A.cpp:41:5:41:6 | insert output argument | A.cpp:43:10:43:12 | *& ... |
1414
| A.cpp:41:15:41:21 | new | A.cpp:41:5:41:6 | insert output argument |
15-
| A.cpp:41:15:41:21 | new | A.cpp:41:5:41:6 | insert output argument |
16-
| A.cpp:41:15:41:21 | new | A.cpp:41:15:41:21 | new |
1715
| A.cpp:47:12:47:18 | new | A.cpp:48:20:48:20 | c |
1816
| A.cpp:48:12:48:18 | *call to make [c] | A.cpp:49:10:49:10 | *b [c] |
1917
| A.cpp:48:20:48:20 | c | A.cpp:29:23:29:23 | c |
@@ -22,7 +20,6 @@ edges
2220
| A.cpp:55:5:55:5 | set output argument [c] | A.cpp:56:10:56:10 | *b [c] |
2321
| A.cpp:55:12:55:19 | new | A.cpp:27:17:27:17 | c |
2422
| A.cpp:55:12:55:19 | new | A.cpp:55:5:55:5 | set output argument [c] |
25-
| A.cpp:55:12:55:19 | new | A.cpp:55:12:55:19 | new |
2623
| A.cpp:56:10:56:10 | *b [c] | A.cpp:28:8:28:10 | *this [c] |
2724
| A.cpp:56:10:56:10 | *b [c] | A.cpp:56:10:56:17 | call to get |
2825
| A.cpp:57:11:57:24 | *new [c] | A.cpp:28:8:28:10 | *this [c] |
@@ -33,12 +30,10 @@ edges
3330
| A.cpp:57:17:57:23 | new | A.cpp:57:17:57:23 | new |
3431
| A.cpp:64:10:64:15 | *call to setOnB [c] | A.cpp:66:10:66:11 | *b2 [c] |
3532
| A.cpp:64:21:64:28 | new | A.cpp:64:10:64:15 | *call to setOnB [c] |
36-
| A.cpp:64:21:64:28 | new | A.cpp:64:21:64:28 | new |
3733
| A.cpp:64:21:64:28 | new | A.cpp:85:26:85:26 | c |
3834
| A.cpp:66:10:66:11 | *b2 [c] | A.cpp:66:10:66:14 | c |
3935
| A.cpp:73:10:73:19 | *call to setOnBWrap [c] | A.cpp:75:10:75:11 | *b2 [c] |
4036
| A.cpp:73:25:73:32 | new | A.cpp:73:10:73:19 | *call to setOnBWrap [c] |
41-
| A.cpp:73:25:73:32 | new | A.cpp:73:25:73:32 | new |
4237
| A.cpp:73:25:73:32 | new | A.cpp:78:27:78:27 | c |
4338
| A.cpp:75:10:75:11 | *b2 [c] | A.cpp:75:10:75:14 | c |
4439
| A.cpp:78:27:78:27 | c | A.cpp:81:21:81:21 | c |
@@ -770,7 +765,6 @@ nodes
770765
| A.cpp:31:20:31:20 | c | semmle.label | c |
771766
| A.cpp:41:5:41:6 | insert output argument | semmle.label | insert output argument |
772767
| A.cpp:41:15:41:21 | new | semmle.label | new |
773-
| A.cpp:41:15:41:21 | new | semmle.label | new |
774768
| A.cpp:43:10:43:12 | *& ... | semmle.label | *& ... |
775769
| A.cpp:47:12:47:18 | new | semmle.label | new |
776770
| A.cpp:48:12:48:18 | *call to make [c] | semmle.label | *call to make [c] |
@@ -779,7 +773,6 @@ nodes
779773
| A.cpp:49:10:49:13 | c | semmle.label | c |
780774
| A.cpp:55:5:55:5 | set output argument [c] | semmle.label | set output argument [c] |
781775
| A.cpp:55:12:55:19 | new | semmle.label | new |
782-
| A.cpp:55:12:55:19 | new | semmle.label | new |
783776
| A.cpp:56:10:56:10 | *b [c] | semmle.label | *b [c] |
784777
| A.cpp:56:10:56:17 | call to get | semmle.label | call to get |
785778
| A.cpp:57:10:57:32 | call to get | semmle.label | call to get |
@@ -789,12 +782,10 @@ nodes
789782
| A.cpp:57:17:57:23 | new | semmle.label | new |
790783
| A.cpp:64:10:64:15 | *call to setOnB [c] | semmle.label | *call to setOnB [c] |
791784
| A.cpp:64:21:64:28 | new | semmle.label | new |
792-
| A.cpp:64:21:64:28 | new | semmle.label | new |
793785
| A.cpp:66:10:66:11 | *b2 [c] | semmle.label | *b2 [c] |
794786
| A.cpp:66:10:66:14 | c | semmle.label | c |
795787
| A.cpp:73:10:73:19 | *call to setOnBWrap [c] | semmle.label | *call to setOnBWrap [c] |
796788
| A.cpp:73:25:73:32 | new | semmle.label | new |
797-
| A.cpp:73:25:73:32 | new | semmle.label | new |
798789
| A.cpp:75:10:75:11 | *b2 [c] | semmle.label | *b2 [c] |
799790
| A.cpp:75:10:75:14 | c | semmle.label | c |
800791
| A.cpp:78:6:78:15 | **setOnBWrap [c] | semmle.label | **setOnBWrap [c] |
@@ -1608,14 +1599,10 @@ subpaths
16081599
| simple.cpp:84:14:84:20 | *this [f2, f1] | simple.cpp:78:9:78:15 | *this [f2, f1] | simple.cpp:78:9:78:15 | *getf2f1 | simple.cpp:84:14:84:20 | call to getf2f1 |
16091600
#select
16101601
| A.cpp:43:10:43:12 | *& ... | A.cpp:41:15:41:21 | new | A.cpp:43:10:43:12 | *& ... | *& ... flows from $@ | A.cpp:41:15:41:21 | new | new |
1611-
| A.cpp:43:10:43:12 | *& ... | A.cpp:41:15:41:21 | new | A.cpp:43:10:43:12 | *& ... | *& ... flows from $@ | A.cpp:41:15:41:21 | new | new |
16121602
| A.cpp:49:10:49:13 | c | A.cpp:47:12:47:18 | new | A.cpp:49:10:49:13 | c | c flows from $@ | A.cpp:47:12:47:18 | new | new |
16131603
| A.cpp:56:10:56:17 | call to get | A.cpp:55:12:55:19 | new | A.cpp:56:10:56:17 | call to get | call to get flows from $@ | A.cpp:55:12:55:19 | new | new |
1614-
| A.cpp:56:10:56:17 | call to get | A.cpp:55:12:55:19 | new | A.cpp:56:10:56:17 | call to get | call to get flows from $@ | A.cpp:55:12:55:19 | new | new |
16151604
| A.cpp:57:10:57:32 | call to get | A.cpp:57:17:57:23 | new | A.cpp:57:10:57:32 | call to get | call to get flows from $@ | A.cpp:57:17:57:23 | new | new |
16161605
| A.cpp:66:10:66:14 | c | A.cpp:64:21:64:28 | new | A.cpp:66:10:66:14 | c | c flows from $@ | A.cpp:64:21:64:28 | new | new |
1617-
| A.cpp:66:10:66:14 | c | A.cpp:64:21:64:28 | new | A.cpp:66:10:66:14 | c | c flows from $@ | A.cpp:64:21:64:28 | new | new |
1618-
| A.cpp:75:10:75:14 | c | A.cpp:73:25:73:32 | new | A.cpp:75:10:75:14 | c | c flows from $@ | A.cpp:73:25:73:32 | new | new |
16191606
| A.cpp:75:10:75:14 | c | A.cpp:73:25:73:32 | new | A.cpp:75:10:75:14 | c | c flows from $@ | A.cpp:73:25:73:32 | new | new |
16201607
| A.cpp:107:12:107:16 | a | A.cpp:98:12:98:18 | new | A.cpp:107:12:107:16 | a | a flows from $@ | A.cpp:98:12:98:18 | new | new |
16211608
| A.cpp:120:12:120:16 | a | A.cpp:98:12:98:18 | new | A.cpp:120:12:120:16 | a | a flows from $@ | A.cpp:98:12:98:18 | new | new |

cpp/ql/test/library-tests/string_concat/strconcat.expected

-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:22:23:25 | str1 | concat.cpp:23:22:23:31 | call to operator+ |
2-
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:22:23:25 | str1 | concat.cpp:23:22:23:31 | call to operator+ |
32
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:22:23:25 | str1 | concat.cpp:23:27:23:27 | call to operator+ |
43
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:29:23:31 | | concat.cpp:23:22:23:31 | call to operator+ |
5-
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:29:23:31 | | concat.cpp:23:22:23:31 | call to operator+ |
64
| concat.cpp:23:27:23:27 | call to operator+ | concat.cpp:23:29:23:31 | | concat.cpp:23:27:23:27 | call to operator+ |
75
| concat.cpp:23:33:23:33 | call to operator+ | concat.cpp:23:35:23:38 | str2 | concat.cpp:23:22:23:38 | call to operator+ |
8-
| concat.cpp:23:33:23:33 | call to operator+ | concat.cpp:23:35:23:38 | str2 | concat.cpp:23:22:23:38 | call to operator+ |
96
| concat.cpp:23:33:23:33 | call to operator+ | concat.cpp:23:35:23:38 | str2 | concat.cpp:23:33:23:33 | call to operator+ |
107
| concat.cpp:23:40:23:40 | call to operator+ | concat.cpp:23:42:23:45 | str3 | concat.cpp:23:40:23:40 | call to operator+ |
118
| concat.cpp:47:8:47:8 | call to operator<< | concat.cpp:47:11:47:14 | str1 | concat.cpp:47:8:47:17 | call to operator<< |

0 commit comments

Comments
 (0)