[clang] [BoundsSafety][NFC] Hold LateParsedTypeAttrInfo in declarator late-attribute lists (PR #239050)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 17:07:55 PST 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/include/clang/Parse/Parser.h clang/include/clang/Sema/DeclSpec.h clang/lib/Parse/ParseDecl.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index f3e1dfa2d..88a867b76 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -277,709 +277,712 @@ namespace clang {
   /// storage.
   using LateParsedTypeAttrInfoList = SmallVector<LateParsedTypeAttrInfo *, 0>;
 
-/// Captures information about "declaration specifiers".
-///
-/// "Declaration specifiers" encompasses storage-class-specifiers,
-/// type-specifiers, type-qualifiers, and function-specifiers.
-class DeclSpec {
-public:
-  /// storage-class-specifier
-  /// \note The order of these enumerators is important for diagnostics.
-  enum SCS {
-    SCS_unspecified = 0,
-    SCS_typedef,
-    SCS_extern,
-    SCS_static,
-    SCS_auto,
-    SCS_register,
-    SCS_private_extern,
-    SCS_mutable
-  };
+  /// Captures information about "declaration specifiers".
+  ///
+  /// "Declaration specifiers" encompasses storage-class-specifiers,
+  /// type-specifiers, type-qualifiers, and function-specifiers.
+  class DeclSpec {
+  public:
+    /// storage-class-specifier
+    /// \note The order of these enumerators is important for diagnostics.
+    enum SCS {
+      SCS_unspecified = 0,
+      SCS_typedef,
+      SCS_extern,
+      SCS_static,
+      SCS_auto,
+      SCS_register,
+      SCS_private_extern,
+      SCS_mutable
+    };
 
-  // Import thread storage class specifier enumeration and constants.
-  // These can be combined with SCS_extern and SCS_static.
-  typedef ThreadStorageClassSpecifier TSCS;
-  static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
-  static const TSCS TSCS___thread = clang::TSCS___thread;
-  static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
-  static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
-
-  enum TSC {
-    TSC_unspecified,
-    TSC_imaginary, // Unsupported
-    TSC_complex
-  };
+    // Import thread storage class specifier enumeration and constants.
+    // These can be combined with SCS_extern and SCS_static.
+    typedef ThreadStorageClassSpecifier TSCS;
+    static const TSCS TSCS_unspecified = clang::TSCS_unspecified;
+    static const TSCS TSCS___thread = clang::TSCS___thread;
+    static const TSCS TSCS_thread_local = clang::TSCS_thread_local;
+    static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local;
+
+    enum TSC {
+      TSC_unspecified,
+      TSC_imaginary, // Unsupported
+      TSC_complex
+    };
 
-  // Import type specifier type enumeration and constants.
-  typedef TypeSpecifierType TST;
-  static const TST TST_unspecified = clang::TST_unspecified;
-  static const TST TST_void = clang::TST_void;
-  static const TST TST_char = clang::TST_char;
-  static const TST TST_wchar = clang::TST_wchar;
-  static const TST TST_char8 = clang::TST_char8;
-  static const TST TST_char16 = clang::TST_char16;
-  static const TST TST_char32 = clang::TST_char32;
-  static const TST TST_int = clang::TST_int;
-  static const TST TST_int128 = clang::TST_int128;
-  static const TST TST_bitint = clang::TST_bitint;
-  static const TST TST_half = clang::TST_half;
-  static const TST TST_BFloat16 = clang::TST_BFloat16;
-  static const TST TST_float = clang::TST_float;
-  static const TST TST_double = clang::TST_double;
-  static const TST TST_float16 = clang::TST_Float16;
-  static const TST TST_accum = clang::TST_Accum;
-  static const TST TST_fract = clang::TST_Fract;
-  static const TST TST_float128 = clang::TST_float128;
-  static const TST TST_ibm128 = clang::TST_ibm128;
-  static const TST TST_bool = clang::TST_bool;
-  static const TST TST_decimal32 = clang::TST_decimal32;
-  static const TST TST_decimal64 = clang::TST_decimal64;
-  static const TST TST_decimal128 = clang::TST_decimal128;
-  static const TST TST_enum = clang::TST_enum;
-  static const TST TST_union = clang::TST_union;
-  static const TST TST_struct = clang::TST_struct;
-  static const TST TST_interface = clang::TST_interface;
-  static const TST TST_class = clang::TST_class;
-  static const TST TST_typename = clang::TST_typename;
-  static const TST TST_typeofType = clang::TST_typeofType;
-  static const TST TST_typeofExpr = clang::TST_typeofExpr;
-  static const TST TST_typeof_unqualType = clang::TST_typeof_unqualType;
-  static const TST TST_typeof_unqualExpr = clang::TST_typeof_unqualExpr;
-  static const TST TST_decltype = clang::TST_decltype;
-  static const TST TST_decltype_auto = clang::TST_decltype_auto;
-  static const TST TST_typename_pack_indexing =
-      clang::TST_typename_pack_indexing;
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait)                                     \
-  static const TST TST_##Trait = clang::TST_##Trait;
+    // Import type specifier type enumeration and constants.
+    typedef TypeSpecifierType TST;
+    static const TST TST_unspecified = clang::TST_unspecified;
+    static const TST TST_void = clang::TST_void;
+    static const TST TST_char = clang::TST_char;
+    static const TST TST_wchar = clang::TST_wchar;
+    static const TST TST_char8 = clang::TST_char8;
+    static const TST TST_char16 = clang::TST_char16;
+    static const TST TST_char32 = clang::TST_char32;
+    static const TST TST_int = clang::TST_int;
+    static const TST TST_int128 = clang::TST_int128;
+    static const TST TST_bitint = clang::TST_bitint;
+    static const TST TST_half = clang::TST_half;
+    static const TST TST_BFloat16 = clang::TST_BFloat16;
+    static const TST TST_float = clang::TST_float;
+    static const TST TST_double = clang::TST_double;
+    static const TST TST_float16 = clang::TST_Float16;
+    static const TST TST_accum = clang::TST_Accum;
+    static const TST TST_fract = clang::TST_Fract;
+    static const TST TST_float128 = clang::TST_float128;
+    static const TST TST_ibm128 = clang::TST_ibm128;
+    static const TST TST_bool = clang::TST_bool;
+    static const TST TST_decimal32 = clang::TST_decimal32;
+    static const TST TST_decimal64 = clang::TST_decimal64;
+    static const TST TST_decimal128 = clang::TST_decimal128;
+    static const TST TST_enum = clang::TST_enum;
+    static const TST TST_union = clang::TST_union;
+    static const TST TST_struct = clang::TST_struct;
+    static const TST TST_interface = clang::TST_interface;
+    static const TST TST_class = clang::TST_class;
+    static const TST TST_typename = clang::TST_typename;
+    static const TST TST_typeofType = clang::TST_typeofType;
+    static const TST TST_typeofExpr = clang::TST_typeofExpr;
+    static const TST TST_typeof_unqualType = clang::TST_typeof_unqualType;
+    static const TST TST_typeof_unqualExpr = clang::TST_typeof_unqualExpr;
+    static const TST TST_decltype = clang::TST_decltype;
+    static const TST TST_decltype_auto = clang::TST_decltype_auto;
+    static const TST TST_typename_pack_indexing =
+        clang::TST_typename_pack_indexing;
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait)                                   \
+    static const TST TST_##Trait = clang::TST_##Trait;
 #include "clang/Basic/BuiltinTraits.inc"
-  static const TST TST_auto = clang::TST_auto;
-  static const TST TST_auto_type = clang::TST_auto_type;
-  static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
-  static const TST TST_atomic = clang::TST_atomic;
-#define GENERIC_IMAGE_TYPE(ImgType, Id) \
-  static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
+    static const TST TST_auto = clang::TST_auto;
+    static const TST TST_auto_type = clang::TST_auto_type;
+    static const TST TST_unknown_anytype = clang::TST_unknown_anytype;
+    static const TST TST_atomic = clang::TST_atomic;
+#define GENERIC_IMAGE_TYPE(ImgType, Id)                                      \
+    static const TST TST_##ImgType##_t = clang::TST_##ImgType##_t;
 #include "clang/Basic/OpenCLImageTypes.def"
-#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                            \
-  static const TST TST_##Name = clang::TST_##Name;
+#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId)                          \
+    static const TST TST_##Name = clang::TST_##Name;
 #include "clang/Basic/HLSLIntangibleTypes.def"
-#define HLSL_PACKED_TYPE(Name, Id, SingletonId)                                \
-  static const TST TST_##Name = clang::TST_##Name;
+#define HLSL_PACKED_TYPE(Name, Id, SingletonId)                              \
+    static const TST TST_##Name = clang::TST_##Name;
 #include "clang/Basic/HLSLPackedTypes.def"
-  static const TST TST_error = clang::TST_error;
-
-  // type-qualifiers
-  enum TQ {   // NOTE: These flags must be kept in sync with Qualifiers::TQ.
-    TQ_unspecified = 0,
-    TQ_const       = 1,
-    TQ_restrict    = 2,
-    TQ_volatile    = 4,
-    TQ_unaligned   = 8,
-    // This has no corresponding Qualifiers::TQ value, because it's not treated
-    // as a qualifier in our type system.
-    TQ_atomic      = 16
-  };
-
-  /// ParsedSpecifiers - Flags to query which specifiers were applied.  This is
-  /// returned by getParsedSpecifiers.
-  enum ParsedSpecifiers {
-    PQ_None                  = 0,
-    PQ_StorageClassSpecifier = 1,
-    PQ_TypeSpecifier         = 2,
-    PQ_TypeQualifier         = 4,
-    PQ_FunctionSpecifier     = 8
-    // FIXME: Attributes should be included here.
-  };
-
-  enum FriendSpecified : bool { No, Yes };
+    static const TST TST_error = clang::TST_error;
+
+    // type-qualifiers
+    enum TQ { // NOTE: These flags must be kept in sync with Qualifiers::TQ.
+      TQ_unspecified = 0,
+      TQ_const = 1,
+      TQ_restrict = 2,
+      TQ_volatile = 4,
+      TQ_unaligned = 8,
+      // This has no corresponding Qualifiers::TQ value, because it's not
+      // treated
+      // as a qualifier in our type system.
+      TQ_atomic = 16
+    };
 
-  enum class OverflowBehaviorState {
-    Unspecified, // No overflow behavior specified
-    Wrap,        // __ob_wrap or __attribute__((overflow_behavior(wrap)))
-    Trap         // __ob_trap or __attribute__((overflow_behavior(trap)))
-  };
+    /// ParsedSpecifiers - Flags to query which specifiers were applied.  This
+    /// is returned by getParsedSpecifiers.
+    enum ParsedSpecifiers {
+      PQ_None = 0,
+      PQ_StorageClassSpecifier = 1,
+      PQ_TypeSpecifier = 2,
+      PQ_TypeQualifier = 4,
+      PQ_FunctionSpecifier = 8
+      // FIXME: Attributes should be included here.
+    };
 
-private:
-  // storage-class-specifier
-  LLVM_PREFERRED_TYPE(SCS)
-  unsigned StorageClassSpec : 3;
-  LLVM_PREFERRED_TYPE(TSCS)
-  unsigned ThreadStorageClassSpec : 2;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned SCS_extern_in_linkage_spec : 1;
-
-  // type-specifier
-  LLVM_PREFERRED_TYPE(TypeSpecifierWidth)
-  unsigned TypeSpecWidth : 2;
-  LLVM_PREFERRED_TYPE(TSC)
-  unsigned TypeSpecComplex : 2;
-  LLVM_PREFERRED_TYPE(TypeSpecifierSign)
-  unsigned TypeSpecSign : 2;
-  LLVM_PREFERRED_TYPE(TST)
-  unsigned TypeSpecType : 7;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeAltiVecVector : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeAltiVecPixel : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeAltiVecBool : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeSpecOwned : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeSpecPipe : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned TypeSpecSat : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned ConstrainedAuto : 1;
+    enum FriendSpecified : bool { No, Yes };
 
-  // type-qualifiers
-  LLVM_PREFERRED_TYPE(TQ)
-  unsigned TypeQualifiers : 5;  // Bitwise OR of TQ.
+    enum class OverflowBehaviorState {
+      Unspecified, // No overflow behavior specified
+      Wrap,        // __ob_wrap or __attribute__((overflow_behavior(wrap)))
+      Trap         // __ob_trap or __attribute__((overflow_behavior(trap)))
+    };
 
-  // overflow behavior qualifiers
-  LLVM_PREFERRED_TYPE(OverflowBehaviorState)
-  unsigned OB_state : 2;
+  private:
+    // storage-class-specifier
+    LLVM_PREFERRED_TYPE(SCS)
+    unsigned StorageClassSpec : 3;
+    LLVM_PREFERRED_TYPE(TSCS)
+    unsigned ThreadStorageClassSpec : 2;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned SCS_extern_in_linkage_spec : 1;
+
+    // type-specifier
+    LLVM_PREFERRED_TYPE(TypeSpecifierWidth)
+    unsigned TypeSpecWidth : 2;
+    LLVM_PREFERRED_TYPE(TSC)
+    unsigned TypeSpecComplex : 2;
+    LLVM_PREFERRED_TYPE(TypeSpecifierSign)
+    unsigned TypeSpecSign : 2;
+    LLVM_PREFERRED_TYPE(TST)
+    unsigned TypeSpecType : 7;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeAltiVecVector : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeAltiVecPixel : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeAltiVecBool : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeSpecOwned : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeSpecPipe : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned TypeSpecSat : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned ConstrainedAuto : 1;
 
-  // function-specifier
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned FS_inline_specified : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned FS_forceinline_specified: 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned FS_virtual_specified : 1;
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned FS_noreturn_specified : 1;
+    // type-qualifiers
+    LLVM_PREFERRED_TYPE(TQ)
+    unsigned TypeQualifiers : 5; // Bitwise OR of TQ.
 
-  // friend-specifier
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned FriendSpecifiedFirst : 1;
+    // overflow behavior qualifiers
+    LLVM_PREFERRED_TYPE(OverflowBehaviorState)
+    unsigned OB_state : 2;
 
-  // constexpr-specifier
-  LLVM_PREFERRED_TYPE(ConstexprSpecKind)
-  unsigned ConstexprSpecifier : 2;
+    // function-specifier
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned FS_inline_specified : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned FS_forceinline_specified : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned FS_virtual_specified : 1;
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned FS_noreturn_specified : 1;
 
-  union {
-    UnionParsedType TypeRep;
-    Decl *DeclRep;
-    Expr *ExprRep;
-    TemplateIdAnnotation *TemplateIdRep;
-  };
-  Expr *PackIndexingExpr = nullptr;
+    // friend-specifier
+    LLVM_PREFERRED_TYPE(bool)
+    unsigned FriendSpecifiedFirst : 1;
 
-  /// ExplicitSpecifier - Store information about explicit spicifer.
-  ExplicitSpecifier FS_explicit_specifier;
+    // constexpr-specifier
+    LLVM_PREFERRED_TYPE(ConstexprSpecKind)
+    unsigned ConstexprSpecifier : 2;
 
-  // attributes.
-  ParsedAttributes Attrs;
+    union {
+      UnionParsedType TypeRep;
+      Decl *DeclRep;
+      Expr *ExprRep;
+      TemplateIdAnnotation *TemplateIdRep;
+    };
+    Expr *PackIndexingExpr = nullptr;
 
-  // late attributes
-  LateParsedTypeAttrInfoList LateParsedAttrs;
+    /// ExplicitSpecifier - Store information about explicit spicifer.
+    ExplicitSpecifier FS_explicit_specifier;
 
-  // Scope specifier for the type spec, if applicable.
-  CXXScopeSpec TypeScope;
+    // attributes.
+    ParsedAttributes Attrs;
 
-  // SourceLocation info.  These are null if the item wasn't specified or if
-  // the setting was synthesized.
-  SourceRange Range;
+    // late attributes
+    LateParsedTypeAttrInfoList LateParsedAttrs;
 
-  SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
-  SourceRange TSWRange;
-  SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc, EllipsisLoc;
-  /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
-  /// typename, then this is the location of the named type (if present);
-  /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
-  /// TSTNameLoc provides source range info for tag types.
-  SourceLocation TSTNameLoc;
-  SourceRange TypeofParensRange;
-  SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
-      TQ_unalignedLoc;
-  SourceLocation OB_Loc;
-  SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
-  SourceLocation FS_explicitCloseParenLoc;
-  SourceLocation FS_forceinlineLoc;
-  SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
-  SourceLocation TQ_pipeLoc;
-
-  WrittenBuiltinSpecs writtenBS;
-  void SaveWrittenBuiltinSpecs();
-
-  ObjCDeclSpec *ObjCQualifiers;
-
-  static bool isTypeRep(TST T) {
-    return T == TST_atomic || T == TST_typename || T == TST_typeofType ||
-           T == TST_typeof_unqualType || isTransformTypeTrait(T) ||
-           T == TST_typename_pack_indexing;
-  }
-  static bool isExprRep(TST T) {
-    return T == TST_typeofExpr || T == TST_typeof_unqualExpr ||
-           T == TST_decltype || T == TST_bitint;
-  }
-  static bool isTemplateIdRep(TST T) {
-    return (T == TST_auto || T == TST_decltype_auto);
-  }
-
-  DeclSpec(const DeclSpec &) = delete;
-  void operator=(const DeclSpec &) = delete;
-public:
-  static bool isDeclRep(TST T) {
-    return (T == TST_enum || T == TST_struct ||
-            T == TST_interface || T == TST_union ||
-            T == TST_class);
-  }
-  static bool isTransformTypeTrait(TST T) {
-    constexpr std::array<TST, 16> Traits = {
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait,
-#include "clang/Basic/BuiltinTraits.inc"
-    };
+    // Scope specifier for the type spec, if applicable.
+    CXXScopeSpec TypeScope;
 
-    return T >= Traits.front() && T <= Traits.back();
-  }
+    // SourceLocation info.  These are null if the item wasn't specified or if
+    // the setting was synthesized.
+    SourceRange Range;
 
-  DeclSpec(AttributeFactory &attrFactory)
-      : StorageClassSpec(SCS_unspecified),
-        ThreadStorageClassSpec(TSCS_unspecified),
-        SCS_extern_in_linkage_spec(false),
-        TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)),
-        TypeSpecComplex(TSC_unspecified),
-        TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)),
-        TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
-        TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
-        TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
-        TypeQualifiers(TQ_unspecified),
-        OB_state(static_cast<unsigned>(OverflowBehaviorState::Unspecified)),
-        FS_inline_specified(false), FS_forceinline_specified(false),
-        FS_virtual_specified(false), FS_noreturn_specified(false),
-        FriendSpecifiedFirst(false), ConstexprSpecifier(static_cast<unsigned>(
-                                         ConstexprSpecKind::Unspecified)),
-        Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
+    SourceLocation StorageClassSpecLoc, ThreadStorageClassSpecLoc;
+    SourceRange TSWRange;
+    SourceLocation TSCLoc, TSSLoc, TSTLoc, AltiVecLoc, TSSatLoc, EllipsisLoc;
+    /// TSTNameLoc - If TypeSpecType is any of class, enum, struct, union,
+    /// typename, then this is the location of the named type (if present);
+    /// otherwise, it is the same as TSTLoc. Hence, the pair TSTLoc and
+    /// TSTNameLoc provides source range info for tag types.
+    SourceLocation TSTNameLoc;
+    SourceRange TypeofParensRange;
+    SourceLocation TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc,
+        TQ_unalignedLoc;
+    SourceLocation OB_Loc;
+    SourceLocation FS_inlineLoc, FS_virtualLoc, FS_explicitLoc, FS_noreturnLoc;
+    SourceLocation FS_explicitCloseParenLoc;
+    SourceLocation FS_forceinlineLoc;
+    SourceLocation FriendLoc, ModulePrivateLoc, ConstexprLoc;
+    SourceLocation TQ_pipeLoc;
+
+    WrittenBuiltinSpecs writtenBS;
+    void SaveWrittenBuiltinSpecs();
+
+    ObjCDeclSpec *ObjCQualifiers;
+
+    static bool isTypeRep(TST T) {
+      return T == TST_atomic || T == TST_typename || T == TST_typeofType ||
+             T == TST_typeof_unqualType || isTransformTypeTrait(T) ||
+             T == TST_typename_pack_indexing;
+    }
+    static bool isExprRep(TST T) {
+      return T == TST_typeofExpr || T == TST_typeof_unqualExpr ||
+             T == TST_decltype || T == TST_bitint;
+    }
+    static bool isTemplateIdRep(TST T) {
+      return (T == TST_auto || T == TST_decltype_auto);
+    }
 
