[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:18 PDT 2026


================
@@ -326,11 +409,20 @@ CIRGenFunction::emitCoroutineBody(const CoroutineBodyStmt &s) {
 
     curCoro.data->currentAwaitKind = cir::AwaitKind::User;
 
-    // FIXME(cir): wrap emitBodyAndFallthrough with try/catch bits.
-    if (s.getExceptionHandler())
-      assert(!cir::MissingFeatures::coroutineExceptions());
-    if (emitBodyAndFallthrough(*this, s, s.getBody(), curLexScope).failed())
-      return mlir::failure();
+    mlir::OpBuilder::InsertPoint userBody;
+    cir::CoroBodyOp::create(builder, openCurlyLoc, /*scopeBuilder=*/
+                            [&](mlir::OpBuilder &b, mlir::Location loc) {
+                              userBody = b.saveInsertionPoint();
+                            });
+    {
+      mlir::OpBuilder::InsertionGuard guard(builder);
+      builder.restoreInsertionPoint(userBody);
+      // FIXME(cir): wrap emitBodyAndFallthrough with try/catch bits.
+      if (s.getExceptionHandler())
+        assert(!cir::MissingFeatures::coroutineExceptions());
----------------
Andres-Salamanca wrote:

Done

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


More information about the cfe-commits mailing list