@@ -22,13 +22,13 @@ private import semmle.code.csharp.frameworks.system.threading.Tasks
2222DataFlowCallable nodeGetEnclosingCallable ( Node n ) { result = n .getEnclosingCallable ( ) }
2323
2424/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
25- predicate isParameterNode ( ParameterNode p , DataFlowCallable c , ParameterPosition pos ) {
26- exists ( int i | pos = MkParameterPosition ( i ) and p .isParameterOf ( c , i ) )
25+ predicate isParameterNode ( ParameterNodeImpl p , DataFlowCallable c , ParameterPosition pos ) {
26+ p .isParameterOf ( c , pos )
2727}
2828
2929/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
3030predicate isArgumentNode ( ArgumentNode arg , DataFlowCall c , ArgumentPosition pos ) {
31- exists ( int i | pos = MkArgumentPosition ( i ) and arg .argumentOf ( c , i ) )
31+ arg .argumentOf ( c , pos )
3232}
3333
3434abstract class NodeImpl extends Node {
@@ -469,26 +469,28 @@ private predicate isParamsArg(Call c, Expr arg, Parameter p) {
469469/** An argument of a C# call (including qualifier arguments). */
470470private class Argument extends Expr {
471471 private Expr call ;
472- private int arg ;
472+ private ArgumentPosition arg ;
473473
474474 Argument ( ) {
475475 call =
476476 any ( DispatchCall dc |
477- this = dc .getArgument ( arg ) and
477+ this = dc .getArgument ( arg . getPosition ( ) ) and
478478 not isParamsArg ( _, this , _)
479479 or
480- this = dc .getQualifier ( ) and arg = - 1 and not dc .getAStaticTarget ( ) .( Modifiable ) .isStatic ( )
480+ this = dc .getQualifier ( ) and
481+ arg .isQualifier ( ) and
482+ not dc .getAStaticTarget ( ) .( Modifiable ) .isStatic ( )
481483 ) .getCall ( )
482484 or
483- this = call .( DelegateLikeCall ) .getArgument ( arg )
485+ this = call .( DelegateLikeCall ) .getArgument ( arg . getPosition ( ) )
484486 }
485487
486488 /**
487489 * Holds if this expression is the `i`th argument of `c`.
488490 *
489491 * Qualifier arguments have index `-1`.
490492 */
491- predicate isArgumentOf ( Expr c , int i ) { c = call and i = arg }
493+ predicate isArgumentOf ( Expr c , ArgumentPosition pos ) { c = call and pos = arg }
492494}
493495
494496/**
@@ -855,7 +857,7 @@ class SsaDefinitionNode extends NodeImpl, TSsaDefinitionNode {
855857}
856858
857859abstract class ParameterNodeImpl extends NodeImpl {
858- abstract predicate isParameterOf ( DataFlowCallable c , int i ) ;
860+ abstract predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) ;
859861}
860862
861863private module ParameterNodes {
@@ -874,7 +876,9 @@ private module ParameterNodes {
874876 parameter
875877 }
876878
877- override predicate isParameterOf ( DataFlowCallable c , int i ) { c .getParameter ( i ) = parameter }
879+ override predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) {
880+ c .getParameter ( pos .getPosition ( ) ) = parameter
881+ }
878882
879883 override DataFlowCallable getEnclosingCallableImpl ( ) { result = parameter .getCallable ( ) }
880884
@@ -896,7 +900,9 @@ private module ParameterNodes {
896900 /** Gets the callable containing this implicit instance parameter. */
897901 Callable getCallable ( ) { result = callable }
898902
899- override predicate isParameterOf ( DataFlowCallable c , int pos ) { callable = c and pos = - 1 }
903+ override predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) {
904+ callable = c and pos .isThisParameter ( )
905+ }
900906
901907 override DataFlowCallable getEnclosingCallableImpl ( ) { result = callable }
902908
@@ -909,42 +915,15 @@ private module ParameterNodes {
909915 override string toStringImpl ( ) { result = "this" }
910916 }
911917
912- module ImplicitCapturedParameterNodeImpl {
913- /** An implicit entry definition for a captured variable. */
914- class SsaCapturedEntryDefinition extends Ssa:: ImplicitEntryDefinition {
915- private LocalScopeVariable v ;
916-
917- SsaCapturedEntryDefinition ( ) { this .getSourceVariable ( ) .getAssignable ( ) = v }
918-
919- LocalScopeVariable getVariable ( ) { result = v }
920- }
921-
922- private class CapturedVariable extends LocalScopeVariable {
923- CapturedVariable ( ) { this = any ( SsaCapturedEntryDefinition d ) .getVariable ( ) }
924- }
925-
926- private predicate id ( CapturedVariable x , CapturedVariable y ) { x = y }
927-
928- private predicate idOf ( CapturedVariable x , int y ) = equivalenceRelation( id / 2 ) ( x , y )
918+ /** An implicit entry definition for a captured variable. */
919+ class SsaCapturedEntryDefinition extends Ssa:: ImplicitEntryDefinition {
920+ private LocalScopeVariable v ;
929921
930- int getId ( CapturedVariable v ) { idOf ( v , result ) }
922+ SsaCapturedEntryDefinition ( ) { this . getSourceVariable ( ) . getAssignable ( ) = v }
931923
932- // we model implicit parameters for captured variables starting from index `-2`,
933- // the order is irrelevant
934- int getParameterPosition ( SsaCapturedEntryDefinition def ) {
935- exists ( Callable c | c = def .getCallable ( ) |
936- def =
937- rank [ - result - 1 ] ( SsaCapturedEntryDefinition def0 |
938- def0 .getCallable ( ) = c
939- |
940- def0 order by getId ( def0 .getSourceVariable ( ) .getAssignable ( ) )
941- )
942- )
943- }
924+ LocalScopeVariable getVariable ( ) { result = v }
944925 }
945926
946- private import ImplicitCapturedParameterNodeImpl
947-
948927 /**
949928 * The value of an implicit captured variable parameter at function entry,
950929 * viewed as a node in a data flow graph.
@@ -970,8 +949,8 @@ private module ParameterNodes {
970949 /** Gets the captured variable that this implicit parameter models. */
971950 LocalScopeVariable getVariable ( ) { result = def .getVariable ( ) }
972951
973- override predicate isParameterOf ( DataFlowCallable c , int i ) {
974- i = getParameterPosition ( def ) and
952+ override predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) {
953+ pos . isImplicitCapturedParameterPosition ( def ) and
975954 c = this .getEnclosingCallable ( )
976955 }
977956 }
@@ -982,11 +961,13 @@ import ParameterNodes
982961/** A data-flow node that represents a call argument. */
983962class ArgumentNode extends Node instanceof ArgumentNodeImpl {
984963 /** Holds if this argument occurs at the given position in the given call. */
985- final predicate argumentOf ( DataFlowCall call , int pos ) { super .argumentOf ( call , pos ) }
964+ final predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
965+ super .argumentOf ( call , pos )
966+ }
986967}
987968
988969abstract private class ArgumentNodeImpl extends Node {
989- abstract predicate argumentOf ( DataFlowCall call , int pos ) ;
970+ abstract predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) ;
990971}
991972
992973private module ArgumentNodes {
@@ -1011,7 +992,7 @@ private module ArgumentNodes {
1011992 this .asExpr ( ) = any ( CIL:: Call call ) .getAnArgument ( )
1012993 }
1013994
1014- override predicate argumentOf ( DataFlowCall call , int pos ) {
995+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1015996 exists ( ArgumentConfiguration x , Expr c , Argument arg |
1016997 arg = this .asExpr ( ) and
1017998 c = call .getExpr ( ) and
@@ -1022,7 +1003,7 @@ private module ArgumentNodes {
10221003 exists ( CIL:: Call c , CIL:: Expr arg |
10231004 arg = this .asExpr ( ) and
10241005 c = call .getExpr ( ) and
1025- arg = c .getArgument ( pos )
1006+ arg = c .getArgument ( pos . getPosition ( ) )
10261007 )
10271008 }
10281009 }
@@ -1060,10 +1041,15 @@ private module ArgumentNodes {
10601041 )
10611042 }
10621043
1063- override predicate argumentOf ( DataFlowCall call , int pos ) {
1064- exists ( ImplicitCapturedParameterNode p , boolean additionalCalls |
1044+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1045+ exists (
1046+ ImplicitCapturedParameterNode p , boolean additionalCalls , ParameterPosition ppos ,
1047+ SsaCapturedEntryDefinition def
1048+ |
10651049 this .flowsInto ( p , additionalCalls ) and
1066- p .isParameterOf ( call .getARuntimeTarget ( ) , pos ) and
1050+ p .isParameterOf ( call .getARuntimeTarget ( ) , ppos ) and
1051+ pos .isImplicitCapturedArgumentPosition ( def ) and
1052+ ppos .isImplicitCapturedParameterPosition ( def ) and
10671053 call .getControlFlowNode ( ) = cfn and
10681054 if call instanceof TransitiveCapturedDataFlowCall
10691055 then additionalCalls = true
@@ -1091,9 +1077,9 @@ private module ArgumentNodes {
10911077
10921078 MallocNode ( ) { this = TMallocNode ( cfn ) }
10931079
1094- override predicate argumentOf ( DataFlowCall call , int pos ) {
1080+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
10951081 call = TNonDelegateCall ( cfn , _) and
1096- pos = - 1
1082+ pos . isQualifier ( )
10971083 }
10981084
10991085 override ControlFlow:: Node getControlFlowNodeImpl ( ) { result = cfn }
@@ -1130,9 +1116,9 @@ private module ArgumentNodes {
11301116 callCfn = any ( Call c | isParamsArg ( c , _, result ) ) .getAControlFlowNode ( )
11311117 }
11321118
1133- override predicate argumentOf ( DataFlowCall call , int pos ) {
1119+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
11341120 callCfn = call .getControlFlowNode ( ) and
1135- pos = this .getParameter ( ) .getPosition ( )
1121+ pos . getPosition ( ) = this .getParameter ( ) .getPosition ( )
11361122 }
11371123
11381124 override DataFlowCallable getEnclosingCallableImpl ( ) { result = callCfn .getEnclosingCallable ( ) }
@@ -1149,11 +1135,8 @@ private module ArgumentNodes {
11491135 private class SummaryArgumentNode extends SummaryNode , ArgumentNodeImpl {
11501136 SummaryArgumentNode ( ) { FlowSummaryImpl:: Private:: summaryArgumentNode ( _, this , _) }
11511137
1152- override predicate argumentOf ( DataFlowCall call , int pos ) {
1153- exists ( ArgumentPosition apos |
1154- FlowSummaryImpl:: Private:: summaryArgumentNode ( call , this , apos ) and
1155- apos .getPosition ( ) = pos
1156- )
1138+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1139+ FlowSummaryImpl:: Private:: summaryArgumentNode ( call , this , pos )
11571140 }
11581141 }
11591142}
@@ -1870,8 +1853,8 @@ private module PostUpdateNodes {
18701853
18711854 override MallocNode getPreUpdateNode ( ) { result .getControlFlowNode ( ) = cfn }
18721855
1873- override predicate argumentOf ( DataFlowCall call , int pos ) {
1874- pos = - 1 and
1856+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1857+ pos . isQualifier ( ) and
18751858 any ( ObjectOrCollectionInitializerConfiguration x )
18761859 .hasExprPath ( _, cfn , _, call .getControlFlowNode ( ) )
18771860 }
0 commit comments