27#include "llvm/ADT/SmallSet.h"
72 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
73 if (MD->isInstance()) {
97 diag::err_coroutine_type_missing_specialization))
101 assert(RD &&
"specialization of class template is not a class?");
110 diag::err_implied_std_coroutine_traits_promise_type_not_found)
117 auto buildElaboratedType = [&]() {
126 diag::err_implied_std_coroutine_traits_promise_type_not_class)
127 << buildElaboratedType();
131 diag::err_coroutine_promise_type_incomplete))
144 assert(CoroNamespace &&
"Should already be diagnosed");
149 S.
Diag(Loc, diag::err_implied_coroutine_type_not_found)
150 <<
"std::coroutine_handle";
156 Result.suppressDiagnostics();
159 S.
Diag(Found->
getLocation(), diag::err_malformed_std_coroutine_handle);
172 if (CoroHandleType.
isNull())
175 diag::err_coroutine_type_missing_specialization))
178 return CoroHandleType;
189 auto *FD = dyn_cast<FunctionDecl>(S.
CurContext);
192 ? diag::err_coroutine_objc_method
193 : diag::err_coroutine_outside_function) << Keyword;
199 enum InvalidFuncDiag {
208 bool Diagnosed =
false;
209 auto DiagInvalid = [&](InvalidFuncDiag ID) {
210 S.
Diag(Loc, diag::err_coroutine_invalid_func_context) << ID << Keyword;
217 auto *MD = dyn_cast<CXXMethodDecl>(FD);
219 if (MD && isa<CXXConstructorDecl>(MD))
220 return DiagInvalid(DiagCtor);
222 else if (MD && isa<CXXDestructorDecl>(MD))
223 return DiagInvalid(DiagDtor);
225 else if (FD->isMain())
226 return DiagInvalid(DiagMain);
232 if (FD->isConstexpr())
233 DiagInvalid(FD->isConsteval() ? DiagConsteval : DiagConstexpr);
236 if (FD->getReturnType()->isUndeducedType())
237 DiagInvalid(DiagAutoRet);
241 if (FD->isVariadic())
242 DiagInvalid(DiagVarargs);
262 cast<UnresolvedLookupExpr>(R.
get()));
268 if (CoroHandleType.
isNull())
275 S.
Diag(Loc, diag::err_coroutine_handle_missing_member)
306 Base,
Base->getType(), Loc,
false, SS,
313 if (
auto *TE = dyn_cast<TypoExpr>(
Result.get())) {
315 S.
Diag(Loc, diag::err_no_member)
316 << NameInfo.
getName() <<
Base->getType()->getAsCXXRecordDecl()
317 <<
Base->getSourceRange();
344 Expr *JustAddress = AddressExpr.
get();
348 S.
Diag(cast<CallExpr>(JustAddress)->getCalleeDecl()->getLocation(),
349 diag::warn_coroutine_handle_address_invalid_return_type)
385 auto BuildSubExpr = [&](ACT CallType, StringRef Func,
396 CallExpr *AwaitReady = cast_or_null<CallExpr>(
397 BuildSubExpr(ACT::ACT_Ready,
"await_ready", std::nullopt));
407 diag::note_await_ready_no_bool_conversion);
408 S.
Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
421 Expr *CoroHandle = CoroHandleRes.
get();
422 CallExpr *AwaitSuspend = cast_or_null<CallExpr>(
423 BuildSubExpr(ACT::ACT_Suspend,
"await_suspend", CoroHandle));
434 if (
Expr *TailCallSuspend =
441 Calls.
Results[ACT::ACT_Suspend] = TailCallSuspend;
447 diag::err_await_suspend_invalid_return_type)
449 S.
Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
453 Calls.
Results[ACT::ACT_Suspend] =
458 BuildSubExpr(ACT::ACT_Resume,
"await_resume", std::nullopt);
480 assert(isa<FunctionDecl>(
CurContext) &&
"not in a function scope");
482 bool IsThisDependentType = [&] {
483 if (
auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD))
484 return MD->isInstance() && MD->getThisType()->isDependentType();
500 if (VD->isInvalidDecl())
510 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
518 CtorArgExprs.push_back(ThisExpr.
get());
523 auto &Moves = ScopeInfo->CoroutineParameterMoves;
524 for (
auto *PD : FD->parameters()) {
525 if (PD->getType()->isDependentType())
529 auto Move = Moves.find(PD);
530 assert(Move != Moves.end() &&
531 "Coroutine function parameter not inserted into move map");
535 cast<VarDecl>(cast<DeclStmt>(Move->second)->getSingleDecl());
539 if (RefExpr.isInvalid())
541 CtorArgExprs.push_back(RefExpr.get());
546 if (!CtorArgExprs.empty()) {
550 CtorArgExprs, FD->getLocation());
553 VD->getLocation(),
true, PLE);
567 VD->setInvalidDecl();
568 }
else if (
Result.get()) {
585 bool IsImplicit =
false) {
589 assert(isa<FunctionDecl>(S.
CurContext) &&
"not in a function scope");
592 assert(ScopeInfo &&
"missing function scope for function");
594 if (ScopeInfo->FirstCoroutineStmtLoc.isInvalid() && !IsImplicit)
595 ScopeInfo->setFirstCoroutineStmt(Loc, Keyword);
597 if (ScopeInfo->CoroutinePromise)
604 if (!ScopeInfo->CoroutinePromise)
614 llvm::SmallPtrSetImpl<const Decl *> &ThrowingDecls) {
615 auto checkDeclNoexcept = [&](
const Decl *D,
bool IsDtor =
false) {
619 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
627 if (FD->getBuiltinID() == Builtin::BI__builtin_coro_resume)
630 if (ThrowingDecls.empty()) {
637 diag::err_coroutine_promise_final_suspend_requires_nothrow);
639 ThrowingDecls.insert(D);
643 if (
auto *CE = dyn_cast<CXXConstructExpr>(E)) {
645 checkDeclNoexcept(Ctor);
648 }
else if (
auto *CE = dyn_cast<CallExpr>(E)) {
649 if (CE->isTypeDependent())
652 checkDeclNoexcept(CE->getCalleeDecl());
659 checkDeclNoexcept(cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
663 for (
const auto *Child : E->
children()) {
678 ThrowingDecls.end()};
679 sort(SortedDecls, [](
const Decl *A,
const Decl *B) {
682 for (
const auto *D : SortedDecls) {
683 Diag(D->getEndLoc(), diag::note_coroutine_function_declare_noexcept);
685 return ThrowingDecls.empty();
693 assert(ScopeInfo->CoroutinePromise);
697 if (!ScopeInfo->NeedsCoroutineSuspends)
700 ScopeInfo->setNeedsCoroutineSuspends(
false);
705 auto buildSuspends = [&](StringRef Name)
mutable ->
StmtResult {
707 Loc, Name, std::nullopt);
708 if (Operand.isInvalid())
718 Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required)
719 << ((Name ==
"initial_suspend") ? 0 : 1);
720 Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword;
723 return cast<Stmt>(Suspend.
get());
726 StmtResult InitSuspend = buildSuspends(
"initial_suspend");
730 StmtResult FinalSuspend = buildSuspends(
"final_suspend");
734 ScopeInfo->setCoroutineSuspends(InitSuspend.
get(), FinalSuspend.
get());
756 while (S && !S->isFunctionScope()) {
757 if (S->isCatchScope())
775 S.
Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword;
781 S.
Diag(Loc, diag::err_coroutine_within_handler) << Keyword;
806 cast<UnresolvedLookupExpr>(Lookup.
get()));
816 assert(!Operators.
isAmbiguous() &&
"Operator lookup cannot be ambiguous");
819 Functions.size() > 1 ||
820 (Functions.size() == 1 && isa<FunctionTemplateDecl>(*Functions.begin()));
824 Functions.begin(), Functions.end());
837 if (Operand->hasPlaceholderType()) {
844 auto *Promise = FSI->CoroutinePromise;
845 if (Promise->getType()->isDependentType()) {
852 auto *Transformed = Operand;
858 diag::note_coroutine_promise_implicit_await_transform_required_here)
859 << Operand->getSourceRange();
862 Transformed = R.
get();
872 Expr *Awaiter,
bool IsImplicit) {
923 *
this,
getCurFunction()->CoroutinePromise, Loc,
"yield_value", E);
959 *
this, Coroutine->CoroutinePromise, Loc, E);
991 VarDecl *Promise = FSI->CoroutinePromise;
1012 assert(
Std &&
"Should already be diagnosed");
1019 S.
Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found);
1025 Result.suppressDiagnostics();
1053 assert(PointeeRD &&
"PromiseType must be a CxxRecordDecl type");
1055 const bool Overaligned = S.
getLangOpts().CoroAlignedAllocation;
1072 if (!OperatorDelete) {
1075 const bool CanProvideSize =
true;
1080 Overaligned, DeleteName);
1082 if (!OperatorDelete)
1093 assert(Fn && Fn->
isCoroutine() &&
"not a coroutine");
1096 "a null body is only allowed for invalid declarations");
1104 if (isa<CoroutineBodyStmt>(Body)) {
1114 if (FD->
hasAttr<AlwaysInlineAttr>())
1121 "first coroutine location not set");
1133 if (Builder.isInvalid() || !Builder.buildStatements())
1143 : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()),
1144 IsPromiseDependentType(
1145 !Fn.CoroutinePromise ||
1146 Fn.CoroutinePromise->getType()->isDependentType()) {
1150 this->ParamMovesVector.push_back(KV.second);
1153 if (!IsPromiseDependentType) {
1155 assert(PromiseRecordDecl &&
"Type should have already been checked");
1157 this->IsValid = makePromiseStmt() && makeInitialAndFinalSuspend();
1161 assert(this->IsValid &&
"coroutine already invalid");
1162 this->IsValid = makeReturnObject();
1163 if (this->IsValid && !IsPromiseDependentType)
1165 return this->IsValid;
1169 assert(this->IsValid &&
"coroutine already invalid");
1170 assert(!this->IsPromiseDependentType &&
1171 "coroutine cannot have a dependent promise type");
1172 this->IsValid = makeOnException() && makeOnFallthrough() &&
1173 makeGroDeclAndReturnStmt() && makeReturnOnAllocFailure() &&
1174 makeNewAndDeleteExpr();
1175 return this->IsValid;
1178bool CoroutineStmtBuilder::makePromiseStmt() {
1190bool CoroutineStmtBuilder::makeInitialAndFinalSuspend() {
1202 if (
auto *DeclRef = dyn_cast_or_null<DeclRefExpr>(E)) {
1203 auto *
Decl = DeclRef->getDecl();
1205 if (Method->isStatic())
1214 diag::err_coroutine_promise_get_return_object_on_allocation_failure)
1215 << PromiseRecordDecl;
1221bool CoroutineStmtBuilder::makeReturnOnAllocFailure() {
1222 assert(!IsPromiseDependentType &&
1223 "cannot make statement while the promise type is dependent");
1251 if (ReturnObjectOnAllocationFailure.
isInvalid())
1257 S.
Diag(Found.getFoundDecl()->getLocation(), diag::note_member_declared_here)
1273 if (
auto *MD = dyn_cast<CXXMethodDecl>(&FD)) {
1281 PlacementArgs.push_back(ThisExpr.
get());
1286 if (PD->getType()->isDependentType())
1290 auto PDLoc = PD->getLocation();
1297 PlacementArgs.push_back(PDRefExpr.
get());
1303bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
1305 assert(!IsPromiseDependentType &&
1306 "cannot make statement while the promise type is dependent");
1350 const bool PromiseContainsNew = [
this, &PromiseType]() ->
bool {
1358 return !R.empty() && !R.isAmbiguous();
1363 bool PassAlignment = S.
getLangOpts().CoroAlignedAllocation;
1366 bool WithoutPlacementArgs =
false,
1367 bool ForceNonAligned =
false) {
1377 PassAlignment = !ForceNonAligned && S.
getLangOpts().CoroAlignedAllocation;
1381 false, PassAlignment,
1384 OperatorNew, UnusedResult,
false);
1393 LookupAllocationFunction();
1395 if (PromiseContainsNew && !PlacementArgs.empty()) {
1409 (S.
getLangOpts().CoroAlignedAllocation && !PassAlignment))
1432 bool FoundNonAlignedInPromise =
false;
1433 if (PromiseContainsNew && S.
getLangOpts().CoroAlignedAllocation)
1434 if (!OperatorNew || !PassAlignment) {
1435 FoundNonAlignedInPromise = OperatorNew;
1441 if (!OperatorNew && !PlacementArgs.empty())
1447 bool IsGlobalOverload =
1448 OperatorNew && !isa<CXXRecordDecl>(OperatorNew->
getDeclContext());
1452 if (RequiresNoThrowAlloc && (!OperatorNew || IsGlobalOverload)) {
1456 PlacementArgs = {StdNoThrow};
1457 OperatorNew =
nullptr;
1464 if (FoundNonAlignedInPromise) {
1466 diag::warn_non_aligned_allocation_function)
1471 if (PromiseContainsNew)
1472 S.
Diag(Loc, diag::err_coroutine_unusable_new) << PromiseType << &FD;
1473 else if (RequiresNoThrowAlloc)
1474 S.
Diag(Loc, diag::err_coroutine_unfound_nothrow_new)
1480 if (RequiresNoThrowAlloc) {
1482 if (!FT->isNothrow(
false)) {
1484 diag::err_coroutine_promise_new_requires_nothrow)
1486 S.
Diag(Loc, diag::note_coroutine_promise_call_implicitly_required)
1506 Expr *FrameAlignment =
nullptr;
1529 if (S.
getLangOpts().CoroAlignedAllocation && PassAlignment)
1530 NewArgs.push_back(FrameAlignment);
1533 llvm::append_range(NewArgs, PlacementArgs);
1560 const auto *OpDeleteType =
1562 if (OpDeleteType->getNumParams() > DeleteArgs.size() &&
1564 OpDeleteType->getParamType(DeleteArgs.size()), FrameSize->
getType()))
1565 DeleteArgs.push_back(FrameSize);
1579 OpDeleteType->getNumParams() > DeleteArgs.size() &&
1581 OpDeleteType->getParamType(DeleteArgs.size()),
1583 DeleteArgs.push_back(FrameAlignment);
1598bool CoroutineStmtBuilder::makeOnFallthrough() {
1599 assert(!IsPromiseDependentType &&
1600 "cannot make statement while the promise type is dependent");
1609 bool HasRVoid, HasRValue;
1611 lookupMember(S,
"return_void", PromiseRecordDecl, Loc, HasRVoid);
1613 lookupMember(S,
"return_value", PromiseRecordDecl, Loc, HasRValue);
1616 if (HasRVoid && HasRValue) {
1618 S.
Diag(FD.getLocation(),
1619 diag::err_coroutine_promise_incompatible_return_functions)
1620 << PromiseRecordDecl;
1622 diag::note_member_first_declared_here)
1625 diag::note_member_first_declared_here)
1628 }
else if (!HasRVoid && !HasRValue) {
1642 }
else if (HasRVoid) {
1654bool CoroutineStmtBuilder::makeOnException() {
1656 assert(!IsPromiseDependentType &&
1657 "cannot make statement while the promise type is dependent");
1659 const bool RequireUnhandledException = S.
getLangOpts().CXXExceptions;
1661 if (!
lookupMember(S,
"unhandled_exception", PromiseRecordDecl, Loc)) {
1663 RequireUnhandledException
1664 ? diag::err_coroutine_promise_unhandled_exception_required
1666 warn_coroutine_promise_unhandled_exception_required_with_exceptions;
1667 S.
Diag(Loc, DiagID) << PromiseRecordDecl;
1669 << PromiseRecordDecl;
1670 return !RequireUnhandledException;
1697bool CoroutineStmtBuilder::makeReturnObject() {
1702 "get_return_object", std::nullopt);
1711 if (
auto *MbrRef = dyn_cast<CXXMemberCallExpr>(E)) {
1712 auto *MethodDecl = MbrRef->getMethodDecl();
1713 S.
Diag(MethodDecl->getLocation(), diag::note_member_declared_here)
1720bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() {
1721 assert(!IsPromiseDependentType &&
1722 "cannot make statement while the promise type is dependent");
1723 assert(this->
ReturnValue &&
"ReturnValue must be already formed");
1727 "get_return_object type must no longer be dependent");
1729 QualType const FnRetType = FD.getReturnType();
1731 "get_return_object type must no longer be dependent");
1747 if (!GroMatchesRetType)
1763 if (GroMatchesRetType) {
1767 S.
Context, &FD, FD.getLocation(), FD.getLocation(),
1812 if (!GroMatchesRetType &&
1813 cast<clang::ReturnStmt>(
ReturnStmt.get())->getNRVOCandidate() == GroDecl)
1849 assert(isa<FunctionDecl>(
CurContext) &&
"not in a function scope");
1853 if (!ScopeInfo->CoroutineParameterMoves.empty())
1862 for (
auto *PD : FD->parameters()) {
1863 if (PD->getType()->isDependentType())
1872 Expr *CExpr =
nullptr;
1873 if (PD->getType()->getAsCXXRecordDecl() ||
1874 PD->getType()->isRValueReferenceType())
1877 CExpr = PDRefExpr.
get();
1881 auto *D =
buildVarDecl(*
this, Loc, PD->getType(), PD->getIdentifier());
1886 if (
Stmt.isInvalid())
1889 ScopeInfo->CoroutineParameterMoves.insert(std::make_pair(PD,
Stmt.get()));
1915 Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
1916 <<
"std::coroutine_traits";
1923 Result.suppressDiagnostics();
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::Preprocessor interface.
static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType, SourceLocation Loc)
static void noteMemberDeclaredHere(Sema &S, Expr *E, FunctionScopeInfo &Fn)
static bool isValidCoroutineContext(Sema &S, SourceLocation Loc, StringRef Keyword)
static Expr * buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc)
Look up the std::nothrow object.
static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S, SourceLocation Loc, Expr *E)
static bool diagReturnOnAllocFailure(Sema &S, Expr *E, CXXRecordDecl *PromiseRecordDecl, FunctionScopeInfo &Fn)
static ExprResult buildPromiseCall(Sema &S, VarDecl *Promise, SourceLocation Loc, StringRef Name, MultiExprArg Args)
static Expr * castForMoving(Sema &S, Expr *E, QualType T=QualType())
static Expr * maybeTailCall(Sema &S, QualType RetType, Expr *E, SourceLocation Loc)
static ExprResult buildMemberCall(Sema &S, Expr *Base, SourceLocation Loc, StringRef Name, MultiExprArg Args)
static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD, SourceLocation Loc, bool &Res)
static TypeSourceInfo * getTypeSourceInfoForStdAlignValT(Sema &S, SourceLocation Loc)
static bool isWithinCatchScope(Scope *S)
static bool findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseType, FunctionDecl *&OperatorDelete)
static VarDecl * buildVarDecl(Sema &S, SourceLocation Loc, QualType Type, IdentifierInfo *II)
Build a variable declaration for move parameter.
static void checkNoThrow(Sema &S, const Stmt *E, llvm::SmallPtrSetImpl< const Decl * > &ThrowingDecls)
Recursively check E and all its children to see if any call target (including constructor call) is de...
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.
static bool checkSuspensionContext(Sema &S, SourceLocation Loc, StringRef Keyword)
static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType, SourceLocation Loc)
Look up the std::coroutine_handle<PromiseType>.
static bool collectPlacementArgs(Sema &S, FunctionDecl &FD, SourceLocation Loc, SmallVectorImpl< Expr * > &PlacementArgs)
static QualType lookupPromiseType(Sema &S, const FunctionDecl *FD, SourceLocation KwLoc)
Look up the std::coroutine_traits<...>::promise_type for the given function type.
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.
static bool IsOverloaded(const UnresolvedSetImpl &Functions)
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
DeclarationNameTable DeclarationNames
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
AddrLabelExpr - The GNU address of label extension, representing &&label.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a C++ constructor within a class.
Represents a static or instance method of a struct/union/class.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Represents a C++ struct/union/class.
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
Represents a C++ nested-name-specifier or a global scope specifier.
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Declaration of a class template.
void setExprNeedsCleanups(bool SideEffects)
Represents a 'co_await' expression.
Represents a 'co_return' statement in the C++ Coroutines TS.
Represents the body of a coroutine.
static CoroutineBodyStmt * Create(const ASTContext &C, CtorArgs const &Args)
CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, sema::FunctionScopeInfo &Fn, Stmt *Body)
Construct a CoroutineStmtBuilder and initialize the promise statement and initial/final suspends from...
bool buildDependentStatements()
Build the coroutine body statements that require a non-dependent promise type in order to construct.
bool buildStatements()
Build the coroutine body statements, including the "promise dependent" statements when the promise ty...
Represents a 'co_yield' expression.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
SourceLocation getEndLoc() const LLVM_READONLY
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isInvalidDecl() const
SourceLocation getLocation() const
void setImplicit(bool I=true)
DeclContext * getDeclContext()
The name of a declaration.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a 'co_await' expression while the type of the promise is dependent.
This represents one expression.
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Represents a function declaration or definition.
ArrayRef< ParmVarDecl * > parameters() const
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
Represents a prototype with parameter type info, e.g.
ArrayRef< QualType > getParamTypes() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
QualType getReturnType() const
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
Describes the sequence of initializations required to initialize a given object or reference with a s...
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
Describes an entity that is being initialized.
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type)
Create the initialization entity for the result of a function.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
Represents the results of name lookup.
DeclClass * getAsSingle() const
const UnresolvedSetImpl & asUnresolvedSet() const
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
DeclarationName getLookupName() const
Gets the name to look up.
This represents a decl that may have a name.
Represent a C++ namespace.
A C++ nested-name-specifier augmented with source location information.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
decls_iterator decls_begin() const
decls_iterator decls_end() const
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
PointerType - C99 6.7.5.1 - Pointer Declarators.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
IdentifierTable & getIdentifierTable()
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getCanonicalType() const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Scope - A scope is a transient data structure that is used while parsing the program.
Sema - This implements semantic analysis and AST building for C.
FunctionDecl * FindUsualDeallocationFunction(SourceLocation StartLoc, bool CanProvideSize, bool Overaligned, DeclarationName Name)
ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression.
Scope * getCurScope() const
Retrieve the parser's current scope.
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)
ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *InputExpr, bool IsAfterAmp=false)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupOperatorName
Look up of an operator name (e.g., operator+) for use with operator overloading.
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs)
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body)
bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, StringRef Keyword)
VarDecl * buildCoroutinePromise(SourceLocation Loc)
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
Expr * BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, MultiExprArg CallArgs)
BuildBuiltinCallExpr - Create a call to a builtin function specified by Id.
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E)
ExprResult ActOnCXXThis(SourceLocation loc)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
ClassTemplateDecl * StdCoroutineTraitsCache
The C++ "std::coroutine_traits" template, which is defined in <coroutine_traits>
ASTContext & getASTContext() const
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
EnumDecl * getStdAlignValT() const
NamedReturnInfo getNamedReturnInfo(Expr *&E, SimplerImplicitMoveMode Mode=SimplerImplicitMoveMode::Normal)
Determine whether the given expression might be move-eligible or copy-elidable in either a (co_)retur...
StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E)
const LangOptions & getLangOpts() const
StmtResult ActOnFinishFullStmt(Stmt *Stmt)
ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr, bool IsExecConfig=false, bool AllowRecovery=false)
BuildCallExpr - Handle a call to Fn with the specified array of arguments.
bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, AllocationFunctionScope NewScope, AllocationFunctionScope DeleteScope, QualType AllocType, bool IsArray, bool &PassAlignment, MultiExprArg PlaceArgs, FunctionDecl *&OperatorNew, FunctionDecl *&OperatorDelete, bool Diagnose=true)
Finds the overloads of operator new and delete that are appropriate for the allocation.
CleanupInfo Cleanup
Used to control the generation of ExprWithCleanups.
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, UnresolvedLookupExpr *Lookup)
bool buildCoroutineParameterMoves(SourceLocation Loc)
sema::FunctionScopeInfo * getCurFunction() const
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input, bool RequiresADL=true)
Create a unary operation that may resolve to an overloaded operator.
ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E)
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, DeclarationName Name, FunctionDecl *&Operator, bool Diagnose=true, bool WantSize=false, bool WantAligned=false)
MaterializeTemporaryExpr * CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, bool BoundToLvalueReference)
ExprResult PerformContextuallyConvertToBool(Expr *From)
PerformContextuallyConvertToBool - Perform a contextual conversion of the expression From to bool (C+...
bool isUnevaluatedContext() const
Determines whether we are currently in a context that is not evaluated as per C++ [expr] p5.
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
ClassTemplateDecl * lookupCoroutineTraits(SourceLocation KwLoc, SourceLocation FuncLoc)
Lookup 'coroutine_traits' in std namespace and std::experimental namespace.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
void CheckCompleteVariableDeclaration(VarDecl *VD)
ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc)
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
FullExprArg MakeFullDiscardedValueExpr(Expr *Arg)
NamespaceDecl * getStdNamespace() const
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
void ActOnUninitializedDecl(Decl *dcl)
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
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,...
void clearDelayedTypo(TypoExpr *TE)
Clears the state of the given TypoExpr.
void CheckVariableDeclarationType(VarDecl *NewVD)
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
AllocationFunctionScope
The scope in which to find allocation functions.
@ AFS_Both
Look for allocation functions in both the global scope and in the scope of the allocated class.
@ AFS_Class
Only look for allocation functions in the scope of the allocated class.
@ AFS_Global
Only look for allocation functions in the global scope.
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, SourceLocation Loc=SourceLocation())
Determine whether the callee of a particular function call can throw.
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
A convenient class for passing around template argument information.
void addArgument(const TemplateArgumentLoc &Loc)
Location wrapper for a TemplateArgument.
Represents a template argument.
Represents a C++ template name within the type system.
Represents a declaration of a type.
A container of type source information.
The base class of the type hierarchy.
bool isStructureType() const
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isBooleanType() const
bool isVoidPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
bool isRecordType() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
void append(iterator I, iterator E)
A set of unresolved declarations.
Represents a variable declaration or definition.
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
@ CallInit
Call-style initialization (C++98)
void setNRVOVariable(bool NRVO)
Retains information about a function, method, or block that is currently being parsed.
llvm::SmallMapVector< ParmVarDecl *, Stmt *, 4 > CoroutineParameterMoves
A mapping between the coroutine function parameters that were moved to the coroutine frame,...
SourceLocation FirstCoroutineStmtLoc
First coroutine statement in the current function.
std::pair< Stmt *, Stmt * > CoroutineSuspends
The initial and final coroutine suspend points.
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
bool hasInvalidCoroutineSuspends() const
StringRef getFirstCoroutineStmtKeyword() const
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
llvm::SmallVector< AddrLabelExpr *, 4 > AddrLabels
The set of GNU address of label extension "&&label".
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
bool isLambdaCallOperator(const CXXMethodDecl *MD)
@ Result
The result type of a method or function.
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
@ ETK_None
No keyword precedes the qualified type name.
OpaqueValueExpr * OpaqueValue
Stmt * ReturnStmtOnAllocFailure
ArrayRef< Stmt * > ParamMoves
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
DeclarationName getName() const
getName - Returns the embedded declaration name.