clang  5.0.0
SemaCoroutine.cpp
Go to the documentation of this file.
1 //===--- SemaCoroutines.cpp - Semantic Analysis for Coroutines ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements semantic analysis for C++ Coroutines.
11 //
12 //===----------------------------------------------------------------------===//
13 
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"
20 #include "clang/Sema/Overload.h"
22 
23 using namespace clang;
24 using namespace sema;
25 
26 static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD,
27  SourceLocation Loc, bool &Res) {
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.
33  Res = S.LookupQualifiedName(LR, RD);
34  return LR;
35 }
36 
37 static bool lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD,
38  SourceLocation Loc) {
39  bool Res;
40  lookupMember(S, Name, RD, Loc, Res);
41  return Res;
42 }
43 
44 /// Look up the std::coroutine_traits<...>::promise_type for the given
45 /// function type.
47  SourceLocation KwLoc) {
48  const FunctionProtoType *FnType = FD->getType()->castAs<FunctionProtoType>();
49  const SourceLocation FuncLoc = FD->getLocation();
50  // FIXME: Cache std::coroutine_traits once we've found it.
52  if (!StdExp) {
53  S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
54  << "std::experimental::coroutine_traits";
55  return QualType();
56  }
57 
58  LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_traits"),
59  FuncLoc, Sema::LookupOrdinaryName);
60  if (!S.LookupQualifiedName(Result, StdExp)) {
61  S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
62  << "std::experimental::coroutine_traits";
63  return QualType();
64  }
65 
66  ClassTemplateDecl *CoroTraits = Result.getAsSingle<ClassTemplateDecl>();
67  if (!CoroTraits) {
68  Result.suppressDiagnostics();
69  // We found something weird. Complain about the first thing we found.
70  NamedDecl *Found = *Result.begin();
71  S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
72  return QualType();
73  }
74 
75  // Form template argument list for coroutine_traits<R, P1, P2, ...> according
76  // to [dcl.fct.def.coroutine]3
77  TemplateArgumentListInfo Args(KwLoc, KwLoc);
78  auto AddArg = [&](QualType T) {
81  };
82  AddArg(FnType->getReturnType());
83  // If the function is a non-static member function, add the type
84  // of the implicit object parameter before the formal parameters.
85  if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
86  if (MD->isInstance()) {
87  // [over.match.funcs]4
88  // For non-static member functions, the type of the implicit object
89  // parameter is
90  // -- "lvalue reference to cv X" for functions declared without a
91  // ref-qualifier or with the & ref-qualifier
92  // -- "rvalue reference to cv X" for functions declared with the &&
93  // ref-qualifier
94  QualType T =
95  MD->getThisType(S.Context)->getAs<PointerType>()->getPointeeType();
96  T = FnType->getRefQualifier() == RQ_RValue
98  : S.Context.getLValueReferenceType(T, /*SpelledAsLValue*/ true);
99  AddArg(T);
100  }
101  }
102  for (QualType T : FnType->getParamTypes())
103  AddArg(T);
104 
105  // Build the template-id.
106  QualType CoroTrait =
107  S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args);
108  if (CoroTrait.isNull())
109  return QualType();
110  if (S.RequireCompleteType(KwLoc, CoroTrait,
111  diag::err_coroutine_type_missing_specialization))
112  return QualType();
113 
114  auto *RD = CoroTrait->getAsCXXRecordDecl();
115  assert(RD && "specialization of class template is not a class?");
116 
117  // Look up the ::promise_type member.
118  LookupResult R(S, &S.PP.getIdentifierTable().get("promise_type"), KwLoc,
120  S.LookupQualifiedName(R, RD);
121  auto *Promise = R.getAsSingle<TypeDecl>();
122  if (!Promise) {
123  S.Diag(FuncLoc,
124  diag::err_implied_std_coroutine_traits_promise_type_not_found)
125  << RD;
126  return QualType();
127  }
128  // The promise type is required to be a class type.
129  QualType PromiseType = S.Context.getTypeDeclType(Promise);
130 
131  auto buildElaboratedType = [&]() {
132  auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, StdExp);
133  NNS = NestedNameSpecifier::Create(S.Context, NNS, false,
134  CoroTrait.getTypePtr());
135  return S.Context.getElaboratedType(ETK_None, NNS, PromiseType);
136  };
137 
138  if (!PromiseType->getAsCXXRecordDecl()) {
139  S.Diag(FuncLoc,
140  diag::err_implied_std_coroutine_traits_promise_type_not_class)
141  << buildElaboratedType();
142  return QualType();
143  }
144  if (S.RequireCompleteType(FuncLoc, buildElaboratedType(),
145  diag::err_coroutine_promise_type_incomplete))
146  return QualType();
147 
148  return PromiseType;
149 }
150 
151 /// Look up the std::experimental::coroutine_handle<PromiseType>.
153  SourceLocation Loc) {
154  if (PromiseType.isNull())
155  return QualType();
156 
158  assert(StdExp && "Should already be diagnosed");
159 
160  LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_handle"),
162  if (!S.LookupQualifiedName(Result, StdExp)) {
163  S.Diag(Loc, diag::err_implied_coroutine_type_not_found)
164  << "std::experimental::coroutine_handle";
165  return QualType();
166  }
167 
168  ClassTemplateDecl *CoroHandle = Result.getAsSingle<ClassTemplateDecl>();
169  if (!CoroHandle) {
170  Result.suppressDiagnostics();
171  // We found something weird. Complain about the first thing we found.
172  NamedDecl *Found = *Result.begin();
173  S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle);
174  return QualType();
175  }
176 
177  // Form template argument list for coroutine_handle<Promise>.
178  TemplateArgumentListInfo Args(Loc, Loc);
180  TemplateArgument(PromiseType),
181  S.Context.getTrivialTypeSourceInfo(PromiseType, Loc)));
182 
183  // Build the template-id.
184  QualType CoroHandleType =
185  S.CheckTemplateIdType(TemplateName(CoroHandle), Loc, Args);
186  if (CoroHandleType.isNull())
187  return QualType();
188  if (S.RequireCompleteType(Loc, CoroHandleType,
189  diag::err_coroutine_type_missing_specialization))
190  return QualType();
191 
192  return CoroHandleType;
193 }
194 
196  StringRef Keyword) {
197  // 'co_await' and 'co_yield' are not permitted in unevaluated operands.
198  if (S.isUnevaluatedContext()) {
199  S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
200  return false;
201  }
202 
203  // Any other usage must be within a function.
204  auto *FD = dyn_cast<FunctionDecl>(S.CurContext);
205  if (!FD) {
206  S.Diag(Loc, isa<ObjCMethodDecl>(S.CurContext)
207  ? diag::err_coroutine_objc_method
208  : diag::err_coroutine_outside_function) << Keyword;
209  return false;
210  }
211 
212  // An enumeration for mapping the diagnostic type to the correct diagnostic
213  // selection index.
214  enum InvalidFuncDiag {
215  DiagCtor = 0,
216  DiagDtor,
217  DiagCopyAssign,
218  DiagMoveAssign,
219  DiagMain,
220  DiagConstexpr,
221  DiagAutoRet,
222  DiagVarargs,
223  };
224  bool Diagnosed = false;
225  auto DiagInvalid = [&](InvalidFuncDiag ID) {
226  S.Diag(Loc, diag::err_coroutine_invalid_func_context) << ID << Keyword;
227  Diagnosed = true;
228  return false;
229  };
230 
231  // Diagnose when a constructor, destructor, copy/move assignment operator,
232  // or the function 'main' are declared as a coroutine.
233  auto *MD = dyn_cast<CXXMethodDecl>(FD);
234  if (MD && isa<CXXConstructorDecl>(MD))
235  return DiagInvalid(DiagCtor);
236  else if (MD && isa<CXXDestructorDecl>(MD))
237  return DiagInvalid(DiagDtor);
238  else if (MD && MD->isCopyAssignmentOperator())
239  return DiagInvalid(DiagCopyAssign);
240  else if (MD && MD->isMoveAssignmentOperator())
241  return DiagInvalid(DiagMoveAssign);
242  else if (FD->isMain())
243  return DiagInvalid(DiagMain);
244 
245  // Emit a diagnostics for each of the following conditions which is not met.
246  if (FD->isConstexpr())
247  DiagInvalid(DiagConstexpr);
248  if (FD->getReturnType()->isUndeducedType())
249  DiagInvalid(DiagAutoRet);
250  if (FD->isVariadic())
251  DiagInvalid(DiagVarargs);
252 
253  return !Diagnosed;
254 }
255 
257  SourceLocation Loc) {
258  DeclarationName OpName =
259  SemaRef.Context.DeclarationNames.getCXXOperatorName(OO_Coawait);
260  LookupResult Operators(SemaRef, OpName, SourceLocation(),
262  SemaRef.LookupName(Operators, S);
263 
264  assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous");
265  const auto &Functions = Operators.asUnresolvedSet();
266  bool IsOverloaded =
267  Functions.size() > 1 ||
268  (Functions.size() == 1 && isa<FunctionTemplateDecl>(*Functions.begin()));
269  Expr *CoawaitOp = UnresolvedLookupExpr::Create(
270  SemaRef.Context, /*NamingClass*/ nullptr, NestedNameSpecifierLoc(),
271  DeclarationNameInfo(OpName, Loc), /*RequiresADL*/ true, IsOverloaded,
272  Functions.begin(), Functions.end());
273  assert(CoawaitOp);
274  return CoawaitOp;
275 }
276 
277 /// Build a call to 'operator co_await' if there is a suitable operator for
278 /// the given expression.
280  Expr *E,
281  UnresolvedLookupExpr *Lookup) {
282  UnresolvedSet<16> Functions;
283  Functions.append(Lookup->decls_begin(), Lookup->decls_end());
284  return SemaRef.CreateOverloadedUnaryOp(Loc, UO_Coawait, Functions, E);
285 }
286 
288  SourceLocation Loc, Expr *E) {
289  ExprResult R = buildOperatorCoawaitLookupExpr(SemaRef, S, Loc);
290  if (R.isInvalid())
291  return ExprError();
292  return buildOperatorCoawaitCall(SemaRef, Loc, E,
293  cast<UnresolvedLookupExpr>(R.get()));
294 }
295 
297  MultiExprArg CallArgs) {
298  StringRef Name = S.Context.BuiltinInfo.getName(Id);
300  S.LookupName(R, S.TUScope, /*AllowBuiltinCreation=*/true);
301 
302  auto *BuiltInDecl = R.getAsSingle<FunctionDecl>();
303  assert(BuiltInDecl && "failed to find builtin declaration");
304 
305  ExprResult DeclRef =
306  S.BuildDeclRefExpr(BuiltInDecl, BuiltInDecl->getType(), VK_LValue, Loc);
307  assert(DeclRef.isUsable() && "Builtin reference cannot fail");
308 
309  ExprResult Call =
310  S.ActOnCallExpr(/*Scope=*/nullptr, DeclRef.get(), Loc, CallArgs, Loc);
311 
312  assert(!Call.isInvalid() && "Call to builtin cannot fail!");
313  return Call.get();
314 }
315 
317  SourceLocation Loc) {
318  QualType CoroHandleType = lookupCoroutineHandleType(S, PromiseType, Loc);
319  if (CoroHandleType.isNull())
320  return ExprError();
321 
322  DeclContext *LookupCtx = S.computeDeclContext(CoroHandleType);
323  LookupResult Found(S, &S.PP.getIdentifierTable().get("from_address"), Loc,
325  if (!S.LookupQualifiedName(Found, LookupCtx)) {
326  S.Diag(Loc, diag::err_coroutine_handle_missing_member)
327  << "from_address";
328  return ExprError();
329  }
330 
331  Expr *FramePtr =
332  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
333 
334  CXXScopeSpec SS;
335  ExprResult FromAddr =
336  S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
337  if (FromAddr.isInvalid())
338  return ExprError();
339 
340  return S.ActOnCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc);
341 }
342 
344  enum AwaitCallType { ACT_Ready, ACT_Suspend, ACT_Resume };
345  Expr *Results[3];
347  bool IsInvalid;
348 };
349 
351  StringRef Name, MultiExprArg Args) {
352  DeclarationNameInfo NameInfo(&S.PP.getIdentifierTable().get(Name), Loc);
353 
354  // FIXME: Fix BuildMemberReferenceExpr to take a const CXXScopeSpec&.
355  CXXScopeSpec SS;
357  Base, Base->getType(), Loc, /*IsPtr=*/false, SS,
358  SourceLocation(), nullptr, NameInfo, /*TemplateArgs=*/nullptr,
359  /*Scope=*/nullptr);
360  if (Result.isInvalid())
361  return ExprError();
362 
363  return S.ActOnCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr);
364 }
365 
366 /// Build calls to await_ready, await_suspend, and await_resume for a co_await
367 /// expression.
369  SourceLocation Loc, Expr *E) {
370  OpaqueValueExpr *Operand = new (S.Context)
371  OpaqueValueExpr(Loc, E->getType(), VK_LValue, E->getObjectKind(), E);
372 
373  // Assume invalid until we see otherwise.
374  ReadySuspendResumeResult Calls = {{}, Operand, /*IsInvalid=*/true};
375 
376  ExprResult CoroHandleRes = buildCoroutineHandle(S, CoroPromise->getType(), Loc);
377  if (CoroHandleRes.isInvalid())
378  return Calls;
379  Expr *CoroHandle = CoroHandleRes.get();
380 
381  const StringRef Funcs[] = {"await_ready", "await_suspend", "await_resume"};
382  MultiExprArg Args[] = {None, CoroHandle, None};
383  for (size_t I = 0, N = llvm::array_lengthof(Funcs); I != N; ++I) {
384  ExprResult Result = buildMemberCall(S, Operand, Loc, Funcs[I], Args[I]);
385  if (Result.isInvalid())
386  return Calls;
387  Calls.Results[I] = Result.get();
388  }
389 
390  // Assume the calls are valid; all further checking should make them invalid.
391  Calls.IsInvalid = false;
392 
394  CallExpr *AwaitReady = cast<CallExpr>(Calls.Results[ACT::ACT_Ready]);
395  if (!AwaitReady->getType()->isDependentType()) {
396  // [expr.await]p3 [...]
397  // — await-ready is the expression e.await_ready(), contextually converted
398  // to bool.
399  ExprResult Conv = S.PerformContextuallyConvertToBool(AwaitReady);
400  if (Conv.isInvalid()) {
401  S.Diag(AwaitReady->getDirectCallee()->getLocStart(),
402  diag::note_await_ready_no_bool_conversion);
403  S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
404  << AwaitReady->getDirectCallee() << E->getSourceRange();
405  Calls.IsInvalid = true;
406  }
407  Calls.Results[ACT::ACT_Ready] = Conv.get();
408  }
409  CallExpr *AwaitSuspend = cast<CallExpr>(Calls.Results[ACT::ACT_Suspend]);
410  if (!AwaitSuspend->getType()->isDependentType()) {
411  // [expr.await]p3 [...]
412  // - await-suspend is the expression e.await_suspend(h), which shall be
413  // a prvalue of type void or bool.
414  QualType RetType = AwaitSuspend->getCallReturnType(S.Context);
415  // non-class prvalues always have cv-unqualified types
416  QualType AdjRetType = RetType.getUnqualifiedType();
417  if (RetType->isReferenceType() ||
418  (AdjRetType != S.Context.BoolTy && AdjRetType != S.Context.VoidTy)) {
419  S.Diag(AwaitSuspend->getCalleeDecl()->getLocation(),
420  diag::err_await_suspend_invalid_return_type)
421  << RetType;
422  S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
423  << AwaitSuspend->getDirectCallee();
424  Calls.IsInvalid = true;
425  }
426  }
427 
428  return Calls;
429 }
430 
432  SourceLocation Loc, StringRef Name,
433  MultiExprArg Args) {
434 
435  // Form a reference to the promise.
436  ExprResult PromiseRef = S.BuildDeclRefExpr(
437  Promise, Promise->getType().getNonReferenceType(), VK_LValue, Loc);
438  if (PromiseRef.isInvalid())
439  return ExprError();
440 
441  return buildMemberCall(S, PromiseRef.get(), Loc, Name, Args);
442 }
443 
445  assert(isa<FunctionDecl>(CurContext) && "not in a function scope");
446  auto *FD = cast<FunctionDecl>(CurContext);
447  bool IsThisDependentType = [&] {
448  if (auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD))
449  return MD->isInstance() && MD->getThisType(Context)->isDependentType();
450  else
451  return false;
452  }();
453 
454  QualType T = FD->getType()->isDependentType() || IsThisDependentType
456  : lookupPromiseType(*this, FD, Loc);
457  if (T.isNull())
458  return nullptr;
459 
460  auto *VD = VarDecl::Create(Context, FD, FD->getLocation(), FD->getLocation(),
461  &PP.getIdentifierTable().get("__promise"), T,
463  CheckVariableDeclarationType(VD);
464  if (VD->isInvalidDecl())
465  return nullptr;
466  ActOnUninitializedDecl(VD);
467  FD->addDecl(VD);
468  assert(!VD->isInvalidDecl());
469  return VD;
470 }
471 
472 /// Check that this is a context in which a coroutine suspension can appear.
474  StringRef Keyword,
475  bool IsImplicit = false) {
476  if (!isValidCoroutineContext(S, Loc, Keyword))
477  return nullptr;
478 
479  assert(isa<FunctionDecl>(S.CurContext) && "not in a function scope");
480 
481  auto *ScopeInfo = S.getCurFunction();
482  assert(ScopeInfo && "missing function scope for function");
483 
484  if (ScopeInfo->FirstCoroutineStmtLoc.isInvalid() && !IsImplicit)
485  ScopeInfo->setFirstCoroutineStmt(Loc, Keyword);
486 
487  if (ScopeInfo->CoroutinePromise)
488  return ScopeInfo;
489 
490  ScopeInfo->CoroutinePromise = S.buildCoroutinePromise(Loc);
491  if (!ScopeInfo->CoroutinePromise)
492  return nullptr;
493 
494  return ScopeInfo;
495 }
496 
498  StringRef Keyword) {
499  if (!checkCoroutineContext(*this, KWLoc, Keyword))
500  return false;
501  auto *ScopeInfo = getCurFunction();
502  assert(ScopeInfo->CoroutinePromise);
503 
504  // If we have existing coroutine statements then we have already built
505  // the initial and final suspend points.
506  if (!ScopeInfo->NeedsCoroutineSuspends)
507  return true;
508 
509  ScopeInfo->setNeedsCoroutineSuspends(false);
510 
511  auto *Fn = cast<FunctionDecl>(CurContext);
512  SourceLocation Loc = Fn->getLocation();
513  // Build the initial suspend point
514  auto buildSuspends = [&](StringRef Name) mutable -> StmtResult {
515  ExprResult Suspend =
516  buildPromiseCall(*this, ScopeInfo->CoroutinePromise, Loc, Name, None);
517  if (Suspend.isInvalid())
518  return StmtError();
519  Suspend = buildOperatorCoawaitCall(*this, SC, Loc, Suspend.get());
520  if (Suspend.isInvalid())
521  return StmtError();
522  Suspend = BuildResolvedCoawaitExpr(Loc, Suspend.get(),
523  /*IsImplicit*/ true);
524  Suspend = ActOnFinishFullExpr(Suspend.get());
525  if (Suspend.isInvalid()) {
526  Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required)
527  << ((Name == "initial_suspend") ? 0 : 1);
528  Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword;
529  return StmtError();
530  }
531  return cast<Stmt>(Suspend.get());
532  };
533 
534  StmtResult InitSuspend = buildSuspends("initial_suspend");
535  if (InitSuspend.isInvalid())
536  return true;
537 
538  StmtResult FinalSuspend = buildSuspends("final_suspend");
539  if (FinalSuspend.isInvalid())
540  return true;
541 
542  ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
543 
544  return true;
545 }
546 
548  if (!ActOnCoroutineBodyStart(S, Loc, "co_await")) {
549  CorrectDelayedTyposInExpr(E);
550  return ExprError();
551  }
552 
553  if (E->getType()->isPlaceholderType()) {
554  ExprResult R = CheckPlaceholderExpr(E);
555  if (R.isInvalid()) return ExprError();
556  E = R.get();
557  }
558  ExprResult Lookup = buildOperatorCoawaitLookupExpr(*this, S, Loc);
559  if (Lookup.isInvalid())
560  return ExprError();
561  return BuildUnresolvedCoawaitExpr(Loc, E,
562  cast<UnresolvedLookupExpr>(Lookup.get()));
563 }
564 
566  UnresolvedLookupExpr *Lookup) {
567  auto *FSI = checkCoroutineContext(*this, Loc, "co_await");
568  if (!FSI)
569  return ExprError();
570 
571  if (E->getType()->isPlaceholderType()) {
572  ExprResult R = CheckPlaceholderExpr(E);
573  if (R.isInvalid())
574  return ExprError();
575  E = R.get();
576  }
577 
578  auto *Promise = FSI->CoroutinePromise;
579  if (Promise->getType()->isDependentType()) {
580  Expr *Res =
581  new (Context) DependentCoawaitExpr(Loc, Context.DependentTy, E, Lookup);
582  return Res;
583  }
584 
585  auto *RD = Promise->getType()->getAsCXXRecordDecl();
586  if (lookupMember(*this, "await_transform", RD, Loc)) {
587  ExprResult R = buildPromiseCall(*this, Promise, Loc, "await_transform", E);
588  if (R.isInvalid()) {
589  Diag(Loc,
590  diag::note_coroutine_promise_implicit_await_transform_required_here)
591  << E->getSourceRange();
592  return ExprError();
593  }
594  E = R.get();
595  }
596  ExprResult Awaitable = buildOperatorCoawaitCall(*this, Loc, E, Lookup);
597  if (Awaitable.isInvalid())
598  return ExprError();
599 
600  return BuildResolvedCoawaitExpr(Loc, Awaitable.get());
601 }
602 
604  bool IsImplicit) {
605  auto *Coroutine = checkCoroutineContext(*this, Loc, "co_await", IsImplicit);
606  if (!Coroutine)
607  return ExprError();
608 
609  if (E->getType()->isPlaceholderType()) {
610  ExprResult R = CheckPlaceholderExpr(E);
611  if (R.isInvalid()) return ExprError();
612  E = R.get();
613  }
614 
615  if (E->getType()->isDependentType()) {
616  Expr *Res = new (Context)
617  CoawaitExpr(Loc, Context.DependentTy, E, IsImplicit);
618  return Res;
619  }
620 
621  // If the expression is a temporary, materialize it as an lvalue so that we
622  // can use it multiple times.
623  if (E->getValueKind() == VK_RValue)
624  E = CreateMaterializeTemporaryExpr(E->getType(), E, true);
625 
626  // Build the await_ready, await_suspend, await_resume calls.
628  buildCoawaitCalls(*this, Coroutine->CoroutinePromise, Loc, E);
629  if (RSS.IsInvalid)
630  return ExprError();
631 
632  Expr *Res =
633  new (Context) CoawaitExpr(Loc, E, RSS.Results[0], RSS.Results[1],
634  RSS.Results[2], RSS.OpaqueValue, IsImplicit);
635 
636  return Res;
637 }
638 
640  if (!ActOnCoroutineBodyStart(S, Loc, "co_yield")) {
641  CorrectDelayedTyposInExpr(E);
642  return ExprError();
643  }
644 
645  // Build yield_value call.
646  ExprResult Awaitable = buildPromiseCall(
647  *this, getCurFunction()->CoroutinePromise, Loc, "yield_value", E);
648  if (Awaitable.isInvalid())
649  return ExprError();
650 
651  // Build 'operator co_await' call.
652  Awaitable = buildOperatorCoawaitCall(*this, S, Loc, Awaitable.get());
653  if (Awaitable.isInvalid())
654  return ExprError();
655 
656  return BuildCoyieldExpr(Loc, Awaitable.get());
657 }
659  auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield");
660  if (!Coroutine)
661  return ExprError();
662 
663  if (E->getType()->isPlaceholderType()) {
664  ExprResult R = CheckPlaceholderExpr(E);
665  if (R.isInvalid()) return ExprError();
666  E = R.get();
667  }
668 
669  if (E->getType()->isDependentType()) {
670  Expr *Res = new (Context) CoyieldExpr(Loc, Context.DependentTy, E);
671  return Res;
672  }
673 
674  // If the expression is a temporary, materialize it as an lvalue so that we
675  // can use it multiple times.
676  if (E->getValueKind() == VK_RValue)
677  E = CreateMaterializeTemporaryExpr(E->getType(), E, true);
678 
679  // Build the await_ready, await_suspend, await_resume calls.
681  buildCoawaitCalls(*this, Coroutine->CoroutinePromise, Loc, E);
682  if (RSS.IsInvalid)
683  return ExprError();
684 
685  Expr *Res =
686  new (Context) CoyieldExpr(Loc, E, RSS.Results[0], RSS.Results[1],
687  RSS.Results[2], RSS.OpaqueValue);
688 
689  return Res;
690 }
691 
693  if (!ActOnCoroutineBodyStart(S, Loc, "co_return")) {
694  CorrectDelayedTyposInExpr(E);
695  return StmtError();
696  }
697  return BuildCoreturnStmt(Loc, E);
698 }
699 
701  bool IsImplicit) {
702  auto *FSI = checkCoroutineContext(*this, Loc, "co_return", IsImplicit);
703  if (!FSI)
704  return StmtError();
705 
706  if (E && E->getType()->isPlaceholderType() &&
707  !E->getType()->isSpecificPlaceholderType(BuiltinType::Overload)) {
708  ExprResult R = CheckPlaceholderExpr(E);
709  if (R.isInvalid()) return StmtError();
710  E = R.get();
711  }
712 
713  // FIXME: If the operand is a reference to a variable that's about to go out
714  // of scope, we should treat the operand as an xvalue for this overload
715  // resolution.
716  VarDecl *Promise = FSI->CoroutinePromise;
717  ExprResult PC;
718  if (E && (isa<InitListExpr>(E) || !E->getType()->isVoidType())) {
719  PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
720  } else {
721  E = MakeFullDiscardedValueExpr(E).get();
722  PC = buildPromiseCall(*this, Promise, Loc, "return_void", None);
723  }
724  if (PC.isInvalid())
725  return StmtError();
726 
727  Expr *PCE = ActOnFinishFullExpr(PC.get()).get();
728 
729  Stmt *Res = new (Context) CoreturnStmt(Loc, E, PCE, IsImplicit);
730  return Res;
731 }
732 
733 /// Look up the std::nothrow object.
735  NamespaceDecl *Std = S.getStdNamespace();
736  assert(Std && "Should already be diagnosed");
737 
738  LookupResult Result(S, &S.PP.getIdentifierTable().get("nothrow"), Loc,
740  if (!S.LookupQualifiedName(Result, Std)) {
741  // FIXME: <experimental/coroutine> should have been included already.
742  // If we require it to include <new> then this diagnostic is no longer
743  // needed.
744  S.Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found);
745  return nullptr;
746  }
747 
748  auto *VD = Result.getAsSingle<VarDecl>();
749  if (!VD) {
750  Result.suppressDiagnostics();
751  // We found something weird. Complain about the first thing we found.
752  NamedDecl *Found = *Result.begin();
753  S.Diag(Found->getLocation(), diag::err_malformed_std_nothrow);
754  return nullptr;
755  }
756 
757  ExprResult DR = S.BuildDeclRefExpr(VD, VD->getType(), VK_LValue, Loc);
758  if (DR.isInvalid())
759  return nullptr;
760 
761  return DR.get();
762 }
763 
764 // Find an appropriate delete for the promise.
766  QualType PromiseType) {
767  FunctionDecl *OperatorDelete = nullptr;
768 
769  DeclarationName DeleteName =
771 
772  auto *PointeeRD = PromiseType->getAsCXXRecordDecl();
773  assert(PointeeRD && "PromiseType must be a CxxRecordDecl type");
774 
775  if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete))
776  return nullptr;
777 
778  if (!OperatorDelete) {
779  // Look for a global declaration.
780  const bool CanProvideSize = S.isCompleteType(Loc, PromiseType);
781  const bool Overaligned = false;
782  OperatorDelete = S.FindUsualDeallocationFunction(Loc, CanProvideSize,
783  Overaligned, DeleteName);
784  }
785  S.MarkFunctionReferenced(Loc, OperatorDelete);
786  return OperatorDelete;
787 }
788 
789 
791  FunctionScopeInfo *Fn = getCurFunction();
792  assert(Fn && Fn->isCoroutine() && "not a coroutine");
793  if (!Body) {
794  assert(FD->isInvalidDecl() &&
795  "a null body is only allowed for invalid declarations");
796  return;
797  }
798  // We have a function that uses coroutine keywords, but we failed to build
799  // the promise type.
800  if (!Fn->CoroutinePromise)
801  return FD->setInvalidDecl();
802 
803  if (isa<CoroutineBodyStmt>(Body)) {
804  // Nothing todo. the body is already a transformed coroutine body statement.
805  return;
806  }
807 
808  // Coroutines [stmt.return]p1:
809  // A return statement shall not appear in a coroutine.
810  if (Fn->FirstReturnLoc.isValid()) {
811  assert(Fn->FirstCoroutineStmtLoc.isValid() &&
812  "first coroutine location not set");
813  Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine);
814  Diag(Fn->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
816  }
817  CoroutineStmtBuilder Builder(*this, *FD, *Fn, Body);
818  if (Builder.isInvalid() || !Builder.buildStatements())
819  return FD->setInvalidDecl();
820 
821  // Build body for the coroutine wrapper statement.
822  Body = CoroutineBodyStmt::Create(Context, Builder);
823 }
824 
827  Stmt *Body)
828  : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()),
829  IsPromiseDependentType(
830  !Fn.CoroutinePromise ||
831  Fn.CoroutinePromise->getType()->isDependentType()) {
832  this->Body = Body;
833  if (!IsPromiseDependentType) {
834  PromiseRecordDecl = Fn.CoroutinePromise->getType()->getAsCXXRecordDecl();
835  assert(PromiseRecordDecl && "Type should have already been checked");
836  }
837  this->IsValid = makePromiseStmt() && makeInitialAndFinalSuspend();
838 }
839 
841  assert(this->IsValid && "coroutine already invalid");
842  this->IsValid = makeReturnObject() && makeParamMoves();
843  if (this->IsValid && !IsPromiseDependentType)
845  return this->IsValid;
846 }
847 
849  assert(this->IsValid && "coroutine already invalid");
850  assert(!this->IsPromiseDependentType &&
851  "coroutine cannot have a dependent promise type");
852  this->IsValid = makeOnException() && makeOnFallthrough() &&
853  makeGroDeclAndReturnStmt() && makeReturnOnAllocFailure() &&
854  makeNewAndDeleteExpr();
855  return this->IsValid;
856 }
857 
859  assert(this->IsValid && "coroutine already invalid");
860  assert(this->ParamMoves.empty() && "param moves already built");
861  return this->IsValid = makeParamMoves();
862 }
863 
864 bool CoroutineStmtBuilder::makePromiseStmt() {
865  // Form a declaration statement for the promise declaration, so that AST
866  // visitors can more easily find it.
867  StmtResult PromiseStmt =
869  if (PromiseStmt.isInvalid())
870  return false;
871 
872  this->Promise = PromiseStmt.get();
873  return true;
874 }
875 
876 bool CoroutineStmtBuilder::makeInitialAndFinalSuspend() {
878  return false;
879  this->InitialSuspend = cast<Expr>(Fn.CoroutineSuspends.first);
880  this->FinalSuspend = cast<Expr>(Fn.CoroutineSuspends.second);
881  return true;
882 }
883 
885  CXXRecordDecl *PromiseRecordDecl,
886  FunctionScopeInfo &Fn) {
887  auto Loc = E->getExprLoc();
888  if (auto *DeclRef = dyn_cast_or_null<DeclRefExpr>(E)) {
889  auto *Decl = DeclRef->getDecl();
890  if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(Decl)) {
891  if (Method->isStatic())
892  return true;
893  else
894  Loc = Decl->getLocation();
895  }
896  }
897 
898  S.Diag(
899  Loc,
900  diag::err_coroutine_promise_get_return_object_on_allocation_failure)
901  << PromiseRecordDecl;
902  S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
904  return false;
905 }
906 
907 bool CoroutineStmtBuilder::makeReturnOnAllocFailure() {
908  assert(!IsPromiseDependentType &&
909  "cannot make statement while the promise type is dependent");
910 
911  // [dcl.fct.def.coroutine]/8
912  // The unqualified-id get_return_object_on_allocation_failure is looked up in
913  // the scope of class P by class member access lookup (3.4.5). ...
914  // If an allocation function returns nullptr, ... the coroutine return value
915  // is obtained by a call to ... get_return_object_on_allocation_failure().
916 
917  DeclarationName DN =
918  S.PP.getIdentifierInfo("get_return_object_on_allocation_failure");
919  LookupResult Found(S, DN, Loc, Sema::LookupMemberName);
920  if (!S.LookupQualifiedName(Found, PromiseRecordDecl))
921  return true;
922 
923  CXXScopeSpec SS;
924  ExprResult DeclNameExpr =
925  S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false);
926  if (DeclNameExpr.isInvalid())
927  return false;
928 
929  if (!diagReturnOnAllocFailure(S, DeclNameExpr.get(), PromiseRecordDecl, Fn))
930  return false;
931 
932  ExprResult ReturnObjectOnAllocationFailure =
933  S.ActOnCallExpr(nullptr, DeclNameExpr.get(), Loc, {}, Loc);
934  if (ReturnObjectOnAllocationFailure.isInvalid())
935  return false;
936 
938  S.BuildReturnStmt(Loc, ReturnObjectOnAllocationFailure.get());
939  if (ReturnStmt.isInvalid()) {
940  S.Diag(Found.getFoundDecl()->getLocation(), diag::note_member_declared_here)
941  << DN;
942  S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
944  return false;
945  }
946 
947  this->ReturnStmtOnAllocFailure = ReturnStmt.get();
948  return true;
949 }
950 
951 bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
952  // Form and check allocation and deallocation calls.
953  assert(!IsPromiseDependentType &&
954  "cannot make statement while the promise type is dependent");
955  QualType PromiseType = Fn.CoroutinePromise->getType();
956 
957  if (S.RequireCompleteType(Loc, PromiseType, diag::err_incomplete_type))
958  return false;
959 
960  const bool RequiresNoThrowAlloc = ReturnStmtOnAllocFailure != nullptr;
961 
962  // FIXME: Add support for stateful allocators.
963 
964  FunctionDecl *OperatorNew = nullptr;
965  FunctionDecl *OperatorDelete = nullptr;
966  FunctionDecl *UnusedResult = nullptr;
967  bool PassAlignment = false;
968  SmallVector<Expr *, 1> PlacementArgs;
969 
971  /*UseGlobal*/ false, PromiseType,
972  /*isArray*/ false, PassAlignment, PlacementArgs,
973  OperatorNew, UnusedResult);
974 
975  bool IsGlobalOverload =
976  OperatorNew && !isa<CXXRecordDecl>(OperatorNew->getDeclContext());
977  // If we didn't find a class-local new declaration and non-throwing new
978  // was is required then we need to lookup the non-throwing global operator
979  // instead.
980  if (RequiresNoThrowAlloc && (!OperatorNew || IsGlobalOverload)) {
981  auto *StdNoThrow = buildStdNoThrowDeclRef(S, Loc);
982  if (!StdNoThrow)
983  return false;
984  PlacementArgs = {StdNoThrow};
985  OperatorNew = nullptr;
987  /*UseGlobal*/ true, PromiseType,
988  /*isArray*/ false, PassAlignment, PlacementArgs,
989  OperatorNew, UnusedResult);
990  }
991 
992  assert(OperatorNew && "expected definition of operator new to be found");
993 
994  if (RequiresNoThrowAlloc) {
995  const auto *FT = OperatorNew->getType()->getAs<FunctionProtoType>();
996  if (!FT->isNothrow(S.Context, /*ResultIfDependent*/ false)) {
997  S.Diag(OperatorNew->getLocation(),
998  diag::err_coroutine_promise_new_requires_nothrow)
999  << OperatorNew;
1000  S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
1001  << OperatorNew;
1002  return false;
1003  }
1004  }
1005 
1006  if ((OperatorDelete = findDeleteForPromise(S, Loc, PromiseType)) == nullptr)
1007  return false;
1008 
1009  Expr *FramePtr =
1010  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_frame, {});
1011 
1012  Expr *FrameSize =
1013  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_size, {});
1014 
1015  // Make new call.
1016 
1017  ExprResult NewRef =
1018  S.BuildDeclRefExpr(OperatorNew, OperatorNew->getType(), VK_LValue, Loc);
1019  if (NewRef.isInvalid())
1020  return false;
1021 
1022  SmallVector<Expr *, 2> NewArgs(1, FrameSize);
1023  for (auto Arg : PlacementArgs)
1024  NewArgs.push_back(Arg);
1025 
1026  ExprResult NewExpr =
1027  S.ActOnCallExpr(S.getCurScope(), NewRef.get(), Loc, NewArgs, Loc);
1028  NewExpr = S.ActOnFinishFullExpr(NewExpr.get());
1029  if (NewExpr.isInvalid())
1030  return false;
1031 
1032  // Make delete call.
1033 
1034  QualType OpDeleteQualType = OperatorDelete->getType();
1035 
1036  ExprResult DeleteRef =
1037  S.BuildDeclRefExpr(OperatorDelete, OpDeleteQualType, VK_LValue, Loc);
1038  if (DeleteRef.isInvalid())
1039  return false;
1040 
1041  Expr *CoroFree =
1042  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_free, {FramePtr});
1043 
1044  SmallVector<Expr *, 2> DeleteArgs{CoroFree};
1045 
1046  // Check if we need to pass the size.
1047  const auto *OpDeleteType =
1048  OpDeleteQualType.getTypePtr()->getAs<FunctionProtoType>();
1049  if (OpDeleteType->getNumParams() > 1)
1050  DeleteArgs.push_back(FrameSize);
1051 
1052  ExprResult DeleteExpr =
1053  S.ActOnCallExpr(S.getCurScope(), DeleteRef.get(), Loc, DeleteArgs, Loc);
1054  DeleteExpr = S.ActOnFinishFullExpr(DeleteExpr.get());
1055  if (DeleteExpr.isInvalid())
1056  return false;
1057 
1058  this->Allocate = NewExpr.get();
1059  this->Deallocate = DeleteExpr.get();
1060 
1061  return true;
1062 }
1063 
1064 bool CoroutineStmtBuilder::makeOnFallthrough() {
1065  assert(!IsPromiseDependentType &&
1066  "cannot make statement while the promise type is dependent");
1067 
1068  // [dcl.fct.def.coroutine]/4
1069  // The unqualified-ids 'return_void' and 'return_value' are looked up in
1070  // the scope of class P. If both are found, the program is ill-formed.
1071  bool HasRVoid, HasRValue;
1072  LookupResult LRVoid =
1073  lookupMember(S, "return_void", PromiseRecordDecl, Loc, HasRVoid);
1074  LookupResult LRValue =
1075  lookupMember(S, "return_value", PromiseRecordDecl, Loc, HasRValue);
1076 
1077  StmtResult Fallthrough;
1078  if (HasRVoid && HasRValue) {
1079  // FIXME Improve this diagnostic
1080  S.Diag(FD.getLocation(),
1081  diag::err_coroutine_promise_incompatible_return_functions)
1082  << PromiseRecordDecl;
1083  S.Diag(LRVoid.getRepresentativeDecl()->getLocation(),
1084  diag::note_member_first_declared_here)
1085  << LRVoid.getLookupName();
1086  S.Diag(LRValue.getRepresentativeDecl()->getLocation(),
1087  diag::note_member_first_declared_here)
1088  << LRValue.getLookupName();
1089  return false;
1090  } else if (!HasRVoid && !HasRValue) {
1091  // FIXME: The PDTS currently specifies this case as UB, not ill-formed.
1092  // However we still diagnose this as an error since until the PDTS is fixed.
1093  S.Diag(FD.getLocation(),
1094  diag::err_coroutine_promise_requires_return_function)
1095  << PromiseRecordDecl;
1096  S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here)
1097  << PromiseRecordDecl;
1098  return false;
1099  } else if (HasRVoid) {
1100  // If the unqualified-id return_void is found, flowing off the end of a
1101  // coroutine is equivalent to a co_return with no operand. Otherwise,
1102  // flowing off the end of a coroutine results in undefined behavior.
1103  Fallthrough = S.BuildCoreturnStmt(FD.getLocation(), nullptr,
1104  /*IsImplicit*/false);
1105  Fallthrough = S.ActOnFinishFullStmt(Fallthrough.get());
1106  if (Fallthrough.isInvalid())
1107  return false;
1108  }
1109 
1110  this->OnFallthrough = Fallthrough.get();
1111  return true;
1112 }
1113 
1114 bool CoroutineStmtBuilder::makeOnException() {
1115  // Try to form 'p.unhandled_exception();'
1116  assert(!IsPromiseDependentType &&
1117  "cannot make statement while the promise type is dependent");
1118 
1119  const bool RequireUnhandledException = S.getLangOpts().CXXExceptions;
1120 
1121  if (!lookupMember(S, "unhandled_exception", PromiseRecordDecl, Loc)) {
1122  auto DiagID =
1123  RequireUnhandledException
1124  ? diag::err_coroutine_promise_unhandled_exception_required
1125  : diag::
1126  warn_coroutine_promise_unhandled_exception_required_with_exceptions;
1127  S.Diag(Loc, DiagID) << PromiseRecordDecl;
1128  S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here)
1129  << PromiseRecordDecl;
1130  return !RequireUnhandledException;
1131  }
1132 
1133  // If exceptions are disabled, don't try to build OnException.
1134  if (!S.getLangOpts().CXXExceptions)
1135  return true;
1136 
1137  ExprResult UnhandledException = buildPromiseCall(S, Fn.CoroutinePromise, Loc,
1138  "unhandled_exception", None);
1139  UnhandledException = S.ActOnFinishFullExpr(UnhandledException.get(), Loc);
1140  if (UnhandledException.isInvalid())
1141  return false;
1142 
1143  // Since the body of the coroutine will be wrapped in try-catch, it will
1144  // be incompatible with SEH __try if present in a function.
1145  if (!S.getLangOpts().Borland && Fn.FirstSEHTryLoc.isValid()) {
1146  S.Diag(Fn.FirstSEHTryLoc, diag::err_seh_in_a_coroutine_with_cxx_exceptions);
1147  S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
1149  return false;
1150  }
1151 
1152  this->OnException = UnhandledException.get();
1153  return true;
1154 }
1155 
1156 bool CoroutineStmtBuilder::makeReturnObject() {
1157  // Build implicit 'p.get_return_object()' expression and form initialization
1158  // of return type from it.
1159  ExprResult ReturnObject =
1160  buildPromiseCall(S, Fn.CoroutinePromise, Loc, "get_return_object", None);
1161  if (ReturnObject.isInvalid())
1162  return false;
1163 
1164  this->ReturnValue = ReturnObject.get();
1165  return true;
1166 }
1167 
1169  if (auto *MbrRef = dyn_cast<CXXMemberCallExpr>(E)) {
1170  auto *MethodDecl = MbrRef->getMethodDecl();
1171  S.Diag(MethodDecl->getLocation(), diag::note_member_declared_here)
1172  << MethodDecl;
1173  }
1174  S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here)
1176 }
1177 
1178 bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() {
1179  assert(!IsPromiseDependentType &&
1180  "cannot make statement while the promise type is dependent");
1181  assert(this->ReturnValue && "ReturnValue must be already formed");
1182 
1183  QualType const GroType = this->ReturnValue->getType();
1184  assert(!GroType->isDependentType() &&
1185  "get_return_object type must no longer be dependent");
1186 
1187  QualType const FnRetType = FD.getReturnType();
1188  assert(!FnRetType->isDependentType() &&
1189  "get_return_object type must no longer be dependent");
1190 
1191  if (FnRetType->isVoidType()) {
1192  ExprResult Res = S.ActOnFinishFullExpr(this->ReturnValue, Loc);
1193  if (Res.isInvalid())
1194  return false;
1195 
1196  this->ResultDecl = Res.get();
1197  return true;
1198  }
1199 
1200  if (GroType->isVoidType()) {
1201  // Trigger a nice error message.
1202  InitializedEntity Entity =
1203  InitializedEntity::InitializeResult(Loc, FnRetType, false);
1204  S.PerformMoveOrCopyInitialization(Entity, nullptr, FnRetType, ReturnValue);
1206  return false;
1207  }
1208 
1209  auto *GroDecl = VarDecl::Create(
1210  S.Context, &FD, FD.getLocation(), FD.getLocation(),
1211  &S.PP.getIdentifierTable().get("__coro_gro"), GroType,
1212  S.Context.getTrivialTypeSourceInfo(GroType, Loc), SC_None);
1213 
1214  S.CheckVariableDeclarationType(GroDecl);
1215  if (GroDecl->isInvalidDecl())
1216  return false;
1217 
1219  ExprResult Res = S.PerformMoveOrCopyInitialization(Entity, nullptr, GroType,
1220  this->ReturnValue);
1221  if (Res.isInvalid())
1222  return false;
1223 
1224  Res = S.ActOnFinishFullExpr(Res.get());
1225  if (Res.isInvalid())
1226  return false;
1227 
1228  if (GroType == FnRetType) {
1229  GroDecl->setNRVOVariable(true);
1230  }
1231 
1232  S.AddInitializerToDecl(GroDecl, Res.get(),
1233  /*DirectInit=*/false);
1234 
1235  S.FinalizeDeclaration(GroDecl);
1236 
1237  // Form a declaration statement for the return declaration, so that AST
1238  // visitors can more easily find it.
1239  StmtResult GroDeclStmt =
1240  S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(GroDecl), Loc, Loc);
1241  if (GroDeclStmt.isInvalid())
1242  return false;
1243 
1244  this->ResultDecl = GroDeclStmt.get();
1245 
1246  ExprResult declRef = S.BuildDeclRefExpr(GroDecl, GroType, VK_LValue, Loc);
1247  if (declRef.isInvalid())
1248  return false;
1249 
1250  StmtResult ReturnStmt = S.BuildReturnStmt(Loc, declRef.get());
1251  if (ReturnStmt.isInvalid()) {
1253  return false;
1254  }
1255 
1256  this->ReturnStmt = ReturnStmt.get();
1257  return true;
1258 }
1259 
1260 // Create a static_cast<T&&>(expr).
1262  if (T.isNull())
1263  T = E->getType();
1264  QualType TargetType = S.BuildReferenceType(
1265  T, /*SpelledAsLValue*/ false, SourceLocation(), DeclarationName());
1266  SourceLocation ExprLoc = E->getLocStart();
1267  TypeSourceInfo *TargetLoc =
1268  S.Context.getTrivialTypeSourceInfo(TargetType, ExprLoc);
1269 
1270  return S
1271  .BuildCXXNamedCast(ExprLoc, tok::kw_static_cast, TargetLoc, E,
1272  SourceRange(ExprLoc, ExprLoc), E->getSourceRange())
1273  .get();
1274 }
1275 
1276 
1277 /// \brief Build a variable declaration for move parameter.
1279  IdentifierInfo *II) {
1280  TypeSourceInfo *TInfo = S.Context.getTrivialTypeSourceInfo(Type, Loc);
1281  VarDecl *Decl =
1282  VarDecl::Create(S.Context, S.CurContext, Loc, Loc, II, Type, TInfo, SC_None);
1283  Decl->setImplicit();
1284  return Decl;
1285 }
1286 
1287 bool CoroutineStmtBuilder::makeParamMoves() {
1288  for (auto *paramDecl : FD.parameters()) {
1289  auto Ty = paramDecl->getType();
1290  if (Ty->isDependentType())
1291  continue;
1292 
1293  // No need to copy scalars, llvm will take care of them.
1294  if (Ty->getAsCXXRecordDecl()) {
1295  ExprResult ParamRef =
1296  S.BuildDeclRefExpr(paramDecl, paramDecl->getType(),
1297  ExprValueKind::VK_LValue, Loc); // FIXME: scope?
1298  if (ParamRef.isInvalid())
1299  return false;
1300 
1301  Expr *RCast = castForMoving(S, ParamRef.get());
1302 
1303  auto D = buildVarDecl(S, Loc, Ty, paramDecl->getIdentifier());
1304  S.AddInitializerToDecl(D, RCast, /*DirectInit=*/true);
1305 
1306  // Convert decl to a statement.
1308  if (Stmt.isInvalid())
1309  return false;
1310 
1311  ParamMovesVector.push_back(Stmt.get());
1312  }
1313  }
1314 
1315  // Convert to ArrayRef in CtorArgs structure that builder inherits from.
1316  ParamMoves = ParamMovesVector;
1317  return true;
1318 }
1319 
1322  if (!Res)
1323  return StmtError();
1324  return Res;
1325 }
NamespaceDecl * lookupStdExperimentalNamespace()
static Expr * buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc)
Look up the std::nothrow object.
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType) const
static ExprResult buildMemberCall(Sema &S, Expr *Base, SourceLocation Loc, StringRef Name, MultiExprArg Args)
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:409
void setImplicit(bool I=true)
Definition: DeclBase.h:538
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
Definition: Decl.h:1618
Represents a 'co_await' expression while the type of the promise is dependent.
Definition: ExprCXX.h:4232
bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, DeclarationName Name, FunctionDecl *&Operator, bool Diagnose=true)
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:10411
ExprResult PerformContextuallyConvertToBool(Expr *From)
PerformContextuallyConvertToBool - Perform a contextual conversion of the expression From to bool (C+...
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2224
A (possibly-)qualified type.
Definition: Type.h:616
bool isInvalid() const
Definition: Ownership.h:159
static VarDecl * buildVarDecl(Sema &S, SourceLocation Loc, QualType Type, IdentifierInfo *II)
Build a variable declaration for move parameter.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2954
const LangOptions & getLangOpts() const
Definition: Sema.h:1166
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
static Expr * castForMoving(Sema &S, Expr *E, QualType T=QualType())
static UnresolvedLookupExpr * Create(const ASTContext &C, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool ADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.h:2703
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition: StmtCXX.h:432
Stmt - This represents one statement.
Definition: Stmt.h:60
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:510
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type...
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:974
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1243
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:81
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:2655
Scope * TUScope
Translation Unit Scope - useful to Objective-C actions that need to lookup file scope declarations in...
Definition: Sema.h:784
PtrTy get() const
Definition: Ownership.h:163
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
The base class of the type hierarchy.
Definition: Type.h:1303
OpaqueValueExpr * OpaqueValue
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:461
A container of type source information.
Definition: Decl.h:62
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2, C99 6.9p3)
Definition: SemaExpr.cpp:13482
std::pair< Stmt *, Stmt * > CoroutineSuspends
The initial and final coroutine suspend points.
Definition: ScopeInfo.h:176
Retains information about a function, method, or block that is currently being parsed.
Definition: ScopeInfo.h:82
VarDecl - An instance of this class is created to represent a variable declaration or definition...
Definition: Decl.h:758
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
static bool diagReturnOnAllocFailure(Sema &S, Expr *E, CXXRecordDecl *PromiseRecordDecl, FunctionScopeInfo &Fn)
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isVoidType() const
Definition: Type.h:5906
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Definition: SemaExpr.cpp:5110
One of these records is kept for each identifier that is lexed.
static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise, SourceLocation Loc, Expr *E)
Build calls to await_ready, await_suspend, and await_resume for a co_await expression.
A C++ nested-name-specifier augmented with source location information.
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:3343
bool isReferenceType() const
Definition: Type.h:5721
bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, StringRef Keyword)
QualType getReturnType() const
Definition: Decl.h:2106
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
Definition: SemaDecl.cpp:54
static FunctionDecl * findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseType)
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input)
Create a unary operation that may resolve to an overloaded operator.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1295
IdentifierTable & Idents
Definition: ASTContext.h:513
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
Definition: ScopeInfo.h:158
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:106
bool isCompleteType(SourceLocation Loc, QualType T)
Definition: Sema.h:1585
Represents the results of name lookup.
Definition: Lookup.h:32
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:5893
static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression...
A convenient class for passing around template argument information.
Definition: TemplateBase.h:524
QualType getReturnType() const
Definition: Type.h:3065
StmtResult StmtError()
Definition: Ownership.h:269
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2642
static ExprResult buildPromiseCall(Sema &S, VarDecl *Promise, SourceLocation Loc, StringRef Name, MultiExprArg Args)
static QualType lookupPromiseType(Sema &S, const FunctionDecl *FD, SourceLocation KwLoc)
Look up the std::coroutine_traits<...>::promise_type for the given function type. ...
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, bool UseGlobal, QualType AllocType, bool IsArray, bool &PassAlignment, MultiExprArg PlaceArgs, FunctionDecl *&OperatorNew, FunctionDecl *&OperatorDelete)
FindAllocationFunctions - Finds the overloads of operator new and delete that are appropriate for the...
StringRef getFirstCoroutineStmtKeyword() const
Definition: ScopeInfo.h:403
void append(iterator I, iterator E)
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
void CheckVariableDeclarationType(VarDecl *NewVD)
Definition: SemaDecl.cpp:7221
Preprocessor & PP
Definition: Sema.h:304
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Definition: Decl.cpp:1858
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:2962
detail::InMemoryDirectory::const_iterator I
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:2721
QualType getType() const
Definition: Decl.h:589
const UnresolvedSetImpl & asUnresolvedSet() const
Definition: Lookup.h:317
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5...
Definition: Sema.h:7357
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:269
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:72
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3129
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp)
Definition: SemaStmt.cpp:3302
StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E)
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:516
ASTContext * Context
Expr - This represents one expression.
Definition: Expr.h:105
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:249
const char * getName(unsigned ID) const
Return the identifier name for the specified builtin, e.g.
Definition: Builtins.h:83
decls_iterator decls_end() const
Definition: ExprCXX.h:2557
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs)
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
Definition: DeclBase.cpp:111
Defines the clang::Preprocessor interface.
DeclContext * getDeclContext()
Definition: DeclBase.h:416
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition: SemaCast.cpp:240
static bool IsOverloaded(const UnresolvedSetImpl &Functions)
Represents a C++ template name within the type system.
Definition: TemplateName.h:176
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:7107
static bool isValidCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword)
bool buildStatements()
Build the coroutine body statements, including the "promise dependent" statements when the promise ty...
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1797
static FunctionScopeInfo * checkCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword, bool IsImplicit=false)
Check that this is a context in which a coroutine suspension can appear.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
Definition: Stmt.h:1392
static Expr * buildBuiltinCall(Sema &S, SourceLocation Loc, Builtin::ID Id, MultiExprArg CallArgs)
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
Definition: ScopeInfo.h:173
ExprResult ActOnFinishFullExpr(Expr *Expr)
Definition: Sema.h:5184
bool isAmbiguous() const
Definition: Lookup.h:287
decls_iterator decls_begin() const
Definition: ExprCXX.h:2556
static CoroutineBodyStmt * Create(const ASTContext &C, CtorArgs const &Args)
Definition: StmtCXX.cpp:90
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
Definition: Expr.h:865
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5489
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:3458
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
Definition: SemaDecl.cpp:11249
bool isValid() const
Return true if this is a valid SourceLocation object.
FunctionDecl * FindUsualDeallocationFunction(SourceLocation StartLoc, bool CanProvideSize, bool Overaligned, DeclarationName Name)
const std::string ID
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:733
static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType, SourceLocation Loc)
Look up the std::experimental::coroutine_handle<PromiseType>.
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1903
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2066
ArrayRef< Stmt * > ParamMoves
Definition: StmtCXX.h:342
CanQualType VoidTy
Definition: ASTContext.h:963
SourceLocation FirstCoroutineStmtLoc
First coroutine statement in the current function.
Definition: ScopeInfo.h:149
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:6105
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
Definition: SemaType.cpp:1912
sema::FunctionScopeInfo * getCurFunction() const
Definition: Sema.h:1293
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1264
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:564
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:216
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1307
QualType getType() const
Definition: Expr.h:127
Represents a template argument.
Definition: TemplateBase.h:40
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1215
StringRef Name
Definition: USRFinder.cpp:123
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
Definition: Expr.cpp:1216
bool isInvalidDecl() const
Definition: DeclBase.h:532
CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, sema::FunctionScopeInfo &Fn, Stmt *Body)
Construct a CoroutineStmtBuilder and initialize the promise statement and initial/final suspends from...
Represents a 'co_yield' expression.
Definition: ExprCXX.h:4276
DeclarationName - The name of a declaration.
A set of unresolved declarations.
SourceLocation getLocStart() const LLVM_READONLY
Definition: Decl.h:683
detail::InMemoryDirectory::const_iterator E
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, UnresolvedLookupExpr *Lookup)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
Definition: SemaDecl.cpp:10239
static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType, SourceLocation Loc)
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
Definition: ScopeInfo.h:152
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:5662
Decl * getCalleeDecl()
Definition: Expr.cpp:1220
StmtResult ActOnFinishFullStmt(Stmt *Stmt)
Represents the body of a coroutine.
Definition: StmtCXX.h:299
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:428
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:6042
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
CanQualType DependentTy
Definition: ASTContext.h:979
Represents a 'co_await' expression.
Definition: ExprCXX.h:4199
static ExprResult buildOperatorCoawaitLookupExpr(Sema &SemaRef, Scope *S, SourceLocation Loc)
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:253
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1548
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E)
bool isUsable() const
Definition: Ownership.h:160
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity, const VarDecl *NRVOCandidate, QualType ResultType, Expr *Value, bool AllowNRVO=true)
Perform the initialization of a potentially-movable value, which is the result of return value...
Definition: SemaStmt.cpp:2897
ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:1639
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:5569
Represents a C++ struct/union/class.
Definition: DeclCXX.h:267
BoundNodesTreeBuilder *const Builder
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Definition: Type.h:5880
Builtin::Context & BuiltinInfo
Definition: ASTContext.h:515
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:317
Declaration of a class template.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:245
bool hasInvalidCoroutineSuspends() const
Definition: ScopeInfo.h:421
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2206
ExprResult ExprError()
Definition: Ownership.h:268
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:402
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body)
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:568
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
bool buildDependentStatements()
Build the coroutine body statements that require a non-dependent promise type in order to construct...
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:110
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
Definition: DeclBase.h:407
ASTContext & Context
Definition: Sema.h:305
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
CanQualType BoolTy
Definition: ASTContext.h:964
No keyword precedes the qualified type name.
Definition: Type.h:4518
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:683
Describes an entity that is being initialized.
Look up of an operator name (e.g., operator+) for use with operator overloading.
Definition: Sema.h:2966
bool buildParameterMoves()
Build just parameter moves. To use for rebuilding in TreeTransform.
NamespaceDecl * getStdNamespace() const
SourceLocation getLocStart() const LLVM_READONLY
Definition: Stmt.cpp:257
const NamedDecl * Result
Definition: USRFinder.cpp:70
static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD, SourceLocation Loc, bool &Res)
VarDecl * buildCoroutinePromise(SourceLocation Loc)
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
getCXXOperatorName - Get the name of the overloadable C++ operator corresponding to Op...
static void noteMemberDeclaredHere(Sema &S, Expr *E, FunctionScopeInfo &Fn)