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:
Uday Bondhugula 2019-02-01 13:18:20 -08:00 committed by jpienaar
parent c46b0feadb
commit f0d4e70f26
1 changed files with 6 additions and 1 deletions

View File

@ -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) {