67 #include "llvm/ADT/APFixedPoint.h"
68 #include "llvm/ADT/APInt.h"
69 #include "llvm/ADT/APSInt.h"
70 #include "llvm/ADT/ArrayRef.h"
71 #include "llvm/ADT/DenseMap.h"
72 #include "llvm/ADT/DenseSet.h"
73 #include "llvm/ADT/FoldingSet.h"
74 #include "llvm/ADT/PointerUnion.h"
75 #include "llvm/ADT/STLExtras.h"
76 #include "llvm/ADT/SmallPtrSet.h"
77 #include "llvm/ADT/SmallVector.h"
78 #include "llvm/ADT/StringExtras.h"
79 #include "llvm/ADT/StringRef.h"
80 #include "llvm/ADT/Triple.h"
81 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
82 #include "llvm/Support/Capacity.h"
83 #include "llvm/Support/Casting.h"
84 #include "llvm/Support/Compiler.h"
85 #include "llvm/Support/ErrorHandling.h"
86 #include "llvm/Support/MD5.h"
87 #include "llvm/Support/MathExtras.h"
88 #include "llvm/Support/raw_ostream.h"
101 using namespace clang;
125 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
130 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
131 if (VD->isStaticDataMember() &&
136 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(D)) {
141 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
148 if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
152 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
155 if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition())
159 if (isa<ParmVarDecl>(D))
164 if (isa<TemplateTypeParmDecl>(D) ||
165 isa<NonTypeTemplateParmDecl>(D) ||
166 isa<TemplateTemplateParmDecl>(D))
175 if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) ||
176 isa<ObjCPropertyDecl>(D) ||
177 isa<RedeclarableTemplateDecl>(D) ||
178 isa<ClassTemplateSpecializationDecl>(D) ||
258 if (isa<EnumDecl>(D)) {
262 BufferRef.has_value()) {
263 llvm::StringRef buffer = BufferRef->getBuffer().substr(
265 if (buffer.starts_with(
"NS_ENUM(") ||
266 buffer.starts_with(
"NS_OPTIONS(")) {
282 const std::map<unsigned, RawComment *> &CommentsInTheFile)
const {
285 if (RepresentativeLocForDecl.
isInvalid() ||
286 !RepresentativeLocForDecl.
isFileID())
290 if (CommentsInTheFile.empty())
295 const std::pair<FileID, unsigned> DeclLocDecomp =
299 auto OffsetCommentBehindDecl =
300 CommentsInTheFile.lower_bound(DeclLocDecomp.second);
303 if (OffsetCommentBehindDecl != CommentsInTheFile.end()) {
304 RawComment *CommentBehindDecl = OffsetCommentBehindDecl->second;
308 (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D) ||
309 isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D))) {
313 if (SourceMgr.
getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) ==
315 OffsetCommentBehindDecl->first)) {
316 return CommentBehindDecl;
323 if (OffsetCommentBehindDecl == CommentsInTheFile.begin())
326 auto OffsetCommentBeforeDecl = --OffsetCommentBehindDecl;
327 RawComment *CommentBeforeDecl = OffsetCommentBeforeDecl->second;
336 const unsigned CommentEndOffset =
340 bool Invalid =
false;
341 const char *Buffer = SourceMgr.
getBufferData(DeclLocDecomp.first,
347 StringRef
Text(Buffer + CommentEndOffset,
348 DeclLocDecomp.second - CommentEndOffset);
352 if (
Text.find_first_of(
";{}#@") != StringRef::npos)
355 return CommentBeforeDecl;
375 if (!
File.isValid()) {
379 if (!CommentsInThisFile || CommentsInThisFile->empty())
386 assert(LangOpts.RetainCommentsFromSystemHeaders ||
395 if (
const auto *FD = dyn_cast<FunctionDecl>(&D)) {
415 if (
const auto *VD = dyn_cast<VarDecl>(&D)) {
418 if (VD->isStaticDataMember())
424 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(&D)) {
431 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(CRD)) {
439 : *
static_cast<const Decl *
>(
445 CRD->getMemberSpecializationInfo())
446 return *Info->getInstantiatedFrom();
450 if (
const auto *ED = dyn_cast<EnumDecl>(&D)) {
463 const Decl **OriginalDecl)
const {
466 OriginalDecl =
nullptr;
478 return DeclComment->second;
491 *OriginalDecl = RedeclComment->second;
494 "This decl is supposed to have comment attached.");
495 return CommentAtRedecl->second;
501 auto LastCheckedRedecl = [
this, CanonicalD]() ->
const Decl * {
504 return LookupRes->second;
508 for (
const auto Redecl : D->
redecls()) {
511 if (LastCheckedRedecl) {
512 if (LastCheckedRedecl == Redecl) {
513 LastCheckedRedecl =
nullptr;
521 *OriginalDecl = Redecl;
522 return RedeclComment;
528 *OriginalDecl =
nullptr;
544 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(DC)) {
549 for (
const auto *Ext :
ID->known_extensions()) {
553 Redeclared.push_back(RedeclaredMethod);
564 for (
Decl *D : Decls) {
574 if (
File.isInvalid())
578 if (!CommentsInThisFile || CommentsInThisFile->empty() ||
579 CommentsInThisFile->rbegin()->second->isAttached())
590 for (
const Decl *D : Decls) {
592 if (D->isInvalidDecl())
615 const Decl *D)
const {
618 ThisDeclInfo->IsFilled =
false;
619 ThisDeclInfo->fill();
620 ThisDeclInfo->CommentDecl = FC->
getDecl();
621 if (!ThisDeclInfo->TemplateParameters)
631 return RC ? RC->
parse(*
this,
nullptr, D) :
nullptr;
642 llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos =
646 if (Canonical != D) {
654 const Decl *OriginalDecl =
nullptr;
658 if (isa<ObjCMethodDecl>(D) || isa<FunctionDecl>(D)) {
660 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
661 if (OMD && OMD->isPropertyAccessor())
668 for (
unsigned i = 0, e = Overridden.size(); i < e; i++)
672 else if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
675 QualType QT = TD->getUnderlyingType();
677 if (
const Decl *TD = TT->getDecl())
681 else if (
const auto *IC = dyn_cast<ObjCInterfaceDecl>(D)) {
682 while (IC->getSuperClass()) {
683 IC = IC->getSuperClass();
688 else if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(D)) {
693 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
694 if (!(RD = RD->getDefinition()))
697 for (
const auto &I : RD->bases()) {
698 if (I.isVirtual() || (I.getAccessSpecifier() !=
AS_public))
704 if (!(NonVirtualBase= NonVirtualBase->getDefinition()))
712 for (
const auto &I : RD->vbases()) {
719 if (!(VirtualBase= VirtualBase->getDefinition()))
733 if (D != OriginalDecl && OriginalDecl)
742 ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &
ID,
750 ID.AddInteger(Params->
size());
752 PEnd = Params->
end();
754 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
756 ID.AddBoolean(TTP->isParameterPack());
758 ID.AddBoolean(TC !=
nullptr);
762 if (TTP->isExpandedParameterPack()) {
764 ID.AddInteger(TTP->getNumExpansionParameters());
766 ID.AddBoolean(
false);
770 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
772 ID.AddBoolean(NTTP->isParameterPack());
773 const Expr *TC = NTTP->getPlaceholderTypeConstraint();
774 ID.AddBoolean(TC !=
nullptr);
775 ID.AddPointer(NTTP->getType().getCanonicalType().getAsOpaquePtr());
778 if (NTTP->isExpandedParameterPack()) {
780 ID.AddInteger(NTTP->getNumExpansionTypes());
781 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
782 QualType T = NTTP->getExpansionType(I);
786 ID.AddBoolean(
false);
790 auto *TTP = cast<TemplateTemplateParmDecl>(*
P);
795 ID.AddBoolean(RequiresClause !=
nullptr);
811 if (
const auto *Fold = dyn_cast<CXXFoldExpr>(IDC))
812 CSE = cast<ConceptSpecializationExpr>(Fold->getLHS());
814 CSE = cast<ConceptSpecializationExpr>(IDC);
817 NewConverted.reserve(OldConverted.size());
822 NewConverted.push_back(ConstrainedType);
823 llvm::append_range(NewConverted,
824 OldConverted.front().pack_elements().drop_front(1));
827 NewConverted.clear();
828 NewConverted.push_back(NewPack);
829 assert(OldConverted.size() == 1 &&
830 "Template parameter pack should be the last parameter");
833 "Unexpected first argument kind for immediately-declared "
835 NewConverted.push_back(ConstrainedType);
836 llvm::append_range(NewConverted, OldConverted.drop_front(1));
846 if (
auto *OrigFold = dyn_cast<CXXFoldExpr>(IDC))
855 ASTContext::getCanonicalTemplateTemplateParmDecl(
858 llvm::FoldingSetNodeID
ID;
859 CanonicalTemplateTemplateParm::Profile(
ID, *
this, TTP);
860 void *InsertPos =
nullptr;
861 CanonicalTemplateTemplateParm *Canonical
862 = CanonTemplateTemplateParms.FindNodeOrInsertPos(
ID, InsertPos);
864 return Canonical->getParam();
869 CanonParams.reserve(Params->
size());
871 PEnd = Params->
end();
873 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
879 ? std::optional<unsigned>(TTP->getNumExpansionParameters())
881 if (
const auto *TC = TTP->getTypeConstraint()) {
884 *
this, TC->getImmediatelyDeclaredConstraint(),
892 TC->getNamedConcept(),
nullptr, NewIDC);
894 CanonParams.push_back(NewTTP);
895 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
899 if (NTTP->isExpandedParameterPack()) {
902 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
904 ExpandedTInfos.push_back(
912 NTTP->getPosition(),
nullptr,
922 NTTP->getPosition(),
nullptr,
924 NTTP->isParameterPack(),
928 if (AT->isConstrained()) {
931 *
this, NTTP->getPlaceholderTypeConstraint(), T));
934 CanonParams.push_back(Param);
937 CanonParams.push_back(getCanonicalTemplateTemplateParmDecl(
938 cast<TemplateTemplateParmDecl>(*
P)));
941 Expr *CanonRequiresClause =
nullptr;
943 CanonRequiresClause = RequiresClause;
955 CanonRequiresClause));
958 Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(
ID, InsertPos);
959 assert(!Canonical &&
"Shouldn't be in the map!");
963 Canonical =
new (*this) CanonicalTemplateTemplateParm(CanonTTP);
964 CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos);
974 if (!LangOpts.CPlusPlus)
return nullptr;
977 case TargetCXXABI::AppleARM64:
978 case TargetCXXABI::Fuchsia:
979 case TargetCXXABI::GenericARM:
980 case TargetCXXABI::iOS:
981 case TargetCXXABI::WatchOS:
982 case TargetCXXABI::GenericAArch64:
983 case TargetCXXABI::GenericMIPS:
984 case TargetCXXABI::GenericItanium:
985 case TargetCXXABI::WebAssembly:
986 case TargetCXXABI::XL:
988 case TargetCXXABI::Microsoft:
991 llvm_unreachable(
"Invalid CXXABI type!");
995 if (!InterpContext) {
998 return *InterpContext.get();
1004 return *ParentMapCtx.get();
1009 switch (LangOpts.getAddressSpaceMapMangling()) {
1017 llvm_unreachable(
"getAddressSpaceMapMangling() doesn't cover anything.");
1023 : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize),
1024 FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize),
1025 TemplateSpecializationTypes(this_()),
1026 DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
1027 SubstTemplateTemplateParmPacks(this_()),
1028 CanonTemplateTemplateParms(this_()), SourceMgr(
SM), LangOpts(LOpts),
1031 LangOpts.XRayNeverInstrumentFiles,
1032 LangOpts.XRayAttrListFiles,
SM)),
1035 BuiltinInfo(builtins), TUKind(TUKind), DeclarationNames(*this),
1036 Comments(
SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
1037 CompCategories(this_()), LastSDM(nullptr, 0) {
1044 ReleaseDeclContextMaps();
1047 for (
auto &Pair : Deallocations)
1048 (Pair.first)(Pair.second);
1049 Deallocations.clear();
1055 I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; )
1059 ObjCLayouts.clear();
1061 for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
1062 I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
1067 ASTRecordLayouts.clear();
1069 for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(),
1070 AEnd = DeclAttrs.end();
1072 A->second->~AttrVec();
1075 for (
const auto &
Value : ModuleInitializers)
1076 Value.second->~PerModuleInitializers();
1077 ModuleInitializers.clear();
1083 TraversalScope = TopLevelDecls;
1088 Deallocations.push_back({Callback, Data});
1097 llvm::errs() <<
"\n*** AST Context Stats:\n";
1098 llvm::errs() <<
" " << Types.size() <<
" types total.\n";
1100 unsigned counts[] = {
1101 #define TYPE(Name, Parent) 0,
1102 #define ABSTRACT_TYPE(Name, Parent)
1103 #include "clang/AST/TypeNodes.inc"
1107 for (
unsigned i = 0, e = Types.size(); i != e; ++i) {
1113 unsigned TotalBytes = 0;
1114 #define TYPE(Name, Parent) \
1116 llvm::errs() << " " << counts[Idx] << " " << #Name \
1117 << " types, " << sizeof(Name##Type) << " each " \
1118 << "(" << counts[Idx] * sizeof(Name##Type) \
1120 TotalBytes += counts[Idx] * sizeof(Name##Type); \
1122 #define ABSTRACT_TYPE(Name, Parent)
1123 #include "clang/AST/TypeNodes.inc"
1125 llvm::errs() <<
"Total bytes = " << TotalBytes <<
"\n";
1130 <<
" implicit default constructors created\n";
1133 <<
" implicit copy constructors created\n";
1137 <<
" implicit move constructors created\n";
1140 <<
" implicit copy assignment operators created\n";
1144 <<
" implicit move assignment operators created\n";
1147 <<
" implicit destructors created\n";
1150 llvm::errs() <<
"\n";
1154 BumpAlloc.PrintStats();
1158 bool NotifyListeners) {
1159 if (NotifyListeners)
1168 if (It == MergedDefModules.end())
1171 auto &Merged = It->second;
1173 for (
Module *&M : Merged)
1174 if (!Found.insert(M).second)
1176 llvm::erase_value(Merged,
nullptr);
1183 if (MergedIt == MergedDefModules.end())
1184 return std::nullopt;
1185 return MergedIt->second;
1188 void ASTContext::PerModuleInitializers::resolve(
ASTContext &Ctx) {
1189 if (LazyInitializers.empty())
1193 assert(Source &&
"lazy initializers but no external source");
1195 auto LazyInits = std::move(LazyInitializers);
1196 LazyInitializers.clear();
1198 for (
auto ID : LazyInits)
1199 Initializers.push_back(Source->GetExternalDecl(
ID));
1201 assert(LazyInitializers.empty() &&
1202 "GetExternalDecl for lazy module initializer added more inits");
1208 if (
const auto *
ID = dyn_cast<ImportDecl>(D)) {
1209 auto It = ModuleInitializers.find(
ID->getImportedModule());
1212 if (It == ModuleInitializers.end())
1216 auto &Imported = *It->second;
1217 if (Imported.Initializers.size() + Imported.LazyInitializers.size() == 1) {
1218 Imported.resolve(*
this);
1219 auto *OnlyDecl = Imported.Initializers.front();
1220 if (isa<ImportDecl>(OnlyDecl))
1225 auto *&Inits = ModuleInitializers[M];
1227 Inits =
new (*this) PerModuleInitializers;
1228 Inits->Initializers.push_back(D);
1232 auto *&Inits = ModuleInitializers[M];
1234 Inits =
new (*this) PerModuleInitializers;
1235 Inits->LazyInitializers.insert(Inits->LazyInitializers.end(),
1236 IDs.begin(), IDs.end());
1240 auto It = ModuleInitializers.find(M);
1241 if (It == ModuleInitializers.end())
1242 return std::nullopt;
1244 auto *Inits = It->second;
1245 Inits->resolve(*
this);
1246 return Inits->Initializers;
1250 if (!ExternCContext)
1253 return ExternCContext;
1259 auto *BuiltinTemplate =
1261 BuiltinTemplate->setImplicit();
1264 return BuiltinTemplate;
1269 if (!MakeIntegerSeqDecl)
1272 return MakeIntegerSeqDecl;
1277 if (!TypePackElementDecl)
1280 return TypePackElementDecl;
1294 NewDecl->
addAttr(TypeVisibilityAttr::CreateImplicit(
1295 const_cast<ASTContext &
>(*
this), TypeVisibilityAttr::Default));
1300 StringRef Name)
const {
1324 Types.push_back(Ty);
1329 assert((!this->Target || this->Target == &
Target) &&
1330 "Incorrect target reinitialization");
1334 this->AuxTarget = AuxTarget;
1336 ABI.reset(createCXXABI(
Target));
1340 InitBuiltinType(
VoidTy, BuiltinType::Void);
1343 InitBuiltinType(
BoolTy, BuiltinType::Bool);
1345 if (LangOpts.CharIsSigned)
1346 InitBuiltinType(
CharTy, BuiltinType::Char_S);
1348 InitBuiltinType(
CharTy, BuiltinType::Char_U);
1351 InitBuiltinType(
ShortTy, BuiltinType::Short);
1352 InitBuiltinType(
IntTy, BuiltinType::Int);
1353 InitBuiltinType(
LongTy, BuiltinType::Long);
1354 InitBuiltinType(
LongLongTy, BuiltinType::LongLong);
1365 InitBuiltinType(
DoubleTy, BuiltinType::Double);
1366 InitBuiltinType(
LongDoubleTy, BuiltinType::LongDouble);
1369 InitBuiltinType(
Float128Ty, BuiltinType::Float128);
1372 InitBuiltinType(
Ibm128Ty, BuiltinType::Ibm128);
1375 InitBuiltinType(
Float16Ty, BuiltinType::Float16);
1378 InitBuiltinType(
ShortAccumTy, BuiltinType::ShortAccum);
1379 InitBuiltinType(
AccumTy, BuiltinType::Accum);
1380 InitBuiltinType(
LongAccumTy, BuiltinType::LongAccum);
1384 InitBuiltinType(
ShortFractTy, BuiltinType::ShortFract);
1385 InitBuiltinType(
FractTy, BuiltinType::Fract);
1386 InitBuiltinType(
LongFractTy, BuiltinType::LongFract);
1391 InitBuiltinType(
SatAccumTy, BuiltinType::SatAccum);
1397 InitBuiltinType(
SatFractTy, BuiltinType::SatFract);
1404 InitBuiltinType(
Int128Ty, BuiltinType::Int128);
1409 InitBuiltinType(
WCharTy, BuiltinType::WChar_S);
1411 InitBuiltinType(
WCharTy, BuiltinType::WChar_U);
1412 if (LangOpts.CPlusPlus && LangOpts.WChar)
1422 InitBuiltinType(
Char8Ty, BuiltinType::Char8);
1424 if (LangOpts.CPlusPlus)
1425 InitBuiltinType(
Char16Ty, BuiltinType::Char16);
1429 if (LangOpts.CPlusPlus)
1430 InitBuiltinType(
Char32Ty, BuiltinType::Char32);
1439 InitBuiltinType(
DependentTy, BuiltinType::Dependent);
1442 InitBuiltinType(
OverloadTy, BuiltinType::Overload);
1451 InitBuiltinType(
UnknownAnyTy, BuiltinType::UnknownAny);
1457 InitBuiltinType(
BuiltinFnTy, BuiltinType::BuiltinFn);
1460 if (LangOpts.OpenMP) {
1465 if (LangOpts.MatrixTypes)
1473 if (LangOpts.OpenCL) {
1474 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1475 InitBuiltinType(SingletonId, BuiltinType::Id);
1476 #include "clang/Basic/OpenCLImageTypes.def"
1478 InitBuiltinType(
OCLSamplerTy, BuiltinType::OCLSampler);
1479 InitBuiltinType(
OCLEventTy, BuiltinType::OCLEvent);
1481 InitBuiltinType(
OCLQueueTy, BuiltinType::OCLQueue);
1484 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1485 InitBuiltinType(Id##Ty, BuiltinType::Id);
1486 #include "clang/Basic/OpenCLExtensionTypes.def"
1489 if (
Target.hasAArch64SVETypes()) {
1490 #define SVE_TYPE(Name, Id, SingletonId) \
1491 InitBuiltinType(SingletonId, BuiltinType::Id);
1492 #include "clang/Basic/AArch64SVEACLETypes.def"
1495 if (
Target.getTriple().isPPC64()) {
1496 #define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
1497 InitBuiltinType(Id##Ty, BuiltinType::Id);
1498 #include "clang/Basic/PPCTypes.def"
1499 #define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
1500 InitBuiltinType(Id##Ty, BuiltinType::Id);
1501 #include "clang/Basic/PPCTypes.def"
1504 if (
Target.hasRISCVVTypes()) {
1505 #define RVV_TYPE(Name, Id, SingletonId) \
1506 InitBuiltinType(SingletonId, BuiltinType::Id);
1507 #include "clang/Basic/RISCVVTypes.def"
1514 ObjCConstantStringType =
QualType();
1519 if (LangOpts.OpenCLGenericAddressSpace) {
1529 InitBuiltinType(
NullPtrTy, BuiltinType::NullPtr);
1532 InitBuiltinType(
HalfTy, BuiltinType::Half);
1534 InitBuiltinType(
BFloat16Ty, BuiltinType::BFloat16);
1540 if (LangOpts.MicrosoftExt || LangOpts.Borland) {
1551 AttrVec *&Result = DeclAttrs[D];
1562 llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D);
1563 if (Pos != DeclAttrs.end()) {
1564 Pos->second->~AttrVec();
1565 DeclAttrs.erase(Pos);
1579 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>::iterator Pos =
1580 TemplateOrInstantiation.find(Var);
1581 if (Pos == TemplateOrInstantiation.end())
1594 Tmpl, TSK, PointOfInstantiation));
1600 assert(!TemplateOrInstantiation[Inst] &&
1601 "Already noted what the variable was instantiated from");
1602 TemplateOrInstantiation[Inst] = TSI;
1607 auto Pos = InstantiatedFromUsingDecl.find(UUD);
1608 if (Pos == InstantiatedFromUsingDecl.end())
1616 assert((isa<UsingDecl>(Pattern) ||
1617 isa<UnresolvedUsingValueDecl>(Pattern) ||
1618 isa<UnresolvedUsingTypenameDecl>(Pattern)) &&
1619 "pattern decl is not a using decl");
1620 assert((isa<UsingDecl>(Inst) ||
1621 isa<UnresolvedUsingValueDecl>(Inst) ||
1622 isa<UnresolvedUsingTypenameDecl>(Inst)) &&
1623 "instantiation did not produce a using decl");
1624 assert(!InstantiatedFromUsingDecl[Inst] &&
"pattern already exists");
1625 InstantiatedFromUsingDecl[Inst] = Pattern;
1630 auto Pos = InstantiatedFromUsingEnumDecl.find(UUD);
1631 if (Pos == InstantiatedFromUsingEnumDecl.end())
1639 assert(!InstantiatedFromUsingEnumDecl[Inst] &&
"pattern already exists");
1640 InstantiatedFromUsingEnumDecl[Inst] = Pattern;
1645 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos
1646 = InstantiatedFromUsingShadowDecl.find(Inst);
1647 if (Pos == InstantiatedFromUsingShadowDecl.end())
1656 assert(!InstantiatedFromUsingShadowDecl[Inst] &&
"pattern already exists");
1657 InstantiatedFromUsingShadowDecl[Inst] = Pattern;
1661 llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos
1662 = InstantiatedFromUnnamedFieldDecl.find(Field);
1663 if (Pos == InstantiatedFromUnnamedFieldDecl.end())
1671 assert(!Inst->
getDeclName() &&
"Instantiated field decl is not unnamed");
1672 assert(!Tmpl->
getDeclName() &&
"Template field decl is not unnamed");
1673 assert(!InstantiatedFromUnnamedFieldDecl[Inst] &&
1674 "Already noted what unnamed field was instantiated from");
1676 InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl;
1692 return Range.end() - Range.begin();
1697 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos =
1699 if (Pos == OverriddenMethods.end())
1707 OverriddenMethods[Method].push_back(Overridden);
1715 if (
const auto *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
1721 const auto *Method = dyn_cast<ObjCMethodDecl>(D);
1726 Method->getOverriddenMethods(OverDecls);
1727 Overridden.append(OverDecls.begin(), OverDecls.end());
1731 assert(!Import->getNextLocalImport() &&
1732 "Import declaration already in the chain");
1733 assert(!Import->isFromASTFile() &&
"Non-local import declaration");
1734 if (!FirstLocalImport) {
1735 FirstLocalImport = Import;
1736 LastLocalImport = Import;
1740 LastLocalImport->setNextLocalImport(Import);
1741 LastLocalImport = Import;
1753 llvm_unreachable(
"Not a floating point type!");
1754 case BuiltinType::BFloat16:
1756 case BuiltinType::Float16:
1758 case BuiltinType::Half:
1770 case BuiltinType::Ibm128:
1772 case BuiltinType::LongDouble:
1776 case BuiltinType::Float128:
1786 bool UseAlignAttrOnly =
false;
1788 Align = AlignFromAttr;
1796 if (isa<FieldDecl>(D)) {
1797 UseAlignAttrOnly = D->
hasAttr<PackedAttr>() ||
1798 cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1800 UseAlignAttrOnly =
true;
1803 else if (isa<FieldDecl>(D))
1806 cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1810 if (UseAlignAttrOnly) {
1812 }
else if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
1828 if (!ForAlignof && MinWidth) {
1831 else if (isa<ConstantArrayType>(
arrayType) &&
1839 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
1840 if (VD->hasGlobalStorage() && !ForAlignof) {
1852 if (
const auto *Field = dyn_cast<FieldDecl>(VD)) {
1855 if (!
Parent->isInvalidDecl()) {
1867 if (LowBitOfOffset < FieldAlign)
1868 FieldAlign =
static_cast<unsigned>(LowBitOfOffset);
1871 Align =
std::min(Align, FieldAlign);
1879 const auto *VD = dyn_cast<VarDecl>(D);
1880 if (MaxAlignedAttr && VD && VD->getStorageClass() ==
SC_Static)
1881 Align =
std::min(Align, MaxAlignedAttr);
1919 "Overflow in array type char size evaluation");
1924 Width = llvm::alignTo(Width, Align);
1931 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
1949 switch (BT->getKind()) {
1950 case BuiltinType::Bool:
1951 case BuiltinType::Char_S:
1952 case BuiltinType::Char_U:
1953 case BuiltinType::SChar:
1954 case BuiltinType::UChar:
1955 case BuiltinType::Short:
1956 case BuiltinType::UShort:
1957 case BuiltinType::WChar_S:
1958 case BuiltinType::WChar_U:
1959 case BuiltinType::Char8:
1960 case BuiltinType::Char16:
1961 case BuiltinType::Char32:
1970 if (T->
isDependentType() || ET->getDecl()->getPromotionType().isNull() ||
1971 ET->getDecl()->isScoped())
1989 bool NeedsPreferredAlignment)
const {
1992 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
2003 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
2008 return TT->getDecl()->getMaxAlignment();
2014 TypeInfoMap::iterator I = MemoizedTypeInfo.find(T);
2015 if (I != MemoizedTypeInfo.end())
2020 MemoizedTypeInfo[T] = TI;
2030 TypeInfo ASTContext::getTypeInfoImpl(
const Type *T)
const {
2036 #define TYPE(Class, Base)
2037 #define ABSTRACT_TYPE(Class, Base)
2038 #define NON_CANONICAL_TYPE(Class, Base)
2039 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
2040 #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) \
2042 assert(!T->isDependentType() && "should not see dependent types here"); \
2043 return getTypeInfo(cast<Class##Type>(T)->desugar().getTypePtr());
2044 #include "clang/AST/TypeNodes.inc"
2045 llvm_unreachable(
"Should not see dependent types");
2047 case Type::FunctionNoProto:
2048 case Type::FunctionProto:
2054 case Type::IncompleteArray:
2055 case Type::VariableArray:
2056 case Type::ConstantArray: {
2059 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
2060 Size = CAT->getSize().getZExtValue();
2063 assert((Size == 0 || EltInfo.
Width <= (
uint64_t)(-1) / Size) &&
2064 "Overflow in array type bit size evaluation");
2065 Width = EltInfo.
Width * Size;
2066 Align = EltInfo.
Align;
2070 Width = llvm::alignTo(Width, Align);
2074 case Type::ExtVector:
2075 case Type::Vector: {
2076 const auto *VT = cast<VectorType>(T);
2078 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
2079 : EltInfo.
Width * VT->getNumElements();
2081 Width = std::max<unsigned>(8, Width);
2082 Align = std::max<unsigned>(8, Width);
2086 if (Align & (Align-1)) {
2087 Align = llvm::NextPowerOf2(Align);
2088 Width = llvm::alignTo(Width, Align);
2092 if (TargetVectorAlign && TargetVectorAlign < Align)
2093 Align = TargetVectorAlign;
2104 case Type::ConstantMatrix: {
2105 const auto *MT = cast<ConstantMatrixType>(T);
2110 Width = ElementInfo.
Width * MT->getNumRows() * MT->getNumColumns();
2111 Align = ElementInfo.
Align;
2116 switch (cast<BuiltinType>(T)->
getKind()) {
2117 default: llvm_unreachable(
"Unknown builtin type!");
2118 case BuiltinType::Void:
2123 case BuiltinType::Bool:
2127 case BuiltinType::Char_S:
2128 case BuiltinType::Char_U:
2129 case BuiltinType::UChar:
2130 case BuiltinType::SChar:
2131 case BuiltinType::Char8:
2135 case BuiltinType::WChar_S:
2136 case BuiltinType::WChar_U:
2140 case BuiltinType::Char16:
2144 case BuiltinType::Char32:
2148 case BuiltinType::UShort:
2149 case BuiltinType::Short:
2153 case BuiltinType::UInt:
2154 case BuiltinType::Int:
2158 case BuiltinType::ULong:
2159 case BuiltinType::Long:
2163 case BuiltinType::ULongLong:
2164 case BuiltinType::LongLong:
2168 case BuiltinType::Int128:
2169 case BuiltinType::UInt128:
2173 case BuiltinType::ShortAccum:
2174 case BuiltinType::UShortAccum:
2175 case BuiltinType::SatShortAccum:
2176 case BuiltinType::SatUShortAccum:
2180 case BuiltinType::Accum:
2181 case BuiltinType::UAccum:
2182 case BuiltinType::SatAccum:
2183 case BuiltinType::SatUAccum:
2187 case BuiltinType::LongAccum:
2188 case BuiltinType::ULongAccum:
2189 case BuiltinType::SatLongAccum:
2190 case BuiltinType::SatULongAccum:
2194 case BuiltinType::ShortFract:
2195 case BuiltinType::UShortFract:
2196 case BuiltinType::SatShortFract:
2197 case BuiltinType::SatUShortFract:
2201 case BuiltinType::Fract:
2202 case BuiltinType::UFract:
2203 case BuiltinType::SatFract:
2204 case BuiltinType::SatUFract:
2208 case BuiltinType::LongFract:
2209 case BuiltinType::ULongFract:
2210 case BuiltinType::SatLongFract:
2211 case BuiltinType::SatULongFract:
2215 case BuiltinType::BFloat16:
2226 case BuiltinType::Float16:
2227 case BuiltinType::Half:
2234 "Expected OpenMP device compilation.");
2243 case BuiltinType::Double:
2247 case BuiltinType::Ibm128:
2251 case BuiltinType::LongDouble:
2262 case BuiltinType::Float128:
2269 "Expected OpenMP device compilation.");
2274 case BuiltinType::NullPtr:
2279 case BuiltinType::ObjCId:
2280 case BuiltinType::ObjCClass:
2281 case BuiltinType::ObjCSel:
2285 case BuiltinType::OCLSampler:
2286 case BuiltinType::OCLEvent:
2287 case BuiltinType::OCLClkEvent:
2288 case BuiltinType::OCLQueue:
2289 case BuiltinType::OCLReserveID:
2290 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2291 case BuiltinType::Id:
2292 #include "clang/Basic/OpenCLImageTypes.def"
2293 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2294 case BuiltinType::Id:
2295 #include "clang/Basic/OpenCLExtensionTypes.def"
2308 #define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
2309 IsSigned, IsFP, IsBF) \
2310 case BuiltinType::Id: \
2314 #define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
2315 case BuiltinType::Id: \
2319 #include "clang/Basic/AArch64SVEACLETypes.def"
2320 #define PPC_VECTOR_TYPE(Name, Id, Size) \
2321 case BuiltinType::Id: \
2325 #include "clang/Basic/PPCTypes.def"
2326 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, NF, IsSigned, \
2328 case BuiltinType::Id: \
2332 #define RVV_PREDICATE_TYPE(Name, Id, SingletonId, ElKind) \
2333 case BuiltinType::Id: \
2337 #include "clang/Basic/RISCVVTypes.def"
2340 case Type::ObjCObjectPointer:
2344 case Type::BlockPointer:
2345 AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace();
2349 case Type::LValueReference:
2350 case Type::RValueReference:
2353 AS = cast<ReferenceType>(T)->getPointeeType().getAddressSpace();
2358 AS = cast<PointerType>(T)->getPointeeType().getAddressSpace();
2362 case Type::MemberPointer: {
2363 const auto *MPT = cast<MemberPointerType>(T);
2369 case Type::Complex: {
2373 Width = EltInfo.
Width * 2;
2374 Align = EltInfo.
Align;
2377 case Type::ObjCObject:
2378 return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr());
2379 case Type::Adjusted:
2382 case Type::ObjCInterface: {
2383 const auto *ObjCI = cast<ObjCInterfaceType>(T);
2384 if (ObjCI->getDecl()->isInvalidDecl()) {
2394 case Type::BitInt: {
2395 const auto *EIT = cast<BitIntType>(T);
2398 getCharWidth(), llvm::PowerOf2Ceil(EIT->getNumBits()))),
2400 Width = llvm::alignTo(EIT->getNumBits(), Align);
2405 const auto *TT = cast<TagType>(T);
2407 if (TT->getDecl()->isInvalidDecl()) {
2413 if (
const auto *ET = dyn_cast<EnumType>(TT)) {
2414 const EnumDecl *ED = ET->getDecl();
2418 Info.
Align = AttrAlign;
2424 const auto *RT = cast<RecordType>(TT);
2429 AlignRequirement = RD->
hasAttr<AlignedAttr>()
2435 case Type::SubstTemplateTypeParm:
2436 return getTypeInfo(cast<SubstTemplateTypeParmType>(T)->
2437 getReplacementType().getTypePtr());
2440 case Type::DeducedTemplateSpecialization: {
2441 const auto *A = cast<DeducedType>(T);
2442 assert(!A->getDeducedType().isNull() &&
2443 "cannot request the size of an undeduced or dependent auto type");
2444 return getTypeInfo(A->getDeducedType().getTypePtr());
2448 return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr());
2450 case Type::MacroQualified:
2454 case Type::ObjCTypeParam:
2455 return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr());
2458 return getTypeInfo(cast<UsingType>(T)->desugar().getTypePtr());
2460 case Type::Typedef: {
2461 const auto *TT = cast<TypedefType>(T);
2466 if (
unsigned AttrAlign = TT->getDecl()->getMaxAlignment()) {
2477 case Type::Elaborated:
2478 return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr());
2480 case Type::Attributed:
2482 cast<AttributedType>(T)->getEquivalentType().getTypePtr());
2484 case Type::BTFTagAttributed:
2486 cast<BTFTagAttributedType>(T)->getWrappedType().getTypePtr());
2488 case Type::Atomic: {
2499 }
else if (Width <= Target->getMaxAtomicPromoteWidth()) {
2505 if (!llvm::isPowerOf2_64(Width))
2506 Width = llvm::NextPowerOf2(Width);
2509 Align =
static_cast<unsigned>(Width);
2520 assert(llvm::isPowerOf2_32(Align) &&
"Alignment must be power of 2");
2521 return TypeInfo(Width, Align, AlignRequirement);
2525 UnadjustedAlignMap::iterator I = MemoizedUnadjustedAlign.find(T);
2526 if (I != MemoizedUnadjustedAlign.end())
2529 unsigned UnadjustedAlign;
2541 MemoizedUnadjustedAlign[T] = UnadjustedAlign;
2542 return UnadjustedAlign;
2546 unsigned SimdAlign = llvm::OpenMPIRBuilder::getOpenMPDefaultSimdAlign(
2596 unsigned ABIAlign = TI.
Align;
2618 unsigned PreferredAlign =
static_cast<unsigned>(
2620 assert(PreferredAlign >= ABIAlign &&
2621 "PreferredAlign should be at least as large as ABIAlign.");
2622 return PreferredAlign;
2629 T = CT->getElementType().getTypePtr();
2631 T = ET->getDecl()->getIntegerType().getTypePtr();
2682 for (
unsigned I = 0, N = Path.size(); I != N; ++I) {
2686 std::swap(
Base, Derived);
2706 llvm::append_range(Ivars, OI->
ivars());
2709 for (
const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
2711 Ivars.push_back(Iv);
2719 if (
const auto *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
2722 for (
auto *Proto : OI->all_referenced_protocols()) {
2727 for (
const auto *Cat : OI->visible_categories())
2733 SD = SD->getSuperClass();
2735 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) {
2736 for (
auto *Proto : OC->protocols()) {
2739 }
else if (
const auto *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) {
2741 if (!Protocols.insert(
2745 for (
auto *Proto : OP->protocols())
2752 assert(RD->
isUnion() &&
"Must be union type");
2755 for (
const auto *Field : RD->
fields()) {
2759 if (FieldSize != UnionSize)
2777 static std::optional<int64_t>
2781 static std::optional<int64_t>
2783 if (Field->getType()->isRecordType()) {
2784 const RecordDecl *RD = Field->getType()->getAsRecordDecl();
2791 bool IsBitIntType = Field->getType()->isBitIntType();
2792 if (!Field->getType()->isReferenceType() && !IsBitIntType &&
2794 return std::nullopt;
2798 if (Field->isBitField()) {
2799 int64_t BitfieldSize = Field->getBitWidthValue(Context);
2801 if ((
unsigned)BitfieldSize >
2802 cast<BitIntType>(Field->getType())->getNumBits())
2803 return std::nullopt;
2804 }
else if (BitfieldSize > FieldSizeInBits) {
2805 return std::nullopt;
2807 FieldSizeInBits = BitfieldSize;
2808 }
else if (IsBitIntType &&
2810 return std::nullopt;
2812 return FieldSizeInBits;
2815 static std::optional<int64_t>
2820 template <
typename RangeT>
2822 const RangeT &Subobjects,
int64_t CurOffsetInBits,
2824 for (
const auto *Subobject : Subobjects) {
2825 std::optional<int64_t> SizeInBits =
2828 return std::nullopt;
2829 if (*SizeInBits != 0) {
2831 if (
Offset != CurOffsetInBits)
2832 return std::nullopt;
2833 CurOffsetInBits += *SizeInBits;
2836 return CurOffsetInBits;
2839 static std::optional<int64_t>
2842 assert(!RD->
isUnion() &&
"Must be struct/class type");
2846 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
2847 if (ClassDecl->isDynamicClass())
2848 return std::nullopt;
2851 for (
const auto &
Base : ClassDecl->bases()) {
2854 Bases.emplace_back(
Base.getType()->getAsCXXRecordDecl());
2858 return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
2861 std::optional<int64_t> OffsetAfterBases =
2864 if (!OffsetAfterBases)
2865 return std::nullopt;
2866 CurOffsetInBits = *OffsetAfterBases;
2869 std::optional<int64_t> OffsetAfterFields =
2871 RD->
fields(), CurOffsetInBits, Context, Layout);
2872 if (!OffsetAfterFields)
2873 return std::nullopt;
2874 CurOffsetInBits = *OffsetAfterFields;
2876 return CurOffsetInBits;
2897 assert(!Ty.
isNull() &&
"Null QualType sent to unique object rep check");
2910 if (
const auto *BIT = dyn_cast<BitIntType>(Ty))
2922 return !ABI->getMemberPointerInfo(MPT).HasPadding;
2934 std::optional<int64_t> StructSize =
2958 count += Ext->ivar_size();
2963 count += ImplDecl->ivar_size();
2981 if (isa<GNUNullExpr>(E))
return true;
2989 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2990 I = ObjCImpls.find(D);
2991 if (I != ObjCImpls.end())
2992 return cast<ObjCImplementationDecl>(I->second);
2999 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
3000 I = ObjCImpls.find(D);
3001 if (I != ObjCImpls.end())
3002 return cast<ObjCCategoryImplDecl>(I->second);
3009 assert(IFaceD && ImplD &&
"Passed null params");
3010 ObjCImpls[IFaceD] = ImplD;
3016 assert(CatD && ImplD &&
"Passed null params");
3017 ObjCImpls[CatD] = ImplD;
3022 return ObjCMethodRedecls.lookup(MD);
3028 ObjCMethodRedecls[MD] = Redecl;
3035 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND->
getDeclContext()))
3036 return CD->getClassInterface();
3037 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(ND->
getDeclContext()))
3038 return IMD->getClassInterface();
3046 assert(VD &&
"Passed null params");
3047 assert(VD->
hasAttr<BlocksAttr>() &&
3048 "getBlockVarCopyInits - not __block var");
3049 auto I = BlockVarCopyInits.find(VD);
3050 if (I != BlockVarCopyInits.end())
3052 return {
nullptr,
false};
3058 assert(VD && CopyExpr &&
"Passed null params");
3059 assert(VD->
hasAttr<BlocksAttr>() &&
3060 "setBlockVarCopyInits - not __block var");
3061 BlockVarCopyInits[VD].setExprAndFlag(CopyExpr,
CanThrow);
3065 unsigned DataSize)
const {
3070 "incorrect data size provided to CreateTypeSourceInfo!");
3087 return getObjCLayout(D,
nullptr);
3098 bool &AnyNonCanonArgs) {
3100 for (
auto &Arg : CanonArgs) {
3102 Arg = C.getCanonicalTemplateArgument(Arg);
3103 AnyNonCanonArgs |= !Arg.structurallyEquals(OrigArg);
3113 ASTContext::getExtQualType(
const Type *baseType,
Qualifiers quals)
const {
3118 llvm::FoldingSetNodeID
ID;
3120 void *insertPos =
nullptr;
3121 if (
ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(
ID, insertPos)) {
3122 assert(eq->getQualifiers() == quals);
3131 canon = getExtQualType(canonSplit.
Ty, canonSplit.
Quals);
3134 (void) ExtQualNodes.FindNodeOrInsertPos(
ID, insertPos);
3138 ExtQualNodes.InsertNode(eq, insertPos);
3143 LangAS AddressSpace)
const {
3156 "Type cannot be in multiple addr spaces!");
3159 return getExtQualType(TypeNode, Quals);
3171 const Type *TypeNode;
3174 TypeNode = Quals.
strip(T);
3178 if (!
QualType(TypeNode, 0).hasAddressSpace())
3191 return getExtQualType(TypeNode, Quals);
3218 "Type cannot have multiple ObjCGCs!");
3221 return getExtQualType(TypeNode, Quals);
3240 if (
const auto *FNPT = dyn_cast<FunctionNoProtoType>(T)) {
3243 const auto *FPT = cast<FunctionProtoType>(T);
3246 Result =
getFunctionType(FPT->getReturnType(), FPT->getParamTypes(), EPI);
3249 return cast<FunctionType>(Result.getTypePtr());
3265 L->DeducedReturnType(FD, ResultType);
3275 if (
const auto *PT = dyn_cast<ParenType>(Orig))
3280 if (
const auto *MQT = dyn_cast<MacroQualifiedType>(Orig))
3283 MQT->getMacroIdentifier());
3286 if (
const auto *AT = dyn_cast<AttributedType>(Orig))
3296 Proto->getReturnType(), Proto->getParamTypes(),
3297 Proto->getExtProtoInfo().withExceptionSpec(ESI));
3312 for (
unsigned i = 0, n = Args.size(); i != n; ++i)
3346 if (TSInfo->getType() != FD->
getType())
3354 "TypeLoc size mismatch from updating exception specification");
3355 TSInfo->overrideType(Updated);
3364 llvm::FoldingSetNodeID
ID;
3367 void *InsertPos =
nullptr;
3368 if (
ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(
ID, InsertPos))
3378 ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(
ID, InsertPos);
3379 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3382 Types.push_back(New);
3383 ComplexTypes.InsertNode(New, InsertPos);
3392 llvm::FoldingSetNodeID
ID;
3395 void *InsertPos =
nullptr;
3396 if (
PointerType *PT = PointerTypes.FindNodeOrInsertPos(
ID, InsertPos))
3406 PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(
ID, InsertPos);
3407 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3410 Types.push_back(New);
3411 PointerTypes.InsertNode(New, InsertPos);
3416 llvm::FoldingSetNodeID
ID;
3418 void *InsertPos =
nullptr;
3419 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(
ID, InsertPos);
3426 AT = AdjustedTypes.FindNodeOrInsertPos(
ID, InsertPos);
3427 assert(!AT &&
"Shouldn't be in the map!");
3431 Types.push_back(AT);
3432 AdjustedTypes.InsertNode(AT, InsertPos);
3437 llvm::FoldingSetNodeID
ID;
3439 void *InsertPos =
nullptr;
3440 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(
ID, InsertPos);
3447 AT = AdjustedTypes.FindNodeOrInsertPos(
ID, InsertPos);
3448 assert(!AT &&
"Shouldn't be in the map!");
3451 Types.push_back(AT);
3452 AdjustedTypes.InsertNode(AT, InsertPos);
3485 llvm::FoldingSetNodeID
ID;
3488 void *InsertPos =
nullptr;
3490 BlockPointerTypes.FindNodeOrInsertPos(
ID, InsertPos))
3501 BlockPointerTypes.FindNodeOrInsertPos(
ID, InsertPos);
3502 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3505 Types.push_back(New);
3506 BlockPointerTypes.InsertNode(New, InsertPos);
3516 "Unresolved placeholder type");
3520 llvm::FoldingSetNodeID
ID;
3523 void *InsertPos =
nullptr;
3525 LValueReferenceTypes.FindNodeOrInsertPos(
ID, InsertPos))
3533 if (!SpelledAsLValue || InnerRef || !T.
isCanonical()) {
3534 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3539 LValueReferenceTypes.FindNodeOrInsertPos(
ID, InsertPos);
3540 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3545 Types.push_back(New);
3546 LValueReferenceTypes.InsertNode(New, InsertPos);
3556 "Unresolved placeholder type");
3560 llvm::FoldingSetNodeID
ID;
3563 void *InsertPos =
nullptr;
3565 RValueReferenceTypes.FindNodeOrInsertPos(
ID, InsertPos))
3574 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3579 RValueReferenceTypes.FindNodeOrInsertPos(
ID, InsertPos);
3580 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3584 Types.push_back(New);
3585 RValueReferenceTypes.InsertNode(New, InsertPos);
3594 llvm::FoldingSetNodeID
ID;
3597 void *InsertPos =
nullptr;
3599 MemberPointerTypes.FindNodeOrInsertPos(
ID, InsertPos))
3610 MemberPointerTypes.FindNodeOrInsertPos(
ID, InsertPos);
3611 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3614 Types.push_back(New);
3615 MemberPointerTypes.InsertNode(New, InsertPos);
3623 const Expr *SizeExpr,
3625 unsigned IndexTypeQuals)
const {
3628 "Constant array of VLAs is illegal!");
3639 llvm::FoldingSetNodeID
ID;
3643 void *InsertPos =
nullptr;
3645 ConstantArrayTypes.FindNodeOrInsertPos(
ID, InsertPos))
3656 ASM, IndexTypeQuals);
3661 ConstantArrayTypes.FindNodeOrInsertPos(
ID, InsertPos);
3662 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3666 ConstantArrayType::totalSizeToAlloc<const Expr *>(SizeExpr ? 1 : 0),
3668 auto *New =
new (Mem)
3670 ConstantArrayTypes.InsertNode(New, InsertPos);
3671 Types.push_back(New);
3680 if (!
type->isVariablyModifiedType())
return type;
3685 const Type *ty = split.
Ty;
3687 #define TYPE(Class, Base)
3688 #define ABSTRACT_TYPE(Class, Base)
3689 #define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3690 #include "clang/AST/TypeNodes.inc"
3691 llvm_unreachable(
"didn't desugar past all non-canonical types?");
3697 case Type::DependentVector:
3698 case Type::ExtVector:
3699 case Type::DependentSizedExtVector:
3700 case Type::ConstantMatrix:
3701 case Type::DependentSizedMatrix:
3702 case Type::DependentAddressSpace:
3703 case Type::ObjCObject:
3704 case Type::ObjCInterface:
3705 case Type::ObjCObjectPointer:
3708 case Type::UnresolvedUsing:
3709 case Type::TypeOfExpr:
3711 case Type::Decltype:
3712 case Type::UnaryTransform:
3713 case Type::DependentName:
3714 case Type::InjectedClassName:
3715 case Type::TemplateSpecialization:
3716 case Type::DependentTemplateSpecialization:
3717 case Type::TemplateTypeParm:
3718 case Type::SubstTemplateTypeParmPack:
3720 case Type::DeducedTemplateSpecialization:
3721 case Type::PackExpansion:
3723 case Type::DependentBitInt:
3724 llvm_unreachable(
"type should never be variably-modified");
3728 case Type::FunctionNoProto:
3729 case Type::FunctionProto:
3730 case Type::BlockPointer:
3731 case Type::MemberPointer:
3741 cast<PointerType>(ty)->getPointeeType()));
3744 case Type::LValueReference: {
3745 const auto *lv = cast<LValueReferenceType>(ty);
3748 lv->isSpelledAsLValue());
3752 case Type::RValueReference: {
3753 const auto *lv = cast<RValueReferenceType>(ty);
3759 case Type::Atomic: {
3760 const auto *at = cast<AtomicType>(ty);
3765 case Type::ConstantArray: {
3766 const auto *
cat = cast<ConstantArrayType>(ty);
3771 cat->getSizeModifier(),
3772 cat->getIndexTypeCVRQualifiers());
3776 case Type::DependentSizedArray: {
3777 const auto *dat = cast<DependentSizedArrayType>(ty);
3781 dat->getSizeModifier(),
3782 dat->getIndexTypeCVRQualifiers(),
3783 dat->getBracketsRange());
3788 case Type::IncompleteArray: {
3789 const auto *iat = cast<IncompleteArrayType>(ty);
3794 iat->getIndexTypeCVRQualifiers(),
3800 case Type::VariableArray: {
3801 const auto *vat = cast<VariableArrayType>(ty);
3806 vat->getIndexTypeCVRQualifiers(),
3807 vat->getBracketsRange());
3821 unsigned IndexTypeQuals,
3832 IndexTypeQuals, Brackets);
3839 VariableArrayTypes.push_back(New);
3840 Types.push_back(New);
3850 unsigned elementTypeQuals,
3854 "Size must be type- or value-dependent!");
3864 numElements, ASM, elementTypeQuals,
3866 Types.push_back(newType);
3875 void *insertPos =
nullptr;
3876 llvm::FoldingSetNodeID
ID;
3879 ASM, elementTypeQuals, numElements);
3883 DependentSizedArrayTypes.FindNodeOrInsertPos(
ID, insertPos);
3889 QualType(), numElements, ASM, elementTypeQuals,
3891 DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
3892 Types.push_back(canonTy);
3897 canonElementType.
Quals);
3901 if (
QualType(canonElementType.
Ty, 0) == elementType &&
3910 ASM, elementTypeQuals, brackets);
3911 Types.push_back(sugaredType);
3917 unsigned elementTypeQuals)
const {
3918 llvm::FoldingSetNodeID
ID;
3921 void *insertPos =
nullptr;
3923 IncompleteArrayTypes.FindNodeOrInsertPos(
ID, insertPos))
3935 ASM, elementTypeQuals);
3940 IncompleteArrayTypes.FindNodeOrInsertPos(
ID, insertPos);
3941 assert(!existing &&
"Shouldn't be in the map!"); (void) existing;
3947 IncompleteArrayTypes.InsertNode(newType, insertPos);
3948 Types.push_back(newType);
3954 #define SVE_INT_ELTTY(BITS, ELTS, SIGNED, NUMVECTORS) \
3955 {getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount::getScalable(ELTS), \
3958 #define SVE_ELTTY(ELTTY, ELTS, NUMVECTORS) \
3959 {ELTTY, llvm::ElementCount::getScalable(ELTS), NUMVECTORS};
3963 llvm_unreachable(
"Unsupported builtin vector type");
3964 case BuiltinType::SveInt8:
3966 case BuiltinType::SveUint8:
3968 case BuiltinType::SveInt8x2:
3970 case BuiltinType::SveUint8x2:
3972 case BuiltinType::SveInt8x3:
3974 case BuiltinType::SveUint8x3:
3976 case BuiltinType::SveInt8x4:
3978 case BuiltinType::SveUint8x4:
3980 case BuiltinType::SveInt16:
3982 case BuiltinType::SveUint16:
3984 case BuiltinType::SveInt16x2:
3986 case BuiltinType::SveUint16x2:
3988 case BuiltinType::SveInt16x3:
3990 case BuiltinType::SveUint16x3:
3992 case BuiltinType::SveInt16x4:
3994 case BuiltinType::SveUint16x4:
3996 case BuiltinType::SveInt32:
3998 case BuiltinType::SveUint32:
4000 case BuiltinType::SveInt32x2:
4002 case BuiltinType::SveUint32x2:
4004 case BuiltinType::SveInt32x3:
4006 case BuiltinType::SveUint32x3:
4008 case BuiltinType::SveInt32x4:
4010 case BuiltinType::SveUint32x4:
4012 case BuiltinType::SveInt64:
4014 case BuiltinType::SveUint64:
4016 case BuiltinType::SveInt64x2:
4018 case BuiltinType::SveUint64x2:
4020 case BuiltinType::SveInt64x3:
4022 case BuiltinType::SveUint64x3:
4024 case BuiltinType::SveInt64x4:
4026 case BuiltinType::SveUint64x4:
4028 case BuiltinType::SveBool:
4030 case BuiltinType::SveFloat16:
4032 case BuiltinType::SveFloat16x2:
4034 case BuiltinType::SveFloat16x3:
4036 case BuiltinType::SveFloat16x4:
4038 case BuiltinType::SveFloat32:
4040 case BuiltinType::SveFloat32x2:
4042 case BuiltinType::SveFloat32x3:
4044 case BuiltinType::SveFloat32x4:
4046 case BuiltinType::SveFloat64:
4048 case BuiltinType::SveFloat64x2:
4050 case BuiltinType::SveFloat64x3:
4052 case BuiltinType::SveFloat64x4:
4054 case BuiltinType::SveBFloat16:
4056 case BuiltinType::SveBFloat16x2:
4058 case BuiltinType::SveBFloat16x3:
4060 case BuiltinType::SveBFloat16x4:
4062 #define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
4064 case BuiltinType::Id: \
4065 return {getIntTypeForBitwidth(ElBits, IsSigned), \
4066 llvm::ElementCount::getScalable(NumEls), NF};
4067 #define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
4068 case BuiltinType::Id: \
4069 return {ElBits == 16 ? Float16Ty : (ElBits == 32 ? FloatTy : DoubleTy), \
4070 llvm::ElementCount::getScalable(NumEls), NF};
4071 #define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4072 case BuiltinType::Id: \
4073 return {BoolTy, llvm::ElementCount::getScalable(NumEls), 1};
4074 #include "clang/Basic/RISCVVTypes.def"
4082 unsigned NumElts)
const {
4085 #define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
4086 IsSigned, IsFP, IsBF) \
4087 if (!EltTy->isBooleanType() && \
4088 ((EltTy->hasIntegerRepresentation() && \
4089 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4090 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
4092 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
4093 IsBF && !IsFP)) && \
4094 EltTySize == ElBits && NumElts == NumEls) { \
4095 return SingletonId; \
4097 #define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
4098 if (EltTy->isBooleanType() && NumElts == NumEls) \
4100 #include "clang/Basic/AArch64SVEACLETypes.def"
4103 #define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
4105 if (!EltTy->isBooleanType() && \
4106 ((EltTy->hasIntegerRepresentation() && \
4107 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4108 (EltTy->hasFloatingRepresentation() && IsFP)) && \
4109 EltTySize == ElBits && NumElts == NumEls) \
4111 #define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4112 if (EltTy->isBooleanType() && NumElts == NumEls) \
4114 #include "clang/Basic/RISCVVTypes.def"
4130 llvm::FoldingSetNodeID
ID;
4133 void *InsertPos =
nullptr;
4134 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(
ID, InsertPos))
4144 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4145 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4148 VectorType(vecType, NumElts, Canonical, VecKind);
4149 VectorTypes.InsertNode(New, InsertPos);
4150 Types.push_back(New);
4158 llvm::FoldingSetNodeID
ID;
4161 void *InsertPos =
nullptr;
4163 DependentVectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4168 *
this, VecType,
QualType(Canon, 0), SizeExpr, AttrLoc, VecKind);
4171 if (CanonVecTy == VecType) {
4173 *
this, VecType,
QualType(), SizeExpr, AttrLoc, VecKind);
4176 DependentVectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4177 assert(!CanonCheck &&
4178 "Dependent-sized vector_size canonical type broken");
4180 DependentVectorTypes.InsertNode(New, InsertPos);
4185 *
this, VecType, CanonTy, SizeExpr, AttrLoc, VecKind);
4189 Types.push_back(New);
4196 unsigned NumElts)
const {
4204 llvm::FoldingSetNodeID
ID;
4207 void *InsertPos =
nullptr;
4208 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(
ID, InsertPos))
4218 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4219 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4223 VectorTypes.InsertNode(New, InsertPos);
4224 Types.push_back(New);
4232 llvm::FoldingSetNodeID
ID;
4236 void *InsertPos =
nullptr;
4238 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4248 if (CanonVecTy == vecType) {
4254 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(
ID, InsertPos);
4255 assert(!CanonCheck &&
"Dependent-sized ext_vector canonical type broken");
4257 DependentSizedExtVectorTypes.InsertNode(New, InsertPos);
4262 *
this, vecType, CanonExtTy, SizeExpr, AttrLoc);
4266 Types.push_back(New);
4271 unsigned NumColumns)
const {
4272 llvm::FoldingSetNodeID
ID;
4274 Type::ConstantMatrix);
4277 "need a valid element type");
4280 "need valid matrix dimensions");
4281 void *InsertPos =
nullptr;
4291 assert(!NewIP &&
"Matrix type shouldn't already exist in the map");
4297 MatrixTypes.InsertNode(New, InsertPos);
4298 Types.push_back(New);
4307 llvm::FoldingSetNodeID
ID;
4311 void *InsertPos =
nullptr;
4313 DependentSizedMatrixTypes.FindNodeOrInsertPos(
ID, InsertPos);
4317 *
this, CanonElementTy,
QualType(), RowExpr, ColumnExpr, AttrLoc);
4320 DependentSizedMatrixTypes.FindNodeOrInsertPos(
ID, InsertPos);
4321 assert(!CanonCheck &&
"Dependent-sized matrix canonical type broken");
4323 DependentSizedMatrixTypes.InsertNode(Canon, InsertPos);
4324 Types.push_back(Canon);
4337 ColumnExpr, AttrLoc);
4338 Types.push_back(New);
4343 Expr *AddrSpaceExpr,
4349 void *insertPos =
nullptr;
4350 llvm::FoldingSetNodeID
ID;
4355 DependentAddressSpaceTypes.FindNodeOrInsertPos(
ID, insertPos);
4360 QualType(), AddrSpaceExpr, AttrLoc);
4361 DependentAddressSpaceTypes.InsertNode(canonTy, insertPos);
4362 Types.push_back(canonTy);
4365 if (canonPointeeType == PointeeType &&
4372 AddrSpaceExpr, AttrLoc);
4373 Types.push_back(sugaredType);
4397 llvm::FoldingSetNodeID
ID;
4400 void *InsertPos =
nullptr;
4402 FunctionNoProtoTypes.FindNodeOrInsertPos(
ID, InsertPos))
4412 FunctionNoProtoTypes.FindNodeOrInsertPos(
ID, InsertPos);
4413 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4418 Types.push_back(New);
4419 FunctionNoProtoTypes.InsertNode(New, InsertPos);
4435 return CanResultType;
4442 if (!NoexceptInType)
4459 bool AnyPackExpansions =
false;
4464 AnyPackExpansions =
true;
4466 return AnyPackExpansions;
4472 QualType ASTContext::getFunctionTypeInternal(
4475 size_t NumArgs = ArgArray.size();
4479 llvm::FoldingSetNodeID
ID;
4484 bool Unique =
false;
4486 void *InsertPos =
nullptr;
4488 FunctionProtoTypes.FindNodeOrInsertPos(
ID, InsertPos)) {
4508 bool IsCanonicalExceptionSpec =
4512 bool isCanonical = !Unique && IsCanonicalExceptionSpec &&
4514 for (
unsigned i = 0; i != NumArgs && isCanonical; ++i)
4515 if (!ArgArray[i].isCanonicalAsParam())
4516 isCanonical =
false;
4518 if (OnlyWantCanonical)
4519 assert(isCanonical &&
4520 "given non-canonical parameters constructing canonical type");
4525 if (!isCanonical && Canonical.
isNull()) {
4527 CanonicalArgs.reserve(NumArgs);
4528 for (
unsigned i = 0; i != NumArgs; ++i)
4535 if (IsCanonicalExceptionSpec) {
4537 }
else if (NoexceptInType) {
4550 bool AnyPacks =
false;
4573 llvm_unreachable(
"dependent noexcept is already canonical");
4582 getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI,
true);
4586 FunctionProtoTypes.FindNodeOrInsertPos(
ID, InsertPos);
4587 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4592 auto ESH = FunctionProtoType::getExceptionSpecSize(
4594 size_t Size = FunctionProtoType::totalSizeToAlloc<
4597 FunctionProtoType::ExtParameterInfo,
Qualifiers>(
4599 ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr,
4606 Types.push_back(FTP);
4608 FunctionProtoTypes.InsertNode(FTP, InsertPos);
4613 llvm::FoldingSetNodeID
ID;
4616 void *InsertPos =
nullptr;
4617 if (
PipeType *PT = PipeTypes.FindNodeOrInsertPos(
ID, InsertPos))
4627 PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(
ID, InsertPos);
4628 assert(!NewIP &&
"Shouldn't be in the map!");
4632 Types.push_back(New);
4633 PipeTypes.InsertNode(New, InsertPos);
4644 return getPipeType(T,
true);
4648 return getPipeType(T,
false);
4652 llvm::FoldingSetNodeID
ID;
4655 void *InsertPos =
nullptr;
4656 if (
BitIntType *EIT = BitIntTypes.FindNodeOrInsertPos(
ID, InsertPos))
4660 BitIntTypes.InsertNode(New, InsertPos);
4661 Types.push_back(New);
4666 Expr *NumBitsExpr)
const {
4668 llvm::FoldingSetNodeID
ID;
4671 void *InsertPos =
nullptr;
4673 DependentBitIntTypes.FindNodeOrInsertPos(
ID, InsertPos))
4678 DependentBitIntTypes.InsertNode(New, InsertPos);
4680 Types.push_back(New);
4686 if (!isa<CXXRecordDecl>(D))
return false;
4687 const auto *RD = cast<CXXRecordDecl>(D);
4688 if (isa<ClassTemplatePartialSpecializationDecl>(RD))
4690 if (RD->getDescribedClassTemplate() &&
4691 !isa<ClassTemplateSpecializationDecl>(RD))
4702 if (
Decl->TypeForDecl) {
4703 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4705 assert(PrevDecl->TypeForDecl &&
"previous declaration has no type");
4706 Decl->TypeForDecl = PrevDecl->TypeForDecl;
4707 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4711 Decl->TypeForDecl = newType;
4712 Types.push_back(newType);
4720 assert(
Decl &&
"Passed null for Decl param");
4721 assert(!
Decl->TypeForDecl &&
"TypeForDecl present in slow case");
4723 if (
const auto *Typedef = dyn_cast<TypedefNameDecl>(
Decl))
4726 assert(!isa<TemplateTypeParmDecl>(
Decl) &&
4727 "Template type parameter types are always available.");
4729 if (
const auto *Record = dyn_cast<RecordDecl>(
Decl)) {
4730 assert(Record->isFirstDecl() &&
"struct/union has previous declaration");
4733 }
else if (
const auto *Enum = dyn_cast<EnumDecl>(
Decl)) {
4734 assert(Enum->isFirstDecl() &&
"enum has previous declaration");
4736 }
else if (
const auto *Using = dyn_cast<UnresolvedUsingTypenameDecl>(
Decl)) {
4739 llvm_unreachable(
"TypeDecl without a type?");
4748 if (!
Decl->TypeForDecl) {
4750 Underlying =
Decl->getUnderlyingType();
4753 Decl->TypeForDecl = NewType;
4754 Types.push_back(NewType);
4757 if (Underlying.
isNull() ||
Decl->getUnderlyingType() == Underlying)
4761 llvm::FoldingSetNodeID
ID;
4764 void *InsertPos =
nullptr;
4765 if (
TypedefType *T = TypedefTypes.FindNodeOrInsertPos(
ID, InsertPos)) {
4766 assert(!T->typeMatchesDecl() &&
4767 "non-divergent case should be handled with TypeDecl");
4773 auto *NewType =
new (Mem)
TypedefType(Type::Typedef,
Decl, Underlying,
4775 TypedefTypes.InsertNode(NewType, InsertPos);
4776 Types.push_back(NewType);
4782 llvm::FoldingSetNodeID
ID;
4785 void *InsertPos =
nullptr;
4786 if (
UsingType *T = UsingTypes.FindNodeOrInsertPos(
ID, InsertPos))
4789 const Type *TypeForDecl =
4799 Allocate(UsingType::totalSizeToAlloc<QualType>(!Underlying.
isNull()),
4802 Types.push_back(NewType);
4803 UsingTypes.InsertNode(NewType, InsertPos);
4811 if (PrevDecl->TypeForDecl)
4812 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4815 Decl->TypeForDecl = newType;
4816 Types.push_back(newType);
4824 if (PrevDecl->TypeForDecl)
4825 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4828 Decl->TypeForDecl = newType;
4829 Types.push_back(newType);
4835 if (
Decl->TypeForDecl)
4840 if (CanonicalDecl->TypeForDecl)
4841 return QualType(
Decl->TypeForDecl = CanonicalDecl->TypeForDecl, 0);
4844 Decl->TypeForDecl = newType;
4845 Types.push_back(newType);
4852 llvm::FoldingSetNodeID id;
4855 void *insertPos =
nullptr;
4863 Types.push_back(
type);
4864 AttributedTypes.InsertNode(
type, insertPos);
4871 llvm::FoldingSetNodeID
ID;
4874 void *InsertPos =
nullptr;
4876 BTFTagAttributedTypes.FindNodeOrInsertPos(
ID, InsertPos);
4883 Types.push_back(Ty);
4884 BTFTagAttributedTypes.InsertNode(Ty, InsertPos);
4891 QualType Replacement,
Decl *AssociatedDecl,
unsigned Index,
4892 std::optional<unsigned> PackIndex)
const {
4893 llvm::FoldingSetNodeID
ID;
4896 void *InsertPos =
nullptr;
4898 SubstTemplateTypeParmTypes.FindNodeOrInsertPos(
ID, InsertPos);
4901 void *Mem =
Allocate(SubstTemplateTypeParmType::totalSizeToAlloc<QualType>(
4906 Types.push_back(SubstParm);
4907 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
4916 unsigned Index,
bool Final,
4923 llvm::FoldingSetNodeID
ID;
4926 void *InsertPos =
nullptr;
4928 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(
ID, InsertPos))
4938 [[maybe_unused]]
const auto *Nothing =
4939 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(
ID, InsertPos);
4945 Canon, AssociatedDecl, Index, Final, ArgPack);
4946 Types.push_back(SubstParm);
4947 SubstTemplateTypeParmPackTypes.InsertNode(SubstParm, InsertPos);
4957 llvm::FoldingSetNodeID
ID;
4959 void *InsertPos =
nullptr;
4961 = TemplateTypeParmTypes.FindNodeOrInsertPos(
ID, InsertPos);
4971 = TemplateTypeParmTypes.FindNodeOrInsertPos(
ID, InsertPos);
4972 assert(!TypeCheck &&
"Template type parameter canonical type broken");
4978 Types.push_back(TypeParm);
4979 TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos);
4989 assert(!Name.getAsDependentTemplateName() &&
4990 "No dependent template names here!");
5001 for (
unsigned i = 0, e = TL.
getNumArgs(); i != e; ++i)
5011 "No dependent template names here!");
5014 ArgVec.reserve(Args.size());
5016 ArgVec.push_back(Arg.getArgument());
5024 if (Arg.isPackExpansion())
5036 "No dependent template names here!");
5039 Template = QTN->getUnderlyingTemplate();
5044 if (!Underlying.
isNull())
5050 "Caller must compute aliased type");
5051 IsTypeAlias =
false;
5060 (IsTypeAlias?
sizeof(
QualType) : 0),
5064 IsTypeAlias ? Underlying :
QualType());
5066 Types.push_back(Spec);
5073 "No dependent template names here!");
5081 bool AnyNonCanonArgs =
false;
5087 llvm::FoldingSetNodeID
ID;
5091 void *InsertPos =
nullptr;
5093 = TemplateSpecializationTypes.FindNodeOrInsertPos(
ID, InsertPos);
5103 Types.push_back(Spec);
5104 TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
5108 "Non-dependent template-id type must have a canonical type");
5115 TagDecl *OwnedTagDecl)
const {
5116 llvm::FoldingSetNodeID
ID;
5119 void *InsertPos =
nullptr;
5127 ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(
ID, InsertPos);
5128 assert(!CheckT &&
"Elaborated canonical type broken");
5132 void *Mem =
Allocate(ElaboratedType::totalSizeToAlloc<TagDecl *>(!!OwnedTagDecl),
5134 T =
new (Mem)
ElaboratedType(Keyword, NNS, NamedType, Canon, OwnedTagDecl);
5137 ElaboratedTypes.InsertNode(T, InsertPos);
5143 llvm::FoldingSetNodeID
ID;
5146 void *InsertPos =
nullptr;
5147 ParenType *T = ParenTypes.FindNodeOrInsertPos(
ID, InsertPos);
5154 ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(
ID, InsertPos);
5155 assert(!CheckT &&
"Paren canonical type broken");
5161 ParenTypes.InsertNode(T, InsertPos);
5174 Types.push_back(newType);
5184 if (CanonNNS != NNS)
5188 llvm::FoldingSetNodeID
ID;
5191 void *InsertPos =
nullptr;
5193 = DependentNameTypes.FindNodeOrInsertPos(
ID, InsertPos);
5199 DependentNameTypes.InsertNode(T, InsertPos);
5208 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
5220 "nested-name-specifier must be dependent");
5222 llvm::FoldingSetNodeID
ID;
5226 void *InsertPos =
nullptr;
5228 = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(
ID, InsertPos);
5237 bool AnyNonCanonArgs =
false;
5242 if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) {
5248 [[maybe_unused]]
auto *Nothing =
5249 DependentTemplateSpecializationTypes.FindNodeOrInsertPos(
ID, InsertPos);
5250 assert(!Nothing &&
"canonical type broken");
5259 DependentTemplateSpecializationTypes.InsertNode(T, InsertPos);
5265 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
5271 }
else if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
5273 NTTP->getType().getNonPackExpansionType().getNonLValueExprType(*
this);
5281 *
this, NTTP,
false, T,
5284 if (NTTP->isParameterPack())
5289 auto *TTP = cast<TemplateTemplateParmDecl>(Param);
5305 Args.reserve(Args.size() + Params->
size());
5312 std::optional<unsigned> NumExpansions,
5313 bool ExpectPackInType) {
5315 "Pack expansions must expand one or more parameter packs");
5317 llvm::FoldingSetNodeID
ID;
5320 void *InsertPos =
nullptr;
5332 PackExpansionTypes.FindNodeOrInsertPos(
ID, InsertPos);
5338 PackExpansionTypes.InsertNode(T, InsertPos);
5350 if (Protocols.empty())
return true;
5355 for (
unsigned i = 1; i != Protocols.size(); ++i)
5365 llvm::array_pod_sort(Protocols.begin(), Protocols.end(),
CmpProtocolNames);
5369 P =
P->getCanonicalDecl();
5372 auto ProtocolsEnd = std::unique(Protocols.begin(), Protocols.end());
5373 Protocols.erase(ProtocolsEnd, Protocols.end());
5378 unsigned NumProtocols)
const {
5388 bool isKindOf)
const {
5391 if (typeArgs.empty() && protocols.empty() && !isKindOf &&
5392 isa<ObjCInterfaceType>(baseType))
5396 llvm::FoldingSetNodeID
ID;
5398 void *InsertPos =
nullptr;
5399 if (
ObjCObjectType *QT = ObjCObjectTypes.FindNodeOrInsertPos(
ID, InsertPos))