[Mlir-commits] [mlir] [mlir][IR] Fix `Block::without_terminator` for blocks without terminator (PR #154498)

Mehdi Amini llvmlistbot at llvm.org
Wed Aug 20 05:47:13 PDT 2025


================
@@ -221,9 +226,15 @@ class alignas(8) Block : public IRObjectWithUseList<BlockOperand>,
   /// the block might have a valid terminator operation.
   Operation *getTerminator();
 
-  /// Check whether this block might have a terminator.
+  /// Return "true" if this block might have a terminator. Return "true" if
+  /// the last operation is unregistered.
   bool mightHaveTerminator();
 
+  /// Return "true" if this block has a terminator. Return "false" if the last
+  /// operation is unregistered. In that case, the presence of a terminator
+  /// cannot be determined.
+  bool hasTerminator();
----------------
joker-eph wrote:

This API does not exist intentionally: folks should use `mightHaveTerminator()` and then check further themselves to adjust to their local need.

The `without_terminator()` API is convenient but a real footgun in situation where we're not sure: I can see it breaking badly different scenario regardless of the behavior we chose!


https://github.com/llvm/llvm-project/pull/154498


More information about the Mlir-commits mailing list