Skip to content

Commit d736426

Browse files
committed
C++: Support guards without implicit boolean conversions.
1 parent 806d428 commit d736426

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,22 @@ private predicate simple_comparison_eq(Instruction test, Operand op, int k, Abst
790790
exists(switch.getSuccessor(case)) and
791791
case.getValue().toInt() = k
792792
)
793+
or
794+
// There's no implicit CompareInstruction in files compiled as C since C
795+
// doesn't have implicit boolean conversions. So instead we check whether
796+
// there's a branch on a value ofpointer or integer type.
797+
exists(ConditionalBranchInstruction branch, IRType type |
798+
not test instanceof CompareInstruction and
799+
(type instanceof IRAddressType or type instanceof IRIntegerType) and
800+
test = branch.getCondition() and
801+
op.getDef() = test
802+
|
803+
k = 1 and
804+
value.(BooleanValue).getValue() = true
805+
or
806+
k = 0 and
807+
value.(BooleanValue).getValue() = false
808+
)
793809
}
794810

795811
private predicate complex_eq(

0 commit comments

Comments
 (0)