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