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 // A bit to tell whether a function is agnostic about sme ZA state.
4597 SME_AgnosticZAStateShift = 8,
4598 SME_AgnosticZAStateMask = 1 << SME_AgnosticZAStateShift,
4599
4600 SME_AttributeMask =
4601 0b1'111'111'11 // We can't support more than 9 bits because of
4602 // the bitmask in FunctionTypeArmAttributes
4603 // and ExtProtoInfo.
4605
4606 enum ArmStateValue : unsigned {
4607 ARM_None = 0,
4608 ARM_Preserves = 1,
4609 ARM_In = 2,
4610 ARM_Out = 3,
4611 ARM_InOut = 4,
4612 };
4613
4614 static ArmStateValue getArmZAState(unsigned AttrBits) {
4615 return (ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4616 }
4617
4618 static ArmStateValue getArmZT0State(unsigned AttrBits) {
4619 return (ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4620 }
4621
4622 /// A holder for Arm type attributes as described in the Arm C/C++
4623 /// Language extensions which are not particularly common to all
4624 /// types and therefore accounted separately from FunctionTypeBitfields.
4625 struct alignas(void *) FunctionTypeArmAttributes {
4626 /// Any AArch64 SME ACLE type attributes that need to be propagated
4627 /// on declarations and function pointers.
4629
4630 FunctionTypeArmAttributes() : AArch64SMEAttributes(SME_NormalFunction) {}
4631 };
4632
4633protected:
4636 : Type(tc, Canonical, Dependence), ResultType(res) {
4637 FunctionTypeBits.ExtInfo = Info.Bits;
4638 }
4639
4641 if (isFunctionProtoType())
4642 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4643
4644 return Qualifiers();
4645 }
4646
4647public:
4648 QualType getReturnType() const { return ResultType; }
4649
4650 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
4651 unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
4652
4653 /// Determine whether this function type includes the GNU noreturn
4654 /// attribute. The C++11 [[noreturn]] attribute does not affect the function
4655 /// type.
4656 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
4657
4658 bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
4659 CallingConv getCallConv() const { return getExtInfo().getCC(); }
4660 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
4661
4662 static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4663 "Const, volatile and restrict are assumed to be a subset of "
4664 "the fast qualifiers.");
4665
4666 bool isConst() const { return getFastTypeQuals().hasConst(); }
4667 bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
4668 bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
4669
4670 /// Determine the type of an expression that calls a function of
4671 /// this type.
4672 QualType getCallResultType(const ASTContext &Context) const {
4673 return getReturnType().getNonLValueExprType(Context);
4674 }
4675
4676 static StringRef getNameForCallConv(CallingConv CC);
4677
4678 static bool classof(const Type *T) {
4679 return T->getTypeClass() == FunctionNoProto ||
4680 T->getTypeClass() == FunctionProto;
4681 }
4682};
4683
4684/// Represents a K&R-style 'int foo()' function, which has
4685/// no information available about its arguments.
4686class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
4687 friend class ASTContext; // ASTContext creates these.
4688
4689 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
4690 : FunctionType(FunctionNoProto, Result, Canonical,
4691 Result->getDependence() &
4692 ~(TypeDependence::DependentInstantiation |
4693 TypeDependence::UnexpandedPack),
4694 Info) {}
4695
4696public:
4697 // No additional state past what FunctionType provides.
4698
4699 bool isSugared() const { return false; }
4700 QualType desugar() const { return QualType(this, 0); }
4701
4702 void Profile(llvm::FoldingSetNodeID &ID) {
4703 Profile(ID, getReturnType(), getExtInfo());
4704 }
4705
4706 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
4707 ExtInfo Info) {
4708 Info.Profile(ID);
4709 ID.AddPointer(ResultType.getAsOpaquePtr());
4710 }
4711
4712 static bool classof(const Type *T) {
4713 return T->getTypeClass() == FunctionNoProto;
4714 }
4715};
4716
4717// ------------------------------------------------------------------------------
4718
4719/// Represents an abstract function effect, using just an enumeration describing
4720/// its kind.
4722public:
4723 /// Identifies the particular effect.
4724 enum class Kind : uint8_t {
4725 NonBlocking,
4726 NonAllocating,
4727 Blocking,
4728 Allocating,
4729 Last = Allocating
4730 };
4731 constexpr static size_t KindCount = static_cast<size_t>(Kind::Last) + 1;
4732
4733 /// Flags describing some behaviors of the effect.
4736 // Can verification inspect callees' implementations? (e.g. nonblocking:
4737 // yes, tcb+types: no). This also implies the need for 2nd-pass
4738 // verification.
4739 FE_InferrableOnCallees = 0x1,
4740
4741 // Language constructs which effects can diagnose as disallowed.
4742 FE_ExcludeThrow = 0x2,
4743 FE_ExcludeCatch = 0x4,
4744 FE_ExcludeObjCMessageSend = 0x8,
4745 FE_ExcludeStaticLocalVars = 0x10,
4746 FE_ExcludeThreadLocalVars = 0x20
4748
4749private:
4750 Kind FKind;
4751
4752 // Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
4753 // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would
4754 // be considered for uniqueness.
4755
4756public:
4757 explicit FunctionEffect(Kind K) : FKind(K) {}
4758
4759 /// The kind of the effect.
4760 Kind kind() const { return FKind; }
4761
4762 /// Return the opposite kind, for effects which have opposites.
4763 Kind oppositeKind() const;
4764
4765 /// For serialization.
4766 uint32_t toOpaqueInt32() const { return uint32_t(FKind); }
4768 return FunctionEffect(Kind(Value));
4769 }
4770
4771 /// Flags describing some behaviors of the effect.
4772 Flags flags() const {
4773 switch (kind()) {
4774 case Kind::NonBlocking:
4775 return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
4776 FE_ExcludeObjCMessageSend | FE_ExcludeStaticLocalVars |
4777 FE_ExcludeThreadLocalVars;
4778 case Kind::NonAllocating:
4779 // Same as NonBlocking, except without FE_ExcludeStaticLocalVars.
4780 return FE_InferrableOnCallees | FE_ExcludeThrow | FE_ExcludeCatch |
4781 FE_ExcludeObjCMessageSend | FE_ExcludeThreadLocalVars;
4782 case Kind::Blocking:
4783 case Kind::Allocating:
4784 return 0;
4785 }
4786 llvm_unreachable("unknown effect kind");
4787 }
4788
4789 /// The description printed in diagnostics, e.g. 'nonblocking'.
4790 StringRef name() const;
4791
4792 friend raw_ostream &operator<<(raw_ostream &OS,
4793 const FunctionEffect &Effect) {
4794 OS << Effect.name();
4795 return OS;
4796 }
4797
4798 /// Determine whether the effect is allowed to be inferred on the callee,
4799 /// which is either a FunctionDecl or BlockDecl. If the returned optional
4800 /// is empty, inference is permitted; otherwise it holds the effect which
4801 /// blocked inference.
4802 /// Example: This allows nonblocking(false) to prevent inference for the
4803 /// function.
4804 std::optional<FunctionEffect>
4805 effectProhibitingInference(const Decl &Callee,
4806 FunctionEffectKindSet CalleeFX) const;
4807
4808 // Return false for success. When true is returned for a direct call, then the
4809 // FE_InferrableOnCallees flag may trigger inference rather than an immediate
4810 // diagnostic. Caller should be assumed to have the effect (it may not have it
4811 // explicitly when inferring).
4812 bool shouldDiagnoseFunctionCall(bool Direct,
4813 FunctionEffectKindSet CalleeFX) const;
4814
4816 return LHS.FKind == RHS.FKind;
4817 }
4819 return !(LHS == RHS);
4820 }
4822 return LHS.FKind < RHS.FKind;
4823 }
4824};
4825
4826/// Wrap a function effect's condition expression in another struct so
4827/// that FunctionProtoType's TrailingObjects can treat it separately.
4829 Expr *Cond = nullptr; // if null, unconditional.
4830
4831public:
4834
4835 Expr *getCondition() const { return Cond; }
4836
4837 bool operator==(const EffectConditionExpr &RHS) const {
4838 return Cond == RHS.Cond;
4839 }
4840};
4841
4842/// A FunctionEffect plus a potential boolean expression determining whether
4843/// the effect is declared (e.g. nonblocking(expr)). Generally the condition
4844/// expression when present, is dependent.
4848
4850 : Effect(E), Cond(C) {}
4851
4852 /// Return a textual description of the effect, and its condition, if any.
4853 std::string description() const;
4854
4855 friend raw_ostream &operator<<(raw_ostream &OS,
4856 const FunctionEffectWithCondition &CFE);
4857};
4858
4859/// Support iteration in parallel through a pair of FunctionEffect and
4860/// EffectConditionExpr containers.
4861template <typename Container> class FunctionEffectIterator {
4862 friend Container;
4863
4864 const Container *Outer = nullptr;
4865 size_t Idx = 0;
4866
4867public:
4869 FunctionEffectIterator(const Container &O, size_t I) : Outer(&O), Idx(I) {}
4870 bool operator==(const FunctionEffectIterator &Other) const {
4871 return Idx == Other.Idx;
4872 }
4873 bool operator!=(const FunctionEffectIterator &Other) const {
4874 return Idx != Other.Idx;
4875 }
4876
4878 ++Idx;
4879 return *this;
4880 }
4881
4883 assert(Outer != nullptr && "invalid FunctionEffectIterator");
4884 bool HasConds = !Outer->Conditions.empty();
4885 return FunctionEffectWithCondition{Outer->Effects[Idx],
4886 HasConds ? Outer->Conditions[Idx]
4888 }
4889};
4890
4891/// An immutable set of FunctionEffects and possibly conditions attached to
4892/// them. The effects and conditions reside in memory not managed by this object
4893/// (typically, trailing objects in FunctionProtoType, or borrowed references
4894/// from a FunctionEffectSet).
4895///
4896/// Invariants:
4897/// - there is never more than one instance of any given effect.
4898/// - the array of conditions is either empty or has the same size as the
4899/// array of effects.
4900/// - some conditions may be null expressions; each condition pertains to
4901/// the effect at the same array index.
4902///
4903/// Also, if there are any conditions, at least one of those expressions will be
4904/// dependent, but this is only asserted in the constructor of
4905/// FunctionProtoType.
4906///
4907/// See also FunctionEffectSet, in Sema, which provides a mutable set.
4909 // Restrict classes which can call the private constructor -- these friends
4910 // all maintain the required invariants. FunctionEffectSet is generally the
4911 // only way in which the arrays are created; FunctionProtoType will not
4912 // reorder them.
4913 friend FunctionProtoType;
4914 friend FunctionEffectSet;
4915
4918
4919 // The arrays are expected to have been sorted by the caller, with the
4920 // effects in order. The conditions array must be empty or the same size
4921 // as the effects array, since the conditions are associated with the effects
4922 // at the same array indices.
4925 : Effects(FX), Conditions(Conds) {}
4926
4927public:
4928 /// Extract the effects from a Type if it is a function, block, or member
4929 /// function pointer, or a reference or pointer to one.
4930 static FunctionEffectsRef get(QualType QT);
4931
4932 /// Asserts invariants.
4935
4937
4938 bool empty() const { return Effects.empty(); }
4939 size_t size() const { return Effects.size(); }
4940
4941 ArrayRef<FunctionEffect> effects() const { return Effects; }
4942 ArrayRef<EffectConditionExpr> conditions() const { return Conditions; }
4943
4945 friend iterator;
4946 iterator begin() const { return iterator(*this, 0); }
4947 iterator end() const { return iterator(*this, size()); }
4948
4949 friend bool operator==(const FunctionEffectsRef &LHS,
4950 const FunctionEffectsRef &RHS) {
4951 return LHS.Effects == RHS.Effects && LHS.Conditions == RHS.Conditions;
4952 }
4953 friend bool operator!=(const FunctionEffectsRef &LHS,
4954 const FunctionEffectsRef &RHS) {
4955 return !(LHS == RHS);
4956 }
4957
4958 void dump(llvm::raw_ostream &OS) const;
4959};
4960
4961/// A mutable set of FunctionEffect::Kind.
4963 // For now this only needs to be a bitmap.
4964 constexpr static size_t EndBitPos = FunctionEffect::KindCount;
4965 using KindBitsT = std::bitset<EndBitPos>;
4966
4967 KindBitsT KindBits{};
4968
4969 explicit FunctionEffectKindSet(KindBitsT KB) : KindBits(KB) {}
4970
4971 // Functions to translate between an effect kind, starting at 1, and a
4972 // position in the bitset.
4973
4974 constexpr static size_t kindToPos(FunctionEffect::Kind K) {
4975 return static_cast<size_t>(K);
4976 }
4977
4978 constexpr static FunctionEffect::Kind posToKind(size_t Pos) {
4979 return static_cast<FunctionEffect::Kind>(Pos);
4980 }
4981
4982 // Iterates through the bits which are set.
4983 class iterator {
4984 const FunctionEffectKindSet *Outer = nullptr;
4985 size_t Idx = 0;
4986
4987 // If Idx does not reference a set bit, advance it until it does,
4988 // or until it reaches EndBitPos.
4989 void advanceToNextSetBit() {
4990 while (Idx < EndBitPos && !Outer->KindBits.test(Idx))
4991 ++Idx;
4992 }
4993
4994 public:
4995 iterator();
4996 iterator(const FunctionEffectKindSet &O, size_t I) : Outer(&O), Idx(I) {
4997 advanceToNextSetBit();
4998 }
4999 bool operator==(const iterator &Other) const { return Idx == Other.Idx; }
5000 bool operator!=(const iterator &Other) const { return Idx != Other.Idx; }
5001
5002 iterator operator++() {
5003 ++Idx;
5004 advanceToNextSetBit();
5005 return *this;
5006 }
5007
5008 FunctionEffect operator*() const {
5009 assert(Idx < EndBitPos && "Dereference of end iterator");
5010 return FunctionEffect(posToKind(Idx));
5011 }
5012 };
5013
5014public:
5016 explicit FunctionEffectKindSet(FunctionEffectsRef FX) { insert(FX); }
5017
5018 iterator begin() const { return iterator(*this, 0); }
5019 iterator end() const { return iterator(*this, EndBitPos); }
5020
5021 void insert(FunctionEffect Effect) { KindBits.set(kindToPos(Effect.kind())); }
5023 for (FunctionEffect Item : FX.effects())
5024 insert(Item);
5025 }
5026 void insert(FunctionEffectKindSet Set) { KindBits |= Set.KindBits; }
5027
5028 bool empty() const { return KindBits.none(); }
5029 bool contains(const FunctionEffect::Kind EK) const {
5030 return KindBits.test(kindToPos(EK));
5031 }
5032 void dump(llvm::raw_ostream &OS) const;
5033
5036 return FunctionEffectKindSet(LHS.KindBits & ~RHS.KindBits);
5037 }
5038};
5039
5040/// A mutable set of FunctionEffects and possibly conditions attached to them.
5041/// Used to compare and merge effects on declarations.
5042///
5043/// Has the same invariants as FunctionEffectsRef.
5047
5048public:
5050
5052 : Effects(FX.effects()), Conditions(FX.conditions()) {}
5053
5054 bool empty() const { return Effects.empty(); }
5055 size_t size() const { return Effects.size(); }
5056
5058 friend iterator;
5059 iterator begin() const { return iterator(*this, 0); }
5060 iterator end() const { return iterator(*this, size()); }
5061
5062 operator FunctionEffectsRef() const { return {Effects, Conditions}; }
5063
5064 void dump(llvm::raw_ostream &OS) const;
5065
5066 // Mutators
5067
5068 // On insertion, a conflict occurs when attempting to insert an
5069 // effect which is opposite an effect already in the set, or attempting
5070 // to insert an effect which is already in the set but with a condition
5071 // which is not identical.
5072 struct Conflict {
5075 };
5077
5078 // Returns true for success (obviating a check of Errs.empty()).
5079 bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs);
5080
5081 // Returns true for success (obviating a check of Errs.empty()).
5082 bool insert(const FunctionEffectsRef &Set, Conflicts &Errs);
5083
5084 // Set operations
5085
5086 static FunctionEffectSet getUnion(FunctionEffectsRef LHS,
5087 FunctionEffectsRef RHS, Conflicts &Errs);
5088 static FunctionEffectSet getIntersection(FunctionEffectsRef LHS,
5089 FunctionEffectsRef RHS);
5090};
5091
5092/// Represents a prototype with parameter type info, e.g.
5093/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
5094/// parameters, not as having a single void parameter. Such a type can have
5095/// an exception specification, but this specification is not part of the
5096/// canonical type. FunctionProtoType has several trailing objects, some of
5097/// which optional. For more information about the trailing objects see
5098/// the first comment inside FunctionProtoType.
5100 : public FunctionType,
5101 public llvm::FoldingSetNode,
5102 private llvm::TrailingObjects<
5103 FunctionProtoType, QualType, SourceLocation,
5104 FunctionType::FunctionTypeExtraBitfields,
5105 FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
5106 Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers,
5107 FunctionEffect, EffectConditionExpr> {
5108 friend class ASTContext; // ASTContext creates these.
5109 friend TrailingObjects;
5110
5111 // FunctionProtoType is followed by several trailing objects, some of
5112 // which optional. They are in order:
5113 //
5114 // * An array of getNumParams() QualType holding the parameter types.
5115 // Always present. Note that for the vast majority of FunctionProtoType,
5116 // these will be the only trailing objects.
5117 //
5118 // * Optionally if the function is variadic, the SourceLocation of the
5119 // ellipsis.
5120 //
5121 // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
5122 // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
5123 // a single FunctionTypeExtraBitfields. Present if and only if
5124 // hasExtraBitfields() is true.
5125 //
5126 // * Optionally exactly one of:
5127 // * an array of getNumExceptions() ExceptionType,
5128 // * a single Expr *,
5129 // * a pair of FunctionDecl *,
5130 // * a single FunctionDecl *
5131 // used to store information about the various types of exception
5132 // specification. See getExceptionSpecSize for the details.
5133 //
5134 // * Optionally an array of getNumParams() ExtParameterInfo holding
5135 // an ExtParameterInfo for each of the parameters. Present if and
5136 // only if hasExtParameterInfos() is true.
5137 //
5138 // * Optionally a Qualifiers object to represent extra qualifiers that can't
5139 // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and
5140 // only if hasExtQualifiers() is true.
5141 //
5142 // * Optionally, an array of getNumFunctionEffects() FunctionEffect.
5143 // Present only when getNumFunctionEffects() > 0
5144 //
5145 // * Optionally, an array of getNumFunctionEffects() EffectConditionExpr.
5146 // Present only when getNumFunctionEffectConditions() > 0.
5147 //
5148 // The optional FunctionTypeExtraBitfields has to be before the data
5149 // related to the exception specification since it contains the number
5150 // of exception types.
5151 //
5152 // We put the ExtParameterInfos later. If all were equal, it would make
5153 // more sense to put these before the exception specification, because
5154 // it's much easier to skip past them compared to the elaborate switch
5155 // required to skip the exception specification. However, all is not
5156 // equal; ExtParameterInfos are used to model very uncommon features,
5157 // and it's better not to burden the more common paths.
5158
5159public:
5160 /// Holds information about the various types of exception specification.
5161 /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
5162 /// used to group together the various bits of information about the
5163 /// exception specification.
5165 /// The kind of exception specification this is.
5167
5168 /// Explicitly-specified list of exception types.
5170
5171 /// Noexcept expression, if this is a computed noexcept specification.
5172 Expr *NoexceptExpr = nullptr;
5173
5174 /// The function whose exception specification this is, for
5175 /// EST_Unevaluated and EST_Uninstantiated.
5176 FunctionDecl *SourceDecl = nullptr;
5177
5178 /// The function template whose exception specification this is instantiated
5179 /// from, for EST_Uninstantiated.
5180 FunctionDecl *SourceTemplate = nullptr;
5181
5183
5185
5186 void instantiate();
5187 };
5188
5189 /// Extra information about a function prototype. ExtProtoInfo is not
5190 /// stored as such in FunctionProtoType but is used to group together
5191 /// the various bits of extra information about a function prototype.
5194 unsigned Variadic : 1;
5195 unsigned HasTrailingReturn : 1;
5200 const ExtParameterInfo *ExtParameterInfos = nullptr;
5203
5205 : Variadic(false), HasTrailingReturn(false),
5206 AArch64SMEAttributes(SME_NormalFunction) {}
5207
5209 : ExtInfo(CC), Variadic(false), HasTrailingReturn(false),
5210 AArch64SMEAttributes(SME_NormalFunction) {}
5211
5213 ExtProtoInfo Result(*this);
5214 Result.ExceptionSpec = ESI;
5215 return Result;
5216 }
5217
5219 return ExceptionSpec.Type == EST_Dynamic ||
5220 requiresFunctionProtoTypeArmAttributes() ||
5221 !FunctionEffects.empty();
5222 }
5223
5225 return AArch64SMEAttributes != SME_NormalFunction;
5226 }
5227
5229 if (Enable)
5230 AArch64SMEAttributes |= Kind;
5231 else
5232 AArch64SMEAttributes &= ~Kind;
5233 }
5234 };
5235
5236private:
5237 unsigned numTrailingObjects(OverloadToken<QualType>) const {
5238 return getNumParams();
5239 }
5240
5241 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
5242 return isVariadic();
5243 }
5244
5245 unsigned numTrailingObjects(OverloadToken<FunctionTypeArmAttributes>) const {
5246 return hasArmTypeAttributes();
5247 }
5248
5249 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
5250 return hasExtraBitfields();
5251 }
5252
5253 unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
5254 return getExceptionSpecSize().NumExceptionType;
5255 }
5256
5257 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
5258 return getExceptionSpecSize().NumExprPtr;
5259 }
5260
5261 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
5262 return getExceptionSpecSize().NumFunctionDeclPtr;
5263 }
5264
5265 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
5266 return hasExtParameterInfos() ? getNumParams() : 0;
5267 }
5268
5269 unsigned numTrailingObjects(OverloadToken<Qualifiers>) const {
5270 return hasExtQualifiers() ? 1 : 0;
5271 }
5272
5273 unsigned numTrailingObjects(OverloadToken<FunctionEffect>) const {
5274 return getNumFunctionEffects();
5275 }
5276
5277 unsigned numTrailingObjects(OverloadToken<EffectConditionExpr>) const {
5278 return getNumFunctionEffectConditions();
5279 }
5280
5281 /// Determine whether there are any argument types that
5282 /// contain an unexpanded parameter pack.
5283 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
5284 unsigned numArgs) {
5285 for (unsigned Idx = 0; Idx < numArgs; ++Idx)
5286 if (ArgArray[Idx]->containsUnexpandedParameterPack())
5287 return true;
5288
5289 return false;
5290 }
5291
5292 FunctionProtoType(QualType result, ArrayRef<QualType> params,
5293 QualType canonical, const ExtProtoInfo &epi);
5294
5295 /// This struct is returned by getExceptionSpecSize and is used to
5296 /// translate an ExceptionSpecificationType to the number and kind
5297 /// of trailing objects related to the exception specification.
5298 struct ExceptionSpecSizeHolder {
5299 unsigned NumExceptionType;
5300 unsigned NumExprPtr;
5301 unsigned NumFunctionDeclPtr;
5302 };
5303
5304 /// Return the number and kind of trailing objects
5305 /// related to the exception specification.
5306 static ExceptionSpecSizeHolder
5307 getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
5308 switch (EST) {
5309 case EST_None:
5310 case EST_DynamicNone:
5311 case EST_MSAny:
5312 case EST_BasicNoexcept:
5313 case EST_Unparsed:
5314 case EST_NoThrow:
5315 return {0, 0, 0};
5316
5317 case EST_Dynamic:
5318 return {NumExceptions, 0, 0};
5319
5321 case EST_NoexceptFalse:
5322 case EST_NoexceptTrue:
5323 return {0, 1, 0};
5324
5325 case EST_Uninstantiated:
5326 return {0, 0, 2};
5327
5328 case EST_Unevaluated:
5329 return {0, 0, 1};
5330 }
5331 llvm_unreachable("bad exception specification kind");
5332 }
5333
5334 /// Return the number and kind of trailing objects
5335 /// related to the exception specification.
5336 ExceptionSpecSizeHolder getExceptionSpecSize() const {
5337 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
5338 }
5339
5340 /// Whether the trailing FunctionTypeExtraBitfields is present.
5341 bool hasExtraBitfields() const {
5342 assert((getExceptionSpecType() != EST_Dynamic ||
5343 FunctionTypeBits.HasExtraBitfields) &&
5344 "ExtraBitfields are required for given ExceptionSpecType");
5345 return FunctionTypeBits.HasExtraBitfields;
5346
5347 }
5348
5349 bool hasArmTypeAttributes() const {
5350 return FunctionTypeBits.HasExtraBitfields &&
5351 getTrailingObjects<FunctionTypeExtraBitfields>()
5352 ->HasArmTypeAttributes;
5353 }
5354
5355 bool hasExtQualifiers() const {
5356 return FunctionTypeBits.HasExtQuals;
5357 }
5358
5359public:
5360 unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
5361
5362 QualType getParamType(unsigned i) const {
5363 assert(i < getNumParams() && "invalid parameter index");
5364 return param_type_begin()[i];
5365 }
5366
5368 return llvm::ArrayRef(param_type_begin(), param_type_end());
5369 }
5370
5372 ExtProtoInfo EPI;
5373 EPI.ExtInfo = getExtInfo();
5374 EPI.Variadic = isVariadic();
5375 EPI.EllipsisLoc = getEllipsisLoc();
5376 EPI.HasTrailingReturn = hasTrailingReturn();
5377 EPI.ExceptionSpec = getExceptionSpecInfo();
5378 EPI.TypeQuals = getMethodQuals();
5379 EPI.RefQualifier = getRefQualifier();
5380 EPI.ExtParameterInfos = getExtParameterInfosOrNull();
5381 EPI.AArch64SMEAttributes = getAArch64SMEAttributes();
5382 EPI.FunctionEffects = getFunctionEffects();
5383 return EPI;
5384 }
5385
5386 /// Get the kind of exception specification on this function.
5388 return static_cast<ExceptionSpecificationType>(
5389 FunctionTypeBits.ExceptionSpecType);
5390 }
5391
5392 /// Return whether this function has any kind of exception spec.
5393 bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
5394
5395 /// Return whether this function has a dynamic (throw) exception spec.
5397 return isDynamicExceptionSpec(getExceptionSpecType());
5398 }
5399
5400 /// Return whether this function has a noexcept exception spec.
5402 return isNoexceptExceptionSpec(getExceptionSpecType());
5403 }
5404
5405 /// Return whether this function has a dependent exception spec.
5406 bool hasDependentExceptionSpec() const;
5407
5408 /// Return whether this function has an instantiation-dependent exception
5409 /// spec.
5410 bool hasInstantiationDependentExceptionSpec() const;
5411
5412 /// Return all the available information about this type's exception spec.
5414 ExceptionSpecInfo Result;
5415 Result.Type = getExceptionSpecType();
5416 if (Result.Type == EST_Dynamic) {
5417 Result.Exceptions = exceptions();
5418 } else if (isComputedNoexcept(Result.Type)) {
5419 Result.NoexceptExpr = getNoexceptExpr();
5420 } else if (Result.Type == EST_Uninstantiated) {
5421 Result.SourceDecl = getExceptionSpecDecl();
5422 Result.SourceTemplate = getExceptionSpecTemplate();
5423 } else if (Result.Type == EST_Unevaluated) {
5424 Result.SourceDecl = getExceptionSpecDecl();
5425 }
5426 return Result;
5427 }
5428
5429 /// Return the number of types in the exception specification.
5430 unsigned getNumExceptions() const {
5431 return getExceptionSpecType() == EST_Dynamic
5432 ? getTrailingObjects<FunctionTypeExtraBitfields>()
5433 ->NumExceptionType
5434 : 0;
5435 }
5436
5437 /// Return the ith exception type, where 0 <= i < getNumExceptions().
5438 QualType getExceptionType(unsigned i) const {
5439 assert(i < getNumExceptions() && "Invalid exception number!");
5440 return exception_begin()[i];
5441 }
5442
5443 /// Return the expression inside noexcept(expression), or a null pointer
5444 /// if there is none (because the exception spec is not of this form).
5446 if (!isComputedNoexcept(getExceptionSpecType()))
5447 return nullptr;
5448 return *getTrailingObjects<Expr *>();
5449 }
5450
5451 /// If this function type has an exception specification which hasn't
5452 /// been determined yet (either because it has not been evaluated or because
5453 /// it has not been instantiated), this is the function whose exception
5454 /// specification is represented by this type.
5456 if (getExceptionSpecType() != EST_Uninstantiated &&
5457 getExceptionSpecType() != EST_Unevaluated)
5458 return nullptr;
5459 return getTrailingObjects<FunctionDecl *>()[0];
5460 }
5461
5462 /// If this function type has an uninstantiated exception
5463 /// specification, this is the function whose exception specification
5464 /// should be instantiated to find the exception specification for
5465 /// this type.
5467 if (getExceptionSpecType() != EST_Uninstantiated)
5468 return nullptr;
5469 return getTrailingObjects<FunctionDecl *>()[1];
5470 }
5471
5472 /// Determine whether this function type has a non-throwing exception
5473 /// specification.
5474 CanThrowResult canThrow() const;
5475
5476 /// Determine whether this function type has a non-throwing exception
5477 /// specification. If this depends on template arguments, returns
5478 /// \c ResultIfDependent.
5479 bool isNothrow(bool ResultIfDependent = false) const {
5480 return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
5481 }
5482
5483 /// Whether this function prototype is variadic.
5484 bool isVariadic() const { return FunctionTypeBits.Variadic; }
5485
5487 return isVariadic() ? *getTrailingObjects<SourceLocation>()
5488 : SourceLocation();
5489 }
5490
5491 /// Determines whether this function prototype contains a
5492 /// parameter pack at the end.
5493 ///
5494 /// A function template whose last parameter is a parameter pack can be
5495 /// called with an arbitrary number of arguments, much like a variadic
5496 /// function.
5497 bool isTemplateVariadic() const;
5498
5499 /// Whether this function prototype has a trailing return type.
5500 bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
5501
5503 if (hasExtQualifiers())
5504 return *getTrailingObjects<Qualifiers>();
5505 else
5506 return getFastTypeQuals();
5507 }
5508
5509 /// Retrieve the ref-qualifier associated with this function type.
5511 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
5512 }
5513
5515
5517 return llvm::ArrayRef(param_type_begin(), param_type_end());
5518 }
5519
5521 return getTrailingObjects<QualType>();
5522 }
5523
5525 return param_type_begin() + getNumParams();
5526 }
5527
5529
5531 return llvm::ArrayRef(exception_begin(), exception_end());
5532 }
5533
5535 return reinterpret_cast<exception_iterator>(
5536 getTrailingObjects<ExceptionType>());
5537 }
5538
5540 return exception_begin() + getNumExceptions();
5541 }
5542
5543 /// Is there any interesting extra information for any of the parameters
5544 /// of this function type?
5546 return FunctionTypeBits.HasExtParameterInfos;
5547 }
5548
5550 assert(hasExtParameterInfos());
5551 return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
5552 getNumParams());
5553 }
5554
5555 /// Return a pointer to the beginning of the array of extra parameter
5556 /// information, if present, or else null if none of the parameters
5557 /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
5559 if (!hasExtParameterInfos())
5560 return nullptr;
5561 return getTrailingObjects<ExtParameterInfo>();
5562 }
5563
5564 /// Return a bitmask describing the SME attributes on the function type, see
5565 /// AArch64SMETypeAttributes for their values.
5566 unsigned getAArch64SMEAttributes() const {
5567 if (!hasArmTypeAttributes())
5568 return SME_NormalFunction;
5569 return getTrailingObjects<FunctionTypeArmAttributes>()
5570 ->AArch64SMEAttributes;
5571 }
5572
5574 assert(I < getNumParams() && "parameter index out of range");
5575 if (hasExtParameterInfos())
5576 return getTrailingObjects<ExtParameterInfo>()[I];
5577 return ExtParameterInfo();
5578 }
5579
5580 ParameterABI getParameterABI(unsigned I) const {
5581 assert(I < getNumParams() && "parameter index out of range");
5582 if (hasExtParameterInfos())
5583 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
5584 return ParameterABI::Ordinary;
5585 }
5586
5587 bool isParamConsumed(unsigned I) const {
5588 assert(I < getNumParams() && "parameter index out of range");
5589 if (hasExtParameterInfos())
5590 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
5591 return false;
5592 }
5593
5594 unsigned getNumFunctionEffects() const {
5595 return hasExtraBitfields()
5596 ? getTrailingObjects<FunctionTypeExtraBitfields>()
5597 ->NumFunctionEffects
5598 : 0;
5599 }
5600
5601 // For serialization.
5603 if (hasExtraBitfields()) {
5604 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
5605 if (Bitfields->NumFunctionEffects > 0)
5606 return {getTrailingObjects<FunctionEffect>(),
5607 Bitfields->NumFunctionEffects};
5608 }
5609 return {};
5610 }
5611
5613 if (hasExtraBitfields()) {
5614 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
5615 if (Bitfields->EffectsHaveConditions)
5616 return Bitfields->NumFunctionEffects;
5617 }
5618 return 0;
5619 }
5620
5621 // For serialization.
5623 if (hasExtraBitfields()) {
5624 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
5625 if (Bitfields->EffectsHaveConditions)
5626 return {getTrailingObjects<EffectConditionExpr>(),
5627 Bitfields->NumFunctionEffects};
5628 }
5629 return {};
5630 }
5631
5632 // Combines effects with their conditions.
5634 if (hasExtraBitfields()) {
5635 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
5636 if (Bitfields->NumFunctionEffects > 0) {
5637 const size_t NumConds = Bitfields->EffectsHaveConditions
5638 ? Bitfields->NumFunctionEffects
5639 : 0;
5640 return FunctionEffectsRef(
5641 {getTrailingObjects<FunctionEffect>(),
5642 Bitfields->NumFunctionEffects},
5643 {NumConds ? getTrailingObjects<EffectConditionExpr>() : nullptr,
5644 NumConds});
5645 }
5646 }
5647 return {};
5648 }
5649
5650 bool isSugared() const { return false; }
5651 QualType desugar() const { return QualType(this, 0); }
5652
5653 void printExceptionSpecification(raw_ostream &OS,
5654 const PrintingPolicy &Policy) const;
5655
5656 static bool classof(const Type *T) {
5657 return T->getTypeClass() == FunctionProto;
5658 }
5659
5660 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
5661 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
5662 param_type_iterator ArgTys, unsigned NumArgs,
5663 const ExtProtoInfo &EPI, const ASTContext &Context,
5664 bool Canonical);
5665};
5666
5667/// Represents the dependent type named by a dependently-scoped
5668/// typename using declaration, e.g.
5669/// using typename Base<T>::foo;
5670///
5671/// Template instantiation turns these into the underlying type.
5673 friend class ASTContext; // ASTContext creates these.
5674
5676
5678 : Type(UnresolvedUsing, QualType(),
5679 TypeDependence::DependentInstantiation),
5680 Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {}
5681
5682public:
5684
5685 bool isSugared() const { return false; }
5686 QualType desugar() const { return QualType(this, 0); }
5687
5688 static bool classof(const Type *T) {
5689 return T->getTypeClass() == UnresolvedUsing;
5690 }
5691
5692 void Profile(llvm::FoldingSetNodeID &ID) {
5693 return Profile(ID, Decl);
5694 }
5695
5696 static void Profile(llvm::FoldingSetNodeID &ID,
5698 ID.AddPointer(D);
5699 }
5700};
5701
5702class UsingType final : public Type,
5703 public llvm::FoldingSetNode,
5704 private llvm::TrailingObjects<UsingType, QualType> {
5706 friend class ASTContext; // ASTContext creates these.
5707 friend TrailingObjects;
5708
5709 UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
5710
5711public:
5714
5715 bool isSugared() const { return true; }
5716
5717 // This always has the 'same' type as declared, but not necessarily identical.
5718 QualType desugar() const { return getUnderlyingType(); }
5719
5720 // Internal helper, for debugging purposes.
5721 bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
5722
5723 void Profile(llvm::FoldingSetNodeID &ID) {
5724 Profile(ID, Found, getUnderlyingType());
5725 }
5726 static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
5727 QualType Underlying) {
5728 ID.AddPointer(Found);
5729 Underlying.Profile(ID);
5730 }
5731 static bool classof(const Type *T) { return T->getTypeClass() == Using; }
5732};
5733
5734class TypedefType final : public Type,
5735 public llvm::FoldingSetNode,
5736 private llvm::TrailingObjects<TypedefType, QualType> {
5738 friend class ASTContext; // ASTContext creates these.
5739 friend TrailingObjects;
5740
5741 TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying,
5742 QualType can);
5743
5744public:
5745 TypedefNameDecl *getDecl() const { return Decl; }
5746
5747 bool isSugared() const { return true; }
5748
5749 // This always has the 'same' type as declared, but not necessarily identical.
5750 QualType desugar() const;
5751
5752 // Internal helper, for debugging purposes.
5753 bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
5754
5755 void Profile(llvm::FoldingSetNodeID &ID) {
5756 Profile(ID, Decl, typeMatchesDecl() ? QualType() : desugar());
5757 }
5758 static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl,
5759 QualType Underlying) {
5760 ID.AddPointer(Decl);
5761 if (!Underlying.isNull())
5762 Underlying.Profile(ID);
5763 }
5764
5765 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
5766};
5767
5768/// Sugar type that represents a type that was qualified by a qualifier written
5769/// as a macro invocation.
5770class MacroQualifiedType : public Type {
5771 friend class ASTContext; // ASTContext creates these.
5772
5773 QualType UnderlyingTy;
5774 const IdentifierInfo *MacroII;
5775
5776 MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
5777 const IdentifierInfo *MacroII)
5778 : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
5779 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
5780 assert(isa<AttributedType>(UnderlyingTy) &&
5781 "Expected a macro qualified type to only wrap attributed types.");
5782 }
5783
5784public:
5785 const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
5786 QualType getUnderlyingType() const { return UnderlyingTy; }
5787
5788 /// Return this attributed type's modified type with no qualifiers attached to
5789 /// it.
5790 QualType getModifiedType() const;
5791
5792 bool isSugared() const { return true; }
5793 QualType desugar() const;
5794
5795 static bool classof(const Type *T) {
5796 return T->getTypeClass() == MacroQualified;
5797 }
5798};
5799
5800/// Represents a `typeof` (or __typeof__) expression (a C23 feature and GCC
5801/// extension) or a `typeof_unqual` expression (a C23 feature).
5802class TypeOfExprType : public Type {
5803 Expr *TOExpr;
5804 const ASTContext &Context;
5805
5806protected:
5807 friend class ASTContext; // ASTContext creates these.
5808
5809 TypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind,
5810 QualType Can = QualType());
5811
5812public:
5813 Expr *getUnderlyingExpr() const { return TOExpr; }
5814
5815 /// Returns the kind of 'typeof' type this is.
5817 return static_cast<TypeOfKind>(TypeOfBits.Kind);
5818 }
5819
5820 /// Remove a single level of sugar.
5821 QualType desugar() const;
5822
5823 /// Returns whether this type directly provides sugar.
5824 bool isSugared() const;
5825
5826 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
5827};
5828
5829/// Internal representation of canonical, dependent
5830/// `typeof(expr)` types.
5831///
5832/// This class is used internally by the ASTContext to manage
5833/// canonical, dependent types, only. Clients will only see instances
5834/// of this class via TypeOfExprType nodes.
5836 public llvm::FoldingSetNode {
5837public:
5839 : TypeOfExprType(Context, E, Kind) {}
5840
5841 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5842 Profile(ID, Context, getUnderlyingExpr(),
5843 getKind() == TypeOfKind::Unqualified);
5844 }
5845
5846 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5847 Expr *E, bool IsUnqual);
5848};
5849
5850/// Represents `typeof(type)`, a C23 feature and GCC extension, or
5851/// `typeof_unqual(type), a C23 feature.
5852class TypeOfType : public Type {
5853 friend class ASTContext; // ASTContext creates these.
5854
5855 QualType TOType;
5856 const ASTContext &Context;
5857
5858 TypeOfType(const ASTContext &Context, QualType T, QualType Can,
5860
5861public:
5862 QualType getUnmodifiedType() const { return TOType; }
5863
5864 /// Remove a single level of sugar.
5865 QualType desugar() const;
5866
5867 /// Returns whether this type directly provides sugar.
5868 bool isSugared() const { return true; }
5869
5870 /// Returns the kind of 'typeof' type this is.
5872 return static_cast<TypeOfKind>(TypeOfBits.Kind);
5873 }
5874
5875 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
5876};
5877
5878/// Represents the type `decltype(expr)` (C++11).
5879class DecltypeType : public Type {
5880 Expr *E;
5881 QualType UnderlyingType;
5882
5883protected:
5884 friend class ASTContext; // ASTContext creates these.
5885
5886 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
5887
5888public:
5889 Expr *getUnderlyingExpr() const { return E; }
5890 QualType getUnderlyingType() const { return UnderlyingType; }
5891
5892 /// Remove a single level of sugar.
5893 QualType desugar() const;
5894
5895 /// Returns whether this type directly provides sugar.
5896 bool isSugared() const;
5897
5898 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
5899};
5900
5901/// Internal representation of canonical, dependent
5902/// decltype(expr) types.
5903///
5904/// This class is used internally by the ASTContext to manage
5905/// canonical, dependent types, only. Clients will only see instances
5906/// of this class via DecltypeType nodes.
5907class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
5908public:
5909 DependentDecltypeType(Expr *E, QualType UnderlyingTpe);
5910
5911 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
5912 Profile(ID, Context, getUnderlyingExpr());
5913 }
5914
5915 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5916 Expr *E);
5917};
5918
5920 : public Type,
5921 public llvm::FoldingSetNode,
5922 private llvm::TrailingObjects<PackIndexingType, QualType> {
5923 friend TrailingObjects;
5924
5925 const ASTContext &Context;
5926 QualType Pattern;
5927 Expr *IndexExpr;
5928
5929 unsigned Size : 31;
5930
5931 LLVM_PREFERRED_TYPE(bool)
5932 unsigned FullySubstituted : 1;
5933
5934protected:
5935 friend class ASTContext; // ASTContext creates these.
5936 PackIndexingType(const ASTContext &Context, QualType Canonical,
5937 QualType Pattern, Expr *IndexExpr, bool FullySubstituted,
5938 ArrayRef<QualType> Expansions = {});
5939
5940public:
5941 Expr *getIndexExpr() const { return IndexExpr; }
5942 QualType getPattern() const { return Pattern; }
5943
5944 bool isSugared() const { return hasSelectedType(); }
5945
5947 if (hasSelectedType())
5948 return getSelectedType();
5949 return QualType(this, 0);
5950 }
5951
5953 assert(hasSelectedType() && "Type is dependant");
5954 return *(getExpansionsPtr() + *getSelectedIndex());
5955 }
5956
5957 std::optional<unsigned> getSelectedIndex() const;
5958
5959 bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }
5960
5961 bool isFullySubstituted() const { return FullySubstituted; }
5962
5963 bool expandsToEmptyPack() const { return isFullySubstituted() && Size == 0; }
5964
5966 return {getExpansionsPtr(), Size};
5967 }
5968
5969 static bool classof(const Type *T) {
5970 return T->getTypeClass() == PackIndexing;
5971 }
5972
5973 void Profile(llvm::FoldingSetNodeID &ID) {
5974 if (hasSelectedType())
5975 getSelectedType().Profile(ID);
5976 else
5977 Profile(ID, Context, getPattern(), getIndexExpr(), isFullySubstituted());
5978 }
5979 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
5980 QualType Pattern, Expr *E, bool FullySubstituted);
5981
5982private:
5983 const QualType *getExpansionsPtr() const {
5984 return getTrailingObjects<QualType>();
5985 }
5986
5987 static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
5988 ArrayRef<QualType> Expansions = {});
5989
5990 unsigned numTrailingObjects(OverloadToken<QualType>) const { return Size; }
5991};
5992
5993/// A unary type transform, which is a type constructed from another.
5994class UnaryTransformType : public Type {
5995public:
5996 enum UTTKind {
5997#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
5998#include "clang/Basic/TransformTypeTraits.def"
5999 };
6000
6001private:
6002 /// The untransformed type.
6003 QualType BaseType;
6004
6005 /// The transformed type if not dependent, otherwise the same as BaseType.
6006 QualType UnderlyingType;
6007
6008 UTTKind UKind;
6009
6010protected:
6011 friend class ASTContext;
6012
6013 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
6014 QualType CanonicalTy);
6015
6016public:
6017 bool isSugared() const { return !isDependentType(); }
6018 QualType desugar() const { return UnderlyingType; }
6019
6020 QualType getUnderlyingType() const { return UnderlyingType; }
6021 QualType getBaseType() const { return BaseType; }
6022
6023 UTTKind getUTTKind() const { return UKind; }
6024
6025 static bool classof(const Type *T) {
6026 return T->getTypeClass() == UnaryTransform;
6027 }
6028};
6029
6030/// Internal representation of canonical, dependent
6031/// __underlying_type(type) types.
6032///
6033/// This class is used internally by the ASTContext to manage
6034/// canonical, dependent types, only. Clients will only see instances
6035/// of this class via UnaryTransformType nodes.
6037 public llvm::FoldingSetNode {
6038public:
6040 UTTKind UKind);
6041
6042 void Profile(llvm::FoldingSetNodeID &ID) {
6043 Profile(ID, getBaseType(), getUTTKind());
6044 }
6045
6046 static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType,
6047 UTTKind UKind) {
6048 ID.AddPointer(BaseType.getAsOpaquePtr());
6049 ID.AddInteger((unsigned)UKind);
6050 }
6051};
6052
6053class TagType : public Type {
6054 friend class ASTReader;
6055 template <class T> friend class serialization::AbstractTypeReader;
6056
6057 /// Stores the TagDecl associated with this type. The decl may point to any
6058 /// TagDecl that declares the entity.
6059 TagDecl *decl;
6060
6061protected:
6062 TagType(TypeClass TC, const TagDecl *D, QualType can);
6063
6064public:
6065 TagDecl *getDecl() const;
6066
6067 /// Determines whether this type is in the process of being defined.
6068 bool isBeingDefined() const;
6069
6070 static bool classof(const Type *T) {
6071 return T->getTypeClass() == Enum || T->getTypeClass() == Record;
6072 }
6073};
6074
6075/// A helper class that allows the use of isa/cast/dyncast
6076/// to detect TagType objects of structs/unions/classes.
6077class RecordType : public TagType {
6078protected:
6079 friend class ASTContext; // ASTContext creates these.
6080
6081 explicit RecordType(const RecordDecl *D)
6082 : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {}
6084 : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {}
6085
6086public:
6088 return reinterpret_cast<RecordDecl*>(TagType::getDecl());
6089 }
6090
6091 /// Recursively check all fields in the record for const-ness. If any field
6092 /// is declared const, return true. Otherwise, return false.
6093 bool hasConstFields() const;
6094
6095 bool isSugared() const { return false; }
6096 QualType desugar() const { return QualType(this, 0); }
6097
6098 static bool classof(const Type *T) { return T->getTypeClass() == Record; }
6099};
6100
6101/// A helper class that allows the use of isa/cast/dyncast
6102/// to detect TagType objects of enums.
6103class EnumType : public TagType {
6104 friend class ASTContext; // ASTContext creates these.
6105
6106 explicit EnumType(const EnumDecl *D)
6107 : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {}
6108
6109public:
6111 return reinterpret_cast<EnumDecl*>(TagType::getDecl());
6112 }
6113
6114 bool isSugared() const { return false; }
6115 QualType desugar() const { return QualType(this, 0); }
6116
6117 static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
6118};
6119
6120/// An attributed type is a type to which a type attribute has been applied.
6121///
6122/// The "modified type" is the fully-sugared type to which the attributed
6123/// type was applied; generally it is not canonically equivalent to the
6124/// attributed type. The "equivalent type" is the minimally-desugared type
6125/// which the type is canonically equivalent to.
6126///
6127/// For example, in the following attributed type:
6128/// int32_t __attribute__((vector_size(16)))
6129/// - the modified type is the TypedefType for int32_t
6130/// - the equivalent type is VectorType(16, int32_t)
6131/// - the canonical type is VectorType(16, int)
6132class AttributedType : public Type, public llvm::FoldingSetNode {
6133public:
6135
6136private:
6137 friend class ASTContext; // ASTContext creates these
6138
6139 const Attr *Attribute;
6140
6141 QualType ModifiedType;
6142 QualType EquivalentType;
6143
6144 AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
6145 QualType equivalent)
6146 : AttributedType(canon, attrKind, nullptr, modified, equivalent) {}
6147
6148 AttributedType(QualType canon, const Attr *attr, QualType modified,
6149 QualType equivalent);
6150
6151private:
6152 AttributedType(QualType canon, attr::Kind attrKind, const Attr *attr,
6153 QualType modified, QualType equivalent);
6154
6155public:
6157 return static_cast<Kind>(AttributedTypeBits.AttrKind);
6158 }
6159
6160 const Attr *getAttr() const { return Attribute; }
6161
6162 QualType getModifiedType() const { return ModifiedType; }
6163 QualType getEquivalentType() const { return EquivalentType; }
6164
6165 bool isSugared() const { return true; }
6166 QualType desugar() const { return getEquivalentType(); }
6167
6168 /// Does this attribute behave like a type qualifier?
6169 ///
6170 /// A type qualifier adjusts a type to provide specialized rules for
6171 /// a specific object, like the standard const and volatile qualifiers.
6172 /// This includes attributes controlling things like nullability,
6173 /// address spaces, and ARC ownership. The value of the object is still
6174 /// largely described by the modified type.
6175 ///
6176 /// In contrast, many type attributes "rewrite" their modified type to
6177 /// produce a fundamentally different type, not necessarily related in any
6178 /// formalizable way to the original type. For example, calling convention
6179 /// and vector attributes are not simple type qualifiers.
6180 ///
6181 /// Type qualifiers are often, but not always, reflected in the canonical
6182 /// type.
6183 bool isQualifier() const;
6184
6185 bool isMSTypeSpec() const;
6186
6187 bool isWebAssemblyFuncrefSpec() const;
6188
6189 bool isCallingConv() const;
6190
6191 std::optional<NullabilityKind> getImmediateNullability() const;
6192
6193 /// Strip off the top-level nullability annotation on the given
6194 /// type, if it's there.
6195 ///
6196 /// \param T The type to strip. If the type is exactly an
6197 /// AttributedType specifying nullability (without looking through
6198 /// type sugar), the nullability is returned and this type changed
6199 /// to the underlying modified type.
6200 ///
6201 /// \returns the top-level nullability, if present.
6202 static std::optional<NullabilityKind> stripOuterNullability(QualType &T);
6203
6204 void Profile(llvm::FoldingSetNodeID &ID) {
6205 Profile(ID, getAttrKind(), ModifiedType, EquivalentType, Attribute);
6206 }
6207
6208 static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind,
6209 QualType modified, QualType equivalent,
6210 const Attr *attr) {
6211 ID.AddInteger(attrKind);
6212 ID.AddPointer(modified.getAsOpaquePtr());
6213 ID.AddPointer(equivalent.getAsOpaquePtr());
6214 ID.AddPointer(attr);
6215 }
6216
6217 static bool classof(const Type *T) {
6218 return T->getTypeClass() == Attributed;
6219 }
6220};
6221
6222class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
6223private:
6224 friend class ASTContext; // ASTContext creates these
6225
6226 QualType WrappedType;
6227 const BTFTypeTagAttr *BTFAttr;
6228
6229 BTFTagAttributedType(QualType Canon, QualType Wrapped,
6230 const BTFTypeTagAttr *BTFAttr)
6231 : Type(BTFTagAttributed, Canon, Wrapped->getDependence()),
6232 WrappedType(Wrapped), BTFAttr(BTFAttr) {}
6233
6234public:
6235 QualType getWrappedType() const { return WrappedType; }
6236 const BTFTypeTagAttr *getAttr() const { return BTFAttr; }
6237
6238 bool isSugared() const { return true; }
6239 QualType desugar() const { return getWrappedType(); }
6240
6241 void Profile(llvm::FoldingSetNodeID &ID) {
6242 Profile(ID, WrappedType, BTFAttr);
6243 }
6244
6245 static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
6246 const BTFTypeTagAttr *BTFAttr) {
6247 ID.AddPointer(Wrapped.getAsOpaquePtr());
6248 ID.AddPointer(BTFAttr);
6249 }
6250
6251 static bool classof(const Type *T) {
6252 return T->getTypeClass() == BTFTagAttributed;
6253 }
6254};
6255
6256class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
6257public:
6258 struct Attributes {
6259 // Data gathered from HLSL resource attributes
6260 llvm::dxil::ResourceClass ResourceClass;
6261
6262 LLVM_PREFERRED_TYPE(bool)
6263 uint8_t IsROV : 1;
6264
6265 LLVM_PREFERRED_TYPE(bool)
6266 uint8_t RawBuffer : 1;
6267
6268 Attributes(llvm::dxil::ResourceClass ResourceClass, bool IsROV,
6269 bool RawBuffer)
6270 : ResourceClass(ResourceClass), IsROV(IsROV), RawBuffer(RawBuffer) {}
6271
6272 Attributes() : Attributes(llvm::dxil::ResourceClass::UAV, false, false) {}
6273
6274 friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
6275 return std::tie(LHS.ResourceClass, LHS.IsROV, LHS.RawBuffer) ==
6276 std::tie(RHS.ResourceClass, RHS.IsROV, RHS.RawBuffer);
6277 }
6278 friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
6279 return !(LHS == RHS);
6280 }
6281 };
6282
6283private:
6284 friend class ASTContext; // ASTContext creates these
6285
6286 QualType WrappedType;
6287 QualType ContainedType;
6288 const Attributes Attrs;
6289
6290 HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
6291 const Attributes &Attrs)
6292 : Type(HLSLAttributedResource, QualType(),
6293 Contained.isNull() ? TypeDependence::None
6294 : Contained->getDependence()),
6295 WrappedType(Wrapped), ContainedType(Contained), Attrs(Attrs) {}
6296
6297public:
6298 QualType getWrappedType() const { return WrappedType; }
6299 QualType getContainedType() const { return ContainedType; }
6300 bool hasContainedType() const { return !ContainedType.isNull(); }
6301 const Attributes &getAttrs() const { return Attrs; }
6302
6303 bool isSugared() const { return false; }
6304 QualType desugar() const { return QualType(this, 0); }
6305
6306 void Profile(llvm::FoldingSetNodeID &ID) {
6307 Profile(ID, WrappedType, ContainedType, Attrs);
6308 }
6309
6310 static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
6311 QualType Contained, const Attributes &Attrs) {
6312 ID.AddPointer(Wrapped.getAsOpaquePtr());
6313 ID.AddPointer(Contained.getAsOpaquePtr());
6314 ID.AddInteger(static_cast<uint32_t>(Attrs.ResourceClass));
6315 ID.AddBoolean(Attrs.IsROV);
6316 ID.AddBoolean(Attrs.RawBuffer);
6317 }
6318
6319 static bool classof(const Type *T) {
6320 return T->getTypeClass() == HLSLAttributedResource;
6321 }
6322
6323 // Returns handle type from HLSL resource, if the type is a resource
6324 static const HLSLAttributedResourceType *
6325 findHandleTypeOnResource(const Type *RT);
6326};
6327
6328class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
6329 friend class ASTContext; // ASTContext creates these
6330
6331 // The associated TemplateTypeParmDecl for the non-canonical type.
6332 TemplateTypeParmDecl *TTPDecl;
6333
6334 TemplateTypeParmType(unsigned D, unsigned I, bool PP,
6335 TemplateTypeParmDecl *TTPDecl, QualType Canon)
6336 : Type(TemplateTypeParm, Canon,
6337 TypeDependence::DependentInstantiation |
6338 (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)),
6339 TTPDecl(TTPDecl) {
6340 assert(!TTPDecl == Canon.isNull());
6341 TemplateTypeParmTypeBits.Depth = D;
6342 TemplateTypeParmTypeBits.Index = I;
6343 TemplateTypeParmTypeBits.ParameterPack = PP;
6344 }
6345
6346public:
6347 unsigned getDepth() const { return TemplateTypeParmTypeBits.Depth; }
6348 unsigned getIndex() const { return TemplateTypeParmTypeBits.Index; }
6349 bool isParameterPack() const {
6350 return TemplateTypeParmTypeBits.ParameterPack;
6351 }
6352
6353 TemplateTypeParmDecl *getDecl() const { return TTPDecl; }
6354
6356
6357 bool isSugared() const { return false; }
6358 QualType desugar() const { return QualType(this, 0); }
6359
6360 void Profile(llvm::FoldingSetNodeID &ID) {
6361 Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl());
6362 }
6363
6364 static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth,
6365 unsigned Index, bool ParameterPack,
6366 TemplateTypeParmDecl *TTPDecl) {
6367 ID.AddInteger(Depth);
6368 ID.AddInteger(Index);
6369 ID.AddBoolean(ParameterPack);
6370 ID.AddPointer(TTPDecl);
6371 }
6372
6373 static bool classof(const Type *T) {
6374 return T->getTypeClass() == TemplateTypeParm;
6375 }
6376};
6377
6378/// Represents the result of substituting a type for a template
6379/// type parameter.
6380///
6381/// Within an instantiated template, all template type parameters have
6382/// been replaced with these. They are used solely to record that a
6383/// type was originally written as a template type parameter;
6384/// therefore they are never canonical.
6386 : public Type,
6387 public llvm::FoldingSetNode,
6388 private llvm::TrailingObjects<SubstTemplateTypeParmType, QualType> {
6389 friend class ASTContext;
6390 friend class llvm::TrailingObjects<SubstTemplateTypeParmType, QualType>;
6391
6392 Decl *AssociatedDecl;
6393
6394 SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
6395 unsigned Index, std::optional<unsigned> PackIndex,
6397
6398public:
6399 /// Gets the type that was substituted for the template
6400 /// parameter.
6402 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
6403 ? *getTrailingObjects<QualType>()
6404 : getCanonicalTypeInternal();
6405 }
6406
6407 /// A template-like entity which owns the whole pattern being substituted.
6408 /// This will usually own a set of template parameters, or in some
6409 /// cases might even be a template parameter itself.
6410 Decl *getAssociatedDecl() const { return AssociatedDecl; }
6411
6412 /// Gets the template parameter declaration that was substituted for.
6414
6415 /// Returns the index of the replaced parameter in the associated declaration.
6416 /// This should match the result of `getReplacedParameter()->getIndex()`.
6417 unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
6418
6419 std::optional<unsigned> getPackIndex() const {
6420 if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
6421 return std::nullopt;
6422 return SubstTemplateTypeParmTypeBits.PackIndex - 1;
6423 }
6424
6426 return static_cast<SubstTemplateTypeParmTypeFlag>(
6427 SubstTemplateTypeParmTypeBits.SubstitutionFlag);
6428 }
6429
6430 bool isSugared() const { return true; }
6431 QualType desugar() const { return getReplacementType(); }
6432
6433 void Profile(llvm::FoldingSetNodeID &ID) {
6434 Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
6435 getPackIndex(), getSubstitutionFlag());
6436 }
6437
6438 static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
6439 const Decl *AssociatedDecl, unsigned Index,
6440 std::optional<unsigned> PackIndex,
6442 Replacement.Profile(ID);
6443 ID.AddPointer(AssociatedDecl);
6444 ID.AddInteger(Index);
6445 ID.AddInteger(PackIndex ? *PackIndex - 1 : 0);
6446 ID.AddInteger(llvm::to_underlying(Flag));
6447 assert((Flag != SubstTemplateTypeParmTypeFlag::ExpandPacksInPlace ||
6448 PackIndex) &&
6449 "ExpandPacksInPlace needs a valid PackIndex");
6450 }
6451
6452 static bool classof(const Type *T) {
6453 return T->getTypeClass() == SubstTemplateTypeParm;
6454 }
6455};
6456
6457/// Represents the result of substituting a set of types for a template
6458/// type parameter pack.
6459///
6460/// When a pack expansion in the source code contains multiple parameter packs
6461/// and those parameter packs correspond to different levels of template
6462/// parameter lists, this type node is used to represent a template type
6463/// parameter pack from an outer level, which has already had its argument pack
6464/// substituted but that still lives within a pack expansion that itself
6465/// could not be instantiated. When actually performing a substitution into
6466/// that pack expansion (e.g., when all template parameters have corresponding
6467/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
6468/// at the current pack substitution index.
6469class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
6470 friend class ASTContext;
6471
6472 /// A pointer to the set of template arguments that this
6473 /// parameter pack is instantiated with.
6474 const TemplateArgument *Arguments;
6475
6476 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
6477
6478 SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
6479 unsigned Index, bool Final,
6480 const TemplateArgument &ArgPack);
6481
6482public:
6484
6485 /// A template-like entity which owns the whole pattern being substituted.
6486 /// This will usually own a set of template parameters, or in some
6487 /// cases might even be a template parameter itself.
6488 Decl *getAssociatedDecl() const;
6489
6490 /// Gets the template parameter declaration that was substituted for.
6492
6493 /// Returns the index of the replaced parameter in the associated declaration.
6494 /// This should match the result of `getReplacedParameter()->getIndex()`.
6495 unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
6496
6497 // When true the substitution will be 'Final' (subst node won't be placed).
6498 bool getFinal() const;
6499
6500 unsigned getNumArgs() const {
6501 return SubstTemplateTypeParmPackTypeBits.NumArgs;
6502 }
6503
6504 bool isSugared() const { return false; }
6505 QualType desugar() const { return QualType(this, 0); }
6506
6507 TemplateArgument getArgumentPack() const;
6508
6509 void Profile(llvm::FoldingSetNodeID &ID);
6510 static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
6511 unsigned Index, bool Final,
6512 const TemplateArgument &ArgPack);
6513
6514 static bool classof(const Type *T) {
6515 return T->getTypeClass() == SubstTemplateTypeParmPack;
6516 }
6517};
6518
6519/// Common base class for placeholders for types that get replaced by
6520/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
6521/// class template types, and constrained type names.
6522///
6523/// These types are usually a placeholder for a deduced type. However, before
6524/// the initializer is attached, or (usually) if the initializer is
6525/// type-dependent, there is no deduced type and the type is canonical. In
6526/// the latter case, it is also a dependent type.
6527class DeducedType : public Type {
6528 QualType DeducedAsType;
6529
6530protected:
6531 DeducedType(TypeClass TC, QualType DeducedAsType,
6532 TypeDependence ExtraDependence, QualType Canon)
6533 : Type(TC, Canon,
6534 ExtraDependence | (DeducedAsType.isNull()
6536 : DeducedAsType->getDependence() &
6537 ~TypeDependence::VariablyModified)),
6538 DeducedAsType(DeducedAsType) {}
6539
6540public:
6541 bool isSugared() const { return !DeducedAsType.isNull(); }
6543 return isSugared() ? DeducedAsType : QualType(this, 0);
6544 }
6545
6546 /// Get the type deduced for this placeholder type, or null if it
6547 /// has not been deduced.
6548 QualType getDeducedType() const { return DeducedAsType; }
6549 bool isDeduced() const {
6550 return !DeducedAsType.isNull() || isDependentType();
6551 }
6552
6553 static bool classof(const Type *T) {
6554 return T->getTypeClass() == Auto ||
6555 T->getTypeClass() == DeducedTemplateSpecialization;
6556 }
6557};
6558
6559/// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
6560/// by a type-constraint.
6561class AutoType : public DeducedType {
6562 friend class ASTContext; // ASTContext creates these
6563
6564 ConceptDecl *TypeConstraintConcept;
6565
6566 AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword,
6567 TypeDependence ExtraDependence, QualType Canon, ConceptDecl *CD,
6568 ArrayRef<TemplateArgument> TypeConstraintArgs);
6569
6570public:
6572 return {reinterpret_cast<const TemplateArgument *>(this + 1),
6573 AutoTypeBits.NumArgs};
6574 }
6575
6577 return TypeConstraintConcept;
6578 }
6579
6580 bool isConstrained() const {
6581 return TypeConstraintConcept != nullptr;
6582 }
6583
6584 bool isDecltypeAuto() const {
6585 return getKeyword() == AutoTypeKeyword::DecltypeAuto;
6586 }
6587
6588 bool isGNUAutoType() const {
6589 return getKeyword() == AutoTypeKeyword::GNUAutoType;
6590 }
6591
6593 return (AutoTypeKeyword)AutoTypeBits.Keyword;
6594 }
6595
6596 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
6597 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6598 QualType Deduced, AutoTypeKeyword Keyword,
6599 bool IsDependent, ConceptDecl *CD,
6600 ArrayRef<TemplateArgument> Arguments);
6601
6602 static bool classof(const Type *T) {
6603 return T->getTypeClass() == Auto;
6604 }
6605};
6606
6607/// Represents a C++17 deduced template specialization type.
6609 public llvm::FoldingSetNode {
6610 friend class ASTContext; // ASTContext creates these
6611
6612 /// The name of the template whose arguments will be deduced.
6613 TemplateName Template;
6614
6616 QualType DeducedAsType,
6617 bool IsDeducedAsDependent, QualType Canon)
6618 : DeducedType(DeducedTemplateSpecialization, DeducedAsType,
6619 toTypeDependence(Template.getDependence()) |
6620 (IsDeducedAsDependent
6621 ? TypeDependence::DependentInstantiation
6622 : TypeDependence::None),
6623 Canon),
6624 Template(Template) {}
6625
6626public:
6627 /// Retrieve the name of the template that we are deducing.
6628 TemplateName getTemplateName() const { return Template;}
6629
6630 void Profile(llvm::FoldingSetNodeID &ID) const {
6631 Profile(ID, getTemplateName(), getDeducedType(), isDependentType());
6632 }
6633
6634 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template,
6635 QualType Deduced, bool IsDependent) {
6636 Template.Profile(ID);
6637 Deduced.Profile(ID);
6638 ID.AddBoolean(IsDependent || Template.isDependent());
6639 }
6640
6641 static bool classof(const Type *T) {
6642 return T->getTypeClass() == DeducedTemplateSpecialization;
6643 }
6644};
6645
6646/// Represents a type template specialization; the template
6647/// must be a class template, a type alias template, or a template
6648/// template parameter. A template which cannot be resolved to one of
6649/// these, e.g. because it is written with a dependent scope
6650/// specifier, is instead represented as a
6651/// @c DependentTemplateSpecializationType.
6652///
6653/// A non-dependent template specialization type is always "sugar",
6654/// typically for a \c RecordType. For example, a class template
6655/// specialization type of \c vector<int> will refer to a tag type for
6656/// the instantiation \c std::vector<int, std::allocator<int>>
6657///
6658/// Template specializations are dependent if either the template or
6659/// any of the template arguments are dependent, in which case the
6660/// type may also be canonical.
6661///
6662/// Instances of this type are allocated with a trailing array of
6663/// TemplateArguments, followed by a QualType representing the
6664/// non-canonical aliased type when the template is a type alias
6665/// template.
6666class TemplateSpecializationType : public Type, public llvm::FoldingSetNode {
6667 friend class ASTContext; // ASTContext creates these
6668
6669 /// The name of the template being specialized. This is
6670 /// either a TemplateName::Template (in which case it is a
6671 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
6672 /// TypeAliasTemplateDecl*), a
6673 /// TemplateName::SubstTemplateTemplateParmPack, or a
6674 /// TemplateName::SubstTemplateTemplateParm (in which case the
6675 /// replacement must, recursively, be one of these).
6676 TemplateName Template;
6677
6680 QualType Canon,
6681 QualType Aliased);
6682
6683public:
6684 /// Determine whether any of the given template arguments are dependent.
6685 ///
6686 /// The converted arguments should be supplied when known; whether an
6687 /// argument is dependent can depend on the conversions performed on it
6688 /// (for example, a 'const int' passed as a template argument might be
6689 /// dependent if the parameter is a reference but non-dependent if the
6690 /// parameter is an int).
6691 ///
6692 /// Note that the \p Args parameter is unused: this is intentional, to remind
6693 /// the caller that they need to pass in the converted arguments, not the
6694 /// specified arguments.
6695 static bool
6696 anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
6697 ArrayRef<TemplateArgument> Converted);
6698 static bool
6699 anyDependentTemplateArguments(const TemplateArgumentListInfo &,
6700 ArrayRef<TemplateArgument> Converted);
6701 static bool anyInstantiationDependentTemplateArguments(
6703
6704 /// True if this template specialization type matches a current
6705 /// instantiation in the context in which it is found.
6707 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
6708 }
6709
6710 /// Determine if this template specialization type is for a type alias
6711 /// template that has been substituted.
6712 ///
6713 /// Nearly every template specialization type whose template is an alias
6714 /// template will be substituted. However, this is not the case when
6715 /// the specialization contains a pack expansion but the template alias
6716 /// does not have a corresponding parameter pack, e.g.,
6717 ///
6718 /// \code
6719 /// template<typename T, typename U, typename V> struct S;
6720 /// template<typename T, typename U> using A = S<T, int, U>;
6721 /// template<typename... Ts> struct X {
6722 /// typedef A<Ts...> type; // not a type alias
6723 /// };
6724 /// \endcode
6725 bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
6726
6727 /// Get the aliased type, if this is a specialization of a type alias
6728 /// template.
6729 QualType getAliasedType() const;
6730
6731 /// Retrieve the name of the template that we are specializing.
6732 TemplateName getTemplateName() const { return Template; }
6733
6735 return {reinterpret_cast<const TemplateArgument *>(this + 1),
6736 TemplateSpecializationTypeBits.NumArgs};
6737 }
6738
6739 bool isSugared() const {
6740 return !isDependentType() || isCurrentInstantiation() || isTypeAlias();
6741 }
6742
6744 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
6745 }
6746
6747 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
6748 static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
6750 const ASTContext &Context);
6751
6752 static bool classof(const Type *T) {
6753 return T->getTypeClass() == TemplateSpecialization;
6754 }
6755};
6756
6757/// Print a template argument list, including the '<' and '>'
6758/// enclosing the template arguments.
6759void printTemplateArgumentList(raw_ostream &OS,
6760 ArrayRef<TemplateArgument> Args,
6761 const PrintingPolicy &Policy,
6762 const TemplateParameterList *TPL = nullptr);
6763
6764void printTemplateArgumentList(raw_ostream &OS,
6765 ArrayRef<TemplateArgumentLoc> Args,
6766 const PrintingPolicy &Policy,
6767 const TemplateParameterList *TPL = nullptr);
6768
6769void printTemplateArgumentList(raw_ostream &OS,
6770 const TemplateArgumentListInfo &Args,
6771 const PrintingPolicy &Policy,
6772 const TemplateParameterList *TPL = nullptr);
6773
6774/// Make a best-effort determination of whether the type T can be produced by
6775/// substituting Args into the default argument of Param.
6776bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
6777 const NamedDecl *Param,
6778 ArrayRef<TemplateArgument> Args,
6779 unsigned Depth);
6780
6781/// The injected class name of a C++ class template or class
6782/// template partial specialization. Used to record that a type was
6783/// spelled with a bare identifier rather than as a template-id; the
6784/// equivalent for non-templated classes is just RecordType.
6785///
6786/// Injected class name types are always dependent. Template
6787/// instantiation turns these into RecordTypes.
6788///
6789/// Injected class name types are always canonical. This works
6790/// because it is impossible to compare an injected class name type
6791/// with the corresponding non-injected template type, for the same
6792/// reason that it is impossible to directly compare template
6793/// parameters from different dependent contexts: injected class name
6794/// types can only occur within the scope of a particular templated
6795/// declaration, and within that scope every template specialization
6796/// will canonicalize to the injected class name (when appropriate
6797/// according to the rules of the language).
6799 friend class ASTContext; // ASTContext creates these.
6800 friend class ASTNodeImporter;
6801 friend class ASTReader; // FIXME: ASTContext::getInjectedClassNameType is not
6802 // currently suitable for AST reading, too much
6803 // interdependencies.
6804 template <class T> friend class serialization::AbstractTypeReader;
6805
6807
6808 /// The template specialization which this type represents.
6809 /// For example, in
6810 /// template <class T> class A { ... };
6811 /// this is A<T>, whereas in
6812 /// template <class X, class Y> class A<B<X,Y> > { ... };
6813 /// this is A<B<X,Y> >.
6814 ///
6815 /// It is always unqualified, always a template specialization type,
6816 /// and always dependent.
6817 QualType InjectedType;
6818
6820 : Type(InjectedClassName, QualType(),
6821 TypeDependence::DependentInstantiation),
6822 Decl(D), InjectedType(TST) {
6823 assert(isa<TemplateSpecializationType>(TST));
6824 assert(!TST.hasQualifiers());
6825 assert(TST->isDependentType());
6826 }
6827
6828public:
6829 QualType getInjectedSpecializationType() const { return InjectedType; }
6830
6832 return cast<TemplateSpecializationType>(InjectedType.getTypePtr());
6833 }
6834
6836 return getInjectedTST()->getTemplateName();
6837 }
6838
6839 CXXRecordDecl *getDecl() const;
6840
6841 bool isSugared() const { return false; }
6842 QualType desugar() const { return QualType(this, 0); }
6843
6844 static bool classof(const Type *T) {
6845 return T->getTypeClass() == InjectedClassName;
6846 }
6847};
6848
6849/// The elaboration keyword that precedes a qualified type name or
6850/// introduces an elaborated-type-specifier.
6852 /// The "struct" keyword introduces the elaborated-type-specifier.
6853 Struct,
6854
6855 /// The "__interface" keyword introduces the elaborated-type-specifier.
6856 Interface,
6857
6858 /// The "union" keyword introduces the elaborated-type-specifier.
6859 Union,
6860
6861 /// The "class" keyword introduces the elaborated-type-specifier.
6862 Class,
6863
6864 /// The "enum" keyword introduces the elaborated-type-specifier.
6865 Enum,
6866
6867 /// The "typename" keyword precedes the qualified type name, e.g.,
6868 /// \c typename T::type.
6869 Typename,
6870
6871 /// No keyword precedes the qualified type name.
6872 None
6873};
6874
6875/// The kind of a tag type.
6876enum class TagTypeKind {
6877 /// The "struct" keyword.
6878 Struct,
6879
6880 /// The "__interface" keyword.
6881 Interface,
6882
6883 /// The "union" keyword.
6884 Union,
6885
6886 /// The "class" keyword.
6887 Class,
6888
6889 /// The "enum" keyword.
6890 Enum
6891};
6892
6893/// A helper class for Type nodes having an ElaboratedTypeKeyword.
6894/// The keyword in stored in the free bits of the base class.
6895/// Also provides a few static helpers for converting and printing
6896/// elaborated type keyword and tag type kind enumerations.
6897class TypeWithKeyword : public Type {
6898protected:
6901 : Type(tc, Canonical, Dependence) {
6902 TypeWithKeywordBits.Keyword = llvm::to_underlying(Keyword);
6903 }
6904
6905public:
6907 return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword);
6908 }
6909
6910 /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
6911 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
6912
6913 /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
6914 /// It is an error to provide a type specifier which *isn't* a tag kind here.
6915 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
6916
6917 /// Converts a TagTypeKind into an elaborated type keyword.
6918 static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);
6919
6920 /// Converts an elaborated type keyword into a TagTypeKind.
6921 /// It is an error to provide an elaborated type keyword
6922 /// which *isn't* a tag kind here.
6923 static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword);
6924
6925 static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword);
6926
6927 static StringRef getKeywordName(ElaboratedTypeKeyword Keyword);
6928
6930 return getKeywordName(getKeywordForTagTypeKind(Kind));
6931 }
6932
6935};
6936
6937/// Represents a type that was referred to using an elaborated type
6938/// keyword, e.g., struct S, or via a qualified name, e.g., N::M::type,
6939/// or both.
6940///
6941/// This type is used to keep track of a type name as written in the
6942/// source code, including tag keywords and any nested-name-specifiers.
6943/// The type itself is always "sugar", used to express what was written
6944/// in the source code but containing no additional semantic information.
6946 : public TypeWithKeyword,
6947 public llvm::FoldingSetNode,
6948 private llvm::TrailingObjects<ElaboratedType, TagDecl *> {
6949 friend class ASTContext; // ASTContext creates these
6950 friend TrailingObjects;
6951
6952 /// The nested name specifier containing the qualifier.
6954
6955 /// The type that this qualified name refers to.
6956 QualType NamedType;
6957
6958 /// The (re)declaration of this tag type owned by this occurrence is stored
6959 /// as a trailing object if there is one. Use getOwnedTagDecl to obtain
6960 /// it, or obtain a null pointer if there is none.
6961
6963 QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl)
6964 : TypeWithKeyword(Keyword, Elaborated, CanonType,
6965 // Any semantic dependence on the qualifier will have
6966 // been incorporated into NamedType. We still need to
6967 // track syntactic (instantiation / error / pack)
6968 // dependence on the qualifier.
6969 NamedType->getDependence() |
6970 (NNS ? toSyntacticDependence(
6971 toTypeDependence(NNS->getDependence()))
6972 : TypeDependence::None)),
6973 NNS(NNS), NamedType(NamedType) {
6974 ElaboratedTypeBits.HasOwnedTagDecl = false;
6975 if (OwnedTagDecl) {
6976 ElaboratedTypeBits.HasOwnedTagDecl = true;
6977 *getTrailingObjects<TagDecl *>() = OwnedTagDecl;
6978 }
6979 }
6980
6981public:
6982 /// Retrieve the qualification on this type.
6983 NestedNameSpecifier *getQualifier() const { return NNS; }
6984
6985 /// Retrieve the type named by the qualified-id.
6986 QualType getNamedType() const { return NamedType; }
6987
6988 /// Remove a single level of sugar.
6989 QualType desugar() const { return getNamedType(); }
6990
6991 /// Returns whether this type directly provides sugar.
6992 bool isSugared() const { return true; }
6993
6994 /// Return the (re)declaration of this type owned by this occurrence of this
6995 /// type, or nullptr if there is none.
6997 return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>()
6998 : nullptr;
6999 }
7000
7001 void Profile(llvm::FoldingSetNodeID &ID) {
7002 Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl());
7003 }
7004
7005 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
7006 NestedNameSpecifier *NNS, QualType NamedType,
7007 TagDecl *OwnedTagDecl) {
7008 ID.AddInteger(llvm::to_underlying(Keyword));
7009 ID.AddPointer(NNS);
7010 NamedType.Profile(ID);
7011 ID.AddPointer(OwnedTagDecl);
7012 }
7013
7014 static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; }
7015};
7016
7017/// Represents a qualified type name for which the type name is
7018/// dependent.
7019///
7020/// DependentNameType represents a class of dependent types that involve a
7021/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
7022/// name of a type. The DependentNameType may start with a "typename" (for a
7023/// typename-specifier), "class", "struct", "union", or "enum" (for a
7024/// dependent elaborated-type-specifier), or nothing (in contexts where we
7025/// know that we must be referring to a type, e.g., in a base class specifier).
7026/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
7027/// mode, this type is used with non-dependent names to delay name lookup until
7028/// instantiation.
7029class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
7030 friend class ASTContext; // ASTContext creates these
7031
7032 /// The nested name specifier containing the qualifier.
7034
7035 /// The type that this typename specifier refers to.
7036 const IdentifierInfo *Name;
7037
7039 const IdentifierInfo *Name, QualType CanonType)
7040 : TypeWithKeyword(Keyword, DependentName, CanonType,
7041 TypeDependence::DependentInstantiation |
7042 toTypeDependence(NNS->getDependence())),
7043 NNS(NNS), Name(Name) {}
7044
7045public:
7046 /// Retrieve the qualification on this type.
7047 NestedNameSpecifier *getQualifier() const { return NNS; }
7048
7049 /// Retrieve the type named by the typename specifier as an identifier.
7050 ///
7051 /// This routine will return a non-NULL identifier pointer when the
7052 /// form of the original typename was terminated by an identifier,
7053 /// e.g., "typename T::type".
7055 return Name;
7056 }
7057
7058 bool isSugared() const { return false; }
7059 QualType desugar() const { return QualType(this, 0); }
7060
7061 void Profile(llvm::FoldingSetNodeID &ID) {
7062 Profile(ID, getKeyword(), NNS, Name);
7063 }
7064
7065 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
7066 NestedNameSpecifier *NNS, const IdentifierInfo *Name) {
7067 ID.AddInteger(llvm::to_underlying(Keyword));
7068 ID.AddPointer(NNS);
7069 ID.AddPointer(Name);
7070 }
7071
7072 static bool classof(const Type *T) {
7073 return T->getTypeClass() == DependentName;
7074 }
7075};
7076
7077/// Represents a template specialization type whose template cannot be
7078/// resolved, e.g.
7079/// A<T>::template B<T>
7081 public llvm::FoldingSetNode {
7082 friend class ASTContext; // ASTContext creates these
7083
7084 /// The nested name specifier containing the qualifier.
7086
7087 /// The identifier of the template.
7088 const IdentifierInfo *Name;
7089
7092 const IdentifierInfo *Name,
7094 QualType Canon);
7095
7096public:
7097 NestedNameSpecifier *getQualifier() const { return NNS; }
7098 const IdentifierInfo *getIdentifier() const { return Name; }
7099
7101 return {reinterpret_cast<const TemplateArgument *>(this + 1),
7102 DependentTemplateSpecializationTypeBits.NumArgs};
7103 }
7104
7105 bool isSugared() const { return false; }
7106 QualType desugar() const { return QualType(this, 0); }
7107
7108 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
7109 Profile(ID, Context, getKeyword(), NNS, Name, template_arguments());
7110 }
7111
7112 static void Profile(llvm::FoldingSetNodeID &ID,
7113 const ASTContext &Context,
7114 ElaboratedTypeKeyword Keyword,
7115 NestedNameSpecifier *Qualifier,
7116 const IdentifierInfo *Name,
7118
7119 static bool classof(const Type *T) {
7120 return T->getTypeClass() == DependentTemplateSpecialization;
7121 }
7122};
7123
7124/// Represents a pack expansion of types.
7125///
7126/// Pack expansions are part of C++11 variadic templates. A pack
7127/// expansion contains a pattern, which itself contains one or more
7128/// "unexpanded" parameter packs. When instantiated, a pack expansion
7129/// produces a series of types, each instantiated from the pattern of
7130/// the expansion, where the Ith instantiation of the pattern uses the
7131/// Ith arguments bound to each of the unexpanded parameter packs. The
7132/// pack expansion is considered to "expand" these unexpanded
7133/// parameter packs.
7134///
7135/// \code
7136/// template<typename ...Types> struct tuple;
7137///
7138/// template<typename ...Types>
7139/// struct tuple_of_references {
7140/// typedef tuple<Types&...> type;
7141/// };
7142/// \endcode
7143///
7144/// Here, the pack expansion \c Types&... is represented via a
7145/// PackExpansionType whose pattern is Types&.
7146class PackExpansionType : public Type, public llvm::FoldingSetNode {
7147 friend class ASTContext; // ASTContext creates these
7148
7149 /// The pattern of the pack expansion.
7150 QualType Pattern;
7151
7152 PackExpansionType(QualType Pattern, QualType Canon,
7153 std::optional<unsigned> NumExpansions)
7154 : Type(PackExpansion, Canon,
7155 (Pattern->getDependence() | TypeDependence::Dependent |
7156 TypeDependence::Instantiation) &
7157 ~TypeDependence::UnexpandedPack),
7158 Pattern(Pattern) {
7159 PackExpansionTypeBits.NumExpansions =
7160 NumExpansions ? *NumExpansions + 1 : 0;
7161 }
7162
7163public:
7164 /// Retrieve the pattern of this pack expansion, which is the
7165 /// type that will be repeatedly instantiated when instantiating the
7166 /// pack expansion itself.
7167 QualType getPattern() const { return Pattern; }
7168
7169 /// Retrieve the number of expansions that this pack expansion will
7170 /// generate, if known.
7171 std::optional<unsigned> getNumExpansions() const {
7172 if (PackExpansionTypeBits.NumExpansions)
7173 return PackExpansionTypeBits.NumExpansions - 1;
7174 return std::nullopt;
7175 }
7176
7177 bool isSugared() const { return false; }
7178 QualType desugar() const { return QualType(this, 0); }
7179
7180 void Profile(llvm::FoldingSetNodeID &ID) {
7181 Profile(ID, getPattern(), getNumExpansions());
7182 }
7183
7184 static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern,
7185 std::optional<unsigned> NumExpansions) {
7186 ID.AddPointer(Pattern.getAsOpaquePtr());
7187 ID.AddBoolean(NumExpansions.has_value());
7188 if (NumExpansions)
7189 ID.AddInteger(*NumExpansions);
7190 }
7191
7192 static bool classof(const Type *T) {
7193 return T->getTypeClass() == PackExpansion;
7194 }
7195};
7196
7197/// This class wraps the list of protocol qualifiers. For types that can
7198/// take ObjC protocol qualifers, they can subclass this class.
7199template <class T>
7201protected:
7203
7205 return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
7206 }
7207
7209 return static_cast<T*>(this)->getProtocolStorageImpl();
7210 }
7211
7212 void setNumProtocols(unsigned N) {
7213 static_cast<T*>(this)->setNumProtocolsImpl(N);
7214 }
7215
7217 setNumProtocols(protocols.size());
7218 assert(getNumProtocols() == protocols.size() &&
7219 "bitfield overflow in protocol count");
7220 if (!protocols.empty())
7221 memcpy(getProtocolStorage(), protocols.data(),
7222 protocols.size() * sizeof(ObjCProtocolDecl*));
7223 }
7224
7225public:
7227 using qual_range = llvm::iterator_range<qual_iterator>;
7228
7229 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
7230 qual_iterator qual_begin() const { return getProtocolStorage(); }
7231 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
7232
7233 bool qual_empty() const { return getNumProtocols() == 0; }
7234
7235 /// Return the number of qualifying protocols in this type, or 0 if
7236 /// there are none.
7237 unsigned getNumProtocols() const {
7238 return static_cast<const T*>(this)->getNumProtocolsImpl();
7239 }
7240
7241 /// Fetch a protocol by index.
7242 ObjCProtocolDecl *getProtocol(unsigned I) const {
7243 assert(I < getNumProtocols() && "Out-of-range protocol access");
7244 return qual_begin()[I];
7245 }
7246
7247 /// Retrieve all of the protocol qualifiers.
7249 return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
7250 }
7251};
7252
7253/// Represents a type parameter type in Objective C. It can take
7254/// a list of protocols.
7256 public ObjCProtocolQualifiers<ObjCTypeParamType>,
7257 public llvm::FoldingSetNode {
7258 friend class ASTContext;
7260
7261 /// The number of protocols stored on this type.
7262 unsigned NumProtocols : 6;
7263
7264 ObjCTypeParamDecl *OTPDecl;
7265
7266 /// The protocols are stored after the ObjCTypeParamType node. In the
7267 /// canonical type, the list of protocols are sorted alphabetically
7268 /// and uniqued.
7269 ObjCProtocolDecl **getProtocolStorageImpl();
7270
7271 /// Return the number of qualifying protocols in this interface type,
7272 /// or 0 if there are none.
7273 unsigned getNumProtocolsImpl() const {
7274 return NumProtocols;
7275 }
7276
7277 void setNumProtocolsImpl(unsigned N) {
7278 NumProtocols = N;
7279 }
7280
7281 ObjCTypeParamType(const ObjCTypeParamDecl *D,
7282 QualType can,
7283 ArrayRef<ObjCProtocolDecl *> protocols);
7284
7285public:
7286 bool isSugared() const { return true; }
7287 QualType desugar() const { return getCanonicalTypeInternal(); }
7288
7289 static bool classof(const Type *T) {
7290 return T->getTypeClass() == ObjCTypeParam;
7291 }
7292
7293 void Profile(llvm::FoldingSetNodeID &ID);
7294 static void Profile(llvm::FoldingSetNodeID &ID,
7295 const ObjCTypeParamDecl *OTPDecl,
7296 QualType CanonicalType,
7298
7299 ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
7300};
7301
7302/// Represents a class type in Objective C.
7303///
7304/// Every Objective C type is a combination of a base type, a set of
7305/// type arguments (optional, for parameterized classes) and a list of
7306/// protocols.
7307///
7308/// Given the following declarations:
7309/// \code
7310/// \@class C<T>;
7311/// \@protocol P;
7312/// \endcode
7313///
7314/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
7315/// with base C and no protocols.
7316///
7317/// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
7318/// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
7319/// protocol list.
7320/// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
7321/// and protocol list [P].
7322///
7323/// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
7324/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
7325/// and no protocols.
7326///
7327/// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
7328/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
7329/// this should get its own sugar class to better represent the source.
7330class ObjCObjectType : public Type,
7331 public ObjCProtocolQualifiers<ObjCObjectType> {
7333
7334 // ObjCObjectType.NumTypeArgs - the number of type arguments stored
7335 // after the ObjCObjectPointerType node.
7336 // ObjCObjectType.NumProtocols - the number of protocols stored
7337 // after the type arguments of ObjCObjectPointerType node.
7338 //
7339 // These protocols are those written directly on the type. If
7340 // protocol qualifiers ever become additive, the iterators will need
7341 // to get kindof complicated.
7342 //
7343 // In the canonical object type, these are sorted alphabetically
7344 // and uniqued.
7345
7346 /// Either a BuiltinType or an InterfaceType or sugar for either.
7347 QualType BaseType;
7348
7349 /// Cached superclass type.
7350 mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
7351 CachedSuperClassType;
7352
7353 QualType *getTypeArgStorage();
7354 const QualType *getTypeArgStorage() const {
7355 return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
7356 }
7357
7358 ObjCProtocolDecl **getProtocolStorageImpl();
7359 /// Return the number of qualifying protocols in this interface type,
7360 /// or 0 if there are none.
7361 unsigned getNumProtocolsImpl() const {
7362 return ObjCObjectTypeBits.NumProtocols;
7363 }
7364 void setNumProtocolsImpl(unsigned N) {
7365 ObjCObjectTypeBits.NumProtocols = N;
7366 }
7367
7368protected:
7370
7372 ArrayRef<QualType> typeArgs,
7374 bool isKindOf);
7375
7377 : Type(ObjCInterface, QualType(), TypeDependence::None),
7378 BaseType(QualType(this_(), 0)) {
7379 ObjCObjectTypeBits.NumProtocols = 0;
7380 ObjCObjectTypeBits.NumTypeArgs = 0;
7381 ObjCObjectTypeBits.IsKindOf = 0;
7382 }
7383
7384 void computeSuperClassTypeSlow() const;
7385
7386public:
7387 /// Gets the base type of this object type. This is always (possibly
7388 /// sugar for) one of:
7389 /// - the 'id' builtin type (as opposed to the 'id' type visible to the
7390 /// user, which is a typedef for an ObjCObjectPointerType)
7391 /// - the 'Class' builtin type (same caveat)
7392 /// - an ObjCObjectType (currently always an ObjCInterfaceType)
7393 QualType getBaseType() const { return BaseType; }
7394
7395 bool isObjCId() const {
7396 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
7397 }
7398
7399 bool isObjCClass() const {
7400 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
7401 }
7402
7403 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
7404 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
7406 if (!qual_empty()) return false;
7407 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
7408 return T->getKind() == BuiltinType::ObjCId ||
7409 T->getKind() == BuiltinType::ObjCClass;
7410 return false;
7411 }
7412 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
7413 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
7414
7415 /// Gets the interface declaration for this object type, if the base type
7416 /// really is an interface.
7417 ObjCInterfaceDecl *getInterface() const;
7418
7419 /// Determine whether this object type is "specialized", meaning
7420 /// that it has type arguments.
7421 bool isSpecialized() const;
7422
7423 /// Determine whether this object type was written with type arguments.
7425 return ObjCObjectTypeBits.NumTypeArgs > 0;
7426 }
7427
7428 /// Determine whether this object type is "unspecialized", meaning
7429 /// that it has no type arguments.
7430 bool isUnspecialized() const { return !isSpecialized(); }
7431
7432 /// Determine whether this object type is "unspecialized" as
7433 /// written, meaning that it has no type arguments.
7434 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
7435
7436 /// Retrieve the type arguments of this object type (semantically).
7437 ArrayRef<QualType> getTypeArgs() const;
7438
7439 /// Retrieve the type arguments of this object type as they were
7440 /// written.
7442 return llvm::ArrayRef(getTypeArgStorage(), ObjCObjectTypeBits.NumTypeArgs);
7443 }
7444
7445 /// Whether this is a "__kindof" type as written.
7446 bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
7447
7448 /// Whether this ia a "__kindof" type (semantically).
7449 bool isKindOfType() const;
7450
7451 /// Retrieve the type of the superclass of this object type.
7452 ///
7453 /// This operation substitutes any type arguments into the
7454 /// superclass of the current class type, potentially producing a
7455 /// specialization of the superclass type. Produces a null type if
7456 /// there is no superclass.
7458 if (!CachedSuperClassType.getInt())
7459 computeSuperClassTypeSlow();
7460
7461 assert(CachedSuperClassType.getInt() && "Superclass not set?");
7462 return QualType(CachedSuperClassType.getPointer(), 0);
7463 }
7464
7465 /// Strip off the Objective-C "kindof" type and (with it) any
7466 /// protocol qualifiers.
7467 QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
7468
7469 bool isSugared() const { return false; }
7470 QualType desugar() const { return QualType(this, 0); }
7471
7472 static bool classof(const Type *T) {
7473 return T->getTypeClass() == ObjCObject ||
7474 T->getTypeClass() == ObjCInterface;
7475 }
7476};
7477
7478/// A class providing a concrete implementation
7479/// of ObjCObjectType, so as to not increase the footprint of
7480/// ObjCInterfaceType. Code outside of ASTContext and the core type
7481/// system should not reference this type.
7482class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
7483 friend class ASTContext;
7484
7485 // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
7486 // will need to be modified.
7487
7489 ArrayRef<QualType> typeArgs,
7491 bool isKindOf)
7492 : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
7493
7494public:
7495 void Profile(llvm::FoldingSetNodeID &ID);
7496 static void Profile(llvm::FoldingSetNodeID &ID,
7497 QualType Base,
7498 ArrayRef<QualType> typeArgs,
7500 bool isKindOf);
7501};
7502
7503inline QualType *ObjCObjectType::getTypeArgStorage() {
7504 return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
7505}
7506
7507inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
7508 return reinterpret_cast<ObjCProtocolDecl**>(
7509 getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
7510}
7511
7512inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
7513 return reinterpret_cast<ObjCProtocolDecl**>(
7514 static_cast<ObjCTypeParamType*>(this)+1);
7515}
7516
7517/// Interfaces are the core concept in Objective-C for object oriented design.
7518/// They basically correspond to C++ classes. There are two kinds of interface
7519/// types: normal interfaces like `NSString`, and qualified interfaces, which
7520/// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
7521///
7522/// ObjCInterfaceType guarantees the following properties when considered
7523/// as a subtype of its superclass, ObjCObjectType:
7524/// - There are no protocol qualifiers. To reinforce this, code which
7525/// tries to invoke the protocol methods via an ObjCInterfaceType will
7526/// fail to compile.
7527/// - It is its own base type. That is, if T is an ObjCInterfaceType*,
7528/// T->getBaseType() == QualType(T, 0).
7530 friend class ASTContext; // ASTContext creates these.
7531 friend class ASTReader;
7532 template <class T> friend class serialization::AbstractTypeReader;
7533
7535
7538 Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
7539
7540public:
7541 /// Get the declaration of this interface.
7542 ObjCInterfaceDecl *getDecl() const;
7543
7544 bool isSugared() const { return false; }
7545 QualType desugar() const { return QualType(this, 0); }
7546
7547 static bool classof(const Type *T) {
7548 return T->getTypeClass() == ObjCInterface;
7549 }
7550
7551 // Nonsense to "hide" certain members of ObjCObjectType within this
7552 // class. People asking for protocols on an ObjCInterfaceType are
7553 // not going to get what they want: ObjCInterfaceTypes are
7554 // guaranteed to have no protocols.
7555 enum {
7560 getProtocol
7562};
7563
7564inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
7565 QualType baseType = getBaseType();
7566 while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) {
7567 if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT))
7568 return T->getDecl();
7569
7570 baseType = ObjT->getBaseType();
7571 }
7572
7573 return nullptr;
7574}
7575
7576/// Represents a pointer to an Objective C object.
7577///
7578/// These are constructed from pointer declarators when the pointee type is
7579/// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
7580/// types are typedefs for these, and the protocol-qualified types 'id<P>'
7581/// and 'Class<P>' are translated into these.
7582///
7583/// Pointers to pointers to Objective C objects are still PointerTypes;
7584/// only the first level of pointer gets it own type implementation.
7585class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
7586 friend class ASTContext; // ASTContext creates these.
7587
7588 QualType PointeeType;
7589
7590 ObjCObjectPointerType(QualType Canonical, QualType Pointee)
7591 : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()),
7592 PointeeType(Pointee) {}
7593
7594public:
7595 /// Gets the type pointed to by this ObjC pointer.
7596 /// The result will always be an ObjCObjectType or sugar thereof.
7597 QualType getPointeeType() const { return PointeeType; }
7598
7599 /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
7600 ///
7601 /// This method is equivalent to getPointeeType() except that
7602 /// it discards any typedefs (or other sugar) between this
7603 /// type and the "outermost" object type. So for:
7604 /// \code
7605 /// \@class A; \@protocol P; \@protocol Q;
7606 /// typedef A<P> AP;
7607 /// typedef A A1;
7608 /// typedef A1<P> A1P;
7609 /// typedef A1P<Q> A1PQ;
7610 /// \endcode
7611 /// For 'A*', getObjectType() will return 'A'.
7612 /// For 'A<P>*', getObjectType() will return 'A<P>'.
7613 /// For 'AP*', getObjectType() will return 'A<P>'.
7614 /// For 'A1*', getObjectType() will return 'A'.
7615 /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
7616 /// For 'A1P*', getObjectType() will return 'A1<P>'.
7617 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
7618 /// adding protocols to a protocol-qualified base discards the
7619 /// old qualifiers (for now). But if it didn't, getObjectType()
7620 /// would return 'A1P<Q>' (and we'd have to make iterating over
7621 /// qualifiers more complicated).
7623 return PointeeType->castAs<ObjCObjectType>();
7624 }
7625
7626 /// If this pointer points to an Objective C
7627 /// \@interface type, gets the type for that interface. Any protocol
7628 /// qualifiers on the interface are ignored.
7629 ///
7630 /// \return null if the base type for this pointer is 'id' or 'Class'
7631 const ObjCInterfaceType *getInterfaceType() const;
7632
7633 /// If this pointer points to an Objective \@interface
7634 /// type, gets the declaration for that interface.
7635 ///
7636 /// \return null if the base type for this pointer is 'id' or 'Class'
7638 return getObjectType()->getInterface();
7639 }
7640
7641 /// True if this is equivalent to the 'id' type, i.e. if
7642 /// its object type is the primitive 'id' type with no protocols.
7643 bool isObjCIdType() const {
7644 return getObjectType()->isObjCUnqualifiedId();
7645 }
7646
7647 /// True if this is equivalent to the 'Class' type,
7648 /// i.e. if its object tive is the primitive 'Class' type with no protocols.
7649 bool isObjCClassType() const {
7650 return getObjectType()->isObjCUnqualifiedClass();
7651 }
7652
7653 /// True if this is equivalent to the 'id' or 'Class' type,
7654 bool isObjCIdOrClassType() const {
7655 return getObjectType()->isObjCUnqualifiedIdOrClass();
7656 }
7657
7658 /// True if this is equivalent to 'id<P>' for some non-empty set of
7659 /// protocols.
7661 return getObjectType()->isObjCQualifiedId();
7662 }
7663
7664 /// True if this is equivalent to 'Class<P>' for some non-empty set of
7665 /// protocols.
7667 return getObjectType()->isObjCQualifiedClass();
7668 }
7669
7670 /// Whether this is a "__kindof" type.
7671 bool isKindOfType() const { return getObjectType()->isKindOfType(); }
7672
7673 /// Whether this type is specialized, meaning that it has type arguments.
7674 bool isSpecialized() const { return getObjectType()->isSpecialized(); }
7675
7676 /// Whether this type is specialized, meaning that it has type arguments.
7678 return getObjectType()->isSpecializedAsWritten();
7679 }
7680
7681 /// Whether this type is unspecialized, meaning that is has no type arguments.
7682 bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
7683
7684 /// Determine whether this object type is "unspecialized" as
7685 /// written, meaning that it has no type arguments.
7686 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
7687
7688 /// Retrieve the type arguments for this type.
7690 return getObjectType()->getTypeArgs();
7691 }
7692
7693 /// Retrieve the type arguments for this type.
7695 return getObjectType()->getTypeArgsAsWritten();
7696 }
7697
7698 /// An iterator over the qualifiers on the object type. Provided
7699 /// for convenience. This will always iterate over the full set of
7700 /// protocols on a type, not just those provided directly.
7702 using qual_range = llvm::iterator_range<qual_iterator>;
7703
7704 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
7705
7707 return getObjectType()->qual_begin();
7708 }
7709
7711 return getObjectType()->qual_end();
7712 }
7713
7714 bool qual_empty() const { return getObjectType()->qual_empty(); }
7715
7716 /// Return the number of qualifying protocols on the object type.
7717 unsigned getNumProtocols() const {
7718 return getObjectType()->getNumProtocols();
7719 }
7720
7721 /// Retrieve a qualifying protocol by index on the object type.
7722 ObjCProtocolDecl *getProtocol(unsigned I) const {
7723 return getObjectType()->getProtocol(I);
7724 }
7725
7726 bool isSugared() const { return false; }
7727 QualType desugar() const { return QualType(this, 0); }
7728
7729 /// Retrieve the type of the superclass of this object pointer type.
7730 ///
7731 /// This operation substitutes any type arguments into the
7732 /// superclass of the current class type, potentially producing a
7733 /// pointer to a specialization of the superclass type. Produces a
7734 /// null type if there is no superclass.
7735 QualType getSuperClassType() const;
7736
7737 /// Strip off the Objective-C "kindof" type and (with it) any
7738 /// protocol qualifiers.
7739 const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
7740 const ASTContext &ctx) const;
7741
7742 void Profile(llvm::FoldingSetNodeID &ID) {
7743 Profile(ID, getPointeeType());
7744 }
7745
7746 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7747 ID.AddPointer(T.getAsOpaquePtr());
7748 }
7749
7750 static bool classof(const Type *T) {
7751 return T->getTypeClass() == ObjCObjectPointer;
7752 }
7753};
7754
7755class AtomicType : public Type, public llvm::FoldingSetNode {
7756 friend class ASTContext; // ASTContext creates these.
7757
7758 QualType ValueType;
7759
7760 AtomicType(QualType ValTy, QualType Canonical)
7761 : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {}
7762
7763public:
7764 /// Gets the type contained by this atomic type, i.e.
7765 /// the type returned by performing an atomic load of this atomic type.
7766 QualType getValueType() const { return ValueType; }
7767
7768 bool isSugared() const { return false; }
7769 QualType desugar() const { return QualType(this, 0); }
7770
7771 void Profile(llvm::FoldingSetNodeID &ID) {
7772 Profile(ID, getValueType());
7773 }
7774
7775 static void Profile(llvm::FoldingSetNodeID &ID, QualType T) {
7776 ID.AddPointer(T.getAsOpaquePtr());
7777 }
7778
7779 static bool classof(const Type *T) {
7780 return T->getTypeClass() == Atomic;
7781 }
7782};
7783
7784/// PipeType - OpenCL20.
7785class PipeType : public Type, public llvm::FoldingSetNode {
7786 friend class ASTContext; // ASTContext creates these.
7787
7788 QualType ElementType;
7789 bool isRead;
7790
7791 PipeType(QualType elemType, QualType CanonicalPtr, bool isRead)
7792 : Type(Pipe, CanonicalPtr, elemType->getDependence()),
7793 ElementType(elemType), isRead(isRead) {}
7794
7795public:
7796 QualType getElementType() const { return ElementType; }
7797
7798 bool isSugared() const { return false; }
7799
7800 QualType desugar() const { return QualType(this, 0); }
7801
7802 void Profile(llvm::FoldingSetNodeID &ID) {
7803 Profile(ID, getElementType(), isReadOnly());
7804 }
7805
7806 static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) {
7807 ID.AddPointer(T.getAsOpaquePtr());
7808 ID.AddBoolean(isRead);
7809 }
7810
7811 static bool classof(const Type *T) {
7812 return T->getTypeClass() == Pipe;
7813 }
7814
7815 bool isReadOnly() const { return isRead; }
7816};
7817
7818/// A fixed int type of a specified bitwidth.
7819class BitIntType final : public Type, public llvm::FoldingSetNode {
7820 friend class ASTContext;
7821 LLVM_PREFERRED_TYPE(bool)
7822 unsigned IsUnsigned : 1;
7823 unsigned NumBits : 24;
7824
7825protected:
7826 BitIntType(bool isUnsigned, unsigned NumBits);
7827
7828public:
7829 bool isUnsigned() const { return IsUnsigned; }
7830 bool isSigned() const { return !IsUnsigned; }
7831 unsigned getNumBits() const { return NumBits; }
7832
7833 bool isSugared() const { return false; }
7834 QualType desugar() const { return QualType(this, 0); }
7835
7836 void Profile(llvm::FoldingSetNodeID &ID) const {
7837 Profile(ID, isUnsigned(), getNumBits());
7838 }
7839
7840 static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned,
7841 unsigned NumBits) {
7842 ID.AddBoolean(IsUnsigned);
7843 ID.AddInteger(NumBits);
7844 }
7845
7846 static bool classof(const Type *T) { return T->getTypeClass() == BitInt; }
7847};
7848
7849class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
7850 friend class ASTContext;
7851 llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
7852
7853protected:
7854 DependentBitIntType(bool IsUnsigned, Expr *NumBits);
7855
7856public:
7857 bool isUnsigned() const;
7858 bool isSigned() const { return !isUnsigned(); }
7859 Expr *getNumBitsExpr() const;
7860
7861 bool isSugared() const { return false; }
7862 QualType desugar() const { return QualType(this, 0); }
7863
7864 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
7865 Profile(ID, Context, isUnsigned(), getNumBitsExpr());
7866 }
7867 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
7868 bool IsUnsigned, Expr *NumBitsExpr);
7869
7870 static bool classof(const Type *T) {
7871 return T->getTypeClass() == DependentBitInt;
7872 }
7873};
7874
7875/// A qualifier set is used to build a set of qualifiers.
7877public:
7879
7880 /// Collect any qualifiers on the given type and return an
7881 /// unqualified type. The qualifiers are assumed to be consistent
7882 /// with those already in the type.
7883 const Type *strip(QualType type) {
7884 addFastQualifiers(type.getLocalFastQualifiers());
7885 if (!type.hasLocalNonFastQualifiers())
7886 return type.getTypePtrUnsafe();
7887
7888 const ExtQuals *extQuals = type.getExtQualsUnsafe();
7889 addConsistentQualifiers(extQuals->getQualifiers());
7890 return extQuals->getBaseType();
7891 }
7892
7893 /// Apply the collected qualifiers to the given type.
7894 QualType apply(const ASTContext &Context, QualType QT) const;
7895
7896 /// Apply the collected qualifiers to the given type.
7897 QualType apply(const ASTContext &Context, const Type* T) const;
7898};
7899
7900/// A container of type source information.
7901///
7902/// A client can read the relevant info using TypeLoc wrappers, e.g:
7903/// @code
7904/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
7905/// TL.getBeginLoc().print(OS, SrcMgr);
7906/// @endcode
7907class alignas(8) TypeSourceInfo {
7908 // Contains a memory block after the class, used for type source information,
7909 // allocated by ASTContext.
7910 friend class ASTContext;
7911
7912 QualType Ty;
7913
7914 TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
7915
7916public:
7917 /// Return the type wrapped by this type source info.
7918 QualType getType() const { return Ty; }
7919
7920 /// Return the TypeLoc wrapper for the type source info.
7921 TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
7922
7923 /// Override the type stored in this TypeSourceInfo. Use with caution!
7924 void overrideType(QualType T) { Ty = T; }
7925};
7926
7927// Inline function definitions.
7928
7929inline SplitQualType SplitQualType::getSingleStepDesugaredType() const {
7930 SplitQualType desugar =
7931 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
7932 desugar.Quals.addConsistentQualifiers(Quals);
7933 return desugar;
7934}
7935
7936inline const Type *QualType::getTypePtr() const {
7937 return getCommonPtr()->BaseType;
7938}
7939
7940inline const Type *QualType::getTypePtrOrNull() const {
7941 return (isNull() ? nullptr : getCommonPtr()->BaseType);
7942}
7943
7944inline bool QualType::isReferenceable() const {
7945 // C++ [defns.referenceable]
7946 // type that is either an object type, a function type that does not have
7947 // cv-qualifiers or a ref-qualifier, or a reference type.
7948 const Type &Self = **this;
7949 if (Self.isObjectType() || Self.isReferenceType())
7950 return true;
7951 if (const auto *F = Self.getAs<FunctionProtoType>())
7952 return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
7953
7954 return false;
7955}
7956
7957inline SplitQualType QualType::split() const {
7958 if (!hasLocalNonFastQualifiers())
7959 return SplitQualType(getTypePtrUnsafe(),
7960 Qualifiers::fromFastMask(getLocalFastQualifiers()));
7961
7962 const ExtQuals *eq = getExtQualsUnsafe();
7963 Qualifiers qs = eq->getQualifiers();
7964 qs.addFastQualifiers(getLocalFastQualifiers());
7965 return SplitQualType(eq->getBaseType(), qs);
7966}
7967
7968inline Qualifiers QualType::getLocalQualifiers() const {
7969 Qualifiers Quals;
7970 if (hasLocalNonFastQualifiers())
7971 Quals = getExtQualsUnsafe()->getQualifiers();
7972 Quals.addFastQualifiers(getLocalFastQualifiers());
7973 return Quals;
7974}
7975
7976inline Qualifiers QualType::getQualifiers() const {
7977 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
7978 quals.addFastQualifiers(getLocalFastQualifiers());
7979 return quals;
7980}
7981
7982inline unsigned QualType::getCVRQualifiers() const {
7983 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
7984 cvr |= getLocalCVRQualifiers();
7985 return cvr;
7986}
7987
7988inline QualType QualType::getCanonicalType() const {
7989 QualType canon = getCommonPtr()->CanonicalType;
7990 return canon.withFastQualifiers(getLocalFastQualifiers());
7991}
7992
7993inline bool QualType::isCanonical() const {
7994 return getTypePtr()->isCanonicalUnqualified();
7995}
7996
7997inline bool QualType::isCanonicalAsParam() const {
7998 if (!isCanonical()) return false;
7999 if (hasLocalQualifiers()) return false;
8000
8001 const Type *T = getTypePtr();
8003 return false;
8004
8005 return !isa<FunctionType>(T) &&
8006 (!isa<ArrayType>(T) || isa<ArrayParameterType>(T));
8007}
8008
8009inline bool QualType::isConstQualified() const {
8010 return isLocalConstQualified() ||
8011 getCommonPtr()->CanonicalType.isLocalConstQualified();
8012}
8013
8014inline bool QualType::isRestrictQualified() const {
8015 return isLocalRestrictQualified() ||
8016 getCommonPtr()->CanonicalType.isLocalRestrictQualified();
8017}
8018
8019
8020inline bool QualType::isVolatileQualified() const {
8021 return isLocalVolatileQualified() ||
8022 getCommonPtr()->CanonicalType.isLocalVolatileQualified();
8023}
8024
8025inline bool QualType::hasQualifiers() const {
8026 return hasLocalQualifiers() ||
8027 getCommonPtr()->CanonicalType.hasLocalQualifiers();
8028}
8029
8030inline QualType QualType::getUnqualifiedType() const {
8031 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
8032 return QualType(getTypePtr(), 0);
8033
8034 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
8035}
8036
8037inline SplitQualType QualType::getSplitUnqualifiedType() const {
8038 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
8039 return split();
8040
8041 return getSplitUnqualifiedTypeImpl(*this);
8042}
8043
8044inline void QualType::removeLocalConst() {
8045 removeLocalFastQualifiers(Qualifiers::Const);
8046}
8047
8048inline void QualType::removeLocalRestrict() {
8049 removeLocalFastQualifiers(Qualifiers::Restrict);
8050}
8051
8052inline void QualType::removeLocalVolatile() {
8053 removeLocalFastQualifiers(Qualifiers::Volatile);
8054}
8055
8056/// Check if this type has any address space qualifier.
8057inline bool QualType::hasAddressSpace() const {
8058 return getQualifiers().hasAddressSpace();
8059}
8060
8061/// Return the address space of this type.
8062inline LangAS QualType::getAddressSpace() const {
8063 return getQualifiers().getAddressSpace();
8064}
8065
8066/// Return the gc attribute of this type.
8067inline Qualifiers::GC QualType::getObjCGCAttr() const {
8068 return getQualifiers().getObjCGCAttr();
8069}
8070
8071inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
8072 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
8073 return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD);
8074 return false;
8075}
8076
8077inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const {
8078 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
8079 return hasNonTrivialToPrimitiveDestructCUnion(RD);
8080 return false;
8081}
8082
8083inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const {
8084 if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl())
8085 return hasNonTrivialToPrimitiveCopyCUnion(RD);
8086 return false;
8087}
8088
8090 if (const auto *PT = t.getAs<PointerType>()) {
8091 if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>())
8092 return FT->getExtInfo();
8093 } else if (const auto *FT = t.getAs<FunctionType>())
8094 return FT->getExtInfo();
8095
8096 return FunctionType::ExtInfo();
8097}
8098
8100 return getFunctionExtInfo(*t);
8101}
8102
8103/// Determine whether this type is more
8104/// qualified than the Other type. For example, "const volatile int"
8105/// is more qualified than "const int", "volatile int", and
8106/// "int". However, it is not more qualified than "const volatile
8107/// int".
8108inline bool QualType::isMoreQualifiedThan(QualType other,
8109 const ASTContext &Ctx) const {
8110 Qualifiers MyQuals = getQualifiers();
8111 Qualifiers OtherQuals = other.getQualifiers();
8112 return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals, Ctx));
8113}
8114
8115/// Determine whether this type is at last
8116/// as qualified as the Other type. For example, "const volatile
8117/// int" is at least as qualified as "const int", "volatile int",
8118/// "int", and "const volatile int".
8119inline bool QualType::isAtLeastAsQualifiedAs(QualType other,
8120 const ASTContext &Ctx) const {
8121 Qualifiers OtherQuals = other.getQualifiers();
8122
8123 // Ignore __unaligned qualifier if this type is a void.
8124 if (getUnqualifiedType()->isVoidType())
8125 OtherQuals.removeUnaligned();
8126
8127 return getQualifiers().compatiblyIncludes(OtherQuals, Ctx);
8128}
8129
8130/// If Type is a reference type (e.g., const
8131/// int&), returns the type that the reference refers to ("const
8132/// int"). Otherwise, returns the type itself. This routine is used
8133/// throughout Sema to implement C++ 5p6:
8134///
8135/// If an expression initially has the type "reference to T" (8.3.2,
8136/// 8.5.3), the type is adjusted to "T" prior to any further
8137/// analysis, the expression designates the object or function
8138/// denoted by the reference, and the expression is an lvalue.
8139inline QualType QualType::getNonReferenceType() const {
8140 if (const auto *RefType = (*this)->getAs<ReferenceType>())
8141 return RefType->getPointeeType();
8142 else
8143 return *this;
8144}
8145
8146inline bool QualType::isCForbiddenLValueType() const {
8147 return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
8148 getTypePtr()->isFunctionType());
8149}
8150
8151/// Tests whether the type is categorized as a fundamental type.
8152///
8153/// \returns True for types specified in C++0x [basic.fundamental].
8154inline bool Type::isFundamentalType() const {
8155 return isVoidType() ||
8156 isNullPtrType() ||
8157 // FIXME: It's really annoying that we don't have an
8158 // 'isArithmeticType()' which agrees with the standard definition.
8159 (isArithmeticType() && !isEnumeralType());
8160}
8161
8162/// Tests whether the type is categorized as a compound type.
8163///
8164/// \returns True for types specified in C++0x [basic.compound].
8165inline bool Type::isCompoundType() const {
8166 // C++0x [basic.compound]p1:
8167 // Compound types can be constructed in the following ways:
8168 // -- arrays of objects of a given type [...];
8169 return isArrayType() ||
8170 // -- functions, which have parameters of given types [...];
8171 isFunctionType() ||
8172 // -- pointers to void or objects or functions [...];
8173 isPointerType() ||
8174 // -- references to objects or functions of a given type. [...]
8175 isReferenceType() ||
8176 // -- classes containing a sequence of objects of various types, [...];
8177 isRecordType() ||
8178 // -- unions, which are classes capable of containing objects of different
8179 // types at different times;
8180 isUnionType() ||
8181 // -- enumerations, which comprise a set of named constant values. [...];
8182 isEnumeralType() ||
8183 // -- pointers to non-static class members, [...].
8184 isMemberPointerType();
8185}
8186
8187inline bool Type::isFunctionType() const {
8188 return isa<FunctionType>(CanonicalType);
8189}
8190
8191inline bool Type::isPointerType() const {
8192 return isa<PointerType>(CanonicalType);
8193}
8194
8195inline bool Type::isPointerOrReferenceType() const {
8196 return isPointerType() || isReferenceType();
8197}
8198
8199inline bool Type::isAnyPointerType() const {
8200 return isPointerType() || isObjCObjectPointerType();
8201}
8202
8203inline bool Type::isSignableType() const { return isPointerType(); }
8204
8205inline bool Type::isBlockPointerType() const {
8206 return isa<BlockPointerType>(CanonicalType);
8207}
8208
8209inline bool Type::isReferenceType() const {
8210 return isa<ReferenceType>(CanonicalType);
8211}
8212
8213inline bool Type::isLValueReferenceType() const {
8214 return isa<LValueReferenceType>(CanonicalType);
8215}
8216
8217inline bool Type::isRValueReferenceType() const {
8218 return isa<RValueReferenceType>(CanonicalType);
8219}
8220
8221inline bool Type::isObjectPointerType() const {
8222 // Note: an "object pointer type" is not the same thing as a pointer to an
8223 // object type; rather, it is a pointer to an object type or a pointer to cv
8224 // void.
8225 if (const auto *T = getAs<PointerType>())
8226 return !T->getPointeeType()->isFunctionType();
8227 else
8228 return false;
8229}
8230
8231inline bool Type::isFunctionPointerType() const {
8232 if (const auto *T = getAs<PointerType>())
8233 return T->getPointeeType()->isFunctionType();
8234 else
8235 return false;
8236}
8237
8238inline bool Type::isFunctionReferenceType() const {
8239 if (const auto *T = getAs<ReferenceType>())
8240 return T->getPointeeType()->isFunctionType();
8241 else
8242 return false;
8243}
8244
8245inline bool Type::isMemberPointerType() const {
8246 return isa<MemberPointerType>(CanonicalType);
8247}
8248
8249inline bool Type::isMemberFunctionPointerType() const {
8250 if (const auto *T = getAs<MemberPointerType>())
8251 return T->isMemberFunctionPointer();
8252 else
8253 return false;
8254}
8255
8256inline bool Type::isMemberDataPointerType() const {
8257 if (const auto *T = getAs<MemberPointerType>())
8258 return T->isMemberDataPointer();
8259 else
8260 return false;
8261}
8262
8263inline bool Type::isArrayType() const {
8264 return isa<ArrayType>(CanonicalType);
8265}
8266
8267inline bool Type::isConstantArrayType() const {
8268 return isa<ConstantArrayType>(CanonicalType);
8269}
8270
8271inline bool Type::isIncompleteArrayType() const {
8272 return isa<IncompleteArrayType>(CanonicalType);
8273}
8274
8275inline bool Type::isVariableArrayType() const {
8276 return isa<VariableArrayType>(CanonicalType);
8277}
8278
8279inline bool Type::isArrayParameterType() const {
8280 return isa<ArrayParameterType>(CanonicalType);
8281}
8282
8283inline bool Type::isDependentSizedArrayType() const {
8284 return isa<DependentSizedArrayType>(CanonicalType);
8285}
8286
8287inline bool Type::isBuiltinType() const {
8288 return isa<BuiltinType>(CanonicalType);
8289}
8290
8291inline bool Type::isRecordType() const {
8292 return isa<RecordType>(CanonicalType);
8293}
8294
8295inline bool Type::isEnumeralType() const {
8296 return isa<EnumType>(CanonicalType);
8297}
8298
8299inline bool Type::isAnyComplexType() const {
8300 return isa<ComplexType>(CanonicalType);
8301}
8302
8303inline bool Type::isVectorType() const {
8304 return isa<VectorType>(CanonicalType);
8305}
8306
8307inline bool Type::isExtVectorType() const {
8308 return isa<ExtVectorType>(CanonicalType);
8309}
8310
8311inline bool Type::isExtVectorBoolType() const {
8312 if (!isExtVectorType())
8313 return false;
8314 return cast<ExtVectorType>(CanonicalType)->getElementType()->isBooleanType();
8315}
8316
8317inline bool Type::isSubscriptableVectorType() const {
8318 return isVectorType() || isSveVLSBuiltinType();
8319}
8320
8321inline bool Type::isMatrixType() const {
8322 return isa<MatrixType>(CanonicalType);
8323}
8324
8325inline bool Type::isConstantMatrixType() const {
8326 return isa<ConstantMatrixType>(CanonicalType);
8327}
8328
8329inline bool Type::isDependentAddressSpaceType() const {
8330 return isa<DependentAddressSpaceType>(CanonicalType);
8331}
8332
8333inline bool Type::isObjCObjectPointerType() const {
8334 return isa<ObjCObjectPointerType>(CanonicalType);
8335}
8336
8337inline bool Type::isObjCObjectType() const {
8338 return isa<ObjCObjectType>(CanonicalType);
8339}
8340
8341inline bool Type::isObjCObjectOrInterfaceType() const {
8342 return isa<ObjCInterfaceType>(CanonicalType) ||
8343 isa<ObjCObjectType>(CanonicalType);
8344}
8345
8346inline bool Type::isAtomicType() const {
8347 return isa<AtomicType>(CanonicalType);
8348}
8349
8350inline bool Type::isUndeducedAutoType() const {
8351 return isa<AutoType>(CanonicalType);
8352}
8353
8354inline bool Type::isObjCQualifiedIdType() const {
8355 if (const auto *OPT = getAs<ObjCObjectPointerType>())
8356 return OPT->isObjCQualifiedIdType();
8357 return false;
8358}
8359
8360inline bool Type::isObjCQualifiedClassType() const {
8361 if (const auto *OPT = getAs<ObjCObjectPointerType>())
8362 return OPT->isObjCQualifiedClassType();
8363 return false;
8364}
8365
8366inline bool Type::isObjCIdType() const {
8367 if (const auto *OPT = getAs<ObjCObjectPointerType>())
8368 return OPT->isObjCIdType();
8369 return false;
8370}
8371
8372inline bool Type::isObjCClassType() const {
8373 if (const auto *OPT = getAs<ObjCObjectPointerType>())
8374 return OPT->isObjCClassType();
8375 return false;
8376}
8377
8378inline bool Type::isObjCSelType() const {
8379 if (const auto *OPT = getAs<PointerType>())
8380 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
8381 return false;
8382}
8383
8384inline bool Type::isObjCBuiltinType() const {
8385 return isObjCIdType() || isObjCClassType() || isObjCSelType();
8386}
8387
8388inline bool Type::isDecltypeType() const {
8389 return isa<DecltypeType>(this);
8390}
8391
8392#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
8393 inline bool Type::is##Id##Type() const { \
8394 return isSpecificBuiltinType(BuiltinType::Id); \
8395 }
8396#include "clang/Basic/OpenCLImageTypes.def"
8397
8398inline bool Type::isSamplerT() const {
8399 return isSpecificBuiltinType(BuiltinType::OCLSampler);
8400}
8401
8402inline bool Type::isEventT() const {
8403 return isSpecificBuiltinType(BuiltinType::OCLEvent);
8404}
8405
8406inline bool Type::isClkEventT() const {
8407 return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
8408}
8409
8410inline bool Type::isQueueT() const {
8411 return isSpecificBuiltinType(BuiltinType::OCLQueue);
8412}
8413
8414inline bool Type::isReserveIDT() const {
8415 return isSpecificBuiltinType(BuiltinType::OCLReserveID);
8416}
8417
8418inline bool Type::isImageType() const {
8419#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
8420 return
8421#include "clang/Basic/OpenCLImageTypes.def"
8422 false; // end boolean or operation
8423}
8424
8425inline bool Type::isPipeType() const {
8426 return isa<PipeType>(CanonicalType);
8427}
8428
8429inline bool Type::isBitIntType() const {
8430 return isa<BitIntType>(CanonicalType);
8431}
8432
8433#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
8434 inline bool Type::is##Id##Type() const { \
8435 return isSpecificBuiltinType(BuiltinType::Id); \
8436 }
8437#include "clang/Basic/OpenCLExtensionTypes.def"
8438
8439inline bool Type::isOCLIntelSubgroupAVCType() const {
8440#define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \
8441 isOCLIntelSubgroupAVC##Id##Type() ||
8442 return
8443#include "clang/Basic/OpenCLExtensionTypes.def"
8444 false; // end of boolean or operation
8445}
8446
8447inline bool Type::isOCLExtOpaqueType() const {
8448#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() ||
8449 return
8450#include "clang/Basic/OpenCLExtensionTypes.def"
8451 false; // end of boolean or operation
8452}
8453
8454inline bool Type::isOpenCLSpecificType() const {
8455 return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
8456 isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
8457}
8458
8459#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
8460 inline bool Type::is##Id##Type() const { \
8461 return isSpecificBuiltinType(BuiltinType::Id); \
8462 }
8463#include "clang/Basic/HLSLIntangibleTypes.def"
8464
8465inline bool Type::isHLSLBuiltinIntangibleType() const {
8466#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
8467 return
8468#include "clang/Basic/HLSLIntangibleTypes.def"
8469 false;
8470}
8471
8472inline bool Type::isHLSLSpecificType() const {
8473 return isHLSLBuiltinIntangibleType() || isHLSLAttributedResourceType();
8474}
8475
8476inline bool Type::isHLSLAttributedResourceType() const {
8477 return isa<HLSLAttributedResourceType>(this);
8478}
8479
8480inline bool Type::isTemplateTypeParmType() const {
8481 return isa<TemplateTypeParmType>(CanonicalType);
8482}
8483
8484inline bool Type::isSpecificBuiltinType(unsigned K) const {
8485 if (const BuiltinType *BT = getAs<BuiltinType>()) {
8486 return BT->getKind() == static_cast<BuiltinType::Kind>(K);
8487 }
8488 return false;
8489}
8490
8491inline bool Type::isPlaceholderType() const {
8492 if (const auto *BT = dyn_cast<BuiltinType>(this))
8493 return BT->isPlaceholderType();
8494 return false;
8495}
8496
8497inline const BuiltinType *Type::getAsPlaceholderType() const {
8498 if (const auto *BT = dyn_cast<BuiltinType>(this))
8499 if (BT->isPlaceholderType())
8500 return BT;
8501 return nullptr;
8502}
8503
8504inline bool Type::isSpecificPlaceholderType(unsigned K) const {
8505 assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K));
8506 return isSpecificBuiltinType(K);
8507}
8508
8509inline bool Type::isNonOverloadPlaceholderType() const {
8510 if (const auto *BT = dyn_cast<BuiltinType>(this))
8511 return BT->isNonOverloadPlaceholderType();
8512 return false;
8513}
8514
8515inline bool Type::isVoidType() const {
8516 return isSpecificBuiltinType(BuiltinType::Void);
8517}
8518
8519inline bool Type::isHalfType() const {
8520 // FIXME: Should we allow complex __fp16? Probably not.
8521 return isSpecificBuiltinType(BuiltinType::Half);
8522}
8523
8524inline bool Type::isFloat16Type() const {
8525 return isSpecificBuiltinType(BuiltinType::Float16);
8526}
8527
8528inline bool Type::isFloat32Type() const {
8529 return isSpecificBuiltinType(BuiltinType::Float);
8530}
8531
8532inline bool Type::isDoubleType() const {
8533 return isSpecificBuiltinType(BuiltinType::Double);
8534}
8535
8536inline bool Type::isBFloat16Type() const {
8537 return isSpecificBuiltinType(BuiltinType::BFloat16);
8538}
8539
8540inline bool Type::isFloat128Type() const {
8541 return isSpecificBuiltinType(BuiltinType::Float128);
8542}
8543
8544inline bool Type::isIbm128Type() const {
8545 return isSpecificBuiltinType(BuiltinType::Ibm128);
8546}
8547
8548inline bool Type::isNullPtrType() const {
8549 return isSpecificBuiltinType(BuiltinType::NullPtr);
8550}
8551
8554
8555inline bool Type::isIntegerType() const {
8556 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8557 return BT->getKind() >= BuiltinType::Bool &&
8558 BT->getKind() <= BuiltinType::Int128;
8559 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
8560 // Incomplete enum types are not treated as integer types.
8561 // FIXME: In C++, enum types are never integer types.
8562 return IsEnumDeclComplete(ET->getDecl()) &&
8563 !IsEnumDeclScoped(ET->getDecl());
8564 }
8565 return isBitIntType();
8566}
8567
8568inline bool Type::isFixedPointType() const {
8569 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
8570 return BT->getKind() >= BuiltinType::ShortAccum &&
8571 BT->getKind() <= BuiltinType::SatULongFract;
8572 }
8573 return false;
8574}
8575
8576inline bool Type::isFixedPointOrIntegerType() const {
8577 return isFixedPointType() || isIntegerType();
8578}
8579
8580inline bool Type::isConvertibleToFixedPointType() const {
8581 return isRealFloatingType() || isFixedPointOrIntegerType();
8582}
8583
8584inline bool Type::isSaturatedFixedPointType() const {
8585 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
8586 return BT->getKind() >= BuiltinType::SatShortAccum &&
8587 BT->getKind() <= BuiltinType::SatULongFract;
8588 }
8589 return false;
8590}
8591
8592inline bool Type::isUnsaturatedFixedPointType() const {
8593 return isFixedPointType() && !isSaturatedFixedPointType();
8594}
8595
8596inline bool Type::isSignedFixedPointType() const {
8597 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
8598 return ((BT->getKind() >= BuiltinType::ShortAccum &&
8599 BT->getKind() <= BuiltinType::LongAccum) ||
8600 (BT->getKind() >= BuiltinType::ShortFract &&
8601 BT->getKind() <= BuiltinType::LongFract) ||
8602 (BT->getKind() >= BuiltinType::SatShortAccum &&
8603 BT->getKind() <= BuiltinType::SatLongAccum) ||
8604 (BT->getKind() >= BuiltinType::SatShortFract &&
8605 BT->getKind() <= BuiltinType::SatLongFract));
8606 }
8607 return false;
8608}
8609
8610inline bool Type::isUnsignedFixedPointType() const {
8611 return isFixedPointType() && !isSignedFixedPointType();
8612}
8613
8614inline bool Type::isScalarType() const {
8615 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8616 return BT->getKind() > BuiltinType::Void &&
8617 BT->getKind() <= BuiltinType::NullPtr;
8618 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
8619 // Enums are scalar types, but only if they are defined. Incomplete enums
8620 // are not treated as scalar types.
8621 return IsEnumDeclComplete(ET->getDecl());
8622 return isa<PointerType>(CanonicalType) ||
8623 isa<BlockPointerType>(CanonicalType) ||
8624 isa<MemberPointerType>(CanonicalType) ||
8625 isa<ComplexType>(CanonicalType) ||
8626 isa<ObjCObjectPointerType>(CanonicalType) ||
8627 isBitIntType();
8628}
8629
8630inline bool Type::isIntegralOrEnumerationType() const {
8631 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8632 return BT->getKind() >= BuiltinType::Bool &&
8633 BT->getKind() <= BuiltinType::Int128;
8634
8635 // Check for a complete enum type; incomplete enum types are not properly an
8636 // enumeration type in the sense required here.
8637 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
8638 return IsEnumDeclComplete(ET->getDecl());
8639
8640 return isBitIntType();
8641}
8642
8643inline bool Type::isBooleanType() const {
8644 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
8645 return BT->getKind() == BuiltinType::Bool;
8646 return false;
8647}
8648
8649inline bool Type::isUndeducedType() const {
8650 auto *DT = getContainedDeducedType();
8651 return DT && !DT->isDeduced();
8652}
8653
8654/// Determines whether this is a type for which one can define
8655/// an overloaded operator.
8656inline bool Type::isOverloadableType() const {
8657 if (!isDependentType())
8658 return isRecordType() || isEnumeralType();
8659 return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
8660 !isMemberPointerType();
8661}
8662
8663/// Determines whether this type is written as a typedef-name.
8664inline bool Type::isTypedefNameType() const {
8665 if (getAs<TypedefType>())
8666 return true;
8667 if (auto *TST = getAs<TemplateSpecializationType>())
8668 return TST->isTypeAlias();
8669 return false;
8670}
8671
8672/// Determines whether this type can decay to a pointer type.
8673inline bool Type::canDecayToPointerType() const {
8674 return isFunctionType() || (isArrayType() && !isArrayParameterType());
8675}
8676
8677inline bool Type::hasPointerRepresentation() const {
8678 return (isPointerType() || isReferenceType() || isBlockPointerType() ||
8679 isObjCObjectPointerType() || isNullPtrType());
8680}
8681
8682inline bool Type::hasObjCPointerRepresentation() const {
8683 return isObjCObjectPointerType();
8684}
8685
8686inline const Type *Type::getBaseElementTypeUnsafe() const {
8687 const Type *type = this;
8688 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
8689 type = arrayType->getElementType().getTypePtr();
8690 return type;
8691}
8692
8693inline const Type *Type::getPointeeOrArrayElementType() const {
8694 const Type *type = this;
8695 if (type->isAnyPointerType())
8696 return type->getPointeeType().getTypePtr();
8697 else if (type->isArrayType())
8698 return type->getBaseElementTypeUnsafe();
8699 return type;
8700}
8701/// Insertion operator for partial diagnostics. This allows sending adress
8702/// spaces into a diagnostic with <<.
8703inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8704 LangAS AS) {
8705 PD.AddTaggedVal(llvm::to_underlying(AS),
8706 DiagnosticsEngine::ArgumentKind::ak_addrspace);
8707 return PD;
8708}
8709
8710/// Insertion operator for partial diagnostics. This allows sending Qualifiers
8711/// into a diagnostic with <<.
8712inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8713 Qualifiers Q) {
8715 DiagnosticsEngine::ArgumentKind::ak_qual);
8716 return PD;
8717}
8718
8719/// Insertion operator for partial diagnostics. This allows sending QualType's
8720/// into a diagnostic with <<.
8721inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
8722 QualType T) {
8723 PD.AddTaggedVal(reinterpret_cast<uint64_t>(T.getAsOpaquePtr()),
8724 DiagnosticsEngine::ak_qualtype);
8725 return PD;
8726}
8727
8728// Helper class template that is used by Type::getAs to ensure that one does
8729// not try to look through a qualified type to get to an array type.
8730template <typename T>
8732 std::integral_constant<bool, std::is_same<T, ArrayType>::value ||
8733 std::is_base_of<ArrayType, T>::value>;
8734
8735// Member-template getAs<specific type>'.
8736template <typename T> const T *Type::getAs() const {
8737 static_assert(!TypeIsArrayType<T>::value,
8738 "ArrayType cannot be used with getAs!");
8739
8740 // If this is directly a T type, return it.
8741 if (const auto *Ty = dyn_cast<T>(this))
8742 return Ty;
8743
8744 // If the canonical form of this type isn't the right kind, reject it.
8745 if (!isa<T>(CanonicalType))
8746 return nullptr;
8747
8748 // If this is a typedef for the type, strip the typedef off without
8749 // losing all typedef information.
8750 return cast<T>(getUnqualifiedDesugaredType());
8751}
8752
8753template <typename T> const T *Type::getAsAdjusted() const {
8754 static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
8755
8756 // If this is directly a T type, return it.
8757 if (const auto *Ty = dyn_cast<T>(this))
8758 return Ty;
8759
8760 // If the canonical form of this type isn't the right kind, reject it.
8761 if (!isa<T>(CanonicalType))
8762 return nullptr;
8763
8764 // Strip off type adjustments that do not modify the underlying nature of the
8765 // type.
8766 const Type *Ty = this;
8767 while (Ty) {
8768 if (const auto *A = dyn_cast<AttributedType>(Ty))
8769 Ty = A->getModifiedType().getTypePtr();
8770 else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
8771 Ty = A->getWrappedType().getTypePtr();
8772 else if (const auto *A = dyn_cast<HLSLAttributedResourceType>(Ty))
8773 Ty = A->getWrappedType().getTypePtr();
8774 else if (const auto *E = dyn_cast<ElaboratedType>(Ty))
8775 Ty = E->desugar().getTypePtr();
8776 else if (const auto *P = dyn_cast<ParenType>(Ty))
8777 Ty = P->desugar().getTypePtr();
8778 else if (const auto *A = dyn_cast<AdjustedType>(Ty))
8779 Ty = A->desugar().getTypePtr();
8780 else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))
8781 Ty = M->desugar().getTypePtr();
8782 else
8783 break;
8784 }
8785
8786 // Just because the canonical type is correct does not mean we can use cast<>,
8787 // since we may not have stripped off all the sugar down to the base type.
8788 return dyn_cast<T>(Ty);
8789}
8790
8791inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
8792 // If this is directly an array type, return it.
8793 if (const auto *arr = dyn_cast<ArrayType>(this))
8794 return arr;
8795
8796 // If the canonical form of this type isn't the right kind, reject it.
8797 if (!isa<ArrayType>(CanonicalType))
8798 return nullptr;
8799
8800 // If this is a typedef for the type, strip the typedef off without
8801 // losing all typedef information.
8802 return cast<ArrayType>(getUnqualifiedDesugaredType());
8803}
8804
8805template <typename T> const T *Type::castAs() const {
8806 static_assert(!TypeIsArrayType<T>::value,
8807 "ArrayType cannot be used with castAs!");
8808
8809 if (const auto *ty = dyn_cast<T>(this)) return ty;
8810 assert(isa<T>(CanonicalType));
8811 return cast<T>(getUnqualifiedDesugaredType());
8812}
8813
8814inline const ArrayType *Type::castAsArrayTypeUnsafe() const {
8815 assert(isa<ArrayType>(CanonicalType));
8816 if (const auto *arr = dyn_cast<ArrayType>(this)) return arr;
8817 return cast<ArrayType>(getUnqualifiedDesugaredType());
8818}
8819
8820DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
8821 QualType CanonicalPtr)
8822 : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
8823#ifndef NDEBUG
8824 QualType Adjusted = getAdjustedType();
8826 assert(isa<PointerType>(Adjusted));
8827#endif
8828}
8829
8831 QualType Decayed = getDecayedType();
8833 return cast<PointerType>(Decayed)->getPointeeType();
8834}
8835
8836// Get the decimal string representation of a fixed point type, represented
8837// as a scaled integer.
8838// TODO: At some point, we should change the arguments to instead just accept an
8839// APFixedPoint instead of APSInt and scale.
8840void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
8841 unsigned Scale);
8842
8844 while (true) {
8845 QualType Pointee = QT->getPointeeType();
8846 if (Pointee.isNull())
8847 break;
8848 QT = Pointee;
8849 }
8850 if (const auto *FPT = QT->getAs<FunctionProtoType>())
8851 return FPT->getFunctionEffects();
8852 return {};
8853}
8854
8855} // namespace clang
8856
8857#endif // LLVM_CLANG_AST_TYPE_H
#define V(N, I)
Definition: ASTContext.h:3453
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
enum clang::sema::@1724::IndirectLocalPathEntry::EntryKind Kind
Expr * E
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:7775
bool isSugared() const
Definition: Type.h:7768
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition: Type.h:7766
QualType desugar() const
Definition: Type.h:7769
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7771
static bool classof(const Type *T)
Definition: Type.h:7779
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:6132
QualType getModifiedType() const
Definition: Type.h:6162
static bool classof(const Type *T)
Definition: Type.h:6217
const Attr * getAttr() const
Definition: Type.h:6160
bool isSugared() const
Definition: Type.h:6165
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:6208
QualType desugar() const
Definition: Type.h:6166
QualType getEquivalentType() const
Definition: Type.h:6163
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6204
Kind getAttrKind() const
Definition: Type.h:6156
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6561
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6571
static bool classof(const Type *T)
Definition: Type.h:6602
bool isDecltypeAuto() const
Definition: Type.h:6584
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6576
AutoTypeKeyword getKeyword() const
Definition: Type.h:6592
bool isGNUAutoType() const
Definition: Type.h:6588
bool isConstrained() const
Definition: Type.h:6580
static bool classof(const Type *T)
Definition: Type.h:6251
const BTFTypeTagAttr * getAttr() const
Definition: Type.h:6236
QualType getWrappedType() const
Definition: Type.h:6235
QualType desugar() const
Definition: Type.h:6239
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6241
static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped, const BTFTypeTagAttr *BTFAttr)
Definition: Type.h:6245
bool isSugared() const
Definition: Type.h:6238
A fixed int type of a specified bitwidth.
Definition: Type.h:7819
bool isSigned() const
Definition: Type.h:7830
static bool classof(const Type *T)
Definition: Type.h:7846
static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned, unsigned NumBits)
Definition: Type.h:7840
bool isSugared() const
Definition: Type.h:7833
bool isUnsigned() const
Definition: Type.h:7829
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:7836
unsigned getNumBits() const
Definition: Type.h:7831
QualType desugar() const
Definition: Type.h:7834
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:8830
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:5879
static bool classof(const Type *T)
Definition: Type.h:5898
Expr * getUnderlyingExpr() const
Definition: Type.h:5889
QualType getUnderlyingType() const
Definition: Type.h:5890
Represents a C++17 deduced template specialization type.
Definition: Type.h:6609
void Profile(llvm::FoldingSetNodeID &ID) const
Definition: Type.h:6630
TemplateName getTemplateName() const
Retrieve the name of the template that we are deducing.
Definition: Type.h:6628
static bool classof(const Type *T)
Definition: Type.h:6641
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, QualType Deduced, bool IsDependent)
Definition: Type.h:6634
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Definition: Type.h:6527
static bool classof(const Type *T)
Definition: Type.h:6553
bool isSugared() const
Definition: Type.h:6541
QualType desugar() const
Definition: Type.h:6542
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:6548
DeducedType(TypeClass TC, QualType DeducedAsType, TypeDependence ExtraDependence, QualType Canon)
Definition: Type.h:6531
bool isDeduced() const
Definition: Type.h:6549
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:7862
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:7864
bool isSigned() const
Definition: Type.h:7858
bool isSugared() const
Definition: Type.h:7861
static bool classof(const Type *T)
Definition: Type.h:7870
Internal representation of canonical, dependent decltype(expr) types.
Definition: Type.h:5907
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5911
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:7029
bool isSugared() const
Definition: Type.h:7058
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:7047
static bool classof(const Type *T)
Definition: Type.h:7072
const IdentifierInfo * getIdentifier() const
Retrieve the type named by the typename specifier as an identifier.
Definition: Type.h:7054
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7061
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name)
Definition: Type.h:7065
QualType desugar() const
Definition: Type.h:7059
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:7081
const IdentifierInfo * getIdentifier() const
Definition: Type.h:7098
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:7108
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:7100
NestedNameSpecifier * getQualifier() const
Definition: Type.h:7097
static bool classof(const Type *T)
Definition: Type.h:7119
Internal representation of canonical, dependent typeof(expr) types.
Definition: Type.h:5836
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition: Type.h:5841
DependentTypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind)
Definition: Type.h:5838
Internal representation of canonical, dependent __underlying_type(type) types.
Definition: Type.h:6037
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6042
static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, UTTKind UKind)
Definition: Type.h:6046
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:4828
EffectConditionExpr(Expr *E)
Definition: Type.h:4833
Expr * getCondition() const
Definition: Type.h:4835
bool operator==(const EffectConditionExpr &RHS) const
Definition: Type.h:4837
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6948
static bool classof(const Type *T)
Definition: Type.h:7014
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:6996
QualType desugar() const
Remove a single level of sugar.
Definition: Type.h:6989
NestedNameSpecifier * getQualifier() const
Retrieve the qualification on this type.
Definition: Type.h:6983
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl)
Definition: Type.h:7005
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:6992
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7001
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:6986
Represents an enum.
Definition: Decl.h:3861
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6103
EnumDecl * getDecl() const
Definition: Type.h:6110
bool isSugared() const
Definition: Type.h:6114
static bool classof(const Type *T)
Definition: Type.h:6117
QualType desugar() const
Definition: Type.h:6115
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:4861
bool operator==(const FunctionEffectIterator &Other) const
Definition: Type.h:4870
bool operator!=(const FunctionEffectIterator &Other) const
Definition: Type.h:4873
FunctionEffectIterator operator++()
Definition: Type.h:4877
FunctionEffectIterator(const Container &O, size_t I)
Definition: Type.h:4869
FunctionEffectWithCondition operator*() const
Definition: Type.h:4882
A mutable set of FunctionEffect::Kind.
Definition: Type.h:4962
static FunctionEffectKindSet difference(FunctionEffectKindSet LHS, FunctionEffectKindSet RHS)
Definition: Type.h:5034
bool contains(const FunctionEffect::Kind EK) const
Definition: Type.h:5029
iterator begin() const
Definition: Type.h:5018
FunctionEffectKindSet(FunctionEffectsRef FX)
Definition: Type.h:5016
void insert(FunctionEffectKindSet Set)
Definition: Type.h:5026
void insert(FunctionEffectsRef FX)
Definition: Type.h:5022
iterator end() const
Definition: Type.h:5019
void insert(FunctionEffect Effect)
Definition: Type.h:5021
A mutable set of FunctionEffects and possibly conditions attached to them.
Definition: Type.h:5044
FunctionEffectSet(const FunctionEffectsRef &FX)
Definition: Type.h:5051
iterator end() const
Definition: Type.h:5060
size_t size() const
Definition: Type.h:5055
bool empty() const
Definition: Type.h:5054
iterator begin() const
Definition: Type.h:5059
Represents an abstract function effect, using just an enumeration describing its kind.
Definition: Type.h:4721
Kind kind() const
The kind of the effect.
Definition: Type.h:4760
friend bool operator<(FunctionEffect LHS, FunctionEffect RHS)
Definition: Type.h:4821
friend bool operator==(FunctionEffect LHS, FunctionEffect RHS)
Definition: Type.h:4815
uint32_t toOpaqueInt32() const
For serialization.
Definition: Type.h:4766
friend bool operator!=(FunctionEffect LHS, FunctionEffect RHS)
Definition: Type.h:4818
Kind
Identifies the particular effect.
Definition: Type.h:4724
Flags flags() const
Flags describing some behaviors of the effect.
Definition: Type.h:4772
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5223
static FunctionEffect fromOpaqueInt32(uint32_t Value)
Definition: Type.h:4767
FunctionEffect(Kind K)
Definition: Type.h:4757
friend raw_ostream & operator<<(raw_ostream &OS, const FunctionEffect &Effect)
Definition: Type.h:4792
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition: Type.h:4908
size_t size() const
Definition: Type.h:4939
ArrayRef< FunctionEffect > effects() const
Definition: Type.h:4941
iterator begin() const
Definition: Type.h:4946
ArrayRef< EffectConditionExpr > conditions() const
Definition: Type.h:4942
iterator end() const
Definition: Type.h:4947
friend bool operator==(const FunctionEffectsRef &LHS, const FunctionEffectsRef &RHS)
Definition: Type.h:4949
static FunctionEffectsRef get(QualType QT)
Extract the effects from a Type if it is a function, block, or member function pointer,...
Definition: Type.h:8843
bool empty() const
Definition: Type.h:4938
friend bool operator!=(const FunctionEffectsRef &LHS, const FunctionEffectsRef &RHS)
Definition: Type.h:4953
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4686
bool isSugared() const
Definition: Type.h:4699
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition: Type.h:4706
QualType desugar() const
Definition: Type.h:4700
static bool classof(const Type *T)
Definition: Type.h:4712
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:4702
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5107
QualType desugar() const
Definition: Type.h:5651
param_type_iterator param_type_begin() const
Definition: Type.h:5520
unsigned getNumFunctionEffectConditions() const
Definition: Type.h:5612
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition: Type.h:5573
ArrayRef< EffectConditionExpr > getFunctionEffectConditions() const
Definition: Type.h:5622
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition: Type.h:5387
ArrayRef< FunctionEffect > getFunctionEffectsWithoutConditions() const
Definition: Type.h:5602
bool isParamConsumed(unsigned I) const
Definition: Type.h:5587
exception_iterator exception_end() const
Definition: Type.h:5539
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5558
unsigned getNumParams() const
Definition: Type.h:5360
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5500
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
Definition: Type.h:5413
Qualifiers getMethodQuals() const
Definition: Type.h:5502
static bool classof(const Type *T)
Definition: Type.h:5656
QualType getParamType(unsigned i) const
Definition: Type.h:5362
FunctionEffectsRef getFunctionEffects() const
Definition: Type.h:5633
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition: Type.h:5566
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition: Type.h:5438
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:5486
unsigned getNumFunctionEffects() const
Definition: Type.h:5594
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition: Type.h:5430
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition: Type.h:5393
bool hasDynamicExceptionSpec() const
Return whether this function has a dynamic (throw) exception spec.
Definition: Type.h:5396
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition: Type.h:5401
bool isVariadic() const
Whether this function prototype is variadic.
Definition: Type.h:5484
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5371
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition: Type.h:5445
param_type_iterator param_type_end() const
Definition: Type.h:5524
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition: Type.h:5466
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition: Type.h:5479
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5367
ArrayRef< QualType > exceptions() const
Definition: Type.h:5530
ParameterABI getParameterABI(unsigned I) const
Definition: Type.h:5580
ArrayRef< QualType > param_types() const
Definition: Type.h:5516
bool isSugared() const
Definition: Type.h:5650
exception_iterator exception_begin() const
Definition: Type.h:5534
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition: Type.h:5549
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition: Type.h:5545
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition: Type.h:5510
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition: Type.h:5455
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:4660
static ArmStateValue getArmZT0State(unsigned AttrBits)
Definition: Type.h:4618
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition: Type.h:4656
bool isConst() const
Definition: Type.h:4666
static ArmStateValue getArmZAState(unsigned AttrBits)
Definition: Type.h:4614
unsigned getRegParmType() const
Definition: Type.h:4651
CallingConv getCallConv() const
Definition: Type.h:4659
bool isRestrict() const
Definition: Type.h:4668
QualType getReturnType() const
Definition: Type.h:4648
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition: Type.h:4634
static bool classof(const Type *T)
Definition: Type.h:4678
bool getCmseNSCallAttr() const
Definition: Type.h:4658
bool getHasRegParm() const
Definition: Type.h:4650
Qualifiers getFastTypeQuals() const
Definition: Type.h:4640
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition: Type.h:4672
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:4667
QualType getWrappedType() const
Definition: Type.h:6298
const Attributes & getAttrs() const
Definition: Type.h:6301
QualType desugar() const
Definition: Type.h:6304
static bool classof(const Type *T)
Definition: Type.h:6319
static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped, QualType Contained, const Attributes &Attrs)
Definition: Type.h:6310
QualType getContainedType() const
Definition: Type.h:6299
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6306
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:6798
QualType desugar() const
Definition: Type.h:6842
static bool classof(const Type *T)
Definition: Type.h:6844
const TemplateSpecializationType * getInjectedTST() const
Definition: Type.h:6831
TemplateName getTemplateName() const
Definition: Type.h:6835
QualType getInjectedSpecializationType() const
Definition: Type.h:6829
bool isSugared() const
Definition: Type.h:6841
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:5770
bool isSugared() const
Definition: Type.h:5792
static bool classof(const Type *T)
Definition: Type.h:5795
QualType getUnderlyingType() const
Definition: Type.h:5786
const IdentifierInfo * getMacroIdentifier() const
Definition: Type.h:5785
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:7529
QualType desugar() const
Definition: Type.h:7545
bool isSugared() const
Definition: Type.h:7544
static bool classof(const Type *T)
Definition: Type.h:7547
Represents a pointer to an Objective C object.
Definition: Type.h:7585
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition: Type.h:7717
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7674
qual_iterator qual_end() const
Definition: Type.h:7710
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition: Type.h:7666
static void Profile(llvm::FoldingSetNodeID &ID, QualType T)
Definition: Type.h:7746
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition: Type.h:7660
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition: Type.h:7677
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:7686
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition: Type.h:7694
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7742
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7622
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition: Type.h:7701
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:7702
static bool classof(const Type *T)
Definition: Type.h:7750
bool qual_empty() const
Definition: Type.h:7714
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition: Type.h:7682
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition: Type.h:7643
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition: Type.h:7722
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition: Type.h:7597
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition: Type.h:7637
QualType desugar() const
Definition: Type.h:7727
qual_range quals() const
Definition: Type.h:7704
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition: Type.h:7649
bool isSugared() const
Definition: Type.h:7726
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition: Type.h:7654
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition: Type.h:7689
qual_iterator qual_begin() const
Definition: Type.h:7706
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition: Type.h:7671
A class providing a concrete implementation of ObjCObjectType, so as to not increase the footprint of...
Definition: Type.h:7482
Represents a class type in Objective C.
Definition: Type.h:7331
bool isKindOfTypeAsWritten() const
Whether this is a "__kindof" type as written.
Definition: Type.h:7446
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments of this object type as they were written.
Definition: Type.h:7441
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition: Type.h:7434
bool isObjCQualifiedClass() const
Definition: Type.h:7413
ObjCObjectType(enum Nonce_ObjCInterface)
Definition: Type.h:7376
bool isObjCUnqualifiedIdOrClass() const
Definition: Type.h:7405
QualType getBaseType() const
Gets the base type of this object type.
Definition: Type.h:7393
bool isObjCClass() const
Definition: Type.h:7399
QualType desugar() const
Definition: Type.h:7470
bool isObjCQualifiedId() const
Definition: Type.h:7412
bool isSpecializedAsWritten() const
Determine whether this object type was written with type arguments.
Definition: Type.h:7424
bool isObjCUnqualifiedId() const
Definition: Type.h:7403
bool isUnspecialized() const
Determine whether this object type is "unspecialized", meaning that it has no type arguments.
Definition: Type.h:7430
bool isSugared() const
Definition: Type.h:7469
bool isObjCUnqualifiedClass() const
Definition: Type.h:7404
static bool classof(const Type *T)
Definition: Type.h:7472
QualType getSuperClassType() const
Retrieve the type of the superclass of this object type.
Definition: Type.h:7457
bool isObjCId() const
Definition: Type.h:7395
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
This class wraps the list of protocol qualifiers.
Definition: Type.h:7200
llvm::iterator_range< qual_iterator > qual_range
Definition: Type.h:7227
void initialize(ArrayRef< ObjCProtocolDecl * > protocols)
Definition: Type.h:7216
ObjCProtocolDecl ** getProtocolStorage()
Definition: Type.h:7208
ArrayRef< ObjCProtocolDecl * > getProtocols() const
Retrieve all of the protocol qualifiers.
Definition: Type.h:7248
unsigned getNumProtocols() const
Return the number of qualifying protocols in this type, or 0 if there are none.
Definition: Type.h:7237
void setNumProtocols(unsigned N)
Definition: Type.h:7212
qual_iterator qual_end() const
Definition: Type.h:7231
ObjCProtocolDecl *const * getProtocolStorage() const
Definition: Type.h:7204
ObjCProtocolDecl * getProtocol(unsigned I) const
Fetch a protocol by index.
Definition: Type.h:7242
qual_iterator qual_begin() const
Definition: Type.h:7230
qual_range quals() const
Definition: Type.h:7229
bool qual_empty() const
Definition: Type.h:7233
ObjCProtocolDecl *const * qual_iterator
Definition: Type.h:7226
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Represents a type parameter type in Objective C.
Definition: Type.h:7257
static bool classof(const Type *T)
Definition: Type.h:7289
bool isSugared() const
Definition: Type.h:7286
QualType desugar() const
Definition: Type.h:7287
ObjCTypeParamDecl * getDecl() const
Definition: Type.h:7299
Represents a pack expansion of types.
Definition: Type.h:7146
bool isSugared() const
Definition: Type.h:7177
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7180
static bool classof(const Type *T)
Definition: Type.h:7192
static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, std::optional< unsigned > NumExpansions)
Definition: Type.h:7184
QualType getPattern() const
Retrieve the pattern of this pack expansion, which is the type that will be repeatedly instantiated w...
Definition: Type.h:7167
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7171
QualType desugar() const
Definition: Type.h:7178
bool hasSelectedType() const
Definition: Type.h:5959
QualType getPattern() const
Definition: Type.h:5942
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5973
QualType getSelectedType() const
Definition: Type.h:5952
bool isFullySubstituted() const
Definition: Type.h:5961
ArrayRef< QualType > getExpansions() const
Definition: Type.h:5965
QualType desugar() const
Definition: Type.h:5946
Expr * getIndexExpr() const
Definition: Type.h:5941
static bool classof(const Type *T)
Definition: Type.h:5969
bool isSugared() const
Definition: Type.h:5944
bool expandsToEmptyPack() const
Definition: Type.h:5963
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:7785
QualType desugar() const
Definition: Type.h:7800
bool isSugared() const
Definition: Type.h:7798
static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead)
Definition: Type.h:7806
QualType getElementType() const
Definition: Type.h:7796
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:7802
static bool classof(const Type *T)
Definition: Type.h:7811
bool isReadOnly() const
Definition: Type.h:7815
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:8020
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition: Type.h:8014
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:8067
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:8025
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:8083
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:7936
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:8062
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:8077
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7976
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:7944
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:8139
QualType getCanonicalType() const
Definition: Type.h:7988
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:8030
void removeLocalVolatile()
Definition: Type.h:8052
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:7957
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:8146
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:8108
bool isCanonicalAsParam() const
Definition: Type.h:7997
void removeLocalConst()
Definition: Type.h:8044
void removeLocalRestrict()
Definition: Type.h:8048
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:8037
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:8009
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition: Type.h:8057
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:7993
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:7982
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:7940
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:8119
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:7968
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:8071
A qualifier set is used to build a set of qualifiers.
Definition: Type.h:7876
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Definition: Type.h:7883
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition: Type.h:7878
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:4162
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6077
RecordType(const RecordDecl *D)
Definition: Type.h:6081
bool isSugared() const
Definition: Type.h:6095
QualType desugar() const
Definition: Type.h:6096
RecordDecl * getDecl() const
Definition: Type.h:6087
RecordType(TypeClass TC, RecordDecl *D)
Definition: Type.h:6083
static bool classof(const Type *T)
Definition: Type.h:6098
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:6469
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:6495
static bool classof(const Type *T)
Definition: Type.h:6514
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:6388
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6433
static bool classof(const Type *T)
Definition: Type.h:6452
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: Type.h:6410
std::optional< unsigned > getPackIndex() const
Definition: Type.h:6419
QualType getReplacementType() const
Gets the type that was substituted for the template parameter.
Definition: Type.h:6401
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: Type.h:6417
SubstTemplateTypeParmTypeFlag getSubstitutionFlag() const
Definition: Type.h:6425
static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement, const Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag)
Definition: Type.h:6438
QualType desugar() const
Definition: Type.h:6431
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3578
static bool classof(const Type *T)
Definition: Type.h:6070
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:6666
ArrayRef< TemplateArgument > template_arguments() const
Definition: Type.h:6734
static bool classof(const Type *T)
Definition: Type.h:6752
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:6732
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Definition: Type.h:6725
QualType desugar() const
Definition: Type.h:6743
bool isCurrentInstantiation() const
True if this template specialization type matches a current instantiation in the context in which it ...
Definition: Type.h:6706
Declaration of a template type parameter.
TemplateTypeParmDecl * getDecl() const
Definition: Type.h:6353
QualType desugar() const
Definition: Type.h:6358
bool isParameterPack() const
Definition: Type.h:6349
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:6360
unsigned getIndex() const
Definition: Type.h:6348
bool isSugared() const
Definition: Type.h:6357
static bool classof(const Type *T)
Definition: Type.h:6373
static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *TTPDecl)
Definition: Type.h:6364
unsigned getDepth() const
Definition: Type.h:6347
[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:5802
static bool classof(const Type *T)
Definition: Type.h:5826
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5816
Expr * getUnderlyingExpr() const
Definition: Type.h:5813
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5852
static bool classof(const Type *T)
Definition: Type.h:5875
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition: Type.h:5871
bool isSugared() const
Returns whether this type directly provides sugar.
Definition: Type.h:5868
QualType getUnmodifiedType() const
Definition: Type.h:5862
The type-property cache.
Definition: Type.cpp:4501
A container of type source information.
Definition: Type.h:7907
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7918
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition: Type.h:7924
A helper class for Type nodes having an ElaboratedTypeKeyword.
Definition: Type.h:6897
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence)
Definition: Type.h:6899
static CannotCastToThisType classof(const Type *)
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition: Type.h:6929
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6906
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:8643
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:8805
BuiltinTypeBitfields BuiltinTypeBits
Definition: Type.h:2277
bool isReferenceType() const
Definition: Type.h:8209
bool isEnumeralType() const
Definition: Type.h:8295
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:8187
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:8736
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:3427
TypedefNameDecl * getDecl() const
Definition: Type.h:5745
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5755
static bool classof(const Type *T)
Definition: Type.h:5765
bool typeMatchesDecl() const
Definition: Type.h:5753
bool isSugared() const
Definition: Type.h:5747
static void Profile(llvm::FoldingSetNodeID &ID, const TypedefNameDecl *Decl, QualType Underlying)
Definition: Type.h:5758
A unary type transform, which is a type constructed from another.
Definition: Type.h:5994
QualType getUnderlyingType() const
Definition: Type.h:6020
QualType getBaseType() const
Definition: Type.h:6021
UTTKind getUTTKind() const
Definition: Type.h:6023
bool isSugared() const
Definition: Type.h:6017
static bool classof(const Type *T)
Definition: Type.h:6025
QualType desugar() const
Definition: Type.h:6018
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5672
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5692
QualType desugar() const
Definition: Type.h:5686
static void Profile(llvm::FoldingSetNodeID &ID, UnresolvedUsingTypenameDecl *D)
Definition: Type.h:5696
UnresolvedUsingTypenameDecl * getDecl() const
Definition: Type.h:5683
static bool classof(const Type *T)
Definition: Type.h:5688
bool isSugared() const
Definition: Type.h:5685
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3982
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3343
QualType desugar() const
Definition: Type.h:5718
void Profile(llvm::FoldingSetNodeID &ID)
Definition: Type.h:5723
bool isSugared() const
Definition: Type.h:5715
static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found, QualType Underlying)
Definition: Type.h:5726
static bool classof(const Type *T)
Definition: Type.h:5731
UsingShadowDecl * getFoundDecl() const
Definition: Type.h:5712
bool typeMatchesDecl() const
Definition: Type.h:5721
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:8089
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:5033
@ 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:6876
constexpr unsigned PointerAuthKeyNone
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition: Decl.h:5041
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
void FixedPointValueToString(SmallVectorImpl< char > &Str, llvm::APSInt Val, unsigned Scale)
Definition: Type.cpp:5161
std::integral_constant< bool, std::is_same< T, ArrayType >::value||std::is_base_of< ArrayType, T >::value > TypeIsArrayType
Definition: Type.h:8733
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:6851
@ 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:5074
FunctionEffectWithCondition Kept
Definition: Type.h:5073
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition: Type.h:4845
FunctionEffectWithCondition(FunctionEffect E, const EffectConditionExpr &C)
Definition: Type.h:4849
EffectConditionExpr Cond
Definition: Type.h:4847
Holds information about the various types of exception specification.
Definition: Type.h:5164
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition: Type.h:5184
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5166
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5169
Extra information about a function prototype.
Definition: Type.h:5192
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5199
bool requiresFunctionProtoTypeArmAttributes() const
Definition: Type.h:5224
FunctionEffectsRef FunctionEffects
Definition: Type.h:5202
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5200
bool requiresFunctionProtoTypeExtraBitfields() const
Definition: Type.h:5218
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
Definition: Type.h:5228
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:5212
FunctionType::ExtInfo ExtInfo
Definition: Type.h:5193
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:4625
unsigned AArch64SMEAttributes
Any AArch64 SME ACLE type attributes that need to be propagated on declarations and function pointers...
Definition: Type.h:4628
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:6274
llvm::dxil::ResourceClass ResourceClass
Definition: Type.h:6260
friend bool operator!=(const Attributes &LHS, const Attributes &RHS)
Definition: Type.h:6278
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:7929
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