@@ -456,7 +456,10 @@ class IRGuardCondition extends Instruction {
456
456
/** Holds if (determined by this guard) `left < right + k` evaluates to `isLessThan` if this expression evaluates to `testIsTrue`. */
457
457
cached
458
458
predicate comparesLt ( Operand left , Operand right , int k , boolean isLessThan , boolean testIsTrue ) {
459
- compares_lt ( this , left , right , k , isLessThan , testIsTrue )
459
+ exists ( BooleanValue value |
460
+ compares_lt ( this , left , right , k , isLessThan , value ) and
461
+ value .getValue ( ) = testIsTrue
462
+ )
460
463
}
461
464
462
465
/**
@@ -465,8 +468,8 @@ class IRGuardCondition extends Instruction {
465
468
*/
466
469
cached
467
470
predicate ensuresLt ( Operand left , Operand right , int k , IRBlock block , boolean isLessThan ) {
468
- exists ( boolean testIsTrue |
469
- compares_lt ( this , left , right , k , isLessThan , testIsTrue ) and this .controls ( block , testIsTrue )
471
+ exists ( AbstractValue value |
472
+ compares_lt ( this , left , right , k , isLessThan , value ) and this .valueControls ( block , value )
470
473
)
471
474
}
472
475
@@ -478,9 +481,9 @@ class IRGuardCondition extends Instruction {
478
481
predicate ensuresLtEdge (
479
482
Operand left , Operand right , int k , IRBlock pred , IRBlock succ , boolean isLessThan
480
483
) {
481
- exists ( boolean testIsTrue |
482
- compares_lt ( this , left , right , k , isLessThan , testIsTrue ) and
483
- this .controlsEdge ( pred , succ , testIsTrue )
484
+ exists ( AbstractValue value |
485
+ compares_lt ( this , left , right , k , isLessThan , value ) and
486
+ this .valueControlsEdge ( pred , succ , value )
484
487
)
485
488
}
486
489
@@ -746,31 +749,28 @@ private predicate complex_eq(
746
749
747
750
/** Holds if `left < right + k` evaluates to `isLt` given that test is `testIsTrue`. */
748
751
private predicate compares_lt (
749
- Instruction test , Operand left , Operand right , int k , boolean isLt , boolean testIsTrue
752
+ Instruction test , Operand left , Operand right , int k , boolean isLt , AbstractValue value
750
753
) {
751
754
/* In the simple case, the test is the comparison, so isLt = testIsTrue */
752
- simple_comparison_lt ( test , left , right , k ) and isLt = true and testIsTrue = true
753
- or
754
- simple_comparison_lt ( test , left , right , k ) and isLt = false and testIsTrue = false
755
+ simple_comparison_lt ( test , left , right , k ) and
756
+ value .( BooleanValue ) .getValue ( ) = isLt
755
757
or
756
- complex_lt ( test , left , right , k , isLt , testIsTrue )
758
+ complex_lt ( test , left , right , k , isLt , value )
757
759
or
758
760
/* (not (left < right + k)) => (left >= right + k) */
759
- exists ( boolean isGe | isLt = isGe .booleanNot ( ) |
760
- compares_ge ( test , left , right , k , isGe , testIsTrue )
761
- )
761
+ exists ( boolean isGe | isLt = isGe .booleanNot ( ) | compares_ge ( test , left , right , k , isGe , value ) )
762
762
or
763
763
/* (x is true => (left < right + k)) => (!x is false => (left < right + k)) */
764
- exists ( boolean isFalse | testIsTrue = isFalse . booleanNot ( ) |
765
- compares_lt ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , isLt , isFalse )
764
+ exists ( AbstractValue dual | value = dual . getDualValue ( ) |
765
+ compares_lt ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , isLt , dual )
766
766
)
767
767
}
768
768
769
769
/** `(a < b + k) => (b > a - k) => (b >= a + (1-k))` */
770
770
private predicate compares_ge (
771
- Instruction test , Operand left , Operand right , int k , boolean isGe , boolean testIsTrue
771
+ Instruction test , Operand left , Operand right , int k , boolean isGe , AbstractValue value
772
772
) {
773
- exists ( int onemk | k = 1 - onemk | compares_lt ( test , right , left , onemk , isGe , testIsTrue ) )
773
+ exists ( int onemk | k = 1 - onemk | compares_lt ( test , right , left , onemk , isGe , value ) )
774
774
}
775
775
776
776
/** Rearrange various simple comparisons into `left < right + k` form. */
@@ -797,41 +797,41 @@ private predicate simple_comparison_lt(CompareInstruction cmp, Operand left, Ope
797
797
}
798
798
799
799
private predicate complex_lt (
800
- CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , boolean testIsTrue
800
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
801
801
) {
802
- sub_lt ( cmp , left , right , k , isLt , testIsTrue )
802
+ sub_lt ( cmp , left , right , k , isLt , value )
803
803
or
804
- add_lt ( cmp , left , right , k , isLt , testIsTrue )
804
+ add_lt ( cmp , left , right , k , isLt , value )
805
805
}
806
806
807
807
// left - x < right + c => left < right + (c+x)
808
808
// left < (right - x) + c => left < right + (c-x)
809
809
private predicate sub_lt (
810
- CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , boolean testIsTrue
810
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
811
811
) {
812
812
exists ( SubInstruction lhs , int c , int x |
813
- compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , testIsTrue ) and
813
+ compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
814
814
left = lhs .getLeftOperand ( ) and
815
815
x = int_value ( lhs .getRight ( ) ) and
816
816
k = c + x
817
817
)
818
818
or
819
819
exists ( SubInstruction rhs , int c , int x |
820
- compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , testIsTrue ) and
820
+ compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , value ) and
821
821
right = rhs .getLeftOperand ( ) and
822
822
x = int_value ( rhs .getRight ( ) ) and
823
823
k = c - x
824
824
)
825
825
or
826
826
exists ( PointerSubInstruction lhs , int c , int x |
827
- compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , testIsTrue ) and
827
+ compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
828
828
left = lhs .getLeftOperand ( ) and
829
829
x = int_value ( lhs .getRight ( ) ) and
830
830
k = c + x
831
831
)
832
832
or
833
833
exists ( PointerSubInstruction rhs , int c , int x |
834
- compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , testIsTrue ) and
834
+ compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , value ) and
835
835
right = rhs .getLeftOperand ( ) and
836
836
x = int_value ( rhs .getRight ( ) ) and
837
837
k = c - x
@@ -841,10 +841,10 @@ private predicate sub_lt(
841
841
// left + x < right + c => left < right + (c-x)
842
842
// left < (right + x) + c => left < right + (c+x)
843
843
private predicate add_lt (
844
- CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , boolean testIsTrue
844
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean isLt , AbstractValue value
845
845
) {
846
846
exists ( AddInstruction lhs , int c , int x |
847
- compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , testIsTrue ) and
847
+ compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
848
848
(
849
849
left = lhs .getLeftOperand ( ) and x = int_value ( lhs .getRight ( ) )
850
850
or
@@ -854,7 +854,7 @@ private predicate add_lt(
854
854
)
855
855
or
856
856
exists ( AddInstruction rhs , int c , int x |
857
- compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , testIsTrue ) and
857
+ compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , value ) and
858
858
(
859
859
right = rhs .getLeftOperand ( ) and x = int_value ( rhs .getRight ( ) )
860
860
or
@@ -864,7 +864,7 @@ private predicate add_lt(
864
864
)
865
865
or
866
866
exists ( PointerAddInstruction lhs , int c , int x |
867
- compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , testIsTrue ) and
867
+ compares_lt ( cmp , lhs .getAUse ( ) , right , c , isLt , value ) and
868
868
(
869
869
left = lhs .getLeftOperand ( ) and x = int_value ( lhs .getRight ( ) )
870
870
or
@@ -874,7 +874,7 @@ private predicate add_lt(
874
874
)
875
875
or
876
876
exists ( PointerAddInstruction rhs , int c , int x |
877
- compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , testIsTrue ) and
877
+ compares_lt ( cmp , left , rhs .getAUse ( ) , c , isLt , value ) and
878
878
(
879
879
right = rhs .getLeftOperand ( ) and x = int_value ( rhs .getRight ( ) )
880
880
or
0 commit comments