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