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