Skip to content

Commit 09ba9a7

Browse files
authored
Merge pull request #12959 from MathiasVP/identity-consistency-check
DataFlow: Add an "identity-step" consistency check
2 parents 929d9db + 2a4b176 commit 09ba9a7

File tree

62 files changed

+6585
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+6585
-0
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module Consistency {
5858
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
5959
none()
6060
}
61+
62+
/** Holds if `n` should be excluded from the consistency test `identityLocalStep`. */
63+
predicate identityLocalStepExclude(Node n) { none() }
6164
}
6265

6366
private class RelevantNode extends Node {
@@ -287,4 +290,10 @@ module Consistency {
287290
not exists(unique(ContentApprox approx | approx = getContentApprox(c))) and
288291
msg = "Non-unique content approximation."
289292
}
293+
294+
query predicate identityLocalStep(Node n, string msg) {
295+
simpleLocalFlowStep(n, n) and
296+
not any(ConsistencyConfiguration c).identityLocalStepExclude(n) and
297+
msg = "Node steps to itself"
298+
}
290299
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module Consistency {
5858
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
5959
none()
6060
}
61+
62+
/** Holds if `n` should be excluded from the consistency test `identityLocalStep`. */
63+
predicate identityLocalStepExclude(Node n) { none() }
6164
}
6265

6366
private class RelevantNode extends Node {
@@ -287,4 +290,10 @@ module Consistency {
287290
not exists(unique(ContentApprox approx | approx = getContentApprox(c))) and
288291
msg = "Non-unique content approximation."
289292
}
293+
294+
query predicate identityLocalStep(Node n, string msg) {
295+
simpleLocalFlowStep(n, n) and
296+
not any(ConsistencyConfiguration c).identityLocalStepExclude(n) and
297+
msg = "Node steps to itself"
298+
}
290299
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ viableImplInCallContextTooLarge
129129
uniqueParameterNodeAtPosition
130130
uniqueParameterNodePosition
131131
uniqueContentApprox
132+
identityLocalStep

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

Lines changed: 401 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,4 @@ viableImplInCallContextTooLarge
162162
uniqueParameterNodeAtPosition
163163
uniqueParameterNodePosition
164164
uniqueContentApprox
165+
identityLocalStep

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

Lines changed: 377 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/library-tests/syntax-zoo/dataflow-consistency.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ viableImplInCallContextTooLarge
9797
uniqueParameterNodeAtPosition
9898
uniqueParameterNodePosition
9999
uniqueContentApprox
100+
identityLocalStep

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

Lines changed: 1165 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ private class MyConsistencyConfiguration extends ConsistencyConfiguration {
7171
}
7272

7373
override predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
74+
75+
override predicate identityLocalStepExclude(Node n) { this.missingLocationExclude(n) }
7476
}

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module Consistency {
5858
predicate uniqueParameterNodePositionExclude(DataFlowCallable c, ParameterPosition pos, Node p) {
5959
none()
6060
}
61+
62+
/** Holds if `n` should be excluded from the consistency test `identityLocalStep`. */
63+
predicate identityLocalStepExclude(Node n) { none() }
6164
}
6265

6366
private class RelevantNode extends Node {
@@ -287,4 +290,10 @@ module Consistency {
287290
not exists(unique(ContentApprox approx | approx = getContentApprox(c))) and
288291
msg = "Non-unique content approximation."
289292
}
293+
294+
query predicate identityLocalStep(Node n, string msg) {
295+
simpleLocalFlowStep(n, n) and
296+
not any(ConsistencyConfiguration c).identityLocalStepExclude(n) and
297+
msg = "Node steps to itself"
298+
}
290299
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
identityLocalStep
2+
| test.cs:17:41:17:44 | this access | Node steps to itself |
3+
| test.cs:34:41:34:44 | this access | Node steps to itself |
4+
| test.cs:52:41:52:44 | this access | Node steps to itself |
5+
| test.cs:67:41:67:44 | this access | Node steps to itself |
6+
| test.cs:77:22:77:24 | this access | Node steps to itself |
7+
| test.cs:90:41:90:44 | this access | Node steps to itself |

csharp/ql/test/library-tests/cil/attributes/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/consistency/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/dataflow/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/enums/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/functionPointers/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/init-only-prop/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/pdbs/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/regressions/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/cil/typeAnnotations/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/commons/Disposal/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 749 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
identityLocalStep
2+
| Conditions.cs:133:17:133:22 | [Field1 (line 129): false] this access | Node steps to itself |

csharp/ql/test/library-tests/controlflow/guards/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 348 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
identityLocalStep
2+
| SplittingStressTest.cs:172:16:172:16 | SSA phi read(b29) | Node steps to itself |
3+
| SplittingStressTest.cs:179:13:183:13 | [b1 (line 170): false] SSA phi read(b1) | Node steps to itself |
4+
| SplittingStressTest.cs:184:13:188:13 | [b2 (line 170): false] SSA phi read(b2) | Node steps to itself |
5+
| SplittingStressTest.cs:189:13:193:13 | [b3 (line 170): false] SSA phi read(b3) | Node steps to itself |
6+
| SplittingStressTest.cs:194:13:198:13 | [b4 (line 170): false] SSA phi read(b4) | Node steps to itself |
7+
| SplittingStressTest.cs:199:13:203:13 | [b5 (line 170): false] SSA phi read(b5) | Node steps to itself |

csharp/ql/test/library-tests/csharp11/cil/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 263 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
identityLocalStep
2+
| Test.cs:80:37:80:42 | this access | Node steps to itself |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
identityLocalStep
2+
| GlobalDataFlow.cs:573:9:576:9 | SSA phi read(f) | Node steps to itself |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
identityLocalStep
2+
| DefUse.cs:80:37:80:42 | this access | Node steps to itself |
3+
| Properties.cs:65:24:65:31 | this access | Node steps to itself |

0 commit comments

Comments
 (0)