Skip to content

Commit 9c98652

Browse files
committed
C++: Handle 'unlikely' in IRGuards.
1 parent 000a81f commit 9c98652

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,12 @@ private predicate compares_eq(
762762
exists(AbstractValue dual | value = dual.getDualValue() |
763763
compares_eq(test.(LogicalNotInstruction).getUnary(), left, right, k, areEqual, dual)
764764
)
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+
)
765771
}
766772

767773
/**
@@ -831,6 +837,13 @@ private predicate unary_compares_eq(
831837
int_value(const) = k1 and
832838
k = k1 + k2
833839
)
840+
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+
)
834847
}
835848

836849
/** Rearrange various simple comparisons into `left == right + k` form. */

0 commit comments

Comments
 (0)