-  // storage-class-specifier
-  SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
-  TSCS getThreadStorageClassSpec() const {
-    return (TSCS)ThreadStorageClassSpec;
-  }
-  bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
-  void setExternInLinkageSpec(bool Value) {
-    SCS_extern_in_linkage_spec = Value;
-  }
+    DeclSpec(const DeclSpec &) = delete;
+    void operator=(const DeclSpec &) = delete;
 
-  SourceLocation getStorageClassSpecLoc() const { return StorageClassSpecLoc; }
-  SourceLocation getThreadStorageClassSpecLoc() const {
-    return ThreadStorageClassSpecLoc;
-  }
+  public:
+    static bool isDeclRep(TST T) {
+      return (T == TST_enum || T == TST_struct || T == TST_interface ||
+              T == TST_union || T == TST_class);
+    }
+    static bool isTransformTypeTrait(TST T) {
+      constexpr std::array<TST, 16> Traits = {
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) TST_##Trait,
+#include "clang/Basic/BuiltinTraits.inc"
+      };
 
-  void ClearStorageClassSpecs() {
-    StorageClassSpec           = DeclSpec::SCS_unspecified;
-    ThreadStorageClassSpec     = DeclSpec::TSCS_unspecified;
-    SCS_extern_in_linkage_spec = false;
-    StorageClassSpecLoc        = SourceLocation();
-    ThreadStorageClassSpecLoc  = SourceLocation();
-  }
+      return T >= Traits.front() && T <= Traits.back();
+    }
 
