55#include "llvm/ADT/APSInt.h"
56#include "llvm/ADT/ArrayRef.h"
57#include "llvm/ADT/STLExtras.h"
58#include "llvm/ADT/SmallVector.h"
59#include "llvm/ADT/StringRef.h"
60#include "llvm/ADT/StringSwitch.h"
61#include "llvm/Support/Casting.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/raw_ostream.h"
64#include "llvm/TargetParser/Triple.h"
90 if (
auto *ND = dyn_cast_if_present<NamedDecl>(TheDecl)) {
104TranslationUnitDecl::TranslationUnitDecl(
ASTContext &ctx)
106 DeclContext(TranslationUnit), redeclarable_base(ctx), Ctx(ctx) {}
168 Kind.IgnoreExplicitVisibility =
true;
174 assert(!kind.IgnoreExplicitVisibility &&
175 "asking for explicit visibility when we shouldn't be");
176 return D->getExplicitVisibility(kind.getExplicitVisibilityKind());
182 return isa<TypeDecl>(
D) ||
183 isa<ClassTemplateDecl>(
D) ||
184 isa<ObjCInterfaceDecl>(
D);
190static std::enable_if_t<!std::is_base_of_v<RedeclarableTemplateDecl, T>,
bool>
193 D->getMemberSpecializationInfo()) {
194 return member->isExplicitSpecialization();
203 return D->isMemberSpecialization();
210 switch (
attr->getVisibility()) {
218 llvm_unreachable(
"bad visibility kind");
222static std::optional<Visibility>
227 if (
const auto *A =
D->
getAttr<TypeVisibilityAttr>()) {
233 if (
const auto *A =
D->
getAttr<VisibilityAttr>()) {
250LinkageInfo LinkageComputer::getLVForTemplateParameterList(
256 if (isa<TemplateTypeParmDecl>(
P))
263 if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(
P)) {
265 if (!NTTP->isExpandedParameterPack()) {
266 if (!NTTP->getType()->isDependentType()) {
267 LV.
merge(getLVForType(*NTTP->getType(), computation));
273 for (
unsigned i = 0, n = NTTP->getNumExpansionTypes(); i != n; ++i) {
275 if (!
type->isDependentType())
283 const auto *TTP = cast<TemplateTemplateParmDecl>(
P);
286 if (!TTP->isExpandedParameterPack()) {
287 LV.
merge(getLVForTemplateParameterList(TTP->getTemplateParameters(),
293 for (
unsigned i = 0, n = TTP->getNumExpansionTemplateParameters();
295 LV.
merge(getLVForTemplateParameterList(
296 TTP->getExpansionTemplateParameters(i), computation));
304 const Decl *Ret =
nullptr;
306 while (DC->
getDeclKind() != Decl::TranslationUnit) {
307 if (isa<FunctionDecl>(DC) || isa<BlockDecl>(DC))
308 Ret = cast<Decl>(DC);
325 switch (Arg.getKind()) {
332 LV.
merge(getLVForType(*Arg.getAsType(), computation));
347 LV.
merge(getLVForValue(Arg.getAsStructuralValue(), computation));
353 Arg.getAsTemplateOrTemplatePattern().getAsTemplateDecl())
358 LV.
merge(getLVForTemplateArgumentList(Arg.getPackAsArray(), computation));
361 llvm_unreachable(
"bad template argument kind");
370 return getLVForTemplateArgumentList(TArgs.
asArray(), computation);
382 return !fn->
hasAttr<VisibilityAttr>();
392void LinkageComputer::mergeTemplateLV(
396 bool considerVisibility =
413 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
466void LinkageComputer::mergeTemplateLV(
489 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
490 if (considerVisibility)
523void LinkageComputer::mergeTemplateLV(
LinkageInfo &LV,
540 LinkageInfo argsLV = getLVForTemplateArgumentList(templateArgs, computation);
541 if (considerVisibility)
549 if (!Opts.CPlusPlus || !Opts.InlineVisibilityHidden)
552 const auto *FD = dyn_cast<FunctionDecl>(
D);
558 = FD->getTemplateSpecializationInfo()) {
561 FD->getMemberSpecializationInfo()) {
562 TSK = MSI->getTemplateSpecializationKind();
575 const T *
First =
D->getFirstDecl();
576 return First->isInExternCContext();
581 if (!SD->hasBraces())
591 if (
auto *TD = dyn_cast<TemplateDecl>(
D))
592 D = TD->getTemplatedDecl();
594 if (
auto *VD = dyn_cast<VarDecl>(
D))
595 return VD->getStorageClass();
596 if (
auto *FD = dyn_cast<FunctionDecl>(
D))
597 return FD->getStorageClass();
603LinkageComputer::getLVForNamespaceScopeDecl(
const NamedDecl *
D,
605 bool IgnoreVarTypeLinkage) {
607 "Not a name having namespace scope");
609 const auto *Var = dyn_cast<VarDecl>(
D);
616 (Context.
getLangOpts().C23 && Var && Var->isConstexpr())) {
637 if (Context.
getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
638 !Var->getType().isVolatileQualified() && !Var->isInline() &&
642 if (auto *M = Var->getOwningModule())
643 return M->isInterfaceOrPartition() || M->isImplicitGlobalModule();
646 !isa<VarTemplateSpecializationDecl>(Var) &&
647 !Var->getDescribedVarTemplate()) {
652 if (Var->getStorageClass() !=
SC_Extern &&
661 Var->getStorageClass() ==
SC_None)
667 }
else if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(
D)) {
669 const VarDecl *VD = IFD->getVarDecl();
670 assert(VD &&
"Expected a VarDecl in this IndirectFieldDecl!");
671 return getLVForNamespaceScopeDecl(VD, computation, IgnoreVarTypeLinkage);
673 assert(!isa<FieldDecl>(
D) &&
"Didn't expect a FieldDecl!");
678 const auto *Var = dyn_cast<VarDecl>(
D);
679 const auto *
Func = dyn_cast<FunctionDecl>(
D);
707 !isa<TranslationUnitDecl>(DC);
709 const auto *ND = dyn_cast<NamespaceDecl>(DC);
711 if (std::optional<Visibility> Vis =
751 if (
const auto *Var = dyn_cast<VarDecl>(
D)) {
775 !IgnoreVarTypeLinkage) {
776 LinkageInfo TypeLV = getLVForType(*Var->getType(), computation);
793 if (
const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
794 mergeTemplateLV(LV, spec, computation);
798 }
else if (
const auto *
Function = dyn_cast<FunctionDecl>(
D)) {
814 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(
Function)))
830 TypeAsWritten = TSI->getType();
839 =
Function->getTemplateSpecializationInfo()) {
840 mergeTemplateLV(LV,
Function, specInfo, computation);
849 }
else if (
const auto *Tag = dyn_cast<TagDecl>(
D)) {
851 if (!
Tag->hasNameForLinkage())
857 if (
const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(Tag)) {
858 mergeTemplateLV(LV, spec, computation);
863 }
else if (isa<EnumConstantDecl>(
D)) {
871 }
else if (
const auto *temp = dyn_cast<TemplateDecl>(
D)) {
882 }
else if (isa<NamespaceDecl>(
D)) {
887 }
else if (isa<ObjCInterfaceDecl>(
D)) {
890 }
else if (
auto *TD = dyn_cast<TypedefNameDecl>(
D)) {
893 if (!TD->getAnonDeclWithTypedefName(
true))
896 }
else if (isa<MSGuidDecl>(
D)) {
914LinkageComputer::getLVForClassMember(
const NamedDecl *
D,
916 bool IgnoreVarTypeLinkage) {
927 if (!(isa<CXXMethodDecl>(
D) ||
930 isa<IndirectFieldDecl>(
D) ||
932 isa<TemplateDecl>(
D)))
970 const NamedDecl *explicitSpecSuppressor =
nullptr;
972 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
D)) {
975 QualType TypeAsWritten = MD->getType();
977 TypeAsWritten = TSI->getType();
984 = MD->getTemplateSpecializationInfo()) {
985 mergeTemplateLV(LV, MD, spec, computation);
987 explicitSpecSuppressor = MD;
989 explicitSpecSuppressor = spec->getTemplate()->getTemplatedDecl();
992 explicitSpecSuppressor = MD;
1003 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(MD)))
1006 }
else if (
const auto *RD = dyn_cast<CXXRecordDecl>(
D)) {
1007 if (
const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
1008 mergeTemplateLV(LV, spec, computation);
1010 explicitSpecSuppressor = spec;
1018 explicitSpecSuppressor = RD;
1022 }
else if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
1023 if (
const auto *spec = dyn_cast<VarTemplateSpecializationDecl>(VD))
1024 mergeTemplateLV(LV, spec, computation);
1028 if (!IgnoreVarTypeLinkage) {
1038 explicitSpecSuppressor = VD;
1042 }
else if (
const auto *temp = dyn_cast<TemplateDecl>(
D)) {
1043 bool considerVisibility =
1051 if (
const auto *redeclTemp = dyn_cast<RedeclarableTemplateDecl>(temp)) {
1059 assert(!explicitSpecSuppressor || !isa<TemplateDecl>(explicitSpecSuppressor));
1063 bool considerClassVisibility =
true;
1064 if (explicitSpecSuppressor &&
1069 considerClassVisibility =
false;
1077void NamedDecl::anchor() {}
1100 if (isa<FieldDecl>(
this))
1102 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(
this)) {
1106 const VarDecl *VD = IFD->getVarDecl();
1110 if (
const auto *VD = dyn_cast<VarDecl>(
this)) {
1111 if (isa<ParmVarDecl>(VD))
1117 if (
const auto *BD = dyn_cast<BindingDecl>(
this);
1119 const VarDecl *VD = BD->getHoldingVar();
1151 if (
auto *VD = dyn_cast<VarDecl>(
this))
1154 if (
auto *FD = dyn_cast<FunctionDecl>(
this))
1155 if (FD->isExternC())
1167 if (name.front() ==
'C')
1168 if (name ==
"CFStringCreateWithFormat" ||
1169 name ==
"CFStringCreateWithFormatAndArguments" ||
1170 name ==
"CFStringAppendFormat" ||
1171 name ==
"CFStringAppendFormatAndArguments")
1195 llvm_unreachable(
"unexpected module ownership kind");
1214 !isa<NamespaceDecl>(
this))
1224static std::optional<Visibility>
1227 bool IsMostRecent) {
1236 if (
const auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
1238 if (InstantiatedFrom)
1245 if (
const auto *spec = dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
1249 while (TD !=
nullptr) {
1251 if (Vis != std::nullopt)
1253 TD = TD->getPreviousDecl();
1255 return std::nullopt;
1259 if (!IsMostRecent && !isa<NamespaceDecl>(ND)) {
1261 if (MostRecent != ND)
1265 if (
const auto *Var = dyn_cast<VarDecl>(ND)) {
1266 if (Var->isStaticDataMember()) {
1268 if (InstantiatedFrom)
1272 if (
const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Var))
1273 return getVisibilityOf(VTSD->getSpecializedTemplate()->getTemplatedDecl(),
1276 return std::nullopt;
1279 if (
const auto *fn = dyn_cast<FunctionDecl>(ND)) {
1284 return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl(),
1290 if (InstantiatedFrom)
1293 return std::nullopt;
1297 if (
const auto *TD = dyn_cast<TemplateDecl>(ND))
1300 return std::nullopt;
1303std::optional<Visibility>
1314 Owner = dyn_cast<NamedDecl>(DC);
1315 else if (isa<ParmVarDecl>(ContextDecl))
1318 else if (isa<ImplicitConceptSpecializationDecl>(ContextDecl)) {
1323 Owner = cast<NamedDecl>(ContextDecl);
1333 auto *VD = dyn_cast<VarDecl>(Owner);
1349 if (
const auto *
Function = dyn_cast<FunctionDecl>(
D)) {
1350 if (
Function->isInAnonymousNamespace() &&
1360 if (std::optional<Visibility> Vis =
1372 if (
const auto *Var = dyn_cast<VarDecl>(
D)) {
1373 if (Var->hasExternalStorage()) {
1381 if (std::optional<Visibility> Vis =
1396 if (!Var->isStaticLocal())
1409 if (
const auto *BD = dyn_cast<BlockDecl>(OuterD)) {
1410 if (!BD->getBlockManglingNumber())
1413 LV = getLVForClosure(BD->getDeclContext()->getRedeclContext(),
1414 BD->getBlockManglingContextDecl(), computation);
1416 const auto *FD = cast<FunctionDecl>(OuterD);
1417 if (!FD->isInlined() &&
1427 !Context.
getLangOpts().VisibilityInlinesHiddenStaticLocalVar) {
1428 assert(cast<VarDecl>(
D)->isStaticLocal());
1432 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1452 bool IgnoreVarTypeLinkage) {
1454 if (
D->
hasAttr<InternalLinkageAttr>())
1469 case Decl::ImplicitParam:
1471 case Decl::NamespaceAlias:
1474 case Decl::UsingEnum:
1475 case Decl::UsingShadow:
1476 case Decl::UsingDirective:
1479 case Decl::EnumConstant:
1486 case Decl::TypeAlias:
1489 if (!cast<TypedefNameDecl>(
D)
1490 ->getAnonDeclWithTypedefName(
true))
1494 case Decl::TemplateTemplateParm:
1495 case Decl::NonTypeTemplateParm:
1496 case Decl::ObjCAtDefsField:
1497 case Decl::ObjCCategory:
1498 case Decl::ObjCCategoryImpl:
1499 case Decl::ObjCCompatibleAlias:
1500 case Decl::ObjCImplementation:
1501 case Decl::ObjCMethod:
1502 case Decl::ObjCProperty:
1503 case Decl::ObjCPropertyImpl:
1504 case Decl::ObjCProtocol:
1507 case Decl::CXXRecord: {
1508 const auto *
Record = cast<CXXRecordDecl>(
D);
1509 if (
Record->isLambda()) {
1510 if (
Record->hasKnownLambdaInternalLinkage() ||
1511 !
Record->getLambdaManglingNumber()) {
1516 return getLVForClosure(
1517 Record->getDeclContext()->getRedeclContext(),
1518 Record->getLambdaContextDecl(), computation);
1524 case Decl::TemplateParamObject: {
1527 auto *TPO = cast<TemplateParamObjectDecl>(
D);
1528 LinkageInfo LV = getLVForType(*TPO->getType(), computation);
1529 LV.
merge(getLVForValue(TPO->getValue(), computation));
1536 return getLVForNamespaceScopeDecl(
D, computation, IgnoreVarTypeLinkage);
1546 return getLVForClassMember(
D, computation, IgnoreVarTypeLinkage);
1560 return getLVForLocalDecl(
D, computation);
1571 if (
D->
hasAttr<InternalLinkageAttr>())
1577 if (std::optional<LinkageInfo> LI = lookup(
D, computation))
1585 cache(
D, computation, LV);
1592 if (!Opts.CPlusPlus || Opts.MicrosoftExt)
1600 auto *
T = cast<NamedDecl>(I);
1603 if (!
T->isInvalidDecl() &&
T->hasCachedLinkage()) {
1625 if (isa<NamespaceDecl>(
this))
1657 llvm_unreachable(
"unknown module kind");
1661 Name.
print(OS, Policy);
1669 std::string QualName;
1670 llvm::raw_string_ostream OS(QualName);
1693 llvm::raw_svector_ostream NameOS(NameBuffer);
1695 if (NameBuffer.empty())
1696 OS <<
"(anonymous)";
1712 if (
auto *MD = dyn_cast<ObjCMethodDecl>(
this)) {
1713 if (
auto *ID = MD->getClassInterface())
1715 }
else if (
auto *PD = dyn_cast<ObjCPropertyDecl>(
this)) {
1716 if (
auto *MD = PD->getGetterMethodDecl())
1717 if (
auto *ID = MD->getClassInterface())
1719 }
else if (
auto *ID = dyn_cast<ObjCIvarDecl>(
this)) {
1720 if (
auto *CI = ID->getContainingInterface())
1728 ContextsTy Contexts;
1734 if (
P.SuppressUnwrittenScope && isa<NamespaceDecl>(Ctx) &&
1735 cast<NamespaceDecl>(Ctx)->isAnonymousNamespace())
1740 cast<NamespaceDecl>(Ctx)->isRedundantInlineQualifierFor(NameInScope))
1744 const NamedDecl *ND = dyn_cast<NamedDecl>(Ctx);
1748 Contexts.push_back(Ctx);
1752 for (
const DeclContext *DC : llvm::reverse(Contexts)) {
1753 if (
const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(DC)) {
1754 OS << Spec->getName();
1758 Spec->getSpecializedTemplate()->getTemplateParameters());
1759 }
else if (
const auto *ND = dyn_cast<NamespaceDecl>(DC)) {
1760 if (ND->isAnonymousNamespace()) {
1761 OS << (
P.MSVCFormatting ?
"`anonymous namespace\'"
1762 :
"(anonymous namespace)");
1766 }
else if (
const auto *RD = dyn_cast<RecordDecl>(DC)) {
1767 if (!RD->getIdentifier())
1768 OS <<
"(anonymous " << RD->getKindName() <<
')';
1771 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(DC)) {
1773 if (FD->hasWrittenPrototype())
1774 FT = dyn_cast<FunctionProtoType>(FD->getType()->castAs<
FunctionType>());
1778 unsigned NumParams = FD->getNumParams();
1779 for (
unsigned i = 0; i < NumParams; ++i) {
1782 OS << FD->getParamDecl(i)->getType().stream(
P);
1792 }
else if (
const auto *ED = dyn_cast<EnumDecl>(DC)) {
1805 OS << *cast<NamedDecl>(DC);
1826#define DECL(Type, Base) \
1828 return isRedeclarableImpl((Type##Decl *)nullptr);
1829#define ABSTRACT_DECL(DECL)
1830#include "clang/AST/DeclNodes.inc"
1832 llvm_unreachable(
"unknown decl kind");
1836 bool IsKnownNewer)
const {
1849 if (isa<ObjCMethodDecl>(
this))
1854 if (isa<ParmVarDecl>(
this))
1866 if (
const auto *UD = dyn_cast<UsingDecl>(
this)) {
1870 cast<UsingDecl>(OldD)->getQualifier());
1872 if (
const auto *UUVD = dyn_cast<UnresolvedUsingValueDecl>(
this)) {
1876 cast<UnresolvedUsingValueDecl>(OldD)->getQualifier());
1915 llvm_unreachable(
"Linkage hasn't been computed!");
1922 llvm_unreachable(
"Non-formal linkage is not allowed here!");
1927 llvm_unreachable(
"Unhandled Linkage enum");
1930NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
1932 if (
auto *UD = dyn_cast<UsingShadowDecl>(ND))
1933 ND = UD->getTargetDecl();
1935 if (
auto *AD = dyn_cast<ObjCCompatibleAliasDecl>(ND))
1936 return AD->getClassInterface();
1938 if (
auto *AD = dyn_cast<NamespaceAliasDecl>(ND))
1939 return AD->getNamespace();
1949 if (isa<UsingShadowDecl>(
D))
1950 D = cast<UsingShadowDecl>(
D)->getTargetDecl();
1952 if (isa<FieldDecl>(
D) || isa<IndirectFieldDecl>(
D) || isa<MSPropertyDecl>(
D))
1954 if (
const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
D->
getAsFunction()))
1955 return MD->isInstance();
1963template <
typename DeclT>
1965 if (
decl->getNumTemplateParameterLists() > 0)
1966 return decl->getTemplateParameterList(0)->getTemplateLoc();
1967 return decl->getInnerLocStart();
1985 if (!hasExtInfo()) {
1991 getExtInfo()->TInfo = savedTInfo;
1994 getExtInfo()->QualifierLoc = QualifierLoc;
1995 }
else if (hasExtInfo()) {
1997 getExtInfo()->QualifierLoc = QualifierLoc;
2002 assert(TrailingRequiresClause);
2004 if (!hasExtInfo()) {
2010 getExtInfo()->TInfo = savedTInfo;
2013 getExtInfo()->TrailingRequiresClause = TrailingRequiresClause;
2018 assert(!TPLists.empty());
2020 if (!hasExtInfo()) {
2026 getExtInfo()->TInfo = savedTInfo;
2029 getExtInfo()->setTemplateParameterListsInfo(Context, TPLists);
2047 case Type::BlockPointer:
2050 case Type::MemberPointer:
2053 case Type::LValueReference:
2054 case Type::RValueReference:
2057 case Type::PackExpansion:
2058 QT = cast<PackExpansionType>(
T)->getPattern();
2061 case Type::ConstantArray:
2062 case Type::DependentSizedArray:
2063 case Type::IncompleteArray:
2064 case Type::VariableArray:
2065 case Type::FunctionProto:
2066 case Type::FunctionNoProto:
2078 RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
2092 if (!TPLists.empty()) {
2113 llvm_unreachable(
"Invalid storage class");
2122 static_assert(
sizeof(VarDeclBitfields) <=
sizeof(
unsigned),
2123 "VarDeclBitfields too large!");
2125 "ParmVarDeclBitfields too large!");
2127 "NonParmVarDeclBitfields too large!");
2136 return new (
C, DC)
VarDecl(Var,
C, DC, StartL, IdL,
Id,
T, TInfo, S);
2153 if (!hasAttr<ThreadAttr>() &&
2156 hasAttr<OMPThreadPrivateDeclAttr>()))
2160 hasAttr<OMPThreadPrivateDeclAttr>())
2169 llvm_unreachable(
"Unknown thread storage class specifier!");
2187 if (!
D.hasExternalFormalLinkage())
2271 isa<VarTemplatePartialSpecializationDecl>(
this)))
2290 if (
const auto *SAA = getAttr<SelectAnyAttr>())
2291 if (!SAA->isInherited())
2297 if (
auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(
this)) {
2299 !isa<VarTemplatePartialSpecializationDecl>(VTSD) &&
2300 !VTSD->IsCompleteDefinition)
2332 VarDecl *LastTentative =
nullptr;
2337 Kind =
Decl->isThisDeclarationADefinition();
2342 LastTentative =
Decl;
2345 return LastTentative;
2351 if (I->isThisDeclarationADefinition(
C) ==
Definition)
2362 Kind = std::max(
Kind, I->isThisDeclarationADefinition(
C));
2372 if (
auto Expr = I->getInit()) {
2381 if (
auto *
P = dyn_cast<ParmVarDecl>(
this))
2382 if (
P->hasUnparsedDefaultArg() ||
P->hasUninstantiatedDefaultArg())
2386 return Eval->Value.isValid();
2388 return !
Init.isNull();
2395 if (
auto *S =
Init.dyn_cast<
Stmt *>())
2396 return cast<Expr>(S);
2400 return cast<Expr>(Eval->Value.get(
2401 Eval->Value.isOffset() ?
getASTContext().getExternalSource() :
nullptr));
2406 return ES->Value.getAddressOfPointer(
getASTContext().getExternalSource());
2408 return Init.getAddrOfPtr1();
2417 if (I->isThisDeclarationADefinition()) {
2444 Eval->~EvaluatedStmt();
2456 if (!Lang.CPlusPlus && !Lang.OpenCL && !Lang.C23)
2460 if (isa<ParmVarDecl>(
this))
2469 if (Lang.CPlusPlus11 &&
getType()->isReferenceType())
2480 if (
getType()->isIntegralOrEnumerationType() && !Lang.C23)
2490 return (Lang.CPlusPlus11 || Lang.C23) &&
isConstexpr();
2497 const VarDecl *DefVD =
nullptr;
2499 if (!
Init ||
Init->isValueDependent() ||
getType()->isDependentType())
2545 bool IsConstantInitialization)
const {
2549 assert(!
Init->isValueDependent());
2566 IsConstantInitialization);
2572 if (IsConstantInitialization &&
2602 assert(
Init &&
"no initializer");
2632 "already evaluated var value before checking for constant init");
2635 "only meaningful in C++/C23");
2637 assert(!
getInit()->isValueDependent());
2641 evaluateValueImpl(Notes,
true) && Notes.empty();
2652 return isa<PackExpansionType>(
getType());
2655template<
typename DeclT>
2658 if (
auto *Def =
D->getDefinition())
2674 llvm::any_of(specific_attrs<AlignedAttr>(), [](
const AlignedAttr *AA) {
2675 return AA->isAlignmentDependent();
2694 if (
auto *VDTemplSpec = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
2696 auto From = VDTemplSpec->getInstantiatedFrom();
2698 while (!VTD->isMemberSpecialization()) {
2699 auto *NewVTD = VTD->getInstantiatedFromMemberTemplate();
2708 while (!VTPSD->isMemberSpecialization()) {
2709 auto *NewVTPSD = VTPSD->getInstantiatedFromMember();
2714 return getDefinitionOrSelf<VarDecl>(VTPSD);
2722 while (!VarTemplate->isMemberSpecialization()) {
2723 auto *NewVT = VarTemplate->getInstantiatedFromMemberTemplate();
2726 VarTemplate = NewVT;
2739 return cast<VarDecl>(MSI->getInstantiatedFrom());
2745 if (
const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(
this))
2746 return Spec->getSpecializationKind();
2749 return MSI->getTemplateSpecializationKind();
2757 return MSI->getTemplateSpecializationKind();
2759 if (
const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(
this))
2760 return Spec->getSpecializationKind();
2766 if (
const auto *Spec = dyn_cast<VarTemplateSpecializationDecl>(
this))
2767 return Spec->getPointOfInstantiation();
2770 return MSI->getPointOfInstantiation();
2793 if (LangOpts.CUDA && !LangOpts.GPURelocatableDeviceCode &&
2795 isa<IncompleteArrayType>(
getType()))
2804 !hasAttr<AlwaysDestroyAttr>()));
2820 assert(
hasInit() &&
"Expect initializer to check for flexible array init");
2822 if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
2824 auto *List = dyn_cast<InitListExpr>(
getInit()->IgnoreParens());
2827 const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
2835 assert(
hasInit() &&
"Expect initializer to check for flexible array init");
2837 if (!Ty || !Ty->getDecl()->hasFlexibleArrayMember())
2839 auto *List = dyn_cast<InitListExpr>(
getInit()->IgnoreParens());
2840 if (!List || List->getNumInits() == 0)
2842 const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
2850 if (FlexibleArrayOffset + FlexibleArraySize < RL.
getSize())
2852 return FlexibleArrayOffset + FlexibleArraySize - RL.
getSize();
2866 assert((isa<VarTemplateSpecializationDecl>(
this) ||
2868 "not a variable or static data member template specialization");
2871 dyn_cast<VarTemplateSpecializationDecl>(
this)) {
2872 Spec->setSpecializationKind(TSK);
2874 PointOfInstantiation.
isValid() &&
2875 Spec->getPointOfInstantiation().isInvalid()) {
2876 Spec->setPointOfInstantiation(PointOfInstantiation);
2878 L->InstantiationRequested(
this);
2881 MSI->setTemplateSpecializationKind(TSK);
2883 MSI->getPointOfInstantiation().isInvalid()) {
2884 MSI->setPointOfInstantiation(PointOfInstantiation);
2886 L->InstantiationRequested(
this);
2894 assert(
getASTContext().getTemplateOrSpecializationInfo(
this).isNull() &&
2895 "Previous template or instantiation?");
2908 return new (
C, DC)
ParmVarDecl(ParmVar,
C, DC, StartLoc, IdLoc,
Id,
T, TInfo,
2915 if (
const auto *DT = dyn_cast<DecayedType>(
T))
2916 return DT->getOriginalType();
2943 if (hasAttr<NSConsumedAttr>())
2949 if (RT && RT->getDecl()->isParamDestroyedInCallee() &&
2959 "Default argument is not yet instantiated!");
2962 if (
auto *
E = dyn_cast_if_present<FullExpr>(Arg))
2963 return E->getSubExpr();
2990 llvm_unreachable(
"Invalid default argument kind.");
3000 "Wrong kind of initialization expression!");
3001 return cast_if_present<Expr>(
Init.get<
Stmt *>());
3012void ParmVarDecl::setParameterIndexLarge(
unsigned parameterIndex) {
3017unsigned ParmVarDecl::getParameterIndexLarge()
const {
3029 bool UsesFPIntrin,
bool isInlineSpecified,
3031 Expr *TrailingRequiresClause)
3035 EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.
getInfo()) {
3065 if (TrailingRequiresClause)
3078 if (
const auto *FT =
getType()->getAs<FunctionProtoType>())
3079 return FT->isVariadic();
3087 static constexpr size_t Alignment =
3090 size_t Size = totalSizeToAlloc<DeclAccessPair, StringLiteral *>(
3091 Lookups.size(), DeletedMessage !=
nullptr);
3095 Info->NumLookups = Lookups.size();
3096 Info->HasDeletedMessage = DeletedMessage !=
nullptr;
3098 std::uninitialized_copy(Lookups.begin(), Lookups.end(),
3101 *Info->getTrailingObjects<
StringLiteral *>() = DeletedMessage;
3107 assert(!
FunctionDeclBits.HasDefaultedOrDeletedInfo &&
"already have this");
3108 assert(!
Body &&
"can't replace function body with defaulted function info");
3133 assert(HasDeletedMessage &&
3134 "No space to store a delete message in this DefaultedOrDeletedInfo");
3135 *getTrailingObjects<StringLiteral *>() = Message;
3145 for (
const auto *I :
redecls()) {
3146 if (I->doesThisDeclarationHaveABody()) {
3163 if (isa<CompoundStmt>(S) && cast<CompoundStmt>(S)->body_empty())
3176 return InstantiatedFrom->getFriendObjectKind() &&
3177 InstantiatedFrom->isThisDeclarationADefinition();
3184 return InstantiatedFrom->getFriendObjectKind() &&
3185 InstantiatedFrom->isThisDeclarationADefinition();
3192 bool CheckForPendingFriendDefinition)
const {
3194 if (FD->isThisDeclarationADefinition()) {
3214 if (CheckForPendingFriendDefinition &&
3215 FD->isThisDeclarationInstantiatedFromAFriendDefinition()) {
3228 assert(!
Definition->FunctionDeclBits.HasDefaultedOrDeletedInfo &&
3229 "definition should not have a body");
3247 Parent->markedVirtualFunctionPure();
3250template<std::
size_t Len>
3253 return II && II->
isStr(Str);
3287 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
this);
3288 MD && MD->isLambdaStaticInvoker())
3289 return MD->getParent()->getLambdaCallOperator()->isImmediateFunction();
3317 return llvm::StringSwitch<bool>(
getName())
3330 if (
getDeclName().getCXXOverloadedOperator() != OO_New &&
3331 getDeclName().getCXXOverloadedOperator() != OO_Delete &&
3332 getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
3333 getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
3340 if (proto->getNumParams() != 2 || proto->isVariadic())
3349 return (proto->getParamType(1).getCanonicalType() == Context.
VoidPtrTy);
3353 std::optional<unsigned> *AlignmentParam,
bool *IsNothrow)
const {
3356 if (
getDeclName().getCXXOverloadedOperator() != OO_New &&
3357 getDeclName().getCXXOverloadedOperator() != OO_Delete &&
3358 getDeclName().getCXXOverloadedOperator() != OO_Array_New &&
3359 getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
3370 if (FPT->getNumParams() == 0 || FPT->getNumParams() > 4 || FPT->isVariadic())
3375 if (FPT->getNumParams() == 1)
3378 unsigned Params = 1;
3379 QualType Ty = FPT->getParamType(Params);
3382 auto Consume = [&] {
3384 Ty = Params < FPT->getNumParams() ? FPT->getParamType(Params) :
QualType();
3388 bool IsSizedDelete =
false;
3390 (
getDeclName().getCXXOverloadedOperator() == OO_Delete ||
3391 getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
3393 IsSizedDelete =
true;
3402 *AlignmentParam = Params;
3425 T = TD->getDecl()->getUnderlyingType();
3428 if (II && II->
isStr(
"__hot_cold_t"))
3432 return Params == FPT->getNumParams();
3457 llvm_unreachable(
"Unknown GVALinkage");
3471 RD->getIdentifier()->isStr(
"destroying_delete_t");
3483 if (hasAttr<OpenCLKernelAttr>())
3493 if (
const auto *Method = dyn_cast<CXXMethodDecl>(
this))
3494 return Method->isStatic();
3502 if (
const auto *Namespace = cast<NamespaceDecl>(DC)) {
3503 if (!Namespace->getDeclName())
3512 if (hasAttr<NoReturnAttr>() || hasAttr<CXX11NoReturnAttr>() ||
3513 hasAttr<C11NoReturnAttr>())
3516 if (
auto *FnTy =
getType()->getAs<FunctionType>())
3517 return FnTy->getNoReturnAttr();
3545 if (hasAttr<TargetAttr>())
3547 if (hasAttr<TargetVersionAttr>())
3549 if (hasAttr<CPUDispatchAttr>())
3551 if (hasAttr<CPUSpecificAttr>())
3553 if (hasAttr<TargetClonesAttr>())
3568 (hasAttr<TargetAttr>() || hasAttr<TargetVersionAttr>());
3574 if (hasAttr<TargetAttr>())
3575 return getAttr<TargetAttr>()->isDefaultVersion();
3576 return hasAttr<TargetVersionAttr>() &&
3577 getAttr<TargetVersionAttr>()->isDefaultVersion();
3595 assert((!PrevDecl || PrevFunTmpl) &&
"Function/function template mismatch");
3596 FunTmpl->setPreviousDecl(PrevFunTmpl);
3619 unsigned BuiltinID = 0;
3621 if (
const auto *ABAA = getAttr<ArmBuiltinAliasAttr>()) {
3622 BuiltinID = ABAA->getBuiltinName()->getBuiltinID();
3623 }
else if (
const auto *BAA = getAttr<BuiltinAliasAttr>()) {
3624 BuiltinID = BAA->getBuiltinName()->getBuiltinID();
3625 }
else if (
const auto *A = getAttr<BuiltinAttr>()) {
3626 BuiltinID = A->getID();
3634 if (!ConsiderWrapperFunctions && hasAttr<OverloadableAttr>() &&
3635 (!hasAttr<ArmBuiltinAliasAttr>() && !hasAttr<BuiltinAliasAttr>()))
3658 if (Context.
getLangOpts().CUDA && hasAttr<CUDADeviceAttr>() &&
3659 !hasAttr<CUDAHostAttr>() &&
3660 !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))
3669 !(BuiltinID == Builtin::BIprintf || BuiltinID == Builtin::BImalloc))
3685 assert(!ParamInfo &&
"Already has param info!");
3686 assert(NewParamInfo.size() ==
getNumParams() &&
"Parameter count mismatch!");
3689 if (!NewParamInfo.empty()) {
3691 std::copy(NewParamInfo.begin(), NewParamInfo.end(), ParamInfo);
3705 unsigned NumRequiredArgs = 0;
3706 unsigned MinParamsSoFar = 0;
3708 if (!Param->isParameterPack()) {
3710 if (!Param->hasDefaultArg())
3711 NumRequiredArgs = MinParamsSoFar;
3714 return NumRequiredArgs;
3744 assert(
isInlined() &&
"expected to get called on an inlined function!");
3748 !hasAttr<DLLExportAttr>())
3753 if (!FD->isImplicit() && FD->getStorageClass() ==
SC_Extern)
3765 if (!FD->isImplicit() && FD->getStorageClass() ==
SC_Extern)
3795 "Must have a declaration without a body.");
3809 if (Context.
getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3819 bool FoundBody =
false;
3844 bool FoundBody =
false;
3869 !
SM.isBeforeInTranslationUnit(RTRange.
getEnd(), Boundary))
3915 hasAttr<AliasAttr>()) &&
3916 "Must be a function definition");
3917 assert(
isInlined() &&
"Function must be inline");
3920 if (Context.
getLangOpts().GNUInline || hasAttr<GNUInlineAttr>()) {
3934 for (
auto *Redecl :
redecls()) {
3935 if (Redecl->isInlineSpecified() &&
3945 "should not use C inline rules in C++");
3951 for (
auto *Redecl :
redecls()) {
3980 if (TemplateOrSpecialization.isNull())
3982 if (
const auto *ND = TemplateOrSpecialization.dyn_cast<
NamedDecl *>()) {
3983 if (isa<FunctionDecl>(ND))
3985 assert(isa<FunctionTemplateDecl>(ND) &&
3986 "No other valid types in NamedDecl");
3993 if (TemplateOrSpecialization.is
3997 llvm_unreachable(
"Did we miss a TemplateOrSpecialization type?");
4002 return cast<FunctionDecl>(Info->getInstantiatedFrom());
4011 if (
auto *FTSI = TemplateOrSpecialization
4012 .dyn_cast<FunctionTemplateSpecializationInfo *>())
4013 return FTSI->getMemberSpecializationInfo();
4018FunctionDecl::setInstantiationOfMemberFunction(
ASTContext &
C,
4021 assert(TemplateOrSpecialization.isNull() &&
4022 "Member function is already a specialization");
4025 TemplateOrSpecialization = Info;
4029 return dyn_cast_if_present<FunctionTemplateDecl>(
4030 TemplateOrSpecialization.dyn_cast<
NamedDecl *>());
4035 assert(TemplateOrSpecialization.isNull() &&
4036 "Member function is already a specialization");
4037 TemplateOrSpecialization = Template;
4042 TemplateOrSpecialization
4043 .is<DependentFunctionTemplateSpecializationInfo *>();
4047 assert(TemplateOrSpecialization.isNull() &&
4048 "Function is already a specialization");
4049 TemplateOrSpecialization = FD;
4053 return dyn_cast_if_present<FunctionDecl>(
4054 TemplateOrSpecialization.dyn_cast<
NamedDecl *>());
4078 bool HasPattern =
false;
4080 HasPattern = PatternDecl->
hasBody(PatternDecl);
4086 if (!HasPattern || !PatternDecl)
4110 dyn_cast<CXXMethodDecl>(
this))) {
4122 if (ForDefinition &&
4128 if (ForDefinition &&
4135 while (!ForDefinition || !Primary->isMemberSpecialization()) {
4136 auto *NewPrimary = Primary->getInstantiatedFromMemberTemplate();
4139 Primary = NewPrimary;
4150 = TemplateOrSpecialization
4151 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4152 return Info->getTemplate();
4159 return TemplateOrSpecialization
4166 = TemplateOrSpecialization
4167 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4168 return Info->TemplateArguments;
4176 = TemplateOrSpecialization
4177 .dyn_cast<FunctionTemplateSpecializationInfo*>()) {
4178 return Info->TemplateArgumentsAsWritten;
4181 TemplateOrSpecialization
4182 .dyn_cast<DependentFunctionTemplateSpecializationInfo *>()) {
4183 return Info->TemplateArgumentsAsWritten;
4188void FunctionDecl::setFunctionTemplateSpecialization(
4194 assert((TemplateOrSpecialization.isNull() ||
4196 "Member function is already a specialization");
4198 "Must specify the type of function template specialization");
4199 assert((TemplateOrSpecialization.isNull() ||
4202 "Member specialization must be an explicit specialization");
4205 C,
this, Template, TSK, TemplateArgs, TemplateArgsAsWritten,
4206 PointOfInstantiation,
4208 TemplateOrSpecialization = Info;
4215 assert(TemplateOrSpecialization.isNull());
4219 TemplateOrSpecialization = Info;
4224 return TemplateOrSpecialization
4232 const auto *TArgsWritten =
4235 totalSizeToAlloc<FunctionTemplateDecl *>(Candidates.
size())))
4239DependentFunctionTemplateSpecializationInfo::
4240 DependentFunctionTemplateSpecializationInfo(
4243 : NumCandidates(Candidates.size()),
4244 TemplateArgumentsAsWritten(TemplateArgsWritten) {
4245 std::transform(Candidates.
begin(), Candidates.
end(),
4246 getTrailingObjects<FunctionTemplateDecl *>(),
4248 return cast<FunctionTemplateDecl>(ND->getUnderlyingDecl());
4256 TemplateOrSpecialization
4257 .dyn_cast<FunctionTemplateSpecializationInfo *>())
4258 return FTSInfo->getTemplateSpecializationKind();
4262 return MSInfo->getTemplateSpecializationKind();
4266 if (TemplateOrSpecialization
4267 .is<DependentFunctionTemplateSpecializationInfo *>() &&
4299 TemplateOrSpecialization
4300 .dyn_cast<FunctionTemplateSpecializationInfo *>()) {
4301 if (
auto *MSInfo = FTSInfo->getMemberSpecializationInfo())
4302 return MSInfo->getTemplateSpecializationKind();
4303 return FTSInfo->getTemplateSpecializationKind();
4308 return MSInfo->getTemplateSpecializationKind();
4310 if (TemplateOrSpecialization
4311 .is<DependentFunctionTemplateSpecializationInfo *>() &&
4322 = TemplateOrSpecialization.dyn_cast<
4324 FTSInfo->setTemplateSpecializationKind(TSK);
4326 PointOfInstantiation.
isValid() &&
4327 FTSInfo->getPointOfInstantiation().isInvalid()) {
4328 FTSInfo->setPointOfInstantiation(PointOfInstantiation);
4330 L->InstantiationRequested(
this);
4334 MSInfo->setTemplateSpecializationKind(TSK);
4336 PointOfInstantiation.
isValid() &&
4337 MSInfo->getPointOfInstantiation().isInvalid()) {
4338 MSInfo->setPointOfInstantiation(PointOfInstantiation);
4340 L->InstantiationRequested(
this);
4343 llvm_unreachable(
"Function cannot have a template specialization kind");
4348 = TemplateOrSpecialization.dyn_cast<
4350 return FTSInfo->getPointOfInstantiation();
4353 return MSInfo->getPointOfInstantiation();
4374 if (FunTmpl->getTemplatedDecl()->hasBody(
Definition))
4393 case Builtin::BI__builtin_memset:
4394 case Builtin::BI__builtin___memset_chk:
4395 case Builtin::BImemset:
4396 return Builtin::BImemset;
4398 case Builtin::BI__builtin_memcpy:
4399 case Builtin::BI__builtin___memcpy_chk:
4400 case Builtin::BImemcpy:
4401 return Builtin::BImemcpy;
4403 case Builtin::BI__builtin_mempcpy:
4404 case Builtin::BI__builtin___mempcpy_chk:
4405 case Builtin::BImempcpy:
4406 return Builtin::BImempcpy;
4408 case Builtin::BI__builtin_memmove:
4409 case Builtin::BI__builtin___memmove_chk:
4410 case Builtin::BImemmove:
4411 return Builtin::BImemmove;
4413 case Builtin::BIstrlcpy:
4414 case Builtin::BI__builtin___strlcpy_chk:
4415 return Builtin::BIstrlcpy;
4417 case Builtin::BIstrlcat:
4418 case Builtin::BI__builtin___strlcat_chk:
4419 return Builtin::BIstrlcat;
4421 case Builtin::BI__builtin_memcmp:
4422 case Builtin::BImemcmp:
4423 return Builtin::BImemcmp;
4425 case Builtin::BI__builtin_bcmp:
4426 case Builtin::BIbcmp:
4427 return Builtin::BIbcmp;
4429 case Builtin::BI__builtin_strncpy:
4430 case Builtin::BI__builtin___strncpy_chk:
4431 case Builtin::BIstrncpy:
4432 return Builtin::BIstrncpy;
4434 case Builtin::BI__builtin_strncmp:
4435 case Builtin::BIstrncmp:
4436 return Builtin::BIstrncmp;
4438 case Builtin::BI__builtin_strncasecmp:
4439 case Builtin::BIstrncasecmp:
4440 return Builtin::BIstrncasecmp;
4442 case Builtin::BI__builtin_strncat:
4443 case Builtin::BI__builtin___strncat_chk:
4444 case Builtin::BIstrncat:
4445 return Builtin::BIstrncat;
4447 case Builtin::BI__builtin_strndup:
4448 case Builtin::BIstrndup:
4449 return Builtin::BIstrndup;
4451 case Builtin::BI__builtin_strlen:
4452 case Builtin::BIstrlen:
4453 return Builtin::BIstrlen;
4455 case Builtin::BI__builtin_bzero:
4456 case Builtin::BIbzero:
4457 return Builtin::BIbzero;
4459 case Builtin::BI__builtin_bcopy:
4460 case Builtin::BIbcopy:
4461 return Builtin::BIbcopy;
4463 case Builtin::BIfree:
4464 return Builtin::BIfree;
4468 if (FnInfo->
isStr(
"memset"))
4469 return Builtin::BImemset;
4470 if (FnInfo->
isStr(
"memcpy"))
4471 return Builtin::BImemcpy;
4472 if (FnInfo->
isStr(
"mempcpy"))
4473 return Builtin::BImempcpy;
4474 if (FnInfo->
isStr(
"memmove"))
4475 return Builtin::BImemmove;
4476 if (FnInfo->
isStr(
"memcmp"))
4477 return Builtin::BImemcmp;
4478 if (FnInfo->
isStr(
"bcmp"))
4479 return Builtin::BIbcmp;
4480 if (FnInfo->
isStr(
"strncpy"))
4481 return Builtin::BIstrncpy;
4482 if (FnInfo->
isStr(
"strncmp"))
4483 return Builtin::BIstrncmp;
4484 if (FnInfo->
isStr(
"strncasecmp"))
4485 return Builtin::BIstrncasecmp;
4486 if (FnInfo->
isStr(
"strncat"))
4487 return Builtin::BIstrncat;
4488 if (FnInfo->
isStr(
"strndup"))
4489 return Builtin::BIstrndup;
4490 if (FnInfo->
isStr(
"strlen"))
4491 return Builtin::BIstrlen;
4492 if (FnInfo->
isStr(
"bzero"))
4493 return Builtin::BIbzero;
4494 if (FnInfo->
isStr(
"bcopy"))
4495 return Builtin::BIbcopy;
4497 if (FnInfo->
isStr(
"free"))
4498 return Builtin::BIfree;
4506 assert(hasODRHash());
4515 setHasODRHash(
true);
4522 setHasODRHash(
true);
4536 return new (
C, DC)
FieldDecl(Decl::Field, DC, StartLoc, IdLoc,
Id,
T, TInfo,
4537 BW, Mutable, InitStyle);
4551 return Record->getDecl()->isAnonymousStructOrUnion();
4561 return cast_if_present<Expr>(
4563 : InitPtr.
get(
nullptr));
4595 if (!hasAttr<NoUniqueAddressAttr>())
4604 assert(
isInvalidDecl() &&
"valid field has incomplete type");
4610 const auto *CXXRD = cast<CXXRecordDecl>(RD);
4611 if (!CXXRD->isEmpty())
4621 return !llvm::any_of(CXXRD->fields(), [](
const FieldDecl *Field) {
4622 return Field->getType()->getAs<RecordType>();
4632 if (Canonical !=
this)
4635 if (CachedFieldIndex)
return CachedFieldIndex - 1;
4639 assert(RD &&
"requested index for field of struct with no definition");
4641 for (
auto *Field : RD->
fields()) {
4642 Field->getCanonicalDecl()->CachedFieldIndex = Index + 1;
4643 assert(Field->getCanonicalDecl()->CachedFieldIndex == Index + 1 &&
4644 "overflow in field numbering");
4648 assert(CachedFieldIndex &&
"failed to find field in parent");
4649 return CachedFieldIndex - 1;
4663 "capturing type in non-lambda or captured record.");
4664 assert(StorageKind == ISK_NoInit && !BitField &&
4665 "bit-field or field with default member initializer cannot capture "
4667 StorageKind = ISK_CapturedVLAType;
4686 const auto *CountDRE = cast<DeclRefExpr>(CAT->getCountExpr());
4687 const auto *CountDecl = CountDRE->getDecl();
4688 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(CountDecl))
4689 CountDecl = IFD->getAnonField();
4691 return dyn_cast<FieldDecl>(CountDecl);
4704 "EnumDecl not matched with TagTypeKind::Enum");
4712 TagDeclBits.IsThisDeclarationADemotedDefinition =
false;
4728 TypedefNameDeclOrQualifier = TDD;
4739 if (
auto *
D = dyn_cast<CXXRecordDecl>(
this)) {
4740 struct CXXRecordDecl::DefinitionData *
Data =
4743 cast<CXXRecordDecl>(I)->DefinitionData =
Data;
4748 assert((!isa<CXXRecordDecl>(
this) ||
4750 "definition completed but not started");
4756 L->CompletedTagDefinition(
this);
4761 return const_cast<TagDecl *
>(
this);
4766 if (II->isOutOfDate()) {
4772 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(
this))
4773 return CXXRD->getDefinition();
4776 if (R->isCompleteDefinition())
4792 if (getExtInfo()->NumTemplParamLists == 0) {
4806 if (Name.isIdentifier() && !Name.getAsIdentifierInfo()) {
4811 Copy.SuppressScope =
true;
4816 Name.print(OS, Policy);
4821 assert(!TPLists.empty());
4836 bool Scoped,
bool ScopedUsingClassTag,
bool Fixed)
4838 assert(Scoped || !ScopedUsingClassTag);
4839 IntegerType =
nullptr;
4840 setNumPositiveBits(0);
4841 setNumNegativeBits(0);
4843 setScopedUsingClassTag(ScopedUsingClassTag);
4845 setHasODRHash(
false);
4849void EnumDecl::anchor() {}
4855 bool IsScopedUsingClassTag,
bool IsFixed) {
4857 IsScoped, IsScopedUsingClassTag, IsFixed);
4858 Enum->setMayHaveOutOfDateDef(
C.getLangOpts().Modules);
4859 C.getTypeDeclType(
Enum, PrevDecl);
4866 nullptr,
nullptr,
false,
false,
false);
4867 Enum->setMayHaveOutOfDateDef(
C.getLangOpts().Modules);
4873 return TI->getTypeLoc().getSourceRange();
4879 unsigned NumPositiveBits,
4880 unsigned NumNegativeBits) {
4884 PromotionType = NewPromotionType;
4885 setNumPositiveBits(NumPositiveBits);
4886 setNumNegativeBits(NumNegativeBits);
4891 if (
const auto *A = getAttr<EnumExtensibilityAttr>())
4892 return A->getExtensibility() == EnumExtensibilityAttr::Closed;
4897 return isClosed() && hasAttr<FlagEnumAttr>();
4901 return isClosed() && !hasAttr<FlagEnumAttr>();
4906 return MSI->getTemplateSpecializationKind();
4914 assert(MSI &&
"Not an instantiated member enumeration?");
4917 PointOfInstantiation.
isValid() &&
4933 "couldn't find pattern for enum instantiation");
4938 if (SpecializationInfo)
4946 assert(!SpecializationInfo &&
"Member enum is already a specialization");
4956 setHasODRHash(
true);
4967 Res.setEnd(TSI->getTypeLoc().getEndLoc());