@@ -22,13 +22,13 @@ private import semmle.code.csharp.frameworks.system.threading.Tasks
22
22
DataFlowCallable nodeGetEnclosingCallable ( Node n ) { result = n .getEnclosingCallable ( ) }
23
23
24
24
/** 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 )
27
27
}
28
28
29
29
/** Holds if `arg` is an `ArgumentNode` of `c` with position `pos`. */
30
30
predicate isArgumentNode ( ArgumentNode arg , DataFlowCall c , ArgumentPosition pos ) {
31
- exists ( int i | pos = MkArgumentPosition ( i ) and arg .argumentOf ( c , i ) )
31
+ arg .argumentOf ( c , pos )
32
32
}
33
33
34
34
abstract class NodeImpl extends Node {
@@ -469,26 +469,28 @@ private predicate isParamsArg(Call c, Expr arg, Parameter p) {
469
469
/** An argument of a C# call (including qualifier arguments). */
470
470
private class Argument extends Expr {
471
471
private Expr call ;
472
- private int arg ;
472
+ private ArgumentPosition arg ;
473
473
474
474
Argument ( ) {
475
475
call =
476
476
any ( DispatchCall dc |
477
- this = dc .getArgument ( arg ) and
477
+ this = dc .getArgument ( arg . getPosition ( ) ) and
478
478
not isParamsArg ( _, this , _)
479
479
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 ( )
481
483
) .getCall ( )
482
484
or
483
- this = call .( DelegateLikeCall ) .getArgument ( arg )
485
+ this = call .( DelegateLikeCall ) .getArgument ( arg . getPosition ( ) )
484
486
}
485
487
486
488
/**
487
489
* Holds if this expression is the `i`th argument of `c`.
488
490
*
489
491
* Qualifier arguments have index `-1`.
490
492
*/
491
- predicate isArgumentOf ( Expr c , int i ) { c = call and i = arg }
493
+ predicate isArgumentOf ( Expr c , ArgumentPosition pos ) { c = call and pos = arg }
492
494
}
493
495
494
496
/**
@@ -855,7 +857,7 @@ class SsaDefinitionNode extends NodeImpl, TSsaDefinitionNode {
855
857
}
856
858
857
859
abstract class ParameterNodeImpl extends NodeImpl {
858
- abstract predicate isParameterOf ( DataFlowCallable c , int i ) ;
860
+ abstract predicate isParameterOf ( DataFlowCallable c , ParameterPosition pos ) ;
859
861
}
860
862
861
863
private module ParameterNodes {
@@ -874,7 +876,9 @@ private module ParameterNodes {
874
876
parameter
875
877
}
876
878
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
+ }
878
882
879
883
override DataFlowCallable getEnclosingCallableImpl ( ) { result = parameter .getCallable ( ) }
880
884
@@ -896,7 +900,9 @@ private module ParameterNodes {
896
900
/** Gets the callable containing this implicit instance parameter. */
897
901
Callable getCallable ( ) { result = callable }
898
902
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
+ }
900
906
901
907
override DataFlowCallable getEnclosingCallableImpl ( ) { result = callable }
902
908
@@ -909,42 +915,15 @@ private module ParameterNodes {
909
915
override string toStringImpl ( ) { result = "this" }
910
916
}
911
917
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 ;
929
921
930
- int getId ( CapturedVariable v ) { idOf ( v , result ) }
922
+ SsaCapturedEntryDefinition ( ) { this . getSourceVariable ( ) . getAssignable ( ) = v }
931
923
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 }
944
925
}
945
926
946
- private import ImplicitCapturedParameterNodeImpl
947
-
948
927
/**
949
928
* The value of an implicit captured variable parameter at function entry,
950
929
* viewed as a node in a data flow graph.
@@ -970,8 +949,8 @@ private module ParameterNodes {
970
949
/** Gets the captured variable that this implicit parameter models. */
971
950
LocalScopeVariable getVariable ( ) { result = def .getVariable ( ) }
972
951
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
975
954
c = this .getEnclosingCallable ( )
976
955
}
977
956
}
@@ -982,11 +961,13 @@ import ParameterNodes
982
961
/** A data-flow node that represents a call argument. */
983
962
class ArgumentNode extends Node instanceof ArgumentNodeImpl {
984
963
/** 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
+ }
986
967
}
987
968
988
969
abstract private class ArgumentNodeImpl extends Node {
989
- abstract predicate argumentOf ( DataFlowCall call , int pos ) ;
970
+ abstract predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) ;
990
971
}
991
972
992
973
private module ArgumentNodes {
@@ -1011,7 +992,7 @@ private module ArgumentNodes {
1011
992
this .asExpr ( ) = any ( CIL:: Call call ) .getAnArgument ( )
1012
993
}
1013
994
1014
- override predicate argumentOf ( DataFlowCall call , int pos ) {
995
+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1015
996
exists ( ArgumentConfiguration x , Expr c , Argument arg |
1016
997
arg = this .asExpr ( ) and
1017
998
c = call .getExpr ( ) and
@@ -1022,7 +1003,7 @@ private module ArgumentNodes {
1022
1003
exists ( CIL:: Call c , CIL:: Expr arg |
1023
1004
arg = this .asExpr ( ) and
1024
1005
c = call .getExpr ( ) and
1025
- arg = c .getArgument ( pos )
1006
+ arg = c .getArgument ( pos . getPosition ( ) )
1026
1007
)
1027
1008
}
1028
1009
}
@@ -1060,10 +1041,15 @@ private module ArgumentNodes {
1060
1041
)
1061
1042
}
1062
1043
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
+ |
1065
1049
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
1067
1053
call .getControlFlowNode ( ) = cfn and
1068
1054
if call instanceof TransitiveCapturedDataFlowCall
1069
1055
then additionalCalls = true
@@ -1091,9 +1077,9 @@ private module ArgumentNodes {
1091
1077
1092
1078
MallocNode ( ) { this = TMallocNode ( cfn ) }
1093
1079
1094
- override predicate argumentOf ( DataFlowCall call , int pos ) {
1080
+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1095
1081
call = TNonDelegateCall ( cfn , _) and
1096
- pos = - 1
1082
+ pos . isQualifier ( )
1097
1083
}
1098
1084
1099
1085
override ControlFlow:: Node getControlFlowNodeImpl ( ) { result = cfn }
@@ -1130,9 +1116,9 @@ private module ArgumentNodes {
1130
1116
callCfn = any ( Call c | isParamsArg ( c , _, result ) ) .getAControlFlowNode ( )
1131
1117
}
1132
1118
1133
- override predicate argumentOf ( DataFlowCall call , int pos ) {
1119
+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1134
1120
callCfn = call .getControlFlowNode ( ) and
1135
- pos = this .getParameter ( ) .getPosition ( )
1121
+ pos . getPosition ( ) = this .getParameter ( ) .getPosition ( )
1136
1122
}
1137
1123
1138
1124
override DataFlowCallable getEnclosingCallableImpl ( ) { result = callCfn .getEnclosingCallable ( ) }
@@ -1149,11 +1135,8 @@ private module ArgumentNodes {
1149
1135
private class SummaryArgumentNode extends SummaryNode , ArgumentNodeImpl {
1150
1136
SummaryArgumentNode ( ) { FlowSummaryImpl:: Private:: summaryArgumentNode ( _, this , _) }
1151
1137
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 )
1157
1140
}
1158
1141
}
1159
1142
}
@@ -1870,8 +1853,8 @@ private module PostUpdateNodes {
1870
1853
1871
1854
override MallocNode getPreUpdateNode ( ) { result .getControlFlowNode ( ) = cfn }
1872
1855
1873
- override predicate argumentOf ( DataFlowCall call , int pos ) {
1874
- pos = - 1 and
1856
+ override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
1857
+ pos . isQualifier ( ) and
1875
1858
any ( ObjectOrCollectionInitializerConfiguration x )
1876
1859
.hasExprPath ( _, cfn , _, call .getControlFlowNode ( ) )
1877
1860
}
0 commit comments