17#ifndef LLVM_CLANG_AST_TYPE_H
18#define LLVM_CLANG_AST_TYPE_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/ErrorHandling.h"
48#include "llvm/Support/PointerLikeTypeTraits.h"
49#include "llvm/Support/TrailingObjects.h"
50#include "llvm/Support/type_traits.h"
68class TemplateParameterList;
76namespace serialization {
77 template <
class T>
class AbstractTypeReader;
114template <
typename>
class CanQual;
119class ExtQualsTypeCommonBase;
121class FunctionEffectSet;
124class ObjCInterfaceDecl;
125class ObjCProtocolDecl;
126class ObjCTypeParamDecl;
127struct PrintingPolicy;
131class TemplateArgument;
132class TemplateArgumentListInfo;
133class TemplateArgumentLoc;
134class TemplateTypeParmDecl;
135class TypedefNameDecl;
136class UnresolvedUsingTypenameDecl;
137class UsingShadowDecl;
142#define TYPE(Class, Base) class Class##Type;
143#include "clang/AST/TypeNodes.inc"
150 EnabledMask = 1 << EnabledShift,
151 AddressDiscriminatedShift = EnabledShift + EnabledBits,
152 AddressDiscriminatedBits = 1,
153 AddressDiscriminatedMask = 1 << AddressDiscriminatedShift,
154 AuthenticationModeShift =
155 AddressDiscriminatedShift + AddressDiscriminatedBits,
156 AuthenticationModeBits = 2,
157 AuthenticationModeMask = ((1 << AuthenticationModeBits) - 1)
158 << AuthenticationModeShift,
159 IsaPointerShift = AuthenticationModeShift + AuthenticationModeBits,
161 IsaPointerMask = ((1 << IsaPointerBits) - 1) << IsaPointerShift,
162 AuthenticatesNullValuesShift = IsaPointerShift + IsaPointerBits,
163 AuthenticatesNullValuesBits = 1,
164 AuthenticatesNullValuesMask = ((1 << AuthenticatesNullValuesBits) - 1)
165 << AuthenticatesNullValuesShift,
166 KeyShift = AuthenticatesNullValuesShift + AuthenticatesNullValuesBits,
168 KeyMask = ((1 << KeyBits) - 1) << KeyShift,
169 DiscriminatorShift = KeyShift + KeyBits,
170 DiscriminatorBits = 16,
171 DiscriminatorMask = ((1u << DiscriminatorBits) - 1) << DiscriminatorShift,
182 static_assert((EnabledBits + AddressDiscriminatedBits +
183 AuthenticationModeBits + IsaPointerBits +
184 AuthenticatesNullValuesBits + KeyBits + DiscriminatorBits) ==
186 "PointerAuthQualifier should be exactly 32 bits");
187 static_assert((EnabledMask + AddressDiscriminatedMask +
188 AuthenticationModeMask + IsaPointerMask +
189 AuthenticatesNullValuesMask + KeyMask + DiscriminatorMask) ==
191 "All masks should cover the entire bits");
192 static_assert((EnabledMask ^ AddressDiscriminatedMask ^
193 AuthenticationModeMask ^ IsaPointerMask ^
194 AuthenticatesNullValuesMask ^ KeyMask ^ DiscriminatorMask) ==
196 "All masks should cover the entire bits");
199 unsigned ExtraDiscriminator,
201 bool IsIsaPointer,
bool AuthenticatesNullValues)
203 (IsAddressDiscriminated
204 ? llvm::to_underlying(AddressDiscriminatedMask)
207 (llvm::to_underlying(AuthenticationMode)
208 << AuthenticationModeShift) |
209 (ExtraDiscriminator << DiscriminatorShift) |
210 (IsIsaPointer << IsaPointerShift) |
211 (AuthenticatesNullValues << AuthenticatesNullValuesShift)) {
214 assert((
Data == 0) ==
233 Create(
unsigned Key,
bool IsAddressDiscriminated,
unsigned ExtraDiscriminator,
235 bool AuthenticatesNullValues) {
240 AuthenticationMode, IsIsaPointer,
241 AuthenticatesNullValues);
245 assert((
Data == 0) ==
254 return (
Data & KeyMask) >> KeyShift;
261 return (
Data & AddressDiscriminatedMask) >> AddressDiscriminatedShift;
266 return (
Data >> DiscriminatorShift);
271 AuthenticationModeShift);
276 return (
Data & IsaPointerMask) >> IsaPointerShift;
281 return (
Data & AuthenticatesNullValuesMask) >> AuthenticatesNullValuesShift;
289 return Lhs.Data == Rhs.Data;
292 return Lhs.Data != Rhs.Data;
305 assert((
Result.Data == 0) ==
385 Q.Mask = L.Mask & R.Mask;
479 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
480 Mask = (Mask & ~CVRMask) | mask;
483 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
484 Mask &= ~static_cast<uint64_t>(mask);
490 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
494 assert(!(mask & ~
CVRMask & ~UMask) &&
"bitmask contains non-CVRU bits");
500 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
508 Mask = (Mask & ~GCAttrMask) | (
type << GCAttrShift);
533 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
536 Mask = (Mask & ~LifetimeMask) | (
type << LifetimeShift);
542 Mask |= (
type << LifetimeShift);
559 return static_cast<LangAS>(Mask >> AddressSpaceShift);
580 Mask = (Mask & ~AddressSpaceMask)
581 | (((uint32_t) space) << AddressSpaceShift);
594 Mask = (Mask & ~PtrAuthMask) |
608 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
609 Mask = (Mask & ~FastMask) | mask;
612 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
613 Mask &= ~static_cast<uint64_t>(mask);
619 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
634 bool empty()
const {
return !Mask; }
807 bool appendSpaceIfNonEmpty =
false)
const;
809 void Profile(llvm::FoldingSetNodeID &
ID)
const {
ID.AddInteger(Mask); }
816 "PointerAuthQualifier must be 32 bits");
818 static constexpr uint64_t UMask = 0x8;
819 static constexpr uint64_t UShift = 3;
820 static constexpr uint64_t GCAttrMask = 0x30;
821 static constexpr uint64_t GCAttrShift = 4;
822 static constexpr uint64_t LifetimeMask = 0x1C0;
823 static constexpr uint64_t LifetimeShift = 6;
824 static constexpr uint64_t AddressSpaceMask =
825 ~(
CVRMask | UMask | GCAttrMask | LifetimeMask);
826 static constexpr uint64_t AddressSpaceShift = 9;
827 static constexpr uint64_t PtrAuthShift = 32;
828 static constexpr uint64_t PtrAuthMask = uint64_t(0xffffffff) << PtrAuthShift;
838 : Quals(Quals), HasAtomic(HasAtomic) {}
887 std::pair<const Type *,Qualifiers>
asPair()
const {
888 return std::pair<const Type *, Qualifiers>(
Ty,
Quals);
892 return a.
Ty ==
b.Ty && a.
Quals ==
b.Quals;
895 return a.
Ty !=
b.Ty || a.
Quals !=
b.Quals;
945 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
948 const ExtQuals *getExtQualsUnsafe()
const {
952 const Type *getTypePtrUnsafe()
const {
953 return Value.getPointer().get<
const Type*>();
956 const ExtQualsTypeCommonBase *getCommonPtr()
const {
957 assert(!
isNull() &&
"Cannot retrieve a NULL type pointer");
958 auto CommonPtrVal =
reinterpret_cast<uintptr_t>(
Value.getOpaqueValue());
960 return reinterpret_cast<ExtQualsTypeCommonBase*
>(CommonPtrVal);
992 T.Value.setFromOpaqueValue(
const_cast<void*
>(Ptr));
1009 return Value.getPointer().isNull();
1036 std::optional<NonConstantStorageReason>
1192 &&
"non-fast qualifier bits set in mask!");
1210 T.addFastQualifiers(TQs);
1223 T.removeLocalFastQualifiers();
1317 return getSingleStepDesugaredTypeImpl(*
this, Context);
1323 if (isa<ParenType>(*
this))
1330 return LHS.Value == RHS.Value;
1333 return LHS.Value != RHS.Value;
1336 return LHS.Value < RHS.Value;
1350 const Twine &PlaceHolder = Twine(),
1351 unsigned Indentation = 0)
const;
1355 unsigned Indentation = 0) {
1361 const Twine &PlaceHolder,
1362 unsigned Indentation = 0);
1379 const Twine &PlaceHolder;
1380 unsigned Indentation;
1384 const Twine &PlaceHolder,
unsigned Indentation)
1385 :
T(
T), Policy(Policy), PlaceHolder(PlaceHolder),
1386 Indentation(Indentation) {}
1390 SQT.T.
print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1396 const Twine &PlaceHolder = Twine(),
1397 unsigned Indentation = 0)
const {
1401 void dump(
const char *
s)
const;
1403 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
1543 return isDestructedTypeImpl(*
this);
1645raw_ostream &
operator<<(raw_ostream &OS, QualType QT);
1665 return P.getAsOpaquePtr();
1673 static constexpr int NumLowBitsAvailable = 0;
1693 const Type *
const BaseType;
1699 : BaseType(baseType), CanonicalType(canon) {}
1713 public llvm::FoldingSetNode {
1736 canon.isNull() ?
QualType(this_(), 0) : canon),
1738 assert(Quals.hasNonFastQualifiers()
1739 &&
"ExtQuals created with no fast qualifiers");
1740 assert(!Quals.hasFastQualifiers()
1741 &&
"ExtQuals created with fast qualifiers");
1751 return Quals.getObjCLifetime();
1761 Profile(
ID, getBaseType(), Quals);
1765 const Type *BaseType,
1768 ID.AddPointer(BaseType);
1799enum class ArraySizeModifier;
1800enum class ElaboratedTypeKeyword;
1801enum class VectorKind;
1832#define TYPE(Class, Base) Class,
1833#define LAST_TYPE(Class) TypeLast = Class
1834#define ABSTRACT_TYPE(Class, Base)
1835#include "clang/AST/TypeNodes.inc"
1840 class TypeBitfields {
1842 template <
class T>
friend class TypePropertyCache;
1845 LLVM_PREFERRED_TYPE(TypeClass)
1850 unsigned Dependence : llvm::BitWidth<TypeDependence>;
1854 LLVM_PREFERRED_TYPE(
bool)
1855 mutable unsigned CacheValid : 1;
1859 mutable unsigned CachedLinkage : 3;
1862 LLVM_PREFERRED_TYPE(
bool)
1863 mutable unsigned CachedLocalOrUnnamed : 1;
1866 LLVM_PREFERRED_TYPE(
bool)
1867 mutable unsigned FromAST : 1;
1869 bool isCacheValid()
const {
1874 assert(isCacheValid() &&
"getting linkage from invalid cache");
1875 return static_cast<Linkage>(CachedLinkage);
1878 bool hasLocalOrUnnamedType()
const {
1879 assert(isCacheValid() &&
"getting linkage from invalid cache");
1880 return CachedLocalOrUnnamed;
1883 enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1892 LLVM_PREFERRED_TYPE(TypeBitfields)
1898 unsigned IndexTypeQuals : 3;
1903 unsigned SizeModifier : 3;
1905 enum { NumArrayTypeBits = NumTypeBits + 6 };
1914 LLVM_PREFERRED_TYPE(
bool)
1915 unsigned HasExternalSize : 1;
1917 LLVM_PREFERRED_TYPE(
unsigned)
1918 unsigned SizeWidth : 5;
1924 LLVM_PREFERRED_TYPE(TypeBitfields)
1928 static constexpr unsigned NumOfBuiltinTypeBits = 9;
1929 unsigned Kind : NumOfBuiltinTypeBits;
1939 LLVM_PREFERRED_TYPE(TypeBitfields)
1945 unsigned ExtInfo : 13;
1951 unsigned RefQualifier : 2;
1960 unsigned FastTypeQuals : Qualifiers::FastWidth;
1962 LLVM_PREFERRED_TYPE(
bool)
1963 unsigned HasExtQuals : 1;
1969 unsigned NumParams : 16;
1973 unsigned ExceptionSpecType : 4;
1976 LLVM_PREFERRED_TYPE(
bool)
1977 unsigned HasExtParameterInfos : 1;
1980 LLVM_PREFERRED_TYPE(
bool)
1981 unsigned HasExtraBitfields : 1;
1984 LLVM_PREFERRED_TYPE(
bool)
1985 unsigned Variadic : 1;
1988 LLVM_PREFERRED_TYPE(
bool)
1989 unsigned HasTrailingReturn : 1;
1995 LLVM_PREFERRED_TYPE(TypeBitfields)
1999 unsigned NumTypeArgs : 7;
2002 unsigned NumProtocols : 6;
2005 LLVM_PREFERRED_TYPE(
bool)
2006 unsigned IsKindOf : 1;
2012 LLVM_PREFERRED_TYPE(TypeBitfields)
2026 LLVM_PREFERRED_TYPE(
bool)
2027 unsigned SpelledAsLValue : 1;
2031 LLVM_PREFERRED_TYPE(
bool)
2032 unsigned InnerRef : 1;
2038 LLVM_PREFERRED_TYPE(TypeBitfields)
2043 unsigned Keyword : 8;
2046 enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
2055 LLVM_PREFERRED_TYPE(
bool)
2056 unsigned HasOwnedTagDecl : 1;
2063 LLVM_PREFERRED_TYPE(TypeBitfields)
2069 unsigned VecKind : 4;
2071 uint32_t NumElements;
2077 LLVM_PREFERRED_TYPE(TypeBitfields)
2081 unsigned AttrKind : 32 - NumTypeBits;
2087 LLVM_PREFERRED_TYPE(TypeBitfields)
2093 unsigned Keyword : 2;
2109 LLVM_PREFERRED_TYPE(TypeBitfields)
2118 LLVM_PREFERRED_TYPE(TypeBitfields)
2122 LLVM_PREFERRED_TYPE(
bool)
2123 unsigned hasTypeDifferentFromDecl : 1;
2129 LLVM_PREFERRED_TYPE(TypeBitfields)
2133 LLVM_PREFERRED_TYPE(
bool)
2134 unsigned hasTypeDifferentFromDecl : 1;
2140 LLVM_PREFERRED_TYPE(TypeBitfields)
2144 unsigned Depth : 15;
2147 LLVM_PREFERRED_TYPE(
bool)
2148 unsigned ParameterPack : 1;
2151 unsigned Index : 16;
2157 LLVM_PREFERRED_TYPE(TypeBitfields)
2160 LLVM_PREFERRED_TYPE(
bool)
2161 unsigned HasNonCanonicalUnderlyingType : 1;
2164 unsigned Index : 15;
2171 unsigned PackIndex : 16;
2177 LLVM_PREFERRED_TYPE(TypeBitfields)
2181 unsigned Index : 16;
2187 unsigned NumArgs : 16;
2193 LLVM_PREFERRED_TYPE(TypeBitfields)
2197 LLVM_PREFERRED_TYPE(
bool)
2198 unsigned TypeAlias : 1;
2229 LLVM_PREFERRED_TYPE(TypeBitfields)
2243 unsigned NumExpansions;
2249 LLVM_PREFERRED_TYPE(TypeBitfields)
2252 static constexpr unsigned NumCoupledDeclsBits = 4;
2253 unsigned NumCoupledDecls : NumCoupledDeclsBits;
2254 LLVM_PREFERRED_TYPE(
bool)
2255 unsigned CountInBytes : 1;
2256 LLVM_PREFERRED_TYPE(
bool)
2257 unsigned OrNull : 1;
2291 void setFromAST(
bool V =
true)
const {
2292 TypeBits.FromAST =
V;
2300 canon.isNull() ?
QualType(this_(), 0) : canon) {
2301 static_assert(
sizeof(*this) <=
2303 "changing bitfields changed sizeof(Type)!");
2304 static_assert(
alignof(
decltype(*this)) %
TypeAlignment == 0,
2305 "Insufficient alignment!");
2307 TypeBits.Dependence =
static_cast<unsigned>(
Dependence);
2308 TypeBits.CacheValid =
false;
2309 TypeBits.CachedLocalOrUnnamed =
false;
2310 TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2311 TypeBits.FromAST =
false;
2318 TypeBits.Dependence =
static_cast<unsigned>(
D);
2355 return getDependence() & TypeDependence::UnexpandedPack;
2361 return CanonicalType ==
QualType(
this, 0);
2367 QualType getLocallyUnqualifiedSingleStepDesugaredType()
const;
2375 bool isSizelessType()
const;
2376 bool isSizelessBuiltinType()
const;
2379 bool isSizelessVectorType()
const;
2382 bool isSVESizelessBuiltinType()
const;
2385 bool isRVVSizelessBuiltinType()
const;
2388 bool isWebAssemblyExternrefType()
const;
2393 bool isWebAssemblyTableType()
const;
2398 bool isSveVLSBuiltinType()
const;
2408 bool isRVVVLSBuiltinType()
const;
2430 bool isIncompleteType(
NamedDecl **Def =
nullptr)
const;
2435 return !isFunctionType();
2443 return !isReferenceType() && !isFunctionType() && !isVoidType();
2448 bool isLiteralType(
const ASTContext &Ctx)
const;
2451 bool isStructuralType()
const;
2455 bool isStandardLayoutType()
const;
2461 bool isBuiltinType()
const;
2464 bool isSpecificBuiltinType(
unsigned K)
const;
2469 bool isPlaceholderType()
const;
2473 bool isSpecificPlaceholderType(
unsigned K)
const;
2477 bool isNonOverloadPlaceholderType()
const;
2481 bool isIntegerType()
const;
2482 bool isEnumeralType()
const;
2485 bool isScopedEnumeralType()
const;
2487 bool isCharType()
const;
2488 bool isWideCharType()
const;
2489 bool isChar8Type()
const;
2490 bool isChar16Type()
const;
2491 bool isChar32Type()
const;
2492 bool isAnyCharacterType()
const;
2493 bool isIntegralType(
const ASTContext &Ctx)
const;
2496 bool isIntegralOrEnumerationType()
const;
2499 bool isIntegralOrUnscopedEnumerationType()
const;
2500 bool isUnscopedEnumerationType()
const;
2503 bool isRealFloatingType()
const;
2506 bool isComplexType()
const;
2507 bool isAnyComplexType()
const;
2508 bool isFloatingType()
const;
2509 bool isHalfType()
const;
2510 bool isFloat16Type()
const;
2511 bool isFloat32Type()
const;
2512 bool isDoubleType()
const;
2513 bool isBFloat16Type()
const;
2514 bool isFloat128Type()
const;
2515 bool isIbm128Type()
const;
2516 bool isRealType()
const;
2517 bool isArithmeticType()
const;
2518 bool isVoidType()
const;
2519 bool isScalarType()
const;
2520 bool isAggregateType()
const;
2521 bool isFundamentalType()
const;
2522 bool isCompoundType()
const;
2526 bool isFunctionType()
const;
2529 bool isPointerType()
const;
2530 bool isPointerOrReferenceType()
const;
2531 bool isSignableType()
const;
2532 bool isAnyPointerType()
const;
2533 bool isCountAttributedType()
const;
2534 bool isBlockPointerType()
const;
2535 bool isVoidPointerType()
const;
2536 bool isReferenceType()
const;
2537 bool isLValueReferenceType()
const;
2538 bool isRValueReferenceType()
const;
2539 bool isObjectPointerType()
const;
2540 bool isFunctionPointerType()
const;
2541 bool isFunctionReferenceType()
const;
2542 bool isMemberPointerType()
const;
2543 bool isMemberFunctionPointerType()
const;
2544 bool isMemberDataPointerType()
const;
2545 bool isArrayType()
const;
2546 bool isConstantArrayType()
const;
2547 bool isIncompleteArrayType()
const;
2548 bool isVariableArrayType()
const;
2549 bool isArrayParameterType()
const;
2550 bool isDependentSizedArrayType()
const;
2552 bool isClassType()
const;
2553 bool isStructureType()
const;
2554 bool isStructureTypeWithFlexibleArrayMember()
const;
2555 bool isObjCBoxableRecordType()
const;
2556 bool isInterfaceType()
const;
2557 bool isStructureOrClassType()
const;
2558 bool isUnionType()
const;
2559 bool isComplexIntegerType()
const;
2560 bool isVectorType()
const;
2561 bool isExtVectorType()
const;
2562 bool isExtVectorBoolType()
const;
2563 bool isSubscriptableVectorType()
const;
2564 bool isMatrixType()
const;
2565 bool isConstantMatrixType()
const;
2566 bool isDependentAddressSpaceType()
const;
2567 bool isObjCObjectPointerType()
const;
2568 bool isObjCRetainableType()
const;
2569 bool isObjCLifetimeType()
const;
2570 bool isObjCIndirectLifetimeType()
const;
2571 bool isObjCNSObjectType()
const;
2572 bool isObjCIndependentClassType()
const;
2575 bool isObjCObjectType()
const;
2576 bool isObjCQualifiedInterfaceType()
const;
2577 bool isObjCQualifiedIdType()
const;
2578 bool isObjCQualifiedClassType()
const;
2579 bool isObjCObjectOrInterfaceType()
const;
2580 bool isObjCIdType()
const;
2581 bool isDecltypeType()
const;
2589 return hasAttr(attr::ObjCInertUnsafeUnretained);
2599 bool isObjCIdOrObjectKindOfType(
const ASTContext &ctx,
2602 bool isObjCClassType()
const;
2610 bool isObjCClassOrClassKindOfType()
const;
2612 bool isBlockCompatibleObjCPointerType(
ASTContext &ctx)
const;
2613 bool isObjCSelType()
const;
2614 bool isObjCBuiltinType()
const;
2615 bool isObjCARCBridgableType()
const;
2616 bool isCARCBridgableType()
const;
2617 bool isTemplateTypeParmType()
const;
2618 bool isNullPtrType()
const;
2620 bool isNothrowT()
const;
2621 bool isAlignValT()
const;
2622 bool isStdByteType()
const;
2623 bool isAtomicType()
const;
2624 bool isUndeducedAutoType()
const;
2626 bool isTypedefNameType()
const;
2628#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2629 bool is##Id##Type() const;
2630#include "clang/Basic/OpenCLImageTypes.def"
2632 bool isImageType()
const;
2634 bool isSamplerT()
const;
2635 bool isEventT()
const;
2636 bool isClkEventT()
const;
2637 bool isQueueT()
const;
2638 bool isReserveIDT()
const;
2640#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2641 bool is##Id##Type() const;
2642#include "clang/Basic/OpenCLExtensionTypes.def"
2644 bool isOCLIntelSubgroupAVCType()
const;
2645 bool isOCLExtOpaqueType()
const;
2647 bool isPipeType()
const;
2648 bool isBitIntType()
const;
2649 bool isOpenCLSpecificType()
const;
2651#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
2652#include "clang/Basic/HLSLIntangibleTypes.def"
2653 bool isHLSLSpecificType()
const;
2658 bool isObjCARCImplicitlyUnretainedType()
const;
2661 bool isCUDADeviceBuiltinSurfaceType()
const;
2663 bool isCUDADeviceBuiltinTextureType()
const;
2682 ScalarTypeKind getScalarTypeKind()
const;
2690 return getDependence() & TypeDependence::Error;
2696 return getDependence() & TypeDependence::Dependent;
2704 return getDependence() & TypeDependence::Instantiation;
2710 bool isUndeducedType()
const;
2714 return getDependence() & TypeDependence::VariablyModified;
2719 bool hasSizedVLAType()
const;
2722 bool hasUnnamedOrLocalType()
const;
2724 bool isOverloadableType()
const;
2727 bool isElaboratedTypeSpecifier()
const;
2729 bool canDecayToPointerType()
const;
2734 bool hasPointerRepresentation()
const;
2738 bool hasObjCPointerRepresentation()
const;
2742 bool hasIntegerRepresentation()
const;
2746 bool hasSignedIntegerRepresentation()
const;
2750 bool hasUnsignedIntegerRepresentation()
const;
2754 bool hasFloatingRepresentation()
const;
2759 const RecordType *getAsStructureType()
const;
2762 const ComplexType *getAsComplexIntegerType()
const;
2783 TagDecl *getAsTagDecl()
const;
2801 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2807 bool hasAutoForTrailingReturnType()
const;
2815 template <
typename T>
const T *getAs()
const;
2822 template <
typename T>
const T *getAsAdjusted()
const;
2826 const ArrayType *getAsArrayTypeUnsafe()
const;
2834 template <
typename T>
const T *castAs()
const;
2838 const ArrayType *castAsArrayTypeUnsafe()
const;
2847 const Type *getBaseElementTypeUnsafe()
const;
2852 const Type *getArrayElementTypeNoTypeQual()
const;
2857 const Type *getPointeeOrArrayElementType()
const;
2865 const Type *getUnqualifiedDesugaredType()
const;
2870 bool isSignedIntegerType()
const;
2875 bool isUnsignedIntegerType()
const;
2879 bool isSignedIntegerOrEnumerationType()
const;
2883 bool isUnsignedIntegerOrEnumerationType()
const;
2887 bool isFixedPointType()
const;
2890 bool isFixedPointOrIntegerType()
const;
2893 bool isConvertibleToFixedPointType()
const;
2897 bool isSaturatedFixedPointType()
const;
2901 bool isUnsaturatedFixedPointType()
const;
2905 bool isSignedFixedPointType()
const;
2909 bool isUnsignedFixedPointType()
const;
2914 bool isConstantSizeType()
const;
2918 bool isSpecifierType()
const;
2925 return getLinkageAndVisibility().getVisibility();
2930 return getLinkageAndVisibility().isVisibilityExplicit();
2938 bool isLinkageValid()
const;
2945 std::optional<NullabilityKind> getNullability()
const;
2952 bool canHaveNullability(
bool ResultIfUnknown =
true)
const;
2969 std::optional<ArrayRef<QualType>>
2970 getObjCSubstitutions(
const DeclContext *dc)
const;
2974 bool acceptsObjCTypeParams()
const;
2976 const char *getTypeClassName()
const;
2979 return CanonicalType;
2984 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
2989template <>
const TypedefType *Type::getAs()
const;
2990template <>
const UsingType *Type::getAs()
const;
2995template <>
const TemplateSpecializationType *Type::getAs()
const;
2999template <>
const AttributedType *Type::getAs()
const;
3003template <>
const BoundsAttributedType *Type::getAs()
const;
3007template <>
const CountAttributedType *Type::getAs()
const;
3011#define TYPE(Class, Base)
3012#define LEAF_TYPE(Class) \
3013template <> inline const Class##Type *Type::getAs() const { \
3014 return dyn_cast<Class##Type>(CanonicalType); \
3016template <> inline const Class##Type *Type::castAs() const { \
3017 return cast<Class##Type>(CanonicalType); \
3019#include "clang/AST/TypeNodes.inc"
3027#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
3028#include "clang/Basic/OpenCLImageTypes.def"
3030#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
3031#include "clang/Basic/OpenCLExtensionTypes.def"
3033#define SVE_TYPE(Name, Id, SingletonId) Id,
3034#include "clang/Basic/AArch64SVEACLETypes.def"
3036#define PPC_VECTOR_TYPE(Name, Id, Size) Id,
3037#include "clang/Basic/PPCTypes.def"
3039#define RVV_TYPE(Name, Id, SingletonId) Id,
3040#include "clang/Basic/RISCVVTypes.def"
3042#define WASM_TYPE(Name, Id, SingletonId) Id,
3043#include "clang/Basic/WebAssemblyReferenceTypes.def"
3045#define AMDGPU_TYPE(Name, Id, SingletonId) Id,
3046#include "clang/Basic/AMDGPUTypes.def"
3048#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) Id,
3049#include "clang/Basic/HLSLIntangibleTypes.def"
3051#define BUILTIN_TYPE(Id, SingletonId) Id,
3052#define LAST_BUILTIN_TYPE(Id) LastKind = Id
3053#include "clang/AST/BuiltinTypes.def"
3063 static_assert(Kind::LastKind <
3064 (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
3065 "Defined builtin type exceeds the allocated space for serial "
3067 BuiltinTypeBits.Kind = K;
3076 StringRef str =
getName(Policy);
3077 assert(!str.empty() && str.data()[str.size()] ==
'\0');
3106 return K >= Overload;
3113 return isPlaceholderTypeKind(
getKind());
3140 :
Type(
Complex, CanonicalPtr, Element->getDependence()),
3141 ElementType(Element) {}
3150 Profile(
ID, getElementType());
3154 ID.AddPointer(Element.getAsOpaquePtr());
3167 :
Type(
Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
3176 Profile(
ID, getInnerType());
3193 :
Type(
Pointer, CanonicalPtr, Pointee->getDependence()),
3194 PointeeType(Pointee) {}
3217 using BaseTy = llvm::PointerIntPair<ValueDecl *, 1, unsigned>;
3232 bool isDeref()
const;
3234 unsigned getInt()
const;
3235 void *getOpaqueValue()
const;
3237 void setFromOpaqueValue(
void *
V);
3268 return decl_range(dependent_decl_begin(), dependent_decl_end());
3272 return {dependent_decl_begin(), dependent_decl_end()};
3275 bool referencesFieldDecls()
const;
3282 case CountAttributed:
3294 public llvm::TrailingObjects<CountAttributedType,
3295 TypeCoupledDeclRefInfo> {
3306 bool CountInBytes,
bool OrNull,
3309 unsigned numTrailingObjects(OverloadToken<TypeCoupledDeclRefInfo>)
const {
3310 return CountAttributedTypeBits.NumCoupledDecls;
3323 bool isOrNull()
const {
return CountAttributedTypeBits.OrNull; }
3327 return isCountInBytes() ? SizedByOrNull : CountedByOrNull;
3328 return isCountInBytes() ? SizedBy : CountedBy;
3332 Profile(
ID, desugar(), CountExpr, isCountInBytes(), isOrNull());
3335 static void Profile(llvm::FoldingSetNodeID &
ID,
QualType WrappedTy,
3336 Expr *CountExpr,
bool CountInBytes,
bool Nullable);
3355 :
Type(TC, CanonicalPtr, OriginalTy->getDependence()),
3356 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
3366 Profile(
ID, OriginalTy, AdjustedTy);
3404 :
Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
3405 PointeeType(Pointee) {}
3433 bool SpelledAsLValue)
3434 :
Type(tc, CanonicalRef, Referencee->getDependence()),
3435 PointeeType(Referencee) {
3436 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3449 while (
T->isInnerRef())
3451 return T->PointeeType;
3455 Profile(
ID, PointeeType, isSpelledAsLValue());
3460 bool SpelledAsLValue) {
3462 ID.AddBoolean(SpelledAsLValue);
3476 bool SpelledAsLValue)
3518 :
Type(MemberPointer, CanonicalPtr,
3520 Pointee->getDependence()),
3521 PointeeType(Pointee),
Class(Cls) {}
3549 const Type *Class) {
3575 unsigned tq,
const Expr *sz =
nullptr);
3585 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3589 return ArrayTypeBits.IndexTypeQuals;
3607 struct ExternalSize {
3608 ExternalSize(
const llvm::APInt &Sz,
const Expr *SE)
3609 : Size(Sz), SizeExpr(SE) {}
3611 const Expr *SizeExpr;
3621 :
ArrayType(ConstantArray, Et, Can,
SM, TQ, nullptr), Size(Sz) {
3622 ConstantArrayTypeBits.HasExternalSize =
false;
3623 ConstantArrayTypeBits.SizeWidth = Width / 8;
3626 assert(Width < 0xFF &&
"Type width in bits must be less than 8 bits");
3629 ConstantArrayType(QualType Et, QualType Can, ExternalSize *SzPtr,
3630 ArraySizeModifier
SM,
unsigned TQ)
3631 : ArrayType(ConstantArray, Et, Can,
SM, TQ, SzPtr->SizeExpr),
3633 ConstantArrayTypeBits.HasExternalSize =
true;
3634 ConstantArrayTypeBits.SizeWidth = 0;
3636 assert((SzPtr->SizeExpr ==
nullptr || !Can.isNull()) &&
3637 "canonical constant array should not have size expression");
3640 static ConstantArrayType *
Create(
const ASTContext &Ctx, QualType ET,
3641 QualType Can,
const llvm::APInt &Sz,
3642 const Expr *SzExpr, ArraySizeModifier SzMod,
3647 :
ArrayType(Tc, ATy->getElementType(), Can, ATy->getSizeModifier(),
3648 ATy->getIndexTypeQualifiers().getAsOpaqueValue(), nullptr) {
3649 ConstantArrayTypeBits.HasExternalSize =
3651 if (!ConstantArrayTypeBits.HasExternalSize) {
3661 return ConstantArrayTypeBits.HasExternalSize
3663 : llvm::APInt(ConstantArrayTypeBits.SizeWidth * 8, Size);
3668 return ConstantArrayTypeBits.HasExternalSize
3669 ? SizePtr->Size.getBitWidth()
3670 :
static_cast<unsigned>(ConstantArrayTypeBits.SizeWidth * 8);
3675 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
3681 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
3687 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
3688 :
static_cast<int64_t
>(Size);
3694 return ConstantArrayTypeBits.HasExternalSize
3695 ? SizePtr->Size.getLimitedValue()
3701 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr :
nullptr;
3709 static unsigned getNumAddressingBits(
const ASTContext &Context,
3711 const llvm::APInt &NumElements);
3713 unsigned getNumAddressingBits(
const ASTContext &Context)
const;
3717 static unsigned getMaxSizeBits(
const ASTContext &Context);
3720 Profile(
ID, Ctx, getElementType(), getZExtSize(), getSizeExpr(),
3721 getSizeModifier(), getIndexTypeCVRQualifiers());
3724 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx,
3756 :
ArrayType(IncompleteArray, et, can, sm, tq) {}
3769 Profile(
ID, getElementType(), getSizeModifier(),
3770 getIndexTypeCVRQualifiers());
3776 ID.AddInteger(llvm::to_underlying(SizeMod));
3777 ID.AddInteger(TypeQuals);
3808 :
ArrayType(VariableArray, et, can, sm, tq, e),
3809 SizeExpr((
Stmt*) e), Brackets(brackets) {}
3817 return (
Expr*) SizeExpr;
3832 llvm_unreachable(
"Cannot unique VariableArrayTypes.");
3872 return (
Expr*) SizeExpr;
3887 Profile(
ID, Context, getElementType(),
3888 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3891 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3893 unsigned TypeQuals,
Expr *
E);
3910 Expr *AddrSpaceExpr;
3933 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3973 Profile(
ID, Context, getElementType(), getSizeExpr());
3976 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4046 Profile(
ID, getElementType(), getNumElements(),
4047 getTypeClass(), getVectorKind());
4054 ID.AddInteger(NumElements);
4056 ID.AddInteger(llvm::to_underlying(VecKind));
4099 Profile(
ID, Context, getElementType(), getSizeExpr(), getVectorKind());
4102 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4117 :
VectorType(ExtVector, vecType, nElements, canonType,
4124 case 'x':
case 'r':
return 0;
4125 case 'y':
case 'g':
return 1;
4126 case 'z':
case 'b':
return 2;
4127 case 'w':
case 'a':
return 3;
4145 case 'a':
return 10;
4147 case 'b':
return 11;
4149 case 'c':
return 12;
4151 case 'd':
return 13;
4153 case 'e':
return 14;
4155 case 'f':
return 15;
4160 if (isNumericAccessor)
4161 return getNumericAccessorIdx(
c);
4163 return getPointAccessorIdx(
c);
4167 if (
int idx = getAccessorIdx(
c, isNumericAccessor)+1)
4168 return unsigned(idx-1) < getNumElements();
4193 const Expr *RowExpr =
nullptr,
const Expr *ColumnExpr =
nullptr);
4227 static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
4230 unsigned NColumns,
QualType CanonElementType);
4233 unsigned NColumns,
QualType CanonElementType);
4244 return getNumRows() * getNumColumns();
4249 return NumElements > 0 && NumElements <= MaxElementsPerDimension;
4254 return MaxElementsPerDimension;
4258 Profile(
ID, getElementType(), getNumRows(), getNumColumns(),
4263 unsigned NumRows,
unsigned NumColumns,
4266 ID.AddInteger(NumRows);
4267 ID.AddInteger(NumColumns);
4299 Profile(
ID, Context, getElementType(), getRowExpr(), getColumnExpr());
4302 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4338 HasPassObjSize = 0x20,
4341 unsigned char Data = 0;
4350 copy.Data = (copy.Data & ~ABIMask) |
unsigned(kind);
4360 copy.Data |= IsConsumed;
4362 copy.Data &= ~IsConsumed;
4369 Copy.Data |= HasPassObjSize;
4377 Copy.Data |= IsNoEscape;
4379 Copy.Data &= ~IsNoEscape;
4391 return lhs.Data == rhs.Data;
4395 return lhs.Data != rhs.Data;
4430 enum { CallConvMask = 0x1F };
4431 enum { NoReturnMask = 0x20 };
4432 enum { ProducesResultMask = 0x40 };
4433 enum { NoCallerSavedRegsMask = 0x80 };
4435 RegParmMask = 0x700,
4438 enum { NoCfCheckMask = 0x800 };
4439 enum { CmseNSCallMask = 0x1000 };
4440 uint16_t Bits =
CC_C;
4442 ExtInfo(
unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
4448 bool producesResult,
bool noCallerSavedRegs,
bool NoCfCheck,
4450 assert((!hasRegParm || regParm < 7) &&
"Invalid regparm value");
4451 Bits = ((
unsigned)cc) | (noReturn ? NoReturnMask : 0) |
4452 (producesResult ? ProducesResultMask : 0) |
4453 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
4454 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
4455 (NoCfCheck ? NoCfCheckMask : 0) |
4456 (cmseNSCall ? CmseNSCallMask : 0);
4472 bool getHasRegParm()
const {
return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
4475 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
4484 return Bits ==
Other.Bits;
4487 return Bits !=
Other.Bits;
4495 return ExtInfo(Bits | NoReturnMask);
4497 return ExtInfo(Bits & ~NoReturnMask);
4502 return ExtInfo(Bits | ProducesResultMask);
4504 return ExtInfo(Bits & ~ProducesResultMask);
4509 return ExtInfo(Bits | CmseNSCallMask);
4511 return ExtInfo(Bits & ~CmseNSCallMask);
4515 if (noCallerSavedRegs)
4516 return ExtInfo(Bits | NoCallerSavedRegsMask);
4518 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4523 return ExtInfo(Bits | NoCfCheckMask);
4525 return ExtInfo(Bits & ~NoCfCheckMask);
4529 assert(RegParm < 7 &&
"Invalid regparm value");
4530 return ExtInfo((Bits & ~RegParmMask) |
4531 ((RegParm + 1) << RegParmOffset));
4535 return ExtInfo((Bits & ~CallConvMask) | (
unsigned) cc);
4539 ID.AddInteger(Bits);
4557 LLVM_PREFERRED_TYPE(
bool)
4560 LLVM_PREFERRED_TYPE(
bool)
4561 unsigned EffectsHaveConditions : 1;
4562 unsigned NumFunctionEffects : 4;
4565 : NumExceptionType(0), HasArmTypeAttributes(
false),
4566 EffectsHaveConditions(
false), NumFunctionEffects(0) {}
4573 SME_NormalFunction = 0,
4574 SME_PStateSMEnabledMask = 1 << 0,
4575 SME_PStateSMCompatibleMask = 1 << 1,
4579 SME_ZAMask = 0b111 << SME_ZAShift,
4581 SME_ZT0Mask = 0b111 << SME_ZT0Shift,
4597 return (
ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4601 return (
ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4619 FunctionTypeBits.ExtInfo = Info.Bits;
4623 if (isFunctionProtoType())
4624 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4644 static_assert((
~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4645 "Const, volatile and restrict are assumed to be a subset of "
4646 "the fast qualifiers.");
4648 bool isConst()
const {
return getFastTypeQuals().hasConst(); }
4649 bool isVolatile()
const {
return getFastTypeQuals().hasVolatile(); }
4650 bool isRestrict()
const {
return getFastTypeQuals().hasRestrict(); }
4658 static StringRef getNameForCallConv(
CallingConv CC);
4673 Result->getDependence() &
4685 Profile(
ID, getReturnType(), getExtInfo());
4720 FE_InferrableOnCallees = 0x1,
4723 FE_ExcludeThrow = 0x2,
4724 FE_ExcludeCatch = 0x4,
4725 FE_ExcludeObjCMessageSend = 0x8,
4726 FE_ExcludeStaticLocalVars = 0x10,
4727 FE_ExcludeThreadLocalVars = 0x20
4746 Kind oppositeKind()
const;