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 &= ~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 &= ~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 /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2382 /// object types, function types, and incomplete types.
2383
2384 /// Return true if this is an incomplete type.
2385 /// A type that can describe objects, but which lacks information needed to
2386 /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2387 /// routine will need to determine if the size is actually required.
2388 ///
2389 /// Def If non-null, and the type refers to some kind of declaration
2390 /// that can be completed (such as a C struct, C++ class, or Objective-C
2391 /// class), will be set to the declaration.
2392 bool isIncompleteType(NamedDecl **Def = nullptr) const;
2393
2394 /// Return true if this is an incomplete or object
2395 /// type, in other words, not a function type.
2397 return !isFunctionType();
2398 }
2399
2400 /// Determine whether this type is an object type.
2401 bool isObjectType() const {
2402 // C++ [basic.types]p8:
2403 // An object type is a (possibly cv-qualified) type that is not a
2404 // function type, not a reference type, and not a void type.
2405 return !isReferenceType() && !isFunctionType() && !isVoidType();
2406 }
2407
2408 /// Return true if this is a literal type
2409 /// (C++11 [basic.types]p10)
2410 bool isLiteralType(const ASTContext &Ctx) const;
2411
2412 /// Determine if this type is a structural type, per C++20 [temp.param]p7.
2413 bool isStructuralType() const;
2414
2415 /// Test if this type is a standard-layout type.
2416 /// (C++0x [basic.type]p9)
2417 bool isStandardLayoutType() const;
2418
2419 /// Helper methods to distinguish type categories. All type predicates
2420 /// operate on the canonical type, ignoring typedefs and qualifiers.
2421
2422 /// Returns true if the type is a builtin type.
2423 bool isBuiltinType() const;
2424
2425 /// Test for a particular builtin type.
2426 bool isSpecificBuiltinType(unsigned K) const;
2427
2428 /// Test for a type which does not represent an actual type-system type but
2429 /// is instead used as a placeholder for various convenient purposes within
2430 /// Clang. All such types are BuiltinTypes.
2431 bool isPlaceholderType() const;
2432 const BuiltinType *getAsPlaceholderType() const;
2433
2434 /// Test for a specific placeholder type.
2435 bool isSpecificPlaceholderType(unsigned K) const;
2436
2437 /// Test for a placeholder type other than Overload; see
2438 /// BuiltinType::isNonOverloadPlaceholderType.
2439 bool isNonOverloadPlaceholderType() const;
2440
2441 /// isIntegerType() does *not* include complex integers (a GCC extension).
2442 /// isComplexIntegerType() can be used to test for complex integers.
2443 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
2444 bool isEnumeralType() const;
2445
2446 /// Determine whether this type is a scoped enumeration type.
2447 bool isScopedEnumeralType() const;
2448 bool isBooleanType() const;
2449 bool isCharType() const;
2450 bool isWideCharType() const;
2451 bool isChar8Type() const;
2452 bool isChar16Type() const;
2453 bool isChar32Type() const;
2454 bool isAnyCharacterType() const;
2455 bool isIntegralType(const ASTContext &Ctx) const;
2456
2457 /// Determine whether this type is an integral or enumeration type.
2458 bool isIntegralOrEnumerationType() const;
2459
2460 /// Determine whether this type is an integral or unscoped enumeration type.
2461 bool isIntegralOrUnscopedEnumerationType() const;
2462 bool isUnscopedEnumerationType() const;
2463
2464 /// Floating point categories.
2465 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2466 /// isComplexType() does *not* include complex integers (a GCC extension).
2467 /// isComplexIntegerType() can be used to test for complex integers.
2468 bool isComplexType() const; // C99 6.2.5p11 (complex)
2469 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
2470 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
2471 bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
2472 bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
2473 bool isFloat32Type() const;
2474 bool isDoubleType() const;
2475 bool isBFloat16Type() const;
2476 bool isFloat128Type() const;
2477 bool isIbm128Type() const;
2478 bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
2479 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
2480 bool isVoidType() const; // C99 6.2.5p19
2481 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
2482 bool isAggregateType() const;
2483 bool isFundamentalType() const;
2484 bool isCompoundType() const;
2485
2486 // Type Predicates: Check to see if this type is structurally the specified
2487 // type, ignoring typedefs and qualifiers.
2488 bool isFunctionType() const;
2489 bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); }
2490 bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); }
2491 bool isPointerType() const;
2492 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
2493 bool isCountAttributedType() const;
2494 bool isBlockPointerType() const;
2495 bool isVoidPointerType() const;
2496 bool isReferenceType() const;
2497 bool isLValueReferenceType() const;
2498 bool isRValueReferenceType() const;
2499 bool isObjectPointerType() const;
2500 bool isFunctionPointerType() const;
2501 bool isFunctionReferenceType() const;
2502 bool isMemberPointerType() const;
2503 bool isMemberFunctionPointerType() const;
2504 bool isMemberDataPointerType() const;
2505 bool isArrayType() const;
2506 bool isConstantArrayType() const;
2507 bool isIncompleteArrayType() const;
2508 bool isVariableArrayType() const;
2509 bool isArrayParameterType() const;
2510 bool isDependentSizedArrayType() const;
2511 bool isRecordType() const;
2512 bool isClassType() const;
2513 bool isStructureType() const;
2514 bool isObjCBoxableRecordType() const;
2515 bool isInterfaceType() const;
2516 bool isStructureOrClassType() const;
2517 bool isUnionType() const;
2518 bool isComplexIntegerType() const; // GCC _Complex integer type.
2519 bool isVectorType() const; // GCC vector type.
2520 bool isExtVectorType() const; // Extended vector type.
2521 bool isExtVectorBoolType() const; // Extended vector type with bool element.
2522 bool isMatrixType() const; // Matrix type.
2523 bool isConstantMatrixType() const; // Constant matrix type.
2524 bool isDependentAddressSpaceType() const; // value-dependent address space qualifier
2525 bool isObjCObjectPointerType() const; // pointer to ObjC object
2526 bool isObjCRetainableType() const; // ObjC object or block pointer
2527 bool isObjCLifetimeType() const; // (array of)* retainable type
2528 bool isObjCIndirectLifetimeType() const; // (pointer to)* lifetime type
2529 bool isObjCNSObjectType() const; // __attribute__((NSObject))
2530 bool isObjCIndependentClassType() const; // __attribute__((objc_independent_class))
2531 // FIXME: change this to 'raw' interface type, so we can used 'interface' type
2532 // for the common case.
2533 bool isObjCObjectType() const; // NSString or typeof(*(id)0)
2534 bool isObjCQualifiedInterfaceType() const; // NSString<foo>
2535 bool isObjCQualifiedIdType() const; // id<foo>
2536 bool isObjCQualifiedClassType() const; // Class<foo>
2537 bool isObjCObjectOrInterfaceType() const;
2538 bool isObjCIdType() const; // id
2539 bool isDecltypeType() const;
2540 /// Was this type written with the special inert-in-ARC __unsafe_unretained
2541 /// qualifier?
2542 ///
2543 /// This approximates the answer to the following question: if this
2544 /// translation unit were compiled in ARC, would this type be qualified
2545 /// with __unsafe_unretained?
2547 return hasAttr(attr::ObjCInertUnsafeUnretained);
2548 }
2549
2550 /// Whether the type is Objective-C 'id' or a __kindof type of an
2551 /// object type, e.g., __kindof NSView * or __kindof id
2552 /// <NSCopying>.
2553 ///
2554 /// \param bound Will be set to the bound on non-id subtype types,
2555 /// which will be (possibly specialized) Objective-C class type, or
2556 /// null for 'id.
2557 bool isObjCIdOrObjectKindOfType(const ASTContext &ctx,
2558 const ObjCObjectType *&bound) const;
2559
2560 bool isObjCClassType() const; // Class
2561
2562 /// Whether the type is Objective-C 'Class' or a __kindof type of an
2563 /// Class type, e.g., __kindof Class <NSCopying>.
2564 ///
2565 /// Unlike \c isObjCIdOrObjectKindOfType, there is no relevant bound
2566 /// here because Objective-C's type system cannot express "a class
2567 /// object for a subclass of NSFoo".
2568 bool isObjCClassOrClassKindOfType() const;
2569
2570 bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const;
2571 bool isObjCSelType() const; // Class
2572 bool isObjCBuiltinType() const; // 'id' or 'Class'
2573 bool isObjCARCBridgableType() const;
2574 bool isCARCBridgableType() const;
2575 bool isTemplateTypeParmType() const; // C++ template type parameter
2576 bool isNullPtrType() const; // C++11 std::nullptr_t or
2577 // C23 nullptr_t
2578 bool isNothrowT() const; // C++ std::nothrow_t
2579 bool isAlignValT() const; // C++17 std::align_val_t
2580 bool isStdByteType() const; // C++17 std::byte
2581 bool isAtomicType() const; // C11 _Atomic()
2582 bool isUndeducedAutoType() const; // C++11 auto or
2583 // C++14 decltype(auto)
2584 bool isTypedefNameType() const; // typedef or alias template
2585
2586#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2587 bool is##Id##Type() const;
2588#include "clang/Basic/OpenCLImageTypes.def"
2589
2590 bool isImageType() const; // Any OpenCL image type
2591
2592 bool isSamplerT() const; // OpenCL sampler_t
2593 bool isEventT() const; // OpenCL event_t
2594 bool isClkEventT() const; // OpenCL clk_event_t
2595 bool isQueueT() const; // OpenCL queue_t
2596 bool isReserveIDT() const; // OpenCL reserve_id_t
2597
2598#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2599 bool is##Id##Type() const;
2600#include "clang/Basic/OpenCLExtensionTypes.def"
2601 // Type defined in cl_intel_device_side_avc_motion_estimation OpenCL extension
2602 bool isOCLIntelSubgroupAVCType() const;
2603 bool isOCLExtOpaqueType() const; // Any OpenCL extension type
2604
2605 bool isPipeType() const; // OpenCL pipe type
2606 bool isBitIntType() const; // Bit-precise integer type
2607 bool isOpenCLSpecificType() const; // Any OpenCL specific type
2608
2609 /// Determines if this type, which must satisfy
2610 /// isObjCLifetimeType(), is implicitly __unsafe_unretained rather
2611 /// than implicitly __strong.
2612 bool isObjCARCImplicitlyUnretainedType() const;
2613
2614 /// Check if the type is the CUDA device builtin surface type.
2615 bool isCUDADeviceBuiltinSurfaceType() const;
2616 /// Check if the type is the CUDA device builtin texture type.
2617 bool isCUDADeviceBuiltinTextureType() const;
2618
2619 /// Return the implicit lifetime for this type, which must not be dependent.
2620 Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
2621
2632 STK_FixedPoint
2634
2635 /// Given that this is a scalar type, classify it.
2636 ScalarTypeKind getScalarTypeKind() const;
2637
2639 return static_cast<TypeDependence>(TypeBits.Dependence);
2640 }
2641
2642 /// Whether this type is an error type.
2643 bool containsErrors() const {
2644 return getDependence() & TypeDependence::Error;
2645 }
2646
2647 /// Whether this type is a dependent type, meaning that its definition
2648 /// somehow depends on a template parameter (C++ [temp.dep.type]).
2649 bool isDependentType() const {
2650 return getDependence() & TypeDependence::Dependent;
2651 }
2652
2653 /// Determine whether this type is an instantiation-dependent type,
2654 /// meaning that the type involves a template parameter (even if the
2655 /// definition does not actually depend on the type substituted for that
2656 /// template parameter).
2658 return getDependence() & TypeDependence::Instantiation;
2659 }
2660
2661 /// Determine whether this type is an undeduced type, meaning that
2662 /// it somehow involves a C++11 'auto' type or similar which has not yet been
2663 /// deduced.
2664 bool isUndeducedType() const;
2665
2666 /// Whether this type is a variably-modified type (C99 6.7.5).
2668 return getDependence() & TypeDependence::VariablyModified;
2669 }
2670
2671 /// Whether this type involves a variable-length array type
2672 /// with a definite size.
2673 bool hasSizedVLAType() const;
2674
2675 /// Whether this type is or contains a local or unnamed type.
2676 bool hasUnnamedOrLocalType() const;
2677
2678 bool isOverloadableType() const;
2679
2680 /// Determine wither this type is a C++ elaborated-type-specifier.
2681 bool isElaboratedTypeSpecifier() const;
2682
2683 bool canDecayToPointerType() const;
2684
2685 /// Whether this type is represented natively as a pointer. This includes
2686 /// pointers, references, block pointers, and Objective-C interface,
2687 /// qualified id, and qualified interface types, as well as nullptr_t.
2688 bool hasPointerRepresentation() const;
2689
2690 /// Whether this type can represent an objective pointer type for the
2691 /// purpose of GC'ability
2692 bool hasObjCPointerRepresentation() const;
2693
2694 /// Determine whether this type has an integer representation
2695 /// of some sort, e.g., it is an integer type or a vector.
2696 bool hasIntegerRepresentation() const;
2697
2698 /// Determine whether this type has an signed integer representation
2699 /// of some sort, e.g., it is an signed integer type or a vector.
2700 bool hasSignedIntegerRepresentation() const;
2701
2702 /// Determine whether this type has an unsigned integer representation
2703 /// of some sort, e.g., it is an unsigned integer type or a vector.
2704 bool hasUnsignedIntegerRepresentation() const;
2705
2706 /// Determine whether this type has a floating-point representation
2707 /// of some sort, e.g., it is a floating-point type or a vector thereof.
2708 bool hasFloatingRepresentation() const;
2709
2710 // Type Checking Functions: Check to see if this type is structurally the
2711 // specified type, ignoring typedefs and qualifiers, and return a pointer to
2712 // the best type we can.
2713 const RecordType *getAsStructureType() const;
2714 /// NOTE: getAs*ArrayType are methods on ASTContext.
2715 const RecordType *getAsUnionType() const;
2716 const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
2717 const ObjCObjectType *getAsObjCInterfaceType() const;
2718
2719 // The following is a convenience method that returns an ObjCObjectPointerType
2720 // for object declared using an interface.
2721 const ObjCObjectPointerType *getAsObjCInterfacePointerType() const;
2722 const ObjCObjectPointerType *getAsObjCQualifiedIdType() const;
2723 const ObjCObjectPointerType *getAsObjCQualifiedClassType() const;
2724 const ObjCObjectType *getAsObjCQualifiedInterfaceType() const;
2725
2726 /// Retrieves the CXXRecordDecl that this type refers to, either
2727 /// because the type is a RecordType or because it is the injected-class-name
2728 /// type of a class template or class template partial specialization.
2729 CXXRecordDecl *getAsCXXRecordDecl() const;
2730
2731 /// Retrieves the RecordDecl this type refers to.
2732 RecordDecl *getAsRecordDecl() const;
2733
2734 /// Retrieves the TagDecl that this type refers to, either
2735 /// because the type is a TagType or because it is the injected-class-name
2736 /// type of a class template or class template partial specialization.
2737 TagDecl *getAsTagDecl() const;
2738
2739 /// If this is a pointer or reference to a RecordType, return the
2740 /// CXXRecordDecl that the type refers to.
2741 ///
2742 /// If this is not a pointer or reference, or the type being pointed to does
2743 /// not refer to a CXXRecordDecl, returns NULL.
2744 const CXXRecordDecl *getPointeeCXXRecordDecl() const;
2745
2746 /// Get the DeducedType whose type will be deduced for a variable with
2747 /// an initializer of this type. This looks through declarators like pointer
2748 /// types, but not through decltype or typedefs.
2749 DeducedType *getContainedDeducedType() const;
2750
2751 /// Get the AutoType whose type will be deduced for a variable with
2752 /// an initializer of this type. This looks through declarators like pointer
2753 /// types, but not through decltype or typedefs.
2755 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2756 }
2757
2758 /// Determine whether this type was written with a leading 'auto'
2759 /// corresponding to a trailing return type (possibly for a nested
2760 /// function type within a pointer to function type or similar).
2761 bool hasAutoForTrailingReturnType() const;
2762
2763 /// Member-template getAs<specific type>'. Look through sugar for
2764 /// an instance of <specific type>. This scheme will eventually
2765 /// replace the specific getAsXXXX methods above.
2766 ///
2767 /// There are some specializations of this member template listed
2768 /// immediately following this class.
2769 template <typename T> const T *getAs() const;
2770
2771 /// Member-template getAsAdjusted<specific type>. Look through specific kinds
2772 /// of sugar (parens, attributes, etc) for an instance of <specific type>.
2773 /// This is used when you need to walk over sugar nodes that represent some
2774 /// kind of type adjustment from a type that was written as a <specific type>
2775 /// to another type that is still canonically a <specific type>.
2776 template <typename T> const T *getAsAdjusted() const;
2777
2778 /// A variant of getAs<> for array types which silently discards
2779 /// qualifiers from the outermost type.
2780 const ArrayType *getAsArrayTypeUnsafe() const;
2781
2782 /// Member-template castAs<specific type>. Look through sugar for
2783 /// the underlying instance of <specific type>.
2784 ///
2785 /// This method has the same relationship to getAs<T> as cast<T> has
2786 /// to dyn_cast<T>; which is to say, the underlying type *must*
2787 /// have the intended type, and this method will never return null.
2788 template <typename T> const T *castAs() const;
2789
2790 /// A variant of castAs<> for array type which silently discards
2791 /// qualifiers from the outermost type.
2792 const ArrayType *castAsArrayTypeUnsafe() const;
2793
2794 /// Determine whether this type had the specified attribute applied to it
2795 /// (looking through top-level type sugar).
2796 bool hasAttr(attr::Kind AK) const;
2797
2798 /// Get the base element type of this type, potentially discarding type
2799 /// qualifiers. This should never be used when type qualifiers
2800 /// are meaningful.
2801 const Type *getBaseElementTypeUnsafe() const;
2802
2803 /// If this is an array type, return the element type of the array,
2804 /// potentially with type qualifiers missing.
2805 /// This should never be used when type qualifiers are meaningful.
2806 const Type *getArrayElementTypeNoTypeQual() const;
2807
2808 /// If this is a pointer type, return the pointee type.
2809 /// If this is an array type, return the array element type.
2810 /// This should never be used when type qualifiers are meaningful.
2811 const Type *getPointeeOrArrayElementType() const;
2812
2813 /// If this is a pointer, ObjC object pointer, or block
2814 /// pointer, this returns the respective pointee.
2815 QualType getPointeeType() const;
2816
2817 /// Return the specified type with any "sugar" removed from the type,
2818 /// removing any typedefs, typeofs, etc., as well as any qualifiers.
2819 const Type *getUnqualifiedDesugaredType() const;
2820
2821 /// Return true if this is an integer type that is
2822 /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
2823 /// or an enum decl which has a signed representation.
2824 bool isSignedIntegerType() const;
2825
2826 /// Return true if this is an integer type that is
2827 /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool],
2828 /// or an enum decl which has an unsigned representation.
2829 bool isUnsignedIntegerType() const;
2830
2831 /// Determines whether this is an integer type that is signed or an
2832 /// enumeration types whose underlying type is a signed integer type.
2833 bool isSignedIntegerOrEnumerationType() const;
2834
2835 /// Determines whether this is an integer type that is unsigned or an
2836 /// enumeration types whose underlying type is a unsigned integer type.
2837 bool isUnsignedIntegerOrEnumerationType() const;
2838
2839 /// Return true if this is a fixed point type according to
2840 /// ISO/IEC JTC1 SC22 WG14 N1169.
2841 bool isFixedPointType() const;
2842
2843 /// Return true if this is a fixed point or integer type.
2844 bool isFixedPointOrIntegerType() const;
2845
2846 /// Return true if this can be converted to (or from) a fixed point type.
2847 bool isConvertibleToFixedPointType() const;
2848
2849 /// Return true if this is a saturated fixed point type according to
2850 /// ISO/IEC JTC1 SC22 WG14 N1169. This type can be signed or unsigned.
2851 bool isSaturatedFixedPointType() 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 isUnsaturatedFixedPointType() const;
2856
2857 /// Return true if this is a fixed point type that is signed according
2858 /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2859 bool isSignedFixedPointType() const;
2860
2861 /// Return true if this is a fixed point type that is unsigned according
2862 /// to ISO/IEC JTC1 SC22 WG14 N1169. This type can also be saturated.
2863 bool isUnsignedFixedPointType() const;
2864
2865 /// Return true if this is not a variable sized type,
2866 /// according to the rules of C99 6.7.5p3. It is not legal to call this on
2867 /// incomplete types.
2868 bool isConstantSizeType() const;
2869
2870 /// Returns true if this type can be represented by some
2871 /// set of type specifiers.
2872 bool isSpecifierType() const;
2873
2874 /// Determine the linkage of this type.
2875 Linkage getLinkage() const;
2876
2877 /// Determine the visibility of this type.
2879 return getLinkageAndVisibility().getVisibility();
2880 }
2881
2882 /// Return true if the visibility was explicitly set is the code.
2884 return getLinkageAndVisibility().isVisibilityExplicit();
2885 }
2886
2887 /// Determine the linkage and visibility of this type.
2888 LinkageInfo getLinkageAndVisibility() const;
2889
2890 /// True if the computed linkage is valid. Used for consistency
2891 /// checking. Should always return true.
2892 bool isLinkageValid() const;
2893
2894 /// Determine the nullability of the given type.
2895 ///
2896 /// Note that nullability is only captured as sugar within the type
2897 /// system, not as part of the canonical type, so nullability will
2898 /// be lost by canonicalization and desugaring.
2899 std::optional<NullabilityKind> getNullability() const;
2900
2901 /// Determine whether the given type can have a nullability
2902 /// specifier applied to it, i.e., if it is any kind of pointer type.
2903 ///
2904 /// \param ResultIfUnknown The value to return if we don't yet know whether
2905 /// this type can have nullability because it is dependent.
2906 bool canHaveNullability(bool ResultIfUnknown = true) const;
2907
2908 /// Retrieve the set of substitutions required when accessing a member
2909 /// of the Objective-C receiver type that is declared in the given context.
2910 ///
2911 /// \c *this is the type of the object we're operating on, e.g., the
2912 /// receiver for a message send or the base of a property access, and is
2913 /// expected to be of some object or object pointer type.
2914 ///
2915 /// \param dc The declaration context for which we are building up a
2916 /// substitution mapping, which should be an Objective-C class, extension,
2917 /// category, or method within.
2918 ///
2919 /// \returns an array of type arguments that can be substituted for
2920 /// the type parameters of the given declaration context in any type described
2921 /// within that context, or an empty optional to indicate that no
2922 /// substitution is required.
2923 std::optional<ArrayRef<QualType>>
2924 getObjCSubstitutions(const DeclContext *dc) const;
2925
2926 /// Determines if this is an ObjC interface type that may accept type
2927 /// parameters.
2928 bool acceptsObjCTypeParams() const;
2929
2930 const char *getTypeClassName() const;
2931
2933 return CanonicalType;
2934 }
2935
2936 CanQualType getCanonicalTypeUnqualified() const; // in CanonicalType.h
2937 void dump() const;
2938 void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
2939};
2940
2941/// This will check for a TypedefType by removing any existing sugar
2942/// until it reaches a TypedefType or a non-sugared type.
2943template <> const TypedefType *Type::getAs() const;
2944template <> const UsingType *Type::getAs() const;
2945
2946/// This will check for a TemplateSpecializationType by removing any
2947/// existing sugar until it reaches a TemplateSpecializationType or a
2948/// non-sugared type.
2949template <> const TemplateSpecializationType *Type::getAs() const;
2950
2951/// This will check for an AttributedType by removing any existing sugar
2952/// until it reaches an AttributedType or a non-sugared type.
2953template <> const AttributedType *Type::getAs() const;
2954
2955/// This will check for a BoundsAttributedType by removing any existing
2956/// sugar until it reaches an BoundsAttributedType or a non-sugared type.
2957template <> const BoundsAttributedType *Type::getAs() const;
2958
2959/// This will check for a CountAttributedType by removing any existing
2960/// sugar until it reaches an CountAttributedType or a non-sugared type.
2961template <> const CountAttributedType *Type::getAs() const;
2962
2963// We can do canonical leaf types faster, because we don't have to
2964// worry about preserving child type decoration.
2965#define TYPE(Class, Base)
2966#define LEAF_TYPE(Class) \
2967template <> inline const Class##Type *Type::getAs() const { \
2968 return dyn_cast<Class##Type>(CanonicalType); \
2969} \
2970template <> inline const Class##Type *Type::castAs() const { \
2971 return cast<Class##Type>(CanonicalType); \
2972}
2973#include "clang/AST/TypeNodes.inc"
2974
2975/// This class is used for builtin types like 'int'. Builtin
2976/// types are always canonical and have a literal name field.
2977class BuiltinType : public Type {
2978public:
2979 enum Kind {
2980// OpenCL image types
2981#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2982#include "clang/Basic/OpenCLImageTypes.def"
2983// OpenCL extension types
2984#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
2985#include "clang/Basic/OpenCLExtensionTypes.def"
2986// SVE Types
2987#define SVE_TYPE(Name, Id, SingletonId) Id,
2988#include "clang/Basic/AArch64SVEACLETypes.def"
2989// PPC MMA Types
2990#define PPC_VECTOR_TYPE(Name, Id, Size) Id,
2991#include "clang/Basic/PPCTypes.def"
2992// RVV Types
2993#define RVV_TYPE(Name, Id, SingletonId) Id,
2994#include "clang/Basic/RISCVVTypes.def"
2995// WebAssembly reference types
2996#define WASM_TYPE(Name, Id, SingletonId) Id,
2997#include "clang/Basic/WebAssemblyReferenceTypes.def"
2998// All other builtin types
2999#define BUILTIN_TYPE(Id, SingletonId) Id,
3000#define LAST_BUILTIN_TYPE(Id) LastKind = Id
3001#include "clang/AST/BuiltinTypes.def"
3002 };
3003
3004private:
3005 friend class ASTContext; // ASTContext creates these.
3006
3007 BuiltinType(Kind K)
3008 : Type(Builtin, QualType(),
3009 K == Dependent ? TypeDependence::DependentInstantiation
3010 : TypeDependence::None) {
3011 static_assert(Kind::LastKind <
3012 (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
3013 "Defined builtin type exceeds the allocated space for serial "
3014 "numbering");
3015 BuiltinTypeBits.Kind = K;
3016 }
3017
3018public:
3019 Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
3020 StringRef getName(const PrintingPolicy &Policy) const;
3021
3022 const char *getNameAsCString(const PrintingPolicy &Policy) const {
3023 // The StringRef is null-terminated.
3024 StringRef str = getName(Policy);
3025 assert(!str.empty() && str.data()[str.size()] == '\0');
3026 return str.data();
3027 }
3028
3029 bool isSugared() const { return false; }
3030 QualType desugar() const { return QualType(this, 0); }
3031
3032 bool isInteger() const {
3033 return getKind() >= Bool && getKind() <= Int128;
3034 }
3035
3036 bool isSignedInteger() const {
3037 return getKind() >= Char_S && getKind() <= Int128;
3038 }
3039
3040 bool isUnsignedInteger() const {
3041 return getKind() >= Bool && getKind() <= UInt128;
3042 }
3043
3044 bool isFloatingPoint() const {
3045 return getKind() >= Half && getKind() <= Ibm128;
3046 }
3047
3048 bool isSVEBool() const { return getKind() == Kind::SveBool; }
3049
3050 bool isSVECount() const { return getKind() == Kind::SveCount; }
3051
3052 /// Determines whether the given kind corresponds to a placeholder type.
3054 return K >= Overload;
3055 }
3056
3057 /// Determines whether this type is a placeholder type, i.e. a type
3058 /// which cannot appear in arbitrary positions in a fully-formed
3059 /// expression.
3060 bool isPlaceholderType() const {
3061 return isPlaceholderTypeKind(getKind());
3062 }
3063
3064 /// Determines whether this type is a placeholder type other than
3065 /// Overload. Most placeholder types require only syntactic
3066 /// information about their context in order to be resolved (e.g.
3067 /// whether it is a call expression), which means they can (and
3068 /// should) be resolved in an earlier "phase" of analysis.
3069 /// Overload expressions sometimes pick up further information
3070 /// from their context, like whether the context expects a
3071 /// specific function-pointer type, and so frequently need
3072 /// special treatment.
3074 return getKind() > Overload;
3075 }
3076
3077 static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
3078};
3079
3080/// Complex values, per C99 6.2.5p11. This supports the C99 complex
3081/// types (_Complex float etc) as well as the GCC integer complex extensions.
3082class ComplexType : public Type, public llvm::FoldingSetNode {
3083 friend class ASTContext; // ASTContext creates these.
3084
3085 QualType ElementType;
3086
3087 ComplexType(QualType Element, QualType CanonicalPtr)
3088 : Type(Complex, CanonicalPtr, Element->getDependence()),
3089 ElementType(Element) {}
3090
3091public:
3092 QualType getElementType() const { return ElementType; }
3093
3094 bool isSugared() const { return false; }
3095 QualType desugar() const { return QualType(this, 0); }
3096
3097 void Profile(llvm::FoldingSetNodeID &ID) {
3098 Profile(ID, getElementType());
3099 }
3100
3101 static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) {
3102 ID.AddPointer(Element.getAsOpaquePtr());
3103 }
3104
3105 static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
3106};
3107
3108/// Sugar for parentheses used when specifying types.
3109class ParenType : public Type, public llvm::FoldingSetNode {
3110 friend class ASTContext; // ASTContext creates these.
3111
3112 QualType Inner;
3113
3114 ParenType(QualType InnerType, QualType CanonType)
3115 : Type(Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
3116
3117public:
3118 QualType getInnerType() const { return Inner; }
3119
3120 bool isSugared() const { return true; }
3121 QualType desugar() const { return getInnerType(); }
3122
3123 void Profile(llvm::FoldingSetNodeID &ID) {
3124 Profile(ID, getInnerType());
3125 }
3126
3127 static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) {
3128 Inner.Profile(ID);
3129 }
3130
3131 static bool classof(const Type *T) { return T->getTypeClass() == Paren; }
3132};
3133
3134/// PointerType - C99 6.7.5.1 - Pointer Declarators.
3135class PointerType : public Type, public llvm::FoldingSetNode {
3136 friend class ASTContext; // ASTContext creates these.
3137
3138 QualType PointeeType;
3139
3140 PointerType(QualType Pointee, QualType CanonicalPtr)
3141 : Type(Pointer, CanonicalPtr, Pointee->getDependence()),
3142 PointeeType(Pointee) {}
3143
3144public:
3145 QualType getPointeeType() const { return PointeeType; }
3146
3147 bool isSugared() const { return false; }
3148 QualType desugar() const { return QualType(this, 0); }
3149
3150 void Profile(llvm::FoldingSetNodeID &ID) {
3151 Profile(ID, getPointeeType());
3152 }
3153
3154 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
3155 ID.AddPointer(Pointee.getAsOpaquePtr());
3156 }
3157
3158 static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
3159};
3160
3161/// [BoundsSafety] Represents information of declarations referenced by the
3162/// arguments of the `counted_by` attribute and the likes.
3164public:
3165 using BaseTy = llvm::PointerIntPair<ValueDecl *, 1, unsigned>;
3166
3167private:
3168 enum {
3169 DerefShift = 0,
3170 DerefMask = 1,
3171 };
3172 BaseTy Data;
3173
3174public:
3175 /// \p D is to a declaration referenced by the argument of attribute. \p Deref
3176 /// indicates whether \p D is referenced as a dereferenced form, e.g., \p
3177 /// Deref is true for `*n` in `int *__counted_by(*n)`.
3178 TypeCoupledDeclRefInfo(ValueDecl *D = nullptr, bool Deref = false);
3179
3180 bool isDeref() const;
3181 ValueDecl *getDecl() const;
3182 unsigned getInt() const;
3183 void *getOpaqueValue() const;
3184 bool operator==(const TypeCoupledDeclRefInfo &Other) const;
3185 void setFromOpaqueValue(void *V);
3186};
3187
3188/// [BoundsSafety] Represents a parent type class for CountAttributedType and
3189/// similar sugar types that will be introduced to represent a type with a
3190/// bounds attribute.
3191///
3192/// Provides a common interface to navigate declarations referred to by the
3193/// bounds expression.
3194
3195class BoundsAttributedType : public Type, public llvm::FoldingSetNode {
3196 QualType WrappedTy;
3197
3198protected:
3199 ArrayRef<TypeCoupledDeclRefInfo> Decls; // stored in trailing objects
3200
3201 BoundsAttributedType(TypeClass TC, QualType Wrapped, QualType Canon);
3202
3203public:
3204 bool isSugared() const { return true; }
3205 QualType desugar() const { return WrappedTy; }
3206
3208 using decl_range = llvm::iterator_range<decl_iterator>;
3209
3210 decl_iterator dependent_decl_begin() const { return Decls.begin(); }
3211 decl_iterator dependent_decl_end() const { return Decls.end(); }
3212
3213 unsigned getNumCoupledDecls() const { return Decls.size(); }
3214
3216 return decl_range(dependent_decl_begin(), dependent_decl_end());
3217 }
3218
3220 return {dependent_decl_begin(), dependent_decl_end()};
3221 }
3222
3223 bool referencesFieldDecls() const;
3224
3225 static bool classof(const Type *T) {
3226 // Currently, only `class CountAttributedType` inherits
3227 // `BoundsAttributedType` but the subclass will grow as we add more bounds
3228 // annotations.
3229 switch (T->getTypeClass()) {
3230 case CountAttributed:
3231 return true;
3232 default:
3233 return false;
3234 }
3235 }
3236};
3237
3238/// Represents a sugar type with `__counted_by` or `__sized_by` annotations,
3239/// including their `_or_null` variants.
3241 : public BoundsAttributedType,
3242 public llvm::TrailingObjects<CountAttributedType,
3243 TypeCoupledDeclRefInfo> {
3244 friend class ASTContext;
3245
3246 Expr *CountExpr;
3247 /// \p CountExpr represents the argument of __counted_by or the likes. \p
3248 /// CountInBytes indicates that \p CountExpr is a byte count (i.e.,
3249 /// __sized_by(_or_null)) \p OrNull means it's an or_null variant (i.e.,
3250 /// __counted_by_or_null or __sized_by_or_null) \p CoupledDecls contains the
3251 /// list of declarations referenced by \p CountExpr, which the type depends on
3252 /// for the bounds information.
3253 CountAttributedType(QualType Wrapped, QualType Canon, Expr *CountExpr,
3254 bool CountInBytes, bool OrNull,
3256
3257 unsigned numTrailingObjects(OverloadToken<TypeCoupledDeclRefInfo>) const {
3258 return CountAttributedTypeBits.NumCoupledDecls;
3259 }
3260
3261public:
3263 CountedBy = 0,
3267 };
3268
3269 Expr *getCountExpr() const { return CountExpr; }
3270 bool isCountInBytes() const { return CountAttributedTypeBits.CountInBytes; }
3271 bool isOrNull() const { return CountAttributedTypeBits.OrNull; }
3272
3274 if (isOrNull())
3275 return isCountInBytes() ? SizedByOrNull : CountedByOrNull;
3276 return isCountInBytes() ? SizedBy : CountedBy;
3277 }
3278
3279 void Profile(llvm::FoldingSetNodeID &ID) {
3280 Profile(ID, desugar(), CountExpr, isCountInBytes(), isOrNull());
3281 }
3282
3283 static void Profile(llvm::FoldingSetNodeID &ID, QualType WrappedTy,
3284 Expr *CountExpr, bool CountInBytes, bool Nullable);
3285
3286 static bool classof(const Type *T) {
3287 return T->getTypeClass() == CountAttributed;
3288 }
3289};
3290
3291/// Represents a type which was implicitly adjusted by the semantic
3292/// engine for arbitrary reasons. For example, array and function types can
3293/// decay, and function types can have their calling conventions adjusted.
3294class AdjustedType : public Type, public llvm::FoldingSetNode {
3295 QualType OriginalTy;
3296 QualType AdjustedTy;
3297
3298protected:
3299 friend class ASTContext; // ASTContext creates these.
3300
3301 AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy,
3302 QualType CanonicalPtr)
3303 : Type(TC, CanonicalPtr, OriginalTy->getDependence()),
3304 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
3305
3306public:
3307 QualType getOriginalType() const { return OriginalTy; }
3308 QualType getAdjustedType() const { return AdjustedTy; }
3309
3310 bool isSugared() const { return true; }
3311 QualType desugar() const { return AdjustedTy; }
3312
3313 void Profile(llvm::FoldingSetNodeID &ID) {
3314 Profile(ID, OriginalTy, AdjustedTy);
3315 }
3316
3317 static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) {
3318 ID.AddPointer(Orig.getAsOpaquePtr());
3319 ID.AddPointer(New.getAsOpaquePtr());
3320 }
3321
3322 static bool classof(const Type *T) {
3323 return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed;
3324 }
3325};
3326
3327/// Represents a pointer type decayed from an array or function type.
3329 friend class ASTContext; // ASTContext creates these.
3330
3331 inline
3332 DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical);
3333
3334public:
3335 QualType getDecayedType() const { return getAdjustedType(); }
3336
3337 inline QualType getPointeeType() const;
3338
3339 static bool classof(const Type *T) { return T->getTypeClass() == Decayed; }
3340};
3341
3342/// Pointer to a block type.
3343/// This type is to represent types syntactically represented as
3344/// "void (^)(int)", etc. Pointee is required to always be a function type.
3345class BlockPointerType : public Type, public llvm::FoldingSetNode {
3346 friend class ASTContext; // ASTContext creates these.
3347
3348 // Block is some kind of pointer type
3349 QualType PointeeType;
3350
3351 BlockPointerType(QualType Pointee, QualType CanonicalCls)
3352 : Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
3353 PointeeType(Pointee) {}
3354
3355public:
3356 // Get the pointee type. Pointee is required to always be a function type.
3357 QualType getPointeeType() const { return PointeeType; }
3358
3359 bool isSugared() const { return false; }
3360 QualType desugar() const { return QualType(this, 0); }
3361
3362 void Profile(llvm::FoldingSetNodeID &ID) {
3363 Profile(ID, getPointeeType());
3364 }
3365
3366 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) {
3367 ID.AddPointer(Pointee.getAsOpaquePtr());
3368 }
3369
3370 static bool classof(const Type *T) {
3371 return T->getTypeClass() == BlockPointer;
3372 }
3373};
3374
3375/// Base for LValueReferenceType and RValueReferenceType
3376class ReferenceType : public Type, public llvm::FoldingSetNode {
3377 QualType PointeeType;
3378
3379protected:
3380 ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef,
3381 bool SpelledAsLValue)
3382 : Type(tc, CanonicalRef, Referencee->getDependence()),
3383 PointeeType(Referencee) {
3384 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3385 ReferenceTypeBits.InnerRef = Referencee->isReferenceType();
3386 }
3387
3388public:
3389 bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; }
3390 bool isInnerRef() const { return ReferenceTypeBits.InnerRef; }
3391
3392 QualType getPointeeTypeAsWritten() const { return PointeeType; }
3393
3395 // FIXME: this might strip inner qualifiers; okay?
3396 const ReferenceType *T = this;
3397 while (T->isInnerRef())
3398 T = T->PointeeType->castAs<ReferenceType>();
3399 return T->PointeeType;
3400 }
3401
3402 void Profile(llvm::FoldingSetNodeID &ID) {
3403 Profile(ID, PointeeType, isSpelledAsLValue());
3404 }
3405
3406 static void Profile(llvm::FoldingSetNodeID &ID,
3407 QualType Referencee,
3408 bool SpelledAsLValue) {
3409 ID.AddPointer(Referencee.getAsOpaquePtr());
3410 ID.AddBoolean(SpelledAsLValue);
3411 }
3412
3413 static bool classof(const Type *T) {
3414 return T->getTypeClass() == LValueReference ||
3415 T->getTypeClass() == RValueReference;
3416 }
3417};
3418
3419/// An lvalue reference type, per C++11 [dcl.ref].
3421 friend class ASTContext; // ASTContext creates these
3422
3423 LValueReferenceType(QualType Referencee, QualType CanonicalRef,
3424 bool SpelledAsLValue)
3425 : ReferenceType(LValueReference, Referencee, CanonicalRef,
3426 SpelledAsLValue) {}
3427
3428public:
3429 bool isSugared() const { return false; }
3430 QualType desugar() const { return QualType(this, 0); }
3431
3432 static bool classof(const Type *T) {
3433 return T->getTypeClass() == LValueReference;
3434 }
3435};
3436
3437/// An rvalue reference type, per C++11 [dcl.ref].
3439 friend class ASTContext; // ASTContext creates these
3440
3441 RValueReferenceType(QualType Referencee, QualType CanonicalRef)
3442 : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {}
3443
3444public:
3445 bool isSugared() const { return false; }
3446 QualType desugar() const { return QualType(this, 0); }
3447
3448 static bool classof(const Type *T) {
3449 return T->getTypeClass() == RValueReference;
3450 }
3451};
3452
3453/// A pointer to member type per C++ 8.3.3 - Pointers to members.
3454///
3455/// This includes both pointers to data members and pointer to member functions.
3456class MemberPointerType : public Type, public llvm::FoldingSetNode {
3457 friend class ASTContext; // ASTContext creates these.
3458
3459 QualType PointeeType;
3460
3461 /// The class of which the pointee is a member. Must ultimately be a
3462 /// RecordType, but could be a typedef or a template parameter too.
3463 const Type *Class;
3464
3465 MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr)
3466 : Type(MemberPointer, CanonicalPtr,
3467 (Cls->getDependence() & ~TypeDependence::VariablyModified) |
3468 Pointee->getDependence()),
3469 PointeeType(Pointee), Class(Cls) {}
3470
3471public:
3472 QualType getPointeeType() const { return PointeeType; }
3473
3474 /// Returns true if the member type (i.e. the pointee type) is a
3475 /// function type rather than a data-member type.
3477 return PointeeType->isFunctionProtoType();
3478 }
3479
3480 /// Returns true if the member type (i.e. the pointee type) is a
3481 /// data type rather than a function type.
3482 bool isMemberDataPointer() const {
3483 return !PointeeType->isFunctionProtoType();
3484 }
3485
3486 const Type *getClass() const { return Class; }
3487 CXXRecordDecl *getMostRecentCXXRecordDecl() const;
3488
3489 bool isSugared() const { return false; }
3490 QualType desugar() const { return QualType(this, 0); }
3491
3492 void Profile(llvm::FoldingSetNodeID &ID) {
3493 Profile(ID, getPointeeType(), getClass());
3494 }
3495
3496 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee,
3497 const Type *Class) {
3498 ID.AddPointer(Pointee.getAsOpaquePtr());
3499 ID.AddPointer(Class);
3500 }
3501
3502 static bool classof(const Type *T) {
3503 return T->getTypeClass() == MemberPointer;
3504 }
3505};
3506
3507/// Capture whether this is a normal array (e.g. int X[4])
3508/// an array with a static size (e.g. int X[static 4]), or an array
3509/// with a star size (e.g. int X[*]).
3510/// 'static' is only allowed on function parameters.
3511enum class ArraySizeModifier { Normal, Static, Star };
3512
3513/// Represents an array type, per C99 6.7.5.2 - Array Declarators.
3514class ArrayType : public Type, public llvm::FoldingSetNode {
3515private:
3516 /// The element type of the array.
3517 QualType ElementType;
3518
3519protected:
3520 friend class ASTContext; // ASTContext creates these.
3521
3523 unsigned tq, const Expr *sz = nullptr);
3524
3525public:
3526 QualType getElementType() const { return ElementType; }
3527
3529 return ArraySizeModifier(ArrayTypeBits.SizeModifier);
3530 }
3531
3533 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3534 }
3535
3536 unsigned getIndexTypeCVRQualifiers() const {
3537 return ArrayTypeBits.IndexTypeQuals;
3538 }
3539
3540 static bool classof(const Type *T) {
3541 return T->getTypeClass() == ConstantArray ||
3542 T->getTypeClass() == VariableArray ||
3543 T->getTypeClass() == IncompleteArray ||
3544 T->getTypeClass() == DependentSizedArray ||
3545 T->getTypeClass() == ArrayParameter;
3546 }
3547};
3548
3549/// Represents the canonical version of C arrays with a specified constant size.
3550/// For example, the canonical type for 'int A[4 + 4*100]' is a
3551/// ConstantArrayType where the element type is 'int' and the size is 404.
3553 friend class ASTContext; // ASTContext creates these.
3554
3555 struct ExternalSize {
3556 ExternalSize(const llvm::APInt &Sz, const Expr *SE)
3557 : Size(Sz), SizeExpr(SE) {}
3558 llvm::APInt Size; // Allows us to unique the type.
3559 const Expr *SizeExpr;
3560 };
3561
3562 union {
3563 uint64_t Size;
3564 ExternalSize *SizePtr;
3565 };
3566
3567 ConstantArrayType(QualType Et, QualType Can, uint64_t Width, uint64_t Sz,
3568 ArraySizeModifier SM, unsigned TQ)
3569 : ArrayType(ConstantArray, Et, Can, SM, TQ, nullptr), Size(Sz) {
3570 ConstantArrayTypeBits.HasExternalSize = false;
3571 ConstantArrayTypeBits.SizeWidth = Width / 8;
3572 // The in-structure size stores the size in bytes rather than bits so we
3573 // drop the three least significant bits since they're always zero anyways.
3574 assert(Width < 0xFF && "Type width in bits must be less than 8 bits");
3575 }
3576
3577 ConstantArrayType(QualType Et, QualType Can, ExternalSize *SzPtr,
3578 ArraySizeModifier SM, unsigned TQ)
3579 : ArrayType(ConstantArray, Et, Can, SM, TQ, SzPtr->SizeExpr),
3580 SizePtr(SzPtr) {
3581 ConstantArrayTypeBits.HasExternalSize = true;
3582 ConstantArrayTypeBits.SizeWidth = 0;
3583
3584 assert((SzPtr->SizeExpr == nullptr || !Can.isNull()) &&
3585 "canonical constant array should not have size expression");
3586 }
3587
3588 static ConstantArrayType *Create(const ASTContext &Ctx, QualType ET,
3589 QualType Can, const llvm::APInt &Sz,
3590 const Expr *SzExpr, ArraySizeModifier SzMod,
3591 unsigned Qual);
3592
3593protected:
3595 : ArrayType(Tc, ATy->getElementType(), Can, ATy->getSizeModifier(),
3596 ATy->getIndexTypeQualifiers().getAsOpaqueValue(), nullptr) {
3597 ConstantArrayTypeBits.HasExternalSize =
3598 ATy->ConstantArrayTypeBits.HasExternalSize;
3599 if (!ConstantArrayTypeBits.HasExternalSize) {
3600 ConstantArrayTypeBits.SizeWidth = ATy->ConstantArrayTypeBits.SizeWidth;
3601 Size = ATy->Size;
3602 } else
3603 SizePtr = ATy->SizePtr;
3604 }
3605
3606public:
3607 /// Return the constant array size as an APInt.
3608 llvm::APInt getSize() const {
3609 return ConstantArrayTypeBits.HasExternalSize
3610 ? SizePtr->Size
3611 : llvm::APInt(ConstantArrayTypeBits.SizeWidth * 8, Size);
3612 }
3613
3614 /// Return the bit width of the size type.
3615 unsigned getSizeBitWidth() const {
3616 return ConstantArrayTypeBits.HasExternalSize
3617 ? SizePtr->Size.getBitWidth()
3618 : static_cast<unsigned>(ConstantArrayTypeBits.SizeWidth * 8);
3619 }
3620
3621 /// Return true if the size is zero.
3622 bool isZeroSize() const {
3623 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
3624 : 0 == Size;
3625 }
3626
3627 /// Return the size zero-extended as a uint64_t.
3628 uint64_t getZExtSize() const {
3629 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
3630 : Size;
3631 }
3632
3633 /// Return the size sign-extended as a uint64_t.
3634 int64_t getSExtSize() const {
3635 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
3636 : static_cast<int64_t>(Size);
3637 }
3638
3639 /// Return the size zero-extended to uint64_t or UINT64_MAX if the value is
3640 /// larger than UINT64_MAX.
3641 uint64_t getLimitedSize() const {
3642 return ConstantArrayTypeBits.HasExternalSize
3643 ? SizePtr->Size.getLimitedValue()
3644 : Size;
3645 }
3646
3647 /// Return a pointer to the size expression.
3648 const Expr *getSizeExpr() const {
3649 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr : nullptr;
3650 }
3651
3652 bool isSugared() const { return false; }
3653 QualType desugar() const { return QualType(this, 0); }
3654
3655 /// Determine the number of bits required to address a member of
3656 // an array with the given element type and number of elements.
3657 static unsigned getNumAddressingBits(const ASTContext &Context,
3658 QualType ElementType,
3659 const llvm::APInt &NumElements);
3660
3661 unsigned getNumAddressingBits(const ASTContext &Context) const;
3662
3663 /// Determine the maximum number of active bits that an array's size
3664 /// can require, which limits the maximum size of the array.
3665 static unsigned getMaxSizeBits(const ASTContext &Context);
3666
3667 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
3668 Profile(ID, Ctx, getElementType(), getZExtSize(), getSizeExpr(),
3669 getSizeModifier(), getIndexTypeCVRQualifiers());
3670 }
3671
3672 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
3673 QualType ET, uint64_t ArraySize, const Expr *SizeExpr,
3674 ArraySizeModifier SizeMod, unsigned TypeQuals);
3675
3676 static bool classof(const Type *T) {
3677 return T->getTypeClass() == ConstantArray ||
3678 T->getTypeClass() == ArrayParameter;
3679 }
3680};
3681
3682/// Represents a constant array type that does not decay to a pointer when used
3683/// as a function parameter.
3685 friend class ASTContext; // ASTContext creates these.
3686
3688 : ConstantArrayType(ArrayParameter, ATy, CanTy) {}
3689
3690public:
3691 static bool classof(const Type *T) {
3692 return T->getTypeClass() == ArrayParameter;
3693 }
3694};
3695
3696/// Represents a C array with an unspecified size. For example 'int A[]' has
3697/// an IncompleteArrayType where the element type is 'int' and the size is
3698/// unspecified.
3700 friend class ASTContext; // ASTContext creates these.
3701
3703 ArraySizeModifier sm, unsigned tq)
3704 : ArrayType(IncompleteArray, et, can, sm, tq) {}
3705
3706public:
3707 friend class StmtIteratorBase;
3708
3709 bool isSugared() const { return false; }
3710 QualType desugar() const { return QualType(this, 0); }
3711
3712 static bool classof(const Type *T) {
3713 return T->getTypeClass() == IncompleteArray;
3714 }
3715
3716 void Profile(llvm::FoldingSetNodeID &ID) {
3717 Profile(ID, getElementType(), getSizeModifier(),
3718 getIndexTypeCVRQualifiers());
3719 }
3720
3721 static void Profile(llvm::FoldingSetNodeID &ID, QualType ET,
3722 ArraySizeModifier SizeMod, unsigned TypeQuals) {
3723 ID.AddPointer(ET.getAsOpaquePtr());
3724 ID.AddInteger(llvm::to_underlying(SizeMod));
3725 ID.AddInteger(TypeQuals);
3726 }
3727};
3728
3729/// Represents a C array with a specified size that is not an
3730/// integer-constant-expression. For example, 'int s[x+foo()]'.
3731/// Since the size expression is an arbitrary expression, we store it as such.
3732///
3733/// Note: VariableArrayType's aren't uniqued (since the expressions aren't) and
3734/// should not be: two lexically equivalent variable array types could mean
3735/// different things, for example, these variables do not have the same type
3736/// dynamically:
3737///
3738/// void foo(int x) {
3739/// int Y[x];
3740/// ++x;
3741/// int Z[x];
3742/// }
3744 friend class ASTContext; // ASTContext creates these.
3745
3746 /// An assignment-expression. VLA's are only permitted within
3747 /// a function block.
3748 Stmt *SizeExpr;
3749
3750 /// The range spanned by the left and right array brackets.
3751 SourceRange Brackets;
3752
3754 ArraySizeModifier sm, unsigned tq,
3755 SourceRange brackets)
3756 : ArrayType(VariableArray, et, can, sm, tq, e),
3757 SizeExpr((Stmt*) e), Brackets(brackets) {}
3758
3759public:
3760 friend class StmtIteratorBase;
3761
3763 // We use C-style casts instead of cast<> here because we do not wish
3764 // to have a dependency of Type.h on Stmt.h/Expr.h.
3765 return (Expr*) SizeExpr;
3766 }
3767
3768 SourceRange getBracketsRange() const { return Brackets; }
3769 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3770 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3771
3772 bool isSugared() const { return false; }
3773 QualType desugar() const { return QualType(this, 0); }
3774
3775 static bool classof(const Type *T) {
3776 return T->getTypeClass() == VariableArray;
3777 }
3778
3779 void Profile(llvm::FoldingSetNodeID &ID) {
3780 llvm_unreachable("Cannot unique VariableArrayTypes.");
3781 }
3782};
3783
3784/// Represents an array type in C++ whose size is a value-dependent expression.
3785///
3786/// For example:
3787/// \code
3788/// template<typename T, int Size>
3789/// class array {
3790/// T data[Size];
3791/// };
3792/// \endcode
3793///
3794/// For these types, we won't actually know what the array bound is
3795/// until template instantiation occurs, at which point this will
3796/// become either a ConstantArrayType or a VariableArrayType.
3798 friend class ASTContext; // ASTContext creates these.
3799
3800 /// An assignment expression that will instantiate to the
3801 /// size of the array.
3802 ///
3803 /// The expression itself might be null, in which case the array
3804 /// type will have its size deduced from an initializer.
3805 Stmt *SizeExpr;
3806
3807 /// The range spanned by the left and right array brackets.
3808 SourceRange Brackets;
3809
3811 ArraySizeModifier sm, unsigned tq,
3812 SourceRange brackets);
3813
3814public:
3815 friend class StmtIteratorBase;
3816
3818 // We use C-style casts instead of cast<> here because we do not wish
3819 // to have a dependency of Type.h on Stmt.h/Expr.h.
3820 return (Expr*) SizeExpr;
3821 }
3822
3823 SourceRange getBracketsRange() const { return Brackets; }
3824 SourceLocation getLBracketLoc() const { return Brackets.getBegin(); }
3825 SourceLocation getRBracketLoc() const { return Brackets.getEnd(); }
3826
3827 bool isSugared() const { return false; }
3828 QualType desugar() const { return QualType(this, 0); }
3829
3830 static bool classof(const Type *T) {
3831 return T->getTypeClass() == DependentSizedArray;
3832 }
3833
3834 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3835 Profile(ID, Context, getElementType(),
3836 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3837 }
3838
3839 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3840 QualType ET, ArraySizeModifier SizeMod,
3841 unsigned TypeQuals, Expr *E);
3842};
3843
3844/// Represents an extended address space qualifier where the input address space
3845/// value is dependent. Non-dependent address spaces are not represented with a
3846/// special Type subclass; they are stored on an ExtQuals node as part of a QualType.
3847///
3848/// For example:
3849/// \code
3850/// template<typename T, int AddrSpace>
3851/// class AddressSpace {
3852/// typedef T __attribute__((address_space(AddrSpace))) type;
3853/// }
3854/// \endcode
3855class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode {
3856 friend class ASTContext;
3857
3858 Expr *AddrSpaceExpr;
3859 QualType PointeeType;
3860 SourceLocation loc;
3861
3863 Expr *AddrSpaceExpr, SourceLocation loc);
3864
3865public:
3866 Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; }
3867 QualType getPointeeType() const { return PointeeType; }
3868 SourceLocation getAttributeLoc() const { return loc; }
3869
3870 bool isSugared() const { return false; }
3871 QualType desugar() const { return QualType(this, 0); }
3872
3873 static bool classof(const Type *T) {
3874 return T->getTypeClass() == DependentAddressSpace;
3875 }
3876
3877 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3878 Profile(ID, Context, getPointeeType(), getAddrSpaceExpr());
3879 }
3880
3881 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3882 QualType PointeeType, Expr *AddrSpaceExpr);
3883};
3884
3885/// Represents an extended vector type where either the type or size is
3886/// dependent.
3887///
3888/// For example:
3889/// \code
3890/// template<typename T, int Size>
3891/// class vector {
3892/// typedef T __attribute__((ext_vector_type(Size))) type;
3893/// }
3894/// \endcode
3895class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
3896 friend class ASTContext;
3897
3898 Expr *SizeExpr;
3899
3900 /// The element type of the array.
3901 QualType ElementType;
3902
3903 SourceLocation loc;
3904
3906 Expr *SizeExpr, SourceLocation loc);
3907
3908public:
3909 Expr *getSizeExpr() const { return SizeExpr; }
3910 QualType getElementType() const { return ElementType; }
3911 SourceLocation getAttributeLoc() const { return loc; }
3912
3913 bool isSugared() const { return false; }
3914 QualType desugar() const { return QualType(this, 0); }
3915
3916 static bool classof(const Type *T) {
3917 return T->getTypeClass() == DependentSizedExtVector;
3918 }
3919
3920 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
3921 Profile(ID, Context, getElementType(), getSizeExpr());
3922 }
3923
3924 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
3925 QualType ElementType, Expr *SizeExpr);
3926};
3927
3928enum class VectorKind {
3929 /// not a target-specific vector type
3930 Generic,
3931
3932 /// is AltiVec vector
3934
3935 /// is AltiVec 'vector Pixel'
3937
3938 /// is AltiVec 'vector bool ...'
3940
3941 /// is ARM Neon vector
3942 Neon,
3943
3944 /// is ARM Neon polynomial vector
3945 NeonPoly,
3946
3947 /// is AArch64 SVE fixed-length data vector
3949
3950 /// is AArch64 SVE fixed-length predicate vector
3952
3953 /// is RISC-V RVV fixed-length data vector
3955
3956 /// is RISC-V RVV fixed-length mask vector
3958};
3959
3960/// Represents a GCC generic vector type. This type is created using
3961/// __attribute__((vector_size(n)), where "n" specifies the vector size in
3962/// bytes; or from an Altivec __vector or vector declaration.
3963/// Since the constructor takes the number of vector elements, the
3964/// client is responsible for converting the size into the number of elements.
3965class VectorType : public Type, public llvm::FoldingSetNode {
3966protected:
3967 friend class ASTContext; // ASTContext creates these.
3968
3969 /// The element type of the vector.
3971
3972 VectorType(QualType vecType, unsigned nElements, QualType canonType,
3973 VectorKind vecKind);
3974
3975 VectorType(TypeClass tc, QualType vecType, unsigned nElements,
3976 QualType canonType, VectorKind vecKind);
3977
3978public:
3979 QualType getElementType() const { return ElementType; }
3980 unsigned getNumElements() const { return VectorTypeBits.NumElements; }
3981
3982 bool isSugared() const { return false; }
3983 QualType desugar() const { return QualType(this, 0); }
3984
3986 return VectorKind(VectorTypeBits.VecKind);
3987 }
3988
3989 void Profile(llvm::FoldingSetNodeID &ID) {
3990 Profile(ID, getElementType(), getNumElements(),
3991 getTypeClass(), getVectorKind());
3992 }
3993
3994 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
3995 unsigned NumElements, TypeClass TypeClass,
3996 VectorKind VecKind) {
3997 ID.AddPointer(ElementType.getAsOpaquePtr());
3998 ID.AddInteger(NumElements);
3999 ID.AddInteger(TypeClass);
4000 ID.AddInteger(llvm::to_underlying(VecKind));
4001 }
4002
4003 static bool classof(const Type *T) {
4004 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
4005 }
4006};
4007
4008/// Represents a vector type where either the type or size is dependent.
4009////
4010/// For example:
4011/// \code
4012/// template<typename T, int Size>
4013/// class vector {
4014/// typedef T __attribute__((vector_size(Size))) type;
4015/// }
4016/// \endcode
4017class DependentVectorType : public Type, public llvm::FoldingSetNode {
4018 friend class ASTContext;
4019
4020 QualType ElementType;
4021 Expr *SizeExpr;
4022 SourceLocation Loc;
4023
4024 DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
4025 SourceLocation Loc, VectorKind vecKind);
4026
4027public:
4028 Expr *getSizeExpr() const { return SizeExpr; }
4029 QualType getElementType() const { return ElementType; }
4030 SourceLocation getAttributeLoc() const { return Loc; }
4032 return VectorKind(VectorTypeBits.VecKind);
4033 }
4034
4035 bool isSugared() const { return false; }
4036 QualType desugar() const { return QualType(this, 0); }
4037
4038 static bool classof(const Type *T) {
4039 return T->getTypeClass() == DependentVector;
4040 }
4041
4042 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4043 Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
4044 }
4045
4046 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4047 QualType ElementType, const Expr *SizeExpr,
4048 VectorKind VecKind);
4049};
4050
4051/// ExtVectorType - Extended vector type. This type is created using
4052/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
4053/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
4054/// class enables syntactic extensions, like Vector Components for accessing
4055/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
4056/// Shading Language).
4058 friend class ASTContext; // ASTContext creates these.
4059
4060 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
4061 : VectorType(ExtVector, vecType, nElements, canonType,
4062 VectorKind::Generic) {}
4063
4064public:
4065 static int getPointAccessorIdx(char c) {
4066 switch (c) {
4067 default: return -1;
4068 case 'x': case 'r': return 0;
4069 case 'y': case 'g': return 1;
4070 case 'z': case 'b': return 2;
4071 case 'w': case 'a': return 3;
4072 }
4073 }
4074
4075 static int getNumericAccessorIdx(char c) {
4076 switch (c) {
4077 default: return -1;
4078 case '0': return 0;
4079 case '1': return 1;
4080 case '2': return 2;
4081 case '3': return 3;
4082 case '4': return 4;
4083 case '5': return 5;
4084 case '6': return 6;
4085 case '7': return 7;
4086 case '8': return 8;
4087 case '9': return 9;
4088 case 'A':
4089 case 'a': return 10;
4090 case 'B':
4091 case 'b': return 11;
4092 case 'C':
4093 case 'c': return 12;
4094 case 'D':
4095 case 'd': return 13;
4096 case 'E':
4097 case 'e': return 14;
4098 case 'F':
4099 case 'f': return 15;
4100 }
4101 }
4102
4103 static int getAccessorIdx(char c, bool isNumericAccessor) {
4104 if (isNumericAccessor)
4105 return getNumericAccessorIdx(c);
4106 else
4107 return getPointAccessorIdx(c);
4108 }
4109
4110 bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
4111 if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
4112 return unsigned(idx-1) < getNumElements();
4113 return false;
4114 }
4115
4116 bool isSugared() const { return false; }
4117 QualType desugar() const { return QualType(this, 0); }
4118
4119 static bool classof(const Type *T) {
4120 return T->getTypeClass() == ExtVector;
4121 }
4122};
4123
4124/// Represents a matrix type, as defined in the Matrix Types clang extensions.
4125/// __attribute__((matrix_type(rows, columns))), where "rows" specifies
4126/// number of rows and "columns" specifies the number of columns.
4127class MatrixType : public Type, public llvm::FoldingSetNode {
4128protected:
4129 friend class ASTContext;
4130
4131 /// The element type of the matrix.
4133
4134 MatrixType(QualType ElementTy, QualType CanonElementTy);
4135
4136 MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy,
4137 const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr);
4138
4139public:
4140 /// Returns type of the elements being stored in the matrix
4141 QualType getElementType() const { return ElementType; }
4142
4143 /// Valid elements types are the following:
4144 /// * an integer type (as in C23 6.2.5p22), but excluding enumerated types
4145 /// and _Bool
4146 /// * the standard floating types float or double
4147 /// * a half-precision floating point type, if one is supported on the target
4149 return T->isDependentType() ||
4150 (T->isRealType() && !T->isBooleanType() && !T->isEnumeralType());
4151 }
4152
4153 bool isSugared() const { return false; }
4154 QualType desugar() const { return QualType(this, 0); }
4155
4156 static bool classof(const Type *T) {
4157 return T->getTypeClass() == ConstantMatrix ||
4158 T->getTypeClass() == DependentSizedMatrix;
4159 }
4160};
4161
4162/// Represents a concrete matrix type with constant number of rows and columns
4163class ConstantMatrixType final : public MatrixType {
4164protected:
4165 friend class ASTContext;
4166
4167 /// Number of rows and columns.
4168 unsigned NumRows;
4169 unsigned NumColumns;
4170
4171 static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
4172
4173 ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
4174 unsigned NColumns, QualType CanonElementType);
4175
4176 ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows,
4177 unsigned NColumns, QualType CanonElementType);
4178
4179public:
4180 /// Returns the number of rows in the matrix.
4181 unsigned getNumRows() const { return NumRows; }
4182
4183 /// Returns the number of columns in the matrix.
4184 unsigned getNumColumns() const { return NumColumns; }
4185
4186 /// Returns the number of elements required to embed the matrix into a vector.
4187 unsigned getNumElementsFlattened() const {
4188 return getNumRows() * getNumColumns();
4189 }
4190
4191 /// Returns true if \p NumElements is a valid matrix dimension.
4192 static constexpr bool isDimensionValid(size_t NumElements) {
4193 return NumElements > 0 && NumElements <= MaxElementsPerDimension;
4194 }
4195
4196 /// Returns the maximum number of elements per dimension.
4197 static constexpr unsigned getMaxElementsPerDimension() {
4198 return MaxElementsPerDimension;
4199 }
4200
4201 void Profile(llvm::FoldingSetNodeID &ID) {
4202 Profile(ID, getElementType(), getNumRows(), getNumColumns(),
4203 getTypeClass());
4204 }
4205
4206 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
4207 unsigned NumRows, unsigned NumColumns,
4209 ID.AddPointer(ElementType.getAsOpaquePtr());
4210 ID.AddInteger(NumRows);
4211 ID.AddInteger(NumColumns);
4212 ID.AddInteger(TypeClass);
4213 }
4214
4215 static bool classof(const Type *T) {
4216 return T->getTypeClass() == ConstantMatrix;
4217 }
4218};
4219
4220/// Represents a matrix type where the type and the number of rows and columns
4221/// is dependent on a template.
4223 friend class ASTContext;
4224
4225 Expr *RowExpr;
4226 Expr *ColumnExpr;
4227
4228 SourceLocation loc;
4229
4230 DependentSizedMatrixType(QualType ElementType, QualType CanonicalType,
4231 Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc);
4232
4233public:
4234 Expr *getRowExpr() const { return RowExpr; }
4235 Expr *getColumnExpr() const { return ColumnExpr; }
4236 SourceLocation getAttributeLoc() const { return loc; }
4237
4238 static bool classof(const Type *T) {
4239 return T->getTypeClass() == DependentSizedMatrix;
4240 }
4241
4242 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4243 Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
4244 }
4245
4246 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4247 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr);
4248};
4249
4250/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
4251/// class of FunctionNoProtoType and FunctionProtoType.
4252class FunctionType : public Type {
4253 // The type returned by the function.
4254 QualType ResultType;
4255
4256public:
4257 /// Interesting information about a specific parameter that can't simply
4258 /// be reflected in parameter's type. This is only used by FunctionProtoType
4259 /// but is in FunctionType to make this class available during the
4260 /// specification of the bases of FunctionProtoType.
4261 ///
4262 /// It makes sense to model language features this way when there's some
4263 /// sort of parameter-specific override (such as an attribute) that
4264 /// affects how the function is called. For example, the ARC ns_consumed
4265 /// attribute changes whether a parameter is passed at +0 (the default)
4266 /// or +1 (ns_consumed). This must be reflected in the function type,
4267 /// but isn't really a change to the parameter type.
4268 ///
4269 /// One serious disadvantage of modelling language features this way is
4270 /// that they generally do not work with language features that attempt
4271 /// to destructure types. For example, template argument deduction will
4272 /// not be able to match a parameter declared as
4273 /// T (*)(U)
4274 /// against an argument of type
4275 /// void (*)(__attribute__((ns_consumed)) id)
4276 /// because the substitution of T=void, U=id into the former will
4277 /// not produce the latter.
4279 enum {
4280 ABIMask = 0x0F,
4281 IsConsumed = 0x10,
4282 HasPassObjSize = 0x20,
4283 IsNoEscape = 0x40,
4284 };
4285 unsigned char Data = 0;
4286
4287 public:
4288 ExtParameterInfo() = default;
4289
4290 /// Return the ABI treatment of this parameter.
4291 ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
4293 ExtParameterInfo copy = *this;
4294 copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
4295 return copy;
4296 }
4297
4298 /// Is this parameter considered "consumed" by Objective-C ARC?
4299 /// Consumed parameters must have retainable object type.
4300 bool isConsumed() const { return (Data & IsConsumed); }
4301 ExtParameterInfo withIsConsumed(bool consumed) const {
4302 ExtParameterInfo copy = *this;
4303 if (consumed)
4304 copy.Data |= IsConsumed;
4305 else
4306 copy.Data &= ~IsConsumed;
4307 return copy;
4308 }
4309
4310 bool hasPassObjectSize() const { return Data & HasPassObjSize; }
4312 ExtParameterInfo Copy = *this;
4313 Copy.Data |= HasPassObjSize;
4314 return Copy;
4315 }
4316
4317 bool isNoEscape() const { return Data & IsNoEscape; }
4318 ExtParameterInfo withIsNoEscape(bool NoEscape) const {
4319 ExtParameterInfo Copy = *this;
4320 if (NoEscape)
4321 Copy.Data |= IsNoEscape;
4322 else
4323 Copy.Data &= ~IsNoEscape;
4324 return Copy;
4325 }
4326
4327 unsigned char getOpaqueValue() const { return Data; }
4328 static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
4329 ExtParameterInfo result;
4330 result.Data = data;
4331 return result;
4332 }
4333
4335 return lhs.Data == rhs.Data;
4336 }
4337
4339 return lhs.Data != rhs.Data;
4340 }
4341 };
4342
4343 /// A class which abstracts out some details necessary for
4344 /// making a call.
4345 ///
4346 /// It is not actually used directly for storing this information in
4347 /// a FunctionType, although FunctionType does currently use the
4348 /// same bit-pattern.
4349 ///
4350 // If you add a field (say Foo), other than the obvious places (both,
4351 // constructors, compile failures), what you need to update is
4352 // * Operator==
4353 // * getFoo
4354 // * withFoo
4355 // * functionType. Add Foo, getFoo.
4356 // * ASTContext::getFooType
4357 // * ASTContext::mergeFunctionTypes
4358 // * FunctionNoProtoType::Profile
4359 // * FunctionProtoType::Profile
4360 // * TypePrinter::PrintFunctionProto
4361 // * AST read and write
4362 // * Codegen
4363 class ExtInfo {
4364 friend class FunctionType;
4365
4366 // Feel free to rearrange or add bits, but if you go over 16, you'll need to
4367 // adjust the Bits field below, and if you add bits, you'll need to adjust
4368 // Type::FunctionTypeBitfields::ExtInfo as well.
4369
4370 // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
4371 // |0 .. 4| 5 | 6 | 7 |8 .. 10| 11 | 12 |
4372 //
4373 // regparm is either 0 (no regparm attribute) or the regparm value+1.
4374 enum { CallConvMask = 0x1F };
4375 enum { NoReturnMask = 0x20 };
4376 enum { ProducesResultMask = 0x40 };
4377 enum { NoCallerSavedRegsMask = 0x80 };
4378 enum {
4379 RegParmMask = 0x700,
4380 RegParmOffset = 8
4381 };
4382 enum { NoCfCheckMask = 0x800 };
4383 enum { CmseNSCallMask = 0x1000 };
4384 uint16_t Bits = CC_C;
4385
4386 ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
4387
4388 public:
4389 // Constructor with no defaults. Use this when you know that you
4390 // have all the elements (when reading an AST file for example).
4391 ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
4392 bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
4393 bool cmseNSCall) {
4394 assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
4395 Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
4396 (producesResult ? ProducesResultMask : 0) |
4397 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
4398 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
4399 (NoCfCheck ? NoCfCheckMask : 0) |
4400 (cmseNSCall ? CmseNSCallMask : 0);
4401 }
4402
4403 // Constructor with all defaults. Use when for example creating a
4404 // function known to use defaults.
4405 ExtInfo() = default;
4406
4407 // Constructor with just the calling convention, which is an important part
4408 // of the canonical type.
4409 ExtInfo(CallingConv CC) : Bits(CC) {}
4410
4411 bool getNoReturn() const { return Bits & NoReturnMask; }
4412 bool getProducesResult() const { return Bits & ProducesResultMask; }
4413 bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
4414 bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
4415 bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
4416 bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
4417
4418 unsigned getRegParm() const {
4419 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
4420 if (RegParm > 0)
4421 --RegParm;
4422 return RegParm;
4423 }
4424
4425 CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
4426
4427 bool operator==(ExtInfo Other) const {
4428 return Bits == Other.Bits;
4429 }
4430 bool operator!=(ExtInfo Other) const {
4431 return Bits != Other.Bits;
4432 }
4433
4434 // Note that we don't have setters. That is by design, use
4435 // the following with methods instead of mutating these objects.
4436
4437 ExtInfo withNoReturn(bool noReturn) const {
4438 if (noReturn)
4439 return ExtInfo(Bits | NoReturnMask);
4440 else
4441 return ExtInfo(Bits & ~NoReturnMask);
4442 }
4443
4444 ExtInfo withProducesResult(bool producesResult) const {
4445 if (producesResult)
4446 return ExtInfo(Bits | ProducesResultMask);
4447 else
4448 return ExtInfo(Bits & ~ProducesResultMask);
4449 }
4450
4451 ExtInfo withCmseNSCall(bool cmseNSCall) const {
4452 if (cmseNSCall)
4453 return ExtInfo(Bits | CmseNSCallMask);
4454 else
4455 return ExtInfo(Bits & ~CmseNSCallMask);
4456 }
4457
4458 ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
4459 if (noCallerSavedRegs)
4460 return ExtInfo(Bits | NoCallerSavedRegsMask);
4461 else
4462 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4463 }
4464
4465 ExtInfo withNoCfCheck(bool noCfCheck) const {
4466 if (noCfCheck)
4467 return ExtInfo(Bits | NoCfCheckMask);
4468 else
4469 return ExtInfo(Bits & ~NoCfCheckMask);
4470 }
4471
4472 ExtInfo withRegParm(unsigned RegParm) const {
4473 assert(RegParm < 7 && "Invalid regparm value");
4474 return ExtInfo((Bits & ~RegParmMask) |
4475 ((RegParm + 1) << RegParmOffset));
4476 }
4477
4479 return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
4480 }
4481
4482 void Profile(llvm::FoldingSetNodeID &ID) const {
4483 ID.AddInteger(Bits);
4484 }
4485 };
4486
4487 /// A simple holder for a QualType representing a type in an
4488 /// exception specification. Unfortunately needed by FunctionProtoType
4489 /// because TrailingObjects cannot handle repeated types.
4491
4492 /// A simple holder for various uncommon bits which do not fit in
4493 /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
4494 /// alignment of subsequent objects in TrailingObjects.
4495 struct alignas(void *) FunctionTypeExtraBitfields {
4496 /// The number of types in the exception specification.
4497 /// A whole unsigned is not needed here and according to
4498 /// [implimits] 8 bits would be enough here.
4499 unsigned NumExceptionType : 10;
4500
4501 LLVM_PREFERRED_TYPE(bool)
4502 unsigned HasArmTypeAttributes : 1;
4503
4505 : NumExceptionType(0), HasArmTypeAttributes(false) {}
4506 };
4507
4508 /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
4509 /// of function type attributes that can be set on function types, including
4510 /// function pointers.
4512 SME_NormalFunction = 0,
4513 SME_PStateSMEnabledMask = 1 << 0,
4514 SME_PStateSMCompatibleMask = 1 << 1,
4515
4516 // Describes the value of the state using ArmStateValue.
4517 SME_ZAShift = 2,
4518 SME_ZAMask = 0b111 << SME_ZAShift,
4519 SME_ZT0Shift = 5,
4520 SME_ZT0Mask = 0b111 << SME_ZT0Shift,
4521
4522 SME_AttributeMask =
4523 0b111'111'11 // We can't support more than 8 bits because of
4524 // the bitmask in FunctionTypeExtraBitfields.
4526
4527 enum ArmStateValue : unsigned {
4528 ARM_None = 0,
4529 ARM_Preserves = 1,
4530 ARM_In = 2,
4531 ARM_Out = 3,
4532 ARM_InOut = 4,
4533 };
4534
4535 static ArmStateValue getArmZAState(unsigned AttrBits) {
4536 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4537 }
4538
4539 static ArmStateValue getArmZT0State(unsigned AttrBits) {
4540 return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4541 }
4542
4543 /// A holder for Arm type attributes as described in the Arm C/C++
4544 /// Language extensions which are not particularly common to all
4545 /// types and therefore accounted separately from FunctionTypeBitfields.
4546 struct alignas(void *) FunctionTypeArmAttributes {
4547 /// Any AArch64 SME ACLE type attributes that need to be propagated
4548 /// on declarations and function pointers.
4550
4551 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
4552 };
4553
4554protected:
4557 : Type(tc, Canonical, Dependence), ResultType(res) {
4558 FunctionTypeBits.ExtInfo = Info.Bits;
4559 }
4560
4562 if (isFunctionProtoType())
4563 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4564
4565 return Qualifiers();
4566 }
4567
4568public:
4569 QualType getReturnType() const { return ResultType; }
4570
4571 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
4572 unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
4573
4574 /// Determine whether this function type includes the GNU noreturn
4575 /// attribute. The C++11 [[noreturn]] attribute does not affect the function
4576 /// type.
4577 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
4578
4579 bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
4580 CallingConv getCallConv() const { return getExtInfo().getCC(); }
4581 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
4582
4583 static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4584 "Const, volatile and restrict are assumed to be a subset of "
4585 "the fast qualifiers.");
4586
4587 bool isConst() const { return getFastTypeQuals().hasConst(); }
4588 bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
4589 bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
4590
4591 /// Determine the type of an expression that calls a function of
4592 /// this type.
4593 QualType getCallResultType(const ASTContext &Context) const {
4594 return getReturnType().getNonLValueExprType(Context);
4595 }
4596
4597 static StringRef getNameForCallConv(CallingConv CC);
4598
4599 static bool classof(const Type *T) {
4600 return T->getTypeClass() == FunctionNoProto ||
4601 T->getTypeClass() == FunctionProto;
4602 }
4603};
4604
4605/// Represents a K&R-style 'int foo()' function, which has
4606/// no information available about its arguments.
4607class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
4608 friend class ASTContext; // ASTContext creates these.
4609
4610 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
4611 : FunctionType(FunctionNoProto, Result, Canonical,
4612 Result->getDependence() &
4613 ~(TypeDependence::DependentInstantiation |
4614 TypeDependence::UnexpandedPack),
4615 Info) {}
4616
4617public:
4618 // No additional state past what FunctionType provides.
4619
4620 bool isSugared() const { return false; }
4621 QualType desugar() const { return QualType(this, 0); }
4622
4623 void Profile(llvm::FoldingSetNodeID &ID) {
4624 Profile(ID, getReturnType(), getExtInfo());
4625 }
4626
4627 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
4628 ExtInfo Info) {
4629 Info.Profile(ID);
4630 ID.AddPointer(ResultType.getAsOpaquePtr());
4631 }
4632
4633 static bool classof(const Type *T) {
4634 return T->getTypeClass() == FunctionNoProto;
4635 }
4636};
4637
4638/// Represents a prototype with parameter type info, e.g.
4639/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
4640/// parameters, not as having a single void parameter. Such a type can have
4641/// an exception specification, but this specification is not part of the
4642/// canonical type. FunctionProtoType has several trailing objects, some of
4643/// which optional. For more information about the trailing objects see
4644/// the first comment inside FunctionProtoType.
4646 : public FunctionType,
4647 public llvm::FoldingSetNode,
4648 private llvm::TrailingObjects<
4649 FunctionProtoType, QualType, SourceLocation,
4650 FunctionType::FunctionTypeExtraBitfields,
4651 FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
4652 Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
4653 friend class ASTContext; // ASTContext creates these.
4654 friend TrailingObjects;
4655
4656 // FunctionProtoType is followed by several trailing objects, some of
4657 // which optional. They are in order:
4658 //
4659 // * An array of getNumParams() QualType holding the parameter types.
4660 // Always present. Note that for the vast majority of FunctionProtoType,
4661 // these will be the only trailing objects.
4662 //
4663 // * Optionally if the function is variadic, the SourceLocation of the
4664 // ellipsis.
4665 //
4666 // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
4667 // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
4668 // a single FunctionTypeExtraBitfields. Present if and only if
4669 // hasExtraBitfields() is true.
4670 //
4671 // * Optionally exactly one of:
4672 // * an array of getNumExceptions() ExceptionType,
4673 // * a single Expr *,
4674 // * a pair of FunctionDecl *,
4675 // * a single FunctionDecl *
4676 // used to store information about the various types of exception
4677 // specification. See getExceptionSpecSize for the details.
4678 //
4679 // * Optionally an array of getNumParams() ExtParameterInfo holding
4680 // an ExtParameterInfo for each of the parameters. Present if and
4681 // only if hasExtParameterInfos() is true.
4682 //
4683 // * Optionally a Qualifiers object to represent extra qualifiers that can't
4684 // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and only
4685 // if hasExtQualifiers() is true.
4686 //
4687 // The optional FunctionTypeExtraBitfields has to be before the data
4688 // related to the exception specification since it contains the number
4689 // of exception types.
4690 //
4691 // We put the ExtParameterInfos last. If all were equal, it would make
4692 // more sense to put these before the exception specification, because
4693 // it's much easier to skip past them compared to the elaborate switch
4694 // required to skip the exception specification. However, all is not
4695 // equal; ExtParameterInfos are used to model very uncommon features,
4696 // and it's better not to burden the more common paths.
4697
4698public:
4699 /// Holds information about the various types of exception specification.
4700 /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
4701 /// used to group together the various bits of information about the
4702 /// exception specification.
4704 /// The kind of exception specification this is.
4706
4707 /// Explicitly-specified list of exception types.
4709
4710 /// Noexcept expression, if this is a computed noexcept specification.
4711 Expr *NoexceptExpr = nullptr;
4712
4713 /// The function whose exception specification this is, for
4714 /// EST_Unevaluated and EST_Uninstantiated.
4715 FunctionDecl *SourceDecl = nullptr;
4716
4717 /// The function template whose exception specification this is instantiated
4718 /// from, for EST_Uninstantiated.
4719 FunctionDecl *SourceTemplate = nullptr;
4720
4722
4724
4725 void instantiate();
4726 };
4727
4728 /// Extra information about a function prototype. ExtProtoInfo is not
4729 /// stored as such in FunctionProtoType but is used to group together
4730 /// the various bits of extra information about a function prototype.
4733 unsigned Variadic : 1;
4734 unsigned HasTrailingReturn : 1;
4739 const ExtParameterInfo *ExtParameterInfos = nullptr;
4741
4743 : Variadic(false), HasTrailingReturn(false),
4744 AArch64SMEAttributes(SME_NormalFunction) {}
4745
4747 : ExtInfo(CC), Variadic(false), HasTrailingReturn(false),
4748 AArch64SMEAttributes(SME_NormalFunction) {}
4749
4751 ExtProtoInfo Result(*this);
4752 Result.ExceptionSpec = ESI;
4753 return Result;
4754 }
4755
4757 return ExceptionSpec.Type == EST_Dynamic ||
4758 requiresFunctionProtoTypeArmAttributes();
4759 }
4760
4762 return AArch64SMEAttributes != SME_NormalFunction;
4763 }
4764
4765 void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable = true) {
4766 if (Enable)
4767 AArch64SMEAttributes |= Kind;
4768 else
4769 AArch64SMEAttributes &= ~Kind;
4770 }
4771 };
4772
4773private:
4774 unsigned numTrailingObjects(OverloadToken<QualType>) const {
4775 return getNumParams();
4776 }
4777
4778 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
4779 return isVariadic();
4780 }
4781
4782 unsigned numTrailingObjects(OverloadToken<FunctionTypeArmAttributes>) const {
4783 return hasArmTypeAttributes();
4784 }
4785
4786 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
4787 return hasExtraBitfields();
4788 }
4789
4790 unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
4791 return getExceptionSpecSize().NumExceptionType;
4792 }
4793
4794 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
4795 return getExceptionSpecSize().NumExprPtr;
4796 }
4797
4798 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
4799 return getExceptionSpecSize().NumFunctionDeclPtr;
4800 }
4801
4802 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
4803 return hasExtParameterInfos() ? getNumParams() : 0;
4804 }
4805
4806 /// Determine whether there are any argument types that
4807 /// contain an unexpanded parameter pack.
4808 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
4809 unsigned numArgs) {
4810 for (unsigned Idx = 0; Idx < numArgs; ++Idx)
4811 if (ArgArray[Idx]->containsUnexpandedParameterPack())
4812 return true;
4813
4814 return false;
4815 }
4816
4817 FunctionProtoType(QualType result, ArrayRef<QualType> params,
4818 QualType canonical, const ExtProtoInfo &epi);
4819
4820 /// This struct is returned by getExceptionSpecSize and is used to
4821 /// translate an ExceptionSpecificationType to the number and kind
4822 /// of trailing objects related to the exception specification.
4823 struct ExceptionSpecSizeHolder {
4824 unsigned NumExceptionType;
4825 unsigned NumExprPtr;
4826 unsigned NumFunctionDeclPtr;
4827 };
4828
4829 /// Return the number and kind of trailing objects
4830 /// related to the exception specification.
4831 static ExceptionSpecSizeHolder
4832 getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
4833 switch (EST) {
4834 case EST_None:
4835 case EST_DynamicNone:
4836 case EST_MSAny:
4837 case EST_BasicNoexcept:
4838 case EST_Unparsed:
4839 case EST_NoThrow:
4840 return {0, 0, 0};
4841
4842 case EST_Dynamic:
4843 return {NumExceptions, 0, 0};
4844
4846 case EST_NoexceptFalse:
4847 case EST_NoexceptTrue:
4848 return {0, 1, 0};
4849
4850 case EST_Uninstantiated:
4851 return {0, 0, 2};
4852
4853 case EST_Unevaluated:
4854 return {0, 0, 1};
4855 }
4856 llvm_unreachable("bad exception specification kind");
4857 }
4858
4859 /// Return the number and kind of trailing objects
4860 /// related to the exception specification.
4861 ExceptionSpecSizeHolder getExceptionSpecSize() const {
4862 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
4863 }
4864
4865 /// Whether the trailing FunctionTypeExtraBitfields is present.
4866 bool hasExtraBitfields() const {
4867 assert((getExceptionSpecType() != EST_Dynamic ||
4868 FunctionTypeBits.HasExtraBitfields) &&
4869 "ExtraBitfields are required for given ExceptionSpecType");
4870 return FunctionTypeBits.HasExtraBitfields;
4871
4872 }
4873
4874 bool hasArmTypeAttributes() const {
4875 return FunctionTypeBits.HasExtraBitfields &&
4876 getTrailingObjects<FunctionTypeExtraBitfields>()
4877 ->HasArmTypeAttributes;
4878 }
4879
4880 bool hasExtQualifiers() const {
4881 return FunctionTypeBits.HasExtQuals;
4882 }
4883
4884public:
4885 unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
4886
4887 QualType getParamType(unsigned i) const {
4888 assert(i < getNumParams() && "invalid parameter index");
4889 return param_type_begin()[i];
4890 }
4891
4893 return llvm::ArrayRef(param_type_begin(), param_type_end());
4894 }
4895
4897 ExtProtoInfo EPI;
4898 EPI.ExtInfo = getExtInfo();
4899 EPI.Variadic = isVariadic();
4900 EPI.EllipsisLoc = getEllipsisLoc();
4901 EPI.HasTrailingReturn = hasTrailingReturn();
4902 EPI.ExceptionSpec = getExceptionSpecInfo();
4903 EPI.TypeQuals = getMethodQuals();
4904 EPI.RefQualifier = getRefQualifier();
4905 EPI.ExtParameterInfos = getExtParameterInfosOrNull();
4906 EPI.AArch64SMEAttributes = getAArch64SMEAttributes();
4907 return EPI;
4908 }
4909
4910 /// Get the kind of exception specification on this function.
4912 return static_cast<ExceptionSpecificationType>(
4913 FunctionTypeBits.ExceptionSpecType);
4914 }
4915
4916 /// Return whether this function has any kind of exception spec.
4917 bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
4918
4919 /// Return whether this function has a dynamic (throw) exception spec.
4921 return isDynamicExceptionSpec(getExceptionSpecType());
4922 }
4923
4924 /// Return whether this function has a noexcept exception spec.
4926 return isNoexceptExceptionSpec(getExceptionSpecType());
4927 }
4928
4929 /// Return whether this function has a dependent exception spec.
4930 bool hasDependentExceptionSpec() const;
4931
4932 /// Return whether this function has an instantiation-dependent exception
4933 /// spec.
4934 bool hasInstantiationDependentExceptionSpec() const;
4935
4936 /// Return all the available information about this type's exception spec.
4938 ExceptionSpecInfo Result;
4939 Result.Type = getExceptionSpecType();
4940 if (Result.Type == EST_Dynamic) {
4941 Result.Exceptions = exceptions();
4942 } else if (isComputedNoexcept(Result.Type)) {
4943 Result.NoexceptExpr = getNoexceptExpr();
4944 } else if (Result.Type == EST_Uninstantiated) {
4945 Result.SourceDecl = getExceptionSpecDecl();
4946 Result.SourceTemplate = getExceptionSpecTemplate();
4947 } else if (Result.Type == EST_Unevaluated) {
4948 Result.SourceDecl = getExceptionSpecDecl();
4949 }
4950 return Result;
4951 }
4952
4953 /// Return the number of types in the exception specification.
4954 unsigned getNumExceptions() const {
4955 return getExceptionSpecType() == EST_Dynamic
4956 ? getTrailingObjects<FunctionTypeExtraBitfields>()
4957 ->NumExceptionType
4958 : 0;
4959 }
4960
4961 /// Return the ith exception type, where 0 <= i < getNumExceptions().
4962 QualType getExceptionType(unsigned i) const {
4963 assert(i < getNumExceptions() && "Invalid exception number!");
4964 return exception_begin()[i];
4965 }
4966
4967 /// Return the expression inside noexcept(expression), or a null pointer
4968 /// if there is none (because the exception spec is not of this form).
4970 if (!isComputedNoexcept(getExceptionSpecType()))
4971 return nullptr;
4972 return *getTrailingObjects<Expr *>();
4973 }
4974
4975 /// If this function type has an exception specification which hasn't
4976 /// been determined yet (either because it has not been evaluated or because
4977 /// it has not been instantiated), this is the function whose exception
4978 /// specification is represented by this type.
4980 if (getExceptionSpecType() != EST_Uninstantiated &&
4981 getExceptionSpecType() != EST_Unevaluated)
4982 return nullptr;
4983 return getTrailingObjects<FunctionDecl *>()[0];
4984 }
4985
4986 /// If this function type has an uninstantiated exception
4987 /// specification, this is the function whose exception specification
4988 /// should be instantiated to find the exception specification for
4989 /// this type.
4991 if (getExceptionSpecType() != EST_Uninstantiated)
4992 return nullptr;
4993 return getTrailingObjects<FunctionDecl *>()[1];
4994 }
4995
4996 /// Determine whether this function type has a non-throwing exception
4997 /// specification.
4998 CanThrowResult canThrow() const;
4999
5000 /// Determine whether this function type has a non-throwing exception
5001 /// specification. If this depends on template arguments, returns
5002 /// \c ResultIfDependent.
5003 bool isNothrow(bool ResultIfDependent = false) const {
5004 return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
5005 }
5006
5007 /// Whether this function prototype is variadic.
5008 bool isVariadic() const { return FunctionTypeBits.Variadic; }
5009
5011 return isVariadic() ? *getTrailingObjects<SourceLocation>()
5012 : SourceLocation();
5013 }
5014
5015 /// Determines whether this function prototype contains a
5016 /// parameter pack at the end.
5017 ///
5018 /// A function template whose last parameter is a parameter pack can be
5019 /// called with an arbitrary number of arguments, much like a variadic
5020 /// function.
5021 bool isTemplateVariadic() const;
5022
5023 /// Whether this function prototype has a trailing return type.
5024 bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
5025
5027 if (hasExtQualifiers())
5028 return *getTrailingObjects<Qualifiers>();
5029 else
5030 return getFastTypeQuals();
5031 }
5032
5033 /// Retrieve the ref-qualifier associated with this function type.
5035 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
5036 }
5037
5039
5041 return llvm::ArrayRef(param_type_begin(), param_type_end());
5042 }
5043
5045 return getTrailingObjects<QualType>();
5046 }
5047
5049 return param_type_begin() + getNumParams();
5050 }
5051
5053
5055 return llvm::ArrayRef(exception_begin(), exception_end());
5056 }
5057
5059 return reinterpret_cast<exception_iterator>(
5060 getTrailingObjects<ExceptionType>());
5061 }
5062
5064 return exception_begin() + getNumExceptions();
5065 }
5066
5067 /// Is there any interesting extra information for any of the parameters
5068 /// of this function type?
5070 return FunctionTypeBits.HasExtParameterInfos;
5071 }
5072
5074 assert(hasExtParameterInfos());
5075 return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
5076 getNumParams());
5077 }
5078
5079 /// Return a pointer to the beginning of the array of extra parameter
5080 /// information, if present, or else null if none of the parameters
5081 /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
5083 if (!hasExtParameterInfos())
5084 return nullptr;
5085 return getTrailingObjects<ExtParameterInfo>();
5086 }
5087
5088 /// Return a bitmask describing the SME attributes on the function type, see
5089 /// AArch64SMETypeAttributes for their values.
5090 unsigned getAArch64SMEAttributes() const {
5091 if (!hasArmTypeAttributes())
5092 return SME_NormalFunction;
5093 return getTrailingObjects<FunctionTypeArmAttributes>()
5094 ->AArch64SMEAttributes;
5095 }
5096
5098 assert(I < getNumParams() && "parameter index out of range");
5099 if (hasExtParameterInfos())
5100 return getTrailingObjects<ExtParameterInfo>()[I];
5101 return ExtParameterInfo();
5102 }
5103
5104 ParameterABI getParameterABI(unsigned I) const {
5105 assert(I < getNumParams() && "parameter index out of range");
5106 if (hasExtParameterInfos())
5107 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
5108 return ParameterABI::Ordinary;
5109 }
5110
5111 bool isParamConsumed(unsigned I) const {
5112 assert(I < getNumParams() && "parameter index out of range");
5113 if (hasExtParameterInfos())
5114 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
5115 return false;
5116 }
5117
5118 bool isSugared() const { return false; }
5119 QualType desugar() const { return QualType(this, 0); }
5120
5121 void printExceptionSpecification(raw_ostream &OS,
5122 const PrintingPolicy &Policy) const;
5123
5124 static bool classof(const Type *T) {
5125 return T->getTypeClass() == FunctionProto;
5126 }
5127
5128 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
5129 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
5130 param_type_iterator ArgTys, unsigned NumArgs,
5131 const ExtProtoInfo &EPI, const ASTContext &Context,
5132 bool Canonical);
5133};
5134
5135/// Represents the dependent type named by a dependently-scoped
5136/// typename using declaration, e.g.
5137/// using typename Base<T>::foo;
5138///
5139/// Template instantiation turns these into the underlying type.
5141 friend class ASTContext; // ASTContext creates these.
5142
5144
5146 : Type(UnresolvedUsing, QualType(),
5147 TypeDependence::DependentInstantiation),
5148 Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {}
5149
5150public:
5152
5153 bool isSugared() const { return false; }
5154 QualType desugar() const { return QualType(this, 0); }
5155
5156 static bool classof(const Type *T) {
5157 return T->getTypeClass() == UnresolvedUsing;
5158 }
5159
5160 void Profile(llvm::FoldingSetNodeID &ID) {
5161 return Profile(ID, Decl);
5162 }
5163
5164 static void Profile(llvm::FoldingSetNodeID &ID,
5166 ID.AddPointer(D);
5167 }
5168};
5169
5170class UsingType final : public Type,
5171 public llvm::FoldingSetNode,
5172 private llvm::TrailingObjects<UsingType, QualType> {
5173 UsingShadowDecl *Found;
5174 friend class ASTContext; // ASTContext creates these.
5175 friend TrailingObjects;
5176
5177 UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
5178
5179public:
5180 UsingShadowDecl *getFoundDecl() const { return Found; }
5182
5183 bool isSugared() const { return true; }
5184
5185 // This always has the 'same' type as declared, but not necessarily identical.
5186 QualType desugar() const { return getUnderlyingType(); }
5187
5188 // Internal helper, for debugging purposes.
5189 bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
5190
5191 void Profile(llvm::FoldingSetNodeID &ID) {
5192 Profile(ID, Found, getUnderlyingType());
5193 }
5194 static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
5195 QualType Underlying) {
5196 ID.AddPointer(Found);
5197 Underlying.Profile(ID);
5198 }
5199 static bool classof(const Type *T) { return T->getTypeClass() == Using; }
5200};
5201
5202class TypedefType final : public Type,
5203 public llvm::FoldingSetNode,
5204 private llvm::TrailingObjects<TypedefType, QualType> {
5206 friend class ASTContext; // ASTContext creates these.
5207 friend TrailingObjects;
5208
5209 TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
5210 QualType can);
5211
5212public:
5213 TypedefNameDecl *getDecl() const { return Decl; }
5214
5215 bool isSugared() const { return true; }
5216
5217 // This always has the 'same' type as declared, but not necessarily identical.
5218 QualType desugar() const;
5219
5220 // Internal helper, for debugging purposes.
5221 bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
5222
5223 void Profile(llvm::FoldingSetNodeID &ID) {
5224 Profile(ID, Decl, typeMatchesDecl() ? QualType() : desugar());
5225 }
5226 static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl,
5227 QualType Underlying) {
5228 ID.AddPointer(Decl);
5229 if (!Underlying.isNull())
5230 Underlying.Profile(ID);
5231 }
5232
5233 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
5234};
5235
5236/// Sugar type that represents a type that was qualified by a qualifier written
5237/// as a macro invocation.
5238class MacroQualifiedType : public Type {
5239 friend class ASTContext; // ASTContext creates these.
5240
5241 QualType UnderlyingTy;
5242 const IdentifierInfo *MacroII;
5243
5244 MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
5245 const IdentifierInfo *MacroII)
5246 : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
5247 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
5248 assert(isa<AttributedType>(UnderlyingTy) &&
5249 "Expected a macro qualified type to only wrap attributed types.");
5250 }
5251
5252public:
5253 const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
5254 QualType getUnderlyingType() const { return UnderlyingTy; }
5255
5256 /// Return this attributed type's modified type with no qualifiers attached to
5257 /// it.
5258 QualType getModifiedType() const;
5259
5260 bool isSugared() const { return true; }
5261 QualType desugar() const;
5262
5263 static bool classof(const Type *T) {
5264 return T->getTypeClass() == MacroQualified;
5265 }
5266};
5267
5268/// Represents a `typeof` (or __typeof__) expression (a C23 feature and GCC
5269/// extension) or a `typeof_unqual` expression (a C23 feature).
5270class TypeOfExprType : public Type {
5271 Expr *TOExpr;
5272
5273protected:
5274 friend class ASTContext; // ASTContext creates these.
5275
5276 TypeOfExprType(Expr *E, TypeOfKind Kind, QualType Can = QualType());
5277
5278public:
5279 Expr *getUnderlyingExpr() const { return TOExpr; }
5280
5281 /// Returns the kind of 'typeof' type this is.
5283 return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
5284 : TypeOfKind::Qualified;
5285 }
5286
5287 /// Remove a single level of sugar.
5288 QualType desugar() const;
5289
5290 /// Returns whether this type directly provides sugar.
5291 bool isSugared() const;
5292
5293 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
5294};
5295
5296/// Internal representation of canonical, dependent
5297/// `typeof(expr)` types.
5298///
5299/// This class is used internally by the ASTContext to manage
5300/// canonical, dependent types, only. Clients will only see instances
5301/// of this class via TypeOfExprType nodes.
5303 public llvm::FoldingSetNode {
5304public:
5306
5307 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5308 Profile(ID, Context, getUnderlyingExpr(),
5309 getKind() == TypeOfKind::Unqualified);
5310 }
5311
5312 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5313 Expr *E, bool IsUnqual);
5314};
5315
5316/// Represents `typeof(type)`, a C23 feature and GCC extension, or
5317/// `typeof_unqual(type), a C23 feature.
5318class TypeOfType : public Type {
5319 friend class ASTContext; // ASTContext creates these.
5320
5321 QualType TOType;
5322
5324 : Type(TypeOf,
5325 Kind == TypeOfKind::Unqualified ? Can.getAtomicUnqualifiedType()
5326 : Can,
5327 T->getDependence()),
5328 TOType(T) {
5329 TypeOfBits.IsUnqual = Kind == TypeOfKind::Unqualified;
5330 }
5331
5332public:
5333 QualType getUnmodifiedType() const { return TOType; }
5334
5335 /// Remove a single level of sugar.
5337 QualType QT = getUnmodifiedType();
5338 return TypeOfBits.IsUnqual ? QT.getAtomicUnqualifiedType() : QT;
5339 }
5340
5341 /// Returns whether this type directly provides sugar.
5342 bool isSugared() const { return true; }
5343
5344 /// Returns the kind of 'typeof' type this is.
5346 return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
5347 : TypeOfKind::Qualified;
5348 }
5349
5350 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
5351};
5352
5353/// Represents the type `decltype(expr)` (C++11).
5354class DecltypeType : public Type {
5355 Expr *E;
5356 QualType UnderlyingType;
5357
5358protected:
5359 friend class ASTContext; // ASTContext creates these.
5360
5361 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
5362
5363public:
5364 Expr *getUnderlyingExpr() const { return E; }
5365 QualType getUnderlyingType() const { return UnderlyingType; }
5366
5367 /// Remove a single level of sugar.
5368 QualType desugar() const;
5369
5370 /// Returns whether this type directly provides sugar.
5371 bool isSugared() const;
5372
5373 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
5374};
5375
5376/// Internal representation of canonical, dependent
5377/// decltype(expr) types.
5378///
5379/// This class is used internally by the ASTContext to manage
5380/// canonical, dependent types, only. Clients will only see instances
5381/// of this class via DecltypeType nodes.
5382class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
5383public:
5384 DependentDecltypeType(Expr *E, QualType UnderlyingTpe);
5385
5386 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5387 Profile(ID, Context, getUnderlyingExpr());
5388 }
5389
5390 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5391 Expr *E);
5392};
5393
5395 : public Type,
5396 public llvm::FoldingSetNode,
5397 private llvm::TrailingObjects<PackIndexingType, QualType> {
5398 friend TrailingObjects;
5399
5400 const ASTContext &Context;
5401 QualType Pattern;
5402 Expr *IndexExpr;
5403
5404 unsigned Size;
5405
5406protected:
5407 friend class ASTContext; // ASTContext creates these.
5408 PackIndexingType(const ASTContext &Context, QualType Canonical,
5409 QualType Pattern, Expr *IndexExpr,
5410 ArrayRef<QualType> Expansions = {});
5411
5412public:
5413 Expr *getIndexExpr() const { return IndexExpr; }
5414 QualType getPattern() const { return Pattern; }
5415
5416 bool isSugared() const { return hasSelectedType(); }
5417
5419 if (hasSelectedType())
5420 return getSelectedType();
5421 return QualType(this, 0);
5422 }
5423
5425 assert(hasSelectedType() && "Type is dependant");
5426 return *(getExpansionsPtr() + *getSelectedIndex());
5427 }
5428
5429 std::optional<unsigned> getSelectedIndex() const;
5430
5431 bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }
5432
5434 return {getExpansionsPtr(), Size};
5435 }
5436
5437 static bool classof(const Type *T) {
5438 return T->getTypeClass() == PackIndexing;
5439 }
5440
5441 void Profile(llvm::FoldingSetNodeID &ID) {
5442 if (hasSelectedType())
5443 getSelectedType().Profile(ID);
5444 else
5445 Profile(ID, Context, getPattern(), getIndexExpr());
5446 }
5447 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5448 QualType Pattern, Expr *E);
5449
5450private:
5451 const QualType *getExpansionsPtr() const {
5452 return getTrailingObjects<QualType>();
5453 }
5454
5455 static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
5456 ArrayRef<QualType> Expansions = {});
5457
5458 unsigned numTrailingObjects(OverloadToken<QualType>) const { return Size; }
5459};
5460
5461/// A unary type transform, which is a type constructed from another.
5462class UnaryTransformType : public Type {
5463public:
5464 enum UTTKind {
5465#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
5466#include "clang/Basic/TransformTypeTraits.def"
5467 };
5468
5469private:
5470 /// The untransformed type.
5471 QualType BaseType;
5472
5473 /// The transformed type if not dependent, otherwise the same as BaseType.
5474 QualType UnderlyingType;
5475
5476 UTTKind UKind;
5477
5478protected:
5479 friend class ASTContext;
5480
5481 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
5482 QualType CanonicalTy);
5483
5484public:
5485 bool isSugared() const { return !isDependentType(); }
5486 QualType desugar() const { return UnderlyingType; }
5487
5488 QualType getUnderlyingType() const { return UnderlyingType; }
5489 QualType getBaseType() const { return BaseType; }
5490
5491 UTTKind getUTTKind() const { return UKind; }
5492
5493 static bool classof(const Type *T) {
5494 return T->getTypeClass() == UnaryTransform;
5495 }
5496};
5497
5498/// Internal representation of canonical, dependent
5499/// __underlying_type(type) types.
5500///
5501/// This class is used internally by the ASTContext to manage
5502/// canonical, dependent types, only. Clients will only see instances
5503/// of this class via UnaryTransformType nodes.
5505 public llvm::FoldingSetNode {
5506public:
5508 UTTKind UKind);
5509
5510 void Profile(llvm::FoldingSetNodeID &ID) {
5511 Profile(ID, getBaseType(), getUTTKind());
5512 }
5513
5514 static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
5515 UTTKind UKind) {
5516 ID.AddPointer(BaseType.getAsOpaquePtr());
5517 ID.AddInteger((unsigned)UKind);
5518 }
5519};
5520
5521class TagType : public Type {
5522 friend class ASTReader;
5523 template <class T> friend class serialization::AbstractTypeReader;
5524
5525 /// Stores the TagDecl associated with this type. The decl may point to any
5526 /// TagDecl that declares the entity.
5527 TagDecl *decl;
5528
5529protected:
5530 TagType(TypeClass TC, const TagDecl *D, QualType can);
5531
5532public:
5533 TagDecl *getDecl() const;
5534
5535 /// Determines whether this type is in the process of being defined.
5536 bool isBeingDefined() const;
5537
5538 static bool classof(const Type *T) {
5539 return T->getTypeClass() == Enum || T->getTypeClass() == Record;
5540 }
5541};
5542
5543/// A helper class that allows the use of isa/cast/dyncast
5544/// to detect TagType objects of structs/unions/classes.
5545class RecordType : public TagType {
5546protected:
5547 friend class ASTContext; // ASTContext creates these.
5548
5549 explicit RecordType(const RecordDecl *D)
5550 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5552 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5553
5554public:
5556 return reinterpret_cast<RecordDecl*>(TagType::getDecl());
5557 }
5558
5559 /// Recursively check all fields in the record for const-ness. If any field
5560 /// is declared const, return true. Otherwise, return false.
5561 bool hasConstFields() const;
5562
5563 bool isSugared() const { return false; }
5564 QualType desugar() const { return QualType(this, 0); }
5565
5566 static bool classof(const Type *T) { return T->getTypeClass() == Record; }
5567};
5568
5569/// A helper class that allows the use of isa/cast/dyncast
5570/// to detect TagType objects of enums.
5571class EnumType : public TagType {
5572 friend class ASTContext; // ASTContext creates these.
5573
5574 explicit EnumType(const EnumDecl *D)
5575 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
5576
5577public:
5579 return reinterpret_cast<EnumDecl*>(TagType::getDecl());
5580 }
5581
5582 bool isSugared() const { return false; }
5583 QualType desugar() const { return QualType(this, 0); }
5584
5585 static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
5586};
5587
5588/// An attributed type is a type to which a type attribute has been applied.
5589///
5590/// The "modified type" is the fully-sugared type to which the attributed
5591/// type was applied; generally it is not canonically equivalent to the
5592/// attributed type. The "equivalent type" is the minimally-desugared type
5593/// which the type is canonically equivalent to.
5594///
5595/// For example, in the following attributed type:
5596/// int32_t __attribute__((vector_size(16)))
5597/// - the modified type is the TypedefType for int32_t
5598/// - the equivalent type is VectorType(16, int32_t)
5599/// - the canonical type is VectorType(16, int)
5600class AttributedType : public Type, public llvm::FoldingSetNode {
5601public:
5603
5604private:
5605 friend class ASTContext; // ASTContext creates these
5606
5607 QualType ModifiedType;
5608 QualType EquivalentType;
5609
5610 AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
5611 QualType equivalent)
5612 : Type(Attributed, canon, equivalent->getDependence()),
5613 ModifiedType(modified), EquivalentType(equivalent) {
5614 AttributedTypeBits.AttrKind = attrKind;
5615 }
5616
5617public:
5619 return static_cast<Kind>(AttributedTypeBits.AttrKind);
5620 }
5621
5622 QualType getModifiedType() const { return ModifiedType; }
5623 QualType getEquivalentType() const { return EquivalentType; }
5624
5625 bool isSugared() const { return true; }
5626 QualType desugar() const { return getEquivalentType(); }
5627
5628 /// Does this attribute behave like a type qualifier?
5629 ///
5630 /// A type qualifier adjusts a type to provide specialized rules for
5631 /// a specific object, like the standard const and volatile qualifiers.
5632 /// This includes attributes controlling things like nullability,
5633 /// address spaces, and ARC ownership. The value of the object is still
5634 /// largely described by the modified type.
5635 ///
5636 /// In contrast, many type attributes "rewrite" their modified type to
5637 /// produce a fundamentally different type, not necessarily related in any
5638 /// formalizable way to the original type. For example, calling convention
5639 /// and vector attributes are not simple type qualifiers.
5640 ///
5641 /// Type qualifiers are often, but not always, reflected in the canonical
5642 /// type.
5643 bool isQualifier() const;
5644
5645 bool isMSTypeSpec() const;
5646
5647 bool isWebAssemblyFuncrefSpec() const;
5648
5649 bool isCallingConv() const;
5650
5651 std::optional<NullabilityKind> getImmediateNullability() const;
5652
5653 /// Retrieve the attribute kind corresponding to the given
5654 /// nullability kind.
5656 switch (kind) {
5657 case NullabilityKind::NonNull:
5658 return attr::TypeNonNull;
5659
5660 case NullabilityKind::Nullable:
5661 return attr::TypeNullable;
5662
5663 case NullabilityKind::NullableResult:
5664 return attr::TypeNullableResult;
5665
5666 case NullabilityKind::Unspecified:
5667 return attr::TypeNullUnspecified;
5668 }
5669 llvm_unreachable("Unknown nullability kind.");
5670 }
5671
5672 /// Strip off the top-level nullability annotation on the given
5673 /// type, if it's there.
5674 ///
5675 /// \param T The type to strip. If the type is exactly an
5676 /// AttributedType specifying nullability (without looking through
5677 /// type sugar), the nullability is returned and this type changed
5678 /// to the underlying modified type.
5679 ///
5680 /// \returns the top-level nullability, if present.
5681 static std::optional<NullabilityKind> stripOuterNullability(QualType &T);
5682
5683 void Profile(llvm::FoldingSetNodeID &ID) {
5684 Profile(ID, getAttrKind(), ModifiedType, EquivalentType);
5685 }
5686
5687 static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
5688 QualType modified, QualType equivalent) {
5689 ID.AddInteger(attrKind);
5690 ID.AddPointer(modified.getAsOpaquePtr());
5691 ID.AddPointer(equivalent.getAsOpaquePtr());
5692 }
5693
5694 static bool classof(const Type *T) {
5695 return T->getTypeClass() == Attributed;
5696 }
5697};
5698
5699class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
5700private:
5701 friend class ASTContext; // ASTContext creates these
5702
5703 QualType WrappedType;
5704 const BTFTypeTagAttr *BTFAttr;
5705
5706 BTFTagAttributedType(QualType Canon, QualType Wrapped,
5707 const BTFTypeTagAttr *BTFAttr)
5708 : Type(BTFTagAttributed, Canon, Wrapped->getDependence()),
5709 WrappedType(Wrapped), BTFAttr(BTFAttr) {}
5710
5711public:
5712 QualType getWrappedType() const { return WrappedType; }
5713 const BTFTypeTagAttr *getAttr() const { return BTFAttr; }
5714
5715 bool isSugared() const { return true; }
5716 QualType desugar() const { return getWrappedType(); }
5717
5718 void Profile(llvm::FoldingSetNodeID &ID) {
5719 Profile(ID, WrappedType, BTFAttr);
5720 }
5721
5722 static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
5723 const BTFTypeTagAttr *BTFAttr) {
5724 ID.AddPointer(Wrapped.getAsOpaquePtr());
5725 ID.AddPointer(BTFAttr);
5726 }
5727
5728 static bool classof(const Type *T) {
5729 return T->getTypeClass() == BTFTagAttributed;
5730 }
5731};
5732
5733class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
5734 friend class ASTContext; // ASTContext creates these
5735
5736 // Helper data collector for canonical types.
5737 struct CanonicalTTPTInfo {
5738 unsigned Depth : 15;
5739 unsigned ParameterPack : 1;
5740 unsigned Index : 16;
5741 };
5742
5743 union {
5744 // Info for the canonical type.
5745 CanonicalTTPTInfo CanTTPTInfo;
5746
5747 // Info for the non-canonical type.
5749 };
5750
5751 /// Build a non-canonical type.
5753 : Type(TemplateTypeParm, Canon,
5754 TypeDependence::DependentInstantiation |
5755 (Canon->getDependence() & TypeDependence::UnexpandedPack)),
5756 TTPDecl(TTPDecl) {}
5757
5758 /// Build the canonical type.
5759 TemplateTypeParmType(unsigned D, unsigned I, bool PP)
5760 : Type(TemplateTypeParm, QualType(this, 0),
5761 TypeDependence::DependentInstantiation |
5762 (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)) {
5763 CanTTPTInfo.Depth = D;
5764 CanTTPTInfo.Index = I;
5765 CanTTPTInfo.ParameterPack = PP;
5766 }
5767
5768 const CanonicalTTPTInfo& getCanTTPTInfo() const {
5769 QualType Can = getCanonicalTypeInternal();
5770 return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo;
5771 }
5772
5773public:
5774 unsigned getDepth() const { return getCanTTPTInfo().Depth; }
5775 unsigned getIndex() const { return getCanTTPTInfo().Index; }
5776 bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; }
5777
5779 return isCanonicalUnqualified() ? nullptr : TTPDecl;
5780 }
5781
5783
5784 bool isSugared() const { return false; }
5785 QualType desugar() const { return QualType(this, 0); }
5786
5787 void Profile(llvm::FoldingSetNodeID &ID) {
5788 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
5789 }
5790
5791 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
5792 unsigned Index, bool ParameterPack,
5793 TemplateTypeParmDecl *TTPDecl) {
5794 ID.AddInteger(Depth);
5795 ID.AddInteger(Index);
5796 ID.AddBoolean(ParameterPack);
5797 ID.AddPointer(TTPDecl);
5798 }
5799
5800 static bool classof(const Type *T) {
5801 return T->getTypeClass() == TemplateTypeParm;
5802 }
5803};
5804
5805/// Represents the result of substituting a type for a template
5806/// type parameter.
5807///
5808/// Within an instantiated template, all template type parameters have
5809/// been replaced with these. They are used solely to record that a
5810/// type was originally written as a template type parameter;
5811/// therefore they are never canonical.
5813 : public Type,
5814 public llvm::FoldingSetNode,
5815 private llvm::TrailingObjects<SubstTemplateTypeParmType, QualType> {
5816 friend class ASTContext;
5817 friend class llvm::TrailingObjects<SubstTemplateTypeParmType, QualType>;
5818
5819 Decl *AssociatedDecl;
5820
5821 SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
5822 unsigned Index, std::optional<unsigned> PackIndex);
5823
5824public:
5825 /// Gets the type that was substituted for the template
5826 /// parameter.
5828 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
5829 ? *getTrailingObjects<QualType>()
5830 : getCanonicalTypeInternal();
5831 }
5832
5833 /// A template-like entity which owns the whole pattern being substituted.
5834 /// This will usually own a set of template parameters, or in some
5835 /// cases might even be a template parameter itself.
5836 Decl *getAssociatedDecl() const { return AssociatedDecl; }
5837
5838 /// Gets the template parameter declaration that was substituted for.
5840
5841 /// Returns the index of the replaced parameter in the associated declaration.
5842 /// This should match the result of `getReplacedParameter()->getIndex()`.
5843 unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
5844
5845 std::optional<unsigned> getPackIndex() const {
5846 if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
5847 return std::nullopt;
5848 return SubstTemplateTypeParmTypeBits.PackIndex - 1;
5849 }
5850
5851 bool isSugared() const { return true; }
5852 QualType desugar() const { return getReplacementType(); }
5853
5854 void Profile(llvm::FoldingSetNodeID &ID) {
5855 Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
5856 getPackIndex());
5857 }
5858
5859 static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
5860 const Decl *AssociatedDecl, unsigned Index,
5861 std::optional<unsigned> PackIndex) {
5862 Replacement.Profile(ID);
5863 ID.AddPointer(AssociatedDecl);
5864 ID.AddInteger(Index);
5865 ID.AddInteger(PackIndex ? *PackIndex - 1 : 0);
5866 }
5867
5868 static bool classof(const Type *T) {
5869 return T->getTypeClass() == SubstTemplateTypeParm;
5870 }
5871};
5872
5873/// Represents the result of substituting a set of types for a template
5874/// type parameter pack.
5875///
5876/// When a pack expansion in the source code contains multiple parameter packs
5877/// and those parameter packs correspond to different levels of template
5878/// parameter lists, this type node is used to represent a template type
5879/// parameter pack from an outer level, which has already had its argument pack
5880/// substituted but that still lives within a pack expansion that itself
5881/// could not be instantiated. When actually performing a substitution into
5882/// that pack expansion (e.g., when all template parameters have corresponding
5883/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
5884/// at the current pack substitution index.
5885class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
5886 friend class ASTContext;
5887
5888 /// A pointer to the set of template arguments that this
5889 /// parameter pack is instantiated with.
5890 const TemplateArgument *Arguments;
5891
5892 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
5893
5894 SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
5895 unsigned Index, bool Final,
5896 const TemplateArgument &ArgPack);
5897
5898public:
5900
5901 /// A template-like entity which owns the whole pattern being substituted.
5902 /// This will usually own a set of template parameters, or in some
5903 /// cases might even be a template parameter itself.
5904 Decl *getAssociatedDecl() const;
5905
5906 /// Gets the template parameter declaration that was substituted for.
5908
5909 /// Returns the index of the replaced parameter in the associated declaration.
5910 /// This should match the result of `getReplacedParameter()->getIndex()`.
5911 unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
5912
5913 // When true the substitution will be 'Final' (subst node won't be placed).
5914 bool getFinal() const;
5915
5916 unsigned getNumArgs() const {
5917 return SubstTemplateTypeParmPackTypeBits.NumArgs;
5918 }
5919
5920 bool isSugared() const { return false; }
5921 QualType desugar() const { return QualType(this, 0); }
5922
5923 TemplateArgument getArgumentPack() const;
5924
5925 void Profile(llvm::FoldingSetNodeID &ID);
5926 static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
5927 unsigned Index, bool Final,
5928 const TemplateArgument &ArgPack);
5929
5930 static bool classof(const Type *T) {
5931 return T->getTypeClass() == SubstTemplateTypeParmPack;
5932 }
5933};
5934
5935/// Common base class for placeholders for types that get replaced by
5936/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
5937/// class template types, and constrained type names.
5938///
5939/// These types are usually a placeholder for a deduced type. However, before
5940/// the initializer is attached, or (usually) if the initializer is
5941/// type-dependent, there is no deduced type and the type is canonical. In
5942/// the latter case, it is also a dependent type.
5943class DeducedType : public Type {
5944 QualType DeducedAsType;
5945
5946protected:
5947 DeducedType(TypeClass TC, QualType DeducedAsType,
5948 TypeDependence ExtraDependence, QualType Canon)
5949 : Type(TC, Canon,
5950 ExtraDependence | (DeducedAsType.isNull()
5952 : DeducedAsType->getDependence() &
5953 ~TypeDependence::VariablyModified)),
5954 DeducedAsType(DeducedAsType) {}
5955
5956public:
5957 bool isSugared() const { return !DeducedAsType.isNull(); }
5959 return isSugared() ? DeducedAsType : QualType(this, 0);
5960 }
5961
5962 /// Get the type deduced for this placeholder type, or null if it
5963 /// has not been deduced.
5964 QualType getDeducedType() const { return DeducedAsType; }
5965 bool isDeduced() const {
5966 return !DeducedAsType.isNull() || isDependentType();
5967 }
5968
5969 static bool classof(const Type *T) {
5970 return T->getTypeClass() == Auto ||
5971 T->getTypeClass() == DeducedTemplateSpecialization;
5972 }
5973};
5974
5975/// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
5976/// by a type-constraint.
5977class AutoType : public DeducedType, public llvm::FoldingSetNode {
5978 friend class ASTContext; // ASTContext creates these
5979
5980 ConceptDecl *TypeConstraintConcept;
5981
5982 AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
5983 TypeDependence ExtraDependence, QualType Canon, ConceptDecl *CD,
5984 ArrayRef<TemplateArgument> TypeConstraintArgs);
5985
5986public:
5988 return {reinterpret_cast<const TemplateArgument *>(this + 1),
5989 AutoTypeBits.NumArgs};
5990 }
5991
5993 return TypeConstraintConcept;
5994 }
5995
5996 bool isConstrained() const {
5997 return TypeConstraintConcept != nullptr;
5998 }
5999
6000 bool isDecltypeAuto() const {
6001 return getKeyword() == AutoTypeKeyword::DecltypeAuto;
6002 }
6003
6004 bool isGNUAutoType() const {
6005 return getKeyword() == AutoTypeKeyword::GNUAutoType;
6006 }
6007
6009 return (AutoTypeKeyword)AutoTypeBits.Keyword;
6010 }
6011
6012 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
6013 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6014 QualType Deduced, AutoTypeKeyword Keyword,
6015 bool IsDependent, ConceptDecl *CD,
6016 ArrayRef<TemplateArgument> Arguments);
6017
6018 static bool classof(const Type *T) {
6019 return T->getTypeClass() == Auto;
6020 }
6021};
6022
6023/// Represents a C++17 deduced template specialization type.
6025 public llvm::FoldingSetNode {
6026 friend class ASTContext; // ASTContext creates these
6027
6028 /// The name of the template whose arguments will be deduced.
6029 TemplateName Template;
6030
6032 QualType DeducedAsType,
6033 bool IsDeducedAsDependent)
6034 : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
6035 toTypeDependence(Template.getDependence()) |
6036 (IsDeducedAsDependent
6037 ? TypeDependence::DependentInstantiation
6038 : TypeDependence::None),
6039 DeducedAsType.isNull() ? QualType(this, 0)
6040 : DeducedAsType.getCanonicalType()),
6041 Template(Template) {}
6042
6043public:
6044 /// Retrieve the name of the template that we are deducing.
6045 TemplateName getTemplateName() const { return Template;}
6046
6047 void Profile(llvm::FoldingSetNodeID &ID) {
6048 Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
6049 }
6050
6051 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
6052 QualType Deduced, bool IsDependent) {
6053 Template.Profile(ID);
6054 QualType CanonicalType =
6055 Deduced.isNull() ? Deduced : Deduced.getCanonicalType();
6056 ID.AddPointer(CanonicalType.getAsOpaquePtr());
6057 ID.AddBoolean(IsDependent || Template.isDependent());
6058 }
6059
6060 static bool classof(const Type *T) {
6061 return T->getTypeClass() == DeducedTemplateSpecialization;
6062 }
6063};
6064
6065/// Represents a type template specialization; the template
6066/// must be a class template, a type alias template, or a template
6067/// template parameter. A template which cannot be resolved to one of
6068/// these, e.g. because it is written with a dependent scope
6069/// specifier, is instead represented as a
6070/// @c DependentTemplateSpecializationType.
6071///
6072/// A non-dependent template specialization type is always "sugar",
6073/// typically for a \c RecordType. For example, a class template
6074/// specialization type of \c vector<int> will refer to a tag type for
6075/// the instantiation \c std::vector<int, std::allocator<int>>
6076///
6077/// Template specializations are dependent if either the template or
6078/// any of the template arguments are dependent, in which case the
6079/// type may also be canonical.
6080///
6081/// Instances of this type are allocated with a trailing array of
6082/// TemplateArguments, followed by a QualType representing the
6083/// non-canonical aliased type when the template is a type alias
6084/// template.
6085class TemplateSpecializationType : public Type, public llvm::FoldingSetNode {
6086 friend class ASTContext; // ASTContext creates these
6087
6088 /// The name of the template being specialized. This is
6089 /// either a TemplateName::Template (in which case it is a
6090 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
6091 /// TypeAliasTemplateDecl*), a
6092 /// TemplateName::SubstTemplateTemplateParmPack, or a
6093 /// TemplateName::SubstTemplateTemplateParm (in which case the
6094 /// replacement must, recursively, be one of these).
6095 TemplateName Template;
6096
6099 QualType Canon,
6100 QualType Aliased);
6101
6102public:
6103 /// Determine whether any of the given template arguments are dependent.
6104 ///
6105 /// The converted arguments should be supplied when known; whether an
6106 /// argument is dependent can depend on the conversions performed on it
6107 /// (for example, a 'const int' passed as a template argument might be
6108 /// dependent if the parameter is a reference but non-dependent if the
6109 /// parameter is an int).
6110 ///
6111 /// Note that the \p Args parameter is unused: this is intentional, to remind
6112 /// the caller that they need to pass in the converted arguments, not the
6113 /// specified arguments.
6114 static bool
6115 anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
6116 ArrayRef<TemplateArgument> Converted);
6117 static bool
6118 anyDependentTemplateArguments(const TemplateArgumentListInfo &,
6119 ArrayRef<TemplateArgument> Converted);
6120 static bool anyInstantiationDependentTemplateArguments(
6122
6123 /// True if this template specialization type matches a current
6124 /// instantiation in the context in which it is found.
6126 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
6127 }
6128
6129 /// Determine if this template specialization type is for a type alias
6130 /// template that has been substituted.
6131 ///
6132 /// Nearly every template specialization type whose template is an alias
6133 /// template will be substituted. However, this is not the case when
6134 /// the specialization contains a pack expansion but the template alias
6135 /// does not have a corresponding parameter pack, e.g.,
6136 ///
6137 /// \code
6138 /// template<typename T, typename U, typename V> struct S;
6139 /// template<typename T, typename U> using A = S<T, int, U>;
6140 /// template<typename... Ts> struct X {
6141 /// typedef A<Ts...> type; // not a type alias
6142 /// };
6143 /// \endcode
6144 bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
6145
6146 /// Get the aliased type, if this is a specialization of a type alias
6147 /// template.
6148 QualType getAliasedType() const;
6149
6150 /// Retrieve the name of the template that we are specializing.
6151 TemplateName getTemplateName() const { return Template; }
6152
6154 return {reinterpret_cast<const TemplateArgument *>(this + 1),
6155 TemplateSpecializationTypeBits.NumArgs};
6156 }
6157
6158 bool isSugared() const {
6159 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
6160 }
6161
6163 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
6164 }
6165
6166 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
6167 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
6169 const ASTContext &Context);
6170
6171 static bool classof(const Type *T) {
6172 return T->getTypeClass() == TemplateSpecialization;
6173 }
6174};
6175
6176/// Print a template argument list, including the '<' and '>'
6177/// enclosing the template arguments.
6178void printTemplateArgumentList(raw_ostream &OS,
6179 ArrayRef<TemplateArgument> Args,
6180 const PrintingPolicy &Policy,
6181 const TemplateParameterList *TPL = nullptr);
6182
6183void printTemplateArgumentList(raw_ostream &OS,
6184 ArrayRef<TemplateArgumentLoc> Args,
6185 const PrintingPolicy &Policy,
6186 const TemplateParameterList *TPL = nullptr);
6187
6188void printTemplateArgumentList(raw_ostream &OS,
6189 const TemplateArgumentListInfo &Args,
6190 const PrintingPolicy &Policy,
6191 const TemplateParameterList *TPL = nullptr);
6192
6193/// Make a best-effort determination of whether the type T can be produced by
6194/// substituting Args into the default argument of Param.
6195bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
6196 const NamedDecl *Param,
6197 ArrayRef<TemplateArgument> Args,
6198 unsigned Depth);
6199
6200/// The injected class name of a C++ class template or class
6201/// template partial specialization. Used to record that a type was
6202/// spelled with a bare identifier rather than as a template-id; the
6203/// equivalent for non-templated classes is just RecordType.
6204///
6205/// Injected class name types are always dependent. Template
6206/// instantiation turns these into RecordTypes.
6207///
6208/// Injected class name types are always canonical. This works
6209/// because it is impossible to compare an injected class name type
6210/// with the corresponding non-injected template type, for the same
6211/// reason that it is impossible to directly compare template
6212/// parameters from different dependent contexts: injected class name
6213/// types can only occur within the scope of a particular templated
6214/// declaration, and within that scope every template specialization
6215/// will canonicalize to the injected class name (when appropriate
6216/// according to the rules of the language).
6218 friend class ASTContext; // ASTContext creates these.
6219 friend class ASTNodeImporter;
6220 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
6221 // currently suitable for AST reading, too much
6222 // interdependencies.
6223 template <class T> friend class serialization::AbstractTypeReader;
6224
6226
6227 /// The template specialization which this type represents.
6228 /// For example, in
6229 /// template <class T> class A { ... };
6230 /// this is A<T>, whereas in
6231 /// template <class X, class Y> class A<B<X,Y> > { ... };
6232 /// this is A<B<X,Y> >.
6233 ///
6234 /// It is always unqualified, always a template specialization type,
6235 /// and always dependent.
6236 QualType InjectedType;
6237
6239 : Type(InjectedClassName, QualType(),
6240 TypeDependence::DependentInstantiation),
6241 Decl(D), InjectedType(TST) {
6242 assert(isa<TemplateSpecializationType>(TST));
6243 assert(!TST.hasQualifiers());
6244 assert(TST->isDependentType());
6245 }
6246
6247public:
6248 QualType getInjectedSpecializationType() const { return InjectedType; }
6249
6251 return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
6252 }
6253
6255 return getInjectedTST()->getTemplateName();
6256 }
6257
6258 CXXRecordDecl *getDecl() const;
6259
6260 bool isSugared() const { return false; }
6261 QualType desugar() const { return QualType(this, 0); }
6262
6263 static bool classof(const Type *T) {
6264 return T->getTypeClass() == InjectedClassName;
6265 }
6266};
6267
6268/// The elaboration keyword that precedes a qualified type name or
6269/// introduces an elaborated-type-specifier.
6271 /// The "struct" keyword introduces the elaborated-type-specifier.
6272 Struct,
6273
6274 /// The "__interface" keyword introduces the elaborated-type-specifier.
6275 Interface,
6276
6277 /// The "union" keyword introduces the elaborated-type-specifier.
6278 Union,
6279
6280 /// The "class" keyword introduces the elaborated-type-specifier.
6281 Class,
6282
6283 /// The "enum" keyword introduces the elaborated-type-specifier.
6284 Enum,
6285
6286 /// The "typename" keyword precedes the qualified type name, e.g.,
6287 /// \c typename T::type.
6288 Typename,
6289
6290 /// No keyword precedes the qualified type name.
6291 None
6292};
6293
6294/// The kind of a tag type.
6295enum class TagTypeKind {
6296 /// The "struct" keyword.
6297 Struct,
6298
6299 /// The "__interface" keyword.
6300 Interface,
6301
6302 /// The "union" keyword.
6303 Union,
6304
6305 /// The "class" keyword.
6306 Class,
6307
6308 /// The "enum" keyword.
6309 Enum
6310};
6311
6312/// A helper class for Type nodes having an ElaboratedTypeKeyword.
6313/// The keyword in stored in the free bits of the base class.
6314/// Also provides a few static helpers for converting and printing
6315/// elaborated type keyword and tag type kind enumerations.
6316class TypeWithKeyword : public Type {
6317protected:
6320 : Type(tc, Canonical, Dependence) {
6321 TypeWithKeywordBits.Keyword = llvm::to_underlying(Keyword);
6322 }
6323
6324public:
6326 return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
6327 }
6328
6329 /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
6330 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
6331
6332 /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
6333 /// It is an error to provide a type specifier which *isn't* a tag kind here.
6334 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
6335
6336 /// Converts a TagTypeKind into an elaborated type keyword.
6337 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
6338
6339 /// Converts an elaborated type keyword into a TagTypeKind.
6340 /// It is an error to provide an elaborated type keyword
6341 /// which *isn't* a tag kind here.
6342 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
6343
6344 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
6345
6346 static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
6347
6348 static StringRef getTagTypeKindName(TagTypeKind Kind) {
6349 return getKeywordName(getKeywordForTagTypeKind(Kind));
6350 }
6351
6354};
6355
6356/// Represents a type that was referred to using an elaborated type
6357/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
6358/// or both.
6359///
6360/// This type is used to keep track of a type name as written in the
6361/// source code, including tag keywords and any nested-name-specifiers.
6362/// The type itself is always "sugar", used to express what was written
6363/// in the source code but containing no additional semantic information.
6365 : public TypeWithKeyword,
6366 public llvm::FoldingSetNode,
6367 private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
6368 friend class ASTContext; // ASTContext creates these
6369 friend TrailingObjects;
6370
6371 /// The nested name specifier containing the qualifier.
6373
6374 /// The type that this qualified name refers to.
6375 QualType NamedType;
6376
6377 /// The (re)declaration of this tag type owned by this occurrence is stored
6378 /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
6379 /// it, or obtain a null pointer if there is none.
6380
6382 QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
6383 : TypeWithKeyword(Keyword, Elaborated, CanonType,
6384 // Any semantic dependence on the qualifier will have
6385 // been incorporated into NamedType. We still need to
6386 // track syntactic (instantiation / error / pack)
6387 // dependence on the qualifier.
6388 NamedType->getDependence() |
6389 (NNS ? toSyntacticDependence(
6390 toTypeDependence(NNS->getDependence()))
6391 : TypeDependence::None)),
6392 NNS(NNS), NamedType(NamedType) {
6393 ElaboratedTypeBits.HasOwnedTagDecl = false;
6394 if (OwnedTagDecl) {
6395 ElaboratedTypeBits.HasOwnedTagDecl = true;
6396 *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
6397 }
6398 }
6399
6400public:
6401 /// Retrieve the qualification on this type.
6402 NestedNameSpecifier *getQualifier() const { return NNS; }
6403
6404 /// Retrieve the type named by the qualified-id.
6405 QualType getNamedType() const { return NamedType; }
6406
6407 /// Remove a single level of sugar.
6408 QualType desugar() const { return getNamedType(); }
6409
6410 /// Returns whether this type directly provides sugar.
6411 bool isSugared() const { return true; }
6412
6413 /// Return the (re)declaration of this type owned by this occurrence of this
6414 /// type, or nullptr if there is none.
6416 return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
6417 : nullptr;
6418 }
6419
6420 void Profile(llvm::FoldingSetNodeID &ID) {
6421 Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
6422 }
6423
6424 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6425 NestedNameSpecifier *NNS, QualType NamedType,
6426 TagDecl *OwnedTagDecl) {
6427 ID.AddInteger(llvm::to_underlying(Keyword));
6428 ID.AddPointer(NNS);
6429 NamedType.Profile(ID);
6430 ID.AddPointer(OwnedTagDecl);
6431 }
6432
6433 static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
6434};
6435
6436/// Represents a qualified type name for which the type name is
6437/// dependent.
6438///
6439/// DependentNameType represents a class of dependent types that involve a
6440/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
6441/// name of a type. The DependentNameType may start with a "typename" (for a
6442/// typename-specifier), "class", "struct", "union", or "enum" (for a
6443/// dependent elaborated-type-specifier), or nothing (in contexts where we
6444/// know that we must be referring to a type, e.g., in a base class specifier).
6445/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
6446/// mode, this type is used with non-dependent names to delay name lookup until
6447/// instantiation.
6448class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
6449 friend class ASTContext; // ASTContext creates these
6450
6451 /// The nested name specifier containing the qualifier.
6453
6454 /// The type that this typename specifier refers to.
6455 const IdentifierInfo *Name;
6456
6458 const IdentifierInfo *Name, QualType CanonType)
6459 : TypeWithKeyword(Keyword, DependentName, CanonType,
6460 TypeDependence::DependentInstantiation |
6461 toTypeDependence(NNS->getDependence())),
6462 NNS(NNS), Name(Name) {}
6463
6464public:
6465 /// Retrieve the qualification on this type.
6466 NestedNameSpecifier *getQualifier() const { return NNS; }
6467
6468 /// Retrieve the type named by the typename specifier as an identifier.
6469 ///
6470 /// This routine will return a non-NULL identifier pointer when the
6471 /// form of the original typename was terminated by an identifier,
6472 /// e.g., "typename T::type".
6474 return Name;
6475 }
6476
6477 bool isSugared() const { return false; }
6478 QualType desugar() const { return QualType(this, 0); }
6479
6480 void Profile(llvm::FoldingSetNodeID &ID) {
6481 Profile(ID, getKeyword(), NNS, Name);
6482 }
6483
6484 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6485 NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
6486 ID.AddInteger(llvm::to_underlying(Keyword));
6487 ID.AddPointer(NNS);
6488 ID.AddPointer(Name);
6489 }
6490
6491 static bool classof(const Type *T) {
6492 return T->getTypeClass() == DependentName;
6493 }
6494};
6495
6496/// Represents a template specialization type whose template cannot be
6497/// resolved, e.g.
6498/// A<T>::template B<T>
6500 public llvm::FoldingSetNode {
6501 friend class ASTContext; // ASTContext creates these
6502
6503 /// The nested name specifier containing the qualifier.
6505
6506 /// The identifier of the template.
6507 const IdentifierInfo *Name;
6508
6511 const IdentifierInfo *Name,
6513 QualType Canon);
6514
6515public:
6516 NestedNameSpecifier *getQualifier() const { return NNS; }
6517 const IdentifierInfo *getIdentifier() const { return Name; }
6518
6520 return {reinterpret_cast<const TemplateArgument *>(this + 1),
6521 DependentTemplateSpecializationTypeBits.NumArgs};
6522 }
6523
6524 bool isSugared() const { return false; }
6525 QualType desugar() const { return QualType(this, 0); }
6526
6527 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6528 Profile(ID, Context, getKeyword(), NNS, Name, template_arguments());
6529 }
6530
6531 static void Profile(llvm::FoldingSetNodeID &ID,
6532 const ASTContext &Context,
6533 ElaboratedTypeKeyword Keyword,
6534 NestedNameSpecifier *Qualifier,
6535 const IdentifierInfo *Name,
6537
6538 static bool classof(const Type *T) {
6539 return T->getTypeClass() == DependentTemplateSpecialization;
6540 }
6541};
6542
6543/// Represents a pack expansion of types.
6544///
6545/// Pack expansions are part of C++11 variadic templates. A pack
6546/// expansion contains a pattern, which itself contains one or more
6547/// "unexpanded" parameter packs. When instantiated, a pack expansion
6548/// produces a series of types, each instantiated from the pattern of
6549/// the expansion, where the Ith instantiation of the pattern uses the
6550/// Ith arguments bound to each of the unexpanded parameter packs. The
6551/// pack expansion is considered to "expand" these unexpanded
6552/// parameter packs.
6553///
6554/// \code
6555/// template<typename ...Types> struct tuple;
6556///
6557/// template<typename ...Types>
6558/// struct tuple_of_references {
6559/// typedef tuple<Types&...> type;
6560/// };
6561/// \endcode
6562///
6563/// Here, the pack expansion \c Types&... is represented via a
6564/// PackExpansionType whose pattern is Types&.
6565class PackExpansionType : public Type, public llvm::FoldingSetNode {
6566 friend class ASTContext; // ASTContext creates these
6567
6568 /// The pattern of the pack expansion.
6569 QualType Pattern;
6570
6571 PackExpansionType(QualType Pattern, QualType Canon,
6572 std::optional<unsigned> NumExpansions)
6573 : Type(PackExpansion, Canon,
6574 (Pattern->getDependence() | TypeDependence::Dependent |
6575 TypeDependence::Instantiation) &
6576 ~TypeDependence::UnexpandedPack),
6577 Pattern(Pattern) {
6578 PackExpansionTypeBits.NumExpansions =
6579 NumExpansions ? *NumExpansions + 1 : 0;
6580 }
6581
6582public:
6583 /// Retrieve the pattern of this pack expansion, which is the
6584 /// type that will be repeatedly instantiated when instantiating the
6585 /// pack expansion itself.
6586 QualType getPattern() const { return Pattern; }
6587
6588 /// Retrieve the number of expansions that this pack expansion will
6589 /// generate, if known.
6590 std::optional<unsigned> getNumExpansions() const {
6591 if (PackExpansionTypeBits.NumExpansions)
6592 return PackExpansionTypeBits.NumExpansions - 1;
6593 return std::nullopt;
6594 }
6595
6596 bool isSugared() const { return false; }
6597 QualType desugar() const { return QualType(this, 0); }
6598
6599 void Profile(llvm::FoldingSetNodeID &ID) {
6600 Profile(ID, getPattern(), getNumExpansions());
6601 }
6602
6603 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
6604 std::optional<unsigned> NumExpansions) {
6605 ID.AddPointer(Pattern.getAsOpaquePtr());
6606 ID.AddBoolean(NumExpansions.has_value());
6607 if (NumExpansions)
6608 ID.AddInteger(*NumExpansions);
6609 }
6610
6611 static bool classof(const Type *T) {
6612 return T->getTypeClass() == PackExpansion;
6613 }
6614};
6615
6616/// This class wraps the list of protocol qualifiers. For types that can
6617/// take ObjC protocol qualifers, they can subclass this class.
6618template <class T>
6620protected:
6622
6624 return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
6625 }
6626
6628 return static_cast<T*>(this)->getProtocolStorageImpl();
6629 }
6630
6631 void setNumProtocols(unsigned N) {
6632 static_cast<T*>(this)->setNumProtocolsImpl(N);
6633 }
6634
6636 setNumProtocols(protocols.size());
6637 assert(getNumProtocols() == protocols.size() &&
6638 "bitfield overflow in protocol count");
6639 if (!protocols.empty())
6640 memcpy(getProtocolStorage(), protocols.data(),
6641 protocols.size() * sizeof(ObjCProtocolDecl*));
6642 }
6643
6644public:
6646 using qual_range = llvm::iterator_range<qual_iterator>;
6647
6648 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
6649 qual_iterator qual_begin() const { return getProtocolStorage(); }
6650 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
6651
6652 bool qual_empty() const { return getNumProtocols() == 0; }
6653
6654 /// Return the number of qualifying protocols in this type, or 0 if
6655 /// there are none.
6656 unsigned getNumProtocols() const {
6657 return static_cast<const T*>(this)->getNumProtocolsImpl();
6658 }
6659
6660 /// Fetch a protocol by index.
6661 ObjCProtocolDecl *getProtocol(unsigned I) const {
6662 assert(I < getNumProtocols() && "Out-of-range protocol access");
6663 return qual_begin()[I];
6664 }
6665
6666 /// Retrieve all of the protocol qualifiers.
6668 return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
6669 }
6670};
6671
6672/// Represents a type parameter type in Objective C. It can take
6673/// a list of protocols.
6675 public ObjCProtocolQualifiers<ObjCTypeParamType>,
6676 public llvm::FoldingSetNode {
6677 friend class ASTContext;
6679
6680 /// The number of protocols stored on this type.
6681 unsigned NumProtocols : 6;
6682
6683 ObjCTypeParamDecl *OTPDecl;
6684
6685 /// The protocols are stored after the ObjCTypeParamType node. In the
6686 /// canonical type, the list of protocols are sorted alphabetically
6687 /// and uniqued.
6688 ObjCProtocolDecl **getProtocolStorageImpl();
6689
6690 /// Return the number of qualifying protocols in this interface type,
6691 /// or 0 if there are none.
6692 unsigned getNumProtocolsImpl() const {
6693 return NumProtocols;
6694 }
6695
6696 void setNumProtocolsImpl(unsigned N) {
6697 NumProtocols = N;
6698 }
6699
6700 ObjCTypeParamType(const ObjCTypeParamDecl *D,
6701 QualType can,
6702 ArrayRef<ObjCProtocolDecl *> protocols);
6703
6704public:
6705 bool isSugared() const { return true; }
6706 QualType desugar() const { return getCanonicalTypeInternal(); }
6707
6708 static bool classof(const Type *T) {
6709 return T->getTypeClass() == ObjCTypeParam;
6710 }
6711
6712 void Profile(llvm::FoldingSetNodeID &ID);
6713 static void Profile(llvm::FoldingSetNodeID &ID,
6714 const ObjCTypeParamDecl *OTPDecl,
6715 QualType CanonicalType,
6717
6718 ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
6719};
6720
6721/// Represents a class type in Objective C.
6722///
6723/// Every Objective C type is a combination of a base type, a set of
6724/// type arguments (optional, for parameterized classes) and a list of
6725/// protocols.
6726///
6727/// Given the following declarations:
6728/// \code
6729/// \@class C<T>;
6730/// \@protocol P;
6731/// \endcode
6732///
6733/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
6734/// with base C and no protocols.
6735///
6736/// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
6737/// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
6738/// protocol list.
6739/// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
6740/// and protocol list [P].
6741///
6742/// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
6743/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
6744/// and no protocols.
6745///
6746/// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
6747/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
6748/// this should get its own sugar class to better represent the source.
6749class ObjCObjectType : public Type,
6750 public ObjCProtocolQualifiers<ObjCObjectType> {
6752
6753 // ObjCObjectType.NumTypeArgs - the number of type arguments stored
6754 // after the ObjCObjectPointerType node.
6755 // ObjCObjectType.NumProtocols - the number of protocols stored
6756 // after the type arguments of ObjCObjectPointerType node.
6757 //
6758 // These protocols are those written directly on the type. If
6759 // protocol qualifiers ever become additive, the iterators will need
6760 // to get kindof complicated.
6761 //
6762 // In the canonical object type, these are sorted alphabetically
6763 // and uniqued.
6764
6765 /// Either a BuiltinType or an InterfaceType or sugar for either.
6766 QualType BaseType;
6767
6768 /// Cached superclass type.
6769 mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
6770 CachedSuperClassType;
6771
6772 QualType *getTypeArgStorage();
6773 const QualType *getTypeArgStorage() const {
6774 return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
6775 }
6776
6777 ObjCProtocolDecl **getProtocolStorageImpl();
6778 /// Return the number of qualifying protocols in this interface type,
6779 /// or 0 if there are none.
6780 unsigned getNumProtocolsImpl() const {
6781 return ObjCObjectTypeBits.NumProtocols;
6782 }
6783 void setNumProtocolsImpl(unsigned N) {
6784 ObjCObjectTypeBits.NumProtocols = N;
6785 }
6786
6787protected:
6789
6791 ArrayRef<QualType> typeArgs,
6793 bool isKindOf);
6794
6796 : Type(ObjCInterface, QualType(), TypeDependence::None),
6797 BaseType(QualType(this_(), 0)) {
6798 ObjCObjectTypeBits.NumProtocols = 0;
6799 ObjCObjectTypeBits.NumTypeArgs = 0;
6800 ObjCObjectTypeBits.IsKindOf = 0;
6801 }
6802
6803 void computeSuperClassTypeSlow() const;
6804
6805public:
6806 /// Gets the base type of this object type. This is always (possibly
6807 /// sugar for) one of:
6808 /// - the 'id' builtin type (as opposed to the 'id' type visible to the
6809 /// user, which is a typedef for an ObjCObjectPointerType)
6810 /// - the 'Class' builtin type (same caveat)
6811 /// - an ObjCObjectType (currently always an ObjCInterfaceType)
6812 QualType getBaseType() const { return BaseType; }
6813
6814 bool isObjCId() const {
6815 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
6816 }
6817
6818 bool isObjCClass() const {
6819 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
6820 }
6821
6822 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
6823 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
6825 if (!qual_empty()) return false;
6826 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
6827 return T->getKind() == BuiltinType::ObjCId ||
6828 T->getKind() == BuiltinType::ObjCClass;
6829 return false;
6830 }
6831 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
6832 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
6833
6834 /// Gets the interface declaration for this object type, if the base type
6835 /// really is an interface.
6836 ObjCInterfaceDecl *getInterface() const;
6837
6838 /// Determine whether this object type is "specialized", meaning
6839 /// that it has type arguments.
6840 bool isSpecialized() const;
6841
6842 /// Determine whether this object type was written with type arguments.
6844 return ObjCObjectTypeBits.NumTypeArgs > 0;
6845 }
6846
6847 /// Determine whether this object type is "unspecialized", meaning
6848 /// that it has no type arguments.
6849 bool isUnspecialized() const { return !isSpecialized(); }
6850
6851 /// Determine whether this object type is "unspecialized" as
6852 /// written, meaning that it has no type arguments.
6853 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
6854
6855 /// Retrieve the type arguments of this object type (semantically).
6856 ArrayRef<QualType> getTypeArgs() const;
6857
6858 /// Retrieve the type arguments of this object type as they were
6859 /// written.
6861 return llvm::ArrayRef(getTypeArgStorage(), ObjCObjectTypeBits.NumTypeArgs);
6862 }
6863
6864 /// Whether this is a "__kindof" type as written.
6865 bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
6866
6867 /// Whether this ia a "__kindof" type (semantically).
6868 bool isKindOfType() const;
6869
6870 /// Retrieve the type of the superclass of this object type.
6871 ///
6872 /// This operation substitutes any type arguments into the
6873 /// superclass of the current class type, potentially producing a
6874 /// specialization of the superclass type. Produces a null type if
6875 /// there is no superclass.
6877 if (!CachedSuperClassType.getInt())
6878 computeSuperClassTypeSlow();
6879
6880 assert(CachedSuperClassType.getInt() && "Superclass not set?");
6881 return QualType(CachedSuperClassType.getPointer(), 0);
6882 }
6883
6884 /// Strip off the Objective-C "kindof" type and (with it) any
6885 /// protocol qualifiers.
6886 QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
6887
6888 bool isSugared() const { return false; }
6889 QualType desugar() const { return QualType(this, 0); }
6890
6891 static bool classof(const Type *T) {
6892 return T->getTypeClass() == ObjCObject ||
6893 T->getTypeClass() == ObjCInterface;
6894 }
6895};
6896
6897/// A class providing a concrete implementation
6898/// of ObjCObjectType, so as to not increase the footprint of
6899/// ObjCInterfaceType. Code outside of ASTContext and the core type
6900/// system should not reference this type.
6901class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
6902 friend class ASTContext;
6903
6904 // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
6905 // will need to be modified.
6906
6908 ArrayRef<QualType> typeArgs,
6910 bool isKindOf)
6911 : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
6912
6913public:
6914 void Profile(llvm::FoldingSetNodeID &ID);
6915 static void Profile(llvm::FoldingSetNodeID &ID,
6916 QualType Base,
6917 ArrayRef<QualType> typeArgs,
6919 bool isKindOf);
6920};
6921
6922inline QualType *ObjCObjectType::getTypeArgStorage() {
6923 return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
6924}
6925
6926inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
6927 return reinterpret_cast<ObjCProtocolDecl**>(
6928 getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
6929}
6930
6931inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
6932 return reinterpret_cast<ObjCProtocolDecl**>(
6933 static_cast<ObjCTypeParamType*>(this)+1);
6934}
6935
6936/// Interfaces are the core concept in Objective-C for object oriented design.
6937/// They basically correspond to C++ classes. There are two kinds of interface
6938/// types: normal interfaces like `NSString`, and qualified interfaces, which
6939/// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
6940///
6941/// ObjCInterfaceType guarantees the following properties when considered
6942/// as a subtype of its superclass, ObjCObjectType:
6943/// - There are no protocol qualifiers. To reinforce this, code which
6944/// tries to invoke the protocol methods via an ObjCInterfaceType will
6945/// fail to compile.
6946/// - It is its own base type. That is, if T is an ObjCInterfaceType*,
6947/// T->getBaseType() == QualType(T, 0).
6949 friend class ASTContext; // ASTContext creates these.
6950 friend class ASTReader;
6951 template <class T> friend class serialization::AbstractTypeReader;
6952
6954
6957 Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
6958
6959public:
6960 /// Get the declaration of this interface.
6961 ObjCInterfaceDecl *getDecl() const;
6962
6963 bool isSugared() const { return false; }
6964 QualType desugar() const { return QualType(this, 0); }
6965
6966 static bool classof(const Type *T) {
6967 return T->getTypeClass() == ObjCInterface;
6968 }
6969
6970 // Nonsense to "hide" certain members of ObjCObjectType within this
6971 // class. People asking for protocols on an ObjCInterfaceType are
6972 // not going to get what they want: ObjCInterfaceTypes are
6973 // guaranteed to have no protocols.
6974 enum {
6979 getProtocol
6981};
6982
6983inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
6984 QualType baseType = getBaseType();
6985 while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) {
6986 if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT))
6987 return T->getDecl();
6988
6989 baseType = ObjT->getBaseType();
6990 }
6991
6992 return nullptr;
6993}
6994
6995/// Represents a pointer to an Objective C object.
6996///
6997/// These are constructed from pointer declarators when the pointee type is
6998/// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
6999/// types are typedefs for these, and the protocol-qualified types 'id<P>'
7000/// and 'Class<P>' are translated into these.
7001///
7002/// Pointers to pointers to Objective C objects are still PointerTypes;
7003/// only the first level of pointer gets it own type implementation.
7004class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
7005 friend class ASTContext; // ASTContext creates these.
7006
7007 QualType PointeeType;
7008
7009 ObjCObjectPointerType(QualType Canonical, QualType Pointee)
7010 : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()),
7011 PointeeType(Pointee) {}
7012
7013public:
7014 /// Gets the type pointed to by this ObjC pointer.
7015 /// The result will always be an ObjCObjectType or sugar thereof.
7016 QualType getPointeeType() const { return PointeeType; }
7017
7018 /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
7019 ///
7020 /// This method is equivalent to getPointeeType() except that
7021 /// it discards any typedefs (or other sugar) between this
7022 /// type and the "outermost" object type. So for:
7023 /// \code
7024 /// \@class A; \@protocol P; \@protocol Q;
7025 /// typedef A<P> AP;
7026 /// typedef A A1;
7027 /// typedef A1<P> A1P;
7028 /// typedef A1P<Q> A1PQ;
7029 /// \endcode
7030 /// For 'A*', getObjectType() will return 'A'.
7031 /// For 'A<P>*', getObjectType() will return 'A<P>'.
7032 /// For 'AP*', getObjectType() will return 'A<P>'.
7033 /// For 'A1*', getObjectType() will return 'A'.
7034 /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
7035 /// For 'A1P*', getObjectType() will return 'A1<P>'.
7036 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
7037 /// adding protocols to a protocol-qualified base discards the
7038 /// old qualifiers (for now). But if it didn't, getObjectType()
7039 /// would return 'A1P<Q>' (and we'd have to make iterating over
7040 /// qualifiers more complicated).
7042 return PointeeType->castAs<ObjCObjectType>();
7043 }
7044
7045 /// If this pointer points to an Objective C
7046 /// \@interface type, gets the type for that interface. Any protocol
7047 /// qualifiers on the interface are ignored.
7048 ///
7049 /// \return null if the base type for this pointer is 'id' or 'Class'
7050 const ObjCInterfaceType *getInterfaceType() const;
7051
7052 /// If this pointer points to an Objective \@interface
7053 /// type, gets the declaration for that interface.
7054 ///
7055 /// \return null if the base type for this pointer is 'id' or 'Class'
7057 return getObjectType()->getInterface();
7058 }
7059
7060 /// True if this is equivalent to the 'id' type, i.e. if
7061 /// its object type is the primitive 'id' type with no protocols.
7062 bool isObjCIdType() const {
7063 return getObjectType()->isObjCUnqualifiedId();
7064 }
7065
7066 /// True if this is equivalent to the 'Class' type,
7067 /// i.e. if its object tive is the primitive 'Class' type with no protocols.
7068 bool isObjCClassType() const {
7069 return getObjectType()->isObjCUnqualifiedClass();
7070 }
7071
7072 /// True if this is equivalent to the 'id' or 'Class' type,
7073 bool isObjCIdOrClassType() const {
7074 return getObjectType()->isObjCUnqualifiedIdOrClass();
7075 }
7076
7077 /// True if this is equivalent to 'id<P>' for some non-empty set of
7078 /// protocols.
7080 return getObjectType()->isObjCQualifiedId();
7081 }
7082
7083 /// True if this is equivalent to 'Class<P>' for some non-empty set of
7084 /// protocols.
7086 return getObjectType()->isObjCQualifiedClass();
7087 }
7088
7089 /// Whether this is a "__kindof" type.
7090 bool isKindOfType() const { return getObjectType()->isKindOfType(); }
7091
7092 /// Whether this type is specialized, meaning that it has type arguments.
7093 bool isSpecialized() const { return getObjectType()->isSpecialized(); }
7094
7095 /// Whether this type is specialized, meaning that it has type arguments.
7097 return getObjectType()->isSpecializedAsWritten();
7098 }
7099
7100 /// Whether this type is unspecialized, meaning that is has no type arguments.
7101 bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
7102
7103 /// Determine whether this object type is "unspecialized" as
7104 /// written, meaning that it has no type arguments.
7105 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
7106
7107 /// Retrieve the type arguments for this type.
7109 return getObjectType()->getTypeArgs();
7110 }
7111
7112 /// Retrieve the type arguments for this type.
7114 return getObjectType()->getTypeArgsAsWritten();
7115 }
7116
7117 /// An iterator over the qualifiers on the object type. Provided
7118 /// for convenience. This will always iterate over the full set of
7119 /// protocols on a type, not just those provided directly.
7121 using qual_range = llvm::iterator_range<qual_iterator>;
7122
7123 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
7124
7126 return getObjectType()->qual_begin();
7127 }
7128
7130 return getObjectType()->qual_end();
7131 }
7132
7133 bool qual_empty() const { return getObjectType()->qual_empty(); }
7134
7135 /// Return the number of qualifying protocols on the object type.
7136 unsigned getNumProtocols() const {
7137 return getObjectType()->getNumProtocols();
7138 }
7139
7140 /// Retrieve a qualifying protocol by index on the object type.
7141 ObjCProtocolDecl *getProtocol(unsigned I) const {
7142 return getObjectType()->getProtocol(I);
7143 }
7144
7145 bool isSugared() const { return false; }
7146 QualType desugar() const { return QualType(this, 0); }
7147
7148 /// Retrieve the type of the superclass of this object pointer type.
7149 ///
7150 /// This operation substitutes any type arguments into the
7151 /// superclass of the current class type, potentially producing a
7152 /// pointer to a specialization of the superclass type. Produces a
7153 /// null type if there is no superclass.
7154 QualType getSuperClassType() const;
7155
7156 /// Strip off the Objective-C "kindof" type and (with it) any
7157 /// protocol qualifiers.
7158 const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
7159 const ASTContext &ctx) const;
7160
7161 void Profile(llvm::FoldingSetNodeID &ID) {
7162 Profile(ID, getPointeeType());
7163 }
7164
7165 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7166 ID.AddPointer(T.getAsOpaquePtr());
7167 }
7168
7169 static bool classof(const Type *T) {
7170 return T->getTypeClass() == ObjCObjectPointer;
7171 }
7172};
7173
7174class AtomicType : public Type, public llvm::FoldingSetNode {
7175 friend class ASTContext; // ASTContext creates these.
7176
7177 QualType ValueType;
7178
7179 AtomicType(QualType ValTy, QualType Canonical)
7180 : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {}
7181
7182public:
7183 /// Gets the type contained by this atomic type, i.e.
7184 /// the type returned by performing an atomic load of this atomic type.
7185 QualType getValueType() const { return ValueType; }
7186
7187 bool isSugared() const { return false; }
7188 QualType desugar() const { return QualType(this, 0); }
7189
7190 void Profile(llvm::FoldingSetNodeID &ID) {
7191 Profile(ID, getValueType());
7192 }
7193
7194 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7195 ID.AddPointer(T.getAsOpaquePtr());
7196 }
7197
7198 static bool classof(const Type *T) {
7199 return T->getTypeClass() == Atomic;
7200 }
7201};
7202
7203/// PipeType - OpenCL20.
7204class PipeType : public Type, public llvm::FoldingSetNode {
7205 friend class ASTContext; // ASTContext creates these.
7206
7207 QualType ElementType;
7208 bool isRead;
7209
7210 PipeType(QualType elemType, QualType CanonicalPtr, bool isRead)
7211 : Type(Pipe, CanonicalPtr, elemType->getDependence()),
7212 ElementType(elemType), isRead(isRead) {}
7213
7214public:
7215 QualType getElementType() const { return ElementType; }
7216
7217 bool isSugared() const { return false; }
7218
7219 QualType desugar() const { return QualType(this, 0); }
7220
7221 void Profile(llvm::FoldingSetNodeID &ID) {
7222 Profile(ID, getElementType(), isReadOnly());
7223 }
7224
7225 static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) {
7226 ID.AddPointer(T.getAsOpaquePtr());
7227 ID.AddBoolean(isRead);
7228 }
7229
7230 static bool classof(const Type *T) {
7231 return T->getTypeClass() == Pipe;
7232 }
7233
7234 bool isReadOnly() const { return isRead; }
7235};
7236
7237/// A fixed int type of a specified bitwidth.
7238class BitIntType final : public Type, public llvm::FoldingSetNode {
7239 friend class ASTContext;
7240 LLVM_PREFERRED_TYPE(bool)
7241 unsigned IsUnsigned : 1;
7242 unsigned NumBits : 24;
7243
7244protected:
7245 BitIntType(bool isUnsigned, unsigned NumBits);
7246
7247public:
7248 bool isUnsigned() const { return IsUnsigned; }
7249 bool isSigned() const { return !IsUnsigned; }
7250 unsigned getNumBits() const { return NumBits; }
7251
7252 bool isSugared() const { return false; }
7253 QualType desugar() const { return QualType(this, 0); }
7254
7255 void Profile(llvm::FoldingSetNodeID &ID) const {
7256 Profile(ID, isUnsigned(), getNumBits());
7257 }
7258
7259 static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned,
7260 unsigned NumBits) {
7261 ID.AddBoolean(IsUnsigned);
7262 ID.AddInteger(NumBits);
7263 }
7264
7265 static bool classof(const Type *T) { return T->getTypeClass() == BitInt; }
7266};
7267
7268class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
7269 friend class ASTContext;
7270 llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
7271
7272protected:
7273 DependentBitIntType(bool IsUnsigned, Expr *NumBits);
7274
7275public:
7276 bool isUnsigned() const;
7277 bool isSigned() const { return !isUnsigned(); }
7278 Expr *getNumBitsExpr() const;
7279
7280 bool isSugared() const { return false; }
7281 QualType desugar() const { return QualType(this, 0); }
7282
7283 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
7284 Profile(ID, Context, isUnsigned(), getNumBitsExpr());
7285 }
7286 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
7287 bool IsUnsigned, Expr *NumBitsExpr);
7288
7289 static bool classof(const Type *T) {
7290 return T->getTypeClass() == DependentBitInt;
7291 }
7292};
7293
7294/// A qualifier set is used to build a set of qualifiers.
7296public:
7298
7299 /// Collect any qualifiers on the given type and return an
7300 /// unqualified type. The qualifiers are assumed to be consistent
7301 /// with those already in the type.
7302 const Type *strip(QualType type) {
7303 addFastQualifiers(type.getLocalFastQualifiers());
7304 if (!type.hasLocalNonFastQualifiers())
7305 return type.getTypePtrUnsafe();
7306
7307 const ExtQuals *extQuals = type.getExtQualsUnsafe();
7308 addConsistentQualifiers(extQuals->getQualifiers());
7309 return extQuals->getBaseType();
7310 }
7311
7312 /// Apply the collected qualifiers to the given type.
7313 QualType apply(const ASTContext &Context, QualType QT) const;
7314
7315 /// Apply the collected qualifiers to the given type.
7316 QualType apply(const ASTContext &Context, const Type* T) const;
7317};
7318
7319/// A container of type source information.
7320///
7321/// A client can read the relevant info using TypeLoc wrappers, e.g:
7322/// @code
7323/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
7324/// TL.getBeginLoc().print(OS, SrcMgr);
7325/// @endcode
7326class alignas(8) TypeSourceInfo {
7327 // Contains a memory block after the class, used for type source information,
7328 // allocated by ASTContext.
7329 friend class ASTContext;
7330
7331 QualType Ty;
7332
7333 TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
7334
7335public:
7336 /// Return the type wrapped by this type source info.
7337 QualType getType() const { return Ty; }
7338
7339 /// Return the TypeLoc wrapper for the type source info.
7340 TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
7341
7342 /// Override the type stored in this TypeSourceInfo. Use with caution!
7343 void overrideType(QualType T) { Ty = T; }
7344};
7345
7346// Inline function definitions.
7347
7348inline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
7349 SplitQualType desugar =
7350 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
7351 desugar.Quals.addConsistentQualifiers(Quals);
7352 return desugar;
7353}
7354
7355inline const Type *QualType::getTypePtr() const {
7356 return getCommonPtr()->BaseType;
7357}
7358
7359inline const Type *QualType::getTypePtrOrNull() const {
7360 return (isNull() ? nullptr : getCommonPtr()->BaseType);
7361}
7362
7363inline bool QualType::isReferenceable() const {
7364 // C++ [defns.referenceable]
7365 // type that is either an object type, a function type that does not have
7366 // cv-qualifiers or a ref-qualifier, or a reference type.
7367 const Type &Self = **this;
7368 if (Self.isObjectType() || Self.isReferenceType())
7369 return true;
7370 if (const auto *F = Self.getAs<FunctionProtoType>())
7371 return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
7372
7373 return false;
7374}
7375
7376inline SplitQualType QualType::split() const {
7377 if (!hasLocalNonFastQualifiers())
7378 return SplitQualType(getTypePtrUnsafe(),
7379 Qualifiers::fromFastMask(getLocalFastQualifiers()));
7380
7381 const ExtQuals *eq = getExtQualsUnsafe();
7382 Qualifiers qs = eq->getQualifiers();
7383 qs.addFastQualifiers(getLocalFastQualifiers());
7384 return SplitQualType(eq->getBaseType(), qs);
7385}
7386
7387inline Qualifiers QualType::getLocalQualifiers() const {
7388 Qualifiers Quals;
7389 if (hasLocalNonFastQualifiers())
7390 Quals = getExtQualsUnsafe()->getQualifiers();
7391 Quals.addFastQualifiers(getLocalFastQualifiers());
7392 return Quals;
7393}
7394
7395inline Qualifiers QualType::getQualifiers() const {
7396 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
7397 quals.addFastQualifiers(getLocalFastQualifiers());
7398 return quals;
7399}
7400
7401inline unsigned QualType::getCVRQualifiers() const {
7402 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
7403 cvr |= getLocalCVRQualifiers();
7404 return cvr;
7405}
7406
7407inline QualType QualType::getCanonicalType() const {
7408 QualType canon = getCommonPtr()->CanonicalType;
7409 return canon.withFastQualifiers(getLocalFastQualifiers());
7410}
7411
7412inline bool QualType::isCanonical() const {
7413 return getTypePtr()->isCanonicalUnqualified();
7414}
7415
7416inline bool QualType::isCanonicalAsParam() const {
7417 if (!isCanonical()) return false;
7418 if (hasLocalQualifiers()) return false;
7419
7420 const Type *T = getTypePtr();
7422 return false;
7423
7424 return !isa<FunctionType>(T) &&
7425 (!isa<ArrayType>(T) || isa<ArrayParameterType>(T));
7426}
7427
7428inline bool QualType::isConstQualified() const {
7429 return isLocalConstQualified() ||
7430 getCommonPtr()->CanonicalType.isLocalConstQualified();
7431}
7432
7433inline bool QualType::isRestrictQualified() const {
7434 return isLocalRestrictQualified() ||
7435 getCommonPtr()->CanonicalType.isLocalRestrictQualified();
7436}
7437
7438
7439inline bool QualType::isVolatileQualified() const {
7440 return isLocalVolatileQualified() ||
7441 getCommonPtr()->CanonicalType.isLocalVolatileQualified();
7442}
7443
7444inline bool QualType::hasQualifiers() const {
7445 return hasLocalQualifiers() ||
7446 getCommonPtr()->CanonicalType.hasLocalQualifiers();
7447}
7448
7449inline QualType QualType::getUnqualifiedType() const {
7450 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
7451 return QualType(getTypePtr(), 0);
7452
7453 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
7454}
7455
7456inline SplitQualType QualType::getSplitUnqualifiedType() const {
7457 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
7458 return split();
7459
7460 return getSplitUnqualifiedTypeImpl(*this);
7461}
7462
7463inline void QualType::removeLocalConst() {
7464 removeLocalFastQualifiers(Qualifiers::Const);
7465}
7466
7467inline void QualType::removeLocalRestrict() {
7468 removeLocalFastQualifiers(Qualifiers::Restrict);
7469}
7470
7471inline void QualType::removeLocalVolatile() {
7472 removeLocalFastQualifiers(Qualifiers::Volatile);
7473}
7474
7475/// Check if this type has any address space qualifier.
7476inline bool QualType::hasAddressSpace() const {
7477 return getQualifiers().hasAddressSpace();
7478}
7479
7480/// Return the address space of this type.
7481inline LangAS QualType::getAddressSpace() const {
7482 return getQualifiers().getAddressSpace();
7483}
7484
7485/// Return the gc attribute of this type.
7486inline Qualifiers::GC QualType::getObjCGCAttr() const {
7487 return getQualifiers().getObjCGCAttr();
7488}
7489
7490inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
7491 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7492 return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
7493 return false;
7494}
7495
7496inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const {
7497 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7498 return hasNonTrivialToPrimitiveDestructCUnion(RD);
7499 return false;
7500}
7501
7502inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const {
7503 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
7504 return hasNonTrivialToPrimitiveCopyCUnion(RD);
7505 return false;
7506}
7507
7509 if (const auto *PT = t.getAs<PointerType>()) {
7510 if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>())
7511 return FT->getExtInfo();
7512 } else if (const auto *FT = t.getAs<FunctionType>())
7513 return FT->getExtInfo();
7514
7515 return FunctionType::ExtInfo();
7516}
7517
7519 return getFunctionExtInfo(*t);
7520}
7521
7522/// Determine whether this type is more
7523/// qualified than the Other type. For example, "const volatile int"
7524/// is more qualified than "const int", "volatile int", and
7525/// "int". However, it is not more qualified than "const volatile
7526/// int".
7527inline bool QualType::isMoreQualifiedThan(QualType other) const {
7528 Qualifiers MyQuals = getQualifiers();
7529 Qualifiers OtherQuals = other.getQualifiers();
7530 return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals));
7531}
7532
7533/// Determine whether this type is at last
7534/// as qualified as the Other type. For example, "const volatile
7535/// int" is at least as qualified as "const int", "volatile int",
7536/// "int", and "const volatile int".
7537inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const {
7538 Qualifiers OtherQuals = other.getQualifiers();
7539
7540 // Ignore __unaligned qualifier if this type is a void.
7541 if (getUnqualifiedType()->isVoidType())
7542 OtherQuals.removeUnaligned();
7543
7544 return getQualifiers().compatiblyIncludes(OtherQuals);
7545}
7546
7547/// If Type is a reference type (e.g., const
7548/// int&), returns the type that the reference refers to ("const
7549/// int"). Otherwise, returns the type itself. This routine is used
7550/// throughout Sema to implement C++ 5p6:
7551///
7552/// If an expression initially has the type "reference to T" (8.3.2,
7553/// 8.5.3), the type is adjusted to "T" prior to any further
7554/// analysis, the expression designates the object or function
7555/// denoted by the reference, and the expression is an lvalue.
7556inline QualType QualType::getNonReferenceType() const {
7557 if (const auto *RefType = (*this)->getAs<ReferenceType>())
7558 return RefType->getPointeeType();
7559 else
7560 return *this;
7561}
7562
7563inline bool QualType::isCForbiddenLValueType() const {
7564 return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
7565 getTypePtr()->isFunctionType());
7566}
7567
7568/// Tests whether the type is categorized as a fundamental type.
7569///
7570/// \returns True for types specified in C++0x [basic.fundamental].
7571inline bool Type::isFundamentalType() const {
7572 return isVoidType() ||
7573 isNullPtrType() ||
7574 // FIXME: It's really annoying that we don't have an
7575 // 'isArithmeticType()' which agrees with the standard definition.
7576 (isArithmeticType() && !isEnumeralType());
7577}
7578
7579/// Tests whether the type is categorized as a compound type.
7580///
7581/// \returns True for types specified in C++0x [basic.compound].
7582inline bool Type::isCompoundType() const {
7583 // C++0x [basic.compound]p1:
7584 // Compound types can be constructed in the following ways:
7585 // -- arrays of objects of a given type [...];
7586 return isArrayType() ||
7587 // -- functions, which have parameters of given types [...];
7588 isFunctionType() ||
7589 // -- pointers to void or objects or functions [...];
7590 isPointerType() ||
7591 // -- references to objects or functions of a given type. [...]
7592 isReferenceType() ||
7593 // -- classes containing a sequence of objects of various types, [...];
7594 isRecordType() ||
7595 // -- unions, which are classes capable of containing objects of different
7596 // types at different times;
7597 isUnionType() ||
7598 // -- enumerations, which comprise a set of named constant values. [...];
7599 isEnumeralType() ||
7600 // -- pointers to non-static class members, [...].
7601 isMemberPointerType();
7602}
7603
7604inline bool Type::isFunctionType() const {
7605 return isa<FunctionType>(CanonicalType);
7606}
7607
7608inline bool Type::isPointerType() const {
7609 return isa<PointerType>(CanonicalType);
7610}
7611
7612inline bool Type::isAnyPointerType() const {
7613 return isPointerType() || isObjCObjectPointerType();
7614}
7615
7616inline bool Type::isBlockPointerType() const {
7617 return isa<BlockPointerType>(CanonicalType);
7618}
7619
7620inline bool Type::isReferenceType() const {
7621 return isa<ReferenceType>(CanonicalType);
7622}
7623
7624inline bool Type::isLValueReferenceType() const {
7625 return isa<LValueReferenceType>(CanonicalType);
7626}
7627
7628inline bool Type::isRValueReferenceType() const {
7629 return isa<RValueReferenceType>(CanonicalType);
7630}
7631
7632inline bool Type::isObjectPointerType() const {
7633 // Note: an "object pointer type" is not the same thing as a pointer to an
7634 // object type; rather, it is a pointer to an object type or a pointer to cv
7635 // void.
7636 if (const auto *T = getAs<PointerType>())
7637 return !T->getPointeeType()->isFunctionType();
7638 else
7639 return false;
7640}
7641
7642inline bool Type::isFunctionPointerType() const {
7643 if (const auto *T = getAs<PointerType>())
7644 return T->getPointeeType()->isFunctionType();
7645 else
7646 return false;
7647}
7648
7649inline bool Type::isFunctionReferenceType() const {
7650 if (const auto *T = getAs<ReferenceType>())
7651 return T->getPointeeType()->isFunctionType();
7652 else
7653 return false;
7654}
7655
7656inline bool Type::isMemberPointerType() const {
7657 return isa<MemberPointerType>(CanonicalType);
7658}
7659
7660inline bool Type::isMemberFunctionPointerType() const {
7661 if (const auto *T = getAs<MemberPointerType>())
7662 return T->isMemberFunctionPointer();
7663 else
7664 return false;
7665}
7666
7667inline bool Type::isMemberDataPointerType() const {
7668 if (const auto *T = getAs<MemberPointerType>())
7669 return T->isMemberDataPointer();
7670 else
7671 return false;
7672}
7673
7674inline bool Type::isArrayType() const {
7675 return isa<ArrayType>(CanonicalType);
7676}
7677
7678inline bool Type::isConstantArrayType() const {
7679 return isa<ConstantArrayType>(CanonicalType);
7680}
7681
7682inline bool Type::isIncompleteArrayType() const {
7683 return isa<IncompleteArrayType>(CanonicalType);
7684}
7685
7686inline bool Type::isVariableArrayType() const {
7687 return isa<VariableArrayType>(CanonicalType);
7688}
7689
7690inline bool Type::isArrayParameterType() const {
7691 return isa<ArrayParameterType>(CanonicalType);
7692}
7693
7694inline bool Type::isDependentSizedArrayType() const {
7695 return isa<DependentSizedArrayType>(CanonicalType);
7696}
7697
7698inline bool Type::isBuiltinType() const {
7699 return isa<BuiltinType>(CanonicalType);
7700}
7701
7702inline bool Type::isRecordType() const {
7703 return isa<RecordType>(CanonicalType);
7704}
7705
7706inline bool Type::isEnumeralType() const {
7707 return isa<EnumType>(CanonicalType);
7708}
7709
7710inline bool Type::isAnyComplexType() const {
7711 return isa<ComplexType>(CanonicalType);
7712}
7713
7714inline bool Type::isVectorType() const {
7715 return isa<VectorType>(CanonicalType);
7716}
7717
7718inline bool Type::isExtVectorType() const {
7719 return isa<ExtVectorType>(CanonicalType);
7720}
7721
7722inline bool Type::isExtVectorBoolType() const {
7723 if (!isExtVectorType())
7724 return false;
7725 return cast<ExtVectorType>(CanonicalType)->getElementType()->isBooleanType();
7726}
7727
7728inline bool Type::isMatrixType() const {
7729 return isa<MatrixType>(CanonicalType);
7730}
7731
7732inline bool Type::isConstantMatrixType() const {
7733 return isa<ConstantMatrixType>(CanonicalType);
7734}
7735
7736inline bool Type::isDependentAddressSpaceType() const {
7737 return isa<DependentAddressSpaceType>(CanonicalType);
7738}
7739
7740inline bool Type::isObjCObjectPointerType() const {
7741 return isa<ObjCObjectPointerType>(CanonicalType);
7742}
7743
7744inline bool Type::isObjCObjectType() const {
7745 return isa<ObjCObjectType>(CanonicalType);
7746}
7747
7748inline bool Type::isObjCObjectOrInterfaceType() const {
7749 return isa<ObjCInterfaceType>(CanonicalType) ||
7750 isa<ObjCObjectType>(CanonicalType);
7751}
7752
7753inline bool Type::isAtomicType() const {
7754 return isa<AtomicType>(CanonicalType);
7755}
7756
7757inline bool Type::isUndeducedAutoType() const {
7758 return isa<AutoType>(CanonicalType);
7759}
7760
7761inline bool Type::isObjCQualifiedIdType() const {
7762 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7763 return OPT->isObjCQualifiedIdType();
7764 return false;
7765}
7766
7767inline bool Type::isObjCQualifiedClassType() const {
7768 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7769 return OPT->isObjCQualifiedClassType();
7770 return false;
7771}
7772
7773inline bool Type::isObjCIdType() const {
7774 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7775 return OPT->isObjCIdType();
7776 return false;
7777}
7778
7779inline bool Type::isObjCClassType() const {
7780 if (const auto *OPT = getAs<ObjCObjectPointerType>())
7781 return OPT->isObjCClassType();
7782 return false;
7783}
7784
7785inline bool Type::isObjCSelType() const {
7786 if (const auto *OPT = getAs<PointerType>())
7787 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
7788 return false;
7789}
7790
7791inline bool Type::isObjCBuiltinType() const {
7792 return isObjCIdType() || isObjCClassType() || isObjCSelType();
7793}
7794
7795inline bool Type::isDecltypeType() const {
7796 return isa<DecltypeType>(this);
7797}
7798
7799#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
7800 inline bool Type::is##Id##Type() const { \
7801 return isSpecificBuiltinType(BuiltinType::Id); \
7802 }
7803#include "clang/Basic/OpenCLImageTypes.def"
7804
7805inline bool Type::isSamplerT() const {
7806 return isSpecificBuiltinType(BuiltinType::OCLSampler);
7807}
7808
7809inline bool Type::isEventT() const {
7810 return isSpecificBuiltinType(BuiltinType::OCLEvent);
7811}
7812
7813inline bool Type::isClkEventT() const {
7814 return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
7815}
7816
7817inline bool Type::isQueueT() const {
7818 return isSpecificBuiltinType(BuiltinType::OCLQueue);
7819}
7820
7821inline bool Type::isReserveIDT() const {
7822 return isSpecificBuiltinType(BuiltinType::OCLReserveID);
7823}
7824
7825inline bool Type::isImageType() const {
7826#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
7827 return
7828#include "clang/Basic/OpenCLImageTypes.def"
7829 false; // end boolean or operation
7830}
7831
7832inline bool Type::isPipeType() const {
7833 return isa<PipeType>(CanonicalType);
7834}
7835
7836inline bool Type::isBitIntType() const {
7837 return isa<BitIntType>(CanonicalType);
7838}
7839
7840#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
7841 inline bool Type::is##Id##Type() const { \
7842 return isSpecificBuiltinType(BuiltinType::Id); \
7843 }
7844#include "clang/Basic/OpenCLExtensionTypes.def"
7845
7846inline bool Type::isOCLIntelSubgroupAVCType() const {
7847#define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \
7848 isOCLIntelSubgroupAVC##Id##Type() ||
7849 return
7850#include "clang/Basic/OpenCLExtensionTypes.def"
7851 false; // end of boolean or operation
7852}
7853
7854inline bool Type::isOCLExtOpaqueType() const {
7855#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() ||
7856 return
7857#include "clang/Basic/OpenCLExtensionTypes.def"
7858 false; // end of boolean or operation
7859}
7860
7861inline bool Type::isOpenCLSpecificType() const {
7862 return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
7863 isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
7864}
7865
7866inline bool Type::isTemplateTypeParmType() const {
7867 return isa<TemplateTypeParmType>(CanonicalType);
7868}
7869
7870inline bool Type::isSpecificBuiltinType(unsigned K) const {
7871 if (const BuiltinType *BT = getAs<BuiltinType>()) {
7872 return BT->getKind() == static_cast<BuiltinType::Kind>(K);
7873 }
7874 return false;
7875}
7876
7877inline bool Type::isPlaceholderType() const {
7878 if (const auto *BT = dyn_cast<BuiltinType>(this))
7879 return BT->isPlaceholderType();
7880 return false;
7881}
7882
7883inline const BuiltinType *Type::getAsPlaceholderType() const {
7884 if (const auto *BT = dyn_cast<BuiltinType>(this))
7885 if (BT->isPlaceholderType())
7886 return BT;
7887 return nullptr;
7888}
7889
7890inline bool Type::isSpecificPlaceholderType(unsigned K) const {
7891 assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
7892 return isSpecificBuiltinType(K);
7893}
7894
7895inline bool Type::isNonOverloadPlaceholderType() const {
7896 if (const auto *BT = dyn_cast<BuiltinType>(this))
7897 return BT->isNonOverloadPlaceholderType();
7898 return false;
7899}
7900
7901inline bool Type::isVoidType() const {
7902 return isSpecificBuiltinType(BuiltinType::Void);
7903}
7904
7905inline bool Type::isHalfType() const {
7906 // FIXME: Should we allow complex __fp16? Probably not.
7907 return isSpecificBuiltinType(BuiltinType::Half);
7908}
7909
7910inline bool Type::isFloat16Type() const {
7911 return isSpecificBuiltinType(BuiltinType::Float16);
7912}
7913
7914inline bool Type::isFloat32Type() const {
7915 return isSpecificBuiltinType(BuiltinType::Float);
7916}
7917
7918inline bool Type::isDoubleType() const {
7919 return isSpecificBuiltinType(BuiltinType::Double);
7920}
7921
7922inline bool Type::isBFloat16Type() const {
7923 return isSpecificBuiltinType(BuiltinType::BFloat16);
7924}
7925
7926inline bool Type::isFloat128Type() const {
7927 return isSpecificBuiltinType(BuiltinType::Float128);
7928}
7929
7930inline bool Type::isIbm128Type() const {
7931 return isSpecificBuiltinType(BuiltinType::Ibm128);
7932}
7933
7934inline bool Type::isNullPtrType() const {
7935 return isSpecificBuiltinType(BuiltinType::NullPtr);
7936}
7937
7940
7941inline bool Type::isIntegerType() const {
7942 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
7943 return BT->getKind() >= BuiltinType::Bool &&
7944 BT->getKind() <= BuiltinType::Int128;
7945 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
7946 // Incomplete enum types are not treated as integer types.
7947 // FIXME: In C++, enum types are never integer types.
7948 return IsEnumDeclComplete(ET->getDecl()) &&
7949 !IsEnumDeclScoped(ET->getDecl());
7950 }
7951 return isBitIntType();
7952}
7953
7954inline bool Type::isFixedPointType() const {
7955 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7956 return BT->getKind() >= BuiltinType::ShortAccum &&
7957 BT->getKind() <= BuiltinType::SatULongFract;
7958 }
7959 return false;
7960}
7961
7962inline bool Type::isFixedPointOrIntegerType() const {
7963 return isFixedPointType() || isIntegerType();
7964}
7965
7966inline bool Type::isConvertibleToFixedPointType() const {
7967 return isRealFloatingType() || isFixedPointOrIntegerType();
7968}
7969
7970inline bool Type::isSaturatedFixedPointType() const {
7971 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7972 return BT->getKind() >= BuiltinType::SatShortAccum &&
7973 BT->getKind() <= BuiltinType::SatULongFract;
7974 }
7975 return false;
7976}
7977
7978inline bool Type::isUnsaturatedFixedPointType() const {
7979 return isFixedPointType() && !isSaturatedFixedPointType();
7980}
7981
7982inline bool Type::isSignedFixedPointType() const {
7983 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
7984 return ((BT->getKind() >= BuiltinType::ShortAccum &&
7985 BT->getKind() <= BuiltinType::LongAccum) ||
7986 (BT->getKind() >= BuiltinType::ShortFract &&
7987 BT->getKind() <= BuiltinType::LongFract) ||
7988 (BT->getKind() >= BuiltinType::SatShortAccum &&
7989 BT->getKind() <= BuiltinType::SatLongAccum) ||
7990 (BT->getKind() >= BuiltinType::SatShortFract &&
7991 BT->getKind() <= BuiltinType::SatLongFract));
7992 }
7993 return false;
7994}
7995
7996inline bool Type::isUnsignedFixedPointType() const {
7997 return isFixedPointType() && !isSignedFixedPointType();
7998}
7999
8000inline bool Type::isScalarType() const {
8001 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8002 return BT->getKind() > BuiltinType::Void &&
8003 BT->getKind() <= BuiltinType::NullPtr;
8004 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
8005 // Enums are scalar types, but only if they are defined. Incomplete enums
8006 // are not treated as scalar types.
8007 return IsEnumDeclComplete(ET->getDecl());
8008 return isa<PointerType>(CanonicalType) ||
8009 isa<BlockPointerType>(CanonicalType) ||
8010 isa<MemberPointerType>(CanonicalType) ||
8011 isa<ComplexType>(CanonicalType) ||
8012 isa<ObjCObjectPointerType>(CanonicalType) ||
8013 isBitIntType();
8014}
8015
8016inline bool Type::isIntegralOrEnumerationType() const {
8017 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8018 return BT->getKind() >= BuiltinType::Bool &&
8019 BT->getKind() <= BuiltinType::Int128;
8020
8021 // Check for a complete enum type; incomplete enum types are not properly an
8022 // enumeration type in the sense required here.
8023 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
8024 return IsEnumDeclComplete(ET->getDecl());
8025
8026 return isBitIntType();
8027}
8028
8029inline bool Type::isBooleanType() const {
8030 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8031 return BT->getKind() == BuiltinType::Bool;
8032 return false;
8033}
8034
8035inline bool Type::isUndeducedType() const {
8036 auto *DT = getContainedDeducedType();
8037 return DT && !DT->isDeduced();
8038}
8039
8040/// Determines whether this is a type for which one can define
8041/// an overloaded operator.
8042inline bool Type::isOverloadableType() const {
8043 return isDependentType() || isRecordType() || isEnumeralType();
8044}
8045
8046/// Determines whether this type is written as a typedef-name.
8047inline bool Type::isTypedefNameType() const {
8048 if (getAs<TypedefType>())
8049 return true;
8050 if (auto *TST = getAs<TemplateSpecializationType>())
8051 return TST->isTypeAlias();
8052 return false;
8053}
8054
8055/// Determines whether this type can decay to a pointer type.
8056inline bool Type::canDecayToPointerType() const {
8057 return isFunctionType() || (isArrayType() && !isArrayParameterType());
8058}
8059
8060inline bool Type::hasPointerRepresentation() const {
8061 return (isPointerType() || isReferenceType() || isBlockPointerType() ||
8062 isObjCObjectPointerType() || isNullPtrType());
8063}
8064
8065inline bool Type::hasObjCPointerRepresentation() const {
8066 return isObjCObjectPointerType();
8067}
8068
8069inline const Type *Type::getBaseElementTypeUnsafe() const {
8070 const Type *type = this;
8071 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
8072 type = arrayType->getElementType().getTypePtr();
8073 return type;
8074}
8075
8076inline const Type *Type::getPointeeOrArrayElementType() const {
8077 const Type *type = this;
8078 if (type->isAnyPointerType())
8079 return type->getPointeeType().getTypePtr();
8080 else if (type->isArrayType())
8081 return type->getBaseElementTypeUnsafe();
8082 return type;
8083}
8084/// Insertion operator for partial diagnostics. This allows sending adress
8085/// spaces into a diagnostic with <<.
8086inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8087 LangAS AS) {
8088 PD.AddTaggedVal(llvm::to_underlying(AS),
8089 DiagnosticsEngine::ArgumentKind::ak_addrspace);
8090 return PD;
8091}
8092
8093/// Insertion operator for partial diagnostics. This allows sending Qualifiers
8094/// into a diagnostic with <<.
8095inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8096 Qualifiers Q) {
8098 DiagnosticsEngine::ArgumentKind::ak_qual);
8099 return PD;
8100}
8101
8102/// Insertion operator for partial diagnostics. This allows sending QualType's
8103/// into a diagnostic with <<.
8104inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8105 QualType T) {
8106 PD.AddTaggedVal(reinterpret_cast<uint64_t>(T.getAsOpaquePtr()),
8107 DiagnosticsEngine::ak_qualtype);
8108 return PD;
8109}
8110
8111// Helper class template that is used by Type::getAs to ensure that one does
8112// not try to look through a qualified type to get to an array type.
8113template <typename T>
8115 std::integral_constant<bool, std::is_same<T, ArrayType>::value ||
8116 std::is_base_of<ArrayType, T>::value>;
8117
8118// Member-template getAs<specific type>'.
8119template <typename T> const T *Type::getAs() const {
8120 static_assert(!TypeIsArrayType<T>::value,
8121 "ArrayType cannot be used with getAs!");
8122
8123 // If this is directly a T type, return it.
8124 if (const auto *Ty = dyn_cast<T>(this))
8125 return Ty;
8126
8127 // If the canonical form of this type isn't the right kind, reject it.
8128 if (!isa<T>(CanonicalType))
8129 return nullptr;
8130
8131 // If this is a typedef for the type, strip the typedef off without
8132 // losing all typedef information.
8133 return cast<T>(getUnqualifiedDesugaredType());
8134}
8135
8136template <typename T> const T *Type::getAsAdjusted() const {
8137 static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
8138
8139 // If this is directly a T type, return it.
8140 if (const auto *Ty = dyn_cast<T>(this))
8141 return Ty;
8142
8143 // If the canonical form of this type isn't the right kind, reject it.
8144 if (!isa<T>(CanonicalType))
8145 return nullptr;
8146
8147 // Strip off type adjustments that do not modify the underlying nature of the
8148 // type.
8149 const Type *Ty = this;
8150 while (Ty) {
8151 if (const auto *A = dyn_cast<AttributedType>(Ty))
8152 Ty = A->getModifiedType().getTypePtr();
8153 else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
8154 Ty = A->getWrappedType().getTypePtr();
8155 else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
8156 Ty = E->desugar().getTypePtr();
8157 else if (const auto *P = dyn_cast<ParenType>(Ty))
8158 Ty = P->desugar().getTypePtr();
8159 else if (const auto *A = dyn_cast<AdjustedType>(Ty))
8160 Ty = A->desugar().getTypePtr();
8161 else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))
8162 Ty = M->desugar().getTypePtr();
8163 else
8164 break;
8165 }
8166
8167 // Just because the canonical type is correct does not mean we can use cast<>,
8168 // since we may not have stripped off all the sugar down to the base type.
8169 return dyn_cast<T>(Ty);
8170}
8171
8172inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
8173 // If this is directly an array type, return it.
8174 if (const auto *arr = dyn_cast<ArrayType>(this))
8175 return arr;
8176
8177 // If the canonical form of this type isn't the right kind, reject it.
8178 if (!isa<ArrayType>(CanonicalType))
8179 return nullptr;
8180
8181 // If this is a typedef for the type, strip the typedef off without
8182 // losing all typedef information.
8183 return cast<ArrayType>(getUnqualifiedDesugaredType());
8184}
8185
8186template <typename T> const T *Type::castAs() const {
8187 static_assert(!TypeIsArrayType<T>::value,
8188 "ArrayType cannot be used with castAs!");
8189
8190 if (const auto *ty = dyn_cast<T>(this)) return ty;
8191 assert(isa<T>(CanonicalType));
8192 return cast<T>(getUnqualifiedDesugaredType());
8193}
8194
8195inline const ArrayType *Type::castAsArrayTypeUnsafe() const {
8196 assert(isa<ArrayType>(CanonicalType));
8197 if (const auto *arr = dyn_cast<ArrayType>(this)) return arr;
8198 return cast<ArrayType>(getUnqualifiedDesugaredType());
8199}
8200
8201DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
8202 QualType CanonicalPtr)
8203 : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
8204#ifndef NDEBUG
8205 QualType Adjusted = getAdjustedType();
8207 assert(isa<PointerType>(Adjusted));
8208#endif
8209}
8210
8212 QualType Decayed = getDecayedType();
8214 return cast<PointerType>(Decayed)->getPointeeType();
8215}
8216
8217// Get the decimal string representation of a fixed point type, represented
8218// as a scaled integer.
8219// TODO: At some point, we should change the arguments to instead just accept an
8220// APFixedPoint instead of APSInt and scale.
8221void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
8222 unsigned Scale);
8223
8224} // namespace clang
8225
8226#endif // LLVM_CLANG_AST_TYPE_H
#define V(N, I)
Definition: ASTContext.h:3284
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:82
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:1109
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)
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:4102
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:86
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3294
static bool classof(const Type *T)
Definition: Type.h:3322
static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New)
Definition: Type.h:3317
AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, QualType CanonicalPtr)
Definition: Type.h:3301
QualType desugar() const
Definition: Type.h:3311
QualType getAdjustedType() const
Definition: Type.h:3308
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3313
bool isSugared() const
Definition: Type.h:3310
QualType getOriginalType() const
Definition: Type.h:3307
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3684
static bool classof(const Type *T)
Definition: Type.h:3691
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3514
ArraySizeModifier getSizeModifier() const
Definition: Type.h:3528
Qualifiers getIndexTypeQualifiers() const
Definition: Type.h:3532
static bool classof(const Type *T)
Definition: Type.h:3540
QualType getElementType() const
Definition: Type.h:3526
unsigned getIndexTypeCVRQualifiers() const
Definition: Type.h:3536
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:7194
bool isSugared() const
Definition: Type.h:7187
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:7185
QualType desugar() const
Definition: Type.h:7188
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7190
static bool classof(const Type *T)
Definition: Type.h:7198
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5600
QualType getModifiedType() const
Definition: Type.h:5622
static bool classof(const Type *T)
Definition: Type.h:5694
static Kind getNullabilityAttrKind(NullabilityKind kind)
Retrieve the attribute kind corresponding to the given nullability kind.
Definition: Type.h:5655
bool isSugared() const
Definition: Type.h:5625
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:4777
static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, QualType modified, QualType equivalent)
Definition: Type.h:5687
QualType desugar() const
Definition: Type.h:5626
QualType getEquivalentType() const
Definition: Type.h:5623
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5683
Kind getAttrKind() const
Definition: Type.h:5618
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5977
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5987
static bool classof(const Type *T)
Definition: Type.h:6018
bool isDecltypeAuto() const
Definition: Type.h:6000
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5992
AutoTypeKeyword getKeyword() const
Definition: Type.h:6008
bool isGNUAutoType() const
Definition: Type.h:6004
bool isConstrained() const
Definition: Type.h:5996
static bool classof(const Type *T)
Definition: Type.h:5728
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:5713
QualType getWrappedType() const
Definition: Type.h:5712
QualType desugar() const
Definition: Type.h:5716
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5718
static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped, const BTFTypeTagAttr *BTFAttr)
Definition: Type.h:5722
bool isSugared() const
Definition: Type.h:5715
A fixed int type of a specified bitwidth.
Definition: Type.h:7238
bool isSigned() const
Definition: Type.h:7249
static bool classof(const Type *T)
Definition: Type.h:7265
static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned, unsigned NumBits)
Definition: Type.h:7259
bool isSugared() const
Definition: Type.h:7252
bool isUnsigned() const
Definition: Type.h:7248
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:7255
unsigned getNumBits() const
Definition: Type.h:7250
QualType desugar() const
Definition: Type.h:7253
Pointer to a block type.
Definition: Type.h:3345
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3362
QualType getPointeeType() const
Definition: Type.h:3357
static bool classof(const Type *T)
Definition: Type.h:3370
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:3366
QualType desugar() const
Definition: Type.h:3360
bool isSugared() const
Definition: Type.h:3359
[BoundsSafety] Represents a parent type class for CountAttributedType and similar sugar types that wi...
Definition: Type.h:3195
decl_iterator dependent_decl_begin() const
Definition: Type.h:3210
bool isSugared() const
Definition: Type.h:3204
decl_iterator dependent_decl_end() const
Definition: Type.h:3211
unsigned getNumCoupledDecls() const
Definition: Type.h:3213
decl_range dependent_decls() const
Definition: Type.h:3215
QualType desugar() const
Definition: Type.h:3205
ArrayRef< TypeCoupledDeclRefInfo > getCoupledDecls() const
Definition: Type.h:3219
llvm::iterator_range< decl_iterator > decl_range
Definition: Type.h:3208
static bool classof(const Type *T)
Definition: Type.h:3225
ArrayRef< TypeCoupledDeclRefInfo > Decls
Definition: Type.h:3199
This class is used for builtin types like 'int'.
Definition: Type.h:2977
bool isPlaceholderType() const
Determines whether this type is a placeholder type, i.e.
Definition: Type.h:3060
bool isSugared() const
Definition: Type.h:3029
bool isNonOverloadPlaceholderType() const
Determines whether this type is a placeholder type other than Overload.
Definition: Type.h:3073
bool isSVECount() const
Definition: Type.h:3050
bool isSVEBool() const
Definition: Type.h:3048
QualType desugar() const
Definition: Type.h:3030
bool isInteger() const
Definition: Type.h:3032
bool isFloatingPoint() const
Definition: Type.h:3044
static bool classof(const Type *T)
Definition: Type.h:3077
bool isSignedInteger() const
Definition: Type.h:3036
bool isUnsignedInteger() const
Definition: Type.h:3040
Kind getKind() const
Definition: Type.h:3019
static bool isPlaceholderTypeKind(Kind K)
Determines whether the given kind corresponds to a placeholder type.
Definition: Type.h:3053
const char * getNameAsCString(const PrintingPolicy &Policy) const
Definition: Type.h:3022
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Complex values, per C99 6.2.5p11.
Definition: Type.h:3082
bool isSugared() const
Definition: Type.h:3094
QualType getElementType() const
Definition: Type.h:3092
static void Profile(llvm::FoldingSetNodeID &ID, QualType Element)
Definition: Type.h:3101
static bool classof(const Type *T)
Definition: Type.h:3105
QualType desugar() const
Definition: Type.h:3095
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3097
Declaration of a C++20 concept.
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3552
unsigned getSizeBitWidth() const
Return the bit width of the size type.
Definition: Type.h:3615
ConstantArrayType(TypeClass Tc, const ConstantArrayType *ATy, QualType Can)
Definition: Type.h:3594
ExternalSize * SizePtr
Definition: Type.h:3564
QualType desugar() const
Definition: Type.h:3653
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:3641
bool isZeroSize() const
Return true if the size is zero.
Definition: Type.h:3622
int64_t getSExtSize() const
Return the size sign-extended as a uint64_t.
Definition: Type.h:3634
const Expr * getSizeExpr() const
Return a pointer to the size expression.
Definition: Type.h:3648
bool isSugared() const
Definition: Type.h:3652
static bool classof(const Type *T)
Definition: Type.h:3676
llvm::APInt getSize() const
Return the constant array size as an APInt.
Definition: Type.h:3608
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx)
Definition: Type.h:3667
uint64_t getZExtSize() const
Return the size zero-extended as a uint64_t.
Definition: Type.h:3628
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4163
unsigned getNumColumns() const
Returns the number of columns in the matrix.
Definition: Type.h:4184
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumRows, unsigned NumColumns, TypeClass TypeClass)
Definition: Type.h:4206
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4201
static constexpr unsigned getMaxElementsPerDimension()
Returns the maximum number of elements per dimension.
Definition: Type.h:4197
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition: Type.h:4181
unsigned getNumElementsFlattened() const
Returns the number of elements required to embed the matrix into a vector.
Definition: Type.h:4187
static constexpr bool isDimensionValid(size_t NumElements)
Returns true if NumElements is a valid matrix dimension.
Definition: Type.h:4192
unsigned NumRows
Number of rows and columns.
Definition: Type.h:4168
static bool classof(const Type *T)
Definition: Type.h:4215
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3243
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3279
static bool classof(const Type *T)
Definition: Type.h:3286
bool isOrNull() const
Definition: Type.h:3271
bool isCountInBytes() const
Definition: Type.h:3270
Expr * getCountExpr() const
Definition: Type.h:3269
DynamicCountPointerKind getKind() const
Definition: Type.h:3273
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3328
QualType getPointeeType() const
Definition: Type.h:8211
static bool classof(const Type *T)
Definition: Type.h:3339
QualType getDecayedType() const
Definition: Type.h:3335
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:5354
static bool classof(const Type *T)
Definition: Type.h:5373
Expr * getUnderlyingExpr() const
Definition: Type.h:5364
QualType getUnderlyingType() const
Definition: Type.h:5365
Represents a C++17 deduced template specialization type.
Definition: Type.h:6025
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:6045
static bool classof(const Type *T)
Definition: Type.h:6060
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6047
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, QualType Deduced, bool IsDependent)
Definition: Type.h:6051
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:5943
static bool classof(const Type *T)
Definition: Type.h:5969
bool isSugared() const
Definition: Type.h:5957
QualType desugar() const
Definition: Type.h:5958
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5964
DeducedType(TypeClass TC, QualType DeducedAsType, TypeDependence ExtraDependence, QualType Canon)
Definition: Type.h:5947
bool isDeduced() const
Definition: Type.h:5965
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3855
QualType desugar() const
Definition: Type.h:3871
Expr * getAddrSpaceExpr() const
Definition: Type.h:3866
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3877
QualType getPointeeType() const
Definition: Type.h:3867
static bool classof(const Type *T)
Definition: Type.h:3873
SourceLocation getAttributeLoc() const
Definition: Type.h:3868
QualType desugar() const
Definition: Type.h:7281
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:7283
bool isSigned() const
Definition: Type.h:7277
bool isSugared() const
Definition: Type.h:7280
static bool classof(const Type *T)
Definition: Type.h:7289
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:5382
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5386
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6448
bool isSugared() const
Definition: Type.h:6477
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6466
static bool classof(const Type *T)
Definition: Type.h:6491
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:6473
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6480
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name)
Definition: Type.h:6484
QualType desugar() const
Definition: Type.h:6478
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3797
QualType desugar() const
Definition: Type.h:3828
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3834
static bool classof(const Type *T)
Definition: Type.h:3830
SourceRange getBracketsRange() const
Definition: Type.h:3823
Expr * getSizeExpr() const
Definition: Type.h:3817
SourceLocation getLBracketLoc() const
Definition: Type.h:3824
SourceLocation getRBracketLoc() const
Definition: Type.h:3825
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3895
QualType desugar() const
Definition: Type.h:3914
static bool classof(const Type *T)
Definition: Type.h:3916
SourceLocation getAttributeLoc() const
Definition: Type.h:3911
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:3920
QualType getElementType() const
Definition: Type.h:3910
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4222
Expr * getColumnExpr() const
Definition: Type.h:4235
Expr * getRowExpr() const
Definition: Type.h:4234
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4242
SourceLocation getAttributeLoc() const
Definition: Type.h:4236
static bool classof(const Type *T)
Definition: Type.h:4238
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6500
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6517
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:6527
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6519
NestedNameSpecifier * getQualifier() const
Definition: Type.h:6516
static bool classof(const Type *T)
Definition: Type.h:6538
Internal representation of canonical, dependent typeof(expr) types.
Definition: Type.h:5303
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5307
DependentTypeOfExprType(Expr *E, TypeOfKind Kind)
Definition: Type.h:5305
Internal representation of canonical, dependent __underlying_type(type) types.
Definition: Type.h:5505
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5510
static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, UTTKind UKind)
Definition: Type.h:5514
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4017
Expr * getSizeExpr() const
Definition: Type.h:4028
VectorKind getVectorKind() const
Definition: Type.h:4031
SourceLocation getAttributeLoc() const
Definition: Type.h:4030
bool isSugared() const
Definition: Type.h:4035
QualType getElementType() const
Definition: Type.h:4029
QualType desugar() const
Definition: Type.h:4036
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:4042
static bool classof(const Type *T)
Definition: Type.h:4038
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6367
static bool classof(const Type *T)
Definition: Type.h:6433
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:6415
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:6408
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6402
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl)
Definition: Type.h:6424
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:6411
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6420
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:6405
Represents an enum.
Definition: Decl.h:3868
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5571
EnumDecl * getDecl() const
Definition: Type.h:5578
bool isSugared() const
Definition: Type.h:5582
static bool classof(const Type *T)
Definition: Type.h:5585
QualType desugar() const
Definition: Type.h:5583
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:4057
bool isSugared() const
Definition: Type.h:4116
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition: Type.h:4110
static int getNumericAccessorIdx(char c)
Definition: Type.h:4075
static bool classof(const Type *T)
Definition: Type.h:4119
static int getPointAccessorIdx(char c)
Definition: Type.h:4065
QualType desugar() const
Definition: Type.h:4117
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition: Type.h:4103
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:4607
bool isSugared() const
Definition: Type.h:4620
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition: Type.h:4627
QualType desugar() const
Definition: Type.h:4621
static bool classof(const Type *T)
Definition: Type.h:4633
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4623
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4652
QualType desugar() const
Definition: Type.h:5119
param_type_iterator param_type_begin() const
Definition: Type.h:5044
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:5097
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:4911
bool isParamConsumed(unsigned I) const
Definition: Type.h:5111
exception_iterator exception_end() const
Definition: Type.h:5063
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5082
unsigned getNumParams() const
Definition: Type.h:4885
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5024
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
Definition: Type.h:4937
Qualifiers getMethodQuals() const
Definition: Type.h:5026
static bool classof(const Type *T)
Definition: Type.h:5124
QualType getParamType(unsigned i) const
Definition: Type.h:4887
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition: Type.h:5090
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:4962
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:5010
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:4954
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:4917
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:4920
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition: Type.h:4925
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5008
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4896
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:4969
param_type_iterator param_type_end() const
Definition: Type.h:5048
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:4990
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.h:5003
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4892
ArrayRef< QualType > exceptions() const
Definition: Type.h:5054
ParameterABI getParameterABI(unsigned I) const
Definition: Type.h:5104
ArrayRef< QualType > param_types() const
Definition: Type.h:5040
bool isSugared() const
Definition: Type.h:5118
exception_iterator exception_begin() const
Definition: Type.h:5058
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition: Type.h:5073
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition: Type.h:5069
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:5034
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition: Type.h:4979
A class which abstracts out some details necessary for making a call.
Definition: Type.h:4363
ExtInfo withNoCfCheck(bool noCfCheck) const
Definition: Type.h:4465
ExtInfo withCallingConv(CallingConv cc) const
Definition: Type.h:4478
CallingConv getCC() const
Definition: Type.h:4425
ExtInfo withProducesResult(bool producesResult) const
Definition: Type.h:4444
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, bool producesResult, bool noCallerSavedRegs, bool NoCfCheck, bool cmseNSCall)
Definition: Type.h:4391
bool getCmseNSCall() const
Definition: Type.h:4413
bool getNoCfCheck() const
Definition: Type.h:4415
unsigned getRegParm() const
Definition: Type.h:4418
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:4482
bool getNoCallerSavedRegs() const
Definition: Type.h:4414
ExtInfo withNoReturn(bool noReturn) const
Definition: Type.h:4437
bool getHasRegParm() const
Definition: Type.h:4416
bool getNoReturn() const
Definition: Type.h:4411
bool operator==(ExtInfo Other) const
Definition: Type.h:4427
bool getProducesResult() const
Definition: Type.h:4412
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
Definition: Type.h:4458
ExtInfo withCmseNSCall(bool cmseNSCall) const
Definition: Type.h:4451
ExtInfo(CallingConv CC)
Definition: Type.h:4409
ExtInfo withRegParm(unsigned RegParm) const
Definition: Type.h:4472
bool operator!=(ExtInfo Other) const
Definition: Type.h:4430
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4278
friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:4334
friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition: Type.h:4338
ExtParameterInfo withHasPassObjectSize() const
Definition: Type.h:4311
unsigned char getOpaqueValue() const
Definition: Type.h:4327
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC? Consumed parameters must have retainable ...
Definition: Type.h:4300
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition: Type.h:4291
ExtParameterInfo withIsConsumed(bool consumed) const
Definition: Type.h:4301
ExtParameterInfo withIsNoEscape(bool NoEscape) const
Definition: Type.h:4318
ExtParameterInfo withABI(ParameterABI kind) const
Definition: Type.h:4292
static ExtParameterInfo getFromOpaqueValue(unsigned char data)
Definition: Type.h:4328
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4252
ExtInfo getExtInfo() const
Definition: Type.h:4581
static ArmStateValue getArmZT0State(unsigned AttrBits)
Definition: Type.h:4539
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:4577
bool isConst() const
Definition: Type.h:4587
static ArmStateValue getArmZAState(unsigned AttrBits)
Definition: Type.h:4535
unsigned getRegParmType() const
Definition: Type.h:4572
CallingConv getCallConv() const
Definition: Type.h:4580
bool isRestrict() const
Definition: Type.h:4589
QualType getReturnType() const
Definition: Type.h:4569
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition: Type.h:4555
static bool classof(const Type *T)
Definition: Type.h:4599
bool getCmseNSCallAttr() const
Definition: Type.h:4579
bool getHasRegParm() const
Definition: Type.h:4571
Qualifiers getFastTypeQuals() const
Definition: Type.h:4561
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition: Type.h:4593
AArch64SMETypeAttributes
The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number of function type attributes that...
Definition: Type.h:4511
bool isVolatile() const
Definition: Type.h:4588
One of these records is kept for each identifier that is lexed.
Represents a C array with an unspecified size.
Definition: Type.h:3699
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3716
static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, ArraySizeModifier SizeMod, unsigned TypeQuals)
Definition: Type.h:3721
QualType desugar() const
Definition: Type.h:3710
bool isSugared() const
Definition: Type.h:3709
static bool classof(const Type *T)
Definition: Type.h:3712
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6217
QualType desugar() const
Definition: Type.h:6261
static bool classof(const Type *T)
Definition: Type.h:6263
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:6250
TemplateName getTemplateName() const
Definition: Type.h:6254
QualType getInjectedSpecializationType() const
Definition: Type.h:6248
bool isSugared() const
Definition: Type.h:6260
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3420
static bool classof(const Type *T)
Definition: Type.h:3432
QualType desugar() const
Definition: Type.h:3430
bool isSugared() const
Definition: Type.h:3429
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5238
bool isSugared() const
Definition: Type.h:5260
static bool classof(const Type *T)
Definition: Type.h:5263
QualType getUnderlyingType() const
Definition: Type.h:5254
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:5253
Represents a matrix type, as defined in the Matrix Types clang extensions.
Definition: Type.h:4127
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition: Type.h:4141
QualType desugar() const
Definition: Type.h:4154
MatrixType(QualType ElementTy, QualType CanonElementTy)
static bool isValidElementType(QualType T)
Valid elements types are the following:
Definition: Type.h:4148
QualType ElementType
The element type of the matrix.
Definition: Type.h:4132
bool isSugared() const
Definition: Type.h:4153
static bool classof(const Type *T)
Definition: Type.h:4156
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3456
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3492
QualType getPointeeType() const
Definition: Type.h:3472
bool isSugared() const
Definition: Type.h:3489
bool isMemberFunctionPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3476
bool isMemberDataPointer() const
Returns true if the member type (i.e.
Definition: Type.h:3482
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, const Type *Class)
Definition: Type.h:3496
QualType desugar() const
Definition: Type.h:3490
static bool classof(const Type *T)
Definition: Type.h:3502
const Type * getClass() const
Definition: Type.h:3486
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:6948
QualType desugar() const
Definition: Type.h:6964
bool isSugared() const
Definition: Type.h:6963
static bool classof(const Type *T)
Definition: Type.h:6966
Represents a pointer to an Objective C object.
Definition: Type.h:7004
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition: Type.h:7136
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7093
qual_iterator qual_end() const
Definition: Type.h:7129
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:7085
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:7165
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7079
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7096
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:7105
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition: Type.h:7113
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7161
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7041
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:7120
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:7121
static bool classof(const Type *T)
Definition: Type.h:7169
bool qual_empty() const
Definition: Type.h:7133
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition: Type.h:7101
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:7062
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition: Type.h:7141
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7016
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition: Type.h:7056
QualType desugar() const
Definition: Type.h:7146
qual_range quals() const
Definition: Type.h:7123
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:7068
bool isSugared() const
Definition: Type.h:7145
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7073
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition: Type.h:7108
qual_iterator qual_begin() const
Definition: Type.h:7125
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:7090
A class providing a concrete implementation of ObjCObjectType, so as to not increase the footprint of...
Definition: Type.h:6901
Represents a class type in Objective C.
Definition: Type.h:6750
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:6865
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:6860
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:6853
bool isObjCQualifiedClass() const
Definition: Type.h:6832
ObjCObjectType(enum Nonce_ObjCInterface)
Definition: Type.h:6795
bool isObjCUnqualifiedIdOrClass() const
Definition: Type.h:6824
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:6812
bool isObjCClass() const
Definition: Type.h:6818
QualType desugar() const
Definition: Type.h:6889
bool isObjCQualifiedId() const
Definition: Type.h:6831
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:6843
bool isObjCUnqualifiedId() const
Definition: Type.h:6822
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments.
Definition: Type.h:6849
bool isSugared() const
Definition: Type.h:6888
bool isObjCUnqualifiedClass() const
Definition: Type.h:6823
static bool classof(const Type *T)
Definition: Type.h:6891
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:6876
bool isObjCId() const
Definition: Type.h:6814
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
This class wraps the list of protocol qualifiers.
Definition: Type.h:6619
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:6646
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:6635
ObjCProtocolDecl ** getProtocolStorage()
Definition: Type.h:6627
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:6667
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:6656
void setNumProtocols(unsigned N)
Definition: Type.h:6631
qual_iterator qual_end() const
Definition: Type.h:6650
ObjCProtocolDecl *const * getProtocolStorage() const
Definition: Type.h:6623
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:6661
qual_iterator qual_begin() const
Definition: Type.h:6649
qual_range quals() const
Definition: Type.h:6648
bool qual_empty() const
Definition: Type.h:6652
ObjCProtocolDecl *const * qual_iterator
Definition: Type.h:6645
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Represents a type parameter type in Objective C.
Definition: Type.h:6676
static bool classof(const Type *T)
Definition: Type.h:6708
bool isSugared() const
Definition: Type.h:6705
QualType desugar() const
Definition: Type.h:6706
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:6718
Represents a pack expansion of types.
Definition: Type.h:6565
bool isSugared() const
Definition: Type.h:6596
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6599
static bool classof(const Type *T)
Definition: Type.h:6611
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, std::optional< unsigned > NumExpansions)
Definition: Type.h:6603
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:6586
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6590
QualType desugar() const
Definition: Type.h:6597
bool hasSelectedType() const
Definition: Type.h:5431
QualType getPattern() const
Definition: Type.h:5414
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5441
QualType getSelectedType() const
Definition: Type.h:5424
ArrayRef< QualType > getExpansions() const
Definition: Type.h:5433
QualType desugar() const
Definition: Type.h:5418
Expr * getIndexExpr() const
Definition: Type.h:5413
static bool classof(const Type *T)
Definition: Type.h:5437
bool isSugared() const
Definition: Type.h:5416
Sugar for parentheses used when specifying types.
Definition: Type.h:3109
QualType desugar() const
Definition: Type.h:3121
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3123
static bool classof(const Type *T)
Definition: Type.h:3131
static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner)
Definition: Type.h:3127
bool isSugared() const
Definition: Type.h:3120
QualType getInnerType() const
Definition: Type.h:3118
PipeType - OpenCL20.
Definition: Type.h:7204
QualType desugar() const
Definition: Type.h:7219
bool isSugared() const
Definition: Type.h:7217
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead)
Definition: Type.h:7225
QualType getElementType() const
Definition: Type.h:7215
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7221
static bool classof(const Type *T)
Definition: Type.h:7230
bool isReadOnly() const
Definition: Type.h:7234
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:3135
QualType getPointeeType() const
Definition: Type.h:3145
static bool classof(const Type *T)
Definition: Type.h:3158
QualType desugar() const
Definition: Type.h:3148
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3150
bool isSugared() const
Definition: Type.h:3147
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee)
Definition: Type.h:3154
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:7439
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition: Type.h:7433
bool isTriviallyCopyableType(const ASTContext &Context) const
Return true if this is a trivially copyable type (C++0x [basic.types]p9)
Definition: Type.cpp:2716
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:7486
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:7444
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:7502
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:2836
QualType getNonLValueExprType(const ASTContext &Context) const
Determine the type of a (typically non-lvalue) expression with the specified result type.
Definition: Type.cpp:3454
@ 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:2810
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:7537
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:2721
bool isTrivialType(const ASTContext &Context) const
Return true if this is a trivial type per (C++0x [basic.types]p9)
Definition: Type.cpp:2618
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:2858
bool isTriviallyRelocatableType(const ASTContext &Context) const
Return true if this is a trivially relocatable type.
Definition: Type.cpp:2727
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7355
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7481
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:7496
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7395
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:2569
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:1611
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:7363
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:7556
QualType getCanonicalType() const
Definition: Type.h:7407
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7449
bool isTriviallyEqualityComparableType(const ASTContext &Context) const
Return true if this is a trivially equality comparable type.
Definition: Type.cpp:2794
void removeLocalVolatile()
Definition: Type.h:7471
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:1602
bool isWebAssemblyReferenceType() const
Returns true if it is a WebAssembly Reference Type.
Definition: Type.cpp:2828
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:7376
bool UseExcessPrecision(const ASTContext &Ctx)
Definition: Type.cpp:1560
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:7563
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
Definition: Type.cpp:2842
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:7416
void removeLocalConst()
Definition: Type.h:7463
void removeLocalRestrict()
Definition: Type.h:7467
bool isWebAssemblyExternrefType() const
Returns true if it is a WebAssembly Externref Type.
Definition: Type.cpp:2832
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:3447
bool isMoreQualifiedThan(QualType Other) const
Determine whether this type is more qualified than the other given type, requiring exact equality for...
Definition: Type.h:7527
SplitQualType getSplitUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7456
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:2997
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:7428
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition: Type.h:7476
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:1595
unsigned getLocalFastQualifiers() const
Definition: Type.h:967
void removeLocalFastQualifiers()
Definition: Type.h:1188
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition: Type.cpp:1618
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:7412
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:7401
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:7359
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:2561
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:2876
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:7387
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:7490
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:7295
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:7302
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition: Type.h:7297
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:3438
static bool classof(const Type *T)
Definition: Type.h:3448
QualType desugar() const
Definition: Type.h:3446
bool isSugared() const
Definition: Type.h:3445
Represents a struct/union/class.
Definition: Decl.h:4169
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5545
RecordType(const RecordDecl *D)
Definition: Type.h:5549
bool isSugared() const
Definition: Type.h:5563
QualType desugar() const
Definition: Type.h:5564
RecordDecl * getDecl() const
Definition: Type.h:5555
RecordType(TypeClass TC, RecordDecl *D)
Definition: Type.h:5551
static bool classof(const Type *T)
Definition: Type.h:5566
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3376
bool isInnerRef() const
Definition: Type.h:3390
QualType getPointeeType() const
Definition: Type.h:3394
ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, bool SpelledAsLValue)
Definition: Type.h:3380
static bool classof(const Type *T)
Definition: Type.h:3413
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3392
bool isSpelledAsLValue() const
Definition: Type.h:3389
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3402
static void Profile(llvm::FoldingSetNodeID &ID, QualType Referencee, bool SpelledAsLValue)
Definition: Type.h:3406
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:5885
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5911
static bool classof(const Type *T)
Definition: Type.h:5930
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:5815
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5854
static bool classof(const Type *T)
Definition: Type.h:5868
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:5836
std::optional< unsigned > getPackIndex() const
Definition: Type.h:5845
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:5827
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:5843
QualType desugar() const
Definition: Type.h:5852
static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement, const Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex)
Definition: Type.h:5859
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3585
static bool classof(const Type *T)
Definition: Type.h:5538
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:6085
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6153
static bool classof(const Type *T)
Definition: Type.h:6171
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:6151
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:6144
QualType desugar() const
Definition: Type.h:6162
bool isCurrentInstantiation() const
True if this template specialization type matches a current instantiation in the context in which it ...
Definition: Type.h:6125
Declaration of a template type parameter.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:5778
QualType desugar() const
Definition: Type.h:5785
bool isParameterPack() const
Definition: Type.h:5776
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5787
unsigned getIndex() const
Definition: Type.h:5775
bool isSugared() const
Definition: Type.h:5784
static bool classof(const Type *T)
Definition: Type.h:5800
static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *TTPDecl)
Definition: Type.h:5791
CanonicalTTPTInfo CanTTPTInfo
Definition: Type.h:5745
TemplateTypeParmDecl * TTPDecl
Definition: Type.h:5748
unsigned getDepth() const
Definition: Type.h:5774
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: Type.h:3163
llvm::PointerIntPair< ValueDecl *, 1, unsigned > BaseTy
Definition: Type.h:3165
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:5270
static bool classof(const Type *T)
Definition: Type.h:5293
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5282
Expr * getUnderlyingExpr() const
Definition: Type.h:5279
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5318
static bool classof(const Type *T)
Definition: Type.h:5350
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5345
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:5342
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:5336
QualType getUnmodifiedType() const
Definition: Type.h:5333
The type-property cache.
Definition: Type.cpp:4353
A container of type source information.
Definition: Type.h:7326
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7337
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition: Type.h:7343
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:6316
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence)
Definition: Type.h:6318
static CannotCastToThisType classof(const Type *)
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:6348
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6325
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:2396
TypedefBitfields TypedefBits
Definition: Type.h:2235
UsingBitfields UsingBits
Definition: Type.h:2236
bool isBooleanType() const
Definition: Type.h:8029
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:8186
BuiltinTypeBitfields BuiltinTypeBits
Definition: Type.h:2237
bool isReferenceType() const
Definition: Type.h:7620
bool isEnumeralType() const
Definition: Type.h:7706
bool isVisibilityExplicit() const
Return true if the visibility was explicitly set is the code.
Definition: Type.h:2883
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:694
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:2754
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
Definition: Type.h:2657
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2649
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:2932
bool containsErrors() const
Whether this type is an error type.
Definition: Type.h:2643
AttributedTypeBitfields AttributedTypeBits
Definition: Type.h:2232
bool isFunctionProtoType() const
Definition: Type.h:2490
PackExpansionTypeBitfields PackExpansionTypeBits
Definition: Type.h:2249
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
Definition: Type.h:2667
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:2401
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:7604
SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits
Definition: Type.h:2244
TypeDependence getDependence() const
Definition: Type.h:2638
Visibility getVisibility() const
Determine the visibility of this type.
Definition: Type.h:2878
bool isObjCInertUnsafeUnretainedType() const
Was this type written with the special inert-in-ARC __unsafe_unretained qualifier?
Definition: Type.h:2546
ObjCObjectTypeBitfields ObjCObjectTypeBits
Definition: Type.h:2239
ScalarTypeKind
Definition: Type.h:2622
@ STK_FloatingComplex
Definition: Type.h:2631
@ STK_Floating
Definition: Type.h:2629
@ STK_BlockPointer
Definition: Type.h:2624
@ STK_Bool
Definition: Type.h:2627
@ STK_ObjCObjectPointer
Definition: Type.h:2625
@ STK_IntegralComplex
Definition: Type.h:2630
@ STK_CPointer
Definition: Type.h:2623
@ STK_Integral
Definition: Type.h:2628
@ STK_MemberPointer
Definition: Type.h:2626
bool isRealType() const
Definition: Type.cpp:2260
bool hasSizedVLAType() const
Whether this type involves a variable-length array type with a definite size.
Definition: Type.cpp:4919
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:8119
SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits
Definition: Type.h:2245
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition: Type.h:2246
bool isFunctionNoProtoType() const
Definition: Type.h:2489
AutoTypeBitfields AutoTypeBits
Definition: Type.h:2233
Type & operator=(Type &&)=delete
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3433
TypedefNameDecl * getDecl() const
Definition: Type.h:5213
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5223
static bool classof(const Type *T)
Definition: Type.h:5233
bool typeMatchesDecl() const
Definition: Type.h:5221
bool isSugared() const
Definition: Type.h:5215
static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl, QualType Underlying)
Definition: Type.h:5226
A unary type transform, which is a type constructed from another.
Definition: Type.h:5462
QualType getUnderlyingType() const
Definition: Type.h:5488
QualType getBaseType() const
Definition: Type.h:5489
UTTKind getUTTKind() const
Definition: Type.h:5491
bool isSugared() const
Definition: Type.h:5485
static bool classof(const Type *T)
Definition: Type.h:5493
QualType desugar() const
Definition: Type.h:5486
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5140
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5160
QualType desugar() const
Definition: Type.h:5154
static void Profile(llvm::FoldingSetNodeID &ID, UnresolvedUsingTypenameDecl *D)
Definition: Type.h:5164
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:5151
static bool classof(const Type *T)
Definition: Type.h:5156
bool isSugared() const
Definition: Type.h:5153
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:5186
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5191
bool isSugared() const
Definition: Type.h:5183
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found, QualType Underlying)
Definition: Type.h:5194
static bool classof(const Type *T)
Definition: Type.h:5199
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:5180
bool typeMatchesDecl() const
Definition: Type.h:5189
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:3743
SourceRange getBracketsRange() const
Definition: Type.h:3768
SourceLocation getLBracketLoc() const
Definition: Type.h:3769
static bool classof(const Type *T)
Definition: Type.h:3775
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3779
Expr * getSizeExpr() const
Definition: Type.h:3762
SourceLocation getRBracketLoc() const
Definition: Type.h:3770
QualType desugar() const
Definition: Type.h:3773
bool isSugared() const
Definition: Type.h:3772
Represents a GCC generic vector type.
Definition: Type.h:3965
unsigned getNumElements() const
Definition: Type.h:3980
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:3989
bool isSugared() const
Definition: Type.h:3982
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumElements, TypeClass TypeClass, VectorKind VecKind)
Definition: Type.h:3994
VectorKind getVectorKind() const
Definition: Type.h:3985
QualType ElementType
The element type of the vector.
Definition: Type.h:3970
QualType desugar() const
Definition: Type.h:3983
QualType getElementType() const
Definition: Type.h:3979
static bool classof(const Type *T)
Definition: Type.h:4003
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
'copyin' 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:7508
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:5033
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:3511
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:6295
constexpr unsigned PointerAuthKeyNone
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:5041
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:4972
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:8116
@ 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:3928
@ 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:6270
@ 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:22
#define bool
Definition: stdbool.h:20
Holds information about the various types of exception specification.
Definition: Type.h:4703
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition: Type.h:4723
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4705
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4708
Extra information about a function prototype.
Definition: Type.h:4731
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4738
bool requiresFunctionProtoTypeArmAttributes() const
Definition: Type.h:4761
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:4739
bool requiresFunctionProtoTypeExtraBitfields() const
Definition: Type.h:4756
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
Definition: Type.h:4765
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:4750
FunctionType::ExtInfo ExtInfo
Definition: Type.h:4732
A simple holder for a QualType representing a type in an exception specification.
Definition: Type.h:4490
A holder for Arm type attributes as described in the Arm C/C++ Language extensions which are not part...
Definition: Type.h:4546
unsigned AArch64SMEAttributes
Any AArch64 SME ACLE type attributes that need to be propagated on declarations and function pointers...
Definition: Type.h:4549
A simple holder for various uncommon bits which do not fit in FunctionTypeBitfields.
Definition: Type.h:4495
unsigned NumExceptionType
The number of types in the exception specification.
Definition: Type.h:4499
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:7348
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