forked from OSchip/llvm-project
Fix Block::getNumSuccessors()
- getTerminator() on a block can return nullptr; moreover, blocks that are improperly constructed/transformed by utilities/passes may not have terminators even for the top-level blocks PiperOrigin-RevId: 232025963
This commit is contained in:
parent
c46b0feadb
commit
f0d4e70f26
|
@ -189,7 +189,12 @@ bool Block::hasNoPredecessors() const { return pred_begin() == pred_end(); }
|
||||||
|
|
||||||
// Indexed successor access.
|
// Indexed successor access.
|
||||||
unsigned Block::getNumSuccessors() const {
|
unsigned Block::getNumSuccessors() const {
|
||||||
return getTerminator()->getNumSuccessors();
|
if (auto *terminator = getTerminator()) {
|
||||||
|
return terminator->getNumSuccessors();
|
||||||
|
}
|
||||||
|
assert(getParent() && "top-level block with no terminator");
|
||||||
|
// Blocks inside 'for'/'if' instructions don't have successors.
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block *Block::getSuccessor(unsigned i) {
|
Block *Block::getSuccessor(unsigned i) {
|
||||||
|
|
Loading…
Reference in New Issue