clang 20.0.0git
|
#include "clang/Sema/SemaLambda.h"
#include "TypeLocBuilder.h"
#include "clang/AST/ASTLambda.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/MangleNumberingContext.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/DeclSpec.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Scope.h"
#include "clang/Sema/ScopeInfo.h"
#include "clang/Sema/SemaCUDA.h"
#include "clang/Sema/SemaInternal.h"
#include "clang/Sema/SemaOpenMP.h"
#include "clang/Sema/Template.h"
#include "llvm/ADT/STLExtras.h"
#include <optional>
Go to the source code of this file.
Functions | |
static std::optional< unsigned > | getStackIndexOfNearestEnclosingCaptureReadyLambda (ArrayRef< const clang::sema::FunctionScopeInfo * > FunctionScopes, ValueDecl *VarToCapture) |
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda) that is 'capture-ready' for the variable referenced in the current lambda (i.e. | |
static TemplateParameterList * | getGenericLambdaTemplateParameterList (LambdaScopeInfo *LSI, Sema &SemaRef) |
static bool | isInInlineFunction (const DeclContext *DC) |
Determine whether the given context is or is enclosed in an inline function. | |
static QualType | buildTypeForLambdaCallOperator (Sema &S, clang::CXXRecordDecl *Class, TemplateParameterList *TemplateParams, TypeSourceInfo *MethodTypeInfo) |
static void | buildLambdaScopeReturnType (Sema &S, LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, bool ExplicitResultType) |
static EnumDecl * | findEnumForBlockReturn (Expr *E) |
If this expression is an enumerator-like expression of some type T, return the type T; otherwise, return null. | |
static EnumDecl * | findEnumForBlockReturn (ReturnStmt *ret) |
Attempt to find a type T for which the returned expression of the given statement is an enumerator-like expression of that type. | |
static EnumDecl * | findCommonEnumForBlockReturns (ArrayRef< ReturnStmt * > returns) |
Attempt to find a common type T for which all of the returned expressions in a block are enumerator-like expressions of that type. | |
static void | adjustBlockReturnsToEnum (Sema &S, ArrayRef< ReturnStmt * > returns, QualType returnType) |
Adjust the given return statements so that they formally return the given type. | |
static LambdaScopeInfo * | getCurrentLambdaScopeUnsafe (Sema &S) |
static TypeSourceInfo * | getDummyLambdaType (Sema &S, SourceLocation Loc=SourceLocation()) |
static TypeSourceInfo * | getLambdaType (Sema &S, LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope, SourceLocation Loc, bool &ExplicitResultType) |
template<typename Func > | |
static void | repeatForLambdaConversionFunctionCallingConvs (Sema &S, const FunctionProtoType &CallOpProto, Func F) |
static CallingConv | getLambdaConversionFunctionCallConv (Sema &S, const FunctionProtoType *CallOpProto) |
static void | addFunctionPointerConversion (Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator, QualType InvokerFunctionTy) |
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6. | |
static void | addFunctionPointerConversions (Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator) |
Add a lambda's conversion to function pointers, as described in C++11 [expr.prim.lambda]p6. | |
static void | addBlockPointerConversion (Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator) |
Add a lambda's conversion to block pointer. | |
static LambdaCaptureDefault | mapImplicitCaptureStyle (CapturingScopeInfo::ImplicitCaptureStyle ICS) |
static FunctionDecl * | getPatternFunctionDecl (FunctionDecl *FD) |
|
static |
Add a lambda's conversion to block pointer.
Definition at line 1851 of file SemaLambda.cpp.
References clang::Qualifiers::addConst(), clang::AS_public, clang::Type::castAs(), clang::Class, clang::Sema::Context, clang::CXXConversionDecl::Create(), clang::ASTContext::DeclarationNames, clang::SourceRange::getBegin(), clang::ASTContext::getBlockPointerType(), clang::FunctionDecl::getBody(), clang::ASTContext::getCanonicalType(), clang::Sema::getCurFPFeatures(), clang::DeclarationNameTable::getCXXConversionFunctionName(), clang::ASTContext::getDefaultCallingConvention(), clang::Stmt::getEndLoc(), clang::ASTContext::getFunctionType(), getLambdaConversionFunctionCallConv(), clang::Sema::getLambdaConversionFunctionResultType(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::ValueDecl::getType(), clang::FPOptions::isFPConstrained(), Loc, clang::DeclarationNameLoc::makeNamedTypeLoc(), clang::Decl::setAccess(), clang::Decl::setImplicit(), clang::FunctionProtoType::ExtProtoInfo::TypeQuals, and clang::Unspecified.
Referenced by clang::Sema::BuildLambdaExpr().
|
static |
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6.
Definition at line 1661 of file SemaLambda.cpp.
References clang::Qualifiers::addConst(), clang::AS_private, clang::AS_public, clang::Class, clang::Constexpr, clang::Sema::Context, clang::CXXConversionDecl::Create(), clang::CXXMethodDecl::Create(), clang::FunctionTemplateDecl::Create(), clang::ParmVarDecl::Create(), clang::ASTContext::DeclarationNames, clang::EST_BasicNoexcept, clang::FunctionProtoType::ExtProtoInfo::ExceptionSpec, clang::IdentifierTable::get(), clang::TypeLoc::getAs(), clang::SourceRange::getBegin(), clang::DeclaratorDecl::getBeginLoc(), clang::FunctionDecl::getBody(), clang::ASTContext::getCanonicalType(), clang::FunctionDecl::getConstexprKind(), clang::Sema::getCurFPFeatures(), clang::DeclarationNameTable::getCXXConversionFunctionName(), clang::ASTContext::getDefaultCallingConvention(), clang::FunctionDecl::getDescribedFunctionTemplate(), clang::Stmt::getEndLoc(), clang::ASTContext::getFunctionType(), clang::NamedDecl::getIdentifier(), clang::getLambdaStaticInvokerName(), clang::Sema::getLangOpts(), clang::Decl::getLocation(), clang::FunctionDecl::getNumParams(), clang::FunctionDecl::getParamDecl(), clang::ASTContext::getPointerType(), clang::FunctionTypeLoc::getReturnLoc(), clang::VarDecl::getStorageClass(), clang::TemplateDecl::getTemplateParameters(), clang::DeclaratorDecl::getTrailingRequiresClause(), clang::ASTContext::getTranslationUnitDecl(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::ValueDecl::getType(), clang::TypeSourceInfo::getTypeLoc(), clang::DeclaratorDecl::getTypeSourceInfo(), clang::ASTContext::Idents, clang::FPOptions::isFPConstrained(), clang::CXXMethodDecl::isImplicitObjectMemberFunction(), Loc, clang::DeclarationNameLoc::makeNamedTypeLoc(), P, clang::FunctionDecl::parameters(), clang::SC_Static, clang::Decl::setAccess(), clang::FunctionDecl::setDescribedFunctionTemplate(), clang::Decl::setImplicit(), clang::FunctionDecl::setParams(), clang::DeclaratorDecl::setTrailingRequiresClause(), clang::FunctionProtoType::ExceptionSpecInfo::Type, clang::FunctionProtoType::ExtProtoInfo::TypeQuals, and clang::Unspecified.
Referenced by addFunctionPointerConversions().
|
static |
Add a lambda's conversion to function pointers, as described in C++11 [expr.prim.lambda]p6.
Note that in most cases, this should emit only a single pointer conversion. In the event that the default calling convention for free and member functions is different, it will emit both conventions.
Definition at line 1835 of file SemaLambda.cpp.
References addFunctionPointerConversion(), clang::Type::castAs(), clang::Class, clang::Sema::getLambdaConversionFunctionResultType(), clang::ValueDecl::getType(), and repeatForLambdaConversionFunctionCallingConvs().
Referenced by clang::Sema::BuildLambdaExpr().
|
static |
Adjust the given return statements so that they formally return the given type.
It should require, at most, an IntegralCast.
Definition at line 664 of file SemaLambda.cpp.
References clang::Sema::Context, clang::ImplicitCastExpr::Create(), E, clang::ReturnStmt::getRetValue(), clang::FullExpr::getSubExpr(), clang::Expr::getType(), clang::ASTContext::hasSameType(), clang::Type::isIntegralOrUnscopedEnumerationType(), clang::ReturnStmt::setRetValue(), clang::FullExpr::setSubExpr(), and clang::VK_PRValue.
Referenced by clang::Sema::deduceClosureReturnType().
|
static |
Definition at line 509 of file SemaLambda.cpp.
References clang::DeclaratorDecl::getBeginLoc(), clang::FunctionDecl::getReturnType(), clang::sema::CapturingScopeInfo::HasImplicitReturnType, clang::Type::isDependentType(), clang::Type::isVoidType(), clang::Sema::RequireCompleteType(), and clang::sema::CapturingScopeInfo::ReturnType.
Referenced by clang::Sema::CompleteLambdaCallOperator().
|
static |
Definition at line 365 of file SemaLambda.cpp.
References clang::Type::castAs(), clang::Class, clang::Sema::Context, clang::FunctionProtoType::getExtProtoInfo(), clang::ASTContext::getFunctionType(), clang::FunctionProtoType::getParamTypes(), clang::FunctionType::getReturnType(), clang::TypeSourceInfo::getType(), clang::Result, and clang::Sema::SubstAutoTypeDependent().
Referenced by clang::Sema::CompleteLambdaCallOperator().
|
static |
Attempt to find a common type T for which all of the returned expressions in a block are enumerator-like expressions of that type.
Definition at line 643 of file SemaLambda.cpp.
References findEnumForBlockReturn(), and clang::TagDecl::hasNameForLinkage().
Referenced by clang::Sema::deduceClosureReturnType().
If this expression is an enumerator-like expression of some type T, return the type T; otherwise, return null.
Pointer comparisons on the result here should always work because it's derived from either the parent of an EnumConstantDecl (i.e. the definition) or the declaration returned by EnumType::getDecl() (i.e. the definition).
Definition at line 571 of file SemaLambda.cpp.
References D, E, findEnumForBlockReturn(), clang::Type::getAs(), clang::Decl::getDeclContext(), clang::Expr::getType(), and clang::Expr::IgnoreParens().
Referenced by findCommonEnumForBlockReturns(), and findEnumForBlockReturn().
|
static |
Attempt to find a type T for which the returned expression of the given statement is an enumerator-like expression of that type.
Definition at line 634 of file SemaLambda.cpp.
References findEnumForBlockReturn(), and clang::ReturnStmt::getRetValue().
|
static |
Definition at line 885 of file SemaLambda.cpp.
References clang::Sema::FunctionScopes.
Referenced by clang::Sema::ActOnLambdaClosureParameters(), clang::Sema::ActOnLambdaClosureQualifiers(), clang::Sema::ActOnStartOfLambdaDefinition(), and clang::Sema::CompleteLambdaCallOperator().
|
static |
Definition at line 891 of file SemaLambda.cpp.
References clang::Qualifiers::addAddressSpace(), clang::Qualifiers::addConst(), clang::Sema::Context, clang::Default, clang::ASTContext::DependentTy, clang::ASTContext::getAutoDeductType(), clang::ASTContext::getDefaultCallingConvention(), clang::Sema::getDefaultCXXMethodAddrSpace(), clang::ASTContext::getFunctionType(), clang::Sema::getLangOpts(), clang::ASTContext::getTrivialTypeSourceInfo(), clang::FunctionProtoType::ExtProtoInfo::HasTrailingReturn, Loc, and clang::FunctionProtoType::ExtProtoInfo::TypeQuals.
Referenced by getLambdaType().
|
inlinestatic |
Definition at line 235 of file SemaLambda.cpp.
References clang::Sema::Context, clang::sema::LambdaScopeInfo::ExplicitTemplateParamsRange, clang::ActionResult< PtrTy, Compress >::get(), clang::SourceRange::getBegin(), clang::SourceRange::getEnd(), clang::sema::LambdaScopeInfo::GLTemplateParameterList, clang::sema::LambdaScopeInfo::RequiresClause, and clang::InventedTemplateParameterInfo::TemplateParams.
Referenced by clang::Sema::ActOnLambdaClosureParameters(), clang::Sema::ActOnStartOfLambdaDefinition(), clang::Sema::CompleteLambdaCallOperator(), and clang::Sema::createLambdaClosureType().
|
static |
Definition at line 1631 of file SemaLambda.cpp.
References clang::Sema::Context, clang::FunctionType::getCallConv(), clang::ASTContext::getDefaultCallingConvention(), and clang::FunctionProtoType::isVariadic().
Referenced by addBlockPointerConversion().
|
static |
Definition at line 917 of file SemaLambda.cpp.
References clang::Sema::CheckExplicitObjectLambda(), clang::Type::containsUnexpandedParameterPack(), clang::Default, clang::SemaBase::Diag(), clang::Sema::DiagnoseUnexpandedParameterPack(), clang::OpaquePtr< PtrTy >::get(), clang::QualType::getAddressSpace(), clang::SourceRange::getBegin(), clang::Declarator::getDeclSpec(), getDummyLambdaType(), clang::Declarator::getFunctionTypeInfo(), clang::Sema::getLangOpts(), clang::Declarator::getNumTypeObjects(), clang::DeclaratorChunk::FunctionTypeInfo::getOrCreateMethodQualifiers(), clang::DeclSpec::getStorageClassSpec(), clang::DeclaratorChunk::FunctionTypeInfo::getTrailingReturnType(), clang::DeclaratorChunk::FunctionTypeInfo::getTrailingReturnTypeLoc(), clang::TypeSourceInfo::getType(), clang::Sema::GetTypeForDeclarator(), clang::DeclaratorChunk::FunctionTypeInfo::hasMutableQualifier(), clang::DeclaratorChunk::FunctionTypeInfo::hasTrailingReturnType(), clang::Declarator::isExplicitObjectMemberFunction(), clang::QualType::isNull(), Loc, clang::LambdaIntroducer::Range, clang::DeclSpec::SCS_static, clang::DeclSpec::SCS_unspecified, clang::DeclSpec::SetTypeQual(), clang::DeclSpec::TQ_const, and clang::Sema::UPPC_DeclarationType.
Referenced by clang::Sema::ActOnStartOfLambdaDefinition().
|
static |
Definition at line 2363 of file SemaLambda.cpp.
References clang::FunctionDecl::getInstantiatedFromDecl(), clang::FunctionDecl::getInstantiatedFromMemberFunction(), clang::FunctionTemplateDecl::getInstantiatedFromMemberTemplate(), clang::FunctionDecl::getPrimaryTemplate(), clang::FunctionTemplateDecl::getTemplatedDecl(), clang::FunctionDecl::getTemplatedKind(), clang::FunctionDecl::TK_DependentNonTemplate, and clang::FunctionDecl::TK_MemberSpecialization.
Referenced by clang::Sema::LambdaScopeForCallOperatorInstantiationRAII::LambdaScopeForCallOperatorInstantiationRAII().
|
inlinestatic |
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda) that is 'capture-ready' for the variable referenced in the current lambda (i.e.
VarToCapture
). If successful, returns the index into Sema's FunctionScopeInfo stack of the capture-ready lambda's LambdaScopeInfo.
Climbs down the stack of lambdas (deepest nested lambda - i.e. current lambda - is on top) to determine the index of the nearest enclosing/outer lambda that is ready to capture the VarToCapture
being referenced in the current lambda. As we climb down the stack, we want the index of the first such lambda - that is the lambda with the highest index that is 'capture-ready'.
A lambda 'L' is capture-ready for 'V' (var or this) if:
VarToCapture
is 'null' then we are trying to capture 'this'.Note that a lambda that is deemed 'capture-ready' still needs to be checked for whether it is 'capture-capable' (see getStackIndexOfNearestEnclosingCaptureCapableLambda), before it can truly capture.
FunctionScopes | - Sema's stack of nested FunctionScopeInfo's (which a LambdaScopeInfo inherits from). The current/deepest/innermost lambda is at the top of the stack and has the highest index. |
VarToCapture | - the variable to capture. If NULL, capture 'this'. |
VarToCapture
. Definition at line 69 of file SemaLambda.cpp.
References clang::DeclContext::Equals(), clang::Decl::getDeclContext(), clang::getLambdaAwareParentOfDeclContext(), clang::sema::CapturingScopeInfo::ImpCaptureStyle, clang::sema::CapturingScopeInfo::isCaptured(), clang::sema::CapturingScopeInfo::isCXXThisCaptured(), clang::DeclContext::isDependentContext(), clang::isLambdaCallOperator(), and clang::DeclContext::isTranslationUnit().
Referenced by clang::getStackIndexOfNearestEnclosingCaptureCapableLambda().
|
static |
Determine whether the given context is or is enclosed in an inline function.
Definition at line 269 of file SemaLambda.cpp.
References clang::DeclContext::getLexicalParent(), and clang::DeclContext::isFileContext().
Referenced by clang::Sema::getCurrentMangleNumberContext().
|
static |
Definition at line 1957 of file SemaLambda.cpp.
References clang::sema::CapturingScopeInfo::ImpCap_Block, clang::sema::CapturingScopeInfo::ImpCap_CapturedRegion, clang::sema::CapturingScopeInfo::ImpCap_LambdaByref, clang::sema::CapturingScopeInfo::ImpCap_LambdaByval, clang::sema::CapturingScopeInfo::ImpCap_None, clang::LCD_ByCopy, clang::LCD_ByRef, and clang::LCD_None.
Referenced by clang::Sema::BuildLambdaExpr().
|
static |
Implement emitting a version of the operator for many of the calling conventions for MSVC, as described here: https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623. Experimentally, we determined that cdecl, stdcall, fastcall, and vectorcall are generated by MSVC when it is supported by the target. Additionally, we are ensuring that the default-free/default-member and call-operator calling convention are generated as well. NOTE: We intentionally generate a 'thiscall' on Win32 implicitly from the 'member default', despite MSVC not doing so. We do this in order to ensure that someone who intentionally places 'thiscall' on the lambda call operator will still get that overload, since we don't have the a way of detecting the attribute by the time we get here.
Definition at line 1583 of file SemaLambda.cpp.
References clang::C, clang::CC_C, clang::CC_X86FastCall, clang::CC_X86StdCall, clang::CC_X86VectorCall, clang::TargetInfo::CCCR_OK, clang::TargetInfo::checkCallingConvention(), clang::Sema::Context, clang::Sema::getASTContext(), clang::FunctionType::getCallConv(), clang::ASTContext::getDefaultCallingConvention(), clang::Sema::getLangOpts(), clang::ASTContext::getTargetInfo(), clang::FunctionProtoType::isVariadic(), and Range.
Referenced by addFunctionPointerConversions().