@@ -256,8 +256,9 @@ module VariableCapture {
256256 private predicate closureFlowStep ( ControlFlow:: Nodes:: ExprNode e1 , ControlFlow:: Nodes:: ExprNode e2 ) {
257257 e1 = LocalFlow:: getALastEvalNode ( e2 )
258258 or
259- exists ( Ssa:: Definition def |
260- SsaFlow:: Input:: ssaDefAssigns ( def .getAnUltimateDefinition ( ) , e1 ) and
259+ exists ( Ssa:: Definition def , AssignableDefinition adef |
260+ LocalFlow:: defAssigns ( adef , _, e1 ) and
261+ def .getAnUltimateDefinition ( ) .( Ssa:: ExplicitDefinition ) .getADefinition ( ) = adef and
261262 exists ( def .getAReadAtNode ( e2 ) )
262263 )
263264 }
@@ -483,42 +484,7 @@ module VariableCapture {
483484
484485/** Provides logic related to SSA. */
485486module SsaFlow {
486- module Input implements SsaImpl:: Impl:: DataFlowIntegrationInputSig {
487- private import csharp as Cs
488-
489- class Expr extends ControlFlow:: Node {
490- predicate hasCfgNode ( ControlFlow:: BasicBlock bb , int i ) { this = bb .getNode ( i ) }
491- }
492-
493- predicate ssaDefAssigns ( SsaImpl:: WriteDefinition def , Expr value ) {
494- exists ( AssignableDefinition adef , ControlFlow:: Node cfnDef |
495- any ( LocalFlow:: LocalExprStepConfiguration conf ) .hasDefPath ( _, value , adef , cfnDef ) and
496- def .( Ssa:: ExplicitDefinition ) .getADefinition ( ) = adef and
497- def .( Ssa:: ExplicitDefinition ) .getControlFlowNode ( ) = cfnDef
498- )
499- }
500-
501- class Parameter = Cs:: Parameter ;
502-
503- predicate ssaDefInitializesParam ( SsaImpl:: WriteDefinition def , Parameter p ) {
504- def .( Ssa:: ImplicitParameterDefinition ) .getParameter ( ) = p
505- }
506-
507- /**
508- * Allows for flow into uncertain defintions that are not call definitions,
509- * as we, conservatively, consider such definitions to be certain.
510- */
511- predicate allowFlowIntoUncertainDef ( SsaImpl:: UncertainWriteDefinition def ) {
512- def instanceof Ssa:: ExplicitDefinition
513- or
514- def =
515- any ( Ssa:: ImplicitQualifierDefinition qdef |
516- allowFlowIntoUncertainDef ( qdef .getQualifierDefinition ( ) )
517- )
518- }
519- }
520-
521- module Impl = SsaImpl:: Impl:: DataFlowIntegration< Input > ;
487+ module Impl = SsaImpl:: DataFlowIntegration;
522488
523489 Impl:: Node asNode ( Node n ) {
524490 n = TSsaNode ( result )
@@ -532,47 +498,12 @@ module SsaFlow {
532498 }
533499
534500 predicate localFlowStep ( SsaImpl:: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
535- Impl:: localFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) ) and
536- // exclude flow directly from RHS to SSA definition, as we instead want to
537- // go from RHS to matching assingnable definition, and from there to SSA definition
538- not Input:: ssaDefAssigns ( def , nodeFrom .( ExprNode ) .getControlFlowNode ( ) )
501+ Impl:: localFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
539502 }
540503
541504 predicate localMustFlowStep ( SsaImpl:: DefinitionExt def , Node nodeFrom , Node nodeTo ) {
542505 Impl:: localMustFlowStep ( def , asNode ( nodeFrom ) , asNode ( nodeTo ) )
543506 }
544-
545- module BarrierGuardsInput implements Impl:: BarrierGuardsInputSig {
546- private import semmle.code.csharp.controlflow.BasicBlocks
547- private import semmle.code.csharp.controlflow.Guards as Guards
548-
549- class Guard extends Guards:: Guard {
550- predicate hasCfgNode ( ControlFlow:: BasicBlock bb , int i ) {
551- this .getAControlFlowNode ( ) = bb .getNode ( i )
552- }
553- }
554-
555- /** Holds if the guard `guard` controls block `bb` upon evaluating to `branch`. */
556- predicate guardControlsBlock ( Guard guard , ControlFlow:: BasicBlock bb , boolean branch ) {
557- exists ( ConditionBlock conditionBlock , ControlFlow:: SuccessorTypes:: ConditionalSuccessor s |
558- guard .getAControlFlowNode ( ) = conditionBlock .getLastNode ( ) and
559- s .getValue ( ) = branch and
560- conditionBlock .controls ( bb , s )
561- )
562- }
563-
564- /** Gets an immediate conditional successor of basic block `bb`, if any. */
565- ControlFlow:: BasicBlock getAConditionalBasicBlockSuccessor (
566- ControlFlow:: BasicBlock bb , boolean branch
567- ) {
568- exists ( ControlFlow:: SuccessorTypes:: ConditionalSuccessor s |
569- result = bb .getASuccessorByType ( s ) and
570- s .getValue ( ) = branch
571- )
572- }
573- }
574-
575- module BarrierGuardsImpl = Impl:: BarrierGuards< BarrierGuardsInput > ;
576507}
577508
578509/** Provides predicates related to local data flow. */
@@ -1200,6 +1131,11 @@ private module Cached {
12001131 newtype TDataFlowType =
12011132 TGvnDataFlowType ( Gvn:: GvnType t ) or
12021133 TDelegateDataFlowType ( Callable lambda ) { lambdaCreationExpr ( _, lambda ) }
1134+
1135+ cached
1136+ Node getABarrierNode ( Guard guard , Ssa:: Definition def , boolean branch ) {
1137+ SsaFlow:: asNode ( result ) = SsaImpl:: DataFlowIntegration:: getABarrierNode ( guard , def , branch )
1138+ }
12031139}
12041140
12051141import Cached
0 commit comments