@@ -763,11 +763,7 @@ private predicate compares_eq(
763
763
compares_eq ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , areEqual , dual )
764
764
)
765
765
or
766
- exists ( CallInstruction call |
767
- test = call and
768
- call .getStaticCallTarget ( ) .hasName ( "__builtin_expect" ) and
769
- compares_eq ( call .getArgument ( 0 ) .( ConvertInstruction ) .getUnary ( ) , left , right , k , areEqual , value )
770
- )
766
+ compares_eq ( test .( BuiltinExpectCallInstruction ) .getCondition ( ) , left , right , k , areEqual , value )
771
767
}
772
768
773
769
/**
@@ -838,12 +834,8 @@ private predicate unary_compares_eq(
838
834
k = k1 + k2
839
835
)
840
836
or
841
- exists ( CallInstruction call , Instruction arg |
842
- test = call and
843
- call .getStaticCallTarget ( ) .hasName ( "__builtin_expect" ) and
844
- arg = call .getArgument ( 0 ) and
845
- unary_compares_eq ( arg .( ConvertInstruction ) .getUnary ( ) , op , k , areEqual , inNonZeroCase , value )
846
- )
837
+ unary_compares_eq ( test .( BuiltinExpectCallInstruction ) .getCondition ( ) , op , k , areEqual ,
838
+ inNonZeroCase , value )
847
839
}
848
840
849
841
/** Rearrange various simple comparisons into `left == right + k` form. */
@@ -926,6 +918,13 @@ private predicate unary_simple_comparison_eq(
926
918
/** A call to the builtin operation `__builtin_expect`. */
927
919
private class BuiltinExpectCallInstruction extends CallInstruction {
928
920
BuiltinExpectCallInstruction ( ) { this .getStaticCallTarget ( ) .hasName ( "__builtin_expect" ) }
921
+
922
+ /** Gets the condition of this call. */
923
+ Instruction getCondition ( ) {
924
+ // The first parameter of `__builtin_expect` has type `long`. So we skip
925
+ // the conversion when inferring guards.
926
+ result = this .getArgument ( 0 ) .( ConvertInstruction ) .getUnary ( )
927
+ }
929
928
}
930
929
931
930
/**
@@ -935,14 +934,10 @@ private class BuiltinExpectCallInstruction extends CallInstruction {
935
934
private predicate builtin_expect_eq (
936
935
CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
937
936
) {
938
- exists (
939
- BuiltinExpectCallInstruction call , ConvertInstruction arg , Instruction const ,
940
- AbstractValue innerValue
941
- |
937
+ exists ( BuiltinExpectCallInstruction call , Instruction const , AbstractValue innerValue |
942
938
int_value ( const ) = 0 and
943
939
cmp .hasOperands ( call .getAUse ( ) , const .getAUse ( ) ) and
944
- arg = call .getArgument ( 0 ) and
945
- compares_eq ( arg .getUnary ( ) , left , right , k , areEqual , innerValue )
940
+ compares_eq ( call .getCondition ( ) , left , right , k , areEqual , innerValue )
946
941
|
947
942
cmp instanceof CompareNEInstruction and
948
943
value = innerValue
@@ -970,14 +965,10 @@ private predicate unary_builtin_expect_eq(
970
965
CompareInstruction cmp , Operand op , int k , boolean areEqual , boolean inNonZeroCase ,
971
966
AbstractValue value
972
967
) {
973
- exists (
974
- BuiltinExpectCallInstruction call , ConvertInstruction arg , Instruction const ,
975
- AbstractValue innerValue
976
- |
968
+ exists ( BuiltinExpectCallInstruction call , Instruction const , AbstractValue innerValue |
977
969
int_value ( const ) = 0 and
978
970
cmp .hasOperands ( call .getAUse ( ) , const .getAUse ( ) ) and
979
- arg = call .getArgument ( 0 ) and
980
- unary_compares_eq ( arg .getUnary ( ) , op , k , areEqual , inNonZeroCase , innerValue )
971
+ unary_compares_eq ( call .getCondition ( ) , op , k , areEqual , inNonZeroCase , innerValue )
981
972
|
982
973
cmp instanceof CompareNEInstruction and
983
974
value = innerValue
0 commit comments