Skip to content

Commit d182a41

Browse files
committed
C++: Improve IRGuads logic for 'unlikely' expressions.
1 parent ca19863 commit d182a41

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

+22
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,14 @@ private module Cached {
965965
compares_eq(test.(BuiltinExpectCallValueNumber).getCondition(), left, right, k, areEqual, value)
966966
}
967967

968+
private predicate isConvertedBool(Instruction instr) {
969+
instr.getResultIRType() instanceof IRBooleanType
970+
or
971+
isConvertedBool(instr.(ConvertInstruction).getUnary())
972+
or
973+
isConvertedBool(instr.(BuiltinExpectCallInstruction).getCondition())
974+
}
975+
968976
/**
969977
* Holds if `op == k` is `areEqual` given that `test` is equal to `value`.
970978
*/
@@ -995,6 +1003,20 @@ private module Cached {
9951003
k = k1 + k2
9961004
)
9971005
or
1006+
exists(CompareValueNumber cmp, Operand left, Operand right, AbstractValue v |
1007+
test = cmp and
1008+
cmp.hasOperands(left, right) and
1009+
isConvertedBool(left.getDef()) and
1010+
int_value(right.getDef()) = 0 and
1011+
unary_compares_eq(valueNumberOfOperand(left), op, k, areEqual, v)
1012+
|
1013+
cmp instanceof CompareNEValueNumber and
1014+
v = value
1015+
or
1016+
cmp instanceof CompareEQValueNumber and
1017+
v.getDualValue() = value
1018+
)
1019+
or
9981020
unary_compares_eq(test.(BuiltinExpectCallValueNumber).getCondition(), op, k, areEqual, value)
9991021
}
10001022

0 commit comments

Comments
 (0)