C++: Add a new consistency check for branching on non-boolean values.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-11-18 15:21:28 +00:00
parent e081b9a420
commit 493ea6da31
12 changed files with 80 additions and 0 deletions

View File

@@ -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 '$@'."
)
}
}

View File

@@ -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 '$@'."
)
}
}

View File

@@ -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 '$@'."
)
}
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
fieldAddressOnNonPointer
thisArgumentIsNonPointer
nonUniqueIRVariable
nonBooleanOperand
missingCppType

View File

@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
fieldAddressOnNonPointer
thisArgumentIsNonPointer
nonUniqueIRVariable
nonBooleanOperand
missingCppType

View File

@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
fieldAddressOnNonPointer
thisArgumentIsNonPointer
nonUniqueIRVariable
nonBooleanOperand
missingCppType

View File

@@ -28,4 +28,5 @@ nonUniqueEnclosingIRFunction
fieldAddressOnNonPointer
thisArgumentIsNonPointer
nonUniqueIRVariable
nonBooleanOperand
missingCppType