@@ -297,71 +297,86 @@ private module Cached {
297297 any ( DelegateArgumentConfiguration x ) .hasExprPath ( _, cfn , _, call )
298298 } or
299299 TMallocNode ( ControlFlow:: Nodes:: ElementNode cfn ) { cfn .getElement ( ) instanceof ObjectCreation } or
300- TArgumentPostCallNode ( ControlFlow:: Nodes:: ElementNode cfn ) {
300+ TExprPostUpdateNode ( ControlFlow:: Nodes:: ElementNode cfn ) {
301301 exists ( Argument a , Type t |
302302 a = cfn .getElement ( ) and
303303 t = a .stripCasts ( ) .getType ( )
304304 |
305305 t instanceof RefType or
306306 t = any ( TypeParameter tp | not tp .isValueType ( ) )
307307 )
308- } or
309- TStoreTargetNode ( ControlFlow:: Nodes:: ElementNode cfn ) {
308+ or
310309 instanceFieldLikeAssign ( _, _, _, cfn .getElement ( ) )
310+ or
311+ exists ( TExprPostUpdateNode upd , FieldLikeAccess fla |
312+ upd = TExprPostUpdateNode ( fla .getAControlFlowNode ( ) )
313+ |
314+ cfn .getElement ( ) = fla .getQualifier ( )
315+ )
311316 }
312317
313- /**
314- * This is the local flow predicate that's used as a building block in global
315- * data flow. It may have less flow than the `localFlowStep` predicate.
316- */
318+ private predicate usesInstanceField ( Ssa:: Definition def ) {
319+ exists ( Ssa:: SourceVariables:: FieldOrPropSourceVariable fp | fp = def .getSourceVariable ( ) |
320+ not fp .getAssignable ( ) .isStatic ( )
321+ )
322+ }
323+
317324 cached
318- predicate simpleLocalFlowStep ( Node nodeFrom , Node nodeTo ) {
319- any ( LocalFlow:: LocalExprStepConfiguration x ) .hasNodePath ( nodeFrom , nodeTo )
325+ predicate localFlowStepImpl ( Node nodeFrom , Node nodeTo , boolean simple ) {
326+ any ( LocalFlow:: LocalExprStepConfiguration x ) .hasNodePath ( nodeFrom , nodeTo ) and
327+ simple = true
320328 or
321329 // Flow from SSA definition to first read
322330 exists ( Ssa:: Definition def , ControlFlow:: Node cfn |
323- def = nodeFrom .( SsaDefinitionNode ) .getDefinition ( )
324- |
325- nodeTo . asExprAtNode ( cfn ) = def . getAFirstReadAtNode ( cfn )
331+ def = nodeFrom .( SsaDefinitionNode ) .getDefinition ( ) and
332+ nodeTo . asExprAtNode ( cfn ) = def . getAFirstReadAtNode ( cfn ) and
333+ if usesInstanceField ( def ) then simple = false else simple = true
326334 )
327335 or
328336 // Flow from read to next read
329- exists ( ControlFlow:: Node cfnFrom , ControlFlow:: Node cfnTo |
330- Ssa:: Internal:: adjacentReadPairSameVar ( cfnFrom , cfnTo ) and
331- nodeTo = TExprNode ( cfnTo )
337+ exists ( Ssa:: Definition def , ControlFlow:: Node cfnFrom , ControlFlow:: Node cfnTo |
338+ Ssa:: Internal:: adjacentReadPairSameVar ( def , cfnFrom , cfnTo ) and
339+ nodeTo = TExprNode ( cfnTo ) and
340+ if usesInstanceField ( def ) then simple = false else simple = true
332341 |
333342 nodeFrom = TExprNode ( cfnFrom )
334343 or
335344 cfnFrom = nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) .getControlFlowNode ( )
336345 )
337346 or
338- ThisFlow:: adjacentThisRefs ( nodeFrom , nodeTo )
347+ ThisFlow:: adjacentThisRefs ( nodeFrom , nodeTo ) and
348+ simple = true
339349 or
340- ThisFlow:: adjacentThisRefs ( nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) , nodeTo )
350+ ThisFlow:: adjacentThisRefs ( nodeFrom .( PostUpdateNode ) .getPreUpdateNode ( ) , nodeTo ) and
351+ simple = true
341352 or
342353 // Flow into SSA pseudo definition
343354 exists ( Ssa:: Definition def , Ssa:: PseudoDefinition pseudo |
344- LocalFlow:: localFlowSsaInput ( nodeFrom , def )
345- |
355+ LocalFlow:: localFlowSsaInput ( nodeFrom , def ) and
346356 pseudo = nodeTo .( SsaDefinitionNode ) .getDefinition ( ) and
347- def = pseudo .getAnInput ( )
357+ def = pseudo .getAnInput ( ) and
358+ if usesInstanceField ( def ) then simple = false else simple = true
348359 )
349360 or
350361 // Flow into uncertain SSA definition
351362 exists ( Ssa:: Definition def , LocalFlow:: UncertainExplicitSsaDefinition uncertain |
352- LocalFlow:: localFlowSsaInput ( nodeFrom , def )
353- |
363+ LocalFlow:: localFlowSsaInput ( nodeFrom , def ) and
354364 uncertain = nodeTo .( SsaDefinitionNode ) .getDefinition ( ) and
355- def = uncertain .getPriorDefinition ( )
365+ def = uncertain .getPriorDefinition ( ) and
366+ if usesInstanceField ( def ) then simple = false else simple = true
356367 )
357368 or
358- LocalFlow:: localFlowCapturedVarStep ( nodeFrom , nodeTo )
369+ LocalFlow:: localFlowCapturedVarStep ( nodeFrom , nodeTo ) and
370+ simple = true
359371 or
360- flowOutOfDelegateLibraryCall ( nodeFrom , nodeTo , true )
372+ flowOutOfDelegateLibraryCall ( nodeFrom , nodeTo , true ) and
373+ simple = true
361374 or
362- flowThroughLibraryCallableOutRef ( _, nodeFrom , nodeTo , true )
375+ flowThroughLibraryCallableOutRef ( _, nodeFrom , nodeTo , true ) and
376+ simple = true
363377 or
364- LocalFlow:: localFlowStepCil ( nodeFrom , nodeTo )
378+ LocalFlow:: localFlowStepCil ( nodeFrom , nodeTo ) and
379+ simple = true
365380 }
366381
367382 /**
@@ -409,6 +424,15 @@ private module Cached {
409424}
410425import Cached
411426
427+ /**
428+ * This is the local flow predicate that is used as a building block in global
429+ * data flow. It is a strict subset of the `localFlowStep` predicate, as it
430+ * excludes SSA flow through instance fields.
431+ */
432+ predicate simpleLocalFlowStep ( Node nodeFrom , Node nodeTo ) {
433+ localFlowStepImpl ( nodeFrom , nodeTo , true )
434+ }
435+
412436/** An SSA definition, viewed as a node in a data flow graph. */
413437class SsaDefinitionNode extends Node , TSsaDefinitionNode {
414438 Ssa:: Definition def ;
@@ -1250,26 +1274,10 @@ private module PostUpdateNodes {
12501274 override MallocNode getPreUpdateNode ( ) { this = TExprNode ( result .getControlFlowNode ( ) ) }
12511275 }
12521276
1253- private class ArgumentPostCallNode extends PostUpdateNode , TArgumentPostCallNode {
1254- private ControlFlow:: Nodes:: ElementNode cfn ;
1255-
1256- ArgumentPostCallNode ( ) { this = TArgumentPostCallNode ( cfn ) }
1257-
1258- override ExprNode getPreUpdateNode ( ) { cfn = result .getControlFlowNode ( ) }
1259-
1260- override Callable getEnclosingCallable ( ) { result = cfn .getEnclosingCallable ( ) }
1261-
1262- override Type getType ( ) { result = cfn .getElement ( ) .( Expr ) .getType ( ) }
1263-
1264- override Location getLocation ( ) { result = cfn .getLocation ( ) }
1265-
1266- override string toString ( ) { result = "[post] " + cfn .toString ( ) }
1267- }
1268-
1269- private class StoreTargetNode extends PostUpdateNode , TStoreTargetNode {
1277+ private class ExprPostUpdateNode extends PostUpdateNode , TExprPostUpdateNode {
12701278 private ControlFlow:: Nodes:: ElementNode cfn ;
12711279
1272- StoreTargetNode ( ) { this = TStoreTargetNode ( cfn ) }
1280+ ExprPostUpdateNode ( ) { this = TExprPostUpdateNode ( cfn ) }
12731281
12741282 override ExprNode getPreUpdateNode ( ) { cfn = result .getControlFlowNode ( ) }
12751283
0 commit comments