[llvm] [MachineBB] Make sure there are successors in terminatorIsComputedGoto. (PR #151342)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 07:10:40 PDT 2025


https://github.com/fhahn created https://github.com/llvm/llvm-project/pull/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
https://github.com/llvm/llvm-project/pull/150911.

>From 92fb44f0a1067a84bfb82497c19de250db983645 Mon Sep 17 00:00:00 2001
From: Florian Hahn <flo at fhahn.com>
Date: Fri, 25 Jul 2025 09:46:31 +0100
Subject: [PATCH] [MachineBB] Make sure there are successors in
 terminatorIsComputedGoto.

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
https://github.com/llvm/llvm-project/pull/150911.
---
 llvm/include/llvm/CodeGen/MachineBasicBlock.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
index 938d71dd030e8..050b92f47dd5f 100644
--- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h
@@ -326,7 +326,7 @@ class MachineBasicBlock
   /// Returns true if the original IR terminator is an `indirectbr`. This
   /// typically corresponds to a `goto` in C, rather than jump tables.
   bool terminatorIsComputedGoto() const {
-    return back().isIndirectBranch() &&
+    return back().isIndirectBranch() && !succ_empty() &&
            llvm::all_of(successors(), [](const MachineBasicBlock *Succ) {
              return Succ->isIRBlockAddressTaken();
            });



More information about the llvm-commits mailing list