17#ifndef LLVM_CLANG_AST_TYPE_H
18#define LLVM_CLANG_AST_TYPE_H
33#include "llvm/ADT/APInt.h"
34#include "llvm/ADT/APSInt.h"
35#include "llvm/ADT/ArrayRef.h"
36#include "llvm/ADT/FoldingSet.h"
37#include "llvm/ADT/PointerIntPair.h"
38#include "llvm/ADT/PointerUnion.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/ADT/Twine.h"
41#include "llvm/ADT/iterator_range.h"
42#include "llvm/Support/Casting.h"
43#include "llvm/Support/Compiler.h"
44#include "llvm/Support/ErrorHandling.h"
45#include "llvm/Support/PointerLikeTypeTraits.h"
46#include "llvm/Support/TrailingObjects.h"
47#include "llvm/Support/type_traits.h"
64class TemplateParameterList;
72namespace serialization {
73 template <
class T>
class AbstractTypeReader;
110template <
typename>
class CanQual;
115class ExtQualsTypeCommonBase;
119class ObjCInterfaceDecl;
120class ObjCProtocolDecl;
121class ObjCTypeParamDecl;
122struct PrintingPolicy;
126class TemplateArgument;
127class TemplateArgumentListInfo;
128class TemplateArgumentLoc;
129class TemplateTypeParmDecl;
130class TypedefNameDecl;
131class UnresolvedUsingTypenameDecl;
132class UsingShadowDecl;
137#define TYPE(Class, Base) class Class##Type;
138#include "clang/AST/TypeNodes.inc"
201 Q.Mask = L.Mask & R.Mask;
298 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
299 Mask = (Mask & ~CVRMask) | mask;
302 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
309 assert(!(mask & ~
CVRMask) &&
"bitmask contains non-CVR bits");
313 assert(!(mask & ~
CVRMask & ~UMask) &&
"bitmask contains non-CVRU bits");
319 Mask = (Mask & ~UMask) | (flag ? UMask : 0);
327 Mask = (Mask & ~GCAttrMask) | (
type << GCAttrShift);
352 return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift);
355 Mask = (Mask & ~LifetimeMask) | (
type << LifetimeShift);
361 Mask |= (
type << LifetimeShift);
378 return static_cast<LangAS>(Mask >> AddressSpaceShift);
399 Mask = (Mask & ~AddressSpaceMask)
400 | (((uint32_t) space) << AddressSpaceShift);
413 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
414 Mask = (Mask & ~FastMask) | mask;
417 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
424 assert(!(mask & ~
FastMask) &&
"bitmask contains non-fast qualifier bits");
439 bool empty()
const {
return !Mask; }
604 bool appendSpaceIfNonEmpty =
false)
const;
615 static const uint32_t UMask = 0x8;
616 static const uint32_t UShift = 3;
617 static const uint32_t GCAttrMask = 0x30;
618 static const uint32_t GCAttrShift = 4;
619 static const uint32_t LifetimeMask = 0x1C0;
620 static const uint32_t LifetimeShift = 6;
621 static const uint32_t AddressSpaceMask =
622 ~(
CVRMask | UMask | GCAttrMask | LifetimeMask);
623 static const uint32_t AddressSpaceShift = 9;
633 : Quals(Quals), HasAtomic(HasAtomic) {}
682 std::pair<const Type *,Qualifiers>
asPair()
const {
683 return std::pair<const Type *, Qualifiers>(
Ty,
Quals);
687 return a.
Ty ==
b.Ty && a.
Quals ==
b.Quals;
690 return a.
Ty !=
b.Ty || a.
Quals !=
b.Quals;
740 llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>,
743 const ExtQuals *getExtQualsUnsafe()
const {
747 const Type *getTypePtrUnsafe()
const {
748 return Value.getPointer().get<
const Type*>();
751 const ExtQualsTypeCommonBase *getCommonPtr()
const {
752 assert(!
isNull() &&
"Cannot retrieve a NULL type pointer");
753 auto CommonPtrVal =
reinterpret_cast<uintptr_t>(
Value.getOpaqueValue());
755 return reinterpret_cast<ExtQualsTypeCommonBase*
>(CommonPtrVal);
787 T.Value.setFromOpaqueValue(
const_cast<void*
>(Ptr));
804 return Value.getPointer().isNull();
831 std::optional<NonConstantStorageReason>
973 &&
"non-fast qualifier bits set in mask!");
1098 return getSingleStepDesugaredTypeImpl(*
this, Context);
1104 if (isa<ParenType>(*
this))
1111 return LHS.Value == RHS.Value;
1114 return LHS.Value != RHS.Value;
1117 return LHS.Value < RHS.Value;
1131 const Twine &PlaceHolder = Twine(),
1132 unsigned Indentation = 0)
const;
1136 unsigned Indentation = 0) {
1142 const Twine &PlaceHolder,
1143 unsigned Indentation = 0);
1160 const Twine &PlaceHolder;
1161 unsigned Indentation;
1165 const Twine &PlaceHolder,
unsigned Indentation)
1166 : T(T), Policy(Policy), PlaceHolder(PlaceHolder),
1167 Indentation(Indentation) {}
1171 SQT.T.
print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation);
1177 const Twine &PlaceHolder = Twine(),
1178 unsigned Indentation = 0)
const {
1182 void dump(
const char *
s)
const;
1184 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
1320 return isDestructedTypeImpl(*
this);
1418raw_ostream &
operator<<(raw_ostream &OS, QualType QT);
1438 return P.getAsOpaquePtr();
1446 static constexpr int NumLowBitsAvailable = 0;
1466 const Type *
const BaseType;
1472 : BaseType(baseType), CanonicalType(canon) {}
1486 public llvm::FoldingSetNode {
1509 canon.isNull() ?
QualType(this_(), 0) : canon),
1511 assert(Quals.hasNonFastQualifiers()
1512 &&
"ExtQuals created with no fast qualifiers");
1513 assert(!Quals.hasFastQualifiers()
1514 &&
"ExtQuals created with fast qualifiers");
1524 return Quals.getObjCLifetime();
1534 Profile(
ID, getBaseType(), Quals);
1538 const Type *BaseType,
1541 ID.AddPointer(BaseType);
1572enum class ArraySizeModifier;
1573enum class ElaboratedTypeKeyword;
1574enum class VectorKind;
1605#define TYPE(Class, Base) Class,
1606#define LAST_TYPE(Class) TypeLast = Class
1607#define ABSTRACT_TYPE(Class, Base)
1608#include "clang/AST/TypeNodes.inc"
1613 class TypeBitfields {
1615 template <
class T>
friend class TypePropertyCache;
1618 LLVM_PREFERRED_TYPE(TypeClass)
1623 unsigned Dependence : llvm::BitWidth<TypeDependence>;
1627 LLVM_PREFERRED_TYPE(
bool)
1628 mutable unsigned CacheValid : 1;
1632 mutable unsigned CachedLinkage : 3;
1635 LLVM_PREFERRED_TYPE(
bool)
1636 mutable unsigned CachedLocalOrUnnamed : 1;
1639 LLVM_PREFERRED_TYPE(
bool)
1640 mutable unsigned FromAST : 1;
1642 bool isCacheValid()
const {
1647 assert(isCacheValid() &&
"getting linkage from invalid cache");
1648 return static_cast<Linkage>(CachedLinkage);
1651 bool hasLocalOrUnnamedType()
const {
1652 assert(isCacheValid() &&
"getting linkage from invalid cache");
1653 return CachedLocalOrUnnamed;
1656 enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 };
1665 LLVM_PREFERRED_TYPE(TypeBitfields)
1671 unsigned IndexTypeQuals : 3;
1676 unsigned SizeModifier : 3;
1678 enum { NumArrayTypeBits = NumTypeBits + 6 };
1687 LLVM_PREFERRED_TYPE(
bool)
1688 unsigned HasStoredSizeExpr : 1;
1694 LLVM_PREFERRED_TYPE(TypeBitfields)
1698 static constexpr unsigned NumOfBuiltinTypeBits = 9;
1699 unsigned Kind : NumOfBuiltinTypeBits;
1709 LLVM_PREFERRED_TYPE(TypeBitfields)
1715 unsigned ExtInfo : 13;
1721 unsigned RefQualifier : 2;
1730 unsigned FastTypeQuals : Qualifiers::FastWidth;
1732 LLVM_PREFERRED_TYPE(
bool)
1733 unsigned HasExtQuals : 1;
1739 unsigned NumParams : 16;
1743 unsigned ExceptionSpecType : 4;
1746 LLVM_PREFERRED_TYPE(
bool)
1747 unsigned HasExtParameterInfos : 1;
1750 LLVM_PREFERRED_TYPE(
bool)
1751 unsigned HasExtraBitfields : 1;
1754 LLVM_PREFERRED_TYPE(
bool)
1755 unsigned Variadic : 1;
1758 LLVM_PREFERRED_TYPE(
bool)
1759 unsigned HasTrailingReturn : 1;
1765 LLVM_PREFERRED_TYPE(TypeBitfields)
1769 unsigned NumTypeArgs : 7;
1772 unsigned NumProtocols : 6;
1775 LLVM_PREFERRED_TYPE(
bool)
1776 unsigned IsKindOf : 1;
1782 LLVM_PREFERRED_TYPE(TypeBitfields)
1796 LLVM_PREFERRED_TYPE(
bool)
1797 unsigned SpelledAsLValue : 1;
1801 LLVM_PREFERRED_TYPE(
bool)
1802 unsigned InnerRef : 1;
1808 LLVM_PREFERRED_TYPE(TypeBitfields)
1813 unsigned Keyword : 8;
1816 enum { NumTypeWithKeywordBits = NumTypeBits + 8 };
1825 LLVM_PREFERRED_TYPE(
bool)
1826 unsigned HasOwnedTagDecl : 1;
1833 LLVM_PREFERRED_TYPE(TypeBitfields)
1839 unsigned VecKind : 4;
1841 uint32_t NumElements;
1847 LLVM_PREFERRED_TYPE(TypeBitfields)
1851 unsigned AttrKind : 32 - NumTypeBits;
1857 LLVM_PREFERRED_TYPE(TypeBitfields)
1863 unsigned Keyword : 2;
1879 LLVM_PREFERRED_TYPE(TypeBitfields)
1881 LLVM_PREFERRED_TYPE(
bool)
1882 unsigned IsUnqual : 1;
1888 LLVM_PREFERRED_TYPE(TypeBitfields)
1892 LLVM_PREFERRED_TYPE(
bool)
1893 unsigned hasTypeDifferentFromDecl : 1;
1899 LLVM_PREFERRED_TYPE(TypeBitfields)
1903 LLVM_PREFERRED_TYPE(
bool)
1904 unsigned hasTypeDifferentFromDecl : 1;
1910 LLVM_PREFERRED_TYPE(TypeBitfields)
1913 LLVM_PREFERRED_TYPE(
bool)
1914 unsigned HasNonCanonicalUnderlyingType : 1;
1917 unsigned Index : 15;
1924 unsigned PackIndex : 16;
1930 LLVM_PREFERRED_TYPE(TypeBitfields)
1934 unsigned Index : 16;
1940 unsigned NumArgs : 16;
1946 LLVM_PREFERRED_TYPE(TypeBitfields)
1950 LLVM_PREFERRED_TYPE(
bool)
1951 unsigned TypeAlias : 1;
1982 LLVM_PREFERRED_TYPE(TypeBitfields)
1996 unsigned NumExpansions;
2027 void setFromAST(
bool V =
true)
const {
2028 TypeBits.FromAST =
V;
2036 canon.isNull() ?
QualType(this_(), 0) : canon) {
2037 static_assert(
sizeof(*this) <=
2039 "changing bitfields changed sizeof(Type)!");
2040 static_assert(
alignof(
decltype(*this)) %
TypeAlignment == 0,
2041 "Insufficient alignment!");
2043 TypeBits.Dependence =
static_cast<unsigned>(
Dependence);
2044 TypeBits.CacheValid =
false;
2045 TypeBits.CachedLocalOrUnnamed =
false;
2046 TypeBits.CachedLinkage = llvm::to_underlying(Linkage::Invalid);
2047 TypeBits.FromAST =
false;
2054 TypeBits.Dependence =
static_cast<unsigned>(D);
2091 return getDependence() & TypeDependence::UnexpandedPack;
2097 return CanonicalType ==
QualType(
this, 0);
2103 QualType getLocallyUnqualifiedSingleStepDesugaredType()
const;
2111 bool isSizelessType()
const;
2112 bool isSizelessBuiltinType()
const;
2115 bool isSizelessVectorType()
const;
2118 bool isSVESizelessBuiltinType()
const;
2121 bool isRVVSizelessBuiltinType()
const;
2124 bool isWebAssemblyExternrefType()
const;
2129 bool isWebAssemblyTableType()
const;
2134 bool isSveVLSBuiltinType()
const;
2144 bool isRVVVLSBuiltinType()
const;
2162 bool isIncompleteType(
NamedDecl **Def =
nullptr)
const;
2167 return !isFunctionType();
2175 return !isReferenceType() && !isFunctionType() && !isVoidType();
2180 bool isLiteralType(
const ASTContext &Ctx)
const;
2183 bool isStructuralType()
const;
2187 bool isStandardLayoutType()
const;
2193 bool isBuiltinType()
const;
2196 bool isSpecificBuiltinType(
unsigned K)
const;
2201 bool isPlaceholderType()
const;
2205 bool isSpecificPlaceholderType(
unsigned K)
const;
2209 bool isNonOverloadPlaceholderType()
const;
2213 bool isIntegerType()
const;
2214 bool isEnumeralType()
const;
2217 bool isScopedEnumeralType()
const;
2219 bool isCharType()
const;
2220 bool isWideCharType()
const;
2221 bool isChar8Type()
const;
2222 bool isChar16Type()
const;
2223 bool isChar32Type()
const;
2224 bool isAnyCharacterType()
const;
2225 bool isIntegralType(
const ASTContext &Ctx)
const;
2228 bool isIntegralOrEnumerationType()
const;
2231 bool isIntegralOrUnscopedEnumerationType()
const;
2232 bool isUnscopedEnumerationType()
const;
2235 bool isRealFloatingType()
const;
2238 bool isComplexType()
const;
2239 bool isAnyComplexType()
const;
2240 bool isFloatingType()
const;
2241 bool isHalfType()
const;
2242 bool isFloat16Type()
const;
2243 bool isBFloat16Type()
const;
2244 bool isFloat128Type()
const;
2245 bool isIbm128Type()
const;
2246 bool isRealType()
const;
2247 bool isArithmeticType()
const;
2248 bool isVoidType()
const;
2249 bool isScalarType()
const;
2250 bool isAggregateType()
const;
2251 bool isFundamentalType()
const;
2252 bool isCompoundType()
const;
2256 bool isFunctionType()
const;
2259 bool isPointerType()
const;
2260 bool isAnyPointerType()
const;
2261 bool isBlockPointerType()
const;
2262 bool isVoidPointerType()
const;
2263 bool isReferenceType()
const;
2264 bool isLValueReferenceType()
const;
2265 bool isRValueReferenceType()
const;
2266 bool isObjectPointerType()
const;
2267 bool isFunctionPointerType()
const;
2268 bool isFunctionReferenceType()
const;
2269 bool isMemberPointerType()
const;
2270 bool isMemberFunctionPointerType()
const;
2271 bool isMemberDataPointerType()
const;
2272 bool isArrayType()
const;
2273 bool isConstantArrayType()
const;
2274 bool isIncompleteArrayType()
const;
2275 bool isVariableArrayType()
const;
2276 bool isDependentSizedArrayType()
const;
2278 bool isClassType()
const;
2279 bool isStructureType()
const;
2280 bool isObjCBoxableRecordType()
const;
2281 bool isInterfaceType()
const;
2282 bool isStructureOrClassType()
const;
2283 bool isUnionType()
const;
2284 bool isComplexIntegerType()
const;
2285 bool isVectorType()
const;
2286 bool isExtVectorType()
const;
2287 bool isExtVectorBoolType()
const;
2288 bool isMatrixType()
const;
2289 bool isConstantMatrixType()
const;
2290 bool isDependentAddressSpaceType()
const;
2291 bool isObjCObjectPointerType()
const;
2292 bool isObjCRetainableType()
const;
2293 bool isObjCLifetimeType()
const;
2294 bool isObjCIndirectLifetimeType()
const;
2295 bool isObjCNSObjectType()
const;
2296 bool isObjCIndependentClassType()
const;
2299 bool isObjCObjectType()
const;
2300 bool isObjCQualifiedInterfaceType()
const;
2301 bool isObjCQualifiedIdType()
const;
2302 bool isObjCQualifiedClassType()
const;
2303 bool isObjCObjectOrInterfaceType()
const;
2304 bool isObjCIdType()
const;
2305 bool isDecltypeType()
const;
2313 return hasAttr(attr::ObjCInertUnsafeUnretained);
2323 bool isObjCIdOrObjectKindOfType(
const ASTContext &ctx,
2326 bool isObjCClassType()
const;
2334 bool isObjCClassOrClassKindOfType()
const;
2336 bool isBlockCompatibleObjCPointerType(
ASTContext &ctx)
const;
2337 bool isObjCSelType()
const;
2338 bool isObjCBuiltinType()
const;
2339 bool isObjCARCBridgableType()
const;
2340 bool isCARCBridgableType()
const;
2341 bool isTemplateTypeParmType()
const;
2342 bool isNullPtrType()
const;
2344 bool isNothrowT()
const;
2345 bool isAlignValT()
const;
2346 bool isStdByteType()
const;
2347 bool isAtomicType()
const;
2348 bool isUndeducedAutoType()
const;
2350 bool isTypedefNameType()
const;
2352#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2353 bool is##Id##Type() const;
2354#include "clang/Basic/OpenCLImageTypes.def"
2356 bool isImageType()
const;
2358 bool isSamplerT()
const;
2359 bool isEventT()
const;
2360 bool isClkEventT()
const;
2361 bool isQueueT()
const;
2362 bool isReserveIDT()
const;
2364#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2365 bool is##Id##Type() const;
2366#include "clang/Basic/OpenCLExtensionTypes.def"
2368 bool isOCLIntelSubgroupAVCType()
const;
2369 bool isOCLExtOpaqueType()
const;
2371 bool isPipeType()
const;
2372 bool isBitIntType()
const;
2373 bool isOpenCLSpecificType()
const;
2378 bool isObjCARCImplicitlyUnretainedType()
const;
2381 bool isCUDADeviceBuiltinSurfaceType()
const;
2383 bool isCUDADeviceBuiltinTextureType()
const;
2385 bool isRVVType(
unsigned ElementCount)
const;
2387 bool isRVVType()
const;
2389 bool isRVVType(
unsigned Bitwidth,
bool IsFloat,
bool IsBFloat =
false)
const;
2408 ScalarTypeKind getScalarTypeKind()
const;
2416 return getDependence() & TypeDependence::Error;
2422 return getDependence() & TypeDependence::Dependent;
2430 return getDependence() & TypeDependence::Instantiation;
2436 bool isUndeducedType()
const;
2440 return getDependence() & TypeDependence::VariablyModified;
2445 bool hasSizedVLAType()
const;
2448 bool hasUnnamedOrLocalType()
const;
2450 bool isOverloadableType()
const;
2453 bool isElaboratedTypeSpecifier()
const;
2455 bool canDecayToPointerType()
const;
2460 bool hasPointerRepresentation()
const;
2464 bool hasObjCPointerRepresentation()
const;
2468 bool hasIntegerRepresentation()
const;
2472 bool hasSignedIntegerRepresentation()
const;
2476 bool hasUnsignedIntegerRepresentation()
const;
2480 bool hasFloatingRepresentation()
const;
2485 const RecordType *getAsStructureType()
const;
2488 const ComplexType *getAsComplexIntegerType()
const;
2509 TagDecl *getAsTagDecl()
const;
2527 return dyn_cast_or_null<AutoType>(getContainedDeducedType());
2533 bool hasAutoForTrailingReturnType()
const;
2541 template <
typename T>
const T *getAs()
const;
2548 template <
typename T>
const T *getAsAdjusted()
const;
2552 const ArrayType *getAsArrayTypeUnsafe()
const;
2560 template <
typename T>
const T *castAs()
const;
2564 const ArrayType *castAsArrayTypeUnsafe()
const;
2573 const Type *getBaseElementTypeUnsafe()
const;
2578 const Type *getArrayElementTypeNoTypeQual()
const;
2583 const Type *getPointeeOrArrayElementType()
const;
2591 const Type *getUnqualifiedDesugaredType()
const;
2596 bool isSignedIntegerType()
const;
2601 bool isUnsignedIntegerType()
const;
2605 bool isSignedIntegerOrEnumerationType()
const;
2609 bool isUnsignedIntegerOrEnumerationType()
const;
2613 bool isFixedPointType()
const;
2616 bool isFixedPointOrIntegerType()
const;
2620 bool isSaturatedFixedPointType()
const;
2624 bool isUnsaturatedFixedPointType()
const;
2628 bool isSignedFixedPointType()
const;
2632 bool isUnsignedFixedPointType()
const;
2637 bool isConstantSizeType()
const;
2641 bool isSpecifierType()
const;
2648 return getLinkageAndVisibility().getVisibility();
2653 return getLinkageAndVisibility().isVisibilityExplicit();
2661 bool isLinkageValid()
const;
2668 std::optional<NullabilityKind> getNullability()
const;
2675 bool canHaveNullability(
bool ResultIfUnknown =
true)
const;
2692 std::optional<ArrayRef<QualType>>
2693 getObjCSubstitutions(
const DeclContext *dc)
const;
2697 bool acceptsObjCTypeParams()
const;
2699 const char *getTypeClassName()
const;
2702 return CanonicalType;
2707 void dump(llvm::raw_ostream &OS,
const ASTContext &Context)
const;
2712template <>
const TypedefType *Type::getAs()
const;
2713template <>
const UsingType *Type::getAs()
const;
2718template <>
const TemplateSpecializationType *Type::getAs()
const;
2722template <>
const AttributedType *Type::getAs()
const;
2726#define TYPE(Class, Base)
2727#define LEAF_TYPE(Class) \
2728template <> inline const Class##Type *Type::getAs() const { \
2729 return dyn_cast<Class##Type>(CanonicalType); \
2731template <> inline const Class##Type *Type::castAs() const { \
2732 return cast<Class##Type>(CanonicalType); \
2734#include "clang/AST/TypeNodes.inc"
2742#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id,
2743#include "clang/Basic/OpenCLImageTypes.def"
2745#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id,
2746#include "clang/Basic/OpenCLExtensionTypes.def"
2748#define SVE_TYPE(Name, Id, SingletonId) Id,
2749#include "clang/Basic/AArch64SVEACLETypes.def"
2751#define PPC_VECTOR_TYPE(Name, Id, Size) Id,
2752#include "clang/Basic/PPCTypes.def"
2754#define RVV_TYPE(Name, Id, SingletonId) Id,
2755#include "clang/Basic/RISCVVTypes.def"
2757#define WASM_TYPE(Name, Id, SingletonId) Id,
2758#include "clang/Basic/WebAssemblyReferenceTypes.def"
2760#define BUILTIN_TYPE(Id, SingletonId) Id,
2761#define LAST_BUILTIN_TYPE(Id) LastKind = Id
2762#include "clang/AST/BuiltinTypes.def"
2772 static_assert(Kind::LastKind <
2773 (1 << BuiltinTypeBitfields::NumOfBuiltinTypeBits) &&
2774 "Defined builtin type exceeds the allocated space for serial "
2776 BuiltinTypeBits.Kind = K;
2785 StringRef str =
getName(Policy);
2786 assert(!str.empty() && str.data()[str.size()] ==
'\0');
2815 return K >= Overload;
2822 return isPlaceholderTypeKind(
getKind());
2849 :
Type(
Complex, CanonicalPtr, Element->getDependence()),
2850 ElementType(Element) {}
2859 Profile(
ID, getElementType());
2863 ID.AddPointer(Element.getAsOpaquePtr());
2876 :
Type(
Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {}
2885 Profile(
ID, getInnerType());
2902 :
Type(
Pointer, CanonicalPtr, Pointee->getDependence()),
2903 PointeeType(Pointee) {}
2912 Profile(
ID, getPointeeType());
2934 :
Type(TC, CanonicalPtr, OriginalTy->getDependence()),
2935 OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {}
2945 Profile(
ID, OriginalTy, AdjustedTy);
2968 inline QualType getPointeeType()
const;
2983 :
Type(BlockPointer, CanonicalCls, Pointee->getDependence()),
2984 PointeeType(Pointee) {}
2994 Profile(
ID, getPointeeType());
3012 bool SpelledAsLValue)
3013 :
Type(tc, CanonicalRef, Referencee->getDependence()),
3014 PointeeType(Referencee) {
3015 ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue;
3030 return T->PointeeType;
3034 Profile(
ID, PointeeType, isSpelledAsLValue());
3039 bool SpelledAsLValue) {
3041 ID.AddBoolean(SpelledAsLValue);
3055 bool SpelledAsLValue)
3097 :
Type(MemberPointer, CanonicalPtr,
3099 Pointee->getDependence()),
3100 PointeeType(Pointee),
Class(Cls) {}
3124 Profile(
ID, getPointeeType(), getClass());
3128 const Type *Class) {
3154 unsigned tq,
const Expr *sz =
nullptr);
3164 return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers());
3168 return ArrayTypeBits.IndexTypeQuals;
3184 private llvm::TrailingObjects<ConstantArrayType, const Expr *> {
3186 friend TrailingObjects;
3192 :
ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) {
3193 ConstantArrayTypeBits.HasStoredSizeExpr = sz !=
nullptr;
3194 if (ConstantArrayTypeBits.HasStoredSizeExpr) {
3195 assert(!can.
isNull() &&
"canonical constant array should not have size");
3196 *getTrailingObjects<const Expr*>() = sz;
3200 unsigned numTrailingObjects(OverloadToken<const Expr*>)
const {
3201 return ConstantArrayTypeBits.HasStoredSizeExpr;
3205 const llvm::APInt &
getSize()
const {
return Size; }
3207 return ConstantArrayTypeBits.HasStoredSizeExpr
3208 ? *getTrailingObjects<const Expr *>()
3216 static unsigned getNumAddressingBits(
const ASTContext &Context,
3218 const llvm::APInt &NumElements);
3220 unsigned getNumAddressingBits(
const ASTContext &Context)
const;
3224 static unsigned getMaxSizeBits(
const ASTContext &Context);
3227 Profile(
ID, Ctx, getElementType(), getSize(), getSizeExpr(),
3228 getSizeModifier(), getIndexTypeCVRQualifiers());
3231 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx,
3232 QualType ET,
const llvm::APInt &ArraySize,
3234 unsigned TypeQuals);
3249 :
ArrayType(IncompleteArray, et, can, sm, tq) {}
3262 Profile(
ID, getElementType(), getSizeModifier(),
3263 getIndexTypeCVRQualifiers());
3269 ID.AddInteger(llvm::to_underlying(SizeMod));
3270 ID.AddInteger(TypeQuals);
3301 :
ArrayType(VariableArray, et, can, sm, tq, e),
3302 SizeExpr((
Stmt*) e), Brackets(brackets) {}
3310 return (
Expr*) SizeExpr;
3325 llvm_unreachable(
"Cannot unique VariableArrayTypes.");
3365 return (
Expr*) SizeExpr;
3380 Profile(
ID, Context, getElementType(),
3381 getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr());
3384 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3386 unsigned TypeQuals,
Expr *E);
3403 Expr *AddrSpaceExpr;
3423 Profile(
ID, Context, getPointeeType(), getAddrSpaceExpr());
3426 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3466 Profile(
ID, Context, getElementType(), getSizeExpr());
3469 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3532 Profile(
ID, getElementType(), getNumElements(),
3533 getTypeClass(), getVectorKind());
3540 ID.AddInteger(NumElements);
3542 ID.AddInteger(llvm::to_underlying(VecKind));
3585 Profile(
ID, Context, getElementType(), getSizeExpr(), getVectorKind());
3588 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3603 :
VectorType(ExtVector, vecType, nElements, canonType,
3610 case 'x':
case 'r':
return 0;
3611 case 'y':
case 'g':
return 1;
3612 case 'z':
case 'b':
return 2;
3613 case 'w':
case 'a':
return 3;
3631 case 'a':
return 10;
3633 case 'b':
return 11;
3635 case 'c':
return 12;
3637 case 'd':
return 13;
3639 case 'e':
return 14;
3641 case 'f':
return 15;
3646 if (isNumericAccessor)
3647 return getNumericAccessorIdx(
c);
3649 return getPointAccessorIdx(
c);
3653 if (
int idx = getAccessorIdx(
c, isNumericAccessor)+1)
3654 return unsigned(idx-1) < getNumElements();
3679 const Expr *RowExpr =
nullptr,
const Expr *ColumnExpr =
nullptr);
3713 static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1;
3716 unsigned NColumns,
QualType CanonElementType);
3719 unsigned NColumns,
QualType CanonElementType);
3730 return getNumRows() * getNumColumns();
3735 return NumElements > 0 && NumElements <= MaxElementsPerDimension;
3740 return MaxElementsPerDimension;
3744 Profile(
ID, getElementType(), getNumRows(), getNumColumns(),
3749 unsigned NumRows,
unsigned NumColumns,
3752 ID.AddInteger(NumRows);
3753 ID.AddInteger(NumColumns);
3785 Profile(
ID, Context, getElementType(), getRowExpr(), getColumnExpr());
3788 static void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
3824 HasPassObjSize = 0x20,
3827 unsigned char Data = 0;
3836 copy.Data = (copy.Data & ~ABIMask) |
unsigned(kind);
3846 copy.Data |= IsConsumed;
3848 copy.Data &= ~IsConsumed;
3855 Copy.Data |= HasPassObjSize;
3863 Copy.Data |= IsNoEscape;
3865 Copy.Data &= ~IsNoEscape;
3877 return lhs.Data == rhs.Data;
3881 return lhs.Data != rhs.Data;
3916 enum { CallConvMask = 0x1F };
3917 enum { NoReturnMask = 0x20 };
3918 enum { ProducesResultMask = 0x40 };
3919 enum { NoCallerSavedRegsMask = 0x80 };
3921 RegParmMask = 0x700,
3924 enum { NoCfCheckMask = 0x800 };
3925 enum { CmseNSCallMask = 0x1000 };
3926 uint16_t Bits =
CC_C;
3928 ExtInfo(
unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {}
3934 bool producesResult,
bool noCallerSavedRegs,
bool NoCfCheck,
3936 assert((!hasRegParm || regParm < 7) &&
"Invalid regparm value");
3937 Bits = ((
unsigned)cc) | (noReturn ? NoReturnMask : 0) |
3938 (producesResult ? ProducesResultMask : 0) |
3939 (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) |
3940 (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) |
3941 (NoCfCheck ? NoCfCheckMask : 0) |
3942 (cmseNSCall ? CmseNSCallMask : 0);
3958 bool getHasRegParm()
const {
return ((Bits & RegParmMask) >> RegParmOffset) != 0; }
3961 unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset;
3970 return Bits ==
Other.Bits;
3973 return Bits !=
Other.Bits;
3981 return ExtInfo(Bits | NoReturnMask);
3983 return ExtInfo(Bits & ~NoReturnMask);
3988 return ExtInfo(Bits | ProducesResultMask);
3990 return ExtInfo(Bits & ~ProducesResultMask);
3995 return ExtInfo(Bits | CmseNSCallMask);
3997 return ExtInfo(Bits & ~CmseNSCallMask);
4001 if (noCallerSavedRegs)
4002 return ExtInfo(Bits | NoCallerSavedRegsMask);
4004 return ExtInfo(Bits & ~NoCallerSavedRegsMask);
4009 return ExtInfo(Bits | NoCfCheckMask);
4011 return ExtInfo(Bits & ~NoCfCheckMask);
4015 assert(RegParm < 7 &&
"Invalid regparm value");
4016 return ExtInfo((Bits & ~RegParmMask) |
4017 ((RegParm + 1) << RegParmOffset));
4021 return ExtInfo((Bits & ~CallConvMask) | (
unsigned) cc);
4025 ID.AddInteger(Bits);
4038 SME_NormalFunction = 0,
4039 SME_PStateSMEnabledMask = 1 << 0,
4040 SME_PStateSMCompatibleMask = 1 << 1,
4041 SME_PStateZASharedMask = 1 << 2,
4042 SME_PStateZAPreservedMask = 1 << 3,
4043 SME_AttributeMask = 0b111'111
4060 : NumExceptionType(0), AArch64SMEAttributes(SME_NormalFunction) {}
4067 FunctionTypeBits.ExtInfo = Info.Bits;
4071 if (isFunctionProtoType())
4072 return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals);
4092 static_assert((
~Qualifiers::FastMask & Qualifiers::CVRMask) == 0,
4093 "Const, volatile and restrict are assumed to be a subset of "
4094 "the fast qualifiers.");
4096 bool isConst()
const {
return getFastTypeQuals().hasConst(); }
4097 bool isVolatile()
const {
return getFastTypeQuals().hasVolatile(); }
4098 bool isRestrict()
const {
return getFastTypeQuals().hasRestrict(); }
4106 static StringRef getNameForCallConv(
CallingConv CC);
4121 Result->getDependence() &
4133 Profile(
ID, getReturnType(), getExtInfo());
4156 public llvm::FoldingSetNode,
4157 private llvm::TrailingObjects<
4158 FunctionProtoType, QualType, SourceLocation,
4159 FunctionType::FunctionTypeExtraBitfields, FunctionType::ExceptionType,
4160 Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> {
4162 friend TrailingObjects;
4250 AArch64SMEAttributes(SME_NormalFunction) {}
4254 AArch64SMEAttributes(SME_NormalFunction) {}
4258 Result.ExceptionSpec = ESI;
4264 AArch64SMEAttributes != SME_NormalFunction;
4269 AArch64SMEAttributes |= Kind;
4271 AArch64SMEAttributes &= ~Kind;
4276 unsigned numTrailingObjects(OverloadToken<QualType>)
const {
4277 return getNumParams();
4280 unsigned numTrailingObjects(OverloadToken<SourceLocation>)
const {
4281 return isVariadic();
4284 unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>)
const {
4285 return hasExtraBitfields();
4288 unsigned numTrailingObjects(OverloadToken<ExceptionType>)
const {
4289 return getExceptionSpecSize().NumExceptionType;
4292 unsigned numTrailingObjects(OverloadToken<Expr *>)
const {
4293 return getExceptionSpecSize().NumExprPtr;
4296 unsigned numTrailingObjects(OverloadToken<FunctionDecl *>)
const {
4297 return getExceptionSpecSize().NumFunctionDeclPtr;
4300 unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>)
const {
4301 return hasExtParameterInfos() ? getNumParams() : 0;
4306 static bool containsAnyUnexpandedParameterPack(
const QualType *ArgArray,
4308 for (
unsigned Idx = 0; Idx < numArgs; ++Idx)
4309 if (ArgArray[Idx]->containsUnexpandedParameterPack())
4315 FunctionProtoType(QualType result, ArrayRef<QualType> params,
4316 QualType canonical,
const ExtProtoInfo &epi);
4321 struct ExceptionSpecSizeHolder {
4322 unsigned NumExceptionType;
4323 unsigned NumExprPtr;
4324 unsigned NumFunctionDeclPtr;
4329 static ExceptionSpecSizeHolder
4330 getExceptionSpecSize(ExceptionSpecificationType EST,
unsigned NumExceptions) {
4341 return {NumExceptions, 0, 0};
4354 llvm_unreachable(
"bad exception specification kind");
4359 ExceptionSpecSizeHolder getExceptionSpecSize()
const {
4360 return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions());
4364 bool hasExtraBitfields()
const {
4365 assert((getExceptionSpecType() != EST_Dynamic ||
4366 FunctionTypeBits.HasExtraBitfields) &&
4367 "ExtraBitfields are required for given ExceptionSpecType");
4368 return FunctionTypeBits.HasExtraBitfields;
4372 bool hasExtQualifiers()
const {
4373 return FunctionTypeBits.HasExtQuals;
4380 assert(i < getNumParams() &&
"invalid parameter index");
4381 return param_type_begin()[i];
4405 FunctionTypeBits.ExceptionSpecType);
4422 bool hasDependentExceptionSpec()
const;
4426 bool hasInstantiationDependentExceptionSpec()
const;
4431 Result.Type = getExceptionSpecType();
4433 Result.Exceptions = exceptions();
4435 Result.NoexceptExpr = getNoexceptExpr();
4437 Result.SourceDecl = getExceptionSpecDecl();
4438 Result.SourceTemplate = getExceptionSpecTemplate();
4440 Result.SourceDecl = getExceptionSpecDecl();
4448 ? getTrailingObjects<FunctionTypeExtraBitfields>()
4455 assert(i < getNumExceptions() &&
"Invalid exception number!");
4456 return exception_begin()[i];
4464 return *getTrailingObjects<Expr *>();
4475 return getTrailingObjects<FunctionDecl *>()[0];
4485 return getTrailingObjects<FunctionDecl *>()[1];
4496 return ResultIfDependent ? canThrow() !=
CT_Can : canThrow() ==
CT_Cannot;
4503 return isVariadic() ? *getTrailingObjects<SourceLocation>()
4513 bool isTemplateVariadic()
const;
4519 if (hasExtQualifiers())
4520 return *getTrailingObjects<Qualifiers>();
4522 return getFastTypeQuals();
4537 return getTrailingObjects<QualType>();
4541 return param_type_begin() + getNumParams();
4552 getTrailingObjects<ExceptionType>());
4556 return exception_begin() + getNumExceptions();
4562 return FunctionTypeBits.HasExtParameterInfos;
4566 assert(hasExtParameterInfos());
4575 if (!hasExtParameterInfos())
4577 return getTrailingObjects<ExtParameterInfo>();
4583 if (!hasExtraBitfields())
4584 return SME_NormalFunction;
4585 return getTrailingObjects<FunctionTypeExtraBitfields>()
4586 ->AArch64SMEAttributes;
4590 assert(I < getNumParams() &&
"parameter index out of range");
4591 if (hasExtParameterInfos())
4592 return getTrailingObjects<ExtParameterInfo>()[I];
4597 assert(I < getNumParams() &&
"parameter index out of range");
4598 if (hasExtParameterInfos())
4599 return getTrailingObjects<ExtParameterInfo>()[I].getABI();
4600 return ParameterABI::Ordinary;
4604 assert(I < getNumParams() &&
"parameter index out of range");
4605 if (hasExtParameterInfos())
4606 return getTrailingObjects<ExtParameterInfo>()[I].isConsumed();
4613 void printExceptionSpecification(raw_ostream &OS,
4620 void Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Ctx);
4653 return Profile(
ID,
Decl);
4663 public llvm::FoldingSetNode,
4664 private llvm::TrailingObjects<UsingType, QualType> {
4667 friend TrailingObjects;
4688 ID.AddPointer(Found);
4689 if (!Underlying.
isNull())
4696 public llvm::FoldingSetNode,
4697 private llvm::TrailingObjects<TypedefType, QualType> {
4700 friend TrailingObjects;
4722 if (!Underlying.
isNull())
4739 :
Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()),
4740 UnderlyingTy(UnderlyingTy), MacroII(MacroII) {
4741 assert(isa<AttributedType>(UnderlyingTy) &&
4742 "Expected a macro qualified type to only wrap attributed types.");
4776 return TypeOfBits.IsUnqual ? TypeOfKind::Unqualified
4777 : TypeOfKind::Qualified;