Author: Vlad Serebrennikov Date: 2023-11-04T08:43:59+03:00 New Revision: 0fea0d2f3b5e5be011e229cdddc7540095ff9236
URL: https://github.com/llvm/llvm-project/commit/0fea0d2f3b5e5be011e229cdddc7540095ff9236 DIFF: https://github.com/llvm/llvm-project/commit/0fea0d2f3b5e5be011e229cdddc7540095ff9236.diff LOG: [clang][NFC] Annotate DeclBase.h with `preferred_type` This patch adds `preferred_type` annotations to `Decl` and `DeclContext` bit-fields. Those annotations help debuggers reason about the type of the value stored in bit-field. Added: Modified: clang/include/clang/AST/DeclBase.h Removed: ################################################################################ diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index fdc59ac7419d9e3..5b1038582bc6747 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -16,6 +16,7 @@ #include "clang/AST/ASTDumperUtils.h" #include "clang/AST/AttrIterator.h" #include "clang/AST/DeclarationName.h" +#include "clang/AST/SelectorLocationsKind.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" @@ -284,31 +285,38 @@ class alignas(8) Decl { SourceLocation Loc; /// DeclKind - This indicates which class this is. + LLVM_PREFERRED_TYPE(Kind) unsigned DeclKind : 7; /// InvalidDecl - This indicates a semantic error occurred. + LLVM_PREFERRED_TYPE(bool) unsigned InvalidDecl : 1; /// HasAttrs - This indicates whether the decl has attributes or not. + LLVM_PREFERRED_TYPE(bool) unsigned HasAttrs : 1; /// Implicit - Whether this declaration was implicitly generated by /// the implementation rather than explicitly written by the user. + LLVM_PREFERRED_TYPE(bool) unsigned Implicit : 1; /// Whether this declaration was "used", meaning that a definition is /// required. + LLVM_PREFERRED_TYPE(bool) unsigned Used : 1; /// Whether this declaration was "referenced". /// The diff erence with 'Used' is whether the reference appears in a /// evaluated context or not, e.g. functions used in uninstantiated templates /// are regarded as "referenced" but not "used". + LLVM_PREFERRED_TYPE(bool) unsigned Referenced : 1; /// Whether this declaration is a top-level declaration (function, /// global variable, etc.) that is lexically inside an objc container /// definition. + LLVM_PREFERRED_TYPE(bool) unsigned TopLevelDeclInObjCContainer : 1; /// Whether statistic collection is enabled. @@ -326,15 +334,19 @@ class alignas(8) Decl { /// Access - Used by C++ decls for the access specifier. // NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum + LLVM_PREFERRED_TYPE(AccessSpecifier) unsigned Access : 2; /// Whether this declaration was loaded from an AST file. + LLVM_PREFERRED_TYPE(bool) unsigned FromASTFile : 1; /// IdentifierNamespace - This specifies what IDNS_* namespace this lives in. + LLVM_PREFERRED_TYPE(IdentifierNamespace) unsigned IdentifierNamespace : 14; /// If 0, we have not computed the linkage of this declaration. + LLVM_PREFERRED_TYPE(Linkage) mutable unsigned CacheValidAndLinkage : 3; /// Allocate memory for a deserialized declaration. @@ -1443,35 +1455,42 @@ class DeclContext { class DeclContextBitfields { friend class DeclContext; /// DeclKind - This indicates which class this is. + LLVM_PREFERRED_TYPE(Decl::Kind) uint64_t DeclKind : 7; /// Whether this declaration context also has some external /// storage that contains additional declarations that are lexically /// part of this context. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t ExternalLexicalStorage : 1; /// Whether this declaration context also has some external /// storage that contains additional declarations that are visible /// in this context. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t ExternalVisibleStorage : 1; /// Whether this declaration context has had externally visible /// storage added since the last lookup. In this case, \c LookupPtr's /// invariant may not hold and needs to be fixed before we perform /// another lookup. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t NeedToReconcileExternalVisibleStorage : 1; /// If \c true, this context may have local lexical declarations /// that are missing from the lookup table. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t HasLazyLocalLexicalLookups : 1; /// If \c true, the external source may have lexical declarations /// that are missing from the lookup table. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t HasLazyExternalLexicalLookups : 1; /// If \c true, lookups should only return identifier from /// DeclContext scope (for example TranslationUnit). Used in /// LookupQualifiedName() + LLVM_PREFERRED_TYPE(bool) mutable uint64_t UseQualifiedLookup : 1; }; @@ -1484,38 +1503,47 @@ class DeclContext { class TagDeclBitfields { friend class TagDecl; /// For the bits in DeclContextBitfields + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; /// The TagKind enum. + LLVM_PREFERRED_TYPE(TagTypeKind) uint64_t TagDeclKind : 3; /// True if this is a definition ("struct foo {};"), false if it is a /// declaration ("struct foo;"). It is not considered a definition /// until the definition has been fully processed. + LLVM_PREFERRED_TYPE(bool) uint64_t IsCompleteDefinition : 1; /// True if this is currently being defined. + LLVM_PREFERRED_TYPE(bool) uint64_t IsBeingDefined : 1; /// True if this tag declaration is "embedded" (i.e., defined or declared /// for the very first time) in the syntax of a declarator. + LLVM_PREFERRED_TYPE(bool) uint64_t IsEmbeddedInDeclarator : 1; /// True if this tag is free standing, e.g. "struct foo;". + LLVM_PREFERRED_TYPE(bool) uint64_t IsFreeStanding : 1; /// Indicates whether it is possible for declarations of this kind /// to have an out-of-date definition. /// /// This option is only enabled when modules are enabled. + LLVM_PREFERRED_TYPE(bool) uint64_t MayHaveOutOfDateDef : 1; /// Has the full definition of this type been required by a use somewhere in /// the TU. + LLVM_PREFERRED_TYPE(bool) uint64_t IsCompleteDefinitionRequired : 1; /// Whether this tag is a definition which was demoted due to /// a module merge. + LLVM_PREFERRED_TYPE(bool) uint64_t IsThisDeclarationADemotedDefinition : 1; }; @@ -1528,6 +1556,7 @@ class DeclContext { class EnumDeclBitfields { friend class EnumDecl; /// For the bits in TagDeclBitfields. + LLVM_PREFERRED_TYPE(TagDeclBitfields) uint64_t : NumTagDeclBits; /// Width in bits required to store all the non-negative @@ -1540,19 +1569,23 @@ class DeclContext { /// True if this tag declaration is a scoped enumeration. Only /// possible in C++11 mode. + LLVM_PREFERRED_TYPE(bool) uint64_t IsScoped : 1; /// If this tag declaration is a scoped enum, /// then this is true if the scoped enum was declared using the class /// tag, false if it was declared with the struct tag. No meaning is /// associated if this tag declaration is not a scoped enum. + LLVM_PREFERRED_TYPE(bool) uint64_t IsScopedUsingClassTag : 1; /// True if this is an enumeration with fixed underlying type. Only /// possible in C++11, Microsoft extensions, or Objective C mode. + LLVM_PREFERRED_TYPE(bool) uint64_t IsFixed : 1; /// True if a valid hash is stored in ODRHash. + LLVM_PREFERRED_TYPE(bool) uint64_t HasODRHash : 1; }; @@ -1565,49 +1598,64 @@ class DeclContext { class RecordDeclBitfields { friend class RecordDecl; /// For the bits in TagDeclBitfields. + LLVM_PREFERRED_TYPE(TagDeclBitfields) uint64_t : NumTagDeclBits; /// This is true if this struct ends with a flexible /// array member (e.g. int X[]) or if this union contains a struct that does. /// If so, this cannot be contained in arrays or other structs as a member. + LLVM_PREFERRED_TYPE(bool) uint64_t HasFlexibleArrayMember : 1; /// Whether this is the type of an anonymous struct or union. + LLVM_PREFERRED_TYPE(bool) uint64_t AnonymousStructOrUnion : 1; /// This is true if this struct has at least one member /// containing an Objective-C object pointer type. + LLVM_PREFERRED_TYPE(bool) uint64_t HasObjectMember : 1; /// This is true if struct has at least one member of /// 'volatile' type. + LLVM_PREFERRED_TYPE(bool) uint64_t HasVolatileMember : 1; /// Whether the field declarations of this record have been loaded /// from external storage. To avoid unnecessary deserialization of /// methods/nested types we allow deserialization of just the fields /// when needed. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t LoadedFieldsFromExternalStorage : 1; /// Basic properties of non-trivial C structs. + LLVM_PREFERRED_TYPE(bool) uint64_t NonTrivialToPrimitiveDefaultInitialize : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t NonTrivialToPrimitiveCopy : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t NonTrivialToPrimitiveDestroy : 1; /// The following bits indicate whether this is or contains a C union that /// is non-trivial to default-initialize, destruct, or copy. These bits /// imply the associated basic non-triviality predicates declared above. + LLVM_PREFERRED_TYPE(bool) uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1; /// Indicates whether this struct is destroyed in the callee. + LLVM_PREFERRED_TYPE(bool) uint64_t ParamDestroyedInCallee : 1; /// Represents the way this type is passed to a function. + LLVM_PREFERRED_TYPE(RecordArgPassingKind) uint64_t ArgPassingRestrictions : 2; /// Indicates whether this struct has had its field layout randomized. + LLVM_PREFERRED_TYPE(bool) uint64_t IsRandomized : 1; /// True if a valid hash is stored in ODRHash. This should shave off some @@ -1624,10 +1672,12 @@ class DeclContext { class OMPDeclareReductionDeclBitfields { friend class OMPDeclareReductionDecl; /// For the bits in DeclContextBitfields + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; /// Kind of initializer, /// function call or omp_priv<init_expr> initialization. + LLVM_PREFERRED_TYPE(OMPDeclareReductionInitKind) uint64_t InitializerKind : 2; }; @@ -1644,71 +1694,99 @@ class DeclContext { /// For DeductionCandidateKind friend class CXXDeductionGuideDecl; /// For the bits in DeclContextBitfields. + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; + LLVM_PREFERRED_TYPE(StorageClass) uint64_t SClass : 3; + LLVM_PREFERRED_TYPE(bool) uint64_t IsInline : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsInlineSpecified : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsVirtualAsWritten : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsPure : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasInheritedPrototype : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasWrittenPrototype : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsDeleted : 1; /// Used by CXXMethodDecl + LLVM_PREFERRED_TYPE(bool) uint64_t IsTrivial : 1; /// This flag indicates whether this function is trivial for the purpose of /// calls. This is meaningful only when this function is a copy/move /// constructor or a destructor. + LLVM_PREFERRED_TYPE(bool) uint64_t IsTrivialForCall : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsDefaulted : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsExplicitlyDefaulted : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasDefaultedFunctionInfo : 1; /// For member functions of complete types, whether this is an ineligible /// special member function or an unselected destructor. See /// [class.mem.special]. + LLVM_PREFERRED_TYPE(bool) uint64_t IsIneligibleOrNotSelected : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t HasImplicitReturnZero : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsLateTemplateParsed : 1; /// Kind of contexpr specifier as defined by ConstexprSpecKind. + LLVM_PREFERRED_TYPE(ConstexprSpecKind) uint64_t ConstexprKind : 2; + LLVM_PREFERRED_TYPE(bool) uint64_t BodyContainsImmediateEscalatingExpression : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t InstantiationIsPending : 1; /// Indicates if the function uses __try. + LLVM_PREFERRED_TYPE(bool) uint64_t UsesSEHTry : 1; /// Indicates if the function was a definition /// but its body was skipped. + LLVM_PREFERRED_TYPE(bool) uint64_t HasSkippedBody : 1; /// Indicates if the function declaration will /// have a body, once we're done parsing it. + LLVM_PREFERRED_TYPE(bool) uint64_t WillHaveBody : 1; /// Indicates that this function is a multiversioned /// function using attribute 'target'. + LLVM_PREFERRED_TYPE(bool) uint64_t IsMultiVersion : 1; /// Only used by CXXDeductionGuideDecl. Indicates the kind /// of the Deduction Guide that is implicitly generated /// (used during overload resolution). + LLVM_PREFERRED_TYPE(DeductionCandidate) uint64_t DeductionCandidateKind : 2; /// Store the ODRHash after first calculation. + LLVM_PREFERRED_TYPE(bool) uint64_t HasODRHash : 1; /// Indicates if the function uses Floating Point Constrained Intrinsics + LLVM_PREFERRED_TYPE(bool) uint64_t UsesFPIntrin : 1; // Indicates this function is a constrained friend, where the constraint // refers to an enclosing template for hte purposes of [temp.friend]p9. + LLVM_PREFERRED_TYPE(bool) uint64_t FriendConstraintRefersToEnclosingTemplate : 1; }; @@ -1721,6 +1799,7 @@ class DeclContext { class CXXConstructorDeclBitfields { friend class CXXConstructorDecl; /// For the bits in FunctionDeclBitfields. + LLVM_PREFERRED_TYPE(FunctionDeclBitfields) uint64_t : NumFunctionDeclBits; /// 20 bits to fit in the remaining available space. @@ -1729,12 +1808,15 @@ class DeclContext { /// will need to be shrunk if some bit is added to NumDeclContextBitfields, /// NumFunctionDeclBitfields or CXXConstructorDeclBitfields. uint64_t NumCtorInitializers : 17; + LLVM_PREFERRED_TYPE(bool) uint64_t IsInheritingConstructor : 1; /// Whether this constructor has a trail-allocated explicit specifier. + LLVM_PREFERRED_TYPE(bool) uint64_t HasTrailingExplicitSpecifier : 1; /// If this constructor does't have a trail-allocated explicit specifier. /// Whether this constructor is explicit specified. + LLVM_PREFERRED_TYPE(bool) uint64_t IsSimpleExplicit : 1; }; @@ -1748,43 +1830,56 @@ class DeclContext { friend class ObjCMethodDecl; /// For the bits in DeclContextBitfields. + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; /// The conventional meaning of this method; an ObjCMethodFamily. /// This is not serialized; instead, it is computed on demand and /// cached. + LLVM_PREFERRED_TYPE(ObjCMethodFamily) mutable uint64_t Family : ObjCMethodFamilyBitWidth; /// instance (true) or class (false) method. + LLVM_PREFERRED_TYPE(bool) uint64_t IsInstance : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsVariadic : 1; /// True if this method is the getter or setter for an explicit property. + LLVM_PREFERRED_TYPE(bool) uint64_t IsPropertyAccessor : 1; /// True if this method is a synthesized property accessor stub. + LLVM_PREFERRED_TYPE(bool) uint64_t IsSynthesizedAccessorStub : 1; /// Method has a definition. + LLVM_PREFERRED_TYPE(bool) uint64_t IsDefined : 1; /// Method redeclaration in the same interface. + LLVM_PREFERRED_TYPE(bool) uint64_t IsRedeclaration : 1; /// Is redeclared in the same interface. + LLVM_PREFERRED_TYPE(bool) mutable uint64_t HasRedeclaration : 1; /// \@required/\@optional + LLVM_PREFERRED_TYPE(ObjCImplementationControl) uint64_t DeclImplementation : 2; /// in, inout, etc. + LLVM_PREFERRED_TYPE(Decl::ObjCDeclQualifier) uint64_t objcDeclQualifier : 7; /// Indicates whether this method has a related result type. + LLVM_PREFERRED_TYPE(bool) uint64_t RelatedResultType : 1; /// Whether the locations of the selector identifiers are in a /// "standard" position, a enum SelectorLocationsKind. + LLVM_PREFERRED_TYPE(SelectorLocationsKind) uint64_t SelLocsKind : 2; /// Whether this method overrides any other in the class hierarchy. @@ -1794,9 +1889,11 @@ class DeclContext { /// the same selector and is of the same kind (class or instance). /// A method in an implementation is not considered as overriding the same /// method in the interface or its categories. + LLVM_PREFERRED_TYPE(bool) uint64_t IsOverriding : 1; /// Indicates if the method was a definition but its body was skipped. + LLVM_PREFERRED_TYPE(bool) uint64_t HasSkippedBody : 1; }; @@ -1809,6 +1906,7 @@ class DeclContext { class ObjCContainerDeclBitfields { friend class ObjCContainerDecl; /// For the bits in DeclContextBitfields + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint32_t : NumDeclContextBits; // Not a bitfield but this saves space. @@ -1827,16 +1925,18 @@ class DeclContext { class LinkageSpecDeclBitfields { friend class LinkageSpecDecl; /// For the bits in DeclContextBitfields. + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; - /// The language for this linkage specification with values - /// in the enum LinkageSpecDecl::LanguageIDs. + /// The language for this linkage specification. + LLVM_PREFERRED_TYPE(LinkageSpecLanguageIDs) uint64_t Language : 3; /// True if this linkage spec has braces. /// This is needed so that hasBraces() returns the correct result while the /// linkage spec body is being parsed. Once RBraceLoc has been set this is /// not used, so it doesn't need to be serialized. + LLVM_PREFERRED_TYPE(bool) uint64_t HasBraces : 1; }; @@ -1849,20 +1949,27 @@ class DeclContext { class BlockDeclBitfields { friend class BlockDecl; /// For the bits in DeclContextBitfields. + LLVM_PREFERRED_TYPE(DeclContextBitfields) uint64_t : NumDeclContextBits; + LLVM_PREFERRED_TYPE(bool) uint64_t IsVariadic : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t CapturesCXXThis : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t BlockMissingReturnType : 1; + LLVM_PREFERRED_TYPE(bool) uint64_t IsConversionFromLambda : 1; /// A bit that indicates this block is passed directly to a function as a /// non-escaping parameter. + LLVM_PREFERRED_TYPE(bool) uint64_t DoesNotEscape : 1; /// A bit that indicates whether it's possible to avoid coying this block to /// the heap when it initializes or is assigned to a local variable with /// automatic storage. + LLVM_PREFERRED_TYPE(bool) uint64_t CanAvoidCopyToHeap : 1; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits