Skip to content

Commit 1aa1829

Browse files
authored
Merge pull request #18955 from MathiasVP/share-more-indirect-operands-and-instructions
C++: Share indirect dataflow nodes across `CopyValue` instructions
2 parents 0676c21 + f9a7ac4 commit 1aa1829

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

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

+25-9
Original file line numberDiff line numberDiff line change
@@ -630,10 +630,18 @@ private module Cached {
630630
Operand operand, int indirectionIndex, Operand operandRepr, int indirectionIndexRepr
631631
) {
632632
indirectionIndex = [1 .. countIndirectionsForCppType(getLanguageType(operand))] and
633-
exists(Instruction load |
634-
isDereference(load, operand, false) and
635-
operandRepr = unique( | | getAUse(load)) and
636-
indirectionIndexRepr = indirectionIndex - 1
633+
(
634+
exists(Instruction load |
635+
isDereference(load, operand, false) and
636+
operandRepr = unique( | | getAUse(load)) and
637+
indirectionIndexRepr = indirectionIndex - 1
638+
)
639+
or
640+
exists(CopyValueInstruction copy |
641+
copy.getSourceValueOperand() = operand and
642+
operandRepr = unique( | | getAUse(copy)) and
643+
indirectionIndexRepr = indirectionIndex
644+
)
637645
)
638646
}
639647

@@ -649,11 +657,19 @@ private module Cached {
649657
Instruction instr, int indirectionIndex, Instruction instrRepr, int indirectionIndexRepr
650658
) {
651659
indirectionIndex = [1 .. countIndirectionsForCppType(getResultLanguageType(instr))] and
652-
exists(Instruction load, Operand address |
653-
address = unique( | | getAUse(instr)) and
654-
isDereference(load, address, false) and
655-
instrRepr = load and
656-
indirectionIndexRepr = indirectionIndex - 1
660+
(
661+
exists(Instruction load, Operand address |
662+
address = unique( | | getAUse(instr)) and
663+
isDereference(load, address, false) and
664+
instrRepr = load and
665+
indirectionIndexRepr = indirectionIndex - 1
666+
)
667+
or
668+
exists(CopyValueInstruction copy |
669+
copy.getSourceValueOperand() = unique( | | getAUse(instr)) and
670+
instrRepr = copy and
671+
indirectionIndexRepr = indirectionIndex
672+
)
657673
)
658674
}
659675

cpp/ql/test/library-tests/dataflow/dataflow-tests/localFlow-ir.expected

-8
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
| example.c:26:18:26:24 | *& ... | example.c:26:2:26:7 | *coords |
5454
| example.c:26:18:26:24 | getX output argument | example.c:26:2:26:7 | *coords |
5555
| example.c:26:18:26:24 | pointer to getX output argument | example.c:26:2:26:7 | coords |
56-
| example.c:26:19:26:24 | *coords | example.c:26:18:26:24 | *& ... |
5756
| example.c:26:19:26:24 | coords | example.c:26:18:26:24 | & ... |
5857
| example.c:28:22:28:25 | & ... | example.c:28:14:28:25 | & ... |
5958
| example.c:28:22:28:25 | *& ... | example.c:28:14:28:25 | *& ... |
60-
| example.c:28:23:28:25 | *pos | example.c:28:22:28:25 | *& ... |
6159
| example.c:28:23:28:25 | pos | example.c:28:22:28:25 | & ... |
6260
| test.cpp:6:12:6:17 | call to source | test.cpp:6:12:6:17 | call to source |
6361
| test.cpp:6:12:6:17 | call to source | test.cpp:7:8:7:9 | t1 |
@@ -134,7 +132,6 @@
134132
| test.cpp:384:10:384:13 | *& ... | test.cpp:384:10:384:13 | *& ... |
135133
| test.cpp:384:10:384:13 | memcpy output argument | test.cpp:385:8:385:10 | tmp |
136134
| test.cpp:384:10:384:13 | pointer to memcpy output argument | test.cpp:385:8:385:10 | tmp |
137-
| test.cpp:384:11:384:13 | *tmp | test.cpp:384:10:384:13 | *& ... |
138135
| test.cpp:384:11:384:13 | tmp | test.cpp:384:10:384:13 | & ... |
139136
| test.cpp:384:16:384:23 | & ... | test.cpp:384:16:384:23 | & ... |
140137
| test.cpp:384:16:384:23 | *& ... | test.cpp:384:3:384:8 | **call to memcpy |
@@ -143,7 +140,6 @@
143140
| test.cpp:384:16:384:23 | *& ... | test.cpp:384:16:384:23 | *& ... |
144141
| test.cpp:384:16:384:23 | **& ... | test.cpp:384:3:384:8 | **call to memcpy |
145142
| test.cpp:384:16:384:23 | **& ... | test.cpp:384:10:384:13 | memcpy output argument |
146-
| test.cpp:384:17:384:23 | *source1 | test.cpp:384:16:384:23 | *& ... |
147143
| test.cpp:384:17:384:23 | source1 | test.cpp:384:16:384:23 | & ... |
148144
| test.cpp:388:53:388:59 | source1 | test.cpp:391:16:391:23 | *& ... |
149145
| test.cpp:388:66:388:66 | b | test.cpp:393:7:393:7 | b |
@@ -153,15 +149,13 @@
153149
| test.cpp:390:18:390:21 | & ... | test.cpp:391:10:391:13 | & ... |
154150
| test.cpp:390:18:390:21 | *& ... | test.cpp:390:18:390:21 | *& ... |
155151
| test.cpp:390:18:390:21 | *& ... | test.cpp:391:10:391:13 | *& ... |
156-
| test.cpp:390:19:390:21 | *tmp | test.cpp:390:18:390:21 | *& ... |
157152
| test.cpp:390:19:390:21 | tmp | test.cpp:390:18:390:21 | & ... |
158153
| test.cpp:391:10:391:13 | & ... | test.cpp:391:3:391:8 | call to memcpy |
159154
| test.cpp:391:10:391:13 | & ... | test.cpp:391:10:391:13 | & ... |
160155
| test.cpp:391:10:391:13 | & ... | test.cpp:392:8:392:10 | tmp |
161156
| test.cpp:391:10:391:13 | *& ... | test.cpp:391:10:391:13 | *& ... |
162157
| test.cpp:391:10:391:13 | memcpy output argument | test.cpp:392:8:392:10 | tmp |
163158
| test.cpp:391:10:391:13 | pointer to memcpy output argument | test.cpp:392:8:392:10 | tmp |
164-
| test.cpp:391:11:391:13 | *tmp | test.cpp:391:10:391:13 | *& ... |
165159
| test.cpp:391:11:391:13 | tmp | test.cpp:391:10:391:13 | & ... |
166160
| test.cpp:391:16:391:23 | & ... | test.cpp:391:16:391:23 | & ... |
167161
| test.cpp:391:16:391:23 | *& ... | test.cpp:391:3:391:8 | **call to memcpy |
@@ -170,7 +164,6 @@
170164
| test.cpp:391:16:391:23 | *& ... | test.cpp:391:16:391:23 | *& ... |
171165
| test.cpp:391:16:391:23 | **& ... | test.cpp:391:3:391:8 | **call to memcpy |
172166
| test.cpp:391:16:391:23 | **& ... | test.cpp:391:10:391:13 | memcpy output argument |
173-
| test.cpp:391:17:391:23 | *source1 | test.cpp:391:16:391:23 | *& ... |
174167
| test.cpp:391:17:391:23 | source1 | test.cpp:391:16:391:23 | & ... |
175168
| test.cpp:392:8:392:10 | tmp | test.cpp:394:10:394:12 | tmp |
176169
| test.cpp:392:8:392:10 | tmp | test.cpp:394:10:394:12 | tmp |
@@ -209,5 +202,4 @@
209202
| test.cpp:1087:3:1087:3 | a [post update] | test.cpp:1088:8:1088:9 | & ... |
210203
| test.cpp:1087:15:1087:21 | 0 | test.cpp:1087:3:1087:21 | ... = ... |
211204
| test.cpp:1087:15:1087:21 | *0 | test.cpp:1087:3:1087:21 | *... = ... |
212-
| test.cpp:1088:9:1088:9 | *a | test.cpp:1088:8:1088:9 | *& ... |
213205
| test.cpp:1088:9:1088:9 | a | test.cpp:1088:8:1088:9 | & ... |

0 commit comments

Comments
 (0)