@@ -278,14 +278,20 @@ module LocalFlow {
278
278
)
279
279
}
280
280
281
+ private Ssa:: Definition getSsaDefinition ( Node n ) {
282
+ result = n .( SsaDefinitionNode ) .getDefinition ( )
283
+ or
284
+ result = n .( ExplicitParameterNode ) .getSsaDefinition ( )
285
+ }
286
+
281
287
/**
282
288
* Holds if there is a local flow step from `nodeFrom` to `nodeTo` involving
283
289
* SSA definition `def.
284
290
*/
285
291
predicate localSsaFlowStep ( Ssa:: Definition def , Node nodeFrom , Node nodeTo ) {
286
- // Flow from SSA definition to first read
292
+ // Flow from SSA definition/parameter to first read
287
293
exists ( ControlFlow:: Node cfn |
288
- def = nodeFrom . ( SsaDefinitionNode ) . getDefinition ( ) and
294
+ def = getSsaDefinition ( nodeFrom ) and
289
295
nodeTo .asExprAtNode ( cfn ) = def .getAFirstReadAtNode ( cfn )
290
296
)
291
297
or
@@ -323,11 +329,10 @@ module LocalFlow {
323
329
)
324
330
}
325
331
326
- predicate localFlowCapturedVarStep ( SsaDefinitionNode nodeFrom , ImplicitCapturedArgumentNode nodeTo ) {
332
+ predicate localFlowCapturedVarStep ( Node nodeFrom , ImplicitCapturedArgumentNode nodeTo ) {
327
333
// Flow from SSA definition to implicit captured variable argument
328
334
exists ( Ssa:: ExplicitDefinition def , ControlFlow:: Nodes:: ElementNode call |
329
- def = nodeFrom .getDefinition ( )
330
- |
335
+ def = getSsaDefinition ( nodeFrom ) and
331
336
def .isCapturedVariableDefinitionFlowIn ( _, call , _) and
332
337
nodeTo = TImplicitCapturedArgumentNode ( call , def .getSourceVariable ( ) .getAssignable ( ) )
333
338
)
@@ -569,9 +574,15 @@ private module Cached {
569
574
Stages:: DataFlowStage:: forceCachingInSameStage ( ) and cfn .getElement ( ) instanceof Expr
570
575
} or
571
576
TCilExprNode ( CIL:: Expr e ) { e .getImplementation ( ) instanceof CIL:: BestImplementation } or
572
- TSsaDefinitionNode ( Ssa:: Definition def ) or
573
- TInstanceParameterNode ( Callable c ) { c .hasBody ( ) and not c .( Modifiable ) .isStatic ( ) } or
574
- TCilParameterNode ( CIL:: MethodParameter p ) { p .getMethod ( ) .hasBody ( ) } or
577
+ TSsaDefinitionNode ( Ssa:: Definition def ) {
578
+ // Handled by `TExplicitParameterNode` below
579
+ not def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) instanceof
580
+ AssignableDefinitions:: ImplicitParameterDefinition
581
+ } or
582
+ TExplicitParameterNode ( DotNet:: Parameter p ) { p .isUnboundDeclaration ( ) } or
583
+ TInstanceParameterNode ( Callable c ) {
584
+ c .isUnboundDeclaration ( ) and not c .( Modifiable ) .isStatic ( )
585
+ } or
575
586
TYieldReturnNode ( ControlFlow:: Nodes:: ElementNode cfn ) {
576
587
any ( Callable c ) .canYieldReturn ( cfn .getElement ( ) )
577
588
} or
@@ -605,18 +616,6 @@ private module Cached {
605
616
cfn .getElement ( ) = fla .getQualifier ( )
606
617
)
607
618
} or
608
- TSummaryParameterNode ( SummarizedCallable c , int i ) {
609
- exists ( SummaryInput input | FlowSummaryImpl:: Private:: summary ( c , input , _, _, _, _) |
610
- input = SummaryInput:: parameter ( i )
611
- or
612
- input = SummaryInput:: delegate ( i )
613
- )
614
- or
615
- exists ( SummaryOutput output |
616
- FlowSummaryImpl:: Private:: summary ( c , _, _, output , _, _) and
617
- output = SummaryOutput:: delegate ( i , _)
618
- )
619
- } or
620
619
TSummaryInternalNode (
621
620
SummarizedCallable c , FlowSummaryImpl:: Private:: SummaryInternalNodeState state
622
621
) {
@@ -801,12 +800,10 @@ private module Cached {
801
800
cached
802
801
predicate isUnreachableInCall ( Node n , DataFlowCall call ) {
803
802
exists (
804
- SsaDefinitionNode paramNode , Ssa:: ExplicitDefinition param , Guard guard ,
805
- ControlFlow:: SuccessorTypes:: BooleanSuccessor bs
803
+ ExplicitParameterNode paramNode , Guard guard , ControlFlow:: SuccessorTypes:: BooleanSuccessor bs
806
804
|
807
805
viableConstantBooleanParamArg ( paramNode , bs .getValue ( ) .booleanNot ( ) , call ) and
808
- paramNode .getDefinition ( ) = param and
809
- param .getARead ( ) = guard and
806
+ paramNode .getSsaDefinition ( ) .getARead ( ) = guard and
810
807
guard .controlsBlock ( n .getControlFlowNode ( ) .getBasicBlock ( ) , bs , _)
811
808
)
812
809
}
@@ -874,6 +871,11 @@ private module Cached {
874
871
def instanceof Ssa:: ImplicitCallDefinition
875
872
)
876
873
or
874
+ exists ( Parameter p |
875
+ p = n .( ParameterNode ) .getParameter ( ) and
876
+ not p .fromSource ( )
877
+ )
878
+ or
877
879
n instanceof YieldReturnNode
878
880
or
879
881
n instanceof ImplicitCapturedArgumentNode
@@ -905,33 +907,25 @@ class SsaDefinitionNode extends NodeImpl, TSsaDefinitionNode {
905
907
906
908
override Location getLocationImpl ( ) { result = def .getLocation ( ) }
907
909
908
- override string toStringImpl ( ) {
909
- not explicitParameterNode ( this , _) and
910
- result = def .toString ( )
911
- }
910
+ override string toStringImpl ( ) { result = def .toString ( ) }
912
911
}
913
912
914
913
private module ParameterNodes {
915
914
abstract private class ParameterNodeImpl extends ParameterNode , NodeImpl { }
916
915
917
- /**
918
- * Holds if definition node `node` is an entry definition for parameter `p`.
919
- */
920
- predicate explicitParameterNode ( AssignableDefinitionNode node , Parameter p ) {
921
- p = node .getDefinition ( ) .( AssignableDefinitions:: ImplicitParameterDefinition ) .getParameter ( )
922
- }
923
-
924
916
/**
925
917
* The value of an explicit parameter at function entry, viewed as a node in a data
926
918
* flow graph.
927
919
*/
928
- class ExplicitParameterNode extends ParameterNodeImpl {
920
+ class ExplicitParameterNode extends ParameterNodeImpl , TExplicitParameterNode {
929
921
private DotNet:: Parameter parameter ;
930
922
931
- ExplicitParameterNode ( ) {
932
- explicitParameterNode ( this , parameter )
933
- or
934
- this = TCilParameterNode ( parameter )
923
+ ExplicitParameterNode ( ) { this = TExplicitParameterNode ( parameter ) }
924
+
925
+ /** Gets the SSA definition corresponding to this parameter, if any. */
926
+ Ssa:: ExplicitDefinition getSsaDefinition ( ) {
927
+ result .getADefinition ( ) .( AssignableDefinitions:: ImplicitParameterDefinition ) .getParameter ( ) =
928
+ this .getParameter ( )
935
929
}
936
930
937
931
override DotNet:: Parameter getParameter ( ) { result = parameter }
@@ -1037,46 +1031,6 @@ private module ParameterNodes {
1037
1031
c = this .getEnclosingCallable ( )
1038
1032
}
1039
1033
}
1040
-
1041
- /** A parameter node for a callable with a flow summary. */
1042
- class SummaryParameterNode extends ParameterNodeImpl , SummaryNodeImpl , TSummaryParameterNode {
1043
- private SummarizedCallable sc ;
1044
- private int i ;
1045
-
1046
- SummaryParameterNode ( ) { this = TSummaryParameterNode ( sc , i ) }
1047
-
1048
- override Parameter getParameter ( ) { result = sc .getParameter ( i ) }
1049
-
1050
- override predicate isParameterOf ( DataFlowCallable c , int pos ) {
1051
- c = sc and
1052
- pos = i
1053
- }
1054
-
1055
- override Callable getEnclosingCallableImpl ( ) { result = sc }
1056
-
1057
- override Type getTypeImpl ( ) {
1058
- result = sc .getParameter ( i ) .getType ( )
1059
- or
1060
- i = - 1 and
1061
- result = sc .getDeclaringType ( )
1062
- }
1063
-
1064
- override ControlFlow:: Node getControlFlowNodeImpl ( ) { none ( ) }
1065
-
1066
- override Location getLocationImpl ( ) {
1067
- result = sc .getParameter ( i ) .getLocation ( )
1068
- or
1069
- i = - 1 and
1070
- result = sc .getLocation ( )
1071
- }
1072
-
1073
- override string toStringImpl ( ) {
1074
- result = "[summary] " + sc .getParameter ( i )
1075
- or
1076
- i = - 1 and
1077
- result = "[summary] this"
1078
- }
1079
- }
1080
1034
}
1081
1035
1082
1036
import ParameterNodes
@@ -1934,7 +1888,7 @@ private class ConstantBooleanArgumentNode extends ExprNode {
1934
1888
1935
1889
pragma [ noinline]
1936
1890
private predicate viableConstantBooleanParamArg (
1937
- SsaDefinitionNode paramNode , boolean b , DataFlowCall call
1891
+ ParameterNode paramNode , boolean b , DataFlowCall call
1938
1892
) {
1939
1893
exists ( ConstantBooleanArgumentNode arg |
1940
1894
viableParamArg ( call , paramNode , arg ) and
0 commit comments