@@ -296,11 +296,6 @@ abstract class UseImpl extends TUseImpl {
296
296
)
297
297
}
298
298
299
- final predicate hasNodeAndSourceVariable ( Node n , SourceVariable sv ) {
300
- sv = this .getSourceVariable ( ) and
301
- n = this .getNode ( )
302
- }
303
-
304
299
/**
305
300
* Holds if this use is guaranteed to read the
306
301
* associated variable.
@@ -966,17 +961,22 @@ private module SsaImpl = SsaImplCommon::Make<Location, SsaInput>;
966
961
private module DataFlowIntegrationInput implements SsaImpl:: DataFlowIntegrationInputSig {
967
962
private import codeql.util.Void
968
963
969
- final private class UseImplFinal = UseImpl ;
964
+ class Expr extends Instruction {
965
+ Expr ( ) {
966
+ exists ( IRBlock bb , int i |
967
+ variableRead ( bb , i , _, true ) and
968
+ this = bb .getInstruction ( i )
969
+ )
970
+ }
970
971
971
- class Expr extends UseImplFinal {
972
- predicate hasCfgNode ( SsaInput:: BasicBlock bb , int i ) { this .hasIndexInBlock ( bb , i ) }
972
+ predicate hasCfgNode ( SsaInput:: BasicBlock bb , int i ) { bb .getInstruction ( i ) = this }
973
973
}
974
974
975
975
Expr getARead ( SsaImpl:: Definition def ) {
976
976
exists ( SourceVariable v , IRBlock bb , int i |
977
977
ssaDefReachesRead ( v , def , bb , i ) and
978
978
variableRead ( bb , i , v , true ) and
979
- result .hasIndexInBlock ( bb , i , v )
979
+ result .hasCfgNode ( bb , i )
980
980
)
981
981
}
982
982
@@ -1028,21 +1028,38 @@ signature predicate guardChecksNodeSig(
1028
1028
) ;
1029
1029
1030
1030
module BarrierGuardWithIntParam< guardChecksNodeSig / 4 guardChecksNode> {
1031
+ private predicate ssaDefReachesCertainUse ( Definition def , UseImpl use ) {
1032
+ exists ( SourceVariable v , IRBlock bb , int i |
1033
+ use .hasIndexInBlock ( bb , i , v ) and
1034
+ variableRead ( bb , i , v , true ) and
1035
+ ssaDefReachesRead ( v , def , bb , i )
1036
+ )
1037
+ }
1038
+
1031
1039
private predicate guardChecks (
1032
- DataFlowIntegrationInput:: Guard g , DataFlowIntegrationInput:: Expr e , boolean branch ,
1033
- int indirectionIndex
1040
+ DataFlowIntegrationInput:: Guard g , SsaImpl:: Definition def , boolean branch , int indirectionIndex
1034
1041
) {
1035
- guardChecksNode ( g , e .getNode ( ) , branch , indirectionIndex )
1042
+ exists ( UseImpl use |
1043
+ guardChecksNode ( g , use .getNode ( ) , branch , indirectionIndex ) and
1044
+ ssaDefReachesCertainUse ( def , use )
1045
+ )
1036
1046
}
1037
1047
1038
1048
Node getABarrierNode ( int indirectionIndex ) {
1039
- exists ( DataFlowIntegrationImpl:: Node n |
1040
- n =
1041
- DataFlowIntegrationImpl:: BarrierGuardWithState< int , guardChecks / 4 > :: getABarrierNode ( indirectionIndex )
1042
- |
1043
- n = result .( SsaSynthNode ) .getSynthNode ( )
1044
- or
1045
- n .( DataFlowIntegrationImpl:: ExprNode ) .getExpr ( ) .getNode ( ) = result
1049
+ // Only get the SynthNodes from the shared implementation, as the ExprNodes cannot
1050
+ // be matched on SourceVariable.
1051
+ result .( SsaSynthNode ) .getSynthNode ( ) =
1052
+ DataFlowIntegrationImpl:: BarrierGuardDefWithState< int , guardChecks / 4 > :: getABarrierNode ( indirectionIndex )
1053
+ or
1054
+ // Calculate the guarded UseImpls corresponding to ExprNodes directly.
1055
+ exists ( DataFlowIntegrationInput:: Guard g , boolean branch , Definition def , IRBlock bb |
1056
+ guardChecks ( g , def , branch , indirectionIndex ) and
1057
+ exists ( UseImpl use |
1058
+ ssaDefReachesCertainUse ( def , use ) and
1059
+ use .getBlock ( ) = bb and
1060
+ DataFlowIntegrationInput:: guardControlsBlock ( g , bb , branch ) and
1061
+ result = use .getNode ( )
1062
+ )
1046
1063
)
1047
1064
}
1048
1065
}
@@ -1064,7 +1081,12 @@ pragma[inline_late]
1064
1081
DataFlowIntegrationImpl:: Node fromDfNode ( Node n , SourceVariable v ) {
1065
1082
result = n .( SsaSynthNode ) .getSynthNode ( )
1066
1083
or
1067
- result .( DataFlowIntegrationImpl:: ExprNode ) .getExpr ( ) .hasNodeAndSourceVariable ( n , v )
1084
+ exists ( UseImpl use , IRBlock bb , int i |
1085
+ result .( DataFlowIntegrationImpl:: ExprNode ) .getExpr ( ) .hasCfgNode ( bb , i ) and
1086
+ use .hasIndexInBlock ( bb , i , v ) and
1087
+ use .isCertain ( ) and
1088
+ use .getNode ( ) = n
1089
+ )
1068
1090
or
1069
1091
defToNode ( n , result .( DataFlowIntegrationImpl:: SsaDefinitionNode ) .getDefinition ( ) )
1070
1092
}
0 commit comments