[Mlir-commits] [mlir] [mlir][RegionBranchOpInterface] explicitly check for existance of block terminator (PR #76831)
Maksim Levental
llvmlistbot at llvm.org
Wed Jan 3 08:32:08 PST 2024
https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/76831
`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.
>From 759cefb70fd13284c782971aa252b453051945bf Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Wed, 3 Jan 2024 10:26:48 -0600
Subject: [PATCH] [mlir][RegionBranchOpInterface] explicitly check for
existance of block terminator
---
mlir/lib/Interfaces/ControlFlowInterfaces.cpp | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
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);
More information about the Mlir-commits
mailing list