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/Frontend/OpenMP/OMPIRBuilder.h"
81#include "llvm/Support/Capacity.h"
82#include "llvm/Support/Casting.h"
83#include "llvm/Support/Compiler.h"
84#include "llvm/Support/ErrorHandling.h"
85#include "llvm/Support/MD5.h"
86#include "llvm/Support/MathExtras.h"
87#include "llvm/Support/raw_ostream.h"
88#include "llvm/TargetParser/Triple.h"
101using 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 =
341 const char *Buffer = SourceMgr.
getBufferData(DeclLocDecomp.first,
347 StringRef
Text(Buffer + CommentEndOffset,
348 DeclLocDecomp.second - CommentEndOffset);
352 if (
Text.find_last_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)
742ASTContext::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());
757 if (TTP->isExpandedParameterPack()) {
759 ID.AddInteger(TTP->getNumExpansionParameters());
761 ID.AddBoolean(
false);
765 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
767 ID.AddBoolean(NTTP->isParameterPack());
768 ID.AddPointer(
C.getUnconstrainedType(
C.getCanonicalType(NTTP->getType()))
770 if (NTTP->isExpandedParameterPack()) {
772 ID.AddInteger(NTTP->getNumExpansionTypes());
773 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
774 QualType T = NTTP->getExpansionType(I);
778 ID.AddBoolean(
false);
782 auto *TTP = cast<TemplateTemplateParmDecl>(*
P);
789ASTContext::getCanonicalTemplateTemplateParmDecl(
792 llvm::FoldingSetNodeID
ID;
793 CanonicalTemplateTemplateParm::Profile(ID, *
this, TTP);
794 void *InsertPos =
nullptr;
795 CanonicalTemplateTemplateParm *Canonical
796 = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
798 return Canonical->getParam();
803 CanonParams.reserve(Params->
size());
805 PEnd = Params->
end();
809 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
815 ? std::optional<unsigned>(TTP->getNumExpansionParameters())
817 CanonParams.push_back(NewTTP);
818 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
822 if (NTTP->isExpandedParameterPack()) {
825 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
827 ExpandedTInfos.push_back(
835 NTTP->getPosition(),
nullptr,
845 NTTP->getPosition(),
nullptr,
847 NTTP->isParameterPack(),
850 CanonParams.push_back(Param);
852 CanonParams.push_back(getCanonicalTemplateTemplateParmDecl(
853 cast<TemplateTemplateParmDecl>(*
P)));
864 Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
865 assert(!Canonical &&
"Shouldn't be in the map!");
869 Canonical =
new (*this) CanonicalTemplateTemplateParm(CanonTTP);
870 CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos);
880 if (!LangOpts.CPlusPlus)
return nullptr;
883 case TargetCXXABI::AppleARM64:
884 case TargetCXXABI::Fuchsia:
885 case TargetCXXABI::GenericARM:
886 case TargetCXXABI::iOS:
887 case TargetCXXABI::WatchOS:
888 case TargetCXXABI::GenericAArch64:
889 case TargetCXXABI::GenericMIPS:
890 case TargetCXXABI::GenericItanium:
891 case TargetCXXABI::WebAssembly:
892 case TargetCXXABI::XL:
894 case TargetCXXABI::Microsoft:
897 llvm_unreachable(
"Invalid CXXABI type!");
901 if (!InterpContext) {
904 return *InterpContext.get();
910 return *ParentMapCtx.get();
915 switch (LangOpts.getAddressSpaceMapMangling()) {
923 llvm_unreachable(
"getAddressSpaceMapMangling() doesn't cover anything.");
929 : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize),
930 FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize),
931 TemplateSpecializationTypes(this_()),
932 DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
933 SubstTemplateTemplateParmPacks(this_()),
934 CanonTemplateTemplateParms(this_()), SourceMgr(
SM), LangOpts(LOpts),
937 LangOpts.XRayNeverInstrumentFiles,
938 LangOpts.XRayAttrListFiles,
SM)),
941 BuiltinInfo(builtins), TUKind(TUKind), DeclarationNames(*this),
942 Comments(
SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
943 CompCategories(this_()), LastSDM(nullptr, 0) {
950 ReleaseDeclContextMaps();
953 for (
auto &Pair : Deallocations)
954 (Pair.first)(Pair.second);
955 Deallocations.clear();
961 I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; )
967 for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
968 I = ASTRecordLayouts.begin(), E = ASTRecordLayouts.end(); I != E; ) {
973 ASTRecordLayouts.clear();
975 for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(),
976 AEnd = DeclAttrs.end();
978 A->second->~AttrVec();
981 for (
const auto &
Value : ModuleInitializers)
982 Value.second->~PerModuleInitializers();
983 ModuleInitializers.
clear();
989 TraversalScope = TopLevelDecls;
994 Deallocations.push_back({Callback,
Data});
1003 llvm::errs() <<
"\n*** AST Context Stats:\n";
1004 llvm::errs() <<
" " << Types.size() <<
" types total.\n";
1006 unsigned counts[] = {
1007#define TYPE(Name, Parent) 0,
1008#define ABSTRACT_TYPE(Name, Parent)
1009#include "clang/AST/TypeNodes.inc"
1013 for (
unsigned i = 0, e = Types.size(); i != e; ++i) {
1019 unsigned TotalBytes = 0;
1020#define TYPE(Name, Parent) \
1022 llvm::errs() << " " << counts[Idx] << " " << #Name \
1023 << " types, " << sizeof(Name##Type) << " each " \
1024 << "(" << counts[Idx] * sizeof(Name##Type) \
1026 TotalBytes += counts[Idx] * sizeof(Name##Type); \
1028#define ABSTRACT_TYPE(Name, Parent)
1029#include "clang/AST/TypeNodes.inc"
1031 llvm::errs() <<
"Total bytes = " << TotalBytes <<
"\n";
1036 <<
" implicit default constructors created\n";
1039 <<
" implicit copy constructors created\n";
1043 <<
" implicit move constructors created\n";
1046 <<
" implicit copy assignment operators created\n";
1050 <<
" implicit move assignment operators created\n";
1053 <<
" implicit destructors created\n";
1056 llvm::errs() <<
"\n";
1060 BumpAlloc.PrintStats();
1064 bool NotifyListeners) {
1065 if (NotifyListeners)
1074 if (It == MergedDefModules.end())
1077 auto &Merged = It->second;
1079 for (
Module *&M : Merged)
1080 if (!Found.insert(M).second)
1082 llvm::erase_value(Merged,
nullptr);
1089 if (MergedIt == MergedDefModules.end())
1090 return std::nullopt;
1091 return MergedIt->second;
1094void ASTContext::PerModuleInitializers::resolve(
ASTContext &Ctx) {
1095 if (LazyInitializers.empty())
1099 assert(Source &&
"lazy initializers but no external source");
1101 auto LazyInits = std::move(LazyInitializers);
1102 LazyInitializers.clear();
1104 for (
auto ID : LazyInits)
1105 Initializers.push_back(Source->GetExternalDecl(ID));
1107 assert(LazyInitializers.empty() &&
1108 "GetExternalDecl for lazy module initializer added more inits");
1114 if (
const auto *ID = dyn_cast<ImportDecl>(D)) {
1115 auto It = ModuleInitializers.find(ID->getImportedModule());
1118 if (It == ModuleInitializers.end())
1122 auto &Imported = *It->second;
1123 if (Imported.Initializers.size() + Imported.LazyInitializers.size() == 1) {
1124 Imported.resolve(*
this);
1125 auto *OnlyDecl = Imported.Initializers.front();
1126 if (isa<ImportDecl>(OnlyDecl))
1131 auto *&Inits = ModuleInitializers[M];
1133 Inits =
new (*this) PerModuleInitializers;
1134 Inits->Initializers.push_back(D);
1138 auto *&Inits = ModuleInitializers[M];
1140 Inits =
new (*this) PerModuleInitializers;
1141 Inits->LazyInitializers.insert(Inits->LazyInitializers.end(),
1142 IDs.begin(), IDs.end());
1146 auto It = ModuleInitializers.find(M);
1147 if (It == ModuleInitializers.end())
1148 return std::nullopt;
1150 auto *Inits = It->second;
1151 Inits->resolve(*
this);
1152 return Inits->Initializers;
1157 assert(!CurrentCXXNamedModule &&
1158 "We should set named module for ASTContext for only once");
1159 CurrentCXXNamedModule = M;
1163 if (!ExternCContext)
1166 return ExternCContext;
1172 auto *BuiltinTemplate =
1174 BuiltinTemplate->setImplicit();
1177 return BuiltinTemplate;
1182 if (!MakeIntegerSeqDecl)
1185 return MakeIntegerSeqDecl;
1190 if (!TypePackElementDecl)
1193 return TypePackElementDecl;
1207 NewDecl->
addAttr(TypeVisibilityAttr::CreateImplicit(
1208 const_cast<ASTContext &
>(*
this), TypeVisibilityAttr::Default));
1213 StringRef Name)
const {
1237 Types.push_back(Ty);
1242 assert((!this->Target || this->Target == &
Target) &&
1243 "Incorrect target reinitialization");
1247 this->AuxTarget = AuxTarget;
1249 ABI.reset(createCXXABI(
Target));
1253 InitBuiltinType(
VoidTy, BuiltinType::Void);
1256 InitBuiltinType(
BoolTy, BuiltinType::Bool);
1258 if (LangOpts.CharIsSigned)
1259 InitBuiltinType(
CharTy, BuiltinType::Char_S);
1261 InitBuiltinType(
CharTy, BuiltinType::Char_U);
1264 InitBuiltinType(
ShortTy, BuiltinType::Short);
1265 InitBuiltinType(
IntTy, BuiltinType::Int);
1266 InitBuiltinType(
LongTy, BuiltinType::Long);
1267 InitBuiltinType(
LongLongTy, BuiltinType::LongLong);
1277 InitBuiltinType(
FloatTy, BuiltinType::Float);
1278 InitBuiltinType(
DoubleTy, BuiltinType::Double);
1279 InitBuiltinType(
LongDoubleTy, BuiltinType::LongDouble);
1282 InitBuiltinType(
Float128Ty, BuiltinType::Float128);
1285 InitBuiltinType(
Ibm128Ty, BuiltinType::Ibm128);
1288 InitBuiltinType(
Float16Ty, BuiltinType::Float16);
1291 InitBuiltinType(
ShortAccumTy, BuiltinType::ShortAccum);
1292 InitBuiltinType(
AccumTy, BuiltinType::Accum);
1293 InitBuiltinType(
LongAccumTy, BuiltinType::LongAccum);
1297 InitBuiltinType(
ShortFractTy, BuiltinType::ShortFract);
1298 InitBuiltinType(
FractTy, BuiltinType::Fract);
1299 InitBuiltinType(
LongFractTy, BuiltinType::LongFract);
1304 InitBuiltinType(
SatAccumTy, BuiltinType::SatAccum);
1310 InitBuiltinType(
SatFractTy, BuiltinType::SatFract);
1317 InitBuiltinType(
Int128Ty, BuiltinType::Int128);
1322 InitBuiltinType(
WCharTy, BuiltinType::WChar_S);
1324 InitBuiltinType(
WCharTy, BuiltinType::WChar_U);
1325 if (LangOpts.CPlusPlus && LangOpts.WChar)
1335 InitBuiltinType(
Char8Ty, BuiltinType::Char8);
1337 if (LangOpts.CPlusPlus)
1338 InitBuiltinType(
Char16Ty, BuiltinType::Char16);
1342 if (LangOpts.CPlusPlus)
1343 InitBuiltinType(
Char32Ty, BuiltinType::Char32);
1352 InitBuiltinType(
DependentTy, BuiltinType::Dependent);
1355 InitBuiltinType(
OverloadTy, BuiltinType::Overload);
1364 InitBuiltinType(
UnknownAnyTy, BuiltinType::UnknownAny);
1370 InitBuiltinType(
BuiltinFnTy, BuiltinType::BuiltinFn);
1373 if (LangOpts.OpenMP) {
1378 if (LangOpts.MatrixTypes)
1386 if (LangOpts.OpenCL) {
1387#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1388 InitBuiltinType(SingletonId, BuiltinType::Id);
1389#include "clang/Basic/OpenCLImageTypes.def"
1391 InitBuiltinType(
OCLSamplerTy, BuiltinType::OCLSampler);
1392 InitBuiltinType(
OCLEventTy, BuiltinType::OCLEvent);
1394 InitBuiltinType(
OCLQueueTy, BuiltinType::OCLQueue);
1397#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1398 InitBuiltinType(Id##Ty, BuiltinType::Id);
1399#include "clang/Basic/OpenCLExtensionTypes.def"
1402 if (
Target.hasAArch64SVETypes()) {
1403#define SVE_TYPE(Name, Id, SingletonId) \
1404 InitBuiltinType(SingletonId, BuiltinType::Id);
1405#include "clang/Basic/AArch64SVEACLETypes.def"
1408 if (
Target.getTriple().isPPC64()) {
1409#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
1410 InitBuiltinType(Id##Ty, BuiltinType::Id);
1411#include "clang/Basic/PPCTypes.def"
1412#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
1413 InitBuiltinType(Id##Ty, BuiltinType::Id);
1414#include "clang/Basic/PPCTypes.def"
1417 if (
Target.hasRISCVVTypes()) {
1418#define RVV_TYPE(Name, Id, SingletonId) \
1419 InitBuiltinType(SingletonId, BuiltinType::Id);
1420#include "clang/Basic/RISCVVTypes.def"
1423 if (
Target.getTriple().isWasm() &&
Target.hasFeature(
"reference-types")) {
1424#define WASM_TYPE(Name, Id, SingletonId) \
1425 InitBuiltinType(SingletonId, BuiltinType::Id);
1426#include "clang/Basic/WebAssemblyReferenceTypes.def"
1433 ObjCConstantStringType =
QualType();
1438 if (LangOpts.OpenCLGenericAddressSpace) {
1448 InitBuiltinType(
NullPtrTy, BuiltinType::NullPtr);
1451 InitBuiltinType(
HalfTy, BuiltinType::Half);
1453 InitBuiltinType(
BFloat16Ty, BuiltinType::BFloat16);
1459 if (LangOpts.MicrosoftExt || LangOpts.Borland) {
1481 llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(D);
1482 if (Pos != DeclAttrs.end()) {
1483 Pos->second->~AttrVec();
1484 DeclAttrs.erase(Pos);
1498 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>::iterator Pos =
1499 TemplateOrInstantiation.find(Var);
1500 if (Pos == TemplateOrInstantiation.end())
1513 Tmpl, TSK, PointOfInstantiation));
1519 assert(!TemplateOrInstantiation[Inst] &&
1520 "Already noted what the variable was instantiated from");
1521 TemplateOrInstantiation[Inst] = TSI;
1526 auto Pos = InstantiatedFromUsingDecl.find(UUD);
1527 if (Pos == InstantiatedFromUsingDecl.end())
1535 assert((isa<UsingDecl>(Pattern) ||
1536 isa<UnresolvedUsingValueDecl>(Pattern) ||
1537 isa<UnresolvedUsingTypenameDecl>(Pattern)) &&
1538 "pattern decl is not a using decl");
1539 assert((isa<UsingDecl>(Inst) ||
1540 isa<UnresolvedUsingValueDecl>(Inst) ||
1541 isa<UnresolvedUsingTypenameDecl>(Inst)) &&
1542 "instantiation did not produce a using decl");
1543 assert(!InstantiatedFromUsingDecl[Inst] &&
"pattern already exists");
1544 InstantiatedFromUsingDecl[Inst] = Pattern;
1549 auto Pos = InstantiatedFromUsingEnumDecl.find(UUD);
1550 if (Pos == InstantiatedFromUsingEnumDecl.end())
1558 assert(!InstantiatedFromUsingEnumDecl[Inst] &&
"pattern already exists");
1559 InstantiatedFromUsingEnumDecl[Inst] = Pattern;
1564 llvm::DenseMap<UsingShadowDecl*, UsingShadowDecl*>::const_iterator Pos
1565 = InstantiatedFromUsingShadowDecl.find(Inst);
1566 if (Pos == InstantiatedFromUsingShadowDecl.end())
1575 assert(!InstantiatedFromUsingShadowDecl[Inst] &&
"pattern already exists");
1576 InstantiatedFromUsingShadowDecl[Inst] = Pattern;
1580 llvm::DenseMap<FieldDecl *, FieldDecl *>::iterator Pos
1581 = InstantiatedFromUnnamedFieldDecl.find(Field);
1582 if (Pos == InstantiatedFromUnnamedFieldDecl.end())
1590 assert(!Inst->
getDeclName() &&
"Instantiated field decl is not unnamed");
1591 assert(!Tmpl->
getDeclName() &&
"Template field decl is not unnamed");
1592 assert(!InstantiatedFromUnnamedFieldDecl[Inst] &&
1593 "Already noted what unnamed field was instantiated from");
1595 InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl;
1611 return Range.end() - Range.begin();
1616 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos =
1618 if (Pos == OverriddenMethods.end())
1626 OverriddenMethods[Method].push_back(Overridden);
1634 if (
const auto *CXXMethod = dyn_cast<CXXMethodDecl>(D)) {
1640 const auto *Method = dyn_cast<ObjCMethodDecl>(D);
1645 Method->getOverriddenMethods(OverDecls);
1646 Overridden.append(OverDecls.begin(), OverDecls.end());
1650 assert(!Import->getNextLocalImport() &&
1651 "Import declaration already in the chain");
1652 assert(!Import->isFromASTFile() &&
"Non-local import declaration");
1653 if (!FirstLocalImport) {
1654 FirstLocalImport = Import;
1655 LastLocalImport = Import;
1659 LastLocalImport->setNextLocalImport(Import);
1660 LastLocalImport = Import;
1672 llvm_unreachable(
"Not a floating point type!");
1673 case BuiltinType::BFloat16:
1675 case BuiltinType::Float16:
1677 case BuiltinType::Half:
1689 case BuiltinType::Ibm128:
1691 case BuiltinType::LongDouble:
1695 case BuiltinType::Float128:
1705 bool UseAlignAttrOnly =
false;
1707 Align = AlignFromAttr;
1715 if (isa<FieldDecl>(D)) {
1716 UseAlignAttrOnly = D->
hasAttr<PackedAttr>() ||
1717 cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1719 UseAlignAttrOnly =
true;
1722 else if (isa<FieldDecl>(D))
1725 cast<FieldDecl>(D)->getParent()->hasAttr<PackedAttr>();
1729 if (UseAlignAttrOnly) {
1731 }
else if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
1747 if (!ForAlignof && MinWidth) {
1750 else if (isa<ConstantArrayType>(
arrayType) &&
1758 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
1759 if (VD->hasGlobalStorage() && !ForAlignof) {
1761 Align = std::max(Align,
getTargetInfo().getMinGlobalAlign(TypeSize));
1771 if (
const auto *Field = dyn_cast<FieldDecl>(VD)) {
1774 if (!
Parent->isInvalidDecl()) {
1785 uint64_t LowBitOfOffset =
Offset & (~Offset + 1);
1786 if (LowBitOfOffset < FieldAlign)
1787 FieldAlign =
static_cast<unsigned>(LowBitOfOffset);
1790 Align = std::min(Align, FieldAlign);
1798 const auto *VD = dyn_cast<VarDecl>(D);
1799 if (MaxAlignedAttr && VD && VD->getStorageClass() ==
SC_Static)
1800 Align = std::min(Align, MaxAlignedAttr);
1835 uint64_t Size = CAT->
getSize().getZExtValue();
1837 (uint64_t)(-1)/Size) &&
1838 "Overflow in array type char size evaluation");
1843 Width = llvm::alignTo(Width, Align);
1850 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
1868 switch (BT->getKind()) {
1869 case BuiltinType::Bool:
1870 case BuiltinType::Char_S:
1871 case BuiltinType::Char_U:
1872 case BuiltinType::SChar:
1873 case BuiltinType::UChar:
1874 case BuiltinType::Short:
1875 case BuiltinType::UShort:
1876 case BuiltinType::WChar_S:
1877 case BuiltinType::WChar_U:
1878 case BuiltinType::Char8:
1879 case BuiltinType::Char16:
1880 case BuiltinType::Char32:
1889 if (T->
isDependentType() || ET->getDecl()->getPromotionType().isNull() ||
1890 ET->getDecl()->isScoped())
1908 bool NeedsPreferredAlignment)
const {
1911 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1922 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1927 return TT->getDecl()->getMaxAlignment();
1933 TypeInfoMap::iterator I = MemoizedTypeInfo.find(T);
1934 if (I != MemoizedTypeInfo.end())
1939 MemoizedTypeInfo[T] = TI;
1949TypeInfo ASTContext::getTypeInfoImpl(
const Type *T)
const {
1955#define TYPE(Class, Base)
1956#define ABSTRACT_TYPE(Class, Base)
1957#define NON_CANONICAL_TYPE(Class, Base)
1958#define DEPENDENT_TYPE(Class, Base) case Type::Class:
1959#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) \
1961 assert(!T->isDependentType() && "should not see dependent types here"); \
1962 return getTypeInfo(cast<Class##Type>(T)->desugar().getTypePtr());
1963#include "clang/AST/TypeNodes.inc"
1964 llvm_unreachable(
"Should not see dependent types");
1966 case Type::FunctionNoProto:
1967 case Type::FunctionProto:
1973 case Type::IncompleteArray:
1974 case Type::VariableArray:
1975 case Type::ConstantArray: {
1978 if (
const auto *CAT = dyn_cast<ConstantArrayType>(T))
1979 Size = CAT->getSize().getZExtValue();
1982 assert((Size == 0 || EltInfo.
Width <= (uint64_t)(-1) / Size) &&
1983 "Overflow in array type bit size evaluation");
1984 Width = EltInfo.
Width * Size;
1985 Align = EltInfo.
Align;
1989 Width = llvm::alignTo(Width, Align);
1993 case Type::ExtVector:
1994 case Type::Vector: {
1995 const auto *VT = cast<VectorType>(T);
1997 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
1998 : EltInfo.
Width * VT->getNumElements();
2000 Width = std::max<unsigned>(8, Width);
2001 Align = std::max<unsigned>(8, Width);
2005 if (Align & (Align-1)) {
2006 Align = llvm::bit_ceil(Align);
2007 Width = llvm::alignTo(Width, Align);
2011 if (TargetVectorAlign && TargetVectorAlign < Align)
2012 Align = TargetVectorAlign;
2026 case Type::ConstantMatrix: {
2027 const auto *MT = cast<ConstantMatrixType>(T);
2032 Width = ElementInfo.
Width * MT->getNumRows() * MT->getNumColumns();
2033 Align = ElementInfo.
Align;
2038 switch (cast<BuiltinType>(T)->
getKind()) {
2039 default: llvm_unreachable(
"Unknown builtin type!");
2040 case BuiltinType::Void:
2045 case BuiltinType::Bool:
2049 case BuiltinType::Char_S:
2050 case BuiltinType::Char_U:
2051 case BuiltinType::UChar:
2052 case BuiltinType::SChar:
2053 case BuiltinType::Char8:
2057 case BuiltinType::WChar_S:
2058 case BuiltinType::WChar_U:
2062 case BuiltinType::Char16:
2066 case BuiltinType::Char32:
2070 case BuiltinType::UShort:
2071 case BuiltinType::Short:
2075 case BuiltinType::UInt:
2076 case BuiltinType::Int:
2080 case BuiltinType::ULong:
2081 case BuiltinType::Long:
2085 case BuiltinType::ULongLong:
2086 case BuiltinType::LongLong:
2090 case BuiltinType::Int128:
2091 case BuiltinType::UInt128:
2095 case BuiltinType::ShortAccum:
2096 case BuiltinType::UShortAccum:
2097 case BuiltinType::SatShortAccum:
2098 case BuiltinType::SatUShortAccum:
2102 case BuiltinType::Accum:
2103 case BuiltinType::UAccum:
2104 case BuiltinType::SatAccum:
2105 case BuiltinType::SatUAccum:
2109 case BuiltinType::LongAccum:
2110 case BuiltinType::ULongAccum:
2111 case BuiltinType::SatLongAccum:
2112 case BuiltinType::SatULongAccum:
2116 case BuiltinType::ShortFract:
2117 case BuiltinType::UShortFract:
2118 case BuiltinType::SatShortFract:
2119 case BuiltinType::SatUShortFract:
2123 case BuiltinType::Fract:
2124 case BuiltinType::UFract:
2125 case BuiltinType::SatFract:
2126 case BuiltinType::SatUFract:
2130 case BuiltinType::LongFract:
2131 case BuiltinType::ULongFract:
2132 case BuiltinType::SatLongFract:
2133 case BuiltinType::SatULongFract:
2137 case BuiltinType::BFloat16:
2148 case BuiltinType::Float16:
2149 case BuiltinType::Half:
2156 "Expected OpenMP device compilation.");
2161 case BuiltinType::Float:
2165 case BuiltinType::Double:
2169 case BuiltinType::Ibm128:
2173 case BuiltinType::LongDouble:
2184 case BuiltinType::Float128:
2191 "Expected OpenMP device compilation.");
2196 case BuiltinType::NullPtr:
2201 case BuiltinType::ObjCId:
2202 case BuiltinType::ObjCClass:
2203 case BuiltinType::ObjCSel:
2207 case BuiltinType::OCLSampler:
2208 case BuiltinType::OCLEvent:
2209 case BuiltinType::OCLClkEvent:
2210 case BuiltinType::OCLQueue:
2211 case BuiltinType::OCLReserveID:
2212#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2213 case BuiltinType::Id:
2214#include "clang/Basic/OpenCLImageTypes.def"
2215#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2216 case BuiltinType::Id:
2217#include "clang/Basic/OpenCLExtensionTypes.def"
2230#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
2231 IsSigned, IsFP, IsBF) \
2232 case BuiltinType::Id: \
2236#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
2237 case BuiltinType::Id: \
2241#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
2242 case BuiltinType::Id: \
2246#include "clang/Basic/AArch64SVEACLETypes.def"
2247#define PPC_VECTOR_TYPE(Name, Id, Size) \
2248 case BuiltinType::Id: \
2252#include "clang/Basic/PPCTypes.def"
2253#define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, NF, IsSigned, \
2255 case BuiltinType::Id: \
2259#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, ElKind) \
2260 case BuiltinType::Id: \
2264#include "clang/Basic/RISCVVTypes.def"
2265#define WASM_TYPE(Name, Id, SingletonId) \
2266 case BuiltinType::Id: \
2270#include "clang/Basic/WebAssemblyReferenceTypes.def"
2273 case Type::ObjCObjectPointer:
2277 case Type::BlockPointer:
2278 AS = cast<BlockPointerType>(T)->getPointeeType().getAddressSpace();
2282 case Type::LValueReference:
2283 case Type::RValueReference:
2286 AS = cast<ReferenceType>(T)->getPointeeType().getAddressSpace();
2291 AS = cast<PointerType>(T)->getPointeeType().getAddressSpace();
2295 case Type::MemberPointer: {
2296 const auto *MPT = cast<MemberPointerType>(T);
2302 case Type::Complex: {
2306 Width = EltInfo.
Width * 2;
2307 Align = EltInfo.
Align;
2310 case Type::ObjCObject:
2311 return getTypeInfo(cast<ObjCObjectType>(T)->getBaseType().getTypePtr());
2312 case Type::Adjusted:
2315 case Type::ObjCInterface: {
2316 const auto *ObjCI = cast<ObjCInterfaceType>(T);
2317 if (ObjCI->getDecl()->isInvalidDecl()) {
2327 case Type::BitInt: {
2328 const auto *EIT = cast<BitIntType>(T);
2329 Align = std::clamp<unsigned>(llvm::PowerOf2Ceil(EIT->getNumBits()),
2331 Width = llvm::alignTo(EIT->getNumBits(), Align);
2336 const auto *TT = cast<TagType>(T);
2338 if (TT->getDecl()->isInvalidDecl()) {
2344 if (
const auto *ET = dyn_cast<EnumType>(TT)) {
2345 const EnumDecl *ED = ET->getDecl();
2349 Info.
Align = AttrAlign;
2355 const auto *RT = cast<RecordType>(TT);
2360 AlignRequirement = RD->
hasAttr<AlignedAttr>()
2366 case Type::SubstTemplateTypeParm:
2367 return getTypeInfo(cast<SubstTemplateTypeParmType>(T)->
2368 getReplacementType().getTypePtr());
2371 case Type::DeducedTemplateSpecialization: {
2372 const auto *A = cast<DeducedType>(T);
2373 assert(!A->getDeducedType().isNull() &&
2374 "cannot request the size of an undeduced or dependent auto type");
2375 return getTypeInfo(A->getDeducedType().getTypePtr());
2379 return getTypeInfo(cast<ParenType>(T)->getInnerType().getTypePtr());
2381 case Type::MacroQualified:
2385 case Type::ObjCTypeParam:
2386 return getTypeInfo(cast<ObjCTypeParamType>(T)->desugar().getTypePtr());
2389 return getTypeInfo(cast<UsingType>(T)->desugar().getTypePtr());
2391 case Type::Typedef: {
2392 const auto *TT = cast<TypedefType>(T);
2397 if (
unsigned AttrAlign = TT->getDecl()->getMaxAlignment()) {
2408 case Type::Elaborated:
2409 return getTypeInfo(cast<ElaboratedType>(T)->getNamedType().getTypePtr());
2411 case Type::Attributed:
2413 cast<AttributedType>(T)->getEquivalentType().getTypePtr());
2415 case Type::BTFTagAttributed:
2417 cast<BTFTagAttributedType>(T)->getWrappedType().getTypePtr());
2419 case Type::Atomic: {
2430 }
else if (Width <= Target->getMaxAtomicPromoteWidth()) {
2436 Width = llvm::bit_ceil(Width);
2439 Align =
static_cast<unsigned>(Width);
2450 assert(llvm::isPowerOf2_32(Align) &&
"Alignment must be power of 2");
2451 return TypeInfo(Width, Align, AlignRequirement);
2455 UnadjustedAlignMap::iterator I = MemoizedUnadjustedAlign.find(T);
2456 if (I != MemoizedUnadjustedAlign.end())
2459 unsigned UnadjustedAlign;
2471 MemoizedUnadjustedAlign[T] = UnadjustedAlign;
2472 return UnadjustedAlign;
2476 unsigned SimdAlign = llvm::OpenMPIRBuilder::getOpenMPDefaultSimdAlign(
2526 unsigned ABIAlign = TI.
Align;
2548 unsigned PreferredAlign =
static_cast<unsigned>(
2550 assert(PreferredAlign >= ABIAlign &&
2551 "PreferredAlign should be at least as large as ABIAlign.");
2552 return PreferredAlign;
2559 T = CT->getElementType().getTypePtr();
2561 T = ET->getDecl()->getIntegerType().getTypePtr();
2570 return std::max(ABIAlign, (
unsigned)
getTypeSize(T));
2612 for (
unsigned I = 0, N = Path.size(); I != N; ++I) {
2616 std::swap(
Base, Derived);
2636 llvm::append_range(Ivars, OI->
ivars());
2639 for (
const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
2641 Ivars.push_back(Iv);
2649 if (
const auto *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
2652 for (
auto *Proto : OI->all_referenced_protocols()) {
2657 for (
const auto *Cat : OI->visible_categories())
2663 SD = SD->getSuperClass();
2665 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) {
2666 for (
auto *Proto : OC->protocols()) {
2669 }
else if (
const auto *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) {
2671 if (!Protocols.insert(
2675 for (
auto *Proto : OP->protocols())
2682 bool CheckIfTriviallyCopyable) {
2683 assert(RD->
isUnion() &&
"Must be union type");
2686 for (
const auto *Field : RD->
fields()) {
2688 CheckIfTriviallyCopyable))
2691 if (FieldSize != UnionSize)
2709static std::optional<int64_t>
2712 bool CheckIfTriviallyCopyable);
2714static std::optional<int64_t>
2716 bool CheckIfTriviallyCopyable) {
2717 if (Field->getType()->isRecordType()) {
2718 const RecordDecl *RD = Field->getType()->getAsRecordDecl();
2721 CheckIfTriviallyCopyable);
2726 bool IsBitIntType = Field->getType()->isBitIntType();
2727 if (!Field->getType()->isReferenceType() && !IsBitIntType &&
2729 CheckIfTriviallyCopyable))
2730 return std::nullopt;
2732 int64_t FieldSizeInBits =
2734 if (Field->isBitField()) {
2737 if (Field->isUnnamedBitfield())
2740 int64_t BitfieldSize = Field->getBitWidthValue(Context);
2742 if ((
unsigned)BitfieldSize >
2743 cast<BitIntType>(Field->getType())->getNumBits())
2744 return std::nullopt;
2745 }
else if (BitfieldSize > FieldSizeInBits) {
2746 return std::nullopt;
2748 FieldSizeInBits = BitfieldSize;
2750 Field->getType(), CheckIfTriviallyCopyable)) {
2751 return std::nullopt;
2753 return FieldSizeInBits;
2756static std::optional<int64_t>
2758 bool CheckIfTriviallyCopyable) {
2760 CheckIfTriviallyCopyable);
2763template <
typename RangeT>
2765 const RangeT &Subobjects, int64_t CurOffsetInBits,
2767 bool CheckIfTriviallyCopyable) {
2768 for (
const auto *Subobject : Subobjects) {
2769 std::optional<int64_t> SizeInBits =
2772 return std::nullopt;
2773 if (*SizeInBits != 0) {
2775 if (
Offset != CurOffsetInBits)
2776 return std::nullopt;
2777 CurOffsetInBits += *SizeInBits;
2780 return CurOffsetInBits;
2783static std::optional<int64_t>
2786 bool CheckIfTriviallyCopyable) {
2787 assert(!RD->
isUnion() &&
"Must be struct/class type");
2790 int64_t CurOffsetInBits = 0;
2791 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
2792 if (ClassDecl->isDynamicClass())
2793 return std::nullopt;
2796 for (
const auto &
Base : ClassDecl->bases()) {
2799 Bases.emplace_back(
Base.getType()->getAsCXXRecordDecl());
2803 return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
2806 std::optional<int64_t> OffsetAfterBases =
2808 Bases, CurOffsetInBits, Context, Layout, CheckIfTriviallyCopyable);
2809 if (!OffsetAfterBases)
2810 return std::nullopt;
2811 CurOffsetInBits = *OffsetAfterBases;
2814 std::optional<int64_t> OffsetAfterFields =
2816 RD->
fields(), CurOffsetInBits, Context, Layout,
2817 CheckIfTriviallyCopyable);
2818 if (!OffsetAfterFields)
2819 return std::nullopt;
2820 CurOffsetInBits = *OffsetAfterFields;
2822 return CurOffsetInBits;
2826 QualType Ty,
bool CheckIfTriviallyCopyable)
const {
2844 assert(!Ty.
isNull() &&
"Null QualType sent to unique object rep check");
2849 CheckIfTriviallyCopyable);
2869 return !ABI->getMemberPointerInfo(MPT).HasPadding;
2874 if (Record->isInvalidDecl())
2877 if (Record->isUnion())
2879 CheckIfTriviallyCopyable);
2882 *
this, Record, CheckIfTriviallyCopyable);
2884 return StructSize && *StructSize ==
static_cast<int64_t
>(
getTypeSize(Ty));
2905 count += Ext->ivar_size();
2910 count += ImplDecl->ivar_size();
2928 if (isa<GNUNullExpr>(E))
return true;
2936 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2937 I = ObjCImpls.find(D);
2938 if (I != ObjCImpls.end())
2939 return cast<ObjCImplementationDecl>(I->second);
2946 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2947 I = ObjCImpls.find(D);
2948 if (I != ObjCImpls.end())
2949 return cast<ObjCCategoryImplDecl>(I->second);
2956 assert(IFaceD && ImplD &&
"Passed null params");
2957 ObjCImpls[IFaceD] = ImplD;
2963 assert(CatD && ImplD &&
"Passed null params");
2964 ObjCImpls[CatD] = ImplD;
2969 return ObjCMethodRedecls.lookup(MD);
2975 ObjCMethodRedecls[MD] = Redecl;
2980 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND->
getDeclContext()))
2982 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND->
getDeclContext()))
2983 return CD->getClassInterface();
2984 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(ND->
getDeclContext()))
2985 return IMD->getClassInterface();
2993 assert(VD &&
"Passed null params");
2994 assert(VD->
hasAttr<BlocksAttr>() &&
2995 "getBlockVarCopyInits - not __block var");
2996 auto I = BlockVarCopyInits.find(VD);
2997 if (I != BlockVarCopyInits.end())
2999 return {
nullptr,
false};
3005 assert(VD && CopyExpr &&
"Passed null params");
3006 assert(VD->
hasAttr<BlocksAttr>() &&
3007 "setBlockVarCopyInits - not __block var");
3008 BlockVarCopyInits[VD].setExprAndFlag(CopyExpr,
CanThrow);
3012 unsigned DataSize)
const {
3017 "incorrect data size provided to CreateTypeSourceInfo!");
3034 return getObjCLayout(D,
nullptr);
3045 bool &AnyNonCanonArgs) {
3047 for (
auto &Arg : CanonArgs) {
3049 Arg =
C.getCanonicalTemplateArgument(Arg);
3050 AnyNonCanonArgs |= !Arg.structurallyEquals(OrigArg);
3060ASTContext::getExtQualType(
const Type *baseType,
Qualifiers quals)
const {
3065 llvm::FoldingSetNodeID
ID;
3067 void *insertPos =
nullptr;
3068 if (
ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) {
3069 assert(eq->getQualifiers() == quals);
3078 canon = getExtQualType(canonSplit.
Ty, canonSplit.
Quals);
3081 (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos);
3085 ExtQualNodes.InsertNode(eq, insertPos);
3090 LangAS AddressSpace)
const {
3103 "Type cannot be in multiple addr spaces!");
3106 return getExtQualType(TypeNode, Quals);
3118 const Type *TypeNode;
3121 TypeNode = Quals.
strip(T);
3125 if (!
QualType(TypeNode, 0).hasAddressSpace())
3138 return getExtQualType(TypeNode, Quals);
3165 "Type cannot have multiple ObjCGCs!");
3168 return getExtQualType(TypeNode, Quals);
3187 if (
const auto *FNPT = dyn_cast<FunctionNoProtoType>(T)) {
3190 const auto *FPT = cast<FunctionProtoType>(T);
3196 return cast<FunctionType>(
Result.getTypePtr());
3212 L->DeducedReturnType(FD, ResultType);
3222 if (
const auto *PT = dyn_cast<ParenType>(Orig))
3227 if (
const auto *MQT = dyn_cast<MacroQualifiedType>(Orig))
3230 MQT->getMacroIdentifier());
3233 if (
const auto *AT = dyn_cast<AttributedType>(Orig))
3243 Proto->getReturnType(), Proto->getParamTypes(),
3244 Proto->getExtProtoInfo().withExceptionSpec(ESI));
3259 for (
unsigned i = 0, n = Args.size(); i != n; ++i)
3293 if (TSInfo->getType() != FD->
getType())
3301 "TypeLoc size mismatch from updating exception specification");
3302 TSInfo->overrideType(Updated);
3311 llvm::FoldingSetNodeID ID;
3314 void *InsertPos =
nullptr;
3315 if (
ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos))
3325 ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos);
3326 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3329 Types.push_back(New);
3330 ComplexTypes.InsertNode(New, InsertPos);
3339 llvm::FoldingSetNodeID ID;
3342 void *InsertPos =
nullptr;
3343 if (
PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3353 PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3354 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3357 Types.push_back(New);
3358 PointerTypes.InsertNode(New, InsertPos);
3363 llvm::FoldingSetNodeID ID;
3365 void *InsertPos =
nullptr;
3366 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3373 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3374 assert(!AT &&
"Shouldn't be in the map!");
3378 Types.push_back(AT);
3379 AdjustedTypes.InsertNode(AT, InsertPos);
3384 llvm::FoldingSetNodeID ID;
3386 void *InsertPos =
nullptr;
3387 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3394 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3395 assert(!AT &&
"Shouldn't be in the map!");
3398 Types.push_back(AT);
3399 AdjustedTypes.InsertNode(AT, InsertPos);
3432 llvm::FoldingSetNodeID ID;
3435 void *InsertPos =
nullptr;
3437 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3448 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3449 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3452 Types.push_back(New);
3453 BlockPointerTypes.InsertNode(New, InsertPos);
3463 "Unresolved placeholder type");
3467 llvm::FoldingSetNodeID ID;
3470 void *InsertPos =
nullptr;
3472 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3480 if (!SpelledAsLValue || InnerRef || !T.
isCanonical()) {
3481 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3486 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3487 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3492 Types.push_back(New);
3493 LValueReferenceTypes.InsertNode(New, InsertPos);
3503 "Unresolved placeholder type");
3507 llvm::FoldingSetNodeID ID;
3510 void *InsertPos =
nullptr;
3512 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3521 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() : T);
3526 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3527 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3531 Types.push_back(New);
3532 RValueReferenceTypes.InsertNode(New, InsertPos);
3541 llvm::FoldingSetNodeID ID;
3544 void *InsertPos =
nullptr;
3546 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3557 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3558 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3561 Types.push_back(New);
3562 MemberPointerTypes.InsertNode(New, InsertPos);
3569 const llvm::APInt &ArySizeIn,
3570 const Expr *SizeExpr,
3572 unsigned IndexTypeQuals)
const {
3575 "Constant array of VLAs is illegal!");
3583 llvm::APInt ArySize(ArySizeIn);
3586 llvm::FoldingSetNodeID ID;
3590 void *InsertPos =
nullptr;
3592 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos))
3603 ASM, IndexTypeQuals);
3608 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos);
3609 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3613 ConstantArrayType::totalSizeToAlloc<const Expr *>(SizeExpr ? 1 : 0),
3615 auto *New =
new (Mem)
3617 ConstantArrayTypes.InsertNode(New, InsertPos);
3618 Types.push_back(New);
3627 if (!
type->isVariablyModifiedType())
return type;
3632 const Type *ty = split.
Ty;
3634#define TYPE(Class, Base)
3635#define ABSTRACT_TYPE(Class, Base)
3636#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3637#include "clang/AST/TypeNodes.inc"
3638 llvm_unreachable(
"didn't desugar past all non-canonical types?");
3644 case Type::DependentVector:
3645 case Type::ExtVector:
3646 case Type::DependentSizedExtVector:
3647 case Type::ConstantMatrix:
3648 case Type::DependentSizedMatrix:
3649 case Type::DependentAddressSpace:
3650 case Type::ObjCObject:
3651 case Type::ObjCInterface:
3652 case Type::ObjCObjectPointer:
3655 case Type::UnresolvedUsing:
3656 case Type::TypeOfExpr:
3658 case Type::Decltype:
3659 case Type::UnaryTransform:
3660 case Type::DependentName:
3661 case Type::InjectedClassName:
3662 case Type::TemplateSpecialization:
3663 case Type::DependentTemplateSpecialization:
3664 case Type::TemplateTypeParm:
3665 case Type::SubstTemplateTypeParmPack:
3667 case Type::DeducedTemplateSpecialization:
3668 case Type::PackExpansion:
3670 case Type::DependentBitInt:
3671 llvm_unreachable(
"type should never be variably-modified");
3675 case Type::FunctionNoProto:
3676 case Type::FunctionProto:
3677 case Type::BlockPointer:
3678 case Type::MemberPointer:
3688 cast<PointerType>(ty)->getPointeeType()));
3691 case Type::LValueReference: {
3692 const auto *lv = cast<LValueReferenceType>(ty);
3695 lv->isSpelledAsLValue());
3699 case Type::RValueReference: {
3700 const auto *lv = cast<RValueReferenceType>(ty);
3706 case Type::Atomic: {
3707 const auto *at = cast<AtomicType>(ty);
3712 case Type::ConstantArray: {
3713 const auto *cat = cast<ConstantArrayType>(ty);
3718 cat->getSizeModifier(),
3719 cat->getIndexTypeCVRQualifiers());
3723 case Type::DependentSizedArray: {
3724 const auto *dat = cast<DependentSizedArrayType>(ty);
3728 dat->getSizeModifier(),
3729 dat->getIndexTypeCVRQualifiers(),
3730 dat->getBracketsRange());
3735 case Type::IncompleteArray: {
3736 const auto *iat = cast<IncompleteArrayType>(ty);
3741 iat->getIndexTypeCVRQualifiers(),
3747 case Type::VariableArray: {
3748 const auto *vat = cast<VariableArrayType>(ty);
3753 vat->getIndexTypeCVRQualifiers(),
3754 vat->getBracketsRange());
3768 unsigned IndexTypeQuals,
3779 IndexTypeQuals, Brackets);
3786 VariableArrayTypes.push_back(New);
3787 Types.push_back(New);
3797 unsigned elementTypeQuals,
3801 "Size must be type- or value-dependent!");
3811 numElements, ASM, elementTypeQuals,
3813 Types.push_back(newType);
3822 void *insertPos =
nullptr;
3823 llvm::FoldingSetNodeID ID;
3826 ASM, elementTypeQuals, numElements);
3830 DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos);
3836 QualType(), numElements, ASM, elementTypeQuals,
3838 DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
3839 Types.push_back(canonTy);
3844 canonElementType.
Quals);
3848 if (
QualType(canonElementType.
Ty, 0) == elementType &&
3857 ASM, elementTypeQuals, brackets);
3858 Types.push_back(sugaredType);
3864 unsigned elementTypeQuals)
const {
3865 llvm::FoldingSetNodeID ID;
3868 void *insertPos =
nullptr;
3870 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos))
3882 ASM, elementTypeQuals);
3887 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos);
3888 assert(!existing &&
"Shouldn't be in the map!"); (void) existing;
3894 IncompleteArrayTypes.InsertNode(newType, insertPos);
3895 Types.push_back(newType);
3901#define SVE_INT_ELTTY(BITS, ELTS, SIGNED, NUMVECTORS) \
3902 {getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount::getScalable(ELTS), \
3905#define SVE_ELTTY(ELTTY, ELTS, NUMVECTORS) \
3906 {ELTTY, llvm::ElementCount::getScalable(ELTS), NUMVECTORS};
3910 llvm_unreachable(
"Unsupported builtin vector type");
3911 case BuiltinType::SveInt8:
3913 case BuiltinType::SveUint8:
3915 case BuiltinType::SveInt8x2:
3917 case BuiltinType::SveUint8x2:
3919 case BuiltinType::SveInt8x3:
3921 case BuiltinType::SveUint8x3:
3923 case BuiltinType::SveInt8x4:
3925 case BuiltinType::SveUint8x4:
3927 case BuiltinType::SveInt16:
3929 case BuiltinType::SveUint16:
3931 case BuiltinType::SveInt16x2:
3933 case BuiltinType::SveUint16x2:
3935 case BuiltinType::SveInt16x3:
3937 case BuiltinType::SveUint16x3:
3939 case BuiltinType::SveInt16x4:
3941 case BuiltinType::SveUint16x4:
3943 case BuiltinType::SveInt32:
3945 case BuiltinType::SveUint32:
3947 case BuiltinType::SveInt32x2:
3949 case BuiltinType::SveUint32x2:
3951 case BuiltinType::SveInt32x3:
3953 case BuiltinType::SveUint32x3:
3955 case BuiltinType::SveInt32x4:
3957 case BuiltinType::SveUint32x4:
3959 case BuiltinType::SveInt64:
3961 case BuiltinType::SveUint64:
3963 case BuiltinType::SveInt64x2:
3965 case BuiltinType::SveUint64x2:
3967 case BuiltinType::SveInt64x3:
3969 case BuiltinType::SveUint64x3:
3971 case BuiltinType::SveInt64x4:
3973 case BuiltinType::SveUint64x4:
3975 case BuiltinType::SveBool:
3977 case BuiltinType::SveBoolx2:
3979 case BuiltinType::SveBoolx4:
3981 case BuiltinType::SveFloat16:
3983 case BuiltinType::SveFloat16x2:
3985 case BuiltinType::SveFloat16x3:
3987 case BuiltinType::SveFloat16x4:
3989 case BuiltinType::SveFloat32:
3991 case BuiltinType::SveFloat32x2:
3993 case BuiltinType::SveFloat32x3:
3995 case BuiltinType::SveFloat32x4:
3997 case BuiltinType::SveFloat64:
3999 case BuiltinType::SveFloat64x2:
4001 case BuiltinType::SveFloat64x3:
4003 case BuiltinType::SveFloat64x4:
4005 case BuiltinType::SveBFloat16:
4007 case BuiltinType::SveBFloat16x2:
4009 case BuiltinType::SveBFloat16x3:
4011 case BuiltinType::SveBFloat16x4:
4013#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
4015 case BuiltinType::Id: \
4016 return {getIntTypeForBitwidth(ElBits, IsSigned), \
4017 llvm::ElementCount::getScalable(NumEls), NF};
4018#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
4019 case BuiltinType::Id: \
4020 return {ElBits == 16 ? Float16Ty : (ElBits == 32 ? FloatTy : DoubleTy), \
4021 llvm::ElementCount::getScalable(NumEls), NF};
4022#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4023 case BuiltinType::Id: \
4024 return {BoolTy, llvm::ElementCount::getScalable(NumEls), 1};
4025#include "clang/Basic/RISCVVTypes.def"
4033#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
4034 if (BuiltinType::Id == BuiltinType::WasmExternRef) \
4036#include "clang/Basic/WebAssemblyReferenceTypes.def"
4039 "shouldn't try to generate type externref outside WebAssembly target");
4046 unsigned NumFields)
const {
4049#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
4050 IsSigned, IsFP, IsBF) \
4051 if (!EltTy->isBooleanType() && \
4052 ((EltTy->hasIntegerRepresentation() && \
4053 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4054 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
4056 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
4057 IsBF && !IsFP)) && \
4058 EltTySize == ElBits && NumElts == NumEls) { \
4059 return SingletonId; \
4061#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
4062 if (EltTy->isBooleanType() && NumElts == NumEls) \
4064#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingleTonId)
4065#include "clang/Basic/AArch64SVEACLETypes.def"
4068#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
4070 if (!EltTy->isBooleanType() && \
4071 ((EltTy->hasIntegerRepresentation() && \
4072 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4073 (EltTy->hasFloatingRepresentation() && IsFP)) && \
4074 EltTySize == ElBits && NumElts == NumEls && NumFields == NF) \
4076#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4077 if (EltTy->isBooleanType() && NumElts == NumEls) \
4079#include "clang/Basic/RISCVVTypes.def"
4095 llvm::FoldingSetNodeID ID;
4098 void *InsertPos =
nullptr;
4099 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4109 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4110 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4113 VectorType(vecType, NumElts, Canonical, VecKind);
4114 VectorTypes.InsertNode(New, InsertPos);
4115 Types.push_back(New);
4123 llvm::FoldingSetNodeID ID;
4126 void *InsertPos =
nullptr;
4128 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4133 *
this, VecType,
QualType(Canon, 0), SizeExpr, AttrLoc, VecKind);
4136 if (CanonVecTy == VecType) {
4138 *
this, VecType,
QualType(), SizeExpr, AttrLoc, VecKind);
4141 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4142 assert(!CanonCheck &&
4143 "Dependent-sized vector_size canonical type broken");
4145 DependentVectorTypes.InsertNode(New, InsertPos);
4150 *
this, VecType, CanonTy, SizeExpr, AttrLoc, VecKind);
4154 Types.push_back(New);
4161 unsigned NumElts)
const {
4169 llvm::FoldingSetNodeID ID;
4172 void *InsertPos =
nullptr;
4173 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4183 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4184 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4188 VectorTypes.InsertNode(New, InsertPos);
4189 Types.push_back(New);
4197 llvm::FoldingSetNodeID ID;
4201 void *InsertPos =
nullptr;
4203 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4213 if (CanonVecTy == vecType) {
4219 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4220 assert(!CanonCheck &&
"Dependent-sized ext_vector canonical type broken");
4222 DependentSizedExtVectorTypes.InsertNode(New, InsertPos);
4227 *
this, vecType, CanonExtTy, SizeExpr, AttrLoc);
4231 Types.push_back(New);
4236 unsigned NumColumns)
const {
4237 llvm::FoldingSetNodeID ID;
4239 Type::ConstantMatrix);
4242 "need a valid element type");
4245 "need valid matrix dimensions");
4246 void *InsertPos =
nullptr;
4256 assert(!NewIP &&
"Matrix type shouldn't already exist in the map");
4262 MatrixTypes.InsertNode(New, InsertPos);
4263 Types.push_back(New);
4272 llvm::FoldingSetNodeID ID;
4276 void *InsertPos =
nullptr;
4278 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4282 *
this, CanonElementTy,
QualType(), RowExpr, ColumnExpr, AttrLoc);
4285 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4286 assert(!CanonCheck &&
"Dependent-sized matrix canonical type broken");
4288 DependentSizedMatrixTypes.InsertNode(Canon, InsertPos);
4289 Types.push_back(Canon);
4302 ColumnExpr, AttrLoc);
4303 Types.push_back(New);
4308 Expr *AddrSpaceExpr,
4314 void *insertPos =
nullptr;
4315 llvm::FoldingSetNodeID ID;
4320 DependentAddressSpaceTypes.FindNodeOrInsertPos(ID, insertPos);
4325 QualType(), AddrSpaceExpr, AttrLoc);
4326 DependentAddressSpaceTypes.InsertNode(canonTy, insertPos);
4327 Types.push_back(canonTy);
4330 if (canonPointeeType == PointeeType &&
4337 AddrSpaceExpr, AttrLoc);
4338 Types.push_back(sugaredType);
4362 llvm::FoldingSetNodeID ID;
4365 void *InsertPos =
nullptr;
4367 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos))
4377 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4378 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4383 Types.push_back(New);
4384 FunctionNoProtoTypes.InsertNode(New, InsertPos);
4400 return CanResultType;
4407 if (!NoexceptInType)
4424 bool AnyPackExpansions =
false;
4429 AnyPackExpansions =
true;
4431 return AnyPackExpansions;
4437QualType ASTContext::getFunctionTypeInternal(
4440 size_t NumArgs = ArgArray.size();
4444 llvm::FoldingSetNodeID
ID;
4449 bool Unique =
false;
4451 void *InsertPos =
nullptr;
4453 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) {
4473 bool IsCanonicalExceptionSpec =
4477 bool isCanonical = !Unique && IsCanonicalExceptionSpec &&
4479 for (
unsigned i = 0; i != NumArgs && isCanonical; ++i)
4480 if (!ArgArray[i].isCanonicalAsParam())
4481 isCanonical =
false;
4483 if (OnlyWantCanonical)
4484 assert(isCanonical &&
4485 "given non-canonical parameters constructing canonical type");
4490 if (!isCanonical && Canonical.
isNull()) {
4492 CanonicalArgs.reserve(NumArgs);
4493 for (
unsigned i = 0; i != NumArgs; ++i)
4500 if (IsCanonicalExceptionSpec) {
4502 }
else if (NoexceptInType) {
4515 bool AnyPacks =
false;
4538 llvm_unreachable(
"dependent noexcept is already canonical");
4547 getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI,
true);
4551 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4552 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4557 auto ESH = FunctionProtoType::getExceptionSpecSize(
4559 size_t Size = FunctionProtoType::totalSizeToAlloc<
4564 ESH.NumExceptionType, ESH.NumExprPtr, ESH.NumFunctionDeclPtr,
4571 Types.push_back(FTP);
4573 FunctionProtoTypes.InsertNode(FTP, InsertPos);
4578 llvm::FoldingSetNodeID
ID;
4581 void *InsertPos =
nullptr;
4582 if (
PipeType *PT = PipeTypes.FindNodeOrInsertPos(ID, InsertPos))
4592 PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(ID, InsertPos);
4593 assert(!NewIP &&
"Shouldn't be in the map!");
4597 Types.push_back(New);
4598 PipeTypes.InsertNode(New, InsertPos);
4609 return getPipeType(T,
true);
4613 return getPipeType(T,
false);
4617 llvm::FoldingSetNodeID ID;
4620 void *InsertPos =
nullptr;
4621 if (
BitIntType *EIT = BitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
4625 BitIntTypes.InsertNode(New, InsertPos);
4626 Types.push_back(New);
4631 Expr *NumBitsExpr)
const {
4633 llvm::FoldingSetNodeID ID;
4636 void *InsertPos =
nullptr;
4638 DependentBitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
4643 DependentBitIntTypes.InsertNode(New, InsertPos);
4645 Types.push_back(New);
4651 if (!isa<CXXRecordDecl>(D))
return false;
4652 const auto *RD = cast<CXXRecordDecl>(D);
4653 if (isa<ClassTemplatePartialSpecializationDecl>(RD))
4655 if (RD->getDescribedClassTemplate() &&
4656 !isa<ClassTemplateSpecializationDecl>(RD))
4667 if (
Decl->TypeForDecl) {
4668 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4670 assert(PrevDecl->TypeForDecl &&
"previous declaration has no type");
4671 Decl->TypeForDecl = PrevDecl->TypeForDecl;
4672 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
4676 Decl->TypeForDecl = newType;
4677 Types.push_back(newType);
4685 assert(
Decl &&
"Passed null for Decl param");
4686 assert(!
Decl->TypeForDecl &&
"TypeForDecl present in slow case");
4688 if (
const auto *Typedef = dyn_cast<TypedefNameDecl>(
Decl))
4691 assert(!isa<TemplateTypeParmDecl>(
Decl) &&
4692 "Template type parameter types are always available.");
4694 if (
const auto *Record = dyn_cast<RecordDecl>(
Decl)) {
4695 assert(Record->isFirstDecl() &&
"struct/union has previous declaration");
4698 }
else if (
const auto *
Enum = dyn_cast<EnumDecl>(
Decl)) {
4699 assert(
Enum->isFirstDecl() &&
"enum has previous declaration");
4701 }
else if (
const auto *Using = dyn_cast<UnresolvedUsingTypenameDecl>(
Decl)) {
4704 llvm_unreachable(
"TypeDecl without a type?");
4713 if (!
Decl->TypeForDecl) {
4715 Underlying =
Decl->getUnderlyingType();
4718 Decl->TypeForDecl = NewType;
4719 Types.push_back(NewType);
4722 if (Underlying.
isNull() ||
Decl->getUnderlyingType() == Underlying)
4726 llvm::FoldingSetNodeID ID;
4729 void *InsertPos =
nullptr;
4730 if (
TypedefType *T = TypedefTypes.FindNodeOrInsertPos(ID, InsertPos)) {
4731 assert(!T->typeMatchesDecl() &&
4732 "non-divergent case should be handled with TypeDecl");
4738 auto *NewType =
new (Mem)
TypedefType(Type::Typedef,
Decl, Underlying,
4740 TypedefTypes.InsertNode(NewType, InsertPos);
4741 Types.push_back(NewType);
4747 llvm::FoldingSetNodeID ID;
4750 void *InsertPos =
nullptr;
4751 if (
UsingType *T = UsingTypes.FindNodeOrInsertPos(ID, InsertPos))
4754 const Type *TypeForDecl =
4764 Allocate(UsingType::totalSizeToAlloc<QualType>(!Underlying.
isNull()),
4767 Types.push_back(NewType);
4768 UsingTypes.InsertNode(NewType, InsertPos);
4776 if (PrevDecl->TypeForDecl)
4777 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4780 Decl->TypeForDecl = newType;
4781 Types.push_back(newType);
4789 if (PrevDecl->TypeForDecl)
4790 return QualType(
Decl->TypeForDecl = PrevDecl->TypeForDecl, 0);
4793 Decl->TypeForDecl = newType;
4794 Types.push_back(newType);
4800 if (
Decl->TypeForDecl)
4805 if (CanonicalDecl->TypeForDecl)
4806 return QualType(
Decl->TypeForDecl = CanonicalDecl->TypeForDecl, 0);
4809 Decl->TypeForDecl = newType;
4810 Types.push_back(newType);
4817 llvm::FoldingSetNodeID id;
4820 void *insertPos =
nullptr;
4828 Types.push_back(
type);
4829 AttributedTypes.InsertNode(
type, insertPos);
4836 llvm::FoldingSetNodeID ID;
4839 void *InsertPos =
nullptr;
4841 BTFTagAttributedTypes.FindNodeOrInsertPos(ID, InsertPos);
4848 Types.push_back(Ty);
4849 BTFTagAttributedTypes.InsertNode(Ty, InsertPos);
4856 QualType Replacement,
Decl *AssociatedDecl,
unsigned Index,
4857 std::optional<unsigned> PackIndex)
const {
4858 llvm::FoldingSetNodeID ID;
4861 void *InsertPos =
nullptr;
4863 SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4866 void *Mem =
Allocate(SubstTemplateTypeParmType::totalSizeToAlloc<QualType>(
4871 Types.push_back(SubstParm);
4872 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
4881 unsigned Index,
bool Final,
4888 llvm::FoldingSetNodeID ID;
4891 void *InsertPos =
nullptr;
4893 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos))
4903 [[maybe_unused]]
const auto *Nothing =
4904 SubstTemplateTypeParmPackTypes.FindNodeOrInsertPos(ID, InsertPos);
4910 Canon, AssociatedDecl, Index, Final, ArgPack);
4911 Types.push_back(SubstParm);
4912 SubstTemplateTypeParmPackTypes.InsertNode(SubstParm, InsertPos);
4922 llvm::FoldingSetNodeID ID;
4924 void *InsertPos =
nullptr;
4926 = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4936 = TemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
4937 assert(!TypeCheck &&
"Template type parameter canonical type broken");
4943 Types.push_back(TypeParm);
4944 TemplateTypeParmTypes.InsertNode(TypeParm, InsertPos);
4954 assert(!Name.getAsDependentTemplateName() &&
4955 "No dependent template names here!");
4966 for (
unsigned i = 0, e = TL.
getNumArgs(); i != e; ++i)
4976 "No dependent template names here!");
4979 ArgVec.reserve(Args.size());
4981 ArgVec.push_back(Arg.getArgument());
4989 if (Arg.isPackExpansion())
5001 "No dependent template names here!");
5004 Template = QTN->getUnderlyingTemplate();
5009 if (!Underlying.
isNull())
5015 "Caller must compute aliased type");
5016 IsTypeAlias =
false;
5025 (IsTypeAlias?
sizeof(
QualType) : 0),
5029 IsTypeAlias ? Underlying :
QualType());
5031 Types.push_back(Spec);
5038 "No dependent template names here!");
5046 bool AnyNonCanonArgs =
false;
5052 llvm::FoldingSetNodeID ID;
5056 void *InsertPos =
nullptr;
5058 = TemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
5068 Types.push_back(Spec);
5069 TemplateSpecializationTypes.InsertNode(Spec, InsertPos);
5073 "Non-dependent template-id type must have a canonical type");
5080 TagDecl *OwnedTagDecl)
const {
5081 llvm::FoldingSetNodeID ID;
5084 void *InsertPos =
nullptr;
5085 ElaboratedType *T = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos);
5092 ElaboratedType *CheckT = ElaboratedTypes.FindNodeOrInsertPos(ID, InsertPos);
5093 assert(!CheckT &&
"Elaborated canonical type broken");
5097 void *Mem =
Allocate(ElaboratedType::totalSizeToAlloc<TagDecl *>(!!OwnedTagDecl),
5099 T =
new (Mem)
ElaboratedType(Keyword, NNS, NamedType, Canon, OwnedTagDecl);
5102 ElaboratedTypes.InsertNode(T, InsertPos);
5108 llvm::FoldingSetNodeID ID;
5111 void *InsertPos =
nullptr;
5112 ParenType *T = ParenTypes.FindNodeOrInsertPos(ID, InsertPos);
5119 ParenType *CheckT = ParenTypes.FindNodeOrInsertPos(ID, InsertPos);
5120 assert(!CheckT &&
"Paren canonical type broken");
5126 ParenTypes.InsertNode(T, InsertPos);
5139 Types.push_back(newType);
5149 if (CanonNNS != NNS)
5153 llvm::FoldingSetNodeID ID;
5156 void *InsertPos =
nullptr;
5158 = DependentNameTypes.FindNodeOrInsertPos(ID, InsertPos);
5164 DependentNameTypes.InsertNode(T, InsertPos);
5173 for (
unsigned I = 0, E = Args.size(); I != E; ++I)
5174 ArgCopy.push_back(Args[I].