1 //===--- SemaCoroutines.cpp - Semantic Analysis for Coroutines ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements semantic analysis for C++ Coroutines.
12 //===----------------------------------------------------------------------===//
14 #include "CoroutineStmtBuilder.h"
15 #include "clang/AST/Decl.h"
16 #include "clang/AST/ExprCXX.h"
17 #include "clang/AST/StmtCXX.h"
18 #include "clang/Lex/Preprocessor.h"
19 #include "clang/Sema/Initialization.h"
20 #include "clang/Sema/Overload.h"
21 #include "clang/Sema/SemaInternal.h"
23 using namespace clang;
26 static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD,
27 SourceLocation Loc, bool &Res) {
28 DeclarationName DN = S.PP.getIdentifierInfo(Name);
29 LookupResult LR(S, DN, Loc, Sema::LookupMemberName);
30 // Suppress diagnostics when a private member is selected. The same warnings
31 // will be produced again when building the call.
32 LR.suppressDiagnostics();
33 Res = S.LookupQualifiedName(LR, RD);
37 static bool lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD,
40 lookupMember(S, Name, RD, Loc, Res);
44 /// Look up the std::coroutine_traits<...>::promise_type for the given
46 static QualType lookupPromiseType(Sema &S, const FunctionProtoType *FnType,
48 SourceLocation FuncLoc) {
49 // FIXME: Cache std::coroutine_traits once we've found it.
50 NamespaceDecl *StdExp = S.lookupStdExperimentalNamespace();
52 S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
53 << "std::experimental::coroutine_traits";
57 LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_traits"),
58 FuncLoc, Sema::LookupOrdinaryName);
59 if (!S.LookupQualifiedName(Result, StdExp)) {
60 S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
61 << "std::experimental::coroutine_traits";
65 ClassTemplateDecl *CoroTraits = Result.getAsSingle<ClassTemplateDecl>();
67 Result.suppressDiagnostics();
68 // We found something weird. Complain about the first thing we found.
69 NamedDecl *Found = *Result.begin();
70 S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
74 // Form template argument list for coroutine_traits<R, P1, P2, ...>.
75 TemplateArgumentListInfo Args(KwLoc, KwLoc);
76 Args.addArgument(TemplateArgumentLoc(
77 TemplateArgument(FnType->getReturnType()),
78 S.Context.getTrivialTypeSourceInfo(FnType->getReturnType(), KwLoc)));
79 // FIXME: If the function is a non-static member function, add the type
80 // of the implicit object parameter before the formal parameters.
81 for (QualType T : FnType->getParamTypes())
82 Args.addArgument(TemplateArgumentLoc(
83 TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc)));
85 // Build the template-id.
87 S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args);
88 if (CoroTrait.isNull())
90 if (S.RequireCompleteType(KwLoc, CoroTrait,
91 diag::err_coroutine_type_missing_specialization))
94 auto *RD = CoroTrait->getAsCXXRecordDecl();
95 assert(RD && "specialization of class template is not a class?");
97 // Look up the ::promise_type member.
98 LookupResult R(S, &S.PP.getIdentifierTable().get("promise_type"), KwLoc,
99 Sema::LookupOrdinaryName);
100 S.LookupQualifiedName(R, RD);
101 auto *Promise = R.getAsSingle<TypeDecl>();
104 diag::err_implied_std_coroutine_traits_promise_type_not_found)
108 // The promise type is required to be a class type.
109 QualType PromiseType = S.Context.getTypeDeclType(Promise);
111 auto buildElaboratedType = [&]() {
112 auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, StdExp);
113 NNS = NestedNameSpecifier::Create(S.Context, NNS, false,
114 CoroTrait.getTypePtr());
115 return S.Context.getElaboratedType(ETK_None, NNS, PromiseType);
118 if (!PromiseType->getAsCXXRecordDecl()) {
120 diag::err_implied_std_coroutine_traits_promise_type_not_class)
121 << buildElaboratedType();
124 if (S.RequireCompleteType(FuncLoc, buildElaboratedType(),
125 diag::err_coroutine_promise_type_incomplete))
131 /// Look up the std::experimental::coroutine_handle<PromiseType>.
132 static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType,
133 SourceLocation Loc) {
134 if (PromiseType.isNull())
137 NamespaceDecl *StdExp = S.lookupStdExperimentalNamespace();
138 assert(StdExp && "Should already be diagnosed");
140 LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_handle"),
141 Loc, Sema::LookupOrdinaryName);
142 if (!S.LookupQualifiedName(Result, StdExp)) {
143 S.Diag(Loc, diag::err_implied_coroutine_type_not_found)
144 << "std::experimental::coroutine_handle";
148 ClassTemplateDecl *CoroHandle = Result.getAsSingle<ClassTemplateDecl>();
150 Result.suppressDiagnostics();
151 // We found something weird. Complain about the first thing we found.
152 NamedDecl *Found = *Result.begin();
153 S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle);
157 // Form template argument list for coroutine_handle<Promise>.
158 TemplateArgumentListInfo Args(Loc, Loc);
159 Args.addArgument(TemplateArgumentLoc(
160 TemplateArgument(PromiseType),
161 S.Context.getTrivialTypeSourceInfo(PromiseType, Loc)));
163 // Build the template-id.
164 QualType CoroHandleType =
165 S.CheckTemplateIdType(TemplateName(CoroHandle), Loc, Args);
166 if (CoroHandleType.isNull())
168 if (S.RequireCompleteType(Loc, CoroHandleType,
169 diag::err_coroutine_type_missing_specialization))
172 return CoroHandleType;
175 static bool isValidCoroutineContext(Sema &S, SourceLocation Loc,
177 // 'co_await' and 'co_yield' are not permitted in unevaluated operands.
178 if (S.isUnevaluatedContext()) {
179 S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
183 // Any other usage must be within a function.
184 auto *FD = dyn_cast<FunctionDecl>(S.CurContext);
186 S.Diag(Loc, isa<ObjCMethodDecl>(S.CurContext)
187 ? diag::err_coroutine_objc_method
188 : diag::err_coroutine_outside_function) << Keyword;
192 // An enumeration for mapping the diagnostic type to the correct diagnostic
194 enum InvalidFuncDiag {
204 bool Diagnosed = false;
205 auto DiagInvalid = [&](InvalidFuncDiag ID) {
206 S.Diag(Loc, diag::err_coroutine_invalid_func_context) << ID << Keyword;
211 // Diagnose when a constructor, destructor, copy/move assignment operator,
212 // or the function 'main' are declared as a coroutine.
213 auto *MD = dyn_cast<CXXMethodDecl>(FD);
214 if (MD && isa<CXXConstructorDecl>(MD))
215 return DiagInvalid(DiagCtor);
216 else if (MD && isa<CXXDestructorDecl>(MD))
217 return DiagInvalid(DiagDtor);
218 else if (MD && MD->isCopyAssignmentOperator())
219 return DiagInvalid(DiagCopyAssign);
220 else if (MD && MD->isMoveAssignmentOperator())
221 return DiagInvalid(DiagMoveAssign);
222 else if (FD->isMain())
223 return DiagInvalid(DiagMain);
225 // Emit a diagnostics for each of the following conditions which is not met.
226 if (FD->isConstexpr())
227 DiagInvalid(DiagConstexpr);
228 if (FD->getReturnType()->isUndeducedType())
229 DiagInvalid(DiagAutoRet);
230 if (FD->isVariadic())
231 DiagInvalid(DiagVarargs);
236 static ExprResult buildOperatorCoawaitLookupExpr(Sema &SemaRef, Scope *S,
237 SourceLocation Loc) {
238 DeclarationName OpName =
239 SemaRef.Context.DeclarationNames.getCXXOperatorName(OO_Coawait);
240 LookupResult Operators(SemaRef, OpName, SourceLocation(),
241 Sema::LookupOperatorName);
242 SemaRef.LookupName(Operators, S);
244 assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous");
245 const auto &Functions = Operators.asUnresolvedSet();
247 Functions.size() > 1 ||
248 (Functions.size() == 1 && isa<FunctionTemplateDecl>(*Functions.begin()));
249 Expr *CoawaitOp = UnresolvedLookupExpr::Create(
250 SemaRef.Context, /*NamingClass*/ nullptr, NestedNameSpecifierLoc(),
251 DeclarationNameInfo(OpName, Loc), /*RequiresADL*/ true, IsOverloaded,
252 Functions.begin(), Functions.end());
257 /// Build a call to 'operator co_await' if there is a suitable operator for
258 /// the given expression.
259 static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, SourceLocation Loc,
261 UnresolvedLookupExpr *Lookup) {
262 UnresolvedSet<16> Functions;
263 Functions.append(Lookup->decls_begin(), Lookup->decls_end());
264 return SemaRef.CreateOverloadedUnaryOp(Loc, UO_Coawait, Functions, E);
267 static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S,
268 SourceLocation Loc, Expr *E) {
269 ExprResult R = buildOperatorCoawaitLookupExpr(SemaRef, S, Loc);
272 return buildOperatorCoawaitCall(SemaRef, Loc, E,
273 cast<UnresolvedLookupExpr>(R.get()));
276 static Expr *buildBuiltinCall(Sema &S, SourceLocation Loc, Builtin::ID Id,
277 MultiExprArg CallArgs) {
278 StringRef Name = S.Context.BuiltinInfo.getName(Id);
279 LookupResult R(S, &S.Context.Idents.get(Name), Loc, Sema::LookupOrdinaryName);
280 S.LookupName(R, S.TUScope, /*AllowBuiltinCreation=*/true);
282 auto *BuiltInDecl = R.getAsSingle<FunctionDecl>();
283 assert(BuiltInDecl && "failed to find builtin declaration");
286 S.BuildDeclRefExpr(BuiltInDecl, BuiltInDecl->getType(), VK_LValue, Loc);
287 assert(DeclRef.isUsable() && "Builtin reference cannot fail");
290 S.ActOnCallExpr(/*Scope=*/nullptr, DeclRef.get(), Loc, CallArgs, Loc);
292 assert(!Call.isInvalid() && "Call to builtin cannot fail!");
296 static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType,
297 SourceLocation Loc) {
298 QualType CoroHandleType = lookupCoroutineHandleType(S, PromiseType, Loc);
299 if (CoroHandleType.isNull())
302 DeclContext *LookupCtx = S.computeDeclContext(CoroHandleType);
303 LookupResult Found(S, &S.PP.getIdentifierTable().get("from_address"), Loc,
304 Sema::LookupOrdinaryName);
305 if (!S.LookupQualifiedName(Found, LookupCtx)) {
306 S.Diag(Loc, diag::err_coroutine_handle_missing_member)
312 buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
315 ExprResult FromAddr =
316 S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
317 if (FromAddr.isInvalid())
320 return S.ActOnCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc);
323 struct ReadySuspendResumeResult {
324 enum AwaitCallType { ACT_Ready, ACT_Suspend, ACT_Resume };
326 OpaqueValueExpr *OpaqueValue;
330 static ExprResult buildMemberCall(Sema &S, Expr *Base, SourceLocation Loc,
331 StringRef Name, MultiExprArg Args) {
332 DeclarationNameInfo NameInfo(&S.PP.getIdentifierTable().get(Name), Loc);
334 // FIXME: Fix BuildMemberReferenceExpr to take a const CXXScopeSpec&.
336 ExprResult Result = S.BuildMemberReferenceExpr(
337 Base, Base->getType(), Loc, /*IsPtr=*/false, SS,
338 SourceLocation(), nullptr, NameInfo, /*TemplateArgs=*/nullptr,
340 if (Result.isInvalid())
343 return S.ActOnCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr);
346 /// Build calls to await_ready, await_suspend, and await_resume for a co_await
348 static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise,
349 SourceLocation Loc, Expr *E) {
350 OpaqueValueExpr *Operand = new (S.Context)
351 OpaqueValueExpr(Loc, E->getType(), VK_LValue, E->getObjectKind(), E);
353 // Assume invalid until we see otherwise.
354 ReadySuspendResumeResult Calls = {{}, Operand, /*IsInvalid=*/true};
356 ExprResult CoroHandleRes = buildCoroutineHandle(S, CoroPromise->getType(), Loc);
357 if (CoroHandleRes.isInvalid())
359 Expr *CoroHandle = CoroHandleRes.get();
361 const StringRef Funcs[] = {"await_ready", "await_suspend", "await_resume"};
362 MultiExprArg Args[] = {None, CoroHandle, None};
363 for (size_t I = 0, N = llvm::array_lengthof(Funcs); I != N; ++I) {
364 ExprResult Result = buildMemberCall(S, Operand, Loc, Funcs[I], Args[I]);
365 if (Result.isInvalid())
367 Calls.Results[I] = Result.get();
370 // Assume the calls are valid; all further checking should make them invalid.
371 Calls.IsInvalid = false;
373 using ACT = ReadySuspendResumeResult::AwaitCallType;
374 CallExpr *AwaitReady = cast<CallExpr>(Calls.Results[ACT::ACT_Ready]);
375 if (!AwaitReady->getType()->isDependentType()) {
376 // [expr.await]p3 [...]
377 // — await-ready is the expression e.await_ready(), contextually converted
379 ExprResult Conv = S.PerformContextuallyConvertToBool(AwaitReady);
380 if (Conv.isInvalid()) {
381 S.Diag(AwaitReady->getDirectCallee()->getLocStart(),
382 diag::note_await_ready_no_bool_conversion);
383 S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
384 << AwaitReady->getDirectCallee() << E->getSourceRange();
385 Calls.IsInvalid = true;
387 Calls.Results[ACT::ACT_Ready] = Conv.get();
389 CallExpr *AwaitSuspend = cast<CallExpr>(Calls.Results[ACT::ACT_Suspend]);
390 if (!AwaitSuspend->getType()->isDependentType()) {
391 // [expr.await]p3 [...]
392 // - await-suspend is the expression e.await_suspend(h), which shall be
393 // a prvalue of type void or bool.
394 QualType RetType = AwaitSuspend->getCallReturnType(S.Context);
395 // non-class prvalues always have cv-unqualified types
396 QualType AdjRetType = RetType.getUnqualifiedType();
397 if (RetType->isReferenceType() ||
398 (AdjRetType != S.Context.BoolTy && AdjRetType != S.Context.VoidTy)) {
399 S.Diag(AwaitSuspend->getCalleeDecl()->getLocation(),
400 diag::err_await_suspend_invalid_return_type)
402 S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
403 << AwaitSuspend->getDirectCallee();
404 Calls.IsInvalid = true;
411 static ExprResult buildPromiseCall(Sema &S, VarDecl *Promise,
412 SourceLocation Loc, StringRef Name,
415 // Form a reference to the promise.
416 ExprResult PromiseRef = S.BuildDeclRefExpr(
417 Promise, Promise->getType().getNonReferenceType(), VK_LValue, Loc);
418 if (PromiseRef.isInvalid())
421 return buildMemberCall(S, PromiseRef.get(), Loc, Name, Args);
424 VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) {
425 assert(isa<FunctionDecl>(CurContext) && "not in a function scope");
426 auto *FD = cast<FunctionDecl>(CurContext);
429 FD->getType()->isDependentType()
430 ? Context.DependentTy
431 : lookupPromiseType(*this, FD->getType()->castAs<FunctionProtoType>(),
432 Loc, FD->getLocation());
436 auto *VD = VarDecl::Create(Context, FD, FD->getLocation(), FD->getLocation(),
437 &PP.getIdentifierTable().get("__promise"), T,
438 Context.getTrivialTypeSourceInfo(T, Loc), SC_None);
439 CheckVariableDeclarationType(VD);
440 if (VD->isInvalidDecl())
442 ActOnUninitializedDecl(VD);
444 assert(!VD->isInvalidDecl());
448 /// Check that this is a context in which a coroutine suspension can appear.
449 static FunctionScopeInfo *checkCoroutineContext(Sema &S, SourceLocation Loc,
451 bool IsImplicit = false) {
452 if (!isValidCoroutineContext(S, Loc, Keyword))
455 assert(isa<FunctionDecl>(S.CurContext) && "not in a function scope");
457 auto *ScopeInfo = S.getCurFunction();
458 assert(ScopeInfo && "missing function scope for function");
460 if (ScopeInfo->FirstCoroutineStmtLoc.isInvalid() && !IsImplicit)
461 ScopeInfo->setFirstCoroutineStmt(Loc, Keyword);
463 if (ScopeInfo->CoroutinePromise)
466 ScopeInfo->CoroutinePromise = S.buildCoroutinePromise(Loc);
467 if (!ScopeInfo->CoroutinePromise)
473 bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc,
475 if (!checkCoroutineContext(*this, KWLoc, Keyword))
477 auto *ScopeInfo = getCurFunction();
478 assert(ScopeInfo->CoroutinePromise);
480 // If we have existing coroutine statements then we have already built
481 // the initial and final suspend points.
482 if (!ScopeInfo->NeedsCoroutineSuspends)
485 ScopeInfo->setNeedsCoroutineSuspends(false);
487 auto *Fn = cast<FunctionDecl>(CurContext);
488 SourceLocation Loc = Fn->getLocation();
489 // Build the initial suspend point
490 auto buildSuspends = [&](StringRef Name) mutable -> StmtResult {
492 buildPromiseCall(*this, ScopeInfo->CoroutinePromise, Loc, Name, None);
493 if (Suspend.isInvalid())
495 Suspend = buildOperatorCoawaitCall(*this, SC, Loc, Suspend.get());
496 if (Suspend.isInvalid())
498 Suspend = BuildResolvedCoawaitExpr(Loc, Suspend.get(),
499 /*IsImplicit*/ true);
500 Suspend = ActOnFinishFullExpr(Suspend.get());
501 if (Suspend.isInvalid()) {
502 Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required)
503 << ((Name == "initial_suspend") ? 0 : 1);
504 Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword;
507 return cast<Stmt>(Suspend.get());
510 StmtResult InitSuspend = buildSuspends("initial_suspend");
511 if (InitSuspend.isInvalid())
514 StmtResult FinalSuspend = buildSuspends("final_suspend");
515 if (FinalSuspend.isInvalid())
518 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
523 ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) {
524 if (!ActOnCoroutineBodyStart(S, Loc, "co_await")) {
525 CorrectDelayedTyposInExpr(E);
529 if (E->getType()->isPlaceholderType()) {
530 ExprResult R = CheckPlaceholderExpr(E);
531 if (R.isInvalid()) return ExprError();
534 ExprResult Lookup = buildOperatorCoawaitLookupExpr(*this, S, Loc);
535 if (Lookup.isInvalid())
537 return BuildUnresolvedCoawaitExpr(Loc, E,
538 cast<UnresolvedLookupExpr>(Lookup.get()));
541 ExprResult Sema::BuildUnresolvedCoawaitExpr(SourceLocation Loc, Expr *E,
542 UnresolvedLookupExpr *Lookup) {
543 auto *FSI = checkCoroutineContext(*this, Loc, "co_await");
547 if (E->getType()->isPlaceholderType()) {
548 ExprResult R = CheckPlaceholderExpr(E);
554 auto *Promise = FSI->CoroutinePromise;
555 if (Promise->getType()->isDependentType()) {
557 new (Context) DependentCoawaitExpr(Loc, Context.DependentTy, E, Lookup);
561 auto *RD = Promise->getType()->getAsCXXRecordDecl();
562 if (lookupMember(*this, "await_transform", RD, Loc)) {
563 ExprResult R = buildPromiseCall(*this, Promise, Loc, "await_transform", E);
566 diag::note_coroutine_promise_implicit_await_transform_required_here)
567 << E->getSourceRange();
572 ExprResult Awaitable = buildOperatorCoawaitCall(*this, Loc, E, Lookup);
573 if (Awaitable.isInvalid())
576 return BuildResolvedCoawaitExpr(Loc, Awaitable.get());
579 ExprResult Sema::BuildResolvedCoawaitExpr(SourceLocation Loc, Expr *E,
581 auto *Coroutine = checkCoroutineContext(*this, Loc, "co_await", IsImplicit);
585 if (E->getType()->isPlaceholderType()) {
586 ExprResult R = CheckPlaceholderExpr(E);
587 if (R.isInvalid()) return ExprError();
591 if (E->getType()->isDependentType()) {
592 Expr *Res = new (Context)
593 CoawaitExpr(Loc, Context.DependentTy, E, IsImplicit);
597 // If the expression is a temporary, materialize it as an lvalue so that we
598 // can use it multiple times.
599 if (E->getValueKind() == VK_RValue)
600 E = CreateMaterializeTemporaryExpr(E->getType(), E, true);
602 // Build the await_ready, await_suspend, await_resume calls.
603 ReadySuspendResumeResult RSS =
604 buildCoawaitCalls(*this, Coroutine->CoroutinePromise, Loc, E);
609 new (Context) CoawaitExpr(Loc, E, RSS.Results[0], RSS.Results[1],
610 RSS.Results[2], RSS.OpaqueValue, IsImplicit);
615 ExprResult Sema::ActOnCoyieldExpr(Scope *S, SourceLocation Loc, Expr *E) {
616 if (!ActOnCoroutineBodyStart(S, Loc, "co_yield")) {
617 CorrectDelayedTyposInExpr(E);
621 // Build yield_value call.
622 ExprResult Awaitable = buildPromiseCall(
623 *this, getCurFunction()->CoroutinePromise, Loc, "yield_value", E);
624 if (Awaitable.isInvalid())
627 // Build 'operator co_await' call.
628 Awaitable = buildOperatorCoawaitCall(*this, S, Loc, Awaitable.get());
629 if (Awaitable.isInvalid())
632 return BuildCoyieldExpr(Loc, Awaitable.get());
634 ExprResult Sema::BuildCoyieldExpr(SourceLocation Loc, Expr *E) {
635 auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield");
639 if (E->getType()->isPlaceholderType()) {
640 ExprResult R = CheckPlaceholderExpr(E);
641 if (R.isInvalid()) return ExprError();
645 if (E->getType()->isDependentType()) {
646 Expr *Res = new (Context) CoyieldExpr(Loc, Context.DependentTy, E);
650 // If the expression is a temporary, materialize it as an lvalue so that we
651 // can use it multiple times.
652 if (E->getValueKind() == VK_RValue)
653 E = CreateMaterializeTemporaryExpr(E->getType(), E, true);
655 // Build the await_ready, await_suspend, await_resume calls.
656 ReadySuspendResumeResult RSS =
657 buildCoawaitCalls(*this, Coroutine->CoroutinePromise, Loc, E);
662 new (Context) CoyieldExpr(Loc, E, RSS.Results[0], RSS.Results[1],
663 RSS.Results[2], RSS.OpaqueValue);
668 StmtResult Sema::ActOnCoreturnStmt(Scope *S, SourceLocation Loc, Expr *E) {
669 if (!ActOnCoroutineBodyStart(S, Loc, "co_return")) {
670 CorrectDelayedTyposInExpr(E);
673 return BuildCoreturnStmt(Loc, E);
676 StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E,
678 auto *FSI = checkCoroutineContext(*this, Loc, "co_return", IsImplicit);
682 if (E && E->getType()->isPlaceholderType() &&
683 !E->getType()->isSpecificPlaceholderType(BuiltinType::Overload)) {
684 ExprResult R = CheckPlaceholderExpr(E);
685 if (R.isInvalid()) return StmtError();
689 // FIXME: If the operand is a reference to a variable that's about to go out
690 // of scope, we should treat the operand as an xvalue for this overload
692 VarDecl *Promise = FSI->CoroutinePromise;
694 if (E && (isa<InitListExpr>(E) || !E->getType()->isVoidType())) {
695 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
697 E = MakeFullDiscardedValueExpr(E).get();
698 PC = buildPromiseCall(*this, Promise, Loc, "return_void", None);
703 Expr *PCE = ActOnFinishFullExpr(PC.get()).get();
705 Stmt *Res = new (Context) CoreturnStmt(Loc, E, PCE, IsImplicit);
709 /// Look up the std::nothrow object.
710 static Expr *buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc) {
711 NamespaceDecl *Std = S.getStdNamespace();
712 assert(Std && "Should already be diagnosed");
714 LookupResult Result(S, &S.PP.getIdentifierTable().get("nothrow"), Loc,
715 Sema::LookupOrdinaryName);
716 if (!S.LookupQualifiedName(Result, Std)) {
717 // FIXME: <experimental/coroutine> should have been included already.
718 // If we require it to include <new> then this diagnostic is no longer
720 S.Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found);
724 // FIXME: Mark the variable as ODR used. This currently does not work
725 // likely due to the scope at in which this function is called.
726 auto *VD = Result.getAsSingle<VarDecl>();
728 Result.suppressDiagnostics();
729 // We found something weird. Complain about the first thing we found.
730 NamedDecl *Found = *Result.begin();
731 S.Diag(Found->getLocation(), diag::err_malformed_std_nothrow);
735 ExprResult DR = S.BuildDeclRefExpr(VD, VD->getType(), VK_LValue, Loc);
742 // Find an appropriate delete for the promise.
743 static FunctionDecl *findDeleteForPromise(Sema &S, SourceLocation Loc,
744 QualType PromiseType) {
745 FunctionDecl *OperatorDelete = nullptr;
747 DeclarationName DeleteName =
748 S.Context.DeclarationNames.getCXXOperatorName(OO_Delete);
750 auto *PointeeRD = PromiseType->getAsCXXRecordDecl();
751 assert(PointeeRD && "PromiseType must be a CxxRecordDecl type");
753 if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete))
756 if (!OperatorDelete) {
757 // Look for a global declaration.
758 const bool CanProvideSize = S.isCompleteType(Loc, PromiseType);
759 const bool Overaligned = false;
760 OperatorDelete = S.FindUsualDeallocationFunction(Loc, CanProvideSize,
761 Overaligned, DeleteName);
763 S.MarkFunctionReferenced(Loc, OperatorDelete);
764 return OperatorDelete;
768 void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) {
769 FunctionScopeInfo *Fn = getCurFunction();
770 assert(Fn && Fn->isCoroutine() && "not a coroutine");
772 assert(FD->isInvalidDecl() &&
773 "a null body is only allowed for invalid declarations");
776 // We have a function that uses coroutine keywords, but we failed to build
778 if (!Fn->CoroutinePromise)
779 return FD->setInvalidDecl();
781 if (isa<CoroutineBodyStmt>(Body)) {
782 // Nothing todo. the body is already a transformed coroutine body statement.
786 // Coroutines [stmt.return]p1:
787 // A return statement shall not appear in a coroutine.
788 if (Fn->FirstReturnLoc.isValid()) {
789 assert(Fn->FirstCoroutineStmtLoc.isValid() &&
790 "first coroutine location not set");
791 Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine);
792 Diag(Fn->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
793 << Fn->getFirstCoroutineStmtKeyword();
795 CoroutineStmtBuilder Builder(*this, *FD, *Fn, Body);
796 if (Builder.isInvalid() || !Builder.buildStatements())
797 return FD->setInvalidDecl();
799 // Build body for the coroutine wrapper statement.
800 Body = CoroutineBodyStmt::Create(Context, Builder);
803 CoroutineStmtBuilder::CoroutineStmtBuilder(Sema &S, FunctionDecl &FD,
804 sema::FunctionScopeInfo &Fn,
806 : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()),
807 IsPromiseDependentType(
808 !Fn.CoroutinePromise ||
809 Fn.CoroutinePromise->getType()->isDependentType()) {
811 if (!IsPromiseDependentType) {
812 PromiseRecordDecl = Fn.CoroutinePromise->getType()->getAsCXXRecordDecl();
813 assert(PromiseRecordDecl && "Type should have already been checked");
815 this->IsValid = makePromiseStmt() && makeInitialAndFinalSuspend();
818 bool CoroutineStmtBuilder::buildStatements() {
819 assert(this->IsValid && "coroutine already invalid");
820 this->IsValid = makeReturnObject() && makeParamMoves();
821 if (this->IsValid && !IsPromiseDependentType)
822 buildDependentStatements();
823 return this->IsValid;
826 bool CoroutineStmtBuilder::buildDependentStatements() {
827 assert(this->IsValid && "coroutine already invalid");
828 assert(!this->IsPromiseDependentType &&
829 "coroutine cannot have a dependent promise type");
830 this->IsValid = makeOnException() && makeOnFallthrough() &&
831 makeGroDeclAndReturnStmt() && makeReturnOnAllocFailure() &&
832 makeNewAndDeleteExpr();
833 return this->IsValid;
836 bool CoroutineStmtBuilder::buildParameterMoves() {
837 assert(this->IsValid && "coroutine already invalid");
838 assert(this->ParamMoves.empty() && "param moves already built");
839 return this->IsValid = makeParamMoves();
842 bool CoroutineStmtBuilder::makePromiseStmt() {
843 // Form a declaration statement for the promise declaration, so that AST
844 // visitors can more easily find it.
845 StmtResult PromiseStmt =
846 S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(Fn.CoroutinePromise), Loc, Loc);
847 if (PromiseStmt.isInvalid())
850 this->Promise = PromiseStmt.get();
854 bool CoroutineStmtBuilder::makeInitialAndFinalSuspend() {
855 if (Fn.hasInvalidCoroutineSuspends())
857 this->InitialSuspend = cast<Expr>(Fn.CoroutineSuspends.first);
858 this->FinalSuspend = cast<Expr>(Fn.CoroutineSuspends.second);
862 static bool diagReturnOnAllocFailure(Sema &S, Expr *E,
863 CXXRecordDecl *PromiseRecordDecl,
864 FunctionScopeInfo &Fn) {
865 auto Loc = E->getExprLoc();
866 if (auto *DeclRef = dyn_cast_or_null<DeclRefExpr>(E)) {
867 auto *Decl = DeclRef->getDecl();
868 if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(Decl)) {
869 if (Method->isStatic())
872 Loc = Decl->getLocation();
878 diag::err_coroutine_promise_get_return_object_on_allocation_failure)
879 << PromiseRecordDecl;
880 S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
881 << Fn.getFirstCoroutineStmtKeyword();
885 bool CoroutineStmtBuilder::makeReturnOnAllocFailure() {
886 assert(!IsPromiseDependentType &&
887 "cannot make statement while the promise type is dependent");
889 // [dcl.fct.def.coroutine]/8
890 // The unqualified-id get_return_object_on_allocation_failure is looked up in
891 // the scope of class P by class member access lookup (3.4.5). ...
892 // If an allocation function returns nullptr, ... the coroutine return value
893 // is obtained by a call to ... get_return_object_on_allocation_failure().
896 S.PP.getIdentifierInfo("get_return_object_on_allocation_failure");
897 LookupResult Found(S, DN, Loc, Sema::LookupMemberName);
898 if (!S.LookupQualifiedName(Found, PromiseRecordDecl))
902 ExprResult DeclNameExpr =
903 S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
904 if (DeclNameExpr.isInvalid())
907 if (!diagReturnOnAllocFailure(S, DeclNameExpr.get(), PromiseRecordDecl, Fn))
910 ExprResult ReturnObjectOnAllocationFailure =
911 S.ActOnCallExpr(nullptr, DeclNameExpr.get(), Loc, {}, Loc);
912 if (ReturnObjectOnAllocationFailure.isInvalid())
915 StmtResult ReturnStmt =
916 S.BuildReturnStmt(Loc, ReturnObjectOnAllocationFailure.get());
917 if (ReturnStmt.isInvalid()) {
918 S.Diag(Found.getFoundDecl()->getLocation(), diag::note_member_declared_here)
920 S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
921 << Fn.getFirstCoroutineStmtKeyword();
925 this->ReturnStmtOnAllocFailure = ReturnStmt.get();
929 bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
930 // Form and check allocation and deallocation calls.
931 assert(!IsPromiseDependentType &&
932 "cannot make statement while the promise type is dependent");
933 QualType PromiseType = Fn.CoroutinePromise->getType();
935 if (S.RequireCompleteType(Loc, PromiseType, diag::err_incomplete_type))
938 const bool RequiresNoThrowAlloc = ReturnStmtOnAllocFailure != nullptr;
940 // FIXME: Add support for stateful allocators.
942 FunctionDecl *OperatorNew = nullptr;
943 FunctionDecl *OperatorDelete = nullptr;
944 FunctionDecl *UnusedResult = nullptr;
945 bool PassAlignment = false;
946 SmallVector<Expr *, 1> PlacementArgs;
948 S.FindAllocationFunctions(Loc, SourceRange(),
949 /*UseGlobal*/ false, PromiseType,
950 /*isArray*/ false, PassAlignment, PlacementArgs,
951 OperatorNew, UnusedResult);
953 bool IsGlobalOverload =
954 OperatorNew && !isa<CXXRecordDecl>(OperatorNew->getDeclContext());
955 // If we didn't find a class-local new declaration and non-throwing new
956 // was is required then we need to lookup the non-throwing global operator
958 if (RequiresNoThrowAlloc && (!OperatorNew || IsGlobalOverload)) {
959 auto *StdNoThrow = buildStdNoThrowDeclRef(S, Loc);
962 PlacementArgs = {StdNoThrow};
963 OperatorNew = nullptr;
964 S.FindAllocationFunctions(Loc, SourceRange(),
965 /*UseGlobal*/ true, PromiseType,
966 /*isArray*/ false, PassAlignment, PlacementArgs,
967 OperatorNew, UnusedResult);
970 assert(OperatorNew && "expected definition of operator new to be found");
972 if (RequiresNoThrowAlloc) {
973 const auto *FT = OperatorNew->getType()->getAs<FunctionProtoType>();
974 if (!FT->isNothrow(S.Context, /*ResultIfDependent*/ false)) {
975 S.Diag(OperatorNew->getLocation(),
976 diag::err_coroutine_promise_new_requires_nothrow)
978 S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
984 if ((OperatorDelete = findDeleteForPromise(S, Loc, PromiseType)) == nullptr)
988 buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
991 buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_size, {});
996 S.BuildDeclRefExpr(OperatorNew, OperatorNew->getType(), VK_LValue, Loc);
997 if (NewRef.isInvalid())
1000 SmallVector<Expr *, 2> NewArgs(1, FrameSize);
1001 for (auto Arg : PlacementArgs)
1002 NewArgs.push_back(Arg);
1004 ExprResult NewExpr =
1005 S.ActOnCallExpr(S.getCurScope(), NewRef.get(), Loc, NewArgs, Loc);
1006 NewExpr = S.ActOnFinishFullExpr(NewExpr.get());
1007 if (NewExpr.isInvalid())
1010 // Make delete call.
1012 QualType OpDeleteQualType = OperatorDelete->getType();
1014 ExprResult DeleteRef =
1015 S.BuildDeclRefExpr(OperatorDelete, OpDeleteQualType, VK_LValue, Loc);
1016 if (DeleteRef.isInvalid())
1020 buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_free, {FramePtr});
1022 SmallVector<Expr *, 2> DeleteArgs{CoroFree};
1024 // Check if we need to pass the size.
1025 const auto *OpDeleteType =
1026 OpDeleteQualType.getTypePtr()->getAs<FunctionProtoType>();
1027 if (OpDeleteType->getNumParams() > 1)
1028 DeleteArgs.push_back(FrameSize);
1030 ExprResult DeleteExpr =
1031 S.ActOnCallExpr(S.getCurScope(), DeleteRef.get(), Loc, DeleteArgs, Loc);
1032 DeleteExpr = S.ActOnFinishFullExpr(DeleteExpr.get());
1033 if (DeleteExpr.isInvalid())
1036 this->Allocate = NewExpr.get();
1037 this->Deallocate = DeleteExpr.get();
1042 bool CoroutineStmtBuilder::makeOnFallthrough() {
1043 assert(!IsPromiseDependentType &&
1044 "cannot make statement while the promise type is dependent");
1046 // [dcl.fct.def.coroutine]/4
1047 // The unqualified-ids 'return_void' and 'return_value' are looked up in
1048 // the scope of class P. If both are found, the program is ill-formed.
1049 bool HasRVoid, HasRValue;
1050 LookupResult LRVoid =
1051 lookupMember(S, "return_void", PromiseRecordDecl, Loc, HasRVoid);
1052 LookupResult LRValue =
1053 lookupMember(S, "return_value", PromiseRecordDecl, Loc, HasRValue);
1055 StmtResult Fallthrough;
1056 if (HasRVoid && HasRValue) {
1057 // FIXME Improve this diagnostic
1058 S.Diag(FD.getLocation(),
1059 diag::err_coroutine_promise_incompatible_return_functions)
1060 << PromiseRecordDecl;
1061 S.Diag(LRVoid.getRepresentativeDecl()->getLocation(),
1062 diag::note_member_first_declared_here)
1063 << LRVoid.getLookupName();
1064 S.Diag(LRValue.getRepresentativeDecl()->getLocation(),
1065 diag::note_member_first_declared_here)
1066 << LRValue.getLookupName();
1068 } else if (!HasRVoid && !HasRValue) {
1069 // FIXME: The PDTS currently specifies this case as UB, not ill-formed.
1070 // However we still diagnose this as an error since until the PDTS is fixed.
1071 S.Diag(FD.getLocation(),
1072 diag::err_coroutine_promise_requires_return_function)
1073 << PromiseRecordDecl;
1074 S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here)
1075 << PromiseRecordDecl;
1077 } else if (HasRVoid) {
1078 // If the unqualified-id return_void is found, flowing off the end of a
1079 // coroutine is equivalent to a co_return with no operand. Otherwise,
1080 // flowing off the end of a coroutine results in undefined behavior.
1081 Fallthrough = S.BuildCoreturnStmt(FD.getLocation(), nullptr,
1082 /*IsImplicit*/false);
1083 Fallthrough = S.ActOnFinishFullStmt(Fallthrough.get());
1084 if (Fallthrough.isInvalid())
1088 this->OnFallthrough = Fallthrough.get();
1092 bool CoroutineStmtBuilder::makeOnException() {
1093 // Try to form 'p.unhandled_exception();'
1094 assert(!IsPromiseDependentType &&
1095 "cannot make statement while the promise type is dependent");
1097 const bool RequireUnhandledException = S.getLangOpts().CXXExceptions;
1099 if (!lookupMember(S, "unhandled_exception", PromiseRecordDecl, Loc)) {
1101 RequireUnhandledException
1102 ? diag::err_coroutine_promise_unhandled_exception_required
1104 warn_coroutine_promise_unhandled_exception_required_with_exceptions;
1105 S.Diag(Loc, DiagID) << PromiseRecordDecl;
1106 S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here)
1107 << PromiseRecordDecl;
1108 return !RequireUnhandledException;
1111 // If exceptions are disabled, don't try to build OnException.
1112 if (!S.getLangOpts().CXXExceptions)
1115 ExprResult UnhandledException = buildPromiseCall(S, Fn.CoroutinePromise, Loc,
1116 "unhandled_exception", None);
1117 UnhandledException = S.ActOnFinishFullExpr(UnhandledException.get(), Loc);
1118 if (UnhandledException.isInvalid())
1121 // Since the body of the coroutine will be wrapped in try-catch, it will
1122 // be incompatible with SEH __try if present in a function.
1123 if (!S.getLangOpts().Borland && Fn.FirstSEHTryLoc.isValid()) {
1124 S.Diag(Fn.FirstSEHTryLoc, diag::err_seh_in_a_coroutine_with_cxx_exceptions);
1125 S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
1126 << Fn.getFirstCoroutineStmtKeyword();
1130 this->OnException = UnhandledException.get();
1134 bool CoroutineStmtBuilder::makeReturnObject() {
1135 // Build implicit 'p.get_return_object()' expression and form initialization
1136 // of return type from it.
1137 ExprResult ReturnObject =
1138 buildPromiseCall(S, Fn.CoroutinePromise, Loc, "get_return_object", None);
1139 if (ReturnObject.isInvalid())
1142 this->ReturnValue = ReturnObject.get();
1146 static void noteMemberDeclaredHere(Sema &S, Expr *E, FunctionScopeInfo &Fn) {
1147 if (auto *MbrRef = dyn_cast<CXXMemberCallExpr>(E)) {
1148 auto *MethodDecl = MbrRef->getMethodDecl();
1149 S.Diag(MethodDecl->getLocation(), diag::note_member_declared_here)
1152 S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
1153 << Fn.getFirstCoroutineStmtKeyword();
1156 bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() {
1157 assert(!IsPromiseDependentType &&
1158 "cannot make statement while the promise type is dependent");
1159 assert(this->ReturnValue && "ReturnValue must be already formed");
1161 QualType const GroType = this->ReturnValue->getType();
1162 assert(!GroType->isDependentType() &&
1163 "get_return_object type must no longer be dependent");
1165 QualType const FnRetType = FD.getReturnType();
1166 assert(!FnRetType->isDependentType() &&
1167 "get_return_object type must no longer be dependent");
1169 if (FnRetType->isVoidType()) {
1170 ExprResult Res = S.ActOnFinishFullExpr(this->ReturnValue, Loc);
1171 if (Res.isInvalid())
1174 this->ResultDecl = Res.get();
1178 if (GroType->isVoidType()) {
1179 // Trigger a nice error message.
1180 InitializedEntity Entity =
1181 InitializedEntity::InitializeResult(Loc, FnRetType, false);
1182 S.PerformMoveOrCopyInitialization(Entity, nullptr, FnRetType, ReturnValue);
1183 noteMemberDeclaredHere(S, ReturnValue, Fn);
1187 auto *GroDecl = VarDecl::Create(
1188 S.Context, &FD, FD.getLocation(), FD.getLocation(),
1189 &S.PP.getIdentifierTable().get("__coro_gro"), GroType,
1190 S.Context.getTrivialTypeSourceInfo(GroType, Loc), SC_None);
1192 S.CheckVariableDeclarationType(GroDecl);
1193 if (GroDecl->isInvalidDecl())
1196 InitializedEntity Entity = InitializedEntity::InitializeVariable(GroDecl);
1197 ExprResult Res = S.PerformMoveOrCopyInitialization(Entity, nullptr, GroType,
1199 if (Res.isInvalid())
1202 Res = S.ActOnFinishFullExpr(Res.get());
1203 if (Res.isInvalid())
1206 if (GroType == FnRetType) {
1207 GroDecl->setNRVOVariable(true);
1210 S.AddInitializerToDecl(GroDecl, Res.get(),
1211 /*DirectInit=*/false);
1213 S.FinalizeDeclaration(GroDecl);
1215 // Form a declaration statement for the return declaration, so that AST
1216 // visitors can more easily find it.
1217 StmtResult GroDeclStmt =
1218 S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(GroDecl), Loc, Loc);
1219 if (GroDeclStmt.isInvalid())
1222 this->ResultDecl = GroDeclStmt.get();
1224 ExprResult declRef = S.BuildDeclRefExpr(GroDecl, GroType, VK_LValue, Loc);
1225 if (declRef.isInvalid())
1228 StmtResult ReturnStmt = S.BuildReturnStmt(Loc, declRef.get());
1229 if (ReturnStmt.isInvalid()) {
1230 noteMemberDeclaredHere(S, ReturnValue, Fn);
1234 this->ReturnStmt = ReturnStmt.get();
1238 // Create a static_cast\<T&&>(expr).
1239 static Expr *castForMoving(Sema &S, Expr *E, QualType T = QualType()) {
1242 QualType TargetType = S.BuildReferenceType(
1243 T, /*SpelledAsLValue*/ false, SourceLocation(), DeclarationName());
1244 SourceLocation ExprLoc = E->getLocStart();
1245 TypeSourceInfo *TargetLoc =
1246 S.Context.getTrivialTypeSourceInfo(TargetType, ExprLoc);
1249 .BuildCXXNamedCast(ExprLoc, tok::kw_static_cast, TargetLoc, E,
1250 SourceRange(ExprLoc, ExprLoc), E->getSourceRange())
1255 /// \brief Build a variable declaration for move parameter.
1256 static VarDecl *buildVarDecl(Sema &S, SourceLocation Loc, QualType Type,
1257 IdentifierInfo *II) {
1258 TypeSourceInfo *TInfo = S.Context.getTrivialTypeSourceInfo(Type, Loc);
1260 VarDecl::Create(S.Context, S.CurContext, Loc, Loc, II, Type, TInfo, SC_None);
1261 Decl->setImplicit();
1265 bool CoroutineStmtBuilder::makeParamMoves() {
1266 for (auto *paramDecl : FD.parameters()) {
1267 auto Ty = paramDecl->getType();
1268 if (Ty->isDependentType())
1271 // No need to copy scalars, llvm will take care of them.
1272 if (Ty->getAsCXXRecordDecl()) {
1273 ExprResult ParamRef =
1274 S.BuildDeclRefExpr(paramDecl, paramDecl->getType(),
1275 ExprValueKind::VK_LValue, Loc); // FIXME: scope?
1276 if (ParamRef.isInvalid())
1279 Expr *RCast = castForMoving(S, ParamRef.get());
1281 auto D = buildVarDecl(S, Loc, Ty, paramDecl->getIdentifier());
1282 S.AddInitializerToDecl(D, RCast, /*DirectInit=*/true);
1284 // Convert decl to a statement.
1285 StmtResult Stmt = S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(D), Loc, Loc);
1286 if (Stmt.isInvalid())
1289 ParamMovesVector.push_back(Stmt.get());
1293 // Convert to ArrayRef in CtorArgs structure that builder inherits from.
1294 ParamMoves = ParamMovesVector;
1298 StmtResult Sema::BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
1299 CoroutineBodyStmt *Res = CoroutineBodyStmt::Create(Context, Args);