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