@@ -446,7 +446,10 @@ class IRGuardCondition extends Instruction {
446
446
/** Holds if (determined by this guard) `left == right + k` evaluates to `areEqual` if this expression evaluates to `testIsTrue`. */
447
447
cached
448
448
predicate comparesEq ( Operand left , Operand right , int k , boolean areEqual , boolean testIsTrue ) {
449
- compares_eq ( this , left , right , k , areEqual , testIsTrue )
449
+ exists ( BooleanValue value |
450
+ compares_eq ( this , left , right , k , areEqual , value ) and
451
+ value .getValue ( ) = testIsTrue
452
+ )
450
453
}
451
454
452
455
/**
@@ -455,8 +458,8 @@ class IRGuardCondition extends Instruction {
455
458
*/
456
459
cached
457
460
predicate ensuresEq ( Operand left , Operand right , int k , IRBlock block , boolean areEqual ) {
458
- exists ( boolean testIsTrue |
459
- compares_eq ( this , left , right , k , areEqual , testIsTrue ) and this .controls ( block , testIsTrue )
461
+ exists ( AbstractValue value |
462
+ compares_eq ( this , left , right , k , areEqual , value ) and this .valueControls ( block , value )
460
463
)
461
464
}
462
465
@@ -468,9 +471,9 @@ class IRGuardCondition extends Instruction {
468
471
predicate ensuresEqEdge (
469
472
Operand left , Operand right , int k , IRBlock pred , IRBlock succ , boolean areEqual
470
473
) {
471
- exists ( boolean testIsTrue |
472
- compares_eq ( this , left , right , k , areEqual , testIsTrue ) and
473
- this .controlsEdge ( pred , succ , testIsTrue )
474
+ exists ( AbstractValue value |
475
+ compares_eq ( this , left , right , k , areEqual , value ) and
476
+ this .valueControlsEdge ( pred , succ , value )
474
477
)
475
478
}
476
479
@@ -572,52 +575,52 @@ private Instruction getBranchForCondition(Instruction guard) {
572
575
* Beware making mistaken logical implications here relating `areEqual` and `testIsTrue`.
573
576
*/
574
577
private predicate compares_eq (
575
- Instruction test , Operand left , Operand right , int k , boolean areEqual , boolean testIsTrue
578
+ Instruction test , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
576
579
) {
577
580
/* The simple case where the test *is* the comparison so areEqual = testIsTrue xor eq. */
578
- exists ( boolean eq | simple_comparison_eq ( test , left , right , k , eq ) |
579
- areEqual = true and testIsTrue = eq
581
+ exists ( AbstractValue v | simple_comparison_eq ( test , left , right , k , v ) |
582
+ areEqual = true and value = v
580
583
or
581
- areEqual = false and testIsTrue = eq . booleanNot ( )
584
+ areEqual = false and value = v . getDualValue ( )
582
585
)
583
586
or
584
587
// I think this is handled by forwarding in controlsBlock.
585
588
//or
586
589
//logical_comparison_eq(test, left, right, k, areEqual, testIsTrue)
587
590
/* a == b + k => b == a - k */
588
- exists ( int mk | k = - mk | compares_eq ( test , right , left , mk , areEqual , testIsTrue ) )
591
+ exists ( int mk | k = - mk | compares_eq ( test , right , left , mk , areEqual , value ) )
589
592
or
590
- complex_eq ( test , left , right , k , areEqual , testIsTrue )
593
+ complex_eq ( test , left , right , k , areEqual , value )
591
594
or
592
595
/* (x is true => (left == right + k)) => (!x is false => (left == right + k)) */
593
- exists ( boolean isFalse | testIsTrue = isFalse . booleanNot ( ) |
594
- compares_eq ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , areEqual , isFalse )
596
+ exists ( AbstractValue dual | value = dual . getDualValue ( ) |
597
+ compares_eq ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , areEqual , dual )
595
598
)
596
599
}
597
600
598
601
/** Rearrange various simple comparisons into `left == right + k` form. */
599
602
private predicate simple_comparison_eq (
600
- CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual
603
+ CompareInstruction cmp , Operand left , Operand right , int k , AbstractValue value
601
604
) {
602
605
left = cmp .getLeftOperand ( ) and
603
606
cmp instanceof CompareEQInstruction and
604
607
right = cmp .getRightOperand ( ) and
605
608
k = 0 and
606
- areEqual = true
609
+ value . ( BooleanValue ) . getValue ( ) = true
607
610
or
608
611
left = cmp .getLeftOperand ( ) and
609
612
cmp instanceof CompareNEInstruction and
610
613
right = cmp .getRightOperand ( ) and
611
614
k = 0 and
612
- areEqual = false
615
+ value . ( BooleanValue ) . getValue ( ) = false
613
616
}
614
617
615
618
private predicate complex_eq (
616
- CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , boolean testIsTrue
619
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
617
620
) {
618
- sub_eq ( cmp , left , right , k , areEqual , testIsTrue )
621
+ sub_eq ( cmp , left , right , k , areEqual , value )
619
622
or
620
- add_eq ( cmp , left , right , k , areEqual , testIsTrue )
623
+ add_eq ( cmp , left , right , k , areEqual , value )
621
624
}
622
625
623
626
/*
@@ -768,31 +771,31 @@ private predicate add_lt(
768
771
// left - x == right + c => left == right + (c+x)
769
772
// left == (right - x) + c => left == right + (c-x)
770
773
private predicate sub_eq (
771
- CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , boolean testIsTrue
774
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
772
775
) {
773
776
exists ( SubInstruction lhs , int c , int x |
774
- compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , testIsTrue ) and
777
+ compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
775
778
left = lhs .getLeftOperand ( ) and
776
779
x = int_value ( lhs .getRight ( ) ) and
777
780
k = c + x
778
781
)
779
782
or
780
783
exists ( SubInstruction rhs , int c , int x |
781
- compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , testIsTrue ) and
784
+ compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , value ) and
782
785
right = rhs .getLeftOperand ( ) and
783
786
x = int_value ( rhs .getRight ( ) ) and
784
787
k = c - x
785
788
)
786
789
or
787
790
exists ( PointerSubInstruction lhs , int c , int x |
788
- compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , testIsTrue ) and
791
+ compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
789
792
left = lhs .getLeftOperand ( ) and
790
793
x = int_value ( lhs .getRight ( ) ) and
791
794
k = c + x
792
795
)
793
796
or
794
797
exists ( PointerSubInstruction rhs , int c , int x |
795
- compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , testIsTrue ) and
798
+ compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , value ) and
796
799
right = rhs .getLeftOperand ( ) and
797
800
x = int_value ( rhs .getRight ( ) ) and
798
801
k = c - x
@@ -802,10 +805,10 @@ private predicate sub_eq(
802
805
// left + x == right + c => left == right + (c-x)
803
806
// left == (right + x) + c => left == right + (c+x)
804
807
private predicate add_eq (
805
- CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , boolean testIsTrue
808
+ CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
806
809
) {
807
810
exists ( AddInstruction lhs , int c , int x |
808
- compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , testIsTrue ) and
811
+ compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
809
812
(
810
813
left = lhs .getLeftOperand ( ) and x = int_value ( lhs .getRight ( ) )
811
814
or
@@ -815,7 +818,7 @@ private predicate add_eq(
815
818
)
816
819
or
817
820
exists ( AddInstruction rhs , int c , int x |
818
- compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , testIsTrue ) and
821
+ compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , value ) and
819
822
(
820
823
right = rhs .getLeftOperand ( ) and x = int_value ( rhs .getRight ( ) )
821
824
or
@@ -825,7 +828,7 @@ private predicate add_eq(
825
828
)
826
829
or
827
830
exists ( PointerAddInstruction lhs , int c , int x |
828
- compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , testIsTrue ) and
831
+ compares_eq ( cmp , lhs .getAUse ( ) , right , c , areEqual , value ) and
829
832
(
830
833
left = lhs .getLeftOperand ( ) and x = int_value ( lhs .getRight ( ) )
831
834
or
@@ -835,7 +838,7 @@ private predicate add_eq(
835
838
)
836
839
or
837
840
exists ( PointerAddInstruction rhs , int c , int x |
838
- compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , testIsTrue ) and
841
+ compares_eq ( cmp , left , rhs .getAUse ( ) , c , areEqual , value ) and
839
842
(
840
843
right = rhs .getLeftOperand ( ) and x = int_value ( rhs .getRight ( ) )
841
844
or
0 commit comments