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