Author: Weibo He Date: 2026-03-03T16:08:06+08:00 New Revision: 9cda40735a17194fec9cac9689dd5acf1eb1a44f
URL: https://github.com/llvm/llvm-project/commit/9cda40735a17194fec9cac9689dd5acf1eb1a44f DIFF: https://github.com/llvm/llvm-project/commit/9cda40735a17194fec9cac9689dd5acf1eb1a44f.diff LOG: [clang][Sema] Fix initialization of GRO when GRO-return type mismatches (CWG2563) (#179156) This patch implements one piece of proposed solution to [CWG2563](https://cplusplus.github.io/CWG/issues/2563.html): > get-return-object-invocation is as follows: > ... > otherwise, get-return-object-invocation initializes a variable with the exposition-only name gro as if by > decltype(auto) gro = promise.get_return_object(); Close #98744 Added: clang/test/CodeGenCoroutines/coro-gro3.cpp Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaCoroutine.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 88bdf765f858c..3c3e5f5a77a40 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -329,6 +329,8 @@ Bug Fixes to C++ Support - Fixed a crash when evaluating uninitialized GCC vector/ext_vector_type vectors in ``constexpr``. (#GH180044) - Fixed a crash on ``typeid`` of incomplete local types during template instantiation. (#GH63242), (#GH176397) +- Fix initialization of GRO when GRO-return type mismatches, as part of CWG2563. (#GH98744) + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed a bug where explicit nullability property attributes were not stored in AST nodes in Objective-C. (#GH179703) diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp index 027ec93ce5f66..07bb6e2161cc7 100644 --- a/clang/lib/Sema/SemaCoroutine.cpp +++ b/clang/lib/Sema/SemaCoroutine.cpp @@ -1872,7 +1872,8 @@ bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() { } else { GroDecl = VarDecl::Create( S.Context, &FD, FD.getLocation(), FD.getLocation(), - &S.PP.getIdentifierTable().get("__coro_gro"), GroType, + &S.PP.getIdentifierTable().get("__coro_gro"), + S.BuildDecltypeType(ReturnValue).getCanonicalType(), S.Context.getTrivialTypeSourceInfo(GroType, Loc), SC_None); GroDecl->setImplicit(); diff --git a/clang/test/CodeGenCoroutines/coro-gro3.cpp b/clang/test/CodeGenCoroutines/coro-gro3.cpp new file mode 100644 index 0000000000000..8c37b1e9838d3 --- /dev/null +++ b/clang/test/CodeGenCoroutines/coro-gro3.cpp @@ -0,0 +1,53 @@ +// Tests defination of get-return-object-invocation [dcl.fct.def.coroutine] (and CWG2563) +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s + +#include "Inputs/coroutine.h" + +using namespace std; + +extern "C" { +void wrong(); +} + +template<bool LValue> +struct Promise { + Promise() = default; + Promise(const Promise&) { wrong(); } + Promise(Promise&&) { wrong(); } + + // Tests: decltype(auto) gro = promise.get_return_object(); + auto&& get_return_object() { + if constexpr (LValue) + return *this; + else + return static_cast<Promise&&>(*this); + } + std::suspend_never initial_suspend() const { return {}; } + std::suspend_never final_suspend() const noexcept { return {}; } + void return_void() const {} + void unhandled_exception() const noexcept {} +}; + +template<bool LValue> +struct Handle { + using promise_type = Promise<LValue>; + + Handle(promise_type& p) { + if constexpr (!LValue) + wrong(); + } + Handle(promise_type&& p) { + if constexpr (LValue) + wrong(); + } +}; + +Handle<true> lvalue() { + co_return; +} + +Handle<false> rvalue() { + co_return; +} + +// CHECK-NOT: call void @wrong _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
