[clang] [CIR] Upstream support co_return of values from co_await (PR #173174)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 12 16:49:38 PST 2026


================
@@ -737,7 +722,21 @@ void AggExprEmitter::VisitLambdaExpr(LambdaExpr *e) {
 
 void AggExprEmitter::VisitExprWithCleanups(ExprWithCleanups *e) {
   CIRGenFunction::RunCleanupsScope cleanups(cgf);
-  Visit(e->getSubExpr());
+  auto &builder = cgf.getBuilder();
+  auto scopeLoc = cgf.getLoc(e->getSourceRange());
+  mlir::OpBuilder::InsertPoint scopeBegin;
+  cir::ScopeOp::create(builder, scopeLoc, /*scopeBuilder=*/
+                       [&](mlir::OpBuilder &b, mlir::Location loc) {
+                         scopeBegin = b.saveInsertionPoint();
+                       });
+
+  {
+    mlir::OpBuilder::InsertionGuard guard(builder);
+    builder.restoreInsertionPoint(scopeBegin);
+    CIRGenFunction::LexicalScope lexScope{cgf, scopeLoc,
----------------
andykaylor wrote:

I'm guessing that you did this to get the explicit scopes in the output to match the tests in the incubator. I know this is the way this is implemented in the incubator, but I would have expected the `RunCleanupsScope` on line 724 to be sufficient, making this nested `LexicalScope` redundant. The upstream code before this PR matches what classic codegen has here.

The explicit scope being visible in the CIR output makes sense, but I don't think it should be a lexical scope. The trouble is that we don't represent cleanup scopes yet. I guess it's OK to make this change for now, but we'll probably need to revisit this when the exception handling redesign is implemented.

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


More information about the cfe-commits mailing list