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