Skip to content

Commit 12daa76

Browse files
dave-bartolomeoDave Bartolomeo
authored andcommitted
C++: Make duplicateOperand query report function name
1 parent 53576a4 commit 12daa76

File tree

5 files changed

+70
-30
lines changed

5 files changed

+70
-30
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ module InstructionSanity {
9494
/**
9595
* Holds if instruction `instr` has multiple operands with tag `tag`.
9696
*/
97-
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
98-
strictcount(NonPhiOperand operand |
99-
operand = instr.getAnOperand() and
100-
operand.getOperandTag() = tag
101-
) > 1 and
102-
not tag instanceof UnmodeledUseOperandTag
97+
query predicate duplicateOperand(Instruction instr, string message, IRFunction func,
98+
string funcText) {
99+
exists(OperandTag tag, int operandCount |
100+
operandCount = strictcount(NonPhiOperand operand |
101+
operand = instr.getAnOperand() and
102+
operand.getOperandTag() = tag
103+
) and
104+
operandCount > 1 and
105+
not tag instanceof UnmodeledUseOperandTag and
106+
message = "Instruction has " + operandCount + " operands with tag '" + tag.toString() + "'" +
107+
" in function '$@'." and
108+
func = instr.getEnclosingIRFunction() and
109+
funcText = Language::getIdentityString(func.getFunction())
110+
)
103111
}
104112

105113
/**

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ module InstructionSanity {
9494
/**
9595
* Holds if instruction `instr` has multiple operands with tag `tag`.
9696
*/
97-
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
98-
strictcount(NonPhiOperand operand |
99-
operand = instr.getAnOperand() and
100-
operand.getOperandTag() = tag
101-
) > 1 and
102-
not tag instanceof UnmodeledUseOperandTag
97+
query predicate duplicateOperand(Instruction instr, string message, IRFunction func,
98+
string funcText) {
99+
exists(OperandTag tag, int operandCount |
100+
operandCount = strictcount(NonPhiOperand operand |
101+
operand = instr.getAnOperand() and
102+
operand.getOperandTag() = tag
103+
) and
104+
operandCount > 1 and
105+
not tag instanceof UnmodeledUseOperandTag and
106+
message = "Instruction has " + operandCount + " operands with tag '" + tag.toString() + "'" +
107+
" in function '$@'." and
108+
func = instr.getEnclosingIRFunction() and
109+
funcText = Language::getIdentityString(func.getFunction())
110+
)
103111
}
104112

105113
/**

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ module InstructionSanity {
9494
/**
9595
* Holds if instruction `instr` has multiple operands with tag `tag`.
9696
*/
97-
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
98-
strictcount(NonPhiOperand operand |
99-
operand = instr.getAnOperand() and
100-
operand.getOperandTag() = tag
101-
) > 1 and
102-
not tag instanceof UnmodeledUseOperandTag
97+
query predicate duplicateOperand(Instruction instr, string message, IRFunction func,
98+
string funcText) {
99+
exists(OperandTag tag, int operandCount |
100+
operandCount = strictcount(NonPhiOperand operand |
101+
operand = instr.getAnOperand() and
102+
operand.getOperandTag() = tag
103+
) and
104+
operandCount > 1 and
105+
not tag instanceof UnmodeledUseOperandTag and
106+
message = "Instruction has " + operandCount + " operands with tag '" + tag.toString() + "'" +
107+
" in function '$@'." and
108+
func = instr.getEnclosingIRFunction() and
109+
funcText = Language::getIdentityString(func.getFunction())
110+
)
103111
}
104112

105113
/**

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ module InstructionSanity {
9494
/**
9595
* Holds if instruction `instr` has multiple operands with tag `tag`.
9696
*/
97-
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
98-
strictcount(NonPhiOperand operand |
99-
operand = instr.getAnOperand() and
100-
operand.getOperandTag() = tag
101-
) > 1 and
102-
not tag instanceof UnmodeledUseOperandTag
97+
query predicate duplicateOperand(Instruction instr, string message, IRFunction func,
98+
string funcText) {
99+
exists(OperandTag tag, int operandCount |
100+
operandCount = strictcount(NonPhiOperand operand |
101+
operand = instr.getAnOperand() and
102+
operand.getOperandTag() = tag
103+
) and
104+
operandCount > 1 and
105+
not tag instanceof UnmodeledUseOperandTag and
106+
message = "Instruction has " + operandCount + " operands with tag '" + tag.toString() + "'" +
107+
" in function '$@'." and
108+
func = instr.getEnclosingIRFunction() and
109+
funcText = Language::getIdentityString(func.getFunction())
110+
)
103111
}
104112

105113
/**

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ module InstructionSanity {
9494
/**
9595
* Holds if instruction `instr` has multiple operands with tag `tag`.
9696
*/
97-
query predicate duplicateOperand(Instruction instr, OperandTag tag) {
98-
strictcount(NonPhiOperand operand |
99-
operand = instr.getAnOperand() and
100-
operand.getOperandTag() = tag
101-
) > 1 and
102-
not tag instanceof UnmodeledUseOperandTag
97+
query predicate duplicateOperand(Instruction instr, string message, IRFunction func,
98+
string funcText) {
99+
exists(OperandTag tag, int operandCount |
100+
operandCount = strictcount(NonPhiOperand operand |
101+
operand = instr.getAnOperand() and
102+
operand.getOperandTag() = tag
103+
) and
104+
operandCount > 1 and
105+
not tag instanceof UnmodeledUseOperandTag and
106+
message = "Instruction has " + operandCount + " operands with tag '" + tag.toString() + "'" +
107+
" in function '$@'." and
108+
func = instr.getEnclosingIRFunction() and
109+
funcText = Language::getIdentityString(func.getFunction())
110+
)
103111
}
104112

105113
/**

0 commit comments

Comments
 (0)