-  void ClearTypeSpecType() {
-    TypeSpecType = DeclSpec::TST_unspecified;
-    TypeSpecOwned = false;
-    TSTLoc = SourceLocation();
-  }
+    DeclSpec(AttributeFactory &attrFactory)
+        : StorageClassSpec(SCS_unspecified),
+          ThreadStorageClassSpec(TSCS_unspecified),
+          SCS_extern_in_linkage_spec(false),
+          TypeSpecWidth(static_cast<unsigned>(TypeSpecifierWidth::Unspecified)),
+          TypeSpecComplex(TSC_unspecified),
+          TypeSpecSign(static_cast<unsigned>(TypeSpecifierSign::Unspecified)),
+          TypeSpecType(TST_unspecified), TypeAltiVecVector(false),
+          TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false),
+          TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false),
+          TypeQualifiers(TQ_unspecified),
+          OB_state(static_cast<unsigned>(OverflowBehaviorState::Unspecified)),
+          FS_inline_specified(false), FS_forceinline_specified(false),
+          FS_virtual_specified(false), FS_noreturn_specified(false),
+          FriendSpecifiedFirst(false), ConstexprSpecifier(static_cast<unsigned>(
+                                           ConstexprSpecKind::Unspecified)),
+          Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
+
+    // storage-class-specifier
+    SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
+    TSCS getThreadStorageClassSpec() const {
+      return (TSCS)ThreadStorageClassSpec;
+    }
+    bool isExternInLinkageSpec() const { return SCS_extern_in_linkage_spec; }
+    void setExternInLinkageSpec(bool Value) {
+      SCS_extern_in_linkage_spec = Value;
+    }
 
