clang  14.0.0git
Classes | Functions
SemaCoroutine.cpp File Reference
#include "CoroutineStmtBuilder.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/Decl.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/StmtCXX.h"
#include "clang/Basic/Builtins.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Overload.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/SmallSet.h"
Include dependency graph for SemaCoroutine.cpp:

Go to the source code of this file.

Classes

struct  ReadySuspendResumeResult
 

Functions

static LookupResult lookupMember (Sema &S, const char *Name, CXXRecordDecl *RD, SourceLocation Loc, bool &Res)
 
static bool lookupMember (Sema &S, const char *Name, CXXRecordDecl *RD, SourceLocation Loc)
 
static QualType lookupPromiseType (Sema &S, const FunctionDecl *FD, SourceLocation KwLoc)
 Look up the std::coroutine_traits<...>::promise_type for the given function type. More...
 
static QualType lookupCoroutineHandleType (Sema &S, QualType PromiseType, SourceLocation Loc)
 Look up the std::experimental::coroutine_handle<PromiseType>. More...
 
static bool isValidCoroutineContext (Sema &S, SourceLocation Loc, StringRef Keyword)
 
static ExprResult buildOperatorCoawaitLookupExpr (Sema &SemaRef, Scope *S, SourceLocation Loc)
 
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. More...
 
static ExprResult buildOperatorCoawaitCall (Sema &SemaRef, Scope *S, SourceLocation Loc, Expr *E)
 
static ExprResult buildCoroutineHandle (Sema &S, QualType PromiseType, SourceLocation Loc)
 
static ExprResult buildMemberCall (Sema &S, Expr *Base, SourceLocation Loc, StringRef Name, MultiExprArg Args)
 
static ExprmaybeTailCall (Sema &S, QualType RetType, Expr *E, SourceLocation Loc)
 
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. More...
 
static ExprResult buildPromiseCall (Sema &S, VarDecl *Promise, SourceLocation Loc, StringRef Name, MultiExprArg Args)
 
static FunctionScopeInfocheckCoroutineContext (Sema &S, SourceLocation Loc, StringRef Keyword, bool IsImplicit=false)
 Check that this is a context in which a coroutine suspension can appear. More...
 
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 declared noexcept. More...
 
static bool isWithinCatchScope (Scope *S)
 
static void checkSuspensionContext (Sema &S, SourceLocation Loc, StringRef Keyword)
 
static ExprbuildStdNoThrowDeclRef (Sema &S, SourceLocation Loc)
 Look up the std::nothrow object. More...
 
static FunctionDeclfindDeleteForPromise (Sema &S, SourceLocation Loc, QualType PromiseType)
 
static bool diagReturnOnAllocFailure (Sema &S, Expr *E, CXXRecordDecl *PromiseRecordDecl, FunctionScopeInfo &Fn)
 
static void noteMemberDeclaredHere (Sema &S, Expr *E, FunctionScopeInfo &Fn)
 
static ExprcastForMoving (Sema &S, Expr *E, QualType T=QualType())
 
static VarDeclbuildVarDecl (Sema &S, SourceLocation Loc, QualType Type, IdentifierInfo *II)
 Build a variable declaration for move parameter. More...
 

Function Documentation

◆ buildCoawaitCalls()

static ReadySuspendResumeResult buildCoawaitCalls ( Sema S,
VarDecl CoroPromise,
SourceLocation  Loc,
Expr E 
)
static

Build calls to await_ready, await_suspend, and await_resume for a co_await expression.

The generated AST tries to clean up temporary objects as early as possible so that they don't live across suspension points if possible. Having temporary objects living across suspension points unnecessarily can lead to large frame size, and also lead to memory corruptions if the coroutine frame is destroyed after coming back from suspension. This is done by wrapping both the await_ready call and the await_suspend call with ExprWithCleanups. In the end of this function, we also need to explicitly set cleanup state so that the CoawaitExpr is also wrapped with an ExprWithCleanups to clean up the awaiter associated with the co_await expression.

Definition at line 403 of file SemaCoroutine.cpp.

Referenced by clang::Sema::BuildCoyieldExpr(), and clang::Sema::BuildResolvedCoawaitExpr().

◆ buildCoroutineHandle()

static ExprResult buildCoroutineHandle ( Sema S,
QualType  PromiseType,
SourceLocation  Loc 
)
static

Definition at line 294 of file SemaCoroutine.cpp.

◆ buildMemberCall()

static ExprResult buildMemberCall ( Sema S,
Expr Base,
SourceLocation  Loc,
StringRef  Name,
MultiExprArg  Args 
)
static

Definition at line 328 of file SemaCoroutine.cpp.

◆ buildOperatorCoawaitCall() [1/2]

static ExprResult buildOperatorCoawaitCall ( Sema SemaRef,
Scope S,
SourceLocation  Loc,
Expr E 
)
static

Definition at line 285 of file SemaCoroutine.cpp.

◆ buildOperatorCoawaitCall() [2/2]

static ExprResult buildOperatorCoawaitCall ( Sema SemaRef,
SourceLocation  Loc,
Expr E,
UnresolvedLookupExpr Lookup 
)
static

