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