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