mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
C++: Add a new consistency check for branching on non-boolean values.
This commit is contained in:
@@ -546,4 +546,26 @@ module InstructionConsistency {
|
||||
"' has no associated variable, in function '$@'." and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText)
|
||||
}
|
||||
|
||||
query predicate nonBooleanOperand(
|
||||
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
|
||||
) {
|
||||
exists(Instruction unary |
|
||||
unary = instr.(LogicalNotInstruction).getUnary() and
|
||||
not unary.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Logical Not instruction " + instr.toString() +
|
||||
" with non-Boolean operand, in function '$@'."
|
||||
)
|
||||
or
|
||||
exists(Instruction cond |
|
||||
cond = instr.(ConditionalBranchInstruction).getCondition() and
|
||||
not cond.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Conditional branch instruction " + instr.toString() +
|
||||
" with non-Boolean condition, in function '$@'."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,4 +546,26 @@ module InstructionConsistency {
|
||||
"' has no associated variable, in function '$@'." and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText)
|
||||
}
|
||||
|
||||
query predicate nonBooleanOperand(
|
||||
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
|
||||
) {
|
||||
exists(Instruction unary |
|
||||
unary = instr.(LogicalNotInstruction).getUnary() and
|
||||
not unary.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Logical Not instruction " + instr.toString() +
|
||||
" with non-Boolean operand, in function '$@'."
|
||||
)
|
||||
or
|
||||
exists(Instruction cond |
|
||||
cond = instr.(ConditionalBranchInstruction).getCondition() and
|
||||
not cond.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Conditional branch instruction " + instr.toString() +
|
||||
" with non-Boolean condition, in function '$@'."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -546,4 +546,26 @@ module InstructionConsistency {
|
||||
"' has no associated variable, in function '$@'." and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText)
|
||||
}
|
||||
|
||||
query predicate nonBooleanOperand(
|
||||
Instruction instr, string message, OptionalIRFunction irFunc, string irFuncText
|
||||
) {
|
||||
exists(Instruction unary |
|
||||
unary = instr.(LogicalNotInstruction).getUnary() and
|
||||
not unary.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Logical Not instruction " + instr.toString() +
|
||||
" with non-Boolean operand, in function '$@'."
|
||||
)
|
||||
or
|
||||
exists(Instruction cond |
|
||||
cond = instr.(ConditionalBranchInstruction).getCondition() and
|
||||
not cond.getResultIRType() instanceof IRBooleanType and
|
||||
irFunc = getInstructionIRFunction(instr, irFuncText) and
|
||||
message =
|
||||
"Conditional branch instruction " + instr.toString() +
|
||||
" with non-Boolean condition, in function '$@'."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,6 @@ fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
|
||||
missingCppType
|
||||
|
||||
@@ -29,4 +29,6 @@ fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
|
||||
missingCppType
|
||||
|
||||
@@ -38,4 +38,6 @@ fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
|
||||
missingCppType
|
||||
|
||||
@@ -29,4 +29,6 @@ fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
|
||||
missingCppType
|
||||
|
||||
@@ -29,4 +29,6 @@ fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
| ir.cpp:2546:34:2546:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2545:6:2545:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
| try_except.c:35:13:35:13 | ConditionalBranch: b | Conditional branch instruction ConditionalBranch: b with non-Boolean condition, in function '$@'. | try_except.c:32:6:32:6 | void h(int) | void h(int) |
|
||||
missingCppType
|
||||
|
||||
@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
|
||||
fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
missingCppType
|
||||
|
||||
@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
|
||||
fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
missingCppType
|
||||
|
||||
@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
|
||||
fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
missingCppType
|
||||
|
||||
@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
|
||||
fieldAddressOnNonPointer
|
||||
thisArgumentIsNonPointer
|
||||
nonUniqueIRVariable
|
||||
nonBooleanOperand
|
||||
missingCppType
|
||||
|
||||
Reference in New Issue
Block a user