Skip to content

Commit

Permalink
Rust: Use ParamBase in data flow implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Nov 25, 2024
1 parent 0d02126 commit 0de6658
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class ParameterPosition extends TParameterPosition {
result = "self" and this.isSelf()
}

AstNode getParameterIn(ParamList ps) {
ParamBase getParameterIn(ParamList ps) {
result = ps.getParam(this.getPosition())
or
result = ps.getSelfParam() and this.isSelf()
Expand Down Expand Up @@ -181,28 +181,17 @@ module Node {
PatCfgNode getPat() { result = n }
}

abstract class ParameterNode extends AstCfgFlowNode { }

/**
* The value of a parameter at function entry, viewed as a node in a data
* flow graph.
*/
final class PositionalParameterNode extends ParameterNode, TParameterNode {
override ParamCfgNode n;
final class ParameterNode extends AstCfgFlowNode, TParameterNode {
override ParamBaseCfgNode n;

PositionalParameterNode() { this = TParameterNode(n) }
ParameterNode() { this = TParameterNode(n) }

/** Gets the parameter in the CFG that this node corresponds to. */
ParamCfgNode getParameter() { result = n }
}

final class SelfParameterNode extends ParameterNode, TSelfParameterNode {
override SelfParamCfgNode n;

SelfParameterNode() { this = TSelfParameterNode(n) }

/** Gets the self parameter in the AST that this node corresponds to. */
SelfParamCfgNode getSelfParameter() { result = n }
ParamBaseCfgNode getParameter() { result = n }
}

final class ArgumentNode extends ExprNode {
Expand Down Expand Up @@ -284,7 +273,7 @@ module SsaFlow {
private module SsaFlow = SsaImpl::DataFlowIntegration;

private Node::ParameterNode toParameterNode(ParamCfgNode p) {
result.(Node::PositionalParameterNode).getParameter() = p
result.(Node::ParameterNode).getParameter() = p

Check warning

Code scanning / CodeQL

Redundant cast Warning

Redundant cast to
ParameterNode
.
}

/** Converts a control flow node into an SSA control flow node. */
Expand Down Expand Up @@ -333,7 +322,7 @@ module LocalFlow {
nodeFrom.(Node::AstCfgFlowNode).getCfgNode() =
nodeTo.(Node::SsaNode).getDefinitionExt().(Ssa::WriteDefinition).getControlFlowNode()
or
nodeFrom.(Node::PositionalParameterNode).getParameter().getPat() =
nodeFrom.(Node::ParameterNode).getParameter().(ParamCfgNode).getPat() =
nodeTo.(Node::PatNode).getPat()
or
SsaFlow::localFlowStep(_, nodeFrom, nodeTo, _)
Expand Down Expand Up @@ -559,8 +548,7 @@ private module Cached {
cached
newtype TNode =
TExprNode(ExprCfgNode n) or
TParameterNode(ParamCfgNode p) or
TSelfParameterNode(SelfParamCfgNode p) or
TParameterNode(ParamBaseCfgNode p) or
TPatNode(PatCfgNode p) or
TArgumentPostUpdateNode(ExprCfgNode e) { isArgumentForCall(e, _, _) } or
TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node)
Expand Down

0 comments on commit 0de6658

Please sign in to comment.