Skip to content

Commit ad6bd88

Browse files
authored
Merge pull request github#17954 from paldepind/rust-data-flow-fix-inconsistencies
Rust: Fix data flow fix inconsistencies
2 parents 89a2f0d + aebce74 commit ad6bd88

File tree

111 files changed

+19
-710
lines changed

Some content is hidden

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

111 files changed

+19
-710
lines changed

rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class AstCfgNode extends CfgNode {
1414
AstCfgNode() { node = this.getAstNode() }
1515
}
1616

17+
/** A CFG node that corresponds to a parameter in the AST. */
18+
class ParamCfgNode extends AstCfgNode {
19+
override Param node;
20+
21+
/** Gets the underlying parameter. */
22+
Param getParam() { result = node }
23+
}
24+
1725
/** A CFG node that corresponds to an expression in the AST. */
1826
class ExprCfgNode extends AstCfgNode {
1927
override Expr node;

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ final class NormalCall extends DataFlowCall, TNormalCall {
6464
/** Gets the underlying call in the CFG, if any. */
6565
override CallCfgNode asCall() { result = c }
6666

67-
override DataFlowCallable getEnclosingCallable() { none() }
67+
override DataFlowCallable getEnclosingCallable() {
68+
result = TCfgScope(c.getExpr().getEnclosingCallable())
69+
}
6870

6971
override string toString() { result = c.toString() }
7072

@@ -150,18 +152,18 @@ module Node {
150152
* flow graph.
151153
*/
152154
final class ParameterNode extends Node, TParameterNode {
153-
Param parameter;
155+
ParamCfgNode parameter;
154156

155157
ParameterNode() { this = TParameterNode(parameter) }
156158

157-
override CfgScope getCfgScope() { result = parameter.getEnclosingCallable() }
159+
override CfgScope getCfgScope() { result = parameter.getParam().getEnclosingCallable() }
158160

159161
override Location getLocation() { result = parameter.getLocation() }
160162

161163
override string toString() { result = parameter.toString() }
162164

163165
/** Gets the parameter in the AST that this node corresponds to. */
164-
Param getParameter() { result = parameter }
166+
Param getParameter() { result = parameter.getParam() }
165167
}
166168

167169
final class ArgumentNode = NaNode;
@@ -198,7 +200,7 @@ module Node {
198200
abstract DataFlowCall getCall();
199201
}
200202

201-
final private class ExprOutNode extends OutNode {
203+
final private class ExprOutNode extends ExprNode, OutNode {
202204
ExprOutNode() { this.asExpr() instanceof CallExpr }
203205

204206
/** Gets the underlying call CFG node that includes this out node. */
@@ -230,7 +232,7 @@ final class Node = Node::Node;
230232
module SsaFlow {
231233
private module Impl = SsaImpl::DataFlowIntegration;
232234

233-
private Node::ParameterNode toParameterNode(Param p) { result = TParameterNode(p) }
235+
private Node::ParameterNode toParameterNode(Param p) { result.getParameter() = p }
234236

235237
/** Converts a control flow node into an SSA control flow node. */
236238
Impl::Node asNode(Node n) {
@@ -482,7 +484,7 @@ private module Cached {
482484
cached
483485
newtype TNode =
484486
TExprNode(ExprCfgNode n) or
485-
TParameterNode(Param p) or
487+
TParameterNode(ParamCfgNode p) or
486488
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node)
487489

488490
cached

rust/ql/test/extractor-tests/canonical_path/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/Abi/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/ArgList/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/ArrayType/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/AssocTypeArg/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/Attr/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/AwaitExpr/CONSISTENCY/DataFlowConsistency.expected

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

rust/ql/test/extractor-tests/generated/BecomeExpr/CONSISTENCY/DataFlowConsistency.expected

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

0 commit comments

Comments
 (0)