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