[Mlir-commits] [mlir] Make `FunctionOpInterface` check `ReturnLike` (PR #112615)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Oct 16 13:57:44 PDT 2024


================
@@ -108,6 +108,29 @@ def FunctionOpInterface : OpInterface<"FunctionOpInterface", [
         }
       }
 
+      // FunctionOpInterface is tied to a ReturnLike.
+      Operation *terminator = entryBlock.getTerminator();
+      if (terminator->hasTrait<OpTrait::ReturnLike>()) {
+        return $_op.emitOpError("The body of a FunctionOpInterface must")
+              << "have a ReturnLike terminator.";
+      }
----------------
graphite-app[bot] wrote:

The condition in this check is inverted. It should be:

```c++
if (!terminator->hasTrait<OpTrait::ReturnLike>())
```

This will correctly emit an error when the terminator does not have the `ReturnLike` trait. The current implementation erroneously reports an error when the terminator does have the desired trait.

Additionally, consider updating the error message to reflect this change:

```c++
return $_op.emitOpError("The body of a FunctionOpInterface must have a ReturnLike terminator, but the current terminator does not have this trait.");
```

This modification will make the error message more informative and consistent with the intended check.

*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>

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


More information about the Mlir-commits mailing list