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