-  // type-specifier
-  TypeSpecifierWidth getTypeSpecWidth() const {
-    return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
-  }
-  TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
-  TypeSpecifierSign getTypeSpecSign() const {
-    return static_cast<TypeSpecifierSign>(TypeSpecSign);
-  }
-  TST getTypeSpecType() const { return (TST)TypeSpecType; }
-  bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
-  bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
-  bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
-  bool isTypeSpecOwned() const { return TypeSpecOwned; }
-  bool isTypeRep() const { return isTypeRep((TST) TypeSpecType); }
-  bool isTypeSpecPipe() const { return TypeSpecPipe; }
-  bool isTypeSpecSat() const { return TypeSpecSat; }
-  bool isConstrainedAuto() const { return ConstrainedAuto; }
+    SourceLocation getStorageClassSpecLoc() const {
+      return StorageClassSpecLoc;
+    }
+    SourceLocation getThreadStorageClassSpecLoc() const {
+      return ThreadStorageClassSpecLoc;
+    }
 
-  ParsedType getRepAsType() const {
-    assert(isTypeRep((TST) TypeSpecType) && "DeclSpec does not store a type");
-    return TypeRep;
-  }
-  Decl *getRepAsDecl() const {
-    assert(isDeclRep((TST) TypeSpecType) && "DeclSpec does not store a decl");
-    return DeclRep;
-  }
-  Expr *getRepAsExpr() const {
-    assert(isExprRep((TST) TypeSpecType) && "DeclSpec does not store an expr");
-    return ExprRep;
-  }
+    void ClearStorageClassSpecs() {
+      StorageClassSpec = DeclSpec::SCS_unspecified;
+      ThreadStorageClassSpec = DeclSpec::TSCS_unspecified;
+      SCS_extern_in_linkage_spec = false;
+      StorageClassSpecLoc = SourceLocation();
+      ThreadStorageClassSpecLoc = SourceLocation();
+    }
 
-  Expr *getPackIndexingExpr() const {
-    assert(TypeSpecType == TST_typename_pack_indexing &&
-           "DeclSpec is not a pack indexing expr");
-    return PackIndexingExpr;
-  }
+    void ClearTypeSpecType() {
+      TypeSpecType = DeclSpec::TST_unspecified;
+      TypeSpecOwned = false;
+      TSTLoc = SourceLocation();
+    }
 
-  TemplateIdAnnotation *getRepAsTemplateId() const {
-    assert(isTemplateIdRep((TST) TypeSpecType) &&
-           "DeclSpec does not store a template id");
-    return TemplateIdRep;
-  }
-  CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
-  const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
+    // type-specifier
+    TypeSpecifierWidth getTypeSpecWidth() const {
+      return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
+    }
+    TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
+    TypeSpecifierSign getTypeSpecSign() const {
+      return static_cast<TypeSpecifierSign>(TypeSpecSign);
+    }
+    TST getTypeSpecType() const { return (TST)TypeSpecType; }
+    bool isTypeAltiVecVector() const { return TypeAltiVecVector; }
+    bool isTypeAltiVecPixel() const { return TypeAltiVecPixel; }
+    bool isTypeAltiVecBool() const { return TypeAltiVecBool; }
+    bool isTypeSpecOwned() const { return TypeSpecOwned; }
+    bool isTypeRep() const { return isTypeRep((TST)TypeSpecType); }
+    bool isTypeSpecPipe() const { return TypeSpecPipe; }
+    bool isTypeSpecSat() const { return TypeSpecSat; }
+    bool isConstrainedAuto() const { return ConstrainedAuto; }
+
+    ParsedType getRepAsType() const {
+      assert(isTypeRep((TST)TypeSpecType) && "DeclSpec does not store a type");
+      return TypeRep;
+    }
+    Decl *getRepAsDecl() const {
+      assert(isDeclRep((TST)TypeSpecType) && "DeclSpec does not store a decl");
+      return DeclRep;
+    }
+    Expr *getRepAsExpr() const {
+      assert(isExprRep((TST)TypeSpecType) && "DeclSpec does not store an expr");
+      return ExprRep;
+    }
 
