Skip to content

Commit b437024

Browse files
committed
C++: Remove self edges from post-update SSA.
1 parent 4048915 commit b437024

File tree

4 files changed

+14
-178
lines changed

4 files changed

+14
-178
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ private module Cached {
15401540
cached
15411541
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
15421542
// Post update node -> Node flow
1543-
Ssa::ssaFlow(nodeFrom.(PostUpdateNode).getPreUpdateNode(), nodeTo)
1543+
Ssa::postUpdateFlow(nodeFrom, nodeTo)
15441544
or
15451545
// Def-use/Use-use flow
15461546
Ssa::ssaFlow(nodeFrom, nodeTo)

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,11 +713,23 @@ private Node getAPriorDefinition(SsaDefOrUse defOrUse) {
713713
/** Holds if there is def-use or use-use flow from `nodeFrom` to `nodeTo`. */
714714
predicate ssaFlow(Node nodeFrom, Node nodeTo) {
715715
exists(Node nFrom, boolean uncertain, SsaDefOrUse defOrUse |
716-
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and
716+
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain) and nodeFrom != nodeTo
717+
|
717718
if uncertain = true then nodeFrom = [nFrom, getAPriorDefinition(defOrUse)] else nodeFrom = nFrom
718719
)
719720
}
720721

722+
predicate postUpdateFlow(PostUpdateNode pun, Node nodeTo) {
723+
exists(Node preUpdate, Node nFrom, boolean uncertain, SsaDefOrUse defOrUse |
724+
preUpdate = pun.getPreUpdateNode() and
725+
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain)
726+
|
727+
if uncertain = true
728+
then preUpdate = [nFrom, getAPriorDefinition(defOrUse)]
729+
else preUpdate = nFrom
730+
)
731+
}
732+
721733
/**
722734
* Holds if `use` is a use of `sv` and is a next adjacent use of `phi` in
723735
* index `i1` in basic block `bb1`.

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

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,3 @@ uniqueParameterNodeAtPosition
3232
uniqueParameterNodePosition
3333
uniqueContentApprox
3434
identityLocalStep
35-
| BarrierGuard.cpp:62:10:62:11 | p1 indirection | Node steps to itself |
36-
| BarrierGuard.cpp:64:10:64:11 | p1 indirection | Node steps to itself |
37-
| BarrierGuard.cpp:65:22:65:23 | p2 indirection | Node steps to itself |
38-
| BarrierGuard.cpp:66:10:66:11 | p1 indirection | Node steps to itself |
39-
| BarrierGuard.cpp:76:10:76:12 | buf indirection | Node steps to itself |
40-
| clang.cpp:8:27:8:28 | this indirection | Node steps to itself |
41-
| clang.cpp:31:8:31:24 | sourceStruct1_ptr indirection | Node steps to itself |
42-
| dispatch.cpp:37:3:37:8 | topPtr indirection | Node steps to itself |
43-
| dispatch.cpp:45:3:45:8 | topRef indirection | Node steps to itself |
44-
| dispatch.cpp:55:8:55:19 | globalBottom indirection | Node steps to itself |
45-
| dispatch.cpp:56:8:56:19 | globalMiddle indirection | Node steps to itself |
46-
| dispatch.cpp:69:3:69:5 | top indirection | Node steps to itself |
47-
| dispatch.cpp:73:3:73:5 | top indirection | Node steps to itself |
48-
| dispatch.cpp:81:3:81:3 | x indirection | Node steps to itself |
49-
| dispatch.cpp:89:12:89:17 | bottom indirection | Node steps to itself |
50-
| dispatch.cpp:90:12:90:14 | top indirection | Node steps to itself |
51-
| dispatch.cpp:129:10:129:15 | topPtr indirection | Node steps to itself |
52-
| dispatch.cpp:130:10:130:15 | topRef indirection | Node steps to itself |
53-
| example.c:19:6:19:6 | b indirection | Node steps to itself |
54-
| file://:0:0:0:0 | this indirection | Node steps to itself |
55-
| lambdas.cpp:13:11:13:11 | (unnamed parameter 0) indirection | Node steps to itself |
56-
| lambdas.cpp:20:11:20:11 | (unnamed parameter 0) indirection | Node steps to itself |
57-
| lambdas.cpp:23:3:23:14 | this indirection | Node steps to itself |
58-
| lambdas.cpp:28:11:28:11 | (unnamed parameter 0) indirection | Node steps to itself |
59-
| lambdas.cpp:30:3:30:6 | this indirection | Node steps to itself |
60-
| ref.cpp:16:12:16:14 | lhs indirection | Node steps to itself |
61-
| ref.cpp:75:5:75:7 | lhs indirection | Node steps to itself |
62-
| ref.cpp:79:12:79:14 | lhs indirection | Node steps to itself |
63-
| ref.cpp:87:7:87:9 | lhs indirection | Node steps to itself |
64-
| ref.cpp:89:7:89:9 | lhs indirection | Node steps to itself |
65-
| ref.cpp:96:7:96:9 | out indirection | Node steps to itself |
66-
| ref.cpp:102:21:102:23 | out indirection | Node steps to itself |
67-
| ref.cpp:104:7:104:9 | out indirection | Node steps to itself |
68-
| ref.cpp:113:7:113:9 | out indirection | Node steps to itself |
69-
| ref.cpp:115:7:115:9 | out indirection | Node steps to itself |
70-
| test.cpp:194:13:194:27 | this indirection | Node steps to itself |
71-
| test.cpp:209:13:209:33 | this indirection | Node steps to itself |
72-
| test.cpp:223:13:223:34 | this indirection | Node steps to itself |
73-
| test.cpp:236:13:236:24 | this indirection | Node steps to itself |
74-
| test.cpp:246:7:246:16 | this indirection | Node steps to itself |
75-
| test.cpp:251:7:251:12 | this indirection | Node steps to itself |
76-
| test.cpp:256:7:256:12 | this indirection | Node steps to itself |
77-
| test.cpp:267:11:267:20 | this indirection | Node steps to itself |
78-
| test.cpp:273:14:273:19 | this indirection | Node steps to itself |
79-
| test.cpp:278:14:278:19 | this indirection | Node steps to itself |
80-
| test.cpp:290:13:290:22 | this indirection | Node steps to itself |
81-
| test.cpp:295:17:295:22 | this indirection | Node steps to itself |
82-
| test.cpp:300:23:300:28 | this indirection | Node steps to itself |
83-
| test.cpp:314:2:314:2 | this indirection | Node steps to itself |
84-
| test.cpp:321:2:321:2 | this indirection | Node steps to itself |
85-
| test.cpp:359:5:359:9 | this indirection | Node steps to itself |
86-
| test.cpp:365:10:365:14 | this indirection | Node steps to itself |
87-
| test.cpp:369:10:369:14 | this indirection | Node steps to itself |
88-
| test.cpp:375:10:375:14 | this indirection | Node steps to itself |
89-
| test.cpp:489:20:489:20 | s indirection | Node steps to itself |

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

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -42,124 +42,3 @@ uniqueParameterNodeAtPosition
4242
uniqueParameterNodePosition
4343
uniqueContentApprox
4444
identityLocalStep
45-
| A.cpp:25:7:25:10 | this indirection | Node steps to itself |
46-
| A.cpp:27:22:27:25 | this indirection | Node steps to itself |
47-
| A.cpp:28:23:28:26 | this indirection | Node steps to itself |
48-
| A.cpp:31:20:31:20 | c indirection | Node steps to itself |
49-
| A.cpp:41:15:41:21 | new indirection | Node steps to itself |
50-
| A.cpp:48:20:48:20 | c indirection | Node steps to itself |
51-
| A.cpp:49:10:49:10 | b indirection | Node steps to itself |
52-
| A.cpp:55:12:55:19 | new indirection | Node steps to itself |
53-
| A.cpp:56:10:56:10 | b indirection | Node steps to itself |
54-
| A.cpp:64:10:64:15 | this indirection | Node steps to itself |
55-
| A.cpp:64:21:64:28 | new indirection | Node steps to itself |
56-
| A.cpp:65:10:65:11 | b1 indirection | Node steps to itself |
57-
| A.cpp:66:10:66:11 | b2 indirection | Node steps to itself |
58-
| A.cpp:73:10:73:19 | this indirection | Node steps to itself |
59-
| A.cpp:73:25:73:32 | new indirection | Node steps to itself |
60-
| A.cpp:74:10:74:11 | b1 indirection | Node steps to itself |
61-
| A.cpp:75:10:75:11 | b2 indirection | Node steps to itself |
62-
| A.cpp:81:21:81:21 | c indirection | Node steps to itself |
63-
| A.cpp:82:12:82:12 | this indirection | Node steps to itself |
64-
| A.cpp:87:9:87:9 | this indirection | Node steps to itself |
65-
| A.cpp:90:15:90:15 | c indirection | Node steps to itself |
66-
| A.cpp:101:5:101:6 | this indirection | Node steps to itself |
67-
| A.cpp:101:8:101:9 | c1 indirection | Node steps to itself |
68-
| A.cpp:107:12:107:13 | c1 indirection | Node steps to itself |
69-
| A.cpp:120:12:120:13 | c1 indirection | Node steps to itself |
70-
| A.cpp:126:5:126:5 | b indirection | Node steps to itself |
71-
| A.cpp:131:5:131:6 | this indirection | Node steps to itself |
72-
| A.cpp:132:10:132:10 | b indirection | Node steps to itself |
73-
| A.cpp:143:7:143:10 | this indirection | Node steps to itself |
74-
| A.cpp:151:21:151:21 | this indirection | Node steps to itself |
75-
| A.cpp:153:10:153:10 | d indirection | Node steps to itself |
76-
| A.cpp:154:10:154:10 | b indirection | Node steps to itself |
77-
| A.cpp:160:29:160:29 | b indirection | Node steps to itself |
78-
| A.cpp:161:38:161:39 | l1 indirection | Node steps to itself |
79-
| A.cpp:162:38:162:39 | l2 indirection | Node steps to itself |
80-
| A.cpp:167:44:167:44 | l indirection | Node steps to itself |
81-
| A.cpp:184:7:184:10 | this indirection | Node steps to itself |
82-
| B.cpp:7:25:7:25 | e indirection | Node steps to itself |
83-
| B.cpp:8:25:8:26 | b1 indirection | Node steps to itself |
84-
| B.cpp:10:10:10:11 | b2 indirection | Node steps to itself |
85-
| B.cpp:16:37:16:37 | e indirection | Node steps to itself |
86-
| B.cpp:17:25:17:26 | b1 indirection | Node steps to itself |
87-
| B.cpp:19:10:19:11 | b2 indirection | Node steps to itself |
88-
| B.cpp:36:7:36:10 | this indirection | Node steps to itself |
89-
| B.cpp:46:7:46:10 | this indirection | Node steps to itself |
90-
| C.cpp:19:5:19:5 | c indirection | Node steps to itself |
91-
| C.cpp:24:5:24:8 | this indirection | Node steps to itself |
92-
| C.cpp:31:10:31:11 | this indirection | Node steps to itself |
93-
| D.cpp:9:21:9:24 | this indirection | Node steps to itself |
94-
| D.cpp:10:30:10:33 | this indirection | Node steps to itself |
95-
| D.cpp:11:29:11:32 | this indirection | Node steps to itself |
96-
| D.cpp:16:21:16:23 | this indirection | Node steps to itself |
97-
| D.cpp:17:30:17:32 | this indirection | Node steps to itself |
98-
| D.cpp:18:29:18:31 | this indirection | Node steps to itself |
99-
| D.cpp:22:10:22:11 | b2 indirection | Node steps to itself |
100-
| D.cpp:31:14:31:14 | b indirection | Node steps to itself |
101-
| D.cpp:37:21:37:21 | e indirection | Node steps to itself |
102-
| D.cpp:38:14:38:14 | b indirection | Node steps to itself |
103-
| D.cpp:45:14:45:14 | b indirection | Node steps to itself |
104-
| D.cpp:51:27:51:27 | e indirection | Node steps to itself |
105-
| D.cpp:52:14:52:14 | b indirection | Node steps to itself |
106-
| D.cpp:59:5:59:7 | this indirection | Node steps to itself |
107-
| D.cpp:64:10:64:17 | this indirection | Node steps to itself |
108-
| E.cpp:21:10:21:10 | p indirection | Node steps to itself |
109-
| E.cpp:31:10:31:12 | raw indirection | Node steps to itself |
110-
| E.cpp:32:10:32:10 | b indirection | Node steps to itself |
111-
| aliasing.cpp:9:3:9:3 | s indirection | Node steps to itself |
112-
| aliasing.cpp:13:3:13:3 | s indirection | Node steps to itself |
113-
| aliasing.cpp:37:3:37:6 | ref1 indirection | Node steps to itself |
114-
| aliasing.cpp:43:8:43:11 | ref2 indirection | Node steps to itself |
115-
| aliasing.cpp:79:3:79:3 | s indirection | Node steps to itself |
116-
| aliasing.cpp:86:3:86:3 | s indirection | Node steps to itself |
117-
| aliasing.cpp:201:8:201:10 | ps2 indirection | Node steps to itself |
118-
| aliasing.cpp:206:8:206:10 | ps2 indirection | Node steps to itself |
119-
| by_reference.cpp:12:5:12:5 | s indirection | Node steps to itself |
120-
| by_reference.cpp:16:5:16:8 | this indirection | Node steps to itself |
121-
| by_reference.cpp:20:5:20:8 | this indirection | Node steps to itself |
122-
| by_reference.cpp:20:23:20:27 | value indirection | Node steps to itself |
123-
| by_reference.cpp:20:23:20:27 | value indirection | Node steps to itself |
124-
| by_reference.cpp:24:19:24:22 | this indirection | Node steps to itself |
125-
| by_reference.cpp:24:25:24:29 | value indirection | Node steps to itself |
126-
| by_reference.cpp:24:25:24:29 | value indirection | Node steps to itself |
127-
| by_reference.cpp:32:12:32:12 | s indirection | Node steps to itself |
128-
| by_reference.cpp:36:12:36:15 | this indirection | Node steps to itself |
129-
| by_reference.cpp:40:12:40:15 | this indirection | Node steps to itself |
130-
| by_reference.cpp:44:26:44:29 | this indirection | Node steps to itself |
131-
| by_reference.cpp:84:3:84:7 | inner indirection | Node steps to itself |
132-
| by_reference.cpp:88:3:88:7 | inner indirection | Node steps to itself |
133-
| by_reference.cpp:116:8:116:13 | pouter indirection | Node steps to itself |
134-
| by_reference.cpp:136:8:136:13 | pouter indirection | Node steps to itself |
135-
| complex.cpp:9:20:9:21 | this indirection | Node steps to itself |
136-
| complex.cpp:10:20:10:21 | this indirection | Node steps to itself |
137-
| complex.cpp:11:22:11:23 | this indirection | Node steps to itself |
138-
| complex.cpp:12:22:12:23 | this indirection | Node steps to itself |
139-
| complex.cpp:43:8:43:8 | b indirection | Node steps to itself |
140-
| conflated.cpp:11:9:11:10 | ra indirection | Node steps to itself |
141-
| conflated.cpp:20:8:20:10 | raw indirection | Node steps to itself |
142-
| conflated.cpp:30:8:30:9 | pa indirection | Node steps to itself |
143-
| conflated.cpp:37:8:37:9 | pa indirection | Node steps to itself |
144-
| conflated.cpp:55:8:55:9 | ll indirection | Node steps to itself |
145-
| conflated.cpp:59:35:59:38 | next indirection | Node steps to itself |
146-
| conflated.cpp:61:8:61:9 | ll indirection | Node steps to itself |
147-
| constructors.cpp:18:22:18:23 | this indirection | Node steps to itself |
148-
| constructors.cpp:19:22:19:23 | this indirection | Node steps to itself |
149-
| constructors.cpp:20:24:20:25 | this indirection | Node steps to itself |
150-
| constructors.cpp:21:24:21:25 | this indirection | Node steps to itself |
151-
| constructors.cpp:29:10:29:10 | f indirection | Node steps to itself |
152-
| qualifiers.cpp:9:30:9:33 | this indirection | Node steps to itself |
153-
| qualifiers.cpp:12:49:12:53 | inner indirection | Node steps to itself |
154-
| qualifiers.cpp:13:51:13:55 | inner indirection | Node steps to itself |
155-
| qualifiers.cpp:18:32:18:36 | this indirection | Node steps to itself |
156-
| realistic.cpp:42:20:42:20 | o indirection | Node steps to itself |
157-
| realistic.cpp:42:20:42:20 | o indirection | Node steps to itself |
158-
| simple.cpp:18:22:18:23 | this indirection | Node steps to itself |
159-
| simple.cpp:19:22:19:23 | this indirection | Node steps to itself |
160-
| simple.cpp:20:24:20:25 | this indirection | Node steps to itself |
161-
| simple.cpp:21:24:21:25 | this indirection | Node steps to itself |
162-
| simple.cpp:29:10:29:10 | f indirection | Node steps to itself |
163-
| simple.cpp:79:16:79:17 | this indirection | Node steps to itself |
164-
| simple.cpp:84:14:84:20 | this indirection | Node steps to itself |
165-
| struct_init.c:16:8:16:9 | ab indirection | Node steps to itself |

0 commit comments

Comments
 (0)