From 0de66586608f8cfefd737cc40efebe5a83f75715 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Mon, 25 Nov 2024 14:18:08 +0100 Subject: [PATCH] Rust: Use `ParamBase` in data flow implementation --- .../rust/dataflow/internal/DataFlowImpl.qll | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll b/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll index 1ec8a42ee7e0..d5e496c3f0bc 100644 --- a/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll +++ b/rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll @@ -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() @@ -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 { @@ -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 } /** Converts a control flow node into an SSA control flow node. */ @@ -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, _) @@ -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)