-  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
-  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
-  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
+    Expr *getPackIndexingExpr() const {
+      assert(TypeSpecType == TST_typename_pack_indexing &&
+             "DeclSpec is not a pack indexing expr");
+      return PackIndexingExpr;
+    }
 
-  SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
-  SourceRange getTypeSpecWidthRange() const { return TSWRange; }
-  SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
-  SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
-  SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
-  SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
-  SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
-
-  SourceLocation getTypeSpecTypeNameLoc() const {
-    assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
-           isExprRep((TST)TypeSpecType));
-    return TSTNameLoc;
-  }
-
-  SourceRange getTypeofParensRange() const { return TypeofParensRange; }
-  void setTypeArgumentRange(SourceRange range) { TypeofParensRange = range; }
-
-  bool hasAutoTypeSpec() const {
-    return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
-            TypeSpecType == TST_decltype_auto);
-  }
-
-  bool hasTagDefinition() const;
-
-  /// Turn a type-specifier-type into a string like "_Bool" or "union".
-  static const char *getSpecifierName(DeclSpec::TST T,
-                                      const PrintingPolicy &Policy);
-  static const char *getSpecifierName(DeclSpec::TQ Q);
-  static const char *getSpecifierName(TypeSpecifierSign S);
-  static const char *getSpecifierName(DeclSpec::TSC C);
-  static const char *getSpecifierName(TypeSpecifierWidth W);
-  static const char *getSpecifierName(DeclSpec::SCS S);
-  static const char *getSpecifierName(DeclSpec::TSCS S);
-  static const char *getSpecifierName(ConstexprSpecKind C);
-  static const char *getSpecifierName(OverflowBehaviorState S);
-
-  // type-qualifiers
-
-  /// getTypeQualifiers - Return a set of TQs.
-  unsigned getTypeQualifiers() const { return TypeQualifiers; }
-  SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
-  SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
-  SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
-  SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
-  SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
-  SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
-  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
+    TemplateIdAnnotation *getRepAsTemplateId() const {
+      assert(isTemplateIdRep((TST)TypeSpecType) &&
+             "DeclSpec does not store a template id");
+      return TemplateIdRep;
+    }
+    CXXScopeSpec &getTypeSpecScope() { return TypeScope; }
+    const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; }
 
-  // overflow behavior qualifiers
-  OverflowBehaviorState getOverflowBehaviorState() const {
-    return static_cast<OverflowBehaviorState>(OB_state);
-  }
-  bool isWrapSpecified() const {
-    return getOverflowBehaviorState() == OverflowBehaviorState::Wrap;
-  }
-  bool isTrapSpecified() const {
-    return getOverflowBehaviorState() == OverflowBehaviorState::Trap;
-  }
-  bool isOverflowBehaviorSpecified() const {
-    return getOverflowBehaviorState() != OverflowBehaviorState::Unspecified;
-  }
-  SourceLocation getOverflowBehaviorLoc() const { return OB_Loc; }
+    SourceRange getSourceRange() const LLVM_READONLY { return Range; }
+    SourceLocation getBeginLoc() const LLVM_READONLY {
+      return Range.getBegin();
+    }
+    SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
+
+    SourceLocation getTypeSpecWidthLoc() const { return TSWRange.getBegin(); }
+    SourceRange getTypeSpecWidthRange() const { return TSWRange; }
+    SourceLocation getTypeSpecComplexLoc() const { return TSCLoc; }
+    SourceLocation getTypeSpecSignLoc() const { return TSSLoc; }
+    SourceLocation getTypeSpecTypeLoc() const { return TSTLoc; }
+    SourceLocation getAltiVecLoc() const { return AltiVecLoc; }
+    SourceLocation getTypeSpecSatLoc() const { return TSSatLoc; }
+
+    SourceLocation getTypeSpecTypeNameLoc() const {
+      assert(isDeclRep((TST)TypeSpecType) || isTypeRep((TST)TypeSpecType) ||
+             isExprRep((TST)TypeSpecType));
+      return TSTNameLoc;
+    }
 
-  bool SetOverflowBehavior(OverflowBehaviorType::OverflowBehaviorKind Kind,
-                           SourceLocation Loc, const char *&PrevSpec,
-                           unsigned &DiagID);
+    SourceRange getTypeofParensRange() const { return TypeofParensRange; }
+    void setTypeArgumentRange(SourceRange range) { TypeofParensRange = range; }
 
-  /// Clear out all of the type qualifiers.
-  void ClearTypeQualifiers() {
-    TypeQualifiers = 0;
-    TQ_constLoc = SourceLocation();
-    TQ_restrictLoc = SourceLocation();
-    TQ_volatileLoc = SourceLocation();
-    TQ_atomicLoc = SourceLocation();
-    TQ_unalignedLoc = SourceLocation();
-    TQ_pipeLoc = SourceLocation();
-    OB_state = static_cast<unsigned>(OverflowBehaviorState::Unspecified);
-    OB_Loc = SourceLocation();
-  }
+    bool hasAutoTypeSpec() const {
+      return (TypeSpecType == TST_auto || TypeSpecType == TST_auto_type ||
+              TypeSpecType == TST_decltype_auto);
+    }
 
-  // function-specifier
-  bool isInlineSpecified() const {
-    return FS_inline_specified | FS_forceinline_specified;
-  }
-  SourceLocation getInlineSpecLoc() const {
-    return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
-  }
+    bool hasTagDefinition() const;
+
+    /// Turn a type-specifier-type into a string like "_Bool" or "union".
+    static const char *getSpecifierName(DeclSpec::TST T,
+                                        const PrintingPolicy &Policy);
+    static const char *getSpecifierName(DeclSpec::TQ Q);
+    static const char *getSpecifierName(TypeSpecifierSign S);
+    static const char *getSpecifierName(DeclSpec::TSC C);
+    static const char *getSpecifierName(TypeSpecifierWidth W);
+    static const char *getSpecifierName(DeclSpec::SCS S);
+    static const char *getSpecifierName(DeclSpec::TSCS S);
+    static const char *getSpecifierName(ConstexprSpecKind C);
+    static const char *getSpecifierName(OverflowBehaviorState S);
+
+    // type-qualifiers
+
+    /// getTypeQualifiers - Return a set of TQs.
+    unsigned getTypeQualifiers() const { return TypeQualifiers; }
+    SourceLocation getConstSpecLoc() const { return TQ_constLoc; }
+    SourceLocation getRestrictSpecLoc() const { return TQ_restrictLoc; }
+    SourceLocation getVolatileSpecLoc() const { return TQ_volatileLoc; }
+    SourceLocation getAtomicSpecLoc() const { return TQ_atomicLoc; }
+    SourceLocation getUnalignedSpecLoc() const { return TQ_unalignedLoc; }
+    SourceLocation getPipeLoc() const { return TQ_pipeLoc; }
+    SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
 
-  ExplicitSpecifier getExplicitSpecifier() const {
-    return FS_explicit_specifier;
-  }
+    // overflow behavior qualifiers
+    OverflowBehaviorState getOverflowBehaviorState() const {
+      return static_cast<OverflowBehaviorState>(OB_state);
+    }
+    bool isWrapSpecified() const {
+      return getOverflowBehaviorState() == OverflowBehaviorState::Wrap;
+    }
+    bool isTrapSpecified() const {
+      return getOverflowBehaviorState() == OverflowBehaviorState::Trap;
+    }
+    bool isOverflowBehaviorSpecified() const {
+      return getOverflowBehaviorState() != OverflowBehaviorState::Unspecified;
+    }
+    SourceLocation getOverflowBehaviorLoc() const { return OB_Loc; }
 
-  bool isVirtualSpecified() const { return FS_virtual_specified; }
-  SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
+    bool SetOverflowBehavior(OverflowBehaviorType::OverflowBehaviorKind Kind,
+                             SourceLocation Loc, const char *&PrevSpec,
+                             unsigned &DiagID);
 
-  bool hasExplicitSpecifier() const {
-    return FS_explicit_specifier.isSpecified();
-  }
-  SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
-  SourceRange getExplicitSpecRange() const {
-    return FS_explicit_specifier.getExpr()
-               ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
-               : SourceRange(FS_explicitLoc);
-  }
+    /// Clear out all of the type qualifiers.
+    void ClearTypeQualifiers() {
+      TypeQualifiers = 0;
+      TQ_constLoc = SourceLocation();
+      TQ_restrictLoc = SourceLocation();
+      TQ_volatileLoc = SourceLocation();
+      TQ_atomicLoc = SourceLocation();
+      TQ_unalignedLoc = SourceLocation();
+      TQ_pipeLoc = SourceLocation();
+      OB_state = static_cast<unsigned>(OverflowBehaviorState::Unspecified);
+      OB_Loc = SourceLocation();
+    }
 
-  bool isNoreturnSpecified() const { return FS_noreturn_specified; }
-  SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
+    // function-specifier
+    bool isInlineSpecified() const {
+      return FS_inline_specified | FS_forceinline_specified;
+    }
+    SourceLocation getInlineSpecLoc() const {
+      return FS_inline_specified ? FS_inlineLoc : FS_forceinlineLoc;
+    }
 
-  void ClearFunctionSpecs() {
-    FS_inline_specified = false;
-    FS_inlineLoc = SourceLocation();
-    FS_forceinline_specified = false;
-    FS_forceinlineLoc = SourceLocation();
-    FS_virtual_specified = false;
-    FS_virtualLoc = SourceLocation();
-    FS_explicit_specifier = ExplicitSpecifier();
-    FS_explicitLoc = SourceLocation();
-    FS_explicitCloseParenLoc = SourceLocation();
-    FS_noreturn_specified = false;
-    FS_noreturnLoc = SourceLocation();
-  }
+    ExplicitSpecifier getExplicitSpecifier() const {
+      return FS_explicit_specifier;
+    }
 
-  /// This method calls the passed in handler on each CVRU qual being
-  /// set.
-  /// Handle - a handler to be invoked.
-  void forEachCVRUQualifier(
-      llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
+    bool isVirtualSpecified() const { return FS_virtual_specified; }
+    SourceLocation getVirtualSpecLoc() const { return FS_virtualLoc; }
 
-  /// This method calls the passed in handler on each qual being
-  /// set.
-  /// Handle - a handler to be invoked.
-  void forEachQualifier(
-      llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
+    bool hasExplicitSpecifier() const {
+      return FS_explicit_specifier.isSpecified();
+    }
+    SourceLocation getExplicitSpecLoc() const { return FS_explicitLoc; }
+    SourceRange getExplicitSpecRange() const {
+      return FS_explicit_specifier.getExpr()
+                 ? SourceRange(FS_explicitLoc, FS_explicitCloseParenLoc)
+                 : SourceRange(FS_explicitLoc);
+    }
 
-  /// Return true if any type-specifier has been found.
-  bool hasTypeSpecifier() const {
-    return getTypeSpecType() != DeclSpec::TST_unspecified ||
-           getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
-           getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
-           getTypeSpecSign() != TypeSpecifierSign::Unspecified;
-  }
+    bool isNoreturnSpecified() const { return FS_noreturn_specified; }
+    SourceLocation getNoreturnSpecLoc() const { return FS_noreturnLoc; }
+
+    void ClearFunctionSpecs() {
+      FS_inline_specified = false;
+      FS_inlineLoc = SourceLocation();
+      FS_forceinline_specified = false;
+      FS_forceinlineLoc = SourceLocation();
+      FS_virtual_specified = false;
+      FS_virtualLoc = SourceLocation();
+      FS_explicit_specifier = ExplicitSpecifier();
+      FS_explicitLoc = SourceLocation();
+      FS_explicitCloseParenLoc = SourceLocation();
+      FS_noreturn_specified = false;
+      FS_noreturnLoc = SourceLocation();
+    }
 
-  /// Return a bitmask of which flavors of specifiers this
-  /// DeclSpec includes.
-  unsigned getParsedSpecifiers() const;
+    /// This method calls the passed in handler on each CVRU qual being
+    /// set.
+    /// Handle - a handler to be invoked.
+    void forEachCVRUQualifier(
+        llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
+
+    /// This method calls the passed in handler on each qual being
+    /// set.
+    /// Handle - a handler to be invoked.
+    void forEachQualifier(
+        llvm::function_ref<void(TQ, StringRef, SourceLocation)> Handle);
+
+    /// Return true if any type-specifier has been found.
+    bool hasTypeSpecifier() const {
+      return getTypeSpecType() != DeclSpec::TST_unspecified ||
+             getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
+             getTypeSpecComplex() != DeclSpec::TSC_unspecified ||
+             getTypeSpecSign() != TypeSpecifierSign::Unspecified;
+    }
 
-  /// isEmpty - Return true if this declaration specifier is completely empty:
-  /// no tokens were parsed in the production of it.
-  bool isEmpty() const {
-    return getParsedSpecifiers() == DeclSpec::PQ_None;
-  }
+    /// Return a bitmask of which flavors of specifiers this
+    /// DeclSpec includes.
+    unsigned getParsedSpecifiers() const;
 
-  void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
-  void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
+    /// isEmpty - Return true if this declaration specifier is completely empty:
+    /// no tokens were parsed in the production of it.
+    bool isEmpty() const { return getParsedSpecifiers() == DeclSpec::PQ_None; }
 
-  /// These methods set the specified attribute of the DeclSpec and
-  /// return false if there was no error.  If an error occurs (for
-  /// example, if we tried to set "auto" on a spec with "extern"
-  /// already set), they return true and set PrevSpec and DiagID
-  /// such that
-  ///   Diag(Loc, DiagID) << PrevSpec;
-  /// will yield a useful result.
-  ///
-  /// TODO: use a more general approach that still allows these
-  /// diagnostics to be ignored when desired.
-  bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
-                           const char *&PrevSpec, unsigned &DiagID,
-                           const PrintingPolicy &Policy);
-  bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
-                                 const char *&PrevSpec, unsigned &DiagID);
-  bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc,
-                        const char *&PrevSpec, unsigned &DiagID,
-                        const PrintingPolicy &Policy);
-  bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
-                          unsigned &DiagID);
-  bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
-                       const char *&PrevSpec, unsigned &DiagID);
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, const PrintingPolicy &Policy);
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, ParsedType Rep,
-                       const PrintingPolicy &Policy);
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, TypeResult Rep,
-                       const PrintingPolicy &Policy) {
-    if (Rep.isInvalid())
-      return SetTypeSpecError();
-    return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy);
-  }
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, Decl *Rep, bool Owned,
-                       const PrintingPolicy &Policy);
-  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
-                       SourceLocation TagNameLoc, const char *&PrevSpec,
-                       unsigned &DiagID, ParsedType Rep,
-                       const PrintingPolicy &Policy);
-  bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
-                       SourceLocation TagNameLoc, const char *&PrevSpec,
-                       unsigned &DiagID, Decl *Rep, bool Owned,
-                       const PrintingPolicy &Policy);
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, TemplateIdAnnotation *Rep,
-                       const PrintingPolicy &Policy);
+    void SetRangeStart(SourceLocation Loc) { Range.setBegin(Loc); }
+    void SetRangeEnd(SourceLocation Loc) { Range.setEnd(Loc); }
 
