================ @@ -297,6 +297,26 @@ struct ReadySuspendResumeResult { bool IsInvalid; }; +// Adds [[clang::coro_wrapper]] and [[clang::coro_disable_lifetimebound]] +// attributes to `get_return_object`. +static void handleGetReturnObject(Sema &S, MemberExpr *ME) { + if (!ME || !ME->getMemberDecl() || !ME->getMemberDecl()->getAsFunction()) + return; + auto *MD = ME->getMemberDecl()->getAsFunction(); + auto *RetType = MD->getReturnType()->getAsRecordDecl(); + if (!RetType || !RetType->hasAttr<CoroReturnTypeAttr>()) + return; + // `get_return_object` should be allowed to return coro_return_type. + if (!MD->hasAttr<CoroWrapperAttr>()) + MD->addAttr( + CoroWrapperAttr::CreateImplicit(S.getASTContext(), MD->getLocation())); + // Object arg of `__promise.get_return_object()` is not lifetimebound. + if (RetType->hasAttr<CoroLifetimeBoundAttr>() && + !MD->hasAttr<CoroDisableLifetimeBoundAttr>()) + MD->addAttr(CoroDisableLifetimeBoundAttr::CreateImplicit( + S.getASTContext(), MD->getLocation())); +} + ---------------- usx95 wrote:
Moved the check to `makeReturnObject`. > Then we should be able to get rid of hard-coding the get_return_object name > in Sema::CheckCoroutineWrapper too? `CheckCoroutineWrapper` is called in `ActOnFinishFunctionBody`. At this point, we are in the `promise::get_return_object` definition. It is possible that we have not seen any coroutine associated with this promise until now. So the coroutine statements would not have been generated. https://github.com/llvm/llvm-project/pull/77066 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits