69#include "llvm/ADT/APFixedPoint.h"
70#include "llvm/ADT/APInt.h"
71#include "llvm/ADT/APSInt.h"
72#include "llvm/ADT/ArrayRef.h"
73#include "llvm/ADT/DenseMap.h"
74#include "llvm/ADT/DenseSet.h"
75#include "llvm/ADT/FoldingSet.h"
76#include "llvm/ADT/PointerUnion.h"
77#include "llvm/ADT/STLExtras.h"
78#include "llvm/ADT/SmallPtrSet.h"
79#include "llvm/ADT/SmallVector.h"
80#include "llvm/ADT/StringExtras.h"
81#include "llvm/ADT/StringRef.h"
82#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
83#include "llvm/Support/Capacity.h"
84#include "llvm/Support/Casting.h"
85#include "llvm/Support/Compiler.h"
86#include "llvm/Support/ErrorHandling.h"
87#include "llvm/Support/MD5.h"
88#include "llvm/Support/MathExtras.h"
89#include "llvm/Support/SipHash.h"
90#include "llvm/Support/raw_ostream.h"
91#include "llvm/TargetParser/AArch64TargetParser.h"
92#include "llvm/TargetParser/Triple.h"
105using namespace clang;
129 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
134 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
135 if (VD->isStaticDataMember() &&
140 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(
D)) {
145 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(
D)) {
152 if (
const auto *ED = dyn_cast<EnumDecl>(
D)) {
156 if (
const auto *TD = dyn_cast<TagDecl>(
D)) {
159 if (TD->isEmbeddedInDeclarator() && !TD->isCompleteDefinition())
163 if (isa<ParmVarDecl>(
D))
168 if (isa<TemplateTypeParmDecl>(
D) ||
169 isa<NonTypeTemplateParmDecl>(
D) ||
170 isa<TemplateTemplateParmDecl>(
D))
181 if (isa<ObjCMethodDecl>(
D) || isa<ObjCContainerDecl>(
D) ||
182 isa<ObjCPropertyDecl>(
D) || isa<RedeclarableTemplateDecl>(
D) ||
183 isa<ClassTemplateSpecializationDecl>(
D) ||
191 Locations.emplace_back(BaseLocation);
219 const std::map<unsigned, RawComment *> &CommentsInTheFile)
const {
222 if (RepresentativeLocForDecl.
isInvalid() ||
223 !RepresentativeLocForDecl.
isFileID())
227 if (CommentsInTheFile.empty())
232 const std::pair<FileID, unsigned> DeclLocDecomp =
236 auto OffsetCommentBehindDecl =
237 CommentsInTheFile.lower_bound(DeclLocDecomp.second);
240 if (OffsetCommentBehindDecl != CommentsInTheFile.end()) {
241 RawComment *CommentBehindDecl = OffsetCommentBehindDecl->second;
245 (isa<FieldDecl>(
D) || isa<EnumConstantDecl>(
D) || isa<VarDecl>(
D) ||
246 isa<ObjCMethodDecl>(
D) || isa<ObjCPropertyDecl>(
D))) {
250 if (SourceMgr.
getLineNumber(DeclLocDecomp.first, DeclLocDecomp.second) ==
252 OffsetCommentBehindDecl->first)) {
253 return CommentBehindDecl;
260 if (OffsetCommentBehindDecl == CommentsInTheFile.begin())
263 auto OffsetCommentBeforeDecl = --OffsetCommentBehindDecl;
264 RawComment *CommentBeforeDecl = OffsetCommentBeforeDecl->second;
273 const unsigned CommentEndOffset =
278 const char *Buffer = SourceMgr.
getBufferData(DeclLocDecomp.first,
284 StringRef
Text(Buffer + CommentEndOffset,
285 DeclLocDecomp.second - CommentEndOffset);
289 if (
Text.find_last_of(
";{}#@") != StringRef::npos)
292 return CommentBeforeDecl;
298 for (
const auto DeclLoc : DeclLocs) {
301 if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
317 if (!CommentsInThisFile || CommentsInThisFile->empty())
329 assert(LangOpts.RetainCommentsFromSystemHeaders ||
338 if (
const auto *FD = dyn_cast<FunctionDecl>(&
D)) {
358 if (
const auto *VD = dyn_cast<VarDecl>(&
D)) {
361 if (VD->isStaticDataMember())
367 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(&
D)) {
374 if (
const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(CRD)) {
382 : *
static_cast<const Decl *
>(
388 CRD->getMemberSpecializationInfo())
389 return *Info->getInstantiatedFrom();
393 if (
const auto *ED = dyn_cast<EnumDecl>(&
D)) {
406 const Decl **OriginalDecl)
const {
409 OriginalDecl =
nullptr;
421 return DeclComment->second;
434 *OriginalDecl = RedeclComment->second;
437 "This decl is supposed to have comment attached.");
438 return CommentAtRedecl->second;
444 auto LastCheckedRedecl = [
this, CanonicalD]() ->
const Decl * {
448 for (
const auto Redecl :
D->
redecls()) {
451 if (LastCheckedRedecl) {
452 if (LastCheckedRedecl == Redecl) {
453 LastCheckedRedecl =
nullptr;
461 *OriginalDecl = Redecl;
462 return RedeclComment;
468 *OriginalDecl =
nullptr;
484 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(DC)) {
489 for (
const auto *Ext : ID->known_extensions()) {
493 Redeclared.push_back(RedeclaredMethod);
504 for (
const Decl *
D : Decls) {
518 if (
File.isInvalid())
522 if (!CommentsInThisFile || CommentsInThisFile->empty() ||
523 CommentsInThisFile->rbegin()->second->isAttached())
533 for (
const Decl *
D : Decls) {
545 for (
const auto DeclLoc : DeclLocs) {
546 if (DeclLoc.isInvalid() || !DeclLoc.isFileID())
550 D, DeclLoc, *CommentsInThisFile)) {
561 const Decl *
D)
const {
564 ThisDeclInfo->IsFilled =
false;
565 ThisDeclInfo->fill();
566 ThisDeclInfo->CommentDecl = FC->
getDecl();
567 if (!ThisDeclInfo->TemplateParameters)
577 return RC ? RC->
parse(*
this,
nullptr,
D) :
nullptr;
588 llvm::DenseMap<const Decl *, comments::FullComment *>::iterator Pos =
592 if (Canonical !=
D) {
600 const Decl *OriginalDecl =
nullptr;
604 if (isa<ObjCMethodDecl>(
D) || isa<FunctionDecl>(
D)) {
606 const auto *OMD = dyn_cast<ObjCMethodDecl>(
D);
607 if (OMD && OMD->isPropertyAccessor())
614 for (
unsigned i = 0, e = Overridden.size(); i < e; i++)
618 else if (
const auto *TD = dyn_cast<TypedefNameDecl>(
D)) {
621 QualType QT = TD->getUnderlyingType();
623 if (
const Decl *TD = TT->getDecl())
627 else if (
const auto *IC = dyn_cast<ObjCInterfaceDecl>(
D)) {
628 while (IC->getSuperClass()) {
629 IC = IC->getSuperClass();
634 else if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(
D)) {
639 else if (
const auto *RD = dyn_cast<CXXRecordDecl>(
D)) {
640 if (!(RD = RD->getDefinition()))
643 for (
const auto &I : RD->bases()) {
644 if (I.isVirtual() || (I.getAccessSpecifier() !=
AS_public))
658 for (
const auto &I : RD->vbases()) {
679 if (
D != OriginalDecl && OriginalDecl)
688ASTContext::CanonicalTemplateTemplateParm::Profile(llvm::FoldingSetNodeID &ID,
696 ID.AddInteger(Params->
size());
698 PEnd = Params->
end();
700 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
702 ID.AddBoolean(TTP->isParameterPack());
703 if (TTP->isExpandedParameterPack()) {
705 ID.AddInteger(TTP->getNumExpansionParameters());
707 ID.AddBoolean(
false);
711 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
713 ID.AddBoolean(NTTP->isParameterPack());
714 ID.AddPointer(
C.getUnconstrainedType(
C.getCanonicalType(NTTP->getType()))
716 if (NTTP->isExpandedParameterPack()) {
718 ID.AddInteger(NTTP->getNumExpansionTypes());
719 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
721 ID.AddPointer(
T.getCanonicalType().getAsOpaquePtr());
724 ID.AddBoolean(
false);
728 auto *TTP = cast<TemplateTemplateParmDecl>(*
P);
735ASTContext::getCanonicalTemplateTemplateParmDecl(
738 llvm::FoldingSetNodeID
ID;
739 CanonicalTemplateTemplateParm::Profile(ID, *
this, TTP);
740 void *InsertPos =
nullptr;
741 CanonicalTemplateTemplateParm *Canonical
742 = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
744 return Canonical->getParam();
749 CanonParams.reserve(Params->
size());
751 PEnd = Params->
end();
755 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(*
P)) {
761 ? std::optional<unsigned>(TTP->getNumExpansionParameters())
763 CanonParams.push_back(NewTTP);
764 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*
P)) {
768 if (NTTP->isExpandedParameterPack()) {
771 for (
unsigned I = 0, N = NTTP->getNumExpansionTypes(); I != N; ++I) {
773 ExpandedTInfos.push_back(
781 NTTP->getPosition(),
nullptr,
791 NTTP->getPosition(),
nullptr,
793 NTTP->isParameterPack(),
796 CanonParams.push_back(Param);
798 CanonParams.push_back(getCanonicalTemplateTemplateParmDecl(
799 cast<TemplateTemplateParmDecl>(*
P)));
810 Canonical = CanonTemplateTemplateParms.FindNodeOrInsertPos(ID, InsertPos);
811 assert(!Canonical &&
"Shouldn't be in the map!");
815 Canonical =
new (*this) CanonicalTemplateTemplateParm(CanonTTP);
816 CanonTemplateTemplateParms.InsertNode(Canonical, InsertPos);
826 if (!LangOpts.CPlusPlus)
return nullptr;
829 case TargetCXXABI::AppleARM64:
830 case TargetCXXABI::Fuchsia:
831 case TargetCXXABI::GenericARM:
832 case TargetCXXABI::iOS:
833 case TargetCXXABI::WatchOS:
834 case TargetCXXABI::GenericAArch64:
835 case TargetCXXABI::GenericMIPS:
836 case TargetCXXABI::GenericItanium:
837 case TargetCXXABI::WebAssembly:
838 case TargetCXXABI::XL:
840 case TargetCXXABI::Microsoft:
843 llvm_unreachable(
"Invalid CXXABI type!");
847 if (!InterpContext) {
850 return *InterpContext.get();
856 return *ParentMapCtx.get();
861 switch (LangOpts.getAddressSpaceMapMangling()) {
869 llvm_unreachable(
"getAddressSpaceMapMangling() doesn't cover anything.");
875 : ConstantArrayTypes(this_(), ConstantArrayTypesLog2InitSize),
876 DependentSizedArrayTypes(this_()), DependentSizedExtVectorTypes(this_()),
877 DependentAddressSpaceTypes(this_()), DependentVectorTypes(this_()),
878 DependentSizedMatrixTypes(this_()),
879 FunctionProtoTypes(this_(), FunctionProtoTypesLog2InitSize),
880 DependentTypeOfExprTypes(this_()), DependentDecltypeTypes(this_()),
881 TemplateSpecializationTypes(this_()),
882 DependentTemplateSpecializationTypes(this_()), AutoTypes(this_()),
883 DependentBitIntTypes(this_()), SubstTemplateTemplateParmPacks(this_()),
884 ArrayParameterTypes(this_()), CanonTemplateTemplateParms(this_()),
885 SourceMgr(
SM), LangOpts(LOpts),
888 LangOpts.XRayNeverInstrumentFiles,
889 LangOpts.XRayAttrListFiles,
SM)),
892 BuiltinInfo(builtins), TUKind(TUKind), DeclarationNames(*this),
893 Comments(
SM), CommentCommandTraits(BumpAlloc, LOpts.CommentOpts),
894 CompCategories(this_()), LastSDM(nullptr, 0) {
901 ReleaseDeclContextMaps();
904 for (
auto &Pair : Deallocations)
905 (Pair.first)(Pair.second);
906 Deallocations.clear();
912 I = ObjCLayouts.begin(),
E = ObjCLayouts.end(); I !=
E; )
918 for (llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>::iterator
919 I = ASTRecordLayouts.begin(),
E = ASTRecordLayouts.end(); I !=
E; ) {
924 ASTRecordLayouts.clear();
926 for (llvm::DenseMap<const Decl*, AttrVec*>::iterator A = DeclAttrs.begin(),
927 AEnd = DeclAttrs.end();
929 A->second->~AttrVec();
932 for (
const auto &
Value : ModuleInitializers)
933 Value.second->~PerModuleInitializers();
934 ModuleInitializers.
clear();
940 TraversalScope = TopLevelDecls;
945 Deallocations.push_back({Callback,
Data});
954 llvm::errs() <<
"\n*** AST Context Stats:\n";
955 llvm::errs() <<
" " << Types.size() <<
" types total.\n";
957 unsigned counts[] = {
958#define TYPE(Name, Parent) 0,
959#define ABSTRACT_TYPE(Name, Parent)
960#include "clang/AST/TypeNodes.inc"
964 for (
unsigned i = 0, e = Types.size(); i != e; ++i) {
970 unsigned TotalBytes = 0;
971#define TYPE(Name, Parent) \
973 llvm::errs() << " " << counts[Idx] << " " << #Name \
974 << " types, " << sizeof(Name##Type) << " each " \
975 << "(" << counts[Idx] * sizeof(Name##Type) \
977 TotalBytes += counts[Idx] * sizeof(Name##Type); \
979#define ABSTRACT_TYPE(Name, Parent)
980#include "clang/AST/TypeNodes.inc"
982 llvm::errs() <<
"Total bytes = " << TotalBytes <<
"\n";
987 <<
" implicit default constructors created\n";
990 <<
" implicit copy constructors created\n";
994 <<
" implicit move constructors created\n";
997 <<
" implicit copy assignment operators created\n";
1001 <<
" implicit move assignment operators created\n";
1004 <<
" implicit destructors created\n";
1007 llvm::errs() <<
"\n";
1011 BumpAlloc.PrintStats();
1015 bool NotifyListeners) {
1016 if (NotifyListeners)
1025 if (It == MergedDefModules.end())
1028 auto &Merged = It->second;
1029 llvm::DenseSet<Module*>
Found;
1030 for (
Module *&M : Merged)
1031 if (!
Found.insert(M).second)
1033 llvm::erase(Merged,
nullptr);
1040 if (MergedIt == MergedDefModules.end())
1041 return std::nullopt;
1042 return MergedIt->second;
1045void ASTContext::PerModuleInitializers::resolve(
ASTContext &Ctx) {
1046 if (LazyInitializers.empty())
1050 assert(Source &&
"lazy initializers but no external source");
1052 auto LazyInits = std::move(LazyInitializers);
1053 LazyInitializers.clear();
1055 for (
auto ID : LazyInits)
1056 Initializers.push_back(Source->GetExternalDecl(ID));
1058 assert(LazyInitializers.empty() &&
1059 "GetExternalDecl for lazy module initializer added more inits");
1065 if (
const auto *ID = dyn_cast<ImportDecl>(
D)) {
1066 auto It = ModuleInitializers.find(ID->getImportedModule());
1069 if (It == ModuleInitializers.end())
1073 auto &Imported = *It->second;
1074 if (Imported.Initializers.size() + Imported.LazyInitializers.size() == 1) {
1075 Imported.resolve(*
this);
1076 auto *OnlyDecl = Imported.Initializers.front();
1077 if (isa<ImportDecl>(OnlyDecl))
1082 auto *&Inits = ModuleInitializers[M];
1084 Inits =
new (*this) PerModuleInitializers;
1085 Inits->Initializers.push_back(
D);
1090 auto *&Inits = ModuleInitializers[M];
1092 Inits =
new (*this) PerModuleInitializers;
1093 Inits->LazyInitializers.insert(Inits->LazyInitializers.end(),
1094 IDs.begin(), IDs.end());
1098 auto It = ModuleInitializers.find(M);
1099 if (It == ModuleInitializers.end())
1100 return std::nullopt;
1102 auto *Inits = It->second;
1103 Inits->resolve(*
this);
1104 return Inits->Initializers;
1109 assert(!CurrentCXXNamedModule &&
1110 "We should set named module for ASTContext for only once");
1111 CurrentCXXNamedModule = M;
1123 auto GetRepresentativeModule = [
this](
const Module *M) {
1124 auto Iter = SameModuleLookupSet.find(M);
1125 if (
Iter != SameModuleLookupSet.end())
1126 return Iter->second;
1128 const Module *RepresentativeModule =
1129 PrimaryModuleNameMap.try_emplace(M->getPrimaryModuleInterfaceName(), M)
1131 SameModuleLookupSet[M] = RepresentativeModule;
1132 return RepresentativeModule;
1135 assert(M1 &&
"Shouldn't call `isInSameModule` if both M1 and M2 are none.");
1136 return GetRepresentativeModule(M1) == GetRepresentativeModule(M2);
1140 if (!ExternCContext)
1143 return ExternCContext;
1149 auto *BuiltinTemplate =
1151 BuiltinTemplate->setImplicit();
1154 return BuiltinTemplate;
1159 if (!MakeIntegerSeqDecl)
1162 return MakeIntegerSeqDecl;
1167 if (!TypePackElementDecl)
1170 return TypePackElementDecl;
1184 NewDecl->
addAttr(TypeVisibilityAttr::CreateImplicit(
1185 const_cast<ASTContext &
>(*
this), TypeVisibilityAttr::Default));
1190 StringRef Name)
const {
1214 Types.push_back(Ty);
1219 assert((!this->Target || this->Target == &
Target) &&
1220 "Incorrect target reinitialization");
1224 this->AuxTarget = AuxTarget;
1226 ABI.reset(createCXXABI(
Target));
1230 InitBuiltinType(
VoidTy, BuiltinType::Void);
1233 InitBuiltinType(
BoolTy, BuiltinType::Bool);
1235 if (LangOpts.CharIsSigned)
1236 InitBuiltinType(
CharTy, BuiltinType::Char_S);
1238 InitBuiltinType(
CharTy, BuiltinType::Char_U);
1241 InitBuiltinType(
ShortTy, BuiltinType::Short);
1242 InitBuiltinType(
IntTy, BuiltinType::Int);
1243 InitBuiltinType(
LongTy, BuiltinType::Long);
1244 InitBuiltinType(
LongLongTy, BuiltinType::LongLong);
1254 InitBuiltinType(
FloatTy, BuiltinType::Float);
1255 InitBuiltinType(
DoubleTy, BuiltinType::Double);
1256 InitBuiltinType(
LongDoubleTy, BuiltinType::LongDouble);
1259 InitBuiltinType(
Float128Ty, BuiltinType::Float128);
1262 InitBuiltinType(
Ibm128Ty, BuiltinType::Ibm128);
1265 InitBuiltinType(
Float16Ty, BuiltinType::Float16);
1268 InitBuiltinType(
ShortAccumTy, BuiltinType::ShortAccum);
1269 InitBuiltinType(
AccumTy, BuiltinType::Accum);
1270 InitBuiltinType(
LongAccumTy, BuiltinType::LongAccum);
1274 InitBuiltinType(
ShortFractTy, BuiltinType::ShortFract);
1275 InitBuiltinType(
FractTy, BuiltinType::Fract);
1276 InitBuiltinType(
LongFractTy, BuiltinType::LongFract);
1281 InitBuiltinType(
SatAccumTy, BuiltinType::SatAccum);
1287 InitBuiltinType(
SatFractTy, BuiltinType::SatFract);
1294 InitBuiltinType(
Int128Ty, BuiltinType::Int128);
1299 InitBuiltinType(
WCharTy, BuiltinType::WChar_S);
1301 InitBuiltinType(
WCharTy, BuiltinType::WChar_U);
1302 if (LangOpts.CPlusPlus && LangOpts.WChar)
1312 InitBuiltinType(
Char8Ty, BuiltinType::Char8);
1314 if (LangOpts.CPlusPlus)
1315 InitBuiltinType(
Char16Ty, BuiltinType::Char16);
1319 if (LangOpts.CPlusPlus)
1320 InitBuiltinType(
Char32Ty, BuiltinType::Char32);
1329 InitBuiltinType(
DependentTy, BuiltinType::Dependent);
1332 InitBuiltinType(
OverloadTy, BuiltinType::Overload);
1344 InitBuiltinType(
UnknownAnyTy, BuiltinType::UnknownAny);
1350 InitBuiltinType(
BuiltinFnTy, BuiltinType::BuiltinFn);
1353 if (LangOpts.OpenMP) {
1360 if (LangOpts.OpenACC && !LangOpts.OpenMP) {
1363 if (LangOpts.MatrixTypes)
1371 if (LangOpts.OpenCL) {
1372#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1373 InitBuiltinType(SingletonId, BuiltinType::Id);
1374#include "clang/Basic/OpenCLImageTypes.def"
1376 InitBuiltinType(
OCLSamplerTy, BuiltinType::OCLSampler);
1377 InitBuiltinType(
OCLEventTy, BuiltinType::OCLEvent);
1379 InitBuiltinType(
OCLQueueTy, BuiltinType::OCLQueue);
1382#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1383 InitBuiltinType(Id##Ty, BuiltinType::Id);
1384#include "clang/Basic/OpenCLExtensionTypes.def"
1387 if (LangOpts.HLSL) {
1388#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1389 InitBuiltinType(SingletonId, BuiltinType::Id);
1390#include "clang/Basic/HLSLIntangibleTypes.def"
1393 if (
Target.hasAArch64SVETypes() ||
1395#define SVE_TYPE(Name, Id, SingletonId) \
1396 InitBuiltinType(SingletonId, BuiltinType::Id);
1397#include "clang/Basic/AArch64SVEACLETypes.def"
1400 if (
Target.getTriple().isPPC64()) {
1401#define PPC_VECTOR_MMA_TYPE(Name, Id, Size) \
1402 InitBuiltinType(Id##Ty, BuiltinType::Id);
1403#include "clang/Basic/PPCTypes.def"
1404#define PPC_VECTOR_VSX_TYPE(Name, Id, Size) \
1405 InitBuiltinType(Id##Ty, BuiltinType::Id);
1406#include "clang/Basic/PPCTypes.def"
1409 if (
Target.hasRISCVVTypes()) {
1410#define RVV_TYPE(Name, Id, SingletonId) \
1411 InitBuiltinType(SingletonId, BuiltinType::Id);
1412#include "clang/Basic/RISCVVTypes.def"
1415 if (
Target.getTriple().isWasm() &&
Target.hasFeature(
"reference-types")) {
1416#define WASM_TYPE(Name, Id, SingletonId) \
1417 InitBuiltinType(SingletonId, BuiltinType::Id);
1418#include "clang/Basic/WebAssemblyReferenceTypes.def"
1421 if (
Target.getTriple().isAMDGPU() ||
1422 (AuxTarget && AuxTarget->
getTriple().isAMDGPU())) {
1423#define AMDGPU_TYPE(Name, Id, SingletonId) \
1424 InitBuiltinType(SingletonId, BuiltinType::Id);
1425#include "clang/Basic/AMDGPUTypes.def"
1432 ObjCConstantStringType =
QualType();
1437 if (LangOpts.OpenCLGenericAddressSpace) {
1447 InitBuiltinType(
NullPtrTy, BuiltinType::NullPtr);
1450 InitBuiltinType(
HalfTy, BuiltinType::Half);
1452 InitBuiltinType(
BFloat16Ty, BuiltinType::BFloat16);
1458 if (LangOpts.MicrosoftExt || LangOpts.Borland) {
1480 llvm::DenseMap<const Decl*, AttrVec*>::iterator Pos = DeclAttrs.find(
D);
1481 if (Pos != DeclAttrs.end()) {
1482 Pos->second->~AttrVec();
1483 DeclAttrs.erase(Pos);
1497 llvm::DenseMap<const VarDecl *, TemplateOrSpecializationInfo>::iterator Pos =
1498 TemplateOrInstantiation.find(Var);
1499 if (Pos == TemplateOrInstantiation.end())
1512 Tmpl, TSK, PointOfInstantiation));
1518 assert(!TemplateOrInstantiation[Inst] &&
1519 "Already noted what the variable was instantiated from");
1520 TemplateOrInstantiation[Inst] = TSI;
1525 return InstantiatedFromUsingDecl.lookup(UUD);
1530 assert((isa<UsingDecl>(Pattern) ||
1531 isa<UnresolvedUsingValueDecl>(Pattern) ||
1532 isa<UnresolvedUsingTypenameDecl>(Pattern)) &&
1533 "pattern decl is not a using decl");
1534 assert((isa<UsingDecl>(Inst) ||
1535 isa<UnresolvedUsingValueDecl>(Inst) ||
1536 isa<UnresolvedUsingTypenameDecl>(Inst)) &&
1537 "instantiation did not produce a using decl");
1538 assert(!InstantiatedFromUsingDecl[Inst] &&
"pattern already exists");
1539 InstantiatedFromUsingDecl[Inst] = Pattern;
1544 return InstantiatedFromUsingEnumDecl.lookup(UUD);
1549 assert(!InstantiatedFromUsingEnumDecl[Inst] &&
"pattern already exists");
1550 InstantiatedFromUsingEnumDecl[Inst] = Pattern;
1555 return InstantiatedFromUsingShadowDecl.lookup(Inst);
1561 assert(!InstantiatedFromUsingShadowDecl[Inst] &&
"pattern already exists");
1562 InstantiatedFromUsingShadowDecl[Inst] = Pattern;
1566 return InstantiatedFromUnnamedFieldDecl.lookup(Field);
1571 assert(!Inst->
getDeclName() &&
"Instantiated field decl is not unnamed");
1572 assert(!Tmpl->
getDeclName() &&
"Template field decl is not unnamed");
1573 assert(!InstantiatedFromUnnamedFieldDecl[Inst] &&
1574 "Already noted what unnamed field was instantiated from");
1576 InstantiatedFromUnnamedFieldDecl[Inst] = Tmpl;
1597 llvm::DenseMap<const CXXMethodDecl *, CXXMethodVector>::const_iterator Pos =
1599 if (Pos == OverriddenMethods.end())
1607 OverriddenMethods[Method].push_back(Overridden);
1615 if (
const auto *CXXMethod = dyn_cast<CXXMethodDecl>(
D)) {
1621 const auto *Method = dyn_cast<ObjCMethodDecl>(
D);
1626 Method->getOverriddenMethods(OverDecls);
1627 Overridden.append(OverDecls.begin(), OverDecls.end());
1631 assert(!Import->getNextLocalImport() &&
1632 "Import declaration already in the chain");
1633 assert(!Import->isFromASTFile() &&
"Non-local import declaration");
1634 if (!FirstLocalImport) {
1635 FirstLocalImport = Import;
1636 LastLocalImport = Import;
1640 LastLocalImport->setNextLocalImport(Import);
1641 LastLocalImport = Import;
1653 llvm_unreachable(
"Not a floating point type!");
1654 case BuiltinType::BFloat16:
1655 return Target->getBFloat16Format();
1656 case BuiltinType::Float16:
1657 return Target->getHalfFormat();
1658 case BuiltinType::Half:
1659 return Target->getHalfFormat();
1660 case BuiltinType::Float:
return Target->getFloatFormat();
1661 case BuiltinType::Double:
return Target->getDoubleFormat();
1662 case BuiltinType::Ibm128:
1663 return Target->getIbm128Format();
1664 case BuiltinType::LongDouble:
1667 return Target->getLongDoubleFormat();
1668 case BuiltinType::Float128:
1671 return Target->getFloat128Format();
1676 unsigned Align =
Target->getCharWidth();
1680 Align = AlignFromAttr;
1688 bool UseAlignAttrOnly;
1689 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(
D))
1691 FD->hasAttr<PackedAttr>() || FD->getParent()->hasAttr<PackedAttr>();
1693 UseAlignAttrOnly = AlignFromAttr != 0;
1696 if (UseAlignAttrOnly) {
1698 }
else if (
const auto *VD = dyn_cast<ValueDecl>(
D)) {
1708 Align = getTypeInfoImpl(
T.getTypePtr()).
Align;
1713 unsigned MinWidth =
Target->getLargeArrayMinWidth();
1714 if (!ForAlignof && MinWidth) {
1716 Align = std::max(Align,
Target->getLargeArrayAlign());
1717 else if (isa<ConstantArrayType>(
arrayType) &&
1719 Align = std::max(Align,
Target->getLargeArrayAlign());
1724 Align =
Target->getCharWidth();
1728 if (
const auto *VD = dyn_cast<VarDecl>(
D))
1729 if (VD->hasGlobalStorage() && !ForAlignof) {
1740 if (
const auto *Field = dyn_cast<FieldDecl>(VD)) {
1743 if (!
Parent->isInvalidDecl()) {
1754 uint64_t LowBitOfOffset = Offset & (~Offset + 1);
1755 if (LowBitOfOffset < FieldAlign)
1756 FieldAlign =
static_cast<unsigned>(LowBitOfOffset);
1759 Align = std::min(Align, FieldAlign);
1767 const auto *VD = dyn_cast<VarDecl>(
D);
1768 if (MaxAlignedAttr && VD && VD->getStorageClass() ==
SC_Static)
1769 Align = std::min(Align, MaxAlignedAttr);
1807 (uint64_t)(-1)/Size) &&
1808 "Overflow in array type char size evaluation");
1813 Width = llvm::alignTo(Width, Align);
1820 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
T))
1838 switch (BT->getKind()) {
1839 case BuiltinType::Bool:
1840 case BuiltinType::Char_S:
1841 case BuiltinType::Char_U:
1842 case BuiltinType::SChar:
1843 case BuiltinType::UChar:
1844 case BuiltinType::Short:
1845 case BuiltinType::UShort:
1846 case BuiltinType::WChar_S:
1847 case BuiltinType::WChar_U:
1848 case BuiltinType::Char8:
1849 case BuiltinType::Char16:
1850 case BuiltinType::Char32:
1860 ET->getDecl()->isScoped())
1878 bool NeedsPreferredAlignment)
const {
1881 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1892 if (
unsigned Align = TT->getDecl()->getMaxAlignment())
1897 return TT->getDecl()->getMaxAlignment();
1903 TypeInfoMap::iterator I = MemoizedTypeInfo.find(
T);
1904 if (I != MemoizedTypeInfo.end())
1909 MemoizedTypeInfo[
T] = TI;
1925#define TYPE(Class, Base)
1926#define ABSTRACT_TYPE(Class, Base)
1927#define NON_CANONICAL_TYPE(Class, Base)
1928#define DEPENDENT_TYPE(Class, Base) case Type::Class:
1929#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) \
1931 assert(!T->isDependentType() && "should not see dependent types here"); \
1932 return getTypeInfo(cast<Class##Type>(T)->desugar().getTypePtr());
1933#include "clang/AST/TypeNodes.inc"
1934 llvm_unreachable(
"Should not see dependent types");
1936 case Type::FunctionNoProto:
1937 case Type::FunctionProto:
1943 case Type::IncompleteArray:
1944 case Type::VariableArray:
1945 case Type::ConstantArray:
1946 case Type::ArrayParameter: {
1949 if (
const auto *CAT = dyn_cast<ConstantArrayType>(
T))
1950 Size = CAT->getZExtSize();
1953 assert((Size == 0 || EltInfo.
Width <= (uint64_t)(-1) / Size) &&
1954 "Overflow in array type bit size evaluation");
1955 Width = EltInfo.
Width * Size;
1956 Align = EltInfo.
Align;
1960 Width = llvm::alignTo(Width, Align);
1964 case Type::ExtVector:
1965 case Type::Vector: {
1966 const auto *VT = cast<VectorType>(
T);
1968 Width = VT->isExtVectorBoolType() ? VT->getNumElements()
1969 : EltInfo.
Width * VT->getNumElements();
1971 Width = std::max<unsigned>(8, Width);
1972 Align = std::max<unsigned>(8, Width);
1976 if (Align & (Align-1)) {
1977 Align = llvm::bit_ceil(Align);
1978 Width = llvm::alignTo(Width, Align);
1982 if (TargetVectorAlign && TargetVectorAlign < Align)
1983 Align = TargetVectorAlign;
1997 Align = std::min<unsigned>(64, Width);
2001 case Type::ConstantMatrix: {
2002 const auto *MT = cast<ConstantMatrixType>(
T);
2007 Width = ElementInfo.
Width * MT->getNumRows() * MT->getNumColumns();
2008 Align = ElementInfo.
Align;
2013 switch (cast<BuiltinType>(
T)->
getKind()) {
2014 default: llvm_unreachable(
"Unknown builtin type!");
2015 case BuiltinType::Void:
2020 case BuiltinType::Bool:
2021 Width =
Target->getBoolWidth();
2022 Align =
Target->getBoolAlign();
2024 case BuiltinType::Char_S:
2025 case BuiltinType::Char_U:
2026 case BuiltinType::UChar:
2027 case BuiltinType::SChar:
2028 case BuiltinType::Char8:
2029 Width =
Target->getCharWidth();
2030 Align =
Target->getCharAlign();
2032 case BuiltinType::WChar_S:
2033 case BuiltinType::WChar_U:
2034 Width =
Target->getWCharWidth();
2035 Align =
Target->getWCharAlign();
2037 case BuiltinType::Char16:
2038 Width =
Target->getChar16Width();
2039 Align =
Target->getChar16Align();
2041 case BuiltinType::Char32:
2042 Width =
Target->getChar32Width();
2043 Align =
Target->getChar32Align();
2045 case BuiltinType::UShort:
2046 case BuiltinType::Short:
2047 Width =
Target->getShortWidth();
2048 Align =
Target->getShortAlign();
2050 case BuiltinType::UInt:
2051 case BuiltinType::Int:
2052 Width =
Target->getIntWidth();
2053 Align =
Target->getIntAlign();
2055 case BuiltinType::ULong:
2056 case BuiltinType::Long:
2057 Width =
Target->getLongWidth();
2058 Align =
Target->getLongAlign();
2060 case BuiltinType::ULongLong:
2061 case BuiltinType::LongLong:
2062 Width =
Target->getLongLongWidth();
2063 Align =
Target->getLongLongAlign();
2065 case BuiltinType::Int128:
2066 case BuiltinType::UInt128:
2068 Align =
Target->getInt128Align();
2070 case BuiltinType::ShortAccum:
2071 case BuiltinType::UShortAccum:
2072 case BuiltinType::SatShortAccum:
2073 case BuiltinType::SatUShortAccum:
2074 Width =
Target->getShortAccumWidth();
2075 Align =
Target->getShortAccumAlign();
2077 case BuiltinType::Accum:
2078 case BuiltinType::UAccum:
2079 case BuiltinType::SatAccum:
2080 case BuiltinType::SatUAccum:
2081 Width =
Target->getAccumWidth();
2082 Align =
Target->getAccumAlign();
2084 case BuiltinType::LongAccum:
2085 case BuiltinType::ULongAccum:
2086 case BuiltinType::SatLongAccum:
2087 case BuiltinType::SatULongAccum:
2088 Width =
Target->getLongAccumWidth();
2089 Align =
Target->getLongAccumAlign();
2091 case BuiltinType::ShortFract:
2092 case BuiltinType::UShortFract:
2093 case BuiltinType::SatShortFract:
2094 case BuiltinType::SatUShortFract:
2095 Width =
Target->getShortFractWidth();
2096 Align =
Target->getShortFractAlign();
2098 case BuiltinType::Fract:
2099 case BuiltinType::UFract:
2100 case BuiltinType::SatFract:
2101 case BuiltinType::SatUFract:
2102 Width =
Target->getFractWidth();
2103 Align =
Target->getFractAlign();
2105 case BuiltinType::LongFract:
2106 case BuiltinType::ULongFract:
2107 case BuiltinType::SatLongFract:
2108 case BuiltinType::SatULongFract:
2109 Width =
Target->getLongFractWidth();
2110 Align =
Target->getLongFractAlign();
2112 case BuiltinType::BFloat16:
2113 if (
Target->hasBFloat16Type()) {
2114 Width =
Target->getBFloat16Width();
2115 Align =
Target->getBFloat16Align();
2124 case BuiltinType::Float16:
2125 case BuiltinType::Half:
2128 Width =
Target->getHalfWidth();
2129 Align =
Target->getHalfAlign();
2132 "Expected OpenMP device compilation.");
2137 case BuiltinType::Float:
2138 Width =
Target->getFloatWidth();
2139 Align =
Target->getFloatAlign();
2141 case BuiltinType::Double:
2142 Width =
Target->getDoubleWidth();
2143 Align =
Target->getDoubleAlign();
2145 case BuiltinType::Ibm128:
2146 Width =
Target->getIbm128Width();
2147 Align =
Target->getIbm128Align();
2149 case BuiltinType::LongDouble:
2156 Width =
Target->getLongDoubleWidth();
2157 Align =
Target->getLongDoubleAlign();
2160 case BuiltinType::Float128:
2163 Width =
Target->getFloat128Width();
2164 Align =
Target->getFloat128Align();
2167 "Expected OpenMP device compilation.");
2172 case BuiltinType::NullPtr:
2177 case BuiltinType::ObjCId:
2178 case BuiltinType::ObjCClass:
2179 case BuiltinType::ObjCSel:
2183 case BuiltinType::OCLSampler:
2184 case BuiltinType::OCLEvent:
2185 case BuiltinType::OCLClkEvent:
2186 case BuiltinType::OCLQueue:
2187 case BuiltinType::OCLReserveID:
2188#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
2189 case BuiltinType::Id:
2190#include "clang/Basic/OpenCLImageTypes.def"
2191#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
2192 case BuiltinType::Id:
2193#include "clang/Basic/OpenCLExtensionTypes.def"
2195 Width =
Target->getPointerWidth(AS);
2196 Align =
Target->getPointerAlign(AS);
2206#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
2207 IsSigned, IsFP, IsBF) \
2208 case BuiltinType::Id: \
2212#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
2213 case BuiltinType::Id: \
2217#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingletonId) \
2218 case BuiltinType::Id: \
2222#include "clang/Basic/AArch64SVEACLETypes.def"
2223#define PPC_VECTOR_TYPE(Name, Id, Size) \
2224 case BuiltinType::Id: \
2228#include "clang/Basic/PPCTypes.def"
2229#define RVV_VECTOR_TYPE(Name, Id, SingletonId, ElKind, ElBits, NF, IsSigned, \
2231 case BuiltinType::Id: \
2235#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, ElKind) \
2236 case BuiltinType::Id: \
2240#include "clang/Basic/RISCVVTypes.def"
2241#define WASM_TYPE(Name, Id, SingletonId) \
2242 case BuiltinType::Id: \
2246#include "clang/Basic/WebAssemblyReferenceTypes.def"
2247#define AMDGPU_OPAQUE_PTR_TYPE(NAME, MANGLEDNAME, AS, WIDTH, ALIGN, ID, \
2249 case BuiltinType::ID: \
2253#include "clang/Basic/AMDGPUTypes.def"
2254#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
2255#include "clang/Basic/HLSLIntangibleTypes.def"
2261 case Type::ObjCObjectPointer:
2265 case Type::BlockPointer:
2266 AS = cast<BlockPointerType>(
T)->getPointeeType().getAddressSpace();
2267 Width =
Target->getPointerWidth(AS);
2268 Align =
Target->getPointerAlign(AS);
2270 case Type::LValueReference:
2271 case Type::RValueReference:
2274 AS = cast<ReferenceType>(
T)->getPointeeType().getAddressSpace();
2275 Width =
Target->getPointerWidth(AS);
2276 Align =
Target->getPointerAlign(AS);
2279 AS = cast<PointerType>(
T)->getPointeeType().getAddressSpace();
2280 Width =
Target->getPointerWidth(AS);
2281 Align =
Target->getPointerAlign(AS);
2283 case Type::MemberPointer: {
2284 const auto *MPT = cast<MemberPointerType>(
T);
2290 case Type::Complex: {
2294 Width = EltInfo.
Width * 2;
2295 Align = EltInfo.
Align;
2298 case Type::ObjCObject:
2299 return getTypeInfo(cast<ObjCObjectType>(
T)->getBaseType().getTypePtr());
2300 case Type::Adjusted:
2303 case Type::ObjCInterface: {
2304 const auto *ObjCI = cast<ObjCInterfaceType>(
T);
2305 if (ObjCI->getDecl()->isInvalidDecl()) {
2315 case Type::BitInt: {
2316 const auto *EIT = cast<BitIntType>(
T);
2317 Align =
Target->getBitIntAlign(EIT->getNumBits());
2318 Width =
Target->getBitIntWidth(EIT->getNumBits());
2323 const auto *TT = cast<TagType>(
T);
2325 if (TT->getDecl()->isInvalidDecl()) {
2331 if (
const auto *ET = dyn_cast<EnumType>(TT)) {
2332 const EnumDecl *ED = ET->getDecl();
2336 Info.
Align = AttrAlign;
2342 const auto *RT = cast<RecordType>(TT);
2347 AlignRequirement = RD->
hasAttr<AlignedAttr>()
2353 case Type::SubstTemplateTypeParm:
2354 return getTypeInfo(cast<SubstTemplateTypeParmType>(
T)->
2355 getReplacementType().getTypePtr());
2358 case Type::DeducedTemplateSpecialization: {
2359 const auto *A = cast<DeducedType>(
T);
2360 assert(!A->getDeducedType().isNull() &&
2361 "cannot request the size of an undeduced or dependent auto type");
2362 return getTypeInfo(A->getDeducedType().getTypePtr());
2366 return getTypeInfo(cast<ParenType>(
T)->getInnerType().getTypePtr());
2368 case Type::MacroQualified:
2372 case Type::ObjCTypeParam:
2373 return getTypeInfo(cast<ObjCTypeParamType>(
T)->desugar().getTypePtr());
2376 return getTypeInfo(cast<UsingType>(
T)->desugar().getTypePtr());
2378 case Type::Typedef: {
2379 const auto *TT = cast<TypedefType>(
T);
2384 if (
unsigned AttrAlign = TT->getDecl()->getMaxAlignment()) {
2395 case Type::Elaborated:
2396 return getTypeInfo(cast<ElaboratedType>(
T)->getNamedType().getTypePtr());
2398 case Type::Attributed:
2400 cast<AttributedType>(
T)->getEquivalentType().getTypePtr());
2402 case Type::CountAttributed:
2403 return getTypeInfo(cast<CountAttributedType>(
T)->desugar().getTypePtr());
2405 case Type::BTFTagAttributed:
2407 cast<BTFTagAttributedType>(
T)->getWrappedType().getTypePtr());
2409 case Type::Atomic: {
2418 Width =
Target->getCharWidth();
2420 }
else if (Width <= Target->getMaxAtomicPromoteWidth()) {
2426 Width = llvm::bit_ceil(Width);
2429 Align =
static_cast<unsigned>(Width);
2440 assert(llvm::isPowerOf2_32(Align) &&
"Alignment must be power of 2");
2441 return TypeInfo(Width, Align, AlignRequirement);
2445 UnadjustedAlignMap::iterator I = MemoizedUnadjustedAlign.find(
T);
2446 if (I != MemoizedUnadjustedAlign.end())
2449 unsigned UnadjustedAlign;
2461 MemoizedUnadjustedAlign[
T] = UnadjustedAlign;
2462 return UnadjustedAlign;
2466 unsigned SimdAlign = llvm::OpenMPIRBuilder::getOpenMPDefaultSimdAlign(
2516 unsigned ABIAlign = TI.
Align;
2524 if (!
Target->allowsLargerPreferedTypeAlignment())
2538 unsigned PreferredAlign =
static_cast<unsigned>(
2540 assert(PreferredAlign >= ABIAlign &&
2541 "PreferredAlign should be at least as large as ABIAlign.");
2542 return PreferredAlign;
2549 T = CT->getElementType().getTypePtr();
2551 T = ET->getDecl()->getIntegerType().getTypePtr();
2556 Target->defaultsToAIXPowerAlignment()))
2611 for (
unsigned I = 0, N =
Path.size(); I != N; ++I) {
2615 std::swap(
Base, Derived);
2635 llvm::append_range(Ivars, OI->
ivars());
2638 for (
const ObjCIvarDecl *Iv = IDecl->all_declared_ivar_begin(); Iv;
2640 Ivars.push_back(Iv);
2648 if (
const auto *OI = dyn_cast<ObjCInterfaceDecl>(CDecl)) {
2651 for (
auto *Proto : OI->all_referenced_protocols()) {
2656 for (
const auto *Cat : OI->visible_categories())
2662 SD = SD->getSuperClass();
2664 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(CDecl)) {
2665 for (
auto *Proto : OC->protocols()) {
2668 }
else if (
const auto *OP = dyn_cast<ObjCProtocolDecl>(CDecl)) {
2670 if (!Protocols.insert(
2674 for (
auto *Proto : OP->protocols())
2681 bool CheckIfTriviallyCopyable) {
2682 assert(RD->
isUnion() &&
"Must be union type");
2685 for (
const auto *Field : RD->
fields()) {
2687 CheckIfTriviallyCopyable))
2690 if (FieldSize != UnionSize)
2708static std::optional<int64_t>
2711 bool CheckIfTriviallyCopyable);
2713static std::optional<int64_t>
2715 bool CheckIfTriviallyCopyable) {
2716 if (Field->getType()->isRecordType()) {
2717 const RecordDecl *RD = Field->getType()->getAsRecordDecl();
2720 CheckIfTriviallyCopyable);
2725 bool IsBitIntType = Field->getType()->isBitIntType();
2726 if (!Field->getType()->isReferenceType() && !IsBitIntType &&
2728 CheckIfTriviallyCopyable))
2729 return std::nullopt;
2731 int64_t FieldSizeInBits =
2733 if (Field->isBitField()) {
2736 if (Field->isUnnamedBitField())
2739 int64_t BitfieldSize = Field->getBitWidthValue(Context);
2741 if ((
unsigned)BitfieldSize >
2742 cast<BitIntType>(Field->getType())->getNumBits())
2743 return std::nullopt;
2744 }
else if (BitfieldSize > FieldSizeInBits) {
2745 return std::nullopt;
2747 FieldSizeInBits = BitfieldSize;
2749 Field->getType(), CheckIfTriviallyCopyable)) {
2750 return std::nullopt;
2752 return FieldSizeInBits;
2755static std::optional<int64_t>
2757 bool CheckIfTriviallyCopyable) {
2759 CheckIfTriviallyCopyable);
2762template <
typename RangeT>
2764 const RangeT &Subobjects, int64_t CurOffsetInBits,
2766 bool CheckIfTriviallyCopyable) {
2767 for (
const auto *Subobject : Subobjects) {
2768 std::optional<int64_t> SizeInBits =
2771 return std::nullopt;
2772 if (*SizeInBits != 0) {
2774 if (Offset != CurOffsetInBits)
2775 return std::nullopt;
2776 CurOffsetInBits += *SizeInBits;
2779 return CurOffsetInBits;
2782static std::optional<int64_t>
2785 bool CheckIfTriviallyCopyable) {
2786 assert(!RD->
isUnion() &&
"Must be struct/class type");
2789 int64_t CurOffsetInBits = 0;
2790 if (
const auto *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {
2791 if (ClassDecl->isDynamicClass())
2792 return std::nullopt;
2795 for (
const auto &
Base : ClassDecl->bases()) {
2798 Bases.emplace_back(
Base.getType()->getAsCXXRecordDecl());
2802 return Layout.getBaseClassOffset(L) < Layout.getBaseClassOffset(R);
2805 std::optional<int64_t> OffsetAfterBases =
2807 Bases, CurOffsetInBits, Context, Layout, CheckIfTriviallyCopyable);
2808 if (!OffsetAfterBases)
2809 return std::nullopt;
2810 CurOffsetInBits = *OffsetAfterBases;
2813 std::optional<int64_t> OffsetAfterFields =
2815 RD->
fields(), CurOffsetInBits, Context, Layout,
2816 CheckIfTriviallyCopyable);
2817 if (!OffsetAfterFields)
2818 return std::nullopt;
2819 CurOffsetInBits = *OffsetAfterFields;
2821 return CurOffsetInBits;
2825 QualType Ty,
bool CheckIfTriviallyCopyable)
const {
2842 assert(!Ty.
isNull() &&
"Null QualType sent to unique object rep check");
2847 CheckIfTriviallyCopyable);
2850 "hasUniqueObjectRepresentations should not be called with an "
2871 return !ABI->getMemberPointerInfo(MPT).HasPadding;
2876 if (
Record->isInvalidDecl())
2881 CheckIfTriviallyCopyable);
2884 *
this,
Record, CheckIfTriviallyCopyable);
2886 return StructSize && *StructSize ==
static_cast<int64_t
>(
getTypeSize(Ty));
2907 count += Ext->ivar_size();
2912 count += ImplDecl->ivar_size();
2930 if (isa<GNUNullExpr>(
E))
return true;
2938 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2939 I = ObjCImpls.find(
D);
2940 if (I != ObjCImpls.end())
2941 return cast<ObjCImplementationDecl>(I->second);
2948 llvm::DenseMap<ObjCContainerDecl*, ObjCImplDecl*>::iterator
2949 I = ObjCImpls.find(
D);
2950 if (I != ObjCImpls.end())
2951 return cast<ObjCCategoryImplDecl>(I->second);
2958 assert(IFaceD && ImplD &&
"Passed null params");
2959 ObjCImpls[IFaceD] = ImplD;
2965 assert(CatD && ImplD &&
"Passed null params");
2966 ObjCImpls[CatD] = ImplD;
2971 return ObjCMethodRedecls.lookup(MD);
2977 ObjCMethodRedecls[MD] = Redecl;
2982 if (
const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND->
getDeclContext()))
2984 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND->
getDeclContext()))
2985 return CD->getClassInterface();
2986 if (
const auto *IMD = dyn_cast<ObjCImplDecl>(ND->
getDeclContext()))
2987 return IMD->getClassInterface();
2995 assert(VD &&
"Passed null params");
2996 assert(VD->
hasAttr<BlocksAttr>() &&
2997 "getBlockVarCopyInits - not __block var");
2998 auto I = BlockVarCopyInits.find(VD);
2999 if (I != BlockVarCopyInits.end())
3001 return {
nullptr,
false};
3007 assert(VD && CopyExpr &&
"Passed null params");
3008 assert(VD->
hasAttr<BlocksAttr>() &&
3009 "setBlockVarCopyInits - not __block var");
3010 BlockVarCopyInits[VD].setExprAndFlag(CopyExpr,
CanThrow);
3014 unsigned DataSize)
const {
3019 "incorrect data size provided to CreateTypeSourceInfo!");
3036 return getObjCLayout(
D,
nullptr);
3042 return getObjCLayout(
D->getClassInterface(),
D);
3047 bool &AnyNonCanonArgs) {
3049 for (
auto &Arg : CanonArgs) {
3051 Arg =
C.getCanonicalTemplateArgument(Arg);
3052 AnyNonCanonArgs |= !Arg.structurallyEquals(OrigArg);
3062ASTContext::getExtQualType(
const Type *baseType,
Qualifiers quals)
const {
3067 llvm::FoldingSetNodeID
ID;
3069 void *insertPos =
nullptr;
3070 if (
ExtQuals *eq = ExtQualNodes.FindNodeOrInsertPos(ID, insertPos)) {
3071 assert(eq->getQualifiers() == quals);
3080 canon = getExtQualType(canonSplit.
Ty, canonSplit.
Quals);
3083 (void) ExtQualNodes.FindNodeOrInsertPos(ID, insertPos);
3086 auto *eq =
new (*
this,
alignof(
ExtQuals))
ExtQuals(baseType, canon, quals);
3087 ExtQualNodes.InsertNode(eq, insertPos);
3092 LangAS AddressSpace)
const {
3105 "Type cannot be in multiple addr spaces!");
3108 return getExtQualType(TypeNode, Quals);
3114 if (!
T.hasAddressSpace())
3118 const Type *TypeNode;
3123 TypeNode =
T.getTypePtr();
3127 while (
T.hasAddressSpace()) {
3128 TypeNode = Quals.
strip(
T);
3132 if (!
QualType(TypeNode, 0).hasAddressSpace())
3136 T =
T.getSingleStepDesugaredType(*
this);
3146 return getExtQualType(TypeNode, Quals);
3154 "Attempted to get vtable pointer discriminator on a monomorphic type");
3157 llvm::raw_svector_ostream Out(Str);
3158 MC->mangleCXXVTable(RD, Out);
3159 return llvm::getPointerAuthStableSipHash(Str);
3188 Ctx, OS, cast<AtomicType>(
T)->getValueType());
3190 case Type::LValueReference:
3195 case Type::RValueReference:
3209 case Type::ObjCObjectPointer:
3210 case Type::BlockPointer:
3217 Ctx, OS, cast<ComplexType>(
T)->getElementType());
3219 case Type::VariableArray:
3220 case Type::ConstantArray:
3221 case Type::IncompleteArray:
3222 case Type::ArrayParameter:
3233 Ctx, OS, cast<ArrayType>(
T)->getElementType());
3235 case Type::ObjCInterface:
3236 case Type::ObjCObject:
3237 OS <<
"<objc_object>";
3246 QualType UnderlyingType = cast<EnumType>(
T)->getDecl()->getIntegerType();
3248 Ctx, OS, UnderlyingType.
isNull() ? Ctx.
IntTy : UnderlyingType);
3251 case Type::FunctionNoProto:
3252 case Type::FunctionProto: {
3266 const auto *FuncType = cast<FunctionType>(
T);
3268 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FuncType)) {
3269 for (
QualType Param : FPT->param_types()) {
3273 if (FPT->isVariadic())
3280 case Type::MemberPointer: {
3287 case Type::ExtVector:
3295 case Type::ConstantMatrix:
3299 case Type::Builtin: {
3301 switch (BTy->getKind()) {
3302#define SIGNED_TYPE(Id, SingletonId) \
3303 case BuiltinType::Id: \
3306#define UNSIGNED_TYPE(Id, SingletonId) \
3307 case BuiltinType::Id: \
3310#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
3311#define BUILTIN_TYPE(Id, SingletonId)
3312#include "clang/AST/BuiltinTypes.def"
3313 llvm_unreachable(
"placeholder types should not appear here.");
3315 case BuiltinType::Half:
3318 case BuiltinType::Float:
3321 case BuiltinType::Double:
3324 case BuiltinType::LongDouble:
3327 case BuiltinType::Float16:
3330 case BuiltinType::Float128:
3334 case BuiltinType::Void:
3338 case BuiltinType::ObjCId:
3339 case BuiltinType::ObjCClass:
3340 case BuiltinType::ObjCSel:
3341 case BuiltinType::NullPtr:
3346 case BuiltinType::OCLSampler:
3347 case BuiltinType::OCLEvent:
3348 case BuiltinType::OCLClkEvent:
3349 case BuiltinType::OCLQueue:
3350 case BuiltinType::OCLReserveID:
3351 case BuiltinType::BFloat16:
3352 case BuiltinType::VectorQuad:
3353 case BuiltinType::VectorPair:
3358 case BuiltinType::Ibm128:
3360#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
3361 case BuiltinType::Id: \
3363#include "clang/Basic/OpenCLImageTypes.def"
3364#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
3365 case BuiltinType::Id: \
3367#include "clang/Basic/OpenCLExtensionTypes.def"
3368#define SVE_TYPE(Name, Id, SingletonId) \
3369 case BuiltinType::Id: \
3371#include "clang/Basic/AArch64SVEACLETypes.def"
3372#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
3373 case BuiltinType::Id: \
3375#include "clang/Basic/HLSLIntangibleTypes.def"
3376 case BuiltinType::Dependent:
3377 llvm_unreachable(
"should never get here");
3378 case BuiltinType::AMDGPUBufferRsrc:
3379 case BuiltinType::WasmExternRef:
3380#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
3381#include "clang/Basic/RISCVVTypes.def"
3382 llvm_unreachable(
"not yet implemented");
3384 llvm_unreachable(
"should never get here");
3386 case Type::Record: {
3407 II = Typedef->getDeclName().getAsIdentifierInfo();
3410 OS <<
"<anonymous_record>";
3416 case Type::DeducedTemplateSpecialization:
3418#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
3419#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3420#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
3421#define ABSTRACT_TYPE(Class, Base)
3422#define TYPE(Class, Base)
3423#include "clang/AST/TypeNodes.inc"
3424 llvm_unreachable(
"unexpected non-canonical or dependent type!");
3431 "cannot compute type discriminator of a dependent type");
3434 llvm::raw_svector_ostream Out(Str);
3442 T =
T.getUnqualifiedType();
3444 MC->mangleCanonicalTypeName(
T, Out);
3447 return llvm::getPointerAuthStableSipHash(Str);
3472 "Type cannot have multiple ObjCGCs!");
3475 return getExtQualType(TypeNode, Quals);
3489 QualType WrappedTy,
Expr *CountExpr,
bool CountInBytes,
bool OrNull,
3493 llvm::FoldingSetNodeID ID;
3496 void *InsertPos =
nullptr;
3498 CountAttributedTypes.FindNodeOrInsertPos(ID, InsertPos);
3503 size_t Size = CountAttributedType::totalSizeToAlloc<TypeCoupledDeclRefInfo>(
3504 DependentDecls.size());
3507 OrNull, DependentDecls);
3508 Types.push_back(CATy);
3509 CountAttributedTypes.InsertNode(CATy, InsertPos);
3520 if (
const auto *FNPT = dyn_cast<FunctionNoProtoType>(
T)) {
3523 const auto *FPT = cast<FunctionProtoType>(
T);
3529 return cast<FunctionType>(
Result.getTypePtr());
3545 L->DeducedReturnType(FD, ResultType);
3555 if (
const auto *PT = dyn_cast<ParenType>(Orig))
3560 if (
const auto *MQT = dyn_cast<MacroQualifiedType>(Orig))
3563 MQT->getMacroIdentifier());
3566 if (
const auto *AT = dyn_cast<AttributedType>(Orig))
3576 Proto->getReturnType(), Proto->getParamTypes(),
3577 Proto->getExtProtoInfo().withExceptionSpec(ESI));
3592 for (
unsigned i = 0, n = Args.size(); i != n; ++i)
3626 if (TSInfo->getType() != FD->
getType())
3634 "TypeLoc size mismatch from updating exception specification");
3635 TSInfo->overrideType(Updated);
3644 llvm::FoldingSetNodeID ID;
3647 void *InsertPos =
nullptr;
3648 if (
ComplexType *CT = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos))
3654 if (!
T.isCanonical()) {
3658 ComplexType *NewIP = ComplexTypes.FindNodeOrInsertPos(ID, InsertPos);
3659 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3662 Types.push_back(New);
3663 ComplexTypes.InsertNode(New, InsertPos);
3672 llvm::FoldingSetNodeID ID;
3675 void *InsertPos =
nullptr;
3676 if (
PointerType *PT = PointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3682 if (!
T.isCanonical()) {
3686 PointerType *NewIP = PointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3687 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3690 Types.push_back(New);
3691 PointerTypes.InsertNode(New, InsertPos);
3696 llvm::FoldingSetNodeID ID;
3698 void *InsertPos =
nullptr;
3699 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3706 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3707 assert(!AT &&
"Shouldn't be in the map!");
3711 Types.push_back(AT);
3712 AdjustedTypes.InsertNode(AT, InsertPos);
3717 llvm::FoldingSetNodeID ID;
3719 void *InsertPos =
nullptr;
3720 AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3727 AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
3728 assert(!AT &&
"Shouldn't be in the map!");
3731 Types.push_back(AT);
3732 AdjustedTypes.InsertNode(AT, InsertPos);
3763 const auto *ATy = cast<ConstantArrayType>(Ty);
3764 llvm::FoldingSetNodeID ID;
3765 ATy->Profile(ID, *
this, ATy->getElementType(), ATy->getZExtSize(),
3766 ATy->getSizeExpr(), ATy->getSizeModifier(),
3767 ATy->getIndexTypeQualifiers().getAsOpaqueValue());
3768 void *InsertPos =
nullptr;
3770 ArrayParameterTypes.FindNodeOrInsertPos(ID, InsertPos);
3779 AT = ArrayParameterTypes.FindNodeOrInsertPos(ID, InsertPos);
3780 assert(!AT &&
"Shouldn't be in the map!");
3785 Types.push_back(AT);
3786 ArrayParameterTypes.InsertNode(AT, InsertPos);
3796 llvm::FoldingSetNodeID ID;
3799 void *InsertPos =
nullptr;
3801 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3807 if (!
T.isCanonical()) {
3812 BlockPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3813 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3817 Types.push_back(New);
3818 BlockPointerTypes.InsertNode(New, InsertPos);
3828 "Unresolved placeholder type");
3832 llvm::FoldingSetNodeID ID;
3835 void *InsertPos =
nullptr;
3837 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3845 if (!SpelledAsLValue || InnerRef || !
T.isCanonical()) {
3846 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() :
T);
3851 LValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3852 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3857 Types.push_back(New);
3858 LValueReferenceTypes.InsertNode(New, InsertPos);
3868 "Unresolved placeholder type");
3872 llvm::FoldingSetNodeID ID;
3875 void *InsertPos =
nullptr;
3877 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos))
3885 if (InnerRef || !
T.isCanonical()) {
3886 QualType PointeeType = (InnerRef ? InnerRef->getPointeeType() :
T);
3891 RValueReferenceTypes.FindNodeOrInsertPos(ID, InsertPos);
3892 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3897 Types.push_back(New);
3898 RValueReferenceTypes.InsertNode(New, InsertPos);
3907 llvm::FoldingSetNodeID ID;
3910 void *InsertPos =
nullptr;
3912 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos))
3923 MemberPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
3924 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3928 Types.push_back(New);
3929 MemberPointerTypes.InsertNode(New, InsertPos);
3936 const llvm::APInt &ArySizeIn,
3937 const Expr *SizeExpr,
3939 unsigned IndexTypeQuals)
const {
3942 "Constant array of VLAs is illegal!");
3950 llvm::APInt ArySize(ArySizeIn);
3951 ArySize = ArySize.zextOrTrunc(
Target->getMaxPointerWidth());
3953 llvm::FoldingSetNodeID ID;
3955 ASM, IndexTypeQuals);
3957 void *InsertPos =
nullptr;
3959 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos))
3970 ASM, IndexTypeQuals);
3975 ConstantArrayTypes.FindNodeOrInsertPos(ID, InsertPos);
3976 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
3979 auto *New = ConstantArrayType::Create(*
this, EltTy, Canon, ArySize, SizeExpr,
3980 ASM, IndexTypeQuals);
3981 ConstantArrayTypes.InsertNode(New, InsertPos);
3982 Types.push_back(New);
3991 if (!
type->isVariablyModifiedType())
return type;
3996 const Type *ty = split.
Ty;
3998#define TYPE(Class, Base)
3999#define ABSTRACT_TYPE(Class, Base)
4000#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
4001#include "clang/AST/TypeNodes.inc"
4002 llvm_unreachable(
"didn't desugar past all non-canonical types?");
4008 case Type::DependentVector:
4009 case Type::ExtVector:
4010 case Type::DependentSizedExtVector:
4011 case Type::ConstantMatrix:
4012 case Type::DependentSizedMatrix:
4013 case Type::DependentAddressSpace:
4014 case Type::ObjCObject:
4015 case Type::ObjCInterface:
4016 case Type::ObjCObjectPointer:
4019 case Type::UnresolvedUsing:
4020 case Type::TypeOfExpr:
4022 case Type::Decltype:
4023 case Type::UnaryTransform:
4024 case Type::DependentName:
4025 case Type::InjectedClassName:
4026 case Type::TemplateSpecialization:
4027 case Type::DependentTemplateSpecialization:
4028 case Type::TemplateTypeParm:
4029 case Type::SubstTemplateTypeParmPack:
4031 case Type::DeducedTemplateSpecialization:
4032 case Type::PackExpansion:
4033 case Type::PackIndexing:
4035 case Type::DependentBitInt:
4036 case Type::ArrayParameter:
4037 llvm_unreachable(
"type should never be variably-modified");
4041 case Type::FunctionNoProto:
4042 case Type::FunctionProto:
4043 case Type::BlockPointer:
4044 case Type::MemberPointer:
4057 case Type::LValueReference: {
4058 const auto *lv = cast<LValueReferenceType>(ty);
4061 lv->isSpelledAsLValue());
4065 case Type::RValueReference: {
4066 const auto *lv = cast<RValueReferenceType>(ty);
4072 case Type::Atomic: {
4073 const auto *at = cast<AtomicType>(ty);
4078 case Type::ConstantArray: {
4079 const auto *cat = cast<ConstantArrayType>(ty);
4084 cat->getSizeModifier(),
4085 cat->getIndexTypeCVRQualifiers());
4089 case Type::DependentSizedArray: {
4090 const auto *dat = cast<DependentSizedArrayType>(ty);
4094 dat->getSizeModifier(),
4095 dat->getIndexTypeCVRQualifiers(),
4096 dat->getBracketsRange());
4101 case Type::IncompleteArray: {
4102 const auto *iat = cast<IncompleteArrayType>(ty);
4111 case Type::VariableArray: {
4112 const auto *vat = cast<VariableArrayType>(ty);
4116 vat->getIndexTypeCVRQualifiers(), vat->getBracketsRange());
4129 unsigned IndexTypeQuals,
4140 IndexTypeQuals, Brackets);
4147 VariableArrayTypes.push_back(New);
4148 Types.push_back(New);
4158 unsigned elementTypeQuals,
4162 "Size must be type- or value-dependent!");
4166 void *insertPos =
nullptr;
4167 llvm::FoldingSetNodeID ID;
4169 ID, *
this, numElements ?
QualType(canonElementType.
Ty, 0) : elementType,
4170 ASM, elementTypeQuals, numElements);
4174 DependentSizedArrayTypes.FindNodeOrInsertPos(ID, insertPos);
4185 elementTypeQuals, brackets);
4186 DependentSizedArrayTypes.InsertNode(newType, insertPos);
4187 Types.push_back(newType);
4195 numElements, ASM, elementTypeQuals, brackets);
4196 DependentSizedArrayTypes.InsertNode(canonTy, insertPos);
4197 Types.push_back(canonTy);
4202 canonElementType.
Quals);
4206 if (
QualType(canonElementType.
Ty, 0) == elementType &&
4214 elementTypeQuals, brackets);
4215 Types.push_back(sugaredType);
4221 unsigned elementTypeQuals)
const {
4222 llvm::FoldingSetNodeID ID;
4225 void *insertPos =
nullptr;
4227 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos))
4239 ASM, elementTypeQuals);
4244 IncompleteArrayTypes.FindNodeOrInsertPos(ID, insertPos);
4245 assert(!existing &&
"Shouldn't be in the map!"); (void) existing;
4251 IncompleteArrayTypes.InsertNode(newType, insertPos);
4252 Types.push_back(newType);
4258#define SVE_INT_ELTTY(BITS, ELTS, SIGNED, NUMVECTORS) \
4259 {getIntTypeForBitwidth(BITS, SIGNED), llvm::ElementCount::getScalable(ELTS), \
4262#define SVE_ELTTY(ELTTY, ELTS, NUMVECTORS) \
4263 {ELTTY, llvm::ElementCount::getScalable(ELTS), NUMVECTORS};
4267 llvm_unreachable(
"Unsupported builtin vector type");
4268 case BuiltinType::SveInt8:
4270 case BuiltinType::SveUint8:
4272 case BuiltinType::SveInt8x2:
4274 case BuiltinType::SveUint8x2:
4276 case BuiltinType::SveInt8x3:
4278 case BuiltinType::SveUint8x3:
4280 case BuiltinType::SveInt8x4:
4282 case BuiltinType::SveUint8x4:
4284 case BuiltinType::SveInt16:
4286 case BuiltinType::SveUint16:
4288 case BuiltinType::SveInt16x2:
4290 case BuiltinType::SveUint16x2:
4292 case BuiltinType::SveInt16x3:
4294 case BuiltinType::SveUint16x3:
4296 case BuiltinType::SveInt16x4:
4298 case BuiltinType::SveUint16x4:
4300 case BuiltinType::SveInt32:
4302 case BuiltinType::SveUint32:
4304 case BuiltinType::SveInt32x2:
4306 case BuiltinType::SveUint32x2:
4308 case BuiltinType::SveInt32x3:
4310 case BuiltinType::SveUint32x3:
4312 case BuiltinType::SveInt32x4:
4314 case BuiltinType::SveUint32x4:
4316 case BuiltinType::SveInt64:
4318 case BuiltinType::SveUint64:
4320 case BuiltinType::SveInt64x2:
4322 case BuiltinType::SveUint64x2:
4324 case BuiltinType::SveInt64x3:
4326 case BuiltinType::SveUint64x3:
4328 case BuiltinType::SveInt64x4:
4330 case BuiltinType::SveUint64x4:
4332 case BuiltinType::SveBool:
4334 case BuiltinType::SveBoolx2:
4336 case BuiltinType::SveBoolx4:
4338 case BuiltinType::SveFloat16:
4340 case BuiltinType::SveFloat16x2:
4342 case BuiltinType::SveFloat16x3:
4344 case BuiltinType::SveFloat16x4:
4346 case BuiltinType::SveFloat32:
4348 case BuiltinType::SveFloat32x2:
4350 case BuiltinType::SveFloat32x3:
4352 case BuiltinType::SveFloat32x4:
4354 case BuiltinType::SveFloat64:
4356 case BuiltinType::SveFloat64x2:
4358 case BuiltinType::SveFloat64x3:
4360 case BuiltinType::SveFloat64x4:
4362 case BuiltinType::SveBFloat16:
4364 case BuiltinType::SveBFloat16x2:
4366 case BuiltinType::SveBFloat16x3:
4368 case BuiltinType::SveBFloat16x4:
4370#define RVV_VECTOR_TYPE_INT(Name, Id, SingletonId, NumEls, ElBits, NF, \
4372 case BuiltinType::Id: \
4373 return {getIntTypeForBitwidth(ElBits, IsSigned), \
4374 llvm::ElementCount::getScalable(NumEls), NF};
4375#define RVV_VECTOR_TYPE_FLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
4376 case BuiltinType::Id: \
4377 return {ElBits == 16 ? Float16Ty : (ElBits == 32 ? FloatTy : DoubleTy), \
4378 llvm::ElementCount::getScalable(NumEls), NF};
4379#define RVV_VECTOR_TYPE_BFLOAT(Name, Id, SingletonId, NumEls, ElBits, NF) \
4380 case BuiltinType::Id: \
4381 return {BFloat16Ty, llvm::ElementCount::getScalable(NumEls), NF};
4382#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4383 case BuiltinType::Id: \
4384 return {BoolTy, llvm::ElementCount::getScalable(NumEls), 1};
4385#include "clang/Basic/RISCVVTypes.def"
4392 if (
Target->getTriple().isWasm() &&
Target->hasFeature(
"reference-types")) {
4393#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
4394 if (BuiltinType::Id == BuiltinType::WasmExternRef) \
4396#include "clang/Basic/WebAssemblyReferenceTypes.def"
4399 "shouldn't try to generate type externref outside WebAssembly target");
4406 unsigned NumFields)
const {
4407 if (
Target->hasAArch64SVETypes()) {
4409#define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId, NumEls, ElBits, \
4410 IsSigned, IsFP, IsBF) \
4411 if (!EltTy->isBooleanType() && \
4412 ((EltTy->hasIntegerRepresentation() && \
4413 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4414 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
4416 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
4417 IsBF && !IsFP)) && \
4418 EltTySize == ElBits && NumElts == NumEls) { \
4419 return SingletonId; \
4421#define SVE_PREDICATE_TYPE(Name, MangledName, Id, SingletonId, NumEls) \
4422 if (EltTy->isBooleanType() && NumElts == NumEls) \
4424#define SVE_OPAQUE_TYPE(Name, MangledName, Id, SingleTonId)
4425#include "clang/Basic/AArch64SVEACLETypes.def"
4426 }
else if (
Target->hasRISCVVTypes()) {
4428#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned, \
4430 if (!EltTy->isBooleanType() && \
4431 ((EltTy->hasIntegerRepresentation() && \
4432 EltTy->hasSignedIntegerRepresentation() == IsSigned) || \
4433 (EltTy->hasFloatingRepresentation() && !EltTy->isBFloat16Type() && \
4435 (EltTy->hasFloatingRepresentation() && EltTy->isBFloat16Type() && \
4436 IsBF && !IsFP)) && \
4437 EltTySize == ElBits && NumElts == NumEls && NumFields == NF) \
4439#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
4440 if (EltTy->isBooleanType() && NumElts == NumEls) \
4442#include "clang/Basic/RISCVVTypes.def"
4458 llvm::FoldingSetNodeID ID;
4461 void *InsertPos =
nullptr;
4462 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4472 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4473 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4476 VectorType(vecType, NumElts, Canonical, VecKind);
4477 VectorTypes.InsertNode(New, InsertPos);
4478 Types.push_back(New);
4485 llvm::FoldingSetNodeID ID;
4488 void *InsertPos =
nullptr;
4490 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4495 VecType,
QualType(Canon, 0), SizeExpr, AttrLoc, VecKind);
4498 if (CanonVecTy == VecType) {
4503 DependentVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4504 assert(!CanonCheck &&
4505 "Dependent-sized vector_size canonical type broken");
4507 DependentVectorTypes.InsertNode(New, InsertPos);
4516 Types.push_back(New);
4523 unsigned NumElts)
const {
4531 llvm::FoldingSetNodeID ID;
4534 void *InsertPos =
nullptr;
4535 if (
VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
4545 VectorType *NewIP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4546 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4550 VectorTypes.InsertNode(New, InsertPos);
4551 Types.push_back(New);
4559 llvm::FoldingSetNodeID ID;
4563 void *InsertPos =
nullptr;
4565 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4575 if (CanonVecTy == vecType) {
4580 = DependentSizedExtVectorTypes.FindNodeOrInsertPos(ID, InsertPos);
4581 assert(!CanonCheck &&
"Dependent-sized ext_vector canonical type broken");
4583 DependentSizedExtVectorTypes.InsertNode(New, InsertPos);
4592 Types.push_back(New);
4597 unsigned NumColumns)
const {
4598 llvm::FoldingSetNodeID ID;
4600 Type::ConstantMatrix);
4603 "need a valid element type");
4606 "need valid matrix dimensions");
4607 void *InsertPos =
nullptr;
4617 assert(!NewIP &&
"Matrix type shouldn't already exist in the map");
4623 MatrixTypes.InsertNode(New, InsertPos);
4624 Types.push_back(New);
4633 llvm::FoldingSetNodeID ID;
4637 void *InsertPos =
nullptr;
4639 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4644 ColumnExpr, AttrLoc);
4647 DependentSizedMatrixTypes.FindNodeOrInsertPos(ID, InsertPos);
4648 assert(!CanonCheck &&
"Dependent-sized matrix canonical type broken");
4650 DependentSizedMatrixTypes.InsertNode(Canon, InsertPos);
4651 Types.push_back(Canon);
4664 ColumnExpr, AttrLoc);
4665 Types.push_back(New);
4670 Expr *AddrSpaceExpr,
4676 void *insertPos =
nullptr;
4677 llvm::FoldingSetNodeID ID;
4682 DependentAddressSpaceTypes.FindNodeOrInsertPos(ID, insertPos);
4688 DependentAddressSpaceTypes.InsertNode(canonTy, insertPos);
4689 Types.push_back(canonTy);
4692 if (canonPointeeType == PointeeType &&
4698 AddrSpaceExpr, AttrLoc);
4699 Types.push_back(sugaredType);
4705 return T.isCanonical() &&
4723 llvm::FoldingSetNodeID ID;
4726 void *InsertPos =
nullptr;
4728 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos))
4738 FunctionNoProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4739 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4744 Types.push_back(New);
4745 FunctionNoProtoTypes.InsertNode(New, InsertPos);
4761 return CanResultType;
4768 if (!NoexceptInType)
4785 bool AnyPackExpansions =
false;
4790 AnyPackExpansions =
true;
4792 return AnyPackExpansions;
4798QualType ASTContext::getFunctionTypeInternal(
4801 size_t NumArgs = ArgArray.size();
4805 llvm::FoldingSetNodeID
ID;
4810 bool Unique =
false;
4812 void *InsertPos =
nullptr;
4814 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos)) {
4834 bool IsCanonicalExceptionSpec =
4838 bool isCanonical = !Unique && IsCanonicalExceptionSpec &&
4840 for (
unsigned i = 0; i != NumArgs && isCanonical; ++i)
4841 if (!ArgArray[i].isCanonicalAsParam())
4842 isCanonical =
false;
4844 if (OnlyWantCanonical)
4845 assert(isCanonical &&
4846 "given non-canonical parameters constructing canonical type");
4851 if (!isCanonical && Canonical.
isNull()) {
4853 CanonicalArgs.reserve(NumArgs);
4854 for (
unsigned i = 0; i != NumArgs; ++i)
4861 if (IsCanonicalExceptionSpec) {
4863 }
else if (NoexceptInType) {
4876 bool AnyPacks =
false;
4899 llvm_unreachable(
"dependent noexcept is already canonical");
4908 getFunctionTypeInternal(CanResultTy, CanonicalArgs, CanonicalEPI,
true);
4912 FunctionProtoTypes.FindNodeOrInsertPos(ID, InsertPos);
4913 assert(!NewIP &&
"Shouldn't be in the map!"); (void)NewIP;
4918 auto ESH = FunctionProtoType::getExceptionSpecSize(
4920 size_t Size = FunctionProtoType::totalSizeToAlloc<
4927 ESH.NumExprPtr, ESH.NumFunctionDeclPtr,
4935 Types.push_back(FTP);
4937 FunctionProtoTypes.InsertNode(FTP, InsertPos);
4939 AnyFunctionEffects =
true;
4944 llvm::FoldingSetNodeID
ID;
4947 void *InsertPos =
nullptr;
4948 if (
PipeType *PT = PipeTypes.FindNodeOrInsertPos(ID, InsertPos))
4954 if (!
T.isCanonical()) {
4958 PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(ID, InsertPos);
4959 assert(!NewIP &&
"Shouldn't be in the map!");
4963 Types.push_back(New);
4964 PipeTypes.InsertNode(New, InsertPos);
4975 return getPipeType(
T,
true);
4979 return getPipeType(
T,
false);
4983 llvm::FoldingSetNodeID ID;
4986 void *InsertPos =
nullptr;
4987 if (
BitIntType *EIT = BitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
4991 BitIntTypes.InsertNode(New, InsertPos);
4992 Types.push_back(New);
4997 Expr *NumBitsExpr)
const {
4999 llvm::FoldingSetNodeID ID;
5002 void *InsertPos =
nullptr;
5004 DependentBitIntTypes.FindNodeOrInsertPos(ID, InsertPos))
5009 DependentBitIntTypes.InsertNode(New, InsertPos);
5011 Types.push_back(New);
5017 if (!isa<CXXRecordDecl>(
D))
return false;
5018 const auto *RD = cast<CXXRecordDecl>(
D);
5019 if (isa<ClassTemplatePartialSpecializationDecl>(RD))
5021 if (RD->getDescribedClassTemplate() &&
5022 !isa<ClassTemplateSpecializationDecl>(RD))
5033 if (
Decl->TypeForDecl) {
5034 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
5036 assert(PrevDecl->TypeForDecl &&
"previous declaration has no type");
5037 Decl->TypeForDecl = PrevDecl->TypeForDecl;
5038 assert(isa<InjectedClassNameType>(
Decl->TypeForDecl));
5042 Decl->TypeForDecl = newType;
5043 Types.push_back(newType);