Skip to content

Commit

Permalink
Merge pull request #17954 from paldepind/rust-data-flow-fix-inconsist…
Browse files Browse the repository at this point in the history
…encies

Rust: Fix data flow fix inconsistencies
  • Loading branch information
paldepind authored Nov 11, 2024
2 parents 89a2f0d + aebce74 commit ad6bd88
Show file tree
Hide file tree
Showing 111 changed files with 19 additions and 710 deletions.
8 changes: 8 additions & 0 deletions rust/ql/lib/codeql/rust/controlflow/CfgNodes.qll
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ class AstCfgNode extends CfgNode {
AstCfgNode() { node = this.getAstNode() }
}

/** A CFG node that corresponds to a parameter in the AST. */
class ParamCfgNode extends AstCfgNode {
override Param node;

/** Gets the underlying parameter. */
Param getParam() { result = node }
}

/** A CFG node that corresponds to an expression in the AST. */
class ExprCfgNode extends AstCfgNode {
override Expr node;
Expand Down
16 changes: 9 additions & 7 deletions rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ final class NormalCall extends DataFlowCall, TNormalCall {
/** Gets the underlying call in the CFG, if any. */
override CallCfgNode asCall() { result = c }

override DataFlowCallable getEnclosingCallable() { none() }
override DataFlowCallable getEnclosingCallable() {
result = TCfgScope(c.getExpr().getEnclosingCallable())
}

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

Expand Down Expand Up @@ -150,18 +152,18 @@ module Node {
* flow graph.
*/
final class ParameterNode extends Node, TParameterNode {
Param parameter;
ParamCfgNode parameter;

ParameterNode() { this = TParameterNode(parameter) }

override CfgScope getCfgScope() { result = parameter.getEnclosingCallable() }
override CfgScope getCfgScope() { result = parameter.getParam().getEnclosingCallable() }

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

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

/** Gets the parameter in the AST that this node corresponds to. */
Param getParameter() { result = parameter }
Param getParameter() { result = parameter.getParam() }
}

final class ArgumentNode = NaNode;
Expand Down Expand Up @@ -198,7 +200,7 @@ module Node {
abstract DataFlowCall getCall();
}

final private class ExprOutNode extends OutNode {
final private class ExprOutNode extends ExprNode, OutNode {
ExprOutNode() { this.asExpr() instanceof CallExpr }

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

private Node::ParameterNode toParameterNode(Param p) { result = TParameterNode(p) }
private Node::ParameterNode toParameterNode(Param p) { result.getParameter() = p }

/** Converts a control flow node into an SSA control flow node. */
Impl::Node asNode(Node n) {
Expand Down Expand Up @@ -482,7 +484,7 @@ private module Cached {
cached
newtype TNode =
TExprNode(ExprCfgNode n) or
TParameterNode(Param p) or
TParameterNode(ParamCfgNode p) or
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node)

cached
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ad6bd88

Please sign in to comment.