21 using namespace clang;
31 S.
Diag(Loc, diag::err_implied_std_coroutine_traits_not_found);
38 S.
Diag(Loc, diag::err_implied_std_coroutine_traits_not_found);
44 Result.suppressDiagnostics();
47 S.
Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
68 diag::err_coroutine_traits_missing_specialization))
72 assert(RD &&
"specialization of class template is not a class?");
78 auto *Promise = R.getAsSingle<
TypeDecl>();
80 S.
Diag(Loc, diag::err_implied_std_coroutine_traits_promise_type_not_found)
94 S.
Diag(Loc, diag::err_implied_std_coroutine_traits_promise_type_not_class)
107 S.
Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
116 ? diag::err_coroutine_objc_method
117 : diag::err_coroutine_outside_function) << Keyword;
118 }
else if (isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD)) {
124 S.
Diag(Loc, diag::err_coroutine_ctor_dtor)
125 << isa<CXXDestructorDecl>(FD) << Keyword;
126 }
else if (FD->isConstexpr()) {
127 S.
Diag(Loc, diag::err_coroutine_constexpr) << Keyword;
128 }
else if (FD->isVariadic()) {
129 S.
Diag(Loc, diag::err_coroutine_varargs) << Keyword;
132 assert(ScopeInfo &&
"missing function scope for function");
135 if (!ScopeInfo->CoroutinePromise) {
145 ScopeInfo->CoroutinePromise =
150 if (!ScopeInfo->CoroutinePromise->isInvalidDecl())
183 Base, Base->
getType(), Loc,
false, SS,
199 const StringRef Funcs[] = {
"await_ready",
"await_suspend",
"await_resume"};
200 for (
size_t I = 0, N = llvm::array_lengthof(Funcs);
I != N; ++
I) {
225 return BuildCoawaitExpr(Loc, Awaitable.
get());
240 Coroutine->CoroutineStmts.push_back(Res);
247 E = CreateMaterializeTemporaryExpr(E->
getType(),
E,
true);
256 Coroutine->CoroutineStmts.push_back(Res);
268 Promise, Promise->getType().getNonReferenceType(),
VK_LValue, Loc);
292 return BuildCoyieldExpr(Loc, Awaitable.
get());
307 Coroutine->CoroutineStmts.push_back(Res);
314 E = CreateMaterializeTemporaryExpr(E->
getType(),
E,
true);
323 Coroutine->CoroutineStmts.push_back(Res);
328 return BuildCoreturnStmt(Loc, E);
349 E = MakeFullDiscardedValueExpr(E).get();
355 Expr *PCE = ActOnFinishFullExpr(PC.
get()).
get();
358 Coroutine->CoroutineStmts.push_back(Res);
371 Diag(First->getLocStart(), diag::note_declared_coroutine_here)
372 << (isa<CoawaitExpr>(First) ? 0 :
373 isa<CoyieldExpr>(First) ? 1 : 2);
376 bool AnyCoawaits =
false;
377 bool AnyCoyields =
false;
379 AnyCoawaits |= isa<CoawaitExpr>(CoroutineStmt);
380 AnyCoyields |= isa<CoyieldExpr>(CoroutineStmt);
383 if (!AnyCoawaits && !AnyCoyields)
385 diag::ext_coroutine_without_co_await_co_yield);
394 return FD->setInvalidDecl();
401 InitialSuspend = BuildCoawaitExpr(Loc, InitialSuspend.
get());
402 InitialSuspend = ActOnFinishFullExpr(InitialSuspend.
get());
404 return FD->setInvalidDecl();
411 FinalSuspend = BuildCoawaitExpr(Loc, FinalSuspend.
get());
412 FinalSuspend = ActOnFinishFullExpr(FinalSuspend.
get());
414 return FD->setInvalidDecl();
426 return FD->setInvalidDecl();
431 ReturnObject = PerformMoveOrCopyInitialization(Entity,
nullptr, RetType,
434 return FD->setInvalidDecl();
436 ReturnObject = ActOnFinishFullExpr(ReturnObject.
get(), Loc);
438 return FD->setInvalidDecl();
445 Body, PromiseStmt.
get(), InitialSuspend.
get(), FinalSuspend.
get(),
447 ReturnObject.
get(), ParamMoves);
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType) const
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
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.
A (possibly-)qualified type.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Represents a 'co_return' statement in the C++ Coroutines TS.
ExprResult BuildCoawaitExpr(SourceLocation KwLoc, Expr *E)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
NamespaceDecl - Represent a C++ namespace.
Retains information about a function, method, or block that is currently being parsed.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
StmtResult ActOnCoreturnStmt(SourceLocation KwLoc, Expr *E)
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Defines the clang::Expr interface and subclasses for C++ expressions.
void ActOnUninitializedDecl(Decl *dcl, bool TypeMayContainAuto)
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.
static FunctionScopeInfo * checkCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword)
Check that this is a context in which a coroutine suspension can appear.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
ArrayRef< QualType > getParamTypes() const
QualType getReturnType() const
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.
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
Represents the results of name lookup.
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
A convenient class for passing around template argument information.
QualType getReturnType() const
TypeDecl - Represents a declaration of a type.
Scope - A scope is a transient data structure that is used while parsing the program.
Represents a C++ nested-name-specifier or a global scope specifier.
void CheckVariableDeclarationType(VarDecl *NewVD)
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
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)
detail::InMemoryDirectory::const_iterator I
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5...
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
Sema - This implements semantic analysis and AST building for C.
Represents a prototype with parameter type info, e.g.
Expr - This represents one expression.
static QualType lookupPromiseType(Sema &S, const FunctionProtoType *FnType, SourceLocation Loc)
Look up the std::coroutine_traits<...>::promise_type for the given function type. ...
Defines the clang::Preprocessor interface.
Represents a C++ template name within the type system.
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
The result type of a method or function.
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
static ExprResult buildMemberCall(Sema &S, Expr *Base, SourceLocation Loc, StringRef Name, MutableArrayRef< Expr * > Args)
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
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.
SmallVector< Stmt *, 4 > CoroutineStmts
The list of coroutine control flow constructs (co_await, co_yield, co_return) that occur within the f...
bool isValid() const
Return true if this is a valid SourceLocation object.
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()
sema::FunctionScopeInfo * getCurFunction() const
void addArgument(const TemplateArgumentLoc &Loc)
Represents a template argument.
static ExprResult buildPromiseCall(Sema &S, FunctionScopeInfo *Coroutine, SourceLocation Loc, StringRef Name, MutableArrayRef< Expr * > Args)
Represents a 'co_yield' expression.
A set of unresolved declarations.
detail::InMemoryDirectory::const_iterator E
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, QualType T1, QualType T2, UnresolvedSetImpl &Functions)
Represents the body of a coroutine.
Location wrapper for a TemplateArgument.
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
Represents a 'co_await' expression.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E)
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Represents a C++ struct/union/class.
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Declaration of a class template.
static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S, SourceLocation Loc, Expr *E)
Build a call to 'operator co_await' if there is a suitable operator for the given expression...
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E)
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body)
An l-value expression is a reference to an object with independent storage.
NamedDecl - This represents a decl with a name.
No keyword precedes the qualified type name.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Describes an entity that is being initialized.
NamespaceDecl * getStdNamespace() const
static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, SourceLocation Loc, Expr *E)
Build calls to await_ready, await_suspend, and await_resume for a co_await expression.