-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Include patterns as data flow nodes #17971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,19 @@ | |
| override Location getLocation() { none() } | ||
| } | ||
|
|
||
| /** A data flow node that corresponds to a CFG node for an AST node. */ | ||
| abstract private class AstCfgFlowNode extends Node { | ||
| AstCfgNode n; | ||
|
|
||
| override CfgNode getCfgNode() { result = n } | ||
|
|
||
| override CfgScope getCfgScope() { result = n.getAstNode().getEnclosingCfgScope() } | ||
|
|
||
| override Location getLocation() { result = n.getAstNode().getLocation() } | ||
|
|
||
| override string toString() { result = n.getAstNode().toString() } | ||
| } | ||
|
|
||
| /** | ||
| * A node in the data flow graph that corresponds to an expression in the | ||
| * AST. | ||
|
|
@@ -131,39 +144,34 @@ | |
| * to multiple `ExprNode`s, just like it may correspond to multiple | ||
| * `ControlFlow::Node`s. | ||
| */ | ||
| class ExprNode extends Node, TExprNode { | ||
| ExprCfgNode n; | ||
| class ExprNode extends AstCfgFlowNode, TExprNode { | ||
| override ExprCfgNode n; | ||
|
|
||
| ExprNode() { this = TExprNode(n) } | ||
|
|
||
| override CfgScope getCfgScope() { result = this.asExpr().getEnclosingCfgScope() } | ||
|
|
||
| override Location getLocation() { result = n.getExpr().getLocation() } | ||
| override Expr asExpr() { result = n.getExpr() } | ||
| } | ||
|
|
||
| override string toString() { result = n.getExpr().toString() } | ||
| final class PatNode extends AstCfgFlowNode, TPatNode { | ||
| override PatCfgNode n; | ||
|
|
||
| override Expr asExpr() { result = n.getExpr() } | ||
| PatNode() { this = TPatNode(n) } | ||
|
|
||
| override CfgNode getCfgNode() { result = n } | ||
| /** Gets the Pat in the AST that this node corresponds to. */ | ||
| Pat getPat() { result = n.getPat() } | ||
| } | ||
|
|
||
| /** | ||
| * The value of a parameter at function entry, viewed as a node in a data | ||
| * flow graph. | ||
| */ | ||
| final class ParameterNode extends Node, TParameterNode { | ||
| ParamCfgNode parameter; | ||
| final class ParameterNode extends AstCfgFlowNode, TParameterNode { | ||
| override ParamCfgNode n; | ||
|
|
||
| ParameterNode() { this = TParameterNode(parameter) } | ||
|
|
||
| override CfgScope getCfgScope() { result = parameter.getParam().getEnclosingCfgScope() } | ||
|
|
||
| override Location getLocation() { result = parameter.getLocation() } | ||
|
|
||
| override string toString() { result = parameter.toString() } | ||
| ParameterNode() { this = TParameterNode(n) } | ||
|
|
||
| /** Gets the parameter in the AST that this node corresponds to. */ | ||
| Param getParameter() { result = parameter.getParam() } | ||
| Param getParameter() { result = n.getParam() } | ||
| } | ||
|
|
||
| final class ArgumentNode = NaNode; | ||
|
|
@@ -281,6 +289,11 @@ | |
| pragma[nomagic] | ||
| predicate localFlowStepCommon(Node nodeFrom, Node nodeTo) { | ||
| nodeFrom.getCfgNode() = getALastEvalNode(nodeTo.getCfgNode()) | ||
| or | ||
| exists(LetStmt s | | ||
| nodeFrom.getCfgNode().getAstNode() = s.getInitializer() and | ||
| nodeTo.getCfgNode().getAstNode() = s.getPat() | ||
| ) | ||
|
Comment on lines
+293
to
+296
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not take CFG splitting into account, but that changes once #17918 lands.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I can also adapt this after #17918 (if you don't want to do it all yourself). |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -485,6 +498,7 @@ | |
| newtype TNode = | ||
| TExprNode(ExprCfgNode n) or | ||
| TParameterNode(ParamCfgNode p) or | ||
| TPatNode(PatCfgNode p) or | ||
| TSsaNode(SsaImpl::DataFlowIntegration::SsaNode node) | ||
|
|
||
| cached | ||
|
|
||
Check warning
Code scanning / CodeQL
UnusedField Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a real problem.
nis used in one of the predicates inAstCfgFlowNodeand the subclasses do bind it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be able to suppress it with something like