clang  17.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"
28 #include "clang/Basic/Linkage.h"
31 #include "clang/Basic/Specifiers.h"
32 #include "clang/Basic/Visibility.h"
33 #include "llvm/ADT/APInt.h"
34 #include "llvm/ADT/APSInt.h"
35 #include "llvm/ADT/ArrayRef.h"
36 #include "llvm/ADT/FoldingSet.h"
37 #include "llvm/ADT/PointerIntPair.h"
38 #include "llvm/ADT/PointerUnion.h"
39 #include "llvm/ADT/StringRef.h"
40 #include "llvm/ADT/Twine.h"
41 #include "llvm/ADT/iterator_range.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Compiler.h"
44 #include "llvm/Support/ErrorHandling.h"
45 #include "llvm/Support/PointerLikeTypeTraits.h"
46 #include "llvm/Support/TrailingObjects.h"
47 #include "llvm/Support/type_traits.h"
48 #include <cassert>
49 #include <cstddef>
50 #include <cstdint>
51 #include <cstring>
52 #include <optional>
53 #include <string>
54 #include <type_traits>
55 #include <utility>
56 
57 namespace clang {
58 
59 class BTFTypeTagAttr;
60 class ExtQuals;
61 class QualType;
62 class ConceptDecl;
63 class TagDecl;
64 class TemplateParameterList;
65 class Type;
66 
67 enum {
70 };
71 
72 namespace serialization {
73  template <class T> class AbstractTypeReader;
74  template <class T> class AbstractTypeWriter;
75 }
76 
77 } // namespace clang
78 
79 namespace llvm {
80 
81  template <typename T>
82  struct PointerLikeTypeTraits;
83  template<>
85  static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
86 
88  return static_cast< ::clang::Type*>(P);
89  }
90 
91  static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
92  };
93 
94  template<>
96  static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
97 
98  static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
99  return static_cast< ::clang::ExtQuals*>(P);
100  }
101 
102  static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits;
103  };
104 
105 } // namespace llvm
106 
107 namespace clang {
108 
109 class ASTContext;
110 template <typename> class CanQual;
111 class CXXRecordDecl;
112 class DeclContext;
113 class EnumDecl;
114 class Expr;
115 class ExtQualsTypeCommonBase;
116 class FunctionDecl;
117 class IdentifierInfo;
118 class NamedDecl;
119 class ObjCInterfaceDecl;
120 class ObjCProtocolDecl;
121 class ObjCTypeParamDecl;
122 struct PrintingPolicy;
123 class RecordDecl;
124 class Stmt;
125 class TagDecl;
126 class TemplateArgument;
127 class TemplateArgumentListInfo;
128 class TemplateArgumentLoc;
129 class TemplateTypeParmDecl;
130 class TypedefNameDecl;
131 class UnresolvedUsingTypenameDecl;
132 class UsingShadowDecl;
133 
134 using CanQualType = CanQual<Type>;
135 
136 // Provide forward declarations for all of the *Type classes.
137 #define TYPE(Class, Base) class Class##Type;
138 #include "clang/AST/TypeNodes.inc"
139 
140 /// The collection of all-type qualifiers we support.
141 /// Clang supports five independent qualifiers:
142 /// * C99: const, volatile, and restrict
143 /// * MS: __unaligned
144 /// * Embedded C (TR18037): address spaces
145 /// * Objective C: the GC attributes (none, weak, or strong)
146 class Qualifiers {
147 public:
148  enum TQ { // NOTE: These flags must be kept in sync with DeclSpec::TQ.
149  Const = 0x1,
150  Restrict = 0x2,
151  Volatile = 0x4,
153  };
154 
155  enum GC {
156  GCNone = 0,
159  };
160 
162  /// There is no lifetime qualification on this type.
164 
165  /// This object can be modified without requiring retains or
166  /// releases.
168 
169  /// Assigning into this object requires the old value to be
170  /// released and the new value to be retained. The timing of the
171  /// release of the old value is inexact: it may be moved to
172  /// immediately after the last known point where the value is
173  /// live.
175 
176  /// Reading or writing from this object requires a barrier call.
178 
179  /// Assigning into this object requires a lifetime extension.
181  };
182 
183  enum {
184  /// The maximum supported address space number.
185  /// 23 bits should be enough for anyone.
186  MaxAddressSpace = 0x7fffffu,
187 
188  /// The width of the "fast" qualifier mask.
190 
191  /// The fast qualifier mask.
192  FastMask = (1 << FastWidth) - 1
193  };
194 
195  /// Returns the common set of qualifiers while removing them from
196  /// the given sets.
198  // If both are only CVR-qualified, bit operations are sufficient.
199  if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
200  Qualifiers Q;
201  Q.Mask = L.Mask & R.Mask;
202  L.Mask &= ~Q.Mask;
203  R.Mask &= ~Q.Mask;
204  return Q;
205  }
206 
207  Qualifiers Q;
208  unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
209  Q.addCVRQualifiers(CommonCRV);
210  L.removeCVRQualifiers(CommonCRV);
211  R.removeCVRQualifiers(CommonCRV);
212 
213  if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
215  L.removeObjCGCAttr();
216  R.removeObjCGCAttr();
217  }
218 
219  if (L.getObjCLifetime() == R.getObjCLifetime()) {
221  L.removeObjCLifetime();
222  R.removeObjCLifetime();
223  }
224 
225  if (L.getAddressSpace() == R.getAddressSpace()) {
227  L.removeAddressSpace();
228  R.removeAddressSpace();
229  }
230  return Q;
231  }
232 
233  static Qualifiers fromFastMask(unsigned Mask) {
234  Qualifiers Qs;
235  Qs.addFastQualifiers(Mask);
236  return Qs;
237  }
238 
239  static Qualifiers fromCVRMask(unsigned CVR) {
240  Qualifiers Qs;
241  Qs.addCVRQualifiers(CVR);
242  return Qs;
243  }
244 
245  static Qualifiers fromCVRUMask(unsigned CVRU) {
246  Qualifiers Qs;
247  Qs.addCVRUQualifiers(CVRU);
248  return Qs;
249  }
250 
251  // Deserialize qualifiers from an opaque representation.
252  static Qualifiers fromOpaqueValue(unsigned opaque) {
253  Qualifiers Qs;
254  Qs.Mask = opaque;
255  return Qs;
256  }
257 
258  // Serialize these qualifiers into an opaque representation.
259  unsigned getAsOpaqueValue() const {
260  return Mask;
261  }
262 
263  bool hasConst() const { return Mask & Const; }
264  bool hasOnlyConst() const { return Mask == Const; }
265  void removeConst() { Mask &= ~Const; }
266  void addConst() { Mask |= Const; }
268  Qualifiers Qs = *this;
269  Qs.addConst();
270  return Qs;
271  }
272 
273  bool hasVolatile() const { return Mask & Volatile; }
274  bool hasOnlyVolatile() const { return Mask == Volatile; }
275  void removeVolatile() { Mask &= ~Volatile; }
276  void addVolatile() { Mask |= Volatile; }
278  Qualifiers Qs = *this;
279  Qs.addVolatile();
280  return Qs;
281  }
282 
283  bool hasRestrict() const { return Mask & Restrict; }
284  bool hasOnlyRestrict() const { return Mask == Restrict; }
285  void removeRestrict() { Mask &= ~Restrict; }
286  void addRestrict() { Mask |= Restrict; }
288  Qualifiers Qs = *this;
289  Qs.addRestrict();
290  return Qs;
291  }
292 
293  bool hasCVRQualifiers() const { return getCVRQualifiers(); }
294  unsigned getCVRQualifiers() const { return Mask & CVRMask; }
295  unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); }
296 
297  void setCVRQualifiers(unsigned mask) {
298  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
299  Mask = (Mask & ~CVRMask) | mask;
300  }
301  void removeCVRQualifiers(unsigned mask) {
302  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
303  Mask &= ~mask;
304  }
307  }
308  void addCVRQualifiers(unsigned mask) {
309  assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
310  Mask |= mask;
311  }
312  void addCVRUQualifiers(unsigned mask) {
313  assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
314  Mask |= mask;
315  }
316 
317  bool hasUnaligned() const { return Mask & UMask; }
318  void setUnaligned(bool flag) {
319  Mask = (Mask & ~UMask) | (flag ? UMask : 0);
320  }
321  void removeUnaligned() { Mask &= ~UMask; }
322  void addUnaligned() { Mask |= UMask; }
323 
324  bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
325  GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
327  Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
328  }
331  assert(type);
333  }
335  Qualifiers qs = *this;
336  qs.removeObjCGCAttr();
337  return qs;
338  }
340  Qualifiers qs = *this;
341  qs.removeObjCLifetime();
342  return qs;
343  }
345  Qualifiers qs = *this;
346  qs.removeAddressSpace();
347  return qs;
348  }
349 
350  bool hasObjCLifetime() const { return Mask & LifetimeMask; }
352  return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
353  }
355  Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
356  }
359  assert(type);
360  assert(!hasObjCLifetime());
361  Mask |= (type << LifetimeShift);
362  }
363 
364  /// True if the lifetime is neither None or ExplicitNone.
366  ObjCLifetime lifetime = getObjCLifetime();
367  return (lifetime > OCL_ExplicitNone);
368  }
369 
370  /// True if the lifetime is either strong or weak.
372  ObjCLifetime lifetime = getObjCLifetime();
373  return (lifetime == OCL_Strong || lifetime == OCL_Weak);
374  }
375 
376  bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
378  return static_cast<LangAS>(Mask >> AddressSpaceShift);
379  }
382  }
383  /// Get the address space attribute value to be printed by diagnostics.
385  auto Addr = getAddressSpace();
386  // This function is not supposed to be used with language specific
387  // address spaces. If that happens, the diagnostic message should consider
388  // printing the QualType instead of the address space value.
389  assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace());
390  if (Addr != LangAS::Default)
391  return toTargetAddressSpace(Addr);
392  // TODO: The diagnostic messages where Addr may be 0 should be fixed
393  // since it cannot differentiate the situation where 0 denotes the default
394  // address space or user specified __attribute__((address_space(0))).
395  return 0;
396  }
397  void setAddressSpace(LangAS space) {
398  assert((unsigned)space <= MaxAddressSpace);
399  Mask = (Mask & ~AddressSpaceMask)
400  | (((uint32_t) space) << AddressSpaceShift);
401  }
403  void addAddressSpace(LangAS space) {
404  assert(space != LangAS::Default);
405  setAddressSpace(space);
406  }
407 
408  // Fast qualifiers are those that can be allocated directly
409  // on a QualType object.
410  bool hasFastQualifiers() const { return getFastQualifiers(); }
411  unsigned getFastQualifiers() const { return Mask & FastMask; }
412  void setFastQualifiers(unsigned mask) {
413  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
414  Mask = (Mask & ~FastMask) | mask;
415  }
416  void removeFastQualifiers(unsigned mask) {
417  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
418  Mask &= ~mask;
419  }
422  }
423  void addFastQualifiers(unsigned mask) {
424  assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
425  Mask |= mask;
426  }
427 
428  /// Return true if the set contains any qualifiers which require an ExtQuals
429  /// node to be allocated.
430  bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
432  Qualifiers Quals = *this;
433  Quals.setFastQualifiers(0);
434  return Quals;
435  }
436 
437  /// Return true if the set contains any qualifiers.
438  bool hasQualifiers() const { return Mask; }
439  bool empty() const { return !Mask; }
440 
441  /// Add the qualifiers from the given set to this set.
443  // If the other set doesn't have any non-boolean qualifiers, just
444  // bit-or it in.
445  if (!(Q.Mask & ~CVRMask))
446  Mask |= Q.Mask;
447  else {
448  Mask |= (Q.Mask & CVRMask);
449  if (Q.hasAddressSpace())
451  if (Q.hasObjCGCAttr())
453  if (Q.hasObjCLifetime())
455  }
456  }
457 
458  /// Remove the qualifiers from the given set from this set.
460  // If the other set doesn't have any non-boolean qualifiers, just
461  // bit-and the inverse in.
462  if (!(Q.Mask & ~CVRMask))
463  Mask &= ~Q.Mask;
464  else {
465  Mask &= ~(Q.Mask & CVRMask);
466  if (getObjCGCAttr() == Q.getObjCGCAttr())
468  if (getObjCLifetime() == Q.getObjCLifetime())
470  if (getAddressSpace() == Q.getAddressSpace())
472  }
473  }
474 
475  /// Add the qualifiers from the given set to this set, given that
476  /// they don't conflict.
478  assert(getAddressSpace() == qs.getAddressSpace() ||
479  !hasAddressSpace() || !qs.hasAddressSpace());
480  assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
481  !hasObjCGCAttr() || !qs.hasObjCGCAttr());
482  assert(getObjCLifetime() == qs.getObjCLifetime() ||
483  !hasObjCLifetime() || !qs.hasObjCLifetime());
484  Mask |= qs.Mask;
485  }
486 
487  /// Returns true if address space A is equal to or a superset of B.
488  /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
489  /// overlapping address spaces.
490  /// CL1.1 or CL1.2:
491  /// every address space is a superset of itself.
492  /// CL2.0 adds:
493  /// __generic is a superset of any address space except for __constant.
495  // Address spaces must match exactly.
496  return A == B ||
497  // Otherwise in OpenCLC v2.0 s6.5.5: every address space except
498  // for __constant can be used as __generic.
500  // We also define global_device and global_host address spaces,
501  // to distinguish global pointers allocated on host from pointers
502  // allocated on device, which are a subset of __global.
506  B == LangAS::sycl_global_host)) ||
507  // Consider pointer size address spaces to be equivalent to default.
508  ((isPtrSizeAddressSpace(A) || A == LangAS::Default) &&
509  (isPtrSizeAddressSpace(B) || B == LangAS::Default)) ||
510  // Default is a superset of SYCL address spaces.
511  (A == LangAS::Default &&
514  B == LangAS::sycl_global_host)) ||
515  // In HIP device compilation, any cuda address space is allowed
516  // to implicitly cast into the default address space.
517  (A == LangAS::Default &&
519  B == LangAS::cuda_shared));
520  }
521 
522  /// Returns true if the address space in these qualifiers is equal to or
523  /// a superset of the address space in the argument qualifiers.
526  }
527 
528  /// Determines if these qualifiers compatibly include another set.
529  /// Generally this answers the question of whether an object with the other
530  /// qualifiers can be safely used as an object with these qualifiers.
531  bool compatiblyIncludes(Qualifiers other) const {
532  return isAddressSpaceSupersetOf(other) &&
533  // ObjC GC qualifiers can match, be added, or be removed, but can't
534  // be changed.
535  (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
536  !other.hasObjCGCAttr()) &&
537  // ObjC lifetime qualifiers must match exactly.
538  getObjCLifetime() == other.getObjCLifetime() &&
539  // CVR qualifiers may subset.
540  (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
541  // U qualifier may superset.
542  (!other.hasUnaligned() || hasUnaligned());
543  }
544 
545  /// Determines if these qualifiers compatibly include another set of
546  /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
547  ///
548  /// One set of Objective-C lifetime qualifiers compatibly includes the other
549  /// if the lifetime qualifiers match, or if both are non-__weak and the
550  /// including set also contains the 'const' qualifier, or both are non-__weak
551  /// and one is None (which can only happen in non-ARC modes).
553  if (getObjCLifetime() == other.getObjCLifetime())
554  return true;
555 
556  if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
557  return false;
558 
559  if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
560  return true;
561 
562  return hasConst();
563  }
564 
565  /// Determine whether this set of qualifiers is a strict superset of
566  /// another set of qualifiers, not considering qualifier compatibility.
567  bool isStrictSupersetOf(Qualifiers Other) const;
568 
569  bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
570  bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
571 
572  explicit operator bool() const { return hasQualifiers(); }
573 
575  addQualifiers(R);
576  return *this;
577  }
578 
579  // Union two qualifier sets. If an enumerated qualifier appears
580  // in both sets, use the one from the right.
582  L += R;
583  return L;
584  }
585 
587  removeQualifiers(R);
588  return *this;
589  }
590 
591  /// Compute the difference between two qualifier sets.
593  L -= R;
594  return L;
595  }
596 
597  std::string getAsString() const;
598  std::string getAsString(const PrintingPolicy &Policy) const;
599 
601 
602  bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
603  void print(raw_ostream &OS, const PrintingPolicy &Policy,
604  bool appendSpaceIfNonEmpty = false) const;
605 
606  void Profile(llvm::FoldingSetNodeID &ID) const {
607  ID.AddInteger(Mask);
608  }
609 
610 private:
611  // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|
612  // |C R V|U|GCAttr|Lifetime|AddressSpace|
613  uint32_t Mask = 0;
614 
615  static const uint32_t UMask = 0x8;
616  static const uint32_t UShift = 3;
617  static const uint32_t GCAttrMask = 0x30;
618  static const uint32_t GCAttrShift = 4;
619  static const uint32_t LifetimeMask = 0x1C0;
620  static const uint32_t LifetimeShift = 6;
621  static const uint32_t AddressSpaceMask =
622  ~(CVRMask | UMask | GCAttrMask | LifetimeMask);
623  static const uint32_t AddressSpaceShift = 9;
624 };
625 
627  Qualifiers Quals;
628  bool HasAtomic;
629 
630 public:
631  QualifiersAndAtomic() : HasAtomic(false) {}
632  QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
633  : Quals(Quals), HasAtomic(HasAtomic) {}
634 
635  operator Qualifiers() const { return Quals; }
636 
637  bool hasVolatile() const { return Quals.hasVolatile(); }
638  bool hasConst() const { return Quals.hasConst(); }
639  bool hasRestrict() const { return Quals.hasRestrict(); }
640  bool hasAtomic() const { return HasAtomic; }
641 
642  void addVolatile() { Quals.addVolatile(); }
643  void addConst() { Quals.addConst(); }
644  void addRestrict() { Quals.addRestrict(); }
645  void addAtomic() { HasAtomic = true; }
646 
647  void removeVolatile() { Quals.removeVolatile(); }
648  void removeConst() { Quals.removeConst(); }
649  void removeRestrict() { Quals.removeRestrict(); }
650  void removeAtomic() { HasAtomic = false; }
651 
653  return {Quals.withVolatile(), HasAtomic};
654  }
655  QualifiersAndAtomic withConst() { return {Quals.withConst(), HasAtomic}; }
657  return {Quals.withRestrict(), HasAtomic};
658  }
659  QualifiersAndAtomic withAtomic() { return {Quals, true}; }
660 
662  Quals += RHS;
663  return *this;
664  }
665 };
666 
667 /// A std::pair-like structure for storing a qualified type split
668 /// into its local qualifiers and its locally-unqualified type.
670  /// The locally-unqualified type.
671  const Type *Ty = nullptr;
672 
673  /// The local qualifiers.
675 
676  SplitQualType() = default;
677  SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
678 
679  SplitQualType getSingleStepDesugaredType() const; // end of this file
680 
681  // Make std::tie work.
682  std::pair<const Type *,Qualifiers> asPair() const {
683  return std::pair<const Type *, Qualifiers>(Ty, Quals);
684  }
685 
687  return a.Ty == b.Ty && a.Quals == b.Quals;
688  }
690  return a.Ty != b.Ty || a.Quals != b.Quals;
691  }
692 };
693 
694 /// The kind of type we are substituting Objective-C type arguments into.
695 ///
696 /// The kind of substitution affects the replacement of type parameters when
697 /// no concrete type information is provided, e.g., when dealing with an
698 /// unspecialized type.
700  /// An ordinary type.
701  Ordinary,
702 
703  /// The result type of a method or function.
704  Result,
705 
706  /// The parameter type of a method or function.
707  Parameter,
708 
709  /// The type of a property.
710  Property,
711 
712  /// The superclass of a type.
713  Superclass,
714 };
715 
716 /// The kind of 'typeof' expression we're after.
717 enum class TypeOfKind : uint8_t {
718  Qualified,
719  Unqualified,
720 };
721 
722 /// A (possibly-)qualified type.
723 ///
724 /// For efficiency, we don't store CV-qualified types as nodes on their
725 /// own: instead each reference to a type stores the qualifiers. This
726 /// greatly reduces the number of nodes we need to allocate for types (for
727 /// example we only need one for 'int', 'const int', 'volatile int',
728 /// 'const volatile int', etc).
729 ///
730 /// As an added efficiency bonus, instead of making this a pair, we
731 /// just store the two bits we care about in the low bits of the
732 /// pointer. To handle the packing/unpacking, we make QualType be a
733 /// simple wrapper class that acts like a smart pointer. A third bit
734 /// indicates whether there are extended qualifiers present, in which
735 /// case the pointer points to a special structure.
736 class QualType {
737  friend class QualifierCollector;
738 
739  // Thankfully, these are efficiently composable.
740  llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
742 
743  const ExtQuals *getExtQualsUnsafe() const {
744  return Value.getPointer().get<const ExtQuals*>();
745  }
746 
747  const Type *getTypePtrUnsafe() const {
748  return Value.getPointer().get<const Type*>();
749  }
750 
751  const ExtQualsTypeCommonBase *getCommonPtr() const {
752  assert(!isNull() && "Cannot retrieve a NULL type pointer");
753  auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
754  CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
755  return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
756  }
757 
758 public:
759  QualType() = default;
760  QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
761  QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
762 
763  unsigned getLocalFastQualifiers() const { return Value.getInt(); }
764  void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
765 
766  bool UseExcessPrecision(const ASTContext &Ctx);
767 
768  /// Retrieves a pointer to the underlying (unqualified) type.
769  ///
770  /// This function requires that the type not be NULL. If the type might be
771  /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
772  const Type *getTypePtr() const;
773 
774  const Type *getTypePtrOrNull() const;
775 
776  /// Retrieves a pointer to the name of the base type.
777  const IdentifierInfo *getBaseTypeIdentifier() const;
778 
779  /// Divides a QualType into its unqualified type and a set of local
780  /// qualifiers.
781  SplitQualType split() const;
782 
783  void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
784 
785  static QualType getFromOpaquePtr(const void *Ptr) {
786  QualType T;
787  T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
788  return T;
789  }
790 
791  const Type &operator*() const {
792  return *getTypePtr();
793  }
794 
795  const Type *operator->() const {
796  return getTypePtr();
797  }
798 
799  bool isCanonical() const;
800  bool isCanonicalAsParam() const;
801 
802  /// Return true if this QualType doesn't point to a type yet.
803  bool isNull() const {
804  return Value.getPointer().isNull();
805  }
806 
807  // Determines if a type can form `T&`.
808  bool isReferenceable() const;
809 
810  /// Determine whether this particular QualType instance has the
811  /// "const" qualifier set, without looking through typedefs that may have
812  /// added "const" at a different level.
813  bool isLocalConstQualified() const {
815  }
816 
817  /// Determine whether this type is const-qualified.
818  bool isConstQualified() const;
819 
820  /// Determine whether this particular QualType instance has the
821  /// "restrict" qualifier set, without looking through typedefs that may have
822  /// added "restrict" at a different level.
825  }
826 
827  /// Determine whether this type is restrict-qualified.
828  bool isRestrictQualified() const;
829 
830  /// Determine whether this particular QualType instance has the
831  /// "volatile" qualifier set, without looking through typedefs that may have
832  /// added "volatile" at a different level.
835  }
836 
837  /// Determine whether this type is volatile-qualified.
838  bool isVolatileQualified() const;
839 
840  /// Determine whether this particular QualType instance has any
841  /// qualifiers, without looking through any typedefs that might add
842  /// qualifiers at a different level.
843  bool hasLocalQualifiers() const {
845  }
846 
847  /// Determine whether this type has any qualifiers.
848  bool hasQualifiers() const;
849 
850  /// Determine whether this particular QualType instance has any
851  /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
852  /// instance.
854  return Value.getPointer().is<const ExtQuals*>();
855  }
856 
857  /// Retrieve the set of qualifiers local to this particular QualType
858  /// instance, not including any qualifiers acquired through typedefs or
859  /// other sugar.
861 
862  /// Retrieve the set of qualifiers applied to this type.
863  Qualifiers getQualifiers() const;
864 
865  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
866  /// local to this particular QualType instance, not including any qualifiers
867  /// acquired through typedefs or other sugar.
868  unsigned getLocalCVRQualifiers() const {
869  return getLocalFastQualifiers();
870  }
871 
872  /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
873  /// applied to this type.
874  unsigned getCVRQualifiers() const;
875 
876  bool isConstant(const ASTContext& Ctx) const {
877  return QualType::isConstant(*this, Ctx);
878  }
879 
880  /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
881  bool isPODType(const ASTContext &Context) const;
882 
883  /// Return true if this is a POD type according to the rules of the C++98
884  /// standard, regardless of the current compilation's language.
885  bool isCXX98PODType(const ASTContext &Context) const;
886 
887  /// Return true if this is a POD type according to the more relaxed rules
888  /// of the C++11 standard, regardless of the current compilation's language.
889  /// (C++0x [basic.types]p9). Note that, unlike
890  /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
891  bool isCXX11PODType(const ASTContext &Context) const;
892 
893  /// Return true if this is a trivial type per (C++0x [basic.types]p9)
894  bool isTrivialType(const ASTContext &Context) const;
895 
896  /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
897  bool isTriviallyCopyableType(const ASTContext &Context) const;
898 
899  /// Return true if this is a trivially relocatable type.
900  bool isTriviallyRelocatableType(const ASTContext &Context) const;
901 
902  /// Returns true if it is a class and it might be dynamic.
903  bool mayBeDynamicClass() const;
904 
905  /// Returns true if it is not a class or if the class might not be dynamic.
906  bool mayBeNotDynamicClass() const;
907 
908  // Don't promise in the API that anything besides 'const' can be
909  // easily added.
910 
911  /// Add the `const` type qualifier to this QualType.
912  void addConst() {
914  }
915  QualType withConst() const {
917  }
918 
919  /// Add the `volatile` type qualifier to this QualType.
920  void addVolatile() {
922  }
925  }
926 
927  /// Add the `restrict` qualifier to this QualType.
928  void addRestrict() {
930  }
933  }
934 
935  QualType withCVRQualifiers(unsigned CVR) const {
936  return withFastQualifiers(CVR);
937  }
938 
939  void addFastQualifiers(unsigned TQs) {
940  assert(!(TQs & ~Qualifiers::FastMask)
941  && "non-fast qualifier bits set in mask!");
942  Value.setInt(Value.getInt() | TQs);
943  }
944 
945  void removeLocalConst();
946  void removeLocalVolatile();
947  void removeLocalRestrict();
948  void removeLocalCVRQualifiers(unsigned Mask);
949 
950  void removeLocalFastQualifiers() { Value.setInt(0); }
951  void removeLocalFastQualifiers(unsigned Mask) {
952  assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
953  Value.setInt(Value.getInt() & ~Mask);
954  }
955 
956  // Creates a type with the given qualifiers in addition to any
957  // qualifiers already on this type.
958  QualType withFastQualifiers(unsigned TQs) const {
959  QualType T = *this;
960  T.addFastQualifiers(TQs);
961  return T;
962  }
963 
964  // Creates a type with exactly the given fast qualifiers, removing
965  // any existing fast qualifiers.
968  }
969 
970  // Removes fast qualifiers, but leaves any extended qualifiers in place.
972  QualType T = *this;
974  return T;
975  }
976 
977  QualType getCanonicalType() const;
978 
979  /// Return this type with all of the instance-specific qualifiers
980  /// removed, but without removing any qualifiers that may have been applied
981  /// through typedefs.
983 
984  /// Retrieve the unqualified variant of the given type,
985  /// removing as little sugar as possible.
986  ///
987  /// This routine looks through various kinds of sugar to find the
988  /// least-desugared type that is unqualified. For example, given:
989  ///
990  /// \code
991  /// typedef int Integer;
992  /// typedef const Integer CInteger;
993  /// typedef CInteger DifferenceType;
994  /// \endcode
995  ///
996  /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
997  /// desugar until we hit the type \c Integer, which has no qualifiers on it.
998  ///
999  /// The resulting type might still be qualified if it's sugar for an array
1000  /// type. To strip qualifiers even from within a sugared array type, use
1001  /// ASTContext::getUnqualifiedArrayType.
1002  ///
1003  /// Note: In C, the _Atomic qualifier is special (see C2x 6.2.5p29 for
1004  /// details), and it is not stripped by this function. Use
1005  /// getAtomicUnqualifiedType() to strip qualifiers including _Atomic.
1006  inline QualType getUnqualifiedType() const;
1007 
1008  /// Retrieve the unqualified variant of the given type, removing as little
1009  /// sugar as possible.
1010  ///
1011  /// Like getUnqualifiedType(), but also returns the set of
1012  /// qualifiers that were built up.
1013  ///
1014  /// The resulting type might still be qualified if it's sugar for an array
1015  /// type. To strip qualifiers even from within a sugared array type, use
1016  /// ASTContext::getUnqualifiedArrayType.
1017  inline SplitQualType getSplitUnqualifiedType() const;
1018 
1019  /// Determine whether this type is more qualified than the other
1020  /// given type, requiring exact equality for non-CVR qualifiers.
1021  bool isMoreQualifiedThan(QualType Other) const;
1022 
1023  /// Determine whether this type is at least as qualified as the other
1024  /// given type, requiring exact equality for non-CVR qualifiers.
1025  bool isAtLeastAsQualifiedAs(QualType Other) const;
1026 
1027  QualType getNonReferenceType() const;
1028 
1029  /// Determine the type of a (typically non-lvalue) expression with the
1030  /// specified result type.
1031  ///
1032  /// This routine should be used for expressions for which the return type is
1033  /// explicitly specified (e.g., in a cast or call) and isn't necessarily
1034  /// an lvalue. It removes a top-level reference (since there are no
1035  /// expressions of reference type) and deletes top-level cvr-qualifiers
1036  /// from non-class types (in C++) or all types (in C).
1037  QualType getNonLValueExprType(const ASTContext &Context) const;
1038 
1039  /// Remove an outer pack expansion type (if any) from this type. Used as part
1040  /// of converting the type of a declaration to the type of an expression that
1041  /// references that expression. It's meaningless for an expression to have a
1042  /// pack expansion type.
1044 
1045  /// Return the specified type with any "sugar" removed from
1046  /// the type. This takes off typedefs, typeof's etc. If the outer level of
1047  /// the type is already concrete, it returns it unmodified. This is similar
1048  /// to getting the canonical type, but it doesn't remove *all* typedefs. For
1049  /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
1050  /// concrete.
1051  ///
1052  /// Qualifiers are left in place.
1053  QualType getDesugaredType(const ASTContext &Context) const {
1054  return getDesugaredType(*this, Context);
1055  }
1056 
1058  return getSplitDesugaredType(*this);
1059  }
1060 
1061  /// Return the specified type with one level of "sugar" removed from
1062  /// the type.
1063  ///
1064  /// This routine takes off the first typedef, typeof, etc. If the outer level
1065  /// of the type is already concrete, it returns it unmodified.
1067  return getSingleStepDesugaredTypeImpl(*this, Context);
1068  }
1069 
1070  /// Returns the specified type after dropping any
1071  /// outer-level parentheses.
1073  if (isa<ParenType>(*this))
1074  return QualType::IgnoreParens(*this);
1075  return *this;
1076  }
1077 
1078  /// Indicate whether the specified types and qualifiers are identical.
1079  friend bool operator==(const QualType &LHS, const QualType &RHS) {
1080  return LHS.Value == RHS.Value;
1081  }
1082  friend bool operator!=(const QualType &LHS, const QualType &RHS) {
1083  return LHS.Value != RHS.Value;
1084  }
1085  friend bool operator<(const QualType &LHS, const QualType &RHS) {
1086  return LHS.Value < RHS.Value;
1087  }
1088 
1090  const PrintingPolicy &Policy) {
1091  return getAsString(split.Ty, split.Quals, Policy);
1092  }
1093  static std::string getAsString(const Type *ty, Qualifiers qs,
1094  const PrintingPolicy &Policy);
1095 
1096  std::string getAsString() const;
1097  std::string getAsString(const PrintingPolicy &Policy) const;
1098 
1099  void print(raw_ostream &OS, const PrintingPolicy &Policy,
1100  const Twine &PlaceHolder = Twine(),
1101  unsigned Indentation = 0) const;
1102 
1103  static void print(SplitQualType split, raw_ostream &OS,
1104  const PrintingPolicy &policy, const Twine &PlaceHolder,
1105  unsigned Indentation = 0) {
1106  return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
1107  }
1108 
1109  static void print(const Type *ty, Qualifiers qs,
1110  raw_ostream &OS, const PrintingPolicy &policy,
1111  const Twine &PlaceHolder,
1112  unsigned Indentation = 0);
1113 
1114  void getAsStringInternal(std::string &Str,
1115  const PrintingPolicy &Policy) const;
1116 
1118  const PrintingPolicy &policy) {
1119  return getAsStringInternal(split.Ty, split.Quals, out, policy);
1120  }
1121 
1122  static void getAsStringInternal(const Type *ty, Qualifiers qs,
1123  std::string &out,
1124  const PrintingPolicy &policy);
1125 
1127  const QualType &T;
1128  const PrintingPolicy &Policy;
1129  const Twine &PlaceHolder;
1130  unsigned Indentation;
1131 
1132  public:
1134  const Twine &PlaceHolder, unsigned Indentation)
1135  : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1136  Indentation(Indentation) {}
1137 
1138  friend raw_ostream &operator<<(raw_ostream &OS,
1139  const StreamedQualTypeHelper &SQT) {
1140  SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1141  return OS;
1142  }
1143  };
1144 
1146  const Twine &PlaceHolder = Twine(),
1147  unsigned Indentation = 0) const {
1148  return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1149  }
1150 
1151  void dump(const char *s) const;
1152  void dump() const;
1153  void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
1154 
1155  void Profile(llvm::FoldingSetNodeID &ID) const {
1156  ID.AddPointer(getAsOpaquePtr());
1157  }
1158 
1159  /// Check if this type has any address space qualifier.
1160  inline bool hasAddressSpace() const;
1161 
1162  /// Return the address space of this type.
1163  inline LangAS getAddressSpace() const;
1164 
1165  /// Returns true if address space qualifiers overlap with T address space
1166  /// qualifiers.
1167  /// OpenCL C defines conversion rules for pointers to different address spaces
1168  /// and notion of overlapping address spaces.
1169  /// CL1.1 or CL1.2:
1170  /// address spaces overlap iff they are they same.
1171  /// OpenCL C v2.0 s6.5.5 adds:
1172  /// __generic overlaps with any address space except for __constant.
1174  Qualifiers Q = getQualifiers();
1175  Qualifiers TQ = T.getQualifiers();
1176  // Address spaces overlap if at least one of them is a superset of another
1177  return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q);
1178  }
1179 
1180  /// Returns gc attribute of this type.
1181  inline Qualifiers::GC getObjCGCAttr() const;
1182 
1183  /// true when Type is objc's weak.
1184  bool isObjCGCWeak() const {
1185  return getObjCGCAttr() == Qualifiers::Weak;
1186  }
1187 
1188  /// true when Type is objc's strong.
1189  bool isObjCGCStrong() const {
1190  return getObjCGCAttr() == Qualifiers::Strong;
1191  }
1192 
1193  /// Returns lifetime attribute of this type.
1195  return getQualifiers().getObjCLifetime();
1196  }
1197 
1200  }
1201 
1204  }
1205 
1206  // true when Type is objc's weak and weak is enabled but ARC isn't.
1207  bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1208 
1210  /// The type does not fall into any of the following categories. Note that
1211  /// this case is zero-valued so that values of this enum can be used as a
1212  /// boolean condition for non-triviality.
1214 
1215  /// The type is an Objective-C retainable pointer type that is qualified
1216  /// with the ARC __strong qualifier.
1218 
1219  /// The type is an Objective-C retainable pointer type that is qualified
1220  /// with the ARC __weak qualifier.
1222 
1223  /// The type is a struct containing a field whose type is not PCK_Trivial.
1225  };
1226 
1227  /// Functions to query basic properties of non-trivial C struct types.
1228 
1229  /// Check if this is a non-trivial type that would cause a C struct
1230  /// transitively containing this type to be non-trivial to default initialize
1231  /// and return the kind.
1234 
1236  /// The type does not fall into any of the following categories. Note that
1237  /// this case is zero-valued so that values of this enum can be used as a
1238  /// boolean condition for non-triviality.
1240 
1241  /// The type would be trivial except that it is volatile-qualified. Types
1242  /// that fall into one of the other non-trivial cases may additionally be
1243  /// volatile-qualified.
1245 
1246  /// The type is an Objective-C retainable pointer type that is qualified
1247  /// with the ARC __strong qualifier.
1249 
1250  /// The type is an Objective-C retainable pointer type that is qualified
1251  /// with the ARC __weak qualifier.
1253 
1254  /// The type is a struct containing a field whose type is neither
1255  /// PCK_Trivial nor PCK_VolatileTrivial.
1256  /// Note that a C++ struct type does not necessarily match this; C++ copying
1257  /// semantics are too complex to express here, in part because they depend
1258  /// on the exact constructor or assignment operator that is chosen by
1259  /// overload resolution to do the copy.
1261  };
1262 
1263  /// Check if this is a non-trivial type that would cause a C struct
1264  /// transitively containing this type to be non-trivial to copy and return the
1265  /// kind.
1267 
1268  /// Check if this is a non-trivial type that would cause a C struct
1269  /// transitively containing this type to be non-trivial to destructively
1270  /// move and return the kind. Destructive move in this context is a C++-style
1271  /// move in which the source object is placed in a valid but unspecified state
1272  /// after it is moved, as opposed to a truly destructive move in which the
1273  /// source object is placed in an uninitialized state.
1275 
1282  };
1283 
1284  /// Returns a nonzero value if objects of this type require
1285  /// non-trivial work to clean up after. Non-zero because it's
1286  /// conceivable that qualifiers (objc_gc(weak)?) could make
1287  /// something require destruction.
1289  return isDestructedTypeImpl(*this);
1290  }
1291 
1292  /// Check if this is or contains a C union that is non-trivial to
1293  /// default-initialize, which is a union that has a member that is non-trivial
1294  /// to default-initialize. If this returns true,
1295  /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct.
1297 
1298  /// Check if this is or contains a C union that is non-trivial to destruct,
1299  /// which is a union that has a member that is non-trivial to destruct. If
1300  /// this returns true, isDestructedType returns DK_nontrivial_c_struct.
1302 
1303  /// Check if this is or contains a C union that is non-trivial to copy, which
1304  /// is a union that has a member that is non-trivial to copy. If this returns
1305  /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct.
1307 
1308  /// Determine whether expressions of the given type are forbidden
1309  /// from being lvalues in C.
1310  ///
1311  /// The expression types that are forbidden to be lvalues are:
1312  /// - 'void', but not qualified void
1313  /// - function types
1314  ///
1315  /// The exact rule here is C99 6.3.2.1:
1316  /// An lvalue is an expression with an object type or an incomplete
1317  /// type other than void.
1318  bool isCForbiddenLValueType() const;
1319 
1320  /// Substitute type arguments for the Objective-C type parameters used in the
1321  /// subject type.
1322  ///
1323  /// \param ctx ASTContext in which the type exists.
1324  ///
1325  /// \param typeArgs The type arguments that will be substituted for the
1326  /// Objective-C type parameters in the subject type, which are generally
1327  /// computed via \c Type::getObjCSubstitutions. If empty, the type
1328  /// parameters will be replaced with their bounds or id/Class, as appropriate
1329  /// for the context.
1330  ///
1331  /// \param context The context in which the subject type was written.
1332  ///
1333  /// \returns the resulting type.
1335  ArrayRef<QualType> typeArgs,
1336  ObjCSubstitutionContext context) const;
1337 
1338  /// Substitute type arguments from an object type for the Objective-C type
1339  /// parameters used in the subject type.
1340  ///
1341  /// This operation combines the computation of type arguments for
1342  /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1343  /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1344  /// callers that need to perform a single substitution in isolation.
1345  ///
1346  /// \param objectType The type of the object whose member type we're
1347  /// substituting into. For example, this might be the receiver of a message
1348  /// or the base of a property access.
1349  ///
1350  /// \param dc The declaration context from which the subject type was
1351  /// retrieved, which indicates (for example) which type parameters should
1352  /// be substituted.
1353  ///
1354  /// \param context The context in which the subject type was written.
1355  ///
1356  /// \returns the subject type after replacing all of the Objective-C type
1357  /// parameters with their corresponding arguments.
1359  const DeclContext *dc,
1360  ObjCSubstitutionContext context) const;
1361 
1362  /// Strip Objective-C "__kindof" types from the given type.
1363  QualType stripObjCKindOfType(const ASTContext &ctx) const;
1364 
1365  /// Remove all qualifiers including _Atomic.
1367 
1368 private:
1369  // These methods are implemented in a separate translation unit;
1370  // "static"-ize them to avoid creating temporary QualTypes in the
1371  // caller.
1372  static bool isConstant(QualType T, const ASTContext& Ctx);
1373  static QualType getDesugaredType(QualType T, const ASTContext &Context);
1375  static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1376  static QualType getSingleStepDesugaredTypeImpl(QualType type,
1377  const ASTContext &C);
1378  static QualType IgnoreParens(QualType T);
1379  static DestructionKind isDestructedTypeImpl(QualType type);
1380 
1381  /// Check if \param RD is or contains a non-trivial C union.
1383  static bool hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD);
1384  static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD);
1385 };
1386 
1387 raw_ostream &operator<<(raw_ostream &OS, QualType QT);
1388 
1389 } // namespace clang
1390 
1391 namespace llvm {
1392 
1393 /// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1394 /// to a specific Type class.
1395 template<> struct simplify_type< ::clang::QualType> {
1397 
1399  return Val.getTypePtr();
1400  }
1401 };
1402 
1403 // Teach SmallPtrSet that QualType is "basically a pointer".
1404 template<>
1405 struct PointerLikeTypeTraits<clang::QualType> {
1406  static inline void *getAsVoidPointer(clang::QualType P) {
1407  return P.getAsOpaquePtr();
1408  }
1409 
1410  static inline clang::QualType getFromVoidPointer(void *P) {
1412  }
1413 
1414  // Various qualifiers go in low bits.
1415  static constexpr int NumLowBitsAvailable = 0;
1416 };
1417 
1418 } // namespace llvm
1419 
1420 namespace clang {
1421 
1422 /// Base class that is common to both the \c ExtQuals and \c Type
1423 /// classes, which allows \c QualType to access the common fields between the
1424 /// two.
1426  friend class ExtQuals;
1427  friend class QualType;
1428  friend class Type;
1429 
1430  /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1431  /// a self-referential pointer (for \c Type).
1432  ///
1433  /// This pointer allows an efficient mapping from a QualType to its
1434  /// underlying type pointer.
1435  const Type *const BaseType;
1436 
1437  /// The canonical type of this type. A QualType.
1438  QualType CanonicalType;
1439 
1440  ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1441  : BaseType(baseType), CanonicalType(canon) {}
1442 };
1443 
1444 /// We can encode up to four bits in the low bits of a
1445 /// type pointer, but there are many more type qualifiers that we want
1446 /// to be able to apply to an arbitrary type. Therefore we have this
1447 /// struct, intended to be heap-allocated and used by QualType to
1448 /// store qualifiers.
1449 ///
1450 /// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1451 /// in three low bits on the QualType pointer; a fourth bit records whether
1452 /// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1453 /// Objective-C GC attributes) are much more rare.
1454 class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode {
1455  // NOTE: changing the fast qualifiers should be straightforward as
1456  // long as you don't make 'const' non-fast.
1457  // 1. Qualifiers:
1458  // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1459  // Fast qualifiers must occupy the low-order bits.
1460  // b) Update Qualifiers::FastWidth and FastMask.
1461  // 2. QualType:
1462  // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1463  // b) Update remove{Volatile,Restrict}, defined near the end of
1464  // this header.
1465  // 3. ASTContext:
1466  // a) Update get{Volatile,Restrict}Type.
1467 
1468  /// The immutable set of qualifiers applied by this node. Always contains
1469  /// extended qualifiers.
1470  Qualifiers Quals;
1471 
1472  ExtQuals *this_() { return this; }
1473 
1474 public:
1475  ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1476  : ExtQualsTypeCommonBase(baseType,
1477  canon.isNull() ? QualType(this_(), 0) : canon),
1478  Quals(quals) {
1479  assert(Quals.hasNonFastQualifiers()
1480  && "ExtQuals created with no fast qualifiers");
1481  assert(!Quals.hasFastQualifiers()
1482  && "ExtQuals created with fast qualifiers");
1483  }
1484 
1485  Qualifiers getQualifiers() const { return Quals; }
1486 
1487  bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1488  Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1489 
1490  bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1492  return Quals.getObjCLifetime();
1493  }
1494 
1495  bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1496  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1497 
1498  const Type *getBaseType() const { return BaseType; }
1499 
1500 public:
1501  void Profile(llvm::FoldingSetNodeID &ID) const {
1502  Profile(ID, getBaseType(), Quals);
1503  }
1504 
1505  static void Profile(llvm::FoldingSetNodeID &ID,
1506  const Type *BaseType,
1507  Qualifiers Quals) {
1508  assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1509  ID.AddPointer(BaseType);
1510  Quals.Profile(ID);
1511  }
1512 };
1513 
1514 /// The kind of C++11 ref-qualifier associated with a function type.
1515 /// This determines whether a member function's "this" object can be an
1516 /// lvalue, rvalue, or neither.
1518  /// No ref-qualifier was provided.
1519  RQ_None = 0,
1520 
1521  /// An lvalue ref-qualifier was provided (\c &).
1523 
1524  /// An rvalue ref-qualifier was provided (\c &&).
1526 };
1527 
1528 /// Which keyword(s) were used to create an AutoType.
1529 enum class AutoTypeKeyword {
1530  /// auto
1531  Auto,
1532 
1533  /// decltype(auto)
1534  DecltypeAuto,
1535 
1536  /// __auto_type (GNU extension)
1537  GNUAutoType
1538 };
1539 
1540 /// The base class of the type hierarchy.
1541 ///
1542 /// A central concept with types is that each type always has a canonical
1543 /// type. A canonical type is the type with any typedef names stripped out
1544 /// of it or the types it references. For example, consider:
1545 ///
1546 /// typedef int foo;
1547 /// typedef foo* bar;
1548 /// 'int *' 'foo *' 'bar'
1549 ///
1550 /// There will be a Type object created for 'int'. Since int is canonical, its
1551 /// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1552 /// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1553 /// there is a PointerType that represents 'int*', which, like 'int', is
1554 /// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1555 /// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1556 /// is also 'int*'.
1557 ///
1558 /// Non-canonical types are useful for emitting diagnostics, without losing
1559 /// information about typedefs being used. Canonical types are useful for type
1560 /// comparisons (they allow by-pointer equality tests) and useful for reasoning
1561 /// about whether something has a particular form (e.g. is a function type),
1562 /// because they implicitly, recursively, strip all typedefs out of a type.
1563 ///
1564 /// Types, once created, are immutable.
1565 ///
1566 class alignas(8) Type : public ExtQualsTypeCommonBase {
1567 public:
1568  enum TypeClass {
1569 #define TYPE(Class, Base) Class,
1570 #define LAST_TYPE(Class) TypeLast = Class
1571 #define ABSTRACT_TYPE(Class, Base)
1572 #include "clang/AST/TypeNodes.inc"
1573  };
1574 
1575 private:
1576  /// Bitfields required by the Type class.
1577  class TypeBitfields {
1578  friend class Type;
1579  template <class T> friend class TypePropertyCache;
1580 
1581  /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1582  unsigned TC : 8;
1583 
1584  /// Store information on the type dependency.
1585  unsigned Dependence : llvm::BitWidth<TypeDependence>;
1586 
1587  /// True if the cache (i.e. the bitfields here starting with
1588  /// 'Cache') is valid.
1589  mutable unsigned CacheValid : 1;
1590 
1591  /// Linkage of this type.
1592  mutable unsigned CachedLinkage : 3;
1593 
1594  /// Whether this type involves and local or unnamed types.
1595  mutable unsigned CachedLocalOrUnnamed : 1;
1596 
1597  /// Whether this type comes from an AST file.
1598  mutable unsigned FromAST : 1;
1599 
1600  bool isCacheValid() const {
1601  return CacheValid;
1602  }
1603 
1604  Linkage getLinkage() const {
1605  assert(isCacheValid() && "getting linkage from invalid cache");
1606  return static_cast<Linkage>(CachedLinkage);
1607  }
1608 
1609  bool hasLocalOrUnnamedType() const {
1610  assert(isCacheValid() && "getting linkage from invalid cache");
1611  return CachedLocalOrUnnamed;
1612  }
1613  };
1614  enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1615 
1616 protected:
1617  // These classes allow subclasses to somewhat cleanly pack bitfields
1618  // into Type.
1619 
1621  friend class ArrayType;
1622 
1623  unsigned : NumTypeBits;
1624 
1625  /// CVR qualifiers from declarations like
1626  /// 'int X[static restrict 4]'. For function parameters only.
1627  unsigned IndexTypeQuals : 3;
1628 
1629  /// Storage class qualifiers from declarations like
1630  /// 'int X[static restrict 4]'. For function parameters only.
1631  /// Actually an ArrayType::ArraySizeModifier.
1632  unsigned SizeModifier : 3;
1633  };
1634 
1636  friend class ConstantArrayType;
1637 
1638  unsigned : NumTypeBits + 3 + 3;
1639 
1640  /// Whether we have a stored size expression.
1641  unsigned HasStoredSizeExpr : 1;
1642  };
1643 
1645  friend class BuiltinType;
1646 
1647  unsigned : NumTypeBits;
1648 
1649  /// The kind (BuiltinType::Kind) of builtin type this is.
1650  unsigned Kind : 8;
1651  };
1652 
1653  /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1654  /// Only common bits are stored here. Additional uncommon bits are stored
1655  /// in a trailing object after FunctionProtoType.
1657  friend class FunctionProtoType;
1658  friend class FunctionType;
1659 
1660  unsigned : NumTypeBits;
1661 
1662  /// Extra information which affects how the function is called, like
1663  /// regparm and the calling convention.
1664  unsigned ExtInfo : 13;
1665 
1666  /// The ref-qualifier associated with a \c FunctionProtoType.
1667  ///
1668  /// This is a value of type \c RefQualifierKind.
1669  unsigned RefQualifier : 2;
1670 
1671  /// Used only by FunctionProtoType, put here to pack with the
1672  /// other bitfields.
1673  /// The qualifiers are part of FunctionProtoType because...
1674  ///
1675  /// C++ 8.3.5p4: The return type, the parameter type list and the
1676  /// cv-qualifier-seq, [...], are part of the function type.
1677  unsigned FastTypeQuals : Qualifiers::FastWidth;
1678  /// Whether this function has extended Qualifiers.
1679  unsigned HasExtQuals : 1;
1680 
1681  /// The number of parameters this function has, not counting '...'.
1682  /// According to [implimits] 8 bits should be enough here but this is
1683  /// somewhat easy to exceed with metaprogramming and so we would like to
1684  /// keep NumParams as wide as reasonably possible.
1685  unsigned NumParams : 16;
1686 
1687  /// The type of exception specification this function has.
1688  unsigned ExceptionSpecType : 4;
1689 
1690  /// Whether this function has extended parameter information.
1691  unsigned HasExtParameterInfos : 1;
1692 
1693  /// Whether this function has extra bitfields for the prototype.
1694  unsigned HasExtraBitfields : 1;
1695 
1696  /// Whether the function is variadic.
1697  unsigned Variadic : 1;
1698 
1699  /// Whether this function has a trailing return type.
1700  unsigned HasTrailingReturn : 1;
1701  };
1702 
1704  friend class ObjCObjectType;
1705 
1706  unsigned : NumTypeBits;
1707 
1708  /// The number of type arguments stored directly on this object type.
1709  unsigned NumTypeArgs : 7;
1710 
1711  /// The number of protocols stored directly on this object type.
1712  unsigned NumProtocols : 6;
1713 
1714  /// Whether this is a "kindof" type.
1715  unsigned IsKindOf : 1;
1716  };
1717 
1719  friend class ReferenceType;
1720 
1721  unsigned : NumTypeBits;
1722 
1723  /// True if the type was originally spelled with an lvalue sigil.
1724  /// This is never true of rvalue references but can also be false
1725  /// on lvalue references because of C++0x [dcl.typedef]p9,
1726  /// as follows:
1727  ///
1728  /// typedef int &ref; // lvalue, spelled lvalue
1729  /// typedef int &&rvref; // rvalue
1730  /// ref &a; // lvalue, inner ref, spelled lvalue
1731  /// ref &&a; // lvalue, inner ref
1732  /// rvref &a; // lvalue, inner ref, spelled lvalue
1733  /// rvref &&a; // rvalue, inner ref
1734  unsigned SpelledAsLValue : 1;
1735 
1736  /// True if the inner type is a reference type. This only happens
1737  /// in non-canonical forms.
1738  unsigned InnerRef : 1;
1739  };
1740 
1742  friend class TypeWithKeyword;
1743 
1744  unsigned : NumTypeBits;
1745 
1746  /// An ElaboratedTypeKeyword. 8 bits for efficient access.
1747  unsigned Keyword : 8;
1748  };
1749 
1751 
1753  friend class ElaboratedType;
1754 
1755  unsigned : NumTypeBits;
1757 
1758  /// Whether the ElaboratedType has a trailing OwnedTagDecl.
1759  unsigned HasOwnedTagDecl : 1;
1760  };
1761 
1763  friend class VectorType;
1764  friend class DependentVectorType;
1765 
1766  unsigned : NumTypeBits;
1767 
1768  /// The kind of vector, either a generic vector type or some
1769  /// target-specific vector type such as for AltiVec or Neon.
1770  unsigned VecKind : 3;
1771  /// The number of elements in the vector.
1772  uint32_t NumElements;
1773  };
1774 
1776  friend class AttributedType;
1777 
1778  unsigned : NumTypeBits;
1779 
1780  /// An AttributedType::Kind
1781  unsigned AttrKind : 32 - NumTypeBits;
1782  };
1783 
1785  friend class AutoType;
1786 
1787  unsigned : NumTypeBits;
1788 
1789  /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
1790  /// or '__auto_type'? AutoTypeKeyword value.
1791  unsigned Keyword : 2;
1792 
1793  /// The number of template arguments in the type-constraints, which is
1794  /// expected to be able to hold at least 1024 according to [implimits].
1795  /// However as this limit is somewhat easy to hit with template
1796  /// metaprogramming we'd prefer to keep it as large as possible.
1797  /// At the moment it has been left as a non-bitfield since this type
1798  /// safely fits in 64 bits as an unsigned, so there is no reason to
1799  /// introduce the performance impact of a bitfield.
1800  unsigned NumArgs;
1801  };
1802 
1804  friend class TypeOfType;
1805  friend class TypeOfExprType;
1806 
1807  unsigned : NumTypeBits;
1808  unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
1809  };
1810 
1812  friend class UsingType;
1813 
1814  unsigned : NumTypeBits;
1815 
1816  /// True if the underlying type is different from the declared one.
1817  unsigned hasTypeDifferentFromDecl : 1;
1818  };
1819 
1821  friend class TypedefType;
1822 
1823  unsigned : NumTypeBits;
1824 
1825  /// True if the underlying type is different from the declared one.
1826  unsigned hasTypeDifferentFromDecl : 1;
1827  };
1828 
1831 
1832  unsigned : NumTypeBits;
1833 
1834  unsigned HasNonCanonicalUnderlyingType : 1;
1835 
1836  // The index of the template parameter this substitution represents.
1837  unsigned Index : 15;
1838 
1839  /// Represents the index within a pack if this represents a substitution
1840  /// from a pack expansion. This index starts at the end of the pack and
1841  /// increments towards the beginning.
1842  /// Positive non-zero number represents the index + 1.
1843  /// Zero means this is not substituted from an expansion.
1844  unsigned PackIndex : 16;
1845  };
1846 
1849 
1850  unsigned : NumTypeBits;
1851 
1852  // The index of the template parameter this substitution represents.
1853  unsigned Index : 16;
1854 
1855  /// The number of template arguments in \c Arguments, which is
1856  /// expected to be able to hold at least 1024 according to [implimits].
1857  /// However as this limit is somewhat easy to hit with template
1858  /// metaprogramming we'd prefer to keep it as large as possible.
1859  unsigned NumArgs : 16;
1860  };
1861 
1864 
1865  unsigned : NumTypeBits;
1866 
1867  /// Whether this template specialization type is a substituted type alias.
1868  unsigned TypeAlias : 1;
1869 
1870  /// The number of template arguments named in this class template
1871  /// specialization, which is expected to be able to hold at least 1024
1872  /// according to [implimits]. However, as this limit is somewhat easy to
1873  /// hit with template metaprogramming we'd prefer to keep it as large
1874  /// as possible. At the moment it has been left as a non-bitfield since
1875  /// this type safely fits in 64 bits as an unsigned, so there is no reason
1876  /// to introduce the performance impact of a bitfield.
1877  unsigned NumArgs;
1878  };
1879 
1882 
1883  unsigned : NumTypeBits;
1885 
1886  /// The number of template arguments named in this class template
1887  /// specialization, which is expected to be able to hold at least 1024
1888  /// according to [implimits]. However, as this limit is somewhat easy to
1889  /// hit with template metaprogramming we'd prefer to keep it as large
1890  /// as possible. At the moment it has been left as a non-bitfield since
1891  /// this type safely fits in 64 bits as an unsigned, so there is no reason
1892  /// to introduce the performance impact of a bitfield.
1893  unsigned NumArgs;
1894  };
1895 
1897  friend class PackExpansionType;
1898 
1899  unsigned : NumTypeBits;
1900 
1901  /// The number of expansions that this pack expansion will
1902  /// generate when substituted (+1), which is expected to be able to
1903  /// hold at least 1024 according to [implimits]. However, as this limit
1904  /// is somewhat easy to hit with template metaprogramming we'd prefer to
1905  /// keep it as large as possible. At the moment it has been left as a
1906  /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
1907  /// there is no reason to introduce the performance impact of a bitfield.
1908  ///
1909  /// This field will only have a non-zero value when some of the parameter
1910  /// packs that occur within the pattern have been substituted but others
1911  /// have not.
1912  unsigned NumExpansions;
1913  };
1914 
1915  union {
1916  TypeBitfields TypeBits;
1937  };
1938 
1939 private:
1940  template <class T> friend class TypePropertyCache;
1941 
1942  /// Set whether this type comes from an AST file.
1943  void setFromAST(bool V = true) const {
1944  TypeBits.FromAST = V;
1945  }
1946 
1947 protected:
1948  friend class ASTContext;
1949 
1951  : ExtQualsTypeCommonBase(this,
1952  canon.isNull() ? QualType(this_(), 0) : canon) {
1953  static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase),
1954  "changing bitfields changed sizeof(Type)!");
1955  static_assert(alignof(decltype(*this)) % sizeof(void *) == 0,
1956  "Insufficient alignment!");
1957  TypeBits.TC = tc;
1958  TypeBits.Dependence = static_cast<unsigned>(Dependence);
1959  TypeBits.CacheValid = false;
1960  TypeBits.CachedLocalOrUnnamed = false;
1961  TypeBits.CachedLinkage = NoLinkage;
1962  TypeBits.FromAST = false;
1963  }
1964 
1965  // silence VC++ warning C4355: 'this' : used in base member initializer list
1966  Type *this_() { return this; }
1967 
1969  TypeBits.Dependence = static_cast<unsigned>(D);
1970  }
1971 
1973 
1974 public:
1975  friend class ASTReader;
1976  friend class ASTWriter;
1977  template <class T> friend class serialization::AbstractTypeReader;
1978  template <class T> friend class serialization::AbstractTypeWriter;
1979 
1980  Type(const Type &) = delete;
1981  Type(Type &&) = delete;
1982  Type &operator=(const Type &) = delete;
1983  Type &operator=(Type &&) = delete;
1984 
1985  TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
1986 
1987  /// Whether this type comes from an AST file.
1988  bool isFromAST() const { return TypeBits.FromAST; }
1989 
1990  /// Whether this type is or contains an unexpanded parameter
1991  /// pack, used to support C++0x variadic templates.
1992  ///
1993  /// A type that contains a parameter pack shall be expanded by the
1994  /// ellipsis operator at some point. For example, the typedef in the
1995  /// following example contains an unexpanded parameter pack 'T':
1996  ///
1997  /// \code
1998  /// template<typename ...T>
1999  /// struct X {
2000  /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
2001  /// };
2002  /// \endcode
2003  ///
2004  /// Note that this routine does not specify which
2006  return getDependence() & TypeDependence::UnexpandedPack;
2007  }
2008 
2009  /// Determines if this type would be canonical if it had no further
2010  /// qualification.
2011  bool isCanonicalUnqualified() const {
2012  return CanonicalType == QualType(this, 0);
2013  }
2014 
2015  /// Pull a single level of sugar off of this locally-unqualified type.
2016  /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
2017  /// or QualType::getSingleStepDesugaredType(const ASTContext&).
2019 
2020  /// As an extension, we classify types as one of "sized" or "sizeless";
2021  /// every type is one or the other. Standard types are all sized;
2022  /// sizeless types are purely an extension.
2023  ///
2024  /// Sizeless types contain data with no specified size, alignment,
2025  /// or layout.
2026  bool isSizelessType() const;
2027  bool isSizelessBuiltinType() const;
2028 
2029  /// Returns true for SVE scalable vector types.
2030  bool isSVESizelessBuiltinType() const;
2031 
2032  /// Determines if this is a sizeless type supported by the
2033  /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
2034  /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
2035  bool isVLSTBuiltinType() const;
2036 
2037  /// Returns the representative type for the element of an SVE builtin type.
2038  /// This is used to represent fixed-length SVE vectors created with the
2039  /// 'arm_sve_vector_bits' type attribute as VectorType.
2040  QualType getSveEltType(const ASTContext &Ctx) const;
2041 
2042  /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2043  /// object types, function types, and incomplete types.
2044 
2045  /// Return true if this is an incomplete type.
2046  /// A type that can describe objects, but which lacks information needed to
2047  /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2048  /// routine will need to determine if the size is actually required.
2049  ///
2050  /// Def If non-null, and the type refers to some kind of declaration
2051  /// that can be completed (such as a C struct, C++ class, or Objective-C
2052  /// class), will be set to the declaration.
2053  bool isIncompleteType(NamedDecl **Def = nullptr) const;
2054 
2055  /// Return true if this is an incomplete or object
2056  /// type, in other words, not a function type.
2058  return !isFunctionType();
2059  }
2060 
2061  /// Determine whether this type is an object type.
2062  bool isObjectType() const {
2063  // C++ [basic.types]p8:
2064  // An object type is a (possibly cv-qualified) type that is not a
2065  // function type, not a reference type, and not a void type.
2066  return !isReferenceType() && !isFunctionType() && !isVoidType();
2067  }
2068 
2069  /// Return true if this is a literal type
2070  /// (C++11 [basic.types]p10)
2071  bool isLiteralType(const ASTContext &Ctx) const;
2072 
2073  /// Determine if this type is a structural type, per C++20 [temp.param]p7.
2074  bool isStructuralType() const;
2075 
2076  /// Test if this type is a standard-layout type.
2077  /// (C++0x [basic.type]p9)
2078  bool isStandardLayoutType() const;
2079 
2080  /// Helper methods to distinguish type categories. All type predicates
2081  /// operate on the canonical type, ignoring typedefs and qualifiers.
2082 
2083  /// Returns true if the type is a builtin type.
2084  bool isBuiltinType() const;
2085 
2086  /// Test for a particular builtin type.
2087  bool isSpecificBuiltinType(unsigned K) const;
2088 
2089  /// Test for a type which does not represent an actual type-system type but
2090  /// is instead used as a placeholder for various convenient purposes within
2091  /// Clang. All such types are BuiltinTypes.
2092  bool isPlaceholderType() const;
2093  const BuiltinType *getAsPlaceholderType() const;
2094 
2095  /// Test for a specific placeholder type.
2096  bool isSpecificPlaceholderType(unsigned K) const;
2097 
2098  /// Test for a placeholder type other than Overload; see
2099  /// BuiltinType::isNonOverloadPlaceholderType.
2100  bool isNonOverloadPlaceholderType() const;
2101 
2102  /// isIntegerType() does *not* include complex integers (a GCC extension).
2103  /// isComplexIntegerType() can be used to test for complex integers.
2104  bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
2105  bool isEnumeralType() const;
2106 
2107  /// Determine whether this type is a scoped enumeration type.
2108  bool isScopedEnumeralType() const;
2109  bool isBooleanType() const;
2110  bool isCharType() const;
2111  bool isWideCharType() const;
2112  bool isChar8Type() const;
2113  bool isChar16Type() const;
2114  bool isChar32Type() const;
2115  bool isAnyCharacterType() const;
2116  bool isIntegralType(const ASTContext &Ctx) const;
2117 
2118  /// Determine whether this type is an integral or enumeration type.
2119  bool isIntegralOrEnumerationType() const;
2120 
2121  /// Determine whether this type is an integral or unscoped enumeration type.
2123  bool isUnscopedEnumerationType() const;
2124 
2125  /// Floating point categories.
2126  bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2127  /// isComplexType() does *not* include complex integers (a GCC extension).
2128  /// isComplexIntegerType() can be used to test for complex integers.
2129  bool isComplexType() const; // C99 6.2.5p11 (complex)
2130  bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
2131  bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
2132  bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
2133  bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
2134  bool isBFloat16Type() const;
2135  bool isFloat128Type() const;
2136  bool isIbm128Type() const;
2137  bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
2138  bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
2139  bool isVoidType() const; // C99 6.2.5p19
2140  bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
2141  bool isAggregateType() const;
2142  bool isFundamentalType() const;
2143  bool isCompoundType() const;
2144 
2145  // Type Predicates: Check to see if this type is structurally the specified
2146  // type, ignoring typedefs and qualifiers.
2147  bool isFunctionType() const;
2148  bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
2149  bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
2150  bool isPointerType() const;
2151  bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
2152  bool isBlockPointerType() const;
2153  bool isVoidPointerType() const;
2154  bool isReferenceType() const;
2155  bool isLValueReferenceType() const;
2156  bool isRValueReferenceType() const;
2157  bool isObjectPointerType() const;
2158  bool isFunctionPointerType() const;
2159  bool isFunctionReferenceType() const;
2160  bool isMemberPointerType() const;
2161  bool isMemberFunctionPointerType() const;
2162  bool isMemberDataPointerType() const;
2163  bool isArrayType() const;
2164  bool isConstantArrayType() const;
2165  bool isIncompleteArrayType() const;
2166  bool isVariableArrayType() const;
2167  bool isDependentSizedArrayType() const;
2168  bool isRecordType() const;
2169  bool isClassType() const;
2170  bool isStructureType() const;
2171  bool isObjCBoxableRecordType() const;
2172  bool isInterfaceType() const;
2173  bool isStructureOrClassType() const;
2174  bool isUnionType() const;
2175  bool isComplexIntegerType() const; // GCC _Complex integer type.
2176  bool isVectorType() const; // GCC vector type.
2177  bool isExtVectorType() const; // Extended vector type.
2178  bool isExtVectorBoolType() const; // Extended vector type with bool element.
2179  bool isMatrixType() const; // Matrix type.
2180  bool isConstantMatrixType() const; // Constant matrix type.
2181  bool isDependentAddressSpaceType() const; // value-dependent address space qualifier
2182  bool isObjCObjectPointerType() const; // pointer to ObjC object
2183  bool isObjCRetainableType() const; // ObjC object or block pointer
2184  bool isObjCLifetimeType() const; // (array of)* retainable type
2185  bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
2186  bool isObjCNSObjectType() const; // __attribute__((NSObject))
2187  bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
2188  // FIXME: change this to 'raw' interface type, so we can used 'interface' type
2189  // for the common case.
2190  bool isObjCObjectType() const; // NSString or typeof(*(id)0)
2191  bool isObjCQualifiedInterfaceType() const; // NSString<foo>
2192  bool isObjCQualifiedIdType() const; // id<foo>
2193  bool isObjCQualifiedClassType() const; // Class<foo>
2194  bool isObjCObjectOrInterfaceType() const;
2195  bool isObjCIdType() const; // id
2196  bool isDecltypeType() const;
2197  /// Was this type written with the special inert-in-ARC __unsafe_unretained
2198  /// qualifier?
2199  ///
2200  /// This approximates the answer to the following question: if this
2201  /// translation unit were compiled in ARC, would this type be qualified
2202  /// with __unsafe_unretained?
2204  return hasAttr(attr::ObjCInertUnsafeUnretained);
2205  }
2206 
2207  /// Whether the type is Objective-C 'id' or a __kindof type of an
2208  /// object type, e.g., __kindof NSView * or __kindof id
2209  /// <NSCopying>.
2210  ///
2211  /// \param bound Will be set to the bound on non-id subtype types,
2212  /// which will be (possibly specialized) Objective-C class type, or
2213  /// null for 'id.
2214  bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2215  const ObjCObjectType *&bound) const;
2216 
2217  bool isObjCClassType() const; // Class
2218 
2219  /// Whether the type is Objective-C 'Class' or a __kindof type of an
2220  /// Class type, e.g., __kindof Class <NSCopying>.
2221  ///
2222  /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2223  /// here because Objective-C's type system cannot express "a class
2224  /// object for a subclass of NSFoo".
2225  bool isObjCClassOrClassKindOfType() const;
2226 
2228  bool isObjCSelType() const; // Class
2229  bool isObjCBuiltinType() const; // 'id' or 'Class'
2230  bool isObjCARCBridgableType() const;
2231  bool isCARCBridgableType() const;
2232  bool isTemplateTypeParmType() const; // C++ template type parameter
2233  bool isNullPtrType() const; // C++11 std::nullptr_t or
2234  // C2x nullptr_t
2235  bool isNothrowT() const; // C++ std::nothrow_t
2236  bool isAlignValT() const; // C++17 std::align_val_t
2237  bool isStdByteType() const; // C++17 std::byte
2238  bool isAtomicType() const; // C11 _Atomic()
2239  bool isUndeducedAutoType() const; // C++11 auto or
2240  // C++14 decltype(auto)
2241  bool isTypedefNameType() const; // typedef or alias template
2242 
2243 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2244  bool is##Id##Type() const;
2245 #include "clang/Basic/OpenCLImageTypes.def"
2246 
2247  bool isImageType() const; // Any OpenCL image type
2248 
2249  bool isSamplerT() const; // OpenCL sampler_t
2250  bool isEventT() const; // OpenCL event_t
2251  bool isClkEventT() const; // OpenCL clk_event_t
2252  bool isQueueT() const; // OpenCL queue_t
2253  bool isReserveIDT() const; // OpenCL reserve_id_t
2254 
2255 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2256  bool is##Id##Type() const;
2257 #include "clang/Basic/OpenCLExtensionTypes.def"
2258  // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension
2259  bool isOCLIntelSubgroupAVCType() const;
2260  bool isOCLExtOpaqueType() const; // Any OpenCL extension type
2261 
2262  bool isPipeType() const; // OpenCL pipe type
2263  bool isBitIntType() const; // Bit-precise integer type
2264  bool isOpenCLSpecificType() const; // Any OpenCL specific type
2265 
2266  /// Determines if this type, which must satisfy
2267  /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2268  /// than implicitly __strong.
2269  bool isObjCARCImplicitlyUnretainedType() const;
2270 
2271  /// Check if the type is the CUDA device builtin surface type.
2272  bool isCUDADeviceBuiltinSurfaceType() const;
2273  /// Check if the type is the CUDA device builtin texture type.
2274  bool isCUDADeviceBuiltinTextureType() const;
2275 
2276  bool isRVVType() const;
2277 
2278  /// Return the implicit lifetime for this type, which must not be dependent.
2280 
2292  };
2293 
2294  /// Given that this is a scalar type, classify it.
2296 
2298  return static_cast<TypeDependence>(TypeBits.Dependence);
2299  }
2300 
2301  /// Whether this type is an error type.
2302  bool containsErrors() const {
2304  }
2305 
2306  /// Whether this type is a dependent type, meaning that its definition
2307  /// somehow depends on a template parameter (C++ [temp.dep.type]).
2308  bool isDependentType() const {
2309  return getDependence() & TypeDependence::Dependent;
2310  }
2311 
2312  /// Determine whether this type is an instantiation-dependent type,
2313  /// meaning that the type involves a template parameter (even if the
2314  /// definition does not actually depend on the type substituted for that
2315  /// template parameter).
2317  return getDependence() & TypeDependence::Instantiation;
2318  }
2319 
2320  /// Determine whether this type is an undeduced type, meaning that
2321  /// it somehow involves a C++11 'auto' type or similar which has not yet been
2322  /// deduced.
2323  bool isUndeducedType() const;
2324 
2325  /// Whether this type is a variably-modified type (C99 6.7.5).
2326  bool isVariablyModifiedType() const {
2327  return getDependence() & TypeDependence::VariablyModified;
2328  }
2329 
2330  /// Whether this type involves a variable-length array type
2331  /// with a definite size.
2332  bool hasSizedVLAType() const;
2333 
2334  /// Whether this type is or contains a local or unnamed type.
2335  bool hasUnnamedOrLocalType() const;
2336 
2337  bool isOverloadableType() const;
2338 
2339  /// Determine wither this type is a C++ elaborated-type-specifier.
2340  bool isElaboratedTypeSpecifier() const;
2341 
2342  bool canDecayToPointerType() const;
2343 
2344  /// Whether this type is represented natively as a pointer. This includes
2345  /// pointers, references, block pointers, and Objective-C interface,
2346  /// qualified id, and qualified interface types, as well as nullptr_t.
2347  bool hasPointerRepresentation() const;
2348 
2349  /// Whether this type can represent an objective pointer type for the
2350  /// purpose of GC'ability
2351  bool hasObjCPointerRepresentation() const;
2352 
2353  /// Determine whether this type has an integer representation
2354  /// of some sort, e.g., it is an integer type or a vector.
2355  bool hasIntegerRepresentation() const;
2356 
2357  /// Determine whether this type has an signed integer representation
2358  /// of some sort, e.g., it is an signed integer type or a vector.
2359  bool hasSignedIntegerRepresentation() const;
2360 
2361  /// Determine whether this type has an unsigned integer representation
2362  /// of some sort, e.g., it is an unsigned integer type or a vector.
2363  bool hasUnsignedIntegerRepresentation() const;
2364 
2365  /// Determine whether this type has a floating-point representation
2366  /// of some sort, e.g., it is a floating-point type or a vector thereof.
2367  bool hasFloatingRepresentation() const;
2368 
2369  // Type Checking Functions: Check to see if this type is structurally the
2370  // specified type, ignoring typedefs and qualifiers, and return a pointer to
2371  // the best type we can.
2372  const RecordType *getAsStructureType() const;
2373  /// NOTE: getAs*ArrayType are methods on ASTContext.
2374  const RecordType *getAsUnionType() const;
2375  const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2376  const ObjCObjectType *getAsObjCInterfaceType() const;
2377 
2378  // The following is a convenience method that returns an ObjCObjectPointerType
2379  // for object declared using an interface.
2384 
2385  /// Retrieves the CXXRecordDecl that this type refers to, either
2386  /// because the type is a RecordType or because it is the injected-class-name
2387  /// type of a class template or class template partial specialization.
2389 
2390  /// Retrieves the RecordDecl this type refers to.
2391  RecordDecl *getAsRecordDecl() const;
2392 
2393  /// Retrieves the TagDecl that this type refers to, either
2394  /// because the type is a TagType or because it is the injected-class-name
2395  /// type of a class template or class template partial specialization.
2396  TagDecl *getAsTagDecl() const;
2397 
2398  /// If this is a pointer or reference to a RecordType, return the
2399  /// CXXRecordDecl that the type refers to.
2400  ///
2401  /// If this is not a pointer or reference, or the type being pointed to does
2402  /// not refer to a CXXRecordDecl, returns NULL.
2403  const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2404 
2405  /// Get the DeducedType whose type will be deduced for a variable with
2406  /// an initializer of this type. This looks through declarators like pointer
2407  /// types, but not through decltype or typedefs.
2409 
2410  /// Get the AutoType whose type will be deduced for a variable with
2411  /// an initializer of this type. This looks through declarators like pointer
2412  /// types, but not through decltype or typedefs.
2414  return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2415  }
2416 
2417  /// Determine whether this type was written with a leading 'auto'
2418  /// corresponding to a trailing return type (possibly for a nested
2419  /// function type within a pointer to function type or similar).
2420  bool hasAutoForTrailingReturnType() const;
2421 
2422  /// Member-template getAs<specific type>'. Look through sugar for
2423  /// an instance of <specific type>. This scheme will eventually
2424  /// replace the specific getAsXXXX methods above.
2425  ///
2426  /// There are some specializations of this member template listed
2427  /// immediately following this class.
2428  template <typename T> const T *getAs() const;
2429 
2430  /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2431  /// of sugar (parens, attributes, etc) for an instance of <specific type>.
2432  /// This is used when you need to walk over sugar nodes that represent some
2433  /// kind of type adjustment from a type that was written as a <specific type>
2434  /// to another type that is still canonically a <specific type>.
2435  template <typename T> const T *getAsAdjusted() const;
2436 
2437  /// A variant of getAs<> for array types which silently discards
2438  /// qualifiers from the outermost type.
2439  const ArrayType *getAsArrayTypeUnsafe() const;
2440 
2441  /// Member-template castAs<specific type>. Look through sugar for
2442  /// the underlying instance of <specific type>.
2443  ///
2444  /// This method has the same relationship to getAs<T> as cast<T> has
2445  /// to dyn_cast<T>; which is to say, the underlying type *must*
2446  /// have the intended type, and this method will never return null.
2447  template <typename T> const T *castAs() const;
2448 
2449  /// A variant of castAs<> for array type which silently discards
2450  /// qualifiers from the outermost type.
2451  const ArrayType *castAsArrayTypeUnsafe() const;
2452 
2453  /// Determine whether this type had the specified attribute applied to it
2454  /// (looking through top-level type sugar).
2455  bool hasAttr(attr::Kind AK) const;
2456 
2457  /// Get the base element type of this type, potentially discarding type
2458  /// qualifiers. This should never be used when type qualifiers
2459  /// are meaningful.
2460  const Type *getBaseElementTypeUnsafe() const;
2461 
2462  /// If this is an array type, return the element type of the array,
2463  /// potentially with type qualifiers missing.
2464  /// This should never be used when type qualifiers are meaningful.
2465  const Type *getArrayElementTypeNoTypeQual() const;
2466 
2467  /// If this is a pointer type, return the pointee type.
2468  /// If this is an array type, return the array element type.
2469  /// This should never be used when type qualifiers are meaningful.
2470  const Type *getPointeeOrArrayElementType() const;
2471 
2472  /// If this is a pointer, ObjC object pointer, or block
2473  /// pointer, this returns the respective pointee.
2474  QualType getPointeeType() const;
2475 
2476  /// Return the specified type with any "sugar" removed from the type,
2477  /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2478  const Type *getUnqualifiedDesugaredType() const;
2479 
2480  /// Return true if this is an integer type that is
2481  /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2482  /// or an enum decl which has a signed representation.
2483  bool isSignedIntegerType() const;
2484 
2485  /// Return true if this is an integer type that is
2486  /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2487  /// or an enum decl which has an unsigned representation.
2488  bool isUnsignedIntegerType() const;
2489 
2490  /// Determines whether this is an integer type that is signed or an
2491  /// enumeration types whose underlying type is a signed integer type.
2492  bool isSignedIntegerOrEnumerationType() const;
2493 
2494  /// Determines whether this is an integer type that is unsigned or an
2495  /// enumeration types whose underlying type is a unsigned integer type.
2497 
2498  /// Return true if this is a fixed point type according to
2499  /// ISO/IEC JTC1 SC22 WG14 N1169.
2500  bool isFixedPointType() const;
2501 
2502  /// Return true if this is a fixed point or integer type.
2503  bool isFixedPointOrIntegerType() const;
2504 
2505  /// Return true if this is a saturated fixed point type according to
2506  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2507  bool isSaturatedFixedPointType() const;
2508 
2509  /// Return true if this is a saturated fixed point type according to
2510  /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2511  bool isUnsaturatedFixedPointType() const;
2512 
2513  /// Return true if this is a fixed point type that is signed according
2514  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2515  bool isSignedFixedPointType() const;
2516 
2517  /// Return true if this is a fixed point type that is unsigned according
2518  /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2519  bool isUnsignedFixedPointType() const;
2520 
2521  /// Return true if this is not a variable sized type,
2522  /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2523  /// incomplete types.
2524  bool isConstantSizeType() const;
2525 
2526  /// Returns true if this type can be represented by some
2527  /// set of type specifiers.
2528  bool isSpecifierType() const;
2529 
2530  /// Determine the linkage of this type.
2531  Linkage getLinkage() const;
2532 
2533  /// Determine the visibility of this type.
2536  }
2537 
2538  /// Return true if the visibility was explicitly set is the code.
2539  bool isVisibilityExplicit() const {
2541  }
2542 
2543  /// Determine the linkage and visibility of this type.
2545 
2546  /// True if the computed linkage is valid. Used for consistency
2547  /// checking. Should always return true.
2548  bool isLinkageValid() const;
2549 
2550  /// Determine the nullability of the given type.
2551  ///
2552  /// Note that nullability is only captured as sugar within the type
2553  /// system, not as part of the canonical type, so nullability will
2554  /// be lost by canonicalization and desugaring.
2555  std::optional<NullabilityKind> getNullability() const;
2556 
2557  /// Determine whether the given type can have a nullability
2558  /// specifier applied to it, i.e., if it is any kind of pointer type.
2559  ///
2560  /// \param ResultIfUnknown The value to return if we don't yet know whether
2561  /// this type can have nullability because it is dependent.
2562  bool canHaveNullability(bool ResultIfUnknown = true) const;
2563 
2564  /// Retrieve the set of substitutions required when accessing a member
2565  /// of the Objective-C receiver type that is declared in the given context.
2566  ///
2567  /// \c *this is the type of the object we're operating on, e.g., the
2568  /// receiver for a message send or the base of a property access, and is
2569  /// expected to be of some object or object pointer type.
2570  ///
2571  /// \param dc The declaration context for which we are building up a
2572  /// substitution mapping, which should be an Objective-C class, extension,
2573  /// category, or method within.
2574  ///
2575  /// \returns an array of type arguments that can be substituted for
2576  /// the type parameters of the given declaration context in any type described
2577  /// within that context, or an empty optional to indicate that no
2578  /// substitution is required.
2579  std::optional<ArrayRef<QualType>>
2580  getObjCSubstitutions(const DeclContext *dc) const;
2581 
2582  /// Determines if this is an ObjC interface type that may accept type
2583  /// parameters.
2584  bool acceptsObjCTypeParams() const;
2585 
2586  const char *getTypeClassName() const;
2587 
2589  return CanonicalType;
2590  }
2591 
2592  CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2593  void dump() const;
2594  void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
2595 };
2596 
2597 /// This will check for a TypedefType by removing any existing sugar
2598 /// until it reaches a TypedefType or a non-sugared type.
2599 template <> const TypedefType *Type::getAs() const;
2600 template <> const UsingType *Type::getAs() const;
2601 
2602 /// This will check for a TemplateSpecializationType by removing any
2603 /// existing sugar until it reaches a TemplateSpecializationType or a
2604 /// non-sugared type.
2605 template <> const TemplateSpecializationType *Type::getAs() const;
2606 
2607 /// This will check for an AttributedType by removing any existing sugar
2608 /// until it reaches an AttributedType or a non-sugared type.
2609 template <> const AttributedType *Type::getAs() const;
2610 
2611 // We can do canonical leaf types faster, because we don't have to
2612 // worry about preserving child type decoration.
2613 #define TYPE(Class, Base)
2614 #define LEAF_TYPE(Class) \
2615 template <> inline const Class##Type *Type::getAs() const { \
2616  return dyn_cast<Class##Type>(CanonicalType); \
2617 } \
2618 template <> inline const Class##Type *Type::castAs() const { \
2619  return cast<Class##Type>(CanonicalType); \
2620 }
2621 #include "clang/AST/TypeNodes.inc"
2622 
2623 /// This class is used for builtin types like 'int'. Builtin
2624 /// types are always canonical and have a literal name field.
2625 class BuiltinType : public Type {
2626 public:
2627  enum Kind {
2628 // OpenCL image types
2629 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2630 #include "clang/Basic/OpenCLImageTypes.def"
2631 // OpenCL extension types
2632 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
2633 #include "clang/Basic/OpenCLExtensionTypes.def"
2634 // SVE Types
2635 #define SVE_TYPE(Name, Id, SingletonId) Id,
2636 #include "clang/Basic/AArch64SVEACLETypes.def"
2637 // PPC MMA Types
2638 #define PPC_VECTOR_TYPE(Name, Id, Size) Id,
2639 #include "clang/Basic/PPCTypes.def"
2640 // RVV Types
2641 #define RVV_TYPE(Name, Id, SingletonId) Id,
2642 #include "clang/Basic/RISCVVTypes.def"
2643 // All other builtin types
2644 #define BUILTIN_TYPE(Id, SingletonId) Id,
2645 #define LAST_BUILTIN_TYPE(Id) LastKind = Id
2646 #include "clang/AST/BuiltinTypes.def"
2647  };
2648 
2649 private:
2650  friend class ASTContext; // ASTContext creates these.
2651 
2652  BuiltinType(Kind K)
2653  : Type(Builtin, QualType(),
2654  K == Dependent ? TypeDependence::DependentInstantiation
2655  : TypeDependence::None) {
2656  BuiltinTypeBits.Kind = K;
2657  }
2658 
2659 public:
2660  Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
2661  StringRef getName(const PrintingPolicy &Policy) const;
2662 
2663  const char *getNameAsCString(const PrintingPolicy &Policy) const {
2664  // The StringRef is null-terminated.
2665  StringRef str = getName(Policy);
2666  assert(!str.empty() && str.data()[str.size()] == '\0');
2667  return str.data();
2668  }
2669 
2670  bool isSugared() const { return false; }
2671  QualType desugar() const { return QualType(this, 0); }
2672 
2673  bool isInteger() const {
2674  return getKind() >= Bool && getKind() <= Int128;
2675  }
2676 
2677  bool isSignedInteger() const {
2678  return getKind() >= Char_S && getKind() <= Int128;
2679  }
2680 
2681  bool isUnsignedInteger() const {
2682  return getKind() >= Bool && getKind() <= UInt128;
2683  }
2684 
2685  bool isFloatingPoint() const {
2686  return getKind() >= Half && getKind() <= Ibm128;
2687  }
2688 
2689  bool isSVEBool() const { return getKind() == Kind::SveBool; }
2690 
2691  /// Determines whether the given kind corresponds to a placeholder type.
2692  static bool isPlaceholderTypeKind(Kind K) {
2693  return K >= Overload;
2694  }
2695 
2696  /// Determines whether this type is a placeholder type, i.e. a type
2697  /// which cannot appear in arbitrary positions in a fully-formed
2698  /// expression.
2699  bool isPlaceholderType() const {
2700  return isPlaceholderTypeKind(getKind());
2701  }
2702 
2703  /// Determines whether this type is a placeholder type other than
2704  /// Overload. Most placeholder types require only syntactic
2705  /// information about their context in order to be resolved (e.g.
2706  /// whether it is a call expression), which means they can (and
2707  /// should) be resolved in an earlier "phase" of analysis.
2708  /// Overload expressions sometimes pick up further information
2709  /// from their context, like whether the context expects a
2710  /// specific function-pointer type, and so frequently need
2711  /// special treatment.
2713  return getKind() > Overload;
2714  }
2715 
2716  static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
2717 };
2718 
2719 /// Complex values, per C99 6.2.5p11. This supports the C99 complex
2720 /// types (_Complex float etc) as well as the GCC integer complex extensions.
2721 class ComplexType : public Type, public llvm::FoldingSetNode {
2722  friend class ASTContext; // ASTContext creates these.
2723 
2724  QualType ElementType;
2725 
2726  ComplexType(QualType Element, QualType CanonicalPtr)
2727  : Type(Complex, CanonicalPtr, Element->getDependence()),
2728  ElementType(Element) {}
2729 
2730 public:
2731  QualType getElementType() const { return ElementType; }
2732 
2733  bool isSugared() const { return false; }
2734  QualType desugar() const { return QualType(this, 0); }
2735 
2736  void Profile(llvm::FoldingSetNodeID &ID) {
2738  }
2739 
2740  static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
2741  ID.AddPointer(Element.getAsOpaquePtr());
2742  }
2743 
2744  static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
2745 };
2746 
2747 /// Sugar for parentheses used when specifying types.
2748 class ParenType : public Type, public llvm::FoldingSetNode {
2749  friend class ASTContext; // ASTContext creates these.
2750 
2751  QualType Inner;
2752 
2753  ParenType(QualType InnerType, QualType CanonType)
2754  : Type(Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
2755 
2756 public:
2757  QualType getInnerType() const { return Inner; }
2758 
2759  bool isSugared() const { return true; }
2760  QualType desugar() const { return getInnerType(); }
2761 
2762  void Profile(llvm::FoldingSetNodeID &ID) {
2763  Profile(ID, getInnerType());
2764  }
2765 
2766  static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
2767  Inner.Profile(ID);
2768  }
2769 
2770  static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
2771 };
2772 
2773 /// PointerType - C99 6.7.5.1 - Pointer Declarators.
2774 class PointerType : public Type, public llvm::FoldingSetNode {
2775  friend class ASTContext; // ASTContext creates these.
2776 
2777  QualType PointeeType;
2778 
2779  PointerType(QualType Pointee, QualType CanonicalPtr)
2780  : Type(Pointer, CanonicalPtr, Pointee->getDependence()),
2781  PointeeType(Pointee) {}
2782 
2783 public:
2784  QualType getPointeeType() const { return PointeeType; }
2785 
2786  bool isSugared() const { return false; }
2787  QualType desugar() const { return QualType(this, 0); }
2788 
2789  void Profile(llvm::FoldingSetNodeID &ID) {
2791  }
2792 
2793  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2794  ID.AddPointer(Pointee.getAsOpaquePtr());
2795  }
2796 
2797  static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
2798 };
2799 
2800 /// Represents a type which was implicitly adjusted by the semantic
2801 /// engine for arbitrary reasons. For example, array and function types can
2802 /// decay, and function types can have their calling conventions adjusted.
2803 class AdjustedType : public Type, public llvm::FoldingSetNode {
2804  QualType OriginalTy;
2805  QualType AdjustedTy;
2806 
2807 protected:
2808  friend class ASTContext; // ASTContext creates these.
2809 
2810  AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
2811  QualType CanonicalPtr)
2812  : Type(TC, CanonicalPtr, OriginalTy->getDependence()),
2813  OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2814 
2815 public:
2816  QualType getOriginalType() const { return OriginalTy; }
2817  QualType getAdjustedType() const { return AdjustedTy; }
2818 
2819  bool isSugared() const { return true; }
2820  QualType desugar() const { return AdjustedTy; }
2821 
2822  void Profile(llvm::FoldingSetNodeID &ID) {
2823  Profile(ID, OriginalTy, AdjustedTy);
2824  }
2825 
2826  static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
2827  ID.AddPointer(Orig.getAsOpaquePtr());
2828  ID.AddPointer(New.getAsOpaquePtr());
2829  }
2830 
2831  static bool classof(const Type *T) {
2832  return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
2833  }
2834 };
2835 
2836 /// Represents a pointer type decayed from an array or function type.
2837 class DecayedType : public AdjustedType {
2838  friend class ASTContext; // ASTContext creates these.
2839 
2840  inline
2841  DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
2842 
2843 public:
2845 
2846  inline QualType getPointeeType() const;
2847 
2848  static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
2849 };
2850 
2851 /// Pointer to a block type.
2852 /// This type is to represent types syntactically represented as
2853 /// "void (^)(int)", etc. Pointee is required to always be a function type.
2854 class BlockPointerType : public Type, public llvm::FoldingSetNode {
2855  friend class ASTContext; // ASTContext creates these.
2856 
2857  // Block is some kind of pointer type
2858  QualType PointeeType;
2859 
2860  BlockPointerType(QualType Pointee, QualType CanonicalCls)
2861  : Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
2862  PointeeType(Pointee) {}
2863 
2864 public:
2865  // Get the pointee type. Pointee is required to always be a function type.
2866  QualType getPointeeType() const { return PointeeType; }
2867 
2868  bool isSugared() const { return false; }
2869  QualType desugar() const { return QualType(this, 0); }
2870 
2871  void Profile(llvm::FoldingSetNodeID &ID) {
2873  }
2874 
2875  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
2876  ID.AddPointer(Pointee.getAsOpaquePtr());
2877  }
2878 
2879  static bool classof(const Type *T) {
2880  return T->getTypeClass() == BlockPointer;
2881  }
2882 };
2883 
2884 /// Base for LValueReferenceType and RValueReferenceType
2885 class ReferenceType : public Type, public llvm::FoldingSetNode {
2886  QualType PointeeType;
2887 
2888 protected:
2889  ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
2890  bool SpelledAsLValue)
2891  : Type(tc, CanonicalRef, Referencee->getDependence()),
2892  PointeeType(Referencee) {
2893  ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
2894  ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
2895  }
2896 
2897 public:
2898  bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
2899  bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
2900 
2901  QualType getPointeeTypeAsWritten() const { return PointeeType; }
2902 
2904  // FIXME: this might strip inner qualifiers; okay?
2905  const ReferenceType *T = this;
2906  while (T->isInnerRef())
2907  T = T->PointeeType->castAs<ReferenceType>();
2908  return T->PointeeType;
2909  }
2910 
2911  void Profile(llvm::FoldingSetNodeID &ID) {
2912  Profile(ID, PointeeType, isSpelledAsLValue());
2913  }
2914 
2915  static void Profile(llvm::FoldingSetNodeID &ID,
2916  QualType Referencee,
2917  bool SpelledAsLValue) {
2918  ID.AddPointer(Referencee.getAsOpaquePtr());
2919  ID.AddBoolean(SpelledAsLValue);
2920  }
2921 
2922  static bool classof(const Type *T) {
2923  return T->getTypeClass() == LValueReference ||
2924  T->getTypeClass() == RValueReference;
2925  }
2926 };
2927 
2928 /// An lvalue reference type, per C++11 [dcl.ref].
2930  friend class ASTContext; // ASTContext creates these
2931 
2932  LValueReferenceType(QualType Referencee, QualType CanonicalRef,
2933  bool SpelledAsLValue)
2934  : ReferenceType(LValueReference, Referencee, CanonicalRef,
2935  SpelledAsLValue) {}
2936 
2937 public:
2938  bool isSugared() const { return false; }
2939  QualType desugar() const { return QualType(this, 0); }
2940 
2941  static bool classof(const Type *T) {
2942  return T->getTypeClass() == LValueReference;
2943  }
2944 };
2945 
2946 /// An rvalue reference type, per C++11 [dcl.ref].
2948  friend class ASTContext; // ASTContext creates these
2949 
2950  RValueReferenceType(QualType Referencee, QualType CanonicalRef)
2951  : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
2952 
2953 public:
2954  bool isSugared() const { return false; }
2955  QualType desugar() const { return QualType(this, 0); }
2956 
2957  static bool classof(const Type *T) {
2958  return T->getTypeClass() == RValueReference;
2959  }
2960 };
2961 
2962 /// A pointer to member type per C++ 8.3.3 - Pointers to members.
2963 ///
2964 /// This includes both pointers to data members and pointer to member functions.
2965 class MemberPointerType : public Type, public llvm::FoldingSetNode {
2966  friend class ASTContext; // ASTContext creates these.
2967 
2968  QualType PointeeType;
2969 
2970  /// The class of which the pointee is a member. Must ultimately be a
2971  /// RecordType, but could be a typedef or a template parameter too.
2972  const Type *Class;
2973 
2974  MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
2975  : Type(MemberPointer, CanonicalPtr,
2976  (Cls->getDependence() & ~TypeDependence::VariablyModified) |
2977  Pointee->getDependence()),
2978  PointeeType(Pointee), Class(Cls) {}
2979 
2980 public:
2981  QualType getPointeeType() const { return PointeeType; }
2982 
2983  /// Returns true if the member type (i.e. the pointee type) is a
2984  /// function type rather than a data-member type.
2986  return PointeeType->isFunctionProtoType();
2987  }
2988 
2989  /// Returns true if the member type (i.e. the pointee type) is a
2990  /// data type rather than a function type.
2991  bool isMemberDataPointer() const {
2992  return !PointeeType->isFunctionProtoType();
2993  }
2994 
2995  const Type *getClass() const { return Class; }
2997 
2998  bool isSugared() const { return false; }
2999  QualType desugar() const { return QualType(this, 0); }
3000 
3001  void Profile(llvm::FoldingSetNodeID &ID) {
3003  }
3004 
3005  static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
3006  const Type *Class) {
3007  ID.AddPointer(Pointee.getAsOpaquePtr());
3008  ID.AddPointer(Class);
3009  }
3010 
3011  static bool classof(const Type *T) {
3012  return T->getTypeClass() == MemberPointer;
3013  }
3014 };
3015 
3016 /// Represents an array type, per C99 6.7.5.2 - Array Declarators.
3017 class ArrayType : public Type, public llvm::FoldingSetNode {
3018 public:
3019  /// Capture whether this is a normal array (e.g. int X[4])
3020  /// an array with a static size (e.g. int X[static 4]), or an array
3021  /// with a star size (e.g. int X[*]).
3022  /// 'static' is only allowed on function parameters.
3025  };
3026 
3027 private:
3028  /// The element type of the array.
3029  QualType ElementType;
3030 
3031 protected:
3032  friend class ASTContext; // ASTContext creates these.
3033 
3035  unsigned tq, const Expr *sz = nullptr);
3036 
3037 public:
3038  QualType getElementType() const { return ElementType; }
3039 
3041  return ArraySizeModifier(ArrayTypeBits.SizeModifier);
3042  }
3043 
3046  }
3047 
3048  unsigned getIndexTypeCVRQualifiers() const {
3049  return ArrayTypeBits.IndexTypeQuals;
3050  }
3051 
3052  static bool classof(const Type *T) {
3053  return T->getTypeClass() == ConstantArray ||
3054  T->getTypeClass() == VariableArray ||
3055  T->getTypeClass() == IncompleteArray ||
3056  T->getTypeClass() == DependentSizedArray;
3057  }
3058 };
3059 
3060 /// Represents the canonical version of C arrays with a specified constant size.
3061 /// For example, the canonical type for 'int A[4 + 4*100]' is a
3062 /// ConstantArrayType where the element type is 'int' and the size is 404.
3064  : public ArrayType,
3065  private llvm::TrailingObjects<ConstantArrayType, const Expr *> {
3066  friend class ASTContext; // ASTContext creates these.
3067  friend TrailingObjects;
3068 
3069  llvm::APInt Size; // Allows us to unique the type.
3070 
3071  ConstantArrayType(QualType et, QualType can, const llvm::APInt &size,
3072  const Expr *sz, ArraySizeModifier sm, unsigned tq)
3073  : ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
3074  ConstantArrayTypeBits.HasStoredSizeExpr = sz != nullptr;
3075  if (ConstantArrayTypeBits.HasStoredSizeExpr) {
3076  assert(!can.isNull() && "canonical constant array should not have size");
3077  *getTrailingObjects<const Expr*>() = sz;
3078  }
3079  }
3080 
3081  unsigned numTrailingObjects(OverloadToken<const Expr*>) const {
3082  return ConstantArrayTypeBits.HasStoredSizeExpr;
3083  }
3084 
3085 public:
3086  const llvm::APInt &getSize() const { return Size; }
3087  const Expr *getSizeExpr() const {
3088  return ConstantArrayTypeBits.HasStoredSizeExpr
3089  ? *getTrailingObjects<const Expr *>()
3090  : nullptr;
3091  }
3092  bool isSugared() const { return false; }
3093  QualType desugar() const { return QualType(this, 0); }
3094 
3095  /// Determine the number of bits required to address a member of
3096  // an array with the given element type and number of elements.
3097  static unsigned getNumAddressingBits(const ASTContext &Context,
3098  QualType ElementType,
3099  const llvm::APInt &NumElements);
3100 
3101  /// Determine the maximum number of active bits that an array's size
3102  /// can require, which limits the maximum size of the array.
3103  static unsigned getMaxSizeBits(const ASTContext &Context);
3104 
3105  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
3108  }
3109 
3110  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
3111  QualType ET, const llvm::APInt &ArraySize,
3112  const Expr *SizeExpr, ArraySizeModifier SizeMod,
3113  unsigned TypeQuals);
3114 
3115  static bool classof(const Type *T) {
3116  return T->getTypeClass() == ConstantArray;
3117  }
3118 };
3119 
3120 /// Represents a C array with an unspecified size. For example 'int A[]' has
3121 /// an IncompleteArrayType where the element type is 'int' and the size is
3122 /// unspecified.
3124  friend class ASTContext; // ASTContext creates these.
3125 
3127  ArraySizeModifier sm, unsigned tq)
3128  : ArrayType(IncompleteArray, et, can, sm, tq) {}
3129 
3130 public:
3131  friend class StmtIteratorBase;
3132 
3133  bool isSugared() const { return false; }
3134  QualType desugar() const { return QualType(this, 0); }
3135 
3136  static bool classof(const Type *T) {
3137  return T->getTypeClass() == IncompleteArray;
3138  }
3139 
3140  void Profile(llvm::FoldingSetNodeID &ID) {
3143  }
3144 
3145  static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
3146  ArraySizeModifier SizeMod, unsigned TypeQuals) {
3147  ID.AddPointer(ET.getAsOpaquePtr());
3148  ID.AddInteger(SizeMod);
3149  ID.AddInteger(TypeQuals);
3150  }
3151 };
3152 
3153 /// Represents a C array with a specified size that is not an
3154 /// integer-constant-expression. For example, 'int s[x+foo()]'.
3155 /// Since the size expression is an arbitrary expression, we store it as such.
3156 ///
3157 /// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
3158 /// should not be: two lexically equivalent variable array types could mean
3159 /// different things, for example, these variables do not have the same type
3160 /// dynamically:
3161 ///
3162 /// void foo(int x) {
3163 /// int Y[x];
3164 /// ++x;
3165 /// int Z[x];
3166 /// }
3168  friend class ASTContext; // ASTContext creates these.
3169 
3170  /// An assignment-expression. VLA's are only permitted within
3171  /// a function block.
3172  Stmt *SizeExpr;
3173 
3174  /// The range spanned by the left and right array brackets.
3175  SourceRange Brackets;
3176 
3178  ArraySizeModifier sm, unsigned tq,
3179  SourceRange brackets)
3180  : ArrayType(VariableArray, et, can, sm, tq, e),
3181  SizeExpr((Stmt*) e), Brackets(brackets) {}
3182 
3183 public:
3184  friend class StmtIteratorBase;
3185 
3186  Expr *getSizeExpr() const {
3187  // We use C-style casts instead of cast<> here because we do not wish
3188  // to have a dependency of Type.h on Stmt.h/Expr.h.
3189  return (Expr*) SizeExpr;
3190  }
3191 
3192  SourceRange getBracketsRange() const { return Brackets; }
3193  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3194  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3195 
3196  bool isSugared() const { return false; }
3197  QualType desugar() const { return QualType(this, 0); }
3198 
3199  static bool classof(const Type *T) {
3200  return T->getTypeClass() == VariableArray;
3201  }
3202 
3203  void Profile(llvm::FoldingSetNodeID &ID) {
3204  llvm_unreachable("Cannot unique VariableArrayTypes.");
3205  }
3206 };
3207 
3208 /// Represents an array type in C++ whose size is a value-dependent expression.
3209 ///
3210 /// For example:
3211 /// \code
3212 /// template<typename T, int Size>
3213 /// class array {
3214 /// T data[Size];
3215 /// };
3216 /// \endcode
3217 ///
3218 /// For these types, we won't actually know what the array bound is
3219 /// until template instantiation occurs, at which point this will
3220 /// become either a ConstantArrayType or a VariableArrayType.
3222  friend class ASTContext; // ASTContext creates these.
3223 
3224  const ASTContext &Context;
3225 
3226  /// An assignment expression that will instantiate to the
3227  /// size of the array.
3228  ///
3229  /// The expression itself might be null, in which case the array
3230  /// type will have its size deduced from an initializer.
3231  Stmt *SizeExpr;
3232 
3233  /// The range spanned by the left and right array brackets.
3234  SourceRange Brackets;
3235 
3236  DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can,
3237  Expr *e, ArraySizeModifier sm, unsigned tq,
3238  SourceRange brackets);
3239 
3240 public:
3241  friend class StmtIteratorBase;
3242 
3243  Expr *getSizeExpr() const {
3244  // We use C-style casts instead of cast<> here because we do not wish
3245  // to have a dependency of Type.h on Stmt.h/Expr.h.
3246  return (Expr*) SizeExpr;
3247  }
3248 
3249  SourceRange getBracketsRange() const { return Brackets; }
3250  SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3251  SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3252 
3253  bool isSugared() const { return false; }
3254  QualType desugar() const { return QualType(this, 0); }
3255 
3256  static bool classof(const Type *T) {
3257  return T->getTypeClass() == DependentSizedArray;
3258  }
3259 
3260  void Profile(llvm::FoldingSetNodeID &ID) {
3261  Profile(ID, Context, getElementType(),
3263  }
3264 
3265  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3266  QualType ET, ArraySizeModifier SizeMod,
3267  unsigned TypeQuals, Expr *E);
3268 };
3269 
3270 /// Represents an extended address space qualifier where the input address space
3271 /// value is dependent. Non-dependent address spaces are not represented with a
3272 /// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3273 ///
3274 /// For example:
3275 /// \code
3276 /// template<typename T, int AddrSpace>
3277 /// class AddressSpace {
3278 /// typedef T __attribute__((address_space(AddrSpace))) type;
3279 /// }
3280 /// \endcode
3281 class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3282  friend class ASTContext;
3283 
3284  const ASTContext &Context;
3285  Expr *AddrSpaceExpr;
3286  QualType PointeeType;
3287  SourceLocation loc;
3288 
3289  DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType,
3290  QualType can, Expr *AddrSpaceExpr,
3291  SourceLocation loc);
3292 
3293 public:
3294  Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3295  QualType getPointeeType() const { return PointeeType; }
3296  SourceLocation getAttributeLoc() const { return loc; }
3297 
3298  bool isSugared() const { return false; }
3299  QualType desugar() const { return QualType(this, 0); }
3300 
3301  static bool classof(const Type *T) {
3302  return T->getTypeClass() == DependentAddressSpace;
3303  }
3304 
3305  void Profile(llvm::FoldingSetNodeID &ID) {
3306  Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3307  }
3308 
3309  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3310  QualType PointeeType, Expr *AddrSpaceExpr);
3311 };
3312 
3313 /// Represents an extended vector type where either the type or size is
3314 /// dependent.
3315 ///
3316 /// For example:
3317 /// \code
3318 /// template<typename T, int Size>
3319 /// class vector {
3320 /// typedef T __attribute__((ext_vector_type(Size))) type;
3321 /// }
3322 /// \endcode
3323 class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3324  friend class ASTContext;
3325 
3326  const ASTContext &Context;
3327  Expr *SizeExpr;
3328 
3329  /// The element type of the array.
3330  QualType ElementType;
3331 
3332  SourceLocation loc;
3333 
3334  DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType,
3335  QualType can, Expr *SizeExpr, SourceLocation loc);
3336 
3337 public:
3338  Expr *getSizeExpr() const { return SizeExpr; }
3339  QualType getElementType() const { return ElementType; }
3340  SourceLocation getAttributeLoc() const { return loc; }
3341 
3342  bool isSugared() const { return false; }
3343  QualType desugar() const { return QualType(this, 0); }
3344 
3345  static bool classof(const Type *T) {
3346  return T->getTypeClass() == DependentSizedExtVector;
3347  }
3348 
3349  void Profile(llvm::FoldingSetNodeID &ID) {
3350  Profile(ID, Context, getElementType(), getSizeExpr());
3351  }
3352 
3353  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3354  QualType ElementType, Expr *SizeExpr);
3355 };
3356 
3357 
3358 /// Represents a GCC generic vector type. This type is created using
3359 /// __attribute__((vector_size(n)), where "n" specifies the vector size in
3360 /// bytes; or from an Altivec __vector or vector declaration.
3361 /// Since the constructor takes the number of vector elements, the
3362 /// client is responsible for converting the size into the number of elements.
3363 class VectorType : public Type, public llvm::FoldingSetNode {
3364 public:
3365  enum VectorKind {
3366  /// not a target-specific vector type
3368 
3369  /// is AltiVec vector
3371 
3372  /// is AltiVec 'vector Pixel'
3374 
3375  /// is AltiVec 'vector bool ...'
3377 
3378  /// is ARM Neon vector
3380 
3381  /// is ARM Neon polynomial vector
3383 
3384  /// is AArch64 SVE fixed-length data vector
3386 
3387  /// is AArch64 SVE fixed-length predicate vector
3389  };
3390 
3391 protected:
3392  friend class ASTContext; // ASTContext creates these.
3393 
3394  /// The element type of the vector.
3396 
3397  VectorType(QualType vecType, unsigned nElements, QualType canonType,
3398  VectorKind vecKind);
3399 
3400  VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3401  QualType canonType, VectorKind vecKind);
3402 
3403 public:
3405  unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3406 
3407  bool isSugared() const { return false; }
3408  QualType desugar() const { return QualType(this, 0); }
3409 
3411  return VectorKind(VectorTypeBits.VecKind);
3412  }
3413 
3414  void Profile(llvm::FoldingSetNodeID &ID) {
3417  }
3418 
3419  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3420  unsigned NumElements, TypeClass TypeClass,
3421  VectorKind VecKind) {
3422  ID.AddPointer(ElementType.getAsOpaquePtr());
3423  ID.AddInteger(NumElements);
3424  ID.AddInteger(TypeClass);
3425  ID.AddInteger(VecKind);
3426  }
3427 
3428  static bool classof(const Type *T) {
3429  return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
3430  }
3431 };
3432 
3433 /// Represents a vector type where either the type or size is dependent.
3434 ////
3435 /// For example:
3436 /// \code
3437 /// template<typename T, int Size>
3438 /// class vector {
3439 /// typedef T __attribute__((vector_size(Size))) type;
3440 /// }
3441 /// \endcode
3442 class DependentVectorType : public Type, public llvm::FoldingSetNode {
3443  friend class ASTContext;
3444 
3445  const ASTContext &Context;
3446  QualType ElementType;
3447  Expr *SizeExpr;
3448  SourceLocation Loc;
3449 
3450  DependentVectorType(const ASTContext &Context, QualType ElementType,
3451  QualType CanonType, Expr *SizeExpr,
3452  SourceLocation Loc, VectorType::VectorKind vecKind);
3453 
3454 public:
3455  Expr *getSizeExpr() const { return SizeExpr; }
3456  QualType getElementType() const { return ElementType; }
3457  SourceLocation getAttributeLoc() const { return Loc; }
3459  return VectorType::VectorKind(VectorTypeBits.VecKind);
3460  }
3461 
3462  bool isSugared() const { return false; }
3463  QualType desugar() const { return QualType(this, 0); }
3464 
3465  static bool classof(const Type *T) {
3466  return T->getTypeClass() == DependentVector;
3467  }
3468 
3469  void Profile(llvm::FoldingSetNodeID &ID) {
3470  Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3471  }
3472 
3473  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3474  QualType ElementType, const Expr *SizeExpr,
3475  VectorType::VectorKind VecKind);
3476 };
3477 
3478 /// ExtVectorType - Extended vector type. This type is created using
3479 /// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
3480 /// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
3481 /// class enables syntactic extensions, like Vector Components for accessing
3482 /// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
3483 /// Shading Language).
3484 class ExtVectorType : public VectorType {
3485  friend class ASTContext; // ASTContext creates these.
3486 
3487  ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3488  : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3489 
3490 public:
3491  static int getPointAccessorIdx(char c) {
3492  switch (c) {
3493  default: return -1;
3494  case 'x': case 'r': return 0;
3495  case 'y': case 'g': return 1;
3496  case 'z': case 'b': return 2;
3497  case 'w': case 'a': return 3;
3498  }
3499  }
3500 
3501  static int getNumericAccessorIdx(char c) {
3502  switch (c) {
3503  default: return -1;
3504  case '0': return 0;
3505  case '1': return 1;
3506  case '2': return 2;
3507  case '3': return 3;
3508  case '4': return 4;
3509  case '5': return 5;
3510  case '6': return 6;
3511  case '7': return 7;
3512  case '8': return 8;
3513  case '9': return 9;
3514  case 'A':
3515  case 'a': return 10;
3516  case 'B':
3517  case 'b': return 11;
3518  case 'C':
3519  case 'c': return 12;
3520  case 'D':
3521  case 'd': return 13;
3522  case 'E':
3523  case 'e': return 14;
3524  case 'F':
3525  case 'f': return 15;
3526  }
3527  }
3528 
3529  static int getAccessorIdx(char c, bool isNumericAccessor) {
3530  if (isNumericAccessor)
3531  return getNumericAccessorIdx(c);
3532  else
3533  return getPointAccessorIdx(c);
3534  }
3535 
3536  bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
3537  if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
3538  return unsigned(idx-1) < getNumElements();
3539  return false;
3540  }
3541 
3542  bool isSugared() const { return false; }
3543  QualType desugar() const { return QualType(this, 0); }
3544 
3545  static bool classof(const Type *T) {
3546  return T->getTypeClass() == ExtVector;
3547  }
3548 };
3549 
3550 /// Represents a matrix type, as defined in the Matrix Types clang extensions.
3551 /// __attribute__((matrix_type(rows, columns))), where "rows" specifies
3552 /// number of rows and "columns" specifies the number of columns.
3553 class MatrixType : public Type, public llvm::FoldingSetNode {
3554 protected:
3555  friend class ASTContext;
3556 
3557  /// The element type of the matrix.
3559 
3560  MatrixType(QualType ElementTy, QualType CanonElementTy);
3561 
3562  MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy,
3563  const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr);
3564 
3565 public:
3566  /// Returns type of the elements being stored in the matrix
3568 
3569  /// Valid elements types are the following:
3570  /// * an integer type (as in C2x 6.2.5p19), but excluding enumerated types
3571  /// and _Bool
3572  /// * the standard floating types float or double
3573  /// * a half-precision floating point type, if one is supported on the target
3574  static bool isValidElementType(QualType T) {
3575  return T->isDependentType() ||
3576  (T->isRealType() && !T->isBooleanType() && !T->isEnumeralType());
3577  }
3578 
3579  bool isSugared() const { return false; }
3580  QualType desugar() const { return QualType(this, 0); }
3581 
3582  static bool classof(const Type *T) {
3583  return T->getTypeClass() == ConstantMatrix ||
3584  T->getTypeClass() == DependentSizedMatrix;
3585  }
3586 };
3587 
3588 /// Represents a concrete matrix type with constant number of rows and columns
3589 class ConstantMatrixType final : public MatrixType {
3590 protected:
3591  friend class ASTContext;
3592 
3593  /// Number of rows and columns.
3594  unsigned NumRows;
3595  unsigned NumColumns;
3596 
3597  static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
3598 
3599  ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
3600  unsigned NColumns, QualType CanonElementType);
3601 
3602  ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows,
3603  unsigned NColumns, QualType CanonElementType);
3604 
3605 public:
3606  /// Returns the number of rows in the matrix.
3607  unsigned getNumRows() const { return NumRows; }
3608 
3609  /// Returns the number of columns in the matrix.
3610  unsigned getNumColumns() const { return NumColumns; }
3611 
3612  /// Returns the number of elements required to embed the matrix into a vector.
3613  unsigned getNumElementsFlattened() const {
3614  return getNumRows() * getNumColumns();
3615  }
3616 
3617  /// Returns true if \p NumElements is a valid matrix dimension.
3618  static constexpr bool isDimensionValid(size_t NumElements) {
3619  return NumElements > 0 && NumElements <= MaxElementsPerDimension;
3620  }
3621 
3622  /// Returns the maximum number of elements per dimension.
3623  static constexpr unsigned getMaxElementsPerDimension() {
3624  return MaxElementsPerDimension;
3625  }
3626 
3627  void Profile(llvm::FoldingSetNodeID &ID) {
3629  getTypeClass());
3630  }
3631 
3632  static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3633  unsigned NumRows, unsigned NumColumns,
3634  TypeClass TypeClass) {
3635  ID.AddPointer(ElementType.getAsOpaquePtr());
3636  ID.AddInteger(NumRows);
3637  ID.AddInteger(NumColumns);
3638  ID.AddInteger(TypeClass);
3639  }
3640 
3641  static bool classof(const Type *T) {
3642  return T->getTypeClass() == ConstantMatrix;
3643  }
3644 };
3645 
3646 /// Represents a matrix type where the type and the number of rows and columns
3647 /// is dependent on a template.
3648 class DependentSizedMatrixType final : public MatrixType {
3649  friend class ASTContext;
3650 
3651  const ASTContext &Context;
3652  Expr *RowExpr;
3653  Expr *ColumnExpr;
3654 
3655  SourceLocation loc;
3656 
3658  QualType CanonicalType, Expr *RowExpr,
3659  Expr *ColumnExpr, SourceLocation loc);
3660 
3661 public:
3662  Expr *getRowExpr() const { return RowExpr; }
3663  Expr *getColumnExpr() const { return ColumnExpr; }
3664  SourceLocation getAttributeLoc() const { return loc; }
3665 
3666  static bool classof(const Type *T) {
3667  return T->getTypeClass() == DependentSizedMatrix;
3668  }
3669 
3670  void Profile(llvm::FoldingSetNodeID &ID) {
3671  Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
3672  }
3673 
3674  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3675  QualType ElementType, Expr *RowExpr, Expr *ColumnExpr);
3676 };
3677 
3678 /// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
3679 /// class of FunctionNoProtoType and FunctionProtoType.
3680 class FunctionType : public Type {
3681  // The type returned by the function.
3682  QualType ResultType;
3683 
3684 public:
3685  /// Interesting information about a specific parameter that can't simply
3686  /// be reflected in parameter's type. This is only used by FunctionProtoType
3687  /// but is in FunctionType to make this class available during the
3688  /// specification of the bases of FunctionProtoType.
3689  ///
3690  /// It makes sense to model language features this way when there's some
3691  /// sort of parameter-specific override (such as an attribute) that
3692  /// affects how the function is called. For example, the ARC ns_consumed
3693  /// attribute changes whether a parameter is passed at +0 (the default)
3694  /// or +1 (ns_consumed). This must be reflected in the function type,
3695  /// but isn't really a change to the parameter type.
3696  ///
3697  /// One serious disadvantage of modelling language features this way is
3698  /// that they generally do not work with language features that attempt
3699  /// to destructure types. For example, template argument deduction will
3700  /// not be able to match a parameter declared as
3701  /// T (*)(U)
3702  /// against an argument of type
3703  /// void (*)(__attribute__((ns_consumed)) id)
3704  /// because the substitution of T=void, U=id into the former will
3705  /// not produce the latter.
3707  enum {
3708  ABIMask = 0x0F,
3709  IsConsumed = 0x10,
3710  HasPassObjSize = 0x20,
3711  IsNoEscape = 0x40,
3712  };
3713  unsigned char Data = 0;
3714 
3715  public:
3716  ExtParameterInfo() = default;
3717 
3718  /// Return the ABI treatment of this parameter.
3719  ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
3721  ExtParameterInfo copy = *this;
3722  copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
3723  return copy;
3724  }
3725 
3726  /// Is this parameter considered "consumed" by Objective-C ARC?
3727  /// Consumed parameters must have retainable object type.
3728  bool isConsumed() const { return (Data & IsConsumed); }
3729  ExtParameterInfo withIsConsumed(bool consumed) const {
3730  ExtParameterInfo copy = *this;
3731  if (consumed)
3732  copy.Data |= IsConsumed;
3733  else
3734  copy.Data &= ~IsConsumed;
3735  return copy;
3736  }
3737 
3738  bool hasPassObjectSize() const { return Data & HasPassObjSize; }
3740  ExtParameterInfo Copy = *this;
3741  Copy.Data |= HasPassObjSize;
3742  return Copy;
3743  }
3744 
3745  bool isNoEscape() const { return Data & IsNoEscape; }
3746  ExtParameterInfo withIsNoEscape(bool NoEscape) const {
3747  ExtParameterInfo Copy = *this;
3748  if (NoEscape)
3749  Copy.Data |= IsNoEscape;
3750  else
3751  Copy.Data &= ~IsNoEscape;
3752  return Copy;
3753  }
3754 
3755  unsigned char getOpaqueValue() const { return Data; }
3756  static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
3757  ExtParameterInfo result;
3758  result.Data = data;
3759  return result;
3760  }
3761 
3763  return lhs.Data == rhs.Data;
3764  }
3765 
3767  return lhs.Data != rhs.Data;
3768  }
3769  };
3770 
3771  /// A class which abstracts out some details necessary for
3772  /// making a call.
3773  ///
3774  /// It is not actually used directly for storing this information in
3775  /// a FunctionType, although FunctionType does currently use the
3776  /// same bit-pattern.
3777  ///
3778  // If you add a field (say Foo), other than the obvious places (both,
3779  // constructors, compile failures), what you need to update is
3780  // * Operator==
3781  // * getFoo
3782  // * withFoo
3783  // * functionType. Add Foo, getFoo.
3784  // * ASTContext::getFooType
3785  // * ASTContext::mergeFunctionTypes
3786  // * FunctionNoProtoType::Profile
3787  // * FunctionProtoType::Profile
3788  // * TypePrinter::PrintFunctionProto
3789  // * AST read and write
3790  // * Codegen
3791  class ExtInfo {
3792  friend class FunctionType;
3793 
3794  // Feel free to rearrange or add bits, but if you go over 16, you'll need to
3795  // adjust the Bits field below, and if you add bits, you'll need to adjust
3796  // Type::FunctionTypeBitfields::ExtInfo as well.
3797 
3798  // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
3799  // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | 12 |
3800  //
3801  // regparm is either 0 (no regparm attribute) or the regparm value+1.
3802  enum { CallConvMask = 0x1F };
3803  enum { NoReturnMask = 0x20 };
3804  enum { ProducesResultMask = 0x40 };
3805  enum { NoCallerSavedRegsMask = 0x80 };
3806  enum {
3807  RegParmMask = 0x700,
3808  RegParmOffset = 8
3809  };
3810  enum { NoCfCheckMask = 0x800 };
3811  enum { CmseNSCallMask = 0x1000 };
3812  uint16_t Bits = CC_C;
3813 
3814  ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3815 
3816  public:
3817  // Constructor with no defaults. Use this when you know that you
3818  // have all the elements (when reading an AST file for example).
3819  ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
3820  bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
3821  bool cmseNSCall) {
3822  assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
3823  Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3824  (producesResult ? ProducesResultMask : 0) |
3825  (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3826  (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3827  (NoCfCheck ? NoCfCheckMask : 0) |
3828  (cmseNSCall ? CmseNSCallMask : 0);
3829  }
3830 
3831  // Constructor with all defaults. Use when for example creating a
3832  // function known to use defaults.
3833  ExtInfo() = default;
3834 
3835  // Constructor with just the calling convention, which is an important part
3836  // of the canonical type.
3837  ExtInfo(CallingConv CC) : Bits(CC) {}
3838 
3839  bool getNoReturn() const { return Bits & NoReturnMask; }
3840  bool getProducesResult() const { return Bits & ProducesResultMask; }
3841  bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
3842  bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
3843  bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
3844  bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
3845 
3846  unsigned getRegParm() const {
3847  unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3848  if (RegParm > 0)
3849  --RegParm;
3850  return RegParm;
3851  }
3852 
3853  CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
3854 
3855  bool operator==(ExtInfo Other) const {
3856  return Bits == Other.Bits;
3857  }
3858  bool operator!=(ExtInfo Other) const {
3859  return Bits != Other.Bits;
3860  }
3861 
3862  // Note that we don't have setters. That is by design, use
3863  // the following with methods instead of mutating these objects.
3864 
3865  ExtInfo withNoReturn(bool noReturn) const {
3866  if (noReturn)
3867  return ExtInfo(Bits | NoReturnMask);
3868  else
3869  return ExtInfo(Bits & ~NoReturnMask);
3870  }
3871 
3872  ExtInfo withProducesResult(bool producesResult) const {
3873  if (producesResult)
3874  return ExtInfo(Bits | ProducesResultMask);
3875  else
3876  return ExtInfo(Bits & ~ProducesResultMask);
3877  }
3878 
3879  ExtInfo withCmseNSCall(bool cmseNSCall) const {
3880  if (cmseNSCall)
3881  return ExtInfo(Bits | CmseNSCallMask);
3882  else
3883  return ExtInfo(Bits & ~CmseNSCallMask);
3884  }
3885 
3886  ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
3887  if (noCallerSavedRegs)
3888  return ExtInfo(Bits | NoCallerSavedRegsMask);
3889  else
3890  return ExtInfo(Bits & ~NoCallerSavedRegsMask);
3891  }
3892 
3893  ExtInfo withNoCfCheck(bool noCfCheck) const {
3894  if (noCfCheck)
3895  return ExtInfo(Bits | NoCfCheckMask);
3896  else
3897  return ExtInfo(Bits & ~NoCfCheckMask);
3898  }
3899 
3900  ExtInfo withRegParm(unsigned RegParm) const {
3901  assert(RegParm < 7 && "Invalid regparm value");
3902  return ExtInfo((Bits & ~RegParmMask) |
3903  ((RegParm + 1) << RegParmOffset));
3904  }
3905 
3907  return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
3908  }
3909 
3910  void Profile(llvm::FoldingSetNodeID &ID) const {
3911  ID.AddInteger(Bits);
3912  }
3913  };
3914 
3915  /// A simple holder for a QualType representing a type in an
3916  /// exception specification. Unfortunately needed by FunctionProtoType
3917  /// because TrailingObjects cannot handle repeated types.
3919 
3920  /// A simple holder for various uncommon bits which do not fit in
3921  /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
3922  /// alignment of subsequent objects in TrailingObjects.
3923  struct alignas(void *) FunctionTypeExtraBitfields {
3924  /// The number of types in the exception specification.
3925  /// A whole unsigned is not needed here and according to
3926  /// [implimits] 8 bits would be enough here.
3927  unsigned NumExceptionType = 0;
3928  };
3929 
3930 protected:
3933  : Type(tc, Canonical, Dependence), ResultType(res) {
3934  FunctionTypeBits.ExtInfo = Info.Bits;
3935  }
3936 
3938  if (isFunctionProtoType())
3939  return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
3940 
3941  return Qualifiers();
3942  }
3943 
3944 public:
3945  QualType getReturnType() const { return ResultType; }
3946 
3947  bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
3948  unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
3949 
3950  /// Determine whether this function type includes the GNU noreturn
3951  /// attribute. The C++11 [[noreturn]] attribute does not affect the function
3952  /// type.
3953  bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
3954 
3955  bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
3956  CallingConv getCallConv() const { return getExtInfo().getCC(); }
3957  ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
3958 
3959  static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
3960  "Const, volatile and restrict are assumed to be a subset of "
3961  "the fast qualifiers.");
3962 
3963  bool isConst() const { return getFastTypeQuals().hasConst(); }
3964  bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
3965  bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
3966 
3967  /// Determine the type of an expression that calls a function of
3968  /// this type.
3969  QualType getCallResultType(const ASTContext &Context) const {
3970  return getReturnType().getNonLValueExprType(Context);
3971  }
3972 
3973  static StringRef getNameForCallConv(CallingConv CC);
3974 
3975  static bool classof(const Type *T) {
3976  return T->getTypeClass() == FunctionNoProto ||
3977  T->getTypeClass() == FunctionProto;
3978  }
3979 };
3980 
3981 /// Represents a K&R-style 'int foo()' function, which has
3982 /// no information available about its arguments.
3983 class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
3984  friend class ASTContext; // ASTContext creates these.
3985 
3986  FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
3987  : FunctionType(FunctionNoProto, Result, Canonical,
3988  Result->getDependence() &
3989  ~(TypeDependence::DependentInstantiation |
3990  TypeDependence::UnexpandedPack),
3991  Info) {}
3992 
3993 public:
3994  // No additional state past what FunctionType provides.
3995 
3996  bool isSugared() const { return false; }
3997  QualType desugar() const { return QualType(this, 0); }
3998 
3999  void Profile(llvm::FoldingSetNodeID &ID) {
4001  }
4002 
4003  static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
4004  ExtInfo Info) {
4005  Info.Profile(ID);
4006  ID.AddPointer(ResultType.getAsOpaquePtr());
4007  }
4008 
4009  static bool classof(const Type *T) {
4010  return T->getTypeClass() == FunctionNoProto;
4011  }
4012 };
4013 
4014 /// Represents a prototype with parameter type info, e.g.
4015 /// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
4016 /// parameters, not as having a single void parameter. Such a type can have
4017 /// an exception specification, but this specification is not part of the
4018 /// canonical type. FunctionProtoType has several trailing objects, some of
4019 /// which optional. For more information about the trailing objects see
4020 /// the first comment inside FunctionProtoType.
4022  : public FunctionType,
4023  public llvm::FoldingSetNode,
4024  private llvm::TrailingObjects<
4025  FunctionProtoType, QualType, SourceLocation,
4026  FunctionType::FunctionTypeExtraBitfields, FunctionType::ExceptionType,
4027  Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
4028  friend class ASTContext; // ASTContext creates these.
4029  friend TrailingObjects;
4030 
4031  // FunctionProtoType is followed by several trailing objects, some of
4032  // which optional. They are in order:
4033  //
4034  // * An array of getNumParams() QualType holding the parameter types.
4035  // Always present. Note that for the vast majority of FunctionProtoType,
4036  // these will be the only trailing objects.
4037  //
4038  // * Optionally if the function is variadic, the SourceLocation of the
4039  // ellipsis.
4040  //
4041  // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
4042  // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
4043  // a single FunctionTypeExtraBitfields. Present if and only if
4044  // hasExtraBitfields() is true.
4045  //
4046  // * Optionally exactly one of:
4047  // * an array of getNumExceptions() ExceptionType,
4048  // * a single Expr *,
4049  // * a pair of FunctionDecl *,
4050  // * a single FunctionDecl *
4051  // used to store information about the various types of exception
4052  // specification. See getExceptionSpecSize for the details.
4053  //
4054  // * Optionally an array of getNumParams() ExtParameterInfo holding
4055  // an ExtParameterInfo for each of the parameters. Present if and
4056  // only if hasExtParameterInfos() is true.
4057  //
4058  // * Optionally a Qualifiers object to represent extra qualifiers that can't
4059  // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and only
4060  // if hasExtQualifiers() is true.
4061  //
4062  // The optional FunctionTypeExtraBitfields has to be before the data
4063  // related to the exception specification since it contains the number
4064  // of exception types.
4065  //
4066  // We put the ExtParameterInfos last. If all were equal, it would make
4067  // more sense to put these before the exception specification, because
4068  // it's much easier to skip past them compared to the elaborate switch
4069  // required to skip the exception specification. However, all is not
4070  // equal; ExtParameterInfos are used to model very uncommon features,
4071  // and it's better not to burden the more common paths.
4072 
4073 public:
4074  /// Holds information about the various types of exception specification.
4075  /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
4076  /// used to group together the various bits of information about the
4077  /// exception specification.
4079  /// The kind of exception specification this is.
4081 
4082  /// Explicitly-specified list of exception types.
4084 
4085  /// Noexcept expression, if this is a computed noexcept specification.
4086  Expr *NoexceptExpr = nullptr;
4087 
4088  /// The function whose exception specification this is, for
4089  /// EST_Unevaluated and EST_Uninstantiated.
4091 
4092  /// The function template whose exception specification this is instantiated
4093  /// from, for EST_Uninstantiated.
4095 
4096  ExceptionSpecInfo() = default;
4097 
4099  };
4100 
4101  /// Extra information about a function prototype. ExtProtoInfo is not
4102  /// stored as such in FunctionProtoType but is used to group together
4103  /// the various bits of extra information about a function prototype.
4104  struct ExtProtoInfo {
4106  bool Variadic : 1;
4113 
4115 
4118 
4120  ExtProtoInfo Result(*this);
4121  Result.ExceptionSpec = ESI;
4122  return Result;
4123  }
4124 
4126  return ExceptionSpec.Type == EST_Dynamic;
4127  }
4128  };
4129 
4130 private:
4131  unsigned numTrailingObjects(OverloadToken<QualType>) const {
4132  return getNumParams();
4133  }
4134 
4135  unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
4136  return isVariadic();
4137  }
4138 
4139  unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
4140  return hasExtraBitfields();
4141  }
4142 
4143  unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
4144  return getExceptionSpecSize().NumExceptionType;
4145  }
4146 
4147  unsigned numTrailingObjects(OverloadToken<Expr *>) const {
4148  return getExceptionSpecSize().NumExprPtr;
4149  }
4150 
4151  unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
4152  return getExceptionSpecSize().NumFunctionDeclPtr;
4153  }
4154 
4155  unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
4156  return hasExtParameterInfos() ? getNumParams() : 0;
4157  }
4158 
4159  /// Determine whether there are any argument types that
4160  /// contain an unexpanded parameter pack.
4161  static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
4162  unsigned numArgs) {
4163  for (unsigned Idx = 0; Idx < numArgs; ++Idx)
4164  if (ArgArray[Idx]->containsUnexpandedParameterPack())
4165  return true;
4166 
4167  return false;
4168  }
4169 
4170  FunctionProtoType(QualType result, ArrayRef<QualType> params,
4171  QualType canonical, const ExtProtoInfo &epi);
4172 
4173  /// This struct is returned by getExceptionSpecSize and is used to
4174  /// translate an ExceptionSpecificationType to the number and kind
4175  /// of trailing objects related to the exception specification.
4176  struct ExceptionSpecSizeHolder {
4177  unsigned NumExceptionType;
4178  unsigned NumExprPtr;
4179  unsigned NumFunctionDeclPtr;
4180  };
4181 
4182  /// Return the number and kind of trailing objects
4183  /// related to the exception specification.
4184  static ExceptionSpecSizeHolder
4185  getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
4186  switch (EST) {
4187  case EST_None:
4188  case EST_DynamicNone:
4189  case EST_MSAny:
4190  case EST_BasicNoexcept:
4191  case EST_Unparsed:
4192  case EST_NoThrow:
4193  return {0, 0, 0};
4194 
4195  case EST_Dynamic:
4196  return {NumExceptions, 0, 0};
4197 
4198  case EST_DependentNoexcept:
4199  case EST_NoexceptFalse:
4200  case EST_NoexceptTrue:
4201  return {0, 1, 0};
4202 
4203  case EST_Uninstantiated:
4204  return {0, 0, 2};
4205 
4206  case EST_Unevaluated:
4207  return {0, 0, 1};
4208  }
4209  llvm_unreachable("bad exception specification kind");
4210  }
4211 
4212  /// Return the number and kind of trailing objects
4213  /// related to the exception specification.
4214  ExceptionSpecSizeHolder getExceptionSpecSize() const {
4215  return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
4216  }
4217 
4218  /// Whether the trailing FunctionTypeExtraBitfields is present.
4219  bool hasExtraBitfields() const {
4220  assert((getExceptionSpecType() != EST_Dynamic ||
4221  FunctionTypeBits.HasExtraBitfields) &&
4222  "ExtraBitfields are required for given ExceptionSpecType");
4223  return FunctionTypeBits.HasExtraBitfields;
4224 
4225  }
4226 
4227  bool hasExtQualifiers() const {
4228  return FunctionTypeBits.HasExtQuals;
4229  }
4230 
4231 public:
4232  unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
4233 
4234  QualType getParamType(unsigned i) const {
4235  assert(i < getNumParams() && "invalid parameter index");
4236  return param_type_begin()[i];
4237  }
4238 
4241  }
4242 
4244  ExtProtoInfo EPI;
4245  EPI.ExtInfo = getExtInfo();
4246  EPI.Variadic = isVariadic();
4247  EPI.EllipsisLoc = getEllipsisLoc();
4250  EPI.TypeQuals = getMethodQuals();
4251  EPI.RefQualifier = getRefQualifier();
4253  return EPI;
4254  }
4255 
4256  /// Get the kind of exception specification on this function.
4258  return static_cast<ExceptionSpecificationType>(
4259  FunctionTypeBits.ExceptionSpecType);
4260  }
4261 
4262  /// Return whether this function has any kind of exception spec.
4263  bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
4264 
4265  /// Return whether this function has a dynamic (throw) exception spec.
4268  }
4269 
4270  /// Return whether this function has a noexcept exception spec.
4273  }
4274 
4275  /// Return whether this function has a dependent exception spec.
4276  bool hasDependentExceptionSpec() const;
4277 
4278  /// Return whether this function has an instantiation-dependent exception
4279  /// spec.
4281 
4282  /// Return all the available information about this type's exception spec.
4284  ExceptionSpecInfo Result;
4285  Result.Type = getExceptionSpecType();
4286  if (Result.Type == EST_Dynamic) {
4287  Result.Exceptions = exceptions();
4288  } else if (isComputedNoexcept(Result.Type)) {
4289  Result.NoexceptExpr = getNoexceptExpr();
4290  } else if (Result.Type == EST_Uninstantiated) {
4291  Result.SourceDecl = getExceptionSpecDecl();
4292  Result.SourceTemplate = getExceptionSpecTemplate();
4293  } else if (Result.Type == EST_Unevaluated) {
4294  Result.SourceDecl = getExceptionSpecDecl();
4295  }
4296  return Result;
4297  }
4298 
4299  /// Return the number of types in the exception specification.
4300  unsigned getNumExceptions() const {
4301  return getExceptionSpecType() == EST_Dynamic
4302  ? getTrailingObjects<FunctionTypeExtraBitfields>()
4303  ->NumExceptionType
4304  : 0;
4305  }
4306 
4307  /// Return the ith exception type, where 0 <= i < getNumExceptions().
4308  QualType getExceptionType(unsigned i) const {
4309  assert(i < getNumExceptions() && "Invalid exception number!");
4310  return exception_begin()[i];
4311  }
4312 
4313  /// Return the expression inside noexcept(expression), or a null pointer
4314  /// if there is none (because the exception spec is not of this form).
4317  return nullptr;
4318  return *getTrailingObjects<Expr *>();
4319  }
4320 
4321  /// If this function type has an exception specification which hasn't
4322  /// been determined yet (either because it has not been evaluated or because
4323  /// it has not been instantiated), this is the function whose exception
4324  /// specification is represented by this type.
4328  return nullptr;
4329  return getTrailingObjects<FunctionDecl *>()[0];
4330  }
4331 
4332  /// If this function type has an uninstantiated exception
4333  /// specification, this is the function whose exception specification
4334  /// should be instantiated to find the exception specification for
4335  /// this type.
4338  return nullptr;
4339  return getTrailingObjects<FunctionDecl *>()[1];
4340  }
4341 
4342  /// Determine whether this function type has a non-throwing exception
4343  /// specification.
4344  CanThrowResult canThrow() const;
4345 
4346  /// Determine whether this function type has a non-throwing exception
4347  /// specification. If this depends on template arguments, returns
4348  /// \c ResultIfDependent.
4349  bool isNothrow(bool ResultIfDependent = false) const {
4350  return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
4351  }
4352 
4353  /// Whether this function prototype is variadic.
4354  bool isVariadic() const { return FunctionTypeBits.Variadic; }
4355 
4357  return isVariadic() ? *getTrailingObjects<SourceLocation>()
4358  : SourceLocation();
4359  }
4360 
4361  /// Determines whether this function prototype contains a
4362  /// parameter pack at the end.
4363  ///
4364  /// A function template whose last parameter is a parameter pack can be
4365  /// called with an arbitrary number of arguments, much like a variadic
4366  /// function.
4367  bool isTemplateVariadic() const;
4368 
4369  /// Whether this function prototype has a trailing return type.
4370  bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
4371 
4373  if (hasExtQualifiers())
4374  return *getTrailingObjects<Qualifiers>();
4375  else
4376  return getFastTypeQuals();
4377  }
4378 
4379  /// Retrieve the ref-qualifier associated with this function type.
4381  return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
4382  }
4383 
4385 
4388  }
4389 
4391  return getTrailingObjects<QualType>();
4392  }
4393 
4395  return param_type_begin() + getNumParams();
4396  }
4397 
4398  using exception_iterator = const QualType *;
4399 
4402  }
4403 
4405  return reinterpret_cast<exception_iterator>(
4406  getTrailingObjects<ExceptionType>());
4407  }
4408 
4410  return exception_begin() + getNumExceptions();
4411  }
4412 
4413  /// Is there any interesting extra information for any of the parameters
4414  /// of this function type?
4415  bool hasExtParameterInfos() const {
4416  return FunctionTypeBits.HasExtParameterInfos;
4417  }
4418 
4420  assert(hasExtParameterInfos());
4421  return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
4422  getNumParams());
4423  }
4424 
4425  /// Return a pointer to the beginning of the array of extra parameter
4426  /// information, if present, or else null if none of the parameters
4427  /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
4429  if (!hasExtParameterInfos())
4430  return nullptr;
4431  return getTrailingObjects<ExtParameterInfo>();
4432  }
4433 
4435  assert(I < getNumParams() && "parameter index out of range");
4436  if (hasExtParameterInfos())
4437  return getTrailingObjects<ExtParameterInfo>()[I];
4438  return ExtParameterInfo();
4439  }
4440 
4441  ParameterABI getParameterABI(unsigned I) const {
4442  assert(I < getNumParams() && "parameter index out of range");
4443  if (hasExtParameterInfos())
4444  return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4445  return ParameterABI::Ordinary;
4446  }
4447 
4448  bool isParamConsumed(unsigned I) const {
4449  assert(I < getNumParams() && "parameter index out of range");
4450  if (hasExtParameterInfos())
4451  return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4452  return false;
4453  }
4454 
4455  bool isSugared() const { return false; }
4456  QualType desugar() const { return QualType(this, 0); }
4457 
4458  void printExceptionSpecification(raw_ostream &OS,
4459  const PrintingPolicy &Policy) const;
4460 
4461  static bool classof(const Type *T) {
4462  return T->getTypeClass() == FunctionProto;
4463  }
4464 
4465  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
4466  static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
4467  param_type_iterator ArgTys, unsigned NumArgs,
4468  const ExtProtoInfo &EPI, const ASTContext &Context,
4469  bool Canonical);
4470 };
4471 
4472 /// Represents the dependent type named by a dependently-scoped
4473 /// typename using declaration, e.g.
4474 /// using typename Base<T>::foo;
4475 ///
4476 /// Template instantiation turns these into the underlying type.
4477 class UnresolvedUsingType : public Type {
4478  friend class ASTContext; // ASTContext creates these.
4479 
4481 
4483  : Type(UnresolvedUsing, QualType(),
4484  TypeDependence::DependentInstantiation),
4485  Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {}
4486 
4487 public:
4489 
4490  bool isSugared() const { return false; }
4491  QualType desugar() const { return QualType(this, 0); }
4492 
4493  static bool classof(const Type *T) {
4494  return T->getTypeClass() == UnresolvedUsing;
4495  }
4496 
4497  void Profile(llvm::FoldingSetNodeID &ID) {
4498  return Profile(ID, Decl);
4499  }
4500 
4501  static void Profile(llvm::FoldingSetNodeID &ID,
4503  ID.AddPointer(D);
4504  }
4505 };
4506 
4507 class UsingType final : public Type,
4508  public llvm::FoldingSetNode,
4509  private llvm::TrailingObjects<UsingType, QualType> {
4510  UsingShadowDecl *Found;
4511  friend class ASTContext; // ASTContext creates these.
4512  friend TrailingObjects;
4513 
4514  UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
4515 
4516 public:
4517  UsingShadowDecl *getFoundDecl() const { return Found; }
4518  QualType getUnderlyingType() const;
4519 
4520  bool isSugared() const { return true; }
4521 
4522  // This always has the 'same' type as declared, but not necessarily identical.
4523  QualType desugar() const { return getUnderlyingType(); }
4524 
4525  // Internal helper, for debugging purposes.
4526  bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
4527 
4528  void Profile(llvm::FoldingSetNodeID &ID) {
4530  }
4531  static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
4532  QualType Underlying) {
4533  ID.AddPointer(Found);
4534  if (!Underlying.isNull())
4535  Underlying.Profile(ID);
4536  }
4537  static bool classof(const Type *T) { return T->getTypeClass() == Using; }
4538 };
4539 
4540 class TypedefType final : public Type,
4541  public llvm::FoldingSetNode,
4542  private llvm::TrailingObjects<TypedefType, QualType> {
4544  friend class ASTContext; // ASTContext creates these.
4545  friend TrailingObjects;
4546 
4547  TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
4548  QualType can);
4549 
4550 public:
4551  TypedefNameDecl *getDecl() const { return Decl; }
4552 
4553  bool isSugared() const { return true; }
4554 
4555  // This always has the 'same' type as declared, but not necessarily identical.
4556  QualType desugar() const;
4557 
4558  // Internal helper, for debugging purposes.
4559  bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
4560 
4561  void Profile(llvm::FoldingSetNodeID &ID) {
4563  }
4564  static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl,
4565  QualType Underlying) {
4566  ID.AddPointer(Decl);
4567  if (!Underlying.isNull())
4568  Underlying.Profile(ID);
4569  }
4570 
4571  static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
4572 };
4573 
4574 /// Sugar type that represents a type that was qualified by a qualifier written
4575 /// as a macro invocation.
4576 class MacroQualifiedType : public Type {
4577  friend class ASTContext; // ASTContext creates these.
4578 
4579  QualType UnderlyingTy;
4580  const IdentifierInfo *MacroII;
4581 
4582  MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
4583  const IdentifierInfo *MacroII)
4584  : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
4585  UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
4586  assert(isa<AttributedType>(UnderlyingTy) &&
4587  "Expected a macro qualified type to only wrap attributed types.");
4588  }
4589 
4590 public:
4591  const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
4592  QualType getUnderlyingType() const { return UnderlyingTy; }
4593 
4594  /// Return this attributed type's modified type with no qualifiers attached to
4595  /// it.
4596  QualType getModifiedType() const;
4597 
4598  bool isSugared() const { return true; }
4599  QualType desugar() const;
4600 
4601  static bool classof(const Type *T) {
4602  return T->getTypeClass() == MacroQualified;
4603  }
4604 };
4605 
4606 /// Represents a `typeof` (or __typeof__) expression (a C2x feature and GCC
4607 /// extension) or a `typeof_unqual` expression (a C2x feature).
4608 class TypeOfExprType : public Type {
4609  Expr *TOExpr;
4610 
4611 protected:
4612  friend class ASTContext; // ASTContext creates these.
4613 
4615 
4616 public:
4617  Expr *getUnderlyingExpr() const { return TOExpr; }
4618 
4619  /// Returns the kind of 'typeof' type this is.
4621  return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
4623  }
4624 
4625  /// Remove a single level of sugar.
4626  QualType desugar() const;
4627 
4628  /// Returns whether this type directly provides sugar.
4629  bool isSugared() const;
4630 
4631  static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
4632 };
4633 
4634 /// Internal representation of canonical, dependent
4635 /// `typeof(expr)` types.
4636 ///
4637 /// This class is used internally by the ASTContext to manage
4638 /// canonical, dependent types, only. Clients will only see instances
4639 /// of this class via TypeOfExprType nodes.
4641  : public TypeOfExprType, public llvm::FoldingSetNode {
4642  const ASTContext &Context;
4643 
4644 public:
4646  : TypeOfExprType(E, Kind), Context(Context) {}
4647 
4648  void Profile(llvm::FoldingSetNodeID &ID) {
4649  Profile(ID, Context, getUnderlyingExpr(),
4651  }
4652 
4653  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4654  Expr *E, bool IsUnqual);
4655 };
4656 
4657 /// Represents `typeof(type)`, a C2x feature and GCC extension, or
4658 /// `typeof_unqual(type), a C2x feature.
4659 class TypeOfType : public Type {
4660  friend class ASTContext; // ASTContext creates these.
4661 
4662  QualType TOType;
4663 
4665  : Type(TypeOf,
4666  Kind == TypeOfKind::Unqualified ? Can.getAtomicUnqualifiedType()
4667  : Can,
4668  T->getDependence()),
4669  TOType(T) {
4670  TypeOfBits.IsUnqual = Kind == TypeOfKind::Unqualified;
4671  }
4672 
4673 public:
4674  QualType getUnmodifiedType() const { return TOType; }
4675 
4676  /// Remove a single level of sugar.
4677  QualType desugar() const {
4678  QualType QT = getUnmodifiedType();
4679  return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
4680  }
4681 
4682  /// Returns whether this type directly provides sugar.
4683  bool isSugared() const { return true; }
4684 
4685  /// Returns the kind of 'typeof' type this is.
4687  return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
4689  }
4690 
4691  static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
4692 };
4693 
4694 /// Represents the type `decltype(expr)` (C++11).
4695 class DecltypeType : public Type {
4696  Expr *E;
4697  QualType UnderlyingType;
4698 
4699 protected:
4700  friend class ASTContext; // ASTContext creates these.
4701 
4702  DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
4703 
4704 public:
4705  Expr *getUnderlyingExpr() const { return E; }
4706  QualType getUnderlyingType() const { return UnderlyingType; }
4707 
4708  /// Remove a single level of sugar.
4709  QualType desugar() const;
4710 
4711  /// Returns whether this type directly provides sugar.
4712  bool isSugared() const;
4713 
4714  static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
4715 };
4716 
4717 /// Internal representation of canonical, dependent
4718 /// decltype(expr) types.
4719 ///
4720 /// This class is used internally by the ASTContext to manage
4721 /// canonical, dependent types, only. Clients will only see instances
4722 /// of this class via DecltypeType nodes.
4723 class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
4724  const ASTContext &Context;
4725 
4726 public:
4727  DependentDecltypeType(const ASTContext &Context, Expr *E);
4728 
4729  void Profile(llvm::FoldingSetNodeID &ID) {
4730  Profile(ID, Context, getUnderlyingExpr());
4731  }
4732 
4733  static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4734  Expr *E);
4735 };
4736 
4737 /// A unary type transform, which is a type constructed from another.
4738 class UnaryTransformType : public Type {
4739 public:
4740  enum UTTKind {
4741 #define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
4742 #include "clang/Basic/TransformTypeTraits.def"
4743  };
4744 
4745 private:
4746  /// The untransformed type.
4747  QualType BaseType;
4748 
4749  /// The transformed type if not dependent, otherwise the same as BaseType.
4750  QualType UnderlyingType;
4751 
4752  UTTKind UKind;
4753 
4754 protected:
4755  friend class ASTContext;
4756 
4757  UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
4758  QualType CanonicalTy);
4759 
4760 public:
4761  bool isSugared() const { return !isDependentType(); }
4762  QualType desugar() const { return UnderlyingType; }
4763 
4764  QualType getUnderlyingType() const { return UnderlyingType; }
4765  QualType getBaseType() const { return BaseType; }
4766 
4767  UTTKind getUTTKind() const { return UKind; }
4768 
4769  static bool classof(const Type *T) {
4770  return T->getTypeClass() == UnaryTransform;
4771  }
4772 };
4773 
4774 /// Internal representation of canonical, dependent
4775 /// __underlying_type(type) types.
4776 ///
4777 /// This class is used internally by the ASTContext to manage
4778 /// canonical, dependent types, only. Clients will only see instances
4779 /// of this class via UnaryTransformType nodes.
4781  public llvm::FoldingSetNode {
4782 public:
4783  DependentUnaryTransformType(const ASTContext &C, QualType BaseType,
4784  UTTKind UKind);
4785 
4786  void Profile(llvm::FoldingSe