@@ -48,7 +48,7 @@ final class DataFlowCall extends TDataFlowCall {
4848
4949 MethodCallExprCfgNode asMethodCallExprCfgNode ( ) { this = TMethodCall ( result ) }
5050
51- ExprCfgNode asExprCfgNode ( ) {
51+ CallExprBaseCfgNode asExprCfgNode ( ) {
5252 result = this .asCallExprCfgNode ( ) or result = this .asMethodCallExprCfgNode ( )
5353 }
5454
@@ -76,7 +76,7 @@ module Node {
7676 /**
7777 * Gets the expression that corresponds to this node, if any.
7878 */
79- Expr asExpr ( ) { none ( ) }
79+ ExprCfgNode asExpr ( ) { none ( ) }
8080
8181 /** Gets the enclosing callable. */
8282 DataFlowCallable getEnclosingCallable ( ) { result = TCfgScope ( this .getCfgScope ( ) ) }
@@ -115,13 +115,13 @@ module Node {
115115 abstract class AstCfgFlowNode extends Node {
116116 AstCfgNode n ;
117117
118- override CfgNode getCfgNode ( ) { result = n }
118+ final override CfgNode getCfgNode ( ) { result = n }
119119
120- override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
120+ final override CfgScope getCfgScope ( ) { result = n .getAstNode ( ) .getEnclosingCfgScope ( ) }
121121
122- override Location getLocation ( ) { result = n .getAstNode ( ) .getLocation ( ) }
122+ final override Location getLocation ( ) { result = n .getAstNode ( ) .getLocation ( ) }
123123
124- override string toString ( ) { result = n .getAstNode ( ) .toString ( ) }
124+ final override string toString ( ) { result = n .getAstNode ( ) .toString ( ) }
125125 }
126126
127127 /**
@@ -137,7 +137,7 @@ module Node {
137137
138138 ExprNode ( ) { this = TExprNode ( n ) }
139139
140- override Expr asExpr ( ) { result = n . getExpr ( ) }
140+ override ExprCfgNode asExpr ( ) { result = n }
141141 }
142142
143143 final class PatNode extends AstCfgFlowNode , TPatNode {
@@ -159,7 +159,7 @@ module Node {
159159 ParameterNode ( ) { this = TParameterNode ( n ) }
160160
161161 /** Gets the parameter in the AST that this node corresponds to. */
162- Param getParameter ( ) { result = n . getParam ( ) }
162+ ParamCfgNode getParameter ( ) { result = n }
163163 }
164164
165165 final class ArgumentNode = NaNode ;
@@ -197,7 +197,7 @@ module Node {
197197 }
198198
199199 final private class ExprOutNode extends ExprNode , OutNode {
200- ExprOutNode ( ) { this .asExpr ( ) instanceof CallExpr }
200+ ExprOutNode ( ) { this .asExpr ( ) instanceof CallExprCfgNode }
201201
202202 /** Gets the underlying call CFG node that includes this out node. */
203203 override DataFlowCall getCall ( ) { result .asExprCfgNode ( ) = this .getCfgNode ( ) }
@@ -228,13 +228,13 @@ final class Node = Node::Node;
228228module SsaFlow {
229229 private module Impl = SsaImpl:: DataFlowIntegration;
230230
231- private Node:: ParameterNode toParameterNode ( Param p ) { result .getParameter ( ) = p }
231+ private Node:: ParameterNode toParameterNode ( ParamCfgNode p ) { result .getParameter ( ) = p }
232232
233233 /** Converts a control flow node into an SSA control flow node. */
234234 Impl:: Node asNode ( Node n ) {
235235 n = TSsaNode ( result )
236236 or
237- result .( Impl:: ExprNode ) .getExpr ( ) = n .( Node :: ExprNode ) . getCfgNode ( )
237+ result .( Impl:: ExprNode ) .getExpr ( ) = n .asExpr ( )
238238 or
239239 n = toParameterNode ( result .( Impl:: ParameterNode ) .getParameter ( ) )
240240 }
@@ -248,46 +248,40 @@ module SsaFlow {
248248 }
249249}
250250
251- /**
252- * Holds for expressions `e` that evaluate to the value of any last (in
253- * evaluation order) subexpressions within it. E.g., expressions that propagate
254- * a values from a subexpression.
255- *
256- * For instance, the predicate holds for if expressions as `if b { e1 } else {
257- * e2 }` evalates to the value of one of the subexpressions `e1` or `e2`.
258- */
259- private predicate propagatesValue ( Expr e ) {
260- e instanceof IfExpr or
261- e instanceof LoopExpr or
262- e instanceof ReturnExpr or
263- e instanceof BreakExpr or
264- e .( BlockExpr ) .getStmtList ( ) .hasTailExpr ( ) or
265- e instanceof MatchExpr
266- }
267-
268251/**
269252 * Gets a node that may execute last in `n`, and which, when it executes last,
270253 * will be the value of `n`.
271254 */
272- private ExprCfgNode getALastEvalNode ( ExprCfgNode n ) {
273- propagatesValue ( n .getExpr ( ) ) and result .getASuccessor ( ) = n
255+ private ExprCfgNode getALastEvalNode ( ExprCfgNode e ) {
256+ e = any ( IfExprCfgNode n | result = [ n .getThen ( ) , n .getElse ( ) ] ) or
257+ result = e .( LoopExprCfgNode ) .getLoopBody ( ) or
258+ result = e .( ReturnExprCfgNode ) .getExpr ( ) or
259+ result = e .( BreakExprCfgNode ) .getExpr ( ) or
260+ result = e .( BlockExprCfgNode ) .getTailExpr ( ) or
261+ result = e .( MatchExprCfgNode ) .getArmExpr ( _) or
262+ result .( BreakExprCfgNode ) .getTarget ( ) = e
274263}
275264
276265module LocalFlow {
277266 pragma [ nomagic]
278267 predicate localFlowStepCommon ( Node nodeFrom , Node nodeTo ) {
279268 nodeFrom .getCfgNode ( ) = getALastEvalNode ( nodeTo .getCfgNode ( ) )
280269 or
281- exists ( LetStmt s |
282- nodeFrom .getCfgNode ( ) . getAstNode ( ) = s .getInitializer ( ) and
283- nodeTo .getCfgNode ( ) . getAstNode ( ) = s .getPat ( )
270+ exists ( LetStmtCfgNode s |
271+ nodeFrom .getCfgNode ( ) = s .getInitializer ( ) and
272+ nodeTo .getCfgNode ( ) = s .getPat ( )
284273 )
285274 or
286275 // An edge from a pattern/expression to its corresponding SSA definition.
287276 nodeFrom .( Node:: AstCfgFlowNode ) .getCfgNode ( ) =
288277 nodeTo .( Node:: SsaNode ) .getDefinitionExt ( ) .( Ssa:: WriteDefinition ) .getControlFlowNode ( )
289278 or
290279 SsaFlow:: localFlowStep ( _, nodeFrom , nodeTo , _)
280+ or
281+ exists ( AssignmentExprCfgNode a |
282+ a .getRhs ( ) = nodeFrom .getCfgNode ( ) and
283+ a .getLhs ( ) = nodeTo .getCfgNode ( )
284+ )
291285 }
292286}
293287
@@ -329,7 +323,7 @@ module RustDataFlow implements InputSig<Location> {
329323 class DataFlowExpr = ExprCfgNode ;
330324
331325 /** Gets the node corresponding to `e`. */
332- Node exprNode ( DataFlowExpr e ) { result .getCfgNode ( ) = e }
326+ Node exprNode ( DataFlowExpr e ) { result .asExpr ( ) = e }
333327
334328 final class DataFlowCall = DataFlowCallAlias ;
335329
0 commit comments