mirror of
https://github.com/github/codeql.git
synced 2026-05-02 20:25:13 +02:00
Merge pull request #811 from jbj/ir-successor-sanity
C++: IR sanity queries for outgoing edges
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -3,6 +3,8 @@ unexpectedOperand
|
||||
duplicateOperand
|
||||
missingPhiOperand
|
||||
instructionWithoutSuccessor
|
||||
ambiguousSuccessors
|
||||
unexplainedLoop
|
||||
unnecessaryPhiInstruction
|
||||
operandAcrossFunctions
|
||||
instructionWithoutUniqueBlock
|
||||
|
||||
@@ -3,6 +3,8 @@ unexpectedOperand
|
||||
duplicateOperand
|
||||
missingPhiOperand
|
||||
instructionWithoutSuccessor
|
||||
ambiguousSuccessors
|
||||
unexplainedLoop
|
||||
unnecessaryPhiInstruction
|
||||
operandAcrossFunctions
|
||||
instructionWithoutUniqueBlock
|
||||
|
||||
@@ -3,6 +3,8 @@ unexpectedOperand
|
||||
duplicateOperand
|
||||
missingPhiOperand
|
||||
instructionWithoutSuccessor
|
||||
ambiguousSuccessors
|
||||
unexplainedLoop
|
||||
unnecessaryPhiInstruction
|
||||
operandAcrossFunctions
|
||||
instructionWithoutUniqueBlock
|
||||
|
||||
Reference in New Issue
Block a user