Go to the documentation of this file.
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"
48 class ImplicitParamDecl;
50 class ObjCIvarRefExpr;
51 class ObjCMessageExpr;
52 class ObjCPropertyDecl;
53 class ObjCPropertyRefExpr;
60 class TemplateParameterList;
61 class TemplateTypeParmDecl;
89 llvm::TinyPtrVector<const Stmt*>
Stmts;
187 using SwitchInfo = llvm::PointerIntPair<SwitchStmt*, 1, bool>;
257 using BaseInfoTy = llvm::PointerIntPair<const NamedDecl *, 1, bool>;
267 static BaseInfoTy getBaseInfo(
const Expr *BaseE);
293 return Base.getInt();
297 return Base == Other.Base &&
Property == Other.Property;
311 return WeakObjectProfileTy::getSentinel();
315 using Pair = std::pair<BaseInfoTy, const NamedDecl *>;
335 llvm::PointerIntPair<const Expr *, 1, bool> Rep;
345 return Rep == Other.Rep;
398 template <
typename ExprT>
411 return WeakObjectUses;
472 "first coroutine statement location already set");
475 .Case(
"co_return", 0)
477 .Case(
"co_yield", 2);
482 &&
"no coroutine statement available");
484 case 0:
return "co_return";
485 case 1:
return "co_await";
486 case 2:
return "co_yield";
488 llvm_unreachable(
"FirstCoroutineStmtKind has an invalid value");
494 "we already have valid suspend points");
503 assert(Initial && Final &&
"suspend points cannot be null");
532 Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
561 unsigned CapturesThis : 1;
565 unsigned ODRUsed : 1;
569 unsigned NonODRUsed : 1;
573 unsigned Invalid : 1;
579 :
CapturedVar(Var), Loc(Loc), EllipsisLoc(EllipsisLoc),
580 CaptureType(CaptureType),
581 Kind(
Block ? Cap_Block : ByRef ? Cap_ByRef : Cap_ByCopy),
582 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
583 NonODRUsed(
false), Invalid(Invalid) {}
587 QualType CaptureType,
const bool ByCopy,
bool Invalid)
588 : Loc(Loc), CaptureType(CaptureType),
589 Kind(ByCopy ? Cap_ByCopy : Cap_ByRef), Nested(IsNested),
596 :
CapturedVLA(VLA), Loc(Loc), CaptureType(CaptureType), Kind(Cap_VLA),
597 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
684 QualType CaptureType,
bool Invalid) {
686 EllipsisLoc, CaptureType, Invalid));
693 false, Loc, CaptureType));
719 assert(
isCaptured(Var) &&
"Variable has not been captured");
724 llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
726 assert(Known !=
CaptureMap.end() &&
"Variable has not been captured");
800 return "default captured statement";
802 return "Objective-C @finally statement";
804 return "OpenMP region";
806 llvm_unreachable(
"Invalid captured region kind!");
935 assert(isa<DeclRefExpr>(VarExpr) || isa<MemberExpr>(VarExpr) ||
936 isa<FunctionParmPackExpr>(VarExpr));
988 assert(isa<DeclRefExpr>(CapturingVarExpr) ||
989 isa<MemberExpr>(CapturingVarExpr) ||
990 isa<FunctionParmPackExpr>(CapturingVarExpr));
994 assert(isa<DeclRefExpr>(CapturingVarExpr) ||
995 isa<MemberExpr>(CapturingVarExpr) ||
996 isa<FunctionParmPackExpr>(CapturingVarExpr));
1019 llvm::function_ref<
void(
VarDecl *,
Expr *)> Callback)
const;
1022 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
1025 FunctionScopeInfo::WeakObjectProfileTy
1026 FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
1027 FunctionScopeInfo::WeakObjectProfileTy Result;
1028 Result.Base.setInt(
true);
1032 template <
typename ExprT>
1045 CXXThisCaptureIndex = Captures.size();
1052 #endif // LLVM_CLANG_SEMA_SCOPEINFO_H
static bool classof(const FunctionScopeInfo *FSI)
static unsigned getHashValue(const WeakObjectProfileTy &Val)
static WeakObjectProfileTy getTombstoneKey()
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
bool isThisCapture() const
SourceRange ExplicitTemplateParamsRange
Source range covering the explicit template parameter list (if it exists).
bool NeedsCoroutineSuspends
True only when this function has not already built, or attempted to build, the initial and final coro...
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
A list of PartialDiagnostics created but delayed within the current function scope.
void markUsed(bool IsODRUse)
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
const WeakObjectUseMap & getWeakObjectUses() const
void setHasFallthroughStmt()
StringRef getFirstCoroutineStmtKeyword() const
ScopeKind Kind
What kind of scope we are describing.
A trivial tuple used to represent a source range.
std::pair< Stmt *, Stmt * > CoroutineSuspends
The initial and final coroutine suspend points.
bool ExplicitParams
Whether the (empty) parameter list is explicit.
CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, RecordDecl *RD, ImplicitParamDecl *Context, CapturedRegionKind K, unsigned OpenMPLevel, unsigned OpenMPCaptureLevel)
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.
BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
llvm::TinyPtrVector< VarDecl * > ByrefBlockVars
The set of __block variables that are introduced in this function.
CapturingScopeInfo(const CapturingScopeInfo &)=default
bool isInitCapture() const
Determine whether this capture is an init-capture.
VarDecl * getVariable() const
bool Mutable
Whether this is a mutable lambda.
Encodes a location in the source.
bool isReferenceCapture() const
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 Clear()
Clear out the information in this function scope, making it suitable for reuse.
This represents a decl that may have a name.
llvm::SmallMapVector< ParmVarDecl *, Stmt *, 4 > CoroutineParameterMoves
A mapping between the coroutine function parameters that were moved to the coroutine frame,...
bool HasBranchIntoScope
Whether this function contains any switches or direct gotos.
Capture(IsThisCapture, bool IsNested, SourceLocation Loc, QualType CaptureType, const bool ByCopy, bool Invalid)
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
A (possibly-)qualified type.
unsigned char FirstCoroutineStmtKind
An enumeration represeting the kind of the first coroutine statement in the function.
void addByrefBlockVar(VarDecl *VD)
void setHasOMPDeclareReductionCombiner()
bool isExactProfile() const
Returns true if the object base specifies a known object in memory, rather than, say,...
bool NeedsScopeChecking() const
Concrete class used by the front-end to report problems and issues.
CompoundScopeInfo(bool IsStmtExpr)
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the TemplateParam...
static bool isEqual(const WeakObjectProfileTy &LHS, const WeakObjectProfileTy &RHS)
CapturedRegionKind
The different kinds of captured statement.
void addVLATypeCapture(SourceLocation Loc, const VariableArrayType *VLAType, QualType CaptureType)
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
bool operator==(const WeakUseTy &Other) const
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred since this object instance was created.
LambdaScopeInfo(DiagnosticsEngine &Diag)
bool UsesFPIntrin
Whether this function uses constrained floating point intrinsics.
bool isGenericLambda() const
Is this scope known to be for a generic lambda? (This will be false until we parse a template paramet...
Contains all of the variables defined in this lambda that shadow variables that were defined in paren...
static bool classof(const FunctionScopeInfo *FSI)
Represents the body of a CapturedStmt, and serves as its DeclContext.
Retains information about a block that is currently being parsed.
ExprResult RequiresClause
The requires-clause immediately following the explicit template parameter list, if any.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
RAII class that determines when any errors have occurred between the time the instance was created an...
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
WeakUseTy(const Expr *Use, bool IsRead)
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
static bool classof(const FunctionScopeInfo *FSI)
bool isCopyCapture() const
void setHasBranchProtectedScope()
Retains information about a captured region.
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
SmallVector< WeakUseTy, 4 > WeakUseVector
Used to collect uses of a particular weak object in a function body.
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
unsigned short CapRegionKind
The kind of captured region.
CXXRecordDecl * Lambda
The class that describes the lambda.
llvm::TinyPtrVector< const Stmt * > Stmts
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
unsigned getNumPotentialVariableCaptures() const
llvm::SmallPtrSet< const BlockDecl *, 1 > Blocks
The set of blocks that are introduced in this function.
const VariableArrayType * CapturedVLA
If Kind == Cap_VLA, the captured type.
void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr)
Mark a variable's reference in a lambda as non-odr using.
void removePotentialCapture(Expr *E)
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool HasDroppedStmt
Whether a statement was dropped because it was invalid.
bool IsStmtExpr
Whether this compound statement corresponds to a GNU statement expression.
Scope - A scope is a transient data structure that is used while parsing the program.
const VariableArrayType * getCapturedVLAType() const
SourceLocation PotentialThisCaptureLocation
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
void setHasCXXTry(SourceLocation TryLoc)
void setHasIndirectGoto()
bool hasUnrecoverableErrorOccurred() const
Determine whether an unrecoverable error has occurred within this function.
bool hasPotentialThisCapture() const
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
bool HasEmptyLoopBodies
Whether this compound stamement contains ‘for’ or ‘while’ loops with empty bodies.
bool isNonODRUsed() const
bool hasPotentialCaptures() const
Represents a single use of a weak object.
StringRef getRegionName() const
A descriptive name for the kind of captured region this is.
SmallVector< SwitchInfo, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
bool HasBranchProtectedScope
Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jump...
bool HasPotentialAvailabilityViolations
Whether we make reference to a declaration that could be unavailable.
void setHasBranchIntoScope()
Represents a variable declaration or definition.
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Stores a list of template parameters for a TemplateDecl and its derived classes.
virtual ~FunctionScopeInfo()
void visitPotentialCaptures(llvm::function_ref< void(VarDecl *, Expr *)> Callback) const
~CapturedRegionScopeInfo() override
ImplicitCaptureStyle ImpCaptureStyle
bool ObjCShouldCallSuper
A flag that is set when parsing a method that must call super's implementation, such as -dealloc,...
FunctionScopeInfo(DiagnosticsEngine &Diag)
An expression that sends a message to the given Objective-C object or class.
void setHasSEHTry(SourceLocation TryLoc)
RecordDecl * TheRecordDecl
The captured record type.
QualType FunctionType
BlockType - The function type of the block, if one was given.
SmallVector< NamedDecl *, 4 > LocalPacks
Packs introduced by this lambda, if any.
VarDecl * CapturedVar
Otherwise, the captured variable (if any).
Capture(IsVLACapture, const VariableArrayType *VLA, bool IsNested, SourceLocation Loc, QualType CaptureType)
Retains information about a function, method, or block that is currently being parsed.
Represents a C++ struct/union/class.
SourceLocation FirstCoroutineStmtLoc
First coroutine statement in the current function.
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
Represents a C array with a specified size that is not an integer-constant-expression.
SmallVector< Capture, 4 > Captures
Captures - The captures.
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
bool operator==(const WeakObjectProfileTy &Other) const
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
bool isVLATypeCapture() const
const Expr * getUseExpr() const
Represents one property declaration in an Objective-C interface.
const Capture & getCapture(VarDecl *Var) const
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
void clearPotentialCaptures()
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
void markSafeWeakUse(const Expr *E)
Record that a given expression is a "safe" access of a weak object (e.g.
Scope * TheScope
TheScope - This is the scope for the block itself, which contains arguments etc.
bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const
llvm::DenseMap< VarDecl *, unsigned > CaptureMap
CaptureMap - A map of captured variables to (index+1) into Captures.
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
Used to collect all uses of weak objects in a function body.
void setFirstCoroutineStmt(SourceLocation Loc, StringRef Keyword)
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
Represents a simple identification of a weak object.
bool HasOMPDeclareReductionCombiner
True if current scope is for OpenMP declare reduction combiner.
~BlockScopeInfo() override
ImplicitParamDecl * ContextParam
The implicit parameter for the captured variables.
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
Dataflow Directional Tag Classes.
Scope * TheScope
This is the enclosing scope of the captured region.
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
Contains information about the compound statement currently being parsed.
unsigned short OpenMPCaptureLevel
static WeakObjectProfileTy getEmptyKey()
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
Contains all variable-referring-expressions (i.e.
llvm::DenseMap< unsigned, SourceRange > ExplicitCaptureRanges
A map of explicit capture indices to their introducer source ranges.
Stmt - This represents one statement.
bool isPlainFunction() const
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
static bool classof(const FunctionScopeInfo *FSI)
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
A list of parameters which have the nonnull attribute and are modified in the function.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool HasIndirectGoto
Whether this function contains any indirect gotos.
Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, bool Invalid)
bool HasImplicitReturnType
const NamedDecl * getProperty() const
void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, bool ByCopy)
@ Property
The type of a property.
const VarDecl * ShadowedDecl
unsigned CXXThisCaptureIndex
CXXThisCaptureIndex - The (index+1) of the capture of 'this'; zero if 'this' is not captured.
bool isBlockCapture() const
void addPotentialThisCapture(SourceLocation Loc)
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
bool hasInvalidCoroutineSuspends() const
bool HasFallthroughStmt
Whether there is a fallthrough statement in this function.
void addPotentialCapture(Expr *VarExpr)
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas.
bool isVLATypeCaptured(const VariableArrayType *VAT) const
Determine whether the given variable-array type has been captured.
void setNeedsCoroutineSuspends(bool value=true)
This represents one expression.
FunctionScopeInfo(const FunctionScopeInfo &)=default
bool isVariableCapture() const
void setCoroutineSuspends(Stmt *Initial, Stmt *Final)
unsigned short OpenMPLevel
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
A reference to a declared variable, function, enum, etc.
Represents a struct/union/class.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, ArrayRef< const Stmt * > Stmts)
const NamedDecl * getBase() const
void addBlock(const BlockDecl *BD)
Represents a static or instance method of a struct/union/class.
void setHasEmptyLoopBodies()
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.