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