@@ -278,14 +278,20 @@ module LocalFlow {
278278 )
279279 }
280280
281+ private Ssa:: Definition getSsaDefinition ( Node n ) {
282+ result = n .( SsaDefinitionNode ) .getDefinition ( )
283+ or
284+ result = n .( ExplicitParameterNode ) .getSsaDefinition ( )
285+ }
286+
281287 /**
282288 * Holds if there is a local flow step from `nodeFrom` to `nodeTo` involving
283289 * SSA definition `def.
284290 */
285291 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
287293 exists ( ControlFlow:: Node cfn |
288- def = nodeFrom . ( SsaDefinitionNode ) . getDefinition ( ) and
294+ def = getSsaDefinition ( nodeFrom ) and
289295 nodeTo .asExprAtNode ( cfn ) = def .getAFirstReadAtNode ( cfn )
290296 )
291297 or
@@ -323,11 +329,10 @@ module LocalFlow {
323329 )
324330 }
325331
326- predicate localFlowCapturedVarStep ( SsaDefinitionNode nodeFrom , ImplicitCapturedArgumentNode nodeTo ) {
332+ predicate localFlowCapturedVarStep ( Node nodeFrom , ImplicitCapturedArgumentNode nodeTo ) {
327333 // Flow from SSA definition to implicit captured variable argument
328334 exists ( Ssa:: ExplicitDefinition def , ControlFlow:: Nodes:: ElementNode call |
329- def = nodeFrom .getDefinition ( )
330- |
335+ def = getSsaDefinition ( nodeFrom ) and
331336 def .isCapturedVariableDefinitionFlowIn ( _, call , _) and
332337 nodeTo = TImplicitCapturedArgumentNode ( call , def .getSourceVariable ( ) .getAssignable ( ) )
333338 )
@@ -569,9 +574,15 @@ private module Cached {
569574 Stages:: DataFlowStage:: forceCachingInSameStage ( ) and cfn .getElement ( ) instanceof Expr
570575 } or
571576 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
575586 TYieldReturnNode ( ControlFlow:: Nodes:: ElementNode cfn ) {
576587 any ( Callable c ) .canYieldReturn ( cfn .getElement ( ) )
577588 } or
@@ -605,18 +616,6 @@ private module Cached {
605616 cfn .getElement ( ) = fla .getQualifier ( )
606617 )
607618 } 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
620619 TSummaryInternalNode (
621620 SummarizedCallable c , FlowSummaryImpl:: Private:: SummaryInternalNodeState state
622621 ) {
@@ -801,12 +800,10 @@ private module Cached {
801800 cached
802801 predicate isUnreachableInCall ( Node n , DataFlowCall call ) {
803802 exists (
804- SsaDefinitionNode paramNode , Ssa:: ExplicitDefinition param , Guard guard ,
805- ControlFlow:: SuccessorTypes:: BooleanSuccessor bs
803+ ExplicitParameterNode paramNode , Guard guard , ControlFlow:: SuccessorTypes:: BooleanSuccessor bs
806804 |
807805 viableConstantBooleanParamArg ( paramNode , bs .getValue ( ) .booleanNot ( ) , call ) and
808- paramNode .getDefinition ( ) = param and
809- param .getARead ( ) = guard and
806+ paramNode .getSsaDefinition ( ) .getARead ( ) = guard and
810807 guard .controlsBlock ( n .getControlFlowNode ( ) .getBasicBlock ( ) , bs , _)
811808 )
812809 }
@@ -874,6 +871,11 @@ private module Cached {
874871 def instanceof Ssa:: ImplicitCallDefinition
875872 )
876873 or
874+ exists ( Parameter p |
875+ p = n .( ParameterNode ) .getParameter ( ) and
876+ not p .fromSource ( )
877+ )
878+ or
877879 n instanceof YieldReturnNode
878880 or
879881 n instanceof ImplicitCapturedArgumentNode
@@ -905,33 +907,25 @@ class SsaDefinitionNode extends NodeImpl, TSsaDefinitionNode {
905907
906908 override Location getLocationImpl ( ) { result = def .getLocation ( ) }
907909
908- override string toStringImpl ( ) {
909- not explicitParameterNode ( this , _) and
910- result = def .toString ( )
911- }
910+ override string toStringImpl ( ) { result = def .toString ( ) }
912911}
913912
914913private module ParameterNodes {
915914 abstract private class ParameterNodeImpl extends ParameterNode , NodeImpl { }
916915
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-
924916 /**
925917 * The value of an explicit parameter at function entry, viewed as a node in a data
926918 * flow graph.
927919 */
928- class ExplicitParameterNode extends ParameterNodeImpl {
920+ class ExplicitParameterNode extends ParameterNodeImpl , TExplicitParameterNode {
929921 private DotNet:: Parameter parameter ;
930922
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 ( )
935929 }
936930
937931 override DotNet:: Parameter getParameter ( ) { result = parameter }
@@ -1037,46 +1031,6 @@ private module ParameterNodes {
10371031 c = this .getEnclosingCallable ( )
10381032 }
10391033 }
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- }
10801034}
10811035
10821036import ParameterNodes
@@ -1934,7 +1888,7 @@ private class ConstantBooleanArgumentNode extends ExprNode {
19341888
19351889pragma [ noinline]
19361890private predicate viableConstantBooleanParamArg (
1937- SsaDefinitionNode paramNode , boolean b , DataFlowCall call
1891+ ParameterNode paramNode , boolean b , DataFlowCall call
19381892) {
19391893 exists ( ConstantBooleanArgumentNode arg |
19401894 viableParamArg ( call , paramNode , arg ) and
0 commit comments