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"
93 llvm::TinyPtrVector<const Stmt*>
Stmts;
206 struct SwitchInfo : llvm::PointerIntPair<SwitchStmt *, 1, bool> {
280 class WeakObjectProfileTy {
287 using BaseInfoTy = llvm::PointerIntPair<const NamedDecl *, 1, bool>;
297 static BaseInfoTy getBaseInfo(
const Expr *BaseE);
299 inline WeakObjectProfileTy();
300 static inline WeakObjectProfileTy getSentinel();
323 return Base.getInt();
327 return Base ==
Other.Base && Property ==
Other.Property;
337 using Pair = std::pair<BaseInfoTy, const NamedDecl *>;
339 return llvm::DenseMapInfo<Pair>::getHashValue(Pair(Val.Base,
343 static bool isEqual(
const WeakObjectProfileTy &LHS,
344 const WeakObjectProfileTy &RHS) {
357 llvm::PointerIntPair<const Expr *, 1, bool> Rep;
367 return Rep ==
Other.Rep;
414 return ErrorTrap.hasUnrecoverableErrorOccurred();
420 template <
typename ExprT>
433 return WeakObjectUses;
507 "first coroutine statement location already set");
510 llvm::StringSwitch<unsigned char>(
Keyword)
521 &&
"no coroutine statement available");
532 llvm_unreachable(
"FirstCoroutineStmtKind has an invalid value");
537 "we already have valid suspend points");
546 assert(Initial && Final &&
"suspend points cannot be null");
575 Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_VLA
597 LLVM_PREFERRED_TYPE(CaptureKind)
602 LLVM_PREFERRED_TYPE(
bool)
606 LLVM_PREFERRED_TYPE(
bool)
607 unsigned CapturesThis : 1;
611 LLVM_PREFERRED_TYPE(
bool)
612 unsigned ODRUsed : 1;
616 LLVM_PREFERRED_TYPE(
bool)
617 unsigned NonODRUsed : 1;
621 LLVM_PREFERRED_TYPE(
bool)
628 :
CapturedVar(Var), Loc(Loc), EllipsisLoc(EllipsisLoc),
629 CaptureType(CaptureType), Kind(
Block ? Cap_Block
632 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
633 NonODRUsed(
false), Invalid(Invalid) {}
637 QualType CaptureType,
const bool ByCopy,
bool Invalid)
638 : Loc(Loc), CaptureType(CaptureType),
639 Kind(ByCopy ? Cap_ByCopy : Cap_ByRef), Nested(IsNested),
646 :
CapturedVLA(VLA), Loc(Loc), CaptureType(CaptureType), Kind(Cap_VLA),
647 Nested(IsNested), CapturesThis(
false), ODRUsed(
false),
742 EllipsisLoc, CaptureType,
Invalid));
749 false, Loc, CaptureType));
773 assert(
isCaptured(Var) &&
"Variable has not been captured");
778 llvm::DenseMap<ValueDecl *, unsigned>::const_iterator Known =
780 assert(Known !=
CaptureMap.end() &&
"Variable has not been captured");
854 return "default captured statement";
856 return "Objective-C @finally statement";
858 return "OpenMP region";
860 llvm_unreachable(
"Invalid captured region kind!");
1077 llvm::function_ref<
void(
ValueDecl *,
Expr *)> Callback)
const;
1082FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
1085FunctionScopeInfo::WeakObjectProfileTy
1086FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
1087 FunctionScopeInfo::WeakObjectProfileTy
Result;
1088 Result.Base.setInt(
true);
1092template <
typename ExprT>
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the clang::Expr interface and subclasses for C++ expressions.
Result
Implement __builtin_bit_cast and related operations.
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.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
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...
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.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Scope - A scope is a transient data structure that is used while parsing the program.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
SwitchStmt - This represents a 'switch' stmt.
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.
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.
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.
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
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.
SmallVector< NamedDecl *, 4 > LocalPacks
Packs introduced by this, if any.
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.
FPOptions InitialFPFeatures
FP options at the beginning of the compound statement, prior to any pragma.
bool HasEmptyLoopBodies
Whether this compound statement 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 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.
void setHasObjCTry(SourceLocation TryLoc)
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 representing 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::@340304006310276167163023075110222134352007243353 FirstTryType
bool ObjCWarnForNoInitDelegation
This starts true for a secondary initializer method and will be set to false if there is an invocatio...
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
Used to collect all uses of weak objects in a function body.
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 statement 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)
Expr * SYCLKernelLaunchIdExpr
An unresolved identifier lookup expression for an implicit call to a SYCL kernel launch function in a...
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)
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?
bool lambdaCaptureShouldBeConst() const
void clearPotentialCaptures()
bool BeforeCompoundStatement
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.
void addPotentialThisCapture(SourceLocation Loc)
ParmVarDecl * ExplicitObjectParameter
llvm::SmallPtrSet< VarDecl *, 4 > CUDAPotentialODRUsedVars
Variables that are potentially ODR-used in CUDA/HIP.
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.
llvm::SmallPtrSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
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)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
CapturedRegionKind
The different kinds of captured statement.
@ Keyword
The name has been typo-corrected to a keyword.
ActionResult< Expr * > ExprResult
@ Other
Other implicit parameter.
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
SmallVector< NamedDecl *, 4 > TemplateParams
Store the list of the template parameters for a generic lambda or an abbreviated function template.
SwitchInfo(SwitchStmt *Switch, DeclContext *DC)
DeclContext * EnclosingDC
Contains all of the variables defined in this lambda that shadow variables that were defined in paren...
const NamedDecl * ShadowedDecl