@@ -763,11 +763,7 @@ private predicate compares_eq(
763763 compares_eq ( test .( LogicalNotInstruction ) .getUnary ( ) , left , right , k , areEqual , dual )
764764 )
765765 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 )
771767}
772768
773769/**
@@ -838,12 +834,8 @@ private predicate unary_compares_eq(
838834 k = k1 + k2
839835 )
840836 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 )
847839}
848840
849841/** Rearrange various simple comparisons into `left == right + k` form. */
@@ -926,6 +918,13 @@ private predicate unary_simple_comparison_eq(
926918/** A call to the builtin operation `__builtin_expect`. */
927919private class BuiltinExpectCallInstruction extends CallInstruction {
928920 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+ }
929928}
930929
931930/**
@@ -935,14 +934,10 @@ private class BuiltinExpectCallInstruction extends CallInstruction {
935934private predicate builtin_expect_eq (
936935 CompareInstruction cmp , Operand left , Operand right , int k , boolean areEqual , AbstractValue value
937936) {
938- exists (
939- BuiltinExpectCallInstruction call , ConvertInstruction arg , Instruction const ,
940- AbstractValue innerValue
941- |
937+ exists ( BuiltinExpectCallInstruction call , Instruction const , AbstractValue innerValue |
942938 int_value ( const ) = 0 and
943939 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 )
946941 |
947942 cmp instanceof CompareNEInstruction and
948943 value = innerValue
@@ -970,14 +965,10 @@ private predicate unary_builtin_expect_eq(
970965 CompareInstruction cmp , Operand op , int k , boolean areEqual , boolean inNonZeroCase ,
971966 AbstractValue value
972967) {
973- exists (
974- BuiltinExpectCallInstruction call , ConvertInstruction arg , Instruction const ,
975- AbstractValue innerValue
976- |
968+ exists ( BuiltinExpectCallInstruction call , Instruction const , AbstractValue innerValue |
977969 int_value ( const ) = 0 and
978970 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 )
981972 |
982973 cmp instanceof CompareNEInstruction and
983974 value = innerValue
0 commit comments