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/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"
70class TemplateParameterList;
79namespace serialization {
80 template <
class T>
class AbstractTypeReader;
117template <
typename>
class CanQual;
122class ExtQualsTypeCommonBase;
124class FunctionEffectsRef;
125class FunctionEffectKindSet;
126class FunctionEffectSet;
129class ObjCInterfaceDecl;
130class ObjCProtocolDecl;
131class ObjCTypeParamDecl;
132struct PrintingPolicy;
136class TemplateArgument;
137class TemplateArgumentListInfo;
138class TemplateArgumentLoc;
139class TemplateTypeParmDecl;
140class TypedefNameDecl;
141class UnresolvedUsingTypenameDecl;
142class UsingShadowDecl;
147#define TYPE(Class, Base) class Class##Type;
148#include "clang/AST/TypeNodes.inc"
155 EnabledMask = 1 << EnabledShift,
156 AddressDiscriminatedShift = EnabledShift + EnabledBits,
157 AddressDiscriminatedBits = 1,
158 AddressDiscriminatedMask = 1 << AddressDiscriminatedShift,
159 AuthenticationModeShift =
160 AddressDiscriminatedShift + AddressDiscriminatedBits,
161 AuthenticationModeBits = 2,
162 AuthenticationModeMask = ((1 << AuthenticationModeBits) - 1)
163 << AuthenticationModeShift,
164 IsaPointerShift = AuthenticationModeShift + AuthenticationModeBits,
166 IsaPointerMask = ((1 << IsaPointerBits) - 1) << IsaPointerShift,
167 AuthenticatesNullValuesShift = IsaPointerShift + IsaPointerBits,
168 AuthenticatesNullValuesBits = 1,
169 AuthenticatesNullValuesMask = ((1 << AuthenticatesNullValuesBits) - 1)
170 << AuthenticatesNullValuesShift,
171 KeyShift = AuthenticatesNullValuesShift + AuthenticatesNullValuesBits,
173 KeyMask = ((1 << KeyBits) - 1) << KeyShift,
174 DiscriminatorShift = KeyShift + KeyBits,
175 DiscriminatorBits = 16,
176 DiscriminatorMask = ((1u << DiscriminatorBits) - 1) << DiscriminatorShift,
187 static_assert((EnabledBits + AddressDiscriminatedBits +
188 AuthenticationModeBits + IsaPointerBits +
189 AuthenticatesNullValuesBits + KeyBits + DiscriminatorBits) ==
191 "PointerAuthQualifier should be exactly 32 bits");
192 static_assert((EnabledMask + AddressDiscriminatedMask +
193 AuthenticationModeMask + IsaPointerMask +
194 AuthenticatesNullValuesMask + KeyMask + DiscriminatorMask) ==
196 "All masks should cover the entire bits");
197 static_assert((EnabledMask ^ AddressDiscriminatedMask ^
198 AuthenticationModeMask ^ IsaPointerMask ^
199 AuthenticatesNullValuesMask ^ KeyMask ^ DiscriminatorMask) ==
201 "All masks should cover the entire bits");
204 unsigned ExtraDiscriminator,
206 bool IsIsaPointer,
bool AuthenticatesNullValues)
208 (IsAddressDiscriminated
209 ? llvm::to_underlying(AddressDiscriminatedMask)
212 (llvm::to_underlying(AuthenticationMode)
213 << AuthenticationModeShift) |
214 (ExtraDiscriminator << DiscriminatorShift) |
215 (IsIsaPointer << IsaPointerShift) |
216 (AuthenticatesNullValues << AuthenticatesNullValuesShift)) {
219 assert((
Data == 0) ==
238 Create(
unsigned Key,
bool IsAddressDiscriminated,
unsigned ExtraDiscriminator,
240 bool AuthenticatesNullValues) {
245 AuthenticationMode, IsIsaPointer,
246 AuthenticatesNullValues);
250 assert((
Data == 0) ==
259 return (
Data & KeyMask) >> KeyShift;
266 return (
Data & AddressDiscriminatedMask) >> AddressDiscriminatedShift;
271 return (
Data >> DiscriminatorShift);
276 AuthenticationModeShift);
281 return (
Data & IsaPointerMask) >> IsaPointerShift;
286 return (
Data & AuthenticatesNullValuesMask) >> AuthenticatesNullValuesShift;
294 return Lhs.Data == Rhs.Data;
297 return Lhs.Data != Rhs.Data;
310 assert((
Result.Data == 0) ==
391 Q.Mask = L.Mask & R.Mask;
485 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
486 Mask = (Mask & ~CVRMask) | mask;
489 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
490 Mask &= ~static_cast<uint64_t>(mask);
496 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
500 assert(!(mask & ~
CVRMask & ~UMask) &&
"bitmask contains non-CVRU bits");
506 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
514 Mask = (Mask & ~GCAttrMask) | (
type << GCAttrShift);
539 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
542 Mask = (Mask & ~LifetimeMask) | (
type << LifetimeShift);
548 Mask |= (
type << LifetimeShift);
565 return static_cast<LangAS>(Mask >> AddressSpaceShift);
586 Mask = (Mask & ~AddressSpaceMask)
587 | (((uint32_t) space) << AddressSpaceShift);
600 Mask = (Mask & ~PtrAuthMask) |
614 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
615 Mask = (Mask & ~FastMask) | mask;
618 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
619 Mask &= ~static_cast<uint64_t>(mask);
625 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
640 bool empty()
const {
return !Mask; }
795 bool appendSpaceIfNonEmpty =
false)
const;
797 void Profile(llvm::FoldingSetNodeID &
ID)
const {
ID.AddInteger(Mask); }
804 "PointerAuthQualifier must be 32 bits");
806 static constexpr uint64_t UMask = 0x8;
807 static constexpr uint64_t UShift = 3;
808 static constexpr uint64_t GCAttrMask = 0x30;
809 static constexpr uint64_t GCAttrShift = 4;
810 static constexpr uint64_t LifetimeMask = 0x1C0;
811 static constexpr uint64_t LifetimeShift = 6;
812 static constexpr uint64_t AddressSpaceMask =
813 ~(
CVRMask | UMask | GCAttrMask | LifetimeMask);
814 static constexpr uint64_t AddressSpaceShift = 9;
815 static constexpr uint64_t PtrAuthShift = 32;
816 static constexpr uint64_t PtrAuthMask = uint64_t(0xffffffff) << PtrAuthShift;
826 : Quals(Quals), HasAtomic(HasAtomic) {}
875 std::pair<const Type *,Qualifiers>
asPair()
const {
876 return std::pair<const Type *, Qualifiers>(
Ty,
Quals);
880 return a.
Ty ==
b.Ty && a.
Quals ==
b.Quals;
883 return a.
Ty !=
b.Ty || a.
Quals !=
b.Quals;
933 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
936 const ExtQuals *getExtQualsUnsafe()
const {
937 return cast<const ExtQuals *>(
Value.getPointer());
940 const Type *getTypePtrUnsafe()
const {
941 return cast<const Type *>(
Value.getPointer());
944 const ExtQualsTypeCommonBase *getCommonPtr()
const {
945 assert(!
isNull() &&
"Cannot retrieve a NULL type pointer");
946 auto CommonPtrVal =
reinterpret_cast<uintptr_t>(
Value.getOpaqueValue());
948 return reinterpret_cast<ExtQualsTypeCommonBase*
>(CommonPtrVal);
980 T.Value.setFromOpaqueValue(
const_cast<void*
>(Ptr));
997 return Value.getPointer().isNull();
1024 std::optional<NonConstantStorageReason>
1067 return isa<const ExtQuals *>(
Value.getPointer());
1180 &&
"non-fast qualifier bits set in mask!");
1198 T.addFastQualifiers(TQs);
1211 T.removeLocalFastQualifiers();
1305 return getSingleStepDesugaredTypeImpl(*
this, Context);
1311 if (isa<ParenType>(*
this))
1318 return LHS.Value == RHS.Value;
1321 return LHS.Value != RHS.Value;
1324 return LHS.Value < RHS.Value;
1338 const Twine &PlaceHolder = Twine(),
1339 unsigned Indentation = 0)
const;
1343 unsigned Indentation = 0) {
1349 const Twine &PlaceHolder,
1350 unsigned Indentation = 0);
1367 const Twine &PlaceHolder;
1368 unsigned Indentation;
1372 const Twine &PlaceHolder,
unsigned Indentation)
1373 :
T(
T), Policy(Policy), PlaceHolder(PlaceHolder),
1374 Indentation(Indentation) {}
1378 SQT.T.
print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1384 const Twine &PlaceHolder = Twine(),
1385 unsigned Indentation = 0)
const {
1389 void dump(
const char *
s)
const;
1391 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
1532 return isDestructedTypeImpl(*
this);
1634raw_ostream &
operator<<(raw_ostream &OS, QualType QT);
1654 return P.getAsOpaquePtr();
1662 static constexpr int NumLowBitsAvailable = 0;
1683 const Type *
const BaseType;
1689 : BaseType(baseType), CanonicalType(canon) {}
1703 public llvm::FoldingSetNode {
1726 canon.isNull() ?
QualType(this_(), 0) : canon),
1728 assert(Quals.hasNonFastQualifiers()
1729 &&
"ExtQuals created with no fast qualifiers");
1730 assert(!Quals.hasFastQualifiers()
1731 &&
"ExtQuals created with fast qualifiers");
1741 return Quals.getObjCLifetime();
1751 Profile(
ID, getBaseType(), Quals);
1755 const Type *BaseType,
1758 ID.AddPointer(BaseType);
1798enum class ArraySizeModifier;
1799enum class ElaboratedTypeKeyword;
1800enum class VectorKind;
1831#define TYPE(Class, Base) Class,
1832#define LAST_TYPE(Class) TypeLast = Class
1833#define ABSTRACT_TYPE(Class, Base)
1834#include "clang/AST/TypeNodes.inc"
1839 class TypeBitfields {
1841 template <
class T>
friend class TypePropertyCache;
1844 LLVM_PREFERRED_TYPE(TypeClass)
1849 unsigned Dependence : llvm::BitWidth<TypeDependence>;
1853 LLVM_PREFERRED_TYPE(
bool)
1854 mutable unsigned CacheValid : 1;
1858 mutable unsigned CachedLinkage : 3;
1861 LLVM_PREFERRED_TYPE(
bool)
1862 mutable unsigned CachedLocalOrUnnamed : 1;
1865 LLVM_PREFERRED_TYPE(
bool)
1866 mutable unsigned FromAST : 1;
1868 bool isCacheValid()
const {
1873 assert(isCacheValid() &&
"getting linkage from invalid cache");
1874 return static_cast<Linkage>(CachedLinkage);
1877 bool hasLocalOrUnnamedType()
const {
1878 assert(isCacheValid() &&
"getting linkage from invalid cache");
1879 return CachedLocalOrUnnamed;
1882 enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1891 LLVM_PREFERRED_TYPE(TypeBitfields)
1897 unsigned IndexTypeQuals : 3;
1902 unsigned SizeModifier : 3;
1904 enum { NumArrayTypeBits = NumTypeBits + 6 };
1913 LLVM_PREFERRED_TYPE(
bool)
1914 unsigned HasExternalSize : 1;
1916 LLVM_PREFERRED_TYPE(
unsigned)
1917 unsigned SizeWidth : 5;
1923 LLVM_PREFERRED_TYPE(TypeBitfields)
1927 static constexpr unsigned NumOfBuiltinTypeBits = 9;
1928 unsigned Kind : NumOfBuiltinTypeBits;
1932 static constexpr int FunctionTypeNumParamsWidth = 16;
1933 static constexpr int FunctionTypeNumParamsLimit = (1 << 16) - 1;
1943 LLVM_PREFERRED_TYPE(TypeBitfields)
1949 unsigned ExtInfo : 13;
1955 unsigned RefQualifier : 2;
1964 unsigned FastTypeQuals : Qualifiers::FastWidth;
1966 LLVM_PREFERRED_TYPE(
bool)
1967 unsigned HasExtQuals : 1;
1973 unsigned NumParams : FunctionTypeNumParamsWidth;
1977 unsigned ExceptionSpecType : 4;
1980 LLVM_PREFERRED_TYPE(
bool)
1981 unsigned HasExtParameterInfos : 1;
1984 LLVM_PREFERRED_TYPE(
bool)
1985 unsigned HasExtraBitfields : 1;
1988 LLVM_PREFERRED_TYPE(
bool)
1989 unsigned Variadic : 1;
1992 LLVM_PREFERRED_TYPE(
bool)
1993 unsigned HasTrailingReturn : 1;
1999 LLVM_PREFERRED_TYPE(TypeBitfields)
2003 unsigned NumTypeArgs : 7;
2006 unsigned NumProtocols : 6;
2009 LLVM_PREFERRED_TYPE(
bool)
2010 unsigned IsKindOf : 1;
2016 LLVM_PREFERRED_TYPE(TypeBitfields)
2030 LLVM_PREFERRED_TYPE(
bool)
2031 unsigned SpelledAsLValue : 1;
2035 LLVM_PREFERRED_TYPE(
bool)
2036 unsigned InnerRef : 1;
2042 LLVM_PREFERRED_TYPE(TypeBitfields)
2047 unsigned Keyword : 8;
2050 enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
2059 LLVM_PREFERRED_TYPE(
bool)
2060 unsigned HasOwnedTagDecl : 1;
2067 LLVM_PREFERRED_TYPE(TypeBitfields)
2073 unsigned VecKind : 4;
2075 uint32_t NumElements;
2081 LLVM_PREFERRED_TYPE(TypeBitfields)
2085 unsigned AttrKind : 32 - NumTypeBits;
2091 LLVM_PREFERRED_TYPE(TypeBitfields)
2097 unsigned Keyword : 2;
2113 LLVM_PREFERRED_TYPE(TypeBitfields)
2122 LLVM_PREFERRED_TYPE(TypeBitfields)
2126 LLVM_PREFERRED_TYPE(
bool)
2127 unsigned hasTypeDifferentFromDecl : 1;
2133 LLVM_PREFERRED_TYPE(TypeBitfields)
2137 LLVM_PREFERRED_TYPE(
bool)
2138 unsigned hasTypeDifferentFromDecl : 1;
2144 LLVM_PREFERRED_TYPE(TypeBitfields)
2148 unsigned Depth : 15;
2151 LLVM_PREFERRED_TYPE(
bool)
2152 unsigned ParameterPack : 1;
2155 unsigned Index : 16;
2161 LLVM_PREFERRED_TYPE(TypeBitfields)
2164 LLVM_PREFERRED_TYPE(
bool)
2165 unsigned HasNonCanonicalUnderlyingType : 1;
2168 unsigned SubstitutionFlag : 1;
2171 unsigned Index : 15;
2178 unsigned PackIndex : 16;
2184 LLVM_PREFERRED_TYPE(TypeBitfields)
2188 unsigned Index : 16;
2194 unsigned NumArgs : 16;
2200 LLVM_PREFERRED_TYPE(TypeBitfields)
2204 LLVM_PREFERRED_TYPE(
bool)
2205 unsigned TypeAlias : 1;
2236 LLVM_PREFERRED_TYPE(TypeBitfields)
2250 unsigned NumExpansions;
2256 LLVM_PREFERRED_TYPE(TypeBitfields)
2259 static constexpr unsigned NumCoupledDeclsBits = 4;
2260 unsigned NumCoupledDecls : NumCoupledDeclsBits;
2261 LLVM_PREFERRED_TYPE(
bool)
2262 unsigned CountInBytes : 1;
2263 LLVM_PREFERRED_TYPE(
bool)
2264 unsigned OrNull : 1;
2298 void setFromAST(
bool V =
true)
const {
2299 TypeBits.FromAST =
V;
2307 canon.isNull() ?
QualType(this_(), 0) : canon) {
2308 static_assert(
sizeof(*this) <=
2310 "changing bitfields changed sizeof(Type)!");
2311 static_assert(
alignof(
decltype(*this)) %
TypeAlignment == 0,
2312 "Insufficient alignment!");
2314 TypeBits.Dependence =
static_cast<unsigned>(
Dependence);
2315 TypeBits.CacheValid =
false;
2316 TypeBits.CachedLocalOrUnnamed =
false;
2317 TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2318 TypeBits.FromAST =
false;
2325 TypeBits.Dependence =
static_cast<unsigned>(
D);
2362 return getDependence() & TypeDependence::UnexpandedPack;
2368 return CanonicalType ==
QualType(
this, 0);
2374 QualType getLocallyUnqualifiedSingleStepDesugaredType()
const;
2382 bool isSizelessType()
const;
2383 bool isSizelessBuiltinType()
const;
2386 bool isSizelessVectorType()
const;
2389 bool isSVESizelessBuiltinType()
const;
2392 bool isRVVSizelessBuiltinType()
const;
2395 bool isWebAssemblyExternrefType()
const;
2400 bool isWebAssemblyTableType()
const;
2405 bool isSveVLSBuiltinType()
const;
2415 bool isRVVVLSBuiltinType()
const;
2437 bool isIncompleteType(
NamedDecl **Def =
nullptr)
const;
2442 return !isFunctionType();
2450 return !isReferenceType() && !isFunctionType() && !isVoidType();
2455 bool isLiteralType(
const ASTContext &Ctx)
const;
2458 bool isStructuralType()
const;
2462 bool isStandardLayoutType()
const;
2468 bool isBuiltinType()
const;
2471 bool isSpecificBuiltinType(
unsigned K)
const;
2476 bool isPlaceholderType()
const;
2480 bool isSpecificPlaceholderType(
unsigned K)
const;
2484 bool isNonOverloadPlaceholderType()
const;
2488 bool isIntegerType()
const;
2489 bool isEnumeralType()
const;
2492 bool isScopedEnumeralType()
const;
2494 bool isCharType()
const;
2495 bool isWideCharType()
const;
2496 bool isChar8Type()
const;
2497 bool isChar16Type()
const;
2498 bool isChar32Type()
const;
2499 bool isAnyCharacterType()
const;
2500 bool isIntegralType(
const ASTContext &Ctx)
const;
2503 bool isIntegralOrEnumerationType()
const;
2506 bool isIntegralOrUnscopedEnumerationType()
const;
2507 bool isUnscopedEnumerationType()
const;
2510 bool isRealFloatingType()
const;
2513 bool isComplexType()
const;
2514 bool isAnyComplexType()
const;
2515 bool isFloatingType()
const;
2516 bool isHalfType()
const;
2517 bool isFloat16Type()
const;
2518 bool isFloat32Type()
const;
2519 bool isDoubleType()
const;
2520 bool isBFloat16Type()
const;
2521 bool isFloat128Type()
const;
2522 bool isIbm128Type()
const;
2523 bool isRealType()
const;
2524 bool isArithmeticType()
const;
2525 bool isVoidType()
const;
2526 bool isScalarType()
const;
2527 bool isAggregateType()
const;
2528 bool isFundamentalType()
const;
2529 bool isCompoundType()
const;
2533 bool isFunctionType()
const;
2536 bool isPointerType()
const;
2537 bool isPointerOrReferenceType()
const;
2538 bool isSignableType()
const;
2539 bool isAnyPointerType()
const;
2540 bool isCountAttributedType()
const;
2541 bool isBlockPointerType()
const;
2542 bool isVoidPointerType()
const;
2543 bool isReferenceType()
const;
2544 bool isLValueReferenceType()
const;
2545 bool isRValueReferenceType()
const;
2546 bool isObjectPointerType()
const;
2547 bool isFunctionPointerType()
const;
2548 bool isFunctionReferenceType()
const;
2549 bool isMemberPointerType()
const;
2550 bool isMemberFunctionPointerType()
const;
2551 bool isMemberDataPointerType()
const;
2552 bool isArrayType()
const;
2553 bool isConstantArrayType()
const;
2554 bool isIncompleteArrayType()
const;
2555 bool isVariableArrayType()
const;
2556 bool isArrayParameterType()
const;
2557 bool isDependentSizedArrayType()
const;
2559 bool isClassType()
const;
2560 bool isStructureType()
const;
2561 bool isStructureTypeWithFlexibleArrayMember()
const;
2562 bool isObjCBoxableRecordType()
const;
2563 bool isInterfaceType()
const;
2564 bool isStructureOrClassType()
const;
2565 bool isUnionType()
const;
2566 bool isComplexIntegerType()
const;
2567 bool isVectorType()
const;
2568 bool isExtVectorType()
const;
2569 bool isExtVectorBoolType()
const;
2570 bool isSubscriptableVectorType()
const;
2571 bool isMatrixType()
const;
2572 bool isConstantMatrixType()
const;
2573 bool isDependentAddressSpaceType()
const;
2574 bool isObjCObjectPointerType()
const;
2575 bool isObjCRetainableType()
const;
2576 bool isObjCLifetimeType()
const;
2577 bool isObjCIndirectLifetimeType()
const;
2578 bool isObjCNSObjectType()
const;
2579 bool isObjCIndependentClassType()
const;
2582 bool isObjCObjectType()
const;
2583 bool isObjCQualifiedInterfaceType()
const;
2584 bool isObjCQualifiedIdType()
const;
2585 bool isObjCQualifiedClassType()
const;
2586 bool isObjCObjectOrInterfaceType()
const;
2587 bool isObjCIdType()
const;
2588 bool isDecltypeType()
const;
2596 return hasAttr(attr::ObjCInertUnsafeUnretained);
2606 bool isObjCIdOrObjectKindOfType(
const ASTContext &ctx,
2609 bool isObjCClassType()
const;
2617 bool isObjCClassOrClassKindOfType()
const;
2619 bool isBlockCompatibleObjCPointerType(
ASTContext &ctx)
const;
2620 bool isObjCSelType()
const;
2621 bool isObjCBuiltinType()
const;
2622 bool isObjCARCBridgableType()
const;
2623 bool isCARCBridgableType()
const;
2624 bool isTemplateTypeParmType()
const;
2625 bool isNullPtrType()
const;
2627 bool isNothrowT()
const;
2628 bool isAlignValT()
const;
2629 bool isStdByteType()
const;
2630 bool isAtomicType()
const;
2631 bool isUndeducedAutoType()
const;
2633 bool isTypedefNameType()
const;
2635#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2636 bool is##Id##Type() const;
2637#include "clang/Basic/OpenCLImageTypes.def"
2639 bool isImageType()
const;
2641 bool isSamplerT()
const;
2642 bool isEventT()
const;
2643 bool isClkEventT()
const;
2644 bool isQueueT()
const;
2645 bool isReserveIDT()
const;
2647#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2648 bool is##Id##Type() const;
2649#include "clang/Basic/OpenCLExtensionTypes.def"
2651 bool isOCLIntelSubgroupAVCType()
const;
2652 bool isOCLExtOpaqueType()
const;
2654 bool isPipeType()
const;
2655 bool isBitIntType()
const;
2656 bool isOpenCLSpecificType()
const;
2658#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) bool is##Id##Type() const;
2659#include "clang/Basic/HLSLIntangibleTypes.def"
2660 bool isHLSLSpecificType()
const;
2661 bool isHLSLBuiltinIntangibleType()
const;
2662 bool isHLSLAttributedResourceType()
const;
2663 bool isHLSLIntangibleType()
2669 bool isObjCARCImplicitlyUnretainedType()
const;
2672 bool isCUDADeviceBuiltinSurfaceType()
const;
2674 bool isCUDADeviceBuiltinTextureType()
const;
2693 ScalarTypeKind getScalarTypeKind()
const;
2701 return getDependence() & TypeDependence::Error;
2707 return getDependence() & TypeDependence::Dependent;
2715 return getDependence() & TypeDependence::Instantiation;
2721 bool isUndeducedType()
const;
2725 return getDependence() & TypeDependence::VariablyModified;
2730 bool hasSizedVLAType()
const;
2733 bool hasUnnamedOrLocalType()
const;
2735 bool isOverloadableType()
const;
2738 bool isElaboratedTypeSpecifier()
const;
2740 bool canDecayToPointerType()
const;
2745 bool hasPointerRepresentation()
const;
2749 bool hasObjCPointerRepresentation()
const;
2753 bool hasIntegerRepresentation()
const;
2757 bool hasSignedIntegerRepresentation()
const;
2761 bool hasUnsignedIntegerRepresentation()
const;
2765 bool hasFloatingRepresentation()
const;
2770 const RecordType *getAsStructureType()
const;
2773 const ComplexType *getAsComplexIntegerType()
const;
2794 TagDecl *getAsTagDecl()
const;
2812 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2818 bool hasAutoForTrailingReturnType()
const;
2826 template <
typename T>
const T *getAs()
const;
2833 template <
typename T>
const T *getAsAdjusted()
const;
2837 const ArrayType *getAsArrayTypeUnsafe()
const;
2845 template <
typename T>
const T *castAs()
const;
2849 const ArrayType *castAsArrayTypeUnsafe()
const;
2858 const Type *getBaseElementTypeUnsafe()
const;
2863 const Type *getArrayElementTypeNoTypeQual()
const;
2868 const Type *getPointeeOrArrayElementType()
const;
2876 const Type *getUnqualifiedDesugaredType()
const;
2881 bool isSignedIntegerType()
const;
2886 bool isUnsignedIntegerType()
const;
2890 bool isSignedIntegerOrEnumerationType()
const;
2894 bool isUnsignedIntegerOrEnumerationType()
const;
2898 bool isFixedPointType()
const;
2901 bool isFixedPointOrIntegerType()
const;
2904 bool isConvertibleToFixedPointType()
const;
2908 bool isSaturatedFixedPointType()
const;
2912 bool isUnsaturatedFixedPointType()
const;
2916 bool isSignedFixedPointType()
const;
2920 bool isUnsignedFixedPointType()
const;
2925 bool isConstantSizeType()
const;
2929 bool isSpecifierType()
const;
2936 return getLinkageAndVisibility().getVisibility();
2941 return getLinkageAndVisibility().isVisibilityExplicit();
2949 bool isLinkageValid()
const;
2956 std::optional<NullabilityKind> getNullability()
const;
2963 bool canHaveNullability(
bool ResultIfUnknown =
true)
const;
2980 std::optional<ArrayRef<QualType>>
2981 getObjCSubstitutions(
const DeclContext *dc)
const;
2985 bool acceptsObjCTypeParams()
const;
2987 const char *getTypeClassName()
const;
2990 return CanonicalType;
2995 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
3000template <>
const TypedefType *Type::getAs()
const;
3001template <>
const UsingType *Type::getAs()
const;
3006template <>
const TemplateSpecializationType *Type::getAs()
const;
3010template <>
const AttributedType *Type::getAs()
const;
3014template <>
const BoundsAttributedType *Type::getAs()
const;
3018template <>
const CountAttributedType *Type::getAs()
const;
3022#define TYPE(Class, Base)
3023#define LEAF_TYPE(Class) \
3024template <> inline const Class##Type *Type::getAs() const { \
3025 return dyn_cast<Class##Type>(CanonicalType); \
3027template <> inline const Class##Type *Type::castAs() const { \
3028 return cast<Class##Type>(CanonicalType); \
3030#include "clang/AST/TypeNodes.inc"
3038#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
3039#include "clang/Basic/OpenCLImageTypes.def"
3041#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
3042#include "clang/Basic/OpenCLExtensionTypes.def"
3044#define SVE_TYPE(Name, Id, SingletonId) Id,
3045#include "clang/Basic/AArch64SVEACLETypes.def"
3047#define PPC_VECTOR_TYPE(Name, Id, Size) Id,
3048#include "clang/Basic/PPCTypes.def"
3050#define RVV_TYPE(Name, Id, SingletonId) Id,
3051#include "clang/Basic/RISCVVTypes.def"
3053#define WASM_TYPE(Name, Id, SingletonId) Id,
3054#include "clang/Basic/WebAssemblyReferenceTypes.def"
3056#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) Id,
3057#include "clang/Basic/AMDGPUTypes.def"
3059#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) Id,
3060#include "clang/Basic/HLSLIntangibleTypes.def"
3062#define BUILTIN_TYPE(Id, SingletonId) Id,
3063#define LAST_BUILTIN_TYPE(Id) LastKind = Id
3064#include "clang/AST/BuiltinTypes.def"
3074 static_assert(Kind::LastKind <
3075 (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
3076 "Defined builtin type exceeds the allocated space for serial "
3078 BuiltinTypeBits.Kind = K;
3087 StringRef str =
getName(Policy);
3088 assert(!str.empty() && str.data()[str.size()] ==
'\0');
3117 return K >= Overload;
3124 return isPlaceholderTypeKind(
getKind());
3151 :
Type(
Complex, CanonicalPtr, Element->getDependence()),
3152 ElementType(Element) {}
3161 Profile(
ID, getElementType());
3165 ID.AddPointer(Element.getAsOpaquePtr());
3178 :
Type(
Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
3187 Profile(
ID, getInnerType());
3204 :
Type(
Pointer, CanonicalPtr, Pointee->getDependence()),
3205 PointeeType(Pointee) {}
3228 using BaseTy = llvm::PointerIntPair<ValueDecl *, 1, unsigned>;
3243 bool isDeref()
const;
3245 unsigned getInt()
const;
3246 void *getOpaqueValue()
const;
3248 void setFromOpaqueValue(
void *
V);
3279 return decl_range(dependent_decl_begin(), dependent_decl_end());
3283 return {dependent_decl_begin(), dependent_decl_end()};
3286 bool referencesFieldDecls()
const;
3293 case CountAttributed:
3305 public llvm::TrailingObjects<CountAttributedType,
3306 TypeCoupledDeclRefInfo> {
3317 bool CountInBytes,
bool OrNull,
3320 unsigned numTrailingObjects(OverloadToken<TypeCoupledDeclRefInfo>)
const {
3321 return CountAttributedTypeBits.NumCoupledDecls;
3334 bool isOrNull()
const {
return CountAttributedTypeBits.OrNull; }
3338 return isCountInBytes() ? SizedByOrNull : CountedByOrNull;
3339 return isCountInBytes() ? SizedBy : CountedBy;
3343 Profile(
ID, desugar(), CountExpr, isCountInBytes(), isOrNull());
3346 static void Profile(llvm::FoldingSetNodeID &
ID,
QualType WrappedTy,
3347 Expr *CountExpr,
bool CountInBytes,
bool Nullable);
3366 :
Type(TC, CanonicalPtr, OriginalTy->getDependence()),
3367 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
3377 Profile(
ID, OriginalTy, AdjustedTy);
3415 :
Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
3416 PointeeType(Pointee) {}
3444 bool SpelledAsLValue)
3445 :
Type(tc, CanonicalRef, Referencee->getDependence()),
3446 PointeeType(Referencee) {
3447 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3460 while (
T->isInnerRef())
3462 return T->PointeeType;
3466 Profile(
ID, PointeeType, isSpelledAsLValue());
3471 bool SpelledAsLValue) {
3473 ID.AddBoolean(SpelledAsLValue);
3487 bool SpelledAsLValue)
3529 :
Type(MemberPointer, CanonicalPtr,
3531 Pointee->getDependence()),
3532 PointeeType(Pointee),
Class(Cls) {}
3560 const Type *Class) {
3586 unsigned tq,
const Expr *sz =
nullptr);
3596 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3600 return ArrayTypeBits.IndexTypeQuals;
3618 struct ExternalSize {
3619 ExternalSize(
const llvm::APInt &Sz,
const Expr *SE)
3620 : Size(Sz), SizeExpr(SE) {}
3622 const Expr *SizeExpr;
3632 :
ArrayType(ConstantArray, Et, Can,
SM, TQ, nullptr), Size(Sz) {
3633 ConstantArrayTypeBits.HasExternalSize =
false;
3634 ConstantArrayTypeBits.SizeWidth = Width / 8;
3637 assert(Width < 0xFF &&
"Type width in bits must be less than 8 bits");
3640 ConstantArrayType(QualType Et, QualType Can, ExternalSize *SzPtr,
3641 ArraySizeModifier
SM,
unsigned TQ)
3642 : ArrayType(ConstantArray, Et, Can,
SM, TQ, SzPtr->SizeExpr),
3644 ConstantArrayTypeBits.HasExternalSize =
true;
3645 ConstantArrayTypeBits.SizeWidth = 0;
3647 assert((SzPtr->SizeExpr ==
nullptr || !Can.isNull()) &&
3648 "canonical constant array should not have size expression");
3651 static ConstantArrayType *
Create(
const ASTContext &Ctx, QualType ET,
3652 QualType Can,
const llvm::APInt &Sz,
3653 const Expr *SzExpr, ArraySizeModifier SzMod,
3658 :
ArrayType(Tc, ATy->getElementType(), Can, ATy->getSizeModifier(),
3659 ATy->getIndexTypeQualifiers().getAsOpaqueValue(), nullptr) {
3660 ConstantArrayTypeBits.HasExternalSize =
3662 if (!ConstantArrayTypeBits.HasExternalSize) {
3672 return ConstantArrayTypeBits.HasExternalSize
3674 : llvm::APInt(ConstantArrayTypeBits.SizeWidth * 8, Size);
3679 return ConstantArrayTypeBits.HasExternalSize
3680 ? SizePtr->Size.getBitWidth()
3681 :
static_cast<unsigned>(ConstantArrayTypeBits.SizeWidth * 8);
3686 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.isZero()
3692 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getZExtValue()
3698 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->Size.getSExtValue()
3699 :
static_cast<int64_t
>(Size);
3705 return ConstantArrayTypeBits.HasExternalSize
3706 ? SizePtr->Size.getLimitedValue()
3712 return ConstantArrayTypeBits.HasExternalSize ? SizePtr->SizeExpr :
nullptr;
3720 static unsigned getNumAddressingBits(
const ASTContext &Context,
3722 const llvm::APInt &NumElements);
3724 unsigned getNumAddressingBits(
const ASTContext &Context)
const;
3728 static unsigned getMaxSizeBits(
const ASTContext &Context);
3731 Profile(
ID, Ctx, getElementType(), getZExtSize(), getSizeExpr(),
3732 getSizeModifier(), getIndexTypeCVRQualifiers());
3735 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx,
3769 :
ArrayType(IncompleteArray, et, can, sm, tq) {}
3782 Profile(
ID, getElementType(), getSizeModifier(),
3783 getIndexTypeCVRQualifiers());
3789 ID.AddInteger(llvm::to_underlying(SizeMod));
3790 ID.AddInteger(TypeQuals);
3821 :
ArrayType(VariableArray, et, can, sm, tq, e),
3822 SizeExpr((
Stmt*) e), Brackets(brackets) {}
3830 return (
Expr*) SizeExpr;
3845 llvm_unreachable(
"Cannot unique VariableArrayTypes.");
3885 return (
Expr*) SizeExpr;
3900 Profile(
ID, Context, getElementType(),
3901 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3904 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3906 unsigned TypeQuals,
Expr *
E);
3923 Expr *AddrSpaceExpr;
3946 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3986 Profile(
ID, Context, getElementType(), getSizeExpr());
3989 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4059 Profile(
ID, getElementType(), getNumElements(),
4060 getTypeClass(), getVectorKind());
4067 ID.AddInteger(NumElements);
4069 ID.AddInteger(llvm::to_underlying(VecKind));
4112 Profile(
ID, Context, getElementType(), getSizeExpr(), getVectorKind());
4115 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4130 :
VectorType(ExtVector, vecType, nElements, canonType,
4137 case 'x':
case 'r':
return 0;
4138 case 'y':
case 'g':
return 1;
4139 case 'z':
case 'b':
return 2;
4140 case 'w':
case 'a':
return 3;
4158 case 'a':
return 10;
4160 case 'b':
return 11;
4162 case 'c':
return 12;
4164 case 'd':
return 13;
4166 case 'e':
return 14;
4168 case 'f':
return 15;
4173 if (isNumericAccessor)
4174 return getNumericAccessorIdx(
c);
4176 return getPointAccessorIdx(
c);
4180 if (
int idx = getAccessorIdx(
c, isNumericAccessor)+1)
4181 return unsigned(idx-1) < getNumElements();
4206 const Expr *RowExpr =
nullptr,
const Expr *ColumnExpr =
nullptr);
4240 static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
4243 unsigned NColumns,
QualType CanonElementType);
4246 unsigned NColumns,
QualType CanonElementType);
4257 return getNumRows() * getNumColumns();
4262 return NumElements > 0 && NumElements <= MaxElementsPerDimension;
4267 return MaxElementsPerDimension;
4271 Profile(
ID, getElementType(), getNumRows(), getNumColumns(),
4276 unsigned NumRows,
unsigned NumColumns,
4279 ID.AddInteger(NumRows);
4280 ID.AddInteger(NumColumns);
4312 Profile(
ID, Context, getElementType(), getRowExpr(), getColumnExpr());
4315 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4351 HasPassObjSize = 0x20,
4354 unsigned char Data = 0;
4363 copy.Data = (copy.Data & ~ABIMask) |
unsigned(kind);
4373 copy.Data |= IsConsumed;
4375 copy.Data &= ~IsConsumed;
4382 Copy.Data |= HasPassObjSize;
4390 Copy.Data |= IsNoEscape;
4392 Copy.Data &= ~IsNoEscape;
4404 return lhs.Data == rhs.Data;
4408 return lhs.Data != rhs.Data;
4443 enum { CallConvMask = 0x1F };
4444 enum { NoReturnMask = 0x20 };
4445 enum { ProducesResultMask = 0x40 };
4446 enum { NoCallerSavedRegsMask = 0x80 };
4448 RegParmMask = 0x700,
4451 enum { NoCfCheckMask = 0x800 };
4452 enum { CmseNSCallMask = 0x1000 };
4453 uint16_t Bits =
CC_C;
4455 ExtInfo(
unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
4461 bool producesResult,
bool noCallerSavedRegs,
bool NoCfCheck,
4463 assert((!hasRegParm || regParm < 7) &&
"Invalid regparm value");
4464 Bits = ((
unsigned)cc) | (noReturn ? NoReturnMask : 0) |
4465 (producesResult ? ProducesResultMask : 0) |
4466 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
4467 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
4468 (NoCfCheck ? NoCfCheckMask : 0) |
4469 (cmseNSCall ? CmseNSCallMask : 0);
4485 bool getHasRegParm()
const {
return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
4488 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
4497 return Bits ==
Other.Bits;
4500 return Bits !=
Other.Bits;
4508 return ExtInfo(Bits | NoReturnMask);
4510 return ExtInfo(Bits & ~NoReturnMask);
4515 return ExtInfo(Bits | ProducesResultMask);
4517 return ExtInfo(Bits & ~ProducesResultMask);
4522 return ExtInfo(Bits | CmseNSCallMask);
4524 return ExtInfo(Bits & ~CmseNSCallMask);
4528 if (noCallerSavedRegs)
4529 return ExtInfo(Bits | NoCallerSavedRegsMask);
4531 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4536 return ExtInfo(Bits | NoCfCheckMask);
4538 return ExtInfo(Bits & ~NoCfCheckMask);
4542 assert(RegParm < 7 &&
"Invalid regparm value");
4543 return ExtInfo((Bits & ~RegParmMask) |
4544 ((RegParm + 1) << RegParmOffset));
4548 return ExtInfo((Bits & ~CallConvMask) | (
unsigned) cc);
4552 ID.AddInteger(Bits);
4570 LLVM_PREFERRED_TYPE(
bool)
4573 LLVM_PREFERRED_TYPE(
bool)
4574 unsigned EffectsHaveConditions : 1;
4575 unsigned NumFunctionEffects : 4;
4578 : NumExceptionType(0), HasArmTypeAttributes(
false),
4579 EffectsHaveConditions(
false), NumFunctionEffects(0) {}
4586 SME_NormalFunction = 0,
4587 SME_PStateSMEnabledMask = 1 << 0,
4588 SME_PStateSMCompatibleMask = 1 << 1,
4592 SME_ZAMask = 0b111 << SME_ZAShift,
4594 SME_ZT0Mask = 0b111 << SME_ZT0Shift,
4610 return (
ArmStateValue)((AttrBits & SME_ZAMask) >> SME_ZAShift);
4614 return (
ArmStateValue)((AttrBits & SME_ZT0Mask) >> SME_ZT0Shift);
4632 FunctionTypeBits.ExtInfo = Info.Bits;
4636 if (isFunctionProtoType())
4637 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4657 static_assert((
~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4658 "Const, volatile and restrict are assumed to be a subset of "
4659 "the fast qualifiers.");
4661 bool isConst()
const {
return getFastTypeQuals().hasConst(); }
4662 bool isVolatile()
const {
return getFastTypeQuals().hasVolatile(); }
4663 bool isRestrict()
const {
return getFastTypeQuals().hasRestrict(); }
4671 static StringRef getNameForCallConv(
CallingConv CC);
4686 Result->getDependence() &
4698 Profile(
ID, getReturnType(), getExtInfo());
4726 constexpr static size_t KindCount =
static_cast<size_t>(Kind::Last) + 1;
4734 FE_InferrableOnCallees = 0x1,
4737 FE_ExcludeThrow = 0x2,
4738 FE_ExcludeCatch = 0x4,
4739 FE_ExcludeObjCMessageSend = 0x8,
4740 FE_ExcludeStaticLocalVars = 0x10,
4741 FE_ExcludeThreadLocalVars = 0x20