41 #include "llvm/ADT/APInt.h"
42 #include "llvm/ADT/APSInt.h"
43 #include "llvm/ADT/ArrayRef.h"
44 #include "llvm/ADT/FoldingSet.h"
45 #include "llvm/ADT/SmallVector.h"
46 #include "llvm/Support/Casting.h"
47 #include "llvm/Support/ErrorHandling.h"
48 #include "llvm/Support/MathExtras.h"
54 #include <type_traits>
56 using namespace clang;
59 return (*
this != Other) &&
86 getElementType().getBaseTypeIdentifier();
108 return AT->getElementType().isConstant(Ctx);
127 et->getDependence() |
133 (tc == DependentSizedArray
152 if (llvm::isPowerOf2_64(ElementSize)) {
153 return NumElements.getActiveBits() + llvm::Log2_64(ElementSize);
158 if ((ElementSize >> 32) == 0 && NumElements.getBitWidth() <= 64 &&
159 (NumElements.getZExtValue() >> 32) == 0) {
160 uint64_t TotalSize = NumElements.getZExtValue() * ElementSize;
161 return llvm::bit_width(TotalSize);
167 SizeExtended = SizeExtended.extend(
std::max(SizeTypeBits,
168 SizeExtended.getBitWidth()) * 2);
171 TotalSize *= SizeExtended;
173 return TotalSize.getActiveBits();
192 unsigned TypeQuals) {
194 ID.AddInteger(ArraySize.getZExtValue());
195 ID.AddInteger(SizeMod);
196 ID.AddInteger(TypeQuals);
197 ID.AddBoolean(SizeExpr !=
nullptr);
202 DependentSizedArrayType::DependentSizedArrayType(
const ASTContext &Context,
204 Expr *e, ArraySizeModifier sm,
207 :
ArrayType(DependentSizedArray, et, can, sm, tq, e),
208 Context(Context), SizeExpr((
Stmt*) e), Brackets(brackets) {}
217 ID.AddInteger(SizeMod);
218 ID.AddInteger(TypeQuals);
222 DependentVectorType::DependentVectorType(
const ASTContext &Context,
227 :
Type(DependentVector, CanonType,
229 ElementType->getDependence() |
232 Context(Context), ElementType(ElementType), SizeExpr(SizeExpr), Loc(Loc) {
241 ID.AddInteger(VecKind);
245 DependentSizedExtVectorType::DependentSizedExtVectorType(
248 :
Type(DependentSizedExtVector, can,
250 ElementType->getDependence() |
253 Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {
264 DependentAddressSpaceType::DependentAddressSpaceType(
const ASTContext &Context,
269 :
Type(DependentAddressSpace, can,
271 PointeeType->getDependence() |
274 Context(Context), AddrSpaceExpr(AddrSpaceExpr), PointeeType(PointeeType),
280 Expr *AddrSpaceExpr) {
282 AddrSpaceExpr->
Profile(
ID, Context,
true);
286 const Expr *RowExpr,
const Expr *ColumnExpr)
287 :
Type(tc, canonType,
288 (RowExpr ? (matrixType->getDependence() |
TypeDependence::Dependent |
290 (matrixType->isVariablyModifiedType()
293 (matrixType->containsUnexpandedParameterPack() ||
295 RowExpr->containsUnexpandedParameterPack()) ||
297 ColumnExpr->containsUnexpandedParameterPack())
300 : matrixType->getDependence())),
301 ElementType(matrixType) {}
304 unsigned nColumns,
QualType canonType)
309 unsigned nRows,
unsigned nColumns,
311 :
MatrixType(tc, matrixType, canonType), NumRows(nRows),
312 NumColumns(nColumns) {}
314 DependentSizedMatrixType::DependentSizedMatrixType(
317 :
MatrixType(DependentSizedMatrix, ElementType, CanonicalType, RowExpr,
319 Context(CTX), RowExpr(RowExpr), ColumnExpr(ColumnExpr), loc(loc) {}
332 :
VectorType(Vector, vecType, nElements, canonType, vecKind) {}
336 :
Type(tc, canonType, vecType->getDependence()), ElementType(vecType) {
346 bool IsUnsigned,
Expr *NumBitsExpr)
349 Context(Context), ExprAndUnsigned(NumBitsExpr, IsUnsigned) {}
352 return ExprAndUnsigned.getInt();
356 return ExprAndUnsigned.getPointer();
362 ID.AddBoolean(IsUnsigned);
371 if (
const auto *ATy = dyn_cast<ArrayType>(
this))
372 return ATy->getElementType().getTypePtr();
375 if (!isa<ArrayType>(CanonicalType))
381 ->getElementType().getTypePtr();
405 #define TYPE(CLASS, BASE) \
406 static_assert(!std::is_polymorphic<CLASS##Type>::value, \
407 #CLASS "Type should not be polymorphic!");
408 #include "clang/AST/TypeNodes.inc"
416 #define TYPE(CLASS, BASE) \
417 static_assert(std::is_trivially_destructible<CLASS##Type>::value || \
418 std::is_same<CLASS##Type, ConstantArrayType>::value, \
419 #CLASS "Type should be trivially destructible!");
420 #include "clang/AST/TypeNodes.inc"
424 #define ABSTRACT_TYPE(Class, Parent)
425 #define TYPE(Class, Parent) \
426 case Type::Class: { \
427 const auto *ty = cast<Class##Type>(this); \
428 if (!ty->isSugared()) return QualType(ty, 0); \
429 return ty->desugar(); \
431 #include "clang/AST/TypeNodes.inc"
433 llvm_unreachable(
"bad type kind!");
443 #define ABSTRACT_TYPE(Class, Parent)
444 #define TYPE(Class, Parent) \
445 case Type::Class: { \
446 const auto *Ty = cast<Class##Type>(CurTy); \
447 if (!Ty->isSugared()) \
448 return SplitQualType(Ty, Qs); \
449 Cur = Ty->desugar(); \
452 #include "clang/AST/TypeNodes.inc"
472 #define ABSTRACT_TYPE(Class, Parent)
473 #define TYPE(Class, Parent) \
474 case Type::Class: { \
475 const auto *ty = cast<Class##Type>(split.Ty); \
476 if (!ty->isSugared()) goto done; \
477 next = ty->desugar(); \
480 #include "clang/AST/TypeNodes.inc"
499 T = PT->getInnerType();
508 if (
const auto *Sugar = dyn_cast<T>(Cur))
511 #define ABSTRACT_TYPE(Class, Parent)
512 #define TYPE(Class, Parent) \
513 case Type::Class: { \
514 const auto *Ty = cast<Class##Type>(Cur); \
515 if (!Ty->isSugared()) return 0; \
516 Cur = Ty->desugar().getTypePtr(); \
519 #include "clang/AST/TypeNodes.inc"
525 return getAsSugar<TypedefType>(
this);
529 return getAsSugar<UsingType>(
this);
533 return getAsSugar<TemplateSpecializationType>(
this);
537 return getAsSugar<AttributedType>(
this);
544 const Type *Cur =
this;
548 #define ABSTRACT_TYPE(Class, Parent)
549 #define TYPE(Class, Parent) \
551 const auto *Ty = cast<Class##Type>(Cur); \
552 if (!Ty->isSugared()) return Cur; \
553 Cur = Ty->desugar().getTypePtr(); \
556 #include "clang/AST/TypeNodes.inc"
562 if (
const auto *RT = getAs<RecordType>())
563 return RT->getDecl()->isClass();
568 if (
const auto *RT = getAs<RecordType>())
569 return RT->getDecl()->isStruct();
574 if (
const auto *RT = getAs<RecordType>())
575 return RT->getDecl()->hasAttr<ObjCBoxableAttr>();
580 if (
const auto *RT = getAs<RecordType>())
581 return RT->getDecl()->isInterface();
586 if (
const auto *RT = getAs<RecordType>()) {
594 if (
const auto *PT = getAs<PointerType>())
595 return PT->getPointeeType()->isVoidType();
600 if (
const auto *RT = getAs<RecordType>())
601 return RT->getDecl()->isUnion();
606 if (
const auto *CT = dyn_cast<ComplexType>(CanonicalType))
607 return CT->getElementType()->isFloatingType();
617 if (
const auto *ET = getAs<EnumType>())
618 return ET->getDecl()->isScoped();
623 if (
const auto *
Complex = getAs<ComplexType>())
624 if (
Complex->getElementType()->isIntegerType())
630 if (
const auto *PT = getAs<PointerType>())
632 if (
const auto *OPT = getAs<ObjCObjectPointerType>())
634 if (
const auto *BPT = getAs<BlockPointerType>())
636 if (
const auto *RT = getAs<ReferenceType>())
638 if (
const auto *MPT = getAs<MemberPointerType>())
640 if (
const auto *DT = getAs<DecayedType>())
647 if (
const auto *RT = dyn_cast<RecordType>(
this)) {
648 if (RT->getDecl()->isStruct())
653 if (
const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
654 if (!RT->getDecl()->isStruct())
666 if (
const auto *RT = dyn_cast<RecordType>(
this)) {
667 if (RT->getDecl()->isUnion())
672 if (
const auto *RT = dyn_cast<RecordType>(CanonicalType)) {
673 if (!RT->getDecl()->isUnion())
688 const auto *OPT = getAs<ObjCObjectPointerType>();
693 if (OPT->isObjCIdType())
697 if (!OPT->isKindOfType())
701 if (OPT->isObjCClassType() || OPT->isObjCQualifiedClassType())
711 const auto *OPT = getAs<ObjCObjectPointerType>();
716 if (OPT->isObjCClassType())
720 if (!OPT->isKindOfType())
724 return OPT->isObjCClassType() || OPT->isObjCQualifiedClassType();
738 :
Type(ObjCObject, Canonical,
Base->getDependence()), BaseType(
Base) {
743 "bitfield overflow in type argument count");
744 if (!typeArgs.empty())
745 memcpy(getTypeArgStorage(), typeArgs.data(),
746 typeArgs.size() *
sizeof(
QualType));
748 for (
auto typeArg : typeArgs) {
749 addDependence(typeArg->getDependence() & ~TypeDependence::VariablyModified);
762 if (
const auto objcObject =
getBaseType()->getAs<ObjCObjectType>()) {
764 if (isa<ObjCInterfaceType>(objcObject))
767 return objcObject->isSpecialized();
780 if (
const auto objcObject =
getBaseType()->getAs<ObjCObjectType>()) {
782 if (isa<ObjCInterfaceType>(objcObject))
785 return objcObject->getTypeArgs();
797 if (
const auto objcObject =
getBaseType()->getAs<ObjCObjectType>()) {
799 if (isa<ObjCInterfaceType>(objcObject))
802 return objcObject->isKindOfType();
818 baseType = baseObj->stripObjCKindOfTypeAndQuals(ctx);
821 splitBaseType.
Quals),
847 template <
typename Derived>
848 struct SimpleTransformVisitor :
public TypeVisitor<Derived, QualType> {
856 QualType result =
static_cast<Derived *
>(
this)->Visit(splitType.
Ty);
866 explicit SimpleTransformVisitor(
ASTContext &ctx) : Ctx(ctx) {}
870 #define TYPE(Class, Base)
871 #define DEPENDENT_TYPE(Class, Base) \
872 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
873 #include "clang/AST/TypeNodes.inc"
875 #define TRIVIAL_TYPE_CLASS(Class) \
876 QualType Visit##Class##Type(const Class##Type *T) { return QualType(T, 0); }
877 #define SUGARED_TYPE_CLASS(Class) \
878 QualType Visit##Class##Type(const Class##Type *T) { \
879 if (!T->isSugared()) \
880 return QualType(T, 0); \
881 QualType desugaredType = recurse(T->desugar()); \
882 if (desugaredType.isNull()) \
884 if (desugaredType.getAsOpaquePtr() == T->desugar().getAsOpaquePtr()) \
885 return QualType(T, 0); \
886 return desugaredType; \
1000 if (elementType.
isNull())
1012 if (elementType.
isNull())
1023 if (elementType.
isNull())
1050 bool paramChanged =
false;
1052 QualType newParamType = recurse(paramType);
1053 if (newParamType.
isNull())
1057 paramChanged =
true;
1059 paramTypes.push_back(newParamType);
1064 bool exceptionChanged =
false;
1068 QualType newExceptionType = recurse(exceptionType);
1069 if (newExceptionType.
isNull())
1072 if (newExceptionType.
getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1073 exceptionChanged =
true;
1075 exceptionTypes.push_back(newExceptionType);
1078 if (exceptionChanged) {
1085 !paramChanged && !exceptionChanged)
1108 if (originalType.
isNull())
1112 if (adjustedType.
isNull())
1125 if (originalType.
isNull())
1147 if (modifiedType.
isNull())
1151 if (equivalentType.
isNull())
1166 if (replacementType.
isNull())
1186 if (deducedType.
isNull())
1205 bool typeArgChanged =
false;
1208 QualType newTypeArg = recurse(typeArg);
1213 typeArgChanged =
true;
1215 typeArgs.push_back(newTypeArg);
1232 if (pointeeType.
isNull())
1254 #undef TRIVIAL_TYPE_CLASS
1255 #undef SUGARED_TYPE_CLASS
1258 struct SubstObjCTypeArgsVisitor
1259 :
public SimpleTransformVisitor<SubstObjCTypeArgsVisitor> {
1260 using BaseType = SimpleTransformVisitor<SubstObjCTypeArgsVisitor>;
1267 : BaseType(ctx), TypeArgs(typeArgs), SubstContext(context) {}
1274 if (!TypeArgs.empty()) {
1285 argType, protocolsToApply, hasError,
true);
1288 switch (SubstContext) {
1298 const auto *objPtr =
1303 if (objPtr->isKindOfType() || objPtr->isObjCIdOrClassType())
1307 const auto *obj = objPtr->getObjectType();
1309 obj->getBaseType(), obj->getTypeArgsAsWritten(), obj->getProtocols(),
1316 llvm_unreachable(
"Unexpected ObjCSubstitutionContext!");
1331 if (isa<FunctionNoProtoType>(funcType)) {
1335 return BaseType::VisitFunctionType(funcType);
1341 const auto *funcProtoType = cast<FunctionProtoType>(funcType);
1345 bool paramChanged =
false;
1346 for (
auto paramType : funcProtoType->getParamTypes()) {
1349 if (newParamType.
isNull())
1353 paramChanged =
true;
1355 paramTypes.push_back(newParamType);
1360 bool exceptionChanged =
false;
1366 if (newExceptionType.
isNull())
1369 if (newExceptionType.
getAsOpaquePtr() != exceptionType.getAsOpaquePtr())
1370 exceptionChanged =
true;
1372 exceptionTypes.push_back(newExceptionType);
1375 if (exceptionChanged) {
1382 funcProtoType->getReturnType().getAsOpaquePtr() &&
1383 !paramChanged && !exceptionChanged)
1384 return BaseType::VisitFunctionType(funcType);
1394 bool anyChanged =
false;
1406 if (TypeArgs.empty() &&
1416 newTypeArgs.push_back(newTypeArg);
1428 return BaseType::VisitObjCObjectType(objcObjectType);
1432 QualType newType = BaseType::VisitAttributedType(attrType);
1436 const auto *newAttrType = dyn_cast<AttributedType>(newType.
getTypePtr());
1437 if (!newAttrType || newAttrType->getAttrKind() != attr::ObjCKindOf)
1441 QualType newEquivType = newAttrType->getEquivalentType();
1453 objType->getBaseType(), objType->getTypeArgsAsWritten(),
1454 objType->getProtocols(),
1456 objType->isObjCUnqualifiedId() ?
false :
true);
1464 newAttrType->getModifiedType(), newEquivType);
1468 struct StripObjCKindOfTypeVisitor
1469 :
public SimpleTransformVisitor<StripObjCKindOfTypeVisitor> {
1470 using BaseType = SimpleTransformVisitor<StripObjCKindOfTypeVisitor>;
1472 explicit StripObjCKindOfTypeVisitor(
ASTContext &ctx) : BaseType(ctx) {}
1476 return BaseType::VisitObjCObjectType(objType);
1491 case BuiltinType::Kind::Float16: {
1511 SubstObjCTypeArgsVisitor visitor(ctx, typeArgs, context);
1512 return visitor.recurse(*
this);
1526 auto &ctx =
const_cast<ASTContext &
>(constCtx);
1527 StripObjCKindOfTypeVisitor visitor(ctx);
1528 return visitor.recurse(*
this);
1532 if (
const auto AT =
getTypePtr()->getAs<AtomicType>())
1533 return AT->getValueType().getUnqualifiedType();
1537 std::optional<ArrayRef<QualType>>
1540 if (
const auto method = dyn_cast<ObjCMethodDecl>(dc))
1541 dc = method->getDeclContext();
1545 const auto *dcClassDecl = dyn_cast<ObjCInterfaceDecl>(dc);
1551 dcTypeParams = dcClassDecl->getTypeParamList();
1553 return std::nullopt;
1557 dcCategoryDecl = dyn_cast<ObjCCategoryDecl>(dc);
1558 if (!dcCategoryDecl)
1559 return std::nullopt;
1565 return std::nullopt;
1569 return std::nullopt;
1571 assert(dcTypeParams &&
"No substitutions to perform");
1572 assert(dcClassDecl &&
"No class context");
1576 if (
const auto *objectPointerType = getAs<ObjCObjectPointerType>()) {
1577 objectType = objectPointerType->getObjectType();
1578 }
else if (getAs<BlockPointerType>()) {
1583 objectType = getAs<ObjCObjectType>();
1589 if (!curClassDecl) {
1597 while (curClassDecl != dcClassDecl) {
1600 if (superType.
isNull()) {
1601 objectType =
nullptr;
1621 if (
auto *
ID = IfaceT->getInterface()) {
1622 if (
ID->getTypeParamList())
1636 CachedSuperClassType.setInt(
true);
1642 if (!superClassObjTy) {
1643 CachedSuperClassType.setInt(
true);
1648 if (!superClassDecl) {
1649 CachedSuperClassType.setInt(
true);
1655 QualType superClassType(superClassObjTy, 0);
1657 if (!superClassTypeParams) {
1658 CachedSuperClassType.setPointerAndInt(
1665 CachedSuperClassType.setPointerAndInt(superClassObjTy,
true);
1673 CachedSuperClassType.setPointerAndInt(
1684 CachedSuperClassType.setPointerAndInt(
1692 assert(typeArgs.size() == typeParams->
size());
1693 CachedSuperClassType.setPointerAndInt(
1702 return interfaceDecl->getASTContext().getObjCInterfaceType(interfaceDecl)
1711 if (superObjectType.
isNull())
1712 return superObjectType;
1722 if (
const auto *T = getAs<ObjCObjectType>())
1723 if (T->getNumProtocols() && T->getInterface())
1735 if (
const auto *OPT = getAs<ObjCObjectPointerType>()) {
1736 if (OPT->isObjCQualifiedIdType())
1745 if (
const auto *OPT = getAs<ObjCObjectPointerType>()) {
1746 if (OPT->isObjCQualifiedClassType())
1753 if (
const auto *OT = getAs<ObjCObjectType>()) {
1754 if (OT->getInterface())
1761 if (
const auto *OPT = getAs<ObjCObjectPointerType>()) {
1762 if (OPT->getInterfaceType())
1770 if (
const auto *PT = getAs<PointerType>())
1772 else if (
const auto *RT = getAs<ReferenceType>())
1778 return dyn_cast<CXXRecordDecl>(RT->getDecl());
1784 return dyn_cast_or_null<CXXRecordDecl>(
getAsTagDecl());
1792 if (
const auto *TT = getAs<TagType>())
1793 return TT->getDecl();
1794 if (
const auto *Injected = getAs<InjectedClassNameType>())
1795 return Injected->getDecl();
1801 const Type *Cur =
this;
1803 if (AT->getAttrKind() == AK)
1805 Cur = AT->getEquivalentType().getTypePtr();
1812 class GetContainedDeducedTypeVisitor :
1813 public TypeVisitor<GetContainedDeducedTypeVisitor, Type*> {
1817 GetContainedDeducedTypeVisitor(
bool Syntactic =
false)
1818 : Syntactic(Syntactic) {}
1862 Type *VisitDependentSizedExtVectorType(
1882 return VisitFunctionType(T);
1913 return cast_or_null<DeducedType>(
1914 GetContainedDeducedTypeVisitor().Visit(
this));
1918 return isa_and_nonnull<FunctionType>(
1919 GetContainedDeducedTypeVisitor(
true).Visit(
this));
1923 if (
const auto *VT = dyn_cast<VectorType>(CanonicalType))
1924 return VT->getElementType()->isIntegerType();
1925 if (CanonicalType->isVLSTBuiltinType()) {
1926 const auto *VT = cast<BuiltinType>(CanonicalType);
1927 return VT->getKind() == BuiltinType::SveBool ||
1928 (VT->getKind() >= BuiltinType::SveInt8 &&
1929 VT->getKind() <= BuiltinType::SveUint64);
1955 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1956 return BT->getKind() >= BuiltinType::Bool &&
1957 BT->getKind() <= BuiltinType::Int128;
1961 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType))
1962 return ET->getDecl()->isComplete();
1968 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1969 return BT->getKind() >= BuiltinType::Bool &&
1970 BT->getKind() <= BuiltinType::Int128;
1979 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType))
1980 return !ET->getDecl()->isScoped();
1986 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1987 return BT->getKind() == BuiltinType::Char_U ||
1988 BT->getKind() == BuiltinType::UChar ||
1989 BT->getKind() == BuiltinType::Char_S ||
1990 BT->getKind() == BuiltinType::SChar;
1995 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
1996 return BT->getKind() == BuiltinType::WChar_S ||
1997 BT->getKind() == BuiltinType::WChar_U;
2002 if (
const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
2003 return BT->getKind() == BuiltinType::Char8;
2008 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2009 return BT->getKind() == BuiltinType::Char16;
2014 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2015 return BT->getKind() == BuiltinType::Char32;
2022 const auto *BT = dyn_cast<BuiltinType>(CanonicalType);
2023 if (!BT)
return false;
2024 switch (BT->getKind()) {
2025 default:
return false;
2026 case BuiltinType::Char_U:
2027 case BuiltinType::UChar:
2028 case BuiltinType::WChar_U:
2029 case BuiltinType::Char8:
2030 case BuiltinType::Char16:
2031 case BuiltinType::Char32:
2032 case BuiltinType::Char_S:
2033 case BuiltinType::SChar:
2034 case BuiltinType::WChar_S:
2043 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2044 return BT->getKind() >= BuiltinType::Char_S &&
2045 BT->getKind() <= BuiltinType::Int128;
2048 if (
const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
2051 if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
2052 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2055 if (
const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2056 return IT->isSigned();
2057 if (
const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2058 return IT->isSigned();
2064 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2065 return BT->getKind() >= BuiltinType::Char_S &&
2066 BT->getKind() <= BuiltinType::Int128;
2069 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2070 if (ET->getDecl()->isComplete())
2071 return ET->getDecl()->getIntegerType()->isSignedIntegerType();
2074 if (
const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2075 return IT->isSigned();
2076 if (
const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2077 return IT->isSigned();
2083 if (
const auto *VT = dyn_cast<VectorType>(CanonicalType))
2084 return VT->getElementType()->isSignedIntegerOrEnumerationType();
2093 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2094 return BT->getKind() >= BuiltinType::Bool &&
2095 BT->getKind() <= BuiltinType::UInt128;
2098 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2101 if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
2102 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2105 if (
const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2106 return IT->isUnsigned();
2107 if (
const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2108 return IT->isUnsigned();
2114 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) {
2115 return BT->getKind() >= BuiltinType::Bool &&
2116 BT->getKind() <= BuiltinType::UInt128;
2119 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType)) {
2120 if (ET->getDecl()->isComplete())
2121 return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
2124 if (
const auto *IT = dyn_cast<BitIntType>(CanonicalType))
2125 return IT->isUnsigned();
2126 if (
const auto *IT = dyn_cast<DependentBitIntType>(CanonicalType))
2127 return IT->isUnsigned();
2133 if (
const auto *VT = dyn_cast<VectorType>(CanonicalType))
2134 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2135 if (
const auto *VT = dyn_cast<MatrixType>(CanonicalType))
2136 return VT->getElementType()->isUnsignedIntegerOrEnumerationType();
2137 if (CanonicalType->isVLSTBuiltinType()) {
2138 const auto *VT = cast<BuiltinType>(CanonicalType);
2139 return VT->getKind() >= BuiltinType::SveUint8 &&
2140 VT->getKind() <= BuiltinType::SveUint64;
2146 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2147 return BT->getKind() >= BuiltinType::Half &&
2148 BT->getKind() <= BuiltinType::Ibm128;
2149 if (
const auto *CT = dyn_cast<ComplexType>(CanonicalType))
2150 return CT->getElementType()->isFloatingType();
2155 if (
const auto *VT = dyn_cast<VectorType>(CanonicalType))
2156 return VT->getElementType()->isFloatingType();
2162 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2163 return BT->isFloatingPoint();
2168 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2169 return BT->getKind() >= BuiltinType::Bool &&
2170 BT->getKind() <= BuiltinType::Ibm128;
2171 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType))
2172 return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
2177 if (
const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
2178 return BT->getKind() >= BuiltinType::Bool &&
2179 BT->getKind() <= BuiltinType::Ibm128 &&
2180 BT->getKind() != BuiltinType::BFloat16;
2181 if (
const auto *ET = dyn_cast<EnumType>(CanonicalType))
2188 return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
2189 return isa<ComplexType>(CanonicalType) ||
isBitIntType();
2195 const Type *T = CanonicalType.getTypePtr();
2196 if (
const auto *BT = dyn_cast<BuiltinType>(T)) {
2197 if (BT->getKind() == BuiltinType::Bool)
return STK_Bool;
2198 if (BT->getKind() == BuiltinType::NullPtr)
return STK_CPointer;
2202 llvm_unreachable(
"unknown scalar builtin type");
2203 }
else if (isa<PointerType>(T)) {
2205 }
else if (isa<BlockPointerType>(T)) {
2207 }
else if (isa<ObjCObjectPointerType>(T)) {
2209 }
else if (isa<MemberPointerType>(T)) {
2211 }
else if (isa<EnumType>(T)) {
2212 assert(cast<EnumType>(T)->getDecl()->isComplete());
2214 }
else if (
const auto *CT = dyn_cast<ComplexType>(T)) {
2215 if (CT->getElementType()->isRealFloatingType())
2222 llvm_unreachable(
"unknown scalar type");
2235 if (
const auto *Record = dyn_cast<RecordType>(CanonicalType)) {
2236 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
2237 return ClassDecl->isAggregate();
2242 return isa<ArrayType>(CanonicalType);
2249 assert(!
isIncompleteType() &&
"This doesn't make sense for incomplete types");
2250 assert(!
isDependentType() &&
"This doesn't make sense for dependent types");
2252 return !isa<VariableArrayType>(CanonicalType);
2262 switch (CanonicalType->getTypeClass()) {
2263 default:
return false;
2269 EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
2277 RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
2288 return cast<ArrayType>(CanonicalType)->getElementType()
2289 ->isIncompleteType(Def);
2290 case IncompleteArray:
2293 case MemberPointer: {
2297 auto *MPTy = cast<MemberPointerType>(CanonicalType);
2298 const Type *ClassTy = MPTy->getClass();
2311 if (RD->
hasAttr<MSInheritanceAttr>())
2316 return cast<ObjCObjectType>(CanonicalType)->getBaseType()
2317 ->isIncompleteType(Def);
2318 case ObjCInterface: {
2321 = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
2330 if (
const BuiltinType *BT = getAs<BuiltinType>()) {
2331 switch (BT->getKind()) {
2333 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2334 #include "clang/Basic/AArch64SVEACLETypes.def"
2335 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2336 #include "clang/Basic/RISCVVTypes.def"
2348 if (
const BuiltinType *BT = getAs<BuiltinType>()) {
2349 switch (BT->getKind()) {
2351 #define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2352 #include "clang/Basic/AArch64SVEACLETypes.def"
2362 if (
const BuiltinType *BT = getAs<BuiltinType>()) {
2363 switch (BT->getKind()) {
2364 case BuiltinType::SveInt8:
2365 case BuiltinType::SveInt16:
2366 case BuiltinType::SveInt32:
2367 case BuiltinType::SveInt64:
2368 case BuiltinType::SveUint8:
2369 case BuiltinType::SveUint16:
2370 case BuiltinType::SveUint32:
2371 case BuiltinType::SveUint64:
2372 case BuiltinType::SveFloat16:
2373 case BuiltinType::SveFloat32:
2374 case BuiltinType::SveFloat64:
2375 case BuiltinType::SveBFloat16:
2376 case BuiltinType::SveBool:
2389 if (BTy->
getKind() == BuiltinType::SveBool)
2413 if ((*this)->isIncompleteArrayType())
2416 if ((*this)->isIncompleteType())
2425 default:
return false;
2426 case Type::VariableArray:
2427 case Type::ConstantArray:
2431 case Type::ObjCObjectPointer:
2432 case Type::BlockPointer:
2436 case Type::MemberPointer:
2438 case Type::ExtVector:
2446 if (
const auto *ClassDecl =
2447 dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
2448 return ClassDecl->isPOD();
2462 if ((*this)->isArrayType())
2465 if ((*this)->isSizelessBuiltinType())
2470 if ((*this)->isIncompleteType())
2489 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2494 return ClassDecl->hasDefaultConstructor() &&
2495 !ClassDecl->hasNonTrivialDefaultConstructor() &&
2496 ClassDecl->isTriviallyCopyable();
2507 if ((*this)->isArrayType())
2535 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2536 if (!ClassDecl->isTriviallyCopyable())
return false;
2552 return RD->canPassInRegisters();
2585 if (
const auto *RT =
2586 getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2587 if (RT->getDecl()->isNonTrivialToPrimitiveDefaultInitialize())
2601 if (
const auto *RT =
2602 getTypePtr()->getBaseElementTypeUnsafe()->getAs<RecordType>())
2603 if (RT->getDecl()->isNonTrivialToPrimitiveCopy())
2639 assert(BaseTy &&
"NULL element type");
2669 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2670 return ClassDecl->isLiteral();
2677 return AT->getValueType()->isLiteralType(Ctx);
2699 return RD->isStructural();
2712 assert(BaseTy &&
"NULL element type");
2722 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl()))
2723 if (!ClassDecl->isStandardLayout())
2751 assert(BaseTy &&
"NULL element type");
2764 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RT->getDecl())) {
2767 if (!ClassDecl->isTrivial())
return false;
2772 if (!ClassDecl->isStandardLayout())
return false;
2801 if (
const auto *ET = getAs<EnumType>()) {
2803 if (II && II->
isStr(
"align_val_t") && ET->getDecl()->isInStdNamespace())
2810 if (
const auto *ET = getAs<EnumType>()) {
2812 if (II && II->
isStr(
"byte") && ET->getDecl()->isInStdNamespace())
2828 case TemplateTypeParm:
2829 case SubstTemplateTypeParm:
2830 case TemplateSpecialization:
2833 case DependentTemplateSpecialization:
2865 llvm_unreachable(
"Type specifier is not a tag type kind.");
2877 llvm_unreachable(
"Unknown tag type kind.");
2890 llvm_unreachable(
"Elaborated type keyword is not a tag type kind.");
2892 llvm_unreachable(
"Unknown elaborated type keyword.");
2908 llvm_unreachable(
"Unknown elaborated type keyword.");
2922 llvm_unreachable(
"Unknown elaborated type keyword.");
2925 DependentTemplateSpecializationType::DependentTemplateSpecializationType(
2932 NNS(NNS), Name(Name) {
2935 "DependentTemplateSpecializatonType requires dependent qualifier");
2936 auto *ArgBuffer =
const_cast<TemplateArgument *
>(template_arguments().data());
2939 TemplateArgumentDependence::UnexpandedPack));
2952 ID.AddInteger(Keyword);
2953 ID.AddPointer(Qualifier);
2954 ID.AddPointer(Name);
2956 Arg.Profile(
ID, Context);
2961 if (
const auto *Elab = dyn_cast<ElaboratedType>(
this))
2962 Keyword = Elab->getKeyword();
2963 else if (
const auto *DepName = dyn_cast<DependentNameType>(
this))
2964 Keyword = DepName->getKeyword();
2965 else if (
const auto *DepTST =
2966 dyn_cast<DependentTemplateSpecializationType>(
this))
2967 Keyword = DepTST->getKeyword();
2976 #define ABSTRACT_TYPE(Derived, Base)
2977 #define TYPE(Derived, Base) case Derived: return #Derived;
2978 #include "clang/AST/TypeNodes.inc"
2981 llvm_unreachable(
"Invalid type class.");
2989 return Policy.
Bool ?
"bool" :
"_Bool";
2995 return "signed char";
3007 return "unsigned char";
3009 return "unsigned short";
3011 return "unsigned int";
3013 return "unsigned long";
3015 return "unsigned long long";
3017 return "unsigned __int128";
3019 return Policy.
Half ?
"half" :
"__fp16";
3027 return "long double";
3029 return "short _Accum";
3033 return "long _Accum";
3035 return "unsigned short _Accum";
3037 return "unsigned _Accum";
3039 return "unsigned long _Accum";
3040 case BuiltinType::ShortFract:
3041 return "short _Fract";
3042 case BuiltinType::Fract:
3044 case BuiltinType::LongFract:
3045 return "long _Fract";
3046 case BuiltinType::UShortFract:
3047 return "unsigned short _Fract";
3048 case BuiltinType::UFract:
3049 return "unsigned _Fract";
3050 case BuiltinType::ULongFract:
3051 return "unsigned long _Fract";
3052 case BuiltinType::SatShortAccum:
3053 return "_Sat short _Accum";
3054 case BuiltinType::SatAccum:
3055 return "_Sat _Accum";
3056 case BuiltinType::SatLongAccum:
3057 return "_Sat long _Accum";
3058 case BuiltinType::SatUShortAccum:
3059 return "_Sat unsigned short _Accum";
3060 case BuiltinType::SatUAccum:
3061 return "_Sat unsigned _Accum";
3062 case BuiltinType::SatULongAccum:
3063 return "_Sat unsigned long _Accum";
3064 case BuiltinType::SatShortFract:
3065 return "_Sat short _Fract";
3066 case BuiltinType::SatFract:
3067 return "_Sat _Fract";
3068 case BuiltinType::SatLongFract:
3069 return "_Sat long _Fract";
3070 case BuiltinType::SatUShortFract:
3071 return "_Sat unsigned short _Fract";
3072 case BuiltinType::SatUFract:
3073 return "_Sat unsigned _Fract";
3074 case BuiltinType::SatULongFract:
3075 return "_Sat unsigned long _Fract";
3079 return "__float128";
3084 return Policy.
MSWChar ?
"__wchar_t" :
"wchar_t";
3094 return "<overloaded function type>";
3096 return "<bound member function type>";
3098 return "<pseudo-object type>";
3100 return "<dependent type>";
3102 return "<unknown type>";
3103 case ARCUnbridgedCast:
3104 return "<ARC unbridged cast type>";
3106 return "<builtin fn type>";
3113 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3115 return "__" #Access " " #ImgType "_t";
3116 #include "clang/Basic/OpenCLImageTypes.def"
3122 return "clk_event_t";
3126 return "reserve_id_t";
3127 case IncompleteMatrixIdx:
3128 return "<incomplete matrix index type>";
3129 case OMPArraySection:
3130 return "<OpenMP array section type>";
3131 case OMPArrayShaping:
3132 return "<OpenMP array shaping type>";
3134 return "<OpenMP iterator type>";
3135 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3138 #include "clang/Basic/OpenCLExtensionTypes.def"
3139 #define SVE_TYPE(Name, Id, SingletonId) \
3142 #include "clang/Basic/AArch64SVEACLETypes.def"
3143 #define PPC_VECTOR_TYPE(Name, Id, Size) \
3146 #include "clang/Basic/PPCTypes.def"
3147 #define RVV_TYPE(Name, Id, SingletonId) \
3150 #include "clang/Basic/RISCVVTypes.def"
3153 llvm_unreachable(
"Invalid builtin type.");
3158 if (
auto *PET = dyn_cast<PackExpansionType>(
getTypePtr()))
3159 return PET->getPattern();
3164 if (
const auto *RefType =
getTypePtr()->getAs<ReferenceType>())
3181 case CC_C:
return "cdecl";
3204 llvm_unreachable(
"Invalid calling convention.");
3209 const ExtProtoInfo &epi)
3210 :
FunctionType(FunctionProto, result, canonical, result->getDependence(),
3215 assert(getNumParams() == params.size() &&
"NumParams overflow!");
3221 if (epi.requiresFunctionProtoTypeExtraBitfields()) {
3223 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3224 ExtraBits = FunctionTypeExtraBitfields();
3231 auto *argSlot = getTrailingObjects<QualType>();
3232 for (
unsigned i = 0; i != getNumParams(); ++i) {
3234 ~TypeDependence::VariablyModified);
3235 argSlot[i] = params[i];
3240 auto &ExtraBits = *getTrailingObjects<FunctionTypeExtraBitfields>();
3241 ExtraBits.NumExceptionType = epi.ExceptionSpec.Exceptions.size();
3243 assert(hasExtraBitfields() &&
"missing trailing extra bitfields!");
3245 reinterpret_cast<QualType *
>(getTrailingObjects<ExceptionType>());
3247 for (
QualType ExceptionType : epi.ExceptionSpec.Exceptions) {
3253 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3255 exnSlot[I++] = ExceptionType;
3260 assert(epi.ExceptionSpec.NoexceptExpr &&
"computed noexcept with no expr");
3262 epi.ExceptionSpec.NoexceptExpr->isValueDependent());
3265 *getTrailingObjects<Expr *>() = epi.ExceptionSpec.NoexceptExpr;
3269 (TypeDependence::Instantiation | TypeDependence::UnexpandedPack));
3275 auto **slot = getTrailingObjects<FunctionDecl *>();
3276 slot[0] = epi.ExceptionSpec.SourceDecl;
3277 slot[1] = epi.ExceptionSpec.SourceTemplate;
3283 auto **slot = getTrailingObjects<FunctionDecl *>();
3284 slot[0] = epi.ExceptionSpec.SourceDecl;
3292 assert(hasDependentExceptionSpec() &&
"type should not be canonical");
3301 if (epi.ExtParameterInfos) {
3302 auto *extParamInfos = getTrailingObjects<ExtParameterInfo>();
3303 for (
unsigned i = 0; i != getNumParams(); ++i)
3304 extParamInfos[i] = epi.ExtParameterInfos[i];
3307 if (epi.TypeQuals.hasNonFastQualifiers()) {
3309 *getTrailingObjects<Qualifiers>() = epi.TypeQuals;
3316 auto &EllipsisLoc = *getTrailingObjects<SourceLocation>();
3317 EllipsisLoc = epi.EllipsisLoc;
3323 return NE->isValueDependent();
3335 return NE->isInstantiationDependent();
3337 if (ET->isInstantiationDependentType())
3346 llvm_unreachable(
"should not call this with unresolved exception specs");
3372 llvm_unreachable(
"unexpected exception specification kind");
3376 for (
unsigned ArgIdx =
getNumParams(); ArgIdx; --ArgIdx)
3384 const QualType *ArgTys,
unsigned NumParams,
3385 const ExtProtoInfo &epi,
3404 ID.AddPointer(Result.getAsOpaquePtr());
3405 for (
unsigned i = 0; i != NumParams; ++i)
3406 ID.AddPointer(ArgTys[i].getAsOpaquePtr());
3410 assert(!(
unsigned(epi.Variadic) & ~1) &&
3411 !(
unsigned(epi.RefQualifier) & ~3) &&
3412 !(
unsigned(epi.ExceptionSpec.Type) & ~15) &&
3413 "Values larger than expected.");
3414 ID.AddInteger(
unsigned(epi.Variadic) +
3415 (epi.RefQualifier << 1) +
3416 (epi.ExceptionSpec.Type << 3));
3417 ID.Add(epi.TypeQuals);
3419 for (
QualType Ex : epi.ExceptionSpec.Exceptions)
3422 epi.ExceptionSpec.NoexceptExpr->Profile(
ID, Context, Canonical);
3425 ID.AddPointer(epi.ExceptionSpec.SourceDecl->getCanonicalDecl());
3427 if (epi.ExtParameterInfos) {
3428 for (
unsigned i = 0; i != NumParams; ++i)
3429 ID.AddInteger(epi.ExtParameterInfos[i].getOpaqueValue());
3431 epi.ExtInfo.Profile(
ID);
3432 ID.AddBoolean(epi.HasTrailingReturn);
3445 assert(!isa<TypedefType>(can) &&
"Invalid canonical type");
3447 if (!typeMatchesDecl())
3448 *getTrailingObjects<QualType>() = Underlying;
3453 : *getTrailingObjects<QualType>();
3462 *getTrailingObjects<QualType>() = Underlying;
3468 cast<TypeDecl>(Found->
getTargetDecl())->getTypeForDecl(), 0)
3469 : *getTrailingObjects<QualType>();
3478 while (
auto *InnerMQT = dyn_cast<MacroQualifiedType>(Inner)) {
3481 Inner = InnerMQT->getModifiedType();
3491 ? Can.getAtomicUnqualifiedType()
3494 (E->getType()->getDependence() &
3516 ID.AddBoolean(IsUnqual);
3523 :
Type(Decltype, can,
3527 (E->getType()->getDependence() &
3529 E(E), UnderlyingType(underlyingType) {}
3541 :
DecltypeType(E, Context.DependentTy), Context(Context) {}
3551 :
Type(UnaryTransform, CanonicalType, BaseType->getDependence()),
3552 BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind) {}
3566 for (
auto *I :
decl->redecls()) {
3567 if (I->isCompleteDefinition() || I->isBeingDefined())
3583 std::vector<const RecordType*> RecordTypeList;
3584 RecordTypeList.push_back(
this);
3585 unsigned NextToCheckIndex = 0;
3587 while (RecordTypeList.size() > NextToCheckIndex) {
3589 RecordTypeList[NextToCheckIndex]->
getDecl()->fields()) {
3595 if (!llvm::is_contained(RecordTypeList, FieldRecTy))
3596 RecordTypeList.push_back(FieldRecTy);
3611 case attr::ObjCOwnership:
3612 case attr::ObjCInertUnsafeUnretained:
3613 case attr::TypeNonNull:
3614 case attr::TypeNullable:
3615 case attr::TypeNullableResult:
3616 case attr::TypeNullUnspecified:
3617 case attr::LifetimeBound:
3618 case attr::AddressSpace:
3631 default:
return false;
3638 llvm_unreachable(
"invalid attr kind");
3644 default:
return false;
3647 case attr::FastCall:
3649 case attr::ThisCall:
3651 case attr::SwiftCall:
3652 case attr::SwiftAsyncCall:
3653 case attr::VectorCall:
3654 case attr::AArch64VectorPcs:
3655 case attr::AArch64SVEPcs:
3656 case attr::AMDGPUKernelCall:
3660 case attr::IntelOclBicc:
3661 case attr::PreserveMost:
3662 case attr::PreserveAll:
3665 llvm_unreachable(
"invalid attr kind");
3678 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(D))
3680 return cast<TemplateTypeParmDecl>(
3684 SubstTemplateTypeParmType::SubstTemplateTypeParmType(
3685 QualType Replacement,
Decl *AssociatedDecl,
unsigned Index,
3686 std::optional<unsigned> PackIndex)
3687 :
Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
3688 Replacement->getDependence()),
3689 AssociatedDecl(AssociatedDecl) {
3690 SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
3691 Replacement != getCanonicalTypeInternal();
3692 if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
3693 *getTrailingObjects<QualType>() = Replacement;
3695 SubstTemplateTypeParmTypeBits.Index = Index;
3696 SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
3697 assert(AssociatedDecl !=
nullptr);
3705 SubstTemplateTypeParmPackType::SubstTemplateTypeParmPackType(
3706 QualType Canon,
Decl *AssociatedDecl,
unsigned Index,
bool Final,
3708 :
Type(SubstTemplateTypeParmPack, Canon,
3711 Arguments(ArgPack.pack_begin()),
3712 AssociatedDeclAndFinal(AssociatedDecl, Final) {
3715 assert(AssociatedDecl !=
nullptr);
3719 return AssociatedDeclAndFinal.getPointer();
3723 return AssociatedDeclAndFinal.getInt();
3744 const Decl *AssociatedDecl,
3745 unsigned Index,
bool Final,
3747 ID.AddPointer(AssociatedDecl);
3748 ID.AddInteger(Index);
3749 ID.AddBoolean(Final);
3752 ID.AddPointer(
P.getAsType().getAsOpaquePtr());
3763 if (Arg.isDependent())
3771 if (ArgLoc.getArgument().isInstantiationDependent())
3777 TemplateSpecializationType::TemplateSpecializationType(
3780 :
Type(TemplateSpecialization, Canon.isNull() ?
QualType(this, 0) : Canon,
3791 "Use DependentTemplateSpecializationType for dependent template-name");
3796 "Unexpected template name for TemplateSpecializationType");
3809 ~TypeDependence::Dependent);
3812 TypeDependence::VariablyModified);
3819 *
reinterpret_cast<QualType *
>(
Begin + Args.size()) = AliasedType;
3824 assert(
isTypeAlias() &&
"not a type alias template specialization");
3842 Arg.Profile(
ID, Context);
3867 ID.AddInteger(typeArgs.size());
3868 for (
auto typeArg : typeArgs)
3869 ID.AddPointer(typeArg.getAsOpaquePtr());
3870 ID.AddInteger(protocols.size());
3871 for (
auto *proto : protocols)
3872 ID.AddPointer(proto);
3873 ID.AddBoolean(isKindOf);
3886 ID.AddPointer(OTPDecl);
3888 ID.AddInteger(protocols.size());
3889 for (
auto *proto : protocols)
3890 ID.AddPointer(proto);
3901 class CachedProperties {
3906 CachedProperties(
Linkage L,
bool local) : L(L), local(local) {}
3908 Linkage getLinkage()
const {
return L; }
3909 bool hasLocalOrUnnamedType()
const {
return local; }
3911 friend CachedProperties merge(CachedProperties L, CachedProperties R) {
3913 return CachedProperties(MergedLinkage, L.hasLocalOrUnnamedType() ||
3914 R.hasLocalOrUnnamedType());
3935 return CachedProperties(T->
TypeBits.getLinkage(),
3936 T->
TypeBits.hasLocalOrUnnamedType());
3941 if (T->
TypeBits.isCacheValid())
return;
3957 T->
TypeBits.CachedLinkage = Result.getLinkage();
3958 T->
TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
3977 #define TYPE(Class,Base)
3978 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
3979 #include "clang/AST/TypeNodes.inc"
3980 llvm_unreachable(
"didn't expect a non-canonical type here");
3982 #define TYPE(Class,Base)
3983 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
3984 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
3985 #include "clang/AST/TypeNodes.inc"
3992 case Type::DeducedTemplateSpecialization:
4006 const TagDecl *Tag = cast<TagType>(T)->getDecl();
4013 bool IsLocalOrUnnamed =
4016 return CachedProperties(L, IsLocalOrUnnamed);
4023 return Cache::get(cast<ComplexType>(T)->getElementType());
4025 return Cache::get(cast<PointerType>(T)->getPointeeType());
4026 case Type::BlockPointer:
4027 return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
4028 case Type::LValueReference:
4029 case Type::RValueReference:
4030 return Cache::get(cast<ReferenceType>(T)->getPointeeType());
4031 case Type::MemberPointer: {
4032 const auto *MPT = cast<MemberPointerType>(T);
4033 return merge(Cache::get(MPT->getClass()),
4034 Cache::get(MPT->getPointeeType()));
4036 case Type::ConstantArray:
4037 case Type::IncompleteArray:
4038 case Type::VariableArray:
4039 return Cache::get(cast<ArrayType>(T)->getElementType());
4041 case Type::ExtVector:
4042 return Cache::get(cast<VectorType>(T)->getElementType());
4043 case Type::ConstantMatrix:
4044 return Cache::get(cast<ConstantMatrixType>(T)->getElementType());
4045 case Type::FunctionNoProto:
4046 return Cache::get(cast<FunctionType>(T)->getReturnType());
4047 case Type::FunctionProto: {
4048 const auto *FPT = cast<FunctionProtoType>(T);
4049 CachedProperties result = Cache::get(FPT->getReturnType());
4050 for (
const auto &ai : FPT->param_types())
4051 result = merge(result, Cache::get(ai));
4054 case Type::ObjCInterface: {
4055 Linkage L = cast<ObjCInterfaceType>(T)->getDecl()->getLinkageInternal();
4056 return CachedProperties(L,
false);
4058 case Type::ObjCObject:
4059 return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
4060 case Type::ObjCObjectPointer:
4061 return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
4063 return Cache::get(cast<AtomicType>(T)->getValueType());
4065 return Cache::get(cast<PipeType>(T)->getElementType());
4068 llvm_unreachable(
"unhandled type class");
4073 Cache::ensure(
this);
4078 Cache::ensure(
this);
4079 return TypeBits.hasLocalOrUnnamedType();
4084 #define TYPE(Class,Base)
4085 #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
4086 #include "clang/AST/TypeNodes.inc"
4087 llvm_unreachable(
"didn't expect a non-canonical type here");
4089 #define TYPE(Class,Base)
4090 #define DEPENDENT_TYPE(Class,Base) case Type::Class:
4091 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
4092 #include "clang/AST/TypeNodes.inc"
4102 case Type::DeducedTemplateSpecialization:
4113 case Type::BlockPointer:
4115 case Type::LValueReference:
4116 case Type::RValueReference:
4118 case Type::MemberPointer: {
4119 const auto *MPT = cast<MemberPointerType>(T);
4124 case Type::ConstantArray:
4125 case Type::IncompleteArray:
4126 case Type::VariableArray:
4129 case Type::ExtVector:
4131 case Type::ConstantMatrix:
4133 cast<ConstantMatrixType>(T)->getElementType());
4134 case Type::FunctionNoProto:
4136 case Type::FunctionProto: {
4137 const auto *FPT = cast<FunctionProtoType>(T);
4139 for (
const auto &ai : FPT->param_types())
4143 case Type::ObjCInterface:
4145 case Type::ObjCObject:
4147 case Type::ObjCObjectPointer:
4149 cast<ObjCObjectPointerType>(T)->getPointeeType());
4156 llvm_unreachable(
"unhandled type class");
4187 if (
auto Nullability = AT->getImmediateNullability())
4190 Type = AT->getEquivalentType();
4192 return std::nullopt;
4198 switch (
type->getTypeClass()) {
4200 #define NON_CANONICAL_TYPE(Class, Parent) \
4202 llvm_unreachable("non-canonical type");
4203 #define TYPE(Class, Parent)
4204 #include "clang/AST/TypeNodes.inc"
4208 case Type::BlockPointer:
4209 case Type::MemberPointer:
4210 case Type::ObjCObjectPointer:
4214 case Type::UnresolvedUsing:
4215 case Type::TypeOfExpr:
4217 case Type::Decltype:
4218 case Type::UnaryTransform:
4219 case Type::TemplateTypeParm:
4220 case Type::SubstTemplateTypeParmPack:
4221 case Type::DependentName:
4222 case Type::DependentTemplateSpecialization:
4224 return ResultIfUnknown;
4229 case Type::TemplateSpecialization:
4231 = cast<TemplateSpecializationType>(
type.getTypePtr())
4232 ->getTemplateName().getAsTemplateDecl()) {
4233 if (isa<ClassTemplateDecl>(templateDecl))
4236 return ResultIfUnknown;
4239 switch (cast<BuiltinType>(
type.getTypePtr())->getKind()) {
4241 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4242 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
4243 #define FLOATING_TYPE(Id, SingletonId) case BuiltinType::Id:
4244 #define BUILTIN_TYPE(Id, SingletonId)
4245 #include "clang/AST/BuiltinTypes.def"
4249 case BuiltinType::Dependent:
4250 case BuiltinType::Overload:
4251 case BuiltinType::BoundMember:
4252 case BuiltinType::PseudoObject:
4253 case BuiltinType::UnknownAny:
4254 case BuiltinType::ARCUnbridgedCast:
4255 return ResultIfUnknown;
4257 case BuiltinType::Void:
4258 case BuiltinType::ObjCId:
4259 case BuiltinType::ObjCClass:
4260 case BuiltinType::ObjCSel:
4261 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
4262 case BuiltinType::Id:
4263 #include "clang/Basic/OpenCLImageTypes.def"
4264 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
4265 case BuiltinType::Id:
4266 #include "clang/Basic/OpenCLExtensionTypes.def"
4267 case BuiltinType::OCLSampler:
4268 case BuiltinType::OCLEvent:
4269 case BuiltinType::OCLClkEvent:
4270 case BuiltinType::OCLQueue:
4271 case BuiltinType::OCLReserveID:
4272 #define SVE_TYPE(Name, Id, SingletonId) \
4273 case BuiltinType::Id:
4274 #include "clang/Basic/AArch64SVEACLETypes.def"
4275 #define PPC_VECTOR_TYPE(Name, Id, Size) \
4276 case BuiltinType::Id:
4277 #include "clang/Basic/PPCTypes.def"
4278 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
4279 #include "clang/Basic/RISCVVTypes.def"
4280 case BuiltinType::BuiltinFn:
4281 case BuiltinType::NullPtr:
4282 case BuiltinType::IncompleteMatrixIdx:
4283 case BuiltinType::OMPArraySection:
4284 case BuiltinType::OMPArrayShaping:
4285 case BuiltinType::OMPIterator:
4288 llvm_unreachable(
"unknown builtin type");
4292 case Type::LValueReference:
4293 case Type::RValueReference:
4294 case Type::ConstantArray:
4295 case Type::IncompleteArray:
4296 case Type::VariableArray:
4297 case Type::DependentSizedArray:
4298 case Type::DependentVector:
4299 case Type::DependentSizedExtVector:
4301 case Type::ExtVector:
4302 case Type::ConstantMatrix:
4303 case Type::DependentSizedMatrix:
4304 case Type::DependentAddressSpace:
4305 case Type::FunctionProto:
4306 case Type::FunctionNoProto:
4308 case Type::DeducedTemplateSpecialization:
4310 case Type::InjectedClassName:
4311 case Type::PackExpansion:
4312 case Type::ObjCObject:
4313 case Type::ObjCInterface:
4317 case Type::DependentBitInt:
4320 llvm_unreachable(
"bad type kind!");
4332 return std::nullopt;
4335 std::optional<NullabilityKind>
4338 if (
auto MacroTy = dyn_cast<MacroQualifiedType>(T))
4339 AttrTy = MacroTy->getUnderlyingType();
4341 if (
auto attributed = dyn_cast<AttributedType>(AttrTy)) {
4342 if (
auto nullability = attributed->getImmediateNullability()) {
4343 T = attributed->getModifiedType();
4348 return std::nullopt;
4352 const auto *objcPtr = getAs<ObjCObjectPointerType>();
4356 if (objcPtr->isObjCIdType()) {
4367 }
else if (objcPtr->isObjCQualifiedIdType()) {
4392 "cannot query implicit lifetime for non-inferrable type");
4397 while (
const auto *array = dyn_cast<ArrayType>(canon))
4398 canon = array->getElementType().getTypePtr();
4400 if (
const auto *opt = dyn_cast<ObjCObjectPointerType>(canon)) {
4402 if (opt->getObjectType()->isObjCClass())
4410 if (
const auto *
typedefType = getAs<TypedefType>())
4411 return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
4416 if (
const auto *
typedefType = getAs<TypedefType>())
4417 return typedefType->getDecl()->hasAttr<ObjCIndependentClassAttr>();
4430 if (
const auto *OPT = getAs<PointerType>())
4431 return OPT->getPointeeType()->isObjCIndirectLifetimeType();
4432 if (
const auto *Ref = getAs<ReferenceType>())
4433 return Ref->getPointeeType()->isObjCIndirectLifetimeType();
4434 if (
const auto *MemPtr = getAs<MemberPointerType>())
4435 return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
4443 while (
const ArrayType *array =
type->getAsArrayTypeUnsafe())
4444 type = array->getElementType().getTypePtr();
4445 return type->isObjCRetainableType();
4456 const auto *Pointer = getAs<PointerType>();
4460 QualType Pointee = Pointer->getPointeeType();
4466 if (
const auto *RT = getAs<RecordType>())
4467 return RT->getDecl()->hasAttr<CUDADeviceBuiltinSurfaceTypeAttr>();
4473 if (
const auto *RT = getAs<RecordType>())
4474 return RT->getDecl()->hasAttr<CUDADeviceBuiltinTextureTypeAttr>();
4481 if (
const auto *ptr = getAs<PointerType>())
4482 return ptr->getPointeeType()->hasSizedVLAType();
4483 if (
const auto *ref = getAs<ReferenceType>())
4484 return ref->getPointeeType()->hasSizedVLAType();
4486 if (isa<VariableArrayType>(arr) &&
4487 cast<VariableArrayType>(arr)->getSizeExpr())
4490 return arr->getElementType()->hasSizedVLAType();
4497 switch (
type.getObjCLifetime()) {
4509 if (
const auto *RT =
4512 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4514 if (CXXRD->hasDefinition() && !CXXRD->hasTrivialDestructor())
4533 llvm::FixedPointSemantics FXSema(Val.getBitWidth(), Scale, Val.isSigned(),
4536 llvm::APFixedPoint(Val, FXSema).toString(Str);
4544 AutoTypeBits.Keyword = (
unsigned)Keyword;
4545 AutoTypeBits.NumArgs = TypeConstraintArgs.size();
4546 this->TypeConstraintConcept = TypeConstraintConcept;
4547 if (TypeConstraintConcept) {
4559 void AutoType::Profile(llvm::FoldingSetNodeID &
ID,
const ASTContext &Context,
4564 ID.AddInteger((
unsigned)Keyword);
4565 ID.AddBoolean(IsDependent);
4568 Arg.Profile(
ID, Context);