[Mlir-commits] [mlir] [mlir][RegionBranchOpInterface] explicitly check for existance of block terminator (PR #76831)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Jan 3 08:32:39 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

<details>
<summary>Changes</summary>

`RegionBranchTerminatorOpInterface` doesn't explicitly assume existence of [block terminators](https://github.com/llvm/llvm-project/blob/759cefb70fd13284c782971aa252b453051945bf/mlir/lib/Interfaces/ControlFlowInterfaces.cpp#L187):

```cpp
    // If there is no return-like terminator, the op itself should verify
    // type consistency.
    if (regionReturnOps.empty())
      continue;
```

but it does implicitly because `block.getTerminator()`

```cpp
    SmallVector<RegionBranchTerminatorOpInterface> regionReturnOps;
    for (Block &block : region)
      if (auto terminator = dyn_cast<RegionBranchTerminatorOpInterface>(
              block.getTerminator()))
        regionReturnOps.push_back(terminator);
``` 

does `assert(mightHaveTerminator());`. So just make that explicit.



---
Full diff: https://github.com/llvm/llvm-project/pull/76831.diff


1 Files Affected:

- (modified) mlir/lib/Interfaces/ControlFlowInterfaces.cpp (+4-1) 


``````````diff
diff --git a/mlir/lib/Interfaces/ControlFlowInterfaces.cpp b/mlir/lib/Interfaces/ControlFlowInterfaces.cpp
index 4ed024ddae247b..0585e2ee5e0218 100644
--- a/mlir/lib/Interfaces/ControlFlowInterfaces.cpp
+++ b/mlir/lib/Interfaces/ControlFlowInterfaces.cpp
@@ -177,7 +177,10 @@ LogicalResult detail::verifyTypesAlongControlFlowEdges(Operation *op) {
 
     SmallVector<RegionBranchTerminatorOpInterface> regionReturnOps;
     for (Block &block : region)
-      if (auto terminator = dyn_cast<RegionBranchTerminatorOpInterface>(
+      if (block.mightHaveTerminator() &&
+              dyn_cast<RegionBranchTerminatorOpInterface>(
+                  block.getTerminator());
+          auto terminator = dyn_cast<RegionBranchTerminatorOpInterface>(
               block.getTerminator()))
         regionReturnOps.push_back(terminator);
 

``````````

</details>


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


More information about the Mlir-commits mailing list