@@ -79,11 +79,30 @@ import javascript
7979 * Contains predicates for reasoning about the relative numeric value of expressions.
8080 */
8181module RangeAnalysis {
82+ /**
83+ * Holds if the given node is relevant for range analysis.
84+ */
85+ private predicate isRelevant ( DataFlow:: Node node ) {
86+ node = any ( Comparison cmp ) .getAnOperand ( ) .flow ( )
87+ or
88+ node = any ( ConditionGuardNode guard ) .getTest ( ) .flow ( )
89+ or
90+ exists ( DataFlow:: Node succ | isRelevant ( succ ) |
91+ succ = node .getASuccessor ( )
92+ or
93+ linearDefinitionStep ( succ , node , _, _)
94+ or
95+ exists ( BinaryExpr bin | bin instanceof AddExpr or bin instanceof SubExpr |
96+ succ .asExpr ( ) = bin and
97+ bin .getAnOperand ( ) .flow ( ) = node ) )
98+ }
99+
82100 /**
83101 * Holds if the given node has a unique data flow predecessor.
84102 */
85103 pragma [ noinline]
86104 private predicate hasUniquePredecessor ( DataFlow:: Node node ) {
105+ isRelevant ( node ) and
87106 strictcount ( node .getAPredecessor ( ) ) = 1
88107 }
89108
@@ -206,6 +225,7 @@ module RangeAnalysis {
206225 sign = sign1 * sign2 and
207226 bias = bias1 + sign1 * bias2 )
208227 else (
228+ isRelevant ( r ) and
209229 root = r and
210230 sign = 1 and
211231 bias = 0
@@ -344,6 +364,7 @@ module RangeAnalysis {
344364 */
345365 predicate binaryPhiNode ( DataFlow:: Node node , DataFlow:: Node left , DataFlow:: Node right ) {
346366 exists ( SsaPhiNode phi | node = DataFlow:: ssaDefinitionNode ( phi ) |
367+ isRelevant ( node ) and
347368 strictcount ( phi .getAnInput ( ) ) = 2 and
348369 left = DataFlow:: ssaDefinitionNode ( phi .getAnInput ( ) ) and
349370 right = DataFlow:: ssaDefinitionNode ( phi .getAnInput ( ) ) and
@@ -412,6 +433,7 @@ module RangeAnalysis {
412433 */
413434 predicate constantEdge ( ControlFlowNode cfg , DataFlow:: Node a , int asign , DataFlow:: Node b , int bsign , Bias c ) {
414435 exists ( NumberLiteral literal | cfg = literal |
436+ isRelevant ( literal .flow ( ) ) and
415437 literal .getIntValue ( ) instanceof Bias and // avoid overflow
416438 a = literal .flow ( ) and
417439 b = a and
0 commit comments