68#include "llvm/ADT/APFixedPoint.h"
69#include "llvm/ADT/APInt.h"
70#include "llvm/ADT/APSInt.h"
71#include "llvm/ADT/ArrayRef.h"
72#include "llvm/ADT/DenseMap.h"
73#include "llvm/ADT/DenseSet.h"
74#include "llvm/ADT/FoldingSet.h"
75#include "llvm/ADT/PointerUnion.h"
76#include "llvm/ADT/STLExtras.h"
77#include "llvm/ADT/SmallPtrSet.h"
78#include "llvm/ADT/SmallVector.h"
79#include "llvm/ADT/StringExtras.h"
80#include "llvm/ADT/StringRef.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"
89#include "llvm/TargetParser/Triple.h"
102using namespace clang;
126 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
131 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
132 if (VD->isStaticDataMember() &&
137 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(D)) {
142 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
149 if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
153 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
156 if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition())
160 if (isa<ParmVarDecl>(D))
165 if (isa<TemplateTypeParmDecl>(D) ||
166 isa<NonTypeTemplateParmDecl>(D) ||
167 isa<TemplateTemplateParmDecl>(D))
178 if (isa<ObjCMethodDecl>(D) || isa<ObjCContainerDecl>(D) ||
179 isa<ObjCPropertyDecl>(D) || isa<RedeclarableTemplateDecl>(D) ||
180 isa<ClassTemplateSpecializationDecl>(D) ||
188 Locations.emplace_back(BaseLocation);
216 const std::map<unsigned, RawComment *> &CommentsInTheFile)
const {
219 if (RepresentativeLocForDecl.
isInvalid() ||
220 !RepresentativeLocForDecl.
isFileID())
224 if (CommentsInTheFile.empty())
229 const std::pair<FileID, unsigned> DeclLocDecomp =
233 auto OffsetCommentBehindDecl =
234 CommentsInTheFile.lower_bound(DeclLocDecomp.second);
237 if (OffsetCommentBehindDecl != CommentsInTheFile.end()) {
238 RawComment *CommentBehindDecl = OffsetCommentBehindDecl->second;
242 (isa<FieldDecl>(D) || isa<EnumConstantDecl>(D) || isa<VarDecl>(D) ||
243 isa<ObjCMethodDecl>(D) || isa<ObjCPropertyDecl>(D))) {
247 if (SourceMgr.
getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) ==
249 OffsetCommentBehindDecl->first)) {
250 return CommentBehindDecl;
257 if (OffsetCommentBehindDecl == CommentsInTheFile.begin())
260 auto OffsetCommentBeforeDecl = --OffsetCommentBehindDecl;
261 RawComment *CommentBeforeDecl = OffsetCommentBeforeDecl->second;
270 const unsigned CommentEndOffset =
275 const char *Buffer = SourceMgr.
getBufferData(DeclLocDecomp.first,
281 StringRef
Text(Buffer + CommentEndOffset,
282 DeclLocDecomp.second - CommentEndOffset);
286 if (
Text.find_last_of(
";{}#@") != StringRef::npos)
289 return CommentBeforeDecl;
295 for (
const auto DeclLoc : DeclLocs) {
298 if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
314 if (!CommentsInThisFile || CommentsInThisFile->empty())
326 assert(LangOpts.RetainCommentsFromSystemHeaders ||
335 if (
const auto *FD = dyn_cast<FunctionDecl>(&D)) {
355 if (
const auto *VD = dyn_cast<VarDecl>(&D)) {
358 if (VD->isStaticDataMember())
364 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(&D)) {
371 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(CRD)) {
379 : *
static_cast<const Decl *
>(
385 CRD->getMemberSpecializationInfo())
386 return *Info->getInstantiatedFrom();
390 if (
const auto *ED = dyn_cast<EnumDecl>(&D)) {
403 const Decl **OriginalDecl)
const {
406 OriginalDecl =
nullptr;
418 return DeclComment->second;
431 *OriginalDecl = RedeclComment->second;
434 "This decl is supposed to have comment attached.");
435 return CommentAtRedecl->second;
441 auto LastCheckedRedecl = [
this, CanonicalD]() ->
const Decl * {
445 for (
const auto Redecl : D->
redecls()) {
448 if (LastCheckedRedecl) {
449 if (LastCheckedRedecl == Redecl) {
450 LastCheckedRedecl =
nullptr;
458 *OriginalDecl = Redecl;
459 return RedeclComment;
465 *OriginalDecl =
nullptr;
481 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(DC)) {
486 for (
const auto *Ext : ID->known_extensions()) {
490 Redeclared.push_back(RedeclaredMethod);
501 for (
Decl *D : Decls) {
511 if (
File.isInvalid())
515 if (!CommentsInThisFile || CommentsInThisFile->empty() ||
516 CommentsInThisFile->rbegin()->second->isAttached())
526 for (
const Decl *D : Decls) {
528 if (D->isInvalidDecl())
538 for (
const auto DeclLoc : DeclLocs) {
539 if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
543 D, DeclLoc, *CommentsInThisFile)) {
554 const Decl *D)
const {
557 ThisDeclInfo->IsFilled =
false;
558 ThisDeclInfo->fill();
559 ThisDeclInfo->CommentDecl = FC->
getDecl();
560 if (!ThisDeclInfo->TemplateParameters)
570 return RC ? RC->
parse(*
this,
nullptr, D) :
nullptr;
581 llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos =
585 if (Canonical != D) {
593 const Decl *OriginalDecl =
nullptr;
597 if (isa<ObjCMethodDecl>(D) || isa<FunctionDecl>(D)) {
599 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
600 if (OMD && OMD->isPropertyAccessor())
607 for (
unsigned i = 0, e = Overridden.size(); i < e; i++)
611 else if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
614 QualType QT = TD->getUnderlyingType();
616 if (
const Decl *TD = TT->getDecl())
620 else if (
const auto *IC = dyn_cast<ObjCInterfaceDecl>(D)) {
621 while (IC->getSuperClass()) {
622 IC = IC->getSuperClass();
627 else if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(D)) {
632 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
633 if (!(RD = RD->getDefinition()))
636 for (
const auto &I : RD->bases()) {
637 if (I.isVirtual() || (I.getAccessSpecifier() !=
AS_public))
651 for (
const auto &I : RD->vbases()) {
672 if (D != OriginalDecl && OriginalDecl)
681ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID,
689 ID.AddInteger(Params->
size());
691 PEnd = Params->
end();
693 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
695 ID.AddBoolean(TTP->isParameterPack());
696 if (TTP->isExpandedParameterPack()) {
698 ID.AddInteger(TTP->getNumExpansionParameters());
700 ID.AddBoolean(
false);
704 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
706 ID.AddBoolean(NTTP->isParameterPack());
707 ID.AddPointer(
C.getUnconstrainedType(
C.getCanonicalType(NTTP->getType()))
709 if (NTTP->isExpandedParameterPack()) {
711 ID.AddInteger(NTTP->getNumExpansionTypes());
712 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
713 QualType T = NTTP->getExpansionType(I);
717 ID.AddBoolean(
false);
721 auto *TTP = cast<TemplateTemplateParmDecl>(*
P);
728ASTContext::getCanonicalTemplateTemplateParmDecl(
731 llvm::FoldingSetNodeID
ID;
732 CanonicalTemplateTemplateParm::Profile(ID, *
this, TTP);
733 void *InsertPos =
nullptr;
734 CanonicalTemplateTemplateParm *Canonical
735 = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
737 return Canonical->getParam();
742 CanonParams.reserve(Params->
size());
744 PEnd = Params->
end();
748 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
754 ? std::optional<unsigned>(TTP->getNumExpansionParameters())
756 CanonParams.push_back(NewTTP);
757 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
761 if (NTTP->isExpandedParameterPack()) {
764 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
766 ExpandedTInfos.push_back(
774 NTTP->getPosition(),
nullptr,
784 NTTP->getPosition(),
nullptr,
786 NTTP->isParameterPack(),
789 CanonParams.push_back(Param);
791 CanonParams.push_back(getCanonicalTemplateTemplateParmDecl(
792 cast<TemplateTemplateParmDecl>(*
P)));
803 Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
804 assert(!Canonical &&
"Shouldn't be in the map!");
808 Canonical =
new (*this) CanonicalTemplateTemplateParm(CanonTTP);
809 CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos);
819 if (!LangOpts.CPlusPlus)
return nullptr;
822 case TargetCXXABI::AppleARM64:
823 case TargetCXXABI::Fuchsia:
824 case TargetCXXABI::GenericARM:
825 case TargetCXXABI::iOS:
826 case TargetCXXABI::WatchOS:
827 case TargetCXXABI::GenericAArch64:
828 case TargetCXXABI::GenericMIPS:
829 case TargetCXXABI::GenericItanium:
830 case TargetCXXABI::WebAssembly:
831 case TargetCXXABI::XL:
833 case TargetCXXABI::Microsoft:
836 llvm_unreachable(
"Invalid CXXABI type!");
840 if (!InterpContext) {
843 return *InterpContext.get();
849 return *ParentMapCtx.get();
854 switch (LangOpts.getAddressSpaceMapMangling()) {
862 llvm_unreachable(
"getAddressSpaceMapMangling() doesn't cover anything.");
868 : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize),
869 DependentSizedArrayTypes(this_()), DependentSizedExtVectorTypes(this_()),
870 DependentAddressSpaceTypes(this_()), DependentVectorTypes(this_()),
871 DependentSizedMatrixTypes(this_()),
872 FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize),
873 DependentTypeOfExprTypes(this_()), DependentDecltypeTypes(this_()),
874 TemplateSpecializationTypes(this_()),
875 DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
876 DependentBitIntTypes(this_()), SubstTemplateTemplateParmPacks(this_()),
877 CanonTemplateTemplateParms(this_()), SourceMgr(
SM), LangOpts(LOpts),
880 LangOpts.XRayNeverInstrumentFiles,
881 LangOpts.XRayAttrListFiles,
SM)),
884 BuiltinInfo(builtins), TUKind(TUKind), DeclarationNames(*this),
885 Comments(
SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
886 CompCategories(this_()), LastSDM(nullptr, 0) {
893 ReleaseDeclContextMaps();
896 for (
auto &Pair : Deallocations)
897 (Pair.first)(Pair.second);
898 Deallocations.clear();
904 I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; )
910 for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
911 I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
916 ASTRecordLayouts.clear();
918 for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(),
919 AEnd = DeclAttrs.end();
921 A->second->~AttrVec();
924 for (
const auto &
Value : ModuleInitializers)
925 Value.second->~PerModuleInitializers();
926 ModuleInitializers.
clear();
932 TraversalScope = TopLevelDecls;
937 Deallocations.push_back({Callback,
Data});
946 llvm::errs() <<
"\n*** AST Context Stats:\n";
947 llvm::errs() <<
" " << Types.size() <<
" types total.\n";
949 unsigned counts[] = {
950#define TYPE(Name, Parent) 0,
951#define ABSTRACT_TYPE(Name, Parent)
952#include "clang/AST/TypeNodes.inc"
956 for (
unsigned i = 0, e = Types.size(); i != e; ++i) {
962 unsigned TotalBytes = 0;
963#define TYPE(Name, Parent) \
965 llvm::errs() << " " << counts[Idx] << " " << #Name \
966 << " types, " << sizeof(Name##Type) << " each " \
967 << "(" << counts[Idx] * sizeof(Name##Type) \
969 TotalBytes += counts[Idx] * sizeof(Name##Type); \
971#define ABSTRACT_TYPE(Name, Parent)
972#include "clang/AST/TypeNodes.inc"
974 llvm::errs() <<
"Total bytes = " << TotalBytes <<
"\n";
979 <<
" implicit default constructors created\n";
982 <<
" implicit copy constructors created\n";
986 <<
" implicit move constructors created\n";
989 <<
" implicit copy assignment operators created\n";
993 <<
" implicit move assignment operators created\n";
996 <<
" implicit destructors created\n";
999 llvm::errs() <<
"\n";
1003 BumpAlloc.PrintStats();
1007 bool NotifyListeners) {
1008 if (NotifyListeners)
1017 if (It == MergedDefModules.end())
1020 auto &Merged = It->second;
1022 for (
Module *&M : Merged)
1023 if (!Found.insert(M).second)
1025 llvm::erase(Merged,
nullptr);
1032 if (MergedIt == MergedDefModules.end())
1033 return std::nullopt;
1034 return MergedIt->second;
1037void ASTContext::PerModuleInitializers::resolve(
ASTContext &Ctx) {
1038 if (LazyInitializers.empty())
1042 assert(Source &&
"lazy initializers but no external source");
1044 auto LazyInits = std::move(LazyInitializers);
1045 LazyInitializers.clear();
1047 for (
auto ID : LazyInits)
1048 Initializers.push_back(Source->GetExternalDecl(ID));
1050 assert(LazyInitializers.empty() &&
1051 "GetExternalDecl for lazy module initializer added more inits");
1057 if (
const auto *ID = dyn_cast<ImportDecl>(D)) {
1058 auto It = ModuleInitializers.find(ID->getImportedModule());
1061 if (It == ModuleInitializers.end())
1065 auto &Imported = *It->second;
1066 if (Imported.Initializers.size() + Imported.LazyInitializers.size() == 1) {
1067 Imported.resolve(*
this);
1068 auto *OnlyDecl = Imported.Initializers.front();
1069 if (isa<ImportDecl>(OnlyDecl))
1074 auto *&Inits = ModuleInitializers[M];
1076 Inits =
new (*this) PerModuleInitializers;
1077 Inits->Initializers.push_back(D);
1081 auto *&Inits = ModuleInitializers[M];
1083 Inits =
new (*this) PerModuleInitializers;
1084 Inits->LazyInitializers.insert(Inits->LazyInitializers.end(),
1085 IDs.begin(), IDs.end());
1089 auto It = ModuleInitializers.find(M);
1090 if (It == ModuleInitializers.end())
1091 return std::nullopt;
1093 auto *Inits = It->second;
1094 Inits->resolve(*
this);
1095 return Inits->Initializers;
1100 assert(!CurrentCXXNamedModule &&
1101 "We should set named module for ASTContext for only once");
1102 CurrentCXXNamedModule = M;
1106 if (!ExternCContext)
1109 return ExternCContext;
1115 auto *BuiltinTemplate =
1117 BuiltinTemplate->setImplicit();
1120 return BuiltinTemplate;
1125 if (!MakeIntegerSeqDecl)
1128 return MakeIntegerSeqDecl;
1133 if (!TypePackElementDecl)
1136 return TypePackElementDecl;
1150 NewDecl->
addAttr(TypeVisibilityAttr::CreateImplicit(
1151 const_cast<ASTContext &
>(*
this), TypeVisibilityAttr::Default));
1156 StringRef Name)
const {
1180 Types.push_back(Ty);
1185 assert((!this->Target || this->Target == &
Target) &&
1186 "Incorrect target reinitialization");
1190 this->AuxTarget = AuxTarget;
1192 ABI.reset(createCXXABI(
Target));
1196 InitBuiltinType(
VoidTy, BuiltinType::Void);
1199 InitBuiltinType(
BoolTy, BuiltinType::Bool);
1201 if (LangOpts.CharIsSigned)
1202 InitBuiltinType(
CharTy, BuiltinType::Char_S);
1204 InitBuiltinType(
CharTy, BuiltinType::Char_U);
1207 InitBuiltinType(
ShortTy, BuiltinType::Short);
1208 InitBuiltinType(
IntTy, BuiltinType::Int);
1209 InitBuiltinType(
LongTy, BuiltinType::Long);
1210 InitBuiltinType(
LongLongTy, BuiltinType::LongLong);
1220 InitBuiltinType(
FloatTy, BuiltinType::Float);
1221 InitBuiltinType(
DoubleTy, BuiltinType::Double);
1222 InitBuiltinType(
LongDoubleTy, BuiltinType::LongDouble);
1225 InitBuiltinType(
Float128Ty, BuiltinType::Float128);
1228 InitBuiltinType(
Ibm128Ty, BuiltinType::Ibm128);
1231 InitBuiltinType(
Float16Ty, BuiltinType::Float16);
1234 InitBuiltinType(
ShortAccumTy, BuiltinType::ShortAccum);
1235 InitBuiltinType(
AccumTy, BuiltinType::Accum);
1236 InitBuiltinType(
LongAccumTy, BuiltinType::LongAccum);
1240 InitBuiltinType(
ShortFractTy, BuiltinType::ShortFract);
1241 InitBuiltinType(
FractTy, BuiltinType::Fract);
1242 InitBuiltinType(
LongFractTy, BuiltinType::LongFract);
1247 InitBuiltinType(
SatAccumTy, BuiltinType::SatAccum);
1253 InitBuiltinType(
SatFractTy, BuiltinType::SatFract);
1260 InitBuiltinType(
Int128Ty, BuiltinType::Int128);
1265 InitBuiltinType(
WCharTy, BuiltinType::WChar_S);
1267 InitBuiltinType(
WCharTy, BuiltinType::WChar_U);
1268 if (LangOpts.CPlusPlus && LangOpts.WChar)
1278 InitBuiltinType(
Char8Ty, BuiltinType::Char8);
1280 if (LangOpts.CPlusPlus)
1281 InitBuiltinType(
Char16Ty, BuiltinType::Char16);
1285 if (LangOpts.CPlusPlus)
1286 InitBuiltinType(
Char32Ty, BuiltinType::Char32);
1295 InitBuiltinType(
DependentTy, BuiltinType::Dependent);
1298 InitBuiltinType(
OverloadTy, BuiltinType::Overload);
1307 InitBuiltinType(
UnknownAnyTy, BuiltinType::UnknownAny);
1313 InitBuiltinType(
BuiltinFnTy, BuiltinType::BuiltinFn);
1316 if (LangOpts.OpenMP) {
1321 if (LangOpts.MatrixTypes)
1329 if (LangOpts.OpenCL) {
1330#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1331 InitBuiltinType(SingletonId, BuiltinType::Id);
1332#include "clang/Basic/OpenCLImageTypes.def"
1334 InitBuiltinType(
OCLSamplerTy, BuiltinType::OCLSampler);
1335 InitBuiltinType(
OCLEventTy, BuiltinType::OCLEvent);
1337 InitBuiltinType(
OCLQueueTy, BuiltinType::OCLQueue);
1340#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1341 InitBuiltinType(Id##Ty, BuiltinType::Id);
1342#include "clang/Basic/OpenCLExtensionTypes.def"
1345 if (
Target.hasAArch64SVETypes()) {
1346#define SVE_TYPE(Name, Id, SingletonId) \
1347 InitBuiltinType(SingletonId, BuiltinType::Id);
1348#include "clang/Basic/AArch64SVEACLETypes.def"
1351 if (
Target.getTriple().isPPC64()) {
1352#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
1353 InitBuiltinType(Id##Ty, BuiltinType::Id);
1354#include "clang/Basic/PPCTypes.def"
1355#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
1356 InitBuiltinType(Id##Ty, BuiltinType::Id);
1357#include "clang/Basic/PPCTypes.def"
1360 if (
Target.hasRISCVVTypes()) {
1361#define RVV_TYPE(Name, Id, SingletonId) \
1362 InitBuiltinType(SingletonId, BuiltinType::Id);
1363#include "clang/Basic/RISCVVTypes.def"
1366 if (
Target.getTriple().isWasm() &&
Target.hasFeature(
"reference-types")) {
1367#define WASM_TYPE(Name, Id, SingletonId) \
1368 InitBuiltinType(SingletonId, BuiltinType::Id);
1369#include "clang/Basic/WebAssemblyReferenceTypes.def"
1376 ObjCConstantStringType =
QualType();
1381 if (LangOpts.OpenCLGenericAddressSpace) {
1391 InitBuiltinType(
NullPtrTy, BuiltinType::NullPtr);
1394 InitBuiltinType(
HalfTy, BuiltinType::Half);
1396 InitBuiltinType(
BFloat16Ty, BuiltinType::BFloat16);
1402 if (LangOpts.MicrosoftExt || LangOpts.Borland) {
1424 llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D);
1425 if (Pos != DeclAttrs.end()) {
1426 Pos->second->~AttrVec();
1427 DeclAttrs.erase(Pos);
1441 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>::iterator Pos =
1442 TemplateOrInstantiation.find(Var);
1443 if (Pos == TemplateOrInstantiation.end())
1456 Tmpl, TSK, PointOfInstantiation));
1462 assert(!TemplateOrInstantiation[Inst] &&
1463 "Already noted what the variable was instantiated from");
1464 TemplateOrInstantiation[Inst] = TSI;
1469 return InstantiatedFromUsingDecl.lookup(UUD);
1474 assert((isa<UsingDecl>(Pattern) ||
1475 isa<UnresolvedUsingValueDecl>(Pattern) ||
1476 isa<UnresolvedUsingTypenameDecl>(Pattern)) &&
1477 "pattern decl is not a using decl");
1478 assert((isa<UsingDecl>(Inst) ||
1479 isa<UnresolvedUsingValueDecl>(Inst) ||
1480 isa<UnresolvedUsingTypenameDecl>(Inst)) &&
1481 "instantiation did not produce a using decl");
1482 assert(!InstantiatedFromUsingDecl[Inst] &&
"pattern already exists");
1483 InstantiatedFromUsingDecl[Inst] = Pattern;
1488 return InstantiatedFromUsingEnumDecl.lookup(UUD);
1493 assert(!InstantiatedFromUsingEnumDecl[Inst] &&
"pattern already exists");
1494 InstantiatedFromUsingEnumDecl[Inst] = Pattern;
1499 return InstantiatedFromUsingShadowDecl.lookup(Inst);
1505 assert(!InstantiatedFromUsingShadowDecl[Inst] &&
"pattern already exists");
1506 InstantiatedFromUsingShadowDecl[Inst] = Pattern;
1510 return InstantiatedFromUnnamedFieldDecl.lookup(Field);
1515 assert(!Inst->
getDeclName() &&
"Instantiated field decl is not unnamed");
1516 assert(!Tmpl->
getDeclName() &&
"Template field decl is not unnamed");
1517 assert(!InstantiatedFromUnnamedFieldDecl[Inst] &&
1518 "Already noted what unnamed field was instantiated from");
1520 InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl;
1536 return Range.end() - Range.begin();
1541 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos =
1543 if (Pos == OverriddenMethods.end())
1551 OverriddenMethods[Method].push_back(Overridden);
1559 if (
const auto *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
1565 const auto *Method = dyn_cast<ObjCMethodDecl>(D);
1570 Method->getOverriddenMethods(OverDecls);
1571 Overridden.append(OverDecls.begin(), OverDecls.end());
1575 assert(!Import->getNextLocalImport() &&
1576 "Import declaration already in the chain");
1577 assert(!Import->isFromASTFile() &&
"Non-local import declaration");
1578 if (!FirstLocalImport) {
1579 FirstLocalImport = Import;
1580 LastLocalImport = Import;
1584 LastLocalImport->setNextLocalImport(Import);
1585 LastLocalImport = Import;
1597 llvm_unreachable(
"Not a floating point type!");
1598 case BuiltinType::BFloat16:
1600 case BuiltinType::Float16:
1602 case BuiltinType::Half:
1614 case BuiltinType::Ibm128:
1616 case BuiltinType::LongDouble:
1620 case BuiltinType::Float128:
1632 Align = AlignFromAttr;
1640 bool UseAlignAttrOnly;
1641 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(D))
1643 FD->hasAttr<PackedAttr>() || FD->getParent()->hasAttr<PackedAttr>();
1645 UseAlignAttrOnly = AlignFromAttr != 0;
1648 if (UseAlignAttrOnly) {
1650 }
else if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
1666 if (!ForAlignof && MinWidth) {
1669 else if (isa<ConstantArrayType>(
arrayType) &&
1680 if (
const auto *VD = dyn_cast<VarDecl>(D))
1681 if (VD->hasGlobalStorage() && !ForAlignof) {
1684 Align = std::max(Align,
getTargetInfo().getMinGlobalAlign(TypeSize));
1692 if (
const auto *Field = dyn_cast<FieldDecl>(VD)) {
1695 if (!
Parent->isInvalidDecl()) {
1706 uint64_t LowBitOfOffset = Offset & (~Offset + 1);
1707 if (LowBitOfOffset < FieldAlign)
1708 FieldAlign =
static_cast<unsigned>(LowBitOfOffset);
1711 Align = std::min(Align, FieldAlign);
1719 const auto *VD = dyn_cast<VarDecl>(D);
1720 if (MaxAlignedAttr && VD && VD->getStorageClass() ==
SC_Static)
1721 Align = std::min(Align, MaxAlignedAttr);
1756 uint64_t Size = CAT->
getSize().getZExtValue();
1758 (uint64_t)(-1)/Size) &&
1759 "Overflow in array type char size evaluation");
1764 Width = llvm::alignTo(Width, Align);
1771 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
1789 switch (BT->getKind()) {
1790 case BuiltinType::Bool:
1791 case BuiltinType::Char_S:
1792 case BuiltinType::Char_U:
1793 case BuiltinType::SChar:
1794 case BuiltinType::UChar:
1795 case BuiltinType::Short:
1796 case BuiltinType::UShort:
1797 case BuiltinType::WChar_S:
1798 case BuiltinType::WChar_U:
1799 case BuiltinType::Char8:
1800 case BuiltinType::Char16:
1801 case BuiltinType::Char32:
1810 if (T->
isDependentType() || ET->getDecl()->getPromotionType().isNull() ||
1811 ET->getDecl()->isScoped())
1829 bool NeedsPreferredAlignment)
const {
1832 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1843 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1848 return TT->getDecl()->getMaxAlignment();
1854 TypeInfoMap::iterator I = MemoizedTypeInfo.find(T);
1855 if (I != MemoizedTypeInfo.end())
1860 MemoizedTypeInfo[T] = TI;
1870TypeInfo ASTContext::getTypeInfoImpl(
const Type *T)
const {
1876#define TYPE(Class, Base)
1877#define ABSTRACT_TYPE(Class, Base)
1878#define NON_CANONICAL_TYPE(Class, Base)
1879#define DEPENDENT_TYPE(Class, Base) case Type::Class:
1880#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) \
1882 assert(!T->isDependentType() && "should not see dependent types here"); \
1883 return getTypeInfo(cast<Class##Type>(T)->desugar().getTypePtr());
1884#include "clang/AST/TypeNodes.inc"
1885 llvm_unreachable(
"Should not see dependent types");
1887 case Type::FunctionNoProto:
1888 case Type::FunctionProto:
1894 case Type::IncompleteArray:
1895 case Type::VariableArray:
1896 case Type::ConstantArray: {
1899 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
1900 Size = CAT->getSize().getZExtValue();
1903 assert((Size == 0 || EltInfo.
Width <= (uint64_t)(-1) / Size) &&
1904 "Overflow in array type bit size evaluation");
1905 Width = EltInfo.
Width * Size;
1906 Align = EltInfo.
Align;
1910 Width = llvm::alignTo(Width, Align);
1914 case Type::ExtVector:
1915 case Type::Vector: {
1916 const auto *VT = cast<VectorType>(T);
1918 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
1919 : EltInfo.
Width * VT->getNumElements();
1921 Width = std::max<unsigned>(8, Width);
1922 Align = std::max<unsigned>(8, Width);
1926 if (Align & (Align-1)) {
1927 Align = llvm::bit_ceil(Align);
1928 Width = llvm::alignTo(Width, Align);
1932 if (TargetVectorAlign && TargetVectorAlign < Align)
1933 Align = TargetVectorAlign;
1943 Align = std::min<unsigned>(64, Width);
1947 case Type::ConstantMatrix: {
1948 const auto *MT = cast<ConstantMatrixType>(T);
1953 Width = ElementInfo.
Width * MT->getNumRows() * MT->getNumColumns();
1954 Align = ElementInfo.
Align;
1959 switch (cast<BuiltinType>(T)->
getKind()) {
1960 default: llvm_unreachable(
"Unknown builtin type!");
1961 case BuiltinType::Void:
1966 case BuiltinType::Bool:
1970 case BuiltinType::Char_S:
1971 case BuiltinType::Char_U:
1972 case BuiltinType::UChar:
1973 case BuiltinType::SChar:
1974 case BuiltinType::Char8:
1978 case BuiltinType::WChar_S:
1979 case BuiltinType::WChar_U:
1983 case BuiltinType::Char16:
1987 case BuiltinType::Char32:
1991 case BuiltinType::UShort:
1992 case BuiltinType::Short:
1996 case BuiltinType::UInt:
1997 case BuiltinType::Int:
2001 case BuiltinType::ULong:
2002 case BuiltinType::Long:
2006 case BuiltinType::ULongLong:
2007 case BuiltinType::LongLong:
2011 case BuiltinType::Int128:
2012 case BuiltinType::UInt128:
2016 case BuiltinType::ShortAccum:
2017 case BuiltinType::UShortAccum:
2018 case BuiltinType::SatShortAccum:
2019 case BuiltinType::SatUShortAccum:
2023 case BuiltinType::Accum:
2024 case BuiltinType::UAccum:
2025 case BuiltinType::SatAccum:
2026 case BuiltinType::SatUAccum:
2030 case BuiltinType::LongAccum:
2031 case BuiltinType::ULongAccum:
2032 case BuiltinType::SatLongAccum:
2033 case BuiltinType::SatULongAccum:
2037 case BuiltinType::ShortFract:
2038 case BuiltinType::UShortFract:
2039 case BuiltinType::SatShortFract:
2040 case BuiltinType::SatUShortFract:
2044 case BuiltinType::Fract:
2045 case BuiltinType::UFract:
2046 case BuiltinType::SatFract:
2047 case BuiltinType::SatUFract:
2051 case BuiltinType::LongFract:
2052 case BuiltinType::ULongFract:
2053 case BuiltinType::SatLongFract:
2054 case BuiltinType::SatULongFract:
2058 case BuiltinType::BFloat16:
2070 case BuiltinType::Float16:
2071 case BuiltinType::Half:
2078 "Expected OpenMP device compilation.");
2083 case BuiltinType::Float:
2087 case BuiltinType::Double:
2091 case BuiltinType::Ibm128:
2095 case BuiltinType::LongDouble:
2106 case BuiltinType::Float128:
2113 "Expected OpenMP device compilation.");
2118 case BuiltinType::NullPtr:
2123 case BuiltinType::ObjCId:
2124 case BuiltinType::ObjCClass:
2125 case BuiltinType::ObjCSel:
2129 case BuiltinType::OCLSampler:
2130 case BuiltinType::OCLEvent:
2131 case BuiltinType::OCLClkEvent:
2132 case BuiltinType::OCLQueue:
2133 case BuiltinType::OCLReserveID:
2134#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2135 case BuiltinType::Id:
2136#include "clang/Basic/OpenCLImageTypes.def"
2137#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2138 case BuiltinType::Id:
2139#include "clang/Basic/OpenCLExtensionTypes.def"
2152#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
2153 IsSigned, IsFP, IsBF) \
2154 case BuiltinType::Id: \
2158#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
2159 case BuiltinType::Id: \
2163#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
2164 case BuiltinType::Id: \
2168#include "clang/Basic/AArch64SVEACLETypes.def"
2169#define PPC_VECTOR_TYPE(Name, Id, Size) \
2170 case BuiltinType::Id: \
2174#include "clang/Basic/PPCTypes.def"
2175#define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, NF, IsSigned, \
2177 case BuiltinType::Id: \
2181#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, ElKind) \
2182 case BuiltinType::Id: \
2186#include "clang/Basic/RISCVVTypes.def"
2187#define WASM_TYPE(Name, Id, SingletonId) \
2188 case BuiltinType::Id: \
2192#include "clang/Basic/WebAssemblyReferenceTypes.def"
2195 case Type::ObjCObjectPointer:
2199 case Type::BlockPointer:
2200 AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace();
2204 case Type::LValueReference:
2205 case Type::RValueReference:
2208 AS = cast<ReferenceType>(T)->getPointeeType().getAddressSpace();
2213 AS = cast<PointerType>(T)->getPointeeType().getAddressSpace();
2217 case Type::MemberPointer: {
2218 const auto *MPT = cast<MemberPointerType>(T);
2224 case Type::Complex: {
2228 Width = EltInfo.
Width * 2;
2229 Align = EltInfo.
Align;
2232 case Type::ObjCObject:
2233 return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr());
2234 case Type::Adjusted:
2237 case Type::ObjCInterface: {
2238 const auto *ObjCI = cast<ObjCInterfaceType>(T);
2239 if (ObjCI->getDecl()->isInvalidDecl()) {
2249 case Type::BitInt: {
2250 const auto *EIT = cast<BitIntType>(T);
2251 Align = std::clamp<unsigned>(llvm::PowerOf2Ceil(EIT->getNumBits()),
2253 Width = llvm::alignTo(EIT->getNumBits(), Align);
2258 const auto *TT = cast<TagType>(T);
2260 if (TT->getDecl()->isInvalidDecl()) {
2266 if (
const auto *ET = dyn_cast<EnumType>(TT)) {
2267 const EnumDecl *ED = ET->getDecl();
2271 Info.
Align = AttrAlign;
2277 const auto *RT = cast<RecordType>(TT);
2282 AlignRequirement = RD->
hasAttr<AlignedAttr>()
2288 case Type::SubstTemplateTypeParm:
2289 return getTypeInfo(cast<SubstTemplateTypeParmType>(T)->
2290 getReplacementType().getTypePtr());
2293 case Type::DeducedTemplateSpecialization: {
2294 const auto *A = cast<DeducedType>(T);
2295 assert(!A->getDeducedType().isNull() &&
2296 "cannot request the size of an undeduced or dependent auto type");
2297 return getTypeInfo(A->getDeducedType().getTypePtr());
2301 return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr());
2303 case Type::MacroQualified:
2307 case Type::ObjCTypeParam:
2308 return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr());
2311 return getTypeInfo(cast<UsingType>(T)->desugar().getTypePtr());
2313 case Type::Typedef: {
2314 const auto *TT = cast<TypedefType>(T);
2319 if (
unsigned AttrAlign = TT->getDecl()->getMaxAlignment()) {
2330 case Type::Elaborated:
2331 return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr());
2333 case Type::Attributed:
2335 cast<AttributedType>(T)->getEquivalentType().getTypePtr());
2337 case Type::BTFTagAttributed:
2339 cast<BTFTagAttributedType>(T)->getWrappedType().getTypePtr());
2341 case Type::Atomic: {
2352 }
else if (Width <= Target->getMaxAtomicPromoteWidth()) {
2358 Width = llvm::bit_ceil(Width);
2361 Align =
static_cast<unsigned>(Width);
2372 assert(llvm::isPowerOf2_32(Align) &&
"Alignment must be power of 2");
2373 return TypeInfo(Width, Align, AlignRequirement);
2377 UnadjustedAlignMap::iterator I = MemoizedUnadjustedAlign.find(T);
2378 if (I != MemoizedUnadjustedAlign.end())
2381 unsigned UnadjustedAlign;
2393 MemoizedUnadjustedAlign[T] = UnadjustedAlign;
2394 return UnadjustedAlign;
2398 unsigned SimdAlign = llvm::OpenMPIRBuilder::getOpenMPDefaultSimdAlign(
2448 unsigned ABIAlign = TI.
Align;
2470 unsigned PreferredAlign =
static_cast<unsigned>(
2472 assert(PreferredAlign >= ABIAlign &&
2473 "PreferredAlign should be at least as large as ABIAlign.");
2474 return PreferredAlign;
2481 T = CT->getElementType().getTypePtr();
2483 T = ET->getDecl()->getIntegerType().getTypePtr();
2492 return std::max(ABIAlign, (
unsigned)
getTypeSize(T));
2534 for (
unsigned I = 0, N = Path.size(); I != N; ++I) {
2538 std::swap(
Base, Derived);
2558 llvm::append_range(Ivars, OI->
ivars());
2561 for (
const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
2563 Ivars.push_back(Iv);
2571 if (
const auto *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
2574 for (
auto *Proto : OI->all_referenced_protocols()) {
2579 for (
const auto *Cat : OI->visible_categories())
2585 SD = SD->getSuperClass();
2587 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) {
2588 for (
auto *Proto : OC->protocols()) {
2591 }
else if (
const auto *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) {
2593 if (!Protocols.insert(
2597 for (
auto *Proto : OP->protocols())
2604 bool CheckIfTriviallyCopyable) {
2605 assert(RD->
isUnion() &&
"Must be union type");
2608 for (
const auto *Field : RD->
fields()) {
2610 CheckIfTriviallyCopyable))
2613 if (FieldSize != UnionSize)
2631static std::optional<int64_t>
2634 bool CheckIfTriviallyCopyable);
2636static std::optional<int64_t>
2638 bool CheckIfTriviallyCopyable) {
2639 if (Field->getType()->isRecordType()) {
2640 const RecordDecl *RD = Field->getType()->getAsRecordDecl();
2643 CheckIfTriviallyCopyable);
2648 bool IsBitIntType = Field->getType()->isBitIntType();
2649 if (!Field->getType()->isReferenceType() && !IsBitIntType &&
2651 CheckIfTriviallyCopyable))
2652 return std::nullopt;
2654 int64_t FieldSizeInBits =
2656 if (Field->isBitField()) {
2659 if (Field->isUnnamedBitfield())
2662 int64_t BitfieldSize = Field->getBitWidthValue(Context);
2664 if ((
unsigned)BitfieldSize >
2665 cast<BitIntType>(Field->getType())->getNumBits())
2666 return std::nullopt;
2667 }
else if (BitfieldSize > FieldSizeInBits) {
2668 return std::nullopt;
2670 FieldSizeInBits = BitfieldSize;
2672 Field->getType(), CheckIfTriviallyCopyable)) {
2673 return std::nullopt;
2675 return FieldSizeInBits;
2678static std::optional<int64_t>
2680 bool CheckIfTriviallyCopyable) {
2682 CheckIfTriviallyCopyable);
2685template <
typename RangeT>
2687 const RangeT &Subobjects, int64_t CurOffsetInBits,
2689 bool CheckIfTriviallyCopyable) {
2690 for (
const auto *Subobject : Subobjects) {
2691 std::optional<int64_t> SizeInBits =
2694 return std::nullopt;
2695 if (*SizeInBits != 0) {
2697 if (Offset != CurOffsetInBits)
2698 return std::nullopt;
2699 CurOffsetInBits += *SizeInBits;
2702 return CurOffsetInBits;
2705static std::optional<int64_t>
2708 bool CheckIfTriviallyCopyable) {
2709 assert(!RD->
isUnion() &&
"Must be struct/class type");
2712 int64_t CurOffsetInBits = 0;
2713 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
2714 if (ClassDecl->isDynamicClass())
2715 return std::nullopt;
2718 for (
const auto &
Base : ClassDecl->bases()) {
2721 Bases.emplace_back(
Base.getType()->getAsCXXRecordDecl());
2725 return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
2728 std::optional<int64_t> OffsetAfterBases =
2730 Bases, CurOffsetInBits, Context, Layout, CheckIfTriviallyCopyable);
2731 if (!OffsetAfterBases)
2732 return std::nullopt;
2733 CurOffsetInBits = *OffsetAfterBases;
2736 std::optional<int64_t> OffsetAfterFields =
2738 RD->
fields(), CurOffsetInBits, Context, Layout,
2739 CheckIfTriviallyCopyable);
2740 if (!OffsetAfterFields)
2741 return std::nullopt;
2742 CurOffsetInBits = *OffsetAfterFields;
2744 return CurOffsetInBits;
2748 QualType Ty,
bool CheckIfTriviallyCopyable)
const {
2766 assert(!Ty.
isNull() &&
"Null QualType sent to unique object rep check");
2771 CheckIfTriviallyCopyable);
2791 return !ABI->getMemberPointerInfo(MPT).HasPadding;
2796 if (Record->isInvalidDecl())
2799 if (Record->isUnion())
2801 CheckIfTriviallyCopyable);
2804 *
this, Record, CheckIfTriviallyCopyable);
2806 return StructSize && *StructSize ==
static_cast<int64_t
>(
getTypeSize(Ty));
2827 count += Ext->ivar_size();
2832 count += ImplDecl->ivar_size();
2850 if (isa<GNUNullExpr>(E))
return true;
2858 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2859 I = ObjCImpls.find(D);
2860 if (I != ObjCImpls.end())
2861 return cast<ObjCImplementationDecl>(I->second);
2868 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2869 I = ObjCImpls.find(D);
2870 if (I != ObjCImpls.end())
2871 return cast<ObjCCategoryImplDecl>(I->second);
2878 assert(IFaceD && ImplD &&
"Passed null params");
2879 ObjCImpls[IFaceD] = ImplD;
2885 assert(CatD && ImplD &&
"Passed null params");
2886 ObjCImpls[CatD] = ImplD;
2891 return ObjCMethodRedecls.lookup(MD);
2897 ObjCMethodRedecls[MD] = Redecl;
2902 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND->
getDeclContext()))
2904 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND->
getDeclContext()))
2905 return CD->getClassInterface();
2906 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(ND->
getDeclContext()))
2907 return IMD->getClassInterface();
2915 assert(VD &&
"Passed null params");
2916 assert(VD->
hasAttr<BlocksAttr>() &&
2917 "getBlockVarCopyInits - not __block var");
2918 auto I = BlockVarCopyInits.find(VD);
2919 if (I != BlockVarCopyInits.end())
2921 return {
nullptr,
false};
2927 assert(VD && CopyExpr &&
"Passed null params");
2928 assert(VD->
hasAttr<BlocksAttr>() &&
2929 "setBlockVarCopyInits - not __block var");
2930 BlockVarCopyInits[VD].setExprAndFlag(CopyExpr,
CanThrow);
2934 unsigned DataSize)
const {
2939 "incorrect data size provided to CreateTypeSourceInfo!");
2956 return getObjCLayout(D,
nullptr);
2967 bool &AnyNonCanonArgs) {
2969 for (
auto &Arg : CanonArgs) {
2971 Arg =
C.getCanonicalTemplateArgument(Arg);
2972 AnyNonCanonArgs |= !Arg.structurallyEquals(OrigArg);
2982ASTContext::getExtQualType(
const Type *baseType,
Qualifiers quals)
const {
2987 llvm::FoldingSetNodeID
ID;
2989 void *insertPos =
nullptr;
2990 if (
ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) {
2991 assert(eq->getQualifiers() == quals);
3000 canon = getExtQualType(canonSplit.
Ty, canonSplit.
Quals);
3003 (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos);
3006 auto *eq =
new (*
this,
alignof(
ExtQuals))
ExtQuals(baseType, canon, quals);
3007 ExtQualNodes.InsertNode(eq, insertPos);
3012 LangAS AddressSpace)
const {
3025 "Type cannot be in multiple addr spaces!");
3028 return getExtQualType(TypeNode, Quals);
3040 const Type *TypeNode;
3043 TypeNode = Quals.
strip(T);
3047 if (!
QualType(TypeNode, 0).hasAddressSpace())
3060 return getExtQualType(TypeNode, Quals);
3087 "Type cannot have multiple ObjCGCs!");
3090 return getExtQualType(TypeNode, Quals);
3109 if (
const auto *FNPT = dyn_cast<FunctionNoProtoType>(T)) {
3112 const auto *FPT = cast<FunctionProtoType>(T);
3118 return cast<FunctionType>(
Result.getTypePtr());
3134 L->DeducedReturnType(FD, ResultType);
3144 if (
const auto *PT = dyn_cast<ParenType>(Orig))
3149 if (
const auto *MQT = dyn_cast<MacroQualifiedType>(Orig))
3152 MQT->getMacroIdentifier());
3155 if (
const auto *AT = dyn_cast<AttributedType>(Orig))
3165 Proto->getReturnType(), Proto->getParamTypes(),
3166 Proto->getExtProtoInfo().withExceptionSpec(ESI));
3181 for (
unsigned i = 0, n = Args.size(); i != n; ++i)
3215 if (TSInfo->getType() != FD->
getType())
3223 "TypeLoc size mismatch from updating exception specification");
3224 TSInfo->overrideType(Updated);
3233 llvm::FoldingSetNodeID ID;
3236 void *InsertPos =
nullptr;
3237 if (
ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos))
3247 ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos);
3248 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3251 Types.push_back(New);
3252 ComplexTypes.InsertNode(New, InsertPos);
3261 llvm::FoldingSetNodeID ID;
3264 void *InsertPos =
nullptr;
3265 if (
PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3275 PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3276 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3279 Types.push_back(New);
3280 PointerTypes.InsertNode(New, InsertPos);
3285 llvm::FoldingSetNodeID ID;
3287 void *InsertPos =
nullptr;
3288 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3295 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3296 assert(!AT &&
"Shouldn't be in the map!");
3300 Types.push_back(AT);
3301 AdjustedTypes.InsertNode(AT, InsertPos);
3306 llvm::FoldingSetNodeID ID;
3308 void *InsertPos =
nullptr;
3309 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3316 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3317 assert(!AT &&
"Shouldn't be in the map!");
3320 Types.push_back(AT);
3321 AdjustedTypes.InsertNode(AT, InsertPos);
3354 llvm::FoldingSetNodeID ID;
3357 void *InsertPos =
nullptr;
3359 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3370 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3371 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3375 Types.push_back(New);
3376 BlockPointerTypes.InsertNode(New, InsertPos);
3386 "Unresolved placeholder type");
3390 llvm::FoldingSetNodeID ID;
3393 void *InsertPos =
nullptr;
3395 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3403 if (!SpelledAsLValue || InnerRef || !T.
isCanonical()) {
3404 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3409 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3410 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3415 Types.push_back(New);
3416 LValueReferenceTypes.InsertNode(New, InsertPos);
3426 "Unresolved placeholder type");
3430 llvm::FoldingSetNodeID ID;
3433 void *InsertPos =
nullptr;
3435 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3444 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3449 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3450 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3455 Types.push_back(New);
3456 RValueReferenceTypes.InsertNode(New, InsertPos);
3465 llvm::FoldingSetNodeID ID;
3468 void *InsertPos =
nullptr;
3470 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3481 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3482 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3486 Types.push_back(New);
3487 MemberPointerTypes.InsertNode(New, InsertPos);
3494 const llvm::APInt &ArySizeIn,
3495 const Expr *SizeExpr,
3497 unsigned IndexTypeQuals)
const {
3500 "Constant array of VLAs is illegal!");
3508 llvm::APInt ArySize(ArySizeIn);
3511 llvm::FoldingSetNodeID ID;
3515 void *InsertPos =
nullptr;
3517 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos))
3528 ASM, IndexTypeQuals);
3533 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos);
3534 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3538 ConstantArrayType::totalSizeToAlloc<const Expr *>(SizeExpr ? 1 : 0),
3540 auto *New =
new (Mem)
3542 ConstantArrayTypes.InsertNode(New, InsertPos);
3543 Types.push_back(New);
3552 if (!
type->isVariablyModifiedType())
return type;
3557 const Type *ty = split.
Ty;
3559#define TYPE(Class, Base)
3560#define ABSTRACT_TYPE(Class, Base)
3561#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3562#include "clang/AST/TypeNodes.inc"
3563 llvm_unreachable(
"didn't desugar past all non-canonical types?");
3569 case Type::DependentVector:
3570 case Type::ExtVector:
3571 case Type::DependentSizedExtVector:
3572 case Type::ConstantMatrix:
3573 case Type::DependentSizedMatrix:
3574 case Type::DependentAddressSpace:
3575 case Type::ObjCObject:
3576 case Type::ObjCInterface:
3577 case Type::ObjCObjectPointer:
3580 case Type::UnresolvedUsing:
3581 case Type::TypeOfExpr:
3583 case Type::Decltype:
3584 case Type::UnaryTransform:
3585 case Type::DependentName:
3586 case Type::InjectedClassName:
3587 case Type::TemplateSpecialization:
3588 case Type::DependentTemplateSpecialization:
3589 case Type::TemplateTypeParm:
3590 case Type::SubstTemplateTypeParmPack:
3592 case Type::DeducedTemplateSpecialization:
3593 case Type::PackExpansion:
3595 case Type::DependentBitInt:
3596 llvm_unreachable(
"type should never be variably-modified");
3600 case Type::FunctionNoProto:
3601 case Type::FunctionProto:
3602 case Type::BlockPointer:
3603 case Type::MemberPointer:
3613 cast<PointerType>(ty)->getPointeeType()));
3616 case Type::LValueReference: {
3617 const auto *lv = cast<LValueReferenceType>(ty);
3620 lv->isSpelledAsLValue());
3624 case Type::RValueReference: {
3625 const auto *lv = cast<RValueReferenceType>(ty);
3631 case Type::Atomic: {
3632 const auto *at = cast<AtomicType>(ty);
3637 case Type::ConstantArray: {
3638 const auto *cat = cast<ConstantArrayType>(ty);
3643 cat->getSizeModifier(),
3644 cat->getIndexTypeCVRQualifiers());
3648 case Type::DependentSizedArray: {
3649 const auto *dat = cast<DependentSizedArrayType>(ty);
3653 dat->getSizeModifier(),
3654 dat->getIndexTypeCVRQualifiers(),
3655 dat->getBracketsRange());
3660 case Type::IncompleteArray: {
3661 const auto *iat = cast<IncompleteArrayType>(ty);
3670 case Type::VariableArray: {
3671 const auto *vat = cast<VariableArrayType>(ty);
3675 vat->getIndexTypeCVRQualifiers(), vat->getBracketsRange());
3688 unsigned IndexTypeQuals,
3699 IndexTypeQuals, Brackets);
3706 VariableArrayTypes.push_back(New);
3707 Types.push_back(New);
3717 unsigned elementTypeQuals,
3721 "Size must be type- or value-dependent!");
3730 elementTypeQuals, brackets);
3731 Types.push_back(newType);
3740 void *insertPos =
nullptr;
3741 llvm::FoldingSetNodeID ID;
3744 ASM, elementTypeQuals, numElements);
3748 DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos);
3754 numElements, ASM, elementTypeQuals, brackets);
3755 DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
3756 Types.push_back(canonTy);
3761 canonElementType.
Quals);
3765 if (
QualType(canonElementType.
Ty, 0) == elementType &&
3773 elementTypeQuals, brackets);
3774 Types.push_back(sugaredType);
3780 unsigned elementTypeQuals)
const {
3781 llvm::FoldingSetNodeID ID;
3784 void *insertPos =
nullptr;
3786 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos))
3798 ASM, elementTypeQuals);
3803 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos);
3804 assert(!existing &&
"Shouldn't be in the map!"); (void) existing;
3810 IncompleteArrayTypes.InsertNode(newType, insertPos);
3811 Types.push_back(newType);
3817#define SVE_INT_ELTTY(BITS, ELTS, SIGNED, NUMVECTORS) \
3818 {getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount::getScalable(ELTS), \
3821#define SVE_ELTTY(ELTTY, ELTS, NUMVECTORS) \
3822 {ELTTY, llvm::ElementCount::getScalable(ELTS), NUMVECTORS};
3826 llvm_unreachable(
"Unsupported builtin vector type");
3827 case BuiltinType::SveInt8:
3829 case BuiltinType::SveUint8:
3831 case BuiltinType::SveInt8x2:
3833 case BuiltinType::SveUint8x2:
3835 case BuiltinType::SveInt8x3:
3837 case BuiltinType::SveUint8x3:
3839 case BuiltinType::SveInt8x4:
3841 case BuiltinType::SveUint8x4:
3843 case BuiltinType::SveInt16:
3845 case BuiltinType::SveUint16:
3847 case BuiltinType::SveInt16x2:
3849 case BuiltinType::SveUint16x2:
3851 case BuiltinType::SveInt16x3:
3853 case BuiltinType::SveUint16x3:
3855 case BuiltinType::SveInt16x4:
3857 case BuiltinType::SveUint16x4:
3859 case BuiltinType::SveInt32:
3861 case BuiltinType::SveUint32:
3863 case BuiltinType::SveInt32x2:
3865 case BuiltinType::SveUint32x2:
3867 case BuiltinType::SveInt32x3:
3869 case BuiltinType::SveUint32x3:
3871 case BuiltinType::SveInt32x4:
3873 case BuiltinType::SveUint32x4:
3875 case BuiltinType::SveInt64:
3877 case BuiltinType::SveUint64:
3879 case BuiltinType::SveInt64x2:
3881 case BuiltinType::SveUint64x2:
3883 case BuiltinType::SveInt64x3:
3885 case BuiltinType::SveUint64x3:
3887 case BuiltinType::SveInt64x4:
3889 case BuiltinType::SveUint64x4:
3891 case BuiltinType::SveBool:
3893 case BuiltinType::SveBoolx2:
3895 case BuiltinType::SveBoolx4:
3897 case BuiltinType::SveFloat16:
3899 case BuiltinType::SveFloat16x2:
3901 case BuiltinType::SveFloat16x3:
3903 case BuiltinType::SveFloat16x4:
3905 case BuiltinType::SveFloat32:
3907 case BuiltinType::SveFloat32x2:
3909 case BuiltinType::SveFloat32x3:
3911 case BuiltinType::SveFloat32x4:
3913 case BuiltinType::SveFloat64:
3915 case BuiltinType::SveFloat64x2:
3917 case BuiltinType::SveFloat64x3:
3919 case BuiltinType::SveFloat64x4:
3921 case BuiltinType::SveBFloat16:
3923 case BuiltinType::SveBFloat16x2:
3925 case BuiltinType::SveBFloat16x3:
3927 case BuiltinType::SveBFloat16x4:
3929#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
3931 case BuiltinType::Id: \
3932 return {getIntTypeForBitwidth(ElBits, IsSigned), \
3933 llvm::ElementCount::getScalable(NumEls), NF};
3934#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
3935 case BuiltinType::Id: \
3936 return {ElBits == 16 ? Float16Ty : (ElBits == 32 ? FloatTy : DoubleTy), \
3937 llvm::ElementCount::getScalable(NumEls), NF};
3938#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
3939 case BuiltinType::Id: \
3940 return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
3941#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
3942 case BuiltinType::Id: \
3943 return {BoolTy, llvm::ElementCount::getScalable(NumEls), 1};
3944#include "clang/Basic/RISCVVTypes.def"
3952#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
3953 if (BuiltinType::Id == BuiltinType::WasmExternRef) \
3955#include "clang/Basic/WebAssemblyReferenceTypes.def"
3958 "shouldn't try to generate type externref outside WebAssembly target");
3965 unsigned NumFields)
const {
3968#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
3969 IsSigned, IsFP, IsBF) \
3970 if (!EltTy->isBooleanType() && \
3971 ((EltTy->hasIntegerRepresentation() && \
3972 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
3973 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
3975 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
3976 IsBF && !IsFP)) && \
3977 EltTySize == ElBits && NumElts == NumEls) { \
3978 return SingletonId; \
3980#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
3981 if (EltTy->isBooleanType() && NumElts == NumEls) \
3983#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingleTonId)
3984#include "clang/Basic/AArch64SVEACLETypes.def"
3987#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
3989 if (!EltTy->isBooleanType() && \
3990 ((EltTy->hasIntegerRepresentation() && \
3991 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
3992 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
3994 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
3995 IsBF && !IsFP)) && \
3996 EltTySize == ElBits && NumElts == NumEls && NumFields == NF) \
3998#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
3999 if (EltTy->isBooleanType() && NumElts == NumEls) \
4001#include "clang/Basic/RISCVVTypes.def"
4017 llvm::FoldingSetNodeID ID;
4020 void *InsertPos =
nullptr;
4021 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4031 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4032 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4035 VectorType(vecType, NumElts, Canonical, VecKind);
4036 VectorTypes.InsertNode(New, InsertPos);
4037 Types.push_back(New);
4044 llvm::FoldingSetNodeID ID;
4047 void *InsertPos =
nullptr;
4049 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4054 VecType,
QualType(Canon, 0), SizeExpr, AttrLoc, VecKind);
4057 if (CanonVecTy == VecType) {
4062 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4063 assert(!CanonCheck &&
4064 "Dependent-sized vector_size canonical type broken");
4066 DependentVectorTypes.InsertNode(New, InsertPos);
4075 Types.push_back(New);
4082 unsigned NumElts)
const {
4090 llvm::FoldingSetNodeID ID;
4093 void *InsertPos =
nullptr;
4094 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4104 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4105 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4109 VectorTypes.InsertNode(New, InsertPos);
4110 Types.push_back(New);
4118 llvm::FoldingSetNodeID ID;
4122 void *InsertPos =
nullptr;
4124 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4134 if (CanonVecTy == vecType) {
4139 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4140 assert(!CanonCheck &&
"Dependent-sized ext_vector canonical type broken");
4142 DependentSizedExtVectorTypes.InsertNode(New, InsertPos);
4151 Types.push_back(New);
4156 unsigned NumColumns)
const {
4157 llvm::FoldingSetNodeID ID;
4159 Type::ConstantMatrix);
4162 "need a valid element type");
4165 "need valid matrix dimensions");
4166 void *InsertPos =
nullptr;
4176 assert(!NewIP &&
"Matrix type shouldn't already exist in the map");
4182 MatrixTypes.InsertNode(New, InsertPos);
4183 Types.push_back(New);
4192 llvm::FoldingSetNodeID ID;
4196 void *InsertPos =
nullptr;
4198 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4203 ColumnExpr, AttrLoc);
4206 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4207 assert(!CanonCheck &&
"Dependent-sized matrix canonical type broken");
4209 DependentSizedMatrixTypes.InsertNode(Canon, InsertPos);
4210 Types.push_back(Canon);
4223 ColumnExpr, AttrLoc);
4224 Types.push_back(New);
4229 Expr *AddrSpaceExpr,
4235 void *insertPos =
nullptr;
4236 llvm::FoldingSetNodeID ID;
4241 DependentAddressSpaceTypes.FindNodeOrInsertPos(ID, insertPos);
4247 DependentAddressSpaceTypes.InsertNode(canonTy, insertPos);
4248 Types.push_back(canonTy);
4251 if (canonPointeeType == PointeeType &&
4257 AddrSpaceExpr, AttrLoc);
4258 Types.push_back(sugaredType);
4282 llvm::FoldingSetNodeID ID;
4285 void *InsertPos =
nullptr;
4287 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos))
4297 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4298 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4303 Types.push_back(New);
4304 FunctionNoProtoTypes.InsertNode(New, InsertPos);
4320 return CanResultType;
4327 if (!NoexceptInType)
4344 bool AnyPackExpansions =
false;
4349 AnyPackExpansions =
true;
4351 return AnyPackExpansions;
4357QualType ASTContext::getFunctionTypeInternal(
4360 size_t NumArgs = ArgArray.size();
4364 llvm::FoldingSetNodeID
ID;
4369 bool Unique =
false;
4371 void *InsertPos =
nullptr;
4373 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) {
4393 bool IsCanonicalExceptionSpec =
4397 bool isCanonical = !Unique && IsCanonicalExceptionSpec &&
4399 for (
unsigned i = 0; i != NumArgs && isCanonical; ++i)
4400 if (!ArgArray[i].isCanonicalAsParam())
4401 isCanonical =
false;
4403 if (OnlyWantCanonical)
4404 assert(isCanonical &&
4405 "given non-canonical parameters constructing canonical type");
4410 if (!isCanonical && Canonical.
isNull()) {
4412 CanonicalArgs.reserve(NumArgs);
4413 for (
unsigned i = 0; i != NumArgs; ++i)
4420 if (IsCanonicalExceptionSpec) {
4422 }
else if (NoexceptInType) {
4435 bool AnyPacks =
false;
4458 llvm_unreachable(
"dependent noexcept is already canonical");
4467 getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI,
true);
4471 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4472 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4477 auto ESH = FunctionProtoType::getExceptionSpecSize(
4479 size_t Size = FunctionProtoType::totalSizeToAlloc<
4484 ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr,
4491 Types.push_back(FTP);
4493 FunctionProtoTypes.InsertNode(FTP, InsertPos);
4498 llvm::FoldingSetNodeID
ID;
4501 void *InsertPos =
nullptr;
4502 if (
PipeType *PT = PipeTypes.FindNodeOrInsertPos(ID, InsertPos))
4512 PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(ID, InsertPos);
4513 assert(!NewIP &&
"Shouldn't be in the map!");
4516 auto *New =
new (*
this,
alignof(
PipeType))
PipeType(T, Canonical, ReadOnly);
4517 Types.push_back(New);
4518 PipeTypes.InsertNode(New, InsertPos);
4529 return getPipeType(T,
true);
4533 return getPipeType(T,
false);
4537 llvm::FoldingSetNodeID ID;
4540 void *InsertPos =
nullptr;
4541 if (
BitIntType *EIT = BitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
4545 BitIntTypes.InsertNode(New, InsertPos);
4546 Types.push_back(New);
4551 Expr *NumBitsExpr)
const {
4553 llvm::FoldingSetNodeID ID;
4556 void *InsertPos =
nullptr;
4558 DependentBitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
4563 DependentBitIntTypes.InsertNode(New, InsertPos);
4565 Types.push_back(New);
4571 if (!isa<CXXRecordDecl>(D))
return false;
4572 const auto *RD = cast<CXXRecordDecl>(D);
4573 if (isa<ClassTemplatePartialSpecializationDecl>(RD))
4575 if (RD->getDescribedClassTemplate() &&
4576 !isa<ClassTemplateSpecializationDecl>(RD))
4587 if (
Decl->TypeForDecl) {
4588 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4590 assert(PrevDecl->TypeForDecl &&
"previous declaration has no type");
4591 Decl->TypeForDecl = PrevDecl->TypeForDecl;
4592 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4596 Decl->TypeForDecl = newType;
4597 Types.push_back(newType);
4605 assert(
Decl &&
"Passed null for Decl param");
4606 assert(!
Decl->TypeForDecl &&
"TypeForDecl present in slow case");
4608 if (
const auto *Typedef = dyn_cast<TypedefNameDecl>(
Decl))
4611 assert(!isa<TemplateTypeParmDecl>(
Decl) &&
4612 "Template type parameter types are always available.");
4614 if (
const auto *Record = dyn_cast<RecordDecl>(
Decl)) {
4615 assert(Record->isFirstDecl() &&
"struct/union has previous declaration");
4618 }
else if (
const auto *
Enum = dyn_cast<EnumDecl>(
Decl)) {
4619 assert(
Enum->isFirstDecl() &&
"enum has previous declaration");
4621 }
else if (
const auto *Using = dyn_cast<UnresolvedUsingTypenameDecl>(
Decl)) {
4624 llvm_unreachable(
"TypeDecl without a type?");
4633 if (!
Decl->TypeForDecl) {
4635 Underlying =
Decl->getUnderlyingType();
4638 Decl->TypeForDecl = NewType;
4639 Types.push_back(NewType);
4642 if (Underlying.
isNull() ||
Decl->getUnderlyingType() == Underlying)
4646 llvm::FoldingSetNodeID ID;
4649 void *InsertPos =
nullptr;
4650 if (
TypedefType *T = TypedefTypes.FindNodeOrInsertPos(ID, InsertPos)) {
4651 assert(!T->typeMatchesDecl() &&
4652 "non-divergent case should be handled with TypeDecl");
4656 void *Mem =
Allocate(TypedefType::totalSizeToAlloc<QualType>(
true),
4658 auto *NewType =
new (Mem)
TypedefType(Type::Typedef,
Decl, Underlying,
4660 TypedefTypes.InsertNode(NewType, InsertPos);
4661 Types.push_back(NewType);
4667 llvm::FoldingSetNodeID ID;
4670 void *InsertPos =
nullptr;
4671 if (
UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
4674 const Type *TypeForDecl =
4684 Allocate(UsingType::totalSizeToAlloc<QualType>(!Underlying.
isNull()),
4687 Types.push_back(NewType);
4688 UsingTypes.InsertNode(NewType, InsertPos);
4696 if (PrevDecl->TypeForDecl)
4697 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4700 Decl->TypeForDecl = newType;
4701 Types.push_back(newType);
4709 if (PrevDecl->TypeForDecl)
4710 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4713 Decl->TypeForDecl = newType;
4714 Types.push_back(newType);
4720 if (
Decl->TypeForDecl)
4725 if (CanonicalDecl->TypeForDecl)
4726 return QualType(
Decl->TypeForDecl = CanonicalDecl->TypeForDecl, 0);
4730 Decl->TypeForDecl = newType;
4731 Types.push_back(newType);
4738 llvm::FoldingSetNodeID id;
4741 void *insertPos =
nullptr;
4749 Types.push_back(
type);
4750 AttributedTypes.InsertNode(
type, insertPos);
4757 llvm::FoldingSetNodeID ID;
4760 void *InsertPos =
nullptr;
4762 BTFTagAttributedTypes.FindNodeOrInsertPos(ID, InsertPos);
4770 Types.push_back(Ty);
4771 BTFTagAttributedTypes.InsertNode(Ty, InsertPos);
4778 QualType Replacement,
Decl *AssociatedDecl,
unsigned Index,
4779 std::optional<unsigned> PackIndex)
const {
4780 llvm::FoldingSetNodeID ID;
4783 void *InsertPos =
nullptr;
4785 SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4788 void *Mem =
Allocate(SubstTemplateTypeParmType::totalSizeToAlloc<QualType>(
4793 Types.push_back(SubstParm);
4794 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
4803 unsigned Index,
bool Final,
4810 llvm::FoldingSetNodeID ID;
4813 void *InsertPos =
nullptr;
4815 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos))
4825 [[maybe_unused]]
const auto *Nothing =
4826 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos);
4834 Types.push_back(SubstParm);
4835 SubstTemplateTypeParmPackTypes.InsertNode(SubstParm, InsertPos);
4845 llvm::FoldingSetNodeID ID;
4847 void *InsertPos =
nullptr;
4849 = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4860 = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4861 assert(!TypeCheck &&
"Template type parameter canonical type broken");
4867 Types.push_back(TypeParm);
4868 TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos);
4878 assert(!Name.getAsDependentTemplateName() &&
4879 "No dependent template names here!");
4890 for (
unsigned i = 0, e = TL.
getNumArgs(); i != e; ++i)
4900 "No dependent template names here!");
4903 ArgVec.reserve(Args.size());
4905 ArgVec.push_back(Arg.getArgument());
4913 if (Arg.isPackExpansion())
4925 "No dependent template names here!");
4928 Template = QTN->getUnderlyingTemplate();
4933 if (!Underlying.
isNull())
4939 "Caller must compute aliased type");
4940 IsTypeAlias =
false;
4949 (IsTypeAlias ?
sizeof(
QualType) : 0),
4953 IsTypeAlias ? Underlying :
QualType());
4955 Types.push_back(Spec);
4962 "No dependent template names here!");
4970 bool AnyNonCanonArgs =
false;
4976 llvm::FoldingSetNodeID ID;
4980 void *InsertPos =
nullptr;
4982 = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
4992 Types.push_back(Spec);
4993 TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
4997 "Non-dependent template-id type must have a canonical type");
5004 TagDecl *OwnedTagDecl)
const {
5005 llvm::FoldingSetNodeID ID;
5008 void *InsertPos =
nullptr;
5009 ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos);
5016 ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos);
5017 assert(!CheckT &&
"Elaborated canonical type broken");
5022 Allocate(ElaboratedType::totalSizeToAlloc<TagDecl *>(!!OwnedTagDecl),
5024 T =
new (Mem)
ElaboratedType(Keyword, NNS, NamedType, Canon, OwnedTagDecl);
5027 ElaboratedTypes.InsertNode(T, InsertPos);
5033 llvm::FoldingSetNodeID ID;
5036 void *InsertPos =
nullptr;
5037 ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos);
5044 ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos);
5045 assert(!CheckT &&
"Paren canonical type broken");
5051 ParenTypes.InsertNode(T, InsertPos);
5064 Types.push_back(newType);
5074 if (CanonNNS != NNS)
5078 llvm::FoldingSetNodeID ID;
5081 void *InsertPos =
nullptr;
5083 = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos);
5090 DependentNameTypes.InsertNode(T, InsertPos);
5099 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
5111 "nested-name-specifier must be dependent");
5113 llvm::FoldingSetNodeID ID;
5117 void *InsertPos =
nullptr;
5119 = DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
5129 bool AnyNonCanonArgs =
false;
5134 if (AnyNonCanonArgs || CanonNNS != NNS || CanonKeyword != Keyword) {
5140 [[maybe_unused]]
auto *Nothing =
5141 DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
5142 assert(!Nothing &&
"canonical type broken");
5151 DependentTemplateSpecializationTypes.InsertNode(T, InsertPos);
5157 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
5163 }
else if (
auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
5165 NTTP->getType().getNonPackExpansionType().getNonLValueExprType(*
this);