[clang] [llvm] [clang-tools-extra] [clang][NFC] Annotate `Type` bit-fields with `clang::preferred_type` (PR #70349)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 05:26:02 PDT 2023


https://github.com/Endilll updated https://github.com/llvm/llvm-project/pull/70349

>From 7329f68092d5f8f5a5978e5a6cbad6ada87d4fe8 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Thu, 26 Oct 2023 16:09:25 +0300
Subject: [PATCH 1/6] [clang][NFC] Annotate `Type` bit-fields with
 `clang::preferred_type`

---
 clang/include/clang/AST/DeclBase.h        |  2 +-
 clang/include/clang/AST/DependenceFlags.h |  2 +-
 clang/include/clang/AST/Type.h            | 46 ++++++++++++++++++++++-
 clang/include/clang/Basic/Linkage.h       |  2 +-
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 978e4255e877ec2..0307691fdd480bf 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr;
 class FunctionDecl;
 class FunctionType;
 class IdentifierInfo;
-enum Linkage : unsigned char;
+enum Linkage : unsigned;
 class LinkageSpecDecl;
 class Module;
 class NamedDecl;
diff --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h
index 3b3c1afb096addd..e91b6ff35b34966 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -49,7 +49,7 @@ struct ExprDependenceScope {
 using ExprDependence = ExprDependenceScope::ExprDependence;
 
 struct TypeDependenceScope {
-  enum TypeDependence : uint8_t {
+  enum TypeDependence : unsigned {
     /// Whether this type contains an unexpanded parameter pack
     /// (for C++11 variadic templates)
     UnexpandedPack = 1,
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1e8e1303e65f6ba..f24b1dccc240785 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1611,22 +1611,28 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     template <class T> friend class TypePropertyCache;
 
     /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
+    [[clang::preferred_type(TypeClass)]]
     unsigned TC : 8;
 
     /// Store information on the type dependency.
+    [[clang::preferred_type(TypeDependence)]]
     unsigned Dependence : llvm::BitWidth<TypeDependence>;
 
     /// True if the cache (i.e. the bitfields here starting with
     /// 'Cache') is valid.
+    [[clang::preferred_type(bool)]]
     mutable unsigned CacheValid : 1;
 
     /// Linkage of this type.
+    [[clang::preferred_type(Linkage)]]
     mutable unsigned CachedLinkage : 3;
 
     /// Whether this type involves and local or unnamed types.
+    [[clang::preferred_type(bool)]]
     mutable unsigned CachedLocalOrUnnamed : 1;
 
     /// Whether this type comes from an AST file.
+    [[clang::preferred_type(bool)]]
     mutable unsigned FromAST : 1;
 
     bool isCacheValid() const {
@@ -1652,10 +1658,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ArrayTypeBitfields {
     friend class ArrayType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// CVR qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
+    [[clang::preferred_type(Qualifiers)]]
     unsigned IndexTypeQuals : 3;
 
     /// Storage class qualifiers from declarations like
@@ -1671,12 +1679,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned : NumArrayTypeBits;
 
     /// Whether we have a stored size expression.
+    [[clang::preferred_type(bool)]]
     unsigned HasStoredSizeExpr : 1;
   };
 
   class BuiltinTypeBitfields {
     friend class BuiltinType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// The kind (BuiltinType::Kind) of builtin type this is.
@@ -1691,15 +1701,18 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class FunctionProtoType;
     friend class FunctionType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// Extra information which affects how the function is called, like
     /// regparm and the calling convention.
+    [[clang::preferred_type(CallingConv)]]
     unsigned ExtInfo : 13;
 
     /// The ref-qualifier associated with a \c FunctionProtoType.
     ///
     /// This is a value of type \c RefQualifierKind.
+    [[clang::preferred_type(RefQualifierKind)]]
     unsigned RefQualifier : 2;
 
     /// Used only by FunctionProtoType, put here to pack with the
@@ -1708,8 +1721,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///
     /// C++ 8.3.5p4: The return type, the parameter type list and the
     /// cv-qualifier-seq, [...], are part of the function type.
+    [[clang::preferred_type(Qualifiers)]]
     unsigned FastTypeQuals : Qualifiers::FastWidth;
     /// Whether this function has extended Qualifiers.
+    [[clang::preferred_type(bool)]]
     unsigned HasExtQuals : 1;
 
     /// The number of parameters this function has, not counting '...'.
@@ -1719,24 +1734,30 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumParams : 16;
 
     /// The type of exception specification this function has.
+    [[clang::preferred_type(ExceptionSpecificationType)]]
     unsigned ExceptionSpecType : 4;
 
     /// Whether this function has extended parameter information.
+    [[clang::preferred_type(bool)]]
     unsigned HasExtParameterInfos : 1;
 
     /// Whether this function has extra bitfields for the prototype.
+    [[clang::preferred_type(bool)]]
     unsigned HasExtraBitfields : 1;
 
     /// Whether the function is variadic.
+    [[clang::preferred_type(bool)]]
     unsigned Variadic : 1;
 
     /// Whether this function has a trailing return type.
+    [[clang::preferred_type(bool)]]
     unsigned HasTrailingReturn : 1;
   };
 
   class ObjCObjectTypeBitfields {
     friend class ObjCObjectType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// The number of type arguments stored directly on this object type.
@@ -1746,12 +1767,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumProtocols : 6;
 
     /// Whether this is a "kindof" type.
+    [[clang::preferred_type(bool)]]
     unsigned IsKindOf : 1;
   };
 
   class ReferenceTypeBitfields {
     friend class ReferenceType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// True if the type was originally spelled with an lvalue sigil.
@@ -1765,16 +1788,19 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///   ref &&a;             // lvalue, inner ref
     ///   rvref &a;            // lvalue, inner ref, spelled lvalue
     ///   rvref &&a;           // rvalue, inner ref
+    [[clang::preferred_type(bool)]]
     unsigned SpelledAsLValue : 1;
 
     /// True if the inner type is a reference type.  This only happens
     /// in non-canonical forms.
+    [[clang::preferred_type(bool)]]
     unsigned InnerRef : 1;
   };
 
   class TypeWithKeywordBitfields {
     friend class TypeWithKeyword;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// An ElaboratedTypeKeyword.  8 bits for efficient access.
@@ -1786,10 +1812,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ElaboratedTypeBitfields {
     friend class ElaboratedType;
 
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeWithKeywordBitfields)]]
     unsigned : NumTypeWithKeywordBits;
 
     /// Whether the ElaboratedType has a trailing OwnedTagDecl.
+    [[clang::preferred_type(bool)]]
     unsigned HasOwnedTagDecl : 1;
   };
 
@@ -1797,6 +1824,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class VectorType;
     friend class DependentVectorType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// The kind of vector, either a generic vector type or some
@@ -1809,6 +1837,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AttributedTypeBitfields {
     friend class AttributedType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// An AttributedType::Kind
@@ -1818,10 +1847,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AutoTypeBitfields {
     friend class AutoType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
     /// or '__auto_type'?  AutoTypeKeyword value.
+    [[clang::preferred_type(AutoTypeKeyword)]]
     unsigned Keyword : 2;
 
     /// The number of template arguments in the type-constraints, which is
@@ -1838,33 +1869,40 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class TypeOfType;
     friend class TypeOfExprType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
+    [[clang::preferred_type(bool)]]
     unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
   };
 
   class UsingBitfields {
     friend class UsingType;
 
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
+    [[clang::preferred_type(bool)]]
     unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class TypedefBitfields {
     friend class TypedefType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
+    [[clang::preferred_type(bool)]]
     unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class SubstTemplateTypeParmTypeBitfields {
     friend class SubstTemplateTypeParmType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
+    [[clang::preferred_type(bool)]]
     unsigned HasNonCanonicalUnderlyingType : 1;
 
     // The index of the template parameter this substitution represents.
@@ -1881,6 +1919,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class SubstTemplateTypeParmPackTypeBitfields {
     friend class SubstTemplateTypeParmPackType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     // The index of the template parameter this substitution represents.
@@ -1896,9 +1935,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class TemplateSpecializationTypeBitfields {
     friend class TemplateSpecializationType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// Whether this template specialization type is a substituted type alias.
+    [[clang::preferred_type(bool)]]
     unsigned TypeAlias : 1;
 
     /// The number of template arguments named in this class template
@@ -1929,6 +1970,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class PackExpansionTypeBitfields {
     friend class PackExpansionType;
 
+    [[clang::preferred_type(TypeBitfields)]]
     unsigned : NumTypeBits;
 
     /// The number of expansions that this pack expansion will
diff --git a/clang/include/clang/Basic/Linkage.h b/clang/include/clang/Basic/Linkage.h
index 0b7b61954a075ae..bfe750462cc70b7 100644
--- a/clang/include/clang/Basic/Linkage.h
+++ b/clang/include/clang/Basic/Linkage.h
@@ -20,7 +20,7 @@ namespace clang {
 
 /// Describes the different kinds of linkage
 /// (C++ [basic.link], C99 6.2.2) that an entity may have.
-enum Linkage : unsigned char {
+enum Linkage : unsigned {
   /// No linkage, which means that the entity is unique and
   /// can only be referred to from within its scope.
   NoLinkage = 0,

>From 21689b56d1fc1db0b2263e8049ff656d3757ad36 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Thu, 26 Oct 2023 16:10:15 +0300
Subject: [PATCH 2/6] Run clang-format

---
 clang/include/clang/AST/Type.h | 134 ++++++++++++---------------------
 1 file changed, 48 insertions(+), 86 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f24b1dccc240785..55558a22ecc1b1c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1611,29 +1611,24 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     template <class T> friend class TypePropertyCache;
 
     /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
-    [[clang::preferred_type(TypeClass)]]
-    unsigned TC : 8;
+    [[clang::preferred_type(TypeClass)]] unsigned TC : 8;
 
     /// Store information on the type dependency.
-    [[clang::preferred_type(TypeDependence)]]
-    unsigned Dependence : llvm::BitWidth<TypeDependence>;
+    [[clang::preferred_type(TypeDependence)]] unsigned Dependence
+        : llvm::BitWidth<TypeDependence>;
 
     /// True if the cache (i.e. the bitfields here starting with
     /// 'Cache') is valid.
-    [[clang::preferred_type(bool)]]
-    mutable unsigned CacheValid : 1;
+    [[clang::preferred_type(bool)]] mutable unsigned CacheValid : 1;
 
     /// Linkage of this type.
-    [[clang::preferred_type(Linkage)]]
-    mutable unsigned CachedLinkage : 3;
+    [[clang::preferred_type(Linkage)]] mutable unsigned CachedLinkage : 3;
 
     /// Whether this type involves and local or unnamed types.
-    [[clang::preferred_type(bool)]]
-    mutable unsigned CachedLocalOrUnnamed : 1;
+    [[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1;
 
     /// Whether this type comes from an AST file.
-    [[clang::preferred_type(bool)]]
-    mutable unsigned FromAST : 1;
+    [[clang::preferred_type(bool)]] mutable unsigned FromAST : 1;
 
     bool isCacheValid() const {
       return CacheValid;
@@ -1658,13 +1653,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ArrayTypeBitfields {
     friend class ArrayType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// CVR qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
-    [[clang::preferred_type(Qualifiers)]]
-    unsigned IndexTypeQuals : 3;
+    [[clang::preferred_type(Qualifiers)]] unsigned IndexTypeQuals : 3;
 
     /// Storage class qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
@@ -1679,15 +1672,13 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned : NumArrayTypeBits;
 
     /// Whether we have a stored size expression.
-    [[clang::preferred_type(bool)]]
-    unsigned HasStoredSizeExpr : 1;
+    [[clang::preferred_type(bool)]] unsigned HasStoredSizeExpr : 1;
   };
 
   class BuiltinTypeBitfields {
     friend class BuiltinType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// The kind (BuiltinType::Kind) of builtin type this is.
     static constexpr unsigned NumOfBuiltinTypeBits = 9;
@@ -1701,19 +1692,16 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class FunctionProtoType;
     friend class FunctionType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// Extra information which affects how the function is called, like
     /// regparm and the calling convention.
-    [[clang::preferred_type(CallingConv)]]
-    unsigned ExtInfo : 13;
+    [[clang::preferred_type(CallingConv)]] unsigned ExtInfo : 13;
 
     /// The ref-qualifier associated with a \c FunctionProtoType.
     ///
     /// This is a value of type \c RefQualifierKind.
-    [[clang::preferred_type(RefQualifierKind)]]
-    unsigned RefQualifier : 2;
+    [[clang::preferred_type(RefQualifierKind)]] unsigned RefQualifier : 2;
 
     /// Used only by FunctionProtoType, put here to pack with the
     /// other bitfields.
@@ -1721,11 +1709,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///
     /// C++ 8.3.5p4: The return type, the parameter type list and the
     /// cv-qualifier-seq, [...], are part of the function type.
-    [[clang::preferred_type(Qualifiers)]]
-    unsigned FastTypeQuals : Qualifiers::FastWidth;
+    [[clang::preferred_type(Qualifiers)]] unsigned FastTypeQuals
+        : Qualifiers::FastWidth;
     /// Whether this function has extended Qualifiers.
-    [[clang::preferred_type(bool)]]
-    unsigned HasExtQuals : 1;
+    [[clang::preferred_type(bool)]] unsigned HasExtQuals : 1;
 
     /// The number of parameters this function has, not counting '...'.
     /// According to [implimits] 8 bits should be enough here but this is
@@ -1734,31 +1721,26 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumParams : 16;
 
     /// The type of exception specification this function has.
-    [[clang::preferred_type(ExceptionSpecificationType)]]
-    unsigned ExceptionSpecType : 4;
+    [[clang::preferred_type(
+        ExceptionSpecificationType)]] unsigned ExceptionSpecType : 4;
 
     /// Whether this function has extended parameter information.
-    [[clang::preferred_type(bool)]]
-    unsigned HasExtParameterInfos : 1;
+    [[clang::preferred_type(bool)]] unsigned HasExtParameterInfos : 1;
 
     /// Whether this function has extra bitfields for the prototype.
-    [[clang::preferred_type(bool)]]
-    unsigned HasExtraBitfields : 1;
+    [[clang::preferred_type(bool)]] unsigned HasExtraBitfields : 1;
 
     /// Whether the function is variadic.
-    [[clang::preferred_type(bool)]]
-    unsigned Variadic : 1;
+    [[clang::preferred_type(bool)]] unsigned Variadic : 1;
 
     /// Whether this function has a trailing return type.
-    [[clang::preferred_type(bool)]]
-    unsigned HasTrailingReturn : 1;
+    [[clang::preferred_type(bool)]] unsigned HasTrailingReturn : 1;
   };
 
   class ObjCObjectTypeBitfields {
     friend class ObjCObjectType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// The number of type arguments stored directly on this object type.
     unsigned NumTypeArgs : 7;
@@ -1767,15 +1749,13 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumProtocols : 6;
 
     /// Whether this is a "kindof" type.
-    [[clang::preferred_type(bool)]]
-    unsigned IsKindOf : 1;
+    [[clang::preferred_type(bool)]] unsigned IsKindOf : 1;
   };
 
   class ReferenceTypeBitfields {
     friend class ReferenceType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// True if the type was originally spelled with an lvalue sigil.
     /// This is never true of rvalue references but can also be false
@@ -1788,20 +1768,17 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///   ref &&a;             // lvalue, inner ref
     ///   rvref &a;            // lvalue, inner ref, spelled lvalue
     ///   rvref &&a;           // rvalue, inner ref
-    [[clang::preferred_type(bool)]]
-    unsigned SpelledAsLValue : 1;
+    [[clang::preferred_type(bool)]] unsigned SpelledAsLValue : 1;
 
     /// True if the inner type is a reference type.  This only happens
     /// in non-canonical forms.
-    [[clang::preferred_type(bool)]]
-    unsigned InnerRef : 1;
+    [[clang::preferred_type(bool)]] unsigned InnerRef : 1;
   };
 
   class TypeWithKeywordBitfields {
     friend class TypeWithKeyword;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// An ElaboratedTypeKeyword.  8 bits for efficient access.
     unsigned Keyword : 8;
@@ -1812,20 +1789,18 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ElaboratedTypeBitfields {
     friend class ElaboratedType;
 
-    [[clang::preferred_type(TypeWithKeywordBitfields)]]
-    unsigned : NumTypeWithKeywordBits;
+    [[clang::preferred_type(TypeWithKeywordBitfields)]] unsigned
+        : NumTypeWithKeywordBits;
 
     /// Whether the ElaboratedType has a trailing OwnedTagDecl.
-    [[clang::preferred_type(bool)]]
-    unsigned HasOwnedTagDecl : 1;
+    [[clang::preferred_type(bool)]] unsigned HasOwnedTagDecl : 1;
   };
 
   class VectorTypeBitfields {
     friend class VectorType;
     friend class DependentVectorType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// The kind of vector, either a generic vector type or some
     /// target-specific vector type such as for AltiVec or Neon.
@@ -1837,8 +1812,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AttributedTypeBitfields {
     friend class AttributedType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// An AttributedType::Kind
     unsigned AttrKind : 32 - NumTypeBits;
@@ -1847,13 +1821,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AutoTypeBitfields {
     friend class AutoType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
     /// or '__auto_type'?  AutoTypeKeyword value.
-    [[clang::preferred_type(AutoTypeKeyword)]]
-    unsigned Keyword : 2;
+    [[clang::preferred_type(AutoTypeKeyword)]] unsigned Keyword : 2;
 
     /// The number of template arguments in the type-constraints, which is
     /// expected to be able to hold at least 1024 according to [implimits].
@@ -1869,10 +1841,9 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class TypeOfType;
     friend class TypeOfExprType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
-    [[clang::preferred_type(bool)]]
-    unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(
+        bool)]] unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
   };
 
   class UsingBitfields {
@@ -1881,29 +1852,24 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]]
-    unsigned hasTypeDifferentFromDecl : 1;
+    [[clang::preferred_type(bool)]] unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class TypedefBitfields {
     friend class TypedefType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]]
-    unsigned hasTypeDifferentFromDecl : 1;
+    [[clang::preferred_type(bool)]] unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class SubstTemplateTypeParmTypeBitfields {
     friend class SubstTemplateTypeParmType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
-    [[clang::preferred_type(bool)]]
-    unsigned HasNonCanonicalUnderlyingType : 1;
+    [[clang::preferred_type(bool)]] unsigned HasNonCanonicalUnderlyingType : 1;
 
     // The index of the template parameter this substitution represents.
     unsigned Index : 15;
@@ -1919,8 +1885,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class SubstTemplateTypeParmPackTypeBitfields {
     friend class SubstTemplateTypeParmPackType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     // The index of the template parameter this substitution represents.
     unsigned Index : 16;
@@ -1935,12 +1900,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class TemplateSpecializationTypeBitfields {
     friend class TemplateSpecializationType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// Whether this template specialization type is a substituted type alias.
-    [[clang::preferred_type(bool)]]
-    unsigned TypeAlias : 1;
+    [[clang::preferred_type(bool)]] unsigned TypeAlias : 1;
 
     /// The number of template arguments named in this class template
     /// specialization, which is expected to be able to hold at least 1024
@@ -1970,8 +1933,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class PackExpansionTypeBitfields {
     friend class PackExpansionType;
 
-    [[clang::preferred_type(TypeBitfields)]]
-    unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// The number of expansions that this pack expansion will
     /// generate when substituted (+1), which is expected to be able to

>From 3eb936f9351d1252c465372023423344b63488fa Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Thu, 26 Oct 2023 21:03:22 +0400
Subject: [PATCH 3/6] Revert "Run clang-format"

This reverts commit 21689b56d1fc1db0b2263e8049ff656d3757ad36.
---
 clang/include/clang/AST/Type.h | 134 +++++++++++++++++++++------------
 1 file changed, 86 insertions(+), 48 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 55558a22ecc1b1c..f24b1dccc240785 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1611,24 +1611,29 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     template <class T> friend class TypePropertyCache;
 
     /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
-    [[clang::preferred_type(TypeClass)]] unsigned TC : 8;
+    [[clang::preferred_type(TypeClass)]]
+    unsigned TC : 8;
 
     /// Store information on the type dependency.
-    [[clang::preferred_type(TypeDependence)]] unsigned Dependence
-        : llvm::BitWidth<TypeDependence>;
+    [[clang::preferred_type(TypeDependence)]]
+    unsigned Dependence : llvm::BitWidth<TypeDependence>;
 
     /// True if the cache (i.e. the bitfields here starting with
     /// 'Cache') is valid.
-    [[clang::preferred_type(bool)]] mutable unsigned CacheValid : 1;
+    [[clang::preferred_type(bool)]]
+    mutable unsigned CacheValid : 1;
 
     /// Linkage of this type.
-    [[clang::preferred_type(Linkage)]] mutable unsigned CachedLinkage : 3;
+    [[clang::preferred_type(Linkage)]]
+    mutable unsigned CachedLinkage : 3;
 
     /// Whether this type involves and local or unnamed types.
-    [[clang::preferred_type(bool)]] mutable unsigned CachedLocalOrUnnamed : 1;
+    [[clang::preferred_type(bool)]]
+    mutable unsigned CachedLocalOrUnnamed : 1;
 
     /// Whether this type comes from an AST file.
-    [[clang::preferred_type(bool)]] mutable unsigned FromAST : 1;
+    [[clang::preferred_type(bool)]]
+    mutable unsigned FromAST : 1;
 
     bool isCacheValid() const {
       return CacheValid;
@@ -1653,11 +1658,13 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ArrayTypeBitfields {
     friend class ArrayType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// CVR qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
-    [[clang::preferred_type(Qualifiers)]] unsigned IndexTypeQuals : 3;
+    [[clang::preferred_type(Qualifiers)]]
+    unsigned IndexTypeQuals : 3;
 
     /// Storage class qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
@@ -1672,13 +1679,15 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned : NumArrayTypeBits;
 
     /// Whether we have a stored size expression.
-    [[clang::preferred_type(bool)]] unsigned HasStoredSizeExpr : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasStoredSizeExpr : 1;
   };
 
   class BuiltinTypeBitfields {
     friend class BuiltinType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// The kind (BuiltinType::Kind) of builtin type this is.
     static constexpr unsigned NumOfBuiltinTypeBits = 9;
@@ -1692,16 +1701,19 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class FunctionProtoType;
     friend class FunctionType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// Extra information which affects how the function is called, like
     /// regparm and the calling convention.
-    [[clang::preferred_type(CallingConv)]] unsigned ExtInfo : 13;
+    [[clang::preferred_type(CallingConv)]]
+    unsigned ExtInfo : 13;
 
     /// The ref-qualifier associated with a \c FunctionProtoType.
     ///
     /// This is a value of type \c RefQualifierKind.
-    [[clang::preferred_type(RefQualifierKind)]] unsigned RefQualifier : 2;
+    [[clang::preferred_type(RefQualifierKind)]]
+    unsigned RefQualifier : 2;
 
     /// Used only by FunctionProtoType, put here to pack with the
     /// other bitfields.
@@ -1709,10 +1721,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///
     /// C++ 8.3.5p4: The return type, the parameter type list and the
     /// cv-qualifier-seq, [...], are part of the function type.
-    [[clang::preferred_type(Qualifiers)]] unsigned FastTypeQuals
-        : Qualifiers::FastWidth;
+    [[clang::preferred_type(Qualifiers)]]
+    unsigned FastTypeQuals : Qualifiers::FastWidth;
     /// Whether this function has extended Qualifiers.
-    [[clang::preferred_type(bool)]] unsigned HasExtQuals : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasExtQuals : 1;
 
     /// The number of parameters this function has, not counting '...'.
     /// According to [implimits] 8 bits should be enough here but this is
@@ -1721,26 +1734,31 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumParams : 16;
 
     /// The type of exception specification this function has.
-    [[clang::preferred_type(
-        ExceptionSpecificationType)]] unsigned ExceptionSpecType : 4;
+    [[clang::preferred_type(ExceptionSpecificationType)]]
+    unsigned ExceptionSpecType : 4;
 
     /// Whether this function has extended parameter information.
-    [[clang::preferred_type(bool)]] unsigned HasExtParameterInfos : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasExtParameterInfos : 1;
 
     /// Whether this function has extra bitfields for the prototype.
-    [[clang::preferred_type(bool)]] unsigned HasExtraBitfields : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasExtraBitfields : 1;
 
     /// Whether the function is variadic.
-    [[clang::preferred_type(bool)]] unsigned Variadic : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned Variadic : 1;
 
     /// Whether this function has a trailing return type.
-    [[clang::preferred_type(bool)]] unsigned HasTrailingReturn : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasTrailingReturn : 1;
   };
 
   class ObjCObjectTypeBitfields {
     friend class ObjCObjectType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// The number of type arguments stored directly on this object type.
     unsigned NumTypeArgs : 7;
@@ -1749,13 +1767,15 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumProtocols : 6;
 
     /// Whether this is a "kindof" type.
-    [[clang::preferred_type(bool)]] unsigned IsKindOf : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned IsKindOf : 1;
   };
 
   class ReferenceTypeBitfields {
     friend class ReferenceType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// True if the type was originally spelled with an lvalue sigil.
     /// This is never true of rvalue references but can also be false
@@ -1768,17 +1788,20 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///   ref &&a;             // lvalue, inner ref
     ///   rvref &a;            // lvalue, inner ref, spelled lvalue
     ///   rvref &&a;           // rvalue, inner ref
-    [[clang::preferred_type(bool)]] unsigned SpelledAsLValue : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned SpelledAsLValue : 1;
 
     /// True if the inner type is a reference type.  This only happens
     /// in non-canonical forms.
-    [[clang::preferred_type(bool)]] unsigned InnerRef : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned InnerRef : 1;
   };
 
   class TypeWithKeywordBitfields {
     friend class TypeWithKeyword;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// An ElaboratedTypeKeyword.  8 bits for efficient access.
     unsigned Keyword : 8;
@@ -1789,18 +1812,20 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ElaboratedTypeBitfields {
     friend class ElaboratedType;
 
-    [[clang::preferred_type(TypeWithKeywordBitfields)]] unsigned
-        : NumTypeWithKeywordBits;
+    [[clang::preferred_type(TypeWithKeywordBitfields)]]
+    unsigned : NumTypeWithKeywordBits;
 
     /// Whether the ElaboratedType has a trailing OwnedTagDecl.
-    [[clang::preferred_type(bool)]] unsigned HasOwnedTagDecl : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasOwnedTagDecl : 1;
   };
 
   class VectorTypeBitfields {
     friend class VectorType;
     friend class DependentVectorType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// The kind of vector, either a generic vector type or some
     /// target-specific vector type such as for AltiVec or Neon.
@@ -1812,7 +1837,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AttributedTypeBitfields {
     friend class AttributedType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// An AttributedType::Kind
     unsigned AttrKind : 32 - NumTypeBits;
@@ -1821,11 +1847,13 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AutoTypeBitfields {
     friend class AutoType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
     /// or '__auto_type'?  AutoTypeKeyword value.
-    [[clang::preferred_type(AutoTypeKeyword)]] unsigned Keyword : 2;
+    [[clang::preferred_type(AutoTypeKeyword)]]
+    unsigned Keyword : 2;
 
     /// The number of template arguments in the type-constraints, which is
     /// expected to be able to hold at least 1024 according to [implimits].
@@ -1841,9 +1869,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class TypeOfType;
     friend class TypeOfExprType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
-    [[clang::preferred_type(
-        bool)]] unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
+    [[clang::preferred_type(bool)]]
+    unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
   };
 
   class UsingBitfields {
@@ -1852,24 +1881,29 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]] unsigned hasTypeDifferentFromDecl : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class TypedefBitfields {
     friend class TypedefType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]] unsigned hasTypeDifferentFromDecl : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class SubstTemplateTypeParmTypeBitfields {
     friend class SubstTemplateTypeParmType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
-    [[clang::preferred_type(bool)]] unsigned HasNonCanonicalUnderlyingType : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned HasNonCanonicalUnderlyingType : 1;
 
     // The index of the template parameter this substitution represents.
     unsigned Index : 15;
@@ -1885,7 +1919,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class SubstTemplateTypeParmPackTypeBitfields {
     friend class SubstTemplateTypeParmPackType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     // The index of the template parameter this substitution represents.
     unsigned Index : 16;
@@ -1900,10 +1935,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class TemplateSpecializationTypeBitfields {
     friend class TemplateSpecializationType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// Whether this template specialization type is a substituted type alias.
-    [[clang::preferred_type(bool)]] unsigned TypeAlias : 1;
+    [[clang::preferred_type(bool)]]
+    unsigned TypeAlias : 1;
 
     /// The number of template arguments named in this class template
     /// specialization, which is expected to be able to hold at least 1024
@@ -1933,7 +1970,8 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class PackExpansionTypeBitfields {
     friend class PackExpansionType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    [[clang::preferred_type(TypeBitfields)]]
+    unsigned : NumTypeBits;
 
     /// The number of expansions that this pack expansion will
     /// generate when substituted (+1), which is expected to be able to

>From ea7306d8995424b32b17763d8d1f3c148226cf77 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Mon, 30 Oct 2023 09:11:42 +0300
Subject: [PATCH 4/6] Wrap attribute in a macro

---
 clang/include/clang/AST/Type.h       | 89 ++++++++++++++--------------
 llvm/include/llvm/Support/Compiler.h |  8 +++
 2 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index f24b1dccc240785..f83b40a14dbe5af 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1611,28 +1611,28 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     template <class T> friend class TypePropertyCache;
 
     /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
-    [[clang::preferred_type(TypeClass)]]
+    LLVM_PREFERRED_TYPE(TypeClass)
     unsigned TC : 8;
 
     /// Store information on the type dependency.
-    [[clang::preferred_type(TypeDependence)]]
+    LLVM_PREFERRED_TYPE(TypeDependence)
     unsigned Dependence : llvm::BitWidth<TypeDependence>;
 
     /// True if the cache (i.e. the bitfields here starting with
     /// 'Cache') is valid.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     mutable unsigned CacheValid : 1;
 
     /// Linkage of this type.
-    [[clang::preferred_type(Linkage)]]
+    LLVM_PREFERRED_TYPE(Linkage)
     mutable unsigned CachedLinkage : 3;
 
     /// Whether this type involves and local or unnamed types.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     mutable unsigned CachedLocalOrUnnamed : 1;
 
     /// Whether this type comes from an AST file.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     mutable unsigned FromAST : 1;
 
     bool isCacheValid() const {
@@ -1658,12 +1658,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ArrayTypeBitfields {
     friend class ArrayType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// CVR qualifiers from declarations like
     /// 'int X[static restrict 4]'. For function parameters only.
-    [[clang::preferred_type(Qualifiers)]]
+    LLVM_PREFERRED_TYPE(Qualifiers)
     unsigned IndexTypeQuals : 3;
 
     /// Storage class qualifiers from declarations like
@@ -1679,14 +1679,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned : NumArrayTypeBits;
 
     /// Whether we have a stored size expression.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasStoredSizeExpr : 1;
   };
 
   class BuiltinTypeBitfields {
     friend class BuiltinType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// The kind (BuiltinType::Kind) of builtin type this is.
@@ -1701,18 +1701,18 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class FunctionProtoType;
     friend class FunctionType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// Extra information which affects how the function is called, like
     /// regparm and the calling convention.
-    [[clang::preferred_type(CallingConv)]]
+    LLVM_PREFERRED_TYPE(CallingConv)
     unsigned ExtInfo : 13;
 
     /// The ref-qualifier associated with a \c FunctionProtoType.
     ///
     /// This is a value of type \c RefQualifierKind.
-    [[clang::preferred_type(RefQualifierKind)]]
+    LLVM_PREFERRED_TYPE(RefQualifierKind)
     unsigned RefQualifier : 2;
 
     /// Used only by FunctionProtoType, put here to pack with the
@@ -1721,10 +1721,10 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///
     /// C++ 8.3.5p4: The return type, the parameter type list and the
     /// cv-qualifier-seq, [...], are part of the function type.
-    [[clang::preferred_type(Qualifiers)]]
+    LLVM_PREFERRED_TYPE(Qualifiers)
     unsigned FastTypeQuals : Qualifiers::FastWidth;
     /// Whether this function has extended Qualifiers.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasExtQuals : 1;
 
     /// The number of parameters this function has, not counting '...'.
@@ -1734,30 +1734,30 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumParams : 16;
 
     /// The type of exception specification this function has.
-    [[clang::preferred_type(ExceptionSpecificationType)]]
+    LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
     unsigned ExceptionSpecType : 4;
 
     /// Whether this function has extended parameter information.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasExtParameterInfos : 1;
 
     /// Whether this function has extra bitfields for the prototype.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasExtraBitfields : 1;
 
     /// Whether the function is variadic.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned Variadic : 1;
 
     /// Whether this function has a trailing return type.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasTrailingReturn : 1;
   };
 
   class ObjCObjectTypeBitfields {
     friend class ObjCObjectType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// The number of type arguments stored directly on this object type.
@@ -1767,14 +1767,14 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned NumProtocols : 6;
 
     /// Whether this is a "kindof" type.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned IsKindOf : 1;
   };
 
   class ReferenceTypeBitfields {
     friend class ReferenceType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// True if the type was originally spelled with an lvalue sigil.
@@ -1788,19 +1788,19 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     ///   ref &&a;             // lvalue, inner ref
     ///   rvref &a;            // lvalue, inner ref, spelled lvalue
     ///   rvref &&a;           // rvalue, inner ref
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned SpelledAsLValue : 1;
 
     /// True if the inner type is a reference type.  This only happens
     /// in non-canonical forms.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned InnerRef : 1;
   };
 
   class TypeWithKeywordBitfields {
     friend class TypeWithKeyword;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// An ElaboratedTypeKeyword.  8 bits for efficient access.
@@ -1812,11 +1812,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ElaboratedTypeBitfields {
     friend class ElaboratedType;
 
-    [[clang::preferred_type(TypeWithKeywordBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
     unsigned : NumTypeWithKeywordBits;
 
     /// Whether the ElaboratedType has a trailing OwnedTagDecl.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasOwnedTagDecl : 1;
   };
 
@@ -1824,7 +1824,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class VectorType;
     friend class DependentVectorType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// The kind of vector, either a generic vector type or some
@@ -1837,7 +1837,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AttributedTypeBitfields {
     friend class AttributedType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// An AttributedType::Kind
@@ -1847,12 +1847,12 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class AutoTypeBitfields {
     friend class AutoType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
     /// or '__auto_type'?  AutoTypeKeyword value.
-    [[clang::preferred_type(AutoTypeKeyword)]]
+    LLVM_PREFERRED_TYPE(AutoTypeKeyword)
     unsigned Keyword : 2;
 
     /// The number of template arguments in the type-constraints, which is
@@ -1869,40 +1869,41 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     friend class TypeOfType;
     friend class TypeOfExprType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
   };
 
   class UsingBitfields {
     friend class UsingType;
 
-    [[clang::preferred_type(TypeBitfields)]] unsigned : NumTypeBits;
+    LLVM_PREFERRED_TYPE(TypeBitfields)
+    unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class TypedefBitfields {
     friend class TypedefType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// True if the underlying type is different from the declared one.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned hasTypeDifferentFromDecl : 1;
   };
 
   class SubstTemplateTypeParmTypeBitfields {
     friend class SubstTemplateTypeParmType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned HasNonCanonicalUnderlyingType : 1;
 
     // The index of the template parameter this substitution represents.
@@ -1919,7 +1920,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class SubstTemplateTypeParmPackTypeBitfields {
     friend class SubstTemplateTypeParmPackType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     // The index of the template parameter this substitution represents.
@@ -1935,11 +1936,11 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class TemplateSpecializationTypeBitfields {
     friend class TemplateSpecializationType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// Whether this template specialization type is a substituted type alias.
-    [[clang::preferred_type(bool)]]
+    LLVM_PREFERRED_TYPE(bool)
     unsigned TypeAlias : 1;
 
     /// The number of template arguments named in this class template
@@ -1970,7 +1971,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class PackExpansionTypeBitfields {
     friend class PackExpansionType;
 
-    [[clang::preferred_type(TypeBitfields)]]
+    LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
     /// The number of expansions that this pack expansion will
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index 12afe90f8facd47..28a24733e751033 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -569,4 +569,12 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
 #define LLVM_NO_PROFILE_INSTRUMENT_FUNCTION
 #endif
 
+/// \macro LLVM_PREFERRED_TYPE
+/// Adjust type of bit-field in debug info.
+#if __has_attribute(preferred_type)
+#define LLVM_PREFERRED_TYPE(T) [[clang::preferred_type(T)]]
+#else
+#define LLVM_PREFERRED_TYPE(T)
+#endif
+
 #endif

>From a5028b0aa3fd711f8e16f2b039248b43a3cc6b5d Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Wed, 1 Nov 2023 09:02:50 +0300
Subject: [PATCH 5/6] Add missing annotations

This is made possible by several NFC commits that made some enums complete at the point of declaration of bit-fields.
---
 clang/include/clang/AST/Type.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 99dc3d4019139b5..41b0edab22704c1 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1737,6 +1737,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class ConstantArrayTypeBitfields {
     friend class ConstantArrayType;
 
+    LLVM_PREFERRED_TYPE(ArrayTypeBitfields)
     unsigned : NumArrayTypeBits;
 
     /// Whether we have a stored size expression.
@@ -1865,6 +1866,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     unsigned : NumTypeBits;
 
     /// An ElaboratedTypeKeyword.  8 bits for efficient access.
+    LLVM_PREFERRED_TYPE(ElaboratedTypeKeyword)
     unsigned Keyword : 8;
   };
 
@@ -1890,6 +1892,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
 
     /// The kind of vector, either a generic vector type or some
     /// target-specific vector type such as for AltiVec or Neon.
+    LLVM_PREFERRED_TYPE(VectorKind)
     unsigned VecKind : 4;
     /// The number of elements in the vector.
     uint32_t NumElements;
@@ -1901,7 +1904,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
     LLVM_PREFERRED_TYPE(TypeBitfields)
     unsigned : NumTypeBits;
 
-    /// An AttributedType::Kind
+    LLVM_PREFERRED_TYPE(attr::Kind)
     unsigned AttrKind : 32 - NumTypeBits;
   };
 
@@ -2017,6 +2020,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
   class DependentTemplateSpecializationTypeBitfields {
     friend class DependentTemplateSpecializationType;
 
+    LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
     unsigned : NumTypeWithKeywordBits;
 
     /// The number of template arguments named in this class template

>From 635202250d669d606046e2d563c8ad439ec4d91f Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov <serebrennikov.vladislav at gmail.com>
Date: Thu, 2 Nov 2023 15:25:32 +0300
Subject: [PATCH 6/6] Revert changes to underlying type of enums

---
 clang/include/clang/AST/DeclBase.h        | 2 +-
 clang/include/clang/AST/DependenceFlags.h | 2 +-
 clang/include/clang/Basic/Linkage.h       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 0307691fdd480bf..978e4255e877ec2 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -49,7 +49,7 @@ class ExternalSourceSymbolAttr;
 class FunctionDecl;
 class FunctionType;
 class IdentifierInfo;
-enum Linkage : unsigned;
+enum Linkage : unsigned char;
 class LinkageSpecDecl;
 class Module;
 class NamedDecl;
diff --git a/clang/include/clang/AST/DependenceFlags.h b/clang/include/clang/AST/DependenceFlags.h
index e91b6ff35b34966..3b3c1afb096addd 100644
--- a/clang/include/clang/AST/DependenceFlags.h
+++ b/clang/include/clang/AST/DependenceFlags.h
@@ -49,7 +49,7 @@ struct ExprDependenceScope {
 using ExprDependence = ExprDependenceScope::ExprDependence;
 
 struct TypeDependenceScope {
-  enum TypeDependence : unsigned {
+  enum TypeDependence : uint8_t {
     /// Whether this type contains an unexpanded parameter pack
     /// (for C++11 variadic templates)
     UnexpandedPack = 1,
diff --git a/clang/include/clang/Basic/Linkage.h b/clang/include/clang/Basic/Linkage.h
index bfe750462cc70b7..0b7b61954a075ae 100644
--- a/clang/include/clang/Basic/Linkage.h
+++ b/clang/include/clang/Basic/Linkage.h
@@ -20,7 +20,7 @@ namespace clang {
 
 /// Describes the different kinds of linkage
 /// (C++ [basic.link], C99 6.2.2) that an entity may have.
-enum Linkage : unsigned {
+enum Linkage : unsigned char {
   /// No linkage, which means that the entity is unique and
   /// can only be referred to from within its scope.
   NoLinkage = 0,



More information about the cfe-commits mailing list