clang 24.0.0git
TypeBase.h
Go to the documentation of this file.
1//===- TypeBase.h - C Language Family Type Representation -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// C Language Family Type Representation
11///
12/// This file defines the clang::Type interface and subclasses, used to
13/// represent types for languages in the C family.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CLANG_AST_TYPE_BASE_H
18#define LLVM_CLANG_AST_TYPE_BASE_H
19
27#include "clang/Basic/LLVM.h"
29#include "clang/Basic/Linkage.h"
35#include "llvm/ADT/APInt.h"
36#include "llvm/ADT/APSInt.h"
37#include "llvm/ADT/ArrayRef.h"
38#include "llvm/ADT/FoldingSet.h"
39#include "llvm/ADT/PointerIntPair.h"
40#include "llvm/ADT/PointerUnion.h"
41#include "llvm/ADT/STLForwardCompat.h"
42#include "llvm/ADT/StringRef.h"
43#include "llvm/ADT/Twine.h"
44#include "llvm/ADT/iterator_range.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/Compiler.h"
47#include "llvm/Support/DXILABI.h"
48#include "llvm/Support/ErrorHandling.h"
49#include "llvm/Support/PointerLikeTypeTraits.h"
50#include "llvm/Support/TrailingObjects.h"
51#include "llvm/Support/type_traits.h"
52#include <bitset>
53#include <cassert>
54#include <cstddef>
55#include <cstdint>
56#include <cstring>
57#include <optional>
58#include <string>
59#include <type_traits>
60#include <utility>
61
62namespace clang {
63
64class BTFTypeTagAttr;
65class ExtQuals;
66class QualType;
67class ConceptDecl;
68class ValueDecl;
69class TagDecl;
71class Type;
72class Attr;
74
75enum {
78};
79
80namespace serialization {
81 template <class T> class AbstractTypeReader;
82 template <class T> class AbstractTypeWriter;
83}
84
85} // namespace clang
86
87namespace llvm {
88
89 template <typename T>
91 template<>
93 static inline void *getAsVoidPointer(::clang::Type *P) { return P; }
94
95 static inline ::clang::Type *getFromVoidPointer(void *P) {
96 return static_cast< ::clang::Type*>(P);
97 }
98
100 };
101
102 template<>
104 static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; }
105
106 static inline ::clang::ExtQuals *getFromVoidPointer(void *P) {
107 return static_cast< ::clang::ExtQuals*>(P);
108 }
109
111 };
112
113} // namespace llvm
114
115namespace clang {
116
117class ASTContext;
118template <typename> class CanQual;
119class CXXRecordDecl;
120class DeclContext;
121class EnumDecl;
122class Expr;
123class ExtQualsTypeCommonBase;
124class FunctionDecl;
125class FunctionEffectsRef;
126class FunctionEffectKindSet;
127class FunctionEffectSet;
128class IdentifierInfo;
129class NamedDecl;
130class ObjCInterfaceDecl;
131class ObjCProtocolDecl;
132class ObjCTypeParamDecl;
133struct PrintingPolicy;
134class RecordDecl;
135class Stmt;
136class TagDecl;
137class ClassTemplateDecl;
138class TemplateArgument;
139class TemplateArgumentListInfo;
140class TemplateArgumentLoc;
141class TemplateTypeParmDecl;
142class TypedefNameDecl;
143class UnresolvedUsingTypenameDecl;
144class UsingShadowDecl;
145
146using CanQualType = CanQual<Type>;
147
148// Provide forward declarations for all of the *Type classes.
149#define TYPE(Class, Base) class Class##Type;
150#include "clang/AST/TypeNodes.inc"
151
152/// Pointer-authentication qualifiers.
153class PointerAuthQualifier {
154 enum : uint32_t {
155 EnabledShift = 0,
156 EnabledBits = 1,
157 EnabledMask = 1 << EnabledShift,
158 AddressDiscriminatedShift = EnabledShift + EnabledBits,
159 AddressDiscriminatedBits = 1,
160 AddressDiscriminatedMask = 1 << AddressDiscriminatedShift,
161 AuthenticationModeShift =
162 AddressDiscriminatedShift + AddressDiscriminatedBits,
163 AuthenticationModeBits = 2,
164 AuthenticationModeMask = ((1 << AuthenticationModeBits) - 1)
165 << AuthenticationModeShift,
166 IsaPointerShift = AuthenticationModeShift + AuthenticationModeBits,
167 IsaPointerBits = 1,
168 IsaPointerMask = ((1 << IsaPointerBits) - 1) << IsaPointerShift,
169 AuthenticatesNullValuesShift = IsaPointerShift + IsaPointerBits,
170 AuthenticatesNullValuesBits = 1,
171 AuthenticatesNullValuesMask = ((1 << AuthenticatesNullValuesBits) - 1)
172 << AuthenticatesNullValuesShift,
173 KeyShift = AuthenticatesNullValuesShift + AuthenticatesNullValuesBits,
174 KeyBits = 10,
175 KeyMask = ((1 << KeyBits) - 1) << KeyShift,
176 DiscriminatorShift = KeyShift + KeyBits,
177 DiscriminatorBits = 16,
178 DiscriminatorMask = ((1u << DiscriminatorBits) - 1) << DiscriminatorShift,
179 };
180
181 // bits: |0 |1 |2..3 |4 |
182 // |Enabled|Address|AuthenticationMode|ISA pointer|
183 // bits: |5 |6..15| 16...31 |
184 // |AuthenticatesNull|Key |Discriminator|
185 uint32_t Data = 0;
186
187 // The following static assertions check that each of the 32 bits is present
188 // exactly in one of the constants.
189 static_assert((EnabledBits + AddressDiscriminatedBits +
190 AuthenticationModeBits + IsaPointerBits +
191 AuthenticatesNullValuesBits + KeyBits + DiscriminatorBits) ==
192 32,
193 "PointerAuthQualifier should be exactly 32 bits");
194 static_assert((EnabledMask + AddressDiscriminatedMask +
195 AuthenticationModeMask + IsaPointerMask +
196 AuthenticatesNullValuesMask + KeyMask + DiscriminatorMask) ==
197 0xFFFFFFFF,
198 "All masks should cover the entire bits");
199 static_assert((EnabledMask ^ AddressDiscriminatedMask ^
200 AuthenticationModeMask ^ IsaPointerMask ^
201 AuthenticatesNullValuesMask ^ KeyMask ^ DiscriminatorMask) ==
202 0xFFFFFFFF,
203 "All masks should cover the entire bits");
204
205 PointerAuthQualifier(unsigned Key, bool IsAddressDiscriminated,
206 unsigned ExtraDiscriminator,
207 PointerAuthenticationMode AuthenticationMode,
208 bool IsIsaPointer, bool AuthenticatesNullValues)
209 : Data(EnabledMask |
210 (IsAddressDiscriminated
211 ? llvm::to_underlying(AddressDiscriminatedMask)
212 : 0) |
213 (Key << KeyShift) |
214 (llvm::to_underlying(AuthenticationMode)
215 << AuthenticationModeShift) |
216 (ExtraDiscriminator << DiscriminatorShift) |
217 (IsIsaPointer << IsaPointerShift) |
218 (AuthenticatesNullValues << AuthenticatesNullValuesShift)) {
219 assert(Key <= KeyNoneInternal);
220 assert(ExtraDiscriminator <= MaxDiscriminator);
221 assert((Data == 0) ==
223 }
224
225public:
226 enum {
227 KeyNoneInternal = (1u << KeyBits) - 1,
228
229 /// The maximum supported pointer-authentication key.
231
232 /// The maximum supported pointer-authentication discriminator.
233 MaxDiscriminator = (1u << DiscriminatorBits) - 1
234 };
235
236public:
238
239 static PointerAuthQualifier
240 Create(unsigned Key, bool IsAddressDiscriminated, unsigned ExtraDiscriminator,
241 PointerAuthenticationMode AuthenticationMode, bool IsIsaPointer,
242 bool AuthenticatesNullValues) {
243 if (Key == PointerAuthKeyNone)
244 Key = KeyNoneInternal;
245 assert(Key <= KeyNoneInternal && "out-of-range key value");
246 return PointerAuthQualifier(Key, IsAddressDiscriminated, ExtraDiscriminator,
247 AuthenticationMode, IsIsaPointer,
248 AuthenticatesNullValues);
249 }
250
251 bool isPresent() const {
252 assert((Data == 0) ==
254 return Data != 0;
255 }
256
257 explicit operator bool() const { return isPresent(); }
258
259 unsigned getKey() const {
260 assert(isPresent());
261 return (Data & KeyMask) >> KeyShift;
262 }
263
264 bool hasKeyNone() const { return isPresent() && getKey() == KeyNoneInternal; }
265
267 assert(isPresent());
268 return (Data & AddressDiscriminatedMask) >> AddressDiscriminatedShift;
269 }
270
271 unsigned getExtraDiscriminator() const {
272 assert(isPresent());
273 return (Data >> DiscriminatorShift);
274 }
275
277 return PointerAuthenticationMode((Data & AuthenticationModeMask) >>
278 AuthenticationModeShift);
279 }
280
281 bool isIsaPointer() const {
282 assert(isPresent());
283 return (Data & IsaPointerMask) >> IsaPointerShift;
284 }
285
287 assert(isPresent());
288 return (Data & AuthenticatesNullValuesMask) >> AuthenticatesNullValuesShift;
289 }
290
291 PointerAuthQualifier withoutKeyNone() const {
292 return hasKeyNone() ? PointerAuthQualifier() : *this;
293 }
294
295 friend bool operator==(PointerAuthQualifier Lhs, PointerAuthQualifier Rhs) {
296 return Lhs.Data == Rhs.Data;
297 }
298 friend bool operator!=(PointerAuthQualifier Lhs, PointerAuthQualifier Rhs) {
299 return Lhs.Data != Rhs.Data;
300 }
301
302 bool isEquivalent(PointerAuthQualifier Other) const {
303 return withoutKeyNone() == Other.withoutKeyNone();
304 }
305
306 uint32_t getAsOpaqueValue() const { return Data; }
307
308 // Deserialize pointer-auth qualifiers from an opaque representation.
309 static PointerAuthQualifier fromOpaqueValue(uint32_t Opaque) {
310 PointerAuthQualifier Result;
311 Result.Data = Opaque;
312 assert((Result.Data == 0) ==
313 (Result.getAuthenticationMode() == PointerAuthenticationMode::None));
314 return Result;
315 }
316
317 std::string getAsString() const;
318 std::string getAsString(const PrintingPolicy &Policy) const;
319
320 bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
321 void print(raw_ostream &OS, const PrintingPolicy &Policy) const;
322
323 void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Data); }
324};
325
326/// The collection of all-type qualifiers we support.
327/// Clang supports five independent qualifiers:
328/// * C99: const, volatile, and restrict
329/// * MS: __unaligned
330/// * Embedded C (TR18037): address spaces
331/// * Objective C: the GC attributes (none, weak, or strong)
333public:
334 Qualifiers() = default;
335 enum TQ : uint64_t {
336 // NOTE: These flags must be kept in sync with DeclSpec::TQ.
337 Const = 0x1,
338 Restrict = 0x2,
339 Volatile = 0x4,
341 };
342
343 enum GC {
347 };
348
350 /// There is no lifetime qualification on this type.
352
353 /// This object can be modified without requiring retains or
354 /// releases.
356
357 /// Assigning into this object requires the old value to be
358 /// released and the new value to be retained. The timing of the
359 /// release of the old value is inexact: it may be moved to
360 /// immediately after the last known point where the value is
361 /// live.
363
364 /// Reading or writing from this object requires a barrier call.
366
367 /// Assigning into this object requires a lifetime extension.
369 };
370
371 enum : uint64_t {
372 /// The maximum supported address space number.
373 /// 23 bits should be enough for anyone.
374 MaxAddressSpace = 0x7fffffu,
375
376 /// The width of the "fast" qualifier mask.
378
379 /// The fast qualifier mask.
380 FastMask = (1 << FastWidth) - 1
381 };
382
383 /// Returns the common set of qualifiers while removing them from
384 /// the given sets.
386 Qualifiers Q;
388 if (LPtrAuth.isPresent() &&
390 LPtrAuth == R.getPointerAuth()) {
391 Q.setPointerAuth(LPtrAuth);
394 R.setPointerAuth(Empty);
395 }
396
397 // If both are only CVR-qualified, bit operations are sufficient.
398 if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) {
399 Q.Mask = L.Mask & R.Mask;
400 L.Mask &= ~Q.Mask;
401 R.Mask &= ~Q.Mask;
402 return Q;
403 }
404
405 unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers();
406 Q.addCVRQualifiers(CommonCRV);
407 L.removeCVRQualifiers(CommonCRV);
408 R.removeCVRQualifiers(CommonCRV);
409
410 if (L.getObjCGCAttr() == R.getObjCGCAttr()) {
413 R.removeObjCGCAttr();
414 }
415
416 if (L.getObjCLifetime() == R.getObjCLifetime()) {
419 R.removeObjCLifetime();
420 }
421
422 if (L.getAddressSpace() == R.getAddressSpace()) {
425 R.removeAddressSpace();
426 }
427 return Q;
428 }
429
430 static Qualifiers fromFastMask(unsigned Mask) {
431 Qualifiers Qs;
432 Qs.addFastQualifiers(Mask);
433 return Qs;
434 }
435
436 static Qualifiers fromCVRMask(unsigned CVR) {
437 Qualifiers Qs;
438 Qs.addCVRQualifiers(CVR);
439 return Qs;
440 }
441
442 static Qualifiers fromCVRUMask(unsigned CVRU) {
443 Qualifiers Qs;
444 Qs.addCVRUQualifiers(CVRU);
445 return Qs;
446 }
447
448 // Deserialize qualifiers from an opaque representation.
450 Qualifiers Qs;
451 Qs.Mask = opaque;
452 return Qs;
453 }
454
455 // Serialize these qualifiers into an opaque representation.
456 uint64_t getAsOpaqueValue() const { return Mask; }
457
458 bool hasConst() const { return Mask & Const; }
459 bool hasOnlyConst() const { return Mask == Const; }
460 void removeConst() { Mask &= ~Const; }
461 void addConst() { Mask |= Const; }
463 Qualifiers Qs = *this;
464 Qs.addConst();
465 return Qs;
466 }
467
468 bool hasVolatile() const { return Mask & Volatile; }
469 bool hasOnlyVolatile() const { return Mask == Volatile; }
470 void removeVolatile() { Mask &= ~Volatile; }
471 void addVolatile() { Mask |= Volatile; }
473 Qualifiers Qs = *this;
474 Qs.addVolatile();
475 return Qs;
476 }
477
478 bool hasRestrict() const { return Mask & Restrict; }
479 bool hasOnlyRestrict() const { return Mask == Restrict; }
480 void removeRestrict() { Mask &= ~Restrict; }
481 void addRestrict() { Mask |= Restrict; }
483 Qualifiers Qs = *this;
484 Qs.addRestrict();
485 return Qs;
486 }
487
488 bool hasCVRQualifiers() const { return getCVRQualifiers(); }
489 unsigned getCVRQualifiers() const { return Mask & CVRMask; }
490 unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); }
491
492 void setCVRQualifiers(unsigned mask) {
493 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
494 Mask = (Mask & ~CVRMask) | mask;
495 }
496 void removeCVRQualifiers(unsigned mask) {
497 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
498 Mask &= ~static_cast<uint64_t>(mask);
499 }
503 void addCVRQualifiers(unsigned mask) {
504 assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits");
505 Mask |= mask;
506 }
507 void addCVRUQualifiers(unsigned mask) {
508 assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits");
509 Mask |= mask;
510 }
511
512 bool hasUnaligned() const { return Mask & UMask; }
513 void setUnaligned(bool flag) {
514 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
515 }
516 void removeUnaligned() { Mask &= ~UMask; }
517 void addUnaligned() { Mask |= UMask; }
518
519 bool hasObjCGCAttr() const { return Mask & GCAttrMask; }
520 GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); }
522 Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift);
523 }
526 assert(type);
528 }
530 Qualifiers qs = *this;
531 qs.removeObjCGCAttr();
532 return qs;
533 }
535 Qualifiers qs = *this;
537 return qs;
538 }
540 Qualifiers qs = *this;
542 return qs;
543 }
544
545 bool hasObjCLifetime() const { return Mask & LifetimeMask; }
547 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
548 }
550 Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift);
551 }
554 assert(type);
555 assert(!hasObjCLifetime());
556 Mask |= (type << LifetimeShift);
557 }
558
559 /// True if the lifetime is neither None or ExplicitNone.
561 ObjCLifetime lifetime = getObjCLifetime();
562 return (lifetime > OCL_ExplicitNone);
563 }
564
565 /// True if the lifetime is either strong or weak.
567 ObjCLifetime lifetime = getObjCLifetime();
568 return (lifetime == OCL_Strong || lifetime == OCL_Weak);
569 }
570
571 bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
573 return static_cast<LangAS>((Mask & AddressSpaceMask) >> AddressSpaceShift);
574 }
578 /// Get the address space attribute value to be printed by diagnostics.
580 auto Addr = getAddressSpace();
581 // This function is not supposed to be used with language specific
582 // address spaces. If that happens, the diagnostic message should consider
583 // printing the QualType instead of the address space value.
585 if (Addr != LangAS::Default)
587 // TODO: The diagnostic messages where Addr may be 0 should be fixed
588 // since it cannot differentiate the situation where 0 denotes the default
589 // address space or user specified __attribute__((address_space(0))).
590 return 0;
591 }
593 assert((unsigned)space <= MaxAddressSpace);
594 Mask = (Mask & ~AddressSpaceMask)
595 | (((uint32_t) space) << AddressSpaceShift);
596 }
599 assert(space != LangAS::Default);
600 setAddressSpace(space);
601 }
602
603 bool hasPointerAuth() const { return Mask & PtrAuthMask; }
605 return PointerAuthQualifier::fromOpaqueValue(Mask >> PtrAuthShift);
606 }
608 Mask = (Mask & ~PtrAuthMask) |
609 (uint64_t(Q.getAsOpaqueValue()) << PtrAuthShift);
610 }
611 void removePointerAuth() { Mask &= ~PtrAuthMask; }
613 assert(Q.isPresent());
615 }
616
617 // Fast qualifiers are those that can be allocated directly
618 // on a QualType object.
619 bool hasFastQualifiers() const { return getFastQualifiers(); }
620 unsigned getFastQualifiers() const { return Mask & FastMask; }
621 void setFastQualifiers(unsigned mask) {
622 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
623 Mask = (Mask & ~FastMask) | mask;
624 }
625 void removeFastQualifiers(unsigned mask) {
626 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
627 Mask &= ~static_cast<uint64_t>(mask);
628 }
632 void addFastQualifiers(unsigned mask) {
633 assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits");
634 Mask |= mask;
635 }
636
637 /// Return true if the set contains any qualifiers which require an ExtQuals
638 /// node to be allocated.
639 bool hasNonFastQualifiers() const { return Mask & ~FastMask; }
641 Qualifiers Quals = *this;
642 Quals.setFastQualifiers(0);
643 return Quals;
644 }
645
646 /// Return true if the set contains any qualifiers.
647 bool hasQualifiers() const { return Mask; }
648 bool empty() const { return !Mask; }
649
650 /// Add the qualifiers from the given set to this set.
652 // If the other set doesn't have any non-boolean qualifiers, just
653 // bit-or it in.
654 if (!(Q.Mask & ~CVRMask))
655 Mask |= Q.Mask;
656 else {
657 Mask |= (Q.Mask & CVRMask);
658 if (Q.hasAddressSpace())
660 if (Q.hasObjCGCAttr())
662 if (Q.hasObjCLifetime())
664 if (Q.hasPointerAuth())
666 }
667 }
668
669 /// Remove the qualifiers from the given set from this set.
671 // If the other set doesn't have any non-boolean qualifiers, just
672 // bit-and the inverse in.
673 if (!(Q.Mask & ~CVRMask))
674 Mask &= ~Q.Mask;
675 else {
676 Mask &= ~(Q.Mask & CVRMask);
677 if (getObjCGCAttr() == Q.getObjCGCAttr())
679 if (getObjCLifetime() == Q.getObjCLifetime())
681 if (getAddressSpace() == Q.getAddressSpace())
683 if (getPointerAuth() == Q.getPointerAuth())
685 }
686 }
687
688 /// Add the qualifiers from the given set to this set, given that
689 /// they don't conflict.
691 assert(getAddressSpace() == qs.getAddressSpace() ||
692 !hasAddressSpace() || !qs.hasAddressSpace());
693 assert(getObjCGCAttr() == qs.getObjCGCAttr() ||
694 !hasObjCGCAttr() || !qs.hasObjCGCAttr());
695 assert(getObjCLifetime() == qs.getObjCLifetime() ||
696 !hasObjCLifetime() || !qs.hasObjCLifetime());
697 assert(!hasPointerAuth() || !qs.hasPointerAuth() ||
699 Mask |= qs.Mask;
700 }
701
702 /// Returns true if address space A is equal to or a superset of B.
703 /// OpenCL v2.0 defines conversion rules (OpenCLC v2.0 s6.5.5) and notion of
704 /// overlapping address spaces.
705 /// CL1.1 or CL1.2:
706 /// every address space is a superset of itself.
707 /// CL2.0 adds:
708 /// __generic is a superset of any address space except for __constant.
710 const ASTContext &Ctx) {
711 // Address spaces must match exactly.
712 return A == B || isTargetAddressSpaceSupersetOf(A, B, Ctx);
713 }
714
716 const ASTContext &Ctx);
717
718 /// Returns true if the address space in these qualifiers is equal to or
719 /// a superset of the address space in the argument qualifiers.
720 bool isAddressSpaceSupersetOf(Qualifiers other, const ASTContext &Ctx) const {
722 Ctx);
723 }
724
725 /// Determines if these qualifiers compatibly include another set.
726 /// Generally this answers the question of whether an object with the other
727 /// qualifiers can be safely used as an object with these qualifiers.
728 bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const {
729 return isAddressSpaceSupersetOf(other, Ctx) &&
730 // ObjC GC qualifiers can match, be added, or be removed, but can't
731 // be changed.
732 (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() ||
733 !other.hasObjCGCAttr()) &&
734 // Pointer-auth qualifiers must match exactly.
735 getPointerAuth() == other.getPointerAuth() &&
736 // ObjC lifetime qualifiers must match exactly.
737 getObjCLifetime() == other.getObjCLifetime() &&
738 // CVR qualifiers may subset.
739 (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) &&
740 // U qualifier may superset.
741 (!other.hasUnaligned() || hasUnaligned());
742 }
743
744 /// Determines if these qualifiers compatibly include another set of
745 /// qualifiers from the narrow perspective of Objective-C ARC lifetime.
746 ///
747 /// One set of Objective-C lifetime qualifiers compatibly includes the other
748 /// if the lifetime qualifiers match, or if both are non-__weak and the
749 /// including set also contains the 'const' qualifier, or both are non-__weak
750 /// and one is None (which can only happen in non-ARC modes).
752 if (getObjCLifetime() == other.getObjCLifetime())
753 return true;
754
755 if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak)
756 return false;
757
758 if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None)
759 return true;
760
761 return hasConst();
762 }
763
764 /// Determine whether this set of qualifiers is a strict superset of
765 /// another set of qualifiers, not considering qualifier compatibility.
767
768 bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
769 bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
770
771 explicit operator bool() const { return hasQualifiers(); }
772
774 addQualifiers(R);
775 return *this;
776 }
777
778 // Union two qualifier sets. If an enumerated qualifier appears
779 // in both sets, use the one from the right.
781 L += R;
782 return L;
783 }
784
787 return *this;
788 }
789
790 /// Compute the difference between two qualifier sets.
792 L -= R;
793 return L;
794 }
795
796 std::string getAsString() const;
797 std::string getAsString(const PrintingPolicy &Policy) const;
798
799 static std::string getAddrSpaceAsString(LangAS AS);
800
801 bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const;
802 void print(raw_ostream &OS, const PrintingPolicy &Policy,
803 bool appendSpaceIfNonEmpty = false) const;
804
805 void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(Mask); }
806
807private:
808 // bits: |0 1 2|3|4 .. 5|6 .. 8|9 ... 31|32 ... 63|
809 // |C R V|U|GCAttr|Lifetime|AddressSpace| PtrAuth |
810 uint64_t Mask = 0;
811 static_assert(sizeof(PointerAuthQualifier) == sizeof(uint32_t),
812 "PointerAuthQualifier must be 32 bits");
813
814 static constexpr uint64_t PtrAuthShift = 32;
815 static constexpr uint64_t PtrAuthMask = UINT64_C(0xffffffff) << PtrAuthShift;
816
817 static constexpr uint64_t UMask = 0x8;
818 static constexpr uint64_t UShift = 3;
819 static constexpr uint64_t GCAttrMask = 0x30;
820 static constexpr uint64_t GCAttrShift = 4;
821 static constexpr uint64_t LifetimeMask = 0x1C0;
822 static constexpr uint64_t LifetimeShift = 6;
823 static constexpr uint64_t AddressSpaceMask =
824 ~(CVRMask | UMask | GCAttrMask | LifetimeMask | PtrAuthMask);
825 static constexpr uint64_t AddressSpaceShift = 9;
826};
827
829 Qualifiers Quals;
830 bool HasAtomic;
831
832public:
833 QualifiersAndAtomic() : HasAtomic(false) {}
834 QualifiersAndAtomic(Qualifiers Quals, bool HasAtomic)
835 : Quals(Quals), HasAtomic(HasAtomic) {}
836
837 operator Qualifiers() const { return Quals; }
838
839 bool hasVolatile() const { return Quals.hasVolatile(); }
840 bool hasConst() const { return Quals.hasConst(); }
841 bool hasRestrict() const { return Quals.hasRestrict(); }
842 bool hasAtomic() const { return HasAtomic; }
843
844 void addVolatile() { Quals.addVolatile(); }
845 void addConst() { Quals.addConst(); }
846 void addRestrict() { Quals.addRestrict(); }
847 void addAtomic() { HasAtomic = true; }
848
849 void removeVolatile() { Quals.removeVolatile(); }
850 void removeConst() { Quals.removeConst(); }
851 void removeRestrict() { Quals.removeRestrict(); }
852 void removeAtomic() { HasAtomic = false; }
853
855 return {Quals.withVolatile(), HasAtomic};
856 }
857 QualifiersAndAtomic withConst() { return {Quals.withConst(), HasAtomic}; }
859 return {Quals.withRestrict(), HasAtomic};
860 }
861 QualifiersAndAtomic withAtomic() { return {Quals, true}; }
862
864 Quals += RHS;
865 return *this;
866 }
867};
868
869/// A std::pair-like structure for storing a qualified type split
870/// into its local qualifiers and its locally-unqualified type.
872 /// The locally-unqualified type.
873 const Type *Ty = nullptr;
874
875 /// The local qualifiers.
877
878 SplitQualType() = default;
879 SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {}
880
881 SplitQualType getSingleStepDesugaredType() const; // end of this file
882
883 // Make std::tie work.
884 std::pair<const Type *,Qualifiers> asPair() const {
885 return std::pair<const Type *, Qualifiers>(Ty, Quals);
886 }
887
889 return a.Ty == b.Ty && a.Quals == b.Quals;
890 }
892 return a.Ty != b.Ty || a.Quals != b.Quals;
893 }
894};
895
896/// The kind of type we are substituting Objective-C type arguments into.
897///
898/// The kind of substitution affects the replacement of type parameters when
899/// no concrete type information is provided, e.g., when dealing with an
900/// unspecialized type.
902 /// An ordinary type.
904
905 /// The result type of a method or function.
907
908 /// The parameter type of a method or function.
910
911 /// The type of a property.
913
914 /// The superclass of a type.
916};
917
918/// The kind of 'typeof' expression we're after.
923
924/// A (possibly-)qualified type.
925///
926/// For efficiency, we don't store CV-qualified types as nodes on their
927/// own: instead each reference to a type stores the qualifiers. This
928/// greatly reduces the number of nodes we need to allocate for types (for
929/// example we only need one for 'int', 'const int', 'volatile int',
930/// 'const volatile int', etc).
931///
932/// As an added efficiency bonus, instead of making this a pair, we
933/// just store the two bits we care about in the low bits of the
934/// pointer. To handle the packing/unpacking, we make QualType be a
935/// simple wrapper class that acts like a smart pointer. A third bit
936/// indicates whether there are extended qualifiers present, in which
937/// case the pointer points to a special structure.
938class QualType {
939 friend class QualifierCollector;
940
941 // Thankfully, these are efficiently composable.
942 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
944
945 const ExtQuals *getExtQualsUnsafe() const {
946 return cast<const ExtQuals *>(Value.getPointer());
947 }
948
949 const Type *getTypePtrUnsafe() const {
950 return cast<const Type *>(Value.getPointer());
951 }
952
953 const ExtQualsTypeCommonBase *getCommonPtr() const {
954 assert(!isNull() && "Cannot retrieve a NULL type pointer");
955 auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue());
956 CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1);
957 return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal);
958 }
959
960public:
961 QualType() = default;
962 QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
963 QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {}
964
965 unsigned getLocalFastQualifiers() const { return Value.getInt(); }
966 void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); }
967
968 bool UseExcessPrecision(const ASTContext &Ctx);
969
970 /// Retrieves a pointer to the underlying (unqualified) type.
971 ///
972 /// This function requires that the type not be NULL. If the type might be
973 /// NULL, use the (slightly less efficient) \c getTypePtrOrNull().
974 const Type *getTypePtr() const;
975
976 const Type *getTypePtrOrNull() const;
977
978 /// Retrieves a pointer to the name of the base type.
980
981 /// Divides a QualType into its unqualified type and a set of local
982 /// qualifiers.
983 SplitQualType split() const;
984
985 void *getAsOpaquePtr() const { return Value.getOpaqueValue(); }
986
987 static QualType getFromOpaquePtr(const void *Ptr) {
988 QualType T;
989 T.Value.setFromOpaqueValue(const_cast<void*>(Ptr));
990 return T;
991 }
992
993 const Type &operator*() const {
994 return *getTypePtr();
995 }
996
997 const Type *operator->() const {
998 return getTypePtr();
999 }
1000
1001 bool isCanonical() const;
1002 bool isCanonicalAsParam() const;
1003
1004 /// Return true if this QualType doesn't point to a type yet.
1005 bool isNull() const {
1006 return Value.getPointer().isNull();
1007 }
1008
1009 // Determines if a type can form `T&`.
1010 bool isReferenceable() const;
1011
1012 /// Determine whether this particular QualType instance has the
1013 /// "const" qualifier set, without looking through typedefs that may have
1014 /// added "const" at a different level.
1017 }
1018
1019 /// Determine whether this type is const-qualified.
1020 bool isConstQualified() const;
1021
1028 /// Determine whether instances of this type can be placed in immutable
1029 /// storage.
1030 /// If ExcludeCtor is true, the duration when the object's constructor runs
1031 /// will not be considered. The caller will need to verify that the object is
1032 /// not written to during its construction. ExcludeDtor works similarly.
1033 std::optional<NonConstantStorageReason>
1034 isNonConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
1035 bool ExcludeDtor);
1036
1037 bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor,
1038 bool ExcludeDtor) {
1039 return !isNonConstantStorage(Ctx, ExcludeCtor, ExcludeDtor);
1040 }
1041
1042 /// Determine whether this particular QualType instance has the
1043 /// "restrict" qualifier set, without looking through typedefs that may have
1044 /// added "restrict" at a different level.
1048
1049 /// Determine whether this type is restrict-qualified.
1050 bool isRestrictQualified() const;
1051
1052 /// Determine whether this particular QualType instance has the
1053 /// "volatile" qualifier set, without looking through typedefs that may have
1054 /// added "volatile" at a different level.
1058
1059 /// Determine whether this type is volatile-qualified.
1060 bool isVolatileQualified() const;
1061
1062 /// Determine whether this particular QualType instance has any
1063 /// qualifiers, without looking through any typedefs that might add
1064 /// qualifiers at a different level.
1068
1069 /// Determine whether this type has any qualifiers.
1070 bool hasQualifiers() const;
1071
1072 /// Determine whether this particular QualType instance has any
1073 /// "non-fast" qualifiers, e.g., those that are stored in an ExtQualType
1074 /// instance.
1076 return isa<const ExtQuals *>(Value.getPointer());
1077 }
1078
1079 /// Retrieve the set of qualifiers local to this particular QualType
1080 /// instance, not including any qualifiers acquired through typedefs or
1081 /// other sugar.
1083
1084 /// Retrieve the set of qualifiers applied to this type.
1085 Qualifiers getQualifiers() const;
1086
1087 /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
1088 /// local to this particular QualType instance, not including any qualifiers
1089 /// acquired through typedefs or other sugar.
1090 unsigned getLocalCVRQualifiers() const {
1091 return getLocalFastQualifiers();
1092 }
1093
1094 /// Retrieve the set of CVR (const-volatile-restrict) qualifiers
1095 /// applied to this type.
1096 unsigned getCVRQualifiers() const;
1097
1098 bool isConstant(const ASTContext& Ctx) const {
1099 return QualType::isConstant(*this, Ctx);
1100 }
1101
1102 /// Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
1103 bool isPODType(const ASTContext &Context) const;
1104
1105 /// Return true if this is a POD type according to the rules of the C++98
1106 /// standard, regardless of the current compilation's language.
1107 bool isCXX98PODType(const ASTContext &Context) const;
1108
1109 /// Return true if this is a POD type according to the more relaxed rules
1110 /// of the C++11 standard, regardless of the current compilation's language.
1111 /// (C++0x [basic.types]p9). Note that, unlike
1112 /// CXXRecordDecl::isCXX11StandardLayout, this takes DRs into account.
1113 bool isCXX11PODType(const ASTContext &Context) const;
1114
1115 /// Return true if this is a trivial type per (C++0x [basic.types]p9)
1116 bool isTrivialType(const ASTContext &Context) const;
1117
1118 /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
1119 bool isTriviallyCopyableType(const ASTContext &Context) const;
1120
1121 /// Return true if the type is safe to bitwise copy using memcpy/memmove.
1122 ///
1123 /// This is an extension in clang: bitwise cloneable types act as trivially
1124 /// copyable types, meaning their underlying bytes can be safely copied by
1125 /// memcpy or memmove. After the copy, the destination object has the same
1126 /// object representation.
1127 ///
1128 /// However, there are cases where it is not safe to copy:
1129 /// - When sanitizers, such as AddressSanitizer, add padding with poison,
1130 /// which can cause issues if those poisoned padding bits are accessed.
1131 /// - Types with Objective-C lifetimes, where specific runtime
1132 /// semantics may not be preserved during a bitwise copy.
1133 bool isBitwiseCloneableType(const ASTContext &Context) const;
1134
1135 /// Return true if this is a trivially copyable type
1136 bool isTriviallyCopyConstructibleType(const ASTContext &Context) const;
1137
1138 /// Returns true if the type uses postfix declarator syntax, i.e. the
1139 /// declarator component appears after the name (arrays, functions).
1140 /// Looks through pointer-like types to the pointee.
1141 bool hasPostfixDeclaratorSyntax() const;
1142
1143 /// Returns true if it is a class and it might be dynamic.
1144 bool mayBeDynamicClass() const;
1145
1146 /// Returns true if it is not a class or if the class might not be dynamic.
1147 bool mayBeNotDynamicClass() const;
1148
1149 /// Returns true if it is a WebAssembly Reference Type.
1150 bool isWebAssemblyReferenceType() const;
1151
1152 /// Returns true if it is a WebAssembly Externref Type.
1153 bool isWebAssemblyExternrefType() const;
1154
1155 /// Returns true if it is a WebAssembly Funcref Type.
1156 bool isWebAssemblyFuncrefType() const;
1157
1158 /// Returns true if it is a OverflowBehaviorType of Wrap kind.
1159 bool isWrapType() const;
1160
1161 /// Returns true if it is a OverflowBehaviorType of Trap kind.
1162 bool isTrapType() const;
1163
1164 /// Returns true if this type requires laundering by checking if it is a
1165 /// dynamic class type, or contains a subobject which is a dynamic class type.
1166 bool requiresBuiltinLaunder(const ASTContext &Context) const;
1167
1168 // Don't promise in the API that anything besides 'const' can be
1169 // easily added.
1170
1171 /// Add the `const` type qualifier to this QualType.
1178
1179 /// Add the `volatile` type qualifier to this QualType.
1186
1187 /// Add the `restrict` qualifier to this QualType.
1194
1195 QualType withCVRQualifiers(unsigned CVR) const {
1196 return withFastQualifiers(CVR);
1197 }
1198
1199 void addFastQualifiers(unsigned TQs) {
1200 assert(!(TQs & ~Qualifiers::FastMask)
1201 && "non-fast qualifier bits set in mask!");
1202 Value.setInt(Value.getInt() | TQs);
1203 }
1204
1205 void removeLocalConst();
1206 void removeLocalVolatile();
1207 void removeLocalRestrict();
1208
1209 void removeLocalFastQualifiers() { Value.setInt(0); }
1210 void removeLocalFastQualifiers(unsigned Mask) {
1211 assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers");
1212 Value.setInt(Value.getInt() & ~Mask);
1213 }
1214
1215 // Creates a type with the given qualifiers in addition to any
1216 // qualifiers already on this type.
1217 QualType withFastQualifiers(unsigned TQs) const {
1218 QualType T = *this;
1219 T.addFastQualifiers(TQs);
1220 return T;
1221 }
1222
1223 // Creates a type with exactly the given fast qualifiers, removing
1224 // any existing fast qualifiers.
1228
1229 // Removes fast qualifiers, but leaves any extended qualifiers in place.
1231 QualType T = *this;
1232 T.removeLocalFastQualifiers();
1233 return T;
1234 }
1235
1236 QualType getCanonicalType() const;
1237
1238 /// Return this type with all of the instance-specific qualifiers
1239 /// removed, but without removing any qualifiers that may have been applied
1240 /// through typedefs.
1242
1243 /// Retrieve the unqualified variant of the given type,
1244 /// removing as little sugar as possible.
1245 ///
1246 /// This routine looks through various kinds of sugar to find the
1247 /// least-desugared type that is unqualified. For example, given:
1248 ///
1249 /// \code
1250 /// typedef int Integer;
1251 /// typedef const Integer CInteger;
1252 /// typedef CInteger DifferenceType;
1253 /// \endcode
1254 ///
1255 /// Executing \c getUnqualifiedType() on the type \c DifferenceType will
1256 /// desugar until we hit the type \c Integer, which has no qualifiers on it.
1257 ///
1258 /// The resulting type might still be qualified if it's sugar for an array
1259 /// type. To strip qualifiers even from within a sugared array type, use
1260 /// ASTContext::getUnqualifiedArrayType.
1261 ///
1262 /// Note: In C, the _Atomic qualifier is special (see C23 6.2.5p32 for
1263 /// details), and it is not stripped by this function. Use
1264 /// getAtomicUnqualifiedType() to strip qualifiers including _Atomic.
1265 inline QualType getUnqualifiedType() const;
1266
1267 /// Retrieve the unqualified variant of the given type, removing as little
1268 /// sugar as possible.
1269 ///
1270 /// Like getUnqualifiedType(), but also returns the set of
1271 /// qualifiers that were built up.
1272 ///
1273 /// The resulting type might still be qualified if it's sugar for an array
1274 /// type. To strip qualifiers even from within a sugared array type, use
1275 /// ASTContext::getUnqualifiedArrayType.
1277
1278 /// Determine whether this type is more qualified than the other
1279 /// given type, requiring exact equality for non-CVR qualifiers.
1280 bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const;
1281
1282 /// Determine whether this type is at least as qualified as the other
1283 /// given type, requiring exact equality for non-CVR qualifiers.
1284 bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const;
1285
1287
1288 /// Determine the type of a (typically non-lvalue) expression with the
1289 /// specified result type.
1290 ///
1291 /// This routine should be used for expressions for which the return type is
1292 /// explicitly specified (e.g., in a cast or call) and isn't necessarily
1293 /// an lvalue. It removes a top-level reference (since there are no
1294 /// expressions of reference type) and deletes top-level cvr-qualifiers
1295 /// from non-class types (in C++) or all types (in C).
1296 QualType getNonLValueExprType(const ASTContext &Context) const;
1297
1298 /// Remove an outer pack expansion type (if any) from this type. Used as part
1299 /// of converting the type of a declaration to the type of an expression that
1300 /// references that expression. It's meaningless for an expression to have a
1301 /// pack expansion type.
1303
1304 /// Return the specified type with any "sugar" removed from
1305 /// the type. This takes off typedefs, typeof's etc. If the outer level of
1306 /// the type is already concrete, it returns it unmodified. This is similar
1307 /// to getting the canonical type, but it doesn't remove *all* typedefs. For
1308 /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
1309 /// concrete.
1310 ///
1311 /// Qualifiers are left in place.
1312 QualType getDesugaredType(const ASTContext &Context) const {
1313 return getDesugaredType(*this, Context);
1314 }
1315
1317 return getSplitDesugaredType(*this);
1318 }
1319
1320 /// Return the specified type with one level of "sugar" removed from
1321 /// the type.
1322 ///
1323 /// This routine takes off the first typedef, typeof, etc. If the outer level
1324 /// of the type is already concrete, it returns it unmodified.
1326 return getSingleStepDesugaredTypeImpl(*this, Context);
1327 }
1328
1329 /// Returns the specified type after dropping any
1330 /// outer-level parentheses.
1332 if (isa<ParenType>(*this))
1333 return QualType::IgnoreParens(*this);
1334 return *this;
1335 }
1336
1337 /// Indicate whether the specified types and qualifiers are identical.
1338 friend bool operator==(const QualType &LHS, const QualType &RHS) {
1339 return LHS.Value == RHS.Value;
1340 }
1341 friend bool operator!=(const QualType &LHS, const QualType &RHS) {
1342 return LHS.Value != RHS.Value;
1343 }
1344 friend bool operator<(const QualType &LHS, const QualType &RHS) {
1345 return LHS.Value < RHS.Value;
1346 }
1347
1348 static std::string getAsString(SplitQualType split,
1349 const PrintingPolicy &Policy) {
1350 return getAsString(split.Ty, split.Quals, Policy);
1351 }
1352 static std::string getAsString(const Type *ty, Qualifiers qs,
1353 const PrintingPolicy &Policy);
1354
1355 std::string getAsString() const;
1356 std::string getAsString(const PrintingPolicy &Policy) const;
1357
1358 void print(raw_ostream &OS, const PrintingPolicy &Policy,
1359 const Twine &PlaceHolder = Twine(),
1360 unsigned Indentation = 0) const;
1361
1362 static void print(SplitQualType split, raw_ostream &OS,
1363 const PrintingPolicy &policy, const Twine &PlaceHolder,
1364 unsigned Indentation = 0) {
1365 return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation);
1366 }
1367
1368 static void print(const Type *ty, Qualifiers qs,
1369 raw_ostream &OS, const PrintingPolicy &policy,
1370 const Twine &PlaceHolder,
1371 unsigned Indentation = 0);
1372
1373 void getAsStringInternal(std::string &Str,
1374 const PrintingPolicy &Policy) const;
1375
1376 static void getAsStringInternal(SplitQualType split, std::string &out,
1377 const PrintingPolicy &policy) {
1378 return getAsStringInternal(split.Ty, split.Quals, out, policy);
1379 }
1380
1381 static void getAsStringInternal(const Type *ty, Qualifiers qs,
1382 std::string &out,
1383 const PrintingPolicy &policy);
1384
1386 const QualType &T;
1387 const PrintingPolicy &Policy;
1388 const Twine &PlaceHolder;
1389 unsigned Indentation;
1390
1391 public:
1393 const Twine &PlaceHolder, unsigned Indentation)
1394 : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1395 Indentation(Indentation) {}
1396
1397 friend raw_ostream &operator<<(raw_ostream &OS,
1398 const StreamedQualTypeHelper &SQT) {
1399 SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1400 return OS;
1401 }
1402 };
1403
1405 const Twine &PlaceHolder = Twine(),
1406 unsigned Indentation = 0) const {
1407 return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation);
1408 }
1409
1410 void dump(const char *s) const;
1411 void dump() const;
1412 void dump(llvm::raw_ostream &OS, const ASTContext &Context) const;
1413
1414 void Profile(llvm::FoldingSetNodeID &ID) const {
1415 ID.AddPointer(getAsOpaquePtr());
1416 }
1417
1418 /// Check if this type has any address space qualifier.
1419 inline bool hasAddressSpace() const;
1420
1421 /// Return the address space of this type.
1422 inline LangAS getAddressSpace() const;
1423
1424 /// Returns true if address space qualifiers overlap with T address space
1425 /// qualifiers.
1426 /// OpenCL C defines conversion rules for pointers to different address spaces
1427 /// and notion of overlapping address spaces.
1428 /// CL1.1 or CL1.2:
1429 /// address spaces overlap iff they are they same.
1430 /// OpenCL C v2.0 s6.5.5 adds:
1431 /// __generic overlaps with any address space except for __constant.
1434 Qualifiers TQ = T.getQualifiers();
1435 // Address spaces overlap if at least one of them is a superset of another
1436 return Q.isAddressSpaceSupersetOf(TQ, Ctx) ||
1437 TQ.isAddressSpaceSupersetOf(Q, Ctx);
1438 }
1439
1440 /// Returns gc attribute of this type.
1441 inline Qualifiers::GC getObjCGCAttr() const;
1442
1443 /// true when Type is objc's weak.
1444 bool isObjCGCWeak() const {
1445 return getObjCGCAttr() == Qualifiers::Weak;
1446 }
1447
1448 /// true when Type is objc's strong.
1449 bool isObjCGCStrong() const {
1451 }
1452
1453 /// Returns lifetime attribute of this type.
1457
1461
1465
1466 // true when Type is objc's weak and weak is enabled but ARC isn't.
1467 bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
1468
1472
1474 if (PointerAuthQualifier PtrAuth = getPointerAuth())
1475 return PtrAuth.isAddressDiscriminated();
1476 return false;
1477 }
1478
1480 /// The type does not fall into any of the following categories. Note that
1481 /// this case is zero-valued so that values of this enum can be used as a
1482 /// boolean condition for non-triviality.
1484
1485 /// The type is an Objective-C retainable pointer type that is qualified
1486 /// with the ARC __strong qualifier.
1488
1489 /// The type is an Objective-C retainable pointer type that is qualified
1490 /// with the ARC __weak qualifier.
1492
1493 /// The type is a struct containing a field whose type is not PCK_Trivial.
1495 };
1496
1497 /// Functions to query basic properties of non-trivial C struct types.
1498
1499 /// Check if this is a non-trivial type that would cause a C struct
1500 /// transitively containing this type to be non-trivial to default initialize
1501 /// and return the kind.
1504
1506 /// The type does not fall into any of the following categories. Note that
1507 /// this case is zero-valued so that values of this enum can be used as a
1508 /// boolean condition for non-triviality.
1510
1511 /// The type would be trivial except that it is volatile-qualified. Types
1512 /// that fall into one of the other non-trivial cases may additionally be
1513 /// volatile-qualified.
1515
1516 /// The type is an Objective-C retainable pointer type that is qualified
1517 /// with the ARC __strong qualifier.
1519
1520 /// The type is an Objective-C retainable pointer type that is qualified
1521 /// with the ARC __weak qualifier.
1523
1524 /// The type is an address-discriminated signed pointer type.
1526
1527 /// The type is a struct containing a field whose type is neither
1528 /// PCK_Trivial nor PCK_VolatileTrivial.
1529 /// Note that a C++ struct type does not necessarily match this; C++ copying
1530 /// semantics are too complex to express here, in part because they depend
1531 /// on the exact constructor or assignment operator that is chosen by
1532 /// overload resolution to do the copy.
1534 };
1535
1536 /// Check if this is a non-trivial type that would cause a C struct
1537 /// transitively containing this type to be non-trivial to copy and return the
1538 /// kind.
1540
1541 /// Check if this is a non-trivial type that would cause a C struct
1542 /// transitively containing this type to be non-trivial to destructively
1543 /// move and return the kind. Destructive move in this context is a C++-style
1544 /// move in which the source object is placed in a valid but unspecified state
1545 /// after it is moved, as opposed to a truly destructive move in which the
1546 /// source object is placed in an uninitialized state.
1548
1556
1557 /// Returns a nonzero value if objects of this type require
1558 /// non-trivial work to clean up after. Non-zero because it's
1559 /// conceivable that qualifiers (objc_gc(weak)?) could make
1560 /// something require destruction.
1562 return isDestructedTypeImpl(*this);
1563 }
1564
1565 /// Check if this is or contains a C union that is non-trivial to
1566 /// default-initialize, which is a union that has a member that is non-trivial
1567 /// to default-initialize. If this returns true,
1568 /// isNonTrivialToPrimitiveDefaultInitialize returns PDIK_Struct.
1570
1571 /// Check if this is or contains a C union that is non-trivial to destruct,
1572 /// which is a union that has a member that is non-trivial to destruct. If
1573 /// this returns true, isDestructedType returns DK_nontrivial_c_struct.
1575
1576 /// Check if this is or contains a C union that is non-trivial to copy, which
1577 /// is a union that has a member that is non-trivial to copy. If this returns
1578 /// true, isNonTrivialToPrimitiveCopy returns PCK_Struct.
1580
1581 /// Determine whether expressions of the given type are forbidden
1582 /// from being lvalues in C.
1583 ///
1584 /// The expression types that are forbidden to be lvalues are:
1585 /// - 'void', but not qualified void
1586 /// - function types
1587 ///
1588 /// The exact rule here is C99 6.3.2.1:
1589 /// An lvalue is an expression with an object type or an incomplete
1590 /// type other than void.
1591 bool isCForbiddenLValueType() const;
1592
1593 /// Substitute type arguments for the Objective-C type parameters used in the
1594 /// subject type.
1595 ///
1596 /// \param ctx ASTContext in which the type exists.
1597 ///
1598 /// \param typeArgs The type arguments that will be substituted for the
1599 /// Objective-C type parameters in the subject type, which are generally
1600 /// computed via \c Type::getObjCSubstitutions. If empty, the type
1601 /// parameters will be replaced with their bounds or id/Class, as appropriate
1602 /// for the context.
1603 ///
1604 /// \param context The context in which the subject type was written.
1605 ///
1606 /// \returns the resulting type.
1608 ArrayRef<QualType> typeArgs,
1609 ObjCSubstitutionContext context) const;
1610
1611 /// Substitute type arguments from an object type for the Objective-C type
1612 /// parameters used in the subject type.
1613 ///
1614 /// This operation combines the computation of type arguments for
1615 /// substitution (\c Type::getObjCSubstitutions) with the actual process of
1616 /// substitution (\c QualType::substObjCTypeArgs) for the convenience of
1617 /// callers that need to perform a single substitution in isolation.
1618 ///
1619 /// \param objectType The type of the object whose member type we're
1620 /// substituting into. For example, this might be the receiver of a message
1621 /// or the base of a property access.
1622 ///
1623 /// \param dc The declaration context from which the subject type was
1624 /// retrieved, which indicates (for example) which type parameters should
1625 /// be substituted.
1626 ///
1627 /// \param context The context in which the subject type was written.
1628 ///
1629 /// \returns the subject type after replacing all of the Objective-C type
1630 /// parameters with their corresponding arguments.
1632 const DeclContext *dc,
1633 ObjCSubstitutionContext context) const;
1634
1635 /// Strip Objective-C "__kindof" types from the given type.
1636 QualType stripObjCKindOfType(const ASTContext &ctx) const;
1637
1638 /// Strip nullability attributes from the given type.
1639 QualType stripNullability(const ASTContext &ctx) const;
1640
1641 /// Remove all qualifiers including _Atomic.
1642 ///
1643 /// Like getUnqualifiedType(), the type may still be qualified if it is a
1644 /// sugared array type. To strip qualifiers even from within a sugared array
1645 /// type, use in conjunction with ASTContext::getUnqualifiedArrayType.
1647
1648private:
1649 // These methods are implemented in a separate translation unit;
1650 // "static"-ize them to avoid creating temporary QualTypes in the
1651 // caller.
1652 static bool isConstant(QualType T, const ASTContext& Ctx);
1653 static QualType getDesugaredType(QualType T, const ASTContext &Context);
1655 static SplitQualType getSplitUnqualifiedTypeImpl(QualType type);
1656 static QualType getSingleStepDesugaredTypeImpl(QualType type,
1657 const ASTContext &C);
1659 static DestructionKind isDestructedTypeImpl(QualType type);
1660
1661 /// Check if \param RD is or contains a non-trivial C union.
1664 static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD);
1665};
1666
1667raw_ostream &operator<<(raw_ostream &OS, QualType QT);
1668
1669} // namespace clang
1670
1671namespace llvm {
1672
1673/// Implement simplify_type for QualType, so that we can dyn_cast from QualType
1674/// to a specific Type class.
1675template<> struct simplify_type< ::clang::QualType> {
1676 using SimpleType = const ::clang::Type *;
1677
1679 return Val.getTypePtr();
1680 }
1681};
1682
1683// Teach SmallPtrSet that QualType is "basically a pointer".
1684template<>
1685struct PointerLikeTypeTraits<clang::QualType> {
1686 static inline void *getAsVoidPointer(clang::QualType P) {
1687 return P.getAsOpaquePtr();
1688 }
1689
1690 static inline clang::QualType getFromVoidPointer(void *P) {
1692 }
1693
1694 // Various qualifiers go in low bits.
1695 static constexpr int NumLowBitsAvailable = 0;
1696};
1697
1698} // namespace llvm
1699
1700namespace clang {
1701
1702/// Base class that is common to both the \c ExtQuals and \c Type
1703/// classes, which allows \c QualType to access the common fields between the
1704/// two.
1705class ExtQualsTypeCommonBase {
1706 friend class ExtQuals;
1707 friend class QualType;
1708 friend class Type;
1709 friend class ASTReader;
1710
1711 /// The "base" type of an extended qualifiers type (\c ExtQuals) or
1712 /// a self-referential pointer (for \c Type).
1713 ///
1714 /// This pointer allows an efficient mapping from a QualType to its
1715 /// underlying type pointer.
1716 const Type *const BaseType;
1717
1718 /// The canonical type of this type. A QualType.
1719 QualType CanonicalType;
1720
1721 ExtQualsTypeCommonBase(const Type *baseType, QualType canon)
1722 : BaseType(baseType), CanonicalType(canon) {}
1723};
1724
1725/// We can encode up to four bits in the low bits of a
1726/// type pointer, but there are many more type qualifiers that we want
1727/// to be able to apply to an arbitrary type. Therefore we have this
1728/// struct, intended to be heap-allocated and used by QualType to
1729/// store qualifiers.
1730///
1731/// The current design tags the 'const', 'restrict', and 'volatile' qualifiers
1732/// in three low bits on the QualType pointer; a fourth bit records whether
1733/// the pointer is an ExtQuals node. The extended qualifiers (address spaces,
1734/// Objective-C GC attributes) are much more rare.
1735class alignas(TypeAlignment) ExtQuals : public ExtQualsTypeCommonBase,
1736 public llvm::FoldingSetNode {
1737 // NOTE: changing the fast qualifiers should be straightforward as
1738 // long as you don't make 'const' non-fast.
1739 // 1. Qualifiers:
1740 // a) Modify the bitmasks (Qualifiers::TQ and DeclSpec::TQ).
1741 // Fast qualifiers must occupy the low-order bits.
1742 // b) Update Qualifiers::FastWidth and FastMask.
1743 // 2. QualType:
1744 // a) Update is{Volatile,Restrict}Qualified(), defined inline.
1745 // b) Update remove{Volatile,Restrict}, defined near the end of
1746 // this header.
1747 // 3. ASTContext:
1748 // a) Update get{Volatile,Restrict}Type.
1749
1750 /// The immutable set of qualifiers applied by this node. Always contains
1751 /// extended qualifiers.
1752 Qualifiers Quals;
1753
1754 ExtQuals *this_() { return this; }
1755
1756public:
1757 ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
1758 : ExtQualsTypeCommonBase(baseType,
1759 canon.isNull() ? QualType(this_(), 0) : canon),
1760 Quals(quals) {
1761 assert(Quals.hasNonFastQualifiers()
1762 && "ExtQuals created with no fast qualifiers");
1763 assert(!Quals.hasFastQualifiers()
1764 && "ExtQuals created with fast qualifiers");
1765 }
1766
1767 Qualifiers getQualifiers() const { return Quals; }
1768
1769 bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); }
1770 Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); }
1771
1772 bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); }
1774 return Quals.getObjCLifetime();
1775 }
1776
1777 bool hasAddressSpace() const { return Quals.hasAddressSpace(); }
1778 LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
1779
1780 const Type *getBaseType() const { return BaseType; }
1781
1782public:
1783 void Profile(llvm::FoldingSetNodeID &ID) const {
1784 Profile(ID, getBaseType(), Quals);
1785 }
1786
1787 static void Profile(llvm::FoldingSetNodeID &ID,
1788 const Type *BaseType,
1789 Qualifiers Quals) {
1790 assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!");
1791 ID.AddPointer(BaseType);
1792 Quals.Profile(ID);
1793 }
1794};
1795
1796/// The kind of C++11 ref-qualifier associated with a function type.
1797/// This determines whether a member function's "this" object can be an
1798/// lvalue, rvalue, or neither.
1800 /// No ref-qualifier was provided.
1802
1803 /// An lvalue ref-qualifier was provided (\c &).
1805
1806 /// An rvalue ref-qualifier was provided (\c &&).
1808};
1809
1810// The kind of type deduction represented by a DeducedType (ie AutoType).
1811enum class DeducedKind {
1812 /// Not deduced yet. This is for example an 'auto' which was just parsed.
1814
1815 /// The normal deduced case. For example, an 'auto' which has been deduced to
1816 /// 'int' will be of this kind, with 'int' as the deduced-as type. This is the
1817 /// only case where the node is sugar.
1819
1820 /// This is a special case where the initializer is dependent, so we can't
1821 /// deduce a type yet. For example, 'auto x = V' where 'V' is a
1822 /// value-dependent expression.
1823 /// Formally we can't deduce an initializer which is dependent, because for
1824 /// one reason it might be non-instantiable (ie it can contain a placeholder
1825 /// dependent type such as DependentTy, which cannot be instantiated).
1826 /// In general TreeTransform will turn these back to 'Undeduced' so we can try
1827 /// to deduce them again.
1829
1830 /// Same as above, but additionally this represents a case where the deduced
1831 /// entity itself is a pack.
1832 /// This currently only happens for a lambda init-capture pack, which always
1833 /// uses AutoType.
1835};
1836
1837/// Which keyword(s) were used to create an AutoType.
1839 /// auto
1841
1842 /// decltype(auto)
1844
1845 /// __auto_type (GNU extension)
1847};
1848
1849enum class ArraySizeModifier;
1850enum class ElaboratedTypeKeyword;
1851enum class VectorKind;
1852
1853/// The base class of the type hierarchy.
1854///
1855/// A central concept with types is that each type always has a canonical
1856/// type. A canonical type is the type with any typedef names stripped out
1857/// of it or the types it references. For example, consider:
1858///
1859/// typedef int foo;
1860/// typedef foo* bar;
1861/// 'int *' 'foo *' 'bar'
1862///
1863/// There will be a Type object created for 'int'. Since int is canonical, its
1864/// CanonicalType pointer points to itself. There is also a Type for 'foo' (a
1865/// TypedefType). Its CanonicalType pointer points to the 'int' Type. Next
1866/// there is a PointerType that represents 'int*', which, like 'int', is
1867/// canonical. Finally, there is a PointerType type for 'foo*' whose canonical
1868/// type is 'int*', and there is a TypedefType for 'bar', whose canonical type
1869/// is also 'int*'.
1870///
1871/// Non-canonical types are useful for emitting diagnostics, without losing
1872/// information about typedefs being used. Canonical types are useful for type
1873/// comparisons (they allow by-pointer equality tests) and useful for reasoning
1874/// about whether something has a particular form (e.g. is a function type),
1875/// because they implicitly, recursively, strip all typedefs out of a type.
1876///
1877/// Types, once created, are immutable.
1878///
1879class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
1880public:
1882#define TYPE(Class, Base) Class,
1883#define LAST_TYPE(Class) TypeLast = Class
1884#define ABSTRACT_TYPE(Class, Base)
1885#include "clang/AST/TypeNodes.inc"
1886 };
1887
1888private:
1889 /// Bitfields required by the Type class.
1890 class TypeBitfields {
1891 friend class Type;
1892 template <class T> friend class TypePropertyCache;
1893
1894 /// TypeClass bitfield - Enum that specifies what subclass this belongs to.
1895 LLVM_PREFERRED_TYPE(TypeClass)
1896 unsigned TC : 8;
1897
1898 /// Store information on the type dependency.
1899 LLVM_PREFERRED_TYPE(TypeDependence)
1900 unsigned Dependence : llvm::BitWidth<TypeDependence>;
1901
1902 /// True if the cache (i.e. the bitfields here starting with
1903 /// 'Cache') is valid.
1904 LLVM_PREFERRED_TYPE(bool)
1905 mutable unsigned CacheValid : 1;
1906
1907 /// Linkage of this type.
1908 LLVM_PREFERRED_TYPE(Linkage)
1909 mutable unsigned CachedLinkage : 3;
1910
1911 /// Whether this type involves and local or unnamed types.
1912 LLVM_PREFERRED_TYPE(bool)
1913 mutable unsigned CachedLocalOrUnnamed : 1;
1914
1915 /// Whether this type comes from an AST file.
1916 LLVM_PREFERRED_TYPE(bool)
1917 mutable unsigned FromAST : 1;
1918
1919 bool isCacheValid() const {
1920 return CacheValid;
1921 }
1922
1923 Linkage getLinkage() const {
1924 assert(isCacheValid() && "getting linkage from invalid cache");
1925 return static_cast<Linkage>(CachedLinkage);
1926 }
1927
1928 bool hasLocalOrUnnamedType() const {
1929 assert(isCacheValid() && "getting linkage from invalid cache");
1930 return CachedLocalOrUnnamed;
1931 }
1932 };
1933 enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1934
1935protected:
1936 // These classes allow subclasses to somewhat cleanly pack bitfields
1937 // into Type.
1938
1940 friend class ArrayType;
1941
1942 LLVM_PREFERRED_TYPE(TypeBitfields)
1943 unsigned : NumTypeBits;
1944
1945 /// CVR qualifiers from declarations like
1946 /// 'int X[static restrict 4]'. For function parameters only.
1947 LLVM_PREFERRED_TYPE(Qualifiers)
1948 unsigned IndexTypeQuals : 3;
1949
1950 /// Storage class qualifiers from declarations like
1951 /// 'int X[static restrict 4]'. For function parameters only.
1952 LLVM_PREFERRED_TYPE(ArraySizeModifier)
1953 unsigned SizeModifier : 3;
1954 };
1955 enum { NumArrayTypeBits = NumTypeBits + 6 };
1956
1958 friend class ConstantArrayType;
1959
1960 LLVM_PREFERRED_TYPE(ArrayTypeBitfields)
1962
1963 /// Whether we have a stored size expression.
1964 LLVM_PREFERRED_TYPE(bool)
1965 unsigned HasExternalSize : 1;
1966
1967 LLVM_PREFERRED_TYPE(unsigned)
1968 unsigned SizeWidth : 5;
1969 };
1970
1972 friend class BuiltinType;
1973
1974 LLVM_PREFERRED_TYPE(TypeBitfields)
1975 unsigned : NumTypeBits;
1976
1977 /// The kind (BuiltinType::Kind) of builtin type this is.
1978 static constexpr unsigned NumOfBuiltinTypeBits = 10;
1979 unsigned Kind : NumOfBuiltinTypeBits;
1980 };
1981
1982public:
1983 static constexpr int FunctionTypeNumParamsWidth = 16;
1984 static constexpr int FunctionTypeNumParamsLimit = (1 << 16) - 1;
1985
1986protected:
1987 /// FunctionTypeBitfields store various bits belonging to FunctionProtoType.
1988 /// Only common bits are stored here. Additional uncommon bits are stored
1989 /// in a trailing object after FunctionProtoType.
1991 friend class FunctionProtoType;
1992 friend class FunctionType;
1993
1994 LLVM_PREFERRED_TYPE(TypeBitfields)
1995 unsigned : NumTypeBits;
1996
1997 /// The ref-qualifier associated with a \c FunctionProtoType.
1998 ///
1999 /// This is a value of type \c RefQualifierKind.
2000 LLVM_PREFERRED_TYPE(RefQualifierKind)
2001 unsigned RefQualifier : 2;
2002
2003 /// Used only by FunctionProtoType, put here to pack with the
2004 /// other bitfields.
2005 /// The qualifiers are part of FunctionProtoType because...
2006 ///
2007 /// C++ 8.3.5p4: The return type, the parameter type list and the
2008 /// cv-qualifier-seq, [...], are part of the function type.
2009 LLVM_PREFERRED_TYPE(Qualifiers)
2010 unsigned FastTypeQuals : Qualifiers::FastWidth;
2011 /// Whether this function has extended Qualifiers.
2012 LLVM_PREFERRED_TYPE(bool)
2013 unsigned HasExtQuals : 1;
2014
2015 /// The type of exception specification this function has.
2016 LLVM_PREFERRED_TYPE(ExceptionSpecificationType)
2017 unsigned ExceptionSpecType : 4;
2018
2019 /// Whether this function has extended parameter information.
2020 LLVM_PREFERRED_TYPE(bool)
2021 unsigned HasExtParameterInfos : 1;
2022
2023 /// Whether this function has extra bitfields for the prototype.
2024 LLVM_PREFERRED_TYPE(bool)
2025 unsigned HasExtraBitfields : 1;
2026
2027 /// Whether the function is variadic.
2028 LLVM_PREFERRED_TYPE(bool)
2029 unsigned Variadic : 1;
2030
2031 /// Whether this function has a trailing return type.
2032 LLVM_PREFERRED_TYPE(bool)
2033 unsigned HasTrailingReturn : 1;
2034
2035 /// Whether this function has is a cfi unchecked callee.
2036 LLVM_PREFERRED_TYPE(bool)
2037 unsigned CFIUncheckedCallee : 1;
2038
2039 /// Extra information which affects how the function is called, like
2040 /// regparm and the calling convention.
2041 LLVM_PREFERRED_TYPE(CallingConv)
2042 unsigned ExtInfo : 14;
2043
2044 /// The number of parameters this function has, not counting '...'.
2045 /// According to [implimits] 8 bits should be enough here but this is
2046 /// somewhat easy to exceed with metaprogramming and so we would like to
2047 /// keep NumParams as wide as reasonably possible.
2048 unsigned NumParams : FunctionTypeNumParamsWidth;
2049 };
2050
2052 friend class ObjCObjectType;
2053
2054 LLVM_PREFERRED_TYPE(TypeBitfields)
2055 unsigned : NumTypeBits;
2056
2057 /// The number of type arguments stored directly on this object type.
2058 unsigned NumTypeArgs : 7;
2059
2060 /// The number of protocols stored directly on this object type.
2061 unsigned NumProtocols : 6;
2062
2063 /// Whether this is a "kindof" type.
2064 LLVM_PREFERRED_TYPE(bool)
2065 unsigned IsKindOf : 1;
2066 };
2067
2069 friend class ReferenceType;
2070
2071 LLVM_PREFERRED_TYPE(TypeBitfields)
2072 unsigned : NumTypeBits;
2073
2074 /// True if the type was originally spelled with an lvalue sigil.
2075 /// This is never true of rvalue references but can also be false
2076 /// on lvalue references because of C++0x [dcl.typedef]p9,
2077 /// as follows:
2078 ///
2079 /// typedef int &ref; // lvalue, spelled lvalue
2080 /// typedef int &&rvref; // rvalue
2081 /// ref &a; // lvalue, inner ref, spelled lvalue
2082 /// ref &&a; // lvalue, inner ref
2083 /// rvref &a; // lvalue, inner ref, spelled lvalue
2084 /// rvref &&a; // rvalue, inner ref
2085 LLVM_PREFERRED_TYPE(bool)
2086 unsigned SpelledAsLValue : 1;
2087
2088 /// True if the inner type is a reference type. This only happens
2089 /// in non-canonical forms.
2090 LLVM_PREFERRED_TYPE(bool)
2091 unsigned InnerRef : 1;
2092 };
2093
2095 template <class> friend class KeywordWrapper;
2096
2097 LLVM_PREFERRED_TYPE(TypeBitfields)
2098 unsigned : NumTypeBits;
2099
2100 /// An ElaboratedTypeKeyword. 8 bits for efficient access.
2101 LLVM_PREFERRED_TYPE(ElaboratedTypeKeyword)
2102 unsigned Keyword : 8;
2103 };
2104
2105 enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
2106
2108 friend class TagType;
2109
2110 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2112
2113 /// Whether the TagType has a trailing Qualifier.
2114 LLVM_PREFERRED_TYPE(bool)
2115 unsigned HasQualifier : 1;
2116
2117 /// Whether the TagType owns the Tag.
2118 LLVM_PREFERRED_TYPE(bool)
2119 unsigned OwnsTag : 1;
2120
2121 /// Whether the TagType was created from an injected name.
2122 LLVM_PREFERRED_TYPE(bool)
2123 unsigned IsInjected : 1;
2124 };
2125
2127 friend class VectorType;
2129
2130 LLVM_PREFERRED_TYPE(TypeBitfields)
2131 unsigned : NumTypeBits;
2132
2133 /// The kind of vector, either a generic vector type or some
2134 /// target-specific vector type such as for AltiVec or Neon.
2135 LLVM_PREFERRED_TYPE(VectorKind)
2136 unsigned VecKind : 6;
2137 /// The number of elements in the vector.
2138 uint32_t NumElements;
2139 };
2140
2142 friend class AttributedType;
2143
2144 LLVM_PREFERRED_TYPE(TypeBitfields)
2145 unsigned : NumTypeBits;
2146
2147 LLVM_PREFERRED_TYPE(attr::Kind)
2148 unsigned AttrKind : 32 - NumTypeBits;
2149 };
2150
2152 friend class DeducedType;
2153
2154 // One of the base classes uses the KeywordWrapper, so reserve those bits.
2155 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2157
2158 /// The kind of deduction this type represents, ie 'undeduced' or otherwise.
2159 LLVM_PREFERRED_TYPE(DeducedKind)
2160 unsigned Kind : 2;
2161 };
2162
2163 static constexpr int NumDeducedTypeBits = NumTypeBits + 2;
2164
2166 friend class AutoType;
2167
2168 LLVM_PREFERRED_TYPE(DeducedTypeBitfields)
2170
2171 /// Was this placeholder type spelled as 'auto', 'decltype(auto)',
2172 /// or '__auto_type'? AutoTypeKeyword value.
2173 LLVM_PREFERRED_TYPE(AutoTypeKeyword)
2174 unsigned Keyword : 2;
2175
2176 /// The number of template arguments in the type-constraints, which is
2177 /// expected to be able to hold at least 1024 according to [implimits].
2178 /// However as this limit is somewhat easy to hit with template
2179 /// metaprogramming we'd prefer to keep it as large as possible.
2180 /// At the moment it has been left as a non-bitfield since this type
2181 /// safely fits in 64 bits as an unsigned, so there is no reason to
2182 /// introduce the performance impact of a bitfield.
2183 unsigned NumArgs;
2184 };
2185
2187 friend class TypeOfType;
2188 friend class TypeOfExprType;
2189
2190 LLVM_PREFERRED_TYPE(TypeBitfields)
2191 unsigned : NumTypeBits;
2192 LLVM_PREFERRED_TYPE(TypeOfKind)
2193 unsigned Kind : 1;
2194 };
2195
2198
2199 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2201
2202 /// True if there is a non-null qualifier.
2203 LLVM_PREFERRED_TYPE(bool)
2204 unsigned hasQualifier : 1;
2205 };
2206
2208 friend class UsingType;
2209
2210 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2212
2213 /// True if there is a non-null qualifier.
2214 LLVM_PREFERRED_TYPE(bool)
2215 unsigned hasQualifier : 1;
2216 };
2217
2219 friend class TypedefType;
2220
2221 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2223
2224 /// True if there is a non-null qualifier.
2225 LLVM_PREFERRED_TYPE(bool)
2226 unsigned hasQualifier : 1;
2227
2228 /// True if the underlying type is different from the declared one.
2229 LLVM_PREFERRED_TYPE(bool)
2230 unsigned hasTypeDifferentFromDecl : 1;
2231 };
2232
2233 static constexpr unsigned TemplateTypeParmTypeDepthBits = 15;
2234 static constexpr unsigned TemplateTypeParmTypeIndexBits = 16;
2235
2238
2239 LLVM_PREFERRED_TYPE(TypeBitfields)
2240 unsigned : NumTypeBits;
2241
2242 /// The depth of the template parameter.
2243 unsigned Depth : TemplateTypeParmTypeDepthBits;
2244
2245 /// Whether this is a template parameter pack.
2246 LLVM_PREFERRED_TYPE(bool)
2247 unsigned ParameterPack : 1;
2248
2249 /// The index of the template parameter.
2250 unsigned Index : TemplateTypeParmTypeIndexBits;
2251 };
2252
2255
2256 LLVM_PREFERRED_TYPE(TypeBitfields)
2257 unsigned : NumTypeBits;
2258
2259 LLVM_PREFERRED_TYPE(bool)
2260 unsigned HasNonCanonicalUnderlyingType : 1;
2261
2262 // The index of the template parameter this substitution represents.
2263 unsigned Index : 15;
2264
2265 LLVM_PREFERRED_TYPE(bool)
2266 unsigned Final : 1;
2267
2268 /// Represents the index within a pack if this represents a substitution
2269 /// from a pack expansion. This index starts at the end of the pack and
2270 /// increments towards the beginning.
2271 /// Positive non-zero number represents the index + 1.
2272 /// Zero means this is not substituted from an expansion.
2273 unsigned PackIndex : 16;
2274 };
2275
2277 friend class SubstPackType;
2279
2280 LLVM_PREFERRED_TYPE(TypeBitfields)
2281 unsigned : NumTypeBits;
2282
2283 /// The number of template arguments in \c Arguments, which is
2284 /// expected to be able to hold at least 1024 according to [implimits].
2285 /// However as this limit is somewhat easy to hit with template
2286 /// metaprogramming we'd prefer to keep it as large as possible.
2287 unsigned NumArgs : 16;
2288
2289 // The index of the template parameter this substitution represents.
2290 // Only used by SubstTemplateTypeParmPackType. We keep it in the same
2291 // class to avoid dealing with complexities of bitfields that go over
2292 // the size of `unsigned`.
2293 unsigned SubstTemplTypeParmPackIndex : 16;
2294 };
2295
2298
2299 LLVM_PREFERRED_TYPE(KeywordWrapperBitfields)
2301
2302 /// Whether this template specialization type is a substituted type alias.
2303 LLVM_PREFERRED_TYPE(bool)
2304 unsigned TypeAlias : 1;
2305
2306 /// The number of template arguments named in this class template
2307 /// specialization, which is expected to be able to hold at least 1024
2308 /// according to [implimits]. However, as this limit is somewhat easy to
2309 /// hit with template metaprogramming we'd prefer to keep it as large
2310 /// as possible. At the moment it has been left as a non-bitfield since
2311 /// this type safely fits in 64 bits as an unsigned, so there is no reason
2312 /// to introduce the performance impact of a bitfield.
2313 unsigned NumArgs;
2314 };
2315
2317 friend class PackExpansionType;
2318
2319 LLVM_PREFERRED_TYPE(TypeBitfields)
2320 unsigned : NumTypeBits;
2321
2322 /// The number of expansions that this pack expansion will
2323 /// generate when substituted (+1), which is expected to be able to
2324 /// hold at least 1024 according to [implimits]. However, as this limit
2325 /// is somewhat easy to hit with template metaprogramming we'd prefer to
2326 /// keep it as large as possible. At the moment it has been left as a
2327 /// non-bitfield since this type safely fits in 64 bits as an unsigned, so
2328 /// there is no reason to introduce the performance impact of a bitfield.
2329 ///
2330 /// This field will only have a non-zero value when some of the parameter
2331 /// packs that occur within the pattern have been substituted but others
2332 /// have not.
2333 unsigned NumExpansions;
2334 };
2335
2337 /// The "size_t" type.
2339
2340 /// The signed integer type corresponding to "size_t".
2342
2343 /// The "ptrdiff_t" type.
2345
2346 // Indicates how many items the enum has.
2348 };
2349
2352
2353 LLVM_PREFERRED_TYPE(TypeBitfields)
2354 unsigned : NumTypeBits;
2355
2356 LLVM_PREFERRED_TYPE(PredefinedSugarKind)
2357 unsigned Kind : 8;
2358 };
2359
2362
2363 LLVM_PREFERRED_TYPE(TypeBitfields)
2364 unsigned : NumTypeBits;
2365
2366 static constexpr unsigned NumCoupledDeclsBits = 4;
2367 unsigned NumCoupledDecls : NumCoupledDeclsBits;
2368 LLVM_PREFERRED_TYPE(bool)
2369 unsigned CountInBytes : 1;
2370 LLVM_PREFERRED_TYPE(bool)
2371 unsigned OrNull : 1;
2372 };
2373 static_assert(sizeof(CountAttributedTypeBitfields) <= sizeof(unsigned));
2374
2375 union {
2376 TypeBitfields TypeBits;
2400 };
2401
2402private:
2403 template <class T> friend class TypePropertyCache;
2404
2405 /// Set whether this type comes from an AST file.
2406 void setFromAST(bool V = true) const {
2407 TypeBits.FromAST = V;
2408 }
2409
2410protected:
2411 friend class ASTContext;
2412
2414 : ExtQualsTypeCommonBase(this,
2415 canon.isNull() ? QualType(this_(), 0) : canon) {
2416 static_assert(sizeof(*this) <=
2417 alignof(decltype(*this)) + sizeof(ExtQualsTypeCommonBase),
2418 "changing bitfields changed sizeof(Type)!");
2419 static_assert(alignof(decltype(*this)) % TypeAlignment == 0,
2420 "Insufficient alignment!");
2421 TypeBits.TC = tc;
2422 TypeBits.Dependence = static_cast<unsigned>(Dependence);
2423 TypeBits.CacheValid = false;
2424 TypeBits.CachedLocalOrUnnamed = false;
2425 TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2426 TypeBits.FromAST = false;
2427 }
2428
2429 // silence VC++ warning C4355: 'this' : used in base member initializer list
2430 Type *this_() { return this; }
2431
2433 TypeBits.Dependence = static_cast<unsigned>(D);
2434 }
2435
2437
2438public:
2439 friend class ASTReader;
2440 friend class ASTWriter;
2441 template <class T> friend class serialization::AbstractTypeReader;
2442 template <class T> friend class serialization::AbstractTypeWriter;
2443
2444 Type(const Type &) = delete;
2445 Type(Type &&) = delete;
2446 Type &operator=(const Type &) = delete;
2447 Type &operator=(Type &&) = delete;
2448
2449 TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); }
2450
2451 /// Whether this type comes from an AST file.
2452 bool isFromAST() const { return TypeBits.FromAST; }
2453
2454 /// Whether this type is or contains an unexpanded parameter
2455 /// pack, used to support C++0x variadic templates.
2456 ///
2457 /// A type that contains a parameter pack shall be expanded by the
2458 /// ellipsis operator at some point. For example, the typedef in the
2459 /// following example contains an unexpanded parameter pack 'T':
2460 ///
2461 /// \code
2462 /// template<typename ...T>
2463 /// struct X {
2464 /// typedef T* pointer_types; // ill-formed; T is a parameter pack.
2465 /// };
2466 /// \endcode
2467 ///
2468 /// Note that this routine does not specify which
2470 return getDependence() & TypeDependence::UnexpandedPack;
2471 }
2472
2473 /// Determines if this type would be canonical if it had no further
2474 /// qualification.
2476 return CanonicalType == QualType(this, 0);
2477 }
2478
2479 /// Pull a single level of sugar off of this locally-unqualified type.
2480 /// Users should generally prefer SplitQualType::getSingleStepDesugaredType()
2481 /// or QualType::getSingleStepDesugaredType(const ASTContext&).
2482 QualType getLocallyUnqualifiedSingleStepDesugaredType() const;
2483
2484 /// As an extension, we classify types as one of "sized" or "sizeless";
2485 /// every type is one or the other. Standard types are all sized;
2486 /// sizeless types are purely an extension.
2487 ///
2488 /// Sizeless types contain data with no specified size, alignment,
2489 /// or layout.
2490 bool isSizelessType() const;
2491 bool isSizelessBuiltinType() const;
2492
2493 /// Returns true for all scalable vector types.
2494 bool isSizelessVectorType() const;
2495
2496 /// Returns true for SVE scalable vector types.
2497 bool isSVESizelessBuiltinType() const;
2498
2499 /// Returns true for RVV scalable vector types.
2500 bool isRVVSizelessBuiltinType() const;
2501
2502 /// Check if this is a WebAssembly Externref Type.
2503 bool isWebAssemblyExternrefType() const;
2504
2505 /// Returns true if this is a WebAssembly table type: either an array of
2506 /// reference types, or a pointer to a reference type (which can only be
2507 /// created by array to pointer decay).
2508 bool isWebAssemblyTableType() const;
2509
2510 /// Determines if this is a sizeless type supported by the
2511 /// 'arm_sve_vector_bits' type attribute, which can be applied to a single
2512 /// SVE vector or predicate, excluding tuple types such as svint32x4_t.
2513 bool isSveVLSBuiltinType() const;
2514
2515 /// Returns the representative type for the element of an SVE builtin type.
2516 /// This is used to represent fixed-length SVE vectors created with the
2517 /// 'arm_sve_vector_bits' type attribute as VectorType.
2518 QualType getSveEltType(const ASTContext &Ctx) const;
2519
2520 /// Determines if this is a sizeless type supported by the
2521 /// 'riscv_rvv_vector_bits' type attribute, which can be applied to a single
2522 /// RVV vector or mask.
2523 bool isRVVVLSBuiltinType() const;
2524
2525 /// Returns the representative type for the element of an RVV builtin type.
2526 /// This is used to represent fixed-length RVV vectors created with the
2527 /// 'riscv_rvv_vector_bits' type attribute as VectorType.
2528 QualType getRVVEltType(const ASTContext &Ctx) const;
2529
2530 /// Returns the representative type for the element of a sizeless vector
2531 /// builtin type.
2532 QualType getSizelessVectorEltType(const ASTContext &Ctx) const;
2533
2534 /// Types are partitioned into 3 broad categories (C99 6.2.5p1):
2535 /// object types, function types, and incomplete types.
2536
2537 /// Return true if this is an incomplete type.
2538 /// A type that can describe objects, but which lacks information needed to
2539 /// determine its size (e.g. void, or a fwd declared struct). Clients of this
2540 /// routine will need to determine if the size is actually required.
2541 ///
2542 /// Def If non-null, and the type refers to some kind of declaration
2543 /// that can be completed (such as a C struct, C++ class, or Objective-C
2544 /// class), will be set to the declaration.
2545 bool isIncompleteType(NamedDecl **Def = nullptr) const;
2546
2547 /// Return true if this is an incomplete or object
2548 /// type, in other words, not a function type.
2550 return !isFunctionType();
2551 }
2552
2553 /// \returns True if the type is incomplete and it is also a type that
2554 /// cannot be completed by a later type definition.
2555 ///
2556 /// E.g. For `void` this is true but for `struct ForwardDecl;` this is false
2557 /// because a definition for `ForwardDecl` could be provided later on in the
2558 /// translation unit.
2559 ///
2560 /// Note even for types that this function returns true for it is still
2561 /// possible for the declarations that contain this type to later have a
2562 /// complete type in a translation unit. E.g.:
2563 ///
2564 /// \code{.c}
2565 /// // This decl has type 'char[]' which is incomplete and cannot be later
2566 /// // completed by another by another type declaration.
2567 /// extern char foo[];
2568 /// // This decl now has complete type 'char[5]'.
2569 /// char foo[5]; // foo has a complete type
2570 /// \endcode
2571 bool isAlwaysIncompleteType() const;
2572
2573 /// Determine whether this type is an object type.
2574 bool isObjectType() const {
2575 // C++ [basic.types]p8:
2576 // An object type is a (possibly cv-qualified) type that is not a
2577 // function type, not a reference type, and not a void type.
2578 return !isReferenceType() && !isFunctionType() && !isVoidType();
2579 }
2580
2581 /// Return true if this is a literal type
2582 /// (C++11 [basic.types]p10)
2583 bool isLiteralType(const ASTContext &Ctx) const;
2584
2585 /// Determine if this type is a structural type, per C++20 [temp.param]p7.
2586 bool isStructuralType() const;
2587
2588 /// Test if this type is a standard-layout type.
2589 /// (C++0x [basic.type]p9)
2590 bool isStandardLayoutType() const;
2591
2592 /// Helper methods to distinguish type categories. All type predicates
2593 /// operate on the canonical type, ignoring typedefs and qualifiers.
2594
2595 /// Returns true if the type is a builtin type.
2596 bool isBuiltinType() const;
2597
2598 /// Test for a particular builtin type.
2599 bool isSpecificBuiltinType(unsigned K) const;
2600
2601 /// Test for a type which does not represent an actual type-system type but
2602 /// is instead used as a placeholder for various convenient purposes within
2603 /// Clang. All such types are BuiltinTypes.
2604 bool isPlaceholderType() const;
2605 const BuiltinType *getAsPlaceholderType() const;
2606
2607 /// Test for a specific placeholder type.
2608 bool isSpecificPlaceholderType(unsigned K) const;
2609
2610 /// Test for a placeholder type other than Overload; see
2611 /// BuiltinType::isNonOverloadPlaceholderType.
2612 bool isNonOverloadPlaceholderType() const;
2613
2614 /// isIntegerType() does *not* include complex integers (a GCC extension).
2615 /// isComplexIntegerType() can be used to test for complex integers.
2616 bool isIntegerType() const; // C99 6.2.5p17 (int, char, bool, enum)
2617 bool isEnumeralType() const;
2618
2619 /// Determine whether this type is a scoped enumeration type.
2620 bool isScopedEnumeralType() const;
2621 bool isBooleanType() const;
2622 bool isCharType() const;
2623 bool isWideCharType() const;
2624 bool isChar8Type() const;
2625 bool isChar16Type() const;
2626 bool isChar32Type() const;
2627 bool isAnyCharacterType() const;
2628 bool isUnicodeCharacterType() const;
2629 bool isIntegralType(const ASTContext &Ctx) const;
2630
2631 /// Determine whether this type is an integral or enumeration type.
2632 bool isIntegralOrEnumerationType() const;
2633
2634 /// Determine whether this type is an integral or unscoped enumeration type.
2635 bool isIntegralOrUnscopedEnumerationType() const;
2636 bool isUnscopedEnumerationType() const;
2637
2638 /// Floating point categories.
2639 bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
2640 /// isComplexType() does *not* include complex integers (a GCC extension).
2641 /// isComplexIntegerType() can be used to test for complex integers.
2642 bool isComplexType() const; // C99 6.2.5p11 (complex)
2643 bool isAnyComplexType() const; // C99 6.2.5p11 (complex) + Complex Int.
2644 bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
2645 bool isHalfType() const; // OpenCL 6.1.1.1, NEON (IEEE 754-2008 half)
2646 bool isFloat16Type() const; // C11 extension ISO/IEC TS 18661
2647 bool isFloat32Type() const;
2648 bool isDoubleType() const;
2649 bool isBFloat16Type() const;
2650 bool isMFloat8Type() const;
2651 bool isFloat128Type() const;
2652 bool isIbm128Type() const;
2653 bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
2654 bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
2655 bool isVoidType() const; // C99 6.2.5p19
2656 bool isScalarType() const; // C99 6.2.5p21 (arithmetic + pointers)
2657 bool isAggregateType() const;
2658 bool isFundamentalType() const;
2659 bool isCompoundType() const;
2660
2661 // Type Predicates: Check to see if this type is structurally the specified
2662 // type, ignoring typedefs and qualifiers.
2663 bool isFunctionType() const;
2666 bool isPointerType() const;
2667 bool isPointerOrReferenceType() const;
2668 bool isSignableType(const ASTContext &Ctx) const;
2669 bool isSignablePointerType() const;
2670 bool isSignableIntegerType(const ASTContext &Ctx) const;
2671 bool isAnyPointerType() const; // Any C pointer or ObjC object pointer
2672 bool isCountAttributedType() const;
2673 bool isCFIUncheckedCalleeFunctionType() const;
2674 bool hasPointeeToCFIUncheckedCalleeFunctionType() const;
2675 bool isBlockPointerType() const;
2676 bool isVoidPointerType() const;
2677 bool isReferenceType() const;
2678 bool isLValueReferenceType() const;
2679 bool isRValueReferenceType() const;
2680 bool isObjectPointerType() const;
2681 bool isFunctionPointerType() const;
2682 bool isFunctionReferenceType() const;
2683 bool isMemberPointerType() const;
2684 bool isMemberFunctionPointerType() const;
2685 bool isMemberDataPointerType() const;
2686 bool isArrayType() const;
2687 bool isConstantArrayType() const;
2688 bool isIncompleteArrayType() const;
2689 bool isVariableArrayType() const;
2690 bool isArrayParameterType() const;
2691 bool isDependentSizedArrayType() const;
2692 bool isRecordType() const;
2693 bool isClassType() const;
2694 bool isStructureType() const;
2695 bool isStructureTypeWithFlexibleArrayMember() const;
2696 bool isObjCBoxableRecordType() const;
2697 bool isInterfaceType() const;
2698 bool isStructureOrClassType() const;
2699 bool isUnionType() const;
2700 bool isComplexIntegerType() const; // GCC _Complex integer type.
2701 bool isVectorType() const; // GCC vector type.
2702 bool isExtVectorType() const; // Extended vector type.
2703 bool isExtVectorBoolType() const; // Extended vector type with bool element.
2704 bool isConstantMatrixBoolType() const; // Matrix type with bool element.
2705 // Extended vector type with bool element that is packed. HLSL doesn't pack
2706 // its bool vectors.
2707 bool isPackedVectorBoolType(const ASTContext &ctx) const;
2708 bool isSubscriptableVectorType() const;
2709 bool isMatrixType() const; // Matrix type.
2710 bool isConstantMatrixType() const; // Constant matrix type.
2711 bool 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 {
3870 ExternalSize *SizePtr;
3871 };
3872
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.
3935 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
3936 : Size;
3937 }
3938
3939 /// Return the size sign-extended as a uint64_t.
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.
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
4265
4266 /// is RISC-V RVV fixed-length mask vector of vbool<R>_t; the _<L> kinds
4267 /// have only L lanes in a single byte
4296};
4297
4298// The helpers below rely on the order of the RVV fixed-length kinds:
4299// RVVFixedLengthData_MF8 .. _M8 by LMUL, then RVVFixedLengthMaskRatio<R>,
4300// <R>_1, <R>_2 and <R>_4 for R = 1 .. 64.
4301static_assert(unsigned(VectorKind::RVVFixedLengthData_M1) ==
4302 unsigned(VectorKind::RVVFixedLengthData_MF8) + 3 &&
4303 unsigned(VectorKind::RVVFixedLengthData_M8) ==
4304 unsigned(VectorKind::RVVFixedLengthData_MF8) + 6,
4305 "unexpected order of the RVV fixed-length data vector kinds");
4306static_assert(unsigned(VectorKind::RVVFixedLengthMaskRatio1_4) ==
4307 unsigned(VectorKind::RVVFixedLengthMaskRatio1) + 3 &&
4308 unsigned(VectorKind::RVVFixedLengthMaskRatio2) ==
4309 unsigned(VectorKind::RVVFixedLengthMaskRatio1) + 4 &&
4310 unsigned(VectorKind::RVVFixedLengthMaskRatio64_4) ==
4311 unsigned(VectorKind::RVVFixedLengthMaskRatio1) + 27,
4312 "unexpected order of the RVV fixed-length mask vector kinds");
4313
4314/// True if \p VK is one of the RVV fixed-length data vector kinds, i.e. a
4315/// riscv_rvv_vector_bits typedef of a data (non-mask) RVV type.
4320
4321/// Return log2 of the LMUL recorded in an RVV fixed-length data vector kind:
4322/// MF8 -> -3, ..., M1 -> 0, ..., M8 -> 3.
4325 "not an RVV fixed-length data vector kind");
4327}
4328
4329/// Inverse of getRVVFixedLengthDataLMulLog2().
4331 assert(LMulLog2 >= -3 && LMulLog2 <= 3 &&
4332 "LMUL out of range for an RVV type");
4333 return VectorKind(int(VectorKind::RVVFixedLengthData_M1) + LMulLog2);
4334}
4335
4336/// True if \p VK is one of the RVV fixed-length mask vector kinds, i.e. a
4337/// riscv_rvv_vector_bits typedef of a vbool<R>_t type.
4342
4343/// Return log2 of the R of the vbool<R>_t type recorded in an RVV fixed-length
4344/// mask vector kind: Ratio1 -> 0, Ratio2 -> 1, ..., Ratio64 -> 6.
4347 "not an RVV fixed-length mask vector kind");
4348 return (unsigned(VK) - unsigned(VectorKind::RVVFixedLengthMaskRatio1)) / 4;
4349}
4350
4351/// True if \p VK is one of the RVV fixed-length data or mask vector kinds.
4356
4357/// Return the LMUL of an RVV fixed-length data vector kind, "mf8" .. "m8", or
4358/// the ratio of a mask vector kind, "1" .. "64".
4361 static constexpr const char *LMuls[] = {"mf8", "mf4", "mf2", "m1",
4362 "m2", "m4", "m8"};
4363 return LMuls[getRVVFixedLengthDataLMulLog2(VK) + 3];
4364 }
4365 static constexpr const char *Ratios[] = {"1", "2", "4", "8",
4366 "16", "32", "64"};
4367 return Ratios[getRVVFixedLengthMaskRatioLog2(VK)];
4368}
4369
4370/// Return the number of lanes (1, 2 or 4) of an RVV fixed-length mask vector
4371/// kind that fits in less than one byte, or 0 if its lanes fill whole bytes.
4374 "not an RVV fixed-length mask vector kind");
4375 unsigned Col =
4377 return Col ? 1u << (Col - 1) : 0;
4378}
4379
4380/// Inverse of getRVVFixedLengthMaskRatioLog2() and
4381/// getRVVFixedLengthMaskSubByteLanes().
4383 unsigned SubByteLanes) {
4384 assert(RatioLog2 < 7 && "ratio out of range for an RVV mask type");
4385 assert((SubByteLanes == 0 || SubByteLanes == 1 || SubByteLanes == 2 ||
4386 SubByteLanes == 4) &&
4387 "unexpected sub-byte lane count");
4388 unsigned Col = SubByteLanes == 0 ? 0 : llvm::Log2_32(SubByteLanes) + 1;
4390 RatioLog2 * 4 + Col);
4391}
4392
4393/// Represents a GCC generic vector type. This type is created using
4394/// __attribute__((vector_size(n)), where "n" specifies the vector size in
4395/// bytes; or from an Altivec __vector or vector declaration.
4396/// Since the constructor takes the number of vector elements, the
4397/// client is responsible for converting the size into the number of elements.
4398class VectorType : public Type, public llvm::FoldingSetNode {
4399protected:
4400 friend class ASTContext; // ASTContext creates these.
4401
4402 /// The element type of the vector.
4404
4405 VectorType(QualType vecType, unsigned nElements, QualType canonType,
4406 VectorKind vecKind);
4407
4408 VectorType(TypeClass tc, QualType vecType, unsigned nElements,
4409 QualType canonType, VectorKind vecKind);
4410
4411public:
4413 unsigned getNumElements() const { return VectorTypeBits.NumElements; }
4414
4415 bool isSugared() const { return false; }
4416 QualType desugar() const { return QualType(this, 0); }
4417
4419 return VectorKind(VectorTypeBits.VecKind);
4420 }
4421
4422 /// Return the number of lanes of an RVV fixed-length mask vector. Its
4423 /// elements are bytes, but each lane is a single bit.
4425 unsigned SubByteLanes = getRVVFixedLengthMaskSubByteLanes(getVectorKind());
4426 return SubByteLanes ? SubByteLanes : getNumElements() * 8;
4427 }
4428
4429 void Profile(llvm::FoldingSetNodeID &ID) {
4432 }
4433
4434 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
4435 unsigned NumElements, TypeClass TypeClass,
4436 VectorKind VecKind) {
4437 ID.AddPointer(ElementType.getAsOpaquePtr());
4438 ID.AddInteger(NumElements);
4439 ID.AddInteger(TypeClass);
4440 ID.AddInteger(llvm::to_underlying(VecKind));
4441 }
4442
4443 static bool classof(const Type *T) {
4444 return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector;
4445 }
4446};
4447
4448/// Represents a vector type where either the type or size is dependent.
4449////
4450/// For example:
4451/// \code
4452/// template<typename T, int Size>
4453/// class vector {
4454/// typedef T __attribute__((vector_size(Size))) type;
4455/// }
4456/// \endcode
4457class DependentVectorType : public Type, public llvm::FoldingSetNode {
4458 friend class ASTContext;
4459
4460 QualType ElementType;
4461 Expr *SizeExpr;
4462 SourceLocation Loc;
4463
4464 DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
4465 SourceLocation Loc, VectorKind vecKind);
4466
4467public:
4468 Expr *getSizeExpr() const { return SizeExpr; }
4469 QualType getElementType() const { return ElementType; }
4470 SourceLocation getAttributeLoc() const { return Loc; }
4472 return VectorKind(VectorTypeBits.VecKind);
4473 }
4474
4475 bool isSugared() const { return false; }
4476 QualType desugar() const { return QualType(this, 0); }
4477
4478 static bool classof(const Type *T) {
4479 return T->getTypeClass() == DependentVector;
4480 }
4481
4482 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4483 Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind());
4484 }
4485
4486 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4487 QualType ElementType, const Expr *SizeExpr,
4488 VectorKind VecKind);
4489};
4490
4491/// ExtVectorType - Extended vector type. This type is created using
4492/// __attribute__((ext_vector_type(n)), where "n" is the number of elements.
4493/// Unlike vector_size, ext_vector_type is only allowed on typedef's. This
4494/// class enables syntactic extensions, like Vector Components for accessing
4495/// points (as .xyzw), colors (as .rgba), and textures (modeled after OpenGL
4496/// Shading Language).
4497class ExtVectorType : public VectorType {
4498 friend class ASTContext; // ASTContext creates these.
4499
4500 ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
4501 : VectorType(ExtVector, vecType, nElements, canonType,
4502 VectorKind::Generic) {}
4503
4504public:
4505 static int getPointAccessorIdx(char c) {
4506 switch (c) {
4507 default: return -1;
4508 case 'x': case 'r': return 0;
4509 case 'y': case 'g': return 1;
4510 case 'z': case 'b': return 2;
4511 case 'w': case 'a': return 3;
4512 }
4513 }
4514
4515 static int getNumericAccessorIdx(char c) {
4516 switch (c) {
4517 default: return -1;
4518 case '0': return 0;
4519 case '1': return 1;
4520 case '2': return 2;
4521 case '3': return 3;
4522 case '4': return 4;
4523 case '5': return 5;
4524 case '6': return 6;
4525 case '7': return 7;
4526 case '8': return 8;
4527 case '9': return 9;
4528 case 'A':
4529 case 'a': return 10;
4530 case 'B':
4531 case 'b': return 11;
4532 case 'C':
4533 case 'c': return 12;
4534 case 'D':
4535 case 'd': return 13;
4536 case 'E':
4537 case 'e': return 14;
4538 case 'F':
4539 case 'f': return 15;
4540 }
4541 }
4542
4543 static int getAccessorIdx(char c, bool isNumericAccessor) {
4544 if (isNumericAccessor)
4545 return getNumericAccessorIdx(c);
4546 else
4547 return getPointAccessorIdx(c);
4548 }
4549
4550 bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const {
4551 if (int idx = getAccessorIdx(c, isNumericAccessor)+1)
4552 return unsigned(idx-1) < getNumElements();
4553 return false;
4554 }
4555
4556 bool isSugared() const { return false; }
4557 QualType desugar() const { return QualType(this, 0); }
4558
4559 static bool classof(const Type *T) {
4560 return T->getTypeClass() == ExtVector;
4561 }
4562};
4563
4564/// Represents a matrix type, as defined in the Matrix Types clang extensions.
4565/// __attribute__((matrix_type(rows, columns))), where "rows" specifies
4566/// number of rows and "columns" specifies the number of columns.
4567class MatrixType : public Type, public llvm::FoldingSetNode {
4568protected:
4569 friend class ASTContext;
4570
4571public:
4573
4574private:
4575 /// The element type of the matrix.
4576 QualType ElementType;
4577
4578protected:
4579 MatrixType(QualType ElementTy, QualType CanonElementTy);
4580
4581 MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy,
4582 const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr);
4583
4584public:
4585 /// Returns type of the elements being stored in the matrix
4586 QualType getElementType() const { return ElementType; }
4587
4588 /// Valid elements types are the following:
4589 /// * an integer type (as in C23 6.2.5p22), but excluding enumerated types
4590 /// and _Bool (except that in HLSL, bool is allowed)
4591 /// * the standard floating types float or double
4592 /// * a half-precision floating point type, if one is supported on the target
4593 static bool isValidElementType(QualType T, const LangOptions &LangOpts) {
4594 // Dependent is always okay
4595 if (T->isDependentType())
4596 return true;
4597
4598 // Enums are never okay
4599 if (T->isEnumeralType())
4600 return false;
4601
4602 // In HLSL, bool is allowed as a matrix element type.
4603 // Note: isRealType includes bool so don't need to check
4604 if (LangOpts.HLSL)
4605 return T->isRealType();
4606
4607 // In non-HLSL modes, follow the existing rule:
4608 // real type, but not _Bool.
4609 return T->isRealType() && !T->isBooleanType();
4610 }
4611
4612 bool isSugared() const { return false; }
4613 QualType desugar() const { return QualType(this, 0); }
4614
4615 static bool classof(const Type *T) {
4616 return T->getTypeClass() == ConstantMatrix ||
4617 T->getTypeClass() == DependentSizedMatrix;
4618 }
4619};
4620
4621/// Represents a concrete matrix type with constant number of rows and columns
4622class ConstantMatrixType final : public MatrixType {
4623protected:
4624 friend class ASTContext;
4625
4626 /// Number of rows and columns.
4627 unsigned NumRows;
4628 unsigned NumColumns;
4629 std::optional<LayoutKind> Layout;
4630
4631 ConstantMatrixType(QualType MatrixElementType, unsigned NRows,
4632 unsigned NColumns, QualType CanonElementType,
4633 std::optional<LayoutKind> Layout);
4634
4635 ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows,
4636 unsigned NColumns, QualType CanonElementType,
4637 std::optional<LayoutKind> Layout);
4638
4639public:
4640 /// Returns the number of rows in the matrix.
4641 unsigned getNumRows() const { return NumRows; }
4642
4643 /// Returns the number of columns in the matrix.
4644 unsigned getNumColumns() const { return NumColumns; }
4645
4646 std::optional<LayoutKind> getLayout() const { return Layout; }
4647
4648 /// Returns the number of elements required to embed the matrix into a vector.
4649 unsigned getNumElementsFlattened() const {
4650 return getNumRows() * getNumColumns();
4651 }
4652
4653 /// Returns the row-major flattened index of a matrix element located at row
4654 /// \p Row, and column \p Column
4655 unsigned getRowMajorFlattenedIndex(unsigned Row, unsigned Column) const {
4656 return Row * NumColumns + Column;
4657 }
4658
4659 /// Returns the column-major flattened index of a matrix element located at
4660 /// row \p Row, and column \p Column
4661 unsigned getColumnMajorFlattenedIndex(unsigned Row, unsigned Column) const {
4662 return Column * NumRows + Row;
4663 }
4664
4665 /// Returns the flattened index of a matrix element located at
4666 /// row \p Row, and column \p Column. If \p IsRowMajor is true, returns the
4667 /// row-major order flattened index. Otherwise, returns the column-major order
4668 /// flattened index.
4669 unsigned getFlattenedIndex(unsigned Row, unsigned Column,
4670 bool IsRowMajor = false) const {
4671 return IsRowMajor ? getRowMajorFlattenedIndex(Row, Column)
4673 }
4674
4675 /// Given a column-major flattened index \p ColumnMajorIdx, return the
4676 /// equivalent row-major flattened index.
4677 unsigned
4678 mapColumnMajorToRowMajorFlattenedIndex(unsigned ColumnMajorIdx) const {
4679 unsigned Column = ColumnMajorIdx / NumRows;
4680 unsigned Row = ColumnMajorIdx % NumRows;
4681 return Row * NumColumns + Column;
4682 }
4683
4684 /// Given a row-major flattened index \p RowMajorIdx, return the equivalent
4685 /// column-major flattened index.
4686 unsigned mapRowMajorToColumnMajorFlattenedIndex(unsigned RowMajorIdx) const {
4687 unsigned Row = RowMajorIdx / NumColumns;
4688 unsigned Column = RowMajorIdx % NumColumns;
4689 return Column * NumRows + Row;
4690 }
4691
4692 void Profile(llvm::FoldingSetNodeID &ID) {
4694 getTypeClass());
4695 }
4696
4697 static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType,
4698 unsigned NumRows, unsigned NumColumns,
4699 std::optional<LayoutKind> Layout, TypeClass TypeClass) {
4700 ID.AddPointer(ElementType.getAsOpaquePtr());
4701 ID.AddInteger(NumRows);
4702 ID.AddInteger(NumColumns);
4703 ID.AddInteger(Layout ? llvm::to_underlying(*Layout) + 1 : 0);
4704 ID.AddInteger(TypeClass);
4705 }
4706
4707 static bool classof(const Type *T) {
4708 return T->getTypeClass() == ConstantMatrix;
4709 }
4710};
4711
4712/// Represents a matrix type where the type and the number of rows and columns
4713/// is dependent on a template.
4714class DependentSizedMatrixType final : public MatrixType {
4715 friend class ASTContext;
4716
4717 Expr *RowExpr;
4718 Expr *ColumnExpr;
4719
4720 SourceLocation loc;
4721
4722 DependentSizedMatrixType(QualType ElementType, QualType CanonicalType,
4723 Expr *RowExpr, Expr *ColumnExpr, SourceLocation loc);
4724
4725public:
4726 Expr *getRowExpr() const { return RowExpr; }
4727 Expr *getColumnExpr() const { return ColumnExpr; }
4728 SourceLocation getAttributeLoc() const { return loc; }
4729
4730 static bool classof(const Type *T) {
4731 return T->getTypeClass() == DependentSizedMatrix;
4732 }
4733
4734 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
4735 Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr());
4736 }
4737
4738 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
4739 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr);
4740};
4741
4742/// FunctionType - C99 6.7.5.3 - Function Declarators. This is the common base
4743/// class of FunctionNoProtoType and FunctionProtoType.
4744class FunctionType : public Type {
4745 // The type returned by the function.
4746 QualType ResultType;
4747
4748public:
4749 /// Interesting information about a specific parameter that can't simply
4750 /// be reflected in parameter's type. This is only used by FunctionProtoType
4751 /// but is in FunctionType to make this class available during the
4752 /// specification of the bases of FunctionProtoType.
4753 ///
4754 /// It makes sense to model language features this way when there's some
4755 /// sort of parameter-specific override (such as an attribute) that
4756 /// affects how the function is called. For example, the ARC ns_consumed
4757 /// attribute changes whether a parameter is passed at +0 (the default)
4758 /// or +1 (ns_consumed). This must be reflected in the function type,
4759 /// but isn't really a change to the parameter type.
4760 ///
4761 /// One serious disadvantage of modelling language features this way is
4762 /// that they generally do not work with language features that attempt
4763 /// to destructure types. For example, template argument deduction will
4764 /// not be able to match a parameter declared as
4765 /// T (*)(U)
4766 /// against an argument of type
4767 /// void (*)(__attribute__((ns_consumed)) id)
4768 /// because the substitution of T=void, U=id into the former will
4769 /// not produce the latter.
4771 enum {
4772 ABIMask = 0x0F,
4773 IsConsumed = 0x10,
4774 HasPassObjSize = 0x20,
4775 IsNoEscape = 0x40,
4776 };
4777 unsigned char Data = 0;
4778
4779 public:
4780 ExtParameterInfo() = default;
4781
4782 /// Return the ABI treatment of this parameter.
4783 ParameterABI getABI() const { return ParameterABI(Data & ABIMask); }
4785 ExtParameterInfo copy = *this;
4786 copy.Data = (copy.Data & ~ABIMask) | unsigned(kind);
4787 return copy;
4788 }
4789
4790 /// Is this parameter considered "consumed" by Objective-C ARC?
4791 /// Consumed parameters must have retainable object type.
4792 bool isConsumed() const { return (Data & IsConsumed); }
4794 ExtParameterInfo copy = *this;
4795 if (consumed)
4796 copy.Data |= IsConsumed;
4797 else
4798 copy.Data &= ~IsConsumed;
4799 return copy;
4800 }
4801
4802 bool hasPassObjectSize() const { return Data & HasPassObjSize; }
4804 ExtParameterInfo Copy = *this;
4805 Copy.Data |= HasPassObjSize;
4806 return Copy;
4807 }
4808
4809 bool isNoEscape() const { return Data & IsNoEscape; }
4810 ExtParameterInfo withIsNoEscape(bool NoEscape) const {
4811 ExtParameterInfo Copy = *this;
4812 if (NoEscape)
4813 Copy.Data |= IsNoEscape;
4814 else
4815 Copy.Data &= ~IsNoEscape;
4816 return Copy;
4817 }
4818
4819 unsigned char getOpaqueValue() const { return Data; }
4820 static ExtParameterInfo getFromOpaqueValue(unsigned char data) {
4821 ExtParameterInfo result;
4822 result.Data = data;
4823 return result;
4824 }
4825
4827 return lhs.Data == rhs.Data;
4828 }
4829
4831 return lhs.Data != rhs.Data;
4832 }
4833 };
4834
4835 /// A class which abstracts out some details necessary for
4836 /// making a call.
4837 ///
4838 /// It is not actually used directly for storing this information in
4839 /// a FunctionType, although FunctionType does currently use the
4840 /// same bit-pattern.
4841 ///
4842 // If you add a field (say Foo), other than the obvious places (both,
4843 // constructors, compile failures), what you need to update is
4844 // * Operator==
4845 // * getFoo
4846 // * withFoo
4847 // * functionType. Add Foo, getFoo.
4848 // * ASTContext::getFooType
4849 // * ASTContext::mergeFunctionTypes
4850 // * FunctionNoProtoType::Profile
4851 // * FunctionProtoType::Profile
4852 // * TypePrinter::PrintFunctionProto
4853 // * AST read and write
4854 // * Codegen
4855 class ExtInfo {
4856 friend class FunctionType;
4857
4858 // Feel free to rearrange or add bits, but if you go over 16, you'll need to
4859 // adjust the Bits field below, and if you add bits, you'll need to adjust
4860 // Type::FunctionTypeBitfields::ExtInfo as well.
4861
4862 // | CC |noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
4863 // |0 .. 5| 6 | 7 | 8 |9 .. 11| 12 | 13 |
4864 //
4865 // regparm is either 0 (no regparm attribute) or the regparm value+1.
4866 enum { CallConvMask = 0x3F };
4867 enum { NoReturnMask = 0x40 };
4868 enum { ProducesResultMask = 0x80 };
4869 enum { NoCallerSavedRegsMask = 0x100 };
4870 enum { RegParmMask = 0xe00, RegParmOffset = 9 };
4871 enum { NoCfCheckMask = 0x1000 };
4872 enum { CmseNSCallMask = 0x2000 };
4873 uint16_t Bits = CC_C;
4874
4875 ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
4876
4877 public:
4878 // Constructor with no defaults. Use this when you know that you
4879 // have all the elements (when reading an AST file for example).
4880 ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
4881 bool producesResult, bool noCallerSavedRegs, bool NoCfCheck,
4882 bool cmseNSCall) {
4883 assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
4884 Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) |
4885 (producesResult ? ProducesResultMask : 0) |
4886 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
4887 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
4888 (NoCfCheck ? NoCfCheckMask : 0) |
4889 (cmseNSCall ? CmseNSCallMask : 0);
4890 }
4891
4892 // Constructor with all defaults. Use when for example creating a
4893 // function known to use defaults.
4894 ExtInfo() = default;
4895
4896 // Constructor with just the calling convention, which is an important part
4897 // of the canonical type.
4898 ExtInfo(CallingConv CC) : Bits(CC) {}
4899
4900 bool getNoReturn() const { return Bits & NoReturnMask; }
4901 bool getProducesResult() const { return Bits & ProducesResultMask; }
4902 bool getCmseNSCall() const { return Bits & CmseNSCallMask; }
4903 bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; }
4904 bool getNoCfCheck() const { return Bits & NoCfCheckMask; }
4905 bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
4906
4907 unsigned getRegParm() const {
4908 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
4909 if (RegParm > 0)
4910 --RegParm;
4911 return RegParm;
4912 }
4913
4914 CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
4915
4916 bool operator==(ExtInfo Other) const {
4917 return Bits == Other.Bits;
4918 }
4919 bool operator!=(ExtInfo Other) const {
4920 return Bits != Other.Bits;
4921 }
4922
4923 // Note that we don't have setters. That is by design, use
4924 // the following with methods instead of mutating these objects.
4925
4926 ExtInfo withNoReturn(bool noReturn) const {
4927 if (noReturn)
4928 return ExtInfo(Bits | NoReturnMask);
4929 else
4930 return ExtInfo(Bits & ~NoReturnMask);
4931 }
4932
4933 ExtInfo withProducesResult(bool producesResult) const {
4934 if (producesResult)
4935 return ExtInfo(Bits | ProducesResultMask);
4936 else
4937 return ExtInfo(Bits & ~ProducesResultMask);
4938 }
4939
4940 ExtInfo withCmseNSCall(bool cmseNSCall) const {
4941 if (cmseNSCall)
4942 return ExtInfo(Bits | CmseNSCallMask);
4943 else
4944 return ExtInfo(Bits & ~CmseNSCallMask);
4945 }
4946
4947 ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const {
4948 if (noCallerSavedRegs)
4949 return ExtInfo(Bits | NoCallerSavedRegsMask);
4950 else
4951 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4952 }
4953
4954 ExtInfo withNoCfCheck(bool noCfCheck) const {
4955 if (noCfCheck)
4956 return ExtInfo(Bits | NoCfCheckMask);
4957 else
4958 return ExtInfo(Bits & ~NoCfCheckMask);
4959 }
4960
4961 ExtInfo withRegParm(unsigned RegParm) const {
4962 assert(RegParm < 7 && "Invalid regparm value");
4963 return ExtInfo((Bits & ~RegParmMask) |
4964 ((RegParm + 1) << RegParmOffset));
4965 }
4966
4967 ExtInfo withCallingConv(CallingConv cc) const {
4968 return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc);
4969 }
4970
4971 void Profile(llvm::FoldingSetNodeID &ID) const {
4972 ID.AddInteger(Bits);
4973 }
4974 };
4975
4976 /// A simple holder for a QualType representing a type in an
4977 /// exception specification. Unfortunately needed by FunctionProtoType
4978 /// because TrailingObjects cannot handle repeated types.
4980
4981 /// A simple holder for various uncommon bits which do not fit in
4982 /// FunctionTypeBitfields. Aligned to alignof(void *) to maintain the
4983 /// alignment of subsequent objects in TrailingObjects.
4984 struct alignas(void *) FunctionTypeExtraBitfields {
4985 /// The number of types in the exception specification.
4986 /// A whole unsigned is not needed here and according to
4987 /// [implimits] 8 bits would be enough here.
4988 unsigned NumExceptionType : 10;
4989
4990 LLVM_PREFERRED_TYPE(bool)
4992
4993 LLVM_PREFERRED_TYPE(bool)
4995
4996 LLVM_PREFERRED_TYPE(bool)
4999
5004 };
5005
5006 /// A holder for extra information from attributes which aren't part of an
5007 /// \p AttributedType.
5008 struct alignas(void *) FunctionTypeExtraAttributeInfo {
5009 /// A CFI "salt" that differentiates functions with the same prototype.
5010 StringRef CFISalt;
5011
5012 operator bool() const { return !CFISalt.empty(); }
5013
5014 void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddString(CFISalt); }
5015 };
5016
5017 /// The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number
5018 /// of function type attributes that can be set on function types, including
5019 /// function pointers.
5024
5025 // Describes the value of the state using ArmStateValue.
5030
5031 // A bit to tell whether a function is agnostic about sme ZA state.
5034
5036 0b1'111'111'11 // We can't support more than 9 bits because of
5037 // the bitmask in FunctionTypeArmAttributes
5038 // and ExtProtoInfo.
5039 };
5040
5041 enum ArmStateValue : unsigned {
5047 };
5048
5049 static ArmStateValue getArmZAState(unsigned AttrBits) {
5050 return static_cast<ArmStateValue>((AttrBits & SME_ZAMask) >> SME_ZAShift);
5051 }
5052
5053 static ArmStateValue getArmZT0State(unsigned AttrBits) {
5054 return static_cast<ArmStateValue>((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
5055 }
5056
5057 /// A holder for Arm type attributes as described in the Arm C/C++
5058 /// Language extensions which are not particularly common to all
5059 /// types and therefore accounted separately from FunctionTypeBitfields.
5060 struct alignas(void *) FunctionTypeArmAttributes {
5061 /// Any AArch64 SME ACLE type attributes that need to be propagated
5062 /// on declarations and function pointers.
5063 LLVM_PREFERRED_TYPE(AArch64SMETypeAttributes)
5065
5067 };
5068
5069protected:
5072 : Type(tc, Canonical, Dependence), ResultType(res) {
5073 FunctionTypeBits.ExtInfo = Info.Bits;
5074 }
5075
5077 if (isFunctionProtoType())
5078 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
5079
5080 return Qualifiers();
5081 }
5082
5083public:
5084 QualType getReturnType() const { return ResultType; }
5085
5086 bool getHasRegParm() const { return getExtInfo().getHasRegParm(); }
5087 unsigned getRegParmType() const { return getExtInfo().getRegParm(); }
5088
5089 /// Determine whether this function type includes the GNU noreturn
5090 /// attribute. The C++11 [[noreturn]] attribute does not affect the function
5091 /// type.
5092 bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); }
5093
5094 /// Determine whether this is a function prototype that includes the
5095 /// cfi_unchecked_callee attribute.
5096 bool getCFIUncheckedCalleeAttr() const;
5097
5098 bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); }
5099 CallingConv getCallConv() const { return getExtInfo().getCC(); }
5100 ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); }
5101
5102 static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
5103 "Const, volatile and restrict are assumed to be a subset of "
5104 "the fast qualifiers.");
5105
5106 bool isConst() const { return getFastTypeQuals().hasConst(); }
5107 bool isVolatile() const { return getFastTypeQuals().hasVolatile(); }
5108 bool isRestrict() const { return getFastTypeQuals().hasRestrict(); }
5109
5110 /// Determine the type of an expression that calls a function of
5111 /// this type.
5112 QualType getCallResultType(const ASTContext &Context) const {
5113 return getReturnType().getNonLValueExprType(Context);
5114 }
5115
5116 static StringRef getNameForCallConv(CallingConv CC);
5117
5118 static bool classof(const Type *T) {
5119 return T->getTypeClass() == FunctionNoProto ||
5120 T->getTypeClass() == FunctionProto;
5121 }
5122};
5123
5124/// Represents a K&R-style 'int foo()' function, which has
5125/// no information available about its arguments.
5126class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode {
5127 friend class ASTContext; // ASTContext creates these.
5128
5129 FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info)
5130 : FunctionType(FunctionNoProto, Result, Canonical,
5132 ~(TypeDependence::DependentInstantiation |
5133 TypeDependence::UnexpandedPack),
5134 Info) {}
5135
5136public:
5137 // No additional state past what FunctionType provides.
5138
5139 bool isSugared() const { return false; }
5140 QualType desugar() const { return QualType(this, 0); }
5141
5142 void Profile(llvm::FoldingSetNodeID &ID) {
5144 }
5145
5146 static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType,
5147 ExtInfo Info) {
5148 Info.Profile(ID);
5149 ID.AddPointer(ResultType.getAsOpaquePtr());
5150 }
5151
5152 static bool classof(const Type *T) {
5153 return T->getTypeClass() == FunctionNoProto;
5154 }
5155};
5156
5157// ------------------------------------------------------------------------------
5158
5159/// Represents an abstract function effect, using just an enumeration describing
5160/// its kind.
5162public:
5163 /// Identifies the particular effect.
5171 constexpr static size_t KindCount = static_cast<size_t>(Kind::Last) + 1;
5172
5173 /// Flags describing some behaviors of the effect.
5176 // Can verification inspect callees' implementations? (e.g. nonblocking:
5177 // yes, tcb+types: no). This also implies the need for 2nd-pass
5178 // verification.
5180
5181 // Language constructs which effects can diagnose as disallowed.
5187 };
5188
5189private:
5190 Kind FKind;
5191
5192 // Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
5193 // then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would
5194 // be considered for uniqueness.
5195
5196public:
5197 explicit FunctionEffect(Kind K) : FKind(K) {}
5198
5199 /// The kind of the effect.
5200 Kind kind() const { return FKind; }
5201
5202 /// Return the opposite kind, for effects which have opposites.
5203 Kind oppositeKind() const;
5204
5205 /// For serialization.
5206 uint32_t toOpaqueInt32() const { return uint32_t(FKind); }
5210
5211 /// Flags describing some behaviors of the effect.
5212 Flags flags() const {
5213 switch (kind()) {
5214 case Kind::NonBlocking:
5219 // Same as NonBlocking, except without FE_ExcludeStaticLocalVars.
5222 case Kind::Blocking:
5223 case Kind::Allocating:
5224 return 0;
5225 }
5226 llvm_unreachable("unknown effect kind");
5227 }
5228
5229 /// The description printed in diagnostics, e.g. 'nonblocking'.
5230 StringRef name() const;
5231
5232 friend raw_ostream &operator<<(raw_ostream &OS,
5233 const FunctionEffect &Effect) {
5234 OS << Effect.name();
5235 return OS;
5236 }
5237
5238 /// Determine whether the effect is allowed to be inferred on the callee,
5239 /// which is either a FunctionDecl or BlockDecl. If the returned optional
5240 /// is empty, inference is permitted; otherwise it holds the effect which
5241 /// blocked inference.
5242 /// Example: This allows nonblocking(false) to prevent inference for the
5243 /// function.
5244 std::optional<FunctionEffect>
5245 effectProhibitingInference(const Decl &Callee,
5246 FunctionEffectKindSet CalleeFX) const;
5247
5248 // Return false for success. When true is returned for a direct call, then the
5249 // FE_InferrableOnCallees flag may trigger inference rather than an immediate
5250 // diagnostic. Caller should be assumed to have the effect (it may not have it
5251 // explicitly when inferring).
5252 bool shouldDiagnoseFunctionCall(bool Direct,
5253 FunctionEffectKindSet CalleeFX) const;
5254
5256 return LHS.FKind == RHS.FKind;
5257 }
5259 return !(LHS == RHS);
5260 }
5262 return LHS.FKind < RHS.FKind;
5263 }
5264};
5265
5266/// Wrap a function effect's condition expression in another struct so
5267/// that FunctionProtoType's TrailingObjects can treat it separately.
5269 Expr *Cond = nullptr; // if null, unconditional.
5270
5271public:
5273 EffectConditionExpr(Expr *E) : Cond(E) {}
5274
5275 Expr *getCondition() const { return Cond; }
5276
5277 bool operator==(const EffectConditionExpr &RHS) const {
5278 return Cond == RHS.Cond;
5279 }
5280};
5281
5282/// A FunctionEffect plus a potential boolean expression determining whether
5283/// the effect is declared (e.g. nonblocking(expr)). Generally the condition
5284/// expression when present, is dependent.
5288
5291
5292 /// Return a textual description of the effect, and its condition, if any.
5293 std::string description() const;
5294
5295 friend raw_ostream &operator<<(raw_ostream &OS,
5296 const FunctionEffectWithCondition &CFE);
5297};
5298
5299/// Support iteration in parallel through a pair of FunctionEffect and
5300/// EffectConditionExpr containers.
5301template <typename Container> class FunctionEffectIterator {
5302 friend Container;
5303
5304 const Container *Outer = nullptr;
5305 size_t Idx = 0;
5306
5307public:
5309 FunctionEffectIterator(const Container &O, size_t I) : Outer(&O), Idx(I) {}
5311 return Idx == Other.Idx;
5312 }
5314 return Idx != Other.Idx;
5315 }
5316
5318 ++Idx;
5319 return *this;
5320 }
5321
5323 assert(Outer != nullptr && "invalid FunctionEffectIterator");
5324 bool HasConds = !Outer->Conditions.empty();
5325 return FunctionEffectWithCondition{Outer->Effects[Idx],
5326 HasConds ? Outer->Conditions[Idx]
5328 }
5329};
5330
5331/// An immutable set of FunctionEffects and possibly conditions attached to
5332/// them. The effects and conditions reside in memory not managed by this object
5333/// (typically, trailing objects in FunctionProtoType, or borrowed references
5334/// from a FunctionEffectSet).
5335///
5336/// Invariants:
5337/// - there is never more than one instance of any given effect.
5338/// - the array of conditions is either empty or has the same size as the
5339/// array of effects.
5340/// - some conditions may be null expressions; each condition pertains to
5341/// the effect at the same array index.
5342///
5343/// Also, if there are any conditions, at least one of those expressions will be
5344/// dependent, but this is only asserted in the constructor of
5345/// FunctionProtoType.
5346///
5347/// See also FunctionEffectSet, in Sema, which provides a mutable set.
5348class FunctionEffectsRef {
5349 // Restrict classes which can call the private constructor -- these friends
5350 // all maintain the required invariants. FunctionEffectSet is generally the
5351 // only way in which the arrays are created; FunctionProtoType will not
5352 // reorder them.
5353 friend FunctionProtoType;
5354 friend FunctionEffectSet;
5355
5358
5359 // The arrays are expected to have been sorted by the caller, with the
5360 // effects in order. The conditions array must be empty or the same size
5361 // as the effects array, since the conditions are associated with the effects
5362 // at the same array indices.
5363 FunctionEffectsRef(ArrayRef<FunctionEffect> FX,
5365 : Effects(FX), Conditions(Conds) {}
5366
5367public:
5368 /// Extract the effects from a Type if it is a function, block, or member
5369 /// function pointer, or a reference or pointer to one.
5370 static FunctionEffectsRef get(QualType QT);
5371
5372 /// Asserts invariants.
5373 static FunctionEffectsRef create(ArrayRef<FunctionEffect> FX,
5375
5377
5378 bool empty() const { return Effects.empty(); }
5379 size_t size() const { return Effects.size(); }
5380
5381 ArrayRef<FunctionEffect> effects() const { return Effects; }
5382 ArrayRef<EffectConditionExpr> conditions() const { return Conditions; }
5383
5385 friend iterator;
5386 iterator begin() const { return iterator(*this, 0); }
5387 iterator end() const { return iterator(*this, size()); }
5388
5389 friend bool operator==(const FunctionEffectsRef &LHS,
5390 const FunctionEffectsRef &RHS) {
5391 return LHS.Effects == RHS.Effects && LHS.Conditions == RHS.Conditions;
5392 }
5393 friend bool operator!=(const FunctionEffectsRef &LHS,
5394 const FunctionEffectsRef &RHS) {
5395 return !(LHS == RHS);
5396 }
5397
5398 void dump(llvm::raw_ostream &OS) const;
5399};
5400
5401/// A mutable set of FunctionEffect::Kind.
5402class FunctionEffectKindSet {
5403 // For now this only needs to be a bitmap.
5404 constexpr static size_t EndBitPos = FunctionEffect::KindCount;
5405 using KindBitsT = std::bitset<EndBitPos>;
5406
5407 KindBitsT KindBits{};
5408
5409 explicit FunctionEffectKindSet(KindBitsT KB) : KindBits(KB) {}
5410
5411 // Functions to translate between an effect kind, starting at 1, and a
5412 // position in the bitset.
5413
5414 constexpr static size_t kindToPos(FunctionEffect::Kind K) {
5415 return static_cast<size_t>(K);
5416 }
5417
5418 constexpr static FunctionEffect::Kind posToKind(size_t Pos) {
5419 return static_cast<FunctionEffect::Kind>(Pos);
5420 }
5421
5422 // Iterates through the bits which are set.
5423 class iterator {
5424 const FunctionEffectKindSet *Outer = nullptr;
5425 size_t Idx = 0;
5426
5427 // If Idx does not reference a set bit, advance it until it does,
5428 // or until it reaches EndBitPos.
5429 void advanceToNextSetBit() {
5430 while (Idx < EndBitPos && !Outer->KindBits.test(Idx))
5431 ++Idx;
5432 }
5433
5434 public:
5435 iterator();
5436 iterator(const FunctionEffectKindSet &O, size_t I) : Outer(&O), Idx(I) {
5437 advanceToNextSetBit();
5438 }
5439 bool operator==(const iterator &Other) const { return Idx == Other.Idx; }
5440 bool operator!=(const iterator &Other) const { return Idx != Other.Idx; }
5441
5442 iterator operator++() {
5443 ++Idx;
5444 advanceToNextSetBit();
5445 return *this;
5446 }
5447
5448 FunctionEffect operator*() const {
5449 assert(Idx < EndBitPos && "Dereference of end iterator");
5450 return FunctionEffect(posToKind(Idx));
5451 }
5452 };
5453
5454public:
5457
5458 iterator begin() const { return iterator(*this, 0); }
5459 iterator end() const { return iterator(*this, EndBitPos); }
5460
5461 void insert(FunctionEffect Effect) { KindBits.set(kindToPos(Effect.kind())); }
5463 for (FunctionEffect Item : FX.effects())
5464 insert(Item);
5465 }
5466 void insert(FunctionEffectKindSet Set) { KindBits |= Set.KindBits; }
5467
5468 bool empty() const { return KindBits.none(); }
5469 bool contains(const FunctionEffect::Kind EK) const {
5470 return KindBits.test(kindToPos(EK));
5471 }
5472 void dump(llvm::raw_ostream &OS) const;
5473
5474 static FunctionEffectKindSet difference(FunctionEffectKindSet LHS,
5475 FunctionEffectKindSet RHS) {
5476 return FunctionEffectKindSet(LHS.KindBits & ~RHS.KindBits);
5477 }
5478};
5479
5480/// A mutable set of FunctionEffects and possibly conditions attached to them.
5481/// Used to compare and merge effects on declarations.
5482///
5483/// Has the same invariants as FunctionEffectsRef.
5487
5488public:
5490
5492 : Effects(FX.effects()), Conditions(FX.conditions()) {}
5493
5494 bool empty() const { return Effects.empty(); }
5495 size_t size() const { return Effects.size(); }
5496
5498 friend iterator;
5499 iterator begin() const { return iterator(*this, 0); }
5500 iterator end() const { return iterator(*this, size()); }
5501
5502 operator FunctionEffectsRef() const { return {Effects, Conditions}; }
5503
5504 void dump(llvm::raw_ostream &OS) const;
5505
5506 // Mutators
5507
5508 // On insertion, a conflict occurs when attempting to insert an
5509 // effect which is opposite an effect already in the set, or attempting
5510 // to insert an effect which is already in the set but with a condition
5511 // which is not identical.
5517
5518 // Returns true for success (obviating a check of Errs.empty()).
5519 bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs);
5520
5521 // Returns true for success (obviating a check of Errs.empty()).
5522 bool insert(const FunctionEffectsRef &Set, Conflicts &Errs);
5523
5524 // Set operations
5525
5527 FunctionEffectsRef RHS, Conflicts &Errs);
5529 FunctionEffectsRef RHS);
5530};
5531
5532/// Represents a prototype with parameter type info, e.g.
5533/// 'int foo(int)' or 'int foo(void)'. 'void' is represented as having no
5534/// parameters, not as having a single void parameter. Such a type can have
5535/// an exception specification, but this specification is not part of the
5536/// canonical type. FunctionProtoType has several trailing objects, some of
5537/// which optional. For more information about the trailing objects see
5538/// the first comment inside FunctionProtoType.
5539class FunctionProtoType final
5540 : public FunctionType,
5541 public llvm::FoldingSetNode,
5542 private llvm::TrailingObjects<
5543 FunctionProtoType, QualType, SourceLocation,
5544 FunctionType::FunctionTypeExtraBitfields,
5545 FunctionType::FunctionTypeExtraAttributeInfo,
5546 FunctionType::FunctionTypeArmAttributes, FunctionType::ExceptionType,
5547 Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers,
5548 FunctionEffect, EffectConditionExpr> {
5549 friend class ASTContext; // ASTContext creates these.
5550 friend TrailingObjects;
5551
5552 // FunctionProtoType is followed by several trailing objects, some of
5553 // which optional. They are in order:
5554 //
5555 // * An array of getNumParams() QualType holding the parameter types.
5556 // Always present. Note that for the vast majority of FunctionProtoType,
5557 // these will be the only trailing objects.
5558 //
5559 // * Optionally if the function is variadic, the SourceLocation of the
5560 // ellipsis.
5561 //
5562 // * Optionally if some extra data is stored in FunctionTypeExtraBitfields
5563 // (see FunctionTypeExtraBitfields and FunctionTypeBitfields):
5564 // a single FunctionTypeExtraBitfields. Present if and only if
5565 // hasExtraBitfields() is true.
5566 //
5567 // * Optionally exactly one of:
5568 // * an array of getNumExceptions() ExceptionType,
5569 // * a single Expr *,
5570 // * a pair of FunctionDecl *,
5571 // * a single FunctionDecl *
5572 // used to store information about the various types of exception
5573 // specification. See getExceptionSpecSize for the details.
5574 //
5575 // * Optionally an array of getNumParams() ExtParameterInfo holding
5576 // an ExtParameterInfo for each of the parameters. Present if and
5577 // only if hasExtParameterInfos() is true.
5578 //
5579 // * Optionally a Qualifiers object to represent extra qualifiers that can't
5580 // be represented by FunctionTypeBitfields.FastTypeQuals. Present if and
5581 // only if hasExtQualifiers() is true.
5582 //
5583 // * Optionally, an array of getNumFunctionEffects() FunctionEffect.
5584 // Present only when getNumFunctionEffects() > 0
5585 //
5586 // * Optionally, an array of getNumFunctionEffects() EffectConditionExpr.
5587 // Present only when getNumFunctionEffectConditions() > 0.
5588 //
5589 // The optional FunctionTypeExtraBitfields has to be before the data
5590 // related to the exception specification since it contains the number
5591 // of exception types.
5592 //
5593 // We put the ExtParameterInfos later. If all were equal, it would make
5594 // more sense to put these before the exception specification, because
5595 // it's much easier to skip past them compared to the elaborate switch
5596 // required to skip the exception specification. However, all is not
5597 // equal; ExtParameterInfos are used to model very uncommon features,
5598 // and it's better not to burden the more common paths.
5599
5600public:
5601 /// Holds information about the various types of exception specification.
5602 /// ExceptionSpecInfo is not stored as such in FunctionProtoType but is
5603 /// used to group together the various bits of information about the
5604 /// exception specification.
5606 /// The kind of exception specification this is.
5608
5609 /// Explicitly-specified list of exception types.
5611
5612 /// Noexcept expression, if this is a computed noexcept specification.
5613 Expr *NoexceptExpr = nullptr;
5614
5615 /// The function whose exception specification this is, for
5616 /// EST_Unevaluated and EST_Uninstantiated.
5618
5619 /// The function template whose exception specification this is instantiated
5620 /// from, for EST_Uninstantiated.
5622
5624
5626
5627 void instantiate();
5628 };
5629
5630 /// Extra information about a function prototype. ExtProtoInfo is not
5631 /// stored as such in FunctionProtoType but is used to group together
5632 /// the various bits of extra information about a function prototype.
5642
5643 LLVM_PREFERRED_TYPE(bool)
5645 LLVM_PREFERRED_TYPE(bool)
5646 unsigned HasTrailingReturn : 1;
5647 LLVM_PREFERRED_TYPE(bool)
5649 LLVM_PREFERRED_TYPE(AArch64SMETypeAttributes)
5651
5655
5659
5661 ExtProtoInfo Result(*this);
5662 Result.ExceptionSpec = ESI;
5663 return Result;
5664 }
5665
5667 ExtProtoInfo Result(*this);
5668 Result.CFIUncheckedCallee = CFIUncheckedCallee;
5669 return Result;
5670 }
5671
5678
5682
5684 return static_cast<bool>(ExtraAttributeInfo);
5685 }
5686
5687 void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable = true) {
5688 if (Enable)
5689 AArch64SMEAttributes |= Kind;
5690 else
5691 AArch64SMEAttributes &= ~Kind;
5692 }
5693 };
5694
5695private:
5696 unsigned numTrailingObjects(OverloadToken<QualType>) const {
5697 return getNumParams();
5698 }
5699
5700 unsigned numTrailingObjects(OverloadToken<SourceLocation>) const {
5701 return isVariadic();
5702 }
5703
5704 unsigned numTrailingObjects(OverloadToken<FunctionTypeArmAttributes>) const {
5705 return hasArmTypeAttributes();
5706 }
5707
5708 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const {
5709 return hasExtraBitfields();
5710 }
5711
5712 unsigned
5713 numTrailingObjects(OverloadToken<FunctionTypeExtraAttributeInfo>) const {
5714 return hasExtraAttributeInfo();
5715 }
5716
5717 unsigned numTrailingObjects(OverloadToken<ExceptionType>) const {
5718 return getExceptionSpecSize().NumExceptionType;
5719 }
5720
5721 unsigned numTrailingObjects(OverloadToken<Expr *>) const {
5722 return getExceptionSpecSize().NumExprPtr;
5723 }
5724
5725 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const {
5726 return getExceptionSpecSize().NumFunctionDeclPtr;
5727 }
5728
5729 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const {
5730 return hasExtParameterInfos() ? getNumParams() : 0;
5731 }
5732
5733 unsigned numTrailingObjects(OverloadToken<Qualifiers>) const {
5734 return hasExtQualifiers() ? 1 : 0;
5735 }
5736
5737 unsigned numTrailingObjects(OverloadToken<FunctionEffect>) const {
5738 return getNumFunctionEffects();
5739 }
5740
5741 /// Determine whether there are any argument types that
5742 /// contain an unexpanded parameter pack.
5743 static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray,
5744 unsigned numArgs) {
5745 for (unsigned Idx = 0; Idx < numArgs; ++Idx)
5746 if (ArgArray[Idx]->containsUnexpandedParameterPack())
5747 return true;
5748
5749 return false;
5750 }
5751
5752 FunctionProtoType(QualType result, ArrayRef<QualType> params,
5753 QualType canonical, const ExtProtoInfo &epi);
5754
5755 /// This struct is returned by getExceptionSpecSize and is used to
5756 /// translate an ExceptionSpecificationType to the number and kind
5757 /// of trailing objects related to the exception specification.
5758 struct ExceptionSpecSizeHolder {
5759 unsigned NumExceptionType;
5760 unsigned NumExprPtr;
5761 unsigned NumFunctionDeclPtr;
5762 };
5763
5764 /// Return the number and kind of trailing objects
5765 /// related to the exception specification.
5766 static ExceptionSpecSizeHolder
5767 getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) {
5768 switch (EST) {
5769 case EST_None:
5770 case EST_DynamicNone:
5771 case EST_MSAny:
5772 case EST_BasicNoexcept:
5773 case EST_Unparsed:
5774 case EST_NoThrow:
5775 return {0, 0, 0};
5776
5777 case EST_Dynamic:
5778 return {NumExceptions, 0, 0};
5779
5781 case EST_NoexceptFalse:
5782 case EST_NoexceptTrue:
5783 return {0, 1, 0};
5784
5785 case EST_Uninstantiated:
5786 return {0, 0, 2};
5787
5788 case EST_Unevaluated:
5789 return {0, 0, 1};
5790 }
5791 llvm_unreachable("bad exception specification kind");
5792 }
5793
5794 /// Return the number and kind of trailing objects
5795 /// related to the exception specification.
5796 ExceptionSpecSizeHolder getExceptionSpecSize() const {
5797 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
5798 }
5799
5800 /// Whether the trailing FunctionTypeExtraBitfields is present.
5801 bool hasExtraBitfields() const {
5802 assert((getExceptionSpecType() != EST_Dynamic ||
5803 FunctionTypeBits.HasExtraBitfields) &&
5804 "ExtraBitfields are required for given ExceptionSpecType");
5805 return FunctionTypeBits.HasExtraBitfields;
5806
5807 }
5808
5809 bool hasExtraAttributeInfo() const {
5810 return FunctionTypeBits.HasExtraBitfields &&
5811 getTrailingObjects<FunctionTypeExtraBitfields>()
5812 ->HasExtraAttributeInfo;
5813 }
5814
5815 bool hasArmTypeAttributes() const {
5816 return FunctionTypeBits.HasExtraBitfields &&
5817 getTrailingObjects<FunctionTypeExtraBitfields>()
5818 ->HasArmTypeAttributes;
5819 }
5820
5821 bool hasExtQualifiers() const {
5822 return FunctionTypeBits.HasExtQuals;
5823 }
5824
5825public:
5826 unsigned getNumParams() const { return FunctionTypeBits.NumParams; }
5827
5828 QualType getParamType(unsigned i) const {
5829 assert(i < getNumParams() && "invalid parameter index");
5830 return param_type_begin()[i];
5831 }
5832
5836
5853
5854 /// Get the kind of exception specification on this function.
5856 return static_cast<ExceptionSpecificationType>(
5857 FunctionTypeBits.ExceptionSpecType);
5858 }
5859
5860 /// Return whether this function has any kind of exception spec.
5861 bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; }
5862
5863 /// Return whether this function has a dynamic (throw) exception spec.
5867
5868 /// Return whether this function has a noexcept exception spec.
5872
5873 /// Return whether this function has a dependent exception spec.
5874 bool hasDependentExceptionSpec() const;
5875
5876 /// Return whether this function has an instantiation-dependent exception
5877 /// spec.
5878 bool hasInstantiationDependentExceptionSpec() const;
5879
5880 /// Return all the available information about this type's exception spec.
5884 if (Result.Type == EST_Dynamic) {
5885 Result.Exceptions = exceptions();
5886 } else if (isComputedNoexcept(Result.Type)) {
5887 Result.NoexceptExpr = getNoexceptExpr();
5888 } else if (Result.Type == EST_Uninstantiated) {
5889 Result.SourceDecl = getExceptionSpecDecl();
5890 Result.SourceTemplate = getExceptionSpecTemplate();
5891 } else if (Result.Type == EST_Unevaluated) {
5892 Result.SourceDecl = getExceptionSpecDecl();
5893 }
5894 return Result;
5895 }
5896
5897 /// Return the number of types in the exception specification.
5898 unsigned getNumExceptions() const {
5900 ? getTrailingObjects<FunctionTypeExtraBitfields>()
5901 ->NumExceptionType
5902 : 0;
5903 }
5904
5905 /// Return the ith exception type, where 0 <= i < getNumExceptions().
5906 QualType getExceptionType(unsigned i) const {
5907 assert(i < getNumExceptions() && "Invalid exception number!");
5908 return exception_begin()[i];
5909 }
5910
5911 /// Return the expression inside noexcept(expression), or a null pointer
5912 /// if there is none (because the exception spec is not of this form).
5915 return nullptr;
5916 return *getTrailingObjects<Expr *>();
5917 }
5918
5919 /// If this function type has an exception specification which hasn't
5920 /// been determined yet (either because it has not been evaluated or because
5921 /// it has not been instantiated), this is the function whose exception
5922 /// specification is represented by this type.
5926 return nullptr;
5927 return getTrailingObjects<FunctionDecl *>()[0];
5928 }
5929
5930 /// If this function type has an uninstantiated exception
5931 /// specification, this is the function whose exception specification
5932 /// should be instantiated to find the exception specification for
5933 /// this type.
5936 return nullptr;
5937 return getTrailingObjects<FunctionDecl *>()[1];
5938 }
5939
5940 /// Determine whether this function type has a non-throwing exception
5941 /// specification.
5942 CanThrowResult canThrow() const;
5943
5944 /// Determine whether this function type has a non-throwing exception
5945 /// specification. If this depends on template arguments, returns
5946 /// \c ResultIfDependent.
5947 bool isNothrow(bool ResultIfDependent = false) const {
5948 return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot;
5949 }
5950
5951 /// Whether this function prototype is variadic.
5952 bool isVariadic() const { return FunctionTypeBits.Variadic; }
5953
5955 return isVariadic() ? *getTrailingObjects<SourceLocation>()
5956 : SourceLocation();
5957 }
5958
5959 /// Determines whether this function prototype contains a
5960 /// parameter pack at the end.
5961 ///
5962 /// A function template whose last parameter is a parameter pack can be
5963 /// called with an arbitrary number of arguments, much like a variadic
5964 /// function.
5965 bool isTemplateVariadic() const;
5966
5967 /// Whether this function prototype has a trailing return type.
5968 bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; }
5969
5971 return FunctionTypeBits.CFIUncheckedCallee;
5972 }
5973
5975 if (hasExtQualifiers())
5976 return *getTrailingObjects<Qualifiers>();
5977 else
5978 return getFastTypeQuals();
5979 }
5980
5981 /// Retrieve the ref-qualifier associated with this function type.
5983 return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier);
5984 }
5985
5987
5991
5993 return getTrailingObjects<QualType>();
5994 }
5995
5999
6001
6003 return {exception_begin(), exception_end()};
6004 }
6005
6007 return reinterpret_cast<exception_iterator>(
6008 getTrailingObjects<ExceptionType>());
6009 }
6010
6014
6015 /// Is there any interesting extra information for any of the parameters
6016 /// of this function type?
6018 return FunctionTypeBits.HasExtParameterInfos;
6019 }
6020
6022 assert(hasExtParameterInfos());
6023 return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(),
6024 getNumParams());
6025 }
6026
6027 /// Return a pointer to the beginning of the array of extra parameter
6028 /// information, if present, or else null if none of the parameters
6029 /// carry it. This is equivalent to getExtProtoInfo().ExtParameterInfos.
6031 if (!hasExtParameterInfos())
6032 return nullptr;
6033 return getTrailingObjects<ExtParameterInfo>();
6034 }
6035
6036 /// Return the extra attribute information.
6038 if (hasExtraAttributeInfo())
6039 return *getTrailingObjects<FunctionTypeExtraAttributeInfo>();
6041 }
6042
6043 /// Return a bitmask describing the SME attributes on the function type, see
6044 /// AArch64SMETypeAttributes for their values.
6045 unsigned getAArch64SMEAttributes() const {
6046 if (!hasArmTypeAttributes())
6047 return SME_NormalFunction;
6048 return getTrailingObjects<FunctionTypeArmAttributes>()
6049 ->AArch64SMEAttributes;
6050 }
6051
6053 assert(I < getNumParams() && "parameter index out of range");
6055 return getTrailingObjects<ExtParameterInfo>()[I];
6056 return ExtParameterInfo();
6057 }
6058
6059 ParameterABI getParameterABI(unsigned I) const {
6060 assert(I < getNumParams() && "parameter index out of range");
6062 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
6064 }
6065
6066 bool isParamConsumed(unsigned I) const {
6067 assert(I < getNumParams() && "parameter index out of range");
6069 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
6070 return false;
6071 }
6072
6073 unsigned getNumFunctionEffects() const {
6074 return hasExtraBitfields()
6075 ? getTrailingObjects<FunctionTypeExtraBitfields>()
6076 ->NumFunctionEffects
6077 : 0;
6078 }
6079
6080 // For serialization.
6082 if (hasExtraBitfields()) {
6083 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
6084 if (Bitfields->NumFunctionEffects > 0)
6085 return getTrailingObjects<FunctionEffect>(
6086 Bitfields->NumFunctionEffects);
6087 }
6088 return {};
6089 }
6090
6092 if (hasExtraBitfields()) {
6093 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
6094 if (Bitfields->EffectsHaveConditions)
6095 return Bitfields->NumFunctionEffects;
6096 }
6097 return 0;
6098 }
6099
6100 // For serialization.
6102 if (hasExtraBitfields()) {
6103 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
6104 if (Bitfields->EffectsHaveConditions)
6105 return getTrailingObjects<EffectConditionExpr>(
6106 Bitfields->NumFunctionEffects);
6107 }
6108 return {};
6109 }
6110
6111 // Combines effects with their conditions.
6113 if (hasExtraBitfields()) {
6114 const auto *Bitfields = getTrailingObjects<FunctionTypeExtraBitfields>();
6115 if (Bitfields->NumFunctionEffects > 0) {
6116 const size_t NumConds = Bitfields->EffectsHaveConditions
6117 ? Bitfields->NumFunctionEffects
6118 : 0;
6119 return FunctionEffectsRef(
6120 getTrailingObjects<FunctionEffect>(Bitfields->NumFunctionEffects),
6121 {NumConds ? getTrailingObjects<EffectConditionExpr>() : nullptr,
6122 NumConds});
6123 }
6124 }
6125 return {};
6126 }
6127
6128 bool isSugared() const { return false; }
6129 QualType desugar() const { return QualType(this, 0); }
6130
6131 void printExceptionSpecification(raw_ostream &OS,
6132 const PrintingPolicy &Policy) const;
6133
6134 static bool classof(const Type *T) {
6135 return T->getTypeClass() == FunctionProto;
6136 }
6137
6138 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
6139 static void Profile(llvm::FoldingSetNodeID &ID, QualType Result,
6140 param_type_iterator ArgTys, unsigned NumArgs,
6141 const ExtProtoInfo &EPI, const ASTContext &Context);
6142};
6143
6144/// The elaboration keyword that precedes a qualified type name or
6145/// introduces an elaborated-type-specifier.
6147 /// The "struct" keyword introduces the elaborated-type-specifier.
6149
6150 /// The "__interface" keyword introduces the elaborated-type-specifier.
6152
6153 /// The "union" keyword introduces the elaborated-type-specifier.
6155
6156 /// The "class" keyword introduces the elaborated-type-specifier.
6158
6159 /// The "enum" keyword introduces the elaborated-type-specifier.
6161
6162 /// The "typename" keyword precedes the qualified type name, e.g.,
6163 /// \c typename T::type.
6165
6166 /// No keyword precedes the qualified type name.
6168};
6169
6170/// The kind of a tag type.
6171enum class TagTypeKind {
6172 /// The "struct" keyword.
6174
6175 /// The "__interface" keyword.
6177
6178 /// The "union" keyword.
6180
6181 /// The "class" keyword.
6183
6184 /// The "enum" keyword.
6186};
6187
6188/// Provides a few static helpers for converting and printing
6189/// elaborated type keyword and tag type kind enumerations.
6191 /// Converts a type specifier (DeclSpec::TST) into an elaborated type keyword.
6192 static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
6193
6194 /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
6195 /// It is an error to provide a type specifier which *isn't* a tag kind here.
6196 static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
6197
6198 /// Converts a TagTypeKind into an elaborated type keyword.
6200
6201 /// Converts an elaborated type keyword into a TagTypeKind.
6202 /// It is an error to provide an elaborated type keyword
6203 /// which *isn't* a tag kind here.
6205
6207
6209
6210 static StringRef getTagTypeKindName(TagTypeKind Kind) {
6212 }
6213};
6214
6215template <class T> class KeywordWrapper : public T, public KeywordHelpers {
6216protected:
6217 template <class... As>
6219 : T(std::forward<As>(as)...) {
6220 this->KeywordWrapperBits.Keyword = llvm::to_underlying(Keyword);
6221 }
6222
6223public:
6225 return static_cast<ElaboratedTypeKeyword>(this->KeywordWrapperBits.Keyword);
6226 }
6227
6230};
6231
6232/// A helper class for Type nodes having an ElaboratedTypeKeyword.
6233/// The keyword in stored in the free bits of the base class.
6234class TypeWithKeyword : public KeywordWrapper<Type> {
6235protected:
6239};
6240
6241template <class T> struct FoldingSetPlaceholder : llvm::FoldingSetNode {
6242 void Profile(llvm::FoldingSetNodeID &ID) { getType()->Profile(ID); }
6243
6244 inline const T *getType() const {
6245 constexpr unsigned long Offset =
6246 llvm::alignTo(sizeof(T), alignof(FoldingSetPlaceholder));
6247 const auto *Addr = reinterpret_cast<const T *>(
6248 reinterpret_cast<const char *>(this) - Offset);
6249 assert(llvm::isAddrAligned(llvm::Align(alignof(T)), Addr));
6250 return Addr;
6251 }
6252};
6253
6254/// Represents the dependent type named by a dependently-scoped
6255/// typename using declaration, e.g.
6256/// using typename Base<T>::foo;
6257///
6258/// Template instantiation turns these into the underlying type.
6259class UnresolvedUsingType final
6260 : public TypeWithKeyword,
6261 private llvm::TrailingObjects<UnresolvedUsingType,
6262 FoldingSetPlaceholder<UnresolvedUsingType>,
6263 NestedNameSpecifier> {
6264 friend class ASTContext; // ASTContext creates these.
6265 friend TrailingObjects;
6266
6268
6269 unsigned numTrailingObjects(
6270 OverloadToken<FoldingSetPlaceholder<UnresolvedUsingType>>) const {
6271 assert(UnresolvedUsingBits.hasQualifier ||
6273 return 1;
6274 }
6275
6276 FoldingSetPlaceholder<UnresolvedUsingType> *getFoldingSetPlaceholder() {
6277 assert(numTrailingObjects(
6279 1);
6280 return getTrailingObjects<FoldingSetPlaceholder<UnresolvedUsingType>>();
6281 }
6282
6283 UnresolvedUsingType(ElaboratedTypeKeyword Keyword,
6284 NestedNameSpecifier Qualifier,
6285 const UnresolvedUsingTypenameDecl *D,
6286 const Type *CanonicalType);
6287
6288public:
6290 return UnresolvedUsingBits.hasQualifier
6291 ? *getTrailingObjects<NestedNameSpecifier>()
6292 : std::nullopt;
6293 }
6294
6295 UnresolvedUsingTypenameDecl *getDecl() const { return Decl; }
6296
6297 bool isSugared() const { return false; }
6298 QualType desugar() const { return QualType(this, 0); }
6299
6300 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6301 NestedNameSpecifier Qualifier,
6302 const UnresolvedUsingTypenameDecl *D) {
6303 static_assert(llvm::to_underlying(ElaboratedTypeKeyword::None) <= 7);
6304 ID.AddInteger(uintptr_t(D) | llvm::to_underlying(Keyword));
6305 if (Qualifier)
6306 Qualifier.Profile(ID);
6307 }
6308
6309 void Profile(llvm::FoldingSetNodeID &ID) const {
6311 }
6312
6313 static bool classof(const Type *T) {
6314 return T->getTypeClass() == UnresolvedUsing;
6315 }
6316};
6317
6318class UsingType final : public TypeWithKeyword,
6319 public llvm::FoldingSetNode,
6320 llvm::TrailingObjects<UsingType, NestedNameSpecifier> {
6321 UsingShadowDecl *D;
6322 QualType UnderlyingType;
6323
6324 friend class ASTContext; // ASTContext creates these.
6325 friend TrailingObjects;
6326
6328 const UsingShadowDecl *D, QualType UnderlyingType);
6329
6330public:
6332 return UsingBits.hasQualifier ? *getTrailingObjects() : std::nullopt;
6333 }
6334
6335 UsingShadowDecl *getDecl() const { return D; }
6336
6337 QualType desugar() const { return UnderlyingType; }
6338 bool isSugared() const { return true; }
6339
6340 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6341 NestedNameSpecifier Qualifier, const UsingShadowDecl *D,
6342 QualType UnderlyingType) {
6343 static_assert(llvm::to_underlying(ElaboratedTypeKeyword::None) <= 7);
6344 ID.AddInteger(uintptr_t(D) | llvm::to_underlying(Keyword));
6345 UnderlyingType.Profile(ID);
6346 if (Qualifier)
6347 Qualifier.Profile(ID);
6348 }
6349
6350 void Profile(llvm::FoldingSetNodeID &ID) const {
6351 Profile(ID, getKeyword(), getQualifier(), D, desugar());
6352 }
6353 static bool classof(const Type *T) { return T->getTypeClass() == Using; }
6354};
6355
6356class TypedefType final
6357 : public TypeWithKeyword,
6358 private llvm::TrailingObjects<TypedefType,
6359 FoldingSetPlaceholder<TypedefType>,
6360 NestedNameSpecifier, QualType> {
6361 TypedefNameDecl *Decl;
6362 friend class ASTContext; // ASTContext creates these.
6363 friend TrailingObjects;
6364
6365 unsigned
6366 numTrailingObjects(OverloadToken<FoldingSetPlaceholder<TypedefType>>) const {
6367 assert(TypedefBits.hasQualifier || TypedefBits.hasTypeDifferentFromDecl ||
6369 return 1;
6370 }
6371
6372 unsigned numTrailingObjects(OverloadToken<NestedNameSpecifier>) const {
6373 return TypedefBits.hasQualifier;
6374 }
6375
6376 TypedefType(TypeClass TC, ElaboratedTypeKeyword Keyword,
6377 NestedNameSpecifier Qualifier, const TypedefNameDecl *D,
6378 QualType UnderlyingType, bool HasTypeDifferentFromDecl);
6379
6380 FoldingSetPlaceholder<TypedefType> *getFoldingSetPlaceholder() {
6381 assert(numTrailingObjects(
6382 OverloadToken<FoldingSetPlaceholder<TypedefType>>{}) == 1);
6383 return getTrailingObjects<FoldingSetPlaceholder<TypedefType>>();
6384 }
6385
6386public:
6388 return TypedefBits.hasQualifier ? *getTrailingObjects<NestedNameSpecifier>()
6389 : std::nullopt;
6390 }
6391
6392 TypedefNameDecl *getDecl() const { return Decl; }
6393
6394 bool isSugared() const { return true; }
6395
6396 // This always has the 'same' type as declared, but not necessarily identical.
6397 QualType desugar() const;
6398
6399 // Internal helper, for debugging purposes.
6400 bool typeMatchesDecl() const { return !TypedefBits.hasTypeDifferentFromDecl; }
6401
6402 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6403 NestedNameSpecifier Qualifier,
6404 const TypedefNameDecl *Decl, QualType Underlying) {
6405
6406 ID.AddInteger(uintptr_t(Decl) | (Keyword != ElaboratedTypeKeyword::None) |
6407 (!Qualifier << 1));
6409 ID.AddInteger(llvm::to_underlying(Keyword));
6410 if (Qualifier)
6411 Qualifier.Profile(ID);
6412 if (!Underlying.isNull())
6413 Underlying.Profile(ID);
6414 }
6415
6416 void Profile(llvm::FoldingSetNodeID &ID) const {
6418 typeMatchesDecl() ? QualType() : desugar());
6419 }
6420
6421 static bool classof(const Type *T) { return T->getTypeClass() == Typedef; }
6422};
6423
6424/// Sugar type that represents a type that was qualified by a qualifier written
6425/// as a macro invocation.
6426class MacroQualifiedType : public Type {
6427 friend class ASTContext; // ASTContext creates these.
6428
6429 QualType UnderlyingTy;
6430 const IdentifierInfo *MacroII;
6431
6432 MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy,
6433 const IdentifierInfo *MacroII)
6434 : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
6435 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
6436 assert(isa<AttributedType>(UnderlyingTy) &&
6437 "Expected a macro qualified type to only wrap attributed types.");
6438 }
6439
6440public:
6441 const IdentifierInfo *getMacroIdentifier() const { return MacroII; }
6442 QualType getUnderlyingType() const { return UnderlyingTy; }
6443
6444 /// Return this attributed type's modified type with no qualifiers attached to
6445 /// it.
6446 QualType getModifiedType() const;
6447
6448 bool isSugared() const { return true; }
6449 QualType desugar() const;
6450
6451 static bool classof(const Type *T) {
6452 return T->getTypeClass() == MacroQualified;
6453 }
6454};
6455
6456/// Represents a `typeof` (or __typeof__) expression (a C23 feature and GCC
6457/// extension) or a `typeof_unqual` expression (a C23 feature).
6458class TypeOfExprType : public Type {
6459 Expr *TOExpr;
6460 const ASTContext &Context;
6461
6462protected:
6463 friend class ASTContext; // ASTContext creates these.
6464
6465 TypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind,
6466 QualType Can = QualType());
6467
6468public:
6469 Expr *getUnderlyingExpr() const { return TOExpr; }
6470
6471 /// Returns the kind of 'typeof' type this is.
6473 return static_cast<TypeOfKind>(TypeOfBits.Kind);
6474 }
6475
6476 /// Remove a single level of sugar.
6477 QualType desugar() const;
6478
6479 /// Returns whether this type directly provides sugar.
6480 bool isSugared() const;
6481
6482 static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; }
6483};
6484
6485/// Internal representation of canonical, dependent
6486/// `typeof(expr)` types.
6487///
6488/// This class is used internally by the ASTContext to manage
6489/// canonical, dependent types, only. Clients will only see instances
6490/// of this class via TypeOfExprType nodes.
6492 public llvm::FoldingSetNode {
6493public:
6495 : TypeOfExprType(Context, E, Kind) {}
6496
6497 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6498 Profile(ID, Context, getUnderlyingExpr(),
6500 }
6501
6502 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6503 Expr *E, bool IsUnqual);
6504};
6505
6506/// Represents `typeof(type)`, a C23 feature and GCC extension, or
6507/// `typeof_unqual(type), a C23 feature.
6508class TypeOfType : public Type {
6509 friend class ASTContext; // ASTContext creates these.
6510
6511 QualType TOType;
6512 const ASTContext &Context;
6513
6514 TypeOfType(const ASTContext &Context, QualType T, QualType Can,
6515 TypeOfKind Kind);
6516
6517public:
6518 QualType getUnmodifiedType() const { return TOType; }
6519
6520 /// Remove a single level of sugar.
6521 QualType desugar() const;
6522
6523 /// Returns whether this type directly provides sugar.
6524 bool isSugared() const { return true; }
6525
6526 /// Returns the kind of 'typeof' type this is.
6527 TypeOfKind getKind() const {
6528 return static_cast<TypeOfKind>(TypeOfBits.Kind);
6529 }
6530
6531 static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; }
6532};
6533
6534/// Represents the type `decltype(expr)` (C++11).
6535class DecltypeType : public Type {
6536 Expr *E;
6537 QualType UnderlyingType;
6538
6539protected:
6540 friend class ASTContext; // ASTContext creates these.
6541
6542 DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType());
6543
6544public:
6545 Expr *getUnderlyingExpr() const { return E; }
6546 QualType getUnderlyingType() const { return UnderlyingType; }
6547
6548 /// Remove a single level of sugar.
6549 QualType desugar() const;
6550
6551 /// Returns whether this type directly provides sugar.
6552 bool isSugared() const;
6553
6554 static bool classof(const Type *T) { return T->getTypeClass() == Decltype; }
6555};
6556
6557/// Internal representation of canonical, dependent
6558/// decltype(expr) types.
6559///
6560/// This class is used internally by the ASTContext to manage
6561/// canonical, dependent types, only. Clients will only see instances
6562/// of this class via DecltypeType nodes.
6563class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode {
6564public:
6565 DependentDecltypeType(Expr *E);
6566
6567 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
6568 Profile(ID, Context, getUnderlyingExpr());
6569 }
6570
6571 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6572 Expr *E);
6573};
6574
6575class PackIndexingType final
6576 : public Type,
6577 public llvm::FoldingSetNode,
6578 private llvm::TrailingObjects<PackIndexingType, QualType> {
6579 friend TrailingObjects;
6580
6581 QualType Pattern;
6582 Expr *IndexExpr;
6583
6584 unsigned Size : 31;
6585
6586 LLVM_PREFERRED_TYPE(bool)
6587 unsigned FullySubstituted : 1;
6588
6589protected:
6590 friend class ASTContext; // ASTContext creates these.
6591 PackIndexingType(QualType Canonical, QualType Pattern, Expr *IndexExpr,
6592 bool FullySubstituted, ArrayRef<QualType> Expansions = {});
6593
6594public:
6595 Expr *getIndexExpr() const { return IndexExpr; }
6596 QualType getPattern() const { return Pattern; }
6597
6598 bool isSugared() const { return hasSelectedType(); }
6599
6600 QualType desugar() const {
6601 if (hasSelectedType())
6602 return getSelectedType();
6603 return QualType(this, 0);
6604 }
6605
6606 QualType getSelectedType() const {
6607 assert(hasSelectedType() && "Type is dependant");
6608 return *(getExpansionsPtr() + *getSelectedIndex());
6609 }
6610
6611 UnsignedOrNone getSelectedIndex() const;
6612
6613 bool hasSelectedType() const { return getSelectedIndex() != std::nullopt; }
6614
6615 bool isFullySubstituted() const { return FullySubstituted; }
6616
6617 bool expandsToEmptyPack() const { return isFullySubstituted() && Size == 0; }
6618
6619 ArrayRef<QualType> getExpansions() const {
6620 return {getExpansionsPtr(), Size};
6621 }
6622
6623 static bool classof(const Type *T) {
6624 return T->getTypeClass() == PackIndexing;
6625 }
6626
6627 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
6628 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
6629 QualType Pattern, Expr *E, bool FullySubstituted,
6630 ArrayRef<QualType> Expansions);
6631
6632private:
6633 const QualType *getExpansionsPtr() const { return getTrailingObjects(); }
6634
6635 static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
6636 ArrayRef<QualType> Expansions = {});
6637};
6638
6639/// A unary type transform, which is a type constructed from another.
6640class UnaryTransformType : public Type, public llvm::FoldingSetNode {
6641public:
6642 enum UTTKind {
6643#define TRANSFORM_TYPE_TRAIT_DEF(Enum, _) Enum,
6644#include "clang/Basic/BuiltinTraits.inc"
6645 };
6646
6647private:
6648 /// The untransformed type.
6649 QualType BaseType;
6650
6651 /// The transformed type if not dependent, otherwise the same as BaseType.
6652 QualType UnderlyingType;
6653
6654 UTTKind UKind;
6655
6656protected:
6657 friend class ASTContext;
6658
6659 UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind,
6660 QualType CanonicalTy);
6661
6662public:
6663 bool isSugared() const { return !isDependentType(); }
6664 QualType desugar() const { return UnderlyingType; }
6665
6666 QualType getUnderlyingType() const { return UnderlyingType; }
6667 QualType getBaseType() const { return BaseType; }
6668
6669 UTTKind getUTTKind() const { return UKind; }
6670
6671 static bool classof(const Type *T) {
6672 return T->getTypeClass() == UnaryTransform;
6673 }
6674
6675 std::tuple<QualType, QualType, UTTKind> getKey() const {
6676 return {getBaseType(), getUnderlyingType(), getUTTKind()};
6677 }
6678};
6679
6680class TagType : public TypeWithKeyword {
6681 friend class ASTContext; // ASTContext creates these.
6682
6683 /// Stores the TagDecl associated with this type. The decl may point to any
6684 /// TagDecl that declares the entity.
6685 TagDecl *decl;
6686
6687 void *getTrailingPointer() const;
6688 NestedNameSpecifier &getTrailingQualifier() const;
6689
6690protected:
6691 TagType(TypeClass TC, ElaboratedTypeKeyword Keyword,
6692 NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag,
6693 bool IsInjected, const Type *CanonicalType);
6694
6695public:
6696 TagDecl *getDecl() const { return decl; }
6697 [[deprecated("Use getDecl instead")]] TagDecl *getOriginalDecl() const {
6698 return decl;
6699 }
6700
6701 NestedNameSpecifier getQualifier() const;
6702
6703 /// Does the TagType own this declaration of the Tag?
6704 bool isTagOwned() const { return TagTypeBits.OwnsTag; }
6705
6706 bool isInjected() const { return TagTypeBits.IsInjected; }
6707
6708 ClassTemplateDecl *getTemplateDecl() const;
6709 TemplateName getTemplateName(const ASTContext &Ctx) const;
6710 ArrayRef<TemplateArgument> getTemplateArgs(const ASTContext &Ctx) const;
6711
6712 bool isSugared() const { return false; }
6713 QualType desugar() const { return getCanonicalTypeInternal(); }
6714
6715 static bool classof(const Type *T) {
6716 return T->getTypeClass() == Enum || T->getTypeClass() == Record ||
6717 T->getTypeClass() == InjectedClassName;
6718 }
6719};
6720
6721struct TagTypeFoldingSetPlaceholder : public llvm::FoldingSetNode {
6722 static constexpr size_t getOffset() {
6723 return alignof(TagType) -
6724 (sizeof(TagTypeFoldingSetPlaceholder) % alignof(TagType));
6725 }
6726
6727 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
6728 NestedNameSpecifier Qualifier, const TagDecl *Tag,
6729 bool OwnsTag, bool IsInjected) {
6730 ID.AddInteger(uintptr_t(Tag) | OwnsTag | (IsInjected << 1) |
6731 ((Keyword != ElaboratedTypeKeyword::None) << 2));
6732 if (Keyword != ElaboratedTypeKeyword::None)
6733 ID.AddInteger(llvm::to_underlying(Keyword));
6734 if (Qualifier)
6735 Qualifier.Profile(ID);
6736 }
6737
6738 void Profile(llvm::FoldingSetNodeID &ID) const {
6739 const TagType *T = getTagType();
6740 Profile(ID, T->getKeyword(), T->getQualifier(), T->getDecl(),
6741 T->isTagOwned(), T->isInjected());
6742 }
6743
6744 TagType *getTagType() {
6745 return reinterpret_cast<TagType *>(reinterpret_cast<char *>(this + 1) +
6746 getOffset());
6747 }
6748 const TagType *getTagType() const {
6749 return const_cast<TagTypeFoldingSetPlaceholder *>(this)->getTagType();
6750 }
6751 static TagTypeFoldingSetPlaceholder *fromTagType(TagType *T) {
6752 return reinterpret_cast<TagTypeFoldingSetPlaceholder *>(
6753 reinterpret_cast<char *>(T) - getOffset()) -
6754 1;
6755 }
6756};
6757
6758/// A helper class that allows the use of isa/cast/dyncast
6759/// to detect TagType objects of structs/unions/classes.
6760class RecordType final : public TagType {
6761 using TagType::TagType;
6762
6763public:
6764 RecordDecl *getDecl() const {
6765 return reinterpret_cast<RecordDecl *>(TagType::getDecl());
6766 }
6767 [[deprecated("Use getDecl instead")]] RecordDecl *getOriginalDecl() const {
6768 return getDecl();
6769 }
6770
6771 /// Recursively check all fields in the record for const-ness. If any field
6772 /// is declared const, return true. Otherwise, return false.
6773 bool hasConstFields() const;
6774
6775 static bool classof(const Type *T) { return T->getTypeClass() == Record; }
6776};
6777
6778/// A helper class that allows the use of isa/cast/dyncast
6779/// to detect TagType objects of enums.
6780class EnumType final : public TagType {
6781 using TagType::TagType;
6782
6783public:
6784 EnumDecl *getDecl() const {
6785 return reinterpret_cast<EnumDecl *>(TagType::getDecl());
6786 }
6787 [[deprecated("Use getDecl instead")]] EnumDecl *getOriginalDecl() const {
6788 return getDecl();
6789 }
6790
6791 static bool classof(const Type *T) { return T->getTypeClass() == Enum; }
6792};
6793
6794/// The injected class name of a C++ class template or class
6795/// template partial specialization. Used to record that a type was
6796/// spelled with a bare identifier rather than as a template-id; the
6797/// equivalent for non-templated classes is just RecordType.
6798///
6799/// Injected class name types are always dependent. Template
6800/// instantiation turns these into RecordTypes.
6801///
6802/// Injected class name types are always canonical. This works
6803/// because it is impossible to compare an injected class name type
6804/// with the corresponding non-injected template type, for the same
6805/// reason that it is impossible to directly compare template
6806/// parameters from different dependent contexts: injected class name
6807/// types can only occur within the scope of a particular templated
6808/// declaration, and within that scope every template specialization
6809/// will canonicalize to the injected class name (when appropriate
6810/// according to the rules of the language).
6811class InjectedClassNameType final : public TagType {
6812 friend class ASTContext; // ASTContext creates these.
6813
6814 InjectedClassNameType(ElaboratedTypeKeyword Keyword,
6815 NestedNameSpecifier Qualifier, const TagDecl *TD,
6816 bool IsInjected, const Type *CanonicalType);
6817
6818public:
6819 CXXRecordDecl *getDecl() const {
6820 return reinterpret_cast<CXXRecordDecl *>(TagType::getDecl());
6821 }
6822 [[deprecated("Use getDecl instead")]] CXXRecordDecl *getOriginalDecl() const {
6823 return getDecl();
6824 }
6825
6826 static bool classof(const Type *T) {
6827 return T->getTypeClass() == InjectedClassName;
6828 }
6829};
6830
6831/// An attributed type is a type to which a type attribute has been applied.
6832///
6833/// The "modified type" is the fully-sugared type to which the attributed
6834/// type was applied; generally it is not canonically equivalent to the
6835/// attributed type. The "equivalent type" is the minimally-desugared type
6836/// which the type is canonically equivalent to.
6837///
6838/// For example, in the following attributed type:
6839/// int32_t __attribute__((vector_size(16)))
6840/// - the modified type is the TypedefType for int32_t
6841/// - the equivalent type is VectorType(16, int32_t)
6842/// - the canonical type is VectorType(16, int)
6843class AttributedType : public Type, public llvm::FoldingSetNode {
6844public:
6845 using Kind = attr::Kind;
6846
6847private:
6848 friend class ASTContext; // ASTContext creates these
6849
6850 const Attr *Attribute;
6851
6852 QualType ModifiedType;
6853 QualType EquivalentType;
6854
6855 AttributedType(QualType canon, attr::Kind attrKind, QualType modified,
6856 QualType equivalent)
6857 : AttributedType(canon, attrKind, nullptr, modified, equivalent) {}
6858
6859 AttributedType(QualType canon, const Attr *attr, QualType modified,
6860 QualType equivalent);
6861
6862private:
6863 AttributedType(QualType canon, attr::Kind attrKind, const Attr *attr,
6864 QualType modified, QualType equivalent);
6865
6866public:
6867 Kind getAttrKind() const {
6868 return static_cast<Kind>(AttributedTypeBits.AttrKind);
6869 }
6870
6871 const Attr *getAttr() const { return Attribute; }
6872
6873 QualType getModifiedType() const { return ModifiedType; }
6874 QualType getEquivalentType() const { return EquivalentType; }
6875
6876 bool isSugared() const { return true; }
6877 QualType desugar() const { return getEquivalentType(); }
6878
6879 /// Does this attribute behave like a type qualifier?
6880 ///
6881 /// A type qualifier adjusts a type to provide specialized rules for
6882 /// a specific object, like the standard const and volatile qualifiers.
6883 /// This includes attributes controlling things like nullability,
6884 /// address spaces, and ARC ownership. The value of the object is still
6885 /// largely described by the modified type.
6886 ///
6887 /// In contrast, many type attributes "rewrite" their modified type to
6888 /// produce a fundamentally different type, not necessarily related in any
6889 /// formalizable way to the original type. For example, calling convention
6890 /// and vector attributes are not simple type qualifiers.
6891 ///
6892 /// Type qualifiers are often, but not always, reflected in the canonical
6893 /// type.
6894 bool isQualifier() const;
6895
6896 bool isMSTypeSpec() const;
6897
6898 bool isWebAssemblyFuncrefSpec() const;
6899
6900 bool isCallingConv() const;
6901
6902 NullabilityKindOrNone getImmediateNullability() const;
6903
6904 /// Strip off the top-level nullability annotation on the given
6905 /// type, if it's there.
6906 ///
6907 /// \param T The type to strip. If the type is exactly an
6908 /// AttributedType specifying nullability (without looking through
6909 /// type sugar), the nullability is returned and this type changed
6910 /// to the underlying modified type.
6911 ///
6912 /// \returns the top-level nullability, if present.
6913 static NullabilityKindOrNone stripOuterNullability(QualType &T);
6914
6915 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
6916 Profile(ID, Ctx, getAttrKind(), ModifiedType, EquivalentType, Attribute);
6917 }
6918
6919 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
6920 Kind attrKind, QualType modified, QualType equivalent,
6921 const Attr *attr);
6922
6923 static bool classof(const Type *T) {
6924 return T->getTypeClass() == Attributed;
6925 }
6926};
6927
6928class BTFTagAttributedType : public Type, public llvm::FoldingSetNode {
6929private:
6930 friend class ASTContext; // ASTContext creates these
6931
6932 QualType WrappedType;
6933 const BTFTypeTagAttr *BTFAttr;
6934
6935 BTFTagAttributedType(QualType Canon, QualType Wrapped,
6936 const BTFTypeTagAttr *BTFAttr)
6937 : Type(BTFTagAttributed, Canon, Wrapped->getDependence()),
6938 WrappedType(Wrapped), BTFAttr(BTFAttr) {}
6939
6940public:
6941 QualType getWrappedType() const { return WrappedType; }
6942 const BTFTypeTagAttr *getAttr() const { return BTFAttr; }
6943
6944 bool isSugared() const { return true; }
6945 QualType desugar() const { return getWrappedType(); }
6946
6947 void Profile(llvm::FoldingSetNodeID &ID) {
6948 Profile(ID, WrappedType, BTFAttr);
6949 }
6950
6951 static void Profile(llvm::FoldingSetNodeID &ID, QualType Wrapped,
6952 const BTFTypeTagAttr *BTFAttr) {
6953 ID.AddPointer(Wrapped.getAsOpaquePtr());
6954 ID.AddPointer(BTFAttr);
6955 }
6956
6957 static bool classof(const Type *T) {
6958 return T->getTypeClass() == BTFTagAttributed;
6959 }
6960};
6961
6962class OverflowBehaviorType : public Type, public llvm::FoldingSetNode {
6963public:
6964 enum OverflowBehaviorKind { Wrap, Trap };
6965
6966private:
6967 friend class ASTContext; // ASTContext creates these
6968
6969 QualType UnderlyingType;
6970 OverflowBehaviorKind BehaviorKind;
6971 const ASTContext &Context;
6972
6973 OverflowBehaviorType(const ASTContext &Context, QualType Canon,
6974 QualType Underlying, OverflowBehaviorKind Kind);
6975
6976public:
6977 QualType getUnderlyingType() const { return UnderlyingType; }
6978 OverflowBehaviorKind getBehaviorKind() const { return BehaviorKind; }
6979
6980 bool isWrapKind() const { return BehaviorKind == OverflowBehaviorKind::Wrap; }
6981 bool isTrapKind() const { return BehaviorKind == OverflowBehaviorKind::Trap; }
6982
6983 bool isSugared() const { return false; }
6984 QualType desugar() const { return getUnderlyingType(); }
6985
6986 SplitQualType getSplitUnqualifiedType() const;
6987
6988 std::pair<QualType, OverflowBehaviorKind> getKey() const {
6989 return {UnderlyingType, BehaviorKind};
6990 }
6991
6992 static bool classof(const Type *T) {
6993 return T->getTypeClass() == OverflowBehavior;
6994 }
6995};
6996
6997class HLSLAttributedResourceType : public Type, public llvm::FoldingSetNode {
6998public:
6999 struct Attributes {
7000 // Data gathered from HLSL resource attributes
7001 llvm::dxil::ResourceClass ResourceClass;
7002 llvm::dxil::ResourceDimension ResourceDimension;
7003
7004 LLVM_PREFERRED_TYPE(bool)
7005 uint8_t IsROV : 1;
7006
7007 LLVM_PREFERRED_TYPE(bool)
7008 uint8_t RawBuffer : 1;
7009
7010 LLVM_PREFERRED_TYPE(bool)
7011 uint8_t IsCounter : 1;
7012
7013 LLVM_PREFERRED_TYPE(bool)
7014 uint8_t IsArray : 1;
7015
7016 /// The N in Texture2DMS<T, N>; null for every resource that is not
7017 /// multisampled. A multisampled resource always carries a sample count,
7018 /// defaulting to 0, which means the count comes from the bound resource
7019 /// at runtime rather than denoting zero samples.
7020 Expr *SampleCountExpr;
7021
7022 Attributes(llvm::dxil::ResourceClass ResourceClass,
7023 llvm::dxil::ResourceDimension ResourceDimension,
7024 bool IsROV = false, bool RawBuffer = false,
7025 bool IsCounter = false, bool IsArray = false,
7026 Expr *SampleCountExpr = nullptr)
7027 : ResourceClass(ResourceClass), ResourceDimension(ResourceDimension),
7028 IsROV(IsROV), RawBuffer(RawBuffer), IsCounter(IsCounter),
7029 IsArray(IsArray), SampleCountExpr(SampleCountExpr) {}
7030
7031 Attributes(llvm::dxil::ResourceClass ResourceClass)
7032 : Attributes(ResourceClass, llvm::dxil::ResourceDimension::Unknown) {}
7033
7034 Attributes()
7035 : Attributes(llvm::dxil::ResourceClass::UAV,
7036 llvm::dxil::ResourceDimension::Unknown) {}
7037
7038 bool isMultiSampled() const { return SampleCountExpr != nullptr; }
7039
7040 friend bool operator==(const Attributes &LHS, const Attributes &RHS) {
7041 return std::tie(LHS.ResourceClass, LHS.ResourceDimension, LHS.IsROV,
7042 LHS.RawBuffer, LHS.IsCounter, LHS.IsArray,
7043 LHS.SampleCountExpr) ==
7044 std::tie(RHS.ResourceClass, RHS.ResourceDimension, RHS.IsROV,
7045 RHS.RawBuffer, RHS.IsCounter, RHS.IsArray,
7046 RHS.SampleCountExpr);
7047 }
7048 friend bool operator!=(const Attributes &LHS, const Attributes &RHS) {
7049 return !(LHS == RHS);
7050 }
7051 };
7052
7053private:
7054 friend class ASTContext; // ASTContext creates these
7055
7056 QualType WrappedType;
7057 QualType ContainedType;
7058 const Attributes Attrs;
7059
7060 HLSLAttributedResourceType(QualType Wrapped, QualType Contained,
7061 const Attributes &Attrs);
7062
7063 /// WrappedType is always __hlsl_resource_t, so it never contributes.
7064 static TypeDependence computeDependence(QualType Contained,
7065 const Attributes &Attrs);
7066
7067public:
7068 QualType getWrappedType() const { return WrappedType; }
7069 QualType getContainedType() const { return ContainedType; }
7070 bool hasContainedType() const { return !ContainedType.isNull(); }
7071 Expr *getSampleCountExpr() const { return Attrs.SampleCountExpr; }
7072 bool isMultiSampled() const { return Attrs.isMultiSampled(); }
7073 const Attributes &getAttrs() const { return Attrs; }
7074 bool isRaw() const { return Attrs.RawBuffer; }
7075 bool isStructured() const { return !ContainedType->isChar8Type(); }
7076
7077 bool isSugared() const { return false; }
7078 QualType desugar() const { return QualType(this, 0); }
7079
7080 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) {
7081 Profile(ID, Ctx, WrappedType, ContainedType, Attrs);
7082 }
7083
7084 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx,
7085 QualType Wrapped, QualType Contained,
7086 const Attributes &Attrs);
7087
7088 static bool classof(const Type *T) {
7089 return T->getTypeClass() == HLSLAttributedResource;
7090 }
7091
7092 // Returns handle type from HLSL resource, if the type is a resource
7093 static const HLSLAttributedResourceType *
7094 findHandleTypeOnResource(const Type *RT);
7095};
7096
7097/// Instances of this class represent operands to a SPIR-V type instruction.
7098class SpirvOperand {
7099public:
7100 enum SpirvOperandKind : unsigned char {
7101 Invalid, ///< Uninitialized.
7102 ConstantId, ///< Integral value to represent as a SPIR-V OpConstant
7103 ///< instruction ID.
7104 Literal, ///< Integral value to represent as an immediate literal.
7105 TypeId, ///< Type to represent as a SPIR-V type ID.
7106
7107 Max,
7108 };
7109
7110private:
7111 SpirvOperandKind Kind = Invalid;
7112
7113 QualType ResultType;
7114 llvm::APInt Value; // Signedness of constants is represented by ResultType.
7115
7116public:
7117 SpirvOperand() : Kind(Invalid), ResultType(), Value() {}
7118
7119 SpirvOperand(SpirvOperandKind Kind, QualType ResultType, llvm::APInt Value)
7120 : Kind(Kind), ResultType(ResultType), Value(std::move(Value)) {}
7121
7122 SpirvOperand(const SpirvOperand &Other) = default;
7123 ~SpirvOperand() = default;
7124 SpirvOperand &operator=(const SpirvOperand &Other) = default;
7125
7126 bool operator==(const SpirvOperand &Other) const {
7127 return Kind == Other.Kind && ResultType == Other.ResultType &&
7128 Value == Other.Value;
7129 }
7130
7131 bool operator!=(const SpirvOperand &Other) const { return !(*this == Other); }
7132
7133 SpirvOperandKind getKind() const { return Kind; }
7134
7135 bool isValid() const { return Kind != Invalid && Kind < Max; }
7136 bool isConstant() const { return Kind == ConstantId; }
7137 bool isLiteral() const { return Kind == Literal; }
7138 bool isType() const { return Kind == TypeId; }
7139
7140 llvm::APInt getValue() const {
7141 assert((isConstant() || isLiteral()) &&
7142 "This is not an operand with a value!");
7143 return Value;
7144 }
7145
7146 QualType getResultType() const {
7147 assert((isConstant() || isType()) &&
7148 "This is not an operand with a result type!");
7149 return ResultType;
7150 }
7151
7152 static SpirvOperand createConstant(QualType ResultType, llvm::APInt Val) {
7153 return SpirvOperand(ConstantId, ResultType, std::move(Val));
7154 }
7155
7156 static SpirvOperand createLiteral(llvm::APInt Val) {
7157 return SpirvOperand(Literal, QualType(), std::move(Val));
7158 }
7159
7160 static SpirvOperand createType(QualType T) {
7161 return SpirvOperand(TypeId, T, llvm::APSInt());
7162 }
7163
7164 void Profile(llvm::FoldingSetNodeID &ID) const {
7165 ID.AddInteger(Kind);
7166 ID.AddPointer(ResultType.getAsOpaquePtr());
7167 Value.Profile(ID);
7168 }
7169};
7170
7171/// Represents an arbitrary, user-specified SPIR-V type instruction.
7172class HLSLInlineSpirvType final
7173 : public Type,
7174 public llvm::FoldingSetNode,
7175 private llvm::TrailingObjects<HLSLInlineSpirvType, SpirvOperand> {
7176 friend class ASTContext; // ASTContext creates these
7177 friend TrailingObjects;
7178
7179private:
7181 uint32_t Size;
7182 uint32_t Alignment;
7183 size_t NumOperands;
7184
7185 HLSLInlineSpirvType(uint32_t Opcode, uint32_t Size, uint32_t Alignment,
7186 ArrayRef<SpirvOperand> Operands)
7187 : Type(HLSLInlineSpirv, QualType(), TypeDependence::None), Opcode(Opcode),
7188 Size(Size), Alignment(Alignment), NumOperands(Operands.size()) {
7189 for (size_t I = 0; I < NumOperands; I++) {
7190 // Since Operands are stored as a trailing object, they have not been
7191 // initialized yet. Call the constructor manually.
7192 auto *Operand = new (&getTrailingObjects()[I]) SpirvOperand();
7193 *Operand = Operands[I];
7194 }
7195 }
7196
7197public:
7198 uint32_t getOpcode() const { return Opcode; }
7199 uint32_t getSize() const { return Size; }
7200 uint32_t getAlignment() const { return Alignment; }
7201 ArrayRef<SpirvOperand> getOperands() const {
7202 return getTrailingObjects(NumOperands);
7203 }
7204
7205 bool isSugared() const { return false; }
7206 QualType desugar() const { return QualType(this, 0); }
7207
7208 void Profile(llvm::FoldingSetNodeID &ID) {
7209 Profile(ID, Opcode, Size, Alignment, getOperands());
7210 }
7211
7212 static void Profile(llvm::FoldingSetNodeID &ID, uint32_t Opcode,
7213 uint32_t Size, uint32_t Alignment,
7214 ArrayRef<SpirvOperand> Operands) {
7215 ID.AddInteger(Opcode);
7216 ID.AddInteger(Size);
7217 ID.AddInteger(Alignment);
7218 for (auto &Operand : Operands)
7219 Operand.Profile(ID);
7220 }
7221
7222 static bool classof(const Type *T) {
7223 return T->getTypeClass() == HLSLInlineSpirv;
7224 }
7225};
7226
7227class TemplateTypeParmType : public Type, public llvm::FoldingSetNode {
7228 friend class ASTContext; // ASTContext creates these
7229
7230 // The associated TemplateTypeParmDecl for the non-canonical type.
7231 TemplateTypeParmDecl *TTPDecl;
7232
7233 TemplateTypeParmType(unsigned D, unsigned I, bool PP,
7234 TemplateTypeParmDecl *TTPDecl, QualType Canon)
7235 : Type(TemplateTypeParm, Canon,
7236 TypeDependence::DependentInstantiation |
7237 (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)),
7238 TTPDecl(TTPDecl) {
7239 assert(!TTPDecl == Canon.isNull());
7240 assert(D < (1 << TemplateTypeParmTypeDepthBits) && "Depth too large");
7241 assert(I < (1 << TemplateTypeParmTypeIndexBits) && "Index too large");
7242 TemplateTypeParmTypeBits.Depth = D;
7243 TemplateTypeParmTypeBits.Index = I;
7244 TemplateTypeParmTypeBits.ParameterPack = PP;
7245 }
7246
7247public:
7248 unsigned getDepth() const { return TemplateTypeParmTypeBits.Depth; }
7249 unsigned getIndex() const { return TemplateTypeParmTypeBits.Index; }
7250 bool isParameterPack() const {
7251 return TemplateTypeParmTypeBits.ParameterPack;
7252 }
7253
7254 TemplateTypeParmDecl *getDecl() const { return TTPDecl; }
7255
7256 IdentifierInfo *getIdentifier() const;
7257
7258 bool isSugared() const { return false; }
7259 QualType desugar() const { return QualType(this, 0); }
7260
7261 std::tuple<unsigned, unsigned, unsigned, TemplateTypeParmDecl *>
7262 getKey() const {
7263 return {getDepth(), getIndex(), isParameterPack(), getDecl()};
7264 }
7265
7266 static bool classof(const Type *T) {
7267 return T->getTypeClass() == TemplateTypeParm;
7268 }
7269};
7270
7271/// Represents the result of substituting a type for a template
7272/// type parameter.
7273///
7274/// Within an instantiated template, all template type parameters have
7275/// been replaced with these. They are used solely to record that a
7276/// type was originally written as a template type parameter;
7277/// therefore they are never canonical.
7278class SubstTemplateTypeParmType final
7279 : public Type,
7280 public llvm::FoldingSetNode,
7281 private llvm::TrailingObjects<SubstTemplateTypeParmType, QualType> {
7282 friend class ASTContext;
7283 friend class llvm::TrailingObjects<SubstTemplateTypeParmType, QualType>;
7284
7285 Decl *AssociatedDecl;
7286
7287 SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
7288 unsigned Index, UnsignedOrNone PackIndex,
7289 bool Final);
7290
7291public:
7292 /// Gets the type that was substituted for the template
7293 /// parameter.
7294 QualType getReplacementType() const {
7295 return SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType
7296 ? *getTrailingObjects()
7297 : getCanonicalTypeInternal();
7298 }
7299
7300 /// A template-like entity which owns the whole pattern being substituted.
7301 /// This will usually own a set of template parameters, or in some
7302 /// cases might even be a template parameter itself.
7303 Decl *getAssociatedDecl() const { return AssociatedDecl; }
7304
7305 /// Gets the template parameter declaration that was substituted for.
7306 const TemplateTypeParmDecl *getReplacedParameter() const;
7307
7308 /// Returns the index of the replaced parameter in the associated declaration.
7309 /// This should match the result of `getReplacedParameter()->getIndex()`.
7310 unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
7311
7312 // This substitution is Final, which means the substitution is fully
7313 // sugared: it doesn't need to be resugared later.
7314 unsigned getFinal() const { return SubstTemplateTypeParmTypeBits.Final; }
7315
7316 UnsignedOrNone getPackIndex() const {
7317 return UnsignedOrNone::fromInternalRepresentation(
7318 SubstTemplateTypeParmTypeBits.PackIndex);
7319 }
7320
7321 bool isSugared() const { return true; }
7322 QualType desugar() const { return getReplacementType(); }
7323
7324 std::tuple<QualType, Decl *, unsigned, unsigned, unsigned> getKey() const {
7325 return {getReplacementType(), getAssociatedDecl(), getIndex(),
7326 SubstTemplateTypeParmTypeBits.PackIndex,
7327 SubstTemplateTypeParmTypeBits.Final};
7328 }
7329
7330 static bool classof(const Type *T) {
7331 return T->getTypeClass() == SubstTemplateTypeParm;
7332 }
7333};
7334
7335/// Represents the result of substituting a set of types as a template argument
7336/// that needs to be expanded later.
7337///
7338/// These types are always dependent and produced depending on the situations:
7339/// - SubstTemplateTypeParmPack is an expansion that had to be delayed,
7340/// - SubstBuiltinTemplatePackType is an expansion from a builtin.
7341class SubstPackType : public Type, public llvm::FoldingSetNode {
7342 friend class ASTContext;
7343
7344 /// A pointer to the set of template arguments that this
7345 /// parameter pack is instantiated with.
7346 const TemplateArgument *Arguments;
7347
7348protected:
7349 SubstPackType(TypeClass Derived, QualType Canon,
7350 const TemplateArgument &ArgPack);
7351
7352public:
7353 unsigned getNumArgs() const { return SubstPackTypeBits.NumArgs; }
7354
7355 TemplateArgument getArgumentPack() const;
7356
7357 void Profile(llvm::FoldingSetNodeID &ID);
7358 static void Profile(llvm::FoldingSetNodeID &ID,
7359 const TemplateArgument &ArgPack);
7360
7361 static bool classof(const Type *T) {
7362 return T->getTypeClass() == SubstTemplateTypeParmPack ||
7363 T->getTypeClass() == SubstBuiltinTemplatePack;
7364 }
7365};
7366
7367/// Represents the result of substituting a builtin template as a pack.
7368class SubstBuiltinTemplatePackType : public SubstPackType {
7369 friend class ASTContext;
7370
7371 SubstBuiltinTemplatePackType(QualType Canon, const TemplateArgument &ArgPack);
7372
7373public:
7374 bool isSugared() const { return false; }
7375 QualType desugar() const { return QualType(this, 0); }
7376
7377 /// Mark that we reuse the Profile. We do not introduce new fields.
7378 using SubstPackType::Profile;
7379
7380 static bool classof(const Type *T) {
7381 return T->getTypeClass() == SubstBuiltinTemplatePack;
7382 }
7383};
7384
7385/// Represents the result of substituting a set of types for a template
7386/// type parameter pack.
7387///
7388/// When a pack expansion in the source code contains multiple parameter packs
7389/// and those parameter packs correspond to different levels of template
7390/// parameter lists, this type node is used to represent a template type
7391/// parameter pack from an outer level, which has already had its argument pack
7392/// substituted but that still lives within a pack expansion that itself
7393/// could not be instantiated. When actually performing a substitution into
7394/// that pack expansion (e.g., when all template parameters have corresponding
7395/// arguments), this type will be replaced with the \c SubstTemplateTypeParmType
7396/// at the current pack substitution index.
7397class SubstTemplateTypeParmPackType : public SubstPackType {
7398 friend class ASTContext;
7399
7400 llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndFinal;
7401
7402 SubstTemplateTypeParmPackType(QualType Canon, Decl *AssociatedDecl,
7403 unsigned Index, bool Final,
7404 const TemplateArgument &ArgPack);
7405
7406public:
7407 IdentifierInfo *getIdentifier() const;
7408
7409 /// A template-like entity which owns the whole pattern being substituted.
7410 /// This will usually own a set of template parameters, or in some
7411 /// cases might even be a template parameter itself.
7412 Decl *getAssociatedDecl() const;
7413
7414 /// Gets the template parameter declaration that was substituted for.
7415 const TemplateTypeParmDecl *getReplacedParameter() const;
7416
7417 /// Returns the index of the replaced parameter in the associated declaration.
7418 /// This should match the result of `getReplacedParameter()->getIndex()`.
7419 unsigned getIndex() const {
7420 return SubstPackTypeBits.SubstTemplTypeParmPackIndex;
7421 }
7422
7423 // This substitution will be Final, which means the substitution will be fully
7424 // sugared: it doesn't need to be resugared later.
7425 bool getFinal() const;
7426
7427 bool isSugared() const { return false; }
7428 QualType desugar() const { return QualType(this, 0); }
7429
7430 void Profile(llvm::FoldingSetNodeID &ID);
7431 static void Profile(llvm::FoldingSetNodeID &ID, const Decl *AssociatedDecl,
7432 unsigned Index, bool Final,
7433 const TemplateArgument &ArgPack);
7434
7435 static bool classof(const Type *T) {
7436 return T->getTypeClass() == SubstTemplateTypeParmPack;
7437 }
7438};
7439
7440/// Common base class for placeholders for types that get replaced by
7441/// placeholder type deduction: C++11 auto, C++14 decltype(auto), C++17 deduced
7442/// class template types, and constrained type names.
7443///
7444/// These types are usually a placeholder for a deduced type. However, before
7445/// the initializer is attached, or (usually) if the initializer is
7446/// type-dependent, there is no deduced type and the type is canonical. In
7447/// the latter case, it is also a dependent type.
7448class DeducedType : public Type {
7449 QualType DeducedAsType;
7450
7451protected:
7452 DeducedType(TypeClass TC, DeducedKind DK, QualType DeducedAsTypeOrCanon);
7453
7454 static void Profile(llvm::FoldingSetNodeID &ID, DeducedKind DK,
7455 QualType Deduced) {
7456 ID.AddInteger(llvm::to_underlying(DK));
7457 Deduced.Profile(ID);
7458 }
7459
7460public:
7461 DeducedKind getDeducedKind() const {
7462 return static_cast<DeducedKind>(DeducedTypeBits.Kind);
7463 }
7464
7465 bool isSugared() const { return getDeducedKind() == DeducedKind::Deduced; }
7466 QualType desugar() const {
7467 return isSugared() ? DeducedAsType : QualType(this, 0);
7468 }
7469
7470 /// Get the type deduced for this placeholder type, or null if it
7471 /// has not been deduced.
7472 QualType getDeducedType() const { return DeducedAsType; }
7473 bool isDeduced() const { return getDeducedKind() != DeducedKind::Undeduced; }
7474
7475 static bool classof(const Type *T) {
7476 return T->getTypeClass() == Auto ||
7477 T->getTypeClass() == DeducedTemplateSpecialization;
7478 }
7479};
7480
7481/// Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained
7482/// by a type-constraint.
7483class AutoType : public DeducedType, public llvm::FoldingSetNode {
7484 friend class ASTContext; // ASTContext creates these
7485
7486 TemplateName TypeConstraintConcept;
7487
7488 AutoType(DeducedKind DK, QualType DeducedAsTypeOrCanon,
7489 AutoTypeKeyword Keyword, TemplateName TypeConstraintConcept,
7490 ArrayRef<TemplateArgument> TypeConstraintArgs);
7491
7492public:
7493 ArrayRef<TemplateArgument> getTypeConstraintArguments() const {
7494 return {reinterpret_cast<const TemplateArgument *>(this + 1),
7495 AutoTypeBits.NumArgs};
7496 }
7497
7498 TemplateName getTypeConstraintConcept() const {
7499 return TypeConstraintConcept;
7500 }
7501
7502 bool isConstrained() const { return !TypeConstraintConcept.isNull(); }
7503
7504 bool isDecltypeAuto() const {
7505 return getKeyword() == AutoTypeKeyword::DecltypeAuto;
7506 }
7507
7508 bool isGNUAutoType() const {
7509 return getKeyword() == AutoTypeKeyword::GNUAutoType;
7510 }
7511
7512 AutoTypeKeyword getKeyword() const {
7513 return (AutoTypeKeyword)AutoTypeBits.Keyword;
7514 }
7515
7516 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context);
7517 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
7518 DeducedKind DK, QualType Deduced, AutoTypeKeyword Keyword,
7519 TemplateName CD, ArrayRef<TemplateArgument> Arguments);
7520
7521 static bool classof(const Type *T) {
7522 return T->getTypeClass() == Auto;
7523 }
7524};
7525
7526/// Represents a C++17 deduced template specialization type.
7527class DeducedTemplateSpecializationType : public KeywordWrapper<DeducedType>,
7528 public llvm::FoldingSetNode {
7529 friend class ASTContext; // ASTContext creates these
7530
7531 /// The name of the template whose arguments will be deduced.
7533
7534 DeducedTemplateSpecializationType(DeducedKind DK,
7535 QualType DeducedAsTypeOrCanon,
7536 ElaboratedTypeKeyword Keyword,
7537 TemplateName Template)
7538 : KeywordWrapper(Keyword, DeducedTemplateSpecialization, DK,
7539 DeducedAsTypeOrCanon),
7541
7542 assert(!Template.isNull());
7543
7544 auto Dep = toTypeDependence(Template.getDependence());
7545 // A deduced AutoType only syntactically depends on its template name.
7546 if (DK == DeducedKind::Deduced)
7547 Dep = toSyntacticDependence(Dep);
7548 addDependence(Dep);
7549 }
7550
7551public:
7552 /// Retrieve the name of the template that we are deducing.
7553 TemplateName getTemplateName() const { return Template; }
7554
7555 void Profile(llvm::FoldingSetNodeID &ID) const {
7556 Profile(ID, getDeducedKind(), getDeducedType(), getKeyword(),
7557 getTemplateName());
7558 }
7559
7560 static void Profile(llvm::FoldingSetNodeID &ID, DeducedKind DK,
7561 QualType Deduced, ElaboratedTypeKeyword Keyword,
7562 TemplateName Template) {
7563 DeducedType::Profile(ID, DK, Deduced);
7564 ID.AddInteger(llvm::to_underlying(Keyword));
7565 Template.Profile(ID);
7566 }
7567
7568 static bool classof(const Type *T) {
7569 return T->getTypeClass() == DeducedTemplateSpecialization;
7570 }
7571};
7572
7573/// Represents a type template specialization; the template
7574/// must be a class template, a type alias template, or a template
7575/// template parameter. A template which cannot be resolved to one of
7576/// these, e.g. because it is written with a dependent scope
7577/// specifier, is instead represented as a
7578/// @c DependentTemplateSpecializationType.
7579///
7580/// A non-dependent template specialization type is always "sugar",
7581/// typically for a \c RecordType. For example, a class template
7582/// specialization type of \c vector<int> will refer to a tag type for
7583/// the instantiation \c std::vector<int, std::allocator<int>>
7584///
7585/// Template specializations are dependent if either the template or
7586/// any of the template arguments are dependent, in which case the
7587/// type may also be canonical.
7588///
7589/// Instances of this type are allocated with a trailing array of
7590/// TemplateArguments, followed by a QualType representing the
7591/// non-canonical aliased type when the template is a type alias
7592/// template.
7593class TemplateSpecializationType : public TypeWithKeyword,
7594 public llvm::FoldingSetNode {
7595 friend class ASTContext; // ASTContext creates these
7596
7597 /// The name of the template being specialized. This is
7598 /// either a TemplateName::Template (in which case it is a
7599 /// ClassTemplateDecl*, a TemplateTemplateParmDecl*, or a
7600 /// TypeAliasTemplateDecl*), a
7601 /// TemplateName::SubstTemplateTemplateParmPack, or a
7602 /// TemplateName::SubstTemplateTemplateParm (in which case the
7603 /// replacement must, recursively, be one of these).
7605
7606 TemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName T,
7607 bool IsAlias, ArrayRef<TemplateArgument> Args,
7608 QualType Underlying);
7609
7610public:
7611 /// Determine whether any of the given template arguments are dependent.
7612 ///
7613 /// The converted arguments should be supplied when known; whether an
7614 /// argument is dependent can depend on the conversions performed on it
7615 /// (for example, a 'const int' passed as a template argument might be
7616 /// dependent if the parameter is a reference but non-dependent if the
7617 /// parameter is an int).
7618 ///
7619 /// Note that the \p Args parameter is unused: this is intentional, to remind
7620 /// the caller that they need to pass in the converted arguments, not the
7621 /// specified arguments.
7622 static bool
7623 anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args,
7624 ArrayRef<TemplateArgument> Converted);
7625 static bool
7626 anyDependentTemplateArguments(const TemplateArgumentListInfo &,
7627 ArrayRef<TemplateArgument> Converted);
7628 static bool anyInstantiationDependentTemplateArguments(
7629 ArrayRef<TemplateArgumentLoc> Args);
7630
7631 /// True if this template specialization type matches a current
7632 /// instantiation in the context in which it is found.
7633 bool isCurrentInstantiation() const {
7634 return isa<InjectedClassNameType>(getCanonicalTypeInternal());
7635 }
7636
7637 /// Determine if this template specialization type is for a type alias
7638 /// template that has been substituted.
7639 ///
7640 /// Nearly every template specialization type whose template is an alias
7641 /// template will be substituted. However, this is not the case when
7642 /// the specialization contains a pack expansion but the template alias
7643 /// does not have a corresponding parameter pack, e.g.,
7644 ///
7645 /// \code
7646 /// template<typename T, typename U, typename V> struct S;
7647 /// template<typename T, typename U> using A = S<T, int, U>;
7648 /// template<typename... Ts> struct X {
7649 /// typedef A<Ts...> type; // not a type alias
7650 /// };
7651 /// \endcode
7652 bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; }
7653
7654 /// Get the aliased type, if this is a specialization of a type alias
7655 /// template.
7656 QualType getAliasedType() const;
7657
7658 /// Retrieve the name of the template that we are specializing.
7659 TemplateName getTemplateName() const { return Template; }
7660
7661 ArrayRef<TemplateArgument> template_arguments() const {
7662 return {reinterpret_cast<const TemplateArgument *>(this + 1),
7663 TemplateSpecializationTypeBits.NumArgs};
7664 }
7665
7666 bool isSugared() const;
7667
7668 QualType desugar() const {
7669 return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal();
7670 }
7671
7672 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx);
7673 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
7674 TemplateName T, ArrayRef<TemplateArgument> Args,
7675 QualType Underlying, const ASTContext &Context);
7676
7677 static bool classof(const Type *T) {
7679 }
7680};
7681
7682/// Print a template argument list, including the '<' and '>'
7683/// enclosing the template arguments.
7684void printTemplateArgumentList(raw_ostream &OS,
7685 ArrayRef<TemplateArgument> Args,
7686 const PrintingPolicy &Policy,
7687 const TemplateParameterList *TPL = nullptr);
7688
7689void printTemplateArgumentList(raw_ostream &OS,
7690 ArrayRef<TemplateArgumentLoc> Args,
7691 const PrintingPolicy &Policy,
7692 const TemplateParameterList *TPL = nullptr);
7693
7694void printTemplateArgumentList(raw_ostream &OS,
7695 const TemplateArgumentListInfo &Args,
7696 const PrintingPolicy &Policy,
7697 const TemplateParameterList *TPL = nullptr);
7698
7699/// Make a best-effort determination of whether the type T can be produced by
7700/// substituting Args into the default argument of Param.
7701bool isSubstitutedDefaultArgument(ASTContext &Ctx, TemplateArgument Arg,
7702 const NamedDecl *Param,
7703 ArrayRef<TemplateArgument> Args,
7704 unsigned Depth);
7705
7706/// Represents a qualified type name for which the type name is
7707/// dependent.
7708///
7709/// DependentNameType represents a class of dependent types that involve a
7710/// possibly dependent nested-name-specifier (e.g., "T::") followed by a
7711/// name of a type. The DependentNameType may start with a "typename" (for a
7712/// typename-specifier), "class", "struct", "union", or "enum" (for a
7713/// dependent elaborated-type-specifier), or nothing (in contexts where we
7714/// know that we must be referring to a type, e.g., in a base class specifier).
7715/// Typically the nested-name-specifier is dependent, but in MSVC compatibility
7716/// mode, this type is used with non-dependent names to delay name lookup until
7717/// instantiation.
7718class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
7719 friend class ASTContext; // ASTContext creates these
7720
7721 /// The nested name specifier containing the qualifier.
7722 NestedNameSpecifier NNS;
7723
7724 /// The type that this typename specifier refers to.
7725 const IdentifierInfo *Name;
7726
7727 DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier NNS,
7728 const IdentifierInfo *Name, QualType CanonType)
7729 : TypeWithKeyword(Keyword, DependentName, CanonType,
7730 TypeDependence::DependentInstantiation |
7731 (NNS ? toTypeDependence(NNS.getDependence())
7733 NNS(NNS), Name(Name) {
7734 assert(Name);
7735 }
7736
7737public:
7738 /// Retrieve the qualification on this type.
7739 NestedNameSpecifier getQualifier() const { return NNS; }
7740
7741 /// Retrieve the identifier that terminates this type name.
7742 /// For example, "type" in "typename T::type".
7743 const IdentifierInfo *getIdentifier() const {
7744 return Name;
7745 }
7746
7747 bool isSugared() const { return false; }
7748 QualType desugar() const { return QualType(this, 0); }
7749
7750 void Profile(llvm::FoldingSetNodeID &ID) {
7751 Profile(ID, getKeyword(), NNS, Name);
7752 }
7753
7754 static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword,
7755 NestedNameSpecifier NNS, const IdentifierInfo *Name) {
7756 ID.AddInteger(llvm::to_underlying(Keyword));
7757 NNS.Profile(ID);
7758 ID.AddPointer(Name);
7759 }
7760
7761 static bool classof(const Type *T) {
7762 return T->getTypeClass() == DependentName;
7763 }
7764};
7765
7766/// Represents a pack expansion of types.
7767///
7768/// Pack expansions are part of C++11 variadic templates. A pack
7769/// expansion contains a pattern, which itself contains one or more
7770/// "unexpanded" parameter packs. When instantiated, a pack expansion
7771/// produces a series of types, each instantiated from the pattern of
7772/// the expansion, where the Ith instantiation of the pattern uses the
7773/// Ith arguments bound to each of the unexpanded parameter packs. The
7774/// pack expansion is considered to "expand" these unexpanded
7775/// parameter packs.
7776///
7777/// \code
7778/// template<typename ...Types> struct tuple;
7779///
7780/// template<typename ...Types>
7781/// struct tuple_of_references {
7782/// typedef tuple<Types&...> type;
7783/// };
7784/// \endcode
7785///
7786/// Here, the pack expansion \c Types&... is represented via a
7787/// PackExpansionType whose pattern is Types&.
7788class PackExpansionType : public Type, public llvm::FoldingSetNode {
7789 friend class ASTContext; // ASTContext creates these
7790
7791 /// The pattern of the pack expansion.
7792 QualType Pattern;
7793
7794 PackExpansionType(QualType Pattern, QualType Canon,
7795 UnsignedOrNone NumExpansions)
7796 : Type(PackExpansion, Canon,
7797 (Pattern->getDependence() | TypeDependence::Dependent |
7798 TypeDependence::Instantiation) &
7799 ~TypeDependence::UnexpandedPack),
7800 Pattern(Pattern) {
7801 PackExpansionTypeBits.NumExpansions =
7802 NumExpansions ? *NumExpansions + 1 : 0;
7803 }
7804
7805public:
7806 /// Retrieve the pattern of this pack expansion, which is the
7807 /// type that will be repeatedly instantiated when instantiating the
7808 /// pack expansion itself.
7809 QualType getPattern() const { return Pattern; }
7810
7811 /// Retrieve the number of expansions that this pack expansion will
7812 /// generate, if known.
7813 UnsignedOrNone getNumExpansions() const {
7814 if (PackExpansionTypeBits.NumExpansions)
7815 return PackExpansionTypeBits.NumExpansions - 1;
7816 return std::nullopt;
7817 }
7818
7819 bool isSugared() const { return false; }
7820 QualType desugar() const { return QualType(this, 0); }
7821
7822 std::pair<QualType, unsigned> getKey() const {
7823 return {getPattern(), getNumExpansions().toInternalRepresentation()};
7824 }
7825
7826 static bool classof(const Type *T) {
7827 return T->getTypeClass() == PackExpansion;
7828 }
7829};
7830
7831/// This class wraps the list of protocol qualifiers. For types that can
7832/// take ObjC protocol qualifers, they can subclass this class.
7833template <class T>
7834class ObjCProtocolQualifiers {
7835protected:
7836 ObjCProtocolQualifiers() = default;
7837
7838 ObjCProtocolDecl * const *getProtocolStorage() const {
7839 return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage();
7840 }
7841
7842 ObjCProtocolDecl **getProtocolStorage() {
7843 return static_cast<T*>(this)->getProtocolStorageImpl();
7844 }
7845
7846 void setNumProtocols(unsigned N) {
7847 static_cast<T*>(this)->setNumProtocolsImpl(N);
7848 }
7849
7850 void initialize(ArrayRef<ObjCProtocolDecl *> protocols) {
7851 setNumProtocols(protocols.size());
7852 assert(getNumProtocols() == protocols.size() &&
7853 "bitfield overflow in protocol count");
7854 if (!protocols.empty())
7855 memcpy(getProtocolStorage(), protocols.data(),
7856 protocols.size() * sizeof(ObjCProtocolDecl*));
7857 }
7858
7859public:
7860 using qual_iterator = ObjCProtocolDecl * const *;
7861 using qual_range = llvm::iterator_range<qual_iterator>;
7862
7863 qual_range quals() const { return qual_range(qual_begin(), qual_end()); }
7864 qual_iterator qual_begin() const { return getProtocolStorage(); }
7865 qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); }
7866
7867 bool qual_empty() const { return getNumProtocols() == 0; }
7868
7869 /// Return the number of qualifying protocols in this type, or 0 if
7870 /// there are none.
7871 unsigned getNumProtocols() const {
7872 return static_cast<const T*>(this)->getNumProtocolsImpl();
7873 }
7874
7875 /// Fetch a protocol by index.
7876 ObjCProtocolDecl *getProtocol(unsigned I) const {
7877 assert(I < getNumProtocols() && "Out-of-range protocol access");
7878 return qual_begin()[I];
7879 }
7880
7881 /// Retrieve all of the protocol qualifiers.
7882 ArrayRef<ObjCProtocolDecl *> getProtocols() const {
7883 return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols());
7884 }
7885};
7886
7887/// Represents a type parameter type in Objective C. It can take
7888/// a list of protocols.
7889class ObjCTypeParamType : public Type,
7890 public ObjCProtocolQualifiers<ObjCTypeParamType>,
7891 public llvm::FoldingSetNode {
7892 friend class ASTContext;
7893 friend class ObjCProtocolQualifiers<ObjCTypeParamType>;
7894
7895 /// The number of protocols stored on this type.
7896 unsigned NumProtocols : 6;
7897
7898 ObjCTypeParamDecl *OTPDecl;
7899
7900 /// The protocols are stored after the ObjCTypeParamType node. In the
7901 /// canonical type, the list of protocols are sorted alphabetically
7902 /// and uniqued.
7903 ObjCProtocolDecl **getProtocolStorageImpl();
7904
7905 /// Return the number of qualifying protocols in this interface type,
7906 /// or 0 if there are none.
7907 unsigned getNumProtocolsImpl() const {
7908 return NumProtocols;
7909 }
7910
7911 void setNumProtocolsImpl(unsigned N) {
7912 NumProtocols = N;
7913 }
7914
7915 ObjCTypeParamType(const ObjCTypeParamDecl *D,
7916 QualType can,
7917 ArrayRef<ObjCProtocolDecl *> protocols);
7918
7919public:
7920 bool isSugared() const { return true; }
7921 QualType desugar() const { return getCanonicalTypeInternal(); }
7922
7923 static bool classof(const Type *T) {
7924 return T->getTypeClass() == ObjCTypeParam;
7925 }
7926
7927 ObjCTypeParamDecl *getDecl() const { return OTPDecl; }
7928
7929 std::tuple<const ObjCTypeParamDecl *, QualType, ArrayRef<ObjCProtocolDecl *>>
7930 getKey() const {
7931 return {getDecl(), getCanonicalTypeInternal(),
7932 llvm::ArrayRef(qual_begin(), getNumProtocols())};
7933 }
7934};
7935
7936/// Represents a class type in Objective C.
7937///
7938/// Every Objective C type is a combination of a base type, a set of
7939/// type arguments (optional, for parameterized classes) and a list of
7940/// protocols.
7941///
7942/// Given the following declarations:
7943/// \code
7944/// \@class C<T>;
7945/// \@protocol P;
7946/// \endcode
7947///
7948/// 'C' is an ObjCInterfaceType C. It is sugar for an ObjCObjectType
7949/// with base C and no protocols.
7950///
7951/// 'C<P>' is an unspecialized ObjCObjectType with base C and protocol list [P].
7952/// 'C<C*>' is a specialized ObjCObjectType with type arguments 'C*' and no
7953/// protocol list.
7954/// 'C<C*><P>' is a specialized ObjCObjectType with base C, type arguments 'C*',
7955/// and protocol list [P].
7956///
7957/// 'id' is a TypedefType which is sugar for an ObjCObjectPointerType whose
7958/// pointee is an ObjCObjectType with base BuiltinType::ObjCIdType
7959/// and no protocols.
7960///
7961/// 'id<P>' is an ObjCObjectPointerType whose pointee is an ObjCObjectType
7962/// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually
7963/// this should get its own sugar class to better represent the source.
7964class ObjCObjectType : public Type,
7965 public ObjCProtocolQualifiers<ObjCObjectType> {
7966 friend class ObjCProtocolQualifiers<ObjCObjectType>;
7967
7968 // ObjCObjectType.NumTypeArgs - the number of type arguments stored
7969 // after the ObjCObjectPointerType node.
7970 // ObjCObjectType.NumProtocols - the number of protocols stored
7971 // after the type arguments of ObjCObjectPointerType node.
7972 //
7973 // These protocols are those written directly on the type. If
7974 // protocol qualifiers ever become additive, the iterators will need
7975 // to get kindof complicated.
7976 //
7977 // In the canonical object type, these are sorted alphabetically
7978 // and uniqued.
7979
7980 /// Either a BuiltinType or an InterfaceType or sugar for either.
7981 QualType BaseType;
7982
7983 /// Cached superclass type.
7984 mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool>
7985 CachedSuperClassType;
7986
7987 QualType *getTypeArgStorage();
7988 const QualType *getTypeArgStorage() const {
7989 return const_cast<ObjCObjectType *>(this)->getTypeArgStorage();
7990 }
7991
7992 ObjCProtocolDecl **getProtocolStorageImpl();
7993 /// Return the number of qualifying protocols in this interface type,
7994 /// or 0 if there are none.
7995 unsigned getNumProtocolsImpl() const {
7996 return ObjCObjectTypeBits.NumProtocols;
7997 }
7998 void setNumProtocolsImpl(unsigned N) {
7999 ObjCObjectTypeBits.NumProtocols = N;
8000 }
8001
8002protected:
8003 enum Nonce_ObjCInterface { Nonce_ObjCInterface };
8004
8005 ObjCObjectType(QualType Canonical, QualType Base,
8006 ArrayRef<QualType> typeArgs,
8007 ArrayRef<ObjCProtocolDecl *> protocols,
8008 bool isKindOf);
8009
8010 ObjCObjectType(enum Nonce_ObjCInterface)
8011 : Type(ObjCInterface, QualType(), TypeDependence::None),
8012 BaseType(QualType(this_(), 0)) {
8013 ObjCObjectTypeBits.NumProtocols = 0;
8014 ObjCObjectTypeBits.NumTypeArgs = 0;
8015 ObjCObjectTypeBits.IsKindOf = 0;
8016 }
8017
8018 void computeSuperClassTypeSlow() const;
8019
8020public:
8021 /// Gets the base type of this object type. This is always (possibly
8022 /// sugar for) one of:
8023 /// - the 'id' builtin type (as opposed to the 'id' type visible to the
8024 /// user, which is a typedef for an ObjCObjectPointerType)
8025 /// - the 'Class' builtin type (same caveat)
8026 /// - an ObjCObjectType (currently always an ObjCInterfaceType)
8027 QualType getBaseType() const { return BaseType; }
8028
8029 bool isObjCId() const {
8030 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId);
8031 }
8032
8033 bool isObjCClass() const {
8034 return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass);
8035 }
8036
8037 bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); }
8038 bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); }
8039 bool isObjCUnqualifiedIdOrClass() const {
8040 if (!qual_empty()) return false;
8041 if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>())
8042 return T->getKind() == BuiltinType::ObjCId ||
8043 T->getKind() == BuiltinType::ObjCClass;
8044 return false;
8045 }
8046 bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); }
8047 bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); }
8048
8049 /// Gets the interface declaration for this object type, if the base type
8050 /// really is an interface.
8051 ObjCInterfaceDecl *getInterface() const;
8052
8053 /// Determine whether this object type is "specialized", meaning
8054 /// that it has type arguments.
8055 bool isSpecialized() const;
8056
8057 /// Determine whether this object type was written with type arguments.
8058 bool isSpecializedAsWritten() const {
8059 return ObjCObjectTypeBits.NumTypeArgs > 0;
8060 }
8061
8062 /// Determine whether this object type is "unspecialized", meaning
8063 /// that it has no type arguments.
8064 bool isUnspecialized() const { return !isSpecialized(); }
8065
8066 /// Determine whether this object type is "unspecialized" as
8067 /// written, meaning that it has no type arguments.
8068 bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); }
8069
8070 /// Retrieve the type arguments of this object type (semantically).
8071 ArrayRef<QualType> getTypeArgs() const;
8072
8073 /// Retrieve the type arguments of this object type as they were
8074 /// written.
8075 ArrayRef<QualType> getTypeArgsAsWritten() const {
8076 return {getTypeArgStorage(), ObjCObjectTypeBits.NumTypeArgs};
8077 }
8078
8079 /// Whether this is a "__kindof" type as written.
8080 bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; }
8081
8082 /// Whether this ia a "__kindof" type (semantically).
8083 bool isKindOfType() const;
8084
8085 /// Retrieve the type of the superclass of this object type.
8086 ///
8087 /// This operation substitutes any type arguments into the
8088 /// superclass of the current class type, potentially producing a
8089 /// specialization of the superclass type. Produces a null type if
8090 /// there is no superclass.
8091 QualType getSuperClassType() const {
8092 if (!CachedSuperClassType.getInt())
8093 computeSuperClassTypeSlow();
8094
8095 assert(CachedSuperClassType.getInt() && "Superclass not set?");
8096 return QualType(CachedSuperClassType.getPointer(), 0);
8097 }
8098
8099 /// Strip off the Objective-C "kindof" type and (with it) any
8100 /// protocol qualifiers.
8101 QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const;
8102
8103 bool isSugared() const { return false; }
8104 QualType desugar() const { return QualType(this, 0); }
8105
8106 static bool classof(const Type *T) {
8107 return T->getTypeClass() == ObjCObject ||
8108 T->getTypeClass() == ObjCInterface;
8109 }
8110};
8111
8112/// A class providing a concrete implementation
8113/// of ObjCObjectType, so as to not increase the footprint of
8114/// ObjCInterfaceType. Code outside of ASTContext and the core type
8115/// system should not reference this type.
8116class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode {
8117 friend class ASTContext;
8118
8119 // If anyone adds fields here, ObjCObjectType::getProtocolStorage()
8120 // will need to be modified.
8121
8122 ObjCObjectTypeImpl(QualType Canonical, QualType Base,
8123 ArrayRef<QualType> typeArgs,
8124 ArrayRef<ObjCProtocolDecl *> protocols,
8125 bool isKindOf)
8126 : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {}
8127
8128public:
8129 void Profile(llvm::FoldingSetNodeID &ID);
8130 static void Profile(llvm::FoldingSetNodeID &ID,
8131 QualType Base,
8132 ArrayRef<QualType> typeArgs,
8133 ArrayRef<ObjCProtocolDecl *> protocols,
8134 bool isKindOf);
8135};
8136
8137inline QualType *ObjCObjectType::getTypeArgStorage() {
8138 return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1);
8139}
8140
8141inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() {
8142 return reinterpret_cast<ObjCProtocolDecl**>(
8143 getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs);
8144}
8145
8146inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() {
8147 return reinterpret_cast<ObjCProtocolDecl**>(
8148 static_cast<ObjCTypeParamType*>(this)+1);
8149}
8150
8151/// Interfaces are the core concept in Objective-C for object oriented design.
8152/// They basically correspond to C++ classes. There are two kinds of interface
8153/// types: normal interfaces like `NSString`, and qualified interfaces, which
8154/// are qualified with a protocol list like `NSString<NSCopyable, NSAmazing>`.
8155///
8156/// ObjCInterfaceType guarantees the following properties when considered
8157/// as a subtype of its superclass, ObjCObjectType:
8158/// - There are no protocol qualifiers. To reinforce this, code which
8159/// tries to invoke the protocol methods via an ObjCInterfaceType will
8160/// fail to compile.
8161/// - It is its own base type. That is, if T is an ObjCInterfaceType*,
8162/// T->getBaseType() == QualType(T, 0).
8163class ObjCInterfaceType : public ObjCObjectType {
8164 friend class ASTContext; // ASTContext creates these.
8165 friend class ASTReader;
8166 template <class T> friend class serialization::AbstractTypeReader;
8167
8168 ObjCInterfaceDecl *Decl;
8169
8170 ObjCInterfaceType(const ObjCInterfaceDecl *D)
8171 : ObjCObjectType(Nonce_ObjCInterface),
8172 Decl(const_cast<ObjCInterfaceDecl*>(D)) {}
8173
8174public:
8175 /// Get the declaration of this interface.
8176 ObjCInterfaceDecl *getDecl() const;
8177
8178 bool isSugared() const { return false; }
8179 QualType desugar() const { return QualType(this, 0); }
8180
8181 static bool classof(const Type *T) {
8182 return T->getTypeClass() == ObjCInterface;
8183 }
8184
8185 // Nonsense to "hide" certain members of ObjCObjectType within this
8186 // class. People asking for protocols on an ObjCInterfaceType are
8187 // not going to get what they want: ObjCInterfaceTypes are
8188 // guaranteed to have no protocols.
8189 enum {
8195 };
8196};
8197
8198inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const {
8199 QualType baseType = getBaseType();
8200 while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) {
8201 if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT))
8202 return T->getDecl();
8203
8204 baseType = ObjT->getBaseType();
8205 }
8206
8207 return nullptr;
8208}
8209
8210/// Represents a pointer to an Objective C object.
8211///
8212/// These are constructed from pointer declarators when the pointee type is
8213/// an ObjCObjectType (or sugar for one). In addition, the 'id' and 'Class'
8214/// types are typedefs for these, and the protocol-qualified types 'id<P>'
8215/// and 'Class<P>' are translated into these.
8216///
8217/// Pointers to pointers to Objective C objects are still PointerTypes;
8218/// only the first level of pointer gets it own type implementation.
8219class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode {
8220 friend class ASTContext; // ASTContext creates these.
8221
8222 QualType PointeeType;
8223
8224 ObjCObjectPointerType(QualType Canonical, QualType Pointee)
8225 : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()),
8226 PointeeType(Pointee) {}
8227
8228public:
8229 /// Gets the type pointed to by this ObjC pointer.
8230 /// The result will always be an ObjCObjectType or sugar thereof.
8231 QualType getPointeeType() const { return PointeeType; }
8232
8233 /// Gets the type pointed to by this ObjC pointer. Always returns non-null.
8234 ///
8235 /// This method is equivalent to getPointeeType() except that
8236 /// it discards any typedefs (or other sugar) between this
8237 /// type and the "outermost" object type. So for:
8238 /// \code
8239 /// \@class A; \@protocol P; \@protocol Q;
8240 /// typedef A<P> AP;
8241 /// typedef A A1;
8242 /// typedef A1<P> A1P;
8243 /// typedef A1P<Q> A1PQ;
8244 /// \endcode
8245 /// For 'A*', getObjectType() will return 'A'.
8246 /// For 'A<P>*', getObjectType() will return 'A<P>'.
8247 /// For 'AP*', getObjectType() will return 'A<P>'.
8248 /// For 'A1*', getObjectType() will return 'A'.
8249 /// For 'A1<P>*', getObjectType() will return 'A1<P>'.
8250 /// For 'A1P*', getObjectType() will return 'A1<P>'.
8251 /// For 'A1PQ*', getObjectType() will return 'A1<Q>', because
8252 /// adding protocols to a protocol-qualified base discards the
8253 /// old qualifiers (for now). But if it didn't, getObjectType()
8254 /// would return 'A1P<Q>' (and we'd have to make iterating over
8255 /// qualifiers more complicated).
8257 return PointeeType->castAs<ObjCObjectType>();
8258 }
8259
8260 /// If this pointer points to an Objective C
8261 /// \@interface type, gets the type for that interface. Any protocol
8262 /// qualifiers on the interface are ignored.
8263 ///
8264 /// \return null if the base type for this pointer is 'id' or 'Class'
8265 const ObjCInterfaceType *getInterfaceType() const;
8266
8267 /// If this pointer points to an Objective \@interface
8268 /// type, gets the declaration for that interface.
8269 ///
8270 /// \return null if the base type for this pointer is 'id' or 'Class'
8272 return getObjectType()->getInterface();
8273 }
8274
8275 /// True if this is equivalent to the 'id' type, i.e. if
8276 /// its object type is the primitive 'id' type with no protocols.
8277 bool isObjCIdType() const {
8278 return getObjectType()->isObjCUnqualifiedId();
8279 }
8280
8281 /// True if this is equivalent to the 'Class' type,
8282 /// i.e. if its object tive is the primitive 'Class' type with no protocols.
8283 bool isObjCClassType() const {
8284 return getObjectType()->isObjCUnqualifiedClass();
8285 }
8286
8287 /// True if this is equivalent to the 'id' or 'Class' type,
8288 bool isObjCIdOrClassType() const {
8289 return getObjectType()->isObjCUnqualifiedIdOrClass();
8290 }
8291
8292 /// True if this is equivalent to 'id<P>' for some non-empty set of
8293 /// protocols.
8295 return getObjectType()->isObjCQualifiedId();
8296 }
8297
8298 /// True if this is equivalent to 'Class<P>' for some non-empty set of
8299 /// protocols.
8301 return getObjectType()->isObjCQualifiedClass();
8302 }
8303
8304 /// Whether this is a "__kindof" type.
8305 bool isKindOfType() const { return getObjectType()->isKindOfType(); }
8306
8307 /// Whether this type is specialized, meaning that it has type arguments.
8308 bool isSpecialized() const { return getObjectType()->isSpecialized(); }
8309
8310 /// Whether this type is specialized, meaning that it has type arguments.
8312 return getObjectType()->isSpecializedAsWritten();
8313 }
8314
8315 /// Whether this type is unspecialized, meaning that is has no type arguments.
8316 bool isUnspecialized() const { return getObjectType()->isUnspecialized(); }
8317
8318 /// Determine whether this object type is "unspecialized" as
8319 /// written, meaning that it has no type arguments.
8321
8322 /// Retrieve the type arguments for this type.
8324 return getObjectType()->getTypeArgs();
8325 }
8326
8327 /// Retrieve the type arguments for this type.
8329 return getObjectType()->getTypeArgsAsWritten();
8330 }
8331
8332 /// An iterator over the qualifiers on the object type. Provided
8333 /// for convenience. This will always iterate over the full set of
8334 /// protocols on a type, not just those provided directly.
8335 using qual_iterator = ObjCObjectType::qual_iterator;
8336 using qual_range = llvm::iterator_range<qual_iterator>;
8337
8339
8341 return getObjectType()->qual_begin();
8342 }
8343
8345 return getObjectType()->qual_end();
8346 }
8347
8348 bool qual_empty() const { return getObjectType()->qual_empty(); }
8349
8350 /// Return the number of qualifying protocols on the object type.
8351 unsigned getNumProtocols() const {
8352 return getObjectType()->getNumProtocols();
8353 }
8354
8355 /// Retrieve a qualifying protocol by index on the object type.
8356 ObjCProtocolDecl *getProtocol(unsigned I) const {
8357 return getObjectType()->getProtocol(I);
8358 }
8359
8360 bool isSugared() const { return false; }
8361 QualType desugar() const { return QualType(this, 0); }
8362
8363 /// Retrieve the type of the superclass of this object pointer type.
8364 ///
8365 /// This operation substitutes any type arguments into the
8366 /// superclass of the current class type, potentially producing a
8367 /// pointer to a specialization of the superclass type. Produces a
8368 /// null type if there is no superclass.
8369 QualType getSuperClassType() const;
8370
8371 /// Strip off the Objective-C "kindof" type and (with it) any
8372 /// protocol qualifiers.
8373 const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals(
8374 const ASTContext &ctx) const;
8375
8376 QualType getKey() const { return getPointeeType(); }
8377
8378 static bool classof(const Type *T) {
8379 return T->getTypeClass() == ObjCObjectPointer;
8380 }
8381};
8382
8383class AtomicType : public Type, public llvm::FoldingSetNode {
8384 friend class ASTContext; // ASTContext creates these.
8385
8386 QualType ValueType;
8387
8388 AtomicType(QualType ValTy, QualType Canonical)
8389 : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {}
8390
8391public:
8392 /// Gets the type contained by this atomic type, i.e.
8393 /// the type returned by performing an atomic load of this atomic type.
8394 QualType getValueType() const { return ValueType; }
8395
8396 QualType getKey() const { return getValueType(); }
8397
8398 bool isSugared() const { return false; }
8399 QualType desugar() const { return QualType(this, 0); }
8400
8401 static bool classof(const Type *T) {
8402 return T->getTypeClass() == Atomic;
8403 }
8404};
8405
8406/// PipeType - OpenCL20.
8407class PipeType : public Type, public llvm::FoldingSetNode {
8408 friend class ASTContext; // ASTContext creates these.
8409
8410 QualType ElementType;
8411 bool isRead;
8412
8413 PipeType(QualType elemType, QualType CanonicalPtr, bool isRead)
8414 : Type(Pipe, CanonicalPtr, elemType->getDependence()),
8415 ElementType(elemType), isRead(isRead) {}
8416
8417public:
8418 QualType getElementType() const { return ElementType; }
8419
8420 bool isSugared() const { return false; }
8421
8422 QualType desugar() const { return QualType(this, 0); }
8423
8424 std::pair<QualType, bool> getKey() const {
8425 return {getElementType(), isReadOnly()};
8426 }
8427
8428 static bool classof(const Type *T) {
8429 return T->getTypeClass() == Pipe;
8430 }
8431
8432 bool isReadOnly() const { return isRead; }
8433};
8434
8435/// A fixed int type of a specified bitwidth.
8436class BitIntType final : public Type, public llvm::FoldingSetNode {
8437 friend class ASTContext;
8438 LLVM_PREFERRED_TYPE(bool)
8439 unsigned IsUnsigned : 1;
8440 unsigned NumBits : 24;
8441
8442protected:
8443 BitIntType(bool isUnsigned, unsigned NumBits);
8444
8445public:
8446 bool isUnsigned() const { return IsUnsigned; }
8447 bool isSigned() const { return !IsUnsigned; }
8448 unsigned getNumBits() const { return NumBits; }
8449
8450 bool isSugared() const { return false; }
8451 QualType desugar() const { return QualType(this, 0); }
8452
8453 std::pair<unsigned, unsigned> getKey() const {
8454 return {isUnsigned(), getNumBits()};
8455 }
8456
8457 static bool classof(const Type *T) { return T->getTypeClass() == BitInt; }
8458};
8459
8460class DependentBitIntType final : public Type, public llvm::FoldingSetNode {
8461 friend class ASTContext;
8462 llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned;
8463
8464protected:
8465 DependentBitIntType(bool IsUnsigned, Expr *NumBits);
8466
8467public:
8468 bool isUnsigned() const;
8469 bool isSigned() const { return !isUnsigned(); }
8470 Expr *getNumBitsExpr() const;
8471
8472 bool isSugared() const { return false; }
8473 QualType desugar() const { return QualType(this, 0); }
8474
8475 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) {
8476 Profile(ID, Context, isUnsigned(), getNumBitsExpr());
8477 }
8478 static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
8479 bool IsUnsigned, Expr *NumBitsExpr);
8480
8481 static bool classof(const Type *T) {
8482 return T->getTypeClass() == DependentBitInt;
8483 }
8484};
8485
8486class PredefinedSugarType final : public Type {
8487public:
8488 friend class ASTContext;
8490
8491private:
8492 PredefinedSugarType(Kind KD, const IdentifierInfo *IdentName,
8493 QualType CanonicalType)
8494 : Type(PredefinedSugar, CanonicalType, TypeDependence::None),
8495 Name(IdentName) {
8496 PredefinedSugarTypeBits.Kind = llvm::to_underlying(KD);
8497 }
8498
8499 static StringRef getName(Kind KD);
8500
8501 const IdentifierInfo *Name;
8502
8503public:
8504 bool isSugared() const { return true; }
8505
8507
8508 Kind getKind() const { return Kind(PredefinedSugarTypeBits.Kind); }
8509
8510 const IdentifierInfo *getIdentifier() const { return Name; }
8511
8512 static bool classof(const Type *T) {
8513 return T->getTypeClass() == PredefinedSugar;
8514 }
8515};
8516
8517/// A qualifier set is used to build a set of qualifiers.
8519public:
8521
8522 /// Collect any qualifiers on the given type and return an
8523 /// unqualified type. The qualifiers are assumed to be consistent
8524 /// with those already in the type.
8526 addFastQualifiers(type.getLocalFastQualifiers());
8527 if (!type.hasLocalNonFastQualifiers())
8528 return type.getTypePtrUnsafe();
8529
8530 const ExtQuals *extQuals = type.getExtQualsUnsafe();
8532 return extQuals->getBaseType();
8533 }
8534
8535 /// Apply the collected qualifiers to the given type.
8536 QualType apply(const ASTContext &Context, QualType QT) const;
8537
8538 /// Apply the collected qualifiers to the given type.
8539 QualType apply(const ASTContext &Context, const Type* T) const;
8540};
8541
8542/// A container of type source information.
8543///
8544/// A client can read the relevant info using TypeLoc wrappers, e.g:
8545/// @code
8546/// TypeLoc TL = TypeSourceInfo->getTypeLoc();
8547/// TL.getBeginLoc().print(OS, SrcMgr);
8548/// @endcode
8549class alignas(8) TypeSourceInfo {
8550 // Contains a memory block after the class, used for type source information,
8551 // allocated by ASTContext.
8552 friend class ASTContext;
8553
8554 QualType Ty;
8555
8556 TypeSourceInfo(QualType ty, size_t DataSize); // implemented in TypeLoc.h
8557
8558public:
8559 /// Return the type wrapped by this type source info.
8560 QualType getType() const { return Ty; }
8561
8562 /// Return the TypeLoc wrapper for the type source info.
8563 TypeLoc getTypeLoc() const; // implemented in TypeLoc.h
8564
8565 /// Override the type stored in this TypeSourceInfo. Use with caution!
8566 void overrideType(QualType T) { Ty = T; }
8567};
8568
8569// Inline function definitions.
8570
8572 SplitQualType desugar =
8573 Ty->getLocallyUnqualifiedSingleStepDesugaredType().split();
8575 return desugar;
8576}
8577
8578inline const Type *QualType::getTypePtr() const {
8579 return getCommonPtr()->BaseType;
8580}
8581
8582inline const Type *QualType::getTypePtrOrNull() const {
8583 return (isNull() ? nullptr : getCommonPtr()->BaseType);
8584}
8585
8586inline bool QualType::isReferenceable() const {
8587 // C++ [defns.referenceable]
8588 // type that is either an object type, a function type that does not have
8589 // cv-qualifiers or a ref-qualifier, or a reference type.
8590 const Type &Self = **this;
8591 if (Self.isObjectType() || Self.isReferenceType())
8592 return true;
8593 if (const auto *F = Self.getAs<FunctionProtoType>())
8594 return F->getMethodQuals().empty() && F->getRefQualifier() == RQ_None;
8595
8596 return false;
8597}
8598
8601 return SplitQualType(getTypePtrUnsafe(),
8603
8604 const ExtQuals *eq = getExtQualsUnsafe();
8605 Qualifiers qs = eq->getQualifiers();
8607 return SplitQualType(eq->getBaseType(), qs);
8608}
8609
8611 Qualifiers Quals;
8613 Quals = getExtQualsUnsafe()->getQualifiers();
8615 return Quals;
8616}
8617
8619 Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers();
8621 return quals;
8622}
8623
8624inline unsigned QualType::getCVRQualifiers() const {
8625 unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers();
8626 cvr |= getLocalCVRQualifiers();
8627 return cvr;
8628}
8629
8631 QualType canon = getCommonPtr()->CanonicalType;
8633}
8634
8635inline bool QualType::isCanonical() const {
8636 return getTypePtr()->isCanonicalUnqualified();
8637}
8638
8639inline bool QualType::isCanonicalAsParam() const {
8640 if (!isCanonical()) return false;
8641 if (hasLocalQualifiers()) return false;
8642
8643 const Type *T = getTypePtr();
8644 if (T->isVariablyModifiedType() && T->hasSizedVLAType())
8645 return false;
8646
8647 return !isa<FunctionType>(T) &&
8649}
8650
8651inline bool QualType::isConstQualified() const {
8652 return isLocalConstQualified() ||
8653 getCommonPtr()->CanonicalType.isLocalConstQualified();
8654}
8655
8657 return isLocalRestrictQualified() ||
8658 getCommonPtr()->CanonicalType.isLocalRestrictQualified();
8659}
8660
8661
8663 return isLocalVolatileQualified() ||
8664 getCommonPtr()->CanonicalType.isLocalVolatileQualified();
8665}
8666
8667inline bool QualType::hasQualifiers() const {
8668 return hasLocalQualifiers() ||
8669 getCommonPtr()->CanonicalType.hasLocalQualifiers();
8670}
8671
8673 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
8674 return QualType(getTypePtr(), 0);
8675
8676 return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0);
8677}
8678
8680 if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers())
8681 return split();
8682
8683 return getSplitUnqualifiedTypeImpl(*this);
8684}
8685
8689
8693
8697
8698/// Check if this type has any address space qualifier.
8699inline bool QualType::hasAddressSpace() const {
8700 return getQualifiers().hasAddressSpace();
8701}
8702
8703/// Return the address space of this type.
8705 return getQualifiers().getAddressSpace();
8706}
8707
8708/// Return the gc attribute of this type.
8710 return getQualifiers().getObjCGCAttr();
8711}
8712
8714 if (const auto *PT = t.getAs<PointerType>()) {
8715 if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>())
8716 return FT->getExtInfo();
8717 } else if (const auto *FT = t.getAs<FunctionType>())
8718 return FT->getExtInfo();
8719
8720 return FunctionType::ExtInfo();
8721}
8722
8726
8727/// Determine whether this type is more
8728/// qualified than the Other type. For example, "const volatile int"
8729/// is more qualified than "const int", "volatile int", and
8730/// "int". However, it is not more qualified than "const volatile
8731/// int".
8733 const ASTContext &Ctx) const {
8734 Qualifiers MyQuals = getQualifiers();
8735 Qualifiers OtherQuals = other.getQualifiers();
8736 return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals, Ctx));
8737}
8738
8739/// Determine whether this type is at last
8740/// as qualified as the Other type. For example, "const volatile
8741/// int" is at least as qualified as "const int", "volatile int",
8742/// "int", and "const volatile int".
8744 const ASTContext &Ctx) const {
8745 Qualifiers OtherQuals = other.getQualifiers();
8746
8747 // Ignore __unaligned qualifier if this type is a void.
8748 if (getUnqualifiedType()->isVoidType())
8749 OtherQuals.removeUnaligned();
8750
8751 return getQualifiers().compatiblyIncludes(OtherQuals, Ctx);
8752}
8753
8754/// If Type is a reference type (e.g., const
8755/// int&), returns the type that the reference refers to ("const
8756/// int"). Otherwise, returns the type itself. This routine is used
8757/// throughout Sema to implement C++ 5p6:
8758///
8759/// If an expression initially has the type "reference to T" (8.3.2,
8760/// 8.5.3), the type is adjusted to "T" prior to any further
8761/// analysis, the expression designates the object or function
8762/// denoted by the reference, and the expression is an lvalue.
8764 if (const auto *RefType = (*this)->getAs<ReferenceType>())
8765 return RefType->getPointeeType();
8766 else
8767 return *this;
8768}
8769
8771 return ((getTypePtr()->isVoidType() && !hasQualifiers()) ||
8772 getTypePtr()->isFunctionType());
8773}
8774
8775/// Tests whether the type is categorized as a fundamental type.
8776///
8777/// \returns True for types specified in C++0x [basic.fundamental].
8778inline bool Type::isFundamentalType() const {
8779 return isVoidType() ||
8780 isNullPtrType() ||
8781 // FIXME: It's really annoying that we don't have an
8782 // 'isArithmeticType()' which agrees with the standard definition.
8784}
8785
8786/// Tests whether the type is categorized as a compound type.
8787///
8788/// \returns True for types specified in C++0x [basic.compound].
8789inline bool Type::isCompoundType() const {
8790 // C++0x [basic.compound]p1:
8791 // Compound types can be constructed in the following ways:
8792 // -- arrays of objects of a given type [...];
8793 return isArrayType() ||
8794 // -- functions, which have parameters of given types [...];
8795 isFunctionType() ||
8796 // -- pointers to void or objects or functions [...];
8797 isPointerType() ||
8798 // -- references to objects or functions of a given type. [...]
8799 isReferenceType() ||
8800 // -- classes containing a sequence of objects of various types, [...];
8801 isRecordType() ||
8802 // -- unions, which are classes capable of containing objects of different
8803 // types at different times;
8804 isUnionType() ||
8805 // -- enumerations, which comprise a set of named constant values. [...];
8806 isEnumeralType() ||
8807 // -- pointers to non-static class members, [...].
8809}
8810
8811inline bool Type::isFunctionType() const {
8812 return isa<FunctionType>(CanonicalType);
8813}
8814
8815inline bool Type::isPointerType() const {
8816 return isa<PointerType>(CanonicalType);
8817}
8818
8820 return isPointerType() || isReferenceType();
8821}
8822
8823inline bool Type::isAnyPointerType() const {
8825}
8826
8827inline bool Type::isSignableType(const ASTContext &Ctx) const {
8829}
8830
8831inline bool Type::isSignablePointerType() const {
8833}
8834
8835inline bool Type::isBlockPointerType() const {
8836 return isa<BlockPointerType>(CanonicalType);
8837}
8838
8839inline bool Type::isReferenceType() const {
8840 return isa<ReferenceType>(CanonicalType);
8841}
8842
8843inline bool Type::isLValueReferenceType() const {
8844 return isa<LValueReferenceType>(CanonicalType);
8845}
8846
8847inline bool Type::isRValueReferenceType() const {
8848 return isa<RValueReferenceType>(CanonicalType);
8849}
8850
8851inline bool Type::isObjectPointerType() const {
8852 // Note: an "object pointer type" is not the same thing as a pointer to an
8853 // object type; rather, it is a pointer to an object type or a pointer to cv
8854 // void.
8855 if (const auto *T = getAs<PointerType>())
8856 return !T->getPointeeType()->isFunctionType();
8857 else
8858 return false;
8859}
8860
8862 if (const auto *Fn = getAs<FunctionProtoType>())
8863 return Fn->hasCFIUncheckedCallee();
8864 return false;
8865}
8866
8868 QualType Pointee;
8869 if (const auto *PT = getAs<PointerType>())
8870 Pointee = PT->getPointeeType();
8871 else if (const auto *RT = getAs<ReferenceType>())
8872 Pointee = RT->getPointeeType();
8873 else if (const auto *MPT = getAs<MemberPointerType>())
8874 Pointee = MPT->getPointeeType();
8875 else if (const auto *DT = getAs<DecayedType>())
8876 Pointee = DT->getPointeeType();
8877 else
8878 return false;
8879 return Pointee->isCFIUncheckedCalleeFunctionType();
8880}
8881
8882inline bool Type::isFunctionPointerType() const {
8883 if (const auto *T = getAs<PointerType>())
8884 return T->getPointeeType()->isFunctionType();
8885 else
8886 return false;
8887}
8888
8890 if (const auto *T = getAs<ReferenceType>())
8891 return T->getPointeeType()->isFunctionType();
8892 else
8893 return false;
8894}
8895
8896inline bool Type::isMemberPointerType() const {
8897 return isa<MemberPointerType>(CanonicalType);
8898}
8899
8901 if (const auto *T = getAs<MemberPointerType>())
8902 return T->isMemberFunctionPointer();
8903 else
8904 return false;
8905}
8906
8908 if (const auto *T = getAs<MemberPointerType>())
8909 return T->isMemberDataPointer();
8910 else
8911 return false;
8912}
8913
8914inline bool Type::isArrayType() const {
8915 return isa<ArrayType>(CanonicalType);
8916}
8917
8918inline bool Type::isConstantArrayType() const {
8919 return isa<ConstantArrayType>(CanonicalType);
8920}
8921
8922inline bool Type::isIncompleteArrayType() const {
8923 return isa<IncompleteArrayType>(CanonicalType);
8924}
8925
8926inline bool Type::isVariableArrayType() const {
8927 return isa<VariableArrayType>(CanonicalType);
8928}
8929
8930inline bool Type::isArrayParameterType() const {
8931 return isa<ArrayParameterType>(CanonicalType);
8932}
8933
8935 return isa<DependentSizedArrayType>(CanonicalType);
8936}
8937
8938inline bool Type::isBuiltinType() const {
8939 return isa<BuiltinType>(CanonicalType);
8940}
8941
8942inline bool Type::isRecordType() const {
8943 return isa<RecordType>(CanonicalType);
8944}
8945
8946inline bool Type::isEnumeralType() const {
8947 return isa<EnumType>(CanonicalType);
8948}
8949
8950inline bool Type::isAnyComplexType() const {
8951 return isa<ComplexType>(CanonicalType);
8952}
8953
8954inline bool Type::isVectorType() const {
8955 return isa<VectorType>(CanonicalType);
8956}
8957
8958inline bool Type::isExtVectorType() const {
8959 return isa<ExtVectorType>(CanonicalType);
8960}
8961
8962inline bool Type::isExtVectorBoolType() const {
8963 if (!isExtVectorType())
8964 return false;
8965 return cast<ExtVectorType>(CanonicalType)->getElementType()->isBooleanType();
8966}
8967
8969 if (auto *CMT = dyn_cast<ConstantMatrixType>(CanonicalType))
8970 return CMT->getElementType()->isBooleanType();
8971 return false;
8972}
8973
8975 return isVectorType() || isSveVLSBuiltinType();
8976}
8977
8978inline bool Type::isMatrixType() const {
8979 return isa<MatrixType>(CanonicalType);
8980}
8981
8982inline bool Type::isConstantMatrixType() const {
8983 return isa<ConstantMatrixType>(CanonicalType);
8984}
8985
8986inline bool Type::isOverflowBehaviorType() const {
8987 return isa<OverflowBehaviorType>(CanonicalType);
8988}
8989
8991 return isa<DependentAddressSpaceType>(CanonicalType);
8992}
8993
8995 return isa<ObjCObjectPointerType>(CanonicalType);
8996}
8997
8998inline bool Type::isObjCObjectType() const {
8999 return isa<ObjCObjectType>(CanonicalType);
9000}
9001
9003 return isa<ObjCInterfaceType>(CanonicalType) ||
9004 isa<ObjCObjectType>(CanonicalType);
9005}
9006
9007inline bool Type::isAtomicType() const {
9008 return isa<AtomicType>(CanonicalType);
9009}
9010
9011inline bool Type::isUndeducedAutoType() const {
9012 return isa<AutoType>(CanonicalType);
9013}
9014
9015inline bool Type::isObjCQualifiedIdType() const {
9016 if (const auto *OPT = getAs<ObjCObjectPointerType>())
9017 return OPT->isObjCQualifiedIdType();
9018 return false;
9019}
9020
9022 if (const auto *OPT = getAs<ObjCObjectPointerType>())
9023 return OPT->isObjCQualifiedClassType();
9024 return false;
9025}
9026
9027inline bool Type::isObjCIdType() const {
9028 if (const auto *OPT = getAs<ObjCObjectPointerType>())
9029 return OPT->isObjCIdType();
9030 return false;
9031}
9032
9033inline bool Type::isObjCClassType() const {
9034 if (const auto *OPT = getAs<ObjCObjectPointerType>())
9035 return OPT->isObjCClassType();
9036 return false;
9037}
9038
9039inline bool Type::isObjCSelType() const {
9040 if (const auto *OPT = getAs<PointerType>())
9041 return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel);
9042 return false;
9043}
9044
9045inline bool Type::isObjCBuiltinType() const {
9046 return isObjCIdType() || isObjCClassType() || isObjCSelType();
9047}
9048
9049inline bool Type::isDecltypeType() const {
9050 return isa<DecltypeType>(this);
9051}
9052
9053#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
9054 inline bool Type::is##Id##Type() const { \
9055 return isSpecificBuiltinType(BuiltinType::Id); \
9056 }
9057#include "clang/Basic/OpenCLImageTypes.def"
9058
9059inline bool Type::isSamplerT() const {
9060 return isSpecificBuiltinType(BuiltinType::OCLSampler);
9061}
9062
9063inline bool Type::isEventT() const {
9064 return isSpecificBuiltinType(BuiltinType::OCLEvent);
9065}
9066
9067inline bool Type::isClkEventT() const {
9068 return isSpecificBuiltinType(BuiltinType::OCLClkEvent);
9069}
9070
9071inline bool Type::isQueueT() const {
9072 return isSpecificBuiltinType(BuiltinType::OCLQueue);
9073}
9074
9075inline bool Type::isReserveIDT() const {
9076 return isSpecificBuiltinType(BuiltinType::OCLReserveID);
9077}
9078
9079inline bool Type::isImageType() const {
9080#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() ||
9081 return
9082#include "clang/Basic/OpenCLImageTypes.def"
9083 false; // end boolean or operation
9084}
9085
9086inline bool Type::isPipeType() const {
9087 return isa<PipeType>(CanonicalType);
9088}
9089
9090inline bool Type::isBitIntType() const {
9091 return isa<BitIntType>(CanonicalType);
9092}
9093
9094#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
9095 inline bool Type::is##Id##Type() const { \
9096 return isSpecificBuiltinType(BuiltinType::Id); \
9097 }
9098#include "clang/Basic/OpenCLExtensionTypes.def"
9099
9101#define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \
9102 isOCLIntelSubgroupAVC##Id##Type() ||
9103 return
9104#include "clang/Basic/OpenCLExtensionTypes.def"
9105 false; // end of boolean or operation
9106}
9107
9108inline bool Type::isOCLExtOpaqueType() const {
9109#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() ||
9110 return
9111#include "clang/Basic/OpenCLExtensionTypes.def"
9112 false; // end of boolean or operation
9113}
9114
9115inline bool Type::isOpenCLSpecificType() const {
9116 return isSamplerT() || isEventT() || isImageType() || isClkEventT() ||
9118}
9119
9120#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
9121 inline bool Type::is##Id##Type() const { \
9122 return isSpecificBuiltinType(BuiltinType::Id); \
9123 }
9124#include "clang/Basic/HLSLIntangibleTypes.def"
9125
9126#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
9127 inline bool Type::is##Id##Type() const { \
9128 return isSpecificBuiltinType(BuiltinType::Id); \
9129 }
9130#include "clang/Basic/HLSLPackedTypes.def"
9131
9132#define SPIRV_TYPE(Name, Id, SingletonId) \
9133 inline bool Type::is##Id##Type() const { \
9134 return isSpecificBuiltinType(BuiltinType::Id); \
9135 }
9136#include "clang/Basic/SPIRVTypes.def"
9137
9139#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) is##Id##Type() ||
9140 return
9141#include "clang/Basic/HLSLIntangibleTypes.def"
9142 false;
9143}
9144
9146#define HLSL_PACKED_TYPE(Name, Id, SingletonId) is##Id##Type() ||
9147 return
9148#include "clang/Basic/HLSLPackedTypes.def"
9149 false;
9150}
9151
9156
9159}
9160
9161inline bool Type::isHLSLInlineSpirvType() const {
9162 return isa<HLSLInlineSpirvType>(this);
9163}
9164
9165inline bool Type::isTemplateTypeParmType() const {
9166 return isa<TemplateTypeParmType>(CanonicalType);
9167}
9168
9169inline bool Type::isSpecificBuiltinType(unsigned K) const {
9170 if (const BuiltinType *BT = getAs<BuiltinType>()) {
9171 return BT->getKind() == static_cast<BuiltinType::Kind>(K);
9172 }
9173 return false;
9174}
9175
9176inline bool Type::isPlaceholderType() const {
9177 if (const auto *BT = dyn_cast<BuiltinType>(this))
9178 return BT->isPlaceholderType();
9179 return false;
9180}
9181
9183 if (const auto *BT = dyn_cast<BuiltinType>(this))
9184 if (BT->isPlaceholderType())
9185 return BT;
9186 return nullptr;
9187}
9188
9189inline bool Type::isSpecificPlaceholderType(unsigned K) const {
9191 return isSpecificBuiltinType(K);
9192}
9193
9195 if (const auto *BT = dyn_cast<BuiltinType>(this))
9196 return BT->isNonOverloadPlaceholderType();
9197 return false;
9198}
9199
9200inline bool Type::isVoidType() const {
9201 return isSpecificBuiltinType(BuiltinType::Void);
9202}
9203
9204inline bool Type::isMetaInfoType() const {
9205 return isSpecificBuiltinType(BuiltinType::MetaInfo);
9206}
9207
9208inline bool Type::isHalfType() const {
9209 // FIXME: Should we allow complex __fp16? Probably not.
9210 return isSpecificBuiltinType(BuiltinType::Half);
9211}
9212
9213inline bool Type::isFloat16Type() const {
9214 return isSpecificBuiltinType(BuiltinType::Float16);
9215}
9216
9217inline bool Type::isFloat32Type() const {
9218 return isSpecificBuiltinType(BuiltinType::Float);
9219}
9220
9221inline bool Type::isDoubleType() const {
9222 return isSpecificBuiltinType(BuiltinType::Double);
9223}
9224
9225inline bool Type::isBFloat16Type() const {
9226 return isSpecificBuiltinType(BuiltinType::BFloat16);
9227}
9228
9229inline bool Type::isMFloat8Type() const {
9230 return isSpecificBuiltinType(BuiltinType::MFloat8);
9231}
9232
9233inline bool Type::isFloat128Type() const {
9234 return isSpecificBuiltinType(BuiltinType::Float128);
9235}
9236
9237inline bool Type::isIbm128Type() const {
9238 return isSpecificBuiltinType(BuiltinType::Ibm128);
9239}
9240
9241inline bool Type::isNullPtrType() const {
9242 return isSpecificBuiltinType(BuiltinType::NullPtr);
9243}
9244
9247
9248inline bool Type::isIntegerType() const {
9249 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
9250 return BT->isInteger();
9251 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
9252 // Incomplete enum types are not treated as integer types.
9253 // FIXME: In C++, enum types are never integer types.
9254 return IsEnumDeclComplete(ET->getDecl()) &&
9255 !IsEnumDeclScoped(ET->getDecl());
9256 }
9257
9258 if (const auto *OT = dyn_cast<OverflowBehaviorType>(CanonicalType))
9259 return OT->getUnderlyingType()->isIntegerType();
9260
9261 return isBitIntType();
9262}
9263
9264inline bool Type::isFixedPointType() const {
9265 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
9266 return BT->getKind() >= BuiltinType::ShortAccum &&
9267 BT->getKind() <= BuiltinType::SatULongFract;
9268 }
9269 return false;
9270}
9271
9273 return isFixedPointType() || isIntegerType();
9274}
9275
9279
9281 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
9282 return BT->getKind() >= BuiltinType::SatShortAccum &&
9283 BT->getKind() <= BuiltinType::SatULongFract;
9284 }
9285 return false;
9286}
9287
9291
9292inline bool Type::isSignedFixedPointType() const {
9293 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
9294 return ((BT->getKind() >= BuiltinType::ShortAccum &&
9295 BT->getKind() <= BuiltinType::LongAccum) ||
9296 (BT->getKind() >= BuiltinType::ShortFract &&
9297 BT->getKind() <= BuiltinType::LongFract) ||
9298 (BT->getKind() >= BuiltinType::SatShortAccum &&
9299 BT->getKind() <= BuiltinType::SatLongAccum) ||
9300 (BT->getKind() >= BuiltinType::SatShortFract &&
9301 BT->getKind() <= BuiltinType::SatLongFract));
9302 }
9303 return false;
9304}
9305
9308}
9309
9310inline bool Type::isScalarType() const {
9311 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
9312 return BT->getKind() > BuiltinType::Void &&
9313 BT->getKind() <= BuiltinType::NullPtr;
9314 if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
9315 // Enums are scalar types, but only if they are defined. Incomplete enums
9316 // are not treated as scalar types.
9317 return IsEnumDeclComplete(ET->getDecl());
9318 return isa<PointerType>(CanonicalType) ||
9319 isa<BlockPointerType>(CanonicalType) ||
9320 isa<MemberPointerType>(CanonicalType) ||
9321 isa<ComplexType>(CanonicalType) ||
9322 isa<ObjCObjectPointerType>(CanonicalType) ||
9324}
9325
9327 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
9328 return BT->isInteger();
9329
9330 // Check for a complete enum type; incomplete enum types are not properly an
9331 // enumeration type in the sense required here.
9332 if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
9333 return IsEnumDeclComplete(ET->getDecl());
9334
9335 if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
9336 return OBT->getUnderlyingType()->isIntegralOrEnumerationType();
9337
9338 return isBitIntType();
9339}
9340
9341inline bool Type::isBooleanType() const {
9342 if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
9343 return BT->getKind() == BuiltinType::Bool;
9344 return false;
9345}
9346
9347inline bool Type::isUndeducedType() const {
9348 auto *DT = getContainedDeducedType();
9349 return DT && !DT->isDeduced();
9350}
9351
9352/// Determines whether this is a type for which one can define
9353/// an overloaded operator.
9354inline bool Type::isOverloadableType() const {
9355 if (!isDependentType())
9356 return isRecordType() || isEnumeralType();
9357 return !isArrayType() && !isFunctionType() && !isAnyPointerType() &&
9359}
9360
9361/// Determines whether this type is written as a typedef-name.
9362inline bool Type::isTypedefNameType() const {
9363 if (getAs<TypedefType>())
9364 return true;
9365 if (auto *TST = getAs<TemplateSpecializationType>())
9366 return TST->isTypeAlias();
9367 return false;
9368}
9369
9370/// Determines whether this type can decay to a pointer type.
9371inline bool Type::canDecayToPointerType() const {
9372 return isFunctionType() || (isArrayType() && !isArrayParameterType());
9373}
9374
9379
9381 return isObjCObjectPointerType();
9382}
9383
9385 const Type *type = this;
9386 while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe())
9387 type = arrayType->getElementType().getTypePtr();
9388 return type;
9389}
9390
9392 const Type *type = this;
9393 if (type->isAnyPointerType())
9394 return type->getPointeeType().getTypePtr();
9395 else if (type->isArrayType())
9396 return type->getBaseElementTypeUnsafe();
9397 return type;
9398}
9399/// Insertion operator for partial diagnostics. This allows sending adress
9400/// spaces into a diagnostic with <<.
9402 LangAS AS) {
9403 PD.AddTaggedVal(llvm::to_underlying(AS),
9405 return PD;
9406}
9407
9408/// Insertion operator for partial diagnostics. This allows sending Qualifiers
9409/// into a diagnostic with <<.
9416
9417/// Insertion operator for partial diagnostics. This allows sending QualType's
9418/// into a diagnostic with <<.
9420 QualType T) {
9421 PD.AddTaggedVal(reinterpret_cast<uint64_t>(T.getAsOpaquePtr()),
9423 return PD;
9424}
9425
9426// Helper class template that is used by Type::getAs to ensure that one does
9427// not try to look through a qualified type to get to an array type.
9428template <typename T> using TypeIsArrayType = std::is_base_of<ArrayType, T>;
9429
9430// Member-template getAs<specific type>'.
9431template <typename T> const T *Type::getAs() const {
9432 static_assert(!TypeIsArrayType<T>::value,
9433 "ArrayType cannot be used with getAs!");
9434
9435 // If this is directly a T type, return it.
9436 if (const auto *Ty = dyn_cast<T>(this))
9437 return Ty;
9438
9439 // If the canonical form of this type isn't the right kind, reject it.
9440 if (!isa<T>(CanonicalType))
9441 return nullptr;
9442
9443 // If this is a typedef for the type, strip the typedef off without
9444 // losing all typedef information.
9446}
9447
9448template <typename T> const T *Type::getAsAdjusted() const {
9449 static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!");
9450
9451 // If this is directly a T type, return it.
9452 if (const auto *Ty = dyn_cast<T>(this))
9453 return Ty;
9454
9455 // If the canonical form of this type isn't the right kind, reject it.
9456 if (!isa<T>(CanonicalType))
9457 return nullptr;
9458
9459 // Strip off type adjustments that do not modify the underlying nature of the
9460 // type.
9461 const Type *Ty = this;
9462 while (Ty) {
9463 if (const auto *A = dyn_cast<AttributedType>(Ty))
9464 Ty = A->getModifiedType().getTypePtr();
9465 else if (const auto *A = dyn_cast<BTFTagAttributedType>(Ty))
9466 Ty = A->getWrappedType().getTypePtr();
9467 else if (const auto *A = dyn_cast<HLSLAttributedResourceType>(Ty))
9468 Ty = A->getWrappedType().getTypePtr();
9469 else if (const auto *P = dyn_cast<ParenType>(Ty))
9470 Ty = P->desugar().getTypePtr();
9471 else if (const auto *A = dyn_cast<AdjustedType>(Ty))
9472 Ty = A->desugar().getTypePtr();
9473 else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty))
9474 Ty = M->desugar().getTypePtr();
9475 else
9476 break;
9477 }
9478
9479 // Just because the canonical type is correct does not mean we can use cast<>,
9480 // since we may not have stripped off all the sugar down to the base type.
9481 return dyn_cast<T>(Ty);
9482}
9483
9485 // If this is directly an array type, return it.
9486 if (const auto *arr = dyn_cast<ArrayType>(this))
9487 return arr;
9488
9489 // If the canonical form of this type isn't the right kind, reject it.
9490 if (!isa<ArrayType>(CanonicalType))
9491 return nullptr;
9492
9493 // If this is a typedef for the type, strip the typedef off without
9494 // losing all typedef information.
9496}
9497
9498template <typename T> const T *Type::castAs() const {
9499 static_assert(!TypeIsArrayType<T>::value,
9500 "ArrayType cannot be used with castAs!");
9501
9502 if (const auto *ty = dyn_cast<T>(this)) return ty;
9503 assert(isa<T>(CanonicalType));
9505}
9506
9508 assert(isa<ArrayType>(CanonicalType));
9509 if (const auto *arr = dyn_cast<ArrayType>(this)) return arr;
9511}
9512
9513DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr,
9514 QualType CanonicalPtr)
9515 : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) {
9516#ifndef NDEBUG
9517 QualType Adjusted = getAdjustedType();
9518 (void)AttributedType::stripOuterNullability(Adjusted);
9519 assert(isa<PointerType>(Adjusted));
9520#endif
9521}
9522
9524 QualType Decayed = getDecayedType();
9525 (void)AttributedType::stripOuterNullability(Decayed);
9526 return cast<PointerType>(Decayed)->getPointeeType();
9527}
9528
9529// Get the decimal string representation of a fixed point type, represented
9530// as a scaled integer.
9531// TODO: At some point, we should change the arguments to instead just accept an
9532// APFixedPoint instead of APSInt and scale.
9533void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val,
9534 unsigned Scale);
9535
9536inline FunctionEffectsRef FunctionEffectsRef::get(QualType QT) {
9537 const Type *TypePtr = QT.getTypePtr();
9538 while (true) {
9539 if (QualType Pointee = TypePtr->getPointeeType(); !Pointee.isNull())
9540 TypePtr = Pointee.getTypePtr();
9541 else if (TypePtr->isArrayType())
9542 TypePtr = TypePtr->getBaseElementTypeUnsafe();
9543 else
9544 break;
9545 }
9546 if (const auto *FPT = TypePtr->getAs<FunctionProtoType>())
9547 return FPT->getFunctionEffects();
9548 return {};
9549}
9550
9551} // namespace clang
9552
9553#endif // LLVM_CLANG_AST_TYPE_BASE_H
#define V(N, I)
Provides definitions for the various language-specific address spaces.
Defines the clang::attr::Kind enum.
Defines the Diagnostic-related interfaces.
static bool isBooleanType(QualType Ty)
static bool isUnsigned(SValBuilder &SVB, NonLoc Value)
llvm::dxil::ResourceClass ResourceClass
static std::optional< NonLoc > getIndex(ProgramStateRef State, const ElementRegion *ER, CharKind CK)
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, clang::CharUnits CU)
Definition CharUnits.h:194
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
static Decl::Kind getKind(const Decl *D)
Defines the ExceptionSpecificationType enumeration and various utility functions.
static QualType getObjectType(APValue::LValueBase B)
Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size.
TokenType getType() const
Returns the token's type, e.g.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition MachO.h:31
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const OMPTraitInfo &TI)
static StringRef getIdentifier(const Token &Tok)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static QualType getUnderlyingType(const SubRegion *R)
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
Definition SemaCUDA.cpp:187
static RecordDecl * getAsRecordDecl(QualType BaseType, HeuristicResolver &Resolver)
static bool isRecordType(QualType T)
static bool isMatrixType(QualType QT)
static bool isParameterPack(Expr *PackExpression)
Defines the clang::SourceLocation class and associated facilities.
Defines various enumerations that describe declaration and type specifiers.
static QualType getPointeeType(const MemRegion *R)
Defines the clang::Visibility enumeration and various utility functions.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
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:8398
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
Definition TypeBase.h:8394
QualType getKey() const
Definition TypeBase.h:8396
QualType desugar() const
Definition TypeBase.h:8399
friend class ASTContext
Definition TypeBase.h:8384
static bool classof(const Type *T)
Definition TypeBase.h:8401
Attr - This represents one attribute.
Definition Attr.h:47
bool isSigned() const
Definition TypeBase.h:8447
static bool classof(const Type *T)
Definition TypeBase.h:8457
BitIntType(bool isUnsigned, unsigned NumBits)
Definition Type.cpp:548
bool isSugared() const
Definition TypeBase.h:8450
std::pair< unsigned, unsigned > getKey() const
Definition TypeBase.h:8453
friend class ASTContext
Definition TypeBase.h:8437
bool isUnsigned() const
Definition TypeBase.h:8446
unsigned getNumBits() const
Definition TypeBase.h:8448
QualType desugar() const
Definition TypeBase.h:8451
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:4644
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:4692
std::optional< LayoutKind > getLayout() const
Definition TypeBase.h:4646
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:4655
unsigned getNumRows() const
Returns the number of rows in the matrix.
Definition TypeBase.h:4641
unsigned getNumElementsFlattened() const
Returns the number of elements required to embed the matrix into a vector.
Definition TypeBase.h:4649
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:4669
std::optional< LayoutKind > Layout
Definition TypeBase.h:4629
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumRows, unsigned NumColumns, std::optional< LayoutKind > Layout, TypeClass TypeClass)
Definition TypeBase.h:4697
unsigned mapColumnMajorToRowMajorFlattenedIndex(unsigned ColumnMajorIdx) const
Given a column-major flattened index ColumnMajorIdx, return the equivalent row-major flattened index.
Definition TypeBase.h:4678
unsigned mapRowMajorToColumnMajorFlattenedIndex(unsigned RowMajorIdx) const
Given a row-major flattened index RowMajorIdx, return the equivalent column-major flattened index.
Definition TypeBase.h:4686
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:4661
unsigned NumRows
Number of rows and columns.
Definition TypeBase.h:4627
static bool classof(const Type *T)
Definition TypeBase.h:4707
ConstantMatrixType(QualType MatrixElementType, unsigned NRows, unsigned NColumns, QualType CanonElementType, std::optional< LayoutKind > Layout)
Definition Type.cpp:500
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:9523
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:1467
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:561
QualType desugar() const
Definition TypeBase.h:8473
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:8475
DependentBitIntType(bool IsUnsigned, Expr *NumBits)
Definition Type.cpp:552
static bool classof(const Type *T)
Definition TypeBase.h:8481
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:4734
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4728
static bool classof(const Type *T)
Definition TypeBase.h:4730
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:6497
DependentTypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind)
Definition TypeBase.h:6494
Expr * getSizeExpr() const
Definition TypeBase.h:4468
VectorKind getVectorKind() const
Definition TypeBase.h:4471
SourceLocation getAttributeLoc() const
Definition TypeBase.h:4470
QualType getElementType() const
Definition TypeBase.h:4469
QualType desugar() const
Definition TypeBase.h:4476
void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context)
Definition TypeBase.h:4482
static bool classof(const Type *T)
Definition TypeBase.h:4478
@ 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:5268
Expr * getCondition() const
Definition TypeBase.h:5275
bool operator==(const EffectConditionExpr &RHS) const
Definition TypeBase.h:5277
Represents an enum.
Definition Decl.h:4194
This represents one expression.
Definition Expr.h:114
We can encode up to four bits in the low bits of a type pointer, but there are many more type qualifi...
Definition TypeBase.h:1736
Qualifiers::ObjCLifetime getObjCLifetime() const
Definition TypeBase.h:1773
static void Profile(llvm::FoldingSetNodeID &ID, const Type *BaseType, Qualifiers Quals)
Definition TypeBase.h:1787
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:1783
ExtQuals(const Type *baseType, QualType canon, Qualifiers quals)
Definition TypeBase.h:1757
bool hasObjCGCAttr() const
Definition TypeBase.h:1769
Qualifiers::GC getObjCGCAttr() const
Definition TypeBase.h:1770
bool hasAddressSpace() const
Definition TypeBase.h:1777
const Type * getBaseType() const
Definition TypeBase.h:1780
Qualifiers getQualifiers() const
Definition TypeBase.h:1767
LangAS getAddressSpace() const
Definition TypeBase.h:1778
bool hasObjCLifetime() const
Definition TypeBase.h:1772
bool isSugared() const
Definition TypeBase.h:4556
bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const
Definition TypeBase.h:4550
friend class ASTContext
Definition TypeBase.h:4498
static int getNumericAccessorIdx(char c)
Definition TypeBase.h:4515
static bool classof(const Type *T)
Definition TypeBase.h:4559
static int getPointAccessorIdx(char c)
Definition TypeBase.h:4505
QualType desugar() const
Definition TypeBase.h:4557
static int getAccessorIdx(char c, bool isNumericAccessor)
Definition TypeBase.h:4543
Represents a function declaration or definition.
Definition Decl.h:2082
Support iteration in parallel through a pair of FunctionEffect and EffectConditionExpr containers.
Definition TypeBase.h:5301
bool operator==(const FunctionEffectIterator &Other) const
Definition TypeBase.h:5310
bool operator!=(const FunctionEffectIterator &Other) const
Definition TypeBase.h:5313
FunctionEffectIterator operator++()
Definition TypeBase.h:5317
FunctionEffectIterator(const Container &O, size_t I)
Definition TypeBase.h:5309
FunctionEffectWithCondition operator*() const
Definition TypeBase.h:5322
A mutable set of FunctionEffect::Kind.
Definition TypeBase.h:5402
static FunctionEffectKindSet difference(FunctionEffectKindSet LHS, FunctionEffectKindSet RHS)
Definition TypeBase.h:5474
bool contains(const FunctionEffect::Kind EK) const
Definition TypeBase.h:5469
FunctionEffectKindSet(FunctionEffectsRef FX)
Definition TypeBase.h:5456
void insert(FunctionEffectKindSet Set)
Definition TypeBase.h:5466
void insert(FunctionEffectsRef FX)
Definition TypeBase.h:5462
void insert(FunctionEffect Effect)
Definition TypeBase.h:5461
FunctionEffectSet(const FunctionEffectsRef &FX)
Definition TypeBase.h:5491
iterator end() const
Definition TypeBase.h:5500
size_t size() const
Definition TypeBase.h:5495
FunctionEffectIterator< FunctionEffectSet > iterator
Definition TypeBase.h:5497
bool insert(const FunctionEffectWithCondition &NewEC, Conflicts &Errs)
Definition Type.cpp:6006
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5516
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:5499
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:5161
Kind kind() const
The kind of the effect.
Definition TypeBase.h:5200
unsigned Flags
Flags describing some behaviors of the effect.
Definition TypeBase.h:5174
static constexpr size_t KindCount
Definition TypeBase.h:5171
friend bool operator<(FunctionEffect LHS, FunctionEffect RHS)
Definition TypeBase.h:5261
friend bool operator==(FunctionEffect LHS, FunctionEffect RHS)
Definition TypeBase.h:5255
uint32_t toOpaqueInt32() const
For serialization.
Definition TypeBase.h:5206
friend bool operator!=(FunctionEffect LHS, FunctionEffect RHS)
Definition TypeBase.h:5258
Kind
Identifies the particular effect.
Definition TypeBase.h:5164
Flags flags() const
Flags describing some behaviors of the effect.
Definition TypeBase.h:5212
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5943
static FunctionEffect fromOpaqueInt32(uint32_t Value)
Definition TypeBase.h:5207
friend raw_ostream & operator<<(raw_ostream &OS, const FunctionEffect &Effect)
Definition TypeBase.h:5232
An immutable set of FunctionEffects and possibly conditions attached to them.
Definition TypeBase.h:5348
ArrayRef< FunctionEffect > effects() const
Definition TypeBase.h:5381
iterator begin() const
Definition TypeBase.h:5386
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5382
static FunctionEffectsRef create(ArrayRef< FunctionEffect > FX, ArrayRef< EffectConditionExpr > Conds)
Asserts invariants.
Definition Type.cpp:6137
iterator end() const
Definition TypeBase.h:5387
FunctionEffectIterator< FunctionEffectsRef > iterator
Definition TypeBase.h:5384
friend bool operator==(const FunctionEffectsRef &LHS, const FunctionEffectsRef &RHS)
Definition TypeBase.h:5389
static FunctionEffectsRef get(QualType QT)
Extract the effects from a Type if it is a function, block, or member function pointer,...
Definition TypeBase.h:9536
friend bool operator!=(const FunctionEffectsRef &LHS, const FunctionEffectsRef &RHS)
Definition TypeBase.h:5393
static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, ExtInfo Info)
Definition TypeBase.h:5146
QualType desugar() const
Definition TypeBase.h:5140
static bool classof(const Type *T)
Definition TypeBase.h:5152
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:5142
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
QualType desugar() const
Definition TypeBase.h:6129
param_type_iterator param_type_begin() const
Definition TypeBase.h:5992
unsigned getNumFunctionEffectConditions() const
Definition TypeBase.h:6091
ExtParameterInfo getExtParameterInfo(unsigned I) const
Definition TypeBase.h:6052
ArrayRef< EffectConditionExpr > getFunctionEffectConditions() const
Definition TypeBase.h:6101
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
Definition TypeBase.h:5855
ArrayRef< FunctionEffect > getFunctionEffectsWithoutConditions() const
Definition TypeBase.h:6081
bool isParamConsumed(unsigned I) const
Definition TypeBase.h:6066
exception_iterator exception_end() const
Definition TypeBase.h:6011
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition TypeBase.h:6030
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:5826
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition TypeBase.h:5968
ExceptionSpecInfo getExceptionSpecInfo() const
Return all the available information about this type's exception spec.
Definition TypeBase.h:5881
const QualType * param_type_iterator
Definition TypeBase.h:5986
Qualifiers getMethodQuals() const
Definition TypeBase.h:5974
const QualType * exception_iterator
Definition TypeBase.h:6000
static bool classof(const Type *T)
Definition TypeBase.h:6134
QualType getParamType(unsigned i) const
Definition TypeBase.h:5828
FunctionEffectsRef getFunctionEffects() const
Definition TypeBase.h:6112
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
Definition TypeBase.h:6045
QualType getExceptionType(unsigned i) const
Return the ith exception type, where 0 <= i < getNumExceptions().
Definition TypeBase.h:5906
SourceLocation getEllipsisLoc() const
Definition TypeBase.h:5954
friend class ASTContext
Definition TypeBase.h:5549
unsigned getNumFunctionEffects() const
Definition TypeBase.h:6073
bool hasCFIUncheckedCallee() const
Definition TypeBase.h:5970
unsigned getNumExceptions() const
Return the number of types in the exception specification.
Definition TypeBase.h:5898
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
Definition TypeBase.h:5861
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:5864
bool hasNoexceptExceptionSpec() const
Return whether this function has a noexcept exception spec.
Definition TypeBase.h:5869
bool isVariadic() const
Whether this function prototype is variadic.
Definition TypeBase.h:5952
ExtProtoInfo getExtProtoInfo() const
Definition TypeBase.h:5837
Expr * getNoexceptExpr() const
Return the expression inside noexcept(expression), or a null pointer if there is none (because the ex...
Definition TypeBase.h:5913
param_type_iterator param_type_end() const
Definition TypeBase.h:5996
FunctionDecl * getExceptionSpecTemplate() const
If this function type has an uninstantiated exception specification, this is the function whose excep...
Definition TypeBase.h:5934
FunctionTypeExtraAttributeInfo getExtraAttributeInfo() const
Return the extra attribute information.
Definition TypeBase.h:6037
bool isNothrow(bool ResultIfDependent=false) const
Determine whether this function type has a non-throwing exception specification.
Definition TypeBase.h:5947
ArrayRef< QualType > getParamTypes() const
Definition TypeBase.h:5833
ArrayRef< QualType > exceptions() const
Definition TypeBase.h:6002
ParameterABI getParameterABI(unsigned I) const
Definition TypeBase.h:6059
ArrayRef< QualType > param_types() const
Definition TypeBase.h:5988
exception_iterator exception_begin() const
Definition TypeBase.h:6006
ArrayRef< ExtParameterInfo > getExtParameterInfos() const
Definition TypeBase.h:6021
bool hasExtParameterInfos() const
Is there any interesting extra information for any of the parameters of this function type?
Definition TypeBase.h:6017
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this function type.
Definition TypeBase.h:5982
FunctionDecl * getExceptionSpecDecl() const
If this function type has an exception specification which hasn't been determined yet (either because...
Definition TypeBase.h:5923
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4855
ExtInfo withNoCfCheck(bool noCfCheck) const
Definition TypeBase.h:4954
ExtInfo withCallingConv(CallingConv cc) const
Definition TypeBase.h:4967
CallingConv getCC() const
Definition TypeBase.h:4914
ExtInfo withProducesResult(bool producesResult) const
Definition TypeBase.h:4933
ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, bool producesResult, bool noCallerSavedRegs, bool NoCfCheck, bool cmseNSCall)
Definition TypeBase.h:4880
unsigned getRegParm() const
Definition TypeBase.h:4907
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:4971
bool getNoCallerSavedRegs() const
Definition TypeBase.h:4903
ExtInfo withNoReturn(bool noReturn) const
Definition TypeBase.h:4926
bool operator==(ExtInfo Other) const
Definition TypeBase.h:4916
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
Definition TypeBase.h:4947
ExtInfo withCmseNSCall(bool cmseNSCall) const
Definition TypeBase.h:4940
ExtInfo withRegParm(unsigned RegParm) const
Definition TypeBase.h:4961
bool operator!=(ExtInfo Other) const
Definition TypeBase.h:4919
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4770
friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition TypeBase.h:4826
friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs)
Definition TypeBase.h:4830
ExtParameterInfo withHasPassObjectSize() const
Definition TypeBase.h:4803
unsigned char getOpaqueValue() const
Definition TypeBase.h:4819
bool isConsumed() const
Is this parameter considered "consumed" by Objective-C ARC?
Definition TypeBase.h:4792
ParameterABI getABI() const
Return the ABI treatment of this parameter.
Definition TypeBase.h:4783
ExtParameterInfo withIsConsumed(bool consumed) const
Definition TypeBase.h:4793
ExtParameterInfo withIsNoEscape(bool NoEscape) const
Definition TypeBase.h:4810
ExtParameterInfo withABI(ParameterABI kind) const
Definition TypeBase.h:4784
static ExtParameterInfo getFromOpaqueValue(unsigned char data)
Definition TypeBase.h:4820
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4744
ExtInfo getExtInfo() const
Definition TypeBase.h:5100
AArch64SMETypeAttributes
The AArch64 SME ACLE (Arm C/C++ Language Extensions) define a number of function type attributes that...
Definition TypeBase.h:5020
static ArmStateValue getArmZT0State(unsigned AttrBits)
Definition TypeBase.h:5053
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
Definition TypeBase.h:5092
bool isConst() const
Definition TypeBase.h:5106
static ArmStateValue getArmZAState(unsigned AttrBits)
Definition TypeBase.h:5049
unsigned getRegParmType() const
Definition TypeBase.h:5087
CallingConv getCallConv() const
Definition TypeBase.h:5099
bool isRestrict() const
Definition TypeBase.h:5108
QualType getReturnType() const
Definition TypeBase.h:5084
FunctionType(TypeClass tc, QualType res, QualType Canonical, TypeDependence Dependence, ExtInfo Info)
Definition TypeBase.h:5070
static bool classof(const Type *T)
Definition TypeBase.h:5118
bool getCmseNSCallAttr() const
Definition TypeBase.h:5098
bool getHasRegParm() const
Definition TypeBase.h:5086
Qualifiers getFastTypeQuals() const
Definition TypeBase.h:5076
QualType getCallResultType(const ASTContext &Context) const
Determine the type of an expression that calls a function of this type.
Definition TypeBase.h:5112
bool isVolatile() const
Definition TypeBase.h:5107
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:6218
ElaboratedTypeKeyword getKeyword() const
Definition TypeBase.h:6224
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:6451
QualType getUnderlyingType() const
Definition TypeBase.h:6442
const IdentifierInfo * getMacroIdentifier() const
Definition TypeBase.h:6441
static bool isValidElementType(QualType T, const LangOptions &LangOpts)
Valid elements types are the following:
Definition TypeBase.h:4593
QualType getElementType() const
Returns type of the elements being stored in the matrix.
Definition TypeBase.h:4586
friend class ASTContext
Definition TypeBase.h:4569
QualType desugar() const
Definition TypeBase.h:4613
MatrixType(QualType ElementTy, QualType CanonElementTy)
bool isSugared() const
Definition TypeBase.h:4612
static bool classof(const Type *T)
Definition TypeBase.h:4615
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:276
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Represents an ObjC class declaration.
Definition DeclObjC.h:1160
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition TypeBase.h:8163
QualType desugar() const
Definition TypeBase.h:8179
friend class ASTContext
Definition TypeBase.h:8164
static bool classof(const Type *T)
Definition TypeBase.h:8181
Represents a pointer to an Objective C object.
Definition TypeBase.h:8219
unsigned getNumProtocols() const
Return the number of qualifying protocols on the object type.
Definition TypeBase.h:8351
bool isSpecialized() const
Whether this type is specialized, meaning that it has type arguments.
Definition TypeBase.h:8308
qual_iterator qual_end() const
Definition TypeBase.h:8344
bool isObjCQualifiedClassType() const
True if this is equivalent to 'Class.
Definition TypeBase.h:8300
QualType getKey() const
Definition TypeBase.h:8376
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Definition TypeBase.h:8294
bool isSpecializedAsWritten() const
Whether this type is specialized, meaning that it has type arguments.
Definition TypeBase.h:8311
bool isUnspecializedAsWritten() const
Determine whether this object type is "unspecialized" as written, meaning that it has no type argumen...
Definition TypeBase.h:8320
ArrayRef< QualType > getTypeArgsAsWritten() const
Retrieve the type arguments for this type.
Definition TypeBase.h:8328
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
Definition TypeBase.h:8256
ObjCObjectType::qual_iterator qual_iterator
An iterator over the qualifiers on the object type.
Definition TypeBase.h:8335
llvm::iterator_range< qual_iterator > qual_range
Definition TypeBase.h:8336
static bool classof(const Type *T)
Definition TypeBase.h:8378
bool isUnspecialized() const
Whether this type is unspecialized, meaning that is has no type arguments.
Definition TypeBase.h:8316
bool isObjCIdType() const
True if this is equivalent to the 'id' type, i.e.
Definition TypeBase.h:8277
ObjCProtocolDecl * getProtocol(unsigned I) const
Retrieve a qualifying protocol by index on the object type.
Definition TypeBase.h:8356
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Definition TypeBase.h:8231
ObjCInterfaceDecl * getInterfaceDecl() const
If this pointer points to an Objective @interface type, gets the declaration for that interface.
Definition TypeBase.h:8271
QualType desugar() const
Definition TypeBase.h:8361
qual_range quals() const
Definition TypeBase.h:8338
bool isObjCClassType() const
True if this is equivalent to the 'Class' type, i.e.
Definition TypeBase.h:8283
bool isObjCIdOrClassType() const
True if this is equivalent to the 'id' or 'Class' type,.
Definition TypeBase.h:8288
ArrayRef< QualType > getTypeArgs() const
Retrieve the type arguments for this type.
Definition TypeBase.h:8323
qual_iterator qual_begin() const
Definition TypeBase.h:8340
bool isKindOfType() const
Whether this is a "__kindof" type.
Definition TypeBase.h:8305
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:8422
bool isSugared() const
Definition TypeBase.h:8420
QualType getElementType() const
Definition TypeBase.h:8418
static bool classof(const Type *T)
Definition TypeBase.h:8428
friend class ASTContext
Definition TypeBase.h:8408
bool isReadOnly() const
Definition TypeBase.h:8432
std::pair< QualType, bool > getKey() const
Definition TypeBase.h:8424
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:8489
static bool classof(const Type *T)
Definition TypeBase.h:8512
QualType desugar() const
Definition TypeBase.h:8506
const IdentifierInfo * getIdentifier() const
Definition TypeBase.h:8510
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:8662
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
Definition TypeBase.h:8656
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:8709
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:8667
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:8578
LangAS getAddressSpace() const
Return the address space of this type.
Definition TypeBase.h:8704
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:8618
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:1826
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:8586
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:8763
QualType getCanonicalType() const
Definition TypeBase.h:8630
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition TypeBase.h:8672
void removeLocalVolatile()
Definition TypeBase.h:8694
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:1817
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:8599
bool UseExcessPrecision(const ASTContext &Ctx)
Definition Type.cpp:1775
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:8770
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:8732
bool isCanonicalAsParam() const
Definition TypeBase.h:8639
void removeLocalConst()
Definition TypeBase.h:8686
QualType stripNullability(const ASTContext &ctx) const
Strip nullability attributes from the given type.
Definition Type.cpp:1833
void removeLocalRestrict()
Definition TypeBase.h:8690
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:8679
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:8651
bool hasAddressSpace() const
Check if this type has any address space qualifier.
Definition TypeBase.h:8699
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:1810
unsigned getLocalFastQualifiers() const
Definition TypeBase.h:965
void removeLocalFastQualifiers()
Definition TypeBase.h:1209
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
Definition Type.cpp:1841
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:8635
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:8624
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:8582
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:8743
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:8610
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:8525
QualifierCollector(Qualifiers Qs=Qualifiers())
Definition TypeBase.h:8520
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:4508
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:3900
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:6482
TypeOfKind getKind() const
Returns the kind of 'typeof' type this is.
Definition TypeBase.h:6472
TypeOfExprType(const ASTContext &Context, Expr *E, TypeOfKind Kind, QualType Can=QualType())
Definition Type.cpp:4420
friend class ASTContext
Definition TypeBase.h:6463
Expr * getUnderlyingExpr() const
Definition TypeBase.h:6469
friend class ASTContext
Definition TypeBase.h:8552
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8560
void overrideType(QualType T)
Override the type stored in this TypeSourceInfo. Use with caution!
Definition TypeBase.h:8566
TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, QualType Canonical, TypeDependence Dependence)
Definition TypeBase.h:6236
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:9049
bool isDependentSizedArrayType() const
Definition TypeBase.h:8934
friend class ASTWriter
Definition TypeBase.h:2440
bool isFixedPointOrIntegerType() const
Return true if this is a fixed point or integer type.
Definition TypeBase.h:9272
bool isBlockPointerType() const
Definition TypeBase.h:8835
bool isVoidType() const
Definition TypeBase.h:9200
TypedefBitfields TypedefBits
Definition TypeBase.h:2383
UsingBitfields UsingBits
Definition TypeBase.h:2385
bool isBooleanType() const
Definition TypeBase.h:9341
bool isFunctionReferenceType() const
Definition TypeBase.h:8889
bool isSignableType(const ASTContext &Ctx) const
Definition TypeBase.h:8827
Type(const Type &)=delete
bool isObjCBuiltinType() const
Definition TypeBase.h:9045
const TemplateSpecializationType * getAsNonAliasTemplateSpecializationType() const
Look through sugar for an instance of TemplateSpecializationType which is not a type alias,...
Definition Type.cpp:2092
bool isMFloat8Type() const
Definition TypeBase.h:9229
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition TypeBase.h:9391
bool isIncompleteArrayType() const
Definition TypeBase.h:8922
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:9176
bool isFloat16Type() const
Definition TypeBase.h:9213
ReferenceTypeBitfields ReferenceTypeBits
Definition TypeBase.h:2389
bool isSignablePointerType() const
Definition TypeBase.h:8831
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:9507
static constexpr int NumDeducedTypeBits
Definition TypeBase.h:2163
Type(Type &&)=delete
bool isDependentAddressSpaceType() const
Definition TypeBase.h:8990
bool isUndeducedAutoType() const
Definition TypeBase.h:9011
bool isRValueReferenceType() const
Definition TypeBase.h:8847
bool isFundamentalType() const
Tests whether the type is categorized as a fundamental type.
Definition TypeBase.h:8778
VectorTypeBitfields VectorTypeBits
Definition TypeBase.h:2392
SubstPackTypeBitfields SubstPackTypeBits
Definition TypeBase.h:2395
bool isConstantArrayType() const
Definition TypeBase.h:8918
bool canDecayToPointerType() const
Determines whether this type can decay to a pointer type.
Definition TypeBase.h:9371
bool isArrayType() const
Definition TypeBase.h:8914
bool isFunctionPointerType() const
Definition TypeBase.h:8882
bool isHLSLInlineSpirvType() const
Definition TypeBase.h:9161
bool isConvertibleToFixedPointType() const
Return true if this can be converted to (or from) a fixed point type.
Definition TypeBase.h:9276
bool isArithmeticType() const
Definition Type.cpp:2550
PredefinedSugarTypeBitfields PredefinedSugarTypeBits
Definition TypeBase.h:2399
bool isConstantMatrixType() const
Definition TypeBase.h:8982
bool isHLSLBuiltinIntangibleType() const
Definition TypeBase.h:9138
bool isPointerType() const
Definition TypeBase.h:8815
const TemplateSpecializationType * castAsNonAliasTemplateSpecializationType() const
Definition TypeBase.h:3028
bool isArrayParameterType() const
Definition TypeBase.h:8930
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:9248
bool isObjCSelType() const
Definition TypeBase.h:9039
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9498
BuiltinTypeBitfields BuiltinTypeBits
Definition TypeBase.h:2386
bool isSpecificPlaceholderType(unsigned K) const
Test for a specific placeholder type.
Definition TypeBase.h:9189
bool isReferenceType() const
Definition TypeBase.h:8839
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:9292
bool isObjectPointerType() const
Definition TypeBase.h:8851
bool isEnumeralType() const
Definition TypeBase.h:8946
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:9310
bool isVariableArrayType() const
Definition TypeBase.h:8926
bool isFloat128Type() const
Definition TypeBase.h:9233
bool isClkEventT() const
Definition TypeBase.h:9067
bool isSveVLSBuiltinType() const
Determines if this is a sizeless type supported by the 'arm_sve_vector_bits' type attribute,...
Definition Type.cpp:2829
CountAttributedTypeBitfields CountAttributedTypeBits
Definition TypeBase.h:2398
bool isObjCQualifiedIdType() const
Definition TypeBase.h:9015
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:885
LinkageInfo getLinkageAndVisibility() const
Determine the linkage and visibility of this type.
Definition Type.cpp:5321
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Definition TypeBase.h:9326
bool isExtVectorType() const
Definition TypeBase.h:8958
friend class ASTReader
Definition TypeBase.h:2439
bool isExtVectorBoolType() const
Definition TypeBase.h:8962
Type & operator=(const Type &)=delete
bool isObjCObjectOrInterfaceType() const
Definition TypeBase.h:9002
bool isImageType() const
Definition TypeBase.h:9079
bool isNonOverloadPlaceholderType() const
Test for a placeholder type other than Overload; see BuiltinType::isNonOverloadPlaceholderType.
Definition TypeBase.h:9194
bool isOCLIntelSubgroupAVCType() const
Definition TypeBase.h:9100
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:9086
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:8907
bool isLValueReferenceType() const
Definition TypeBase.h:8843
bool isBitIntType() const
Definition TypeBase.h:9090
bool isSpecificBuiltinType(unsigned K) const
Test for a particular builtin type.
Definition TypeBase.h:9169
bool isBuiltinType() const
Helper methods to distinguish type categories.
Definition TypeBase.h:8938
bool isOpenCLSpecificType() const
Definition TypeBase.h:9115
bool isConstantMatrixBoolType() const
Definition TypeBase.h:8968
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:9217
TypeBitfields TypeBits
Definition TypeBase.h:2376
bool isAnyComplexType() const
Definition TypeBase.h:8950
bool isFixedPointType() const
Return true if this is a fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition TypeBase.h:9264
bool isHalfType() const
Definition TypeBase.h:9208
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:2235
bool isSaturatedFixedPointType() const
Return true if this is a saturated fixed point type according to ISO/IEC JTC1 SC22 WG14 N1169.
Definition TypeBase.h:9280
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:8867
const BuiltinType * getAsPlaceholderType() const
Definition TypeBase.h:9182
QualType getCanonicalTypeInternal() const
Definition TypeBase.h:3200
friend class ASTContext
Definition TypeBase.h:2411
bool isHLSLSpecificType() const
Definition TypeBase.h:9152
bool isTemplateTypeParmType() const
Definition TypeBase.h:9165
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:9071
bool isCompoundType() const
Tests whether the type is categorized as a compound type.
Definition TypeBase.h:8789
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:9384
bool isMemberPointerType() const
Definition TypeBase.h:8896
bool isAtomicType() const
Definition TypeBase.h:9007
AttributedTypeBitfields AttributedTypeBits
Definition TypeBase.h:2379
bool isFunctionProtoType() const
Definition TypeBase.h:2665
bool isIbm128Type() const
Definition TypeBase.h:9237
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9354
bool isObjCIdType() const
Definition TypeBase.h:9027
bool isMatrixType() const
Definition TypeBase.h:8978
TagTypeBitfields TagTypeBits
Definition TypeBase.h:2391
bool isOverflowBehaviorType() const
Definition TypeBase.h:8986
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:9288
UnresolvedUsingBitfields UnresolvedUsingBits
Definition TypeBase.h:2384
bool isObjCObjectType() const
Definition TypeBase.h:8998
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:9484
bool isHLSLBuiltinPackedType() const
Definition TypeBase.h:9145
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Definition TypeBase.h:9347
bool isObjectType() const
Determine whether this type is an object type.
Definition TypeBase.h:2574
bool isEventT() const
Definition TypeBase.h:9063
bool isDoubleType() const
Definition TypeBase.h:9221
bool isPointerOrReferenceType() const
Definition TypeBase.h:8819
bool isMetaInfoType() const
Definition TypeBase.h:9204
Type * this_()
Definition TypeBase.h:2430
KeywordWrapperBitfields KeywordWrapperBits
Definition TypeBase.h:2390
FunctionTypeBitfields FunctionTypeBits
Definition TypeBase.h:2387
bool isBFloat16Type() const
Definition TypeBase.h:9225
void setDependence(TypeDependence D)
Definition TypeBase.h:2432
const T * getAsAdjusted() const
Member-template getAsAdjusted<specific type>.
Definition TypeBase.h:9448
bool isFunctionType() const
Definition TypeBase.h:8811
bool isObjCObjectPointerType() const
Definition TypeBase.h:8994
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:8900
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:9306
bool isVectorType() const
Definition TypeBase.h:8954
bool isObjCQualifiedClassType() const
Definition TypeBase.h:9021
bool isObjCClassType() const
Definition TypeBase.h:9033
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:2533
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:9157
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:9108
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:8823
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:8974
bool isSamplerT() const
Definition TypeBase.h:9059
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9431
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition Type.cpp:786
bool isNullPtrType() const
Definition TypeBase.h:9241
bool isRecordType() const
Definition TypeBase.h:8942
TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits
Definition TypeBase.h:2396
bool isTypedefNameType() const
Determines whether this type is written as a typedef-name.
Definition TypeBase.h:9362
static constexpr int FunctionTypeNumParamsWidth
Definition TypeBase.h:1983
@ NumTypeWithKeywordBits
Definition TypeBase.h:2105
bool isUnionType() const
Definition Type.cpp:851
bool isFunctionNoProtoType() const
Definition TypeBase.h:2664
bool isReserveIDT() const
Definition TypeBase.h:9075
bool hasObjCPointerRepresentation() const
Whether this type can represent an objective pointer type for the purpose of GC'ability.
Definition TypeBase.h:9380
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
Definition TypeBase.h:9375
DeducedTypeBitfields DeducedTypeBits
Definition TypeBase.h:2380
AutoTypeBitfields AutoTypeBits
Definition TypeBase.h:2381
bool isCFIUncheckedCalleeFunctionType() const
Definition TypeBase.h:8861
Type & operator=(Type &&)=delete
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3745
TypedefNameDecl * getDecl() const
Definition TypeBase.h:6392
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6387
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:6402
friend class ASTContext
Definition TypeBase.h:6362
static bool classof(const Type *T)
Definition TypeBase.h:6421
bool typeMatchesDecl() const
Definition TypeBase.h:6400
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:6416
bool isSugared() const
Definition TypeBase.h:6394
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:6309
QualType desugar() const
Definition TypeBase.h:6298
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6289
UnresolvedUsingTypenameDecl * getDecl() const
Definition TypeBase.h:6295
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UnresolvedUsingTypenameDecl *D)
Definition TypeBase.h:6300
static bool classof(const Type *T)
Definition TypeBase.h:6313
Represents a dependent using declaration which was marked with typename.
Definition DeclCXX.h:4084
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3446
UsingShadowDecl * getDecl() const
Definition TypeBase.h:6335
QualType desugar() const
Definition TypeBase.h:6337
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:6350
NestedNameSpecifier getQualifier() const
Definition TypeBase.h:6331
friend class ASTContext
Definition TypeBase.h:6324
static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UsingShadowDecl *D, QualType UnderlyingType)
Definition TypeBase.h:6340
bool isSugared() const
Definition TypeBase.h:6338
static bool classof(const Type *T)
Definition TypeBase.h:6353
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
static bool classof(const Type *T)
Definition TypeBase.h: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:4413
VectorType(QualType vecType, unsigned nElements, QualType canonType, VectorKind vecKind)
Definition Type.cpp:531
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:4429
bool isSugared() const
Definition TypeBase.h:4415
friend class ASTContext
Definition TypeBase.h:4400
static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, unsigned NumElements, TypeClass TypeClass, VectorKind VecKind)
Definition TypeBase.h:4434
unsigned getRVVFixedLengthMaskLanes() const
Return the number of lanes of an RVV fixed-length mask vector.
Definition TypeBase.h:4424
VectorKind getVectorKind() const
Definition TypeBase.h:4418
QualType ElementType
The element type of the vector.
Definition TypeBase.h:4403
QualType desugar() const
Definition TypeBase.h:4416
QualType getElementType() const
Definition TypeBase.h:4412
static bool classof(const Type *T)
Definition TypeBase.h:4443
Code completion in a.
Defines the Linkage enumeration and various utility functions.
Definition SPIR.cpp:47
mlir::Type getBaseType(mlir::Value varPtr)
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
bool operator!=(const CommonEntityInfo &LHS, const CommonEntityInfo &RHS)
Definition Types.h:171
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
uint32_t Literal
Literals are represented as positive integers.
Definition CNFFormula.h:35
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool operator==(const ValueType &a, const ValueType &b)
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition TokenKinds.h:109
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
VectorKind getRVVFixedLengthDataVectorKind(int LMulLog2)
Inverse of getRVVFixedLengthDataLMulLog2().
Definition TypeBase.h:4330
@ Overload
This is a legitimate overload: the existing declarations are functions or function templates with dif...
Definition Sema.h:819
bool isa(CodeGen::Address addr)
Definition Address.h:330
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1838
@ GNUAutoType
__auto_type (GNU extension)
Definition TypeBase.h:1846
@ DecltypeAuto
decltype(auto)
Definition TypeBase.h:1843
bool isTargetAddressSpace(LangAS AS)
bool isRVVFixedLengthDataVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length data vector kinds, i.e.
Definition TypeBase.h:4316
CanThrowResult
Possible results from evaluation of a noexcept expression.
FunctionType::ExtInfo getFunctionExtInfo(const Type &t)
Definition TypeBase.h:8713
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
VectorKind getRVVFixedLengthMaskVectorKind(unsigned RatioLog2, unsigned SubByteLanes)
Inverse of getRVVFixedLengthMaskRatioLog2() and getRVVFixedLengthMaskSubByteLanes().
Definition TypeBase.h:4382
bool IsEnumDeclComplete(EnumDecl *ED)
Check if the given decl is complete.
Definition Decl.h:5557
ExprDependence computeDependence(FullExpr *E)
@ Vector
'vector' clause, allowed on 'loop', Combined, and 'routine' directives.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:919
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
Definition CallGraph.h:218
unsigned getRVVFixedLengthMaskRatioLog2(VectorKind VK)
Return log2 of the R of the vbool<R>_t type recorded in an RVV fixed-length mask vector kind: Ratio1 ...
Definition TypeBase.h:4345
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
TypeDependence toTypeDependence(ExprDependence D)
StringRef getRVVFixedLengthString(VectorKind VK)
Return the LMUL of an RVV fixed-length data vector kind, "mf8" .
Definition TypeBase.h:4359
bool isRVVFixedLengthVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length data or mask vector kinds.
Definition TypeBase.h:4352
@ 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
unsigned getRVVFixedLengthMaskSubByteLanes(VectorKind VK)
Return the number of lanes (1, 2 or 4) of an RVV fixed-length mask vector kind that fits in less than...
Definition TypeBase.h:4372
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:6171
constexpr unsigned PointerAuthKeyNone
int getRVVFixedLengthDataLMulLog2(VectorKind VK)
Return log2 of the LMUL recorded in an RVV fixed-length data vector kind: MF8 -> -3,...
Definition TypeBase.h:4323
bool IsEnumDeclScoped(EnumDecl *ED)
Check if the given decl is scoped.
Definition Decl.h:5567
std::is_base_of< ArrayType, T > TypeIsArrayType
Definition TypeBase.h:9428
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:555
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
@ RVVFixedLengthMaskRatio1
is RISC-V RVV fixed-length mask vector of vbool<R>_t; the _<L> kinds have only L lanes in a single by...
Definition TypeBase.h:4268
@ RVVFixedLengthData_MF8
is RISC-V RVV fixed-length data vector
Definition TypeBase.h:4258
@ 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
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6146
@ Interface
The "__interface" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6151
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6167
@ Struct
The "struct" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6148
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6157
@ Union
The "union" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6154
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6160
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6164
TypeDependence toSyntacticDependence(TypeDependence D)
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DependentNoexcept
noexcept(expression), value-dependent
@ EST_Uninstantiated
not instantiated yet
@ EST_Unparsed
not parsed yet
@ EST_NoThrow
Microsoft __declspec(nothrow) extension.
@ EST_None
no exception specification
@ EST_MSAny
Microsoft throw(...) extension.
@ EST_BasicNoexcept
noexcept
@ EST_NoexceptFalse
noexcept(expression), evals to 'false'
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_NoexceptTrue
noexcept(expression), evals to 'true'
@ EST_Dynamic
throw(T1, T2)
OptionalUnsigned< NullabilityKind > NullabilityKindOrNone
Definition Specifiers.h:366
bool isRVVFixedLengthMaskVectorKind(VectorKind VK)
True if VK is one of the RVV fixed-length mask vector kinds, i.e.
Definition TypeBase.h:4338
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...
__builtin_riscv_nclipru_u32 int64_t
__builtin_riscv_nclipru_u32 __builtin_riscv_nclip_i32 int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 uint8_t
__builtin_riscv_nclipru_u32 __builtin_riscv_nclip_i32 int32_t uint32_t uint32_t __builtin_riscv_mhacc_i32 __builtin_riscv_mhaccu_u32 __builtin_riscv_mhaccsu_i32 __builtin_riscv_mulq_i32 __builtin_riscv_mqwacc_i64 __packed_splat4 uint16_t
#define false
Definition stdbool.h:26
void Profile(llvm::FoldingSetNodeID &ID)
Definition TypeBase.h:6242
const T * getType() const
Definition TypeBase.h:6244
FunctionEffectWithCondition Rejected
Definition TypeBase.h:5514
FunctionEffectWithCondition Kept
Definition TypeBase.h:5513
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5285
FunctionEffectWithCondition(FunctionEffect E, const EffectConditionExpr &C)
Definition TypeBase.h:5289
Holds information about the various types of exception specification.
Definition TypeBase.h:5605
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition TypeBase.h:5617
ExceptionSpecInfo(ExceptionSpecificationType EST)
Definition TypeBase.h:5625
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5621
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5607
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5610
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5613
Extra information about a function prototype.
Definition TypeBase.h:5633
FunctionTypeExtraAttributeInfo ExtraAttributeInfo
Definition TypeBase.h:5641
bool requiresFunctionProtoTypeArmAttributes() const
Definition TypeBase.h:5679
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5638
bool requiresFunctionProtoTypeExtraAttributeInfo() const
Definition TypeBase.h:5683
ExtProtoInfo withCFIUncheckedCallee(bool CFIUncheckedCallee)
Definition TypeBase.h:5666
bool requiresFunctionProtoTypeExtraBitfields() const
Definition TypeBase.h:5672
void setArmSMEAttribute(AArch64SMETypeAttributes Kind, bool Enable=true)
Definition TypeBase.h:5687
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition TypeBase.h:5660
A simple holder for a QualType representing a type in an exception specification.
Definition TypeBase.h:4979
unsigned AArch64SMEAttributes
Any AArch64 SME ACLE type attributes that need to be propagated on declarations and function pointers...
Definition TypeBase.h:5064
A holder for extra information from attributes which aren't part of an AttributedType.
Definition TypeBase.h:5008
StringRef CFISalt
A CFI "salt" that differentiates functions with the same prototype.
Definition TypeBase.h:5010
void Profile(llvm::FoldingSetNodeID &ID) const
Definition TypeBase.h:5014
unsigned NumExceptionType
The number of types in the exception specification.
Definition TypeBase.h:4988
Provides a few static helpers for converting and printing elaborated type keyword and tag type kind e...
Definition TypeBase.h:6190
static StringRef getTagTypeKindName(TagTypeKind Kind)
Definition TypeBase.h:6210
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:238
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:8571
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