Skip to content

Commit 2c9bee6

Browse files
committed
Rust: Only add data flow edge to SSA write definitions from their underlying CFG node
1 parent 6ae9792 commit 2c9bee6

File tree

4 files changed

+7
-19
lines changed

4 files changed

+7
-19
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ module Node {
112112
}
113113

114114
/** A data flow node that corresponds to a CFG node for an AST node. */
115-
abstract private class AstCfgFlowNode extends Node {
115+
abstract class AstCfgFlowNode extends Node {
116116
AstCfgNode n;
117117

118118
override CfgNode getCfgNode() { result = n }
@@ -283,9 +283,11 @@ module LocalFlow {
283283
nodeTo.getCfgNode().getAstNode() = s.getPat()
284284
)
285285
or
286-
// An edge from a pattern to its corresponding SSA definition.
287-
nodeFrom.(Node::PatNode).getPat() =
288-
nodeTo.(Node::SsaNode).getDefinitionExt().getSourceVariable().getPat()
286+
// An edge from a pattern/expression to its corresponding SSA definition.
287+
nodeFrom.(Node::AstCfgFlowNode).getCfgNode() =
288+
nodeTo.(Node::SsaNode).getDefinitionExt().(Ssa::WriteDefinition).getControlFlowNode()
289+
or
290+
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
289291
}
290292
}
291293

@@ -400,11 +402,7 @@ module RustDataFlow implements InputSig<Location> {
400402
* are the value-preserving intra-callable flow steps.
401403
*/
402404
predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo, string model) {
403-
(
404-
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
405-
or
406-
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
407-
) and
405+
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo) and
408406
model = ""
409407
}
410408

@@ -528,8 +526,6 @@ private module Cached {
528526
cached
529527
predicate localFlowStepImpl(Node::Node nodeFrom, Node::Node nodeTo) {
530528
LocalFlow::localFlowStepCommon(nodeFrom, nodeTo)
531-
or
532-
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
533529
}
534530
}
535531

rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
| main.rs:45:15:45:23 | CallExpr | main.rs:45:9:45:23 | BreakExpr |
4444
| main.rs:51:9:51:13 | [SSA] i | main.rs:52:10:52:10 | i |
4545
| main.rs:51:9:51:13 | i | main.rs:51:9:51:13 | [SSA] i |
46-
| main.rs:51:9:51:13 | i | main.rs:53:5:53:5 | [SSA] i |
4746
| main.rs:51:17:51:17 | 1 | main.rs:51:9:51:13 | i |
4847
| main.rs:53:5:53:5 | [SSA] i | main.rs:54:10:54:10 | i |
4948
| main.rs:53:5:53:5 | i | main.rs:53:5:53:5 | [SSA] i |

rust/ql/test/library-tests/variables/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 0 additions & 5 deletions
This file was deleted.

rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ uniqueEnclosingCallable
33
| main.rs:198:28:198:28 | x | Node should have one enclosing callable but has 0. |
44
| main.rs:202:28:202:28 | x | Node should have one enclosing callable but has 0. |
55
| main.rs:206:28:206:28 | x | Node should have one enclosing callable but has 0. |
6-
localFlowIsLocal
7-
| main.rs:432:9:432:10 | i6 | main.rs:434:20:434:44 | [SSA] <captured entry> i6 | Local flow step does not preserve enclosing callable. |

0 commit comments

Comments
 (0)