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