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