https://github.com/xakep8 updated https://github.com/llvm/llvm-project/pull/218779
>From 7ffbdb7603a706c5fcb56f5528686cbceced2af0 Mon Sep 17 00:00:00 2001 From: Kunal Dubey <[email protected]> Date: Wed, 26 Aug 2026 01:56:09 +0530 Subject: [PATCH 1/2] [clang] Delay dependent co_return promise calls Avoiding selection of return_value or return_void while building co_return whose operand is type-dependent and keeping it unset until template init rebuild for a type allows dependent operations like co_return ctx.f(v) to use promise.return_void() instead of needing promise.return_value(). --- clang/lib/Analysis/CFG.cpp | 5 +++-- clang/lib/Sema/SemaCoroutine.cpp | 4 ++++ clang/test/SemaCXX/coreturn.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 5263114ebca28..5aaaf5a8c33a8 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -3432,8 +3432,9 @@ CFGBlock *CFGBuilder::VisitReturnStmt(Stmt *S) { CoreturnStmt *CRS = cast<CoreturnStmt>(S); auto *B = Block; - if (CFGBlock *R = Visit(CRS->getPromiseCall())) - B = R; + if (Expr *PromiseCall = CRS->getPromiseCall()) + if (CFGBlock *R = Visit(PromiseCall)) + B = R; if (Expr *RV = CRS->getOperand()) if (RV->getType()->isVoidType() && !isa<InitListExpr>(RV)) diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 627ed96522025..72e74b928b8e0 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1055,6 +1055,10 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E, E = R.get(); } + if (E && !isa<InitListExpr>(E) && E->isTypeDependent()) + return new (Context) + CoreturnStmt(Loc, E, /*PromiseCall=*/nullptr, IsImplicit); + VarDecl *Promise = FSI->CoroutinePromise; ExprResult PC; if (E && (isa<InitListExpr>(E) || !E->getType()->isVoidType())) { diff --git a/clang/test/SemaCXX/coreturn.cpp b/clang/test/SemaCXX/coreturn.cpp index 7069a1040db23..8fb2506848c3d 100644 --- a/clang/test/SemaCXX/coreturn.cpp +++ b/clang/test/SemaCXX/coreturn.cpp @@ -138,3 +138,29 @@ VoidTagReturnValue test11(bool b) { if (b) co_return 42; } // expected-warning {{non-void coroutine does not return a value in all control paths}} + +namespace dependent_void_coreturn { +struct coro { + struct promise_type { + coro get_return_object(); + suspend_never initial_suspend(); + suspend_never final_suspend() noexcept; + void unhandled_exception(); + void return_void(); + }; +}; + +struct Ctx { + template <typename T> + T &get(); + void f(int); +}; + +template <typename T> +coro f(Ctx &ctx) { + auto &v = ctx.get<T>(); + co_return ctx.f(v); +} + +void use(Ctx &ctx) { f<int>(ctx); } +} >From e6208c2ef5de2cec71bbcf0a7cd1cfb5b9b3e7ad Mon Sep 17 00:00:00 2001 From: Kunal Dubey <[email protected]> Date: Wed, 26 Aug 2026 21:06:41 +0530 Subject: [PATCH 2/2] [clang] Added changes to release notes along with code comment --- clang/docs/ReleaseNotes.md | 4 ++++ clang/lib/Sema/SemaCoroutine.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index cd7f40aec112d..69b9e80e0cf9d 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -522,6 +522,10 @@ features cannot lower the translation-unit ABI level; using ``__is_constructible`` on a nested class template inside the definition of the containing class. (#GH215166) +- Fixed a bug where Clang incorrectly required `promise.return_value()` for a + dependent `co_return` operand that inits to `void`, instead of using + `promise.return_void()`. (#GH218368) + - Fixed merging of lambdas across modules in the case where neither lambda is imported from an AST file. (#GH214560) diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 72e74b928b8e0..b46efba09500f 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1055,6 +1055,9 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E, E = R.get(); } + // A type-dependent operand can init to either void or non-void. + // Delay selecting return_void or return_value until template init + // rebuilds the co_return statement with the operand type. if (E && !isa<InitListExpr>(E) && E->isTypeDependent()) return new (Context) CoreturnStmt(Loc, E, /*PromiseCall=*/nullptr, IsImplicit); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
