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
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ module InstructionSanity {
not instr instanceof UnreachedInstruction
}

/**
* Holds if there are multiple (`n`) edges of kind `kind` from `source`,
* where `target` is among the targets of those edges.
*/
query predicate ambiguousSuccessors(
Instruction source, EdgeKind kind, int n, Instruction target
) {
n = strictcount(Instruction t | source.getSuccessor(kind) = t) and
n > 1 and
source.getSuccessor(kind) = target
}

/**
* Holds if `instr` in `f` is part of a loop even though the AST of `f`
* contains no element that can cause loops.
*/
query predicate unexplainedLoop(Function f, Instruction instr) {
exists(IRBlock block |
instr.getBlock() = block and
block.getFunction() = f and
block.getASuccessor+() = block
) and
not exists(Loop l | l.getEnclosingFunction() = f) and
not exists(GotoStmt s | s.getEnclosingFunction() = f)
}

/**
* Holds if a `Phi` instruction is present in a block with fewer than two
* predecessors.
Expand Down
26 changes: 26 additions & 0 deletions cpp/ql/src/semmle/code/cpp/ir/implementation/raw/Instruction.qll
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ module InstructionSanity {
not instr instanceof UnreachedInstruction
}

/**
* Holds if there are multiple (`n`) edges of kind `kind` from `source`,
* where `target` is among the targets of those edges.
*/
query predicate ambiguousSuccessors(
Instruction source, EdgeKind kind, int n, Instruction target
) {
n = strictcount(Instruction t | source.getSuccessor(kind) = t) and
n > 1 and
source.getSuccessor(kind) = target
}

/**
* Holds if `instr` in `f` is part of a loop even though the AST of `f`
* contains no element that can cause loops.
*/
query predicate unexplainedLoop(Function f, Instruction instr) {
exists(IRBlock block |
instr.getBlock() = block and
block.getFunction() = f and
block.getASuccessor+() = block
) and
not exists(Loop l | l.getEnclosingFunction() = f) and
not exists(GotoStmt s | s.getEnclosingFunction() = f)
}

/**
* Holds if a `Phi` instruction is present in a block with fewer than two
* predecessors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ module InstructionSanity {
not instr instanceof UnreachedInstruction
}

/**
* Holds if there are multiple (`n`) edges of kind `kind` from `source`,
* where `target` is among the targets of those edges.
*/
query predicate ambiguousSuccessors(
Instruction source, EdgeKind kind, int n, Instruction target
) {
n = strictcount(Instruction t | source.getSuccessor(kind) = t) and
n > 1 and
source.getSuccessor(kind) = target
}

/**
* Holds if `instr` in `f` is part of a loop even though the AST of `f`
* contains no element that can cause loops.
*/
query predicate unexplainedLoop(Function f, Instruction instr) {
exists(IRBlock block |
instr.getBlock() = block and
block.getFunction() = f and
block.getASuccessor+() = block
) and
not exists(Loop l | l.getEnclosingFunction() = f) and
not exists(GotoStmt s | s.getEnclosingFunction() = f)
}

/**
* Holds if a `Phi` instruction is present in a block with fewer than two
* predecessors.
Expand Down
2 changes: 2 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/aliased_ssa_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock
2 changes: 2 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/raw_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock
2 changes: 2 additions & 0 deletions cpp/ql/test/library-tests/ir/ir/unaliased_ssa_sanity.expected
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock