clang  19.0.0git
Type.h
Go to the documentation of this file.
1 //===- Type.h - C Language Family Type Representation -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// C Language Family Type Representation
11 ///
12 /// This file defines the clang::Type interface and subclasses, used to
13 /// represent types for languages in the C family.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_CLANG_AST_TYPE_H
18 #define LLVM_CLANG_AST_TYPE_H
19 
22 #include "clang/AST/TemplateName.h"
24 #include "clang/Basic/AttrKinds.h"
25 #include "clang/Basic/Diagnostic.h"
27 #include "clang/Basic/LLVM.h"
29 #include "clang/Basic/Linkage.h"
33 #include "clang/Basic/Specifiers.h"
34 #include "clang/Basic/Visibility.h"
35 #include "llvm/ADT/APInt.h"
36 #include "llvm/ADT/APSInt.h"
37 #include "llvm/ADT/ArrayRef.h"
38 #include "llvm/ADT/FoldingSet.h"
39 #include "llvm/ADT/PointerIntPair.h"
40 #include "llvm/ADT/PointerUnion.h"
41 #include "llvm/ADT/STLForwardCompat.h"
42 #include "llvm/ADT/StringRef.h"
43 #include "llvm/ADT/Twine.h"
44 #include "llvm/ADT/iterator_range.h"
45 #include "llvm/Support/Casting.h"
46 #include "llvm/Support/Compiler.h"
47 #include "llvm/Support/ErrorHandling.h"
48 #include "llvm/Support/PointerLikeTypeTraits.h"
49 #include "llvm/Support/TrailingObjects.h"
50 #include "llvm/Support/type_traits.h"
51 #include <cassert>
52 #include <cstddef>
53 #include <cstdint>
54 #include <cstring>
55 #include <optional>
56 #include <string>
57 #include <type_traits>
58 #include <utility>
59 
60 namespace clang {
61 
62 class BTFTypeTagAttr;
63 class ExtQuals;
64 class QualType;
65 class ConceptDecl;
66 class ValueDecl;
67 class TagDecl;
68 class TemplateParameterList;
69 class Type;
70 
71 enum {
74 };
75 
76 namespace serialization {
77  template <class T> class AbstractTypeReader;
78  template <class T> class AbstractTypeWriter;
79 }
80 
81 } // namespace clang
82 
83 namespace llvm {
84 
85  template <typename T>
86  struct PointerLikeTypeTraits;
87  template<>
89  static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
90 
92  return static_cast< ::clang::Type*>(P);
93  }
94 
95  static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
96  };
97 
98  template<>
100  static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
101 
102  static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
103  return static_cast< ::clang::ExtQuals*>(P);
104  }
105 
106  static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
107  };
108 
109 } // namespace llvm
110 
111 namespace clang {
112 
113 class ASTContext;
114 template <typename> class CanQual;
115 class CXXRecordDecl;
116 class DeclContext;
117 class EnumDecl;
118 class Expr;
119 class ExtQualsTypeCommonBase;
120 class FunctionDecl;
121 class IdentifierInfo;
122 class NamedDecl;
123 class ObjCInterfaceDecl;
124 class ObjCProtocolDecl;
125 class ObjCTypeParamDecl;
126 struct PrintingPolicy;
127 class RecordDecl;
128 class Stmt;
129 class TagDecl;
130 class TemplateArgument;
131 class TemplateArgumentListInfo;
132 class TemplateArgumentLoc;
133 class TemplateTypeParmDecl;
134 class TypedefNameDecl;
135 class UnresolvedUsingTypenameDecl;
136 class UsingShadowDecl;
137 
138 using CanQualType = CanQual<Type>;
139 
140 // Provide forward declarations for all of the *Type classes.
141 #define TYPE(Class, Base) class Class##Type;
142 #include "clang/AST/TypeNodes.inc"
143 
144 /// Pointer-authentication qualifiers.
146  enum : uint32_t {
147  EnabledShift = 0,
148  EnabledBits = 1,
149  EnabledMask = 1 << EnabledShift,
150  AddressDiscriminatedShift = EnabledShift + EnabledBits,
151  AddressDiscriminatedBits = 1,
152  AddressDiscriminatedMask = 1 << AddressDiscriminatedShift,
153  AuthenticationModeShift =
154  AddressDiscriminatedShift + AddressDiscriminatedBits,
155  AuthenticationModeBits = 2,
156  AuthenticationModeMask = ((1 << AuthenticationModeBits) - 1)
157  << AuthenticationModeShift,
158  IsaPointerShift = AuthenticationModeShift + AuthenticationModeBits,
159  IsaPointerBits = 1,
160  IsaPointerMask = ((1 << IsaPointerBits) - 1) << IsaPointerShift,
161  AuthenticatesNullValuesShift = IsaPointerShift + IsaPointerBits,
162  AuthenticatesNullValuesBits = 1,
163  AuthenticatesNullValuesMask = ((1 << AuthenticatesNullValuesBits) - 1)
164  << AuthenticatesNullValuesShift,
165  KeyShift = AuthenticatesNullValuesShift + AuthenticatesNullValuesBits,
166  KeyBits = 10,
167  KeyMask = ((1 << KeyBits) - 1) << KeyShift,
168  DiscriminatorShift = KeyShift + KeyBits,
169  DiscriminatorBits = 16,
170  DiscriminatorMask = ((1u << DiscriminatorBits) - 1) << DiscriminatorShift,
171  };
172 
173  // bits: |0 |1 |2..3 |4 |
174  // |Enabled|Address|AuthenticationMode|ISA pointer|
175  // bits: |5 |6..15| 16...31 |
176  // |AuthenticatesNull|Key |Discriminator|
177  uint32_t Data = 0;
178 
179  // The following static assertions check that each of the 32 bits is present
180  // exactly in one of the constants.
181  static_assert((EnabledBits + AddressDiscriminatedBits +
182  AuthenticationModeBits + IsaPointerBits +
183  AuthenticatesNullValuesBits + KeyBits + DiscriminatorBits) ==
184  32,
185  "PointerAuthQualifier should be exactly 32 bits");
186  static_assert((EnabledMask + AddressDiscriminatedMask +
187  AuthenticationModeMask + IsaPointerMask +
188  AuthenticatesNullValuesMask + KeyMask + DiscriminatorMask) ==
189  0xFFFFFFFF,
190  "All masks should cover the entire bits");
191  static_assert((EnabledMask ^ AddressDiscriminatedMask ^
192  AuthenticationModeMask ^ IsaPointerMask ^
193  AuthenticatesNullValuesMask ^ KeyMask ^ DiscriminatorMask) ==
194  0xFFFFFFFF,
195  "All masks should cover the entire bits");
196 
197  PointerAuthQualifier(unsigned Key, bool IsAddressDiscriminated,
198  unsigned ExtraDiscriminator,
199  PointerAuthenticationMode AuthenticationMode,
200  bool IsIsaPointer, bool AuthenticatesNullValues)
201  : Data(EnabledMask |
202  (IsAddressDiscriminated
203  ? llvm::to_underlying(AddressDiscriminatedMask)
204  : 0) |
205  (Key << KeyShift) |
206  (llvm::to_underlying(AuthenticationMode)
207  << AuthenticationModeShift) |
208  (ExtraDiscriminator << DiscriminatorShift) |
209  (IsIsaPointer << IsaPointerShift) |
210  (AuthenticatesNullValues << AuthenticatesNullValuesShift)) {
211  assert(Key <= KeyNoneInternal);
212  assert(ExtraDiscriminator <= MaxDiscriminator);
213  assert((Data == 0) ==
215  }
216 
217 public:
218  enum {
219  KeyNoneInternal = (1u << KeyBits) - 1,
220 
221  /// The maximum supported pointer-authentication key.
223 
224  /// The maximum supported pointer-authentication discriminator.
225  MaxDiscriminator = (1u << DiscriminatorBits) - 1
226  };
227 
228 public:
229  PointerAuthQualifier() = default;
230 
231  static PointerAuthQualifier
232  Create(unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator,
233  PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer,
234  bool AuthenticatesNullValues) {
235  if (Key == PointerAuthKeyNone)
236  Key = KeyNoneInternal;
237  assert(Key <= KeyNoneInternal && "out-of-range key value");
238  return PointerAuthQualifier(Key, IsAddressDiscriminated, ExtraDiscriminator,
239  AuthenticationMode, IsIsaPointer,
240  AuthenticatesNullValues);
241  }
242 
243  bool isPresent() const {
244  assert((Data == 0) ==
246  return Data != 0;
247  }
248 
249  explicit operator bool() const { return isPresent(); }
250 
251  unsigned getKey() const {
252  assert(isPresent());
253  return (Data & KeyMask) >> KeyShift;
254  }
255 
256  bool hasKeyNone() const { return isPresent() && getKey() == KeyNoneInternal; }
257 
258  bool isAddressDiscriminated() const {
259  assert(isPresent());
260  return (Data & AddressDiscriminatedMask) >> AddressDiscriminatedShift;
261  }
262 
263  unsigned getExtraDiscriminator() const {
264  assert(isPresent());
265  return (Data >> DiscriminatorShift);
266  }
267 
269  return PointerAuthenticationMode((Data & AuthenticationModeMask) >>
270  AuthenticationModeShift);
271  }
272 
273  bool isIsaPointer() const {
274  assert(isPresent());
275  return (Data & IsaPointerMask) >> IsaPointerShift;
276  }
277 
278  bool authenticatesNullValues() const {
279  assert(isPresent());
280  return (Data & AuthenticatesNullValuesMask) >> AuthenticatesNullValuesShift;
281  }
282 
284  return hasKeyNone() ? PointerAuthQualifier() : *this;
285  }
286 
288  return Lhs.Data == Rhs.Data;
289  }
291  return Lhs.Data != Rhs.Data;
292  }
293 
294  bool isEquivalent(PointerAuthQualifier Other) const {
295  return withoutKeyNone() == Other.withoutKeyNone();
296  }
297 
298  uint32_t getAsOpaqueValue() const { return Data; }
299 
300  // Deserialize pointer-auth qualifiers from an opaque representation.
301  static PointerAuthQualifier fromOpaqueValue(uint32_t Opaque) {
302  PointerAuthQualifier Result;
303  Result.Data = Opaque;
304  assert((Result.Data == 0) ==
305  (Result.getAuthenticationMode() == PointerAuthenticationMode::None));
306  return Result;
307  }
308 
309  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Data); }
310 };
311 
312 /// The collection of all-type qualifiers we support.
313 /// Clang supports five independent qualifiers:
314 /// * C99: const, volatile, and restrict
315 /// * MS: __unaligned
316 /// * Embedded C (TR18037): address spaces
317 /// * Objective C: the GC attributes (none, weak, or strong)
318 class Qualifiers {
319 public:
320  enum TQ : uint64_t {
321  // NOTE: These flags must be kept in sync with DeclSpec::TQ.
322  Const = 0x1,
323  Restrict = 0x2,
324  Volatile = 0x4,
326  };
327 
328  enum GC {
329  GCNone = 0,
331  Strong
332  };
333 
335  /// There is no lifetime qualification on this type.
337 
338  /// This object can be modified without requiring retains or
339  /// releases.
341 
342  /// Assigning into this object requires the old value to be
343  /// released and the new value to be retained. The timing of the
344  /// release of the old value is inexact: it may be moved to
345  /// immediately after the last known point where the value is
346  /// live.
348 
349  /// Reading or writing from this object requires a barrier call.
351 
352  /// Assigning into this object requires a lifetime extension.
354  };
355 
356  enum : uint64_t {
357  /// The maximum supported address space number.
358  /// 23 bits should be enough for anyone.
359  MaxAddressSpace = 0x7fffffu,
360 
361  /// The width of the "fast" qualifier mask.
363 
364  /// The fast qualifier mask.
365  FastMask = (1 << FastWidth) - 1
366  };
367 
368  /// Returns the common set of qualifiers while removing them from
369  /// the given sets.
371  Qualifiers Q;
372  PointerAuthQualifier LPtrAuth = L.getPointerAuth();
373  if (LPtrAuth.isPresent() &&
375  LPtrAuth == R.getPointerAuth()) {
376  Q.setPointerAuth(LPtrAuth);
377  PointerAuthQualifier Empty;
378  L.setPointerAuth(Empty);
379  R.setPointerAuth(Empty);
380  }
381 
382  // If both are only CVR-qualified, bit operations are sufficient.
383  if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
384  Q.Mask = L.Mask & R.Mask;
385  L.Mask &= ~Q.Mask;
386  R.Mask &= ~Q.Mask;
387  return Q;
388  }
389 
390  unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
391  Q.addCVRQualifiers(CommonCRV);
392  L.removeCVRQualifiers(CommonCRV);
393  R.removeCVRQualifiers(CommonCRV);
394 
395  if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
397  L.removeObjCGCAttr();
398  R.removeObjCGCAttr();
399  }
400 
401  if (L.getObjCLifetime() == R.getObjCLifetime()) {
403  L.removeObjCLifetime();
404  R.removeObjCLifetime();
405  }
406 
407  if (L.getAddressSpace() == R.getAddressSpace()) {
409  L.removeAddressSpace();
410  R.removeAddressSpace();
411  }
412  return Q;
413  }
414 
415  static Qualifiers fromFastMask(unsigned Mask) {
416  Qualifiers Qs;
417  Qs.addFastQualifiers(Mask);
418  return Qs;
419  }
420 
421  static Qualifiers fromCVRMask(unsigned CVR) {
422  Qualifiers Qs;
423  Qs.addCVRQualifiers(CVR);
424  return Qs;
425  }
426 
427  static Qualifiers fromCVRUMask(unsigned CVRU) {
428  Qualifiers Qs;
429  Qs.addCVRUQualifiers(CVRU);
430  return Qs;
431  }
432 
433  // Deserialize qualifiers from an opaque representation.
435  Qualifiers Qs;
436  Qs.Mask = opaque;
437  return Qs;
438  }
439 
440  // Serialize these qualifiers into an opaque representation.
441  uint64_t getAsOpaqueValue() const { return Mask; }
442 
443  bool hasConst() const { return Mask & Const; }
444  bool hasOnlyConst() const { return Mask == Const; }
445  void removeConst() { Mask &= ~Const; }
446  void addConst() { Mask |= Const; }
448  Qualifiers Qs = *this;
449  Qs.addConst();
450  return Qs;
451  }
452 
453  bool hasVolatile() const { return Mask & Volatile; }
454  bool hasOnlyVolatile() const { return Mask == Volatile; }
455  void removeVolatile() { Mask &= ~Volatile; }
456  void addVolatile() { Mask |= Volatile; }
458  Qualifiers Qs = *this;
459  Qs.addVolatile();
460  return Qs;
461  }
462 
463  bool hasRestrict() const { return Mask & Restrict; }
464  bool hasOnlyRestrict() const { return Mask == Restrict; }
465  void removeRestrict() { Mask &= ~Restrict; }
466  void addRestrict() { Mask |= Restrict; }
468  Qualifiers Qs = *this;
469  Qs.addRestrict();
470  return Qs;
471  }
472 
473  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
474  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
475  unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); }
476 
477  void setCVRQualifiers(unsigned mask) {
478  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
479  Mask = (Mask & ~CVRMask) | mask;
480  }
481  void removeCVRQualifiers(unsigned mask) {
482  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
483  Mask &= ~static_cast<uint64_t>(mask);
484  }
487  }
488  void addCVRQualifiers(unsigned mask) {
489  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
490  Mask |= mask;
491  }
492  void addCVRUQualifiers(unsigned mask) {
493  assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
494  Mask |= mask;
495  }
496 
497  bool hasUnaligned() const { return Mask & UMask; }
498  void setUnaligned(bool flag) {
499  Mask = (Mask & ~UMask) | (flag ? UMask : 0);
500  }
501  void removeUnaligned() { Mask &= ~UMask; }
502  void addUnaligned() { Mask |= UMask; }
503 
504  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
505  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
507  Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
508  }
511  assert(type);
513  }
515  Qualifiers qs = *this;
516  qs.removeObjCGCAttr();
517  return qs;
518  }
520  Qualifiers qs = *this;
521  qs.removeObjCLifetime();
522  return qs;
523  }
525  Qualifiers qs = *this;
526  qs.removeAddressSpace();
527  return qs;
528  }
529 
530  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
532  return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
533  }
535  Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
536  }
539  assert(type);
540  assert(!hasObjCLifetime());
541  Mask |= (type << LifetimeShift);
542  }
543 
544  /// True if the lifetime is neither None or ExplicitNone.
546  ObjCLifetime lifetime = getObjCLifetime();
547  return (lifetime > OCL_ExplicitNone);
548  }
549 
550  /// True if the lifetime is either strong or weak.
552  ObjCLifetime lifetime = getObjCLifetime();
553  return (lifetime == OCL_Strong || lifetime == OCL_Weak);
554  }
555 
556  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
558  return static_cast<LangAS>(Mask >> AddressSpaceShift);
559  }
562  }
563  /// Get the address space attribute value to be printed by diagnostics.
565  auto Addr = getAddressSpace();
566  // This function is not supposed to be used with language specific
567  // address spaces. If that happens, the diagnostic message should consider
568  // printing the QualType instead of the address space value.
569  assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace());
570  if (Addr != LangAS::Default)
571  return toTargetAddressSpace(Addr);
572  // TODO: The diagnostic messages where Addr may be 0 should be fixed
573  // since it cannot differentiate the situation where 0 denotes the default
574  // address space or user specified __attribute__((address_space(0))).
575  return 0;
576  }
577  void setAddressSpace(LangAS space) {
578  assert((unsigned)space <= MaxAddressSpace);
579  Mask = (Mask & ~AddressSpaceMask)
580  | (((uint32_t) space) << AddressSpaceShift);
581  }
583  void addAddressSpace(LangAS space, bool AllowDefaultAddrSpace = false) {
584  assert(space != LangAS::Default || AllowDefaultAddrSpace);
585  setAddressSpace(space);
586  }
587 
588  bool hasPointerAuth() const { return Mask & PtrAuthMask; }
590  return PointerAuthQualifier::fromOpaqueValue(Mask >> PtrAuthShift);
591  }
593  Mask = (Mask & ~PtrAuthMask) |
594  (uint64_t(Q.getAsOpaqueValue()) << PtrAuthShift);
595  }
596  void removePointerAuth() { Mask &= ~PtrAuthMask; }
598  assert(Q.isPresent());
599  setPointerAuth(Q);
600  }
601 
602  // Fast qualifiers are those that can be allocated directly
603  // on a QualType object.
604  bool hasFastQualifiers() const { return getFastQualifiers(); }
605  unsigned getFastQualifiers() const { return Mask & FastMask; }
606  void setFastQualifiers(unsigned mask) {
607  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
608  Mask = (Mask & ~FastMask) | mask;
609  }
610  void removeFastQualifiers(unsigned mask) {
611  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
612  Mask &= ~static_cast<uint64_t>(mask);
613  }
616  }
617  void addFastQualifiers(unsigned mask) {
618  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
619  Mask |= mask;
620  }
621 
622  /// Return true if the set contains any qualifiers which require an ExtQuals
623  /// node to be allocated.
624  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
626  Qualifiers Quals = *this;
627  Quals.setFastQualifiers(0);
628  return Quals;
629  }
630 
631  /// Return true if the set contains any qualifiers.
632  bool hasQualifiers() const { return Mask; }
633  bool empty() const { return !Mask; }
634 
635  /// Add the qualifiers from the given set to this set.
637  // If the other set doesn't have any non-boolean qualifiers, just
638  // bit-or it in.
639  if (!(Q.Mask & ~CVRMask))
640  Mask |= Q.Mask;
641  else {
642  Mask |= (Q.Mask & CVRMask);
643  if (Q.hasAddressSpace())
645  if (Q.hasObjCGCAttr())
647  if (Q.hasObjCLifetime())
649  if (Q.hasPointerAuth())
651  }
652  }
653 
654  /// Remove the qualifiers from the given set from this set.
656  // If the other set doesn't have any non-boolean qualifiers, just
657  // bit-and the inverse in.
658  if (!(Q.Mask & ~CVRMask))
659  Mask &= ~Q.Mask;
660  else {
661  Mask &= ~(Q.Mask & CVRMask);
662  if (getObjCGCAttr() == Q.getObjCGCAttr())
664  if (getObjCLifetime() == Q.getObjCLifetime())
666  if (getAddressSpace() == Q.getAddressSpace())
668  if (getPointerAuth() == Q.getPointerAuth())
670  }
671  }
672 
673  /// Add the qualifiers from the given set to this set, given that
674  /// they don't conflict.
676  assert(getAddressSpace() == qs.getAddressSpace() ||
677  !hasAddressSpace() || !qs.hasAddressSpace());
678  assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
679  !hasObjCGCAttr() || !qs.hasObjCGCAttr());
680  assert(getObjCLifetime() == qs.getObjCLifetime() ||
681  !hasObjCLifetime() || !qs.hasObjCLifetime());
682  assert(!hasPointerAuth() || !qs.hasPointerAuth() ||
683  getPointerAuth() == qs.getPointerAuth());
684  Mask |= qs.Mask;
685  }
686 
687  /// Returns true if address space A is equal to or a superset of B.
688  /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
689  /// overlapping address spaces.
690  /// CL1.1 or CL1.2:
691  /// every address space is a superset of itself.
692  /// CL2.0 adds:
693  /// __generic is a superset of any address space except for __constant.
695  // Address spaces must match exactly.
696  return A == B ||
697  // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
698  // for __constant can be used as __generic.
700  // We also define global_device and global_host address spaces,
701  // to distinguish global pointers allocated on host from pointers
702  // allocated on device, which are a subset of __global.
706  B == LangAS::sycl_global_host)) ||
707  // Consider pointer size address spaces to be equivalent to default.
708  ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
709  (isPtrSizeAddressSpace(B) || B == LangAS::Default)) ||
710  // Default is a superset of SYCL address spaces.
711  (A == LangAS::Default &&
714  B == LangAS::sycl_global_host)) ||
715  // In HIP device compilation, any cuda address space is allowed
716  // to implicitly cast into the default address space.
717  (A == LangAS::Default &&
719  B == LangAS::cuda_shared));
720  }
721 
722  /// Returns true if the address space in these qualifiers is equal to or
723  /// a superset of the address space in the argument qualifiers.
726  }
727 
728  /// Determines if these qualifiers compatibly include another set.
729  /// Generally this answers the question of whether an object with the other
730  /// qualifiers can be safely used as an object with these qualifiers.
731  bool compatiblyIncludes(Qualifiers other) const {
732  return isAddressSpaceSupersetOf(other) &&
733  // ObjC GC qualifiers can match, be added, or be removed, but can't
734  // be changed.
735  (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
736  !other.hasObjCGCAttr()) &&
737  // Pointer-auth qualifiers must match exactly.
738  getPointerAuth() == other.getPointerAuth() &&
739  // ObjC lifetime qualifiers must match exactly.
740  getObjCLifetime() == other.getObjCLifetime() &&
741  // CVR qualifiers may subset.
742  (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
743  // U qualifier may superset.
744  (!other.hasUnaligned() || hasUnaligned());
745  }
746 
747  /// Determines if these qualifiers compatibly include another set of
748  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
749  ///
750  /// One set of Objective-C lifetime qualifiers compatibly includes the other
751  /// if the lifetime qualifiers match, or if both are non-__weak and the
752  /// including set also contains the 'const' qualifier, or both are non-__weak
753  /// and one is None (which can only happen in non-ARC modes).
755  if (getObjCLifetime() == other.getObjCLifetime())
756  return true;
757 
758  if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
759  return false;
760 
761  if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
762  return true;
763 
764  return hasConst();
765  }
766 
767  /// Determine whether this set of qualifiers is a strict superset of
768  /// another set of qualifiers, not considering qualifier compatibility.
769  bool isStrictSupersetOf(Qualifiers Other) const;
770 
771  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
772  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
773 
774  explicit operator bool() const { return hasQualifiers(); }
775 
777  addQualifiers(R);
778  return *this;
779  }
780 
781  // Union two qualifier sets. If an enumerated qualifier appears
782  // in both sets, use the one from the right.
784  L += R;
785  return L;
786  }
787 
789  removeQualifiers(R);
790  return *this;
791  }
792 
793  /// Compute the difference between two qualifier sets.
795  L -= R;
796  return L;
797  }
798 
799  std::string getAsString() const;
800  std::string getAsString(const PrintingPolicy &Policy) const;
801 
802  static std::string getAddrSpaceAsString(LangAS AS);
803 
804  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
805  void print(raw_ostream &OS, const PrintingPolicy &Policy,
806  bool appendSpaceIfNonEmpty = false) const;
807 
808  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Mask); }
809 
810 private:
811  // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|32 ... 63|
812  // |C R V|U|GCAttr|Lifetime|AddressSpace| PtrAuth |
813  uint64_t Mask = 0;
814  static_assert(sizeof(PointerAuthQualifier) == sizeof(uint32_t),
815  "PointerAuthQualifier must be 32 bits");
816 
817  static constexpr uint64_t UMask = 0x8;
818  static constexpr uint64_t UShift = 3;
819  static constexpr uint64_t GCAttrMask = 0x30;
820  static constexpr uint64_t GCAttrShift = 4;
821  static constexpr uint64_t LifetimeMask = 0x1C0;
822  static constexpr uint64_t LifetimeShift = 6;
823  static constexpr uint64_t AddressSpaceMask =
824  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
825  static constexpr uint64_t AddressSpaceShift = 9;
826  static constexpr uint64_t PtrAuthShift = 32;
827  static constexpr uint64_t PtrAuthMask = uint64_t(0xffffffff) << PtrAuthShift;
828 };
829 
831  Qualifiers Quals;
832  bool HasAtomic;
833 
834 public:
835  QualifiersAndAtomic() : HasAtomic(false) {}
836  QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
837  : Quals(Quals), HasAtomic(HasAtomic) {}
838 
839  operator Qualifiers() const { return Quals; }
840 
841  bool hasVolatile() const { return Quals.hasVolatile(); }
842  bool hasConst() const { return Quals.hasConst(); }
843  bool hasRestrict() const { return Quals.hasRestrict(); }
844  bool hasAtomic() const { return HasAtomic; }
845 
846  void addVolatile() { Quals.addVolatile(); }
847  void addConst() { Quals.addConst(); }
848  void addRestrict() { Quals.addRestrict(); }
849  void addAtomic() { HasAtomic = true; }
850 
851  void removeVolatile() { Quals.removeVolatile(); }
852  void removeConst() { Quals.removeConst(); }
853  void removeRestrict() { Quals.removeRestrict(); }
854  void removeAtomic() { HasAtomic = false; }
855 
857  return {Quals.withVolatile(), HasAtomic};
858  }
859  QualifiersAndAtomic withConst() { return {Quals.withConst(), HasAtomic}; }
861  return {Quals.withRestrict(), HasAtomic};
862  }
863  QualifiersAndAtomic withAtomic() { return {Quals, true}; }
864 
866  Quals += RHS;
867  return *this;
868  }
869 };
870 
871 /// A std::pair-like structure for storing a qualified type split
872 /// into its local qualifiers and its locally-unqualified type.
874  /// The locally-unqualified type.
875  const Type *Ty = nullptr;
876 
877  /// The local qualifiers.
879 
880  SplitQualType() = default;
881  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
882 
883  SplitQualType getSingleStepDesugaredType() const; // end of this file
884 
885  // Make std::tie work.
886  std::pair<const Type *,Qualifiers> asPair() const {
887  return std::pair<const Type *, Qualifiers>(Ty, Quals);
888  }
889 
891  return a.Ty == b.Ty && a.Quals == b.Quals;
892  }
894  return a.Ty != b.Ty || a.Quals != b.Quals;
895  }
896 };
897 
898 /// The kind of type we are substituting Objective-C type arguments into.
899 ///
900 /// The kind of substitution affects the replacement of type parameters when
901 /// no concrete type information is provided, e.g., when dealing with an
902 /// unspecialized type.
904  /// An ordinary type.
905  Ordinary,
906 
907  /// The result type of a method or function.
908  Result,
909 
910  /// The parameter type of a method or function.
911  Parameter,
912 
913  /// The type of a property.
914  Property,
915 
916  /// The superclass of a type.
917  Superclass,
918 };
919 
920 /// The kind of 'typeof' expression we're after.
921 enum class TypeOfKind : uint8_t {
922  Qualified,
923  Unqualified,
924 };
925 
926 /// A (possibly-)qualified type.
927 ///
928 /// For efficiency, we don't store CV-qualified types as nodes on their
929 /// own: instead each reference to a type stores the qualifiers. This
930 /// greatly reduces the number of nodes we need to allocate for types (for
931 /// example we only need one for 'int', 'const int', 'volatile int',
932 /// 'const volatile int', etc).
933 ///
934 /// As an added efficiency bonus, instead of making this a pair, we
935 /// just store the two bits we care about in the low bits of the
936 /// pointer. To handle the packing/unpacking, we make QualType be a
937 /// simple wrapper class that acts like a smart pointer. A third bit
938 /// indicates whether there are extended qualifiers present, in which
939 /// case the pointer points to a special structure.
940 class QualType {
941  friend class QualifierCollector;
942 
943  // Thankfully, these are efficiently composable.
944  llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
946 
947  const ExtQuals *getExtQualsUnsafe() const {
948  return Value.getPointer().get<const ExtQuals*>();
949  }
950 
951  const Type *getTypePtrUnsafe() const {
952  return Value.getPointer().get<const Type*>();
953  }
954 
955  const ExtQualsTypeCommonBase *getCommonPtr() const {
956  assert(!isNull() && "Cannot retrieve a NULL type pointer");
957  auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
958  CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
959  return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
960  }
961 
962 public:
963  QualType() = default;
964  QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
965  QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
966 
967  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
968  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
969 
970  bool UseExcessPrecision(const ASTContext &Ctx);
971 
972  /// Retrieves a pointer to the underlying (unqualified) type.
973  ///
974  /// This function requires that the type not be NULL. If the type might be
975  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
976  const Type *getTypePtr() const;
977 
978  const Type *getTypePtrOrNull() const;
979 
980  /// Retrieves a pointer to the name of the base type.
981  const IdentifierInfo *getBaseTypeIdentifier() const;
982 
983  /// Divides a QualType into its unqualified type and a set of local
984  /// qualifiers.
985  SplitQualType split() const;
986 
987  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
988 
989  static QualType getFromOpaquePtr(const void *Ptr) {
990  QualType T;
991  T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
992  return T;
993  }
994 
995  const Type &operator*() const {
996  return *getTypePtr();
997  }
998 
999  const Type *operator->() const {
1000  return getTypePtr();
1001  }
1002 
1003  bool isCanonical() const;
1004  bool isCanonicalAsParam() const;
1005 
1006  /// Return true if this QualType doesn't point to a type yet.
1007  bool isNull() const {
1008  return Value.getPointer().isNull();
1009  }
1010 
1011  // Determines if a type can form `T&`.
1012  bool isReferenceable() const;
1013 
1014  /// Determine whether this particular QualType instance has the
1015  /// "const" qualifier set, without looking through typedefs that may have
1016  /// added "const" at a different level.
1017  bool isLocalConstQualified() const {
1019  }
1020 
1021  /// Determine whether this type is const-qualified.
1022  bool isConstQualified() const;
1023 
1025  MutableField,
1029  };
1030  /// Determine whether instances of this type can be placed in immutable
1031  /// storage.
1032  /// If ExcludeCtor is true, the duration when the object's constructor runs
1033  /// will not be considered. The caller will need to verify that the object is
1034  /// not written to during its construction. ExcludeDtor works similarly.
1035  std::optional<NonConstantStorageReason>
1036  isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
1037  bool ExcludeDtor);
1038 
1039  bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
1040  bool ExcludeDtor) {
1041  return !isNonConstantStorage(Ctx, ExcludeCtor, ExcludeDtor);
1042  }
1043 
1044  /// Determine whether this particular QualType instance has the
1045  /// "restrict" qualifier set, without looking through typedefs that may have
1046  /// added "restrict" at a different level.
1049  }
1050 
1051  /// Determine whether this type is restrict-qualified.
1052  bool isRestrictQualified() const;
1053 
1054  /// Determine whether this particular QualType instance has the
1055  /// "volatile" qualifier set, without looking through typedefs that may have
1056  /// added "volatile" at a different level.
1059  }
1060 
1061  /// Determine whether this type is volatile-qualified.
1062  bool isVolatileQualified() const;
1063 
1064  /// Determine whether this particular QualType instance has any
1065  /// qualifiers, without looking through any typedefs that might add
1066  /// qualifiers at a different level.
1067  bool hasLocalQualifiers() const {
1069  }
1070 
1071  /// Determine whether this type has any qualifiers.
1072  bool hasQualifiers() const;
1073 
1074  /// Determine whether this particular QualType instance has any
1075  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
1076  /// instance.
1078  return Value.getPointer().is<const ExtQuals*>();
1079  }
1080 
1081  /// Retrieve the set of qualifiers local to this particular QualType
1082  /// instance, not including any qualifiers acquired through typedefs or
1083  /// other sugar.
1085 
1086  /// Retrieve the set of qualifiers applied to this type.
1087  Qualifiers getQualifiers() const;
1088 
1089  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
1090  /// local to this particular QualType instance, not including any qualifiers
1091  /// acquired through typedefs or other sugar.
1092  unsigned getLocalCVRQualifiers() const {
1093  return getLocalFastQualifiers();
1094  }
1095 
1096  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
1097  /// applied to this type.
1098  unsigned getCVRQualifiers() const;
1099 
1100  bool isConstant(const ASTContext& Ctx) const {
1101  return QualType::isConstant(*this, Ctx);
1102  }
1103 
1104  /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
1105  bool isPODType(const ASTContext &Context) const;
1106 
1107  /// Return true if this is a POD type according to the rules of the C++98
1108  /// standard, regardless of the current compilation's language.
1109  bool isCXX98PODType(const ASTContext &Context) const;
1110 
1111  /// Return true if this is a POD type according to the more relaxed rules
1112  /// of the C++11 standard, regardless of the current compilation's language.
1113  /// (C++0x [basic.types]p9). Note that, unlike
1114  /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
1115  bool isCXX11PODType(const ASTContext &Context) const;
1116 
1117  /// Return true if this is a trivial type per (C++0x [basic.types]p9)
1118  bool isTrivialType(const ASTContext &Context) const;
1119 
1120  /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
1121  bool isTriviallyCopyableType(const ASTContext &Context) const;
1122 
1123  /// Return true if this is a trivially copyable type
1124  bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
1125 
1126  /// Return true if this is a trivially relocatable type.
1127  bool isTriviallyRelocatableType(const ASTContext &Context) const;
1128 
1129  /// Return true if this is a trivially equality comparable type.
1130  bool isTriviallyEqualityComparableType(const ASTContext &Context) const;
1131 
1132  /// Returns true if it is a class and it might be dynamic.
1133  bool mayBeDynamicClass() const;
1134 
1135  /// Returns true if it is not a class or if the class might not be dynamic.
1136  bool mayBeNotDynamicClass() const;
1137 
1138  /// Returns true if it is a WebAssembly Reference Type.
1139  bool isWebAssemblyReferenceType() const;
1140 
1141  /// Returns true if it is a WebAssembly Externref Type.
1142  bool isWebAssemblyExternrefType() const;
1143 
1144  /// Returns true if it is a WebAssembly Funcref Type.
1145  bool isWebAssemblyFuncrefType() const;
1146 
1147  // Don't promise in the API that anything besides 'const' can be
1148  // easily added.
1149 
1150  /// Add the `const` type qualifier to this QualType.
1151  void addConst() {
1153  }
1156  }
1157 
1158  /// Add the `volatile` type qualifier to this QualType.
1159  void addVolatile() {
1161  }
1164  }
1165 
1166  /// Add the `restrict` qualifier to this QualType.
1167  void addRestrict() {
1169  }
1172  }
1173 
1174  QualType withCVRQualifiers(unsigned CVR) const {
1175  return withFastQualifiers(CVR);
1176  }
1177 
1178  void addFastQualifiers(unsigned TQs) {
1179  assert(!(TQs & ~Qualifiers::FastMask)
1180  && "non-fast qualifier bits set in mask!");
1181  Value.setInt(Value.getInt() | TQs);
1182  }
1183 
1184  void removeLocalConst();
1185  void removeLocalVolatile();
1186  void removeLocalRestrict();
1187 
1188  void removeLocalFastQualifiers() { Value.setInt(0); }
1189  void removeLocalFastQualifiers(unsigned Mask) {
1190  assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
1191  Value.setInt(Value.getInt() & ~Mask);
1192  }
1193 
1194  // Creates a type with the given qualifiers in addition to any
1195  // qualifiers already on this type.
1196  QualType withFastQualifiers(unsigned TQs) const {
1197  QualType T = *this;
1198  T.addFastQualifiers(TQs);
1199  return T;
1200  }
1201 
1202  // Creates a type with exactly the given fast qualifiers, removing
1203  // any existing fast qualifiers.
1206  }
1207 
1208  // Removes fast qualifiers, but leaves any extended qualifiers in place.
1210  QualType T = *this;
1211  T.removeLocalFastQualifiers();
1212  return T;
1213  }
1214 
1215  QualType getCanonicalType() const;
1216 
1217  /// Return this type with all of the instance-specific qualifiers
1218  /// removed, but without removing any qualifiers that may have been applied
1219  /// through typedefs.
1221 
1222  /// Retrieve the unqualified variant of the given type,
1223  /// removing as little sugar as possible.
1224  ///
1225  /// This routine looks through various kinds of sugar to find the
1226  /// least-desugared type that is unqualified. For example, given:
1227  ///
1228  /// \code
1229  /// typedef int Integer;
1230  /// typedef const Integer CInteger;
1231  /// typedef CInteger DifferenceType;
1232  /// \endcode
1233  ///
1234  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
1235  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
1236  ///
1237  /// The resulting type might still be qualified if it's sugar for an array
1238  /// type. To strip qualifiers even from within a sugared array type, use
1239  /// ASTContext::getUnqualifiedArrayType.
1240  ///
1241  /// Note: In C, the _Atomic qualifier is special (see C23 6.2.5p32 for
1242  /// details), and it is not stripped by this function. Use
1243  /// getAtomicUnqualifiedType() to strip qualifiers including _Atomic.
1244  inline QualType getUnqualifiedType() const;
1245 
1246  /// Retrieve the unqualified variant of the given type, removing as little
1247  /// sugar as possible.
1248  ///
1249  /// Like getUnqualifiedType(), but also returns the set of
1250  /// qualifiers that were built up.
1251  ///
1252  /// The resulting type might still be qualified if it's sugar for an array
1253  /// type. To strip qualifiers even from within a sugared array type, use
1254  /// ASTContext::getUnqualifiedArrayType.
1255  inline SplitQualType getSplitUnqualifiedType() const;
1256 
1257  /// Determine whether this type is more qualified than the other
1258  /// given type, requiring exact equality for non-CVR qualifiers.
1259  bool isMoreQualifiedThan(QualType Other) const;
1260 
1261  /// Determine whether this type is at least as qualified as the other
1262  /// given type, requiring exact equality for non-CVR qualifiers.
1263  bool isAtLeastAsQualifiedAs(QualType Other) const;
1264 
1265  QualType getNonReferenceType() const;
1266 
1267  /// Determine the type of a (typically non-lvalue) expression with the
1268  /// specified result type.
1269  ///
1270  /// This routine should be used for expressions for which the return type is
1271  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
1272  /// an lvalue. It removes a top-level reference (since there are no
1273  /// expressions of reference type) and deletes top-level cvr-qualifiers
1274  /// from non-class types (in C++) or all types (in C).
1275  QualType getNonLValueExprType(const ASTContext &Context) const;
1276 
1277  /// Remove an outer pack expansion type (if any) from this type. Used as part
1278  /// of converting the type of a declaration to the type of an expression that
1279  /// references that expression. It's meaningless for an expression to have a
1280  /// pack expansion type.
1282 
1283  /// Return the specified type with any "sugar" removed from
1284  /// the type. This takes off typedefs, typeof's etc. If the outer level of
1285  /// the type is already concrete, it returns it unmodified. This is similar
1286  /// to getting the canonical type, but it doesn't remove *all* typedefs. For
1287  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
1288  /// concrete.
1289  ///
1290  /// Qualifiers are left in place.
1291  QualType getDesugaredType(const ASTContext &Context) const {
1292  return getDesugaredType(*this, Context);
1293  }
1294 
1296  return getSplitDesugaredType(*this);
1297  }
1298 
1299  /// Return the specified type with one level of "sugar" removed from
1300  /// the type.
1301  ///
1302  /// This routine takes off the first typedef, typeof, etc. If the outer level
1303  /// of the type is already concrete, it returns it unmodified.
1305  return getSingleStepDesugaredTypeImpl(*this, Context);
1306  }
1307 
1308  /// Returns the specified type after dropping any
1309  /// outer-level parentheses.
1311  if (isa<ParenType>(*this))
1312  return QualType::IgnoreParens(*this);
1313  return *this;
1314  }
1315 
1316  /// Indicate whether the specified types and qualifiers are identical.
1317  friend bool operator==(const QualType &LHS, const QualType &RHS) {
1318  return LHS.Value == RHS.Value;
1319  }
1320  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
1321  return LHS.Value != RHS.Value;
1322  }
1323  friend bool operator<(const QualType &LHS, const QualType &RHS) {
1324  return LHS.Value < RHS.Value;
1325  }
1326 
1327  static std::string getAsString(SplitQualType split,
1328  const PrintingPolicy &Policy) {
1329  return getAsString(split.Ty, split.Quals, Policy);
1330  }
1331  static std::string getAsString(const Type *ty, Qualifiers qs,
1332  const PrintingPolicy &Policy);
1333 
1334  std::string getAsString() const;
1335  std::string getAsString(const PrintingPolicy &Policy) const;
1336 
1337  void print(raw_ostream &OS, const PrintingPolicy &Policy,
1338  const Twine &PlaceHolder = Twine(),
1339  unsigned Indentation = 0) const;
1340 
1341  static void print(SplitQualType split, raw_ostream &OS,
1342  const PrintingPolicy &policy, const Twine &PlaceHolder,
1343  unsigned Indentation = 0) {
1344  return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
1345  }
1346 
1347  static void print(const Type *ty, Qualifiers qs,
1348  raw_ostream &OS, const PrintingPolicy &policy,
1349  const Twine &PlaceHolder,
1350  unsigned Indentation = 0);
1351 
1352  void getAsStringInternal(std::string &Str,
1353  const PrintingPolicy &Policy) const;
1354 
1355  static void getAsStringInternal(SplitQualType split, std::string &out,
1356  const PrintingPolicy &policy) {
1357  return getAsStringInternal(split.Ty, split.Quals, out, policy);
1358  }
1359 
1360  static void getAsStringInternal(const Type *ty, Qualifiers qs,
1361  std::string &out,
1362  const PrintingPolicy &policy);
1363 
1365  const QualType &T;
1366  const PrintingPolicy &Policy;
1367  const Twine &PlaceHolder;
1368  unsigned Indentation;
1369 
1370  public:
1372  const Twine &PlaceHolder, unsigned Indentation)
1373  : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1374  Indentation(Indentation) {}
1375 
1376  friend raw_ostream &operator<<(raw_ostream &OS,
1377  const StreamedQualTypeHelper &SQT) {
1378  SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1379  return OS;
1380  }
1381  };
1382 
1384  const Twine &PlaceHolder = Twine(),
1385  unsigned Indentation = 0) const {
1386  return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1387  }
1388 
1389  void dump(const char *s) const;
1390  void dump() const;
1391  void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
1392 
1393  void Profile(llvm::FoldingSetNodeID &ID) const {
1394  ID.AddPointer(getAsOpaquePtr());
1395  }
1396 
1397  /// Check if this type has any address space qualifier.
1398  inline bool hasAddressSpace() const;
1399 
1400  /// Return the address space of this type.
1401  inline LangAS getAddressSpace() const;
1402 
1403  /// Returns true if address space qualifiers overlap with T address space
1404  /// qualifiers.
1405  /// OpenCL C defines conversion rules for pointers to different address spaces
1406  /// and notion of overlapping address spaces.
1407  /// CL1.1 or CL1.2:
1408  /// address spaces overlap iff they are they same.
1409  /// OpenCL C v2.0 s6.5.5 adds:
1410  /// __generic overlaps with any address space except for __constant.
1412  Qualifiers Q = getQualifiers();
1413  Qualifiers TQ = T.getQualifiers();
1414  // Address spaces overlap if at least one of them is a superset of another
1415  return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q);
1416  }
1417 
1418  /// Returns gc attribute of this type.
1419  inline Qualifiers::GC getObjCGCAttr() const;
1420 
1421  /// true when Type is objc's weak.
1422  bool isObjCGCWeak() const {
1423  return getObjCGCAttr() == Qualifiers::Weak;
1424  }
1425 
1426  /// true when Type is objc's strong.
1427  bool isObjCGCStrong() const {
1428  return getObjCGCAttr() == Qualifiers::Strong;
1429  }
1430 
1431  /// Returns lifetime attribute of this type.
1433  return getQualifiers().getObjCLifetime();
1434  }
1435 
1438  }
1439 
1442  }
1443 
1444  // true when Type is objc's weak and weak is enabled but ARC isn't.
1445  bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1446 
1448  return getQualifiers().getPointerAuth();
1449  }
1450 
1452  /// The type does not fall into any of the following categories. Note that
1453  /// this case is zero-valued so that values of this enum can be used as a
1454  /// boolean condition for non-triviality.
1456 
1457  /// The type is an Objective-C retainable pointer type that is qualified
1458  /// with the ARC __strong qualifier.
1460 
1461  /// The type is an Objective-C retainable pointer type that is qualified
1462  /// with the ARC __weak qualifier.
1464 
1465  /// The type is a struct containing a field whose type is not PCK_Trivial.
1466  PDIK_Struct
1467  };
1468 
1469  /// Functions to query basic properties of non-trivial C struct types.
1470 
1471  /// Check if this is a non-trivial type that would cause a C struct
1472  /// transitively containing this type to be non-trivial to default initialize
1473  /// and return the kind.
1476 
1478  /// The type does not fall into any of the following categories. Note that
1479  /// this case is zero-valued so that values of this enum can be used as a
1480  /// boolean condition for non-triviality.
1482 
1483  /// The type would be trivial except that it is volatile-qualified. Types
1484  /// that fall into one of the other non-trivial cases may additionally be
1485  /// volatile-qualified.
1487 
1488  /// The type is an Objective-C retainable pointer type that is qualified
1489  /// with the ARC __strong qualifier.
1491 
1492  /// The type is an Objective-C retainable pointer type that is qualified
1493  /// with the ARC __weak qualifier.
1495 
1496  /// The type is a struct containing a field whose type is neither
1497  /// PCK_Trivial nor PCK_VolatileTrivial.
1498  /// Note that a C++ struct type does not necessarily match this; C++ copying
1499  /// semantics are too complex to express here, in part because they depend
1500  /// on the exact constructor or assignment operator that is chosen by
1501  /// overload resolution to do the copy.
1502  PCK_Struct
1503  };
1504 
1505  /// Check if this is a non-trivial type that would cause a C struct
1506  /// transitively containing this type to be non-trivial to copy and return the
1507  /// kind.
1509 
1510  /// Check if this is a non-trivial type that would cause a C struct
1511  /// transitively containing this type to be non-trivial to destructively
1512  /// move and return the kind. Destructive move in this context is a C++-style
1513  /// move in which the source object is placed in a valid but unspecified state
1514  /// after it is moved, as opposed to a truly destructive move in which the
1515  /// source object is placed in an uninitialized state.
1517 
1524  };
1525 
1526  /// Returns a nonzero value if objects of this type require
1527  /// non-trivial work to clean up after. Non-zero because it's
1528  /// conceivable that qualifiers (objc_gc(weak)?) could make
1529  /// something require destruction.
1531  return isDestructedTypeImpl(*this);
1532  }
1533 
1534  /// Check if this is or contains a C union that is non-trivial to
1535  /// default-initialize, which is a union that has a member that is non-trivial
1536  /// to default-initialize. If this returns true,
1537  /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct.
1539 
1540  /// Check if this is or contains a C union that is non-trivial to destruct,
1541  /// which is a union that has a member that is non-trivial to destruct. If
1542  /// this returns true, isDestructedType returns DK_nontrivial_c_struct.
1544 
1545  /// Check if this is or contains a C union that is non-trivial to copy, which
1546  /// is a union that has a member that is non-trivial to copy. If this returns
1547  /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct.
1549 
1550  /// Determine whether expressions of the given type are forbidden
1551  /// from being lvalues in C.
1552  ///
1553  /// The expression types that are forbidden to be lvalues are:
1554  /// - 'void', but not qualified void
1555  /// - function types
1556  ///
1557  /// The exact rule here is C99 6.3.2.1:
1558  /// An lvalue is an expression with an object type or an incomplete
1559  /// type other than void.
1560  bool isCForbiddenLValueType() const;
1561 
1562  /// Substitute type arguments for the Objective-C type parameters used in the
1563  /// subject type.
1564  ///
1565  /// \param ctx ASTContext in which the type exists.
1566  ///
1567  /// \param typeArgs The type arguments that will be substituted for the
1568  /// Objective-C type parameters in the subject type, which are generally
1569  /// computed via \c Type::getObjCSubstitutions. If empty, the type
1570  /// parameters will be replaced with their bounds or id/Class, as appropriate
1571  /// for the context.
1572  ///
1573  /// \param context The context in which the subject type was written.
1574  ///
1575  /// \returns the resulting type.
1577  ArrayRef<QualType> typeArgs,
1578  ObjCSubstitutionContext context) const;
1579 
1580  /// Substitute type arguments from an object type for the Objective-C type
1581  /// parameters used in the subject type.
1582  ///
1583  /// This operation combines the computation of type arguments for
1584  /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1585  /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1586  /// callers that need to perform a single substitution in isolation.
1587  ///
1588  /// \param objectType The type of the object whose member type we're
1589  /// substituting into. For example, this might be the receiver of a message
1590  /// or the base of a property access.
1591  ///
1592  /// \param dc The declaration context from which the subject type was
1593  /// retrieved, which indicates (for example) which type parameters should
1594  /// be substituted.
1595  ///
1596  /// \param context The context in which the subject type was written.
1597  ///
1598  /// \returns the subject type after replacing all of the Objective-C type
1599  /// parameters with their corresponding arguments.
1601  const DeclContext *dc,
1602  ObjCSubstitutionContext context) const;
1603 
1604  /// Strip Objective-C "__kindof" types from the given type.
1605  QualType stripObjCKindOfType(const ASTContext &ctx) const;
1606 
1607  /// Remove all qualifiers including _Atomic.
1609 
1610 private:
1611  // These methods are implemented in a separate translation unit;
1612  // "static"-ize them to avoid creating temporary QualTypes in the
1613  // caller.
1614  static bool isConstant(QualType T, const ASTContext& Ctx);
1615  static QualType getDesugaredType(QualType T, const ASTContext &Context);
1617  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1618  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1619  const ASTContext &C);
1620  static QualType IgnoreParens(QualType T);
1621  static DestructionKind isDestructedTypeImpl(QualType type);
1622 
1623  /// Check if \param RD is or contains a non-trivial C union.
1625  static bool hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD);
1626  static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD);
1627 };
1628 
1629 raw_ostream &operator<<(raw_ostream &OS, QualType QT);
1630 
1631 } // namespace clang
1632 
1633 namespace llvm {
1634 
1635 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1636 /// to a specific Type class.
1637 template<> struct simplify_type< ::clang::QualType> {
1639 
1641  return Val.getTypePtr();
1642  }
1643 };
1644 
1645 // Teach SmallPtrSet that QualType is "basically a pointer".
1646 template<>
1647 struct PointerLikeTypeTraits<clang::QualType> {
1648  static inline void *getAsVoidPointer(clang::QualType P) {
1649  return P.getAsOpaquePtr();
1650  }
1651 
1652  static inline clang::QualType getFromVoidPointer(void *P) {
1654  }
1655 
1656  // Various qualifiers go in low bits.
1657  static constexpr int NumLowBitsAvailable = 0;
1658 };
1659 
1660 } // namespace llvm
1661 
1662 namespace clang {
1663 
1664 /// Base class that is common to both the \c ExtQuals and \c Type
1665 /// classes, which allows \c QualType to access the common fields between the
1666 /// two.
1668  friend class ExtQuals;
1669  friend class QualType;
1670  friend class Type;
1671 
1672  /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1673  /// a self-referential pointer (for \c Type).
1674  ///
1675  /// This pointer allows an efficient mapping from a QualType to its
1676  /// underlying type pointer.
1677  const Type *const BaseType;
1678 
1679  /// The canonical type of this type. A QualType.
1680  QualType CanonicalType;
1681 
1682  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1683  : BaseType(baseType), CanonicalType(canon) {}
1684 };
1685 
1686 /// We can encode up to four bits in the low bits of a
1687 /// type pointer, but there are many more type qualifiers that we want
1688 /// to be able to apply to an arbitrary type. Therefore we have this
1689 /// struct, intended to be heap-allocated and used by QualType to
1690 /// store qualifiers.
1691 ///
1692 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1693 /// in three low bits on the QualType pointer; a fourth bit records whether
1694 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1695 /// Objective-C GC attributes) are much more rare.
1696 class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase,
1697  public llvm::FoldingSetNode {
1698  // NOTE: changing the fast qualifiers should be straightforward as
1699  // long as you don't make 'const' non-fast.
1700  // 1. Qualifiers:
1701  // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1702  // Fast qualifiers must occupy the low-order bits.
1703  // b) Update Qualifiers::FastWidth and FastMask.
1704  // 2. QualType:
1705  // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1706  // b) Update remove{Volatile,Restrict}, defined near the end of
1707  // this header.
1708  // 3. ASTContext:
1709  // a) Update get{Volatile,Restrict}Type.
1710 
1711  /// The immutable set of qualifiers applied by this node. Always contains
1712  /// extended qualifiers.
1713  Qualifiers Quals;
1714 
1715  ExtQuals *this_() { return this; }
1716 
1717 public:
1718  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1719  : ExtQualsTypeCommonBase(baseType,
1720  canon.isNull() ? QualType(this_(), 0) : canon),
1721  Quals(quals) {
1722  assert(Quals.hasNonFastQualifiers()
1723  && "ExtQuals created with no fast qualifiers");
1724  assert(!Quals.hasFastQualifiers()
1725  && "ExtQuals created with fast qualifiers");
1726  }
1727 
1728  Qualifiers getQualifiers() const { return Quals; }
1729 
1730  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1731  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1732 
1733  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1735  return Quals.getObjCLifetime();
1736  }
1737 
1738  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1739  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1740 
1741  const Type *getBaseType() const { return BaseType; }
1742 
1743 public:
1744  void Profile(llvm::FoldingSetNodeID &ID) const {
1745  Profile(ID, getBaseType(), Quals);
1746  }
1747 
1748  static void Profile(llvm::FoldingSetNodeID &ID,
1749  const Type *BaseType,
1750  Qualifiers Quals) {
1751  assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1752  ID.AddPointer(BaseType);
1753  Quals.Profile(ID);
1754  }
1755 };
1756 
1757 /// The kind of C++11 ref-qualifier associated with a function type.
1758 /// This determines whether a member function's "this" object can be an
1759 /// lvalue, rvalue, or neither.
1761  /// No ref-qualifier was provided.
1762  RQ_None = 0,
1763 
1764  /// An lvalue ref-qualifier was provided (\c &).
1766 
1767  /// An rvalue ref-qualifier was provided (\c &&).
1768  RQ_RValue
1769 };
1770 
1771 /// Which keyword(s) were used to create an AutoType.
1772 enum class AutoTypeKeyword {
1773  /// auto
1774  Auto,
1775 
1776  /// decltype(auto)
1777  DecltypeAuto,
1778 
1779  /// __auto_type (GNU extension)
1780  GNUAutoType
1781 };
1782 
1783 enum class ArraySizeModifier;
1784 enum class ElaboratedTypeKeyword;
1785 enum class VectorKind;
1786 
1787 /// The base class of the type hierarchy.
1788 ///
1789 /// A central concept with types is that each type always has a canonical
1790 /// type. A canonical type is the type with any typedef names stripped out
1791 /// of it or the types it references. For example, consider:
1792 ///
1793 /// typedef int foo;
1794 /// typedef foo* bar;
1795 /// 'int *' 'foo *' 'bar'
1796 ///
1797 /// There will be a Type object created for 'int'. Since int is canonical, its
1798 /// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1799 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1800 /// there is a PointerType that represents 'int*', which, like 'int', is
1801 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1802 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1803 /// is also 'int*'.
1804 ///
1805 /// Non-canonical types are useful for emitting diagnostics, without losing
1806 /// information about typedefs being used. Canonical types are useful for type
1807 /// comparisons (they allow by-pointer equality tests) and useful for reasoning
1808 /// about whether something has a particular form (e.g. is a function type),
1809 /// because they implicitly, recursively, strip all typedefs out of a type.
1810 ///
1811 /// Types, once created, are immutable.
1812 ///
1813 class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
1814 public:
1815  enum TypeClass {
1816 #define TYPE(Class, Base) Class,
1817 #define LAST_TYPE(Class) TypeLast = Class
1818 #define ABSTRACT_TYPE(Class, Base)
1819 #include "clang/AST/TypeNodes.inc"
1820  };
1821 
1822 private:
1823  /// Bitfields required by the Type class.
1824  class TypeBitfields {
1825  friend class Type;
1826  template <class T> friend class TypePropertyCache;
1827 
1828  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1829  LLVM_PREFERRED_TYPE(TypeClass)
1830  unsigned TC : 8;
1831 
1832  /// Store information on the type dependency.
1833  LLVM_PREFERRED_TYPE(TypeDependence)
1834  unsigned Dependence : llvm::BitWidth<TypeDependence>;
1835 
1836  /// True if the cache (i.e. the bitfields here starting with
1837  /// 'Cache') is valid.
1838  LLVM_PREFERRED_TYPE(bool)
1839  mutable unsigned CacheValid : 1;
1840 
1841  /// Linkage of this type.
1842  LLVM_PREFERRED_TYPE(Linkage)
1843  mutable unsigned CachedLinkage : 3;
1844 
1845  /// Whether this type involves and local or unnamed types.
1846  LLVM_PREFERRED_TYPE(bool)
1847  mutable unsigned CachedLocalOrUnnamed : 1;
1848 
1849  /// Whether this type comes from an AST file.
1850  LLVM_PREFERRED_TYPE(bool)
1851  mutable unsigned FromAST : 1;
1852 
1853  bool isCacheValid() const {
1854  return CacheValid;
1855  }
1856 
1857  Linkage getLinkage() const {
1858  assert(isCacheValid() && "getting linkage from invalid cache");
1859  return static_cast<Linkage>(CachedLinkage);
1860  }
1861 
1862  bool hasLocalOrUnnamedType() const {
1863  assert(isCacheValid() && "getting linkage from invalid cache");
1864  return CachedLocalOrUnnamed;
1865  }
1866  };
1867  enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1868 
1869 protected:
1870  // These classes allow subclasses to somewhat cleanly pack bitfields
1871  // into Type.
1872 
1874  friend class ArrayType;
1875 
1876  LLVM_PREFERRED_TYPE(TypeBitfields)
1877  unsigned : NumTypeBits;
1878 
1879  /// CVR qualifiers from declarations like
1880  /// 'int X[static restrict 4]'. For function parameters only.
1881  LLVM_PREFERRED_TYPE(Qualifiers)
1882  unsigned IndexTypeQuals : 3;
1883 
1884  /// Storage class qualifiers from declarations like
1885  /// 'int X[static restrict 4]'. For function parameters only.
1886  LLVM_PREFERRED_TYPE(ArraySizeModifier)
1887  unsigned SizeModifier : 3;
1888  };
1889  enum { NumArrayTypeBits = NumTypeBits + 6 };
1890 
1892  friend class ConstantArrayType;
1893 
1894  LLVM_PREFERRED_TYPE(ArrayTypeBitfields)
1895  unsigned : NumArrayTypeBits;
1896 
1897  /// Whether we have a stored size expression.
1898  LLVM_PREFERRED_TYPE(bool)
1899  unsigned HasExternalSize : 1;
1900 
1901  LLVM_PREFERRED_TYPE(unsigned)
1902  unsigned SizeWidth : 5;
1903  };
1904 
1906  friend class BuiltinType;
1907 
1908  LLVM_PREFERRED_TYPE(TypeBitfields)
1909  unsigned : NumTypeBits;
1910 
1911  /// The kind (BuiltinType::Kind) of builtin type this is.
1912  static constexpr unsigned NumOfBuiltinTypeBits = 9;
1913  unsigned Kind : NumOfBuiltinTypeBits;
1914  };
1915 
1916  /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1917  /// Only common bits are stored here. Additional uncommon bits are stored
1918  /// in a trailing object after FunctionProtoType.
1920  friend class FunctionProtoType;
1921  friend class FunctionType;
1922 
1923  LLVM_PREFERRED_TYPE(TypeBitfields)
1924  unsigned : NumTypeBits;
1925 
1926  /// Extra information which affects how the function is called, like
1927  /// regparm and the calling convention.
1928  LLVM_PREFERRED_TYPE(CallingConv)
1929  unsigned ExtInfo : 13;
1930 
1931  /// The ref-qualifier associated with a \c FunctionProtoType.
1932  ///
1933  /// This is a value of type \c RefQualifierKind.
1934  LLVM_PREFERRED_TYPE(RefQualifierKind)
1935  unsigned RefQualifier : 2;
1936 
1937  /// Used only by FunctionProtoType, put here to pack with the
1938  /// other bitfields.
1939  /// The qualifiers are part of FunctionProtoType because...
1940  ///
1941  /// C++ 8.3.5p4: The return type, the parameter type list and the
1942  /// cv-qualifier-seq, [...], are part of the function type.
1943  LLVM_PREFERRED_TYPE(Qualifiers)
1944  unsigned FastTypeQuals : Qualifiers::FastWidth;
1945  /// Whether this function has extended Qualifiers.
1946  LLVM_PREFERRED_TYPE(bool)
1947  unsigned HasExtQuals : 1;
1948 
1949  /// The number of parameters this function has, not counting '...'.
1950  /// According to [implimits] 8 bits should be enough here but this is
1951  /// somewhat easy to exceed with metaprogramming and so we would like to
1952  /// keep NumParams as wide as reasonably possible.
1953  unsigned NumParams : 16;
1954 
1955  /// The type of exception specification this function has.
1956  LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
1957  unsigned ExceptionSpecType : 4;
1958 
1959  /// Whether this function has extended parameter information.
1960  LLVM_PREFERRED_TYPE(bool)
1961  unsigned HasExtParameterInfos : 1;
1962 
1963  /// Whether this function has extra bitfields for the prototype.
1964  LLVM_PREFERRED_TYPE(bool)
1965  unsigned HasExtraBitfields : 1;
1966 
1967  /// Whether the function is variadic.
1968  LLVM_PREFERRED_TYPE(bool)
1969  unsigned Variadic : 1;
1970 
1971  /// Whether this function has a trailing return type.
1972  LLVM_PREFERRED_TYPE(bool)
1973  unsigned HasTrailingReturn : 1;
1974  };
1975 
1977  friend class ObjCObjectType;
1978 
1979  LLVM_PREFERRED_TYPE(TypeBitfields)
1980  unsigned : NumTypeBits;
1981 
1982  /// The number of type arguments stored directly on this object type.
1983  unsigned NumTypeArgs : 7;
1984 
1985  /// The number of protocols stored directly on this object type.
1986  unsigned NumProtocols : 6;
1987 
1988  /// Whether this is a "kindof" type.
1989  LLVM_PREFERRED_TYPE(bool)
1990  unsigned IsKindOf : 1;
1991  };
1992 
1994  friend class ReferenceType;
1995 
1996  LLVM_PREFERRED_TYPE(TypeBitfields)
1997  unsigned : NumTypeBits;
1998 
1999  /// True if the type was originally spelled with an lvalue sigil.
2000  /// This is never true of rvalue references but can also be false
2001  /// on lvalue references because of C++0x [dcl.typedef]p9,
2002  /// as follows:
2003  ///
2004  /// typedef int &ref; // lvalue, spelled lvalue
2005  /// typedef int &&rvref; // rvalue
2006  /// ref &a; // lvalue, inner ref, spelled lvalue
2007  /// ref &&a; // lvalue, inner ref
2008  /// rvref &a; // lvalue, inner ref, spelled lvalue
2009  /// rvref &&a; // rvalue, inner ref
2010  LLVM_PREFERRED_TYPE(bool)
2011  unsigned SpelledAsLValue : 1;
2012 
2013  /// True if the inner type is a reference type. This only happens
2014  /// in non-canonical forms.
2015  LLVM_PREFERRED_TYPE(bool)
2016  unsigned InnerRef : 1;
2017  };
2018 
2020  friend class TypeWithKeyword;
2021 
2022  LLVM_PREFERRED_TYPE(TypeBitfields)
2023  unsigned : NumTypeBits;
2024 
2025  /// An ElaboratedTypeKeyword. 8 bits for efficient access.
2026  LLVM_PREFERRED_TYPE(ElaboratedTypeKeyword)
2027  unsigned Keyword : 8;
2028  };
2029 
2030  enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
2031 
2033  friend class ElaboratedType;
2034 
2035  LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
2036  unsigned : NumTypeWithKeywordBits;
2037 
2038  /// Whether the ElaboratedType has a trailing OwnedTagDecl.
2039  LLVM_PREFERRED_TYPE(bool)
2040  unsigned HasOwnedTagDecl : 1;
2041  };
2042 
2044  friend class VectorType;
2045  friend class DependentVectorType;
2046 
2047  LLVM_PREFERRED_TYPE(TypeBitfields)
2048  unsigned : NumTypeBits;
2049 
2050  /// The kind of vector, either a generic vector type or some
2051  /// target-specific vector type such as for AltiVec or Neon.
2052  LLVM_PREFERRED_TYPE(VectorKind)
2053  unsigned VecKind : 4;
2054  /// The number of elements in the vector.
2055  uint32_t NumElements;
2056  };
2057 
2059  friend class AttributedType;
2060 
2061  LLVM_PREFERRED_TYPE(TypeBitfields)
2062  unsigned : NumTypeBits;
2063 
2064  LLVM_PREFERRED_TYPE(attr::Kind)
2065  unsigned AttrKind : 32 - NumTypeBits;
2066  };
2067 
2069  friend class AutoType;
2070 
2071  LLVM_PREFERRED_TYPE(TypeBitfields)
2072  unsigned : NumTypeBits;
2073 
2074  /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
2075  /// or '__auto_type'? AutoTypeKeyword value.
2076  LLVM_PREFERRED_TYPE(AutoTypeKeyword)
2077  unsigned Keyword : 2;
2078 
2079  /// The number of template arguments in the type-constraints, which is
2080  /// expected to be able to hold at least 1024 according to [implimits].
2081  /// However as this limit is somewhat easy to hit with template
2082  /// metaprogramming we'd prefer to keep it as large as possible.
2083  /// At the moment it has been left as a non-bitfield since this type
2084  /// safely fits in 64 bits as an unsigned, so there is no reason to
2085  /// introduce the performance impact of a bitfield.
2086  unsigned NumArgs;
2087  };
2088 
2090  friend class TypeOfType;
2091  friend class TypeOfExprType;
2092 
2093  LLVM_PREFERRED_TYPE(TypeBitfields)
2094  unsigned : NumTypeBits;
2095  LLVM_PREFERRED_TYPE(bool)
2096  unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
2097  };
2098 
2100  friend class UsingType;
2101 
2102  LLVM_PREFERRED_TYPE(TypeBitfields)
2103  unsigned : NumTypeBits;
2104 
2105  /// True if the underlying type is different from the declared one.
2106  LLVM_PREFERRED_TYPE(bool)
2107  unsigned hasTypeDifferentFromDecl : 1;
2108  };
2109 
2111  friend class TypedefType;
2112 
2113  LLVM_PREFERRED_TYPE(TypeBitfields)
2114  unsigned : NumTypeBits;
2115 
2116  /// True if the underlying type is different from the declared one.
2117  LLVM_PREFERRED_TYPE(bool)
2118  unsigned hasTypeDifferentFromDecl : 1;
2119  };
2120 
2123 
2124  LLVM_PREFERRED_TYPE(TypeBitfields)
2125  unsigned : NumTypeBits;
2126 
2127  LLVM_PREFERRED_TYPE(bool)
2128  unsigned HasNonCanonicalUnderlyingType : 1;
2129 
2130  // The index of the template parameter this substitution represents.
2131  unsigned Index : 15;
2132 
2133  /// Represents the index within a pack if this represents a substitution
2134  /// from a pack expansion. This index starts at the end of the pack and
2135  /// increments towards the beginning.
2136  /// Positive non-zero number represents the index + 1.
2137  /// Zero means this is not substituted from an expansion.
2138  unsigned PackIndex : 16;
2139  };
2140 
2143 
2144  LLVM_PREFERRED_TYPE(TypeBitfields)
2145  unsigned : NumTypeBits;
2146 
2147  // The index of the template parameter this substitution represents.
2148  unsigned Index : 16;
2149 
2150  /// The number of template arguments in \c Arguments, which is
2151  /// expected to be able to hold at least 1024 according to [implimits].
2152  /// However as this limit is somewhat easy to hit with template
2153  /// metaprogramming we'd prefer to keep it as large as possible.
2154  unsigned NumArgs : 16;
2155  };
2156 
2159 
2160  LLVM_PREFERRED_TYPE(TypeBitfields)
2161  unsigned : NumTypeBits;
2162 
2163  /// Whether this template specialization type is a substituted type alias.
2164  LLVM_PREFERRED_TYPE(bool)
2165  unsigned TypeAlias : 1;
2166 
2167  /// The number of template arguments named in this class template
2168  /// specialization, which is expected to be able to hold at least 1024
2169  /// according to [implimits]. However, as this limit is somewhat easy to
2170  /// hit with template metaprogramming we'd prefer to keep it as large
2171  /// as possible. At the moment it has been left as a non-bitfield since
2172  /// this type safely fits in 64 bits as an unsigned, so there is no reason
2173  /// to introduce the performance impact of a bitfield.
2174  unsigned NumArgs;
2175  };
2176 
2179 
2180  LLVM_PREFERRED_TYPE(TypeWithKeywordBitfields)
2181  unsigned : NumTypeWithKeywordBits;
2182 
2183  /// The number of template arguments named in this class template
2184  /// specialization, which is expected to be able to hold at least 1024
2185  /// according to [implimits]. However, as this limit is somewhat easy to
2186  /// hit with template metaprogramming we'd prefer to keep it as large
2187  /// as possible. At the moment it has been left as a non-bitfield since
2188  /// this type safely fits in 64 bits as an unsigned, so there is no reason
2189  /// to introduce the performance impact of a bitfield.
2190  unsigned NumArgs;
2191  };
2192 
2194  friend class PackExpansionType;
2195 
2196  LLVM_PREFERRED_TYPE(TypeBitfields)
2197  unsigned : NumTypeBits;
2198 
2199  /// The number of expansions that this pack expansion will
2200  /// generate when substituted (+1), which is expected to be able to
2201  /// hold at least 1024 according to [implimits]. However, as this limit
2202  /// is somewhat easy to hit with template metaprogramming we'd prefer to
2203  /// keep it as large as possible. At the moment it has been left as a
2204  /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
2205  /// there is no reason to introduce the performance impact of a bitfield.
2206  ///
2207  /// This field will only have a non-zero value when some of the parameter
2208  /// packs that occur within the pattern have been substituted but others
2209  /// have not.
2210  unsigned NumExpansions;
2211  };
2212 
2214  friend class CountAttributedType;
2215 
2216  LLVM_PREFERRED_TYPE(TypeBitfields)
2217  unsigned : NumTypeBits;
2218 
2219  static constexpr unsigned NumCoupledDeclsBits = 4;
2220  unsigned NumCoupledDecls : NumCoupledDeclsBits;
2221  LLVM_PREFERRED_TYPE(bool)
2222  unsigned CountInBytes : 1;
2223  LLVM_PREFERRED_TYPE(bool)
2224  unsigned OrNull : 1;
2225  };
2226  static_assert(sizeof(CountAttributedTypeBitfields) <= sizeof(unsigned));
2227 
2228  union {
2229  TypeBitfields TypeBits;
2251  };
2252 
2253 private:
2254  template <class T> friend class TypePropertyCache;
2255 
2256  /// Set whether this type comes from an AST file.
2257  void setFromAST(bool V = true) const {
2258  TypeBits.FromAST = V;
2259  }
2260 
2261 protected:
2262  friend class ASTContext;
2263 
2265  : ExtQualsTypeCommonBase(this,
2266  canon.isNull() ? QualType(this_(), 0) : canon) {
2267  static_assert(sizeof(*this) <=
2268  alignof(decltype(*this)) + sizeof(ExtQualsTypeCommonBase),
2269  "changing bitfields changed sizeof(Type)!");
2270  static_assert(alignof(decltype(*this)) % TypeAlignment == 0,
2271  "Insufficient alignment!");
2272  TypeBits.TC = tc;
2273  TypeBits.Dependence = static_cast<unsigned>(Dependence);
2274  TypeBits.CacheValid = false;
2275  TypeBits.CachedLocalOrUnnamed = false;
2276  TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2277  TypeBits.FromAST = false;
2278  }
2279 
2280  // silence VC++ warning C4355: 'this' : used in base member initializer list
2281  Type *this_() { return this; }
2282 
2284  TypeBits.Dependence = static_cast<unsigned>(D);
2285  }
2286 
2287  void addDependence(TypeDependence D) { setDependence(getDependence() | D); }
2288 
2289 public:
2290  friend class ASTReader;
2291  friend class ASTWriter;
2292  template <class T> friend class serialization::AbstractTypeReader;
2293  template <class T> friend class serialization::AbstractTypeWriter;
2294 
2295  Type(const Type &) = delete;
2296  Type(Type &&) = delete;
2297  Type &operator=(const Type &) = delete;
2298  Type &operator=(Type &&) = delete;
2299 
2300  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
2301 
2302  /// Whether this type comes from an AST file.
2303  bool isFromAST() const { return TypeBits.FromAST; }
2304 
2305  /// Whether this type is or contains an unexpanded parameter
2306  /// pack, used to support C++0x variadic templates.
2307  ///
2308  /// A type that contains a parameter pack shall be expanded by the
2309  /// ellipsis operator at some point. For example, the typedef in the
2310  /// following example contains an unexpanded parameter pack 'T':
2311  ///
2312  /// \code
2313  /// template<typename ...T>
2314  /// struct X {
2315  /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
2316  /// };
2317  /// \endcode
2318  ///
2319  /// Note that this routine does not specify which
2321  return getDependence() & TypeDependence::UnexpandedPack;
2322  }
2323 
2324  /// Determines if this type would be canonical if it had no further
2325  /// qualification.
2326  bool isCanonicalUnqualified() const {
2327  return CanonicalType == QualType(this, 0);
2328  }
2329 
2330  /// Pull a single level of sugar off of this locally-unqualified type.
2331  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
2332  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
2333  QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
2334 
2335  /// As an extension, we classify types as one of "sized" or "sizeless";
2336  /// every type is one or the other. Standard types are all sized;
2337  /// sizeless types are purely an extension.
2338  ///
2339  /// Sizeless types contain data with no specified size, alignment,
2340  /// or layout.
2341  bool isSizelessType() const;
2342  bool isSizelessBuiltinType() const;
2343 
2344  /// Returns true for all scalable vector types.
2345  bool isSizelessVectorType() const;
2346 
2347  /// Returns true for SVE scalable vector types.
2348  bool isSVESizelessBuiltinType() const;
2349 
2350  /// Returns true for RVV scalable vector types.
2351  bool isRVVSizelessBuiltinType() const;
2352 
2353  /// Check if this is a WebAssembly Externref Type.
2354  bool isWebAssemblyExternrefType() const;
2355 
2356  /// Returns true if this is a WebAssembly table type: either an array of
2357  /// reference types, or a pointer to a reference type (which can only be
2358  /// created by array to pointer decay).
2359  bool isWebAssemblyTableType() const;
2360 
2361  /// Determines if this is a sizeless type supported by the
2362  /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
2363  /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
2364  bool isSveVLSBuiltinType() const;
2365 
2366  /// Returns the representative type for the element of an SVE builtin type.
2367  /// This is used to represent fixed-length SVE vectors created with the
2368  /// 'arm_sve_vector_bits' type attribute as VectorType.
2369  QualType getSveEltType(const ASTContext &Ctx) const;
2370 
2371  /// Determines if this is a sizeless type supported by the
2372  /// 'riscv_rvv_vector_bits' type attribute, which can be applied to a single
2373  /// RVV vector or mask.
2374  bool isRVVVLSBuiltinType() const;
2375 
2376  /// Returns the representative type for the element of an RVV builtin type.
2377  /// This is used to represent fixed-length RVV vectors created with the
2378  /// 'riscv_rvv_vector_bits' type attribute as VectorType.
2379  QualType getRVVEltType(const ASTContext &Ctx) const;
2380 
2381  /// Returns the representative type for the element of a sizeless vector
2382  /// builtin type.
2383  QualType getSizelessVectorEltType(const ASTContext &Ctx) const;
2384 
2385  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2386  /// object types, function types, and incomplete types.
2387 
2388  /// Return true if this is an incomplete type.
2389  /// A type that can describe objects, but which lacks information needed to
2390  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2391  /// routine will need to determine if the size is actually required.
2392  ///
2393  /// Def If non-null, and the type refers to some kind of declaration
2394  /// that can be completed (such as a C struct, C++ class, or Objective-C
2395  /// class), will be set to the declaration.
2396  bool isIncompleteType(NamedDecl **Def = nullptr) const;
2397 
2398  /// Return true if this is an incomplete or object
2399  /// type, in other words, not a function type.
2401  return !isFunctionType();
2402  }
2403 
2404  /// Determine whether this type is an object type.
2405  bool isObjectType() const {
2406  // C++ [basic.types]p8:
2407  // An object type is a (possibly cv-qualified) type that is not a
2408  // function type, not a reference type, and not a void type.
2409  return !isReferenceType() && !isFunctionType() && !isVoidType();
2410  }
2411 
2412  /// Return true if this is a literal type
2413  /// (C++11 [basic.types]p10)
2414  bool isLiteralType(const ASTContext &Ctx) const;
2415 
2416  /// Determine if this type is a structural type, per C++20 [temp.param]p7.
2417  bool isStructuralType() const;
2418 
2419  /// Test if this type is a standard-layout type.
2420  /// (C++0x [basic.type]p9)
2421  bool isStandardLayoutType() const;
2422 
2423  /// Helper methods to distinguish type categories. All type predicates
2424  /// operate on the canonical type, ignoring typedefs and qualifiers.
2425 
2426  /// Returns true if the type is a builtin type.
2427  bool isBuiltinType() const;
2428 
2429  /// Test for a particular builtin type.
2430  bool isSpecificBuiltinType(unsigned K) const;
2431 
2432  /// Test for a type which does not represent an actual type-system type but
2433  /// is instead used as a placeholder for various convenient purposes within
2434  /// Clang. All such types are BuiltinTypes.
2435  bool isPlaceholderType() const;
2436  const BuiltinType *getAsPlaceholderType() const;
2437 
2438  /// Test for a specific placeholder type.
2439  bool isSpecificPlaceholderType(unsigned K) const;
2440 
2441  /// Test for a placeholder type other than Overload; see
2442  /// BuiltinType::isNonOverloadPlaceholderType.
2443  bool isNonOverloadPlaceholderType() const;
2444 
2445  /// isIntegerType() does *not* include complex integers (a GCC extension).
2446  /// isComplexIntegerType() can be used to test for complex integers.
2447  bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
2448  bool isEnumeralType() const;
2449 
2450  /// Determine whether this type is a scoped enumeration type.
2451  bool isScopedEnumeralType() const;
2452  bool isBooleanType() const;
2453  bool isCharType() const;
2454  bool isWideCharType() const;
2455  bool isChar8Type() const;
2456  bool isChar16Type() const;
2457  bool isChar32Type() const;
2458  bool isAnyCharacterType() const;
2459  bool isIntegralType(const ASTContext &Ctx) const;
2460 
2461  /// Determine whether this type is an integral or enumeration type.
2462  bool isIntegralOrEnumerationType() const;
2463 
2464  /// Determine whether this type is an integral or unscoped enumeration type.
2465  bool isIntegralOrUnscopedEnumerationType() const;
2466  bool isUnscopedEnumerationType() const;
2467 
2468  /// Floating point categories.
2469  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2470  /// isComplexType() does *not* include complex integers (a GCC extension).
2471  /// isComplexIntegerType() can be used to test for complex integers.
2472  bool isComplexType() const; // C99 6.2.5p11 (complex)
2473  bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
2474  bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
2475  bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
2476  bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
2477  bool isFloat32Type() const;
2478  bool isDoubleType() const;
2479  bool isBFloat16Type() const;
2480  bool isFloat128Type() const;
2481  bool isIbm128Type() const;
2482  bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
2483  bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
2484  bool isVoidType() const; // C99 6.2.5p19
2485  bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
2486  bool isAggregateType() const;
2487  bool isFundamentalType() const;
2488  bool isCompoundType() const;
2489 
2490  // Type Predicates: Check to see if this type is structurally the specified
2491  // type, ignoring typedefs and qualifiers.
2492  bool isFunctionType() const;
2493  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
2494  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
2495  bool isPointerType() const;
2496  bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
2497  bool isCountAttributedType() const;
2498  bool isBlockPointerType() const;
2499  bool isVoidPointerType() const;
2500  bool isReferenceType() const;
2501  bool isLValueReferenceType() const;
2502  bool isRValueReferenceType() const;
2503  bool isObjectPointerType() const;
2504  bool isFunctionPointerType() const;
2505  bool isFunctionReferenceType() const;
2506  bool isMemberPointerType() const;
2507  bool isMemberFunctionPointerType() const;
2508  bool isMemberDataPointerType() const;
2509  bool isArrayType() const;
2510  bool isConstantArrayType() const;
2511  bool isIncompleteArrayType() const;
2512  bool isVariableArrayType() const;
2513  bool isArrayParameterType() const;
2514  bool isDependentSizedArrayType() const;
2515  bool isRecordType() const;
2516  bool isClassType() const;
2517  bool isStructureType() const;
2518  bool isObjCBoxableRecordType() const;
2519  bool isInterfaceType() const;
2520  bool isStructureOrClassType() const;
2521  bool isUnionType() const;
2522  bool isComplexIntegerType() const; // GCC _Complex integer type.
2523  bool isVectorType() const; // GCC vector type.
2524  bool isExtVectorType() const; // Extended vector type.
2525  bool isExtVectorBoolType() const; // Extended vector type with bool element.
2526  bool isSubscriptableVectorType() const;
2527  bool isMatrixType() const; // Matrix type.
2528  bool isConstantMatrixType() const; // Constant matrix type.
2529  bool isDependentAddressSpaceType() const; // value-dependent address space qualifier
2530  bool isObjCObjectPointerType() const; // pointer to ObjC object
2531  bool isObjCRetainableType() const; // ObjC object or block pointer
2532  bool isObjCLifetimeType() const; // (array of)* retainable type
2533  bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
2534  bool isObjCNSObjectType() const; // __attribute__((NSObject))
2535  bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
2536  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
2537  // for the common case.
2538  bool isObjCObjectType() const; // NSString or typeof(*(id)0)
2539  bool isObjCQualifiedInterfaceType() const; // NSString<foo>
2540  bool isObjCQualifiedIdType() const; // id<foo>
2541  bool isObjCQualifiedClassType() const; // Class<foo>
2542  bool isObjCObjectOrInterfaceType() const;
2543  bool isObjCIdType() const; // id
2544  bool isDecltypeType() const;
2545  /// Was this type written with the special inert-in-ARC __unsafe_unretained
2546  /// qualifier?
2547  ///
2548  /// This approximates the answer to the following question: if this
2549  /// translation unit were compiled in ARC, would this type be qualified
2550  /// with __unsafe_unretained?
2552  return hasAttr(attr::ObjCInertUnsafeUnretained);
2553  }
2554 
2555  /// Whether the type is Objective-C 'id' or a __kindof type of an
2556  /// object type, e.g., __kindof NSView * or __kindof id
2557  /// <NSCopying>.
2558  ///
2559  /// \param bound Will be set to the bound on non-id subtype types,
2560  /// which will be (possibly specialized) Objective-C class type, or
2561  /// null for 'id.
2562  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2563  const ObjCObjectType *&bound) const;
2564 
2565  bool isObjCClassType() const; // Class
2566 
2567  /// Whether the type is Objective-C 'Class' or a __kindof type of an
2568  /// Class type, e.g., __kindof Class <NSCopying>.
2569  ///
2570  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2571  /// here because Objective-C's type system cannot express "a class
2572  /// object for a subclass of NSFoo".
2573  bool isObjCClassOrClassKindOfType() const;
2574 
2575  bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2576  bool isObjCSelType() const; // Class
2577  bool isObjCBuiltinType() const; // 'id' or 'Class'
2578  bool isObjCARCBridgableType() const;
2579  bool isCARCBridgableType() const;
2580  bool isTemplateTypeParmType() const; // C++ template type parameter
2581  bool isNullPtrType() const; // C++11 std::nullptr_t or
2582  // C23 nullptr_t
2583  bool isNothrowT() const; // C++ std::nothrow_t
2584  bool isAlignValT() const; // C++17 std::align_val_t
2585  bool isStdByteType() const; // C++17 std::byte
2586  bool isAtomicType() const; // C11 _Atomic()
2587  bool isUndeducedAutoType() const; // C++11 auto or
2588  // C++14 decltype(auto)
2589  bool isTypedefNameType() const; // typedef or alias template
2590 
2591 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2592  bool is##Id##Type() const;
2593 #include "clang/Basic/OpenCLImageTypes.def"
2594 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2595  bool isSampled##Id##Type() const;
2596 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
2597 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
2598 #include "clang/Basic/OpenCLImageTypes.def"
2599 
2600  bool isImageType() const; // Any OpenCL image type
2601  bool isSampledImageType() const; // Any SPIR-V Sampled image type
2602 
2603  bool isSamplerT() const; // OpenCL sampler_t
2604  bool isEventT() const; // OpenCL event_t
2605  bool isClkEventT() const; // OpenCL clk_event_t
2606  bool isQueueT() const; // OpenCL queue_t
2607  bool isReserveIDT() const; // OpenCL reserve_id_t
2608 
2609 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2610  bool is##Id##Type() const;
2611 #include "clang/Basic/OpenCLExtensionTypes.def"
2612  // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension
2613  bool isOCLIntelSubgroupAVCType() const;
2614  bool isOCLExtOpaqueType() const; // Any OpenCL extension type
2615 
2616  bool isPipeType() const; // OpenCL pipe type
2617  bool isBitIntType() const; // Bit-precise integer type
2618  bool isOpenCLSpecificType() const; // Any OpenCL specific type
2619 
2620  /// Determines if this type, which must satisfy
2621  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2622  /// than implicitly __strong.
2623  bool isObjCARCImplicitlyUnretainedType() const;
2624 
2625  /// Check if the type is the CUDA device builtin surface type.
2626  bool isCUDADeviceBuiltinSurfaceType() const;
2627  /// Check if the type is the CUDA device builtin texture type.
2628  bool isCUDADeviceBuiltinTextureType() const;
2629 
2630  /// Return the implicit lifetime for this type, which must not be dependent.
2631  Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2632 
2643  STK_FixedPoint
2644  };
2645 
2646  /// Given that this is a scalar type, classify it.
2647  ScalarTypeKind getScalarTypeKind() const;
2648 
2650  return static_cast<TypeDependence>(TypeBits.Dependence);
2651  }
2652 
2653  /// Whether this type is an error type.
2654  bool containsErrors() const {
2655  return getDependence() & TypeDependence::Error;
2656  }
2657 
2658  /// Whether this type is a dependent type, meaning that its definition
2659  /// somehow depends on a template parameter (C++ [temp.dep.type]).
2660  bool isDependentType() const {
2661  return getDependence() & TypeDependence::Dependent;
2662  }
2663 
2664  /// Determine whether this type is an instantiation-dependent type,
2665  /// meaning that the type involves a template parameter (even if the
2666  /// definition does not actually depend on the type substituted for that
2667  /// template parameter).
2669  return getDependence() & TypeDependence::Instantiation;
2670  }
2671 
2672  /// Determine whether this type is an undeduced type, meaning that
2673  /// it somehow involves a C++11 'auto' type or similar which has not yet been
2674  /// deduced.
2675  bool isUndeducedType() const;
2676 
2677  /// Whether this type is a variably-modified type (C99 6.7.5).
2678  bool isVariablyModifiedType() const {
2679  return getDependence() & TypeDependence::VariablyModified;
2680  }
2681 
2682  /// Whether this type involves a variable-length array type
2683  /// with a definite size.
2684  bool hasSizedVLAType() const;
2685 
2686  /// Whether this type is or contains a local or unnamed type.
2687  bool hasUnnamedOrLocalType() const;
2688 
2689  bool isOverloadableType() const;
2690 
2691  /// Determine wither this type is a C++ elaborated-type-specifier.
2692  bool isElaboratedTypeSpecifier() const;
2693 
2694  bool canDecayToPointerType() const;
2695 
2696  /// Whether this type is represented natively as a pointer. This includes
2697  /// pointers, references, block pointers, and Objective-C interface,
2698  /// qualified id, and qualified interface types, as well as nullptr_t.
2699  bool hasPointerRepresentation() const;
2700 
2701  /// Whether this type can represent an objective pointer type for the
2702  /// purpose of GC'ability
2703  bool hasObjCPointerRepresentation() const;
2704 
2705  /// Determine whether this type has an integer representation
2706  /// of some sort, e.g., it is an integer type or a vector.
2707  bool hasIntegerRepresentation() const;
2708 
2709  /// Determine whether this type has an signed integer representation
2710  /// of some sort, e.g., it is an signed integer type or a vector.
2711  bool hasSignedIntegerRepresentation() const;
2712 
2713  /// Determine whether this type has an unsigned integer representation
2714  /// of some sort, e.g., it is an unsigned integer type or a vector.
2715  bool hasUnsignedIntegerRepresentation() const;
2716 
2717  /// Determine whether this type has a floating-point representation
2718  /// of some sort, e.g., it is a floating-point type or a vector thereof.
2719  bool hasFloatingRepresentation() const;
2720 
2721  // Type Checking Functions: Check to see if this type is structurally the
2722  // specified type, ignoring typedefs and qualifiers, and return a pointer to
2723  // the best type we can.
2724  const RecordType *getAsStructureType() const;
2725  /// NOTE: getAs*ArrayType are methods on ASTContext.
2726  const RecordType *getAsUnionType() const;
2727  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2728  const ObjCObjectType *getAsObjCInterfaceType() const;
2729 
2730  // The following is a convenience method that returns an ObjCObjectPointerType
2731  // for object declared using an interface.
2732  const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2733  const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2734  const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2735  const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2736 
2737  /// Retrieves the CXXRecordDecl that this type refers to, either
2738  /// because the type is a RecordType or because it is the injected-class-name
2739  /// type of a class template or class template partial specialization.
2740  CXXRecordDecl *getAsCXXRecordDecl() const;
2741 
2742  /// Retrieves the RecordDecl this type refers to.
2743  RecordDecl *getAsRecordDecl() const;
2744 
2745  /// Retrieves the TagDecl that this type refers to, either
2746  /// because the type is a TagType or because it is the injected-class-name
2747  /// type of a class template or class template partial specialization.
2748  TagDecl *getAsTagDecl() const;
2749 
2750  /// If this is a pointer or reference to a RecordType, return the
2751  /// CXXRecordDecl that the type refers to.
2752  ///
2753  /// If this is not a pointer or reference, or the type being pointed to does
2754  /// not refer to a CXXRecordDecl, returns NULL.
2755  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2756 
2757  /// Get the DeducedType whose type will be deduced for a variable with
2758  /// an initializer of this type. This looks through declarators like pointer
2759  /// types, but not through decltype or typedefs.
2760  DeducedType *getContainedDeducedType() const;
2761 
2762  /// Get the AutoType whose type will be deduced for a variable with
2763  /// an initializer of this type. This looks through declarators like pointer
2764  /// types, but not through decltype or typedefs.
2766  return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2767  }
2768 
2769  /// Determine whether this type was written with a leading 'auto'
2770  /// corresponding to a trailing return type (possibly for a nested
2771  /// function type within a pointer to function type or similar).
2772  bool hasAutoForTrailingReturnType() const;
2773 
2774  /// Member-template getAs<specific type>'. Look through sugar for
2775  /// an instance of <specific type>. This scheme will eventually
2776  /// replace the specific getAsXXXX methods above.
2777  ///
2778  /// There are some specializations of this member template listed
2779  /// immediately following this class.
2780  template <typename T> const T *getAs() const;
2781 
2782  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2783  /// of sugar (parens, attributes, etc) for an instance of <specific type>.
2784  /// This is used when you need to walk over sugar nodes that represent some
2785  /// kind of type adjustment from a type that was written as a <specific type>
2786  /// to another type that is still canonically a <specific type>.
2787  template <typename T> const T *getAsAdjusted() const;
2788 
2789  /// A variant of getAs<> for array types which silently discards
2790  /// qualifiers from the outermost type.
2791  const ArrayType *getAsArrayTypeUnsafe() const;
2792 
2793  /// Member-template castAs<specific type>. Look through sugar for
2794  /// the underlying instance of <specific type>.
2795  ///
2796  /// This method has the same relationship to getAs<T> as cast<T> has
2797  /// to dyn_cast<T>; which is to say, the underlying type *must*
2798  /// have the intended type, and this method will never return null.
2799  template <typename T> const T *castAs() const;
2800 
2801  /// A variant of castAs<> for array type which silently discards
2802  /// qualifiers from the outermost type.
2803  const ArrayType *castAsArrayTypeUnsafe() const;
2804 
2805  /// Determine whether this type had the specified attribute applied to it
2806  /// (looking through top-level type sugar).
2807  bool hasAttr(attr::Kind AK) const;
2808 
2809  /// Get the base element type of this type, potentially discarding type
2810  /// qualifiers. This should never be used when type qualifiers
2811  /// are meaningful.
2812  const Type *getBaseElementTypeUnsafe() const;
2813 
2814  /// If this is an array type, return the element type of the array,
2815  /// potentially with type qualifiers missing.
2816  /// This should never be used when type qualifiers are meaningful.
2817  const Type *getArrayElementTypeNoTypeQual() const;
2818 
2819  /// If this is a pointer type, return the pointee type.
2820  /// If this is an array type, return the array element type.
2821  /// This should never be used when type qualifiers are meaningful.
2822  const Type *getPointeeOrArrayElementType() const;
2823 
2824  /// If this is a pointer, ObjC object pointer, or block
2825  /// pointer, this returns the respective pointee.
2826  QualType getPointeeType() const;
2827 
2828  /// Return the specified type with any "sugar" removed from the type,
2829  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2830  const Type *getUnqualifiedDesugaredType() const;
2831 
2832  /// Return true if this is an integer type that is
2833  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2834  /// or an enum decl which has a signed representation.
2835  bool isSignedIntegerType() const;
2836 
2837  /// Return true if this is an integer type that is
2838  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2839  /// or an enum decl which has an unsigned representation.
2840  bool isUnsignedIntegerType() const;
2841 
2842  /// Determines whether this is an integer type that is signed or an
2843  /// enumeration types whose underlying type is a signed integer type.
2844  bool isSignedIntegerOrEnumerationType() const;
2845 
2846  /// Determines whether this is an integer type that is unsigned or an
2847  /// enumeration types whose underlying type is a unsigned integer type.
2848  bool isUnsignedIntegerOrEnumerationType() const;
2849 
2850  /// Return true if this is a fixed point type according to
2851  /// ISO/IEC JTC1 SC22 WG14 N1169.
2852  bool isFixedPointType() const;
2853 
2854  /// Return true if this is a fixed point or integer type.
2855  bool isFixedPointOrIntegerType() const;
2856 
2857  /// Return true if this can be converted to (or from) a fixed point type.
2858  bool isConvertibleToFixedPointType() const;
2859 
2860  /// Return true if this is a saturated fixed point type according to
2861  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2862  bool isSaturatedFixedPointType() const;
2863 
2864  /// Return true if this is a saturated fixed point type according to
2865  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2866  bool isUnsaturatedFixedPointType() const;
2867 
2868  /// Return true if this is a fixed point type that is signed according
2869  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2870  bool isSignedFixedPointType() const;
2871 
2872  /// Return true if this is a fixed point type that is unsigned according
2873  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2874  bool isUnsignedFixedPointType() const;
2875 
2876  /// Return true if this is not a variable sized type,
2877  /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2878  /// incomplete types.
2879  bool isConstantSizeType() const;
2880 
2881  /// Returns true if this type can be represented by some
2882  /// set of type specifiers.
2883  bool isSpecifierType() const;
2884 
2885  /// Determine the linkage of this type.
2886  Linkage getLinkage() const;
2887 
2888  /// Determine the visibility of this type.
2890  return getLinkageAndVisibility().getVisibility();
2891  }
2892 
2893  /// Return true if the visibility was explicitly set is the code.
2894  bool isVisibilityExplicit() const {
2895  return getLinkageAndVisibility().isVisibilityExplicit();
2896  }
2897 
2898  /// Determine the linkage and visibility of this type.
2899  LinkageInfo getLinkageAndVisibility() const;
2900 
2901  /// True if the computed linkage is valid. Used for consistency
2902  /// checking. Should always return true.
2903  bool isLinkageValid() const;
2904 
2905  /// Determine the nullability of the given type.
2906  ///
2907  /// Note that nullability is only captured as sugar within the type
2908  /// system, not as part of the canonical type, so nullability will
2909  /// be lost by canonicalization and desugaring.
2910  std::optional<NullabilityKind> getNullability() const;
2911 
2912  /// Determine whether the given type can have a nullability
2913  /// specifier applied to it, i.e., if it is any kind of pointer type.
2914  ///
2915  /// \param ResultIfUnknown The value to return if we don't yet know whether
2916  /// this type can have nullability because it is dependent.
2917  bool canHaveNullability(bool ResultIfUnknown = true) const;
2918 
2919  /// Retrieve the set of substitutions required when accessing a member
2920  /// of the Objective-C receiver type that is declared in the given context.
2921  ///
2922  /// \c *this is the type of the object we're operating on, e.g., the
2923  /// receiver for a message send or the base of a property access, and is
2924  /// expected to be of some object or object pointer type.
2925  ///
2926  /// \param dc The declaration context for which we are building up a
2927  /// substitution mapping, which should be an Objective-C class, extension,
2928  /// category, or method within.
2929  ///
2930  /// \returns an array of type arguments that can be substituted for
2931  /// the type parameters of the given declaration context in any type described
2932  /// within that context, or an empty optional to indicate that no
2933  /// substitution is required.
2934  std::optional<ArrayRef<QualType>>
2935  getObjCSubstitutions(const DeclContext *dc) const;
2936 
2937  /// Determines if this is an ObjC interface type that may accept type
2938  /// parameters.
2939  bool acceptsObjCTypeParams() const;
2940 
2941  const char *getTypeClassName() const;
2942 
2944  return CanonicalType;
2945  }
2946 
2947  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2948  void dump() const;
2949  void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
2950 };
2951 
2952 /// This will check for a TypedefType by removing any existing sugar
2953 /// until it reaches a TypedefType or a non-sugared type.
2954 template <> const TypedefType *Type::getAs() const;
2955 template <> const UsingType *Type::getAs() const;
2956 
2957 /// This will check for a TemplateSpecializationType by removing any
2958 /// existing sugar until it reaches a TemplateSpecializationType or a
2959 /// non-sugared type.
2960 template <> const TemplateSpecializationType *Type::getAs() const;
2961 
2962 /// This will check for an AttributedType by removing any existing sugar
2963 /// until it reaches an AttributedType or a non-sugared type.
2964 template <> const AttributedType *Type::getAs() const;
2965 
2966 /// This will check for a BoundsAttributedType by removing any existing
2967 /// sugar until it reaches an BoundsAttributedType or a non-sugared type.
2968 template <> const BoundsAttributedType *Type::getAs() const;
2969 
2970 /// This will check for a CountAttributedType by removing any existing
2971 /// sugar until it reaches an CountAttributedType or a non-sugared type.
2972 template <> const CountAttributedType *Type::getAs() const;
2973 
2974 // We can do canonical leaf types faster, because we don't have to
2975 // worry about preserving child type decoration.
2976 #define TYPE(Class, Base)
2977 #define LEAF_TYPE(Class) \
2978 template <> inline const Class##Type *Type::getAs() const { \
2979  return dyn_cast<Class##Type>(CanonicalType); \
2980 } \
2981 template <> inline const Class##Type *Type::castAs() const { \
2982  return cast<Class##Type>(CanonicalType); \
2983 }
2984 #include "clang/AST/TypeNodes.inc"
2985 
2986 /// This class is used for builtin types like 'int'. Builtin
2987 /// types are always canonical and have a literal name field.
2988 class BuiltinType : public Type {
2989 public:
2990  enum Kind {
2991 // OpenCL image types
2992 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2993 #include "clang/Basic/OpenCLImageTypes.def"
2994 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Sampled##Id,
2995 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
2996 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
2997 #include "clang/Basic/OpenCLImageTypes.def"
2998 // OpenCL extension types
2999 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
3000 #include "clang/Basic/OpenCLExtensionTypes.def"
3001 // SVE Types
3002 #define SVE_TYPE(Name, Id, SingletonId) Id,
3003 #include "clang/Basic/AArch64SVEACLETypes.def"
3004 // PPC MMA Types
3005 #define PPC_VECTOR_TYPE(Name, Id, Size) Id,
3006 #include "clang/Basic/PPCTypes.def"
3007 // RVV Types
3008 #define RVV_TYPE(Name, Id, SingletonId) Id,
3009 #include "clang/Basic/RISCVVTypes.def"
3010 // WebAssembly reference types
3011 #define WASM_TYPE(Name, Id, SingletonId) Id,
3012 #include "clang/Basic/WebAssemblyReferenceTypes.def"
3013 // All other builtin types
3014 #define BUILTIN_TYPE(Id, SingletonId) Id,
3015 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
3016 #include "clang/AST/BuiltinTypes.def"
3017  };
3018 
3019 private:
3020  friend class ASTContext; // ASTContext creates these.
3021 
3022  BuiltinType(Kind K)
3023  : Type(Builtin, QualType(),
3024  K == Dependent ? TypeDependence::DependentInstantiation
3025  : TypeDependence::None) {
3026  static_assert(Kind::LastKind <
3027  (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
3028  "Defined builtin type exceeds the allocated space for serial "
3029  "numbering");
3030  BuiltinTypeBits.Kind = K;
3031  }
3032 
3033 public:
3034  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
3035  StringRef getName(const PrintingPolicy &Policy) const;
3036 
3037  const char *getNameAsCString(const PrintingPolicy &Policy) const {
3038  // The StringRef is null-terminated.
3039  StringRef str = getName(Policy);
3040  assert(!str.empty() && str.data()[str.size()] == '\0');
3041  return str.data();
3042  }
3043 
3044  bool isSugared() const { return false; }
3045  QualType desugar() const { return QualType(this, 0); }
3046 
3047  bool isInteger() const {
3048  return getKind() >= Bool && getKind() <= Int128;
3049  }
3050 
3051  bool isSignedInteger() const {
3052  return getKind() >= Char_S && getKind() <= Int128;
3053  }
3054 
3055  bool isUnsignedInteger() const {
3056  return getKind() >= Bool && getKind() <= UInt128;
3057  }
3058 
3059  bool isFloatingPoint() const {
3060  return getKind() >= Half && getKind() <= Ibm128;
3061  }
3062 
3063  bool isSVEBool() const { return getKind() == Kind::SveBool; }
3064 
3065  bool isSVECount() const { return getKind() == Kind::SveCount; }
3066 
3067  /// Determines whether the given kind corresponds to a placeholder type.
3068  static bool isPlaceholderTypeKind(Kind K) {
3069  return K >= Overload;
3070  }
3071 
3072  /// Determines whether this type is a placeholder type, i.e. a type
3073  /// which cannot appear in arbitrary positions in a fully-formed
3074  /// expression.
3075  bool isPlaceholderType() const {
3076  return isPlaceholderTypeKind(getKind());
3077  }
3078 
3079  /// Determines whether this type is a placeholder type other than
3080  /// Overload. Most placeholder types require only syntactic
3081  /// information about their context in order to be resolved (e.g.
3082  /// whether it is a call expression), which means they can (and
3083  /// should) be resolved in an earlier "phase" of analysis.
3084  /// Overload expressions sometimes pick up further information
3085  /// from their context, like whether the context expects a
3086  /// specific function-pointer type, and so frequently need
3087  /// special treatment.
3089  return getKind() > Overload;
3090  }
3091 
3092  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3093 };
3094 
3095 /// Complex values, per C99 6.2.5p11. This supports the C99 complex
3096 /// types (_Complex float etc) as well as the GCC integer complex extensions.
3097 class ComplexType : public Type, public llvm::FoldingSetNode {
3098  friend class ASTContext; // ASTContext creates these.
3099 
3100  QualType ElementType;
3101 
3102  ComplexType(QualType Element, QualType CanonicalPtr)
3103  : Type(Complex, CanonicalPtr, Element->getDependence()),
3104  ElementType(Element) {}
3105 
3106 public:
3107  QualType getElementType() const { return ElementType; }
3108 
3109  bool isSugared() const { return false; }
3110  QualType desugar() const { return QualType(this, 0); }
3111 
3112  void Profile(llvm::FoldingSetNodeID &ID) {
3113  Profile(ID, getElementType());
3114  }
3115 
3116  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
3117  ID.AddPointer(Element.getAsOpaquePtr());
3118  }
3119 
3120  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
3121 };
3122 
3123 /// Sugar for parentheses used when specifying types.
3124 class ParenType : public Type, public llvm::FoldingSetNode {
3125  friend class ASTContext; // ASTContext creates these.
3126 
3127  QualType Inner;
3128 
3129  ParenType(QualType InnerType, QualType CanonType)
3130  : Type(Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
3131 
3132 public:
3133  QualType getInnerType() const { return Inner; }
3134 
3135  bool isSugared() const { return true; }
3136  QualType desugar() const { return getInnerType(); }
3137 
3138  void Profile(llvm::FoldingSetNodeID &ID) {
3139  Profile(ID, getInnerType());
3140  }
3141 
3142  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
3143  Inner.Profile(ID);
3144  }
3145 
3146  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
3147 };
3148 
3149 /// PointerType - C99 6.7.5.1 - Pointer Declarators.
3150 class PointerType : public Type, public llvm::FoldingSetNode {
3151  friend class ASTContext; // ASTContext creates these.
3152 
3153  QualType PointeeType;
3154 
3155  PointerType(QualType Pointee, QualType CanonicalPtr)
3156  : Type(Pointer, CanonicalPtr, Pointee->getDependence()),
3157  PointeeType(Pointee) {}
3158 
3159 public:
3160  QualType getPointeeType() const { return PointeeType; }
3161 
3162  bool isSugared() const { return false; }
3163  QualType desugar() const { return QualType(this, 0); }
3164 
3165  void Profile(llvm::FoldingSetNodeID &ID) {
3166  Profile(ID, getPointeeType());
3167  }
3168 
3169  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
3170  ID.AddPointer(Pointee.getAsOpaquePtr());
3171  }
3172 
3173  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
3174 };
3175 
3176 /// [BoundsSafety] Represents information of declarations referenced by the
3177 /// arguments of the `counted_by` attribute and the likes.
3179 public:
3180  using BaseTy = llvm::PointerIntPair<ValueDecl *, 1, unsigned>;
3181 
3182 private:
3183  enum {
3184  DerefShift = 0,
3185  DerefMask = 1,
3186  };
3187  BaseTy Data;
3188 
3189 public:
3190  /// \p D is to a declaration referenced by the argument of attribute. \p Deref
3191  /// indicates whether \p D is referenced as a dereferenced form, e.g., \p
3192  /// Deref is true for `*n` in `int *__counted_by(*n)`.
3193  TypeCoupledDeclRefInfo(ValueDecl *D = nullptr, bool Deref = false);
3194 
3195  bool isDeref() const;
3196  ValueDecl *getDecl() const;
3197  unsigned getInt() const;
3198  void *getOpaqueValue() const;
3199  bool operator==(const TypeCoupledDeclRefInfo &Other) const;
3200  void setFromOpaqueValue(void *V);
3201 };
3202 
3203 /// [BoundsSafety] Represents a parent type class for CountAttributedType and
3204 /// similar sugar types that will be introduced to represent a type with a
3205 /// bounds attribute.
3206 ///
3207 /// Provides a common interface to navigate declarations referred to by the
3208 /// bounds expression.
3209 
3210 class BoundsAttributedType : public Type, public llvm::FoldingSetNode {
3211  QualType WrappedTy;
3212 
3213 protected:
3214  ArrayRef<TypeCoupledDeclRefInfo> Decls; // stored in trailing objects
3215 
3216  BoundsAttributedType(TypeClass TC, QualType Wrapped, QualType Canon);
3217 
3218 public:
3219  bool isSugared() const { return true; }
3220  QualType desugar() const { return WrappedTy; }
3221 
3223  using decl_range = llvm::iterator_range<decl_iterator>;
3224 
3225  decl_iterator dependent_decl_begin() const { return Decls.begin(); }
3226  decl_iterator dependent_decl_end() const { return Decls.end(); }
3227 
3228  unsigned getNumCoupledDecls() const { return Decls.size(); }
3229 
3231  return decl_range(dependent_decl_begin(), dependent_decl_end());
3232  }
3233 
3235  return {dependent_decl_begin(), dependent_decl_end()};
3236  }
3237 
3238  bool referencesFieldDecls() const;
3239 
3240  static bool classof(const Type *T) {
3241  // Currently, only `class CountAttributedType` inherits
3242  // `BoundsAttributedType` but the subclass will grow as we add more bounds
3243  // annotations.
3244  switch (T->getTypeClass()) {
3245  case CountAttributed:
3246  return true;
3247  default:
3248  return false;
3249  }
3250  }
3251 };
3252 
3253 /// Represents a sugar type with `__counted_by` or `__sized_by` annotations,
3254 /// including their `_or_null` variants.
3256  : public BoundsAttributedType,
3257  public llvm::TrailingObjects<CountAttributedType,
3258  TypeCoupledDeclRefInfo> {
3259  friend class ASTContext;
3260 
3261  Expr *CountExpr;
3262  /// \p CountExpr represents the argument of __counted_by or the likes. \p
3263  /// CountInBytes indicates that \p CountExpr is a byte count (i.e.,
3264  /// __sized_by(_or_null)) \p OrNull means it's an or_null variant (i.e.,
3265  /// __counted_by_or_null or __sized_by_or_null) \p CoupledDecls contains the
3266  /// list of declarations referenced by \p CountExpr, which the type depends on
3267  /// for the bounds information.
3268  CountAttributedType(QualType Wrapped, QualType Canon, Expr *CountExpr,
3269  bool CountInBytes, bool OrNull,
3270  ArrayRef<TypeCoupledDeclRefInfo> CoupledDecls);
3271 
3272  unsigned numTrailingObjects(OverloadToken<TypeCoupledDeclRefInfo>) const {
3273  return CountAttributedTypeBits.NumCoupledDecls;
3274  }
3275 
3276 public:
3278  CountedBy = 0,
3282  };
3283 
3284  Expr *getCountExpr() const { return CountExpr; }
3285  bool isCountInBytes() const { return CountAttributedTypeBits.CountInBytes; }
3286  bool isOrNull() const { return CountAttributedTypeBits.OrNull; }
3287 
3289  if (isOrNull())
3290  return isCountInBytes() ? SizedByOrNull : CountedByOrNull;
3291  return isCountInBytes() ? SizedBy : CountedBy;
3292  }
3293 
3294  void Profile(llvm::FoldingSetNodeID &ID) {
3295  Profile(ID, desugar(), CountExpr, isCountInBytes(), isOrNull());
3296  }
3297 
3298  static void Profile(llvm::FoldingSetNodeID &ID, QualType WrappedTy,
3299  Expr *CountExpr, bool CountInBytes, bool Nullable);
3300 
3301  static bool classof(const Type *T) {
3302  return T->getTypeClass() == CountAttributed;
3303  }
3304 };
3305 
3306 /// Represents a type which was implicitly adjusted by the semantic
3307 /// engine for arbitrary reasons. For example, array and function types can
3308 /// decay, and function types can have their calling conventions adjusted.
3309 class AdjustedType : public Type, public llvm::FoldingSetNode {
3310  QualType OriginalTy;
3311  QualType AdjustedTy;
3312 
3313 protected:
3314  friend class ASTContext; // ASTContext creates these.
3315 
3316  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
3317  QualType CanonicalPtr)
3318  : Type(TC, CanonicalPtr, OriginalTy->getDependence()),
3319  OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
3320 
3321 public:
3322  QualType getOriginalType() const { return OriginalTy; }
3323  QualType getAdjustedType() const { return AdjustedTy; }
3324 
3325  bool isSugared() const { return true; }
3326  QualType desugar() const { return AdjustedTy; }
3327 
3328  void Profile(llvm::FoldingSetNodeID &ID) {
3329  Profile(ID, OriginalTy, AdjustedTy);
3330  }
3331 
3332  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
3333  ID.AddPointer(Orig.getAsOpaquePtr());
3334  ID.AddPointer(New.getAsOpaquePtr());
3335  }
3336 
3337  static bool classof(const Type *T) {
3338  return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
3339  }
3340 };
3341 
3342 /// Represents a pointer type decayed from an array or function type.
3343 class DecayedType : public AdjustedType {
3344  friend class ASTContext; // ASTContext creates these.
3345 
3346  inline
3347  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
3348 
3349 public:
3350  QualType getDecayedType() const { return getAdjustedType(); }
3351 
3352  inline QualType getPointeeType() const;
3353 
3354  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
3355 };
3356 
3357 /// Pointer to a block type.
3358 /// This type is to represent types syntactically represented as
3359 /// "void (^)(int)", etc. Pointee is required to always be a function type.
3360 class BlockPointerType : public Type, public llvm::FoldingSetNode {
3361  friend class ASTContext; // ASTContext creates these.
3362 
3363  // Block is some kind of pointer type
3364  QualType PointeeType;
3365 
3366  BlockPointerType(QualType Pointee, QualType CanonicalCls)
3367  : Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
3368  PointeeType(Pointee) {}
3369 
3370 public:
3371  // Get the pointee type. Pointee is required to always be a function type.
3372  QualType getPointeeType() const { return PointeeType; }
3373 
3374  bool isSugared() const { return false; }
3375  QualType desugar() const { return QualType(this, 0); }
3376 
3377  void Profile(llvm::FoldingSetNodeID &ID) {
3378  Profile(ID, getPointeeType());
3379  }
3380 
3381  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
3382  ID.AddPointer(Pointee.getAsOpaquePtr());
3383  }
3384 
3385  static bool classof(const Type *T) {
3386  return T->getTypeClass() == BlockPointer;
3387  }
3388 };
3389 
3390 /// Base for LValueReferenceType and RValueReferenceType
3391 class ReferenceType : public Type, public llvm::FoldingSetNode {
3392  QualType PointeeType;
3393 
3394 protected:
3395  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
3396  bool SpelledAsLValue)
3397  : Type(tc, CanonicalRef, Referencee->getDependence()),
3398  PointeeType(Referencee) {
3399  ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3400  ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
3401  }
3402 
3403 public:
3404  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
3405  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
3406 
3407  QualType getPointeeTypeAsWritten() const { return PointeeType; }
3408 
3410  // FIXME: this might strip inner qualifiers; okay?
3411  const ReferenceType *T = this;
3412  while (T->isInnerRef())
3413  T = T->PointeeType->castAs<ReferenceType>();
3414  return T->PointeeType;
3415  }
3416 
3417  void Profile(llvm::FoldingSetNodeID &ID) {
3418  Profile(ID, PointeeType, isSpelledAsLValue());
3419  }
3420 
3421  static void Profile(llvm::FoldingSetNodeID &ID,
3422  QualType Referencee,
3423  bool SpelledAsLValue) {
3424  ID.AddPointer(Referencee.getAsOpaquePtr());
3425  ID.AddBoolean(SpelledAsLValue);
3426  }
3427 
3428  static bool classof(const Type *T) {
3429  return T->getTypeClass() == LValueReference ||
3430  T->getTypeClass() == RValueReference;
3431  }
3432 };
3433 
3434 /// An lvalue reference type, per C++11 [dcl.ref].
3436  friend class ASTContext; // ASTContext creates these
3437 
3438  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
3439  bool SpelledAsLValue)
3440  : ReferenceType(LValueReference, Referencee, CanonicalRef,
3441  SpelledAsLValue) {}
3442 
3443 public:
3444  bool isSugared() const { return false; }
3445  QualType desugar() const { return QualType(this, 0); }
3446 
3447  static bool classof(const Type *T) {
3448  return T->getTypeClass() == LValueReference;
3449  }
3450 };
3451 
3452 /// An rvalue reference type, per C++11 [dcl.ref].
3454  friend class ASTContext; // ASTContext creates these
3455 
3456  RValueReferenceType(QualType Referencee, QualType CanonicalRef)
3457  : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
3458 
3459 public:
3460  bool isSugared() const { return false; }
3461  QualType desugar() const { return QualType(this, 0); }
3462 
3463  static bool classof(const Type *T) {
3464  return T->getTypeClass() == RValueReference;
3465  }
3466 };
3467 
3468 /// A pointer to member type per C++ 8.3.3 - Pointers to members.
3469 ///
3470 /// This includes both pointers to data members and pointer to member functions.
3471 class MemberPointerType : public Type, public llvm::FoldingSetNode {
3472  friend class ASTContext; // ASTContext creates these.
3473 
3474  QualType PointeeType;
3475 
3476  /// The class of which the pointee is a member. Must ultimately be a
3477  /// RecordType, but could be a typedef or a template parameter too.
3478  const Type *Class;
3479 
3480  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
3481  : Type(MemberPointer, CanonicalPtr,
3482  (Cls->getDependence() & ~TypeDependence::VariablyModified) |
3483  Pointee->getDependence()),
3484  PointeeType(Pointee), Class(Cls) {}
3485 
3486 public:
3487  QualType getPointeeType() const { return PointeeType; }
3488 
3489  /// Returns true if the member type (i.e. the pointee type) is a
3490  /// function type rather than a data-member type.
3492  return PointeeType->isFunctionProtoType();
3493  }
3494 
3495  /// Returns true if the member type (i.e. the pointee type) is a
3496  /// data type rather than a function type.
3497  bool isMemberDataPointer() const {
3498  return !PointeeType->isFunctionProtoType();
3499  }
3500 
3501  const Type *getClass() const { return Class; }
3502  CXXRecordDecl *getMostRecentCXXRecordDecl() const;
3503 
3504  bool isSugared() const { return false; }
3505  QualType desugar() const { return QualType(this, 0); }
3506 
3507  void Profile(llvm::FoldingSetNodeID &ID) {
3508  Profile(ID, getPointeeType(), getClass());
3509  }
3510 
3511  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
3512  const Type *Class) {
3513  ID.AddPointer(Pointee.getAsOpaquePtr());
3514  ID.AddPointer(Class);
3515  }
3516 
3517  static bool classof(const Type *T) {
3518  return T->getTypeClass() == MemberPointer;
3519  }
3520 };
3521 
3522 /// Capture whether this is a normal array (e.g. int X[4])
3523 /// an array with a static size (e.g. int X[static 4]), or an array
3524 /// with a star size (e.g. int X[*]).
3525 /// 'static' is only allowed on function parameters.
3526 enum class ArraySizeModifier { Normal, Static, Star };
3527 
3528 /// Represents an array type, per C99 6.7.5.2 - Array Declarators.
3529 class ArrayType : public Type, public llvm::FoldingSetNode {
3530 private:
3531  /// The element type of the array.
3532  QualType ElementType;
3533 
3534 protected:
3535  friend class ASTContext; // ASTContext creates these.
3536 
3538  unsigned tq, const Expr *sz = nullptr);
3539 
3540 public:
3541  QualType getElementType() const { return ElementType; }
3542 
3544  return ArraySizeModifier(ArrayTypeBits.SizeModifier);
3545  }
3546 
3548  return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3549  }
3550 
3551  unsigned getIndexTypeCVRQualifiers() const {
3552  return ArrayTypeBits.IndexTypeQuals;
3553  }
3554 
3555  static bool classof(const Type *T) {
3556  return T->getTypeClass() == ConstantArray ||
3557  T->getTypeClass() == VariableArray ||
3558  T->getTypeClass() == IncompleteArray ||
3559  T->getTypeClass() == DependentSizedArray ||
3560  T->getTypeClass() == ArrayParameter;
3561  }
3562 };
3563 
3564 /// Represents the canonical version of C arrays with a specified constant size.
3565 /// For example, the canonical type for 'int A[4 + 4*100]' is a
3566 /// ConstantArrayType where the element type is 'int' and the size is 404.
3568  friend class ASTContext; // ASTContext creates these.
3569 
3570  struct ExternalSize {
3571  ExternalSize(const llvm::APInt &Sz, const Expr *SE)
3572  : Size(Sz), SizeExpr(SE) {}
3573  llvm::APInt Size; // Allows us to unique the type.
3574  const Expr *SizeExpr;
3575  };
3576 
3577  union {
3579  ExternalSize *SizePtr;
3580  };
3581 
3583  ArraySizeModifier SM, unsigned TQ)
3584  : ArrayType(ConstantArray, Et, Can, SM, TQ, nullptr), Size(Sz) {
3585  ConstantArrayTypeBits.HasExternalSize = false;
3586  ConstantArrayTypeBits.SizeWidth = Width / 8;
3587  // The in-structure size stores the size in bytes rather than bits so we
3588  // drop the three least significant bits since they're always zero anyways.
3589  assert(Width < 0xFF && "Type width in bits must be less than 8 bits");
3590  }
3591 
3592  ConstantArrayType(QualType Et, QualType Can, ExternalSize *SzPtr,
3593  ArraySizeModifier SM, unsigned TQ)
3594  : ArrayType(ConstantArray, Et, Can, SM, TQ, SzPtr->SizeExpr),
3595  SizePtr(SzPtr) {
3596  ConstantArrayTypeBits.HasExternalSize = true;
3597  ConstantArrayTypeBits.SizeWidth = 0;
3598 
3599  assert((SzPtr->SizeExpr == nullptr || !Can.isNull()) &&
3600  "canonical constant array should not have size expression");
3601  }
3602 
3603  static ConstantArrayType *Create(const ASTContext &Ctx, QualType ET,
3604  QualType Can, const llvm::APInt &Sz,
3605  const Expr *SzExpr, ArraySizeModifier SzMod,
3606  unsigned Qual);
3607 
3608 protected:
3610  : ArrayType(Tc, ATy->getElementType(), Can, ATy->getSizeModifier(),
3611  ATy->getIndexTypeQualifiers().getAsOpaqueValue(), nullptr) {
3612  ConstantArrayTypeBits.HasExternalSize =
3613  ATy->ConstantArrayTypeBits.HasExternalSize;
3614  if (!ConstantArrayTypeBits.HasExternalSize) {
3615  ConstantArrayTypeBits.SizeWidth = ATy->ConstantArrayTypeBits.SizeWidth;
3616  Size = ATy->Size;
3617  } else
3618  SizePtr = ATy->SizePtr;
3619  }
3620 
3621 public:
3622  /// Return the constant array size as an APInt.
3624  return ConstantArrayTypeBits.HasExternalSize
3625  ? SizePtr->Size
3626  : llvm::APInt(ConstantArrayTypeBits.SizeWidth * 8, Size);
3627  }
3628 
3629  /// Return the bit width of the size type.
3630  unsigned getSizeBitWidth() const {
3631  return ConstantArrayTypeBits.HasExternalSize
3632  ? SizePtr->Size.getBitWidth()
3633  : static_cast<unsigned>(ConstantArrayTypeBits.SizeWidth * 8);
3634  }
3635 
3636  /// Return true if the size is zero.
3637  bool isZeroSize() const {
3638  return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
3639  : 0 == Size;
3640  }
3641 
3642  /// Return the size zero-extended as a uint64_t.
3644  return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
3645  : Size;
3646  }
3647 
3648  /// Return the size sign-extended as a uint64_t.
3650  return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
3651  : static_cast<int64_t>(Size);
3652  }
3653 
3654  /// Return the size zero-extended to uint64_t or UINT64_MAX if the value is
3655  /// larger than UINT64_MAX.
3657  return ConstantArrayTypeBits.HasExternalSize
3658  ? SizePtr->Size.getLimitedValue()
3659  : Size;
3660  }
3661 
3662  /// Return a pointer to the size expression.
3663  const Expr *getSizeExpr() const {
3664  return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr : nullptr;
3665  }
3666 
3667  bool isSugared() const { return false; }
3668  QualType desugar() const { return QualType(this, 0); }
3669 
3670  /// Determine the number of bits required to address a member of
3671  // an array with the given element type and number of elements.
3672  static unsigned getNumAddressingBits(const ASTContext &Context,
3673  QualType ElementType,
3674  const llvm::APInt &NumElements);
3675 
3676  unsigned getNumAddressingBits(const ASTContext &Context) const;
3677 
3678  /// Determine the maximum number of active bits that an array's size
3679  /// can require, which limits the maximum size of the array.
3680  static unsigned getMaxSizeBits(const ASTContext &Context);
3681 
3682  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
3683  Profile(ID, Ctx, getElementType(), getZExtSize(), getSizeExpr(),
3684  getSizeModifier(), getIndexTypeCVRQualifiers());
3685  }
3686 
3687  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
3688  QualType ET, uint64_t ArraySize, const Expr *SizeExpr,
3689  ArraySizeModifier SizeMod, unsigned TypeQuals);
3690 
3691  static bool classof(const Type *T) {
3692  return T->getTypeClass() == ConstantArray ||
3693  T->getTypeClass() == ArrayParameter;
3694  }
3695 };
3696 
3697 /// Represents a constant array type that does not decay to a pointer when used
3698 /// as a function parameter.
3700  friend class ASTContext; // ASTContext creates these.
3701 
3702  ArrayParameterType(const ConstantArrayType *ATy, QualType CanTy)
3703  : ConstantArrayType(ArrayParameter, ATy, CanTy) {}
3704 
3705 public:
3706  static bool classof(const Type *T) {
3707  return T->getTypeClass() == ArrayParameter;
3708  }
3709 };
3710 
3711 /// Represents a C array with an unspecified size. For example 'int A[]' has
3712 /// an IncompleteArrayType where the element type is 'int' and the size is
3713 /// unspecified.
3715  friend class ASTContext; // ASTContext creates these.
3716 
3718  ArraySizeModifier sm, unsigned tq)
3719  : ArrayType(IncompleteArray, et, can, sm, tq) {}
3720 
3721 public:
3722  friend class StmtIteratorBase;
3723 
3724  bool isSugared() const { return false; }
3725  QualType desugar() const { return QualType(this, 0); }
3726 
3727  static bool classof(const Type *T) {
3728  return T->getTypeClass() == IncompleteArray;
3729  }
3730 
3731  void Profile(llvm::FoldingSetNodeID &ID) {
3732  Profile(ID, getElementType(), getSizeModifier(),
3733  getIndexTypeCVRQualifiers());
3734  }
3735 
3736  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
3737  ArraySizeModifier SizeMod, unsigned TypeQuals) {
3738  ID.AddPointer(ET.getAsOpaquePtr());
3739  ID.AddInteger(llvm::to_underlying(SizeMod));
3740  ID.AddInteger(TypeQuals);
3741  }
3742 };
3743 
3744 /// Represents a C array with a specified size that is not an
3745 /// integer-constant-expression. For example, 'int s[x+foo()]'.
3746 /// Since the size expression is an arbitrary expression, we store it as such.
3747 ///
3748 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
3749 /// should not be: two lexically equivalent variable array types could mean
3750 /// different things, for example, these variables do not have the same type
3751 /// dynamically:
3752 ///
3753 /// void foo(int x) {
3754 /// int Y[x];
3755 /// ++x;
3756 /// int Z[x];
3757 /// }
3759  friend class ASTContext; // ASTContext creates these.
3760 
3761  /// An assignment-expression. VLA's are only permitted within
3762  /// a function block.
3763  Stmt *SizeExpr;
3764 
3765  /// The range spanned by the left and right array brackets.
3766  SourceRange Brackets;
3767 
3769  ArraySizeModifier sm, unsigned tq,
3770  SourceRange brackets)
3771  : ArrayType(VariableArray, et, can, sm, tq, e),
3772  SizeExpr((Stmt*) e), Brackets(brackets) {}
3773 
3774 public:
3775  friend class StmtIteratorBase;
3776 
3777  Expr *getSizeExpr() const {
3778  // We use C-style casts instead of cast<> here because we do not wish
3779  // to have a dependency of Type.h on Stmt.h/Expr.h.
3780  return (Expr*) SizeExpr;
3781  }
3782 
3783  SourceRange getBracketsRange() const { return Brackets; }
3784  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3785  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3786 
3787  bool isSugared() const { return false; }
3788  QualType desugar() const { return QualType(this, 0); }
3789 
3790  static bool classof(const Type *T) {
3791  return T->getTypeClass() == VariableArray;
3792  }
3793 
3794  void Profile(llvm::FoldingSetNodeID &ID) {
3795  llvm_unreachable("Cannot unique VariableArrayTypes.");
3796  }
3797 };
3798 
3799 /// Represents an array type in C++ whose size is a value-dependent expression.
3800 ///
3801 /// For example:
3802 /// \code
3803 /// template<typename T, int Size>
3804 /// class array {
3805 /// T data[Size];
3806 /// };
3807 /// \endcode
3808 ///
3809 /// For these types, we won't actually know what the array bound is
3810 /// until template instantiation occurs, at which point this will
3811 /// become either a ConstantArrayType or a VariableArrayType.
3813  friend class ASTContext; // ASTContext creates these.
3814 
3815  /// An assignment expression that will instantiate to the
3816  /// size of the array.
3817  ///
3818  /// The expression itself might be null, in which case the array
3819  /// type will have its size deduced from an initializer.
3820  Stmt *SizeExpr;
3821 
3822  /// The range spanned by the left and right array brackets.
3823  SourceRange Brackets;
3824 
3826  ArraySizeModifier sm, unsigned tq,
3827  SourceRange brackets);
3828 
3829 public:
3830  friend class StmtIteratorBase;
3831 
3832  Expr *getSizeExpr() const {
3833  // We use C-style casts instead of cast<> here because we do not wish
3834  // to have a dependency of Type.h on Stmt.h/Expr.h.
3835  return (Expr*) SizeExpr;
3836  }
3837 
3838  SourceRange getBracketsRange() const { return Brackets; }
3839  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3840  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3841 
3842  bool isSugared() const { return false; }
3843  QualType desugar() const { return QualType(this, 0); }
3844 
3845  static bool classof(const Type *T) {
3846  return T->getTypeClass() == DependentSizedArray;
3847  }
3848 
3849  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3850  Profile(ID, Context, getElementType(),
3851  getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3852  }
3853 
3854  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3855  QualType ET, ArraySizeModifier SizeMod,
3856  unsigned TypeQuals, Expr *E);
3857 };
3858 
3859 /// Represents an extended address space qualifier where the input address space
3860 /// value is dependent. Non-dependent address spaces are not represented with a
3861 /// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3862 ///
3863 /// For example:
3864 /// \code
3865 /// template<typename T, int AddrSpace>
3866 /// class AddressSpace {
3867 /// typedef T __attribute__((address_space(AddrSpace))) type;
3868 /// }
3869 /// \endcode
3870 class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3871  friend class ASTContext;
3872 
3873  Expr *AddrSpaceExpr;
3874  QualType PointeeType;
3875  SourceLocation loc;
3876 
3877  DependentAddressSpaceType(QualType PointeeType, QualType can,
3878  Expr *AddrSpaceExpr, SourceLocation loc);
3879 
3880 public:
3881  Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3882  QualType getPointeeType() const { return PointeeType; }
3883  SourceLocation getAttributeLoc() const { return loc; }
3884 
3885  bool isSugared() const { return false; }
3886  QualType desugar() const { return QualType(this, 0); }
3887 
3888  static bool classof(const Type *T) {
3889  return T->getTypeClass() == DependentAddressSpace;
3890  }
3891 
3892  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3893  Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3894  }
3895 
3896  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3897  QualType PointeeType, Expr *AddrSpaceExpr);
3898 };
3899 
3900 /// Represents an extended vector type where either the type or size is
3901 /// dependent.
3902 ///
3903 /// For example:
3904 /// \code
3905 /// template<typename T, int Size>
3906 /// class vector {
3907 /// typedef T __attribute__((ext_vector_type(Size))) type;
3908 /// }
3909 /// \endcode
3910 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3911  friend class ASTContext;
3912 
3913  Expr *SizeExpr;
3914 
3915  /// The element type of the array.
3916  QualType ElementType;
3917 
3918  SourceLocation loc;
3919 
3921  Expr *SizeExpr, SourceLocation loc);
3922 
3923 public:
3924  Expr *getSizeExpr() const { return SizeExpr; }
3925  QualType getElementType() const { return ElementType; }
3926  SourceLocation getAttributeLoc() const { return loc; }
3927 
3928  bool isSugared() const { return false; }
3929  QualType desugar() const { return QualType(this, 0); }
3930 
3931  static bool classof(const Type *T) {
3932  return T->getTypeClass() == DependentSizedExtVector;
3933  }
3934 
3935  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3936  Profile(ID, Context, getElementType(), getSizeExpr());
3937  }
3938 
3939  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3940  QualType ElementType, Expr *SizeExpr);
3941 };
3942 
3943 enum class VectorKind {
3944  /// not a target-specific vector type
3945  Generic,
3946 
3947  /// is AltiVec vector
3948  AltiVecVector,
3949 
3950  /// is AltiVec 'vector Pixel'
3951  AltiVecPixel,
3952 
3953  /// is AltiVec 'vector bool ...'
3954  AltiVecBool,
3955 
3956  /// is ARM Neon vector
3957  Neon,
3958 
3959  /// is ARM Neon polynomial vector
3960  NeonPoly,
3961 
3962  /// is AArch64 SVE fixed-length data vector
3964 
3965  /// is AArch64 SVE fixed-length predicate vector
3967 
3968  /// is RISC-V RVV fixed-length data vector
3970 
3971  /// is RISC-V RVV fixed-length mask vector
3973 };
3974 
3975 /// Represents a GCC generic vector type. This type is created using
3976 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
3977 /// bytes; or from an Altivec __vector or vector declaration.
3978 /// Since the constructor takes the number of vector elements, the
3979 /// client is responsible for converting the size into the number of elements.
3980 class VectorType : public Type, public llvm::FoldingSetNode {
3981 protected:
3982  friend class ASTContext; // ASTContext creates these.
3983 
3984  /// The element type of the vector.
3986 
3987  VectorType(QualType vecType, unsigned nElements, QualType canonType,
3988  VectorKind vecKind);
3989 
3990  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3991  QualType canonType, VectorKind vecKind);
3992 
3993 public:
3994  QualType getElementType() const { return ElementType; }
3995  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3996 
3997  bool isSugared() const { return false; }
3998  QualType desugar() const { return QualType(this, 0); }
3999 
4001  return VectorKind(VectorTypeBits.VecKind);
4002  }
4003 
4004  void Profile(llvm::FoldingSetNodeID &ID) {
4005  Profile(ID, getElementType(), getNumElements(),
4006  getTypeClass(), getVectorKind());
4007  }
4008 
4009  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
4010  unsigned NumElements, TypeClass TypeClass,
4011  VectorKind VecKind) {
4012  ID.AddPointer(ElementType.getAsOpaquePtr());
4013  ID.AddInteger(NumElements);
4014  ID.AddInteger(TypeClass);
4015  ID.AddInteger(llvm::to_underlying(VecKind));
4016  }
4017 
4018  static bool classof(const Type *T) {
4019  return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
4020  }
4021 };
4022 
4023 /// Represents a vector type where either the type or size is dependent.
4024 ////
4025 /// For example:
4026 /// \code
4027 /// template<typename T, int Size>
4028 /// class vector {
4029 /// typedef T __attribute__((vector_size(Size))) type;
4030 /// }
4031 /// \endcode
4032 class DependentVectorType : public Type, public llvm::FoldingSetNode {
4033  friend class ASTContext;
4034 
4035  QualType ElementType;
4036  Expr *SizeExpr;
4038 
4039  DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
4040  SourceLocation Loc, VectorKind vecKind);
4041 
4042 public:
4043  Expr *getSizeExpr() const { return SizeExpr; }
4044  QualType getElementType() const { return ElementType; }
4045  SourceLocation getAttributeLoc() const { return Loc; }
4047  return VectorKind(VectorTypeBits.VecKind);
4048  }
4049 
4050  bool isSugared() const { return false; }
4051  QualType desugar() const { return QualType(this, 0); }
4052 
4053  static bool classof(const Type *T) {
4054  return T->getTypeClass() == DependentVector;
4055  }
4056 
4057  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4058  Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
4059  }
4060 
4061  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4062  QualType ElementType, const Expr *SizeExpr,
4063  VectorKind VecKind);
4064 };
4065 
4066 /// ExtVectorType - Extended vector type. This type is created using
4067 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
4068 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
4069 /// class enables syntactic extensions, like Vector Components for accessing
4070 /// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
4071 /// Shading Language).
4072 class ExtVectorType : public VectorType {
4073  friend class ASTContext; // ASTContext creates these.
4074 
4075  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
4076  : VectorType(ExtVector, vecType, nElements, canonType,
4077  VectorKind::Generic) {}
4078 
4079 public:
4080  static int getPointAccessorIdx(char c) {
4081  switch (c) {
4082  default: return -1;
4083  case 'x': case 'r': return 0;
4084  case 'y': case 'g': return 1;
4085  case 'z': case 'b': return 2;
4086  case 'w': case 'a': return 3;
4087  }
4088  }
4089 
4090  static int getNumericAccessorIdx(char c) {
4091  switch (c) {
4092  default: return -1;
4093  case '0': return 0;
4094  case '1': return 1;
4095  case '2': return 2;
4096  case '3': return 3;
4097  case '4': return 4;
4098  case '5': return 5;
4099  case '6': return 6;
4100  case '7': return 7;
4101  case '8': return 8;
4102  case '9': return 9;
4103  case 'A':
4104  case 'a': return 10;
4105  case 'B':
4106  case 'b': return 11;
4107  case 'C':
4108  case 'c': return 12;
4109  case 'D':
4110  case 'd': return 13;
4111  case 'E':
4112  case 'e': return 14;
4113  case 'F':
4114  case 'f': return 15;
4115  }
4116  }
4117 
4118  static int getAccessorIdx(char c, bool isNumericAccessor) {
4119  if (isNumericAccessor)
4120  return getNumericAccessorIdx(c);
4121  else
4122  return getPointAccessorIdx(c);
4123  }
4124 
4125  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
4126  if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
4127  return unsigned(idx-1) < getNumElements();
4128  return false;
4129  }
4130 
4131  bool isSugared() const { return false; }
4132  QualType desugar() const { return QualType(this, 0); }
4133 
4134  static bool classof(const Type *T) {
4135  return T->getTypeClass() == ExtVector;
4136  }
4137 };
4138 
4139 /// Represents a matrix type, as defined in the Matrix Types clang extensions.
4140 /// __attribute__((matrix_type(rows, columns))), where "rows" specifies
4141 /// number of rows and "columns" specifies the number of columns.
4142 class MatrixType : public Type, public llvm::FoldingSetNode {
4143 protected:
4144  friend class ASTContext;
4145 
4146  /// The element type of the matrix.
4148 
4149  MatrixType(QualType ElementTy, QualType CanonElementTy);
4150 
4151  MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy,
4152  const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr);
4153 
4154 public:
4155  /// Returns type of the elements being stored in the matrix
4156  QualType getElementType() const { return ElementType; }
4157 
4158  /// Valid elements types are the following:
4159  /// * an integer type (as in C23 6.2.5p22), but excluding enumerated types
4160  /// and _Bool
4161  /// * the standard floating types float or double
4162  /// * a half-precision floating point type, if one is supported on the target
4164  return T->isDependentType() ||
4165  (T->isRealType() && !T->isBooleanType() && !T->isEnumeralType());
4166  }
4167 
4168  bool isSugared() const { return false; }
4169  QualType desugar() const { return QualType(this, 0); }
4170 
4171  static bool classof(const Type *T) {
4172  return T->getTypeClass() == ConstantMatrix ||
4173  T->getTypeClass() == DependentSizedMatrix;
4174  }
4175 };
4176 
4177 /// Represents a concrete matrix type with constant number of rows and columns
4178 class ConstantMatrixType final : public MatrixType {
4179 protected:
4180  friend class ASTContext;
4181 
4182  /// Number of rows and columns.
4183  unsigned NumRows;
4184  unsigned NumColumns;
4185 
4186  static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
4187 
4188  ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
4189  unsigned NColumns, QualType CanonElementType);
4190 
4191  ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows,
4192  unsigned NColumns, QualType CanonElementType);
4193 
4194 public:
4195  /// Returns the number of rows in the matrix.
4196  unsigned getNumRows() const { return NumRows; }
4197 
4198  /// Returns the number of columns in the matrix.
4199  unsigned getNumColumns() const { return NumColumns; }
4200 
4201  /// Returns the number of elements required to embed the matrix into a vector.
4202  unsigned getNumElementsFlattened() const {
4203  return getNumRows() * getNumColumns();
4204  }
4205 
4206  /// Returns true if \p NumElements is a valid matrix dimension.
4207  static constexpr bool isDimensionValid(size_t NumElements) {
4208  return NumElements > 0 && NumElements <= MaxElementsPerDimension;
4209  }
4210 
4211  /// Returns the maximum number of elements per dimension.
4212  static constexpr unsigned getMaxElementsPerDimension() {
4213  return MaxElementsPerDimension;
4214  }
4215 
4216  void Profile(llvm::FoldingSetNodeID &ID) {
4217  Profile(ID, getElementType(), getNumRows(), getNumColumns(),
4218  getTypeClass());
4219  }
4220 
4221  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
4222  unsigned NumRows, unsigned NumColumns,
4223  TypeClass TypeClass) {
4224  ID.AddPointer(ElementType.getAsOpaquePtr());
4225  ID.AddInteger(NumRows);
4226  ID.AddInteger(NumColumns);
4227  ID.AddInteger(TypeClass);
4228  }
4229 
4230  static bool classof(const Type *T) {
4231  return T->getTypeClass() == ConstantMatrix;
4232  }
4233 };
4234 
4235 /// Represents a matrix type where the type and the number of rows and columns
4236 /// is dependent on a template.
4237 class DependentSizedMatrixType final : public MatrixType {
4238  friend class ASTContext;
4239 
4240  Expr *RowExpr;
4241  Expr *ColumnExpr;
4242 
4243  SourceLocation loc;
4244 
4245  DependentSizedMatrixType(QualType ElementType, QualType CanonicalType,
4246  Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc);
4247 
4248 public:
4249  Expr *getRowExpr() const { return RowExpr; }
4250  Expr *getColumnExpr() const { return ColumnExpr; }
4251  SourceLocation getAttributeLoc() const { return loc; }
4252 
4253  static bool classof(const Type *T) {
4254  return T->getTypeClass() == DependentSizedMatrix;
4255  }
4256 
4257  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4258  Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
4259  }
4260 
4261  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4262  QualType ElementType, Expr *RowExpr, Expr *ColumnExpr);
4263 };
4264 
4265 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
4266 /// class of FunctionNoProtoType and FunctionProtoType.
4267 class FunctionType : public Type {
4268  // The type returned by the function.
4269  QualType ResultType;
4270 
4271 public:
4272  /// Interesting information about a specific parameter that can't simply
4273  /// be reflected in parameter's type. This is only used by FunctionProtoType
4274  /// but is in FunctionType to make this class available during the
4275  /// specification of the bases of FunctionProtoType.
4276  ///
4277  /// It makes sense to model language features this way when there's some
4278  /// sort of parameter-specific override (such as an attribute) that
4279  /// affects how the function is called. For example, the ARC ns_consumed
4280  /// attribute changes whether a parameter is passed at +0 (the default)
4281  /// or +1 (ns_consumed). This must be reflected in the function type,
4282  /// but isn't really a change to the parameter type.
4283  ///
4284  /// One serious disadvantage of modelling language features this way is
4285  /// that they generally do not work with language features that attempt
4286  /// to destructure types. For example, template argument deduction will
4287  /// not be able to match a parameter declared as
4288  /// T (*)(U)
4289  /// against an argument of type
4290  /// void (*)(__attribute__((ns_consumed)) id)
4291  /// because the substitution of T=void, U=id into the former will
4292  /// not produce the latter.
4294  enum {
4295  ABIMask = 0x0F,
4296  IsConsumed = 0x10,
4297  HasPassObjSize = 0x20,
4298  IsNoEscape = 0x40,
4299  };
4300  unsigned char Data = 0;
4301 
4302  public:
4303  ExtParameterInfo() = default;
4304 
4305  /// Return the ABI treatment of this parameter.
4306  ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
4308  ExtParameterInfo copy = *this;
4309  copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
4310  return copy;
4311  }
4312 
4313  /// Is this parameter considered "consumed" by Objective-C ARC?
4314  /// Consumed parameters must have retainable object type.
4315  bool isConsumed() const { return (Data & IsConsumed); }
4316  ExtParameterInfo withIsConsumed(bool consumed) const {
4317  ExtParameterInfo copy = *this;
4318  if (consumed)
4319  copy.Data |= IsConsumed;
4320  else
4321  copy.Data &= ~IsConsumed;
4322  return copy;
4323  }
4324 
4325  bool hasPassObjectSize() const { return Data & HasPassObjSize; }
4327  ExtParameterInfo Copy = *this;
4328  Copy.Data |= HasPassObjSize;
4329  return Copy;
4330  }
4331 
4332  bool isNoEscape() const { return Data & IsNoEscape; }
4333  ExtParameterInfo withIsNoEscape(bool NoEscape) const {
4334  ExtParameterInfo Copy = *this;
4335  if (NoEscape)
4336  Copy.Data |= IsNoEscape;
4337  else
4338  Copy.Data &= ~IsNoEscape;
4339  return Copy;
4340  }
4341 
4342  unsigned char getOpaqueValue() const { return Data; }
4343  static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
4344  ExtParameterInfo result;
4345  result.Data = data;
4346  return result;
4347  }
4348 
4350  return lhs.Data == rhs.Data;
4351  }
4352 
4354  return lhs.Data != rhs.Data;
4355  }
4356  };
4357 
4358  /// A class which abstracts out some details necessary for
4359  /// making a call.
4360  ///
4361  /// It is not actually used directly for storing this information in
4362  /// a FunctionType, although FunctionType does currently use the
4363  /// same bit-pattern.
4364  ///
4365  // If you add a field (say Foo), other than the obvious places (both,
4366  // constructors, compile failures), what you need to update is
4367  // * Operator==
4368  // * getFoo
4369  // * withFoo
4370  // * functionType. Add Foo, getFoo.
4371  // * ASTContext::getFooType
4372  // * ASTContext::mergeFunctionTypes
4373  // * FunctionNoProtoType::Profile
4374  // * FunctionProtoType::Profile
4375  // * TypePrinter::PrintFunctionProto
4376  // * AST read and write
4377  // * Codegen
4378  class ExtInfo {
4379  friend class FunctionType;
4380 
4381  // Feel free to rearrange or add bits, but if you go over 16, you'll need to
4382  // adjust the Bits field below, and if you add bits, you'll need to adjust
4383  // Type::FunctionTypeBitfields::ExtInfo as well.
4384 
4385  // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
4386  // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | 12 |
4387  //
4388  // regparm is either 0 (no regparm attribute) or the regparm value+1.
4389  enum { CallConvMask = 0x1F };
4390  enum { NoReturnMask = 0x20 };
4391  enum { ProducesResultMask = 0x40 };
4392  enum { NoCallerSavedRegsMask = 0x80 };
4393  enum {
4394  RegParmMask = 0x700,
4395  RegParmOffset = 8
4396  };
4397  enum { NoCfCheckMask = 0x800 };
4398  enum { CmseNSCallMask = 0x1000 };
4399  uint16_t Bits = CC_C;
4400 
4401  ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
4402 
4403  public:
4404  // Constructor with no defaults. Use this when you know that you
4405  // have all the elements (when reading an AST file for example).
4406  ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
4407  bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
4408  bool cmseNSCall) {
4409  assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
4410  Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
4411  (producesResult ? ProducesResultMask : 0) |
4412  (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
4413  (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
4414  (NoCfCheck ? NoCfCheckMask : 0) |
4415  (cmseNSCall ? CmseNSCallMask : 0);
4416  }
4417 
4418  // Constructor with all defaults. Use when for example creating a
4419  // function known to use defaults.
4420  ExtInfo() = default;
4421 
4422  // Constructor with just the calling convention, which is an important part
4423  // of the canonical type.
4424  ExtInfo(CallingConv CC) : Bits(CC) {}
4425 
4426  bool getNoReturn() const { return Bits & NoReturnMask; }
4427  bool getProducesResult() const { return Bits & ProducesResultMask; }
4428  bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
4429  bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
4430  bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
4431  bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
4432 
4433  unsigned getRegParm() const {
4434  unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
4435  if (RegParm > 0)
4436  --RegParm;
4437  return RegParm;
4438  }
4439 
4440  CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
4441 
4442  bool operator==(ExtInfo Other) const {
4443  return Bits == Other.Bits;
4444  }
4445  bool operator!=(ExtInfo Other) const {
4446  return Bits != Other.Bits;
4447  }
4448 
4449  // Note that we don't have setters. That is by design, use
4450  // the following with methods instead of mutating these objects.
4451 
4452  ExtInfo withNoReturn(bool noReturn) const {
4453  if (noReturn)
4454  return ExtInfo(Bits | NoReturnMask);
4455  else
4456  return ExtInfo(Bits & ~NoReturnMask);
4457  }
4458 
4459  ExtInfo withProducesResult(bool producesResult) const {
4460  if (producesResult)
4461  return ExtInfo(Bits | ProducesResultMask);
4462  else
4463  return ExtInfo(Bits & ~ProducesResultMask);
4464  }
4465 
4466  ExtInfo withCmseNSCall(bool cmseNSCall) const {
4467  if (cmseNSCall)
4468  return ExtInfo(Bits | CmseNSCallMask);
4469  else
4470  return ExtInfo(Bits & ~CmseNSCallMask);
4471  }
4472 
4473  ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
4474  if (noCallerSavedRegs)
4475  return ExtInfo(Bits | NoCallerSavedRegsMask);
4476  else
4477  return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4478  }
4479 
4480  ExtInfo withNoCfCheck(bool noCfCheck) const {
4481  if (noCfCheck)
4482  return ExtInfo(Bits | NoCfCheckMask);
4483  else
4484  return ExtInfo(Bits & ~NoCfCheckMask);
4485  }
4486 
4487  ExtInfo withRegParm(unsigned RegParm) const {
4488  assert(RegParm < 7 && "Invalid regparm value");
4489  return ExtInfo((Bits & ~RegParmMask) |
4490  ((RegParm + 1) << RegParmOffset));
4491  }
4492 
4494  return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
4495  }
4496 
4497  void Profile(llvm::FoldingSetNodeID &ID) const {
4498  ID.AddInteger(Bits);
4499  }
4500  };
4501 
4502  /// A simple holder for a QualType representing a type in an
4503  /// exception specification. Unfortunately needed by FunctionProtoType
4504  /// because TrailingObjects cannot handle repeated types.
4506 
4507  /// A simple holder for various uncommon bits which do not fit in
4508  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
4509  /// alignment of subsequent objects in TrailingObjects.
4510  struct alignas(void *) FunctionTypeExtraBitfields {
4511  /// The number of types in the exception specification.
4512  /// A whole unsigned is not needed here and according to
4513  /// [implimits] 8 bits would be enough here.
4514  unsigned NumExceptionType : 10;
4515 
4516  LLVM_PREFERRED_TYPE(bool)
4517  unsigned HasArmTypeAttributes : 1;
4518 
4520  : NumExceptionType(0), HasArmTypeAttributes(false) {}
4521  };
4522 
4523  /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
4524  /// of function type attributes that can be set on function types, including
4525  /// function pointers.
4526  enum AArch64SMETypeAttributes : unsigned {
4527  SME_NormalFunction = 0,
4528  SME_PStateSMEnabledMask = 1 << 0,
4529  SME_PStateSMCompatibleMask = 1 << 1,
4530 
4531  // Describes the value of the state using ArmStateValue.
4532  SME_ZAShift = 2,
4533  SME_ZAMask = 0b111 << SME_ZAShift,
4534  SME_ZT0Shift = 5,
4535  SME_ZT0Mask = 0b111 << SME_ZT0Shift,
4536 
4537  SME_AttributeMask =
4538  0b111'111'11 // We can't support more than 8 bits because of
4539  // the bitmask in FunctionTypeExtraBitfields.
4540  };
4541 
4542  enum ArmStateValue : unsigned {
4543  ARM_None = 0,
4544  ARM_Preserves = 1,
4545  ARM_In = 2,
4546  ARM_Out = 3,
4547  ARM_InOut = 4,
4548  };
4549 
4550  static ArmStateValue getArmZAState(unsigned AttrBits) {
4551  return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4552  }
4553 
4554  static ArmStateValue getArmZT0State(unsigned AttrBits) {
4555  return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4556  }
4557 
4558  /// A holder for Arm type attributes as described in the Arm C/C++
4559  /// Language extensions which are not particularly common to all
4560  /// types and therefore accounted separately from FunctionTypeBitfields.
4561  struct alignas(void *) FunctionTypeArmAttributes {
4562  /// Any AArch64 SME ACLE type attributes that need to be propagated
4563  /// on declarations and function pointers.
4564  unsigned AArch64SMEAttributes : 8;
4565 
4566  FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
4567  };
4568 
4569 protected:
4572  : Type(tc, Canonical, Dependence), ResultType(res) {
4573  FunctionTypeBits.ExtInfo = Info.Bits;
4574  }
4575 
4577  if (isFunctionProtoType())
4578  return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4579 
4580  return Qualifiers();
4581  }
4582 
4583 public:
4584  QualType getReturnType() const { return ResultType; }
4585 
4586  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
4587  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
4588 
4589  /// Determine whether this function type includes the GNU noreturn
4590  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
4591  /// type.
4592  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
4593 
4594  bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
4595  CallingConv getCallConv() const { return getExtInfo().getCC(); }
4596  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
4597 
4598  static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4599  "Const, volatile and restrict are assumed to be a subset of "
4600  "the fast qualifiers.");
4601 
4602  bool isConst() const { return getFastTypeQuals().hasConst(); }
4603  bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
4604  bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
4605 
4606  /// Determine the type of an expression that calls a function of
4607  /// this type.
4608  QualType getCallResultType(const ASTContext &Context) const {
4609  return getReturnType().getNonLValueExprType(Context);
4610  }
4611 
4612  static StringRef getNameForCallConv(CallingConv CC);
4613 
4614  static bool classof(const Type *T) {
4615  return T->getTypeClass() == FunctionNoProto ||
4616  T->getTypeClass() == FunctionProto;
4617  }
4618 };
4619 
4620 /// Represents a K&R-style 'int foo()' function, which has
4621 /// no information available about its arguments.
4622 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
4623  friend class ASTContext; // ASTContext creates these.
4624 
4625  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
4626  : FunctionType(FunctionNoProto, Result, Canonical,
4627  Result->getDependence() &
4628  ~(TypeDependence::DependentInstantiation |
4629  TypeDependence::UnexpandedPack),
4630  Info) {}
4631 
4632 public:
4633  // No additional state past what FunctionType provides.
4634 
4635  bool isSugared() const { return false; }
4636  QualType desugar() const { return QualType(this, 0); }
4637 
4638  void Profile(llvm::FoldingSetNodeID &ID) {
4639  Profile(ID, getReturnType(), getExtInfo());
4640  }
4641 
4642  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
4643  ExtInfo Info) {
4644  Info.Profile(ID);
4645  ID.AddPointer(ResultType.getAsOpaquePtr());
4646  }
4647 
4648  static bool classof(const Type *T) {
4649  return T->getTypeClass() == FunctionNoProto;
4650  }
4651 };
4652 
4653 /// Represents a prototype with parameter type info, e.g.
4654 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
4655 /// parameters, not as having a single void parameter. Such a type can have
4656 /// an exception specification, but this specification is not part of the
4657 /// canonical type. FunctionProtoType has several trailing objects, some of
4658 /// which optional. For more information about the trailing objects see
4659 /// the first comment inside FunctionProtoType.
4661  : public FunctionType,
4662  public llvm::FoldingSetNode,
4663  private llvm::TrailingObjects<
4664  FunctionProtoType, QualType, SourceLocation,
4665  FunctionType::FunctionTypeExtraBitfields,
4666  FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
4667  Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
4668  friend class ASTContext; // ASTContext creates these.
4669  friend TrailingObjects;
4670 
4671  // FunctionProtoType is followed by several trailing objects, some of
4672  // which optional. They are in order:
4673  //
4674  // * An array of getNumParams() QualType holding the parameter types.
4675  // Always present. Note that for the vast majority of FunctionProtoType,
4676  // these will be the only trailing objects.
4677  //
4678  // * Optionally if the function is variadic, the SourceLocation of the
4679  // ellipsis.
4680  //
4681  // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
4682  // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
4683  // a single FunctionTypeExtraBitfields. Present if and only if
4684  // hasExtraBitfields() is true.
4685  //
4686  // * Optionally exactly one of:
4687  // * an array of getNumExceptions() ExceptionType,
4688  // * a single Expr *,
4689  // * a pair of FunctionDecl *,
4690  // * a single FunctionDecl *
4691  // used to store information about the various types of exception
4692  // specification. See getExceptionSpecSize for the details.
4693  //
4694  // * Optionally an array of getNumParams() ExtParameterInfo holding
4695  // an ExtParameterInfo for each of the parameters. Present if and
4696  // only if hasExtParameterInfos() is true.
4697  //
4698  // * Optionally a Qualifiers object to represent extra qualifiers that can't
4699  // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and only
4700  // if hasExtQualifiers() is true.
4701  //
4702  // The optional FunctionTypeExtraBitfields has to be before the data
4703  // related to the exception specification since it contains the number
4704  // of exception types.
4705  //
4706  // We put the ExtParameterInfos last. If all were equal, it would make
4707  // more sense to put these before the exception specification, because
4708  // it's much easier to skip past them compared to the elaborate switch
4709  // required to skip the exception specification. However, all is not
4710  // equal; ExtParameterInfos are used to model very uncommon features,
4711  // and it's better not to burden the more common paths.
4712 
4713 public:
4714  /// Holds information about the various types of exception specification.
4715  /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
4716  /// used to group together the various bits of information about the
4717  /// exception specification.
4719  /// The kind of exception specification this is.
4721 
4722  /// Explicitly-specified list of exception types.
4724 
4725  /// Noexcept expression, if this is a computed noexcept specification.
4726  Expr *NoexceptExpr = nullptr;
4727 
4728  /// The function whose exception specification this is, for
4729  /// EST_Unevaluated and EST_Uninstantiated.
4730  FunctionDecl *SourceDecl = nullptr;
4731 
4732  /// The function template whose exception specification this is instantiated
4733  /// from, for EST_Uninstantiated.
4734  FunctionDecl *SourceTemplate = nullptr;
4735 
4736  ExceptionSpecInfo() = default;
4737 
4739 
4740  void instantiate();
4741  };
4742 
4743  /// Extra information about a function prototype. ExtProtoInfo is not
4744  /// stored as such in FunctionProtoType but is used to group together
4745  /// the various bits of extra information about a function prototype.
4746  struct ExtProtoInfo {
4748  unsigned Variadic : 1;
4749  unsigned HasTrailingReturn : 1;
4750  unsigned AArch64SMEAttributes : 8;
4752  RefQualifierKind RefQualifier = RQ_None;
4754  const ExtParameterInfo *ExtParameterInfos = nullptr;
4756 
4758  : Variadic(false), HasTrailingReturn(false),
4759  AArch64SMEAttributes(SME_NormalFunction) {}
4760 
4762  : ExtInfo(CC), Variadic(false), HasTrailingReturn(false),
4763  AArch64SMEAttributes(SME_NormalFunction) {}
4764 
4766  ExtProtoInfo Result(*this);
4767  Result.ExceptionSpec = ESI;
4768  return Result;
4769  }
4770 
4772  return ExceptionSpec.Type == EST_Dynamic ||
4773  requiresFunctionProtoTypeArmAttributes();
4774  }
4775 
4777  return AArch64SMEAttributes != SME_NormalFunction;
4778  }
4779 
4781  if (Enable)
4782  AArch64SMEAttributes |= Kind;
4783  else
4784  AArch64SMEAttributes &= ~Kind;
4785  }
4786  };
4787 
4788 private:
4789  unsigned numTrailingObjects(OverloadToken<QualType>) const {
4790  return getNumParams();
4791  }
4792 
4793  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
4794  return isVariadic();
4795  }
4796 
4797  unsigned numTrailingObjects(OverloadToken<FunctionTypeArmAttributes>) const {
4798  return hasArmTypeAttributes();
4799  }
4800 
4801  unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
4802  return hasExtraBitfields();
4803  }
4804 
4805  unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
4806  return getExceptionSpecSize().NumExceptionType;
4807  }
4808 
4809  unsigned numTrailingObjects(OverloadToken<Expr *>) const {
4810  return getExceptionSpecSize().NumExprPtr;
4811  }
4812 
4813  unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
4814  return getExceptionSpecSize().NumFunctionDeclPtr;
4815  }
4816 
4817  unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
4818  return hasExtParameterInfos() ? getNumParams() : 0;
4819  }
4820 
4821  /// Determine whether there are any argument types that
4822  /// contain an unexpanded parameter pack.
4823  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
4824  unsigned numArgs) {
4825  for (unsigned Idx = 0; Idx < numArgs; ++Idx)
4826  if (ArgArray[Idx]->containsUnexpandedParameterPack())
4827  return true;
4828 
4829  return false;
4830  }
4831 
4832  FunctionProtoType(QualType result, ArrayRef<QualType> params,
4833  QualType canonical, const ExtProtoInfo &epi);
4834 
4835  /// This struct is returned by getExceptionSpecSize and is used to
4836  /// translate an ExceptionSpecificationType to the number and kind
4837  /// of trailing objects related to the exception specification.
4838  struct ExceptionSpecSizeHolder {
4839  unsigned NumExceptionType;
4840  unsigned NumExprPtr;
4841  unsigned NumFunctionDeclPtr;
4842  };
4843 
4844  /// Return the number and kind of trailing objects
4845  /// related to the exception specification.
4846  static ExceptionSpecSizeHolder
4847  getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
4848  switch (EST) {
4849  case EST_None:
4850  case EST_DynamicNone:
4851  case EST_MSAny:
4852  case EST_BasicNoexcept:
4853  case EST_Unparsed:
4854  case EST_NoThrow:
4855  return {0, 0, 0};
4856 
4857  case EST_Dynamic:
4858  return {NumExceptions, 0, 0};
4859 
4860  case EST_DependentNoexcept:
4861  case EST_NoexceptFalse:
4862  case EST_NoexceptTrue:
4863  return {0, 1, 0};
4864 
4865  case EST_Uninstantiated:
4866  return {0, 0, 2};
4867 
4868  case EST_Unevaluated:
4869  return {0, 0, 1};
4870  }
4871  llvm_unreachable("bad exception specification kind");
4872  }
4873 
4874  /// Return the number and kind of trailing objects
4875  /// related to the exception specification.
4876  ExceptionSpecSizeHolder getExceptionSpecSize() const {
4877  return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
4878  }
4879 
4880  /// Whether the trailing FunctionTypeExtraBitfields is present.
4881  bool hasExtraBitfields() const {
4882  assert((getExceptionSpecType() != EST_Dynamic ||
4883  FunctionTypeBits.HasExtraBitfields) &&
4884  "ExtraBitfields are required for given ExceptionSpecType");
4885  return FunctionTypeBits.HasExtraBitfields;
4886 
4887  }
4888 
4889  bool hasArmTypeAttributes() const {
4890  return FunctionTypeBits.HasExtraBitfields &&
4891  getTrailingObjects<FunctionTypeExtraBitfields>()
4892  ->HasArmTypeAttributes;
4893  }
4894 
4895  bool hasExtQualifiers() const {
4896  return FunctionTypeBits.HasExtQuals;
4897  }
4898 
4899 public:
4900  unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
4901 
4902  QualType getParamType(unsigned i) const {
4903  assert(i < getNumParams() && "invalid parameter index");
4904  return param_type_begin()[i];
4905  }
4906 
4908  return llvm::ArrayRef(param_type_begin(), param_type_end());
4909  }
4910 
4912  ExtProtoInfo EPI;
4913  EPI.ExtInfo = getExtInfo();
4914  EPI.Variadic = isVariadic();
4915  EPI.EllipsisLoc = getEllipsisLoc();
4916  EPI.HasTrailingReturn = hasTrailingReturn();
4917  EPI.ExceptionSpec = getExceptionSpecInfo();
4918  EPI.TypeQuals = getMethodQuals();
4919  EPI.RefQualifier = getRefQualifier();
4920  EPI.ExtParameterInfos = getExtParameterInfosOrNull();
4921  EPI.AArch64SMEAttributes = getAArch64SMEAttributes();
4922  return EPI;
4923  }
4924 
4925  /// Get the kind of exception specification on this function.
4927  return static_cast<ExceptionSpecificationType>(
4928  FunctionTypeBits.ExceptionSpecType);
4929  }
4930 
4931  /// Return whether this function has any kind of exception spec.
4932  bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
4933 
4934  /// Return whether this function has a dynamic (throw) exception spec.
4936  return isDynamicExceptionSpec(getExceptionSpecType());
4937  }
4938 
4939  /// Return whether this function has a noexcept exception spec.
4941  return isNoexceptExceptionSpec(getExceptionSpecType());
4942  }
4943 
4944  /// Return whether this function has a dependent exception spec.
4945  bool hasDependentExceptionSpec() const;
4946 
4947  /// Return whether this function has an instantiation-dependent exception
4948  /// spec.
4949  bool hasInstantiationDependentExceptionSpec() const;
4950 
4951  /// Return all the available information about this type's exception spec.
4953  ExceptionSpecInfo Result;
4954  Result.Type = getExceptionSpecType();
4955  if (Result.Type == EST_Dynamic) {
4956  Result.Exceptions = exceptions();
4957  } else if (isComputedNoexcept(Result.Type)) {
4958  Result.NoexceptExpr = getNoexceptExpr();
4959  } else if (Result.Type == EST_Uninstantiated) {
4960  Result.SourceDecl = getExceptionSpecDecl();
4961  Result.SourceTemplate = getExceptionSpecTemplate();
4962  } else if (Result.Type == EST_Unevaluated) {
4963  Result.SourceDecl = getExceptionSpecDecl();
4964  }
4965  return Result;
4966  }
4967 
4968  /// Return the number of types in the exception specification.
4969  unsigned getNumExceptions() const {
4970  return getExceptionSpecType() == EST_Dynamic
4971  ? getTrailingObjects<FunctionTypeExtraBitfields>()
4972  ->NumExceptionType
4973  : 0;
4974  }
4975 
4976  /// Return the ith exception type, where 0 <= i < getNumExceptions().
4977  QualType getExceptionType(unsigned i) const {
4978  assert(i < getNumExceptions() && "Invalid exception number!");
4979  return exception_begin()[i];
4980  }
4981 
4982  /// Return the expression inside noexcept(expression), or a null pointer
4983  /// if there is none (because the exception spec is not of this form).
4985  if (!isComputedNoexcept(getExceptionSpecType()))
4986  return nullptr;
4987  return *getTrailingObjects<Expr *>();
4988  }
4989 
4990  /// If this function type has an exception specification which hasn't
4991  /// been determined yet (either because it has not been evaluated or because
4992  /// it has not been instantiated), this is the function whose exception
4993  /// specification is represented by this type.
4995  if (getExceptionSpecType() != EST_Uninstantiated &&
4996  getExceptionSpecType() != EST_Unevaluated)
4997  return nullptr;
4998  return getTrailingObjects<FunctionDecl *>()[0];
4999  }
5000 
5001  /// If this function type has an uninstantiated exception
5002  /// specification, this is the function whose exception specification
5003  /// should be instantiated to find the exception specification for
5004  /// this type.
5006  if (getExceptionSpecType() != EST_Uninstantiated)
5007  return nullptr;
5008  return getTrailingObjects<FunctionDecl *>()[1];
5009  }
5010 
5011  /// Determine whether this function type has a non-throwing exception
5012  /// specification.
5013  CanThrowResult canThrow() const;
5014 
5015  /// Determine whether this function type has a non-throwing exception
5016  /// specification. If this depends on template arguments, returns
5017  /// \c ResultIfDependent.
5018  bool isNothrow(bool ResultIfDependent = false) const {
5019  return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
5020  }
5021 
5022  /// Whether this function prototype is variadic.
5023  bool isVariadic() const { return FunctionTypeBits.Variadic; }
5024 
5026  return isVariadic() ? *getTrailingObjects<SourceLocation>()
5027  : SourceLocation();
5028  }
5029 
5030  /// Determines whether this function prototype contains a
5031  /// parameter pack at the end.
5032  ///
5033  /// A function template whose last parameter is a parameter pack can be
5034  /// called with an arbitrary number of arguments, much like a variadic
5035  /// function.
5036  bool isTemplateVariadic() const;
5037 
5038  /// Whether this function prototype has a trailing return type.
5039  bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
5040 
5042  if (hasExtQualifiers())
5043  return *getTrailingObjects<Qualifiers>();
5044  else
5045  return getFastTypeQuals();
5046  }
5047 
5048  /// Retrieve the ref-qualifier associated with this function type.
5050  return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
5051  }
5052 
5054 
5056  return llvm::ArrayRef(param_type_begin(), param_type_end());
5057  }
5058 
5060  return getTrailingObjects<QualType>();
5061  }
5062 
5064  return param_type_begin() + getNumParams();
5065  }
5066 
5067  using exception_iterator = const QualType *;
5068 
5070  return llvm::ArrayRef(exception_begin(), exception_end());
5071  }
5072 
5074  return reinterpret_cast<exception_iterator>(
5075  getTrailingObjects<ExceptionType>());
5076  }
5077 
5079  return exception_begin() + getNumExceptions();
5080  }
5081 
5082  /// Is there any interesting extra information for any of the parameters
5083  /// of this function type?
5084  bool hasExtParameterInfos() const {
5085  return FunctionTypeBits.HasExtParameterInfos;
5086  }
5087 
5089  assert(hasExtParameterInfos());
5090  return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
5091  getNumParams());
5092  }
5093 
5094  /// Return a pointer to the beginning of the array of extra parameter
5095  /// information, if present, or else null if none of the parameters
5096  /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
5098  if (!hasExtParameterInfos())
5099  return nullptr;
5100  return getTrailingObjects<ExtParameterInfo>();
5101  }
5102 
5103  /// Return a bitmask describing the SME attributes on the function type, see
5104  /// AArch64SMETypeAttributes for their values.
5105  unsigned getAArch64SMEAttributes() const {
5106  if (!hasArmTypeAttributes())
5107  return SME_NormalFunction;
5108  return getTrailingObjects<FunctionTypeArmAttributes>()
5109  ->AArch64SMEAttributes;
5110  }
5111 
5113  assert(I < getNumParams() && "parameter index out of range");
5114  if (hasExtParameterInfos())
5115  return getTrailingObjects<ExtParameterInfo>()[I];
5116  return ExtParameterInfo();
5117  }
5118 
5119  ParameterABI getParameterABI(unsigned I) const {
5120  assert(I < getNumParams() && "parameter index out of range");
5121  if (hasExtParameterInfos())
5122  return getTrailingObjects<ExtParameterInfo>()[I].getABI();
5123  return ParameterABI::Ordinary;
5124  }
5125 
5126  bool isParamConsumed(unsigned I) const {
5127  assert(I < getNumParams() && "parameter index out of range");
5128  if (hasExtParameterInfos())
5129  return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
5130  return false;
5131  }
5132 
5133  bool isSugared() const { return false; }
5134  QualType desugar() const { return QualType(this, 0); }
5135 
5136  void printExceptionSpecification(raw_ostream &OS,
5137  const PrintingPolicy &Policy) const;
5138 
5139  static bool classof(const Type *T) {
5140  return T->getTypeClass() == FunctionProto;
5141  }
5142 
5143  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
5144  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
5145  param_type_iterator ArgTys, unsigned NumArgs,
5146  const ExtProtoInfo &EPI, const ASTContext &Context,
5147  bool Canonical);
5148 };
5149 
5150 /// Represents the dependent type named by a dependently-scoped
5151 /// typename using declaration, e.g.
5152 /// using typename Base<T>::foo;
5153 ///
5154 /// Template instantiation turns these into the underlying type.
5155 class UnresolvedUsingType : public Type {
5156  friend class ASTContext; // ASTContext creates these.
5157 
5159 
5161  : Type(UnresolvedUsing, QualType(),
5162  TypeDependence::DependentInstantiation),
5163  Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {}
5164 
5165 public:
5167 
5168  bool isSugared() const { return false; }
5169  QualType desugar() const { return QualType(this, 0); }
5170 
5171  static bool classof(const Type *T) {
5172  return T->getTypeClass() == UnresolvedUsing;
5173  }
5174 
5175  void Profile(llvm::FoldingSetNodeID &ID) {
5176  return Profile(ID, Decl);
5177  }
5178 
5179  static void Profile(llvm::FoldingSetNodeID &ID,
5181  ID.AddPointer(D);
5182  }
5183 };
5184 
5185 class UsingType final : public Type,
5186  public llvm::FoldingSetNode,
5187  private llvm::TrailingObjects<UsingType, QualType> {
5188  UsingShadowDecl *Found;
5189  friend class ASTContext; // ASTContext creates these.
5190  friend TrailingObjects;
5191 
5192  UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
5193 
5194 public:
5195  UsingShadowDecl *getFoundDecl() const { return Found; }
5196  QualType getUnderlyingType() const;
5197 
5198  bool isSugared() const { return true; }
5199 
5200  // This always has the 'same' type as declared, but not necessarily identical.
5201  QualType desugar() const { return getUnderlyingType(); }
5202 
5203  // Internal helper, for debugging purposes.
5204  bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
5205 
5206  void Profile(llvm::FoldingSetNodeID &ID) {
5207  Profile(ID, Found, getUnderlyingType());
5208  }
5209  static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
5210  QualType Underlying) {
5211  ID.AddPointer(Found);
5212  Underlying.Profile(ID);
5213  }
5214  static bool classof(const Type *T) { return T->getTypeClass() == Using; }
5215 };
5216 
5217 class TypedefType final : public Type,
5218  public llvm::FoldingSetNode,
5219  private llvm::TrailingObjects<TypedefType, QualType> {
5221  friend class ASTContext; // ASTContext creates these.
5222  friend TrailingObjects;
5223 
5224  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
5225  QualType can);
5226 
5227 public:
5228  TypedefNameDecl *getDecl() const { return Decl; }
5229 
5230  bool isSugared() const { return true; }
5231 
5232  // This always has the 'same' type as declared, but not necessarily identical.
5233  QualType desugar() const;
5234 
5235  // Internal helper, for debugging purposes.
5236  bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
5237 
5238  void Profile(llvm::FoldingSetNodeID &ID) {
5239  Profile(ID, Decl, typeMatchesDecl() ? QualType() : desugar());
5240  }
5241  static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl,
5242  QualType Underlying) {
5243  ID.AddPointer(Decl);
5244  if (!Underlying.isNull())
5245  Underlying.Profile(ID);
5246  }
5247 
5248  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
5249 };
5250 
5251 /// Sugar type that represents a type that was qualified by a qualifier written
5252 /// as a macro invocation.
5253 class MacroQualifiedType : public Type {
5254  friend class ASTContext; // ASTContext creates these.
5255 
5256  QualType UnderlyingTy;
5257  const IdentifierInfo *MacroII;
5258 
5259  MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
5260  const IdentifierInfo *MacroII)
5261  : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
5262  UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
5263  assert(isa<AttributedType>(UnderlyingTy) &&
5264  "Expected a macro qualified type to only wrap attributed types.");
5265  }
5266 
5267 public:
5268  const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
5269  QualType getUnderlyingType() const { return UnderlyingTy; }
5270 
5271  /// Return this attributed type's modified type with no qualifiers attached to
5272  /// it.
5273  QualType getModifiedType() const;
5274 
5275  bool isSugared() const { return true; }
5276  QualType desugar() const;
5277 
5278  static bool classof(const Type *T) {
5279  return T->getTypeClass() == MacroQualified;
5280  }
5281 };
5282 
5283 /// Represents a `typeof` (or __typeof__) expression (a C23 feature and GCC
5284 /// extension) or a `typeof_unqual` expression (a C23 feature).
5285 class TypeOfExprType : public Type {
5286  Expr *TOExpr;
5287 
5288 protected:
5289  friend class ASTContext; // ASTContext creates these.
5290 
5292 
5293 public:
5294  Expr *getUnderlyingExpr() const { return TOExpr; }
5295 
5296  /// Returns the kind of 'typeof' type this is.
5298  return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
5300  }
5301 
5302  /// Remove a single level of sugar.
5303  QualType desugar() const;
5304 
5305  /// Returns whether this type directly provides sugar.
5306  bool isSugared() const;
5307 
5308  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
5309 };
5310 
5311 /// Internal representation of canonical, dependent
5312 /// `typeof(expr)` types.
5313 ///
5314 /// This class is used internally by the ASTContext to manage
5315 /// canonical, dependent types, only. Clients will only see instances
5316 /// of this class via TypeOfExprType nodes.
5318  public llvm::FoldingSetNode {
5319 public:
5321 
5322  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5323  Profile(ID, Context, getUnderlyingExpr(),
5325  }
5326 
5327  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5328  Expr *E, bool IsUnqual);
5329 };
5330 
5331 /// Represents `typeof(type)`, a C23 feature and GCC extension, or
5332 /// `typeof_unqual(type), a C23 feature.
5333 class TypeOfType : public Type {
5334  friend class ASTContext; // ASTContext creates these.
5335 
5336  QualType TOType;
5337 
5339  : Type(TypeOf,
5340  Kind == TypeOfKind::Unqualified ? Can.getAtomicUnqualifiedType()
5341  : Can,
5342  T->getDependence()),
5343  TOType(T) {
5344  TypeOfBits.IsUnqual = Kind == TypeOfKind::Unqualified;
5345  }
5346 
5347 public:
5348  QualType getUnmodifiedType() const { return TOType; }
5349 
5350  /// Remove a single level of sugar.
5351  QualType desugar() const {
5352  QualType QT = getUnmodifiedType();
5353  return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
5354  }
5355 
5356  /// Returns whether this type directly provides sugar.
5357  bool isSugared() const { return true; }
5358 
5359  /// Returns the kind of 'typeof' type this is.
5361  return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
5363  }
5364 
5365  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
5366 };
5367 
5368 /// Represents the type `decltype(expr)` (C++11).
5369 class DecltypeType : public Type {
5370  Expr *E;
5371  QualType UnderlyingType;
5372 
5373 protected:
5374  friend class ASTContext; // ASTContext creates these.
5375 
5376  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
5377 
5378 public:
5379  Expr *getUnderlyingExpr() const { return E; }
5380  QualType getUnderlyingType() const { return UnderlyingType; }
5381 
5382  /// Remove a single level of sugar.
5383  QualType desugar() const;
5384 
5385  /// Returns whether this type directly provides sugar.
5386  bool isSugared() const;
5387 
5388  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
5389 };
5390 
5391 /// Internal representation of canonical, dependent
5392 /// decltype(expr) types.
5393 ///
5394 /// This class is used internally by the ASTContext to manage
5395 /// canonical, dependent types, only. Clients will only see instances
5396 /// of this class via DecltypeType nodes.
5397 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
5398 public:
5399  DependentDecltypeType(Expr *E, QualType UnderlyingTpe);
5400 
5401  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5402  Profile(ID, Context, getUnderlyingExpr());
5403  }
5404 
5405  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5406  Expr *E);
5407 };
5408 
5409 class PackIndexingType final
5410  : public Type,
5411  public llvm::FoldingSetNode,
5412  private llvm::TrailingObjects<PackIndexingType, QualType> {
5413  friend TrailingObjects;
5414 
5415  const ASTContext &Context;
5416  QualType Pattern;
5417  Expr *IndexExpr;
5418 
5419  unsigned Size;
5420 
5421 protected:
5422  friend class ASTContext; // ASTContext creates these.
5423  PackIndexingType(const ASTContext &Context, QualType Canonical,
5424  QualType Pattern, Expr *IndexExpr,
5425  ArrayRef<QualType> Expansions = {});
5426 
5427 public:
5428  Expr *getIndexExpr() const { return IndexExpr; }
5429  QualType getPattern() const { return Pattern; }
5430 
5431  bool isSugared() const { return hasSelectedType(); }
5432 
5433  QualType desugar() const {
5434  if (hasSelectedType())
5435  return getSelectedType();
5436  return QualType(this, 0);
5437  }
5438 
5440  assert(hasSelectedType() && "Type is dependant");
5441  return *(getExpansionsPtr() + *getSelectedIndex());
5442  }
5443 
5444  std::optional<unsigned> getSelectedIndex() const;
5445 
5446  bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }
5447 
5449  return {getExpansionsPtr(), Size};
5450  }
5451 
5452  static bool classof(const Type *T) {
5453  return T->getTypeClass() == PackIndexing;
5454  }
5455 
5456  void Profile(llvm::FoldingSetNodeID &ID) {
5457  if (hasSelectedType())
5458  getSelectedType().Profile(ID);
5459  else
5460  Profile(ID, Context, getPattern(), getIndexExpr());
5461  }
5462  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5463  QualType Pattern, Expr *E);
5464 
5465 private:
5466  const QualType *getExpansionsPtr() const {
5467  return getTrailingObjects<QualType>();
5468  }
5469 
5470  static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
5471  ArrayRef<QualType> Expansions = {});
5472 
5473  unsigned numTrailingObjects(OverloadToken<QualType>) const { return Size; }
5474 };
5475 
5476 /// A unary type transform, which is a type constructed from another.
5477 class UnaryTransformType : public Type {
5478 public:
5479  enum UTTKind {
5480 #define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
5481 #include "clang/Basic/TransformTypeTraits.def"
5482  };
5483 
5484 private:
5485  /// The untransformed type.
5486  QualType BaseType;
5487 
5488  /// The transformed type if not dependent, otherwise the same as BaseType.
5489  QualType UnderlyingType;
5490 
5491  UTTKind UKind;
5492 
5493 protected:
5494  friend class ASTContext;
5495 
5496  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
5497  QualType CanonicalTy);
5498 
5499 public:
5500  bool isSugared() const { return !isDependentType(); }
5501  QualType desugar() const { return UnderlyingType; }
5502 
5503  QualType getUnderlyingType() const { return UnderlyingType; }
5504  QualType getBaseType() const { return BaseType; }
5505 
5506  UTTKind getUTTKind() const { return UKind; }
5507 
5508  static bool classof(const Type *T) {
5509  return T->getTypeClass() == UnaryTransform;
5510  }
5511 };
5512 
5513 /// Internal representation of canonical, dependent
5514 /// __underlying_type(type) types.
5515 ///
5516 /// This class is used internally by the ASTContext to manage
5517 /// canonical, dependent types, only. Clients will only see instances
5518 /// of this class via UnaryTransformType nodes.
5520  public llvm::FoldingSetNode {
5521 public:
5522  DependentUnaryTransformType(const ASTContext &C, QualType BaseType,
5523  UTTKind UKind);
5524 
5525  void Profile(llvm::FoldingSetNodeID &ID) {
5526  Profile(ID, getBaseType(), getUTTKind());
5527  }
5528 
5529  static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
5530  UTTKind UKind) {
5531  ID.AddPointer(BaseType.getAsOpaquePtr());
5532  ID.AddInteger((unsigned)UKind);
5533  }
5534 };
5535 
5536 class TagType : public Type {
5537  friend class ASTReader;
5538  template <class T> friend class serialization::AbstractTypeReader;
5539 
5540  /// Stores the TagDecl associated with this type. The decl may point to any
5541  /// TagDecl that declares the entity.
5542  TagDecl *decl;
5543 
5544 protected:
5545  TagType(TypeClass TC, const TagDecl *D, QualType can);
5546 
5547 public:
5548  TagDecl *getDecl() const;
5549 
5550  /// Determines whether this type is in the process of being defined.
5551  bool isBeingDefined() const;
5552 
5553  static bool classof(const Type *T) {
5554  return T->getTypeClass() == Enum || T->getTypeClass() == Record;
5555  }
5556 };
5557 
5558 /// A helper class that allows the use of isa/cast/dyncast
5559 /// to detect TagType objects of structs/unions/classes.
5560 class RecordType : public TagType {
5561 protected:
5562  friend class ASTContext; // ASTContext creates these.
5563 
5564  explicit RecordType(const RecordDecl *D)
5565  : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5567  : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5568 
5569 public:
5570  RecordDecl *getDecl() const {
5571  return reinterpret_cast<RecordDecl*>(TagType::getDecl());
5572  }
5573 
5574  /// Recursively check all fields in the record for const-ness. If any field
5575  /// is declared const, return true. Otherwise, return false.
5576  bool hasConstFields() const;
5577 
5578  bool isSugared() const { return false; }
5579  QualType desugar() const { return QualType(this, 0); }
5580 
5581  static bool classof(const Type *T) { return T->getTypeClass() == Record; }
5582 };
5583 
5584 /// A helper class that allows the use of isa/cast/dyncast
5585 /// to detect TagType objects of enums.
5586 class EnumType : public TagType {
5587  friend class ASTContext; // ASTContext creates these.
5588 
5589  explicit EnumType(const EnumDecl *D)
5590  : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5591 
5592 public:
5593  EnumDecl *getDecl() const {
5594  return reinterpret_cast<EnumDecl*>(TagType::getDecl());
5595  }
5596 
5597  bool isSugared() const { return false; }
5598  QualType desugar() const { return QualType(this, 0); }
5599 
5600  static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
5601 };
5602 
5603 /// An attributed type is a type to which a type attribute has been applied.
5604 ///
5605 /// The "modified type" is the fully-sugared type to which the attributed
5606 /// type was applied; generally it is not canonically equivalent to the
5607 /// attributed type. The "equivalent type" is the minimally-desugared type
5608 /// which the type is canonically equivalent to.
5609 ///
5610 /// For example, in the following attributed type:
5611 /// int32_t __attribute__((vector_size(16)))
5612 /// - the modified type is the TypedefType for int32_t
5613 /// - the equivalent type is VectorType(16, int32_t)
5614 /// - the canonical type is VectorType(16, int)
5615 class AttributedType : public Type, public llvm::FoldingSetNode {
5616 public:
5617  using Kind = attr::Kind;
5618 
5619 private:
5620  friend class ASTContext; // ASTContext creates these
5621 
5622  QualType ModifiedType;
5623  QualType EquivalentType;
5624 
5625  AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
5626  QualType equivalent)
5627  : Type(Attributed, canon, equivalent->getDependence()),
5628  ModifiedType(modified), EquivalentType(equivalent) {
5629  AttributedTypeBits.AttrKind = attrKind;
5630  }
5631 
5632 public:
5633  Kind getAttrKind() const {
5634  return static_cast<Kind>(AttributedTypeBits.AttrKind);
5635  }
5636 
5637  QualType getModifiedType() const { return ModifiedType; }
5638  QualType getEquivalentType() const { return EquivalentType; }
5639 
5640  bool isSugared() const { return true; }
5641  QualType desugar() const { return getEquivalentType(); }
5642 
5643  /// Does this attribute behave like a type qualifier?
5644  ///
5645  /// A type qualifier adjusts a type to provide specialized rules for
5646  /// a specific object, like the standard const and volatile qualifiers.
5647  /// This includes attributes controlling things like nullability,
5648  /// address spaces, and ARC ownership. The value of the object is still
5649  /// largely described by the modified type.
5650  ///
5651  /// In contrast, many type attributes "rewrite" their modified type to
5652  /// produce a fundamentally different type, not necessarily related in any
5653  /// formalizable way to the original type. For example, calling convention
5654  /// and vector attributes are not simple type qualifiers.
5655  ///
5656  /// Type qualifiers are often, but not always, reflected in the canonical
5657  /// type.
5658  bool isQualifier() const;
5659 
5660  bool isMSTypeSpec() const;
5661 
5662  bool isWebAssemblyFuncrefSpec() const;
5663 
5664  bool isCallingConv() const;
5665 
5666  std::optional<NullabilityKind> getImmediateNullability() const;
5667 
5668  /// Retrieve the attribute kind corresponding to the given
5669  /// nullability kind.
5671  switch (kind) {
5673  return attr::TypeNonNull;
5674 
5676  return attr::TypeNullable;
5677 
5679  return attr::TypeNullableResult;
5680 
5682  return attr::TypeNullUnspecified;
5683  }
5684  llvm_unreachable("Unknown nullability kind.");
5685  }
5686 
5687  /// Strip off the top-level nullability annotation on the given
5688  /// type, if it's there.
5689  ///
5690  /// \param T The type to strip. If the type is exactly an
5691  /// AttributedType specifying nullability (without looking through
5692  /// type sugar), the nullability is returned and this type changed
5693  /// to the underlying modified type.
5694  ///
5695  /// \returns the top-level nullability, if present.
5696  static std::optional<NullabilityKind> stripOuterNullability(QualType &T);
5697 
5698  void Profile(llvm::FoldingSetNodeID &ID) {
5699  Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
5700  }
5701 
5702  static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
5703  QualType modified, QualType equivalent) {
5704  ID.AddInteger(attrKind);
5705  ID.AddPointer(modified.getAsOpaquePtr());
5706  ID.AddPointer(equivalent.getAsOpaquePtr());
5707  }
5708 
5709  static bool classof(const Type *T) {
5710  return T->getTypeClass() == Attributed;
5711  }
5712 };
5713 
5714 class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
5715 private:
5716  friend class ASTContext; // ASTContext creates these
5717 
5718  QualType WrappedType;
5719  const BTFTypeTagAttr *BTFAttr;
5720 
5721  BTFTagAttributedType(QualType Canon, QualType Wrapped,
5722  const BTFTypeTagAttr *BTFAttr)
5723  : Type(BTFTagAttributed, Canon, Wrapped->getDependence()),
5724  WrappedType(Wrapped), BTFAttr(BTFAttr) {}
5725 
5726 public:
5727  QualType getWrappedType() const { return WrappedType; }
5728  const BTFTypeTagAttr *getAttr() const { return BTFAttr; }
5729 
5730  bool isSugared() const { return true; }
5731  QualType desugar() const { return getWrappedType(); }
5732 
5733  void Profile(llvm::FoldingSetNodeID &ID) {
5734  Profile(ID, WrappedType, BTFAttr);
5735  }
5736 
5737  static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
5738  const BTFTypeTagAttr *BTFAttr) {
5739  ID.AddPointer(Wrapped.getAsOpaquePtr());
5740  ID.AddPointer(BTFAttr);
5741  }
5742 
5743  static bool classof(const Type *T) {
5744  return T->getTypeClass() == BTFTagAttributed;
5745  }
5746 };
5747 
5748 class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
5749  friend class ASTContext; // ASTContext creates these
5750 
5751  // Helper data collector for canonical types.
5752  struct CanonicalTTPTInfo {
5753  unsigned Depth : 15;
5754  unsigned ParameterPack : 1;
5755  unsigned Index : 16;
5756  };
5757 
5758  union {
5759  // Info for the canonical type.
5760  CanonicalTTPTInfo CanTTPTInfo;
5761 
5762  // Info for the non-canonical type.
5764  };
5765 
5766  /// Build a non-canonical type.
5768  : Type(TemplateTypeParm, Canon,
5769  TypeDependence::DependentInstantiation |
5770  (Canon->getDependence() & TypeDependence::UnexpandedPack)),
5771  TTPDecl(TTPDecl) {}
5772 
5773  /// Build the canonical type.
5774  TemplateTypeParmType(unsigned D, unsigned I, bool PP)
5775  : Type(TemplateTypeParm, QualType(this, 0),
5776  TypeDependence::DependentInstantiation |
5777  (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)) {
5778  CanTTPTInfo.Depth = D;
5779  CanTTPTInfo.Index = I;
5780  CanTTPTInfo.ParameterPack = PP;
5781  }
5782 
5783  const CanonicalTTPTInfo& getCanTTPTInfo() const {
5784  QualType Can = getCanonicalTypeInternal();
5785  return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
5786  }
5787 
5788 public:
5789  unsigned getDepth() const { return getCanTTPTInfo().Depth; }
5790  unsigned getIndex() const { return getCanTTPTInfo().Index; }
5791  bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
5792 
5794  return isCanonicalUnqualified() ? nullptr : TTPDecl;
5795  }
5796 
5797  IdentifierInfo *getIdentifier() const;
5798 
5799  bool isSugared() const { return false; }
5800  QualType desugar() const { return QualType(this, 0); }
5801 
5802  void Profile(llvm::FoldingSetNodeID &ID) {
5803  Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
5804  }
5805 
5806  static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
5807  unsigned Index, bool ParameterPack,
5808  TemplateTypeParmDecl *TTPDecl) {
5809  ID.AddInteger(Depth);
5810  ID.AddInteger(Index);
5811  ID.AddBoolean(ParameterPack);
5812  ID.AddPointer(TTPDecl);
5813  }
5814 
5815  static bool classof(const Type *T) {
5816  return T->getTypeClass() == TemplateTypeParm;
5817  }
5818 };
5819 
5820 /// Represents the result of substituting a type for a template
5821 /// type parameter.
5822 ///
5823 /// Within an instantiated template, all template type parameters have
5824 /// been replaced with these. They are used solely to record that a
5825 /// type was originally written as a template type parameter;
5826 /// therefore they are never canonical.
5828  : public Type,
5829  public llvm::FoldingSetNode,
5830  private llvm::TrailingObjects<SubstTemplateTypeParmType, QualType> {
5831  friend class ASTContext;
5832  friend class llvm::TrailingObjects<SubstTemplateTypeParmType, QualType>;
5833 
5834  Decl *AssociatedDecl;
5835 
5836  SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
5837  unsigned Index, std::optional<unsigned> PackIndex);
5838 
5839 public:
5840  /// Gets the type that was substituted for the template
5841  /// parameter.
5843  return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
5844  ? *getTrailingObjects<QualType>()
5845  : getCanonicalTypeInternal();
5846  }
5847 
5848  /// A template-like entity which owns the whole pattern being substituted.
5849  /// This will usually own a set of template parameters, or in some
5850  /// cases might even be a template parameter itself.
5851  Decl *getAssociatedDecl() const { return AssociatedDecl; }
5852 
5853  /// Gets the template parameter declaration that was substituted for.
5855 
5856  /// Returns the index of the replaced parameter in the associated declaration.
5857  /// This should match the result of `getReplacedParameter()->getIndex()`.
5858  unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
5859 
5860  std::optional<unsigned> getPackIndex() const {
5861  if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
5862  return std::nullopt;
5863  return SubstTemplateTypeParmTypeBits.PackIndex - 1;
5864  }
5865 
5866  bool isSugared() const { return true; }
5867  QualType desugar() const { return getReplacementType(); }
5868 
5869  void Profile(llvm::FoldingSetNodeID &ID) {
5870  Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
5871  getPackIndex());
5872  }
5873 
5874  static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
5875  const Decl *AssociatedDecl, unsigned Index,
5876  std::optional<unsigned> PackIndex) {
5877  Replacement.Profile(ID);
5878  ID.AddPointer(AssociatedDecl);
5879  ID.AddInteger(Index);
5880  ID.AddInteger(PackIndex ? *PackIndex - 1 : 0);
5881  }
5882 
5883  static bool classof(const Type *T) {
5884  return T->getTypeClass() == SubstTemplateTypeParm;
5885  }
5886 };
5887 
5888 /// Represents the result of substituting a set of types for a template
5889 /// type parameter pack.
5890 ///
5891 /// When a pack expansion in the source code contains multiple parameter packs
5892 /// and those parameter packs correspond to different levels of template
5893 /// parameter lists, this type node is used to represent a template type
5894 /// parameter pack from an outer level, which has already had its argument pack
5895 /// substituted but that still lives within a pack expansion that itself
5896 /// could not be instantiated. When actually performing a substitution into
5897 /// that pack expansion (e.g., when all template parameters have corresponding
5898 /// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
5899 /// at the current pack substitution index.
5900 class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
5901  friend class ASTContext;
5902 
5903  /// A pointer to the set of template arguments that this
5904  /// parameter pack is instantiated with.
5905  const TemplateArgument *Arguments;
5906 
5907  llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
5908 
5909  SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
5910  unsigned Index, bool Final,
5911  const TemplateArgument &ArgPack);
5912 
5913 public:
5914  IdentifierInfo *getIdentifier() const;
5915 
5916  /// A template-like entity which owns the whole pattern being substituted.
5917  /// This will usually own a set of template parameters, or in some
5918  /// cases might even be a template parameter itself.
5919  Decl *getAssociatedDecl() const;
5920 
5921  /// Gets the template parameter declaration that was substituted for.
5923 
5924  /// Returns the index of the replaced parameter in the associated declaration.
5925  /// This should match the result of `getReplacedParameter()->getIndex()`.
5926  unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
5927 
5928  // When true the substitution will be 'Final' (subst node won't be placed).
5929  bool getFinal() const;
5930 
5931  unsigned getNumArgs() const {
5932  return SubstTemplateTypeParmPackTypeBits.NumArgs;
5933  }
5934 
5935  bool isSugared() const { return false; }
5936  QualType desugar() const { return QualType(this, 0); }
5937 
5938  TemplateArgument getArgumentPack() const;
5939 
5940  void Profile(llvm::FoldingSetNodeID &ID);
5941  static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
5942  unsigned Index, bool Final,
5943  const TemplateArgument &ArgPack);
5944 
5945  static bool classof(const Type *T) {
5946  return T->getTypeClass() == SubstTemplateTypeParmPack;
5947  }
5948 };
5949 
5950 /// Common base class for placeholders for types that get replaced by
5951 /// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
5952 /// class template types, and constrained type names.
5953 ///
5954 /// These types are usually a placeholder for a deduced type. However, before
5955 /// the initializer is attached, or (usually) if the initializer is
5956 /// type-dependent, there is no deduced type and the type is canonical. In
5957 /// the latter case, it is also a dependent type.
5958 class DeducedType : public Type {
5959  QualType DeducedAsType;
5960 
5961 protected:
5962  DeducedType(TypeClass TC, QualType DeducedAsType,
5963  TypeDependence ExtraDependence, QualType Canon)
5964  : Type(TC, Canon,
5965  ExtraDependence | (DeducedAsType.isNull()
5966  ? TypeDependence::None
5967  : DeducedAsType->getDependence() &
5968  ~TypeDependence::VariablyModified)),
5969  DeducedAsType(DeducedAsType) {}
5970 
5971 public:
5972  bool isSugared() const { return !DeducedAsType.isNull(); }
5973  QualType desugar() const {
5974  return isSugared() ? DeducedAsType : QualType(this, 0);
5975  }
5976 
5977  /// Get the type deduced for this placeholder type, or null if it
5978  /// has not been deduced.
5979  QualType getDeducedType() const { return DeducedAsType; }
5980  bool isDeduced() const {
5981  return !DeducedAsType.isNull() || isDependentType();
5982  }
5983 
5984  static bool classof(const Type *T) {
5985  return T->getTypeClass() == Auto ||
5986  T->getTypeClass() == DeducedTemplateSpecialization;
5987  }
5988 };
5989 
5990 /// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
5991 /// by a type-constraint.
5992 class AutoType : public DeducedType, public llvm::FoldingSetNode {
5993  friend class ASTContext; // ASTContext creates these
5994 
5995  ConceptDecl *TypeConstraintConcept;
5996 
5997  AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
5998  TypeDependence ExtraDependence, QualType Canon, ConceptDecl *CD,
5999  ArrayRef<TemplateArgument> TypeConstraintArgs);
6000 
6001 public:
6003  return {reinterpret_cast<const TemplateArgument *>(this + 1),
6004  AutoTypeBits.NumArgs};
6005  }
6006 
6008  return TypeConstraintConcept;
6009  }
6010 
6011  bool isConstrained() const {
6012  return TypeConstraintConcept != nullptr;
6013  }
6014 
6015  bool isDecltypeAuto() const {
6016  return getKeyword() == AutoTypeKeyword::DecltypeAuto;
6017  }
6018 
6019  bool isGNUAutoType() const {
6020  return getKeyword() == AutoTypeKeyword::GNUAutoType;
6021  }
6022 
6024  return (AutoTypeKeyword)AutoTypeBits.Keyword;
6025  }
6026 
6027  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
6028  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6029  QualType Deduced, AutoTypeKeyword Keyword,
6030  bool IsDependent, ConceptDecl *CD,
6031  ArrayRef<TemplateArgument> Arguments);
6032 
6033  static bool classof(const Type *T) {
6034  return T->getTypeClass() == Auto;
6035  }
6036 };
6037 
6038 /// Represents a C++17 deduced template specialization type.
6040  public llvm::FoldingSetNode {
6041  friend class ASTContext; // ASTContext creates these
6042 
6043  /// The name of the template whose arguments will be deduced.
6044  TemplateName Template;
6045 
6047  QualType DeducedAsType,
6048  bool IsDeducedAsDependent)
6049  : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
6050  toTypeDependence(Template.getDependence()) |
6051  (IsDeducedAsDependent
6052  ? TypeDependence::DependentInstantiation
6053  : TypeDependence::None),
6054  DeducedAsType.isNull() ? QualType(this, 0)
6055  : DeducedAsType.getCanonicalType()),
6056  Template(Template) {}
6057 
6058 public:
6059  /// Retrieve the name of the template that we are deducing.
6060  TemplateName getTemplateName() const { return Template;}
6061 
6062  void Profile(llvm::FoldingSetNodeID &ID) {
6063  Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
6064  }
6065 
6066  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
6067  QualType Deduced, bool IsDependent) {
6068  Template.Profile(ID);
6069  QualType CanonicalType =
6070  Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
6071  ID.AddPointer(CanonicalType.getAsOpaquePtr());
6072  ID.AddBoolean(IsDependent || Template.isDependent());
6073  }
6074 
6075  static bool classof(const Type *T) {
6076  return T->getTypeClass() == DeducedTemplateSpecialization;
6077  }
6078 };
6079 
6080 /// Represents a type template specialization; the template
6081 /// must be a class template, a type alias template, or a template
6082 /// template parameter. A template which cannot be resolved to one of
6083 /// these, e.g. because it is written with a dependent scope
6084 /// specifier, is instead represented as a
6085 /// @c DependentTemplateSpecializationType.
6086 ///
6087 /// A non-dependent template specialization type is always "sugar",
6088 /// typically for a \c RecordType. For example, a class template
6089 /// specialization type of \c vector<int> will refer to a tag type for
6090 /// the instantiation \c std::vector<int, std::allocator<int>>
6091 ///
6092 /// Template specializations are dependent if either the template or
6093 /// any of the template arguments are dependent, in which case the
6094 /// type may also be canonical.
6095 ///
6096 /// Instances of this type are allocated with a trailing array of
6097 /// TemplateArguments, followed by a QualType representing the
6098 /// non-canonical aliased type when the template is a type alias
6099 /// template.
6100 class TemplateSpecializationType : public Type, public llvm::FoldingSetNode {
6101  friend class ASTContext; // ASTContext creates these
6102 
6103  /// The name of the template being specialized. This is
6104  /// either a TemplateName::Template (in which case it is a
6105  /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
6106  /// TypeAliasTemplateDecl*), a
6107  /// TemplateName::SubstTemplateTemplateParmPack, or a
6108  /// TemplateName::SubstTemplateTemplateParm (in which case the
6109  /// replacement must, recursively, be one of these).
6110  TemplateName Template;
6111 
6114  QualType Canon,
6115  QualType Aliased);
6116 
6117 public:
6118  /// Determine whether any of the given template arguments are dependent.
6119  ///
6120  /// The converted arguments should be supplied when known; whether an
6121  /// argument is dependent can depend on the conversions performed on it
6122  /// (for example, a 'const int' passed as a template argument might be
6123  /// dependent if the parameter is a reference but non-dependent if the
6124  /// parameter is an int).
6125  ///
6126  /// Note that the \p Args parameter is unused: this is intentional, to remind
6127  /// the caller that they need to pass in the converted arguments, not the
6128  /// specified arguments.
6129  static bool
6130  anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
6131  ArrayRef<TemplateArgument> Converted);
6132  static bool
6133  anyDependentTemplateArguments(const TemplateArgumentListInfo &,
6134  ArrayRef<TemplateArgument> Converted);
6135  static bool anyInstantiationDependentTemplateArguments(
6137 
6138  /// True if this template specialization type matches a current
6139  /// instantiation in the context in which it is found.
6140  bool isCurrentInstantiation() const {
6141  return isa<InjectedClassNameType>(getCanonicalTypeInternal());
6142  }
6143 
6144  /// Determine if this template specialization type is for a type alias
6145  /// template that has been substituted.
6146  ///
6147  /// Nearly every template specialization type whose template is an alias
6148  /// template will be substituted. However, this is not the case when
6149  /// the specialization contains a pack expansion but the template alias
6150  /// does not have a corresponding parameter pack, e.g.,
6151  ///
6152  /// \code
6153  /// template<typename T, typename U, typename V> struct S;
6154  /// template<typename T, typename U> using A = S<T, int, U>;
6155  /// template<typename... Ts> struct X {
6156  /// typedef A<Ts...> type; // not a type alias
6157  /// };
6158  /// \endcode
6159  bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
6160 
6161  /// Get the aliased type, if this is a specialization of a type alias
6162  /// template.
6163  QualType getAliasedType() const;
6164 
6165  /// Retrieve the name of the template that we are specializing.
6166  TemplateName getTemplateName() const { return Template; }
6167 
6169  return {reinterpret_cast<const TemplateArgument *>(this + 1),
6170  TemplateSpecializationTypeBits.NumArgs};
6171  }
6172 
6173  bool isSugared() const {
6174  return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
6175  }
6176 
6177  QualType desugar() const {
6178  return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
6179  }
6180 
6181  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
6182  static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
6184  const ASTContext &Context);
6185 
6186  static bool classof(const Type *T) {
6187  return T->getTypeClass() == TemplateSpecialization;
6188  }
6189 };
6190 
6191 /// Print a template argument list, including the '<' and '>'
6192 /// enclosing the template arguments.
6193 void printTemplateArgumentList(raw_ostream &OS,
6194  ArrayRef<TemplateArgument> Args,
6195  const PrintingPolicy &Policy,
6196  const TemplateParameterList *TPL = nullptr);
6197 
6198 void printTemplateArgumentList(raw_ostream &OS,
6199  ArrayRef<TemplateArgumentLoc> Args,
6200  const PrintingPolicy &Policy,
6201  const TemplateParameterList *TPL = nullptr);
6202 
6203 void printTemplateArgumentList(raw_ostream &OS,
6204  const TemplateArgumentListInfo &Args,
6205  const PrintingPolicy &Policy,
6206  const TemplateParameterList *TPL = nullptr);
6207 
6208 /// Make a best-effort determination of whether the type T can be produced by
6209 /// substituting Args into the default argument of Param.
6210 bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
6211  const NamedDecl *Param,
6212  ArrayRef<TemplateArgument> Args,
6213  unsigned Depth);
6214 
6215 /// The injected class name of a C++ class template or class
6216 /// template partial specialization. Used to record that a type was
6217 /// spelled with a bare identifier rather than as a template-id; the
6218 /// equivalent for non-templated classes is just RecordType.
6219 ///
6220 /// Injected class name types are always dependent. Template
6221 /// instantiation turns these into RecordTypes.
6222 ///
6223 /// Injected class name types are always canonical. This works
6224 /// because it is impossible to compare an injected class name type
6225 /// with the corresponding non-injected template type, for the same
6226 /// reason that it is impossible to directly compare template
6227 /// parameters from different dependent contexts: injected class name
6228 /// types can only occur within the scope of a particular templated
6229 /// declaration, and within that scope every template specialization
6230 /// will canonicalize to the injected class name (when appropriate
6231 /// according to the rules of the language).
6232 class InjectedClassNameType : public Type {
6233  friend class ASTContext; // ASTContext creates these.
6234  friend class ASTNodeImporter;
6235  friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
6236  // currently suitable for AST reading, too much
6237  // interdependencies.
6238  template <class T> friend class serialization::AbstractTypeReader;
6239 
6241 
6242  /// The template specialization which this type represents.
6243  /// For example, in
6244  /// template <class T> class A { ... };
6245  /// this is A<T>, whereas in
6246  /// template <class X, class Y> class A<B<X,Y> > { ... };
6247  /// this is A<B<X,Y> >.
6248  ///
6249  /// It is always unqualified, always a template specialization type,
6250  /// and always dependent.
6251  QualType InjectedType;
6252 
6254  : Type(InjectedClassName, QualType(),
6255  TypeDependence::DependentInstantiation),
6256  Decl(D), InjectedType(TST) {
6257  assert(isa<TemplateSpecializationType>(TST));
6258  assert(!TST.hasQualifiers());
6259  assert(TST->isDependentType());
6260  }
6261 
6262 public:
6263  QualType getInjectedSpecializationType() const { return InjectedType; }
6264 
6266  return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
6267  }
6268 
6270  return getInjectedTST()->getTemplateName();
6271  }
6272 
6273  CXXRecordDecl *getDecl() const;
6274 
6275  bool isSugared() const { return false; }
6276  QualType desugar() const { return QualType(this, 0); }
6277 
6278  static bool classof(const Type *T) {
6279  return T->getTypeClass() == InjectedClassName;
6280  }
6281 };
6282 
6283 /// The elaboration keyword that precedes a qualified type name or
6284 /// introduces an elaborated-type-specifier.
6286  /// The "struct" keyword introduces the elaborated-type-specifier.
6287  Struct,
6288 
6289  /// The "__interface" keyword introduces the elaborated-type-specifier.
6290  Interface,
6291 
6292  /// The "union" keyword introduces the elaborated-type-specifier.
6293  Union,
6294 
6295  /// The "class" keyword introduces the elaborated-type-specifier.
6296  Class,
6297 
6298  /// The "enum" keyword introduces the elaborated-type-specifier.
6299  Enum,
6300 
6301  /// The "typename" keyword precedes the qualified type name, e.g.,
6302  /// \c typename T::type.
6303  Typename,
6304 
6305  /// No keyword precedes the qualified type name.
6306  None
6307 };
6308 
6309 /// The kind of a tag type.
6310 enum class TagTypeKind {
6311  /// The "struct" keyword.
6312  Struct,
6313 
6314  /// The "__interface" keyword.
6315  Interface,
6316 
6317  /// The "union" keyword.
6318  Union,
6319 
6320  /// The "class" keyword.
6321  Class,
6322 
6323  /// The "enum" keyword.
6324  Enum
6325 };
6326 
6327 /// A helper class for Type nodes having an ElaboratedTypeKeyword.
6328 /// The keyword in stored in the free bits of the base class.
6329 /// Also provides a few static helpers for converting and printing
6330 /// elaborated type keyword and tag type kind enumerations.
6331 class TypeWithKeyword : public Type {
6332 protected:
6334  QualType Canonical, TypeDependence Dependence)
6335  : Type(tc, Canonical, Dependence) {
6336  TypeWithKeywordBits.Keyword = llvm::to_underlying(Keyword);
6337  }
6338 
6339 public:
6341  return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
6342  }
6343 
6344  /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
6345  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
6346 
6347  /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
6348  /// It is an error to provide a type specifier which *isn't* a tag kind here.
6349  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
6350 
6351  /// Converts a TagTypeKind into an elaborated type keyword.
6352  static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
6353 
6354  /// Converts an elaborated type keyword into a TagTypeKind.
6355  /// It is an error to provide an elaborated type keyword
6356  /// which *isn't* a tag kind here.
6357  static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
6358 
6359  static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
6360 
6361  static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
6362 
6364  return getKeywordName(getKeywordForTagTypeKind(Kind));
6365  }
6366 
6369 };
6370 
6371 /// Represents a type that was referred to using an elaborated type
6372 /// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
6373 /// or both.
6374 ///
6375 /// This type is used to keep track of a type name as written in the
6376 /// source code, including tag keywords and any nested-name-specifiers.
6377 /// The type itself is always "sugar", used to express what was written
6378 /// in the source code but containing no additional semantic information.
6379 class ElaboratedType final
6380  : public TypeWithKeyword,
6381  public llvm::FoldingSetNode,
6382  private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
6383  friend class ASTContext; // ASTContext creates these
6384  friend TrailingObjects;
6385 
6386  /// The nested name specifier containing the qualifier.
6387  NestedNameSpecifier *NNS;
6388 
6389  /// The type that this qualified name refers to.
6390  QualType NamedType;
6391 
6392  /// The (re)declaration of this tag type owned by this occurrence is stored
6393  /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
6394  /// it, or obtain a null pointer if there is none.
6395 
6397  QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
6398  : TypeWithKeyword(Keyword, Elaborated, CanonType,
6399  // Any semantic dependence on the qualifier will have
6400  // been incorporated into NamedType. We still need to
6401  // track syntactic (instantiation / error / pack)
6402  // dependence on the qualifier.
6403  NamedType->getDependence() |
6404  (NNS ? toSyntacticDependence(
6405  toTypeDependence(NNS->getDependence()))
6406  : TypeDependence::None)),
6407  NNS(NNS), NamedType(NamedType) {
6408  ElaboratedTypeBits.HasOwnedTagDecl = false;
6409  if (OwnedTagDecl) {
6410  ElaboratedTypeBits.HasOwnedTagDecl = true;
6411  *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
6412  }
6413  }
6414 
6415 public:
6416  /// Retrieve the qualification on this type.
6417  NestedNameSpecifier *getQualifier() const { return NNS; }
6418 
6419  /// Retrieve the type named by the qualified-id.
6420  QualType getNamedType() const { return NamedType; }
6421 
6422  /// Remove a single level of sugar.
6423  QualType desugar() const { return getNamedType(); }
6424 
6425  /// Returns whether this type directly provides sugar.
6426  bool isSugared() const { return true; }
6427 
6428  /// Return the (re)declaration of this type owned by this occurrence of this
6429  /// type, or nullptr if there is none.
6431  return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
6432  : nullptr;
6433  }
6434 
6435  void Profile(llvm::FoldingSetNodeID &ID) {
6436  Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
6437  }
6438 
6439  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6440  NestedNameSpecifier *NNS, QualType NamedType,
6441  TagDecl *OwnedTagDecl) {
6442  ID.AddInteger(llvm::to_underlying(Keyword));
6443  ID.AddPointer(NNS);
6444  NamedType.Profile(ID);
6445  ID.AddPointer(OwnedTagDecl);
6446  }
6447 
6448  static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
6449 };
6450 
6451 /// Represents a qualified type name for which the type name is
6452 /// dependent.
6453 ///
6454 /// DependentNameType represents a class of dependent types that involve a
6455 /// possibly dependent nested-name-specifier (e.g., "T::") followed by a
6456 /// name of a type. The DependentNameType may start with a "typename" (for a
6457 /// typename-specifier), "class", "struct", "union", or "enum" (for a
6458 /// dependent elaborated-type-specifier), or nothing (in contexts where we
6459 /// know that we must be referring to a type, e.g., in a base class specifier).
6460 /// Typically the nested-name-specifier is dependent, but in MSVC compatibility
6461 /// mode, this type is used with non-dependent names to delay name lookup until
6462 /// instantiation.
6463 class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
6464  friend class ASTContext; // ASTContext creates these
6465 
6466  /// The nested name specifier containing the qualifier.
6467  NestedNameSpecifier *NNS;
6468 
6469  /// The type that this typename specifier refers to.
6470  const IdentifierInfo *Name;
6471 
6473  const IdentifierInfo *Name, QualType CanonType)
6474  : TypeWithKeyword(Keyword, DependentName, CanonType,
6475  TypeDependence::DependentInstantiation |
6476  toTypeDependence(NNS->getDependence())),
6477  NNS(NNS), Name(Name) {}
6478 
6479 public:
6480  /// Retrieve the qualification on this type.
6481  NestedNameSpecifier *getQualifier() const { return NNS; }
6482 
6483  /// Retrieve the type named by the typename specifier as an identifier.
6484  ///
6485  /// This routine will return a non-NULL identifier pointer when the
6486  /// form of the original typename was terminated by an identifier,
6487  /// e.g., "typename T::type".
6489  return Name;
6490  }
6491 
6492  bool isSugared() const { return false; }
6493  QualType desugar() const { return QualType(this, 0); }
6494 
6495  void Profile(llvm::FoldingSetNodeID &ID) {
6496  Profile(ID, getKeyword(), NNS, Name);
6497  }
6498 
6499  static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6500  NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
6501  ID.AddInteger(llvm::to_underlying(Keyword));
6502  ID.AddPointer(NNS);
6503  ID.AddPointer(Name);
6504  }
6505 
6506  static bool classof(const Type *T) {
6507  return T->getTypeClass() == DependentName;
6508  }
6509 };
6510 
6511 /// Represents a template specialization type whose template cannot be
6512 /// resolved, e.g.
6513 /// A<T>::template B<T>
6515  public llvm::FoldingSetNode {
6516  friend class ASTContext; // ASTContext creates these
6517 
6518  /// The nested name specifier containing the qualifier.
6519  NestedNameSpecifier *NNS;
6520 
6521  /// The identifier of the template.
6522  const IdentifierInfo *Name;
6523 
6525  NestedNameSpecifier *NNS,
6526  const IdentifierInfo *Name,
6528  QualType Canon);
6529 
6530 public:
6531  NestedNameSpecifier *getQualifier() const { return NNS; }
6532  const IdentifierInfo *getIdentifier() const { return Name; }
6533 
6535  return {reinterpret_cast<const TemplateArgument *>(this + 1),
6536  DependentTemplateSpecializationTypeBits.NumArgs};
6537  }
6538 
6539  bool isSugared() const { return false; }
6540  QualType desugar() const { return QualType(this, 0); }
6541 
6542  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6543  Profile(ID, Context, getKeyword(), NNS, Name, template_arguments());
6544  }
6545 
6546  static void Profile(llvm::FoldingSetNodeID &ID,
6547  const ASTContext &Context,
6548  ElaboratedTypeKeyword Keyword,
6549  NestedNameSpecifier *Qualifier,
6550  const IdentifierInfo *Name,
6552 
6553  static bool classof(const Type *T) {
6554  return T->getTypeClass() == DependentTemplateSpecialization;
6555  }
6556 };
6557 
6558 /// Represents a pack expansion of types.
6559 ///
6560 /// Pack expansions are part of C++11 variadic templates. A pack
6561 /// expansion contains a pattern, which itself contains one or more
6562 /// "unexpanded" parameter packs. When instantiated, a pack expansion
6563 /// produces a series of types, each instantiated from the pattern of
6564 /// the expansion, where the Ith instantiation of the pattern uses the
6565 /// Ith arguments bound to each of the unexpanded parameter packs. The
6566 /// pack expansion is considered to "expand" these unexpanded
6567 /// parameter packs.
6568 ///
6569 /// \code
6570 /// template<typename ...Types> struct tuple;
6571 ///
6572 /// template<typename ...Types>
6573 /// struct tuple_of_references {
6574 /// typedef tuple<Types&...> type;
6575 /// };
6576 /// \endcode
6577 ///
6578 /// Here, the pack expansion \c Types&... is represented via a
6579 /// PackExpansionType whose pattern is Types&.
6580 class PackExpansionType : public Type, public llvm::FoldingSetNode {
6581  friend class ASTContext; // ASTContext creates these
6582 
6583  /// The pattern of the pack expansion.
6584  QualType Pattern;
6585 
6586  PackExpansionType(QualType Pattern, QualType Canon,
6587  std::optional<unsigned> NumExpansions)
6588  : Type(PackExpansion, Canon,
6589  (Pattern->getDependence() | TypeDependence::Dependent |
6590  TypeDependence::Instantiation) &
6591  ~TypeDependence::UnexpandedPack),
6592  Pattern(Pattern) {
6593  PackExpansionTypeBits.NumExpansions =
6594  NumExpansions ? *NumExpansions + 1 : 0;
6595  }
6596 
6597 public:
6598  /// Retrieve the pattern of this pack expansion, which is the
6599  /// type that will be repeatedly instantiated when instantiating the
6600  /// pack expansion itself.
6601  QualType getPattern() const { return Pattern; }
6602 
6603  /// Retrieve the number of expansions that this pack expansion will
6604  /// generate, if known.
6605  std::optional<unsigned> getNumExpansions() const {
6606  if (PackExpansionTypeBits.NumExpansions)
6607  return PackExpansionTypeBits.NumExpansions - 1;
6608  return std::nullopt;
6609  }
6610 
6611  bool isSugared() const { return false; }
6612  QualType desugar() const { return QualType(this, 0); }
6613 
6614  void Profile(llvm::FoldingSetNodeID &ID) {
6615  Profile(ID, getPattern(), getNumExpansions());
6616  }
6617 
6618  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
6619  std::optional<unsigned> NumExpansions) {
6620  ID.AddPointer(Pattern.getAsOpaquePtr());
6621  ID.AddBoolean(NumExpansions.has_value());
6622  if (NumExpansions)
6623  ID.AddInteger(*NumExpansions);
6624  }
6625 
6626  static bool classof(const Type *T) {
6627  return T->getTypeClass() == PackExpansion;
6628  }
6629 };
6630 
6631 /// This class wraps the list of protocol qualifiers. For types that can
6632 /// take ObjC protocol qualifers, they can subclass this class.
6633 template <class T>
6635 protected:
6637 
6639  return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
6640  }
6641 
6643  return static_cast<T*>(this)->getProtocolStorageImpl();
6644  }
6645 
6646  void setNumProtocols(unsigned N) {
6647  static_cast<T*>(this)->setNumProtocolsImpl(N);
6648  }
6649 
6651  setNumProtocols(protocols.size());
6652  assert(getNumProtocols() == protocols.size() &&
6653  "bitfield overflow in protocol count");
6654  if (!protocols.empty())
6655  memcpy(getProtocolStorage(), protocols.data(),
6656  protocols.size() * sizeof(ObjCProtocolDecl*));
6657  }
6658 
6659 public:
6660  using qual_iterator = ObjCProtocolDecl * const *;
6661  using qual_range = llvm::iterator_range<qual_iterator>;
6662 
6663  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
6664  qual_iterator qual_begin() const { return getProtocolStorage(); }
6665  qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
6666 
6667  bool qual_empty() const { return getNumProtocols() == 0; }
6668 
6669  /// Return the number of qualifying protocols in this type, or 0 if
6670  /// there are none.
6671  unsigned getNumProtocols() const {
6672  return static_cast<const T*>(this)->getNumProtocolsImpl();
6673  }
6674 
6675  /// Fetch a protocol by index.
6676  ObjCProtocolDecl *getProtocol(unsigned I) const {
6677  assert(I < getNumProtocols() && "Out-of-range protocol access");
6678  return qual_begin()[I];
6679  }
6680 
6681  /// Retrieve all of the protocol qualifiers.
6683  return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
6684  }
6685 };
6686 
6687 /// Represents a type parameter type in Objective C. It can take
6688 /// a list of protocols.
6689 class ObjCTypeParamType : public Type,
6690  public ObjCProtocolQualifiers<ObjCTypeParamType>,
6691  public llvm::FoldingSetNode {
6692  friend class ASTContext;
6694 
6695  /// The number of protocols stored on this type.
6696  unsigned NumProtocols : 6;
6697 
6698  ObjCTypeParamDecl *OTPDecl;
6699 
6700  /// The protocols are stored after the ObjCTypeParamType node. In the
6701  /// canonical type, the list of protocols are sorted alphabetically
6702  /// and uniqued.
6703  ObjCProtocolDecl **getProtocolStorageImpl();
6704 
6705  /// Return the number of qualifying protocols in this interface type,
6706  /// or 0 if there are none.
6707  unsigned getNumProtocolsImpl() const {
6708  return NumProtocols;
6709  }
6710 
6711  void setNumProtocolsImpl(unsigned N) {
6712  NumProtocols = N;
6713  }
6714 
6715  ObjCTypeParamType(const ObjCTypeParamDecl *D,
6716  QualType can,
6717  ArrayRef<ObjCProtocolDecl *> protocols);
6718 
6719 public:
6720  bool isSugared() const { return true; }
6721  QualType desugar() const { return getCanonicalTypeInternal(); }
6722 
6723  static bool classof(const Type *T) {
6724  return T->getTypeClass() == ObjCTypeParam;
6725  }
6726 
6727  void Profile(llvm::FoldingSetNodeID &ID);
6728  static void Profile(llvm::FoldingSetNodeID &ID,
6729  const ObjCTypeParamDecl *OTPDecl,
6730  QualType CanonicalType,
6731  ArrayRef<ObjCProtocolDecl *> protocols);
6732 
6733  ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
6734 };
6735 
6736 /// Represents a class type in Objective C.
6737 ///
6738 /// Every Objective C type is a combination of a base type, a set of
6739 /// type arguments (optional, for parameterized classes) and a list of
6740 /// protocols.
6741 ///
6742 /// Given the following declarations:
6743 /// \code
6744 /// \@class C<T>;
6745 /// \@protocol P;
6746 /// \endcode
6747 ///
6748 /// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
6749 /// with base C and no protocols.
6750 ///
6751 /// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
6752 /// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
6753 /// protocol list.
6754 /// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
6755 /// and protocol list [P].
6756 ///
6757 /// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
6758 /// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
6759 /// and no protocols.
6760 ///
6761 /// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
6762 /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
6763 /// this should get its own sugar class to better represent the source.
6764 class ObjCObjectType : public Type,
6765  public ObjCProtocolQualifiers<ObjCObjectType> {
6766  friend class ObjCProtocolQualifiers<ObjCObjectType>;
6767 
6768  // ObjCObjectType.NumTypeArgs - the number of type arguments stored
6769  // after the ObjCObjectPointerType node.
6770  // ObjCObjectType.NumProtocols - the number of protocols stored
6771  // after the type arguments of ObjCObjectPointerType node.
6772  //
6773  // These protocols are those written directly on the type. If
6774  // protocol qualifiers ever become additive, the iterators will need
6775  // to get kindof complicated.
6776  //
6777  // In the canonical object type, these are sorted alphabetically
6778  // and uniqued.
6779 
6780  /// Either a BuiltinType or an InterfaceType or sugar for either.
6781  QualType BaseType;
6782 
6783  /// Cached superclass type.
6784  mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
6785  CachedSuperClassType;
6786 
6787  QualType *getTypeArgStorage();
6788  const QualType *getTypeArgStorage() const {
6789  return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
6790  }
6791 
6792  ObjCProtocolDecl **getProtocolStorageImpl();
6793  /// Return the number of qualifying protocols in this interface type,
6794  /// or 0 if there are none.
6795  unsigned getNumProtocolsImpl() const {
6796  return ObjCObjectTypeBits.NumProtocols;
6797  }
6798  void setNumProtocolsImpl(unsigned N) {
6799  ObjCObjectTypeBits.NumProtocols = N;
6800  }
6801 
6802 protected:
6804 
6805  ObjCObjectType(QualType Canonical, QualType Base,
6806  ArrayRef<QualType> typeArgs,
6807  ArrayRef<ObjCProtocolDecl *> protocols,
6808  bool isKindOf);
6809 
6811  : Type(ObjCInterface, QualType(), TypeDependence::None),
6812  BaseType(QualType(this_(), 0)) {
6813  ObjCObjectTypeBits.NumProtocols = 0;
6814  ObjCObjectTypeBits.NumTypeArgs = 0;
6815  ObjCObjectTypeBits.IsKindOf = 0;
6816  }
6817 
6818  void computeSuperClassTypeSlow() const;
6819 
6820 public:
6821  /// Gets the base type of this object type. This is always (possibly
6822  /// sugar for) one of:
6823  /// - the 'id' builtin type (as opposed to the 'id' type visible to the
6824  /// user, which is a typedef for an ObjCObjectPointerType)
6825  /// - the 'Class' builtin type (same caveat)
6826  /// - an ObjCObjectType (currently always an ObjCInterfaceType)
6827  QualType getBaseType() const { return BaseType; }
6828 
6829  bool isObjCId() const {
6830  return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
6831  }
6832 
6833  bool isObjCClass() const {
6834  return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
6835  }
6836 
6837  bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
6838  bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
6840  if (!qual_empty()) return false;
6841  if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
6842  return T->getKind() == BuiltinType::ObjCId ||
6843  T->getKind() == BuiltinType::ObjCClass;
6844  return false;
6845  }
6846  bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
6847  bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
6848 
6849  /// Gets the interface declaration for this object type, if the base type
6850  /// really is an interface.
6851  ObjCInterfaceDecl *getInterface() const;
6852 
6853  /// Determine whether this object type is "specialized", meaning
6854  /// that it has type arguments.
6855  bool isSpecialized() const;
6856 
6857  /// Determine whether this object type was written with type arguments.
6858  bool isSpecializedAsWritten() const {
6859  return ObjCObjectTypeBits.NumTypeArgs > 0;
6860  }
6861 
6862  /// Determine whether this object type is "unspecialized", meaning
6863  /// that it has no type arguments.
6864  bool isUnspecialized() const { return !isSpecialized(); }
6865 
6866  /// Determine whether this object type is "unspecialized" as
6867  /// written, meaning that it has no type arguments.
6868  bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
6869 
6870  /// Retrieve the type arguments of this object type (semantically).
6871  ArrayRef<QualType> getTypeArgs() const;
6872 
6873  /// Retrieve the type arguments of this object type as they were
6874  /// written.
6876  return llvm::ArrayRef(getTypeArgStorage(), ObjCObjectTypeBits.NumTypeArgs);
6877  }
6878 
6879  /// Whether this is a "__kindof" type as written.
6880  bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
6881 
6882  /// Whether this ia a "__kindof" type (semantically).
6883  bool isKindOfType() const;
6884 
6885  /// Retrieve the type of the superclass of this object type.
6886  ///
6887  /// This operation substitutes any type arguments into the
6888  /// superclass of the current class type, potentially producing a
6889  /// specialization of the superclass type. Produces a null type if
6890  /// there is no superclass.
6892  if (!CachedSuperClassType.getInt())
6893  computeSuperClassTypeSlow();
6894 
6895  assert(CachedSuperClassType.getInt() && "Superclass not set?");
6896  return QualType(CachedSuperClassType.getPointer(), 0);
6897  }
6898 
6899  /// Strip off the Objective-C "kindof" type and (with it) any
6900  /// protocol qualifiers.
6901  QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
6902 
6903  bool isSugared() const { return false; }
6904  QualType desugar() const { return QualType(this, 0); }
6905 
6906  static bool classof(const Type *T) {
6907  return T->getTypeClass() == ObjCObject ||
6908  T->getTypeClass() == ObjCInterface;
6909  }
6910 };
6911 
6912 /// A class providing a concrete implementation
6913 /// of ObjCObjectType, so as to not increase the footprint of
6914 /// ObjCInterfaceType. Code outside of ASTContext and the core type
6915 /// system should not reference this type.
6916 class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
6917  friend class ASTContext;
6918 
6919  // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
6920  // will need to be modified.
6921 
6923  ArrayRef<QualType> typeArgs,
6924  ArrayRef<ObjCProtocolDecl *> protocols,
6925  bool isKindOf)
6926  : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
6927 
6928 public:
6929  void Profile(llvm::FoldingSetNodeID &ID);
6930  static void Profile(llvm::FoldingSetNodeID &ID,
6931  QualType Base,
6932  ArrayRef<QualType> typeArgs,
6933  ArrayRef<ObjCProtocolDecl *> protocols,
6934  bool isKindOf);
6935 };
6936 
6937 inline QualType *ObjCObjectType::getTypeArgStorage() {
6938  return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
6939 }
6940 
6941 inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
6942  return reinterpret_cast<ObjCProtocolDecl**>(
6943  getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
6944 }
6945 
6946 inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
6947  return reinterpret_cast<ObjCProtocolDecl**>(
6948  static_cast<ObjCTypeParamType*>(this)+1);
6949 }
6950 
6951 /// Interfaces are the core concept in Objective-C for object oriented design.
6952 /// They basically correspond to C++ classes. There are two kinds of interface
6953 /// types: normal interfaces like `NSString`, and qualified interfaces, which
6954 /// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
6955 ///
6956 /// ObjCInterfaceType guarantees the following properties when considered
6957 /// as a subtype of its superclass, ObjCObjectType:
6958 /// - There are no protocol qualifiers. To reinforce this, code which
6959 /// tries to invoke the protocol methods via an ObjCInterfaceType will
6960 /// fail to compile.
6961 /// - It is its own base type. That is, if T is an ObjCInterfaceType*,
6962 /// T->getBaseType() == QualType(T, 0).
6964  friend class ASTContext; // ASTContext creates these.
6965  friend class ASTReader;
6966  template <class T> friend class serialization::AbstractTypeReader;
6967 
6969 
6972  Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
6973 
6974 public:
6975  /// Get the declaration of this interface.
6976  ObjCInterfaceDecl *getDecl() const;
6977 
6978  bool isSugared() const { return false; }
6979  QualType desugar() const { return QualType(this, 0); }
6980 
6981  static bool classof(const Type *T) {
6982  return T->getTypeClass() == ObjCInterface;
6983  }
6984 
6985  // Nonsense to "hide" certain members of ObjCObjectType within this
6986  // class. People asking for protocols on an ObjCInterfaceType are
6987  // not going to get what they want: ObjCInterfaceTypes are
6988  // guaranteed to have no protocols.
6989  enum {
6994  getProtocol
6995  };
6996 };
6997 
6999  QualType baseType = getBaseType();
7000  while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) {
7001  if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT))
7002  return T->getDecl();
7003 
7004  baseType = ObjT->getBaseType();
7005  }
7006 
7007  return nullptr;
7008 }
7009 
7010 /// Represents a pointer to an Objective C object.
7011 ///
7012 /// These are constructed from pointer declarators when the pointee type is
7013 /// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
7014 /// types are typedefs for these, and the protocol-qualified types 'id<P>'
7015 /// and 'Class<P>' are translated into these.
7016 ///
7017 /// Pointers to pointers to Objective C objects are still PointerTypes;
7018 /// only the first level of pointer gets it own type implementation.
7019 class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
7020  friend class ASTContext; // ASTContext creates these.
7021 
7022  QualType PointeeType;
7023 
7024  ObjCObjectPointerType(QualType Canonical, QualType Pointee)
7025  : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()),
7026  PointeeType(Pointee) {}
7027 
7028 public:
7029  /// Gets the type pointed to by this ObjC pointer.
7030  /// The result will always be an ObjCObjectType or sugar thereof.
7031  QualType getPointeeType() const { return PointeeType; }
7032 
7033  /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
7034  ///
7035  /// This method is equivalent to getPointeeType() except that
7036  /// it discards any typedefs (or other sugar) between this
7037  /// type and the "outermost" object type. So for:
7038  /// \code
7039  /// \@class A; \@protocol P; \@protocol Q;
7040  /// typedef A<P> AP;
7041  /// typedef A A1;
7042  /// typedef A1<P> A1P;
7043  /// typedef A1P<Q> A1PQ;
7044  /// \endcode
7045  /// For 'A*', getObjectType() will return 'A'.
7046  /// For 'A<P>*', getObjectType() will return 'A<P>'.
7047  /// For 'AP*', getObjectType() will return 'A<P>'.
7048  /// For 'A1*', getObjectType() will return 'A'.
7049  /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
7050  /// For 'A1P*', getObjectType() will return 'A1<P>'.
7051  /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
7052  /// adding protocols to a protocol-qualified base discards the
7053  /// old qualifiers (for now). But if it didn't, getObjectType()
7054  /// would return 'A1P<Q>' (and we'd have to make iterating over
7055  /// qualifiers more complicated).
7057  return PointeeType->castAs<ObjCObjectType>();
7058  }
7059 
7060  /// If this pointer points to an Objective C
7061  /// \@interface type, gets the type for that interface. Any protocol
7062  /// qualifiers on the interface are ignored.
7063  ///
7064  /// \return null if the base type for this pointer is 'id' or 'Class'
7065  const ObjCInterfaceType *getInterfaceType() const;
7066 
7067  /// If this pointer points to an Objective \@interface
7068  /// type, gets the declaration for that interface.
7069  ///
7070  /// \return null if the base type for this pointer is 'id' or 'Class'
7072  return getObjectType()->getInterface();
7073  }
7074 
7075  /// True if this is equivalent to the 'id' type, i.e. if
7076  /// its object type is the primitive 'id' type with no protocols.
7077  bool isObjCIdType() const {
7078  return getObjectType()->isObjCUnqualifiedId();
7079  }
7080 
7081  /// True if this is equivalent to the 'Class' type,
7082  /// i.e. if its object tive is the primitive 'Class' type with no protocols.
7083  bool isObjCClassType() const {
7084  return getObjectType()->isObjCUnqualifiedClass();
7085  }
7086 
7087  /// True if this is equivalent to the 'id' or 'Class' type,
7088  bool isObjCIdOrClassType() const {
7089  return getObjectType()->isObjCUnqualifiedIdOrClass();
7090  }
7091 
7092  /// True if this is equivalent to 'id<P>' for some non-empty set of
7093  /// protocols.
7094  bool isObjCQualifiedIdType() const {
7095  return getObjectType()->isObjCQualifiedId();
7096  }
7097 
7098  /// True if this is equivalent to 'Class<P>' for some non-empty set of
7099  /// protocols.
7101  return getObjectType()->isObjCQualifiedClass();
7102  }
7103 
7104  /// Whether this is a "__kindof" type.
7105  bool isKindOfType() const { return getObjectType()->isKindOfType(); }
7106 
7107  /// Whether this type is specialized, meaning that it has type arguments.
7108  bool isSpecialized() const { return getObjectType()->isSpecialized(); }
7109 
7110  /// Whether this type is specialized, meaning that it has type arguments.
7111  bool isSpecializedAsWritten() const {
7112  return getObjectType()->isSpecializedAsWritten();
7113  }
7114 
7115  /// Whether this type is unspecialized, meaning that is has no type arguments.
7116  bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
7117 
7118  /// Determine whether this object type is "unspecialized" as
7119  /// written, meaning that it has no type arguments.
7120  bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
7121 
7122  /// Retrieve the type arguments for this type.
7124  return getObjectType()->getTypeArgs();
7125  }
7126 
7127  /// Retrieve the type arguments for this type.
7129  return getObjectType()->getTypeArgsAsWritten();
7130  }
7131 
7132  /// An iterator over the qualifiers on the object type. Provided
7133  /// for convenience. This will always iterate over the full set of
7134  /// protocols on a type, not just those provided directly.
7136  using qual_range = llvm::iterator_range<qual_iterator>;
7137 
7138  qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
7139 
7141  return getObjectType()->qual_begin();
7142  }
7143 
7145  return getObjectType()->qual_end();
7146  }
7147 
7148  bool qual_empty() const { return getObjectType()->qual_empty(); }
7149 
7150  /// Return the number of qualifying protocols on the object type.
7151  unsigned getNumProtocols() const {
7152  return getObjectType()->getNumProtocols();
7153  }
7154 
7155  /// Retrieve a qualifying protocol by index on the object type.
7156  ObjCProtocolDecl *getProtocol(unsigned I) const {
7157  return getObjectType()->getProtocol(I);
7158  }
7159 
7160  bool isSugared() const { return false; }
7161  QualType desugar() const { return QualType(this, 0); }
7162 
7163  /// Retrieve the type of the superclass of this object pointer type.
7164  ///
7165  /// This operation substitutes any type arguments into the
7166  /// superclass of the current class type, potentially producing a
7167  /// pointer to a specialization of the superclass type. Produces a
7168  /// null type if there is no superclass.
7169  QualType getSuperClassType() const;
7170 
7171  /// Strip off the Objective-C "kindof" type and (with it) any
7172  /// protocol qualifiers.
7173  const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
7174  const ASTContext &ctx) const;
7175 
7176  void Profile(llvm::FoldingSetNodeID &ID) {
7177  Profile(ID, getPointeeType());
7178  }
7179 
7180  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7181  ID.AddPointer(T.getAsOpaquePtr());
7182  }
7183 
7184  static bool classof(const Type *T) {
7185  return T->getTypeClass() == ObjCObjectPointer;
7186  }
7187 };
7188 
7189 class AtomicType : public Type, public llvm::FoldingSetNode {
7190  friend class ASTContext; // ASTContext creates these.
7191 
7192  QualType ValueType;
7193 
7194  AtomicType(QualType ValTy, QualType Canonical)
7195  : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {}
7196 
7197 public:
7198  /// Gets the type contained by this atomic type, i.e.
7199  /// the type returned by performing an atomic load of this atomic type.
7200  QualType getValueType() const { return ValueType; }
7201 
7202  bool isSugared() const { return false; }
7203  QualType desugar() const { return QualType(this, 0); }
7204 
7205  void Profile(llvm::FoldingSetNodeID &ID) {
7206  Profile(ID, getValueType());
7207  }
7208 
7209  static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7210  ID.AddPointer(T.getAsOpaquePtr());
7211  }
7212 
7213  static bool classof(const Type *T) {
7214  return T->getTypeClass() == Atomic;
7215  }
7216 };
7217 
7218 /// PipeType - OpenCL20.
7219 class PipeType : public Type, public llvm::FoldingSetNode {
7220  friend class ASTContext; // ASTContext creates these.
7221 
7222  QualType ElementType;
7223  bool isRead;
7224 
7225  PipeType(QualType elemType, QualType CanonicalPtr, bool isRead)
7226  : Type(Pipe, CanonicalPtr, elemType->getDependence()),
7227  ElementType(elemType), isRead(isRead) {}
7228 
7229 public:
7230  QualType getElementType() const { return ElementType; }
7231 
7232  bool isSugared() const { return false; }
7233 
7234  QualType desugar() const { return QualType(this, 0); }
7235 
7236  void Profile(llvm::FoldingSetNodeID &ID) {
7237  Profile(ID, getElementType(), isReadOnly());
7238  }
7239 
7240  static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) {
7241  ID.AddPointer(T.getAsOpaquePtr());
7242  ID.AddBoolean(isRead);
7243  }
7244 
7245  static bool classof(const Type *T) {
7246  return T->getTypeClass() == Pipe;
7247  }
7248 
7249  bool isReadOnly() const { return isRead; }
7250 };
7251 
7252 /// A fixed int type of a specified bitwidth.
7253 class BitIntType final : public Type, public llvm::FoldingSetNode {
7254  friend class ASTContext;
7255  LLVM_PREFERRED_TYPE(bool)
7256  unsigned IsUnsigned : 1;
7257  unsigned NumBits : 24;
7258 
7259 protected:
7260  BitIntType(bool isUnsigned, unsigned NumBits);
7261 
7262 public:
7263  bool isUnsigned() const { return IsUnsigned; }
7264  bool isSigned() const { return !IsUnsigned; }
7265  unsigned getNumBits() const { return NumBits; }
7266 
7267  bool isSugared() const { return false; }
7268  QualType desugar() const { return QualType(this, 0); }
7269 
7270  void Profile(llvm::FoldingSetNodeID &ID) const {
7271  Profile(ID, isUnsigned(), getNumBits());
7272  }
7273 
7274  static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned,
7275  unsigned NumBits) {
7276  ID.AddBoolean(IsUnsigned);
7277  ID.AddInteger(NumBits);
7278  }
7279 
7280  static bool classof(const Type *T) { return T->getTypeClass() == BitInt; }
7281 };
7282 
7283 class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
7284  friend class ASTContext;
7285  llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
7286 
7287 protected:
7288  DependentBitIntType(bool IsUnsigned, Expr *NumBits);
7289 
7290 public:
7291  bool isUnsigned() const;
7292  bool isSigned() const { return !isUnsigned(); }
7293  Expr *getNumBitsExpr() const;
7294 
7295  bool isSugared() const { return false; }
7296  QualType desugar() const { return QualType(this, 0); }
7297 
7298  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
7299  Profile(ID, Context, isUnsigned(), getNumBitsExpr());
7300  }
7301  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
7302  bool IsUnsigned, Expr *NumBitsExpr);
7303 
7304  static bool classof(const Type *T) {
7305  return T->getTypeClass() == DependentBitInt;
7306  }
7307 };
7308 
7309 /// A qualifier set is used to build a set of qualifiers.
7311 public:
7313 
7314  /// Collect any qualifiers on the given type and return an
7315  /// unqualified type. The qualifiers are assumed to be consistent
7316  /// with those already in the type.
7318  addFastQualifiers(type.getLocalFastQualifiers());
7319  if (!type.hasLocalNonFastQualifiers())
7320  return type.getTypePtrUnsafe();
7321 
7322  const ExtQuals *extQuals = type.getExtQualsUnsafe();
7323  addConsistentQualifiers(extQuals->getQualifiers());
7324  return extQuals->getBaseType();
7325  }
7326 
7327  /// Apply the collected qualifiers to the given type.
7328  QualType apply(const ASTContext &Context, QualType QT) const;
7329 
7330  /// Apply the collected qualifiers to the given type.
7331  QualType apply(const ASTContext &Context, const Type* T) const;
7332 };
7333 
7334 /// A container of type source information.
7335 ///
7336 /// A client can read the relevant info using TypeLoc wrappers, e.g:
7337 /// @code
7338 /// TypeLoc TL = TypeSourceInfo->getTypeLoc();
7339 /// TL.getBeginLoc().print(OS, SrcMgr);
7340 /// @endcode
7341 class alignas(8) TypeSourceInfo {
7342  // Contains a memory block after the class, used for type source information,
7343  // allocated by ASTContext.
7344  friend class ASTContext;
7345 
7346  QualType Ty;
7347 
7348  TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
7349 
7350 public:
7351  /// Return the type wrapped by this type source info.
7352  QualType getType() const { return Ty; }
7353 
7354  /// Return the TypeLoc wrapper for the type source info.
7355  TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
7356 
7357  /// Override the type stored in this TypeSourceInfo. Use with caution!
7358  void overrideType(QualType T) { Ty = T; }
7359 };
7360 
7361 // Inline function definitions.
7362 
7364  SplitQualType desugar =
7365  Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
7366  desugar.Quals.addConsistentQualifiers(Quals);
7367  return desugar;
7368 }
7369 
7370 inline const Type *QualType::getTypePtr() const {
7371  return getCommonPtr()->BaseType;
7372 }
7373 
7374 inline const Type *QualType::getTypePtrOrNull() const {
7375  return (isNull() ? nullptr : getCommonPtr()->BaseType);
7376 }
7377 
7378 inline bool QualType::isReferenceable() const {
7379  // C++ [defns.referenceable]
7380  // type that is either an object type, a function type that does not have
7381  // cv-qualifiers or a ref-qualifier, or a reference type.
7382  const Type &Self = **this;
7383  if (Self.isObjectType() || Self.isReferenceType())
7384  return true;
7385  if (const auto *F = Self.getAs<FunctionProtoType>())
7386  return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
7387 
7388  return false;
7389 }
7390 
7392  if (!hasLocalNonFastQualifiers())
7393  return SplitQualType(getTypePtrUnsafe(),
7394  Qualifiers::fromFastMask(getLocalFastQualifiers()));
7395 
7396  const ExtQuals *eq = getExtQualsUnsafe();
7397  Qualifiers qs = eq->getQualifiers();
7398  qs.addFastQualifiers(getLocalFastQualifiers());
7399  return SplitQualType(eq->getBaseType(), qs);
7400 }
7401 
7403  Qualifiers Quals;
7404  if (hasLocalNonFastQualifiers())
7405  Quals = getExtQualsUnsafe()->getQualifiers();
7406  Quals.addFastQualifiers(getLocalFastQualifiers());
7407  return Quals;
7408 }
7409 
7411  Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
7412  quals.addFastQualifiers(getLocalFastQualifiers());
7413  return quals;
7414 }
7415 
7416 inline unsigned QualType::getCVRQualifiers() const {
7417  unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
7418  cvr |= getLocalCVRQualifiers();
7419  return cvr;
7420 }
7421 
7423  QualType canon = getCommonPtr()->CanonicalType;
7424  return canon.withFastQualifiers(getLocalFastQualifiers());
7425 }
7426 
7427 inline bool QualType::isCanonical() const {
7428  return getTypePtr()->isCanonicalUnqualified();
7429 }
7430 
7431 inline bool QualType::isCanonicalAsParam() const {
7432  if (!isCanonical()) return false;
7433  if (hasLocalQualifiers()) return false;
7434 
7435  const Type *T = getTypePtr();
7437  return false;
7438 
7439  return !isa<FunctionType>(T) &&
7440  (!isa<ArrayType>(T) || isa<ArrayParameterType>(T));
7441 }
7442 
7443 inline bool QualType::isConstQualified() const {
7444  return isLocalConstQualified() ||
7445  getCommonPtr()->CanonicalType.isLocalConstQualified();
7446 }
7447 
7448 inline bool QualType::isRestrictQualified() const {
7449  return isLocalRestrictQualified() ||
7450  getCommonPtr()->CanonicalType.isLocalRestrictQualified();
7451 }
7452 
7453 
7454 inline bool QualType::isVolatileQualified() const {
7455  return isLocalVolatileQualified() ||
7456  getCommonPtr()->CanonicalType.isLocalVolatileQualified();
7457 }
7458 
7459 inline bool QualType::hasQualifiers() const {
7460  return hasLocalQualifiers() ||
7461  getCommonPtr()->CanonicalType.hasLocalQualifiers();
7462 }
7463 
7465  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
7466  return QualType(getTypePtr(), 0);
7467 
7468  return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
7469 }
7470 
7472  if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
7473  return split();
7474 
7475  return getSplitUnqualifiedTypeImpl(*this);
7476 }
7477 
7479  removeLocalFastQualifiers(Qualifiers::Const);
7480 }
7481 
7483  removeLocalFastQualifiers(Qualifiers::Restrict);
7484 }
7485 
7487  removeLocalFastQualifiers(Qualifiers::Volatile);
7488 }
7489 
7490 /// Check if this type has any address space qualifier.
7491 inline bool QualType::hasAddressSpace() const {
7492  return getQualifiers().hasAddressSpace();
7493 }
7494 
7495 /// Return the address space of this type.
7497  return getQualifiers().getAddressSpace();
7498 }
7499 
7500 /// Return the gc attribute of this type.
7502  return getQualifiers().getObjCGCAttr();
7503 }
7504 
7506  if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7507  return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
7508  return false;
7509 }
7510 
7512  if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7513  return hasNonTrivialToPrimitiveDestructCUnion(RD);
7514  return false;
7515 }
7516 
7518  if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7519  return hasNonTrivialToPrimitiveCopyCUnion(RD);
7520  return false;
7521 }
7522 
7524  if (const auto *PT = t.getAs<PointerType>()) {
7525  if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>())
7526  return FT->getExtInfo();
7527  } else if (const auto *FT = t.getAs<FunctionType>())
7528  return FT->getExtInfo();
7529 
7530  return FunctionType::ExtInfo();
7531 }
7532 
7534  return getFunctionExtInfo(*t);
7535 }
7536 
7537 /// Determine whether this type is more
7538 /// qualified than the Other type. For example, "const volatile int"
7539 /// is more qualified than "const int", "volatile int", and
7540 /// "int". However, it is not more qualified than "const volatile
7541 /// int".
7542 inline bool QualType::isMoreQualifiedThan(QualType other) const {
7543  Qualifiers MyQuals = getQualifiers();
7544  Qualifiers OtherQuals = other.getQualifiers();
7545  return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals));
7546 }
7547 
7548 /// Determine whether this type is at last
7549 /// as qualified as the Other type. For example, "const volatile
7550 /// int" is at least as qualified as "const int", "volatile int",
7551 /// "int", and "const volatile int".
7552 inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
7553  Qualifiers OtherQuals = other.getQualifiers();
7554 
7555  // Ignore __unaligned qualifier if this type is a void.
7556  if (getUnqualifiedType()->isVoidType())
7557  OtherQuals.removeUnaligned();
7558 
7559  return getQualifiers().compatiblyIncludes(OtherQuals);
7560 }
7561 
7562 /// If Type is a reference type (e.g., const
7563 /// int&), returns the type that the reference refers to ("const
7564 /// int"). Otherwise, returns the type itself. This routine is used
7565 /// throughout Sema to implement C++ 5p6:
7566 ///
7567 /// If an expression initially has the type "reference to T" (8.3.2,
7568 /// 8.5.3), the type is adjusted to "T" prior to any further
7569 /// analysis, the expression designates the object or function
7570 /// denoted by the reference, and the expression is an lvalue.
7572  if (const auto *RefType = (*this)->getAs<ReferenceType>())
7573  return RefType->getPointeeType();
7574  else
7575  return *this;
7576 }
7577 
7579  return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
7580  getTypePtr()->isFunctionType());
7581 }
7582 
7583 /// Tests whether the type is categorized as a fundamental type.
7584 ///
7585 /// \returns True for types specified in C++0x [basic.fundamental].
7586 inline bool Type::isFundamentalType() const {
7587  return isVoidType() ||
7588  isNullPtrType() ||
7589  // FIXME: It's really annoying that we don't have an
7590  // 'isArithmeticType()' which agrees with the standard definition.
7591  (isArithmeticType() && !isEnumeralType());
7592 }
7593 
7594 /// Tests whether the type is categorized as a compound type.
7595 ///
7596 /// \returns True for types specified in C++0x [basic.compound].
7597 inline bool Type::isCompoundType() const {
7598  // C++0x [basic.compound]p1:
7599  // Compound types can be constructed in the following ways:
7600  // -- arrays of objects of a given type [...];
7601  return isArrayType() ||
7602  // -- functions, which have parameters of given types [...];
7603  isFunctionType() ||
7604  // -- pointers to void or objects or functions [...];
7605  isPointerType() ||
7606  // -- references to objects or functions of a given type. [...]
7607  isReferenceType() ||
7608  // -- classes containing a sequence of objects of various types, [...];
7609  isRecordType() ||
7610  // -- unions, which are classes capable of containing objects of different
7611  // types at different times;
7612  isUnionType() ||
7613  // -- enumerations, which comprise a set of named constant values. [...];
7614  isEnumeralType() ||
7615  // -- pointers to non-static class members, [...].
7616  isMemberPointerType();
7617 }
7618 
7619 inline bool Type::isFunctionType() const {
7620  return isa<FunctionType>(CanonicalType);
7621 }
7622 
7623 inline bool Type::isPointerType() const {
7624  return isa<PointerType>(CanonicalType);
7625 }
7626 
7627 inline bool Type::isAnyPointerType() const {
7628  return isPointerType() || isObjCObjectPointerType();
7629 }
7630 
7631 inline bool Type::isBlockPointerType() const {
7632  return isa<BlockPointerType>(CanonicalType);
7633 }
7634 
7635 inline bool Type::isReferenceType() const {
7636  return isa<ReferenceType>(CanonicalType);
7637 }
7638 
7639 inline bool Type::isLValueReferenceType() const {
7640  return isa<LValueReferenceType>(CanonicalType);
7641 }
7642 
7643 inline bool Type::isRValueReferenceType() const {
7644  return isa<RValueReferenceType>(CanonicalType);
7645 }
7646 
7647 inline bool Type::isObjectPointerType() const {
7648  // Note: an "object pointer type" is not the same thing as a pointer to an
7649  // object type; rather, it is a pointer to an object type or a pointer to cv
7650  // void.
7651  if (const auto *T = getAs<PointerType>())
7652  return !T->getPointeeType()->isFunctionType();
7653  else
7654  return false;
7655 }
7656 
7657 inline bool Type::isFunctionPointerType() const {
7658  if (const auto *T = getAs<PointerType>())
7659  return T->getPointeeType()->isFunctionType();
7660  else
7661  return false;
7662 }
7663 
7664 inline bool Type::isFunctionReferenceType() const {
7665  if (const auto *T = getAs<ReferenceType>())
7666  return T->getPointeeType()->isFunctionType();
7667  else
7668  return false;
7669 }
7670 
7671 inline bool Type::isMemberPointerType() const {
7672  return isa<MemberPointerType>(CanonicalType);
7673 }
7674 
7676  if (const auto *T = getAs<MemberPointerType>())
7677  return T->isMemberFunctionPointer();
7678  else
7679  return false;
7680 }
7681 
7682 inline bool Type::isMemberDataPointerType() const {
7683  if (const auto *T = getAs<MemberPointerType>())
7684  return T->isMemberDataPointer();
7685  else
7686  return false;
7687 }
7688 
7689 inline bool Type::isArrayType() const {
7690  return isa<ArrayType>(CanonicalType);
7691 }
7692 
7693 inline bool Type::isConstantArrayType() const {
7694  return isa<ConstantArrayType>(CanonicalType);
7695 }
7696 
7697 inline bool Type::isIncompleteArrayType() const {
7698  return isa<IncompleteArrayType>(CanonicalType);
7699 }
7700 
7701 inline bool Type::isVariableArrayType() const {
7702  return isa<VariableArrayType>(CanonicalType);
7703 }
7704 
7705 inline bool Type::isArrayParameterType() const {
7706  return isa<ArrayParameterType>(CanonicalType);
7707 }
7708 
7709 inline bool Type::isDependentSizedArrayType() const {
7710  return isa<DependentSizedArrayType>(CanonicalType);
7711 }
7712 
7713 inline bool Type::isBuiltinType() const {
7714  return isa<BuiltinType>(CanonicalType);
7715 }
7716 
7717 inline bool Type::isRecordType() const {
7718  return isa<RecordType>(CanonicalType);
7719 }
7720 
7721 inline bool Type::isEnumeralType() const {
7722  return isa<EnumType>(CanonicalType);
7723 }
7724 
7725 inline bool Type::isAnyComplexType() const {
7726  return isa<ComplexType>(CanonicalType);
7727 }
7728 
7729 inline bool Type::isVectorType() const {
7730  return isa<VectorType>(CanonicalType);
7731 }
7732 
7733 inline bool Type::isExtVectorType() const {
7734  return isa<ExtVectorType>(CanonicalType);
7735 }
7736 
7737 inline bool Type::isExtVectorBoolType() const {
7738  if (!isExtVectorType())
7739  return false;
7740  return cast<ExtVectorType>(CanonicalType)->getElementType()->isBooleanType();
7741 }
7742 
7743 inline bool Type::isSubscriptableVectorType() const {
7744  return isVectorType() || isSveVLSBuiltinType();
7745 }
7746 
7747 inline bool Type::isMatrixType() const {
7748  return isa<MatrixType>(CanonicalType);
7749 }
7750 
7751 inline bool Type::isConstantMatrixType() const {
7752  return isa<ConstantMatrixType>(CanonicalType);
7753 }
7754 
7756  return isa<DependentAddressSpaceType>(CanonicalType);
7757 }
7758 
7759 inline bool Type::isObjCObjectPointerType() const {
7760  return isa<ObjCObjectPointerType>(CanonicalType);
7761 }
7762 
7763 inline bool Type::isObjCObjectType() const {
7764  return isa<ObjCObjectType>(CanonicalType);
7765 }
7766 
7768  return isa<ObjCInterfaceType>(CanonicalType) ||
7769  isa<ObjCObjectType>(CanonicalType);
7770 }
7771 
7772 inline bool Type::isAtomicType() const {
7773  return isa<AtomicType>(CanonicalType);
7774 }
7775 
7776 inline bool Type::isUndeducedAutoType() const {
7777  return isa<AutoType>(CanonicalType);
7778 }
7779 
7780 inline bool Type::isObjCQualifiedIdType() const {
7781  if (const auto *OPT = getAs<ObjCObjectPointerType>())
7782  return OPT->isObjCQualifiedIdType();
7783  return false;
7784 }
7785 
7786 inline bool Type::isObjCQualifiedClassType() const {
7787  if (const auto *OPT = getAs<ObjCObjectPointerType>())
7788  return OPT->isObjCQualifiedClassType();
7789  return false;
7790 }
7791 
7792 inline bool Type::isObjCIdType() const {
7793  if (const auto *OPT = getAs<ObjCObjectPointerType>())
7794  return OPT->isObjCIdType();
7795  return false;
7796 }
7797 
7798 inline bool Type::isObjCClassType() const {
7799  if (const auto *OPT = getAs<ObjCObjectPointerType>())
7800  return OPT->isObjCClassType();
7801  return false;
7802 }
7803 
7804 inline bool Type::isObjCSelType() const {
7805  if (const auto *OPT = getAs<PointerType>())
7806  return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
7807  return false;
7808 }
7809 
7810 inline bool Type::isObjCBuiltinType() const {
7811  return isObjCIdType() || isObjCClassType() || isObjCSelType();
7812 }
7813 
7814 inline bool Type::isDecltypeType() const {
7815  return isa<DecltypeType>(this);
7816 }
7817 
7818 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7819  inline bool Type::is##Id##Type() const { \
7820  return isSpecificBuiltinType(BuiltinType::Id); \
7821  }
7822 #include "clang/Basic/OpenCLImageTypes.def"
7823 
7824 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7825  inline bool Type::isSampled##Id##Type() const { \
7826  return isSpecificBuiltinType(BuiltinType::Sampled##Id); \
7827  }
7828 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
7829 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
7830 #include "clang/Basic/OpenCLImageTypes.def"
7831 
7832 inline bool Type::isSamplerT() const {
7833  return isSpecificBuiltinType(BuiltinType::OCLSampler);
7834 }
7835 
7836 inline bool Type::isEventT() const {
7837  return isSpecificBuiltinType(BuiltinType::OCLEvent);
7838 }
7839 
7840 inline bool Type::isClkEventT() const {
7841  return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
7842 }
7843 
7844 inline bool Type::isQueueT() const {
7845  return isSpecificBuiltinType(BuiltinType::OCLQueue);
7846 }
7847 
7848 inline bool Type::isReserveIDT() const {
7849  return isSpecificBuiltinType(BuiltinType::OCLReserveID);
7850 }
7851 
7852 inline bool Type::isImageType() const {
7853 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
7854  return isSampledImageType() ||
7855 #include "clang/Basic/OpenCLImageTypes.def"
7856  false; // end boolean or operation
7857 }
7858 
7859 inline bool Type::isSampledImageType() const {
7860 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7861  isSampled##Id##Type() ||
7862  return
7863 #define IMAGE_WRITE_TYPE(Type, Id, Ext)
7864 #define IMAGE_READ_WRITE_TYPE(Type, Id, Ext)
7865 #include "clang/Basic/OpenCLImageTypes.def"
7866  false; // end boolean or operation
7867 }
7868 
7869 inline bool Type::isPipeType() const {
7870  return isa<PipeType>(CanonicalType);
7871 }
7872 
7873 inline bool Type::isBitIntType() const {
7874  return isa<BitIntType>(CanonicalType);
7875 }
7876 
7877 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
7878  inline bool Type::is##Id##Type() const { \
7879  return isSpecificBuiltinType(BuiltinType::Id); \
7880  }
7881 #include "clang/Basic/OpenCLExtensionTypes.def"
7882 
7883 inline bool Type::isOCLIntelSubgroupAVCType() const {
7884 #define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \
7885  isOCLIntelSubgroupAVC##Id##Type() ||
7886  return
7887 #include "clang/Basic/OpenCLExtensionTypes.def"
7888  false; // end of boolean or operation
7889 }
7890 
7891 inline bool Type::isOCLExtOpaqueType() const {
7892 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() ||
7893  return
7894 #include "clang/Basic/OpenCLExtensionTypes.def"
7895  false; // end of boolean or operation
7896 }
7897 
7898 inline bool Type::isOpenCLSpecificType() const {
7899  return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
7900  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
7901 }
7902 
7903 inline bool Type::isTemplateTypeParmType() const {
7904  return isa<TemplateTypeParmType>(CanonicalType);
7905 }
7906 
7907 inline bool Type::isSpecificBuiltinType(unsigned K) const {
7908  if (const BuiltinType *BT = getAs<BuiltinType>()) {
7909  return BT->getKind() == static_cast<BuiltinType::Kind>(K);
7910  }
7911  return false;
7912 }
7913 
7914 inline bool Type::isPlaceholderType() const {
7915  if (const auto *BT = dyn_cast<BuiltinType>(this))
7916  return BT->isPlaceholderType();
7917  return false;
7918 }
7919 
7921  if (const auto *BT = dyn_cast<BuiltinType>(this))
7922  if (BT->isPlaceholderType())
7923  return BT;
7924  return nullptr;
7925 }
7926 
7927 inline bool Type::isSpecificPlaceholderType(unsigned K) const {
7929  return isSpecificBuiltinType(K);
7930 }
7931 
7933  if (const auto *BT = dyn_cast<BuiltinType>(this))
7934  return BT->isNonOverloadPlaceholderType();
7935  return false;
7936 }
7937 
7938 inline bool Type::isVoidType() const {
7939  return isSpecificBuiltinType(BuiltinType::Void);
7940 }
7941 
7942 inline bool Type::isHalfType() const {
7943  // FIXME: Should we allow complex __fp16? Probably not.
7944  return isSpecificBuiltinType(BuiltinType::Half);
7945 }
7946 
7947 inline bool Type::isFloat16Type() const {
7948  return isSpecificBuiltinType(BuiltinType::Float16);
7949 }
7950 
7951 inline bool Type::isFloat32Type() const {
7952  return isSpecificBuiltinType(BuiltinType::Float);
7953 }
7954 
7955 inline bool Type::isDoubleType() const {
7956  return isSpecificBuiltinType(BuiltinType::Double);
7957 }
7958 
7959 inline bool Type::isBFloat16Type() const {
7960  return isSpecificBuiltinType(BuiltinType::BFloat16);
7961 }
7962 
7963 inline bool Type::isFloat128Type() const {
7964  return isSpecificBuiltinType(BuiltinType::Float128);
7965 }
7966 
7967 inline bool Type::isIbm128Type() const {
7968  return isSpecificBuiltinType(BuiltinType::Ibm128);
7969 }
7970 
7971 inline bool Type::isNullPtrType() const {
7972  return isSpecificBuiltinType(BuiltinType::NullPtr);
7973 }
7974 
7976 bool IsEnumDeclScoped(EnumDecl *);
7977 
7978 inline bool Type::isIntegerType() const {
7979  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7980  return BT->getKind() >= BuiltinType::Bool &&
7981  BT->getKind() <= BuiltinType::Int128;
7982  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
7983  // Incomplete enum types are not treated as integer types.
7984  // FIXME: In C++, enum types are never integer types.
7985  return IsEnumDeclComplete(ET->getDecl()) &&
7986  !IsEnumDeclScoped(ET->getDecl());
7987  }
7988  return isBitIntType();
7989 }
7990 
7991 inline bool Type::isFixedPointType() const {
7992  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7993  return BT->getKind() >= BuiltinType::ShortAccum &&
7994  BT->getKind() <= BuiltinType::SatULongFract;
7995  }
7996  return false;
7997 }
7998 
7999 inline bool Type::isFixedPointOrIntegerType() const {
8000  return isFixedPointType() || isIntegerType();
8001 }
8002 
8004  return isRealFloatingType() || isFixedPointOrIntegerType();
8005 }
8006 
8007 inline bool Type::isSaturatedFixedPointType() const {
8008  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
8009  return BT->getKind() >= BuiltinType::SatShortAccum &&
8010  BT->getKind() <= BuiltinType::SatULongFract;
8011  }
8012  return false;
8013 }
8014 
8016  return isFixedPointType() && !isSaturatedFixedPointType();
8017 }
8018 
8019 inline bool Type::isSignedFixedPointType() const {
8020  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
8021  return ((BT->getKind() >= BuiltinType::ShortAccum &&
8022  BT->getKind() <= BuiltinType::LongAccum) ||
8023  (BT->getKind() >= BuiltinType::ShortFract &&
8024  BT->getKind() <= BuiltinType::LongFract) ||
8025  (BT->getKind() >= BuiltinType::SatShortAccum &&
8026  BT->getKind() <= BuiltinType::SatLongAccum) ||
8027  (BT->getKind() >= BuiltinType::SatShortFract &&
8028  BT->getKind() <= BuiltinType::SatLongFract));
8029  }
8030  return false;
8031 }
8032 
8033 inline bool Type::isUnsignedFixedPointType() const {
8034  return isFixedPointType() && !isSignedFixedPointType();
8035 }
8036 
8037 inline bool Type::isScalarType() const {
8038  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8039  return BT->getKind() > BuiltinType::Void &&
8040  BT->getKind() <= BuiltinType::NullPtr;
8041  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
8042  // Enums are scalar types, but only if they are defined. Incomplete enums
8043  // are not treated as scalar types.
8044  return IsEnumDeclComplete(ET->getDecl());
8045  return isa<PointerType>(CanonicalType) ||
8046  isa<BlockPointerType>(CanonicalType) ||
8047  isa<MemberPointerType>(CanonicalType) ||
8048  isa<ComplexType>(CanonicalType) ||
8049  isa<ObjCObjectPointerType>(CanonicalType) ||
8050  isBitIntType();
8051 }
8052 
8054  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8055  return BT->getKind() >= BuiltinType::Bool &&
8056  BT->getKind() <= BuiltinType::Int128;
8057 
8058  // Check for a complete enum type; incomplete enum types are not properly an
8059  // enumeration type in the sense required here.
8060  if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
8061  return IsEnumDeclComplete(ET->getDecl());
8062 
8063  return isBitIntType();
8064 }
8065 
8066 inline bool Type::isBooleanType() const {
8067  if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8068  return BT->getKind() == BuiltinType::Bool;
8069  return false;
8070 }
8071 
8072 inline bool Type::isUndeducedType() const {
8073  auto *DT = getContainedDeducedType();
8074  return DT && !DT->isDeduced();
8075 }
8076 
8077 /// Determines whether this is a type for which one can define
8078 /// an overloaded operator.
8079 inline bool Type::isOverloadableType() const {
8080  if (!CanonicalType->isDependentType())
8081  return isRecordType() || isEnumeralType();
8082  return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
8083  !isMemberPointerType();
8084 }
8085 
8086 /// Determines whether this type is written as a typedef-name.
8087 inline bool Type::isTypedefNameType() const {
8088  if (getAs<TypedefType>())
8089  return true;
8090  if (auto *TST = getAs<TemplateSpecializationType>())
8091  return TST->isTypeAlias();
8092  return false;
8093 }
8094 
8095 /// Determines whether this type can decay to a pointer type.
8096 inline bool Type::canDecayToPointerType() const {
8097  return isFunctionType() || (isArrayType() && !isArrayParameterType());
8098 }
8099 
8100 inline bool Type::hasPointerRepresentation() const {
8101  return (isPointerType() || isReferenceType() || isBlockPointerType() ||
8102  isObjCObjectPointerType() || isNullPtrType());
8103 }
8104 
8106  return isObjCObjectPointerType();
8107 }
8108 
8109 inline const Type *Type::getBaseElementTypeUnsafe() const {
8110  const Type *type = this;
8111  while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
8112  type = arrayType->getElementType().getTypePtr();
8113  return type;
8114 }
8115 
8117  const Type *type = this;
8118  if (type->isAnyPointerType())
8119  return type->getPointeeType().getTypePtr();
8120  else if (type->isArrayType())
8121  return type->getBaseElementTypeUnsafe();
8122  return type;
8123 }
8124 /// Insertion operator for partial diagnostics. This allows sending adress
8125 /// spaces into a diagnostic with <<.
8127  LangAS AS) {
8128  PD.AddTaggedVal(llvm::to_underlying(AS),
8129  DiagnosticsEngine::ArgumentKind::ak_addrspace);
8130  return PD;
8131 }
8132 
8133 /// Insertion operator for partial diagnostics. This allows sending Qualifiers
8134 /// into a diagnostic with <<.
8136  Qualifiers Q) {
8138  DiagnosticsEngine::ArgumentKind::ak_qual);
8139  return PD;
8140 }
8141 
8142 /// Insertion operator for partial diagnostics. This allows sending QualType's
8143 /// into a diagnostic with <<.
8145  QualType T) {
8146  PD.AddTaggedVal(reinterpret_cast<uint64_t>(T.getAsOpaquePtr()),
8148  return PD;
8149 }
8150 
8151 // Helper class template that is used by Type::getAs to ensure that one does
8152 // not try to look through a qualified type to get to an array type.
8153 template <typename T>
8155  std::integral_constant<bool, std::is_same<T, ArrayType>::value ||
8156  std::is_base_of<ArrayType, T>::value>;
8157 
8158 // Member-template getAs<specific type>'.
8159 template <typename T> const T *Type::getAs() const {
8160  static_assert(!TypeIsArrayType<T>::value,
8161  "ArrayType cannot be used with getAs!");
8162 
8163  // If this is directly a T type, return it.
8164  if (const auto *Ty = dyn_cast<T>(this))
8165  return Ty;
8166 
8167  // If the canonical form of this type isn't the right kind, reject it.
8168  if (!isa<T>(CanonicalType))
8169  return nullptr;
8170 
8171  // If this is a typedef for the type, strip the typedef off without
8172  // losing all typedef information.
8173  return cast<T>(getUnqualifiedDesugaredType());
8174 }
8175 
8176 template <typename T> const T *Type::getAsAdjusted() const {
8177  static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
8178 
8179  // If this is directly a T type, return it.
8180  if (const auto *Ty = dyn_cast<T>(this))
8181  return Ty;
8182 
8183  // If the canonical form of this type isn't the right kind, reject it.
8184  if (!isa<T>(CanonicalType))
8185  return nullptr;
8186 
8187  // Strip off type adjustments that do not modify the underlying nature of the
8188  // type.
8189  const Type *Ty = this;
8190  while (Ty) {
8191  if (const auto *A = dyn_cast<AttributedType>(Ty))
8192  Ty = A->getModifiedType().getTypePtr();
8193  else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
8194  Ty = A->getWrappedType().getTypePtr();
8195  else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
8196  Ty = E->desugar().getTypePtr();
8197  else if (const auto *P = dyn_cast<ParenType>(Ty))
8198  Ty = P->desugar().getTypePtr();
8199  else if (const auto *A = dyn_cast<AdjustedType>(Ty))
8200  Ty = A->desugar().getTypePtr();
8201  else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))
8202  Ty = M->desugar().getTypePtr();
8203  else
8204  break;
8205  }
8206 
8207  // Just because the canonical type is correct does not mean we can use cast<>,
8208  // since we may not have stripped off all the sugar down to the base type.
8209  return dyn_cast<T>(Ty);
8210 }
8211 
8212 inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
8213  // If this is directly an array type, return it.
8214  if (const auto *arr = dyn_cast<ArrayType>(this))
8215  return arr;
8216 
8217  // If the canonical form of this type isn't the right kind, reject it.
8218  if (!isa<ArrayType>(CanonicalType))
8219  return nullptr;
8220 
8221  // If this is a typedef for the type, strip the typedef off without
8222  // losing all typedef information.
8223  return cast<ArrayType>(getUnqualifiedDesugaredType());
8224 }
8225 
8226 template <typename T> const T *Type::castAs() const {
8227  static_assert(!TypeIsArrayType<T>::value,
8228  "ArrayType cannot be used with castAs!");
8229 
8230  if (const auto *ty = dyn_cast<T>(this)) return ty;
8231  assert(isa<T>(CanonicalType));
8232  return cast<T>(getUnqualifiedDesugaredType());
8233 }
8234 
8236  assert(isa<ArrayType>(CanonicalType));
8237  if (const auto *arr = dyn_cast<ArrayType>(this)) return arr;
8238  return cast<ArrayType>(getUnqualifiedDesugaredType());
8239 }
8240 
8241 DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
8242  QualType CanonicalPtr)
8243  : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
8244 #ifndef NDEBUG
8245  QualType Adjusted = getAdjustedType();
8246  (void)AttributedType::stripOuterNullability(Adjusted);
8247  assert(isa<PointerType>(Adjusted));
8248 #endif
8249 }
8250 
8252  QualType Decayed = getDecayedType();
8254  return cast<PointerType>(Decayed)->getPointeeType();
8255 }
8256 
8257 // Get the decimal string representation of a fixed point type, represented
8258 // as a scaled integer.
8259 // TODO: At some point, we should change the arguments to instead just accept an
8260 // APFixedPoint instead of APSInt and scale.
8262  unsigned Scale);
8263 
8264 } // namespace clang
8265 
8266 #endif // LLVM_CLANG_AST_TYPE_H
#define V(N, I)
Definition: ASTContext.h:3299
int Depth
Definition: ASTDiff.cpp:190
MatchType Type
StringRef P
Provides definitions for the various language-specific address spaces.
static char ID
Definition: Arena.cpp:183
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
Defines the clang::attr::Kind enum.
#define SM(sm)
Definition: Cuda.cpp:83
Defines the Diagnostic-related interfaces.
static bool isBooleanType(QualType Ty)
llvm::APSInt APSInt
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1125
Defines the ExceptionSpecificationType enumeration and various utility functions.
static bool isRead(AccessKinds AK)
static QualType getObjectType(APValue::LValueBase B)
Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
llvm::raw_ostream & OS
Definition: Logger.cpp:24
llvm::MachO::Record Record
Definition: MachO.h:31
static StringRef getIdentifier(const Token &Tok)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static QualType getUnderlyingType(const SubRegion *R)
static std::string getName(const CallEvent &Call)
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
Definition: SemaCUDA.cpp:111
static RecordDecl * getAsRecordDecl(QualType BaseType)
static bool isRecordType(QualType T)
SourceLocation Loc
Definition: SemaObjC.cpp:755
static bool isParameterPack(Expr *PackExpression)
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
const char * Data
static const TemplateTypeParmDecl * getReplacedParameter(Decl *D, unsigned Index)
Definition: Type.cpp:4131
Defines the clang::Visibility enumeration and various utility functions.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
__device__ __2f16 float c
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:366
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:90
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3309
static bool classof(const Type *T)
Definition: Type.h:3337
static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New)
Definition: Type.h:3332
AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr)
Definition: Type.h:3316
QualType desugar() const
Definition: Type.h:3326
QualType getAdjustedType() const
Definition: Type.h:3323
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3328
bool isSugared() const
Definition: Type.h:3325
QualType getOriginalType() const
Definition: Type.h:3322
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3699
static bool classof(const Type *T)
Definition: Type.h:3706
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3529
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3543
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:3547
static bool classof(const Type *T)
Definition: Type.h:3555
QualType getElementType() const
Definition: Type.h:3541
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3551
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:7209
bool isSugared() const
Definition: Type.h:7202
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:7200
QualType desugar() const
Definition: Type.h:7203
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7205
static bool classof(const Type *T)
Definition: Type.h:7213
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5615
QualType getModifiedType() const
Definition: Type.h:5637
static bool classof(const Type *T)
Definition: Type.h:5709
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
Definition: Type.h:5670
bool isSugared() const
Definition: Type.h:5640
static std::optional< NullabilityKind > stripOuterNullability(QualType &T)
Strip off the top-level nullability annotation on the given type, if it's there.
Definition: Type.cpp:4812
static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, QualType modified, QualType equivalent)
Definition: Type.h:5702
QualType desugar() const
Definition: Type.h:5641
QualType getEquivalentType() const
Definition: Type.h:5638
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5698
Kind getAttrKind() const
Definition: Type.h:5633
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5992
static bool classof(const Type *T)
Definition: Type.h:6033
bool isDecltypeAuto() const
Definition: Type.h:6015
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6002
AutoTypeKeyword getKeyword() const
Definition: Type.h:6023
bool isGNUAutoType() const
Definition: Type.h:6019
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6007
bool isConstrained() const
Definition: Type.h:6011
static bool classof(const Type *T)
Definition: Type.h:5743
QualType getWrappedType() const
Definition: Type.h:5727
QualType desugar() const
Definition: Type.h:5731
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5733
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:5728
static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped, const BTFTypeTagAttr *BTFAttr)
Definition: Type.h:5737
bool isSugared() const
Definition: Type.h:5730
A fixed int type of a specified bitwidth.
Definition: Type.h:7253
bool isSigned() const
Definition: Type.h:7264
static bool classof(const Type *T)
Definition: Type.h:7280
static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned, unsigned NumBits)
Definition: Type.h:7274
bool isSugared() const
Definition: Type.h:7267
bool isUnsigned() const
Definition: Type.h:7263
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:7270
unsigned getNumBits() const
Definition: Type.h:7265
QualType desugar() const
Definition: Type.h:7268
Pointer to a block type.
Definition: Type.h:3360
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3377
QualType getPointeeType() const
Definition: Type.h:3372
static bool classof(const Type *T)
Definition: Type.h:3385
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:3381
QualType desugar() const
Definition: Type.h:3375
bool isSugared() const
Definition: Type.h:3374
[BoundsSafety] Represents a parent type class for CountAttributedType and similar sugar types that wi...
Definition: Type.h:3210
decl_iterator dependent_decl_begin() const
Definition: Type.h:3225
bool isSugared() const
Definition: Type.h:3219
decl_iterator dependent_decl_end() const
Definition: Type.h:3226
unsigned getNumCoupledDecls() const
Definition: Type.h:3228
decl_range dependent_decls() const
Definition: Type.h:3230
ArrayRef< TypeCoupledDeclRefInfo > getCoupledDecls() const
Definition: Type.h:3234
QualType desugar() const
Definition: Type.h:3220
llvm::iterator_range< decl_iterator > decl_range
Definition: Type.h:3223
static bool classof(const Type *T)
Definition: Type.h:3240
ArrayRef< TypeCoupledDeclRefInfo > Decls
Definition: Type.h:3214
This class is used for builtin types like 'int'.
Definition: Type.h:2988
bool isPlaceholderType() const
Determines whether this type is a placeholder type, i.e.
Definition: Type.h:3075
bool isSugared() const
Definition: Type.h:3044
bool isNonOverloadPlaceholderType() const
Determines whether this type is a placeholder type other than Overload.
Definition: Type.h:3088
bool isSVECount() const
Definition: Type.h:3065
bool isSVEBool() const
Definition: Type.h:3063
QualType desugar() const
Definition: Type.h:3045
bool isInteger() const
Definition: Type.h:3047
const char * getNameAsCString(const PrintingPolicy &Policy) const
Definition: Type.h:3037
bool isFloatingPoint() const
Definition: Type.h:3059
static bool classof(const Type *T)
Definition: Type.h:3092
bool isSignedInteger() const
Definition: Type.h:3051
bool isUnsignedInteger() const
Definition: Type.h:3055
Kind getKind() const
Definition: Type.h:3034
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition: Type.h:3068
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Complex values, per C99 6.2.5p11.
Definition: Type.h:3097
bool isSugared() const
Definition: Type.h:3109
QualType getElementType() const
Definition: Type.h:3107
static void Profile(llvm::FoldingSetNodeID &ID, QualType Element)
Definition: Type.h:3116
static bool classof(const Type *T)
Definition: Type.h:3120
QualType desugar() const
Definition: Type.h:3110
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3112
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3567
unsigned getSizeBitWidth() const
Return the bit width of the size type.
Definition: Type.h:3630
ConstantArrayType(TypeClass Tc, const ConstantArrayType *ATy, QualType Can)
Definition: Type.h:3609
ExternalSize * SizePtr
Definition: Type.h:3579
QualType desugar() const
Definition: Type.h:3668
uint64_t getLimitedSize() const
Return the size zero-extended to uint64_t or UINT64_MAX if the value is larger than UINT64_MAX.
Definition: Type.h:3656
bool isZeroSize() const
Return true if the size is zero.
Definition: Type.h:3637
int64_t getSExtSize() const
Return the size sign-extended as a uint64_t.
Definition: Type.h:3649
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition: Type.h:3663
bool isSugared() const
Definition: Type.h:3667
static bool classof(const Type *T)
Definition: Type.h:3691
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition: Type.h:3623
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:3682
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
Definition: Type.h:3643
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4178
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:4199
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumRows, unsigned NumColumns, TypeClass TypeClass)
Definition: Type.h:4221
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4216
static constexpr unsigned getMaxElementsPerDimension()
Returns the maximum number of elements per dimension.
Definition: Type.h:4212
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:4196
unsigned getNumElementsFlattened() const
Returns the number of elements required to embed the matrix into a vector.
Definition: Type.h:4202
static constexpr bool isDimensionValid(size_t NumElements)
Returns true if NumElements is a valid matrix dimension.
Definition: Type.h:4207
unsigned NumRows
Number of rows and columns.
Definition: Type.h:4183
static bool classof(const Type *T)
Definition: Type.h:4230
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3258
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3294
static bool classof(const Type *T)
Definition: Type.h:3301
bool isOrNull() const
Definition: Type.h:3286
Expr * getCountExpr() const
Definition: Type.h:3284
bool isCountInBytes() const
Definition: Type.h:3285
DynamicCountPointerKind getKind() const
Definition: Type.h:3288
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3343
QualType getPointeeType() const
Definition: Type.h:8251
static bool classof(const Type *T)
Definition: Type.h:3354
QualType getDecayedType() const
Definition: Type.h:3350
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Represents the type decltype(expr) (C++11).
Definition: Type.h:5369
Expr * getUnderlyingExpr() const
Definition: Type.h:5379
static bool classof(const Type *T)
Definition: Type.h:5388
QualType getUnderlyingType() const
Definition: Type.h:5380
Represents a C++17 deduced template specialization type.
Definition: Type.h:6040
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:6060
static bool classof(const Type *T)
Definition: Type.h:6075
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6062
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, QualType Deduced, bool IsDependent)
Definition: Type.h:6066
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5958
static bool classof(const Type *T)
Definition: Type.h:5984
bool isSugared() const
Definition: Type.h:5972
QualType desugar() const
Definition: Type.h:5973
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5979
DeducedType(TypeClass TC, QualType DeducedAsType, TypeDependence ExtraDependence, QualType Canon)
Definition: Type.h:5962
bool isDeduced() const
Definition: Type.h:5980
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3870
QualType desugar() const
Definition: Type.h:3886
Expr * getAddrSpaceExpr() const
Definition: Type.h:3881
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3892
QualType getPointeeType() const
Definition: Type.h:3882
static bool classof(const Type *T)
Definition: Type.h:3888
SourceLocation getAttributeLoc() const
Definition: Type.h:3883
QualType desugar() const
Definition: Type.h:7296
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:7298
bool isSigned() const
Definition: Type.h:7292
bool isSugared() const
Definition: Type.h:7295
static bool classof(const Type *T)
Definition: Type.h:7304
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:5397
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5401
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6463
bool isSugared() const
Definition: Type.h:6492
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:6488
static bool classof(const Type *T)
Definition: Type.h:6506
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6495
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6481
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name)
Definition: Type.h:6499
QualType desugar() const
Definition: Type.h:6493
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3812
QualType desugar() const
Definition: Type.h:3843
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3849
static bool classof(const Type *T)
Definition: Type.h:3845
SourceRange getBracketsRange() const
Definition: Type.h:3838
SourceLocation getLBracketLoc() const
Definition: Type.h:3839
Expr * getSizeExpr() const
Definition: Type.h:3832
SourceLocation getRBracketLoc() const
Definition: Type.h:3840
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3910
QualType desugar() const
Definition: Type.h:3929
static bool classof(const Type *T)
Definition: Type.h:3931
SourceLocation getAttributeLoc() const
Definition: Type.h:3926
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3935
QualType getElementType() const
Definition: Type.h:3925
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4237
Expr * getRowExpr() const
Definition: Type.h:4249
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4257
Expr * getColumnExpr() const
Definition: Type.h:4250
SourceLocation getAttributeLoc() const
Definition: Type.h:4251
static bool classof(const Type *T)
Definition: Type.h:4253
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6515
NestedNameSpecifier * getQualifier() const
Definition: Type.h:6531
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6532
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6542
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6534
static bool classof(const Type *T)
Definition: Type.h:6553
Internal representation of canonical, dependent typeof(expr) types.
Definition: Type.h:5318
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5322
DependentTypeOfExprType(Expr *E, TypeOfKind Kind)
Definition: Type.h:5320
Internal representation of canonical, dependent __underlying_type(type) types.
Definition: Type.h:5520
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5525
static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, UTTKind UKind)
Definition: Type.h:5529
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4032
Expr * getSizeExpr() const
Definition: Type.h:4043
VectorKind getVectorKind() const
Definition: Type.h:4046
SourceLocation getAttributeLoc() const
Definition: Type.h:4045
bool isSugared() const
Definition: Type.h:4050
QualType getElementType() const
Definition: Type.h:4044
QualType desugar() const
Definition: Type.h:4051
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4057
static bool classof(const Type *T)
Definition: Type.h:4053
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6382
static bool classof(const Type *T)
Definition: Type.h:6448
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:6423
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl)
Definition: Type.h:6439
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:6426
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6417
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6435
TagDecl * getOwnedTagDecl() const
Return the (re)declaration of this type owned by this occurrence of this type, or nullptr if there is...
Definition: Type.h:6430
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:6420
Represents an enum.
Definition: Decl.h:3870
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5586
bool isSugared() const
Definition: Type.h:5597
static bool classof(const Type *T)
Definition: Type.h:5600
QualType desugar() const
Definition: Type.h:5598
EnumDecl * getDecl() const
Definition: Type.h:5593
This represents one expression.
Definition: Expr.h:110
Base class that is common to both the ExtQuals and Type classes, which allows QualType to access the ...
Definition: Type.h:1667
We can encode up to four bits in the low bits of a type pointer, but there are many more type qualifi...
Definition: Type.h:1697
Qualifiers::ObjCLifetime getObjCLifetime() const
Definition: Type.h:1734
const Type * getBaseType() const
Definition: Type.h:1741
static void Profile(llvm::FoldingSetNodeID &ID, const Type *BaseType, Qualifiers Quals)
Definition: Type.h:1748
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1744
ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
Definition: Type.h:1718
bool hasObjCGCAttr() const
Definition: Type.h:1730
Qualifiers::GC getObjCGCAttr() const
Definition: Type.h:1731
bool hasAddressSpace() const
Definition: Type.h:1738
Qualifiers getQualifiers() const
Definition: Type.h:1728
LangAS getAddressSpace() const
Definition: Type.h:1739
bool hasObjCLifetime() const
Definition: Type.h:1733
ExtVectorType - Extended vector type.
Definition: Type.h:4072
bool isSugared() const
Definition: Type.h:4131
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:4125
static int getNumericAccessorIdx(char c)
Definition: Type.h:4090
static bool classof(const Type *T)
Definition: Type.h:4134
static int getPointAccessorIdx(char c)
Definition: Type.h:4080
QualType desugar() const
Definition: Type.h:4132
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:4118
Represents a function declaration or definition.
Definition: Decl.h:1972
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4622
bool isSugared() const
Definition: Type.h:4635
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition: Type.h:4642
QualType desugar() const
Definition: Type.h:4636
static bool classof(const Type *T)
Definition: Type.h:4648
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4638
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4667
QualType desugar() const
Definition: Type.h:5134
param_type_iterator param_type_begin() const
Definition: Type.h:5059
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4984
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5097
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4907
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:5112
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4926
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:5005
bool isParamConsumed(unsigned I) const
Definition: Type.h:5126
exception_iterator exception_end() const
Definition: Type.h:5078
ArrayRef< QualType > param_types() const
Definition: Type.h:5055
unsigned getNumParams() const
Definition: Type.h:4900
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5039
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
Definition: Type.h:4952
Qualifiers getMethodQuals() const
Definition: Type.h:5041
ArrayRef< QualType > exceptions() const
Definition: Type.h:5069
static bool classof(const Type *T)
Definition: Type.h:5139
QualType getParamType(unsigned i) const
Definition: Type.h:4902
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition: Type.h:5105
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4977
static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, param_type_iterator ArgTys, unsigned NumArgs, const ExtProtoInfo &EPI, const ASTContext &Context, bool Canonical)
SourceLocation getEllipsisLoc() const
Definition: Type.h:5025
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4969
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:4932
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition: Type.h:4994
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:4935
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition: Type.h:4940
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5023
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4911
param_type_iterator param_type_end() const
Definition: Type.h:5063
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition: Type.h:5088
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.h:5018
ParameterABI getParameterABI(unsigned I) const
Definition: Type.h:5119
bool isSugared() const
Definition: Type.h:5133
exception_iterator exception_begin() const
Definition: Type.h:5073
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition: Type.h:5084
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:5049
A class which abstracts out some details necessary for making a call.
Definition: Type.h:4378
ExtInfo withNoCfCheck(bool noCfCheck) const
Definition: Type.h:4480
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:4493
CallingConv getCC() const
Definition: Type.h:4440
ExtInfo withProducesResult(bool producesResult) const
Definition: Type.h:4459
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, bool producesResult, bool noCallerSavedRegs, bool NoCfCheck, bool cmseNSCall)
Definition: Type.h:4406
bool getCmseNSCall() const
Definition: Type.h:4428
bool getNoCfCheck() const
Definition: Type.h:4430
unsigned getRegParm() const
Definition: Type.h:4433
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:4497
bool getNoCallerSavedRegs() const
Definition: Type.h:4429
ExtInfo withNoReturn(bool noReturn) const
Definition: Type.h:4452
bool getHasRegParm() const
Definition: Type.h:4431
bool getNoReturn() const
Definition: Type.h:4426
bool operator==(ExtInfo Other) const
Definition: Type.h:4442
bool getProducesResult() const
Definition: Type.h:4427
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
Definition: Type.h:4473
ExtInfo withCmseNSCall(bool cmseNSCall) const
Definition: Type.h:4466
ExtInfo(CallingConv CC)
Definition: Type.h:4424
ExtInfo withRegParm(unsigned RegParm) const
Definition: Type.h:4487
bool operator!=(ExtInfo Other) const
Definition: Type.h:4445
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4293
friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:4349
friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:4353
ExtParameterInfo withHasPassObjectSize() const
Definition: Type.h:4326
unsigned char getOpaqueValue() const
Definition: Type.h:4342
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC? Consumed parameters must have retainable ...
Definition: Type.h:4315
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition: Type.h:4306
ExtParameterInfo withIsConsumed(bool consumed) const
Definition: Type.h:4316
ExtParameterInfo withIsNoEscape(bool NoEscape) const
Definition: Type.h:4333
ExtParameterInfo withABI(ParameterABI kind) const
Definition: Type.h:4307
static ExtParameterInfo getFromOpaqueValue(unsigned char data)
Definition: Type.h:4343
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4267
ExtInfo getExtInfo() const
Definition: Type.h:4596
static ArmStateValue getArmZT0State(unsigned AttrBits)
Definition: Type.h:4554
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:4592
bool isConst() const
Definition: Type.h:4602
static ArmStateValue getArmZAState(unsigned AttrBits)
Definition: Type.h:4550
unsigned getRegParmType() const
Definition: Type.h:4587
CallingConv getCallConv() const
Definition: Type.h:4595
bool isRestrict() const
Definition: Type.h:4604
QualType getReturnType() const
Definition: Type.h:4584
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition: Type.h:4570
static bool classof(const Type *T)
Definition: Type.h:4614
bool getCmseNSCallAttr() const
Definition: Type.h:4594
bool getHasRegParm() const
Definition: Type.h:4586
Qualifiers getFastTypeQuals() const
Definition: Type.h:4576
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition: Type.h:4608
AArch64SMETypeAttributes
The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number of function type attributes that...
Definition: Type.h:4526
bool isVolatile() const
Definition: Type.h:4603
One of these records is kept for each identifier that is lexed.
Represents a C array with an unspecified size.
Definition: Type.h:3714
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3731
static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, ArraySizeModifier SizeMod, unsigned TypeQuals)
Definition: Type.h:3736
QualType desugar() const
Definition: Type.h:3725
bool isSugared() const
Definition: Type.h:3724
static bool classof(const Type *T)
Definition: Type.h:3727
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6232
QualType desugar() const
Definition: Type.h:6276
static bool classof(const Type *T)
Definition: Type.h:6278
TemplateName getTemplateName() const
Definition: Type.h:6269
QualType getInjectedSpecializationType() const
Definition: Type.h:6263
bool isSugared() const
Definition: Type.h:6275
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:6265
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3435
static bool classof(const Type *T)
Definition: Type.h:3447
QualType desugar() const
Definition: Type.h:3445
bool isSugared() const
Definition: Type.h:3444
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5253
bool isSugared() const
Definition: Type.h:5275
static bool classof(const Type *T)
Definition: Type.h:5278
QualType getUnderlyingType() const
Definition: Type.h:5269
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:5268
Represents a matrix type, as defined in the Matrix Types clang extensions.
Definition: Type.h:4142
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:4156
QualType desugar() const
Definition: Type.h:4169
MatrixType(QualType ElementTy, QualType CanonElementTy)
static bool isValidElementType(QualType T)
Valid elements types are the following:
Definition: Type.h:4163
QualType ElementType
The element type of the matrix.
Definition: Type.h:4147
bool isSugared() const
Definition: Type.h:4168
static bool classof(const Type *T)
Definition: Type.h:4171
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3471
const Type * getClass() const
Definition: Type.h:3501
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3507
QualType getPointeeType() const
Definition: Type.h:3487
bool isSugared() const
Definition: Type.h:3504
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3491
bool isMemberDataPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3497
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, const Type *Class)
Definition: Type.h:3511
QualType desugar() const
Definition: Type.h:3505
static bool classof(const Type *T)
Definition: Type.h:3517
This represents a decl that may have a name.
Definition: Decl.h:249
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:6963
QualType desugar() const
Definition: Type.h:6979
bool isSugared() const
Definition: Type.h:6978
static bool classof(const Type *T)
Definition: Type.h:6981
Represents a pointer to an Objective C object.
Definition: Type.h:7019
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition: Type.h:7151
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7108
qual_iterator qual_end() const
Definition: Type.h:7144
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:7100
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:7180
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition: Type.h:7123
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7094
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7111
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:7120
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7176
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition: Type.h:7156
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:7135
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:7136
static bool classof(const Type *T)
Definition: Type.h:7184
bool qual_empty() const
Definition: Type.h:7148
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition: Type.h:7128
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition: Type.h:7116
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:7077
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7056
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7031
QualType desugar() const
Definition: Type.h:7161
qual_range quals() const
Definition: Type.h:7138
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:7083
bool isSugared() const
Definition: Type.h:7160
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7088
qual_iterator qual_begin() const
Definition: Type.h:7140
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition: Type.h:7071
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:7105
A class providing a concrete implementation of ObjCObjectType, so as to not increase the footprint of...
Definition: Type.h:6916
Represents a class type in Objective C.
Definition: Type.h:6765
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6875
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6880
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:6868
bool isObjCQualifiedClass() const
Definition: Type.h:6847
ObjCObjectType(enum Nonce_ObjCInterface)
Definition: Type.h:6810
bool isObjCUnqualifiedIdOrClass() const
Definition: Type.h:6839
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6827
bool isObjCClass() const
Definition: Type.h:6833
QualType desugar() const
Definition: Type.h:6904
bool isObjCQualifiedId() const
Definition: Type.h:6846
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:6858
bool isObjCUnqualifiedId() const
Definition: Type.h:6837
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments.
Definition: Type.h:6864
bool isSugared() const
Definition: Type.h:6903
bool isObjCUnqualifiedClass() const
Definition: Type.h:6838
static bool classof(const Type *T)
Definition: Type.h:6906
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface.
Definition: Type.h:6998
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:6891
bool isObjCId() const
Definition: Type.h:6829
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
This class wraps the list of protocol qualifiers.
Definition: Type.h:6634
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:6661
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6682
ObjCProtocolDecl *const * getProtocolStorage() const
Definition: Type.h:6638
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:6650
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:6671
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:6676
ObjCProtocolDecl ** getProtocolStorage()
Definition: Type.h:6642
void setNumProtocols(unsigned N)
Definition: Type.h:6646
qual_iterator qual_end() const
Definition: Type.h:6665
qual_iterator qual_begin() const
Definition: Type.h:6664
qual_range quals() const
Definition: Type.h:6663
bool qual_empty() const
Definition: Type.h:6667
ObjCProtocolDecl *const * qual_iterator
Definition: Type.h:6660
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Represents a type parameter type in Objective C.
Definition: Type.h:6691
static bool classof(const Type *T)
Definition: Type.h:6723
bool isSugared() const
Definition: Type.h:6720
QualType desugar() const
Definition: Type.h:6721
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6733
Represents a pack expansion of types.
Definition: Type.h:6580
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6605
bool isSugared() const
Definition: Type.h:6611
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6614
static bool classof(const Type *T)
Definition: Type.h:6626
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, std::optional< unsigned > NumExpansions)
Definition: Type.h:6618
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6601
QualType desugar() const
Definition: Type.h:6612
bool hasSelectedType() const
Definition: Type.h:5446
QualType getPattern() const
Definition: Type.h:5429
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5456
Expr * getIndexExpr() const
Definition: Type.h:5428
QualType getSelectedType() const
Definition: Type.h:5439
ArrayRef< QualType > getExpansions() const
Definition: Type.h:5448
QualType desugar() const
Definition: Type.h:5433
static bool classof(const Type *T)
Definition: Type.h:5452
bool isSugared() const
Definition: Type.h:5431
Sugar for parentheses used when specifying types.
Definition: Type.h:3124
QualType desugar() const
Definition: Type.h:3136
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3138
static bool classof(const Type *T)
Definition: Type.h:3146
static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner)
Definition: Type.h:3142
bool isSugared() const
Definition: Type.h:3135
QualType getInnerType() const
Definition: Type.h:3133
PipeType - OpenCL20.
Definition: Type.h:7219
QualType desugar() const
Definition: Type.h:7234
bool isSugared() const
Definition: Type.h:7232
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead)
Definition: Type.h:7240
QualType getElementType() const
Definition: Type.h:7230
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7236
static bool classof(const Type *T)
Definition: Type.h:7245
bool isReadOnly() const
Definition: Type.h:7249
Pointer-authentication qualifiers.
Definition: Type.h:145
static PointerAuthQualifier fromOpaqueValue(uint32_t Opaque)
Definition: Type.h:301
friend bool operator==(PointerAuthQualifier Lhs, PointerAuthQualifier Rhs)
Definition: Type.h:287
bool isIsaPointer() const
Definition: Type.h:273
static PointerAuthQualifier Create(unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator, PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer, bool AuthenticatesNullValues)
Definition: Type.h:232
friend bool operator!=(PointerAuthQualifier Lhs, PointerAuthQualifier Rhs)
Definition: Type.h:290
bool authenticatesNullValues() const
Definition: Type.h:278
bool isEquivalent(PointerAuthQualifier Other) const
Definition: Type.h:294
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:309
bool hasKeyNone() const
Definition: Type.h:256
@ MaxDiscriminator
The maximum supported pointer-authentication discriminator.
Definition: Type.h:225
@ MaxKey
The maximum supported pointer-authentication key.
Definition: Type.h:222
bool isAddressDiscriminated() const
Definition: Type.h:258
PointerAuthQualifier withoutKeyNone() const
Definition: Type.h:283
unsigned getExtraDiscriminator() const
Definition: Type.h:263
PointerAuthenticationMode getAuthenticationMode() const
Definition: Type.h:268
bool isPresent() const
Definition: Type.h:243
uint32_t getAsOpaqueValue() const
Definition: Type.h:298
unsigned getKey() const
Definition: Type.h:251
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3150
QualType getPointeeType() const
Definition: Type.h:3160
static bool classof(const Type *T)
Definition: Type.h:3173
QualType desugar() const
Definition: Type.h:3163
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3165
bool isSugared() const
Definition: Type.h:3162
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:3169
StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, const Twine &PlaceHolder, unsigned Indentation)
Definition: Type.h:1371
friend raw_ostream & operator<<(raw_ostream &OS, const StreamedQualTypeHelper &SQT)
Definition: Type.h:1376
A (possibly-)qualified type.
Definition: Type.h:940
void addRestrict()
Add the restrict qualifier to this QualType.
Definition: Type.h:1167
QualType(const ExtQuals *Ptr, unsigned Quals)
Definition: Type.h:965
bool isLocalConstQualified() const
Determine whether this particular QualType instance has the "const" qualifier set,...
Definition: Type.h:1017
bool isLocalRestrictQualified() const
Determine whether this particular QualType instance has the "restrict" qualifier set,...
Definition: Type.h:1047
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition: Type.h:7454
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition: Type.h:7448
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2737
const Type * operator->() const
Definition: Type.h:999
QualType IgnoreParens() const
Returns the specified type after dropping any outer-level parentheses.
Definition: Type.h:1310
Qualifiers::GC getObjCGCAttr() const
Returns gc attribute of this type.
Definition: Type.h:7501
friend bool operator==(const QualType &LHS, const QualType &RHS)
Indicate whether the specified types and qualifiers are identical.
Definition: Type.h:1317
bool hasQualifiers() const
Determine whether this type has any qualifiers.
Definition: Type.h:7459
QualType withFastQualifiers(unsigned TQs) const
Definition: Type.h:1196
QualType withRestrict() const
Definition: Type.h:1170
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
Definition: Type.h:7517
PointerAuthQualifier getPointerAuth() const
Definition: Type.h:1447
void addFastQualifiers(unsigned TQs)
Definition: Type.h:1178
bool isWebAssemblyFuncrefType() const
Returns true if it is a WebAssembly Funcref Type.
Definition: Type.cpp:2857
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition: Type.cpp:3483
@ DK_cxx_destructor
Definition: Type.h:1520
@ DK_nontrivial_c_struct
Definition: Type.h:1523
@ DK_objc_weak_lifetime
Definition: Type.h:1522
@ DK_objc_strong_lifetime
Definition: Type.h:1521
PrimitiveDefaultInitializeKind
Definition: Type.h:1451
@ PDIK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1463
@ PDIK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1455
@ PDIK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1459
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
Definition: Type.h:1466
bool mayBeDynamicClass() const
Returns true if it is a class and it might be dynamic.
Definition: Type.cpp:95
bool hasLocalNonFastQualifiers() const
Determine whether this particular QualType instance has any "non-fast" qualifiers,...
Definition: Type.h:1077
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
Definition: Type.cpp:2831
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
Definition: Type.cpp:75
QualType withoutLocalFastQualifiers() const
Definition: Type.h:1209
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:1393
void * getAsOpaquePtr() const
Definition: Type.h:987
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
Definition: Type.h:1291
void removeLocalFastQualifiers(unsigned Mask)
Definition: Type.h:1189
QualType withConst() const
Definition: Type.h:1154
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
Definition: Type.h:1220
void addConst()
Add the const type qualifier to this QualType.
Definition: Type.h:1151
bool isAtLeastAsQualifiedAs(QualType Other) const
Determine whether this type is at least as qualified as the other given type, requiring exact equalit...
Definition: Type.h:7552
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Definition: Type.h:1067
bool isTriviallyCopyConstructibleType(const ASTContext &Context) const
Return true if this is a trivially copyable type.
Definition: Type.cpp:2742
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2639
const Type & operator*() const
Definition: Type.h:995
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1007
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2879
bool isTriviallyRelocatableType(const ASTContext &Context) const
Return true if this is a trivially relocatable type.
Definition: Type.cpp:2748
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7370
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7496
bool isConstant(const ASTContext &Ctx) const
Definition: Type.h:1100
static QualType getFromOpaquePtr(const void *Ptr)
Definition: Type.h:989
QualType withVolatile() const
Definition: Type.h:1162
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Definition: Type.h:7511
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7410
void setLocalFastQualifiers(unsigned Quals)
Definition: Type.h:968
bool isAddressSpaceOverlapping(QualType T) const
Returns true if address space qualifiers overlap with T address space qualifiers.
Definition: Type.h:1411
bool isCXX98PODType(const ASTContext &Context) const
Return true if this is a POD type according to the rules of the C++98 standard, regardless of the cur...
Definition: Type.cpp:2590
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1432
QualType stripObjCKindOfType(const ASTContext &ctx) const
Strip Objective-C "__kindof" types from the given type.
Definition: Type.cpp:1612
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void getAsStringInternal(std::string &Str, const PrintingPolicy &Policy) const
bool isReferenceable() const
Definition: Type.h:7378
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Definition: Type.h:7571
QualType getCanonicalType() const
Definition: Type.h:7422
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7464
bool isTriviallyEqualityComparableType(const ASTContext &Context) const
Return true if this is a trivially equality comparable type.
Definition: Type.cpp:2815
void removeLocalVolatile()
Definition: Type.h:7486
QualType substObjCMemberType(QualType objectType, const DeclContext *dc, ObjCSubstitutionContext context) const
Substitute type arguments from an object type for the Objective-C type parameters used in the subject...
Definition: Type.cpp:1603
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
Definition: Type.cpp:2849
SplitQualType getSplitDesugaredType() const
Definition: Type.h:1295
std::optional< NonConstantStorageReason > isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
Determine whether instances of this type can be placed in immutable storage.
Definition: Type.cpp:116
QualType withCVRQualifiers(unsigned CVR) const
Definition: Type.h:1174
QualType()=default
unsigned getLocalCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers local to this particular QualType instan...
Definition: Type.h:1092
SplitQualType split() const
Divides a QualType into its unqualified type and a set of local qualifiers.
Definition: Type.h:7391
bool UseExcessPrecision(const ASTContext &Ctx)
Definition: Type.cpp:1561
void addVolatile()
Add the volatile type qualifier to this QualType.
Definition: Type.h:1159
bool isCForbiddenLValueType() const
Determine whether expressions of the given type are forbidden from being lvalues in C.
Definition: Type.h:7578
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2863
bool isObjCGCStrong() const
true when Type is objc's strong.
Definition: Type.h:1427
std::string getAsString() const
void dump() const
Definition: ASTDumper.cpp:185
static void print(SplitQualType split, raw_ostream &OS, const PrintingPolicy &policy, const Twine &PlaceHolder, unsigned Indentation=0)
Definition: Type.h:1341
bool isCanonicalAsParam() const
Definition: Type.h:7431
void removeLocalConst()
Definition: Type.h:7478
void removeLocalRestrict()
Definition: Type.h:7482
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
Definition: Type.cpp:2853
QualType(const Type *Ptr, unsigned Quals)
Definition: Type.h:964
QualType getNonPackExpansionType() const
Remove an outer pack expansion type (if any) from this type.
Definition: Type.cpp:3476
bool isMoreQualifiedThan(QualType Other) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:7542
SplitQualType getSplitUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7471
bool isCXX11PODType(const ASTContext &Context) const
Return true if this is a POD type according to the more relaxed rules of the C++11 standard,...
Definition: Type.cpp:3018
bool mayBeNotDynamicClass() const
Returns true if it is not a class or if the class might not be dynamic.
Definition: Type.cpp:100
bool isConstQualified() const
Determine whether this type is const-qualified.
Definition: Type.h:7443
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition: Type.h:7491
bool isObjCGCWeak() const
true when Type is objc's weak.
Definition: Type.h:1422
QualType substObjCTypeArgs(ASTContext &ctx, ArrayRef< QualType > typeArgs, ObjCSubstitutionContext context) const
Substitute type arguments for the Objective-C type parameters used in the subject type.
Definition: Type.cpp:1596
unsigned getLocalFastQualifiers() const
Definition: Type.h:967
void removeLocalFastQualifiers()
Definition: Type.h:1188
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1619
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
Definition: Type.h:1530
friend bool operator<(const QualType &LHS, const QualType &RHS)
Definition: Type.h:1323
friend bool operator!=(const QualType &LHS, const QualType &RHS)
Definition: Type.h:1320
bool isCanonical() const
Definition: Type.h:7427
StreamedQualTypeHelper stream(const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Definition: Type.h:1383
bool isLocalVolatileQualified() const
Determine whether this particular QualType instance has the "volatile" qualifier set,...
Definition: Type.h:1057
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
Definition: Type.h:1039
unsigned getCVRQualifiers() const
Retrieve the set of CVR (const-volatile-restrict) qualifiers applied to this type.
Definition: Type.h:7416
static void getAsStringInternal(SplitQualType split, std::string &out, const PrintingPolicy &policy)
Definition: Type.h:1355
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
Definition: Type.h:1304
const Type * getTypePtrOrNull() const
Definition: Type.h:7374
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
Definition: Type.h:1327
bool hasNonTrivialObjCLifetime() const
Definition: Type.h:1436
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Definition: Type.cpp:2582
bool hasStrongOrWeakObjCLifetime() const
Definition: Type.h:1440
PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
Definition: Type.cpp:2897
QualType withExactLocalFastQualifiers(unsigned TQs) const
Definition: Type.h:1204
NonConstantStorageReason
Definition: Type.h:1024
@ PCK_Struct
The type is a struct containing a field whose type is neither PCK_Trivial nor PCK_VolatileTrivial.
Definition: Type.h:1502
@ PCK_Trivial
The type does not fall into any of the following categories.
Definition: Type.h:1481
@ PCK_ARCStrong
The type is an Objective-C retainable pointer type that is qualified with the ARC __strong qualifier.
Definition: Type.h:1490
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
Definition: Type.h:1486
@ PCK_ARCWeak
The type is an Objective-C retainable pointer type that is qualified with the ARC __weak qualifier.
Definition: Type.h:1494
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7402
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
Definition: Type.h:7505
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:7310
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:7317
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition: Type.h:7312
bool hasAtomic() const
Definition: Type.h:844
bool hasConst() const
Definition: Type.h:842
QualifiersAndAtomic & operator+=(Qualifiers RHS)
Definition: Type.h:865
bool hasRestrict() const
Definition: Type.h:843
QualifiersAndAtomic withVolatile()
Definition: Type.h:856
QualifiersAndAtomic withAtomic()
Definition: Type.h:863
QualifiersAndAtomic withConst()
Definition: Type.h:859
bool hasVolatile() const
Definition: Type.h:841
QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
Definition: Type.h:836
QualifiersAndAtomic withRestrict()
Definition: Type.h:860
The collection of all-type qualifiers we support.
Definition: Type.h:318
unsigned getCVRQualifiers() const
Definition: Type.h:474
void removeCVRQualifiers(unsigned mask)
Definition: Type.h:481
GC getObjCGCAttr() const
Definition: Type.h:505
friend Qualifiers operator-(Qualifiers L, Qualifiers R)
Compute the difference between two qualifier sets.
Definition: Type.h:794
static Qualifiers fromFastMask(unsigned Mask)
Definition: Type.h:415
void setFastQualifiers(unsigned mask)
Definition: Type.h:606
Qualifiers & operator+=(Qualifiers R)
Definition: Type.h:776
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
Definition: Type.h:370
bool hasOnlyConst() const
Definition: Type.h:444
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
Definition: Type.h:347
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
Definition: Type.h:340
@ OCL_None
There is no lifetime qualification on this type.
Definition: Type.h:336
@ OCL_Weak
Reading or writing from this object requires a barrier call.
Definition: Type.h:350
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
Definition: Type.h:353
void removeObjCLifetime()
Definition: Type.h:537
bool hasTargetSpecificAddressSpace() const
Definition: Type.h:560
bool isStrictSupersetOf(Qualifiers Other) const
Determine whether this set of qualifiers is a strict superset of another set of qualifiers,...
Definition: Type.cpp:60
bool hasNonFastQualifiers() const
Return true if the set contains any qualifiers which require an ExtQuals node to be allocated.
Definition: Type.h:624
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:808
bool isAddressSpaceSupersetOf(Qualifiers other) const
Returns true if the address space in these qualifiers is equal to or a superset of the address space ...
Definition: Type.h:724
bool operator!=(Qualifiers Other) const
Definition: Type.h:772
bool hasConst() const
Definition: Type.h:443
bool hasNonTrivialObjCLifetime() const
True if the lifetime is neither None or ExplicitNone.
Definition: Type.h:545
void addCVRQualifiers(unsigned mask)
Definition: Type.h:488
bool hasCVRQualifiers() const
Definition: Type.h:473
void addConsistentQualifiers(Qualifiers qs)
Add the qualifiers from the given set to this set, given that they don't conflict.
Definition: Type.h:675
void removeFastQualifiers(unsigned mask)
Definition: Type.h:610
void removeFastQualifiers()
Definition: Type.h:614
bool hasQualifiers() const
Return true if the set contains any qualifiers.
Definition: Type.h:632
void removeCVRQualifiers()
Definition: Type.h:485
Qualifiers withVolatile() const
Definition: Type.h:457
void addCVRUQualifiers(unsigned mask)
Definition: Type.h:492
void addRestrict()
Definition: Type.h:466
bool hasUnaligned() const
Definition: Type.h:497
unsigned getAddressSpaceAttributePrintValue() const
Get the address space attribute value to be printed by diagnostics.
Definition: Type.h:564
bool hasAddressSpace() const
Definition: Type.h:556
bool hasRestrict() const
Definition: Type.h:463
void removeObjCGCAttr()
Definition: Type.h:509
void removeUnaligned()
Definition: Type.h:501
Qualifiers withoutAddressSpace() const
Definition: Type.h:524
void removeConst()
Definition: Type.h:445
void removeRestrict()
Definition: Type.h:465
unsigned getFastQualifiers() const
Definition: Type.h:605
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool appendSpaceIfNonEmpty=false) const
Qualifiers & operator-=(Qualifiers R)
Definition: Type.h:788
void removeAddressSpace()
Definition: Type.h:582
@ FastWidth
The width of the "fast" qualifier mask.
Definition: Type.h:362
@ MaxAddressSpace
The maximum supported address space number.
Definition: Type.h:359
@ FastMask
The fast qualifier mask.
Definition: Type.h:365
void addConst()
Definition: Type.h:446
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
Definition: Type.h:636
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:421
void addUnaligned()
Definition: Type.h:502
void removePointerAuth()
Definition: Type.h:596
void setAddressSpace(LangAS space)
Definition: Type.h:577
static bool isAddressSpaceSupersetOf(LangAS A, LangAS B)
Returns true if address space A is equal to or a superset of B.
Definition: Type.h:694
unsigned getCVRUQualifiers() const
Definition: Type.h:475
bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const
bool hasVolatile() const
Definition: Type.h:453
PointerAuthQualifier getPointerAuth() const
Definition: Type.h:589
void setObjCGCAttr(GC type)
Definition: Type.h:506
Qualifiers withConst() const
Definition: Type.h:447
bool hasObjCGCAttr() const
Definition: Type.h:504
uint64_t getAsOpaqueValue() const
Definition: Type.h:441
void setCVRQualifiers(unsigned mask)
Definition: Type.h:477
bool hasObjCLifetime() const
Definition: Type.h:530
ObjCLifetime getObjCLifetime() const
Definition: Type.h:531
Qualifiers withoutObjCLifetime() const
Definition: Type.h:519
Qualifiers withoutObjCGCAttr() const
Definition: Type.h:514
static Qualifiers fromCVRUMask(unsigned CVRU)
Definition: Type.h:427
friend Qualifiers operator+(Qualifiers L, Qualifiers R)
Definition: Type.h:783
bool empty() const
Definition: Type.h:633
void addAddressSpace(LangAS space, bool AllowDefaultAddrSpace=false)
Definition: Type.h:583
void setUnaligned(bool flag)
Definition: Type.h:498
void addFastQualifiers(unsigned mask)
Definition: Type.h:617
void removeVolatile()
Definition: Type.h:455
std::string getAsString() const
Qualifiers withRestrict() const
Definition: Type.h:467
void addPointerAuth(PointerAuthQualifier Q)
Definition: Type.h:597
void addObjCGCAttr(GC type)
Definition: Type.h:510
bool hasPointerAuth() const
Definition: Type.h:588
bool operator==(Qualifiers Other) const
Definition: Type.h:771
bool compatiblyIncludes(Qualifiers other) const
Determines if these qualifiers compatibly include another set.
Definition: Type.h:731
void removeQualifiers(Qualifiers Q)
Remove the qualifiers from the given set from this set.
Definition: Type.h:655
LangAS getAddressSpace() const
Definition: Type.h:557
bool hasOnlyVolatile() const
Definition: Type.h:454
void setPointerAuth(PointerAuthQualifier Q)
Definition: Type.h:592
bool compatiblyIncludesObjCLifetime(Qualifiers other) const
Determines if these qualifiers compatibly include another set of qualifiers from the narrow perspecti...
Definition: Type.h:754
Qualifiers getNonFastQualifiers() const
Definition: Type.h:625
static Qualifiers fromOpaqueValue(uint64_t opaque)
Definition: Type.h:434
bool hasStrongOrWeakObjCLifetime() const
True if the lifetime is either strong or weak.
Definition: Type.h:551
static std::string getAddrSpaceAsString(LangAS AS)
void addVolatile()
Definition: Type.h:456
bool hasFastQualifiers() const
Definition: Type.h:604
bool hasOnlyRestrict() const
Definition: Type.h:464
void addObjCLifetime(ObjCLifetime type)
Definition: Type.h:538
void setObjCLifetime(ObjCLifetime type)
Definition: Type.h:534
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3453
static bool classof(const Type *T)
Definition: Type.h:3463
QualType desugar() const
Definition: Type.h:3461
bool isSugared() const
Definition: Type.h:3460
Represents a struct/union/class.
Definition: Decl.h:4171
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5560
RecordDecl * getDecl() const
Definition: Type.h:5570
RecordType(const RecordDecl *D)
Definition: Type.h:5564
bool isSugared() const
Definition: Type.h:5578
QualType desugar() const
Definition: Type.h:5579
RecordType(TypeClass TC, RecordDecl *D)
Definition: Type.h:5566
static bool classof(const Type *T)
Definition: Type.h:5581
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3391
bool isInnerRef() const
Definition: Type.h:3405
QualType getPointeeType() const
Definition: Type.h:3409
ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, bool SpelledAsLValue)
Definition: Type.h:3395
static bool classof(const Type *T)
Definition: Type.h:3428
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3407
bool isSpelledAsLValue() const
Definition: Type.h:3404
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3417
static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee, bool SpelledAsLValue)
Definition: Type.h:3421
Encodes a location in the source.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
The streaming interface shared between DiagnosticBuilder and PartialDiagnostic.
Definition: Diagnostic.h:1121
void AddTaggedVal(uint64_t V, DiagnosticsEngine::ArgumentKind Kind) const
Definition: Diagnostic.h:1195
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:5900
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5926
static bool classof(const Type *T)
Definition: Type.h:5945
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5830
std::optional< unsigned > getPackIndex() const
Definition: Type.h:5860
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5869
static bool classof(const Type *T)
Definition: Type.h:5883
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5842
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5858
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5851
QualType desugar() const
Definition: Type.h:5867
static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement, const Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex)
Definition: Type.h:5874
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3587
TagDecl * getDecl() const
Definition: Type.cpp:4022
static bool classof(const Type *T)
Definition: Type.h:5553
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
Represents a template argument.
Definition: TemplateBase.h:61
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
void Profile(llvm::FoldingSetNodeID &ID)
bool isDependent() const
Determines whether this is a dependent template name.
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6100
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6168
static bool classof(const Type *T)
Definition: Type.h:6186
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:6166
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:6159
QualType desugar() const
Definition: Type.h:6177
bool isCurrentInstantiation() const
True if this template specialization type matches a current instantiation in the context in which it ...
Definition: Type.h:6140
Declaration of a template type parameter.
QualType desugar() const
Definition: Type.h:5800
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5793
bool isParameterPack() const
Definition: Type.h:5791
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5802
unsigned getIndex() const
Definition: Type.h:5790
bool isSugared() const
Definition: Type.h:5799
static bool classof(const Type *T)
Definition: Type.h:5815
static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *TTPDecl)
Definition: Type.h:5806
CanonicalTTPTInfo CanTTPTInfo
Definition: Type.h:5760
TemplateTypeParmDecl * TTPDecl
Definition: Type.h:5763
unsigned getDepth() const
Definition: Type.h:5789
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: Type.h:3178
llvm::PointerIntPair< ValueDecl *, 1, unsigned > BaseTy
Definition: Type.h:3180
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5285
static bool classof(const Type *T)
Definition: Type.h:5308
Expr * getUnderlyingExpr() const
Definition: Type.h:5294
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5297
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5333
static bool classof(const Type *T)
Definition: Type.h:5365
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5360
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:5357
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:5351
QualType getUnmodifiedType() const
Definition: Type.h:5348
The type-property cache.
Definition: Type.cpp:4382
A container of type source information.
Definition: Type.h:7341
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7352
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition: Type.h:7358
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:6331
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence)
Definition: Type.h:6333
static CannotCastToThisType classof(const Type *)
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:6363
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6340
FunctionTypeBitfields store various bits belonging to FunctionProtoType.
Definition: Type.h:1919
The base class of the type hierarchy.
Definition: Type.h:1813
bool isIncompleteOrObjectType() const
Return true if this is an incomplete or object type, in other words, not a function type.
Definition: Type.h:2400
bool isDecltypeType() const
Definition: Type.h:7814
bool isDependentSizedArrayType() const
Definition: Type.h:7709
bool isFixedPointOrIntegerType() const
Return true if this is a fixed point or integer type.
Definition: Type.h:7999
bool isBlockPointerType() const
Definition: Type.h:7631
bool isVoidType() const
Definition: Type.h:7938
TypedefBitfields TypedefBits
Definition: Type.h:2235
UsingBitfields UsingBits
Definition: Type.h:2236
bool isBooleanType() const
Definition: Type.h:8066
bool isFunctionReferenceType() const
Definition: Type.h:7664
Type(const Type &)=delete
bool isObjCBuiltinType() const
Definition: Type.h:7810
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8116
bool isIncompleteArrayType() const
Definition: Type.h:7697
bool isPlaceholderType() const
Test for a type which does not represent an actual type-system type but is instead used as a placehol...
Definition: Type.h:7914
bool isFloat16Type() const
Definition: Type.h:7947
ReferenceTypeBitfields ReferenceTypeBits
Definition: Type.h:2240
ElaboratedTypeBitfields ElaboratedTypeBits
Definition: Type.h:2242
ArrayTypeBitfields ArrayTypeBits
Definition: Type.h:2230
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
Definition: Type.h:8235
Type(Type &&)=delete
bool isDependentAddressSpaceType() const
Definition: Type.h:7755
bool isUndeducedAutoType() const
Definition: Type.h:7776
bool isRValueReferenceType() const
Definition: Type.h:7643
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition: Type.h:7586
VectorTypeBitfields VectorTypeBits
Definition: Type.h:2243
bool isConstantArrayType() const
Definition: Type.h:7693
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
Definition: Type.h:8096
Type & operator=(const Type &)=delete
bool isArrayType() const
Definition: Type.h:7689
bool isFunctionPointerType() const
Definition: Type.h:7657
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2765
bool isConvertibleToFixedPointType() const
Return true if this can be converted to (or from) a fixed point type.
Definition: Type.h:8003
bool isConstantMatrixType() const
Definition: Type.h:7751
bool isPointerType() const
Definition: Type.h:7623
TypeWithKeywordBitfields TypeWithKeywordBits
Definition: Type.h:2241
bool isArrayParameterType() const
Definition: Type.h:7705
TypeOfBitfields TypeOfBits
Definition: Type.h:2234
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition: Type.h:7978
bool isObjCSelType() const
Definition: Type.h:7804
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8226
BuiltinTypeBitfields BuiltinTypeBits
Definition: Type.h:2237
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition: Type.h:7927
bool isReferenceType() const
Definition: Type.h:7635
bool isSignedFixedPointType() const
Return true if this is a fixed point type that is signed according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:8019
bool isObjectPointerType() const
Definition: Type.h:7647
bool isEnumeralType() const
Definition: Type.h:7721
bool isVisibilityExplicit() const
Return true if the visibility was explicitly set is the code.
Definition: Type.h:2894
void addDependence(TypeDependence D)
Definition: Type.h:2287
ConstantArrayTypeBitfields ConstantArrayTypeBits
Definition: Type.h:2231
Type(TypeClass tc, QualType canon, TypeDependence Dependence)
Definition: Type.h:2264
bool isScalarType() const
Definition: Type.h:8037
bool isVariableArrayType() const
Definition: Type.h:7701
bool isFloat128Type() const
Definition: Type.h:7963
bool isClkEventT() const
Definition: Type.h:7840
CountAttributedTypeBitfields CountAttributedTypeBits
Definition: Type.h:2250
bool isObjCQualifiedIdType() const
Definition: Type.h:7780
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:695
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition: Type.h:8053
bool isExtVectorType() const
Definition: Type.h:7733
bool isExtVectorBoolType() const
Definition: Type.h:7737
bool isObjCObjectOrInterfaceType() const
Definition: Type.h:7767
bool isSampledImageType() const
Definition: Type.h:7859
bool isImageType() const
Definition: Type.h:7852
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
Definition: Type.h:7932
bool isOCLIntelSubgroupAVCType() const
Definition: Type.h:7883
bool isPipeType() const
Definition: Type.h:7869
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2668
bool isMemberDataPointerType() const
Definition: Type.h:7682
bool isLValueReferenceType() const
Definition: Type.h:7639
bool isBitIntType() const
Definition: Type.h:7873
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition: Type.h:7907
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition: Type.h:7713
bool isOpenCLSpecificType() const
Definition: Type.h:7898
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2660
bool isFloat32Type() const
Definition: Type.h:7951
TypeBitfields TypeBits
Definition: Type.h:2229
bool isAnyComplexType() const
Definition: Type.h:7725
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:7991
bool isHalfType() const
Definition: Type.h:7942
DependentTemplateSpecializationTypeBitfields DependentTemplateSpecializationTypeBits
Definition: Type.h:2248
Type * this_()
Definition: Type.h:2281
bool isSaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:8007
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2320
Type & operator=(Type &&)=delete
const BuiltinType * getAsPlaceholderType() const
Definition: Type.h:7920
QualType getCanonicalTypeInternal() const
Definition: Type.h:2943
bool isTemplateTypeParmType() const
Definition: Type.h:7903
bool isQueueT() const
Definition: Type.h:7844
bool isCompoundType() const
Tests whether the type is categorized as a compound type.
Definition: Type.h:7597
bool containsErrors() const
Whether this type is an error type.
Definition: Type.h:2654
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8109
bool isMemberPointerType() const
Definition: Type.h:7671
bool isAtomicType() const
Definition: Type.h:7772
AttributedTypeBitfields AttributedTypeBits
Definition: Type.h:2232
bool isFunctionProtoType() const
Definition: Type.h:2494
bool isIbm128Type() const
Definition: Type.h:7967
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:8079
bool isObjCIdType() const
Definition: Type.h:7792
bool isMatrixType() const
Definition: Type.h:7747
PackExpansionTypeBitfields PackExpansionTypeBits
Definition: Type.h:2249
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2678
bool isUnsaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:8015
bool isObjCObjectType() const
Definition: Type.h:7763
bool isFromAST() const
Whether this type comes from an AST file.
Definition: Type.h:2303
const ArrayType * getAsArrayTypeUnsafe() const
A variant of getAs<> for array types which silently discards qualifiers from the outermost type.
Definition: Type.h:8212
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition: Type.h:8072
bool isObjectType() const
Determine whether this type is an object type.
Definition: Type.h:2405
bool isEventT() const
Definition: Type.h:7836
bool isDoubleType() const
Definition: Type.h:7955
FunctionTypeBitfields FunctionTypeBits
Definition: Type.h:2238
bool isBFloat16Type() const
Definition: Type.h:7959
void setDependence(TypeDependence D)
Definition: Type.h:2283
const T * getAsAdjusted() const
Member-template getAsAdjusted<specific type>.
Definition: Type.h:8176
bool isFunctionType() const
Definition: Type.h:7619
bool isObjCObjectPointerType() const
Definition: Type.h:7759
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits
Definition: Type.h:2244
TypeDependence getDependence() const
Definition: Type.h:2649
Visibility getVisibility() const
Determine the visibility of this type.
Definition: Type.h:2889
bool isMemberFunctionPointerType() const
Definition: Type.h:7675
bool isUnsignedFixedPointType() const
Return true if this is a fixed point type that is unsigned according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition: Type.h:8033
bool isVectorType() const
Definition: Type.h:7729
bool isObjCQualifiedClassType() const
Definition: Type.h:7786
bool isObjCClassType() const
Definition: Type.h:7798
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-ARC __unsafe_unretained qualifier?
Definition: Type.h:2551
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:2239
ScalarTypeKind
Definition: Type.h:2633
@ STK_FloatingComplex
Definition: Type.h:2642
@ STK_Floating
Definition: Type.h:2640
@ STK_BlockPointer
Definition: Type.h:2635
@ STK_Bool
Definition: Type.h:2638
@ STK_ObjCObjectPointer
Definition: Type.h:2636
@ STK_IntegralComplex
Definition: Type.h:2641
@ STK_CPointer
Definition: Type.h:2634
@ STK_Integral
Definition: Type.h:2639
@ STK_MemberPointer
Definition: Type.h:2637
bool isOCLExtOpaqueType() const
Definition: Type.h:7891
bool isAnyPointerType() const
Definition: Type.h:7627
bool isRealType() const
Definition: Type.cpp:2261
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:4954
TypeClass getTypeClass() const
Definition: Type.h:2300
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2326
bool isSubscriptableVectorType() const
Definition: Type.h:7743
bool isSamplerT() const
Definition: Type.h:7832
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8159
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits
Definition: Type.h:2245
bool isNullPtrType() const
Definition: Type.h:7971
bool isRecordType() const
Definition: Type.h:7717
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition: Type.h:2246
bool isTypedefNameType() const
Determines whether this type is written as a typedef-name.
Definition: Type.h:8087
bool isFunctionNoProtoType() const
Definition: Type.h:2493
bool isReserveIDT() const
Definition: Type.h:7848
bool hasObjCPointerRepresentation() const
Whether this type can represent an objective pointer type for the purpose of GC'ability.
Definition: Type.h:8105
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
Definition: Type.h:8100
AutoTypeBitfields AutoTypeBits
Definition: Type.h:2233
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3435
TypedefNameDecl * getDecl() const
Definition: Type.h:5228
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5238
static bool classof(const Type *T)
Definition: Type.h:5248
bool typeMatchesDecl() const
Definition: Type.h:5236
bool isSugared() const
Definition: Type.h:5230
static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl, QualType Underlying)
Definition: Type.h:5241
A unary type transform, which is a type constructed from another.
Definition: Type.h:5477
QualType getUnderlyingType() const
Definition: Type.h:5503
QualType getBaseType() const
Definition: Type.h:5504
UTTKind getUTTKind() const
Definition: Type.h:5506
bool isSugared() const
Definition: Type.h:5500
static bool classof(const Type *T)
Definition: Type.h:5508
QualType desugar() const
Definition: Type.h:5501
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5155
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5175
QualType desugar() const
Definition: Type.h:5169
static void Profile(llvm::FoldingSetNodeID &ID, UnresolvedUsingTypenameDecl *D)
Definition: Type.h:5179
static bool classof(const Type *T)
Definition: Type.h:5171
bool isSugared() const
Definition: Type.h:5168
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:5166
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3959
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
QualType desugar() const
Definition: Type.h:5201
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5206
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:5195
bool isSugared() const
Definition: Type.h:5198
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found, QualType Underlying)
Definition: Type.h:5209
static bool classof(const Type *T)
Definition: Type.h:5214
bool typeMatchesDecl() const
Definition: Type.h:5204
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:707
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3758
SourceRange getBracketsRange() const
Definition: Type.h:3783
SourceLocation getLBracketLoc() const
Definition: Type.h:3784
static bool classof(const Type *T)
Definition: Type.h:3790
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3794
SourceLocation getRBracketLoc() const
Definition: Type.h:3785
QualType desugar() const
Definition: Type.h:3788
Expr * getSizeExpr() const
Definition: Type.h:3777
bool isSugared() const
Definition: Type.h:3787
Represents a GCC generic vector type.
Definition: Type.h:3980
unsigned getNumElements() const
Definition: Type.h:3995
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4004
bool isSugared() const
Definition: Type.h:3997
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumElements, TypeClass TypeClass, VectorKind VecKind)
Definition: Type.h:4009
VectorKind getVectorKind() const
Definition: Type.h:4000
QualType ElementType
The element type of the vector.
Definition: Type.h:3985
QualType desugar() const
Definition: Type.h:3998
QualType getElementType() const
Definition: Type.h:3994
static bool classof(const Type *T)
Definition: Type.h:4018
Defines the Linkage enumeration and various utility functions.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
Matches all kinds of arrays.
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:65
static bool isQualifier(const FormatToken *const Tok)
llvm::APInt APInt
Definition: Integral.h:29
constexpr bool isIntegralType(PrimType T)
Definition: PrimType.h:70
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
TypeDependenceScope::TypeDependence TypeDependence
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1772
@ GNUAutoType
__auto_type (GNU extension)
@ DecltypeAuto
decltype(auto)
bool isTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:77
CanThrowResult
Possible results from evaluation of a noexcept expression.
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)
Definition: Type.h:7523
bool isDynamicExceptionSpec(ExceptionSpecificationType ESpecType)
NullabilityKind
Describes the nullability of a particular type.
Definition: Specifiers.h:333
@ Nullable
Values of this type can be null.
@ Unspecified
Whether values of this type can be null is (explicitly) unspecified.
@ NonNull
Values of this type can never be null.
RefQualifierKind
The kind of C++11 ref-qualifier associated with a function type.
Definition: Type.h:1760
@ RQ_None
No ref-qualifier was provided.
Definition: Type.h:1762
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
Definition: Type.h:1765
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
Definition: Type.h:1768
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition: Decl.h:5035
ExprDependence computeDependence(FullExpr *E)
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:921
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition: CallGraph.h:223
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
TypeDependence toTypeDependence(ExprDependence D)
const StreamingDiagnostic & operator<<(const StreamingDiagnostic &DB, const ASTContext::SectionInfo &Section)
Insertion operator for diagnostics.
unsigned toTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:81
Linkage
Describes the different kinds of linkage (C++ [basic.link], C99 6.2.2) that an entity may have.
Definition: Linkage.h:24
ObjCSubstitutionContext
The kind of type we are substituting Objective-C type arguments into.
Definition: Type.h:903
@ Superclass
The superclass of a type.
@ Ordinary
An ordinary type.
@ Property
The type of a property.
@ Parameter
The parameter type of a method or function.
@ Result
The result type of a method or function.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3526
ParameterABI
Kinds of parameter ABI.
Definition: Specifiers.h:363
@ Ordinary
This parameter uses ordinary ABI rules for its type.
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
TagTypeKind
The kind of a tag type.
Definition: Type.h:6310
constexpr unsigned PointerAuthKeyNone
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:5043
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:5007
bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg, const NamedDecl *Param, ArrayRef< TemplateArgument > Args, unsigned Depth)
Make a best-effort determination of whether the type T can be produced by substituting Args into the ...
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:8156
@ TypeAlignment
Definition: Type.h:73
@ TypeAlignmentInBits
Definition: Type.h:72
bool isPtrSizeAddressSpace(LangAS AS)
Definition: AddressSpaces.h:91
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
PointerAuthenticationMode
Definition: LangOptions.h:60
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
@ CC_C
Definition: Specifiers.h:276
VectorKind
Definition: Type.h:3943
@ AltiVecBool
is AltiVec 'vector bool ...'
@ SveFixedLengthData
is AArch64 SVE fixed-length data vector
@ AltiVecVector
is AltiVec vector
@ AltiVecPixel
is AltiVec 'vector Pixel'
@ Neon
is ARM Neon vector
@ Generic
not a target-specific vector type
@ RVVFixedLengthData
is RISC-V RVV fixed-length data vector
@ RVVFixedLengthMask
is RISC-V RVV fixed-length mask vector
@ NeonPoly
is ARM Neon polynomial vector
@ SveFixedLengthPredicate
is AArch64 SVE fixed-length predicate vector
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6285
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Union
The "union" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
TypeDependence toSyntacticDependence(TypeDependence D)
@ Other
Other implicit parameter.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:34
unsigned long uint64_t
long int64_t
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
#define false
Definition: stdbool.h:26
#define bool
Definition: stdbool.h:24
Holds information about the various types of exception specification.
Definition: Type.h:4718
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition: Type.h:4738
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4720
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4723
Extra information about a function prototype.
Definition: Type.h:4746
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4753
bool requiresFunctionProtoTypeArmAttributes() const
Definition: Type.h:4776
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:4754
bool requiresFunctionProtoTypeExtraBitfields() const
Definition: Type.h:4771
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
Definition: Type.h:4780
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:4765
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4747
A simple holder for a QualType representing a type in an exception specification.
Definition: Type.h:4505
A holder for Arm type attributes as described in the Arm C/C++ Language extensions which are not part...
Definition: Type.h:4561
unsigned AArch64SMEAttributes
Any AArch64 SME ACLE type attributes that need to be propagated on declarations and function pointers...
Definition: Type.h:4564
A simple holder for various uncommon bits which do not fit in FunctionTypeBitfields.
Definition: Type.h:4510
unsigned NumExceptionType
The number of types in the exception specification.
Definition: Type.h:4514
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
A std::pair-like structure for storing a qualified type split into its local qualifiers and its local...
Definition: Type.h:873
std::pair< const Type *, Qualifiers > asPair() const
Definition: Type.h:886
SplitQualType(const Type *ty, Qualifiers qs)
Definition: Type.h:881
SplitQualType getSingleStepDesugaredType() const
Definition: Type.h:7363
friend bool operator==(SplitQualType a, SplitQualType b)
Definition: Type.h:890
const Type * Ty
The locally-unqualified type.
Definition: Type.h:875
friend bool operator!=(SplitQualType a, SplitQualType b)
Definition: Type.h:893
Qualifiers Quals
The local qualifiers.
Definition: Type.h:878
static void * getAsVoidPointer(::clang::ExtQuals *P)
Definition: Type.h:100
static inline ::clang::ExtQuals * getFromVoidPointer(void *P)
Definition: Type.h:102
static void * getAsVoidPointer(::clang::Type *P)
Definition: Type.h:89
static inline ::clang::Type * getFromVoidPointer(void *P)
Definition: Type.h:91
static clang::QualType getFromVoidPointer(void *P)
Definition: Type.h:1652
static void * getAsVoidPointer(clang::QualType P)
Definition: Type.h:1648
static SimpleType getSimplifiedValue(::clang::QualType Val)
Definition: Type.h:1640