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