Build a call to 'operator co_await' if there is a suitable operator for the given expression.

Definition at line 277 of file SemaCoroutine.cpp.

References clang::UnresolvedSetImpl::append(), clang::Sema::CreateOverloadedUnaryOp(), clang::OverloadExpr::decls_begin(), and clang::OverloadExpr::decls_end().

Referenced by clang::Sema::BuildUnresolvedCoawaitExpr().

◆ buildOperatorCoawaitLookupExpr()

static ExprResult buildOperatorCoawaitLookupExpr ( Sema SemaRef,
Scope S,
SourceLocation  Loc 
)
static

Definition at line 254 of file SemaCoroutine.cpp.

◆ buildPromiseCall()

static ExprResult buildPromiseCall ( Sema S,
VarDecl Promise,
SourceLocation  Loc,
StringRef  Name,
MultiExprArg  Args 
)
static

◆ buildStdNoThrowDeclRef()

static Expr* buildStdNoThrowDeclRef ( Sema S,
SourceLocation  Loc 
)
static

Look up the std::nothrow object.

Definition at line 996 of file SemaCoroutine.cpp.

◆ buildVarDecl()

static VarDecl* buildVarDecl ( Sema S,
SourceLocation  Loc,
QualType  Type,
IdentifierInfo II 
)
static

Build a variable declaration for move parameter.

Definition at line 1609 of file SemaCoroutine.cpp.

Referenced by clang::Sema::buildCoroutineParameterMoves().

◆ castForMoving()

static Expr* castForMoving ( Sema S,
Expr E,
QualType  T = QualType() 
)
static

Definition at line 1593 of file SemaCoroutine.cpp.

Referenced by clang::Sema::buildCoroutineParameterMoves().

◆ checkCoroutineContext()

static FunctionScopeInfo* checkCoroutineContext ( Sema S,
SourceLocation  Loc,
StringRef  Keyword,
bool  IsImplicit = false 
)
static

◆ checkNoThrow()

static void checkNoThrow ( Sema S,
const Stmt E,
llvm::SmallPtrSetImpl< const Decl * > &  ThrowingDecls 
)
static

Recursively check E and all its children to see if any call target (including constructor call) is declared noexcept.

Also any value returned from the call has a noexcept destructor.

Definition at line 638 of file SemaCoroutine.cpp.

Referenced by clang::Sema::checkFinalSuspendNoThrow().

◆ checkSuspensionContext()

static void checkSuspensionContext ( Sema S,
SourceLocation  Loc,
StringRef  Keyword 
)
static

Definition at line 789 of file SemaCoroutine.cpp.

◆ diagReturnOnAllocFailure()

static bool diagReturnOnAllocFailure ( Sema S,
Expr E,
CXXRecordDecl PromiseRecordDecl,
FunctionScopeInfo Fn 
)
static

Definition at line 1145 of file SemaCoroutine.cpp.

◆ findDeleteForPromise()

static FunctionDecl* findDeleteForPromise ( Sema S,
SourceLocation  Loc,
QualType  PromiseType 
)
static

Definition at line 1027 of file SemaCoroutine.cpp.

◆ isValidCoroutineContext()

static bool isValidCoroutineContext ( Sema S,
SourceLocation  Loc,
StringRef  Keyword 
)
static

Definition at line 188 of file SemaCoroutine.cpp.

◆ isWithinCatchScope()

static bool isWithinCatchScope ( Scope S)
static

Definition at line 761 of file SemaCoroutine.cpp.

◆ lookupCoroutineHandleType()

static QualType lookupCoroutineHandleType ( Sema S,
QualType  PromiseType,
SourceLocation  Loc 
)
static

Look up the std::experimental::coroutine_handle<PromiseType>.

Definition at line 145 of file SemaCoroutine.cpp.

◆ lookupMember() [1/2]

static bool lookupMember ( Sema S,
const char *  Name,
CXXRecordDecl RD,
SourceLocation  Loc 
)
static

Definition at line 43 of file SemaCoroutine.cpp.

◆ lookupMember() [2/2]

static LookupResult lookupMember ( Sema S,
const char *  Name,
CXXRecordDecl RD,
SourceLocation  Loc,
bool Res 
)
static

Definition at line 32 of file SemaCoroutine.cpp.

Referenced by clang::Sema::BuildUnresolvedCoawaitExpr().

◆ lookupPromiseType()

static QualType lookupPromiseType ( Sema S,
const FunctionDecl FD,
SourceLocation  KwLoc 
)
static

Look up the std::coroutine_traits<...>::promise_type for the given function type.

Definition at line 52 of file SemaCoroutine.cpp.

Referenced by clang::Sema::buildCoroutinePromise().

◆ maybeTailCall()

static Expr* maybeTailCall ( Sema S,
QualType  RetType,
Expr E,
SourceLocation  Loc 
)
static

Definition at line 357 of file SemaCoroutine.cpp.

◆ noteMemberDeclaredHere()

static void noteMemberDeclaredHere ( Sema S,
Expr E,
FunctionScopeInfo Fn 
)
static

Definition at line 1500 of file SemaCoroutine.cpp.