14#ifndef LLVM_CLANG_SEMA_SCOPEINFO_H
15#define LLVM_CLANG_SEMA_SCOPEINFO_H
26#include "llvm/ADT/DenseMap.h"
27#include "llvm/ADT/DenseMapInfo.h"
28#include "llvm/ADT/MapVector.h"
29#include "llvm/ADT/PointerIntPair.h"
30#include "llvm/ADT/SmallPtrSet.h"
31#include "llvm/ADT/SmallSet.h"
32#include "llvm/ADT/SmallVector.h"
33#include "llvm/ADT/StringRef.h"
34#include "llvm/ADT/StringSwitch.h"
35#include "llvm/ADT/TinyPtrVector.h"
36#include "llvm/Support/Casting.h"
37#include "llvm/Support/ErrorHandling.h"
48class ImplicitParamDecl;
52class ObjCPropertyDecl;
53class ObjCPropertyRefExpr;
60class TemplateParameterList;
93 llvm::TinyPtrVector<const Stmt*>
Stmts;
202 using SwitchInfo = llvm::PointerIntPair<SwitchStmt*, 1, bool>;
275 using BaseInfoTy = llvm::PointerIntPair<const NamedDecl *, 1, bool>;
285 static BaseInfoTy getBaseInfo(
const Expr *BaseE);
311 return Base.getInt();
329 return WeakObjectProfileTy::getSentinel();
333 using Pair = std::pair<BaseInfoTy, const NamedDecl *>;
335 return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base,
353 llvm::PointerIntPair<const Expr *, 1, bool> Rep;
363 return Rep ==
Other.Rep;
416 template <
typename ExprT>
429 return WeakObjectUses;
503 "first coroutine statement location already set");
506 .Case(
"co_return", 0)
508 .Case(
"co_yield", 2);
513 &&
"no coroutine statement available");
515 case 0:
return "co_return";
516 case 1:
return "co_await";
517 case 2:
return "co_yield";
519 llvm_unreachable(
"FirstCoroutineStmtKind has an invalid value");
525 "we already have valid suspend points");
534 assert(Initial && Final &&
"suspend points cannot be null");
563 Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
592 unsigned CapturesThis : 1;
596 unsigned ODRUsed : 1;
600 unsigned NonODRUsed : 1;
604 unsigned Invalid : 1;
610 :
CapturedVar(Var), Loc(Loc), EllipsisLoc(EllipsisLoc),
611 CaptureType(CaptureType), Kind(
Block ? Cap_Block
614 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
615 NonODRUsed(
false), Invalid(Invalid) {}
619 QualType CaptureType,
const bool ByCopy,
bool Invalid)
620 : Loc(Loc), CaptureType(CaptureType),
621 Kind(ByCopy ? Cap_ByCopy : Cap_ByRef), Nested(IsNested),
628 :
CapturedVLA(VLA), Loc(Loc), CaptureType(CaptureType), Kind(Cap_VLA),
629 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
718 EllipsisLoc, CaptureType,
Invalid));
725 false, Loc, CaptureType));
749 assert(
isCaptured(Var) &&
"Variable has not been captured");
754 llvm::DenseMap<ValueDecl *, unsigned>::const_iterator Known =
756 assert(Known !=
CaptureMap.end() &&
"Variable has not been captured");
830 return "default captured statement";
832 return "Objective-C @finally statement";
834 return "OpenMP region";
836 llvm_unreachable(
"Invalid captured region kind!");
973 assert(isa<DeclRefExpr>(VarExpr) || isa<MemberExpr>(VarExpr) ||
974 isa<FunctionParmPackExpr>(VarExpr));
1026 assert(isa<DeclRefExpr>(CapturingVarExpr) ||
1027 isa<MemberExpr>(CapturingVarExpr) ||
1028 isa<FunctionParmPackExpr>(CapturingVarExpr));
1032 assert(isa<DeclRefExpr>(CapturingVarExpr) ||
1033 isa<MemberExpr>(CapturingVarExpr) ||
1034 isa<FunctionParmPackExpr>(CapturingVarExpr));
1054 llvm::function_ref<
void(
ValueDecl *,
Expr *)> Callback)
const;
1059FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
1062FunctionScopeInfo::WeakObjectProfileTy
1063FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
1064 FunctionScopeInfo::WeakObjectProfileTy
Result;
1065 Result.Base.setInt(
true);
1069template <
typename ExprT>
1082 CXXThisCaptureIndex = Captures.size();
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
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.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Represents a static or instance method of a struct/union/class.
Represents a C++ struct/union/class.
Represents the body of a CapturedStmt, and serves as its DeclContext.
A reference to a declared variable, function, enum, etc.
RAII class that determines when any errors have occurred between the time the instance was created an...
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
Concrete class used by the front-end to report problems and issues.
This represents one expression.
This represents a decl that may have a name.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
An expression that sends a message to the given Objective-C object or class.
Represents one property declaration in an Objective-C interface.
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Represents a parameter to a function.
A (possibly-)qualified type.
Represents a struct/union/class.
Scope - A scope is a transient data structure that is used while parsing the program.
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.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
Represents a C array with a specified size that is not an integer-constant-expression.
Retains information about a block that is currently being parsed.
Scope * TheScope
TheScope - This is the scope for the block itself, which contains arguments etc.
BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
static bool classof(const FunctionScopeInfo *FSI)
~BlockScopeInfo() override
QualType FunctionType
BlockType - The function type of the block, if one was given.
ValueDecl * getVariable() const
bool isVariableCapture() const
bool isBlockCapture() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
bool isNonODRUsed() const
Capture(IsThisCapture, bool IsNested, SourceLocation Loc, QualType CaptureType, const bool ByCopy, bool Invalid)
void markUsed(bool IsODRUse)
bool isInitCapture() const
Determine whether this capture is an init-capture.
ValueDecl * CapturedVar
Otherwise, the captured variable (if any).
bool isVLATypeCapture() const
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
bool isThisCapture() const
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
bool isCopyCapture() const
bool isReferenceCapture() const
Capture(IsVLACapture, const VariableArrayType *VLA, bool IsNested, SourceLocation Loc, QualType CaptureType)
Capture(ValueDecl *Var, bool Block, bool ByRef, bool IsNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
const VariableArrayType * getCapturedVLAType() const
const VariableArrayType * CapturedVLA
If Kind == Cap_VLA, the captured type.
Retains information about a captured region.
static bool classof(const FunctionScopeInfo *FSI)
~CapturedRegionScopeInfo() override
unsigned short OpenMPLevel
unsigned short CapRegionKind
The kind of captured region.
ImplicitParamDecl * ContextParam
The implicit parameter for the captured variables.
unsigned short OpenMPCaptureLevel
StringRef getRegionName() const
A descriptive name for the kind of captured region this is.
Scope * TheScope
This is the enclosing scope of the captured region.
CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, RecordDecl *RD, ImplicitParamDecl *Context, CapturedRegionKind K, unsigned OpenMPLevel, unsigned OpenMPCaptureLevel)
RecordDecl * TheRecordDecl
The captured record type.
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
const Capture & getCapture(ValueDecl *Var) const
void addVLATypeCapture(SourceLocation Loc, const VariableArrayType *VLAType, QualType CaptureType)
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
bool isCaptured(ValueDecl *Var) const
Determine whether the given variable has been captured.
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCaptureStyle ImpCaptureStyle
unsigned CXXThisCaptureIndex
CXXThisCaptureIndex - The (index+1) of the capture of 'this'; zero if 'this' is not captured.
bool HasImplicitReturnType
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
CapturingScopeInfo(const CapturingScopeInfo &)=default
llvm::DenseMap< ValueDecl *, unsigned > CaptureMap
CaptureMap - A map of captured variables to (index+1) into Captures.
static bool classof(const FunctionScopeInfo *FSI)
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, bool ByCopy)
CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
bool isVLATypeCaptured(const VariableArrayType *VAT) const
Determine whether the given variable-array type has been captured.
void addCapture(ValueDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
Capture & getCapture(ValueDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Contains information about the compound statement currently being parsed.
FPOptions InitialFPFeatures
FP options at the beginning of the compound statement, prior to any pragma.
bool HasEmptyLoopBodies
Whether this compound stamement contains ‘for’ or ‘while’ loops with empty bodies.
void setHasEmptyLoopBodies()
bool IsStmtExpr
Whether this compound statement corresponds to a GNU statement expression.
CompoundScopeInfo(bool IsStmtExpr, FPOptions FPO)
static WeakObjectProfileTy getEmptyKey()
static WeakObjectProfileTy getTombstoneKey()
static bool isEqual(const WeakObjectProfileTy &LHS, const WeakObjectProfileTy &RHS)
static unsigned getHashValue(const WeakObjectProfileTy &Val)
Represents a simple identification of a weak object.
bool isExactProfile() const
Returns true if the object base specifies a known object in memory, rather than, say,...
bool operator==(const WeakObjectProfileTy &Other) const
const NamedDecl * getBase() const
const NamedDecl * getProperty() const
Represents a single use of a weak object.
const Expr * getUseExpr() const
bool operator==(const WeakUseTy &Other) const
WeakUseTy(const Expr *Use, bool IsRead)
Retains information about a function, method, or block that is currently being parsed.
llvm::PointerIntPair< SwitchStmt *, 1, bool > SwitchInfo
A SwitchStmt, along with a flag indicating if its list of case statements is incomplete (because we d...
void setHasObjCTry(SourceLocation TryLoc)
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
Used to collect all uses of weak objects in a function body.
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
FunctionScopeInfo(DiagnosticsEngine &Diag)
bool HasIndirectGoto
Whether this function contains any indirect gotos.
bool HasFallthroughStmt
Whether there is a fallthrough statement in this function.
SourceLocation FirstVLALoc
First use of a VLA within the current function.
SourceLocation FirstCXXOrObjCTryLoc
First C++ 'try' or ObjC @try statement in the current function.
bool UsesFPIntrin
Whether this function uses constrained floating point intrinsics.
void addByrefBlockVar(VarDecl *VD)
llvm::SmallMapVector< ParmVarDecl *, Stmt *, 4 > CoroutineParameterMoves
A mapping between the coroutine function parameters that were moved to the coroutine frame,...
void setFirstCoroutineStmt(SourceLocation Loc, StringRef Keyword)
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
unsigned char FirstCoroutineStmtKind
An enumeration represeting the kind of the first coroutine statement in the function.
bool NeedsScopeChecking() const
bool HasDroppedStmt
Whether a statement was dropped because it was invalid.
void setNeedsCoroutineSuspends(bool value=true)
void markSafeWeakUse(const Expr *E)
Record that a given expression is a "safe" access of a weak object (e.g.
void setHasOMPDeclareReductionCombiner()
SourceLocation FirstCoroutineStmtLoc
First coroutine statement in the current function.
bool FoundImmediateEscalatingExpression
Whether we found an immediate-escalating expression.
void setHasIndirectGoto()
void setCoroutineSuspends(Stmt *Initial, Stmt *Final)
std::pair< Stmt *, Stmt * > CoroutineSuspends
The initial and final coroutine suspend points.
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
void Clear()
Clear out the information in this function scope, making it suitable for reuse.
bool ObjCShouldCallSuper
A flag that is set when parsing a method that must call super's implementation, such as -dealloc,...
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
void addBlock(const BlockDecl *BD)
SmallVector< WeakUseTy, 4 > WeakUseVector
Used to collect uses of a particular weak object in a function body.
ScopeKind Kind
What kind of scope we are describing.
bool hasInvalidCoroutineSuspends() const
bool HasBranchProtectedScope
Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jump...
bool hasUnrecoverableErrorOccurred() const
Determine whether an unrecoverable error has occurred within this function.
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
A list of PartialDiagnostics created but delayed within the current function scope.
FunctionScopeInfo(const FunctionScopeInfo &)=default
enum clang::sema::FunctionScopeInfo::@237 FirstTryType
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
void setHasFallthroughStmt()
bool isPlainFunction() const
StringRef getFirstCoroutineStmtKeyword() const
bool HasPotentialAvailabilityViolations
Whether we make reference to a declaration that could be unavailable.
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
bool HasBranchIntoScope
Whether this function contains any switches or direct gotos.
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
void setHasCXXTry(SourceLocation TryLoc)
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
const WeakObjectUseMap & getWeakObjectUses() const
llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks
The set of blocks that are introduced in this function.
void setHasVLA(SourceLocation VLALoc)
void setHasBranchProtectedScope()
void setHasBranchIntoScope()
void setHasSEHTry(SourceLocation TryLoc)
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
bool NeedsCoroutineSuspends
True only when this function has not already built, or attempted to build, the initial and final coro...
llvm::SmallVector< AddrLabelExpr *, 4 > AddrLabels
The set of GNU address of label extension "&&label".
llvm::TinyPtrVector< VarDecl * > ByrefBlockVars
The set of __block variables that are introduced in this function.
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
bool HasMustTail
Whether this function contains any statement marked with [[clang::musttail]].
bool HasOMPDeclareReductionCombiner
True if current scope is for OpenMP declare reduction combiner.
virtual ~FunctionScopeInfo()
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
A list of parameters which have the nonnull attribute and are modified in the function.
SourceLocation PotentialThisCaptureLocation
void removePotentialCapture(Expr *E)
void finishedExplicitCaptures()
Note when all explicit captures have been added.
bool hasPotentialThisCapture() const
LambdaScopeInfo(DiagnosticsEngine &Diag)
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
SmallVector< NamedDecl *, 4 > LocalPacks
Packs introduced by this lambda, if any.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
bool isGenericLambda() const
Is this scope known to be for a generic lambda? (This will be false until we parse a template paramet...
bool lambdaCaptureShouldBeConst() const
void clearPotentialCaptures()
bool ExplicitParams
Whether the (empty) parameter list is explicit.
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the TemplateParam...
void addPotentialCapture(Expr *VarExpr)
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas.
void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr)
Mark a variable's reference in a lambda as non-odr using.
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
void addPotentialThisCapture(SourceLocation Loc)
ParmVarDecl * ExplicitObjectParameter
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
ExprResult RequiresClause
The requires-clause immediately following the explicit template parameter list, if any.
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
bool hasPotentialCaptures() const
bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const
CXXRecordDecl * Lambda
The class that describes the lambda.
void visitPotentialCaptures(llvm::function_ref< void(ValueDecl *, Expr *)> Callback) const
unsigned getNumPotentialVariableCaptures() const
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
static bool classof(const FunctionScopeInfo *FSI)
bool AfterParameterList
Indicate that we parsed the parameter list at which point the mutability of the lambda is known.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
bool Mutable
Whether this is a mutable lambda.
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
Contains all variable-referring-expressions (i.e.
llvm::TinyPtrVector< const Stmt * > Stmts
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, ArrayRef< const Stmt * > Stmts)
CapturedRegionKind
The different kinds of captured statement.
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ Other
Other implicit parameter.
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
Contains all of the variables defined in this lambda that shadow variables that were defined in paren...
const VarDecl * ShadowedDecl