@@ -421,32 +421,6 @@ private predicate boundFlowStep(Expr e2, Expr e1, int delta, boolean upper) {
421
421
delta = 0 and
422
422
( upper = true or upper = false )
423
423
or
424
- exists ( Expr x |
425
- e2 .( AddExpr ) .hasOperands ( e1 , x )
426
- or
427
- exists ( AssignAddExpr add | add = e2 |
428
- add .getDest ( ) = e1 and add .getRhs ( ) = x
429
- or
430
- add .getDest ( ) = x and add .getRhs ( ) = e1
431
- )
432
- |
433
- // `x instanceof ConstantIntegerExpr` is covered by valueFlowStep
434
- not x instanceof ConstantIntegerExpr and
435
- not e1 instanceof ConstantIntegerExpr and
436
- if strictlyPositiveIntegralExpr ( x )
437
- then upper = false and delta = 1
438
- else
439
- if positive ( x )
440
- then upper = false and delta = 0
441
- else
442
- if strictlyNegativeIntegralExpr ( x )
443
- then upper = true and delta = - 1
444
- else
445
- if negative ( x )
446
- then upper = true and delta = 0
447
- else none ( )
448
- )
449
- or
450
424
exists ( Expr x |
451
425
exists ( SubExpr sub |
452
426
e2 = sub and
@@ -896,6 +870,20 @@ private predicate bounded(
896
870
or
897
871
upper = false and delta = d1 .minimum ( d2 )
898
872
)
873
+ or
874
+ exists (
875
+ Bound b1 , Bound b2 , int d1 , int d2 , boolean fbe1 , boolean fbe2 , int od1 , int od2 , Reason r1 ,
876
+ Reason r2
877
+ |
878
+ boundedAddition ( e , upper , b1 , true , d1 , fbe1 , od1 , r1 ) and
879
+ boundedAddition ( e , upper , b2 , false , d2 , fbe2 , od2 , r2 ) and
880
+ delta = d1 + d2 and
881
+ fromBackEdge = fbe1 .booleanOr ( fbe2 )
882
+ |
883
+ b = b1 and origdelta = od1 and reason = r1 and b2 instanceof ZeroBound
884
+ or
885
+ b = b2 and origdelta = od2 and reason = r2 and b1 instanceof ZeroBound
886
+ )
899
887
}
900
888
901
889
private predicate boundedConditionalExpr (
@@ -904,3 +892,37 @@ private predicate boundedConditionalExpr(
904
892
) {
905
893
bounded ( cond .getBranchExpr ( branch ) , b , delta , upper , fromBackEdge , origdelta , reason )
906
894
}
895
+
896
+ private predicate nonConstAdd ( Expr add , Expr operand , boolean isLeft ) {
897
+ exists ( Expr other |
898
+ add .( AddExpr ) .getLeftOperand ( ) = operand and
899
+ add .( AddExpr ) .getRightOperand ( ) = other and
900
+ isLeft = true
901
+ or
902
+ add .( AddExpr ) .getLeftOperand ( ) = other and
903
+ add .( AddExpr ) .getRightOperand ( ) = operand and
904
+ isLeft = false
905
+ or
906
+ add .( AssignAddExpr ) .getDest ( ) = operand and
907
+ add .( AssignAddExpr ) .getRhs ( ) = other and
908
+ isLeft = true
909
+ or
910
+ add .( AssignAddExpr ) .getDest ( ) = other and
911
+ add .( AssignAddExpr ) .getRhs ( ) = operand and
912
+ isLeft = false
913
+ |
914
+ // `ConstantIntegerExpr` is covered by valueFlowStep
915
+ not other instanceof ConstantIntegerExpr and
916
+ not operand instanceof ConstantIntegerExpr
917
+ )
918
+ }
919
+
920
+ private predicate boundedAddition (
921
+ Expr add , boolean upper , Bound b , boolean isLeft , int delta , boolean fromBackEdge , int origdelta ,
922
+ Reason reason
923
+ ) {
924
+ exists ( Expr op |
925
+ nonConstAdd ( add , op , isLeft ) and
926
+ bounded ( op , b , delta , upper , fromBackEdge , origdelta , reason )
927
+ )
928
+ }
0 commit comments