Skip to content

Commit d204810

Browse files
committed
C++: Improve IRGuads logic for 'unlikely' expressions.
1 parent 540f4e9 commit d204810

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
@@ -952,6 +952,14 @@ private module Cached {
952952
compares_eq(test.(BuiltinExpectCallValueNumber).getCondition(), left, right, k, areEqual, value)
953953
}
954954

955+
private predicate isConvertedBool(Instruction instr) {
956+
instr.getResultIRType() instanceof IRBooleanType
957+
or
958+
isConvertedBool(instr.(ConvertInstruction).getUnary())
959+
or
960+
isConvertedBool(instr.(BuiltinExpectCallInstruction).getCondition())
961+
}
962+
955963
/**
956964
* Holds if `op == k` is `areEqual` given that `test` is equal to `value`.
957965
*/
@@ -982,6 +990,20 @@ private module Cached {
982990
k = k1 + k2
983991
)
984992
or
993+
exists(CompareValueNumber cmp, Operand left, Operand right, AbstractValue v |
994+
test = cmp and
995+
cmp.hasOperands(left, right) and
996+
isConvertedBool(left.getDef()) and
997+
int_value(right.getDef()) = 0 and
998+
unary_compares_eq(valueNumberOfOperand(left), op, k, areEqual, v)
999+
|
1000+
cmp instanceof CompareNEValueNumber and
1001+
v = value
1002+
or
1003+
cmp instanceof CompareEQValueNumber and
1004+
v.getDualValue() = value
1005+
)
1006+
or
9851007
unary_compares_eq(test.(BuiltinExpectCallValueNumber).getCondition(), op, k, areEqual, value)
9861008
}
9871009

0 commit comments

Comments
 (0)