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