Skip to content

Commit 69f3ea0

Browse files
authored
[MachineBB] Make sure there are successors in terminatorIsComputedGoto. (#151342)
Currently terminatorIsComputedGoto will return for blocks with a indirect branch terminator and no successor. If there are no successor, the terminator is likely not a computed goto, return false in that case. Note that this is currently NFC, as the only use checks it only if there are successors, but it will be needed in #150911. PR: #151342
1 parent 3ca2050 commit 69f3ea0

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ class MachineBasicBlock
323323
const MachineFunction *getParent() const { return xParent; }
324324
MachineFunction *getParent() { return xParent; }
325325

326-
/// Returns true if the original IR terminator is an `indirectbr`. This
327-
/// typically corresponds to a `goto` in C, rather than jump tables.
328-
bool terminatorIsComputedGoto() const {
329-
return back().isIndirectBranch() &&
326+
/// Returns true if the original IR terminator is an `indirectbr` with
327+
/// successor blocks. This typically corresponds to a `goto` in C, rather than
328+
/// jump tables.
329+
bool terminatorIsComputedGotoWithSuccessors() const {
330+
return back().isIndirectBranch() && !succ_empty() &&
330331
llvm::all_of(successors(), [](const MachineBasicBlock *Succ) {
331332
return Succ->isIRBlockAddressTaken();
332333
});

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple,
604604
bool HasComputedGoto = false;
605605
if (!TailBB.empty()) {
606606
HasIndirectbr = TailBB.back().isIndirectBranch();
607-
HasComputedGoto = TailBB.terminatorIsComputedGoto();
607+
HasComputedGoto = TailBB.terminatorIsComputedGotoWithSuccessors();
608608
}
609609

610610
if (HasIndirectbr && PreRegAlloc)

0 commit comments

Comments
 (0)