Skip to content

Commit bb6cc92

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

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,18 @@ private predicate simple_comparison_eq(Instruction test, Operand op, int k, Abst
796796
// there's a branch on a value ofpointer or integer type.
797797
exists(ConditionalBranchInstruction branch, IRType type |
798798
not test instanceof CompareInstruction and
799+
type = test.getResultIRType() and
799800
(type instanceof IRAddressType or type instanceof IRIntegerType) and
800801
test = branch.getCondition() and
801802
op.getDef() = test
802803
|
803-
k = 1 and
804-
value.(BooleanValue).getValue() = true
805-
or
804+
// We'd like to also include a case such as:
805+
// ```
806+
// k = 1 and
807+
// value.(BooleanValue).getValue() = true
808+
// ```
809+
// but all we know is that the value is non-zero in the true branch.
810+
// So we can only conclude something in the false branch.
806811
k = 0 and
807812
value.(BooleanValue).getValue() = false
808813
)

0 commit comments

Comments
 (0)