Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions cpp/ql/src/semmle/code/cpp/ir/internal/Instruction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ module InstructionSanity {
count(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

query predicate operandAcrossFunctions(
Instruction op, Instruction operand, OperandTag tag
) {
operand = op.getOperand(tag) and
operand.getFunctionIR() != op.getFunctionIR()
}
}

/**
Expand Down Expand Up @@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
// Register results are always in SSA form.
not hasMemoryResult() or
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
not exists(UnmodeledUseOperand useTag |
hasUse(_, useTag)
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
this = useInstr.getOperand(useTag)
)
}

Expand Down Expand Up @@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
final Instruction getAPredecessor() {
result = getPredecessor(_)
}

/**
* Holds if the result of this instruction is consumed by `useInstruction` as
* an operand with tag `useTag`.
*/
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
useInstruction.getFunctionIR() = funcIR and
this = useInstruction.getOperand(useTag)
}
}

class VariableInstruction extends Instruction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ predicate operandEscapes(Instruction instr, OperandTag tag) {
predicate resultEscapes(Instruction instr) {
// The result escapes if it has at least one use that escapes.
exists(Instruction useInstr, OperandTag useOperandTag |
instr.hasUse(useInstr, useOperandTag) and
useInstr.getOperand(useOperandTag) = instr and
operandEscapes(useInstr, useOperandTag)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ module InstructionSanity {
count(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

query predicate operandAcrossFunctions(
Instruction op, Instruction operand, OperandTag tag
) {
operand = op.getOperand(tag) and
operand.getFunctionIR() != op.getFunctionIR()
}
}

/**
Expand Down Expand Up @@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
// Register results are always in SSA form.
not hasMemoryResult() or
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
not exists(UnmodeledUseOperand useTag |
hasUse(_, useTag)
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
this = useInstr.getOperand(useTag)
)
}

Expand Down Expand Up @@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
final Instruction getAPredecessor() {
result = getPredecessor(_)
}

/**
* Holds if the result of this instruction is consumed by `useInstruction` as
* an operand with tag `useTag`.
*/
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
useInstruction.getFunctionIR() = funcIR and
this = useInstruction.getOperand(useTag)
}
}

class VariableInstruction extends Instruction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ predicate operandEscapes(Instruction instr, OperandTag tag) {
predicate resultEscapes(Instruction instr) {
// The result escapes if it has at least one use that escapes.
exists(Instruction useInstr, OperandTag useOperandTag |
instr.hasUse(useInstr, useOperandTag) and
useInstr.getOperand(useOperandTag) = instr and
operandEscapes(useInstr, useOperandTag)
)
}
Expand Down
20 changes: 9 additions & 11 deletions cpp/ql/src/semmle/code/cpp/ssa/internal/ssa/Instruction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ module InstructionSanity {
count(instr.getOperand(tag)) > 1 and
not tag instanceof UnmodeledUseOperand
}

query predicate operandAcrossFunctions(
Instruction op, Instruction operand, OperandTag tag
) {
operand = op.getOperand(tag) and
operand.getFunctionIR() != op.getFunctionIR()
}
}

/**
Expand Down Expand Up @@ -262,8 +269,8 @@ class Instruction extends Construction::TInstruction {
// Register results are always in SSA form.
not hasMemoryResult() or
// An unmodeled result will have a use on the `UnmodeledUse` instruction.
not exists(UnmodeledUseOperand useTag |
hasUse(_, useTag)
not exists(Instruction useInstr, UnmodeledUseOperand useTag |
this = useInstr.getOperand(useTag)
)
}

Expand Down Expand Up @@ -296,15 +303,6 @@ class Instruction extends Construction::TInstruction {
final Instruction getAPredecessor() {
result = getPredecessor(_)
}

/**
* Holds if the result of this instruction is consumed by `useInstruction` as
* an operand with tag `useTag`.
*/
final predicate hasUse(Instruction useInstruction, OperandTag useTag) {
useInstruction.getFunctionIR() = funcIR and
this = useInstruction.getOperand(useTag)
}
}

class VariableInstruction extends Instruction {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
missingOperand
unexpectedOperand
duplicateOperand
operandAcrossFunctions
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/ir/ir/IRSanity.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
missingOperand
unexpectedOperand
duplicateOperand
operandAcrossFunctions
1 change: 1 addition & 0 deletions cpp/ql/test/library-tests/ir/ir/SSAIRSanity.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
missingOperand
unexpectedOperand
duplicateOperand
operandAcrossFunctions