[Mlir-commits] [mlir] [mlir][RegionBranchOpInterface] explicitly check for existance of block terminator (PR #76831)
Markus Böck
llvmlistbot at llvm.org
Wed Jan 3 08:57:57 PST 2024
================
@@ -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>(
----------------
zero9178 wrote:
This kind of `if` statement is somewhat controversial (see https://discourse.llvm.org/t/rfc-code-style-of-initializer-in-if-statement/65357) and the way you've written it causes interface lookup to be performed twice.
I think it'd be neater to just write it as:
```cpp
if (block.mightHaveTerminator())
if(auto terminator = dyn_cast<RegionBranchTerminatorOpInterface>(block.getTerminator())
...
```
https://github.com/llvm/llvm-project/pull/76831
More information about the Mlir-commits
mailing list