14 #ifndef LLVM_CLANG_SEMA_INITIALIZATION_H 15 #define LLVM_CLANG_SEMA_INITIALIZATION_H 31 #include "llvm/ADT/ArrayRef.h" 32 #include "llvm/ADT/SmallVector.h" 33 #include "llvm/ADT/StringRef.h" 34 #include "llvm/ADT/iterator_range.h" 35 #include "llvm/Support/Casting.h" 43 class CXXBaseSpecifier;
44 class CXXConstructorDecl;
142 mutable unsigned ManglingNumber = 0;
163 bool IsImplicitFieldInit;
167 bool IsDefaultMemberInit;
220 : Kind(Kind), Type(Type) {
227 bool Implicit,
bool DefaultMemberInit)
229 Variable{Member, Implicit, DefaultMemberInit} {}
238 Capture.VarID = VarID;
259 bool Consumed = (Context.
getLangOpts().ObjCAutoRefCount &&
260 Parm->
hasAttr<NSConsumedAttr>());
266 Entity.Parent =
nullptr;
268 = (
static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm));
280 Entity.Parent =
nullptr;
304 BlockVarLoc, Type, NRVO);
347 bool IsInheritedVirtualBase,
359 bool Implicit =
false) {
367 bool Implicit =
false) {
464 return getKind() ==
EK_New && dyn_cast_or_null<IncompleteArrayType>(
513 return Capture.VarID->getName();
534 unsigned dumpImpl(raw_ostream &OS)
const;
586 InitContext Context : 8;
593 : Kind(Kind), Context(Context) {
605 InitLoc, LParenLoc, RParenLoc);
634 IC_CStyleCast, StartLoc, TypeRange.
getBegin(),
642 IC_FunctionalCast, TypeRange.
getBegin(),
649 bool AllowExplicitConvs =
false) {
651 AllowExplicitConvs? IC_ExplicitConvs : IC_Normal,
652 InitLoc, EqualLoc, EqualLoc);
664 bool isImplicit =
false) {
666 InitLoc, LParenLoc, RParenLoc);
673 if (!Init)
return CreateDefault(Loc);
676 if (isa<InitListExpr>(Init))
688 return Context >= IC_StaticCast;
693 return Context >= IC_CStyleCast;
698 return Context == IC_CStyleCast;
703 return Context == IC_FunctionalCast;
722 assert(Kind == IK_Copy &&
"Only copy initialization has an '='");
737 return !isCopyInit() || Context == IC_ExplicitConvs;
743 return Kind == IK_Direct || Kind == IK_Value || Kind == IK_DirectList;
750 assert(hasParenOrBraceRange() &&
"Only direct, value, and direct-list " 751 "initialization have parentheses or " 1084 std::string ZeroInitializationFixit;
1091 ZeroInitializationFixit = Fixit;
1092 ZeroInitializationFixitLoc = L;
1124 bool TopLevelOfInitList =
false,
1125 bool TreatUnavailableAsInvalid =
true);
1128 bool TopLevelOfInitList,
bool TreatUnavailableAsInvalid);
1163 bool Diagnose(
Sema &S,
1169 enum SequenceKind
getKind()
const {
return SequenceKind; }
1175 explicit operator bool()
const {
return !Failed(); }
1178 bool Failed()
const {
return SequenceKind == FailedSequence; }
1191 bool isDirectReferenceBinding()
const;
1194 bool isAmbiguous()
const;
1198 bool isConstructorInitialization()
const;
1208 bool *isInitializerConstant,
1209 APValue *ConstantValue)
const;
1218 bool HadMultipleCandidates);
1227 void AddDerivedToBaseCastStep(
QualType BaseType,
1235 void AddReferenceBindingStep(
QualType T,
bool BindingTemporary);
1247 void AddExtraneousCopyToTemporary(
QualType T);
1258 bool HadMultipleCandidates);
1262 void AddQualificationConversionStep(
QualType Ty,
1267 void AddAtomicConversionStep(
QualType Ty);
1273 void AddLValueToRValueStep(
QualType Ty);
1277 QualType T,
bool TopLevelOfInitList =
false);
1280 void AddListInitializationStep(
QualType T);
1290 bool HadMultipleCandidates,
1291 bool FromInitList,
bool AsInitList);
1294 void AddZeroInitializationStep(
QualType T);
1301 void AddCAssignmentStep(
QualType T);
1304 void AddStringInitStep(
QualType T);
1308 void AddObjCObjectConversionStep(
QualType T);
1314 void AddArrayInitStep(
QualType T,
bool IsGNUExtension);
1317 void AddParenthesizedArrayInitStep(
QualType T);
1320 void AddPassByIndirectCopyRestoreStep(
QualType T,
bool shouldCopy);
1324 void AddProduceObjCObjectStep(
QualType T);
1328 void AddStdInitializerListConstructionStep(
QualType T);
1332 void AddOCLSamplerInitStep(
QualType T);
1336 void AddOCLZeroOpaqueTypeStep(
QualType T);
1340 void AddOCLIntelSubgroupAVCZeroInitStep(
QualType T);
1348 SequenceKind = FailedSequence;
1349 this->Failure = Failure;
1350 assert((Failure != FK_Incomplete || !FailedIncompleteType.
isNull()) &&
1351 "Incomplete type failure requires a type!");
1361 return FailedCandidateSet;
1367 return FailedOverloadResult;
1373 FailedIncompleteType = IncompleteType;
1374 SetFailed(FK_Incomplete);
1379 assert(Failed() &&
"Not an initialization failure!");
1385 void dump(raw_ostream &OS)
const;
1394 #endif // LLVM_CLANG_SEMA_INITIALIZATION_H Perform a derived-to-base cast, producing an lvalue.
Defines the clang::ASTContext interface.
QualType getVariableArrayDecayedType(QualType Ty) const
Returns a vla type where known sizes are replaced with [*].
Represents a function declaration or definition.
InitListExpr * WrappingSyntacticList
When Kind = SK_RewrapInitList, the syntactic form of the wrapping list.
step_iterator step_begin() const
static InitializationKind CreateDirectList(SourceLocation InitLoc, SourceLocation LBraceLoc, SourceLocation RBraceLoc)
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void SetZeroInitializationFixit(const std::string &Fixit, SourceLocation L)
Call for initializations are invalid but that would be valid zero initialzations if Fixit was applied...
A (possibly-)qualified type.
unsigned Index
When Kind == EK_ArrayElement, EK_VectorElement, or EK_ComplexElement, the index of the array or vecto...
DeclarationName getName() const
Retrieve the name of the entity being initialized.
Produce an Objective-C object pointer.
Initializing char array with wide string literal.
static InitializedEntity InitializeException(SourceLocation ThrowLoc, QualType Type, bool NRVO)
Create the initialization entity for an exception object.
Perform an implicit conversion sequence without narrowing.
An initialization that "converts" an Objective-C object (not a point to an object) to another Objecti...
Perform a qualification conversion, producing an rvalue.
C Language Family Type Representation.
static InitializedEntity InitializeMember(FieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
uintptr_t Base
When Kind == EK_Base, the base specifier that provides the base class.
FailureKind getFailureKind() const
Determine why initialization failed.
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
The base class of the type hierarchy.
The entity being initialized is a variable.
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
Overloading for a user-defined conversion failed.
TypeSourceInfo * getTypeSourceInfo() const
Retrieve complete type-source information for the object being constructed, if known.
A container of type source information.
Perform a derived-to-base cast, producing an xvalue.
SourceLocation getCaptureLoc() const
Determine the location of the capture when initializing field from a captured variable in a lambda...
constexpr XRayInstrMask Function
The entity being initialized is a base member subobject.
List-copy-initialization chose an explicit constructor.
The entity being initialized is the result of a statement expression.
static InitializedEntity InitializeMemberFromDefaultMemberInitializer(FieldDecl *Member)
Create the initialization entity for a default member initializer.
Represents a C++ constructor within a class.
static InitializedEntity InitializeTemporary(QualType Type)
Create the initialization entity for a temporary.
The entity being initialized is a function parameter; function is member of group of audited CF APIs...
Initialize an OpenCL sampler from an integer.
static InitializedEntity InitializeBase(ASTContext &Context, const CXXBaseSpecifier *Base, bool IsInheritedVirtualBase, const InitializedEntity *Parent=nullptr)
Create the initialization entity for a base class subobject.
Represents a variable declaration or definition.
Initialization by string.
Array initialization by elementwise copy.
SourceLocation getEqualLoc() const
Retrieve the location of the equal sign for copy initialization (if present).
ObjCMethodDecl - Represents an instance or class method declaration.
Non-const lvalue reference binding to an lvalue of unrelated type.
SourceLocation getThrowLoc() const
Determine the location of the 'throw' keyword when initializing an exception object.
static InitializedEntity InitializeResult(SourceLocation ReturnLoc, QualType Type, bool NRVO)
Create the initialization entity for the result of a function.
Perform a derived-to-base cast, producing an rvalue.
static InitializationKind CreateDirectList(SourceLocation InitLoc)
EntityKind getKind() const
Determine the kind of initialization.
Initializing char array with UTF-8 string literal.
void setElementIndex(unsigned Index)
If this is already the initializer for an array or vector element, sets the element index...
Represents a parameter to a function.
The entity being initialized is a temporary object.
const CXXBaseSpecifier * getBaseSpecifier() const
Retrieve the base specifier.
Non-const lvalue reference binding to a vector element.
bool isImplicitMemberInitializer() const
Is this the implicit initialization of a member of a class from a defaulted constructor?
Construct a std::initializer_list from an initializer list.
Trying to take the address of a function that doesn't support having its address taken.
One of these records is kept for each identifier that is lexed.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
bool isInheritedVirtualBase() const
Return whether the base is an inherited virtual base.
ImplicitConversionSequence * ICS
When Kind = SK_ConversionSequence, the implicit conversion sequence.
static SourceLocation getFromRawEncoding(unsigned Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
SourceLocation getBeginLoc() const LLVM_READONLY
Represents a member of a struct/union/class.
Rewrap the single-element initializer list for a reference.
FieldDecl * getAnonField() const
StringRef getCapturedVarName() const
For a lambda capture, return the capture's name.
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Perform initialization via a constructor taking a single std::initializer_list argument.
Describes an C or C++ initializer list.
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo)
Create the initialization entity for a temporary.
SourceRange getParenOrBraceRange() const
Retrieve the source range containing the locations of the open and closing parentheses or braces for ...
EntityKind
Specifies the kind of entity being initialized.
static InitializedEntity InitializeDelegation(QualType Type)
Create the initialization entity for a delegated constructor.
StepKind Kind
The kind of conversion or initialization step we are taking.
bool isImplicitValueInit() const
Determine whether this initialization is an implicit value-initialization, e.g., as occurs during agg...
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type...
OverloadCandidateSet & getFailedCandidateSet()
Retrieve a reference to the candidate set when overload resolution fails.
unsigned getElementIndex() const
If this is an array, vector, or complex number element, get the element's index.
Variable-length array must not have an initializer.
Initialization of an incomplete type.
The entity being initialized is a non-static data member subobject.
static InitializationKind CreateValue(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc, bool isImplicit=false)
Create a value initialization.
Unwrap the single-element initializer list for a reference.
SmallVectorImpl< Step >::const_iterator step_iterator
The entity being initialized is an element of a vector.
Perform initialization via a constructor.
Perform a user-defined conversion, either via a conversion function or via a constructor.
Implicit conversion failed.
The entity being initialized is a function parameter.
bool hasParenOrBraceRange() const
Determine whether this initialization has a source range containing the locations of open and closing...
ValueDecl * getDecl() const
Retrieve the variable, parameter, or field being initialized.
static InitializedEntity InitializeNew(SourceLocation NewLoc, QualType Type)
Create the initialization entity for an object allocated via new.
Perform an implicit conversion sequence.
Sema - This implements semantic analysis and AST building for C.
Overloading for list-initialization by constructor failed.
Perform list-initialization without a constructor.
Reference binding drops qualifiers.
Non-const lvalue reference binding to a bit-field.
Cannot resolve the address of an overloaded function.
static InitializedEntity InitializeTemporary(TypeSourceInfo *TypeInfo, QualType Type)
Create the initialization entity for a temporary.
bool isFunctionalCast() const
Determine whether this is a functional-style cast.
unsigned allocateManglingNumber() const
The entity being initialized is a field of block descriptor for the copied-in c++ object...
static InitializedEntity InitializeMember(IndirectFieldDecl *Member, const InitializedEntity *Parent=nullptr, bool Implicit=false)
Create the initialization entity for a member subobject.
Initializing wide char array with incompatible wide string literal.
The entity being initialized is the real or imaginary part of a complex number.
Implicit conversion failed.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
Defines the clang::LangOptions interface.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Initializing char8_t array with plain string literal.
static InitializationKind CreateFunctionalCast(SourceRange TypeRange, bool InitList)
Create a direct initialization for a functional cast.
void dump() const
Dump a representation of the initialized entity to standard error, for debugging purposes.
Scalar initialized from a parenthesized initializer list.
uintptr_t Parameter
When Kind == EK_Parameter, the ParmVarDecl, with the low bit indicating whether the parameter is "con...
The entity being initialized is an object (or array of objects) allocated via new.
Perform a qualification conversion, producing an xvalue.
OverloadingResult getFailedOverloadResult() const
Get the overloading result, for when the initialization sequence failed due to a bad overload...
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
Initializing a wide char array with narrow string literal.
Resolve the address of an overloaded function to a specific function declaration. ...
The entity being initialized is an exception object that is being thrown.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isExplicitCast() const
Determine whether this initialization is an explicit cast.
Initializer has a placeholder type which cannot be resolved by initialization.
SourceLocation getEnd() const
SourceLocation getLocation() const
Retrieve the location at which initialization is occurring.
bool AllowExplicit() const
Retrieve whether this initialization allows the use of explicit constructors.
SourceLocation getReturnLoc() const
Determine the location of the 'return' keyword when initializing the result of a function call...
The result type of a method or function.
Pass an object by indirect restore.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
InitKind getKind() const
Determine the initialization kind.
SourceLocation getEndLoc() const LLVM_READONLY
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
FailureKind
Describes why initialization failed.
Too many initializers for scalar.
List initialization failed at some point.
Perform a conversion adding _Atomic to a type.
bool allowExplicitConversionFunctionsInRefBinding() const
Retrieve whether this initialization allows the use of explicit conversion functions when binding a r...
Perform a qualification conversion, producing an lvalue.
Reference binding to an lvalue.
ImplicitConversionSequence - Represents an implicit conversion sequence, which may be a standard conv...
bool isParameterKind() const
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
bool allowsNRVO() const
Determine whether this initialization allows the named return value optimization, which also applies ...
SequenceKind
Describes the kind of initialization sequence computed.
Array indexing for initialization by elementwise copy.
Encodes a location in the source.
Reference initialization from an initializer list.
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
bool isCStyleOrFunctionalCast() const
Determine whether this initialization is a C-style cast.
StepKind
Describes the kind of a particular step in an initialization sequence.
llvm::iterator_range< step_iterator > step_range
TypeSourceInfo * TypeInfo
When Kind == EK_Temporary or EK_CompoundLiteralInit, the type source information for the temporary...
OverloadingResult
OverloadingResult - Capture the result of performing overload resolution.
VD Variable
When Kind == EK_Variable, EK_Member or EK_Binding, the variable.
static InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
Initialization of some unused destination type with an initializer list.
static InitializedEntity InitializeCompoundLiteralInit(TypeSourceInfo *TSI)
Create the entity for a compound literal initializer.
The entity being initialized is the result of a function call.
The entity being implicitly initialized back to the formal result type.
Zero-initialize the object.
The entity being initialized is the initializer for a compound literal.
Describes the kind of initialization being performed, along with location information for tokens rela...
The entity being initialized is an element of an array.
Reference initialized from a parenthesized initializer list.
Overloading for initialization by constructor failed.
An optional copy of a temporary object to another temporary object, which is permitted (but not requi...
bool HadMultipleCandidates
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13...
static InitializationKind CreateCast(SourceRange TypeRange)
Create a direct initialization due to a cast that isn't a C-style or functional cast.
Pass an object by indirect copy-and-restore.
Defines various enumerations that describe declaration and type specifiers.
A POD class for pairing a NamedDecl* with an access specifier.
Rvalue reference binding to an lvalue.
void SetFailed(FailureKind Failure)
Note that this initialization sequence failed.
Array must be initialized with an initializer list or a string literal.
Optional< types::ID > Type
QualType getType() const
Retrieve type being initialized.
Dataflow Directional Tag Classes.
Non-constant array initializer.
void setIncompleteTypeFailure(QualType IncompleteType)
Note that this initialization sequence failed due to an incomplete type.
A single step in the initialization sequence.
static InitializedEntity InitializeParameter(ASTContext &Context, QualType Type, bool Consumed)
Create the initialization entity for a parameter that is only known by its type.
Array must be initialized with an initializer list or a wide string literal.
Too many initializers provided for a reference.
Perform a load from a glvalue, producing an rvalue.
Represents a field injected from an anonymous union/struct into the parent scope. ...
const InitializedEntity * getParent() const
Retrieve the parent of the entity being initialized, when the initialization itself is occurring with...
The name of a declaration.
Array initialization (from an array rvalue) as a GNU extension.
static InitializationKind CreateCStyleCast(SourceLocation StartLoc, SourceRange TypeRange, bool InitList)
Create a direct initialization for a C-style cast.
Overloading due to reference initialization failed.
Array must be initialized with an initializer list.
The entity being initialized is a structured binding of a decomposition declaration.
Reference binding failed.
step_iterator step_end() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
Represents a base class of a C++ class.
static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc, QualType Type)
Direct-initialization from a reference-related object in the final stage of class copy-initialization...
bool Failed() const
Determine whether the initialization sequence is invalid.
Defines the clang::SourceLocation class and associated facilities.
Describes the sequence of initializations required to initialize a given object or reference with a s...
static InitializedEntity InitializeRelatedResult(ObjCMethodDecl *MD, QualType Type)
Create the initialization entity for a related result.
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Perform initialization via a constructor, taking arguments from a single InitListExpr.
SourceRange getRange() const
Retrieve the source range that covers the initialization.
bool isParameterConsumed() const
Determine whether this initialization consumes the parameter.
The entity being initialized is a field of block descriptor for the copied-in lambda object that's us...
The entity being initialized is the field that captures a variable in a lambda.
void setSequenceKind(enum SequenceKind SK)
Set the kind of sequence computed.
A dependent initialization, which could not be type-checked due to the presence of dependent types or...
bool isCStyleCast() const
Determine whether this is a C-style cast.
void setParameterCFAudited()
ObjCMethodDecl * MethodDecl
When Kind == EK_RelatedResult, the ObjectiveC method where result type was implicitly changed to acco...
Reference binding to a temporary.
The initialization is being done by a delegating constructor.
Array initialization (from an array rvalue).
InitKind
The kind of initialization being performed.
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm, QualType Type)
Create the initialization entity for a parameter, but use another type.
Default-initialization of a 'const' object.
A trivial tuple used to represent a source range.
Describes an entity that is being initialized.
bool isDefaultMemberInitializer() const
Is this the default member initializer of a member (specified inside the class definition)?
ObjCMethodDecl * getMethodDecl() const
Retrieve the ObjectiveC method being initialized.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
bool isVariableLengthArrayNew() const
Determine whether this is an array new with an unknown bound.
Direct list-initialization.
Array initialization from a parenthesized initializer list.
static InitializedEntity InitializeBinding(VarDecl *Binding)
Create the initialization entity for a structured binding.
QualType getType() const
Return the type wrapped by this type source info.
Non-const lvalue reference binding to a temporary.