mirror of
https://github.com/github/codeql.git
synced 2026-04-26 17:25:19 +02: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 '$@'."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user