-  bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
-                       unsigned &DiagID, Expr *Rep,
-                       const PrintingPolicy &policy);
-  bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
-                       const char *&PrevSpec, unsigned &DiagID,
-                       const PrintingPolicy &Policy);
-  bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
-                       const char *&PrevSpec, unsigned &DiagID,
-                       const PrintingPolicy &Policy);
-  bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
-                       const char *&PrevSpec, unsigned &DiagID,
-                       const PrintingPolicy &Policy);
-  bool SetTypePipe(bool isPipe, SourceLocation Loc,
+    /// These methods set the specified attribute of the DeclSpec and
+    /// return false if there was no error.  If an error occurs (for
+    /// example, if we tried to set "auto" on a spec with "extern"
+    /// already set), they return true and set PrevSpec and DiagID
+    /// such that
+    ///   Diag(Loc, DiagID) << PrevSpec;
+    /// will yield a useful result.
+    ///
+    /// TODO: use a more general approach that still allows these
+    /// diagnostics to be ignored when desired.
+    bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc,
+                             const char *&PrevSpec, unsigned &DiagID,
+                             const PrintingPolicy &Policy);
+    bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
+                                   const char *&PrevSpec, unsigned &DiagID);
+    bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc,
+                          const char *&PrevSpec, unsigned &DiagID,
+                          const PrintingPolicy &Policy);
+    bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec,
+                            unsigned &DiagID);
+    bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc,
+                         const char *&PrevSpec, unsigned &DiagID);
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, const PrintingPolicy &Policy);
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, ParsedType Rep,
+                         const PrintingPolicy &Policy);
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, TypeResult Rep,
+                         const PrintingPolicy &Policy) {
+      if (Rep.isInvalid())
+        return SetTypeSpecError();
+      return SetTypeSpecType(T, Loc, PrevSpec, DiagID, Rep.get(), Policy);
+    }
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, Decl *Rep, bool Owned,
+                         const PrintingPolicy &Policy);
+    bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
+                         SourceLocation TagNameLoc, const char *&PrevSpec,
+                         unsigned &DiagID, ParsedType Rep,
+                         const PrintingPolicy &Policy);
+    bool SetTypeSpecType(TST T, SourceLocation TagKwLoc,
+                         SourceLocation TagNameLoc, const char *&PrevSpec,
+                         unsigned &DiagID, Decl *Rep, bool Owned,
+                         const PrintingPolicy &Policy);
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, TemplateIdAnnotation *Rep,
+                         const PrintingPolicy &Policy);
+
+    bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec,
+                         unsigned &DiagID, Expr *Rep,
+                         const PrintingPolicy &policy);
+    bool SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc,
+                              const char *&PrevSpec, unsigned &DiagID,
+                              const PrintingPolicy &Policy);
+    bool SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc,
+                             const char *&PrevSpec, unsigned &DiagID,
+                             const PrintingPolicy &Policy);
+    bool SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc,
+                            const char *&PrevSpec, unsigned &DiagID,
+                            const PrintingPolicy &Policy);
+    bool SetTypePipe(bool isPipe, SourceLocation Loc, const char *&PrevSpec,
+                     unsigned &DiagID, const PrintingPolicy &Policy);
+    bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth,
                        const char *&PrevSpec, unsigned &DiagID,
                        const PrintingPolicy &Policy);
-  bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth,
-                     const char *&PrevSpec, unsigned &DiagID,
-                     const PrintingPolicy &Policy);
-  bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
-                      unsigned &DiagID);
+    bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
+                        unsigned &DiagID);
 
-  void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack);
+    void SetPackIndexingExpr(SourceLocation EllipsisLoc, Expr *Pack);
 
-  bool SetTypeSpecError();
-  void UpdateDeclRep(Decl *Rep) {
-    assert(isDeclRep((TST) TypeSpecType));
-    DeclRep = Rep;
-  }
-  void UpdateTypeRep(ParsedType Rep) {
-    assert(isTypeRep((TST) TypeSpecType));
-    TypeRep = Rep;
-  }
-  void UpdateExprRep(Expr *Rep) {
-    assert(isExprRep((TST) TypeSpecType));
-    ExprRep = Rep;
-  }
+    bool SetTypeSpecError();
+    void UpdateDeclRep(Decl *Rep) {
+      assert(isDeclRep((TST)TypeSpecType));
+      DeclRep = Rep;
+    }
+    void UpdateTypeRep(ParsedType Rep) {
+      assert(isTypeRep((TST)TypeSpecType));
+      TypeRep = Rep;
+    }
+    void UpdateExprRep(Expr *Rep) {
+      assert(isExprRep((TST)TypeSpecType));
+      ExprRep = Rep;
+    }
 
-  bool SetTypeQual(TQ T, SourceLocation Loc);
+    bool SetTypeQual(TQ T, SourceLocation Loc);
 
-  bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
-                   unsigned &DiagID, const LangOptions &Lang);
+    bool SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec,
+                     unsigned &DiagID, const LangOptions &Lang);
 
-  bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
-                             unsigned &DiagID);
-  bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
-                                  unsigned &DiagID);
-  bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
-                              unsigned &DiagID);
-  bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
-                               unsigned &DiagID, ExplicitSpecifier ExplicitSpec,
-                               SourceLocation CloseParenLoc);
-  bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
+    bool setFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec,
                                unsigned &DiagID);
+    bool setFunctionSpecForceInline(SourceLocation Loc, const char *&PrevSpec,
+                                    unsigned &DiagID);
+    bool setFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec,
+                                unsigned &DiagID);
+    bool setFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec,
+                                 unsigned &DiagID,
+                                 ExplicitSpecifier ExplicitSpec,
+                                 SourceLocation CloseParenLoc);
+    bool setFunctionSpecNoreturn(SourceLocation Loc, const char *&PrevSpec,
+                                 unsigned &DiagID);
+
+    bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
+                       unsigned &DiagID);
+    bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
+                              unsigned &DiagID);
+    bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc,
+                          const char *&PrevSpec, unsigned &DiagID);
 
