[clang] [CIR] Add coroutine cleanup handling and update co_return semantics (PR #189281)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 6 19:18:03 PDT 2026
================
@@ -2874,6 +2874,48 @@ LogicalResult cir::AwaitOp::verify() {
return success();
}
+LogicalResult cir::CoReturnOp::verify() {
+ if (!getOperation()->getParentOfType<CoroBodyOp>())
+ return emitOpError("must be inside a cir.coro.body");
+ return success();
+}
+
+//===----------------------------------------------------------------------===//
+// CoroBody
+//===----------------------------------------------------------------------===//
+
+void cir::CoroBodyOp::getSuccessorRegions(
+ mlir::RegionBranchPoint point, SmallVectorImpl<RegionSuccessor> ®ions) {
+ if (!point.isParent()) {
+ regions.push_back(RegionSuccessor::parent());
+ return;
+ }
+
+ regions.push_back(RegionSuccessor(&getBodyRegion()));
+}
+
+mlir::ValueRange
+cir::CoroBodyOp::getSuccessorInputs(RegionSuccessor successor) {
+ return ValueRange();
+}
+
+LogicalResult cir::CoroBodyOp::verify() {
+ if (!getOperation()->getParentOfType<FuncOp>().getCoroutine())
+ return emitOpError("enclosing function must be a coroutine");
+ return success();
----------------
Andres-Salamanca wrote:
No, it does not necessarily need to end with a `CoReturnOp`. There are cases where it cannot be terminated with a `CoReturnOp`, so I added support for allowing the body region to also be terminated using a `YieldOp`. Thanks for catching this!
https://github.com/llvm/llvm-project/pull/189281
More information about the cfe-commits
mailing list