Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd46c43

Browse files
C++: Add sanity test for missing operand type
1 parent a54d864 commit bd46c43

8 files changed

Lines changed: 32 additions & 0 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cpp
77
import semmle.code.cpp.ir.implementation.EdgeKind
88
import semmle.code.cpp.ir.implementation.MemoryAccessKind
99
import semmle.code.cpp.ir.implementation.Opcode
10+
private import semmle.code.cpp.Print
1011
private import semmle.code.cpp.ir.implementation.Opcode
1112
private import semmle.code.cpp.ir.internal.OperandTag
1213

@@ -92,6 +93,14 @@ module InstructionSanity {
9293
)
9394
}
9495

96+
query predicate missingOperandType(Operand operand, string message) {
97+
exists(Function func |
98+
not exists(operand.getType()) and
99+
func = operand.getUseInstruction().getEnclosingFunction() and
100+
message = "Operand missing type in function '" + getIdentityString(func) + "'."
101+
)
102+
}
103+
95104
/**
96105
* Holds if an instruction, other than `ExitFunction`, has no successors.
97106
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cpp
77
import semmle.code.cpp.ir.implementation.EdgeKind
88
import semmle.code.cpp.ir.implementation.MemoryAccessKind
99
import semmle.code.cpp.ir.implementation.Opcode
10+
private import semmle.code.cpp.Print
1011
private import semmle.code.cpp.ir.implementation.Opcode
1112
private import semmle.code.cpp.ir.internal.OperandTag
1213

@@ -92,6 +93,14 @@ module InstructionSanity {
9293
)
9394
}
9495

96+
query predicate missingOperandType(Operand operand, string message) {
97+
exists(Function func |
98+
not exists(operand.getType()) and
99+
func = operand.getUseInstruction().getEnclosingFunction() and
100+
message = "Operand missing type in function '" + getIdentityString(func) + "'."
101+
)
102+
}
103+
95104
/**
96105
* Holds if an instruction, other than `ExitFunction`, has no successors.
97106
*/

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cpp
77
import semmle.code.cpp.ir.implementation.EdgeKind
88
import semmle.code.cpp.ir.implementation.MemoryAccessKind
99
import semmle.code.cpp.ir.implementation.Opcode
10+
private import semmle.code.cpp.Print
1011
private import semmle.code.cpp.ir.implementation.Opcode
1112
private import semmle.code.cpp.ir.internal.OperandTag
1213

@@ -92,6 +93,14 @@ module InstructionSanity {
9293
)
9394
}
9495

96+
query predicate missingOperandType(Operand operand, string message) {
97+
exists(Function func |
98+
not exists(operand.getType()) and
99+
func = operand.getUseInstruction().getEnclosingFunction() and
100+
message = "Operand missing type in function '" + getIdentityString(func) + "'."
101+
)
102+
}
103+
95104
/**
96105
* Holds if an instruction, other than `ExitFunction`, has no successors.
97106
*/

cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
missingOperandType
56
instructionWithoutSuccessor
67
ambiguousSuccessors
78
unexplainedLoop

cpp/ql/test/library-tests/ir/ir/raw_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
missingOperandType
56
instructionWithoutSuccessor
67
ambiguousSuccessors
78
unexplainedLoop

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
missingOperandType
56
instructionWithoutSuccessor
67
ambiguousSuccessors
78
unexplainedLoop

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
missingOperandType
56
instructionWithoutSuccessor
67
ambiguousSuccessors
78
unexplainedLoop

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_sanity.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ missingOperand
22
unexpectedOperand
33
duplicateOperand
44
missingPhiOperand
5+
missingOperandType
56
instructionWithoutSuccessor
67
ambiguousSuccessors
78
unexplainedLoop

0 commit comments

Comments
 (0)