15 #ifndef LLVM_CLANG_SEMA_SCOPEINFO_H
16 #define LLVM_CLANG_SEMA_SCOPEINFO_H
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallSet.h"
26 #include "llvm/ADT/SmallVector.h"
36 class ObjCPropertyDecl;
38 class ImplicitParamDecl;
43 class TemplateTypeParmDecl;
44 class TemplateParameterList;
46 class ObjCIvarRefExpr;
47 class ObjCPropertyRefExpr;
48 class ObjCMessageExpr;
76 : PD(PD), Loc(Loc), stmt(stmt) {}
206 typedef llvm::PointerIntPair<const NamedDecl *, 1, bool> BaseInfoTy;
216 static BaseInfoTy getBaseInfo(
const Expr *BaseE);
242 return Base.getInt();
246 return Base == Other.Base && Property == Other.Property;
259 return WeakObjectProfileTy::getSentinel();
263 typedef std::pair<BaseInfoTy, const NamedDecl *> Pair;
282 llvm::PointerIntPair<const Expr *, 1, bool> Rep;
291 return Rep == Other.Rep;
320 template <
typename ExprT>
333 return WeakObjectUses;
425 Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
428 IsNestedCapture = 0x1,
433 llvm::PointerIntPair<VarDecl*, 2> VarAndNestedAndThis;
438 llvm::PointerIntPair<void *, 2, CaptureKind> InitExprAndCaptureKind;
454 : VarAndNestedAndThis(Var, IsNested ? IsNestedCapture : 0),
455 InitExprAndCaptureKind(
456 Cpy, !Var ? Cap_VLA : Block ? Cap_Block : ByRef ? Cap_ByRef
458 Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {}
463 : VarAndNestedAndThis(
464 nullptr, (IsThisCaptured | (IsNested ? IsNestedCapture : 0))),
465 InitExprAndCaptureKind(Cpy, ByCopy ? Cap_ByCopy : Cap_ByRef),
466 Loc(Loc), EllipsisLoc(), CaptureType(CaptureType) {}
469 return VarAndNestedAndThis.getInt() & IsThisCaptured;
475 return InitExprAndCaptureKind.getInt() == Cap_ByCopy;
478 return InitExprAndCaptureKind.getInt() == Cap_ByRef;
481 return InitExprAndCaptureKind.getInt() == Cap_Block;
484 return InitExprAndCaptureKind.getInt() == Cap_VLA;
487 return VarAndNestedAndThis.getInt() & IsNestedCapture;
491 return VarAndNestedAndThis.getPointer();
511 return static_cast<Expr *
>(InitExprAndCaptureKind.getPointer());
542 EllipsisLoc, CaptureType, Cpy));
557 Expr *Cpy,
bool ByCopy);
579 assert(
isCaptured(Var) &&
"Variable has not been captured");
584 llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
586 assert(Known !=
CaptureMap.end() &&
"Variable has not been captured");
654 return "default captured statement";
656 return "OpenMP region";
658 llvm_unreachable(
"Invalid captured region kind!");
774 assert(isa<DeclRefExpr>(VarExpr) || isa<MemberExpr>(VarExpr));
826 assert(isa<DeclRefExpr>(CapturingVarExpr)
827 || isa<MemberExpr>(CapturingVarExpr));
831 assert(isa<DeclRefExpr>(CapturingVarExpr)
832 || isa<MemberExpr>(CapturingVarExpr));
859 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
862 FunctionScopeInfo::WeakObjectProfileTy
863 FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
864 FunctionScopeInfo::WeakObjectProfileTy Result;
865 Result.Base.setInt(
true);
869 template <
typename ExprT>
880 Captures.push_back(
Capture(Capture::ThisCapture, isNested, Loc,
QualType(),
882 CXXThisCaptureIndex = Captures.size();
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
void clearPotentialCaptures()
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
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.
A (possibly-)qualified type.
void addThisCapture(bool isNested, SourceLocation Loc, Expr *Cpy, bool ByCopy)
bool ExplicitParams
Whether the (empty) parameter list is explicit.
bool isThisCapture() const
bool HasFallthroughStmt
Whether there is a fallthrough statement in this function.
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateP...
Expr * getInitExpr() const
bool HasEmptyLoopBodies
Whether this compound stamement contains `for' or `while' loops with empty bodies.
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
C Language Family Type Representation.
static WeakObjectProfileTy getTombstoneKey()
static unsigned getHashValue(const WeakObjectProfileTy &Val)
bool hasPotentialThisCapture() const
bool NeedsScopeChecking() const
static bool classof(const FunctionScopeInfo *FSI)
Retains information about a function, method, or block that is currently being parsed.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
static bool classof(const FunctionScopeInfo *FSI)
SmallVector< SwitchStmt *, 8 > SwitchStack
SwitchStack - This is the current set of active switch statements in the block.
static bool classof(const FunctionScopeInfo *FSI)
RAII class that determines when any errors have occurred between the time the instance was created an...
CapturingScopeInfo(const CapturingScopeInfo &)=default
Stores a list of template parameters for a TemplateDecl and its derived classes.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
void setHasBranchProtectedScope()
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
bool HasDroppedStmt
Whether a statement was dropped because it was invalid.
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
RecordDecl - Represents a struct/union/class.
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
const Capture & getCapture(VarDecl *Var) const
void setHasIndirectGoto()
void setHasOMPDeclareReductionCombiner()
ScopeKind Kind
What kind of scope we are describing.
Scope * TheScope
This is the enclosing scope of the captured region.
~CapturedRegionScopeInfo() override
VarDecl * getVariable() const
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
const NamedDecl * getBase() const
void setHasBranchIntoScope()
DiagnosticErrorTrap ErrorTrap
Used to determine if errors occurred in this function or block.
void getPotentialVariableCapture(unsigned Idx, VarDecl *&VD, Expr *&E) const
bool hasPotentialCaptures() const
WeakUseTy(const Expr *Use, bool IsRead)
Concrete class used by the front-end to report problems and issues.
QualType FunctionType
BlockType - The function type of the block, if one was given.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
static WeakObjectProfileTy getEmptyKey()
Scope - A scope is a transient data structure that is used while parsing the program.
FunctionScopeInfo(DiagnosticsEngine &Diag)
This represents the body of a CapturedStmt, and serves as its DeclContext.
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, const Stmt *stmt)
SmallVector< TemplateTypeParmDecl *, 4 > AutoTemplateParams
Store the list of the auto parameters for a generic lambda.
SmallVector< WeakUseTy, 4 > WeakUseVector
Used to collect uses of a particular weak object in a function body.
Contains information about the compound statement currently being parsed.
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
ImplicitCaptureStyle ImpCaptureStyle
void addPotentialCapture(Expr *VarExpr)
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas...
bool isBlockCapture() const
void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr)
Mark a variable's reference in a lambda as non-odr using.
bool Mutable
Whether this is a mutable lambda.
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
Retains information about a captured region.
virtual ~FunctionScopeInfo()
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
Record that a weak object was accessed.
SourceLocation PotentialThisCaptureLocation
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, RecordDecl *RD, ImplicitParamDecl *Context, CapturedRegionKind K, unsigned OpenMPLevel)
Retains information about a block that is currently being parsed.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
Expr - This represents one expression.
void removePotentialCapture(Expr *E)
const NamedDecl * getProperty() const
bool HasBranchProtectedScope
Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jump...
bool operator==(const WeakObjectProfileTy &Other) const
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
bool isVLATypeCaptured(const VariableArrayType *VAT) const
Determine whether the given variable-array type has been captured.
An expression that sends a message to the given Objective-C object or class.
void setHasCXXTry(SourceLocation TryLoc)
unsigned short CapRegionKind
The kind of captured region.
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
A list of parameters which have the nonnull attribute and are modified in the function.
VarDecl * CoroutinePromise
The promise object for this coroutine, if any.
CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
void setHasSEHTry(SourceLocation TryLoc)
Encodes a location in the source.
CXXRecordDecl * Lambda
The class that describes the lambda.
SmallVector< Stmt *, 4 > CoroutineStmts
The list of coroutine control flow constructs (co_await, co_yield, co_return) that occur within the f...
bool isValid() const
Return true if this is a valid SourceLocation object.
bool ObjCWarnForNoDesignatedInitChain
This starts true for a method marked as designated initializer and will be set to false if there is a...
StringRef getRegionName() const
A descriptive name for the kind of captured region this is.
Represents a static or instance method of a struct/union/class.
SmallVector< Capture, 4 > Captures
Captures - The captures.
Represents one property declaration in an Objective-C interface.
void addPotentialThisCapture(SourceLocation Loc)
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
bool ObjCShouldCallSuper
A flag that is set when parsing a method that must call super's implementation, such as -dealloc...
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
bool HasOMPDeclareReductionCombiner
True if current scope is for OpenMP declare reduction combiner.
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
Contains all variable-referring-expressions (i.e.
bool ObjCIsSecondaryInit
True when this is an initializer method not marked as a designated initializer within a class that ha...
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
Used to collect all uses of weak objects in a function body.
bool isVLATypeCapture() const
bool HasIndirectGoto
Whether this function contains any indirect gotos.
FunctionScopeInfo(const FunctionScopeInfo &)=default
unsigned CXXThisCaptureIndex
CXXThisCaptureIndex - The (index+1) of the capture of 'this'; zero if 'this' is not captured...
const WeakObjectUseMap & getWeakObjectUses() const
bool isCopyCapture() const
Represents a simple identification of a weak object.
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
detail::InMemoryDirectory::const_iterator E
BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
unsigned short OpenMPLevel
LambdaScopeInfo(DiagnosticsEngine &Diag)
bool isReferenceCapture() const
SourceLocation FirstReturnLoc
First 'return' statement in the current function.
void markSafeWeakUse(const Expr *E)
Record that a given expression is a "safe" access of a weak object (e.g.
RecordDecl * TheRecordDecl
The captured record type.
bool isExactProfile() const
Returns true if the object base specifies a known object in memory, rather than, say, an instance variable or property of another object.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
llvm::DenseMap< VarDecl *, unsigned > CaptureMap
CaptureMap - A map of captured variables to (index+1) into Captures.
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
static bool isEqual(const WeakObjectProfileTy &LHS, const WeakObjectProfileTy &RHS)
Capture(IsThisCapture, bool IsNested, SourceLocation Loc, QualType CaptureType, Expr *Cpy, const bool ByCopy)
unsigned AutoTemplateParameterDepth
If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST const...
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
A list of PartialDiagnostics created but delayed within the current function scope.
Represents a C++ struct/union/class.
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
void setHasEmptyLoopBodies()
static bool classof(const FunctionScopeInfo *FSI)
Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
void addVLATypeCapture(SourceLocation Loc, QualType CaptureType)
Represents a single use of a weak object.
Scope * TheScope
TheScope - This is the scope for the block itself, which contains arguments etc.
bool HasImplicitReturnType
Whether the target type of return statements in this context is deduced (e.g.
const Expr * getUseExpr() const
A reference to a declared variable, function, enum, etc.
~BlockScopeInfo() override
unsigned getNumPotentialVariableCaptures() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
CapturedRegionKind
The different kinds of captured statement.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
ImplicitParamDecl * ContextParam
The implicit parameter for the captured variables.
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const
Represents a C array with a specified size that is not an integer-constant-expression.
void Clear()
Clear out the information in this function scope, making it suitable for reuse.
bool isVariableCapture() const
bool HasBranchIntoScope
Whether this function contains any switches or direct gotos.
void setHasFallthroughStmt()
bool operator==(const WeakUseTy &Other) const