Merge pull request #811 from jbj/ir-successor-sanity

C++: IR sanity queries for outgoing edges
This commit is contained in:
Dave Bartolomeo
2019-01-23 23:11:57 -08:00
committed by GitHub
6 changed files with 84 additions and 0 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock

View File

@@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock

View File

@@ -3,6 +3,8 @@ unexpectedOperand
duplicateOperand
missingPhiOperand
instructionWithoutSuccessor
ambiguousSuccessors
unexplainedLoop
unnecessaryPhiInstruction
operandAcrossFunctions
instructionWithoutUniqueBlock