-  bool SetFriendSpec(SourceLocation Loc, const char *&PrevSpec,
-                     unsigned &DiagID);
-  bool setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec,
-                            unsigned &DiagID);
-  bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc,
-                        const char *&PrevSpec, unsigned &DiagID);
-
-  FriendSpecified isFriendSpecified() const {
-    return static_cast<FriendSpecified>(FriendLoc.isValid());
-  }
+    FriendSpecified isFriendSpecified() const {
+      return static_cast<FriendSpecified>(FriendLoc.isValid());
+    }
 
-  bool isFriendSpecifiedFirst() const { return FriendSpecifiedFirst; }
+    bool isFriendSpecifiedFirst() const { return FriendSpecifiedFirst; }
 
-  SourceLocation getFriendSpecLoc() const { return FriendLoc; }
+    SourceLocation getFriendSpecLoc() const { return FriendLoc; }
 
-  bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
-  SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
+    bool isModulePrivateSpecified() const { return ModulePrivateLoc.isValid(); }
+    SourceLocation getModulePrivateSpecLoc() const { return ModulePrivateLoc; }
 
-  ConstexprSpecKind getConstexprSpecifier() const {
-    return ConstexprSpecKind(ConstexprSpecifier);
-  }
+    ConstexprSpecKind getConstexprSpecifier() const {
+      return ConstexprSpecKind(ConstexprSpecifier);
+    }
 
-  SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
-  bool hasConstexprSpecifier() const {
-    return getConstexprSpecifier() != ConstexprSpecKind::Unspecified;
-  }
+    SourceLocation getConstexprSpecLoc() const { return ConstexprLoc; }
+    bool hasConstexprSpecifier() const {
+      return getConstexprSpecifier() != ConstexprSpecKind::Unspecified;
+    }
 
-  void ClearConstexprSpec() {
-    ConstexprSpecifier = static_cast<unsigned>(ConstexprSpecKind::Unspecified);
-    ConstexprLoc = SourceLocation();
-  }
+    void ClearConstexprSpec() {
+      ConstexprSpecifier =
+          static_cast<unsigned>(ConstexprSpecKind::Unspecified);
+      ConstexprLoc = SourceLocation();
+    }
 
-  AttributePool &getAttributePool() const {
-    return Attrs.getPool();
-  }
+    AttributePool &getAttributePool() const { return Attrs.getPool(); }
 
-  /// Concatenates two attribute lists.
-  ///
-  /// The GCC attribute syntax allows for the following:
-  ///
-  /// \code
-  /// short __attribute__(( unused, deprecated ))
-  /// int __attribute__(( may_alias, aligned(16) )) var;
-  /// \endcode
-  ///
-  /// This declares 4 attributes using 2 lists. The following syntax is
-  /// also allowed and equivalent to the previous declaration.
-  ///
-  /// \code
-  /// short __attribute__((unused)) __attribute__((deprecated))
-  /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
-  /// \endcode
-  ///
-  void addAttributes(const ParsedAttributesView &AL) {
-    Attrs.prepend(AL.begin(), AL.end());
-  }
+    /// Concatenates two attribute lists.
+    ///
+    /// The GCC attribute syntax allows for the following:
+    ///
+    /// \code
+    /// short __attribute__(( unused, deprecated ))
+    /// int __attribute__(( may_alias, aligned(16) )) var;
+    /// \endcode
+    ///
+    /// This declares 4 attributes using 2 lists. The following syntax is
+    /// also allowed and equivalent to the previous declaration.
+    ///
+    /// \code
+    /// short __attribute__((unused)) __attribute__((deprecated))
+    /// int __attribute__((may_alias)) __attribute__((aligned(16))) var;
+    /// \endcode
+    ///
+    void addAttributes(const ParsedAttributesView &AL) {
+      Attrs.prepend(AL.begin(), AL.end());
+    }
 
-  bool hasAttributes() const { return !Attrs.empty(); }
+    bool hasAttributes() const { return !Attrs.empty(); }
 
-  ParsedAttributes &getAttributes() { return Attrs; }
-  const ParsedAttributes &getAttributes() const { return Attrs; }
+    ParsedAttributes &getAttributes() { return Attrs; }
+    const ParsedAttributes &getAttributes() const { return Attrs; }
 
-  LateParsedTypeAttrInfoList &getLateAttributes() { return LateParsedAttrs; }
-  const LateParsedTypeAttrInfoList &getLateAttributes() const {
-    return LateParsedAttrs;
-  }
+    LateParsedTypeAttrInfoList &getLateAttributes() { return LateParsedAttrs; }
+    const LateParsedTypeAttrInfoList &getLateAttributes() const {
+      return LateParsedAttrs;
+    }
 
-  void takeAttributesAppendingingFrom(ParsedAttributes &attrs) {
-    Attrs.takeAllAppendingFrom(attrs);
-  }
+    void takeAttributesAppendingingFrom(ParsedAttributes &attrs) {
+      Attrs.takeAllAppendingFrom(attrs);
+    }
 
-  /// Finish - This does final analysis of the declspec, issuing diagnostics for
-  /// things like "_Complex" (lacking an FP type).  After calling this method,
-  /// DeclSpec is guaranteed self-consistent, even if an error occurred.
-  void Finish(Sema &S, const PrintingPolicy &Policy);
+    /// Finish - This does final analysis of the declspec, issuing diagnostics
+    /// for things like "_Complex" (lacking an FP type).  After calling this
+    /// method, DeclSpec is guaranteed self-consistent, even if an error
+    /// occurred.
+    void Finish(Sema &S, const PrintingPolicy &Policy);
 
-  void CheckTypeSpec(Sema &S, const PrintingPolicy &Policy);
+    void CheckTypeSpec(Sema &S, const PrintingPolicy &Policy);
 
-  void CheckFriendSpec(Sema &S, const PrintingPolicy &Policy);
+    void CheckFriendSpec(Sema &S, const PrintingPolicy &Policy);
 
-  const WrittenBuiltinSpecs& getWrittenBuiltinSpecs() const {
-    return writtenBS;
-  }
+    const WrittenBuiltinSpecs &getWrittenBuiltinSpecs() const {
+      return writtenBS;
+    }
 
-  ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
-  void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
+    ObjCDeclSpec *getObjCQualifiers() const { return ObjCQualifiers; }
+    void setObjCQualifiers(ObjCDeclSpec *quals) { ObjCQualifiers = quals; }
 
-  /// Checks if this DeclSpec can stand alone, without a Declarator.
-  ///
-  /// Only tag declspecs can stand alone.
-  bool isMissingDeclaratorOk();
-};
+    /// Checks if this DeclSpec can stand alone, without a Declarator.
+    ///
+    /// Only tag declspecs can stand alone.
+    bool isMissingDeclaratorOk();
+  };
 
 /// Captures information about "declaration specifiers" specific to
 /// Objective-C.

``````````

</details>


https://github.com/llvm/llvm-project/pull/239050


More information about the cfe-commits mailing list