Lines Matching +full:fsi +full:- +full:attached

1 //===--- SemaDecl.cpp - Semantic Analysis for Declarations ----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
96 if (!AllowInvalidDecl && ND->isInvalidDecl()) in ValidateCandidate()
109 // An injected-class-name of a class template (specialization) is valid in ValidateCandidate()
110 // as a template or as a non-template. in ValidateCandidate()
113 if (!RD || !RD->isInjectedClassName()) in ValidateCandidate()
115 RD = cast<CXXRecordDecl>(RD->getDeclContext()); in ValidateCandidate()
116 return RD->getDescribedClassTemplate() || in ValidateCandidate()
155 if (!RD->hasDefinition()) in lookupUnqualifiedTypeNameInBase()
160 for (const auto &Base : RD->bases()) { in lookupUnqualifiedTypeNameInBase()
162 if (auto *BaseTT = Base.getType()->getAs<TagType>()) in lookupUnqualifiedTypeNameInBase()
163 BaseRD = BaseTT->getAsCXXRecordDecl(); in lookupUnqualifiedTypeNameInBase()
164 else if (auto *TST = Base.getType()->getAs<TemplateSpecializationType>()) { in lookupUnqualifiedTypeNameInBase()
167 if (!TST || !TST->isDependentType()) in lookupUnqualifiedTypeNameInBase()
169 auto *TD = TST->getTemplateName().getAsTemplateDecl(); in lookupUnqualifiedTypeNameInBase()
173 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) { in lookupUnqualifiedTypeNameInBase()
174 if (BasePrimaryTemplate->getCanonicalDecl() != RD->getCanonicalDecl()) in lookupUnqualifiedTypeNameInBase()
178 CTD->findPartialSpecialization(Base.getType())) in lookupUnqualifiedTypeNameInBase()
179 if (PS->getCanonicalDecl() != RD->getCanonicalDecl()) in lookupUnqualifiedTypeNameInBase()
185 for (NamedDecl *ND : BaseRD->lookup(&II)) { in lookupUnqualifiedTypeNameInBase()
216 DC = DC->getParent()) { in recoverFromTypeInKnownDependentBase()
220 if (RD && RD->getDescribedClassTemplate()) in recoverFromTypeInKnownDependentBase()
248 /// Build a ParsedType for a simple-type-specifier with a nested-name-specifier.
252 switch (T->getTypeClass()) { in buildNamedType()
271 if (!SS || SS->isEmpty()) in buildNamedType()
283 ElabTL.setQualifierLoc(SS->getWithLocInContext(S.Context)); in buildNamedType()
304 if (ObjectType->isRecordType()) in getTypeName()
306 } else if (SS && SS->isNotEmpty()) { in getTypeName()
312 // A qualified-id that refers to a type and in which the in getTypeName()
313 // nested-name-specifier depends on a template-parameter (14.6.2) in getTypeName()
315 // qualified-id denotes a type, forming an in getTypeName()
316 // elaborated-type-specifier (7.1.5.3). in getTypeName()
327 SourceLocation QualifiedLoc = SS->getRange().getBegin(); in getTypeName()
332 << SS->getScopeRep() << II.getName() in getTypeName()
343 NestedNameSpecifierLoc QualifierLoc = SS->getWithLocInContext(Context); in getTypeName()
354 if (!LookupCtx->isDependentContext() && in getTypeName()
360 // lookup for class-names. in getTypeName()
368 // nested-name-specifier. in getTypeName()
373 // If the unqualified-id is ~type-name, the type-name is looked up in getTypeName()
374 // in the context of the entire postfix-expression. If the type T of in getTypeName()
375 // the object expression is of a class type C, the type-name is also in getTypeName()
377 // find a name that refers to (possibly cv-qualified) T. in getTypeName()
386 if (Result.empty() && getLangOpts().MSVCCompat && (!SS || SS->isEmpty())) { in getTypeName()
414 // Ignore a correction to a template type as the to-be-corrected in getTypeName()
430 SS->MakeTrivial(Context, NNS, SourceRange(NameLoc)); in getTypeName()
441 SS->getScopeRep(), &II); in getTypeName()
445 TL.setQualifierLoc(SS->getWithLocInContext(Context)); in getTypeName()
456 // Recover from type-hiding ambiguities by hiding the type. We'll in getTypeName()
469 NamedDecl *RealRes = (*Res)->getUnderlyingDecl(); in getTypeName()
475 RealRes->getLocation() < IIDecl->getLocation()) { in getTypeName()
509 // C++ [class.qual]p2: A lookup that would find the injected-class-name in getTypeName()
511 // This is ill-formed when we're not actually forming a ctor or dtor name. in getTypeName()
515 FoundRD->isInjectedClassName() && in getTypeName()
516 declaresSameEntity(LookupRD, cast<Decl>(FoundRD->getParent()))) in getTypeName()
523 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false); in getTypeName()
535 assert(!FoundUsingShadow || FoundUsingShadow->getTargetDecl() == TD); in getTypeName()
537 SS ? SS->getScopeRep() : nullptr, /*TemplateKeyword=*/false, in getTypeName()
561 for (;; DC = DC->getLookupParent()) { in synthesizeCurrentNestedNameSpecifier()
562 DC = DC->getPrimaryContext(); in synthesizeCurrentNestedNameSpecifier()
564 if (ND && !ND->isInline() && !ND->isAnonymousNamespace()) in synthesizeCurrentNestedNameSpecifier()
567 return NestedNameSpecifier::Create(Context, nullptr, RD->isTemplateDecl(), in synthesizeCurrentNestedNameSpecifier()
568 RD->getTypeForDecl()); in synthesizeCurrentNestedNameSpecifier()
577 /// up allowing unqualified dependent type names at class-level, which MSVC
581 for (; DC && DC->isDependentContext(); DC = DC->getLookupParent()) { in findRecordWithDependentBasesOfEnclosingMethod()
582 DC = DC->getPrimaryContext(); in findRecordWithDependentBasesOfEnclosingMethod()
584 if (MD->getParent()->hasAnyDependentBases()) in findRecordWithDependentBasesOfEnclosingMethod()
585 return MD->getParent(); in findRecordWithDependentBasesOfEnclosingMethod()
593 assert(getLangOpts().MSVCCompat && "shouldn't be called in non-MSVC mode"); in ActOnMSVCUnknownTypeName()
596 if (IsTemplateTypeArg && getCurScope()->isTemplateParamScope()) { in ActOnMSVCUnknownTypeName()
598 // until instantiation time by making a non-dependent DependentTypeName. We in ActOnMSVCUnknownTypeName()
610 NNS = NestedNameSpecifier::Create(Context, nullptr, RD->isTemplateDecl(), in ActOnMSVCUnknownTypeName()
611 RD->getTypeForDecl()); in ActOnMSVCUnknownTypeName()
646 switch (TD->getTagKind()) { in isTagName()
664 if (CurContext->isRecord()) { in isMicrosoftMissingTypename()
665 if (SS->getScopeRep()->getKind() == NestedNameSpecifier::Super) in isMicrosoftMissingTypename()
668 const Type *Ty = SS->getScopeRep()->getAsType(); in isMicrosoftMissingTypename()
671 for (const auto &Base : RD->bases()) in isMicrosoftMissingTypename()
674 return S->isFunctionPrototypeScope(); in isMicrosoftMissingTypename()
676 return CurContext->isFunctionOrMethod() || S->isFunctionPrototypeScope(); in isMicrosoftMissingTypename()
686 if (II->isEditorPlaceholder()) in DiagnoseUnknownTypeName()
699 // FIXME: Support error recovery for the template-name case. in DiagnoseUnknownTypeName()
709 // We found a similarly-named type or interface; suggest that. in DiagnoseUnknownTypeName()
710 if (!SS || !SS->isSet()) { in DiagnoseUnknownTypeName()
718 Corrected.WillReplaceSpecifier() && II->getName() == CorrectedStr; in DiagnoseUnknownTypeName()
723 << II << DC << DroppedSpecifier << SS->getRange(), in DiagnoseUnknownTypeName()
764 if (!SS || (!SS->isSet() && !SS->isInvalid())) in DiagnoseUnknownTypeName()
771 << II << DC << SS->getRange(); in DiagnoseUnknownTypeName()
772 else if (SS->isValid() && SS->getScopeRep()->containsErrors()) { in DiagnoseUnknownTypeName()
780 Diag(SS->getRange().getBegin(), DiagID) in DiagnoseUnknownTypeName()
781 << SS->getScopeRep() << II->getName() in DiagnoseUnknownTypeName()
782 << SourceRange(SS->getRange().getBegin(), IILoc) in DiagnoseUnknownTypeName()
783 << FixItHint::CreateInsertion(SS->getRange().getBegin(), "typename "); in DiagnoseUnknownTypeName()
787 assert(SS && SS->isInvalid() && in DiagnoseUnknownTypeName()
817 switch (Tag->getTagKind()) { in isTagTypeWithMissingTag()
846 SemaRef.Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type) in isTagTypeWithMissingTag()
871 // injected-class-name. We don't have a classification for that. in ClassifyName()
892 // Perform lookup for Objective-C instance variables (including automatically in ClassifyName()
893 // synthesized instance variables), if we're in an Objective-C method. in ClassifyName()
914 // If an unqualified-id is followed by a '(', then we have a function in ClassifyName()
917 // In C++, this is an ADL-only call. in ClassifyName()
943 // In C++20 onwards, this could be an ADL-only call to a function in ClassifyName()
989 Name->getName() == CorrectedStr; in ClassifyName()
1009 // If we found an Objective-C instance variable, let in ClassifyName()
1015 ObjC().LookupIvarInObjCMethod(Result, S, Ivar->getIdentifier()); in ClassifyName()
1033 // dependent nested-name-specifier. in ClassifyName()
1037 // dependent on a template-parameter is assumed not to name a type in ClassifyName()
1043 // template-argument-list, which would indicate a missing 'template' in ClassifyName()
1058 // A lookup that finds an injected-class-name (10.2) can result in an in ClassifyName()
1060 // one base class). If all of the injected-class-names that are found in ClassifyName()
1062 // is followed by a template-argument-list, the reference refers to the in ClassifyName()
1087 // After name lookup (3.4) finds that a name is a template-name or that in ClassifyName()
1088 // an operator-function-id or a literal- operator-id refers to a set of in ClassifyName()
1091 // template-argument-list and never as the less-than operator. in ClassifyName()
1094 // unqualified-id followed by a < and name lookup finds either one in ClassifyName()
1102 if (Result.end() - Result.begin() > 1) { in ClassifyName()
1116 TD == cast<TemplateDecl>(FoundUsingShadow->getTargetDecl())); in ClassifyName()
1122 // All results were non-template functions. This is a function template in ClassifyName()
1148 NamedDecl *FirstDecl = (*Result.begin())->getUnderlyingDecl(); in ClassifyName()
1151 MarkAnyDeclReferenced(Type->getLocation(), Type, /*OdrUse=*/false); in ClassifyName()
1160 Class = Alias->getClassInterface(); in ClassifyName()
1168 // Just return "unknown" as a fall-through for now. in ClassifyName()
1196 // Check for a tag type hidden by a non-type decl in a few cases where it in ClassifyName()
1197 // seems likely a type is wanted instead of the non-type that was found. in ClassifyName()
1201 FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) && in ClassifyName()
1209 // that declaration directly. Defer resolving even non-overloaded class in ClassifyName()
1214 (!FirstDecl->isCXXClassMember() || isa<EnumConstantDecl>(FirstDecl))) in ClassifyName()
1228 assert(getLangOpts().CPlusPlus && "ADL-only call in C?"); in ActOnNameClassifiedAsUndeclaredNonType()
1250 if (auto *Ivar = dyn_cast<ObjCIvarDecl>(Found->getUnderlyingDecl())) in ActOnNameClassifiedAsNonType()
1254 LookupResult Result(*this, Found->getDeclName(), NameLoc, LookupOrdinaryName); in ActOnNameClassifiedAsNonType()
1266 if ((*ULE->decls_begin())->isCXXClassMember()) { in ActOnNameClassifiedAsOverloadSet()
1268 SS.Adopt(ULE->getQualifierLoc()); in ActOnNameClassifiedAsOverloadSet()
1271 LookupResult Result(*this, ULE->getName(), ULE->getNameLoc(), in ActOnNameClassifiedAsOverloadSet()
1273 Result.setNamingClass(ULE->getNamingClass()); in ActOnNameClassifiedAsOverloadSet()
1274 for (auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I) in ActOnNameClassifiedAsOverloadSet()
1307 assert(DC->getLexicalParent() == CurContext && in PushDeclContext()
1310 S->setEntity(DC); in PushDeclContext()
1316 CurContext = CurContext->getLexicalParent(); in PopDeclContext()
1323 // the containing DC of TD, because the new context will be some pre-existing in ActOnTagStartSkippedDefinition()
1326 CurContext = cast<TagDecl>(D)->getDefinition(); in ActOnTagStartSkippedDefinition()
1329 // into the pre-existing complete definition. in ActOnTagStartSkippedDefinition()
1330 S->setEntity(CurContext->getLookupParent()); in ActOnTagStartSkippedDefinition()
1341 // X (after the qualified-id of the static member) is looked up as in EnterDeclaratorContext()
1346 // the variable member (after the declarator-id) is looked up as in EnterDeclaratorContext()
1355 assert(!S->getEntity() && "scope already has entity"); in EnterDeclaratorContext()
1358 Scope *Ancestor = S->getParent(); in EnterDeclaratorContext()
1359 while (!Ancestor->getEntity()) Ancestor = Ancestor->getParent(); in EnterDeclaratorContext()
1360 assert(Ancestor->getEntity() == CurContext && "ancestor context mismatch"); in EnterDeclaratorContext()
1364 S->setEntity(DC); in EnterDeclaratorContext()
1366 if (S->getParent()->isTemplateParamScope()) { in EnterDeclaratorContext()
1367 // Also set the corresponding entities for all immediately-enclosing in EnterDeclaratorContext()
1369 EnterTemplatedContext(S->getParent(), DC); in EnterDeclaratorContext()
1374 assert(S->getEntity() == CurContext && "Context imbalance!"); in ExitDeclaratorContext()
1378 Scope *Ancestor = S->getParent(); in ExitDeclaratorContext()
1379 while (!Ancestor->getEntity()) Ancestor = Ancestor->getParent(); in ExitDeclaratorContext()
1380 CurContext = Ancestor->getEntity(); in ExitDeclaratorContext()
1387 assert(S->isTemplateParamScope() && in EnterTemplatedContext()
1393 // template hides the name of a template-parameter of any enclosing class in EnterTemplatedContext()
1394 // templates (but not a template-parameter of the member if the member is a in EnterTemplatedContext()
1399 // each non-dependent base class (13.8.2.1), if the name of the base class in EnterTemplatedContext()
1401 // template-parameter, the base class name or member name hides the in EnterTemplatedContext()
1402 // template-parameter name (6.4.10). in EnterTemplatedContext()
1412 for (; S && S->isTemplateParamScope(); S = S->getParent(), --ScopeDepth) { in EnterTemplatedContext()
1414 for (; DC; DC = DC->getLookupParent()) { in EnterTemplatedContext()
1416 cast<Decl>(DC)->getDescribedTemplateParams()) { in EnterTemplatedContext()
1417 unsigned DCDepth = TPL->getDepth() + 1; in EnterTemplatedContext()
1421 SearchDCAfterScope = DC = DC->getLookupParent(); in EnterTemplatedContext()
1425 S->setLookupEntity(SearchDCAfterScope); in EnterTemplatedContext()
1432 FunctionDecl *FD = D->getAsFunction(); in ActOnReenterFunctionContext()
1437 // from the lexical parent, rather than the top-level class. in ActOnReenterFunctionContext()
1438 assert(CurContext == FD->getLexicalParent() && in ActOnReenterFunctionContext()
1441 S->setEntity(CurContext); in ActOnReenterFunctionContext()
1443 for (unsigned P = 0, NumParams = FD->getNumParams(); P < NumParams; ++P) { in ActOnReenterFunctionContext()
1444 ParmVarDecl *Param = FD->getParamDecl(P); in ActOnReenterFunctionContext()
1446 if (Param->getIdentifier()) { in ActOnReenterFunctionContext()
1447 S->AddDecl(Param); in ActOnReenterFunctionContext()
1455 // rather than the top-level class. in ActOnExitFunctionContext()
1457 CurContext = CurContext->getLexicalParent(); in ActOnExitFunctionContext()
1472 if (Context.getLangOpts().CPlusPlus || New->hasAttr<OverloadableAttr>()) in AllowOverloadingOfFunction()
1487 return ND->hasAttr<OverloadableAttr>(); in AllowOverloadingOfFunction()
1490 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>(); in AllowOverloadingOfFunction()
1497 // non-transparent context. The declaration will be introduced into this in PushOnScopeChains()
1499 while (S->getEntity() && S->getEntity()->isTransparentContext()) in PushOnScopeChains()
1500 S = S->getParent(); in PushOnScopeChains()
1506 CurContext->addDecl(D); in PushOnScopeChains()
1508 // Out-of-line definitions shouldn't be pushed into scope in C++, unless they in PushOnScopeChains()
1509 // are function-local declarations. in PushOnScopeChains()
1510 if (getLangOpts().CPlusPlus && D->isOutOfLine() && !S->getFnParent()) in PushOnScopeChains()
1515 cast<FunctionDecl>(D)->isFunctionTemplateSpecialization()) in PushOnScopeChains()
1518 if (isa<UsingEnumDecl>(D) && D->getDeclName().isEmpty()) { in PushOnScopeChains()
1519 S->AddDecl(D); in PushOnScopeChains()
1523 IdentifierResolver::iterator I = IdResolver.begin(D->getDeclName()), in PushOnScopeChains()
1526 if (S->isDeclScope(*I) && D->declarationReplaces(*I)) { in PushOnScopeChains()
1527 S->RemoveDecl(*I); in PushOnScopeChains()
1535 S->AddDecl(D); in PushOnScopeChains()
1537 if (isa<LabelDecl>(D) && !cast<LabelDecl>(D)->isGnuLocal()) { in PushOnScopeChains()
1538 // Implicitly-generated labels may end up getting generated in an order that in PushOnScopeChains()
1541 for (I = IdResolver.begin(D->getDeclName()); I != IEnd; ++I) { in PushOnScopeChains()
1542 DeclContext *IDC = (*I)->getLexicalDeclContext()->getRedeclContext(); in PushOnScopeChains()
1544 if (!S->isDeclScope(*I)) in PushOnScopeChains()
1546 } else if (IDC->Encloses(CurContext)) in PushOnScopeChains()
1563 DeclContext *TargetDC = DC->getPrimaryContext(); in getScopeForDeclContext()
1565 if (DeclContext *ScopeDC = S->getEntity()) in getScopeForDeclContext()
1566 if (ScopeDC->getPrimaryContext() == TargetDC) in getScopeForDeclContext()
1568 } while ((S = S->getParent())); in getScopeForDeclContext()
1598 // A declaration is attached to a module as follows: in CheckRedeclarationModuleOwnership()
1599 // - If the declaration is a non-dependent friend declaration that nominates a in CheckRedeclarationModuleOwnership()
1600 // function with a declarator-id that is a qualified-id or template-id or that in CheckRedeclarationModuleOwnership()
1601 // nominates a class other than with an elaborated-type-specifier with neither in CheckRedeclarationModuleOwnership()
1602 // a nested-name-specifier nor a simple-template-id, it is attached to the in CheckRedeclarationModuleOwnership()
1603 // module to which the friend is attached ([basic.link]). in CheckRedeclarationModuleOwnership()
1604 if (New->getFriendObjectKind() && in CheckRedeclarationModuleOwnership()
1605 Old->getOwningModuleForLinkage() != New->getOwningModuleForLinkage()) { in CheckRedeclarationModuleOwnership()
1606 New->setLocalOwningModule(Old->getOwningModule()); in CheckRedeclarationModuleOwnership()
1611 Module *NewM = New->getOwningModule(); in CheckRedeclarationModuleOwnership()
1612 Module *OldM = Old->getOwningModule(); in CheckRedeclarationModuleOwnership()
1614 if (NewM && NewM->isPrivateModule()) in CheckRedeclarationModuleOwnership()
1615 NewM = NewM->Parent; in CheckRedeclarationModuleOwnership()
1616 if (OldM && OldM->isPrivateModule()) in CheckRedeclarationModuleOwnership()
1617 OldM = OldM->Parent; in CheckRedeclarationModuleOwnership()
1625 if (NewM->isModuleImplementation() && OldM == ThePrimaryInterface) in CheckRedeclarationModuleOwnership()
1630 if ((NewM->isModulePartition() || OldM->isModulePartition()) && in CheckRedeclarationModuleOwnership()
1635 bool NewIsModuleInterface = NewM && NewM->isNamedModule(); in CheckRedeclarationModuleOwnership()
1636 bool OldIsModuleInterface = OldM && OldM->isNamedModule(); in CheckRedeclarationModuleOwnership()
1641 Diag(New->getLocation(), diag::err_mismatched_owning_module) in CheckRedeclarationModuleOwnership()
1644 << (NewIsModuleInterface ? NewM->getFullModuleName() : "") in CheckRedeclarationModuleOwnership()
1646 << (OldIsModuleInterface ? OldM->getFullModuleName() : ""); in CheckRedeclarationModuleOwnership()
1647 Diag(Old->getLocation(), diag::note_previous_declaration); in CheckRedeclarationModuleOwnership()
1648 New->setInvalidDecl(); in CheckRedeclarationModuleOwnership()
1657 // An export-declaration shall inhabit a namespace scope. in CheckRedeclarationExported()
1661 if (!New->getLexicalDeclContext() in CheckRedeclarationExported()
1662 ->getNonTransparentContext() in CheckRedeclarationExported()
1663 ->isFileContext() || in CheckRedeclarationExported()
1664 !Old->getLexicalDeclContext() in CheckRedeclarationExported()
1665 ->getNonTransparentContext() in CheckRedeclarationExported()
1666 ->isFileContext()) in CheckRedeclarationExported()
1669 bool IsNewExported = New->isInExportDeclContext(); in CheckRedeclarationExported()
1670 bool IsOldExported = Old->isInExportDeclContext(); in CheckRedeclarationExported()
1679 // If the Old declaration are not attached to named modules in CheckRedeclarationExported()
1680 // and the New declaration are attached to global module. in CheckRedeclarationExported()
1683 // https://github.com/llvm/llvm-project/issues/98583 for details. in CheckRedeclarationExported()
1684 if (!Old->isInNamedModule() && New->getOwningModule() && in CheckRedeclarationExported()
1685 New->getOwningModule()->isImplicitGlobalModule()) in CheckRedeclarationExported()
1690 auto Lk = Old->getFormalLinkage(); in CheckRedeclarationExported()
1696 Diag(New->getLocation(), diag::err_redeclaration_non_exported) << New << S; in CheckRedeclarationExported()
1697 Diag(Old->getLocation(), diag::note_previous_declaration); in CheckRedeclarationExported()
1716 assert(const_cast<Sema *>(this)->isReachable(New) && in IsRedefinitionInModule()
1717 const_cast<Sema *>(this)->isReachable(Old) && in IsRedefinitionInModule()
1720 Module *NewM = New->getOwningModule(); in IsRedefinitionInModule()
1721 Module *OldM = Old->getOwningModule(); in IsRedefinitionInModule()
1729 // //--- M.cppm in IsRedefinitionInModule()
1734 // //--- Use.cpp in IsRedefinitionInModule()
1740 // Use.cpp) and `D` is attached to a named module `M`. The compiler should in IsRedefinitionInModule()
1747 if (NewM && NewM->isHeaderLikeModule()) in IsRedefinitionInModule()
1749 if (OldM && OldM->isHeaderLikeModule()) in IsRedefinitionInModule()
1756 // Each such definition shall not be attached to a named module in IsRedefinitionInModule()
1758 if ((NewM && NewM->isNamedModule()) || (OldM && OldM->isNamedModule())) in IsRedefinitionInModule()
1763 NewM = NewM->getTopLevelModule(); in IsRedefinitionInModule()
1765 OldM = OldM->getTopLevelModule(); in IsRedefinitionInModule()
1770 if (D->getDeclContext()->isFileContext()) in isUsingDeclNotAtClassScope()
1799 if (D->doesThisDeclarationHaveABody()) in IsDisallowedCopyOrAssign()
1803 return CD->isCopyConstructor(); in IsDisallowedCopyOrAssign()
1804 return D->isCopyAssignmentOperator(); in IsDisallowedCopyOrAssign()
1808 const DeclContext *DC = D->getDeclContext(); in mightHaveNonExternalLinkage()
1809 while (!DC->isTranslationUnit()) { in mightHaveNonExternalLinkage()
1811 if (!RD->hasNameForLinkage()) in mightHaveNonExternalLinkage()
1814 DC = DC->getParent(); in mightHaveNonExternalLinkage()
1817 return !D->isExternallyVisible(); in mightHaveNonExternalLinkage()
1831 if (D->isInvalidDecl() || D->isUsed() || D->hasAttr<UnusedAttr>()) in ShouldWarnIfUnusedFileScopedDecl()
1834 // Ignore all entities declared within templates, and out-of-line definitions in ShouldWarnIfUnusedFileScopedDecl()
1836 if (D->getDeclContext()->isDependentContext() || in ShouldWarnIfUnusedFileScopedDecl()
1837 D->getLexicalDeclContext()->isDependentContext()) in ShouldWarnIfUnusedFileScopedDecl()
1841 if (FD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) in ShouldWarnIfUnusedFileScopedDecl()
1843 // A non-out-of-line declaration of a member specialization was implicitly in ShouldWarnIfUnusedFileScopedDecl()
1844 // instantiated; it's the out-of-line declaration that we're interested in. in ShouldWarnIfUnusedFileScopedDecl()
1845 if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && in ShouldWarnIfUnusedFileScopedDecl()
1846 FD->getMemberSpecializationInfo() && !FD->isOutOfLine()) in ShouldWarnIfUnusedFileScopedDecl()
1850 if (MD->isVirtual() || IsDisallowedCopyOrAssign(MD)) in ShouldWarnIfUnusedFileScopedDecl()
1854 if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1858 if (FD->doesThisDeclarationHaveABody() && in ShouldWarnIfUnusedFileScopedDecl()
1865 if (!isMainFileLoc(*this, VD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1871 if (VD->isStaticDataMember() && in ShouldWarnIfUnusedFileScopedDecl()
1872 VD->getTemplateSpecializationKind() == TSK_ImplicitInstantiation) in ShouldWarnIfUnusedFileScopedDecl()
1874 if (VD->isStaticDataMember() && in ShouldWarnIfUnusedFileScopedDecl()
1875 VD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && in ShouldWarnIfUnusedFileScopedDecl()
1876 VD->getMemberSpecializationInfo() && !VD->isOutOfLine()) in ShouldWarnIfUnusedFileScopedDecl()
1879 if (VD->isInline() && !isMainFileLoc(*this, VD->getLocation())) in ShouldWarnIfUnusedFileScopedDecl()
1886 // FIXME: This seems like a bogus check; it suppresses -Wunused-function in ShouldWarnIfUnusedFileScopedDecl()
1896 const FunctionDecl *First = FD->getFirstDecl(); in MarkUnusedFileScopedDecl()
1902 const VarDecl *First = VD->getFirstDecl(); in MarkUnusedFileScopedDecl()
1913 if (D->isInvalidDecl()) in ShouldDiagnoseUnusedDecl()
1921 for (const auto *BD : DD->bindings()) { in ShouldDiagnoseUnusedDecl()
1922 if (BD->isReferenced() || BD->hasAttr<UnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1924 IsAllPlaceholders = IsAllPlaceholders && BD->isPlaceholderVar(LangOpts); in ShouldDiagnoseUnusedDecl()
1928 } else if (!D->getDeclName()) { in ShouldDiagnoseUnusedDecl()
1930 } else if (D->isReferenced() || D->isUsed()) { in ShouldDiagnoseUnusedDecl()
1934 if (D->isPlaceholderVar(LangOpts)) in ShouldDiagnoseUnusedDecl()
1937 if (D->hasAttr<UnusedAttr>() || D->hasAttr<ObjCPreciseLifetimeAttr>() || in ShouldDiagnoseUnusedDecl()
1938 D->hasAttr<CleanupAttr>()) in ShouldDiagnoseUnusedDecl()
1946 bool WithinFunction = D->getDeclContext()->isFunctionOrMethod(); in ShouldDiagnoseUnusedDecl()
1947 if (const auto *R = dyn_cast<CXXRecordDecl>(D->getDeclContext())) in ShouldDiagnoseUnusedDecl()
1950 WithinFunction || (R->isLocalClass() && !R->isDependentType()); in ShouldDiagnoseUnusedDecl()
1957 // White-list anything that isn't a local variable. in ShouldDiagnoseUnusedDecl()
1964 const Expr *Init = VD->getInit(); in ShouldDiagnoseUnusedDecl()
1966 Init = Cleanups->getSubExpr(); in ShouldDiagnoseUnusedDecl()
1968 const auto *Ty = VD->getType().getTypePtr(); in ShouldDiagnoseUnusedDecl()
1971 if (const TypedefType *TT = Ty->getAs<TypedefType>()) { in ShouldDiagnoseUnusedDecl()
1973 if (TT->getDecl()->hasAttr<UnusedAttr>()) in ShouldDiagnoseUnusedDecl()
1980 MTE && MTE->getExtendingDecl()) { in ShouldDiagnoseUnusedDecl()
1981 Ty = VD->getType().getNonReferenceType().getTypePtr(); in ShouldDiagnoseUnusedDecl()
1982 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten(); in ShouldDiagnoseUnusedDecl()
1987 if (Ty->isIncompleteType() || Ty->isDependentType()) in ShouldDiagnoseUnusedDecl()
1992 Ty = Ty->getBaseElementTypeUnsafe(); in ShouldDiagnoseUnusedDecl()
1994 if (const TagType *TT = Ty->getAs<TagType>()) { in ShouldDiagnoseUnusedDecl()
1995 const TagDecl *Tag = TT->getDecl(); in ShouldDiagnoseUnusedDecl()
1996 if (Tag->hasAttr<UnusedAttr>()) in ShouldDiagnoseUnusedDecl()
2000 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>()) in ShouldDiagnoseUnusedDecl()
2005 dyn_cast<CXXConstructExpr>(Init->IgnoreImpCasts()); in ShouldDiagnoseUnusedDecl()
2006 if (Construct && !Construct->isElidable()) { in ShouldDiagnoseUnusedDecl()
2007 const CXXConstructorDecl *CD = Construct->getConstructor(); in ShouldDiagnoseUnusedDecl()
2008 if (!CD->isTrivial() && !RD->hasAttr<WarnUnusedAttr>() && in ShouldDiagnoseUnusedDecl()
2009 (VD->getInit()->isValueDependent() || !VD->evaluateValue())) in ShouldDiagnoseUnusedDecl()
2014 // it could possibly be non-trivial constructor. in ShouldDiagnoseUnusedDecl()
2015 if (Init->isTypeDependent()) { in ShouldDiagnoseUnusedDecl()
2016 for (const CXXConstructorDecl *Ctor : RD->ctors()) in ShouldDiagnoseUnusedDecl()
2017 if (!Ctor->isTrivial()) in ShouldDiagnoseUnusedDecl()
2039 D->getEndLoc(), tok::colon, Ctx.getSourceManager(), Ctx.getLangOpts(), in GenerateFixForUnusedDecl()
2044 CharSourceRange::getCharRange(D->getBeginLoc(), AfterColon)); in GenerateFixForUnusedDecl()
2055 if (D->getTypeForDecl()->isDependentType()) in DiagnoseUnusedNestedTypedefs()
2058 for (auto *TmpD : D->decls()) { in DiagnoseUnusedNestedTypedefs()
2077 // at end-of-translation-unit. in DiagnoseUnusedDecl()
2086 if (isa<VarDecl>(D) && cast<VarDecl>(D)->isExceptionVariable()) in DiagnoseUnusedDecl()
2093 SourceLocation DiagLoc = D->getLocation(); in DiagnoseUnusedDecl()
2101 if (!VD->isReferenced() || !VD->getDeclName() || VD->hasAttr<CleanupAttr>()) in DiagnoseUnusedButSetDecl()
2105 if (VD->hasAttr<UnusedAttr>() || VD->isPlaceholderVar(getLangOpts())) in DiagnoseUnusedButSetDecl()
2108 const auto *Ty = VD->getType().getTypePtr()->getBaseElementTypeUnsafe(); in DiagnoseUnusedButSetDecl()
2110 if (Ty->isReferenceType() || Ty->isDependentType()) in DiagnoseUnusedButSetDecl()
2113 if (const TagType *TT = Ty->getAs<TagType>()) { in DiagnoseUnusedButSetDecl()
2114 const TagDecl *Tag = TT->getDecl(); in DiagnoseUnusedButSetDecl()
2115 if (Tag->hasAttr<UnusedAttr>()) in DiagnoseUnusedButSetDecl()
2120 RD && !RD->hasAttr<WarnUnusedAttr>()) in DiagnoseUnusedButSetDecl()
2124 // Don't warn about __block Objective-C pointer variables, as they might in DiagnoseUnusedButSetDecl()
2127 if (VD->hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType()) in DiagnoseUnusedButSetDecl()
2130 // Don't warn about Objective-C pointer variables with precise lifetime in DiagnoseUnusedButSetDecl()
2133 if (VD->hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType()) in DiagnoseUnusedButSetDecl()
2140 assert(iter->getSecond() >= 0 && in DiagnoseUnusedButSetDecl()
2142 if (int RefCnt = iter->getSecond(); RefCnt > 0) { in DiagnoseUnusedButSetDecl()
2152 bool UnusedCXXCondDecl = VD->isCXXCondDecl() && (RefCnt == 1); in DiagnoseUnusedButSetDecl()
2159 DiagReceiver(VD->getLocation(), PDiag(DiagID) << VD); in DiagnoseUnusedButSetDecl()
2169 if (L->isMSAsmLabel()) in CheckPoppedLabel()
2170 Diagnose = !L->isResolvedMSAsmLabel(); in CheckPoppedLabel()
2172 Diagnose = L->getStmt() == nullptr; in CheckPoppedLabel()
2174 DiagReceiver(L->getLocation(), S.PDiag(diag::err_undeclared_label_use) in CheckPoppedLabel()
2179 S->applyNRVO(); in ActOnPopScope()
2181 if (S->decl_empty()) return; in ActOnPopScope()
2182 assert((S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) && in ActOnPopScope()
2185 /// We visit the decls in non-deterministic order, but we want diagnostics in ActOnPopScope()
2203 for (auto *TmpD : S->decls()) { in ActOnPopScope()
2210 if (!S->hasUnrecoverableErrorOccurred()) { in ActOnPopScope()
2220 if (!D->getDeclName()) continue; in ActOnPopScope()
2236 if (const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) { in ActOnPopScope()
2237 addDiagWithPrev(D->getLocation(), FD->getLocation(), in ActOnPopScope()
2239 << D << FD << FD->getParent()); in ActOnPopScope()
2246 [](const LocAndDiag &LHS, const LocAndDiag &RHS) -> bool { in ActOnPopScope()
2261 while (((S->getFlags() & Scope::DeclScope) == 0) || in getNonFieldDeclScope()
2262 (S->getEntity() && S->getEntity()->isTransparentContext()) || in getNonFieldDeclScope()
2263 (S->isClassScope() && !getLangOpts().CPlusPlus)) in getNonFieldDeclScope()
2264 S = S->getParent(); in getNonFieldDeclScope()
2292 CLinkageDecl->setImplicit(); in CreateBuiltin()
2293 Parent->addDecl(CLinkageDecl); in CreateBuiltin()
2307 Type->isFunctionProtoType(), ConstexprKind); in CreateBuiltin()
2308 New->setImplicit(); in CreateBuiltin()
2309 New->addAttr(BuiltinAttr::CreateImplicit(Context, ID)); in CreateBuiltin()
2315 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { in CreateBuiltin()
2318 FT->getParamType(i), /*TInfo=*/nullptr, SC_None, nullptr); in CreateBuiltin()
2319 parm->setScopeInfo(0, i); in CreateBuiltin()
2322 New->setParams(Params); in CreateBuiltin()
2379 // TUScope is the translation-unit scope to insert this function into. in LazilyCreateBuiltin()
2384 CurContext = New->getDeclContext(); in LazilyCreateBuiltin()
2409 // Non-hidden declarations are never ignored. in filterNonConflictingPreviousTypedefDecls()
2416 if (S.Context.hasSameType(OldTD->getUnderlyingType(), in filterNonConflictingPreviousTypedefDecls()
2417 Decl->getUnderlyingType())) in filterNonConflictingPreviousTypedefDecls()
2422 if (OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true) && in filterNonConflictingPreviousTypedefDecls()
2423 Decl->getAnonDeclWithTypedefName()) in filterNonConflictingPreviousTypedefDecls()
2436 OldType = OldTypedef->getUnderlyingType(); in isIncompatibleTypedef()
2439 QualType NewType = New->getUnderlyingType(); in isIncompatibleTypedef()
2441 if (NewType->isVariablyModifiedType()) { in isIncompatibleTypedef()
2442 // Must not redefine a typedef with a variably-modified type. in isIncompatibleTypedef()
2444 Diag(New->getLocation(), diag::err_redefinition_variably_modified_typedef) in isIncompatibleTypedef()
2446 if (Old->getLocation().isValid()) in isIncompatibleTypedef()
2447 notePreviousDefinition(Old, New->getLocation()); in isIncompatibleTypedef()
2448 New->setInvalidDecl(); in isIncompatibleTypedef()
2453 !OldType->isDependentType() && in isIncompatibleTypedef()
2454 !NewType->isDependentType() && in isIncompatibleTypedef()
2457 Diag(New->getLocation(), diag::err_redefinition_different_typedef) in isIncompatibleTypedef()
2459 if (Old->getLocation().isValid()) in isIncompatibleTypedef()
2460 notePreviousDefinition(Old, New->getLocation()); in isIncompatibleTypedef()
2461 New->setInvalidDecl(); in isIncompatibleTypedef()
2471 if (New->isInvalidDecl()) return; in MergeTypedefNameDecl()
2473 // Allow multiple definitions for ObjC built-in typedefs. in MergeTypedefNameDecl()
2476 const IdentifierInfo *TypeID = New->getIdentifier(); in MergeTypedefNameDecl()
2477 switch (TypeID->getLength()) { in MergeTypedefNameDecl()
2481 if (!TypeID->isStr("id")) in MergeTypedefNameDecl()
2483 QualType T = New->getUnderlyingType(); in MergeTypedefNameDecl()
2484 if (!T->isPointerType()) in MergeTypedefNameDecl()
2486 if (!T->isVoidPointerType()) { in MergeTypedefNameDecl()
2487 QualType PT = T->castAs<PointerType>()->getPointeeType(); in MergeTypedefNameDecl()
2488 if (!PT->isStructureType()) in MergeTypedefNameDecl()
2492 // Install the built-in type for 'id', ignoring the current definition. in MergeTypedefNameDecl()
2493 New->setTypeForDecl(Context.getObjCIdType().getTypePtr()); in MergeTypedefNameDecl()
2497 if (!TypeID->isStr("Class")) in MergeTypedefNameDecl()
2499 Context.setObjCClassRedefinitionType(New->getUnderlyingType()); in MergeTypedefNameDecl()
2500 // Install the built-in type for 'Class', ignoring the current definition. in MergeTypedefNameDecl()
2501 New->setTypeForDecl(Context.getObjCClassType().getTypePtr()); in MergeTypedefNameDecl()
2504 if (!TypeID->isStr("SEL")) in MergeTypedefNameDecl()
2506 Context.setObjCSelRedefinitionType(New->getUnderlyingType()); in MergeTypedefNameDecl()
2507 // Install the built-in type for 'SEL', ignoring the current definition. in MergeTypedefNameDecl()
2508 New->setTypeForDecl(Context.getObjCSelType().getTypePtr()); in MergeTypedefNameDecl()
2511 // Fall through - the typedef name was not a builtin type. in MergeTypedefNameDecl()
2517 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeTypedefNameDecl()
2518 << New->getDeclName(); in MergeTypedefNameDecl()
2521 if (OldD->getLocation().isValid()) in MergeTypedefNameDecl()
2522 notePreviousDefinition(OldD, New->getLocation()); in MergeTypedefNameDecl()
2524 return New->setInvalidDecl(); in MergeTypedefNameDecl()
2528 if (Old->isInvalidDecl()) in MergeTypedefNameDecl()
2529 return New->setInvalidDecl(); in MergeTypedefNameDecl()
2532 auto *OldTag = OldTD->getAnonDeclWithTypedefName(/*AnyRedecl*/true); in MergeTypedefNameDecl()
2533 auto *NewTag = New->getAnonDeclWithTypedefName(); in MergeTypedefNameDecl()
2536 OldTag->getCanonicalDecl() != NewTag->getCanonicalDecl() && in MergeTypedefNameDecl()
2540 New->setTypeForDecl(OldTD->getTypeForDecl()); in MergeTypedefNameDecl()
2541 if (OldTD->isModed()) in MergeTypedefNameDecl()
2542 New->setModedTypeSourceInfo(OldTD->getTypeSourceInfo(), in MergeTypedefNameDecl()
2543 OldTD->getUnderlyingType()); in MergeTypedefNameDecl()
2545 New->setTypeSourceInfo(OldTD->getTypeSourceInfo()); in MergeTypedefNameDecl()
2554 for (auto *D : NewTag->decls()) { in MergeTypedefNameDecl()
2556 assert(EnumScope->isDeclScope(ED)); in MergeTypedefNameDecl()
2557 EnumScope->RemoveDecl(ED); in MergeTypedefNameDecl()
2559 ED->getLexicalDeclContext()->removeDecl(ED); in MergeTypedefNameDecl()
2573 New->setPreviousDecl(Typedef); in MergeTypedefNameDecl()
2582 // In a given non-class scope, a typedef specifier can be used to in MergeTypedefNameDecl()
2590 // any class-name declared in that scope that is not also a typedef-name in MergeTypedefNameDecl()
2612 Diag(New->getLocation(), diag::err_redefinition) in MergeTypedefNameDecl()
2613 << New->getDeclName(); in MergeTypedefNameDecl()
2614 notePreviousDefinition(Old, New->getLocation()); in MergeTypedefNameDecl()
2615 return New->setInvalidDecl(); in MergeTypedefNameDecl()
2624 // -Wtypedef-redefinition. If either the original or the redefinition is in MergeTypedefNameDecl()
2628 (Old->isImplicit() || in MergeTypedefNameDecl()
2629 Context.getSourceManager().isInSystemHeader(Old->getLocation()) || in MergeTypedefNameDecl()
2630 Context.getSourceManager().isInSystemHeader(New->getLocation()))) in MergeTypedefNameDecl()
2633 Diag(New->getLocation(), diag::ext_redefinition_of_typedef) in MergeTypedefNameDecl()
2634 << New->getDeclName(); in MergeTypedefNameDecl()
2635 notePreviousDefinition(Old, New->getLocation()); in MergeTypedefNameDecl()
2638 /// DeclhasAttr - returns true if decl Declaration already has the target
2643 for (const auto *i : D->attrs()) in DeclHasAttr()
2644 if (i->getKind() == A->getKind()) { in DeclHasAttr()
2646 if (Ann->getAnnotation() == cast<AnnotateAttr>(i)->getAnnotation()) in DeclHasAttr()
2652 return OA->getOwnKind() == cast<OwnershipAttr>(i)->getOwnKind(); in DeclHasAttr()
2661 return VD->isThisDeclarationADefinition(); in isAttributeTargetADefinition()
2663 return TD->isCompleteDefinition() || TD->isBeingDefined(); in isAttributeTargetADefinition()
2677 for (auto *I : Old->specific_attrs<AlignedAttr>()) { in mergeAlignedAttrs()
2684 if (I->isAlignmentDependent()) in mergeAlignedAttrs()
2687 if (I->isAlignas()) in mergeAlignedAttrs()
2690 unsigned Align = I->getAlignment(S.Context); in mergeAlignedAttrs()
2700 for (auto *I : New->specific_attrs<AlignedAttr>()) { in mergeAlignedAttrs()
2701 if (I->isAlignmentDependent()) in mergeAlignedAttrs()
2704 if (I->isAlignas()) in mergeAlignedAttrs()
2707 unsigned Align = I->getAlignment(S.Context); in mergeAlignedAttrs()
2723 Ty = VD->getType(); in mergeAlignedAttrs()
2734 S.Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch) in mergeAlignedAttrs()
2737 S.Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration); in mergeAlignedAttrs()
2743 // if any declaration of an entity has an alignment-specifier, in mergeAlignedAttrs()
2750 S.Diag(New->getLocation(), diag::err_alignas_missing_on_definition) in mergeAlignedAttrs()
2752 S.Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration) in mergeAlignedAttrs()
2760 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.Context); in mergeAlignedAttrs()
2761 Clone->setInherited(true); in mergeAlignedAttrs()
2762 New->addAttr(Clone); in mergeAlignedAttrs()
2768 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) { in mergeAlignedAttrs()
2769 AlignedAttr *Clone = OldAlignasAttr->clone(S.Context); in mergeAlignedAttrs()
2770 Clone->setInherited(true); in mergeAlignedAttrs()
2771 New->addAttr(Clone); in mergeAlignedAttrs()
2800 D, *AA, AA->getPlatform(), AA->isImplicit(), AA->getIntroduced(), in mergeDeclAttribute()
2801 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(), in mergeDeclAttribute()
2802 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK, in mergeDeclAttribute()
2803 AA->getPriority(), AA->getEnvironment()); in mergeDeclAttribute()
2805 NewAttr = S.mergeVisibilityAttr(D, *VA, VA->getVisibility()); in mergeDeclAttribute()
2807 NewAttr = S.mergeTypeVisibilityAttr(D, *VA, VA->getVisibility()); in mergeDeclAttribute()
2813 NewAttr = S.mergeErrorAttr(D, *EA, EA->getUserDiagnostic()); in mergeDeclAttribute()
2815 NewAttr = S.mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(), in mergeDeclAttribute()
2816 FA->getFirstArg()); in mergeDeclAttribute()
2818 NewAttr = S.mergeSectionAttr(D, *SA, SA->getName()); in mergeDeclAttribute()
2820 NewAttr = S.mergeCodeSegAttr(D, *CSA, CSA->getName()); in mergeDeclAttribute()
2822 NewAttr = S.mergeMSInheritanceAttr(D, *IA, IA->getBestCase(), in mergeDeclAttribute()
2823 IA->getInheritanceModel()); in mergeDeclAttribute()
2826 &S.Context.Idents.get(AA->getSpelling())); in mergeDeclAttribute()
2836 NewAttr = S.Swift().mergeNameAttr(D, *SNA, SNA->getName()); in mergeDeclAttribute()
2851 NewAttr = S.mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl()); in mergeDeclAttribute()
2863 NewAttr = S.HLSL().mergeNumThreadsAttr(D, *NT, NT->getX(), NT->getY(), in mergeDeclAttribute()
2864 NT->getZ()); in mergeDeclAttribute()
2866 NewAttr = S.HLSL().mergeShaderAttr(D, *SA, SA->getType()); in mergeDeclAttribute()
2870 else if (Attr->shouldInheritEvenIfAlreadyPresent() || !DeclHasAttr(D, Attr)) in mergeDeclAttribute()
2871 NewAttr = cast<InheritableAttr>(Attr->clone(S.Context)); in mergeDeclAttribute()
2874 NewAttr->setInherited(true); in mergeDeclAttribute()
2875 D->addAttr(NewAttr); in mergeDeclAttribute()
2886 return TD->getDefinition(); in getDefinition()
2888 const VarDecl *Def = VD->getDefinition(); in getDefinition()
2891 return VD->getActingDefinition(); in getDefinition()
2895 if (FD->isDefined(Def, true)) in getDefinition()
2902 for (const auto *Attribute : D->attrs()) in hasAttribute()
2903 if (Attribute->getKind() == Kind) in hasAttribute()
2908 /// checkNewAttributesAfterDef - If we already have a definition, check that
2911 if (!New->hasAttrs()) in checkNewAttributesAfterDef()
2918 AttrVec &NewAttributes = New->getAttrs(); in checkNewAttributesAfterDef()
2930 --E; in checkNewAttributesAfterDef()
2935 unsigned Diag = cast<VarDecl>(Def)->isThisDeclarationADefinition() == in checkNewAttributesAfterDef()
2939 S.Diag(VD->getLocation(), Diag) << VD->getDeclName(); in checkNewAttributesAfterDef()
2941 S.notePreviousDefinition(Def, VD->getLocation()); in checkNewAttributesAfterDef()
2943 S.Diag(Def->getLocation(), diag::note_previous_definition); in checkNewAttributesAfterDef()
2944 VD->setInvalidDecl(); in checkNewAttributesAfterDef()
2952 if (VD->isThisDeclarationADefinition() != VarDecl::Definition) { in checkNewAttributesAfterDef()
2958 if (hasAttribute(Def, NewAttribute->getKind())) { in checkNewAttributesAfterDef()
2972 if (AA->isAlignas()) { in checkNewAttributesAfterDef()
2974 // if any declaration of an entity has an alignment-specifier, in checkNewAttributesAfterDef()
2981 S.Diag(Def->getLocation(), diag::err_alignas_missing_on_definition) in checkNewAttributesAfterDef()
2983 S.Diag(NewAttribute->getLocation(), diag::note_alignas_on_declaration) in checkNewAttributesAfterDef()
2986 --E; in checkNewAttributesAfterDef()
2994 S.Diag(NewAttribute->getLocation(), in checkNewAttributesAfterDef()
2996 S.Diag(Def->getLocation(), diag::note_previous_definition); in checkNewAttributesAfterDef()
2998 --E; in checkNewAttributesAfterDef()
3002 cast<VarDecl>(New)->isInline() && in checkNewAttributesAfterDef()
3003 !cast<VarDecl>(New)->isInlineSpecified()) { in checkNewAttributesAfterDef()
3017 S.Diag(NewAttribute->getLocation(), in checkNewAttributesAfterDef()
3019 S.Diag(Def->getLocation(), diag::note_previous_definition); in checkNewAttributesAfterDef()
3021 --E; in checkNewAttributesAfterDef()
3028 SourceLocation InsertLoc = InitDecl->getInnerLocStart(); in diagnoseMissingConstinit()
3060 assert(CIAttr->isConstinit() && "should not diagnose this for attribute"); in diagnoseMissingConstinit()
3061 S.Diag(InitDecl->getLocation(), diag::ext_constinit_missing) in diagnoseMissingConstinit()
3063 S.Diag(CIAttr->getLocation(), diag::note_constinit_specified_here); in diagnoseMissingConstinit()
3067 S.Diag(CIAttr->getLocation(), in diagnoseMissingConstinit()
3068 CIAttr->isConstinit() ? diag::err_constinit_added_too_late in diagnoseMissingConstinit()
3070 << FixItHint::CreateRemoval(SourceRange(CIAttr->getLocation())); in diagnoseMissingConstinit()
3071 S.Diag(InitDecl->getLocation(), diag::note_constinit_missing_here) in diagnoseMissingConstinit()
3072 << CIAttr->isConstinit() in diagnoseMissingConstinit()
3079 if (UsedAttr *OldAttr = Old->getMostRecentDecl()->getAttr<UsedAttr>()) { in mergeDeclAttributes()
3080 UsedAttr *NewAttr = OldAttr->clone(Context); in mergeDeclAttributes()
3081 NewAttr->setInherited(true); in mergeDeclAttributes()
3082 New->addAttr(NewAttr); in mergeDeclAttributes()
3084 if (RetainAttr *OldAttr = Old->getMostRecentDecl()->getAttr<RetainAttr>()) { in mergeDeclAttributes()
3085 RetainAttr *NewAttr = OldAttr->clone(Context); in mergeDeclAttributes()
3086 NewAttr->setInherited(true); in mergeDeclAttributes()
3087 New->addAttr(NewAttr); in mergeDeclAttributes()
3090 if (!Old->hasAttrs() && !New->hasAttrs()) in mergeDeclAttributes()
3096 const auto *OldConstInit = Old->getAttr<ConstInitAttr>(); in mergeDeclAttributes()
3097 const auto *NewConstInit = New->getAttr<ConstInitAttr>(); in mergeDeclAttributes()
3104 const VarDecl *InitDecl = OldVD->getInitializingDeclaration(); in mergeDeclAttributes()
3106 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition())) in mergeDeclAttributes()
3111 // that's ill-formed. (Note that we do not apply this to the attribute in mergeDeclAttributes()
3113 if (OldConstInit && OldConstInit->isConstinit()) in mergeDeclAttributes()
3123 NewVD->dropAttr<ConstInitAttr>(); in mergeDeclAttributes()
3128 // Attributes declared post-definition are currently ignored. in mergeDeclAttributes()
3131 if (AsmLabelAttr *NewA = New->getAttr<AsmLabelAttr>()) { in mergeDeclAttributes()
3132 if (AsmLabelAttr *OldA = Old->getAttr<AsmLabelAttr>()) { in mergeDeclAttributes()
3133 if (!OldA->isEquivalent(NewA)) { in mergeDeclAttributes()
3135 Diag(New->getLocation(), diag::err_different_asm_label); in mergeDeclAttributes()
3136 Diag(OldA->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
3138 } else if (Old->isUsed()) { in mergeDeclAttributes()
3140 // already been ODR-used. in mergeDeclAttributes()
3141 Diag(New->getLocation(), diag::err_late_asm_label_name) in mergeDeclAttributes()
3142 << isa<FunctionDecl>(Old) << New->getAttr<AsmLabelAttr>()->getRange(); in mergeDeclAttributes()
3146 // Re-declaration cannot add abi_tag's. in mergeDeclAttributes()
3147 if (const auto *NewAbiTagAttr = New->getAttr<AbiTagAttr>()) { in mergeDeclAttributes()
3148 if (const auto *OldAbiTagAttr = Old->getAttr<AbiTagAttr>()) { in mergeDeclAttributes()
3149 for (const auto &NewTag : NewAbiTagAttr->tags()) { in mergeDeclAttributes()
3150 if (!llvm::is_contained(OldAbiTagAttr->tags(), NewTag)) { in mergeDeclAttributes()
3151 Diag(NewAbiTagAttr->getLocation(), in mergeDeclAttributes()
3154 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
3158 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration); in mergeDeclAttributes()
3159 Diag(Old->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
3164 if (New->hasAttr<SectionAttr>() && !Old->hasAttr<SectionAttr>()) { in mergeDeclAttributes()
3166 if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly) { in mergeDeclAttributes()
3167 Diag(New->getLocation(), diag::warn_attribute_section_on_redeclaration); in mergeDeclAttributes()
3168 Diag(Old->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
3173 // Redeclaration adds code-seg attribute. in mergeDeclAttributes()
3174 const auto *NewCSA = New->getAttr<CodeSegAttr>(); in mergeDeclAttributes()
3175 if (NewCSA && !Old->hasAttr<CodeSegAttr>() && in mergeDeclAttributes()
3176 !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) { in mergeDeclAttributes()
3177 Diag(New->getLocation(), diag::warn_mismatched_section) in mergeDeclAttributes()
3179 Diag(Old->getLocation(), diag::note_previous_declaration); in mergeDeclAttributes()
3182 if (!Old->hasAttrs()) in mergeDeclAttributes()
3185 bool foundAny = New->hasAttrs(); in mergeDeclAttributes()
3189 if (!foundAny) New->setAttrs(AttrVec()); in mergeDeclAttributes()
3191 for (auto *I : Old->specific_attrs<InheritableAttr>()) { in mergeDeclAttributes()
3221 if (!foundAny) New->dropAttrs(); in mergeDeclAttributes()
3224 /// mergeParamDeclAttributes - Copy attributes from the old parameter
3231 // carries_dependency attribute for its declarator-id if any declaration in mergeParamDeclAttributes()
3233 const CarriesDependencyAttr *CDA = newDecl->getAttr<CarriesDependencyAttr>(); in mergeParamDeclAttributes()
3234 if (CDA && !oldDecl->hasAttr<CarriesDependencyAttr>()) { in mergeParamDeclAttributes()
3235 S.Diag(CDA->getLocation(), in mergeParamDeclAttributes()
3240 cast<FunctionDecl>(oldDecl->getDeclContext())->getFirstDecl(); in mergeParamDeclAttributes()
3242 FirstFD->getParamDecl(oldDecl->getFunctionScopeIndex()); in mergeParamDeclAttributes()
3243 S.Diag(FirstVD->getLocation(), in mergeParamDeclAttributes()
3252 const auto *NDAttr = newDecl->getAttr<HLSLParamModifierAttr>(); in mergeParamDeclAttributes()
3253 const auto *ODAttr = oldDecl->getAttr<HLSLParamModifierAttr>(); in mergeParamDeclAttributes()
3259 NDAttr->getSpellingListIndex() != ODAttr->getSpellingListIndex()) { in mergeParamDeclAttributes()
3260 S.Diag(newDecl->getLocation(), diag::err_hlsl_param_qualifier_mismatch) in mergeParamDeclAttributes()
3262 S.Diag(oldDecl->getLocation(), diag::note_previous_declaration_as) in mergeParamDeclAttributes()
3267 if (!oldDecl->hasAttrs()) in mergeParamDeclAttributes()
3270 bool foundAny = newDecl->hasAttrs(); in mergeParamDeclAttributes()
3274 if (!foundAny) newDecl->setAttrs(AttrVec()); in mergeParamDeclAttributes()
3276 for (const auto *I : oldDecl->specific_attrs<InheritableParamAttr>()) { in mergeParamDeclAttributes()
3279 cast<InheritableParamAttr>(I->clone(S.Context)); in mergeParamDeclAttributes()
3280 newAttr->setInherited(true); in mergeParamDeclAttributes()
3281 newDecl->addAttr(newAttr); in mergeParamDeclAttributes()
3286 if (!foundAny) newDecl->dropAttrs(); in mergeParamDeclAttributes()
3293 if (Ty->isIncompleteArrayType() || Ty->isPointerType()) in EquivalentArrayTypes()
3296 return VAT->getSizeModifier() == ArraySizeModifier::Star; in EquivalentArrayTypes()
3305 if (Old->isVariableArrayType() && New->isVariableArrayType()) { in EquivalentArrayTypes()
3308 if ((OldVAT->getSizeModifier() == ArraySizeModifier::Star) ^ in EquivalentArrayTypes()
3309 (NewVAT->getSizeModifier() == ArraySizeModifier::Star)) in EquivalentArrayTypes()
3315 if (Old->isConstantArrayType() && New->isConstantArrayType()) { in EquivalentArrayTypes()
3316 return Ctx.getAsConstantArrayType(Old)->getSize() == in EquivalentArrayTypes()
3317 Ctx.getAsConstantArrayType(New)->getSize(); in EquivalentArrayTypes()
3321 if (Old->isDependentSizedArrayType() && New->isDependentSizedArrayType()) { in EquivalentArrayTypes()
3331 if (auto Oldnullability = OldParam->getType()->getNullability()) { in mergeParamDeclTypes()
3332 if (auto Newnullability = NewParam->getType()->getNullability()) { in mergeParamDeclTypes()
3334 S.Diag(NewParam->getLocation(), diag::warn_mismatched_nullability_attr) in mergeParamDeclTypes()
3337 ((NewParam->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability) in mergeParamDeclTypes()
3341 ((OldParam->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability) in mergeParamDeclTypes()
3343 S.Diag(OldParam->getLocation(), diag::note_previous_declaration); in mergeParamDeclTypes()
3346 QualType NewT = NewParam->getType(); in mergeParamDeclTypes()
3350 NewParam->setType(NewT); in mergeParamDeclTypes()
3353 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->getType()); in mergeParamDeclTypes()
3354 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->getType()); in mergeParamDeclTypes()
3356 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) { in mergeParamDeclTypes()
3357 QualType OldParamOT = OldParamDT->getOriginalType(); in mergeParamDeclTypes()
3358 QualType NewParamOT = NewParamDT->getOriginalType(); in mergeParamDeclTypes()
3360 S.Diag(NewParam->getLocation(), diag::warn_inconsistent_array_form) in mergeParamDeclTypes()
3362 S.Diag(OldParam->getLocation(), diag::note_previous_declaration_as) in mergeParamDeclTypes()
3386 SourceLocation OldLocation = Old->getLocation(); in getNoteDiagForInvalidRedeclaration()
3387 if (Old->isThisDeclarationADefinition()) in getNoteDiagForInvalidRedeclaration()
3389 else if (Old->isImplicit()) { in getNoteDiagForInvalidRedeclaration()
3392 if (FD->getBuiltinID()) in getNoteDiagForInvalidRedeclaration()
3396 OldLocation = New->getLocation(); in getNoteDiagForInvalidRedeclaration()
3402 /// canRedefineFunction - checks if a function can be redefined. Currently,
3407 return ((FD->hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) && in canRedefineFunction()
3409 FD->isInlineSpecified() && in canRedefineFunction()
3410 FD->getStorageClass() == SC_Extern); in canRedefineFunction()
3414 const AttributedType *AT = T->getAs<AttributedType>(); in getCallingConvAttributedType()
3415 while (AT && !AT->isCallingConv()) in getCallingConvAttributedType()
3416 AT = AT->getModifiedType()->getAs<AttributedType>(); in getCallingConvAttributedType()
3422 const DeclContext *DC = Old->getDeclContext(); in haveIncompatibleLanguageLinkages()
3423 if (DC->isRecord()) in haveIncompatibleLanguageLinkages()
3426 LanguageLinkage OldLinkage = Old->getLanguageLinkage(); in haveIncompatibleLanguageLinkages()
3427 if (OldLinkage == CXXLanguageLinkage && New->isInExternCContext()) in haveIncompatibleLanguageLinkages()
3429 if (OldLinkage == CLanguageLinkage && New->isInExternCXXContext()) in haveIncompatibleLanguageLinkages()
3434 template<typename T> static bool isExternC(T *D) { return D->isExternC(); } in isExternC()
3439 /// using-declaration is valid, given that we know it's not an overload
3447 // -- they shall all refer to the same entity, or all refer to functions in checkUsingShadowRedecl()
3449 // -- exactly one declaration shall declare a class name or enumeration in checkUsingShadowRedecl()
3457 // same name and the same parameter-type-list as a function introduced in checkUsingShadowRedecl()
3458 // by a using-declaration, and the declarations do not declare the same in checkUsingShadowRedecl()
3459 // function, the program is ill-formed. in checkUsingShadowRedecl()
3461 auto *Old = dyn_cast<ExpectedDecl>(OldS->getTargetDecl()); in checkUsingShadowRedecl()
3463 !Old->getDeclContext()->getRedeclContext()->Equals( in checkUsingShadowRedecl()
3464 New->getDeclContext()->getRedeclContext()) && in checkUsingShadowRedecl()
3469 S.Diag(New->getLocation(), diag::err_using_decl_conflict_reverse); in checkUsingShadowRedecl()
3470 S.Diag(OldS->getTargetDecl()->getLocation(), diag::note_using_decl_target); in checkUsingShadowRedecl()
3471 S.Diag(OldS->getIntroducer()->getLocation(), diag::note_using_decl) << 0; in checkUsingShadowRedecl()
3479 assert(A->getNumParams() == B->getNumParams()); in hasIdenticalPassObjectSizeAttrs()
3482 const auto *AttrA = A->getAttr<PassObjectSizeAttr>(); in hasIdenticalPassObjectSizeAttrs()
3483 const auto *AttrB = B->getAttr<PassObjectSizeAttr>(); in hasIdenticalPassObjectSizeAttrs()
3486 return AttrA && AttrB && AttrA->getType() == AttrB->getType() && in hasIdenticalPassObjectSizeAttrs()
3487 AttrA->isDynamic() == AttrB->isDynamic(); in hasIdenticalPassObjectSizeAttrs()
3490 return std::equal(A->param_begin(), A->param_end(), B->param_begin(), AttrEq); in hasIdenticalPassObjectSizeAttrs()
3507 if (!NewD->getQualifier()) in adjustDeclContextForDeclaratorDecl()
3511 auto *NamedDC = NewD->getDeclContext()->getRedeclContext(); in adjustDeclContextForDeclaratorDecl()
3512 auto *SemaDC = OldD->getDeclContext()->getRedeclContext(); in adjustDeclContextForDeclaratorDecl()
3513 if (NamedDC->Equals(SemaDC)) in adjustDeclContextForDeclaratorDecl()
3516 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) || in adjustDeclContextForDeclaratorDecl()
3517 NewD->isInvalidDecl() || OldD->isInvalidDecl()) && in adjustDeclContextForDeclaratorDecl()
3520 auto *LexDC = NewD->getLexicalDeclContext(); in adjustDeclContextForDeclaratorDecl()
3524 D->setDeclContext(SemaDC); in adjustDeclContextForDeclaratorDecl()
3525 D->setLexicalDeclContext(LexDC); in adjustDeclContextForDeclaratorDecl()
3530 FixSemaDC(FD->getDescribedFunctionTemplate()); in adjustDeclContextForDeclaratorDecl()
3532 FixSemaDC(VD->getDescribedVarTemplate()); in adjustDeclContextForDeclaratorDecl()
3538 FunctionDecl *Old = OldD->getAsFunction(); in MergeFunctionDecl()
3541 if (New->getFriendObjectKind()) { in MergeFunctionDecl()
3542 Diag(New->getLocation(), diag::err_using_decl_friend); in MergeFunctionDecl()
3543 Diag(Shadow->getTargetDecl()->getLocation(), in MergeFunctionDecl()
3545 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) in MergeFunctionDecl()
3553 New->getDescribedFunctionTemplate()) { in MergeFunctionDecl()
3557 OldD = Old = cast<FunctionTemplateDecl>(Shadow->getTargetDecl()) in MergeFunctionDecl()
3558 ->getAsFunction(); in MergeFunctionDecl()
3562 OldD = Old = cast<FunctionDecl>(Shadow->getTargetDecl()); in MergeFunctionDecl()
3565 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeFunctionDecl()
3566 << New->getDeclName(); in MergeFunctionDecl()
3567 notePreviousDefinition(OldD, New->getLocation()); in MergeFunctionDecl()
3577 if (Old->isInvalidDecl()) in MergeFunctionDecl()
3582 Diag(New->getLocation(), diag::err_builtin_redeclare) << Old->getDeclName(); in MergeFunctionDecl()
3583 Diag(Old->getLocation(), diag::note_previous_builtin_declaration) in MergeFunctionDecl()
3584 << Old << Old->getType(); in MergeFunctionDecl()
3598 New->getStorageClass() == SC_Static && in MergeFunctionDecl()
3599 Old->hasExternalFormalLinkage() && in MergeFunctionDecl()
3600 !New->getTemplateSpecializationInfo() && in MergeFunctionDecl()
3603 Diag(New->getLocation(), diag::ext_static_non_static) << New; in MergeFunctionDecl()
3604 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3606 Diag(New->getLocation(), diag::err_static_non_static) << New; in MergeFunctionDecl()
3607 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3612 if (const auto *ILA = New->getAttr<InternalLinkageAttr>()) in MergeFunctionDecl()
3613 if (!Old->hasAttr<InternalLinkageAttr>()) { in MergeFunctionDecl()
3614 Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl) in MergeFunctionDecl()
3616 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
3617 New->dropAttr<InternalLinkageAttr>(); in MergeFunctionDecl()
3620 if (auto *EA = New->getAttr<ErrorAttr>()) { in MergeFunctionDecl()
3621 if (!Old->hasAttr<ErrorAttr>()) { in MergeFunctionDecl()
3622 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA; in MergeFunctionDecl()
3623 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
3624 New->dropAttr<ErrorAttr>(); in MergeFunctionDecl()
3632 bool OldOvl = Old->hasAttr<OverloadableAttr>(); in MergeFunctionDecl()
3633 if (OldOvl != New->hasAttr<OverloadableAttr>() && !Old->isImplicit()) { in MergeFunctionDecl()
3634 Diag(New->getLocation(), diag::err_attribute_overloadable_mismatch) in MergeFunctionDecl()
3645 auto OldIter = llvm::find_if(Old->redecls(), [](const Decl *D) { in MergeFunctionDecl()
3646 const auto *A = D->getAttr<OverloadableAttr>(); in MergeFunctionDecl()
3647 return A && !A->isImplicit(); in MergeFunctionDecl()
3651 DiagOld = OldIter == Old->redecls_end() ? nullptr : *OldIter; in MergeFunctionDecl()
3655 Diag(DiagOld->getLocation(), in MergeFunctionDecl()
3660 New->addAttr(OverloadableAttr::CreateImplicit(Context)); in MergeFunctionDecl()
3662 New->dropAttr<OverloadableAttr>(); in MergeFunctionDecl()
3668 if (IsInvalidSMECallConversion(Old->getType(), New->getType())) { in MergeFunctionDecl()
3669 Diag(New->getLocation(), diag::err_sme_attr_mismatch) in MergeFunctionDecl()
3670 << New->getType() << Old->getType(); in MergeFunctionDecl()
3688 QualType OldQType = Context.getCanonicalType(Old->getType()); in MergeFunctionDecl()
3689 QualType NewQType = Context.getCanonicalType(New->getType()); in MergeFunctionDecl()
3692 FunctionType::ExtInfo OldTypeInfo = OldType->getExtInfo(); in MergeFunctionDecl()
3693 FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo(); in MergeFunctionDecl()
3697 FunctionDecl *First = Old->getFirstDecl(); in MergeFunctionDecl()
3699 First->getType().getCanonicalType()->castAs<FunctionType>(); in MergeFunctionDecl()
3700 FunctionType::ExtInfo FI = FT->getExtInfo(); in MergeFunctionDecl()
3701 bool NewCCExplicit = getCallingConvAttributedType(New->getType()); in MergeFunctionDecl()
3707 } else if (Old->getBuiltinID()) { in MergeFunctionDecl()
3714 Diag(New->getLocation(), diag::warn_cconv_unsupported) in MergeFunctionDecl()
3721 bool FirstCCExplicit = getCallingConvAttributedType(First->getType()); in MergeFunctionDecl()
3722 Diag(New->getLocation(), diag::err_cconv_change) in MergeFunctionDecl()
3729 Diag(First->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
3744 Diag(New->getLocation(), diag::err_regparm_mismatch) in MergeFunctionDecl()
3745 << NewType->getRegParmType() in MergeFunctionDecl()
3746 << OldType->getRegParmType(); in MergeFunctionDecl()
3758 Diag(New->getLocation(), diag::err_function_attribute_mismatch) in MergeFunctionDecl()
3772 New->getAttr<AnyX86NoCallerSavedRegistersAttr>(); in MergeFunctionDecl()
3773 Diag(New->getLocation(), diag::err_function_attribute_mismatch) << Attr; in MergeFunctionDecl()
3783 const FunctionType *AdjustedType = New->getType()->getAs<FunctionType>(); in MergeFunctionDecl()
3785 New->setType(QualType(AdjustedType, 0)); in MergeFunctionDecl()
3786 NewQType = Context.getCanonicalType(New->getType()); in MergeFunctionDecl()
3791 if (!Old->isInlined() && New->isInlined() && in MergeFunctionDecl()
3792 !New->hasAttr<GNUInlineAttr>() && in MergeFunctionDecl()
3794 Old->isUsed(false) && in MergeFunctionDecl()
3795 !Old->isDefined() && !New->isThisDeclarationADefinition()) in MergeFunctionDecl()
3796 UndefinedButUsed.insert(std::make_pair(Old->getCanonicalDecl(), in MergeFunctionDecl()
3801 if (New->hasAttr<GNUInlineAttr>() && in MergeFunctionDecl()
3802 Old->isInlined() && !Old->hasAttr<GNUInlineAttr>()) { in MergeFunctionDecl()
3803 UndefinedButUsed.erase(Old->getCanonicalDecl()); in MergeFunctionDecl()
3808 if (Old->getNumParams() > 0 && Old->getNumParams() == New->getNumParams() && in MergeFunctionDecl()
3810 Diag(New->getLocation(), diag::err_different_pass_object_size_params) in MergeFunctionDecl()
3811 << New->getDeclName(); in MergeFunctionDecl()
3812 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3818 const auto OldFX = Old->getFunctionEffects(); in MergeFunctionDecl()
3819 const auto NewFX = New->getFunctionEffects(); in MergeFunctionDecl()
3824 Diag(New->getLocation(), in MergeFunctionDecl()
3827 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
3833 if (const auto *NewFPT = NewQType->getAs<FunctionProtoType>()) { in MergeFunctionDecl()
3838 diagnoseFunctionEffectMergeConflicts(MergeErrs, New->getLocation(), in MergeFunctionDecl()
3839 Old->getLocation()); in MergeFunctionDecl()
3841 FunctionProtoType::ExtProtoInfo EPI = NewFPT->getExtProtoInfo(); in MergeFunctionDecl()
3843 QualType ModQT = Context.getFunctionType(NewFPT->getReturnType(), in MergeFunctionDecl()
3844 NewFPT->getParamTypes(), EPI); in MergeFunctionDecl()
3846 New->setType(ModQT); in MergeFunctionDecl()
3847 NewQType = New->getType(); in MergeFunctionDecl()
3851 if (const auto *OldFPT = OldQType->getAs<FunctionProtoType>()) { in MergeFunctionDecl()
3852 EPI = OldFPT->getExtProtoInfo(); in MergeFunctionDecl()
3855 OldFPT->getReturnType(), OldFPT->getParamTypes(), EPI); in MergeFunctionDecl()
3862 OldQType = Context.getCanonicalType(Old->getType()); in MergeFunctionDecl()
3863 NewQType = Context.getCanonicalType(New->getType()); in MergeFunctionDecl()
3870 QualType OldDeclaredReturnType = Old->getDeclaredReturnType(); in MergeFunctionDecl()
3871 QualType NewDeclaredReturnType = New->getDeclaredReturnType(); in MergeFunctionDecl()
3876 if (NewDeclaredReturnType->isObjCObjectPointerType() && in MergeFunctionDecl()
3877 OldDeclaredReturnType->isObjCObjectPointerType()) in MergeFunctionDecl()
3881 if (New->isCXXClassMember() && New->isOutOfLine()) in MergeFunctionDecl()
3882 Diag(New->getLocation(), diag::err_member_def_does_not_match_ret_type) in MergeFunctionDecl()
3883 << New << New->getReturnTypeSourceRange(); in MergeFunctionDecl()
3885 Diag(New->getLocation(), diag::err_ovl_diff_return_type) in MergeFunctionDecl()
3886 << New->getReturnTypeSourceRange(); in MergeFunctionDecl()
3887 Diag(OldLocation, PrevDiag) << Old << Old->getType() in MergeFunctionDecl()
3888 << Old->getReturnTypeSourceRange(); in MergeFunctionDecl()
3895 QualType OldReturnType = OldType->getReturnType(); in MergeFunctionDecl()
3896 QualType NewReturnType = cast<FunctionType>(NewQType)->getReturnType(); in MergeFunctionDecl()
3900 AutoType *OldAT = Old->getReturnType()->getContainedAutoType(); in MergeFunctionDecl()
3901 if (OldAT && OldAT->isDeduced()) { in MergeFunctionDecl()
3902 QualType DT = OldAT->getDeducedType(); in MergeFunctionDecl()
3904 New->setType(SubstAutoTypeDependent(New->getType())); in MergeFunctionDecl()
3907 New->setType(SubstAutoType(New->getType(), DT)); in MergeFunctionDecl()
3917 NewMethod->setTrivial(OldMethod->isTrivial()); in MergeFunctionDecl()
3923 OldMethod->isFunctionTemplateSpecialization() && in MergeFunctionDecl()
3924 NewMethod->isFunctionTemplateSpecialization(); in MergeFunctionDecl()
3925 bool isFriend = NewMethod->getFriendObjectKind(); in MergeFunctionDecl()
3927 if (!isFriend && NewMethod->getLexicalDeclContext()->isRecord() && in MergeFunctionDecl()
3929 // -- Member function declarations with the same name and the in MergeFunctionDecl()
3932 if (OldMethod->isStatic() != NewMethod->isStatic()) { in MergeFunctionDecl()
3933 Diag(New->getLocation(), diag::err_ovl_static_nonstatic_member); in MergeFunctionDecl()
3934 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3940 // member-specification, except that a nested class or member in MergeFunctionDecl()
3953 Diag(New->getLocation(), NewDiag); in MergeFunctionDecl()
3955 Diag(New->getLocation(), diag::err_member_redeclared_in_instantiation) in MergeFunctionDecl()
3956 << New << New->getType(); in MergeFunctionDecl()
3958 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
3966 } else if (OldMethod->isImplicit()) { in MergeFunctionDecl()
3968 NewMethod->setImplicit(); in MergeFunctionDecl()
3970 Diag(NewMethod->getLocation(), in MergeFunctionDecl()
3975 } else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) { in MergeFunctionDecl()
3976 Diag(NewMethod->getLocation(), in MergeFunctionDecl()
3985 // -- Function declarations that differ only in the return type, in MergeFunctionDecl()
4000 if (const auto *NRA = New->getAttr<CXX11NoReturnAttr>()) in MergeFunctionDecl()
4001 if (!Old->hasAttr<CXX11NoReturnAttr>()) { in MergeFunctionDecl()
4002 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl) in MergeFunctionDecl()
4004 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeFunctionDecl()
4009 // carries_dependency attribute for its declarator-id if any declaration in MergeFunctionDecl()
4011 const CarriesDependencyAttr *CDA = New->getAttr<CarriesDependencyAttr>(); in MergeFunctionDecl()
4012 if (CDA && !Old->hasAttr<CarriesDependencyAttr>()) { in MergeFunctionDecl()
4013 Diag(CDA->getLocation(), in MergeFunctionDecl()
4015 Diag(Old->getFirstDecl()->getLocation(), in MergeFunctionDecl()
4021 // return type and the parameter-type-list. in MergeFunctionDecl()
4026 auto *OldType = OldQTypeForComparison->castAs<FunctionProtoType>(); in MergeFunctionDecl()
4042 if (New->getFriendObjectKind() != Decl::FOK_None) { in MergeFunctionDecl()
4043 Diag(New->getLocation(), diag::ext_retained_language_linkage) << New; in MergeFunctionDecl()
4046 Diag(New->getLocation(), diag::err_different_language_linkage) << New; in MergeFunctionDecl()
4054 // CheckEquivalentExceptionSpec, and we don't want follow-on diagnostics in MergeFunctionDecl()
4055 // about incompatible types under -fms-compatibility. in MergeFunctionDecl()
4084 if (Old->hasPrototype() && !New->hasWrittenPrototype() && NewDeclIsDefn && in MergeFunctionDecl()
4085 Old->getNumParams() != New->getNumParams() && !Old->isImplicit()) { in MergeFunctionDecl()
4086 if (Old->hasInheritedPrototype()) in MergeFunctionDecl()
4087 Old = Old->getCanonicalDecl(); in MergeFunctionDecl()
4088 Diag(New->getLocation(), diag::err_conflicting_types) << New; in MergeFunctionDecl()
4089 Diag(Old->getLocation(), PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
4103 if (New->hasWrittenPrototype() != Old->hasWrittenPrototype() && in MergeFunctionDecl()
4104 !New->isImplicit() && !Old->isImplicit()) { in MergeFunctionDecl()
4106 if (New->hasWrittenPrototype()) { in MergeFunctionDecl()
4114 if (WithProto->getNumParams() != 0) { in MergeFunctionDecl()
4115 if (WithoutProto->getBuiltinID() == 0 && !WithoutProto->isImplicit()) { in MergeFunctionDecl()
4117 // warn about that one so long as it's a user-visible declaration. in MergeFunctionDecl()
4123 Diag(WithoutProto->getLocation(), in MergeFunctionDecl()
4125 << IsWithoutProtoADef << (WithoutProto->getNumParams() ? 0 : 1) in MergeFunctionDecl()
4130 // it's a user-visible declaration. There is one exception to this: in MergeFunctionDecl()
4135 if (WithProto->getBuiltinID() == 0 && !WithProto->isImplicit() && in MergeFunctionDecl()
4137 Diag(WithProto->getLocation(), diag::note_conflicting_prototype); in MergeFunctionDecl()
4143 const FunctionType *OldFuncType = OldQType->getAs<FunctionType>(); in MergeFunctionDecl()
4144 const FunctionType *NewFuncType = NewQType->getAs<FunctionType>(); in MergeFunctionDecl()
4150 assert(!OldProto->hasExceptionSpec() && "Exception spec in C"); in MergeFunctionDecl()
4151 NewQType = Context.getFunctionType(NewFuncType->getReturnType(), in MergeFunctionDecl()
4152 OldProto->getParamTypes(), in MergeFunctionDecl()
4153 OldProto->getExtProtoInfo()); in MergeFunctionDecl()
4154 New->setType(NewQType); in MergeFunctionDecl()
4155 New->setHasInheritedPrototype(); in MergeFunctionDecl()
4159 for (const auto &ParamType : OldProto->param_types()) { in MergeFunctionDecl()
4163 Param->setScopeInfo(0, Params.size()); in MergeFunctionDecl()
4164 Param->setImplicit(); in MergeFunctionDecl()
4168 New->setParams(Params); in MergeFunctionDecl()
4187 // If a variadic prototype is followed by a non-variadic K&R definition, in MergeFunctionDecl()
4192 Old->hasPrototype() && !New->hasPrototype() && in MergeFunctionDecl()
4193 New->getType()->getAs<FunctionProtoType>() && in MergeFunctionDecl()
4194 Old->getNumParams() == New->getNumParams()) { in MergeFunctionDecl()
4198 = Old->getType()->getAs<FunctionProtoType>(); in MergeFunctionDecl()
4200 = New->getType()->getAs<FunctionProtoType>(); in MergeFunctionDecl()
4203 QualType MergedReturn = Context.mergeTypes(OldProto->getReturnType(), in MergeFunctionDecl()
4204 NewProto->getReturnType()); in MergeFunctionDecl()
4206 for (unsigned Idx = 0, End = Old->getNumParams(); in MergeFunctionDecl()
4208 ParmVarDecl *OldParm = Old->getParamDecl(Idx); in MergeFunctionDecl()
4209 ParmVarDecl *NewParm = New->getParamDecl(Idx); in MergeFunctionDecl()
4210 if (Context.typesAreCompatible(OldParm->getType(), in MergeFunctionDecl()
4211 NewProto->getParamType(Idx))) { in MergeFunctionDecl()
4212 ArgTypes.push_back(NewParm->getType()); in MergeFunctionDecl()
4213 } else if (Context.typesAreCompatible(OldParm->getType(), in MergeFunctionDecl()
4214 NewParm->getType(), in MergeFunctionDecl()
4217 NewProto->getParamType(Idx) }; in MergeFunctionDecl()
4219 ArgTypes.push_back(NewParm->getType()); in MergeFunctionDecl()
4226 Diag(Warnings[Warn].NewParm->getLocation(), in MergeFunctionDecl()
4229 << Warnings[Warn].OldParm->getType(); in MergeFunctionDecl()
4230 if (Warnings[Warn].OldParm->getLocation().isValid()) in MergeFunctionDecl()
4231 Diag(Warnings[Warn].OldParm->getLocation(), in MergeFunctionDecl()
4236 New->setType(Context.getFunctionType(MergedReturn, ArgTypes, in MergeFunctionDecl()
4237 OldProto->getExtProtoInfo())); in MergeFunctionDecl()
4247 // If the previous declaration was an implicitly-generated builtin in MergeFunctionDecl()
4250 if (Old->isImplicit() && (BuiltinID = Old->getBuiltinID())) { in MergeFunctionDecl()
4251 // If it's actually a library-defined builtin function like 'malloc' in MergeFunctionDecl()
4254 Diag(New->getLocation(), diag::warn_redecl_library_builtin) << New; in MergeFunctionDecl()
4256 << Old << Old->getType(); in MergeFunctionDecl()
4263 Diag(New->getLocation(), diag::err_conflicting_types) << New->getDeclName(); in MergeFunctionDecl()
4264 Diag(OldLocation, PrevDiag) << Old << Old->getType(); in MergeFunctionDecl()
4274 if (Old->isPureVirtual()) in MergeCompatibleFunctionDecls()
4275 New->setIsPureVirtual(); in MergeCompatibleFunctionDecls()
4278 if (Old->getMostRecentDecl()->isUsed(false)) in MergeCompatibleFunctionDecls()
4279 New->setIsUsed(); in MergeCompatibleFunctionDecls()
4283 if (New->getNumParams() == Old->getNumParams()) in MergeCompatibleFunctionDecls()
4284 for (unsigned i = 0, e = New->getNumParams(); i != e; ++i) { in MergeCompatibleFunctionDecls()
4285 ParmVarDecl *NewParam = New->getParamDecl(i); in MergeCompatibleFunctionDecls()
4286 ParmVarDecl *OldParam = Old->getParamDecl(i); in MergeCompatibleFunctionDecls()
4297 QualType Merged = Context.mergeTypes(Old->getType(), New->getType()); in MergeCompatibleFunctionDecls()
4299 New->setType(Merged); in MergeCompatibleFunctionDecls()
4308 isa<ObjCProtocolDecl>(oldMethod->getDeclContext()) in mergeObjCMethodDecls()
4309 ? (oldMethod->isOptional() ? AMK_OptionalProtocolImplementation in mergeObjCMethodDecls()
4311 : isa<ObjCImplDecl>(newMethod->getDeclContext()) ? AMK_Redeclaration in mergeObjCMethodDecls()
4317 ObjCMethodDecl::param_const_iterator oi = oldMethod->param_begin(), in mergeObjCMethodDecls()
4318 oe = oldMethod->param_end(); in mergeObjCMethodDecls()
4320 ni = newMethod->param_begin(), ne = newMethod->param_end(); in mergeObjCMethodDecls()
4328 assert(!S.Context.hasSameType(New->getType(), Old->getType())); in diagnoseVarDeclTypeMismatch()
4330 S.Diag(New->getLocation(), New->isThisDeclarationADefinition() in diagnoseVarDeclTypeMismatch()
4333 << New->getDeclName() << New->getType() << Old->getType(); in diagnoseVarDeclTypeMismatch()
4339 S.Diag(OldLocation, PrevDiag) << Old << Old->getType(); in diagnoseVarDeclTypeMismatch()
4340 New->setInvalidDecl(); in diagnoseVarDeclTypeMismatch()
4345 …if (New->isInvalidDecl() || Old->isInvalidDecl() || New->getType()->containsErrors() || Old->getTy… in MergeVarDeclTypes()
4350 if (New->getType()->isUndeducedType()) { in MergeVarDeclTypes()
4351 // We don't know what the new type is until the initializer is attached. in MergeVarDeclTypes()
4353 } else if (Context.hasSameType(New->getType(), Old->getType())) { in MergeVarDeclTypes()
4362 else if (Old->getType()->isArrayType() && New->getType()->isArrayType()) { in MergeVarDeclTypes()
4363 const ArrayType *OldArray = Context.getAsArrayType(Old->getType()); in MergeVarDeclTypes()
4364 const ArrayType *NewArray = Context.getAsArrayType(New->getType()); in MergeVarDeclTypes()
4369 if (!NewArray->isIncompleteArrayType() && !NewArray->isDependentType()) { in MergeVarDeclTypes()
4370 for (VarDecl *PrevVD = Old->getMostRecentDecl(); PrevVD; in MergeVarDeclTypes()
4371 PrevVD = PrevVD->getPreviousDecl()) { in MergeVarDeclTypes()
4372 QualType PrevVDTy = PrevVD->getType(); in MergeVarDeclTypes()
4373 if (PrevVDTy->isIncompleteArrayType() || PrevVDTy->isDependentType()) in MergeVarDeclTypes()
4376 if (!Context.hasSameType(New->getType(), PrevVDTy)) in MergeVarDeclTypes()
4381 if (OldArray->isIncompleteArrayType() && NewArray->isArrayType()) { in MergeVarDeclTypes()
4382 if (Context.hasSameType(OldArray->getElementType(), in MergeVarDeclTypes()
4383 NewArray->getElementType())) in MergeVarDeclTypes()
4384 MergedT = New->getType(); in MergeVarDeclTypes()
4389 else if (OldArray->isArrayType() && NewArray->isIncompleteArrayType()) { in MergeVarDeclTypes()
4390 if (Context.hasSameType(OldArray->getElementType(), in MergeVarDeclTypes()
4391 NewArray->getElementType())) in MergeVarDeclTypes()
4392 MergedT = Old->getType(); in MergeVarDeclTypes()
4395 else if (New->getType()->isObjCObjectPointerType() && in MergeVarDeclTypes()
4396 Old->getType()->isObjCObjectPointerType()) { in MergeVarDeclTypes()
4397 MergedT = Context.mergeObjCGCQualifiers(New->getType(), in MergeVarDeclTypes()
4398 Old->getType()); in MergeVarDeclTypes()
4404 MergedT = Context.mergeTypes(New->getType(), Old->getType()); in MergeVarDeclTypes()
4408 // block-scope variable. In other cases (static data members of class in MergeVarDeclTypes()
4412 if ((New->getType()->isDependentType() || in MergeVarDeclTypes()
4413 Old->getType()->isDependentType()) && New->isLocalVarDecl()) { in MergeVarDeclTypes()
4417 if (!New->getType()->isDependentType() && MergeTypeWithOld) in MergeVarDeclTypes()
4418 New->setType(Context.DependentTy); in MergeVarDeclTypes()
4427 New->setType(MergedT); in MergeVarDeclTypes()
4448 return NewVD->isPreviousDeclInSameBlockScope() || in mergeTypeWithPrevious()
4449 (!OldVD->getLexicalDeclContext()->isFunctionOrMethod() && in mergeTypeWithPrevious()
4450 !NewVD->getLexicalDeclContext()->isFunctionOrMethod()); in mergeTypeWithPrevious()
4452 // If the old declaration was function-local, don't merge with its in mergeTypeWithPrevious()
4454 return !OldVD->getLexicalDeclContext()->isFunctionOrMethod() || in mergeTypeWithPrevious()
4455 OldVD->getLexicalDeclContext() == NewVD->getLexicalDeclContext(); in mergeTypeWithPrevious()
4461 if (New->isInvalidDecl()) in MergeVarDecl()
4467 VarTemplateDecl *NewTemplate = New->getDescribedVarTemplate(); in MergeVarDecl()
4475 Old = OldTemplate ? OldTemplate->getTemplatedDecl() : nullptr; in MergeVarDecl()
4480 return New->setInvalidDecl(); in MergeVarDecl()
4487 return New->setInvalidDecl(); in MergeVarDecl()
4491 Diag(New->getLocation(), diag::err_redefinition_different_kind) in MergeVarDecl()
4492 << New->getDeclName(); in MergeVarDecl()
4494 New->getLocation()); in MergeVarDecl()
4495 return New->setInvalidDecl(); in MergeVarDecl()
4504 !TemplateParameterListsAreEqual(NewTemplate->getTemplateParameters(), in MergeVarDecl()
4505 OldTemplate->getTemplateParameters(), in MergeVarDecl()
4507 return New->setInvalidDecl(); in MergeVarDecl()
4510 // A member shall not be declared twice in the member-specification [...] in MergeVarDecl()
4513 if (Old->isStaticDataMember() && !New->isOutOfLine()) { in MergeVarDecl()
4514 Diag(New->getLocation(), diag::err_duplicate_member) in MergeVarDecl()
4515 << New->getIdentifier(); in MergeVarDecl()
4516 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeVarDecl()
4517 New->setInvalidDecl(); in MergeVarDecl()
4521 // Warn if an already-defined variable is made a weak_import in a subsequent in MergeVarDecl()
4523 if (New->hasAttr<WeakImportAttr>()) in MergeVarDecl()
4524 for (auto *D = Old; D; D = D->getPreviousDecl()) { in MergeVarDecl()
4525 if (D->isThisDeclarationADefinition() != VarDecl::DeclarationOnly) { in MergeVarDecl()
4526 Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName(); in MergeVarDecl()
4527 Diag(D->getLocation(), diag::note_previous_definition); in MergeVarDecl()
4529 New->dropAttr<WeakImportAttr>(); in MergeVarDecl()
4534 if (const auto *ILA = New->getAttr<InternalLinkageAttr>()) in MergeVarDecl()
4535 if (!Old->hasAttr<InternalLinkageAttr>()) { in MergeVarDecl()
4536 Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl) in MergeVarDecl()
4538 Diag(Old->getLocation(), diag::note_previous_declaration); in MergeVarDecl()
4539 New->dropAttr<InternalLinkageAttr>(); in MergeVarDecl()
4543 VarDecl *MostRecent = Old->getMostRecentDecl(); in MergeVarDecl()
4547 if (New->isInvalidDecl()) in MergeVarDecl()
4552 if (New->isInvalidDecl()) in MergeVarDecl()
4560 // [dcl.stc]p8: Check if we have a non-static decl followed by a static. in MergeVarDecl()
4561 if (New->getStorageClass() == SC_Static && in MergeVarDecl()
4562 !New->isStaticDataMember() && in MergeVarDecl()
4563 Old->hasExternalFormalLinkage()) { in MergeVarDecl()
4565 Diag(New->getLocation(), diag::ext_static_non_static) in MergeVarDecl()
4566 << New->getDeclName(); in MergeVarDecl()
4569 Diag(New->getLocation(), diag::err_static_non_static) in MergeVarDecl()
4570 << New->getDeclName(); in MergeVarDecl()
4572 return New->setInvalidDecl(); in MergeVarDecl()
4576 // For an identifier declared with the storage-class specifier in MergeVarDecl()
4584 if (New->hasExternalStorage() && Old->hasLinkage()) in MergeVarDecl()
4586 else if (New->getCanonicalDecl()->getStorageClass() != SC_Static && in MergeVarDecl()
4587 !New->isStaticDataMember() && in MergeVarDecl()
4588 Old->getCanonicalDecl()->getStorageClass() == SC_Static) { in MergeVarDecl()
4589 Diag(New->getLocation(), diag::err_non_static_static) << New->getDeclName(); in MergeVarDecl()
4591 return New->setInvalidDecl(); in MergeVarDecl()
4594 // Check if extern is followed by non-extern and vice-versa. in MergeVarDecl()
4595 if (New->hasExternalStorage() && in MergeVarDecl()
4596 !Old->hasLinkage() && Old->isLocalVarDeclOrParm()) { in MergeVarDecl()
4597 Diag(New->getLocation(), diag::err_extern_non_extern) << New->getDeclName(); in MergeVarDecl()
4599 return New->setInvalidDecl(); in MergeVarDecl()
4601 if (Old->hasLinkage() && New->isLocalVarDeclOrParm() && in MergeVarDecl()
4602 !New->hasExternalStorage()) { in MergeVarDecl()
4603 Diag(New->getLocation(), diag::err_non_extern_extern) << New->getDeclName(); in MergeVarDecl()
4605 return New->setInvalidDecl(); in MergeVarDecl()
4615 if (!New->hasExternalStorage() && !New->isFileVarDecl() && in MergeVarDecl()
4616 // Don't complain about out-of-line definitions of static members. in MergeVarDecl()
4617 !(Old->getLexicalDeclContext()->isRecord() && in MergeVarDecl()
4618 !New->getLexicalDeclContext()->isRecord())) { in MergeVarDecl()
4619 Diag(New->getLocation(), diag::err_redefinition) << New->getDeclName(); in MergeVarDecl()
4621 return New->setInvalidDecl(); in MergeVarDecl()
4624 if (New->isInline() && !Old->getMostRecentDecl()->isInline()) { in MergeVarDecl()
4625 if (VarDecl *Def = Old->getDefinition()) { in MergeVarDecl()
4628 // its first declaration as inline, the program is ill-formed. in MergeVarDecl()
4629 Diag(New->getLocation(), diag::err_inline_decl_follows_def) << New; in MergeVarDecl()
4630 Diag(Def->getLocation(), diag::note_previous_definition); in MergeVarDecl()
4636 if (!Old->isInline() && New->isInline() && Old->isUsed(false) && in MergeVarDecl()
4637 !Old->getDefinition() && !New->isThisDeclarationADefinition()) in MergeVarDecl()
4638 UndefinedButUsed.insert(std::make_pair(Old->getCanonicalDecl(), in MergeVarDecl()
4641 if (New->getTLSKind() != Old->getTLSKind()) { in MergeVarDecl()
4642 if (!Old->getTLSKind()) { in MergeVarDecl()
4643 Diag(New->getLocation(), diag::err_thread_non_thread) << New->getDeclName(); in MergeVarDecl()
4645 } else if (!New->getTLSKind()) { in MergeVarDecl()
4646 Diag(New->getLocation(), diag::err_non_thread_thread) << New->getDeclName(); in MergeVarDecl()
4653 Diag(New->getLocation(), diag::err_thread_thread_different_kind) in MergeVarDecl()
4654 << New->getDeclName() << (New->getTLSKind() == VarDecl::TLS_Dynamic); in MergeVarDecl()
4661 if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() && in MergeVarDecl()
4662 Old->getCanonicalDecl()->isConstexpr()) { in MergeVarDecl()
4664 Diag(New->getLocation(), in MergeVarDecl()
4666 } else if (New->isThisDeclarationADefinition() == VarDecl::Definition) { in MergeVarDecl()
4667 VarDecl *Def = Old->getDefinition(); in MergeVarDecl()
4674 Diag(New->getLocation(), diag::err_different_language_linkage) << New; in MergeVarDecl()
4676 New->setInvalidDecl(); in MergeVarDecl()
4681 if (Old->getMostRecentDecl()->isUsed(false)) in MergeVarDecl()
4682 New->setIsUsed(); in MergeVarDecl()
4685 New->setPreviousDecl(Old); in MergeVarDecl()
4687 NewTemplate->setPreviousDecl(OldTemplate); in MergeVarDecl()
4690 New->setAccess(Old->getAccess()); in MergeVarDecl()
4692 NewTemplate->setAccess(New->getAccess()); in MergeVarDecl()
4694 if (Old->isInline()) in MergeVarDecl()
4695 New->setImplicitlyInline(); in MergeVarDecl()
4701 auto FOldDecLoc = SrcMgr.getDecomposedLoc(Old->getLocation()); in notePreviousDefinition()
4706 SrcMgr.getFilename(SrcMgr.getSpellingLoc(Old->getLocation())); in notePreviousDefinition()
4709 SourceLocation IncLoc) -> bool { in notePreviousDefinition()
4711 // headers, example: a non-modular header H in module A that also gets in notePreviousDefinition()
4717 << HdrFilename.str() << Mod->getFullModuleName(); in notePreviousDefinition()
4718 if (!Mod->DefinitionLoc.isInvalid()) in notePreviousDefinition()
4719 Diag(Mod->DefinitionLoc, diag::note_defined_here) in notePreviousDefinition()
4720 << Mod->getFullModuleName(); in notePreviousDefinition()
4737 noteFromModuleOrInclude(Old->getOwningModule(), OldIncLoc); in notePreviousDefinition()
4742 Diag(Old->getLocation(), diag::note_use_ifdef_guards); in notePreviousDefinition()
4749 if (Old->getLocation().isValid()) in notePreviousDefinition()
4750 Diag(Old->getLocation(), diag::note_previous_definition); in notePreviousDefinition()
4755 (New->getFormalLinkage() == Linkage::Internal || New->isInline() || in checkVarDeclRedefinition()
4757 New->getDescribedVarTemplate() || New->getNumTemplateParameterLists() || in checkVarDeclRedefinition()
4758 New->getDeclContext()->isDependentContext())) { in checkVarDeclRedefinition()
4761 New->demoteThisDefinitionToDeclaration(); in checkVarDeclRedefinition()
4764 if (auto *OldTD = Old->getDescribedVarTemplate()) in checkVarDeclRedefinition()
4769 Diag(New->getLocation(), diag::err_redefinition) << New; in checkVarDeclRedefinition()
4770 notePreviousDefinition(Old, New->getLocation()); in checkVarDeclRedefinition()
4771 New->setInvalidDecl(); in checkVarDeclRedefinition()
4792 ? S->getMSCurManglingNumber() in getMSManglingNumber()
4793 : S->getMSLastManglingNumber(); in getMSManglingNumber()
4800 if (isa<CXXRecordDecl>(Tag->getParent())) { in handleTagNumbering()
4803 if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl()) in handleTagNumbering()
4806 Context.getManglingNumberContext(Tag->getParent()); in handleTagNumbering()
4817 getCurrentMangleNumberContext(Tag->getDeclContext()); in handleTagNumbering()
4820 Tag, MCtx->getManglingNumber( in handleTagNumbering()
4842 /// Determine whether a class is C-like, according to the rules of C++
4845 if (RD->isInvalidDecl()) in getNonCLikeKindForAnonymousStruct()
4851 // -- have any base classes in getNonCLikeKindForAnonymousStruct()
4852 if (RD->getNumBases()) in getNonCLikeKindForAnonymousStruct()
4854 SourceRange(RD->bases_begin()->getBeginLoc(), in getNonCLikeKindForAnonymousStruct()
4855 RD->bases_end()[-1].getEndLoc())}; in getNonCLikeKindForAnonymousStruct()
4857 for (Decl *D : RD->decls()) { in getNonCLikeKindForAnonymousStruct()
4859 if (D->isInvalidDecl()) { in getNonCLikeKindForAnonymousStruct()
4864 // -- have any [...] default member initializers in getNonCLikeKindForAnonymousStruct()
4866 if (FD->hasInClassInitializer()) { in getNonCLikeKindForAnonymousStruct()
4867 auto *Init = FD->getInClassInitializer(); in getNonCLikeKindForAnonymousStruct()
4869 Init ? Init->getSourceRange() : D->getSourceRange()}; in getNonCLikeKindForAnonymousStruct()
4877 return {NonCLikeKind::Friend, D->getSourceRange()}; in getNonCLikeKindForAnonymousStruct()
4879 // -- declare any members other than non-static data members, member in getNonCLikeKindForAnonymousStruct()
4886 if (D->isImplicit()) in getNonCLikeKindForAnonymousStruct()
4888 return {NonCLikeKind::OtherMember, D->getSourceRange()}; in getNonCLikeKindForAnonymousStruct()
4891 // -- contain a lambda-expression, in getNonCLikeKindForAnonymousStruct()
4892 if (MemberRD->isLambda()) in getNonCLikeKindForAnonymousStruct()
4893 return {NonCLikeKind::Lambda, MemberRD->getSourceRange()}; in getNonCLikeKindForAnonymousStruct()
4897 if (MemberRD->isThisDeclarationADefinition()) { in getNonCLikeKindForAnonymousStruct()
4908 if (TagFromDeclSpec->isInvalidDecl()) in setTagNameForLinkagePurposes()
4912 if (TagFromDeclSpec->hasNameForLinkage()) in setTagNameForLinkagePurposes()
4915 // A well-formed anonymous tag must always be a TagUseKind::Definition. in setTagNameForLinkagePurposes()
4916 assert(TagFromDeclSpec->isThisDeclarationADefinition()); in setTagNameForLinkagePurposes()
4919 if (!Context.hasSameType(NewTD->getUnderlyingType(), in setTagNameForLinkagePurposes()
4928 // C-like]. in setTagNameForLinkagePurposes()
4936 bool ChangesLinkage = TagFromDeclSpec->hasLinkageBeenComputed(); in setTagNameForLinkagePurposes()
4951 getLocForEndOfToken(TagFromDeclSpec->getInnerLocStart()); in setTagNameForLinkagePurposes()
4954 TextToInsert += NewTD->getIdentifier()->getName(); in setTagNameForLinkagePurposes()
4961 << NonCLike.Kind - 1 << NonCLike.Range; in setTagNameForLinkagePurposes()
4963 Diag(NewTD->getLocation(), diag::note_typedef_for_linkage_here) in setTagNameForLinkagePurposes()
4970 // Otherwise, set this as the anon-decl typedef for the tag. in setTagNameForLinkagePurposes()
4971 TagFromDeclSpec->setTypedefNameForAnonDecl(NewTD); in setTagNameForLinkagePurposes()
4987 if (ED->isScopedUsingClassTag()) in GetDiagnosticTypeSpecifierID()
4989 if (ED->isScoped()) in GetDiagnosticTypeSpecifierID()
5022 Tag = CTD->getTemplatedDecl(); in ParsedFreeStandingDeclSpec()
5027 Tag->setFreeStanding(); in ParsedFreeStandingDeclSpec()
5028 if (Tag->isInvalidDecl()) in ParsedFreeStandingDeclSpec()
5034 // or incomplete types shall not be restrict-qualified." in ParsedFreeStandingDeclSpec()
5073 // Track whether this decl-specifier declares anything. in ParsedFreeStandingDeclSpec()
5078 if (!Record->getDeclName() && Record->isCompleteDefinition() && in ParsedFreeStandingDeclSpec()
5081 Record->getDeclContext()->isRecord()) { in ParsedFreeStandingDeclSpec()
5089 if (CurContext->isFunctionOrMethod()) in ParsedFreeStandingDeclSpec()
5100 // A struct-declaration that does not declare an anonymous structure or in ParsedFreeStandingDeclSpec()
5101 // anonymous union shall contain a struct-declarator-list. in ParsedFreeStandingDeclSpec()
5103 // This rule also existed in C89 and C99; the grammar for struct-declaration in ParsedFreeStandingDeclSpec()
5104 // did not permit a struct-declaration without a struct-declarator-list. in ParsedFreeStandingDeclSpec()
5105 if (!getLangOpts().CPlusPlus && CurContext->isRecord() && in ParsedFreeStandingDeclSpec()
5112 // STRUCT_TYPE; <- where STRUCT_TYPE is a typedef struct. in ParsedFreeStandingDeclSpec()
5113 // UNION_TYPE; <- where UNION_TYPE is a typedef union. in ParsedFreeStandingDeclSpec()
5114 if ((Tag && Tag->getDeclName()) || in ParsedFreeStandingDeclSpec()
5120 DS.getRepAsType().get()->getAsStructureType()) in ParsedFreeStandingDeclSpec()
5121 Record = RT->getDecl(); in ParsedFreeStandingDeclSpec()
5122 else if (const RecordType *UT = DS.getRepAsType().get()->getAsUnionType()) in ParsedFreeStandingDeclSpec()
5123 Record = UT->getDecl(); in ParsedFreeStandingDeclSpec()
5127 << Record->isUnion() << DS.getSourceRange(); in ParsedFreeStandingDeclSpec()
5137 (TagD && TagD->isInvalidDecl())) in ParsedFreeStandingDeclSpec()
5143 if (Enum->enumerator_begin() == Enum->enumerator_end() && in ParsedFreeStandingDeclSpec()
5144 !Enum->getIdentifier() && !Enum->isInvalidDecl()) in ParsedFreeStandingDeclSpec()
5157 Tag && Tag->getDeclContext()->isFunctionOrMethod()) in ParsedFreeStandingDeclSpec()
5159 << llvm::to_underlying(Tag->getTagKind()) in ParsedFreeStandingDeclSpec()
5169 // unnamed bit-field, the decl-specifier-seq shall introduce one or more in ParsedFreeStandingDeclSpec()
5183 // If a storage-class-specifier appears in a decl-specifier-seq, [...] the in ParsedFreeStandingDeclSpec()
5184 // init-declarator-list of the declaration shall not be empty. in ParsedFreeStandingDeclSpec()
5186 // If a cv-qualifier appears in a decl-specifier-seq, the in ParsedFreeStandingDeclSpec()
5187 // init-declarator-list of the declaration shall not be empty. in ParsedFreeStandingDeclSpec()
5194 // Note that a linkage-specification sets a storage class, but in ParsedFreeStandingDeclSpec()
5263 Owner->isRecord() ? Sema::LookupMemberName in CheckAnonMemberRedeclaration()
5269 NamedDecl *PrevDecl = R.getRepresentativeDecl()->getUnderlyingDecl(); in CheckAnonMemberRedeclaration()
5270 assert(PrevDecl && "Expected a non-null Decl"); in CheckAnonMemberRedeclaration()
5276 PrevDecl->isPlaceholderVar(SemaRef.getLangOpts()) && in CheckAnonMemberRedeclaration()
5277 (Owner->isFunctionOrMethod() || Owner->isRecord())) { in CheckAnonMemberRedeclaration()
5278 if (!Owner->isRecord()) in CheckAnonMemberRedeclaration()
5285 SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in CheckAnonMemberRedeclaration()
5301 if (Record->isAnonymousStructOrUnion()) in DiagPlaceholderFieldDeclDefinitions()
5305 for (const Decl *D : Record->decls()) { in DiagPlaceholderFieldDeclDefinitions()
5307 if (!ND || !ND->isPlaceholderVar(getLangOpts())) in DiagPlaceholderFieldDeclDefinitions()
5312 DiagPlaceholderVariableDefinition(ND->getLocation()); in DiagPlaceholderFieldDeclDefinitions()
5316 /// InjectAnonymousStructOrUnionMembers - Inject the members of the
5340 for (auto *D : AnonRecord->decls()) { in InjectAnonymousStructOrUnionMembers()
5342 cast<NamedDecl>(D)->getDeclName()) { in InjectAnonymousStructOrUnionMembers()
5344 if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(), in InjectAnonymousStructOrUnionMembers()
5345 VD->getLocation(), AnonRecord->isUnion(), in InjectAnonymousStructOrUnionMembers()
5360 Chaining.append(IF->chain_begin(), IF->chain_end()); in InjectAnonymousStructOrUnionMembers()
5371 SemaRef.Context, Owner, VD->getLocation(), VD->getIdentifier(), in InjectAnonymousStructOrUnionMembers()
5372 VD->getType(), {NamedChain, Chaining.size()}); in InjectAnonymousStructOrUnionMembers()
5374 for (const auto *Attr : VD->attrs()) in InjectAnonymousStructOrUnionMembers()
5375 IndirectField->addAttr(Attr->clone(SemaRef.Context)); in InjectAnonymousStructOrUnionMembers()
5377 IndirectField->setAccess(AS); in InjectAnonymousStructOrUnionMembers()
5378 IndirectField->setImplicit(); in InjectAnonymousStructOrUnionMembers()
5382 if (AS != AS_none) IndirectField->setAccess(AS); in InjectAnonymousStructOrUnionMembers()
5392 /// StorageClassSpecToVarDeclStorageClass - Maps a DeclSpec::SCS to
5418 assert(Record->hasInClassInitializer()); in findDefaultInitializer()
5420 for (const auto *I : Record->decls()) { in findDefaultInitializer()
5423 FD = IFD->getAnonField(); in findDefaultInitializer()
5424 if (FD && FD->hasInClassInitializer()) in findDefaultInitializer()
5425 return FD->getLocation(); in findDefaultInitializer()
5428 llvm_unreachable("couldn't find in-class initializer"); in findDefaultInitializer()
5433 if (!Parent->isUnion() || !Parent->hasInClassInitializer()) in checkDuplicateDefaultInit()
5442 if (!Parent->isUnion() || !Parent->hasInClassInitializer()) in checkDuplicateDefaultInit()
5452 DeclContext *Owner = Record->getDeclContext(); in BuildAnonymousStructOrUnion()
5455 if (Record->isUnion() && !getLangOpts().CPlusPlus && !getLangOpts().C11) in BuildAnonymousStructOrUnion()
5456 Diag(Record->getLocation(), diag::ext_anonymous_union); in BuildAnonymousStructOrUnion()
5457 else if (!Record->isUnion() && getLangOpts().CPlusPlus) in BuildAnonymousStructOrUnion()
5458 Diag(Record->getLocation(), diag::ext_gnu_anonymous_struct); in BuildAnonymousStructOrUnion()
5459 else if (!Record->isUnion() && !getLangOpts().C11) in BuildAnonymousStructOrUnion()
5460 Diag(Record->getLocation(), diag::ext_c11_anonymous_struct); in BuildAnonymousStructOrUnion()
5467 if (Record->isUnion()) { in BuildAnonymousStructOrUnion()
5473 DeclContext *OwnerScope = Owner->getRedeclContext(); in BuildAnonymousStructOrUnion()
5475 (OwnerScope->isTranslationUnit() || in BuildAnonymousStructOrUnion()
5476 (OwnerScope->isNamespace() && in BuildAnonymousStructOrUnion()
5477 !cast<NamespaceDecl>(OwnerScope)->isAnonymousNamespace()))) { in BuildAnonymousStructOrUnion()
5478 Diag(Record->getLocation(), diag::err_anonymous_union_not_static) in BuildAnonymousStructOrUnion()
5479 << FixItHint::CreateInsertion(Record->getLocation(), "static "); in BuildAnonymousStructOrUnion()
5505 << Record->isUnion() << "const" in BuildAnonymousStructOrUnion()
5510 << Record->isUnion() << "volatile" in BuildAnonymousStructOrUnion()
5515 << Record->isUnion() << "restrict" in BuildAnonymousStructOrUnion()
5520 << Record->isUnion() << "_Atomic" in BuildAnonymousStructOrUnion()
5525 << Record->isUnion() << "__unaligned" in BuildAnonymousStructOrUnion()
5532 // The member-specification of an anonymous union shall only in BuildAnonymousStructOrUnion()
5533 // define non-static data members. [Note: nested types and in BuildAnonymousStructOrUnion()
5535 for (auto *Mem : Record->decls()) { in BuildAnonymousStructOrUnion()
5537 if (Mem->isInvalidDecl()) in BuildAnonymousStructOrUnion()
5544 assert(FD->getAccess() != AS_none); in BuildAnonymousStructOrUnion()
5545 if (FD->getAccess() != AS_public) { in BuildAnonymousStructOrUnion()
5546 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member) in BuildAnonymousStructOrUnion()
5547 << Record->isUnion() << (FD->getAccess() == AS_protected); in BuildAnonymousStructOrUnion()
5552 // An object of a class with a non-trivial constructor, a non-trivial in BuildAnonymousStructOrUnion()
5553 // copy constructor, a non-trivial destructor, or a non-trivial copy in BuildAnonymousStructOrUnion()
5558 } else if (Mem->isImplicit()) { in BuildAnonymousStructOrUnion()
5560 } else if (isa<TagDecl>(Mem) && Mem->getDeclContext() != Record) { in BuildAnonymousStructOrUnion()
5562 // elaborated-type-specifier inside the anonymous struct or in BuildAnonymousStructOrUnion()
5566 if (!MemRecord->isAnonymousStructOrUnion() && in BuildAnonymousStructOrUnion()
5567 MemRecord->getDeclName()) { in BuildAnonymousStructOrUnion()
5570 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
5571 << Record->isUnion(); in BuildAnonymousStructOrUnion()
5574 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
5575 << Record->isUnion(); in BuildAnonymousStructOrUnion()
5582 Diag(MemRecord->getLocation(), in BuildAnonymousStructOrUnion()
5584 << Record->isUnion(); in BuildAnonymousStructOrUnion()
5591 // We have something that isn't a non-static data in BuildAnonymousStructOrUnion()
5604 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type) in BuildAnonymousStructOrUnion()
5605 << Record->isUnion(); in BuildAnonymousStructOrUnion()
5607 Diag(Mem->getLocation(), DK) << Record->isUnion(); in BuildAnonymousStructOrUnion()
5615 // brace-or-equal-initializer. in BuildAnonymousStructOrUnion()
5616 if (cast<CXXRecordDecl>(Record)->hasInClassInitializer() && in BuildAnonymousStructOrUnion()
5617 Owner->isRecord()) in BuildAnonymousStructOrUnion()
5622 if (!Record->isUnion() && !Owner->isRecord()) { in BuildAnonymousStructOrUnion()
5623 Diag(Record->getLocation(), diag::err_anonymous_struct_not_member) in BuildAnonymousStructOrUnion()
5630 // unnamed bit-field, the decl-specifier-seq shall introduce one or more in BuildAnonymousStructOrUnion()
5633 // each such member-declaration shall either declare at least one member in BuildAnonymousStructOrUnion()
5634 // name of the class or declare at least one unnamed bit-field in BuildAnonymousStructOrUnion()
5637 if (getLangOpts().CPlusPlus && Record->field_empty()) in BuildAnonymousStructOrUnion()
5650 Context, OwningClass, DS.getBeginLoc(), Record->getLocation(), in BuildAnonymousStructOrUnion()
5654 Anon->setAccess(AS); in BuildAnonymousStructOrUnion()
5658 FieldCollector->Add(cast<FieldDecl>(Anon)); in BuildAnonymousStructOrUnion()
5662 // mutable can only appear on non-static class members, so it's always in BuildAnonymousStructOrUnion()
5664 Diag(Record->getLocation(), diag::err_mutable_nonmember); in BuildAnonymousStructOrUnion()
5670 Record->getLocation(), /*IdentifierInfo=*/nullptr, in BuildAnonymousStructOrUnion()
5673 Anon->setInvalidDecl(); in BuildAnonymousStructOrUnion()
5677 // Default-initialize the implicit variable. This initialization will be in BuildAnonymousStructOrUnion()
5678 // trivial in almost all cases, except if a union member has an in-class in BuildAnonymousStructOrUnion()
5683 Anon->setImplicit(); in BuildAnonymousStructOrUnion()
5686 Record->setAnonymousStructOrUnion(true); in BuildAnonymousStructOrUnion()
5691 Owner->addDecl(Anon); in BuildAnonymousStructOrUnion()
5704 if (getLangOpts().CPlusPlus && NewVD->isStaticLocal()) { in BuildAnonymousStructOrUnion()
5708 getCurrentMangleNumberContext(NewVD->getDeclContext()); in BuildAnonymousStructOrUnion()
5711 NewVD, MCtx->getManglingNumber( in BuildAnonymousStructOrUnion()
5713 Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); in BuildAnonymousStructOrUnion()
5719 Anon->setInvalidDecl(); in BuildAnonymousStructOrUnion()
5742 Anon->setImplicit(); in BuildMicrosoftCAnonymousStruct()
5745 CurContext->addDecl(Anon); in BuildMicrosoftCAnonymousStruct()
5753 RecordDecl *RecordDef = Record->getDefinition(); in BuildMicrosoftCAnonymousStruct()
5754 if (RequireCompleteSizedType(Anon->getLocation(), RecTy, in BuildMicrosoftCAnonymousStruct()
5759 Anon->setInvalidDecl(); in BuildMicrosoftCAnonymousStruct()
5760 ParentDecl->setInvalidDecl(); in BuildMicrosoftCAnonymousStruct()
5784 // The simple-template-id shall name a class template specialization. in GetNameFromUnqualifiedId()
5785 // The template-name shall be the same identifier as the template-name in GetNameFromUnqualifiedId()
5786 // of the simple-template-id. in GetNameFromUnqualifiedId()
5787 // These together intend to imply that the template-name shall name a in GetNameFromUnqualifiedId()
5791 // Y(int) -> Y<int>; in GetNameFromUnqualifiedId()
5845 // In well-formed code, we can only have a constructor in GetNameFromUnqualifiedId()
5846 // template-id that refers to the current context, so go there in GetNameFromUnqualifiedId()
5849 if (!CurClass || CurClass->getIdentifier() != Name.TemplateId->Name) in GetNameFromUnqualifiedId()
5855 // FIXME: Check two things: that the template-id names the same type as in GetNameFromUnqualifiedId()
5856 // CurClassType, and that the template-id does not occur when the name in GetNameFromUnqualifiedId()
5878 TemplateName TName = Name.TemplateId->Template.get(); in GetNameFromUnqualifiedId()
5879 SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc; in GetNameFromUnqualifiedId()
5890 if (Ty->isPointerType() || Ty->isReferenceType()) in getCoreType()
5891 Ty = Ty->getPointeeType(); in getCoreType()
5892 else if (Ty->isArrayType()) in getCoreType()
5893 Ty = Ty->castAsArrayTypeUnsafe()->getElementType(); in getCoreType()
5899 /// hasSimilarParameters - Determine whether the C++ functions Declaration
5901 /// used to improve diagnostics in the case where an out-of-line function
5911 if (Declaration->param_size() != Definition->param_size()) in hasSimilarParameters()
5913 for (unsigned Idx = 0; Idx < Declaration->param_size(); ++Idx) { in hasSimilarParameters()
5914 QualType DeclParamTy = Declaration->getParamDecl(Idx)->getType(); in hasSimilarParameters()
5915 QualType DefParamTy = Definition->getParamDecl(Idx)->getType(); in hasSimilarParameters()
5936 /// RebuildDeclaratorInCurrentInstantiation - Checks whether the given
5940 /// and the base type in any member-pointer chunks.
5944 // - typenames, typeofs, and decltypes in RebuildDeclaratorInCurrentInstantiation()
5945 // - types which will become injected class names in RebuildDeclaratorInCurrentInstantiation()
5961 if (T.isNull() || !T->isInstantiationDependentType()) break; in RebuildDeclaratorInCurrentInstantiation()
5965 // attached already. in RebuildDeclaratorInCurrentInstantiation()
5974 ParsedType LocType = S.CreateParsedType(TSI->getType(), TSI); in RebuildDeclaratorInCurrentInstantiation()
6004 // Rebuild the scope specifier in-place. in RebuildDeclaratorInCurrentInstantiation()
6016 return SM.isInSystemHeader(D->getLocation()) || in isFromSystemHeader()
6017 SM.isInSystemMacro(D->getLocation()); in isFromSystemHeader()
6023 if (D->getPreviousDecl() || D->isImplicit()) in warnOnReservedIdentifier()
6025 ReservedIdentifierStatus Status = D->isReserved(getLangOpts()); in warnOnReservedIdentifier()
6028 Diag(D->getLocation(), diag::warn_reserved_extern_symbol) in warnOnReservedIdentifier()
6040 if (OpenMP().getOMPTraitInfoForSurroundingScope()->isExtensionActive( in ActOnDeclarator()
6048 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer() && in ActOnDeclarator()
6049 Dcl && Dcl->getDeclContext()->isFileContext()) in ActOnDeclarator()
6050 Dcl->setTopLevelDeclInObjCContainer(); in ActOnDeclarator()
6064 while (Record && Record->isAnonymousStructOrUnion()) in DiagnoseClassNameShadow()
6065 Record = dyn_cast<CXXRecordDecl>(Record->getParent()); in DiagnoseClassNameShadow()
6066 if (Record && Record->getIdentifier() && Record->getDeclName() == Name) { in DiagnoseClassNameShadow()
6080 "without nested-name-specifier"); in diagnoseQualifiedDeclaration()
6083 Cur = Cur->getParent(); in diagnoseQualifiedDeclaration()
6092 // Note, it was once ill-formed to give redundant qualification in all in diagnoseQualifiedDeclaration()
6094 if (Cur->Equals(DC)) { in diagnoseQualifiedDeclaration()
6095 if (Cur->isRecord()) { in diagnoseQualifiedDeclaration()
6107 // declaration. For a template-id, we perform the checks in in diagnoseQualifiedDeclaration()
6109 if (!Cur->Encloses(DC) && !(TemplateId || IsMemberSpecialization)) { in diagnoseQualifiedDeclaration()
6110 if (Cur->isRecord()) in diagnoseQualifiedDeclaration()
6137 if (Cur->isRecord()) { in diagnoseQualifiedDeclaration()
6157 // nested-name-specifier. in diagnoseQualifiedDeclaration()
6159 // First check the template-id (if any), and then check each component of the in diagnoseQualifiedDeclaration()
6160 // nested-name-specifier in reverse order. in diagnoseQualifiedDeclaration()
6162 // FIXME: nested-name-specifiers in friend declarations are declarative, in diagnoseQualifiedDeclaration()
6164 if (TemplateId && TemplateId->TemplateKWLoc.isValid()) in diagnoseQualifiedDeclaration()
6166 << FixItHint::CreateRemoval(TemplateId->TemplateKWLoc); in diagnoseQualifiedDeclaration()
6170 if (SpecLoc.getNestedNameSpecifier()->getKind() == in diagnoseQualifiedDeclaration()
6176 if (const Type *T = SpecLoc.getNestedNameSpecifier()->getAsType()) { in diagnoseQualifiedDeclaration()
6177 if (const auto *TST = T->getAsAdjusted<TemplateSpecializationType>()) { in diagnoseQualifiedDeclaration()
6179 // [...] If a nested-name-specifier N is declarative and has a in diagnoseQualifiedDeclaration()
6180 // simple-template-id with a template argument list A that involves a in diagnoseQualifiedDeclaration()
6183 if (TST->isDependentType() && TST->isTypeAlias()) in diagnoseQualifiedDeclaration()
6186 } else if (T->isDecltypeType() || T->getAsAdjusted<PackIndexingType>()) { in diagnoseQualifiedDeclaration()
6188 // [...] A declarative nested-name-specifier shall not have a in diagnoseQualifiedDeclaration()
6189 // computed-type-specifier. in diagnoseQualifiedDeclaration()
6191 // CWG2858 changed this from 'decltype-specifier' to in diagnoseQualifiedDeclaration()
6192 // 'computed-type-specifier'. in diagnoseQualifiedDeclaration()
6194 << T->isDecltypeType() << SpecLoc.getTypeLoc().getSourceRange(); in diagnoseQualifiedDeclaration()
6241 bool IsDependentContext = DC->isDependentContext(); in HandleDeclarator()
6248 if (isa<CXXRecordDecl>(DC) && !cast<CXXRecordDecl>(DC)->hasDefinition()) { in HandleDeclarator()
6262 if (DC->isRecord()) in HandleDeclarator()
6280 QualType R = TInfo->getType(); in HandleDeclarator()
6296 // linkage (C99 6.2.2p4-5 and C++ [basic.link]p6). in HandleDeclarator()
6303 else if (CurContext->isFunctionOrMethod() && in HandleDeclarator()
6305 R->isFunctionType())) { in HandleDeclarator()
6308 CurContext->getEnclosingNamespaceContext()->isTranslationUnit(); in HandleDeclarator()
6309 } else if (CurContext->getRedeclContext()->isTranslationUnit() && in HandleDeclarator()
6324 // When the declarator-id is qualified, the declaration shall refer to a in HandleDeclarator()
6339 // void X::f(int) { } // ill-formed in HandleDeclarator()
6349 TPD && TPD->isTemplateParameter()) { in HandleDeclarator()
6352 // purposes we detect such cases and issue a default-to-error warning that in HandleDeclarator()
6353 // can be disabled with -Wno-strict-primary-template-shadow. in HandleDeclarator()
6356 if (Scope *DeclParent = S->getDeclParent(); in HandleDeclarator()
6357 Scope *TemplateParamParent = S->getTemplateParamParent()) { in HandleDeclarator()
6358 AllowForCompatibility = DeclParent->Contains(*TemplateParamParent) && in HandleDeclarator()
6359 TemplateParamParent->isDeclScope(TPD); in HandleDeclarator()
6369 if (!R->isFunctionType() && DiagnoseClassNameShadow(DC, NameInfo)) in HandleDeclarator()
6370 // Forget that the previous declaration is the injected-class-name. in HandleDeclarator()
6379 (TemplateParamLists.size() == 0 || R->isFunctionType())) in HandleDeclarator()
6388 S = S->getDeclParent(); in HandleDeclarator()
6400 } else if (R->isFunctionType()) { in HandleDeclarator()
6414 if (New->getDeclName() && AddToScope) in HandleDeclarator()
6437 if (T->isDependentType()) in TryToFixInvalidVariablyModifiedType()
6444 QualType Pointee = PTy->getPointeeType(); in TryToFixInvalidVariablyModifiedType()
6453 QualType Inner = PTy->getInnerType(); in TryToFixInvalidVariablyModifiedType()
6466 QualType ElemTy = VLATy->getElementType(); in TryToFixInvalidVariablyModifiedType()
6467 if (ElemTy->isVariablyModifiedType()) { in TryToFixInvalidVariablyModifiedType()
6475 if (!VLATy->getSizeExpr() || in TryToFixInvalidVariablyModifiedType()
6476 !VLATy->getSizeExpr()->EvaluateAsInt(Result, Context)) in TryToFixInvalidVariablyModifiedType()
6489 (!ElemTy->isDependentType() && !ElemTy->isVariablyModifiedType() && in TryToFixInvalidVariablyModifiedType()
6490 !ElemTy->isIncompleteType() && !ElemTy->isUndeducedType()) in TryToFixInvalidVariablyModifiedType()
6499 ElemTy, Res, VLATy->getSizeExpr(), ArraySizeModifier::Normal, 0); in TryToFixInvalidVariablyModifiedType()
6547 = TryToFixInvalidVariablyModifiedType(TInfo->getType(), Context, in TryToFixInvalidVariablyModifiedTypeSourceInfo()
6552 FixInvalidVariablyModifiedTypeLoc(TInfo->getTypeLoc(), in TryToFixInvalidVariablyModifiedTypeSourceInfo()
6553 FixedTInfo->getTypeLoc()); in TryToFixInvalidVariablyModifiedTypeSourceInfo()
6567 T = FixedTInfo->getType(); in tryToFixVariablyModifiedVarType()
6583 ND->getLexicalDeclContext()->getRedeclContext()->isTranslationUnit()) in RegisterLocallyScopedExternCDecl()
6587 // Note that we have a locally-scoped external with this name. in RegisterLocallyScopedExternCDecl()
6588 Context.getExternCContextDecl()->makeDeclVisibleInContext(ND); in RegisterLocallyScopedExternCDecl()
6593 auto Result = Context.getExternCContextDecl()->lookup(Name); in findLocallyScopedExternCDecl()
6646 TypedefDecl *NewTD = ParseTypedefDecl(S, D, TInfo->getType(), TInfo); in ActOnTypedefDeclarator()
6666 TypeSourceInfo *TInfo = NewTD->getTypeSourceInfo(); in CheckTypedefForVariablyModifiedType()
6667 QualType T = TInfo->getType(); in CheckTypedefForVariablyModifiedType()
6668 if (T->isVariablyModifiedType()) { in CheckTypedefForVariablyModifiedType()
6671 if (S->getFnParent() == nullptr) { in CheckTypedefForVariablyModifiedType()
6679 Diag(NewTD->getLocation(), diag::ext_vla_folded_to_constant); in CheckTypedefForVariablyModifiedType()
6680 NewTD->setTypeSourceInfo(FixedTInfo); in CheckTypedefForVariablyModifiedType()
6683 Diag(NewTD->getLocation(), diag::err_typecheck_negative_array_size); in CheckTypedefForVariablyModifiedType()
6684 else if (T->isVariableArrayType()) in CheckTypedefForVariablyModifiedType()
6685 Diag(NewTD->getLocation(), diag::err_vla_decl_in_file_scope); in CheckTypedefForVariablyModifiedType()
6687 Diag(NewTD->getLocation(), diag::err_array_too_large) in CheckTypedefForVariablyModifiedType()
6690 Diag(NewTD->getLocation(), diag::err_vm_decl_in_file_scope); in CheckTypedefForVariablyModifiedType()
6691 NewTD->setInvalidDecl(); in CheckTypedefForVariablyModifiedType()
6720 if (IdentifierInfo *II = NewTD->getIdentifier()) in ActOnTypedefNameDecl()
6721 if (!NewTD->isInvalidDecl() && in ActOnTypedefNameDecl()
6722 NewTD->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in ActOnTypedefNameDecl()
6723 switch (II->getNotableIdentifierID()) { in ActOnTypedefNameDecl()
6738 NewTD->addAttr(AvailableOnlyInDefaultEvalMethodAttr::Create(Context)); in ActOnTypedefNameDecl()
6748 /// Determines whether the given declaration is an out-of-scope
6756 /// 6.2.2p4-5, C++ [basic.link]p6).
6764 /// \returns true if PrevDecl is an out-of-scope previous declaration
6772 if (!PrevDecl->hasLinkage()) in isOutOfScopePreviousDeclaration()
6782 DeclContext *OuterContext = DC->getRedeclContext(); in isOutOfScopePreviousDeclaration()
6783 if (!OuterContext->isFunctionOrMethod()) in isOutOfScopePreviousDeclaration()
6784 // This rule only applies to block-scope declarations. in isOutOfScopePreviousDeclaration()
6787 DeclContext *PrevOuterContext = PrevDecl->getDeclContext(); in isOutOfScopePreviousDeclaration()
6788 if (PrevOuterContext->isRecord()) in isOutOfScopePreviousDeclaration()
6794 OuterContext = OuterContext->getEnclosingNamespaceContext(); in isOutOfScopePreviousDeclaration()
6795 PrevOuterContext = PrevOuterContext->getEnclosingNamespaceContext(); in isOutOfScopePreviousDeclaration()
6799 if (!OuterContext->Equals(PrevOuterContext)) in isOutOfScopePreviousDeclaration()
6809 DD->setQualifierInfo(SS.getWithLocInContext(S.Context)); in SetNestedNameSpecifier()
6813 if (Decl->getType().hasAddressSpace()) in deduceOpenCLAddressSpace()
6815 if (Decl->getType()->isDependentType()) in deduceOpenCLAddressSpace()
6818 QualType Type = Var->getType(); in deduceOpenCLAddressSpace()
6819 if (Type->isSamplerT() || Type->isVoidType()) in deduceOpenCLAddressSpace()
6822 // OpenCL C v3.0 s6.7.8 - For OpenCL C 2.0 or with the in deduceOpenCLAddressSpace()
6827 Var->hasGlobalStorage()) in deduceOpenCLAddressSpace()
6832 auto OrigTy = DT->getOriginalType(); in deduceOpenCLAddressSpace()
6833 if (!OrigTy.hasAddressSpace() && OrigTy->isArrayType()) { in deduceOpenCLAddressSpace()
6838 // Re-generate the decayed type. in deduceOpenCLAddressSpace()
6847 if (Type->isArrayType()) in deduceOpenCLAddressSpace()
6849 Decl->setType(Type); in deduceOpenCLAddressSpace()
6861 S.Diag(Attr->getLocation(), diag::err_attribute_weak_static); in checkAttributesAfterMerging()
6867 S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static); in checkAttributesAfterMerging()
6873 if (VD->hasInit()) { in checkAttributesAfterMerging()
6874 if (const auto *Attr = VD->getAttr<AliasAttr>()) { in checkAttributesAfterMerging()
6875 assert(VD->isThisDeclarationADefinition() && in checkAttributesAfterMerging()
6876 !VD->isExternallyVisible() && "Broken AliasAttr handled late!"); in checkAttributesAfterMerging()
6877 S.Diag(Attr->getLocation(), diag::err_alias_is_definition) << VD << 0; in checkAttributesAfterMerging()
6878 VD->dropAttr<AliasAttr>(); in checkAttributesAfterMerging()
6887 S.Diag(Attr->getLocation(), in checkAttributesAfterMerging()
6895 S.Diag(Attr->getLocation(), in checkAttributesAfterMerging()
6903 const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(VD->getDeclContext()); in checkAttributesAfterMerging()
6905 IsAnonymousNS = NS->isAnonymousNamespace(); in checkAttributesAfterMerging()
6906 NS = dyn_cast<NamespaceDecl>(NS->getParent()); in checkAttributesAfterMerging()
6916 (!ND.isExternallyVisible() || (VD && VD->isStaticLocal())))) { in checkAttributesAfterMerging()
6925 // Don't declare this variable in the second operand of the for-statement; in checkAttributesAfterMerging()
6929 for (TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc(); in checkAttributesAfterMerging()
6933 // parameter of a non-static member function (other than a ctor or dtor) in checkAttributesAfterMerging()
6937 if (!MD || MD->isStatic()) { in checkAttributesAfterMerging()
6938 S.Diag(A->getLocation(), diag::err_lifetimebound_no_object_param) in checkAttributesAfterMerging()
6939 << !MD << A->getRange(); in checkAttributesAfterMerging()
6941 S.Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor) in checkAttributesAfterMerging()
6942 << isa<CXXDestructorDecl>(MD) << A->getRange(); in checkAttributesAfterMerging()
6953 if (OldDecl->isInvalidDecl() || NewDecl->isInvalidDecl()) in checkDLLAttributeRedeclaration()
6958 OldDecl = OldTD->getTemplatedDecl(); in checkDLLAttributeRedeclaration()
6964 NewDecl = NewTD->getTemplatedDecl(); in checkDLLAttributeRedeclaration()
6971 const DLLImportAttr *OldImportAttr = OldDecl->getAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
6972 const DLLExportAttr *OldExportAttr = OldDecl->getAttr<DLLExportAttr>(); in checkDLLAttributeRedeclaration()
6973 const DLLImportAttr *NewImportAttr = NewDecl->getAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
6974 const DLLExportAttr *NewExportAttr = NewDecl->getAttr<DLLExportAttr>(); in checkDLLAttributeRedeclaration()
6978 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) || in checkDLLAttributeRedeclaration()
6979 (NewExportAttr && !NewExportAttr->isInherited()); in checkDLLAttributeRedeclaration()
6987 if (AddsAttr && !IsSpecialization && !OldDecl->isImplicit()) { in checkDLLAttributeRedeclaration()
6990 if (!OldDecl->isCXXClassMember()) { in checkDLLAttributeRedeclaration()
6992 if (VD && !VD->getDescribedVarTemplate()) in checkDLLAttributeRedeclaration()
6995 if (FD && FD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) in checkDLLAttributeRedeclaration()
7002 if (OldDecl->isUsed()) in checkDLLAttributeRedeclaration()
7008 S.Diag(NewDecl->getLocation(), DiagID) in checkDLLAttributeRedeclaration()
7011 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
7013 NewDecl->setInvalidDecl(); in checkDLLAttributeRedeclaration()
7026 // Ignore static data because out-of-line definitions are diagnosed in checkDLLAttributeRedeclaration()
7028 IsStaticDataMember = VD->isStaticDataMember(); in checkDLLAttributeRedeclaration()
7029 IsDefinition = VD->isThisDeclarationADefinition(S.Context) != in checkDLLAttributeRedeclaration()
7032 IsInline = FD->isInlined(); in checkDLLAttributeRedeclaration()
7033 IsQualifiedFriend = FD->getQualifier() && in checkDLLAttributeRedeclaration()
7034 FD->getFriendObjectKind() == Decl::FOK_Declared; in checkDLLAttributeRedeclaration()
7039 !NewDecl->isLocalExternDecl() && !IsQualifiedFriend) { in checkDLLAttributeRedeclaration()
7043 NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
7045 S.Diag(OldImportAttr->getLocation(), diag::note_attribute); in checkDLLAttributeRedeclaration()
7046 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7048 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
7051 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
7052 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7053 NewDecl->addAttr(DLLExportAttr::CreateImplicit( in checkDLLAttributeRedeclaration()
7054 S.Context, NewImportAttr->getRange())); in checkDLLAttributeRedeclaration()
7060 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
7063 S.Diag(OldDecl->getLocation(), diag::note_previous_declaration); in checkDLLAttributeRedeclaration()
7064 S.Diag(OldImportAttr->getLocation(), diag::note_previous_attribute); in checkDLLAttributeRedeclaration()
7065 OldDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7066 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7071 OldDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7072 NewDecl->dropAttr<DLLImportAttr>(); in checkDLLAttributeRedeclaration()
7073 S.Diag(NewDecl->getLocation(), in checkDLLAttributeRedeclaration()
7083 if (MD->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization && in checkDLLAttributeRedeclaration()
7086 MD->getParent()->getAttr<DLLExportAttr>()) { in checkDLLAttributeRedeclaration()
7087 DLLExportAttr *NewAttr = ParentExportAttr->clone(S.Context); in checkDLLAttributeRedeclaration()
7088 NewAttr->setInherited(true); in checkDLLAttributeRedeclaration()
7089 NewDecl->addAttr(NewAttr); in checkDLLAttributeRedeclaration()
7102 if (!FD->isInlined()) return false; in isFunctionDefinitionDiscarded()
7105 if (S.getLangOpts().CPlusPlus && !FD->hasAttr<GNUInlineAttr>()) in isFunctionDefinitionDiscarded()
7108 // Okay, go ahead and call the relatively-more-expensive function. in isFunctionDefinitionDiscarded()
7132 if (!D->isInExternCContext() || D->template hasAttr<OverloadableAttr>()) in isIncompleteDeclExternC()
7136 if (S.getLangOpts().CUDA && (D->template hasAttr<CUDADeviceAttr>() || in isIncompleteDeclExternC()
7137 D->template hasAttr<CUDAHostAttr>())) in isIncompleteDeclExternC()
7140 return D->isExternC(); in isIncompleteDeclExternC()
7144 const DeclContext *DC = VD->getDeclContext()->getRedeclContext(); in shouldConsiderLinkage()
7145 if (DC->isFunctionOrMethod() || isa<OMPDeclareReductionDecl>(DC) || in shouldConsiderLinkage()
7147 return VD->hasExternalStorage(); in shouldConsiderLinkage()
7148 if (DC->isFileContext()) in shouldConsiderLinkage()
7150 if (DC->isRecord()) in shouldConsiderLinkage()
7152 if (DC->getDeclKind() == Decl::HLSLBuffer) in shouldConsiderLinkage()
7161 const DeclContext *DC = FD->getDeclContext()->getRedeclContext(); in shouldConsiderLinkage()
7162 if (DC->isFileContext() || DC->isFunctionOrMethod() || in shouldConsiderLinkage()
7165 if (DC->isRecord()) in shouldConsiderLinkage()
7189 if (!DC->isFunctionOrMethod()) in adjustContextForLocalExternDecl()
7195 if (DC->isDependentContext()) in adjustContextForLocalExternDecl()
7204 // semantically-enclosing namespace, not a lexically-enclosing one. in adjustContextForLocalExternDecl()
7205 while (!DC->isFileContext() && !isa<LinkageSpecDecl>(DC)) in adjustContextForLocalExternDecl()
7206 DC = DC->getParent(); in adjustContextForLocalExternDecl()
7213 return FD->isExternC(); in isDeclExternC()
7215 return VD->isExternC(); in isDeclExternC()
7222 DeclContext *DC = NewVD->getDeclContext(); in diagnoseOpenCLTypes()
7223 QualType R = NewVD->getType(); in diagnoseOpenCLTypes()
7225 // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument. in diagnoseOpenCLTypes()
7226 // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function in diagnoseOpenCLTypes()
7228 if (R->isImageType() || R->isPipeType()) { in diagnoseOpenCLTypes()
7229 Se.Diag(NewVD->getLocation(), in diagnoseOpenCLTypes()
7232 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7241 if (NewVD->hasGlobalStorage() && !NewVD->isStaticLocal()) { in diagnoseOpenCLTypes()
7242 if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { in diagnoseOpenCLTypes()
7243 Se.Diag(NewVD->getLocation(), in diagnoseOpenCLTypes()
7246 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7255 while (NR->isPointerType() || NR->isMemberFunctionPointerType() || in diagnoseOpenCLTypes()
7256 NR->isReferenceType()) { in diagnoseOpenCLTypes()
7257 if (NR->isFunctionPointerType() || NR->isMemberFunctionPointerType() || in diagnoseOpenCLTypes()
7258 NR->isFunctionReferenceType()) { in diagnoseOpenCLTypes()
7259 Se.Diag(NewVD->getLocation(), diag::err_opencl_function_pointer) in diagnoseOpenCLTypes()
7260 << NR->isReferenceType(); in diagnoseOpenCLTypes()
7261 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7264 NR = NR->getPointeeType(); in diagnoseOpenCLTypes()
7272 if (Se.Context.getBaseElementType(R)->isHalfType()) { in diagnoseOpenCLTypes()
7273 Se.Diag(NewVD->getLocation(), diag::err_opencl_half_declaration) << R; in diagnoseOpenCLTypes()
7274 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7282 if (R->isEventT()) { in diagnoseOpenCLTypes()
7284 Se.Diag(NewVD->getBeginLoc(), diag::err_event_t_addr_space_qual); in diagnoseOpenCLTypes()
7285 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7290 if (R->isSamplerT()) { in diagnoseOpenCLTypes()
7296 Se.Diag(NewVD->getLocation(), diag::err_wrong_sampler_addressspace); in diagnoseOpenCLTypes()
7297 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7303 if (DC->isTranslationUnit() && in diagnoseOpenCLTypes()
7306 Se.Diag(NewVD->getLocation(), diag::err_opencl_nonconst_global_sampler); in diagnoseOpenCLTypes()
7307 NewVD->setInvalidDecl(); in diagnoseOpenCLTypes()
7309 if (NewVD->isInvalidDecl()) in diagnoseOpenCLTypes()
7318 const TypedefNameDecl *TND = TT->getDecl(); in copyAttrFromTypedefToDecl()
7319 if (const auto *Attribute = TND->getAttr<AttrTy>()) { in copyAttrFromTypedefToDecl()
7320 AttrTy *Clone = Attribute->clone(S.Context); in copyAttrFromTypedefToDecl()
7321 Clone->setInherited(true); in copyAttrFromTypedefToDecl()
7322 D->addAttr(Clone); in copyAttrFromTypedefToDecl()
7330 QualType VarType = VD->getType().getCanonicalType(); in emitReadOnlyPlacementAttrWarning()
7334 // ReadOnlyPlacementAttr attribute. To be handled in follow-up patch. in emitReadOnlyPlacementAttrWarning()
7335 if (!VD || VD->hasLocalStorage() || VD->getType().isConstQualified()) in emitReadOnlyPlacementAttrWarning()
7338 if (VarType->isArrayType()) { in emitReadOnlyPlacementAttrWarning()
7343 const RecordDecl *RD = VarType->getAsRecordDecl(); in emitReadOnlyPlacementAttrWarning()
7349 if (const auto *ConstDecl = RD->getAttr<ReadOnlyPlacementAttr>()) { in emitReadOnlyPlacementAttrWarning()
7350 S.Diag(VD->getLocation(), diag::warn_var_decl_not_read_only) << RD; in emitReadOnlyPlacementAttrWarning()
7351 S.Diag(ConstDecl->getLocation(), diag::note_enforce_read_only_placement); in emitReadOnlyPlacementAttrWarning()
7360 QualType R = TInfo->getType(); in ActOnVariableDeclarator()
7383 if (LangOpts.CPlusPlus && (DC->isClosure() || DC->isFunctionOrMethod()) && in ActOnVariableDeclarator()
7384 SC != SC_Static && SC != SC_Extern && II && II->isPlaceholder()) { in ActOnVariableDeclarator()
7388 bool SameDC = PrevDecl->getDeclContext()->getRedeclContext()->Equals( in ActOnVariableDeclarator()
7389 DC->getRedeclContext()); in ActOnVariableDeclarator()
7397 if (SC == SC_None && !DC->isRecord() && in ActOnVariableDeclarator()
7407 // mutable can only appear on non-static class members, so it's always in ActOnVariableDeclarator()
7428 if (!DC->isRecord() && S->getFnParent() == nullptr) { in ActOnVariableDeclarator()
7429 // C99 6.9p2: The storage-class specifiers auto and register shall not in ActOnVariableDeclarator()
7439 // fold to a constant-sized type. This is otherwise invalid. in ActOnVariableDeclarator()
7440 if (D.hasInitializer() && R->isVariableArrayType()) in ActOnVariableDeclarator()
7444 if (AutoTypeLoc TL = TInfo->getTypeLoc().getContainedAutoTypeLoc()) { in ActOnVariableDeclarator()
7460 if (R->getContainedDeducedType()) in ActOnVariableDeclarator()
7464 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7466 if (NewVD->getType().hasNonTrivialToPrimitiveDestructCUnion() && in ActOnVariableDeclarator()
7467 NewVD->hasLocalStorage()) in ActOnVariableDeclarator()
7468 checkNonTrivialCUnion(NewVD->getType(), NewVD->getLocation(), in ActOnVariableDeclarator()
7484 if (!TemplateParams->size() && in ActOnVariableDeclarator()
7488 Diag(TemplateParams->getTemplateLoc(), in ActOnVariableDeclarator()
7491 << SourceRange(TemplateParams->getTemplateLoc(), in ActOnVariableDeclarator()
7492 TemplateParams->getRAngleLoc()); in ActOnVariableDeclarator()
7502 IsPartialSpecialization = TemplateParams->size() > 0; in ActOnVariableDeclarator()
7503 } else { // if (TemplateParams->size() > 0) in ActOnVariableDeclarator()
7528 // The declaration in an explicit-specialization shall not be an in ActOnVariableDeclarator()
7529 // export-declaration. An explicit specialization shall not use a in ActOnVariableDeclarator()
7530 // storage-class-specifier other than thread_local. in ActOnVariableDeclarator()
7532 // We use the storage-class-specifier from DeclSpec because we may have in ActOnVariableDeclarator()
7541 if (CurContext->isRecord()) { in ActOnVariableDeclarator()
7548 for (DeclContext *Ctxt = DC; Ctxt; Ctxt = Ctxt->getParent()) { in ActOnVariableDeclarator()
7549 if (Ctxt->isFunctionOrMethod()) { in ActOnVariableDeclarator()
7554 if (ParentDecl && !ParentDecl->getDeclName()) { in ActOnVariableDeclarator()
7564 << Name << RD->getDeclName() in ActOnVariableDeclarator()
7565 << llvm::to_underlying(RD->getTagKind()); in ActOnVariableDeclarator()
7572 << Name << llvm::to_underlying(AnonStruct->getTagKind()); in ActOnVariableDeclarator()
7574 } else if (RD->isUnion()) { in ActOnVariableDeclarator()
7576 // the program is ill-formed. C++11 drops this restriction. in ActOnVariableDeclarator()
7587 << II << TemplateParams->getSourceRange(); in ActOnVariableDeclarator()
7591 } else if (DC->isRecord()) { in ActOnVariableDeclarator()
7592 // This is an out-of-line definition of a static data member. in ActOnVariableDeclarator()
7623 ? TemplateParamLists[0]->getTemplateLoc() in ActOnVariableDeclarator()
7645 NewVD->setDescribedVarTemplate(NewTemplate); in ActOnVariableDeclarator()
7650 if (R->getContainedDeducedType()) in ActOnVariableDeclarator()
7654 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7656 NewTemplate->setInvalidDecl(); in ActOnVariableDeclarator()
7668 NewVD->setTemplateParameterListsInfo( in ActOnVariableDeclarator()
7676 } else if (CurContext->isFunctionOrMethod()) { in ActOnVariableDeclarator()
7685 NewVD->setInlineSpecified(); in ActOnVariableDeclarator()
7691 NewVD->setLexicalDeclContext(CurContext); in ActOnVariableDeclarator()
7693 NewTemplate->setLexicalDeclContext(CurContext); in ActOnVariableDeclarator()
7698 B->setLocalExternDecl(); in ActOnVariableDeclarator()
7700 NewVD->setLocalExternDecl(); in ActOnVariableDeclarator()
7707 // storage-class-specifier static is implied if it does not appear in ActOnVariableDeclarator()
7711 if (NewVD->hasLocalStorage() && in ActOnVariableDeclarator()
7714 !DC->isFunctionOrMethod())) in ActOnVariableDeclarator()
7728 NewVD->setTSCSpec(TSCS); in ActOnVariableDeclarator()
7733 NewVD->setTSCSpec(TSCS); in ActOnVariableDeclarator()
7747 NewVD->setConstexpr(true); in ActOnVariableDeclarator()
7751 if (NewVD->isStaticDataMember() && in ActOnVariableDeclarator()
7754 NewVD->setImplicitlyInline(); in ActOnVariableDeclarator()
7758 if (!NewVD->hasGlobalStorage()) in ActOnVariableDeclarator()
7762 NewVD->addAttr( in ActOnVariableDeclarator()
7777 if (SC == SC_Static && S->getFnParent() != nullptr && in ActOnVariableDeclarator()
7778 !NewVD->getType().isConstQualified()) { in ActOnVariableDeclarator()
7789 Diag(NewVD->getLocation(), diag::err_module_private_specialization) in ActOnVariableDeclarator()
7794 Diag(NewVD->getLocation(), diag::err_module_private_specialization) in ActOnVariableDeclarator()
7797 else if (NewVD->hasLocalStorage()) in ActOnVariableDeclarator()
7798 Diag(NewVD->getLocation(), diag::err_module_private_local) in ActOnVariableDeclarator()
7804 NewVD->setModulePrivate(); in ActOnVariableDeclarator()
7806 NewTemplate->setModulePrivate(); in ActOnVariableDeclarator()
7808 B->setModulePrivate(); in ActOnVariableDeclarator()
7821 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7828 if (const auto *ATy = dyn_cast<ArrayType>(NewVD->getType())) { in ActOnVariableDeclarator()
7829 if (ATy && ATy->getElementType().isWebAssemblyReferenceType() && in ActOnVariableDeclarator()
7830 !NewVD->hasLocalStorage()) { in ActOnVariableDeclarator()
7832 NewVD->getType(), Context.getLangASForBuiltinAddressSpace(1)); in ActOnVariableDeclarator()
7833 NewVD->setType(Type); in ActOnVariableDeclarator()
7844 if (R->isFunctionPointerType()) in ActOnVariableDeclarator()
7845 if (const auto *TT = R->getAs<TypedefType>()) in ActOnVariableDeclarator()
7863 if (SC == SC_None && S->getFnParent() != nullptr && in ActOnVariableDeclarator()
7864 (NewVD->hasAttr<CUDASharedAttr>() || in ActOnVariableDeclarator()
7865 NewVD->hasAttr<CUDAConstantAttr>())) { in ActOnVariableDeclarator()
7866 NewVD->setStorageClass(SC_Static); in ActOnVariableDeclarator()
7873 assert(!NewVD->hasAttr<DLLImportAttr>() || in ActOnVariableDeclarator()
7874 NewVD->getAttr<DLLImportAttr>()->isInherited() || in ActOnVariableDeclarator()
7875 NewVD->isStaticDataMember() || NewVD->getStorageClass() != SC_None); in ActOnVariableDeclarator()
7877 // In auto-retain/release, infer strong retension for variables of in ActOnVariableDeclarator()
7880 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7882 // Handle GNU asm-label extension (encoded as an attribute). in ActOnVariableDeclarator()
7886 StringRef Label = SE->getString(); in ActOnVariableDeclarator()
7887 if (S->getFnParent() != nullptr) { in ActOnVariableDeclarator()
7891 Diag(E->getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label; in ActOnVariableDeclarator()
7897 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label; in ActOnVariableDeclarator()
7911 Diag(E->getExprLoc(), diag::err_asm_unknown_register_name) << Label; in ActOnVariableDeclarator()
7915 Diag(E->getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label; in ActOnVariableDeclarator()
7917 Diag(E->getExprLoc(), diag::err_asm_register_size_mismatch) << Label; in ActOnVariableDeclarator()
7920 if (!R->isIntegralType(Context) && !R->isPointerType()) { in ActOnVariableDeclarator()
7922 NewVD->setInvalidDecl(true); in ActOnVariableDeclarator()
7926 NewVD->addAttr(AsmLabelAttr::Create(Context, Label, in ActOnVariableDeclarator()
7928 SE->getStrTokenLoc(0))); in ActOnVariableDeclarator()
7931 ExtnameUndeclaredIdentifiers.find(NewVD->getIdentifier()); in ActOnVariableDeclarator()
7934 NewVD->addAttr(I->second); in ActOnVariableDeclarator()
7937 Diag(NewVD->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnVariableDeclarator()
7948 // scope and are out-of-semantic-context declarations (if the new in ActOnVariableDeclarator()
7958 NewVD->isLocalVarDecl() && NewVD->hasExternalStorage()) in ActOnVariableDeclarator()
7959 NewVD->setPreviousDeclInSameBlockScope( in ActOnVariableDeclarator()
7968 !NewVD->isInvalidDecl() && CheckMemberSpecialization(NewVD, Previous)) in ActOnVariableDeclarator()
7969 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7976 // The user tried to define a non-static data member in ActOnVariableDeclarator()
7977 // out-of-line (C++ [dcl.meaning]p1). in ActOnVariableDeclarator()
7978 Diag(NewVD->getLocation(), diag::err_nonstatic_member_out_of_line) in ActOnVariableDeclarator()
7981 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7989 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
7996 // error like WebAssembly tables being declared as arrays with a non-zero in ActOnVariableDeclarator()
7999 if (NewVD->getType()->isWebAssemblyTableType() && NewVD->isInvalidDecl()) in ActOnVariableDeclarator()
8004 NewVD->getPreviousDecl() in ActOnVariableDeclarator()
8005 ? NewVD->getPreviousDecl()->getDescribedVarTemplate() in ActOnVariableDeclarator()
8013 PrevVarTemplate ? PrevVarTemplate->getTemplateParameters() in ActOnVariableDeclarator()
8015 (D.getCXXScopeSpec().isSet() && DC && DC->isRecord() && in ActOnVariableDeclarator()
8016 DC->isDependentContext()) in ActOnVariableDeclarator()
8019 NewVD->setInvalidDecl(); in ActOnVariableDeclarator()
8024 PrevVarTemplate->getInstantiatedFromMemberTemplate()) in ActOnVariableDeclarator()
8025 PrevVarTemplate->setMemberSpecialization(); in ActOnVariableDeclarator()
8037 if (NewVD->isFirstDecl() && !NewVD->isInvalidDecl() && in ActOnVariableDeclarator()
8041 if (getLangOpts().CPlusPlus && NewVD->isStaticLocal()) { in ActOnVariableDeclarator()
8045 getCurrentMangleNumberContext(NewVD->getDeclContext()); in ActOnVariableDeclarator()
8048 NewVD, MCtx->getManglingNumber( in ActOnVariableDeclarator()
8050 Context.setStaticLocalNumber(NewVD, MCtx->getStaticLocalNumber(NewVD)); in ActOnVariableDeclarator()
8055 if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main") && in ActOnVariableDeclarator()
8056 NewVD->getDeclContext()->getRedeclContext()->isTranslationUnit() && in ActOnVariableDeclarator()
8057 !getLangOpts().Freestanding && !NewVD->getDescribedVarTemplate()) { in ActOnVariableDeclarator()
8060 // A program that declares a variable main at global scope is ill-formed. in ActOnVariableDeclarator()
8064 // In C, and external-linkage variable named main results in undefined in ActOnVariableDeclarator()
8066 else if (NewVD->hasExternalFormalLinkage()) in ActOnVariableDeclarator()
8077 if (NewVD->isInvalidDecl()) in ActOnVariableDeclarator()
8078 NewTemplate->setInvalidDecl(); in ActOnVariableDeclarator()
8083 if (IsMemberSpecialization && !NewVD->isInvalidDecl()) in ActOnVariableDeclarator()
8114 return OldDC->isFileContext() ? SDK_Global : SDK_Local; in computeShadowedDeclKind()
8121 for (const Capture &Capture : LSI->Captures) { in getCaptureLocation()
8144 if (D->hasGlobalStorage() && !D->isStaticLocal()) in getShadowedDeclaration()
8155 if (D->getDeclContext()->isRecord()) in getShadowedDeclaration()
8177 DeclContext *NewDC = D->getDeclContext(); in CheckShadow()
8182 if (MD->isStatic()) in CheckShadow()
8191 ShadowingDecls.insert({PVD->getCanonicalDecl(), FD}); in CheckShadow()
8197 if (shadowedVar->isExternC()) { in CheckShadow()
8200 for (auto *I : shadowedVar->redecls()) in CheckShadow()
8201 if (I->isFileVarDecl()) { in CheckShadow()
8207 DeclContext *OldDC = ShadowedDecl->getDeclContext()->getRedeclContext(); in CheckShadow()
8212 if (const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->getParent())) { in CheckShadow()
8213 if (RD->isLambda() && OldDC->Encloses(NewDC->getLexicalParent())) { in CheckShadow()
8216 if (RD->getLambdaCaptureDefault() == LCD_None) { in CheckShadow()
8228 ->ShadowingDecls.push_back({D, VD}); in CheckShadow()
8239 ->ShadowingDecls.push_back({D, ShadowedDecl}); in CheckShadow()
8244 VD && VD->hasLocalStorage()) { in CheckShadow()
8246 // they are separated by a non-capturing declaration context. in CheckShadow()
8248 ParentDC && !ParentDC->Equals(OldDC); in CheckShadow()
8262 if (ShadowedDecl->isPlaceholderVar(getLangOpts())) in CheckShadow()
8266 if (NewDC && NewDC->isRecord()) { in CheckShadow()
8267 // In particular, don't warn about shadowing non-class members. in CheckShadow()
8268 if (!OldDC->isRecord()) in CheckShadow()
8288 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in CheckShadow()
8292 for (const auto &Shadow : LSI->ShadowingDecls) { in DiagnoseShadowingLambdaDecls()
8295 const DeclContext *OldDC = ShadowedDecl->getDeclContext(); in DiagnoseShadowingLambdaDecls()
8298 Diag(Shadow.VD->getLocation(), in DiagnoseShadowingLambdaDecls()
8301 << Shadow.VD->getDeclName() in DiagnoseShadowingLambdaDecls()
8305 << Shadow.VD->getDeclName() << /*explicitly*/ 0; in DiagnoseShadowingLambdaDecls()
8306 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in DiagnoseShadowingLambdaDecls()
8308 Diag(Shadow.VD->getLocation(), in DiagnoseShadowingLambdaDecls()
8309 LSI->isCXXThisCaptured() ? diag::warn_decl_shadow in DiagnoseShadowingLambdaDecls()
8311 << Shadow.VD->getDeclName() in DiagnoseShadowingLambdaDecls()
8313 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in DiagnoseShadowingLambdaDecls()
8319 if (Diags.isIgnored(diag::warn_decl_shadow, D->getLocation())) in CheckShadow()
8322 LookupResult R(*this, D->getDeclName(), D->getLocation(), in CheckShadow()
8336 E = E->IgnoreParenImpCasts(); in CheckShadowingDeclModification()
8340 const NamedDecl *D = cast<NamedDecl>(DRE->getDecl()->getCanonicalDecl()); in CheckShadowingDeclModification()
8344 const NamedDecl *ShadowedDecl = I->second; in CheckShadowingDeclModification()
8345 const DeclContext *OldDC = ShadowedDecl->getDeclContext(); in CheckShadowingDeclModification()
8347 Diag(D->getLocation(), diag::note_var_declared_here) << D; in CheckShadowingDeclModification()
8348 Diag(ShadowedDecl->getLocation(), diag::note_previous_declaration); in CheckShadowingDeclModification()
8360 NamedDecl *Prev = S.findLocallyScopedExternCDecl(ND->getDeclName()); in checkGlobalOrExternCConflict()
8377 // This is a global, non-extern "C" declaration, and there is a previous in checkGlobalOrExternCConflict()
8378 // non-global extern "C" declaration. Diagnose if this is a variable in checkGlobalOrExternCConflict()
8397 S.Context.getTranslationUnitDecl()->lookup(ND->getDeclName()); in checkGlobalOrExternCConflict()
8405 // the declaration is ill-formed, but that is a defect: it breaks the in checkGlobalOrExternCConflict()
8417 // is lexically inside an extern "C" linkage-spec. in checkGlobalOrExternCConflict()
8420 Prev = FD->getFirstDecl(); in checkGlobalOrExternCConflict()
8422 Prev = cast<VarDecl>(Prev)->getFirstDecl(); in checkGlobalOrExternCConflict()
8424 S.Diag(ND->getLocation(), diag::err_extern_c_global_conflict) in checkGlobalOrExternCConflict()
8426 S.Diag(Prev->getLocation(), diag::note_extern_c_global_conflict) in checkGlobalOrExternCConflict()
8445 // we find local extern decls in the surrounding file-scope DeclContext. in checkForConflictWithNonVisibleExternC()
8446 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in checkForConflictWithNonVisibleExternC()
8447 if (NamedDecl *Prev = S.findLocallyScopedExternCDecl(ND->getDeclName())) { in checkForConflictWithNonVisibleExternC()
8458 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) in checkForConflictWithNonVisibleExternC()
8474 // C23 6.7.1p5: An object declared with storage-class specifier constexpr or in CheckC23ConstexprVarType()
8477 if (CanonT->isVariablyModifiedType()) { in CheckC23ConstexprVarType()
8483 // works on non-arrays as well). in CheckC23ConstexprVarType()
8486 if (CanonT->isAtomicType() || CanonT.isVolatileQualified() || in CheckC23ConstexprVarType()
8492 if (CanonT->isRecordType()) { in CheckC23ConstexprVarType()
8493 const RecordDecl *RD = CanonT->getAsRecordDecl(); in CheckC23ConstexprVarType()
8494 if (llvm::any_of(RD->fields(), [&SemaRef, VarLoc](const FieldDecl *F) { in CheckC23ConstexprVarType()
8495 return CheckC23ConstexprVarType(SemaRef, VarLoc, F->getType()); in CheckC23ConstexprVarType()
8505 if (NewVD->isInvalidDecl()) in CheckVariableDeclarationType()
8508 QualType T = NewVD->getType(); in CheckVariableDeclarationType()
8510 // Defer checking an 'auto' type until its initializer is attached. in CheckVariableDeclarationType()
8511 if (T->isUndeducedType()) in CheckVariableDeclarationType()
8514 if (NewVD->hasAttrs()) in CheckVariableDeclarationType()
8517 if (T->isObjCObjectType()) { in CheckVariableDeclarationType()
8518 Diag(NewVD->getLocation(), diag::err_statically_allocated_object) in CheckVariableDeclarationType()
8519 << FixItHint::CreateInsertion(NewVD->getLocation(), "*"); in CheckVariableDeclarationType()
8521 NewVD->setType(T); in CheckVariableDeclarationType()
8528 if (!getLangOpts().OpenCL && NewVD->hasLocalStorage() && in CheckVariableDeclarationType()
8530 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 0; in CheckVariableDeclarationType()
8531 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8535 // OpenCL v1.2 s6.8 - The static qualifier is valid only in program in CheckVariableDeclarationType()
8540 NewVD->isStaticLocal()) { in CheckVariableDeclarationType()
8541 Diag(NewVD->getLocation(), diag::err_static_function_scope); in CheckVariableDeclarationType()
8542 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8550 // OpenCL v2.0 s6.12.5 - The __block storage type is not supported. in CheckVariableDeclarationType()
8551 if (NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
8552 Diag(NewVD->getLocation(), diag::err_opencl_block_storage_type); in CheckVariableDeclarationType()
8556 if (T->isBlockPointerType()) { in CheckVariableDeclarationType()
8557 // OpenCL v2.0 s6.12.5 - Any block declaration must be const qualified and in CheckVariableDeclarationType()
8560 Diag(NewVD->getLocation(), diag::err_opencl_invalid_block_declaration) in CheckVariableDeclarationType()
8562 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8565 if (NewVD->hasExternalStorage()) { in CheckVariableDeclarationType()
8566 Diag(NewVD->getLocation(), diag::err_opencl_extern_block_declaration); in CheckVariableDeclarationType()
8567 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8573 if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() || in CheckVariableDeclarationType()
8574 NewVD->hasExternalStorage()) { in CheckVariableDeclarationType()
8575 if (!T->isSamplerT() && !T->isDependentType() && in CheckVariableDeclarationType()
8580 int Scope = NewVD->isStaticLocal() | NewVD->hasExternalStorage() << 1; in CheckVariableDeclarationType()
8582 Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) in CheckVariableDeclarationType()
8585 Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) in CheckVariableDeclarationType()
8587 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8592 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
8594 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8602 if (FD && !FD->hasAttr<OpenCLKernelAttr>()) { in CheckVariableDeclarationType()
8604 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
8605 << 0 /*non-kernel only*/ << "constant"; in CheckVariableDeclarationType()
8607 Diag(NewVD->getLocation(), diag::err_opencl_function_variable) in CheckVariableDeclarationType()
8608 << 0 /*non-kernel only*/ << "local"; in CheckVariableDeclarationType()
8609 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8614 if (FD && FD->hasAttr<OpenCLKernelAttr>()) { in CheckVariableDeclarationType()
8615 if (!getCurScope()->isFunctionScope()) { in CheckVariableDeclarationType()
8617 Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope) in CheckVariableDeclarationType()
8620 Diag(NewVD->getLocation(), diag::err_opencl_addrspace_scope) in CheckVariableDeclarationType()
8622 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8631 Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl) << 1; in CheckVariableDeclarationType()
8632 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8638 if (NewVD->hasLocalStorage() && T.isObjCGCWeak() in CheckVariableDeclarationType()
8639 && !NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
8641 Diag(NewVD->getLocation(), diag::warn_gc_attribute_weak_on_local); in CheckVariableDeclarationType()
8644 Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); in CheckVariableDeclarationType()
8650 if (T->isWebAssemblyTableType()) { in CheckVariableDeclarationType()
8651 if (getCurScope()->getParent()) { // Parent is null at top-level in CheckVariableDeclarationType()
8652 Diag(NewVD->getLocation(), diag::err_wasm_table_in_function); in CheckVariableDeclarationType()
8653 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8656 if (NewVD->getStorageClass() != SC_Static) { in CheckVariableDeclarationType()
8657 Diag(NewVD->getLocation(), diag::err_wasm_table_must_be_static); in CheckVariableDeclarationType()
8658 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8662 if (!ATy || ATy->getZExtSize() != 0) { in CheckVariableDeclarationType()
8663 Diag(NewVD->getLocation(), in CheckVariableDeclarationType()
8665 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8670 bool isVM = T->isVariablyModifiedType(); in CheckVariableDeclarationType()
8671 if (isVM || NewVD->hasAttr<CleanupAttr>() || in CheckVariableDeclarationType()
8672 NewVD->hasAttr<BlocksAttr>()) in CheckVariableDeclarationType()
8675 if ((isVM && NewVD->hasLinkage()) || in CheckVariableDeclarationType()
8676 (T->isVariableArrayType() && NewVD->hasGlobalStorage())) { in CheckVariableDeclarationType()
8680 NewVD->getTypeSourceInfo(), Context, SizeIsNegative, Oversized); in CheckVariableDeclarationType()
8682 if (FixedTInfo && T == NewVD->getTypeSourceInfo()->getType()) in CheckVariableDeclarationType()
8683 FixedT = FixedTInfo->getType(); in CheckVariableDeclarationType()
8685 // Type and type-as-written are canonically different. We need to fix up in CheckVariableDeclarationType()
8690 if ((!FixedTInfo || FixedT.isNull()) && T->isVariableArrayType()) { in CheckVariableDeclarationType()
8694 SourceRange SizeRange = VAT->getSizeExpr()->getSourceRange(); in CheckVariableDeclarationType()
8696 if (NewVD->isFileVarDecl()) in CheckVariableDeclarationType()
8697 Diag(NewVD->getLocation(), diag::err_vla_decl_in_file_scope) in CheckVariableDeclarationType()
8699 else if (NewVD->isStaticLocal()) in CheckVariableDeclarationType()
8700 Diag(NewVD->getLocation(), diag::err_vla_decl_has_static_storage) in CheckVariableDeclarationType()
8703 Diag(NewVD->getLocation(), diag::err_vla_decl_has_extern_linkage) in CheckVariableDeclarationType()
8705 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8710 if (NewVD->isFileVarDecl()) in CheckVariableDeclarationType()
8711 Diag(NewVD->getLocation(), diag::err_vm_decl_in_file_scope); in CheckVariableDeclarationType()
8713 Diag(NewVD->getLocation(), diag::err_vm_decl_has_extern_linkage); in CheckVariableDeclarationType()
8714 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8718 Diag(NewVD->getLocation(), diag::ext_vla_folded_to_constant); in CheckVariableDeclarationType()
8719 NewVD->setType(FixedT); in CheckVariableDeclarationType()
8720 NewVD->setTypeSourceInfo(FixedTInfo); in CheckVariableDeclarationType()
8723 if (T->isVoidType()) { in CheckVariableDeclarationType()
8726 if (NewVD->isThisDeclarationADefinition() || getLangOpts().CPlusPlus) { in CheckVariableDeclarationType()
8727 Diag(NewVD->getLocation(), diag::err_typecheck_decl_incomplete_type) in CheckVariableDeclarationType()
8729 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8734 if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
8735 Diag(NewVD->getLocation(), diag::err_block_on_nonlocal); in CheckVariableDeclarationType()
8736 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8740 if (!NewVD->hasLocalStorage() && T->isSizelessType() && in CheckVariableDeclarationType()
8742 Diag(NewVD->getLocation(), diag::err_sizeless_nonlocal) << T; in CheckVariableDeclarationType()
8743 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8747 if (isVM && NewVD->hasAttr<BlocksAttr>()) { in CheckVariableDeclarationType()
8748 Diag(NewVD->getLocation(), diag::err_block_on_vm); in CheckVariableDeclarationType()
8749 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8753 if (getLangOpts().C23 && NewVD->isConstexpr() && in CheckVariableDeclarationType()
8754 CheckC23ConstexprVarType(*this, NewVD->getLocation(), T)) { in CheckVariableDeclarationType()
8755 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8759 if (NewVD->isConstexpr() && !T->isDependentType() && in CheckVariableDeclarationType()
8760 RequireLiteralType(NewVD->getLocation(), T, in CheckVariableDeclarationType()
8762 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8766 // PPC MMA non-pointer types are not allowed as non-local variable types. in CheckVariableDeclarationType()
8768 !NewVD->isLocalVarDecl() && in CheckVariableDeclarationType()
8769 PPC().CheckPPCMMAType(T, NewVD->getLocation())) { in CheckVariableDeclarationType()
8770 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8775 if (T->isSVESizelessBuiltinType() && isa<FunctionDecl>(CurContext)) { in CheckVariableDeclarationType()
8782 Diag(NewVD->getLocation(), diag::err_sve_vector_in_non_sve_target) << T; in CheckVariableDeclarationType()
8783 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8787 Diag(NewVD->getLocation(), in CheckVariableDeclarationType()
8790 NewVD->setInvalidDecl(); in CheckVariableDeclarationType()
8796 if (T->isRVVSizelessBuiltinType() && isa<FunctionDecl>(CurContext)) { in CheckVariableDeclarationType()
8800 RISCV().checkRVVTypeSupport(T, NewVD->getLocation(), cast<Decl>(CurContext), in CheckVariableDeclarationType()
8809 if (NewVD->isInvalidDecl()) in CheckVariableDeclaration()
8812 // If we did not find anything by this name, look for a non-visible in CheckVariableDeclaration()
8832 CXXRecordDecl *BaseRecord = Specifier->getType()->getAsCXXRecordDecl(); in AddOverriddenMethods()
8833 DeclarationName Name = MD->getDeclName(); in AddOverriddenMethods()
8842 for (NamedDecl *BaseND : BaseRecord->lookup(Name)) { in AddOverriddenMethods()
8844 dyn_cast<CXXMethodDecl>(BaseND->getCanonicalDecl()); in AddOverriddenMethods()
8845 if (!BaseMD || !BaseMD->isVirtual() || in AddOverriddenMethods()
8852 MD->addOverriddenMethod(BaseMD); in AddOverriddenMethods()
8867 DC->lookupInBases(VisitBase, Paths); in AddOverriddenMethods()
8884 // Callback to only accept typo corrections that have a non-zero edit distance.
8891 ExpectedParent(Parent ? Parent->getCanonicalDecl() : nullptr) {} in DifferentNameValidatorCCC()
8903 if (FD && !FD->hasBody() && in ValidateCandidate()
8906 CXXRecordDecl *Parent = MD->getParent(); in ValidateCandidate()
8907 if (Parent && Parent->getCanonicalDecl() == ExpectedParent) in ValidateCandidate()
8946 DeclarationName Name = NewFD->getDeclName(); in DiagnoseInvalidRedeclaration()
8947 DeclContext *NewDC = NewFD->getDeclContext(); in DiagnoseInvalidRedeclaration()
8954 NewFD->getFriendObjectKind() ? diag::err_qualified_friend_no_match : in DiagnoseInvalidRedeclaration()
8956 LookupResult Prev(SemaRef, Name, NewFD->getLocation(), in DiagnoseInvalidRedeclaration()
8961 NewFD->setInvalidDecl(); in DiagnoseInvalidRedeclaration()
8967 "Cannot have an ambiguity in previous-declaration lookup"); in DiagnoseInvalidRedeclaration()
8970 MD ? MD->getParent() : nullptr); in DiagnoseInvalidRedeclaration()
8998 if (FD && !FD->hasBody() && in DiagnoseInvalidRedeclaration()
9013 // pieces need to verify the typo-corrected C++ declaration and hopefully in DiagnoseInvalidRedeclaration()
9017 Correction.getCorrectionDecl()->getDeclContext(), in DiagnoseInvalidRedeclaration()
9018 NewFD->getTypeSourceInfo(), Previous, ExtraArgs.TemplateParamLists, in DiagnoseInvalidRedeclaration()
9027 Decl *Canonical = Result->getCanonicalDecl(); in DiagnoseInvalidRedeclaration()
9030 if ((*I)->getCanonicalDecl() == Canonical) in DiagnoseInvalidRedeclaration()
9052 SemaRef.Diag(NewFD->getLocation(), DiagMsg) in DiagnoseInvalidRedeclaration()
9053 << Name << NewDC << IsDefinition << NewFD->getLocation(); in DiagnoseInvalidRedeclaration()
9057 NewFDisConst = NewMD->isConst(); in DiagnoseInvalidRedeclaration()
9062 FunctionDecl *FD = NearMatch->first; in DiagnoseInvalidRedeclaration()
9064 bool FDisConst = MD && MD->isConst(); in DiagnoseInvalidRedeclaration()
9068 if (unsigned Idx = NearMatch->second) { in DiagnoseInvalidRedeclaration()
9069 ParmVarDecl *FDParam = FD->getParamDecl(Idx-1); in DiagnoseInvalidRedeclaration()
9070 SourceLocation Loc = FDParam->getTypeSpecStartLoc(); in DiagnoseInvalidRedeclaration()
9071 if (Loc.isInvalid()) Loc = FD->getLocation(); in DiagnoseInvalidRedeclaration()
9074 << Idx << FDParam->getType() in DiagnoseInvalidRedeclaration()
9075 << NewFD->getParamDecl(Idx - 1)->getType(); in DiagnoseInvalidRedeclaration()
9077 auto DB = SemaRef.Diag(FD->getLocation(), in DiagnoseInvalidRedeclaration()
9079 << NewFDisConst << FD->getSourceRange().getEnd(); in DiagnoseInvalidRedeclaration()
9087 SemaRef.Diag(FD->getLocation(), in DiagnoseInvalidRedeclaration()
9112 if (SemaRef.CurContext->getRedeclContext()->isFunctionOrMethod()) { in getFunctionStorageClass()
9115 // block scope shall have no explicit storage-class specifier in getFunctionStorageClass()
9161 // - there is a prototype in the declarator, or in CreateNewFunctionDecl()
9162 // - the type R of the function is some kind of typedef or other non- in CreateNewFunctionDecl()
9165 // check this case because attributes may cause a non-function in CreateNewFunctionDecl()
9173 ->isFunctionProtoType()) || in CreateNewFunctionDecl()
9174 (!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType()); in CreateNewFunctionDecl()
9185 NewFD->setInvalidDecl(); in CreateNewFunctionDecl()
9197 assert(DC->isRecord() && in CreateNewFunctionDecl()
9209 if (DC->isRecord()) { in CreateNewFunctionDecl()
9219 if (Record->isBeingDefined()) in CreateNewFunctionDecl()
9220 NewDD->setIneligibleOrNotSelected(true); in CreateNewFunctionDecl()
9244 if (!DC->isRecord()) { in CreateNewFunctionDecl()
9263 SemaRef.Diag(TrailingRequiresClause->getBeginLoc(), in CreateNewFunctionDecl()
9265 << TrailingRequiresClause->getSourceRange(); in CreateNewFunctionDecl()
9271 } else if (DC->isRecord()) { in CreateNewFunctionDecl()
9277 Name.getAsIdentifierInfo() == cast<CXXRecordDecl>(DC)->getIdentifier()){ in CreateNewFunctionDecl()
9289 IsVirtualOkay = !Ret->isStatic(); in CreateNewFunctionDecl()
9294 if (!isFriend && SemaRef.CurContext->isRecord()) in CreateNewFunctionDecl()
9299 // - we're in C++ (where every function has a prototype), in CreateNewFunctionDecl()
9339 if (PT->isDependentType()) in getOpenCLKernelParameterType()
9342 if (PT->isPointerType() || PT->isReferenceType()) { in getOpenCLKernelParameterType()
9343 QualType PointeeType = PT->getPointeeType(); in getOpenCLKernelParameterType()
9349 if (PointeeType->isPointerType()) { in getOpenCLKernelParameterType()
9373 auto CXXRec = PointeeType.getCanonicalType()->getAsCXXRecordDecl(); in getOpenCLKernelParameterType()
9376 // If template type is not ODR-used its definition is only available in getOpenCLKernelParameterType()
9380 if (!CXXRec->hasDefinition()) in getOpenCLKernelParameterType()
9381 CXXRec = CXXRec->getTemplateInstantiationPattern(); in getOpenCLKernelParameterType()
9382 if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout()) in getOpenCLKernelParameterType()
9385 if (!PointeeType->isAtomicType() && !PointeeType->isVoidType() && in getOpenCLKernelParameterType()
9400 // built-in scalar types bool, half, size_t, ptrdiff_t, intptr_t, and in getOpenCLKernelParameterType()
9402 // of these built-in scalar types. in getOpenCLKernelParameterType()
9406 if (PT->isImageType()) in getOpenCLKernelParameterType()
9409 if (PT->isBooleanType() || PT->isEventT() || PT->isReserveIDT()) in getOpenCLKernelParameterType()
9413 // This extension adds support for half scalar and vector types as built-in in getOpenCLKernelParameterType()
9416 PT->isHalfType()) in getOpenCLKernelParameterType()
9420 if (PT->isArrayType()) { in getOpenCLKernelParameterType()
9421 const Type *UnderlyingTy = PT->getPointeeOrArrayElementType(); in getOpenCLKernelParameterType()
9430 // Trivial and standard-layout types C++17 [basic.types] (plain old data in getOpenCLKernelParameterType()
9435 !PT->isOpenCLSpecificType() && !PT.isPODType(S.Context)) in getOpenCLKernelParameterType()
9438 if (PT->isRecordType()) in getOpenCLKernelParameterType()
9449 QualType PT = Param->getType(); in checkIsValidOpenCLKernelParameter()
9461 S.Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param); in checkIsValidOpenCLKernelParameter()
9470 S.Diag(Param->getLocation(), diag::err_kernel_arg_address_space); in checkIsValidOpenCLKernelParameter()
9476 // built-in scalar types bool, half, size_t, ptrdiff_t, intptr_t, and in checkIsValidOpenCLKernelParameter()
9478 // one of these built-in scalar types. in checkIsValidOpenCLKernelParameter()
9486 if (!PT->isHalfType()) { in checkIsValidOpenCLKernelParameter()
9487 S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT; in checkIsValidOpenCLKernelParameter()
9491 while ((Typedef = PT->getAs<TypedefType>())) { in checkIsValidOpenCLKernelParameter()
9492 SourceLocation Loc = Typedef->getDecl()->getLocation(); in checkIsValidOpenCLKernelParameter()
9493 // SourceLocation may be invalid for a built-in type. in checkIsValidOpenCLKernelParameter()
9496 PT = Typedef->desugar(); in checkIsValidOpenCLKernelParameter()
9522 assert((PT->isArrayType() || PT->isRecordType()) && "Unexpected type."); in checkIsValidOpenCLKernelParameter()
9524 PT->getPointeeOrArrayElementType()->getAs<RecordType>(); in checkIsValidOpenCLKernelParameter()
9525 const RecordDecl *OrigRecDecl = RecTy->getDecl(); in checkIsValidOpenCLKernelParameter()
9527 VisitStack.push_back(RecTy->getDecl()); in checkIsValidOpenCLKernelParameter()
9536 ValidTypes.insert(Hist->getType().getTypePtr()); in checkIsValidOpenCLKernelParameter()
9547 QualType FieldTy = Field->getType(); in checkIsValidOpenCLKernelParameter()
9550 assert((FieldTy->isArrayType() || FieldTy->isRecordType()) && in checkIsValidOpenCLKernelParameter()
9552 const Type *FieldRecTy = FieldTy->getPointeeOrArrayElementType(); in checkIsValidOpenCLKernelParameter()
9554 RD = FieldRecTy->castAs<RecordType>()->getDecl(); in checkIsValidOpenCLKernelParameter()
9562 for (const auto *FD : RD->fields()) { in checkIsValidOpenCLKernelParameter()
9563 QualType QT = FD->getType(); in checkIsValidOpenCLKernelParameter()
9584 S.Diag(Param->getLocation(), in checkIsValidOpenCLKernelParameter()
9586 << PT->isUnionType() in checkIsValidOpenCLKernelParameter()
9589 S.Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT; in checkIsValidOpenCLKernelParameter()
9592 S.Diag(OrigRecDecl->getLocation(), diag::note_within_field_of_type) in checkIsValidOpenCLKernelParameter()
9593 << OrigRecDecl->getDeclName(); in checkIsValidOpenCLKernelParameter()
9602 S.Diag(OuterField->getLocation(), diag::note_within_field_of_type) in checkIsValidOpenCLKernelParameter()
9603 << OuterField->getType(); in checkIsValidOpenCLKernelParameter()
9606 S.Diag(FD->getLocation(), diag::note_illegal_field_declared_here) in checkIsValidOpenCLKernelParameter()
9607 << QT->isPointerType() in checkIsValidOpenCLKernelParameter()
9619 while (!DC->isFileContext() && !DC->isFunctionOrMethod()) in getTagInjectionContext()
9620 DC = DC->getParent(); in getTagInjectionContext()
9628 while (S->isClassScope() || in getTagInjectionScope()
9630 S->isFunctionPrototypeScope()) || in getTagInjectionScope()
9631 ((S->getFlags() & Scope::DeclScope) == 0) || in getTagInjectionScope()
9632 (S->getEntity() && S->getEntity()->isTransparentContext())) in getTagInjectionScope()
9633 S = S->getParent(); in getTagInjectionScope()
9655 const auto *FPT = FD->getType()->castAs<FunctionProtoType>(); in isStdBuiltin()
9656 return FPT->getNumParams() == 1 && !FPT->isVariadic(); in isStdBuiltin()
9669 QualType R = TInfo->getType(); in ActOnFunctionDeclarator()
9671 assert(R->isFunctionType()); in ActOnFunctionDeclarator()
9672 if (R.getCanonicalType()->castAs<FunctionType>()->getCmseNSCallAttr()) in ActOnFunctionDeclarator()
9678 if (!TemplateParamLists.empty() && !TemplateParamLists.back()->empty() && in ActOnFunctionDeclarator()
9679 Invented->getDepth() == TemplateParamLists.back()->getDepth()) in ActOnFunctionDeclarator()
9717 if (OriginalLexicalContext && OriginalLexicalContext->isObjCContainer()) in ActOnFunctionDeclarator()
9718 NewFD->setTopLevelDeclInObjCContainer(); in ActOnFunctionDeclarator()
9720 // Set the lexical context. If this is a function-scope declaration, or has a in ActOnFunctionDeclarator()
9723 NewFD->setLexicalDeclContext(CurContext); in ActOnFunctionDeclarator()
9726 NewFD->setLocalExternDecl(); in ActOnFunctionDeclarator()
9730 // with an in-class definition (when such a definition is not attached to in ActOnFunctionDeclarator()
9731 // the global module). User-specified 'inline' overrides this (set when in ActOnFunctionDeclarator()
9735 NewFD->isConstexpr() || NewFD->isConsteval() || in ActOnFunctionDeclarator()
9736 !NewFD->getOwningModule() || in ActOnFunctionDeclarator()
9737 NewFD->isFromGlobalModule() || in ActOnFunctionDeclarator()
9738 NewFD->getOwningModule()->isHeaderLikeModule(); in ActOnFunctionDeclarator()
9744 // Pre-C++20 [class.friend]p5 in ActOnFunctionDeclarator()
9748 // Such a function is implicitly an inline function if it is attached in ActOnFunctionDeclarator()
9750 NewFD->setImplicitlyInline(ImplicitInlineCXX20); in ActOnFunctionDeclarator()
9757 dyn_cast<CXXRecordDecl>(NewFD->getDeclContext())) { in ActOnFunctionDeclarator()
9758 if (Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided()) in ActOnFunctionDeclarator()
9759 NewFD->setIsPureVirtual(true); in ActOnFunctionDeclarator()
9763 if (isVirtual && Parent->isUnion()) { in ActOnFunctionDeclarator()
9765 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9767 if ((Parent->isClass() || Parent->isStruct()) && in ActOnFunctionDeclarator()
9768 Parent->hasAttr<SYCLSpecialClassAttr>() && in ActOnFunctionDeclarator()
9769 NewFD->getKind() == Decl::Kind::CXXMethod && NewFD->getIdentifier() && in ActOnFunctionDeclarator()
9770 NewFD->getName() == "__init" && D.isFunctionDefinition()) { in ActOnFunctionDeclarator()
9771 if (auto *Def = Parent->getDefinition()) in ActOnFunctionDeclarator()
9772 Def->setInitMethod(true); in ActOnFunctionDeclarator()
9780 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9797 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9799 if (TemplateParams->size() > 0) { in ActOnFunctionDeclarator()
9804 Diag(NewFD->getLocation(), diag::err_destructor_template); in ActOnFunctionDeclarator()
9805 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9809 << SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc); in ActOnFunctionDeclarator()
9810 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9816 if (DC->isDependentContext()) { in ActOnFunctionDeclarator()
9823 NewFD->getLocation(), in ActOnFunctionDeclarator()
9826 FunctionTemplate->setLexicalDeclContext(CurContext); in ActOnFunctionDeclarator()
9827 NewFD->setDescribedFunctionTemplate(FunctionTemplate); in ActOnFunctionDeclarator()
9831 NewFD->setTemplateParameterListsInfo(Context, in ActOnFunctionDeclarator()
9840 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists); in ActOnFunctionDeclarator()
9845 SourceRange RemoveRange = TemplateParams->getSourceRange(); in ActOnFunctionDeclarator()
9848 // template-id, we're actually silently creating a problem: in ActOnFunctionDeclarator()
9874 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9880 NewFD->setTemplateParameterListsInfo(Context, TemplateParamLists); in ActOnFunctionDeclarator()
9887 // If this is a function template specialization and the unqualified-id of in ActOnFunctionDeclarator()
9888 // the declarator-id is a template-id, convert the template argument list in ActOnFunctionDeclarator()
9893 TemplateArgs.setLAngleLoc(TemplateId->LAngleLoc); in ActOnFunctionDeclarator()
9894 TemplateArgs.setRAngleLoc(TemplateId->RAngleLoc); in ActOnFunctionDeclarator()
9895 ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(), in ActOnFunctionDeclarator()
9896 TemplateId->NumArgs); in ActOnFunctionDeclarator()
9906 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9911 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
9913 FunctionTemplate->setInvalidDecl(); in ActOnFunctionDeclarator()
9919 // member-specification of a class declaration; see 10.3. in ActOnFunctionDeclarator()
9921 if (isVirtual && !NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
9925 } else if (!CurContext->isRecord()) { in ActOnFunctionDeclarator()
9930 } else if (NewFD->getDescribedFunctionTemplate()) { in ActOnFunctionDeclarator()
9938 NewFD->setVirtualAsWritten(true); in ActOnFunctionDeclarator()
9942 NewFD->getReturnType()->isUndeducedType()) in ActOnFunctionDeclarator()
9949 if (isInline && !NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
9950 if (CurContext->isFunctionOrMethod()) { in ActOnFunctionDeclarator()
9962 if (hasExplicit && !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
9964 if (!CurContext->isRecord()) { in ActOnFunctionDeclarator()
9983 NewFD->setImplicitlyInline(); in ActOnFunctionDeclarator()
9993 NewFD->setConstexprKind(getLangOpts().CPlusPlus20 in ActOnFunctionDeclarator()
10001 (NewFD->getOverloadedOperator() == OO_New || in ActOnFunctionDeclarator()
10002 NewFD->getOverloadedOperator() == OO_Array_New || in ActOnFunctionDeclarator()
10003 NewFD->getOverloadedOperator() == OO_Delete || in ActOnFunctionDeclarator()
10004 NewFD->getOverloadedOperator() == OO_Array_Delete)) { in ActOnFunctionDeclarator()
10008 NewFD->setConstexprKind(ConstexprSpecKind::Constexpr); in ActOnFunctionDeclarator()
10021 NewFD->setModulePrivate(); in ActOnFunctionDeclarator()
10023 FunctionTemplate->setModulePrivate(); in ActOnFunctionDeclarator()
10029 FunctionTemplate->setObjectOfFriendDecl(); in ActOnFunctionDeclarator()
10030 FunctionTemplate->setAccess(AS_public); in ActOnFunctionDeclarator()
10032 NewFD->setObjectOfFriendDecl(); in ActOnFunctionDeclarator()
10033 NewFD->setAccess(AS_public); in ActOnFunctionDeclarator()
10044 NewFD->setDefaulted(); in ActOnFunctionDeclarator()
10048 NewFD->setDeletedAsWritten(); in ActOnFunctionDeclarator()
10058 // If a member function is attached to the global module and is defined in ActOnFunctionDeclarator()
10060 NewFD->setImplicitlyInline(ImplicitInlineCXX20); in ActOnFunctionDeclarator()
10065 // The declaration in an explicit-specialization shall not be an in ActOnFunctionDeclarator()
10066 // export-declaration. An explicit specialization shall not use a in ActOnFunctionDeclarator()
10067 // storage-class-specifier other than thread_local. in ActOnFunctionDeclarator()
10069 // We diagnose friend declarations with storage-class-specifiers in ActOnFunctionDeclarator()
10078 if (SC == SC_Static && !CurContext->isRecord() && DC->isRecord()) { in ActOnFunctionDeclarator()
10080 "Out-of-line member function should be a CXXMethodDecl"); in ActOnFunctionDeclarator()
10086 // Complain about the 'static' specifier if it's on an out-of-line in ActOnFunctionDeclarator()
10090 // out-of-line member function template declaration and class member in ActOnFunctionDeclarator()
10094 cast<CXXRecordDecl>(DC)->getDescribedClassTemplate()) || in ActOnFunctionDeclarator()
10096 NewFD->getDescribedFunctionTemplate())) in ActOnFunctionDeclarator()
10105 // A deallocation function with no exception-specification is treated in ActOnFunctionDeclarator()
10107 const FunctionProtoType *FPT = R->getAs<FunctionProtoType>(); in ActOnFunctionDeclarator()
10110 getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec()) in ActOnFunctionDeclarator()
10111 NewFD->setType(Context.getFunctionType( in ActOnFunctionDeclarator()
10112 FPT->getReturnType(), FPT->getParamTypes(), in ActOnFunctionDeclarator()
10113 FPT->getExtProtoInfo().withExceptionSpec(EST_BasicNoexcept))); in ActOnFunctionDeclarator()
10116 // If an inline function or variable that is attached to a named module in ActOnFunctionDeclarator()
10123 NewFD->isInNamedModule()) { in ActOnFunctionDeclarator()
10134 // Handle GNU asm-label extension (encoded as an attribute). in ActOnFunctionDeclarator()
10138 NewFD->addAttr(AsmLabelAttr::Create(Context, SE->getString(), in ActOnFunctionDeclarator()
10140 SE->getStrTokenLoc(0))); in ActOnFunctionDeclarator()
10143 ExtnameUndeclaredIdentifiers.find(NewFD->getIdentifier()); in ActOnFunctionDeclarator()
10146 NewFD->addAttr(I->second); in ActOnFunctionDeclarator()
10149 Diag(NewFD->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnFunctionDeclarator()
10161 // Check for C99 6.7.5.3p10 - foo(void) is a non-varargs in ActOnFunctionDeclarator()
10169 assert(Param->getDeclContext() != NewFD && "Was set before ?"); in ActOnFunctionDeclarator()
10170 Param->setDeclContext(NewFD); in ActOnFunctionDeclarator()
10173 if (Param->isInvalidDecl()) in ActOnFunctionDeclarator()
10174 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10184 getTagInjectionContext(NewFD->getLexicalDeclContext()); in ActOnFunctionDeclarator()
10192 TD = cast<EnumDecl>(ECD->getDeclContext()); in ActOnFunctionDeclarator()
10196 DeclContext *TagDC = TD->getLexicalDeclContext(); in ActOnFunctionDeclarator()
10197 if (!TagDC->containsDecl(TD)) in ActOnFunctionDeclarator()
10199 TagDC->removeDecl(TD); in ActOnFunctionDeclarator()
10200 TD->setDeclContext(NewFD); in ActOnFunctionDeclarator()
10201 NewFD->addDecl(TD); in ActOnFunctionDeclarator()
10209 TD->setLexicalDeclContext(TagDC); in ActOnFunctionDeclarator()
10212 } else if (const FunctionProtoType *FT = R->getAs<FunctionProtoType>()) { in ActOnFunctionDeclarator()
10223 for (const auto &AI : FT->param_types()) { in ActOnFunctionDeclarator()
10226 Param->setScopeInfo(0, Params.size()); in ActOnFunctionDeclarator()
10230 assert(R->isFunctionNoProtoType() && NewFD->getNumParams() == 0 && in ActOnFunctionDeclarator()
10231 "Should not need args for typedef of non-prototype fn"); in ActOnFunctionDeclarator()
10235 NewFD->setParams(Params); in ActOnFunctionDeclarator()
10238 NewFD->addAttr( in ActOnFunctionDeclarator()
10243 if (!NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
10244 NewFD->getReturnType()->isVariablyModifiedType()) { in ActOnFunctionDeclarator()
10245 Diag(NewFD->getLocation(), diag::err_vm_func_decl); in ActOnFunctionDeclarator()
10246 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10251 !NewFD->hasAttr<SectionAttr>()) in ActOnFunctionDeclarator()
10252 NewFD->addAttr(PragmaClangTextSectionAttr::CreateImplicit( in ActOnFunctionDeclarator()
10258 !NewFD->hasAttr<SectionAttr>()) { in ActOnFunctionDeclarator()
10259 NewFD->addAttr(SectionAttr::CreateImplicit( in ActOnFunctionDeclarator()
10260 Context, CodeSegStack.CurrentValue->getString(), in ActOnFunctionDeclarator()
10262 if (UnifySection(CodeSegStack.CurrentValue->getString(), in ActOnFunctionDeclarator()
10266 NewFD->dropAttr<SectionAttr>(); in ActOnFunctionDeclarator()
10272 !NewFD->hasAttr<StrictGuardStackCheckAttr>()) in ActOnFunctionDeclarator()
10273 NewFD->addAttr(StrictGuardStackCheckAttr::CreateImplicit( in ActOnFunctionDeclarator()
10278 if (!NewFD->hasAttr<CodeSegAttr>()) { in ActOnFunctionDeclarator()
10281 NewFD->addAttr(SAttr); in ActOnFunctionDeclarator()
10287 const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); in ActOnFunctionDeclarator()
10288 if (NewTVA && !NewTVA->isDefaultVersion() && in ActOnFunctionDeclarator()
10301 LangAS AddressSpace = NewFD->getReturnType().getAddressSpace(); in ActOnFunctionDeclarator()
10303 Diag(NewFD->getLocation(), diag::err_return_value_with_address_space); in ActOnFunctionDeclarator()
10304 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10310 if (!NewFD->isInvalidDecl() && NewFD->isMain()) in ActOnFunctionDeclarator()
10313 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint()) in ActOnFunctionDeclarator()
10316 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
10323 assert((NewFD->isInvalidDecl() || !D.isRedeclaration() || in ActOnFunctionDeclarator()
10327 // Diagnose no-prototype function declarations with calling conventions that in ActOnFunctionDeclarator()
10330 const FunctionType *FT = NewFD->getType()->castAs<FunctionType>(); in ActOnFunctionDeclarator()
10332 CallingConv CC = FT->getExtInfo().getCC(); in ActOnFunctionDeclarator()
10338 Diag(NewFD->getLocation(), DiagID) in ActOnFunctionDeclarator()
10343 if (NewFD->getReturnType().hasNonTrivialToPrimitiveDestructCUnion() || in ActOnFunctionDeclarator()
10344 NewFD->getReturnType().hasNonTrivialToPrimitiveCopyCUnion()) in ActOnFunctionDeclarator()
10345 checkNonTrivialCUnion(NewFD->getReturnType(), in ActOnFunctionDeclarator()
10346 NewFD->getReturnTypeSourceRange().getBegin(), in ActOnFunctionDeclarator()
10357 NewFD->isReplaceableGlobalAllocationFunction() && in ActOnFunctionDeclarator()
10358 !NewFD->hasAttr<UsedAttr>()) in ActOnFunctionDeclarator()
10361 << NewFD->getDeclName(); in ActOnFunctionDeclarator()
10363 if (Expr *TRC = NewFD->getTrailingRequiresClause()) { in ActOnFunctionDeclarator()
10365 // The optional requires-clause in an init-declarator or in ActOnFunctionDeclarator()
10366 // member-declarator shall be present only if the declarator declares a in ActOnFunctionDeclarator()
10371 // - a template, in ActOnFunctionDeclarator()
10372 // - an entity defined or created in a templated entity, in ActOnFunctionDeclarator()
10373 // - a member of a templated entity, in ActOnFunctionDeclarator()
10374 // - an enumerator for an enumeration that is a templated entity, or in ActOnFunctionDeclarator()
10375 // - the closure type of a lambda-expression appearing in the in ActOnFunctionDeclarator()
10390 // requires-clause unless it declares a function template. in ActOnFunctionDeclarator()
10393 // definition, and since a non-template friend declaration with a in ActOnFunctionDeclarator()
10394 // trailing requires-clause must be a definition, we diagnose in ActOnFunctionDeclarator()
10396 // requires-clauses on the same path as explicit specializations in ActOnFunctionDeclarator()
10399 Diag(TRC->getBeginLoc(), diag::err_non_temp_spec_requires_clause) in ActOnFunctionDeclarator()
10401 } else if (isFriend && NewFD->isTemplated() && in ActOnFunctionDeclarator()
10404 // A non-template friend declaration with a requires-clause shall be in ActOnFunctionDeclarator()
10406 Diag(NewFD->getBeginLoc(), in ActOnFunctionDeclarator()
10408 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10409 } else if (!NewFD->isTemplated() || in ActOnFunctionDeclarator()
10411 Diag(TRC->getBeginLoc(), in ActOnFunctionDeclarator()
10418 // they may have different constexpr-ness compared to their in ActOnFunctionDeclarator()
10434 // type is dependent, or if its template-id is dependent. in ActOnFunctionDeclarator()
10436 DC->isDependentContext() || NewFD->getType()->isDependentType() || in ActOnFunctionDeclarator()
10446 // For class-scope explicit specializations of function templates, in ActOnFunctionDeclarator()
10450 CurContext->isRecord() && CurContext->isDependentContext(); in ActOnFunctionDeclarator()
10463 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10464 } else if (!NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
10467 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10471 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10475 if (!NewFD->isInvalidDecl() && NewFD->isMain()) in ActOnFunctionDeclarator()
10478 if (!NewFD->isInvalidDecl() && NewFD->isMSVCRTEntryPoint()) in ActOnFunctionDeclarator()
10481 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
10489 assert((NewFD->isInvalidDecl() || NewFD->isMultiVersion() || in ActOnFunctionDeclarator()
10498 if (isFriend && NewFD->getPreviousDecl()) { in ActOnFunctionDeclarator()
10500 if (!NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
10501 Access = NewFD->getPreviousDecl()->getAccess(); in ActOnFunctionDeclarator()
10503 NewFD->setAccess(Access); in ActOnFunctionDeclarator()
10504 if (FunctionTemplate) FunctionTemplate->setAccess(Access); in ActOnFunctionDeclarator()
10507 if (NewFD->isOverloadedOperator() && !DC->isRecord() && in ActOnFunctionDeclarator()
10508 PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary)) in ActOnFunctionDeclarator()
10509 PrincipalDecl->setNonMemberOperator(); in ActOnFunctionDeclarator()
10515 FunctionTemplate->getPreviousDecl(); in ActOnFunctionDeclarator()
10516 CheckTemplateParameterList(FunctionTemplate->getTemplateParameters(), in ActOnFunctionDeclarator()
10517 PrevTemplate ? PrevTemplate->getTemplateParameters() in ActOnFunctionDeclarator()
10524 DC && DC->isRecord() && in ActOnFunctionDeclarator()
10525 DC->isDependentContext()) in ActOnFunctionDeclarator()
10530 if (NewFD->isInvalidDecl()) { in ActOnFunctionDeclarator()
10536 if (isa<CXXRecordDecl>(NewFD->getDeclContext())) in ActOnFunctionDeclarator()
10537 NewFD->setAccess(AS_public); in ActOnFunctionDeclarator()
10541 // ...with the major exception of templated-scope or in ActOnFunctionDeclarator()
10542 // dependent-scope friend declarations. in ActOnFunctionDeclarator()
10555 (D.getCXXScopeSpec().getScopeRep()->isDependent() || in ActOnFunctionDeclarator()
10556 (!Previous.empty() && CurContext->isDependentContext()))) { in ActOnFunctionDeclarator()
10558 } else if (NewFD->isCPUDispatchMultiVersion() || in ActOnFunctionDeclarator()
10559 NewFD->isCPUSpecificMultiVersion()) { in ActOnFunctionDeclarator()
10563 // The user tried to provide an out-of-line definition for a in ActOnFunctionDeclarator()
10572 // void X::f() { } // ill-formed in ActOnFunctionDeclarator()
10575 // matches (e.g., those that differ only in cv-qualifiers and in ActOnFunctionDeclarator()
10587 } else if (isFriend && cast<CXXRecordDecl>(CurContext)->isLocalClass()) { in ActOnFunctionDeclarator()
10595 isa<CXXMethodDecl>(NewFD) && NewFD->isOutOfLine() && in ActOnFunctionDeclarator()
10598 // An out-of-line member function declaration must also be a in ActOnFunctionDeclarator()
10605 Diag(NewFD->getLocation(), diag::ext_out_of_line_declaration) in ActOnFunctionDeclarator()
10612 if (!NewFD->isInvalidDecl() && S->getDepth() == 0 && Name.isIdentifier()) in ActOnFunctionDeclarator()
10615 if (NewFD->hasAttr<HLSLShaderAttr>()) in ActOnFunctionDeclarator()
10623 if (unsigned BuiltinID = II->getBuiltinID()) { in ActOnFunctionDeclarator()
10626 NewFD->getDeclContext()->getRedeclContext()->isFileContext()) { in ActOnFunctionDeclarator()
10627 if (NewFD->getLanguageLinkage() == CLanguageLinkage) { in ActOnFunctionDeclarator()
10631 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID)); in ActOnFunctionDeclarator()
10639 NewFD->getType(), BuiltinType)) in ActOnFunctionDeclarator()
10640 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID)); in ActOnFunctionDeclarator()
10643 } else if (InStdNamespace && NewFD->isInStdNamespace() && in ActOnFunctionDeclarator()
10645 NewFD->addAttr(BuiltinAttr::CreateImplicit(Context, BuiltinID)); in ActOnFunctionDeclarator()
10656 if (NewFD->hasAttr<OverloadableAttr>() && in ActOnFunctionDeclarator()
10657 !NewFD->getType()->getAs<FunctionProtoType>()) { in ActOnFunctionDeclarator()
10658 Diag(NewFD->getLocation(), in ActOnFunctionDeclarator()
10661 NewFD->dropAttr<OverloadableAttr>(); in ActOnFunctionDeclarator()
10666 if (!DC->isRecord() && NewFD->isExternallyVisible()) in ActOnFunctionDeclarator()
10684 if (NewFD->isFirstDecl() && !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
10689 NewFD->setRangeEnd(D.getSourceRange().getEnd()); in ActOnFunctionDeclarator()
10700 IdentifierInfo *II = NewFD->getIdentifier(); in ActOnFunctionDeclarator()
10701 if (II && II->isStr(CUDA().getConfigureFuncName()) && in ActOnFunctionDeclarator()
10702 !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
10703 NewFD->getDeclContext()->getRedeclContext()->isTranslationUnit()) { in ActOnFunctionDeclarator()
10704 if (!R->castAs<FunctionType>()->getReturnType()->isScalarType()) in ActOnFunctionDeclarator()
10705 Diag(NewFD->getLocation(), diag::err_config_scalar_return) in ActOnFunctionDeclarator()
10711 // in device-side CUDA code, unless someone passed in ActOnFunctionDeclarator()
10712 // -fcuda-allow-variadic-functions. in ActOnFunctionDeclarator()
10713 if (!getLangOpts().CUDAAllowVariadicFunctions && NewFD->isVariadic() && in ActOnFunctionDeclarator()
10714 (NewFD->hasAttr<CUDADeviceAttr>() || in ActOnFunctionDeclarator()
10715 NewFD->hasAttr<CUDAGlobalAttr>()) && in ActOnFunctionDeclarator()
10716 !(II && II->isStr("printf") && NewFD->isExternC() && in ActOnFunctionDeclarator()
10718 Diag(NewFD->getLocation(), diag::err_variadic_device_fn); in ActOnFunctionDeclarator()
10726 if (getLangOpts().OpenCL && NewFD->hasAttr<OpenCLKernelAttr>()) { in ActOnFunctionDeclarator()
10733 // OpenCL v1.2, s6.9 -- Kernels can only have return type void. in ActOnFunctionDeclarator()
10734 if (!NewFD->getReturnType()->isVoidType()) { in ActOnFunctionDeclarator()
10735 SourceRange RTRange = NewFD->getReturnTypeSourceRange(); in ActOnFunctionDeclarator()
10743 for (auto *Param : NewFD->parameters()) in ActOnFunctionDeclarator()
10747 if (DC->isRecord()) { in ActOnFunctionDeclarator()
10763 NewFD->setFriendConstraintRefersToEnclosingTemplate(true); in ActOnFunctionDeclarator()
10769 Diag(NewFD->getBeginLoc(), in ActOnFunctionDeclarator()
10771 NewFD->setInvalidDecl(); in ActOnFunctionDeclarator()
10776 if (NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
10777 FunctionTemplate->setInvalidDecl(); in ActOnFunctionDeclarator()
10781 if (isMemberSpecialization && !NewFD->isInvalidDecl()) in ActOnFunctionDeclarator()
10785 for (const ParmVarDecl *Param : NewFD->parameters()) { in ActOnFunctionDeclarator()
10786 QualType PT = Param->getType(); in ActOnFunctionDeclarator()
10788 // OpenCL 2.0 pipe restrictions forbids pipe packet types to be non-value in ActOnFunctionDeclarator()
10791 if(const PipeType *PipeTy = PT->getAs<PipeType>()) { in ActOnFunctionDeclarator()
10792 QualType ElemTy = PipeTy->getElementType(); in ActOnFunctionDeclarator()
10793 if (ElemTy->isReferenceType() || ElemTy->isPointerType()) { in ActOnFunctionDeclarator()
10794 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type ); in ActOnFunctionDeclarator()
10801 if (PT->getUnqualifiedDesugaredType()->isWebAssemblyTableType()) { in ActOnFunctionDeclarator()
10802 Diag(Param->getTypeSpecStartLoc(), in ActOnFunctionDeclarator()
10811 if (const auto *attr = NewFD->getAttr<AvailabilityAttr>()) { in ActOnFunctionDeclarator()
10812 if (NewFD->hasAttr<ConstructorAttr>()) { in ActOnFunctionDeclarator()
10813 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer) in ActOnFunctionDeclarator()
10815 NewFD->dropAttr<AvailabilityAttr>(); in ActOnFunctionDeclarator()
10817 if (NewFD->hasAttr<DestructorAttr>()) { in ActOnFunctionDeclarator()
10818 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer) in ActOnFunctionDeclarator()
10820 NewFD->dropAttr<AvailabilityAttr>(); in ActOnFunctionDeclarator()
10831 if (const auto *NBA = NewFD->getAttr<NoBuiltinAttr>()) in ActOnFunctionDeclarator()
10835 Diag(NBA->getLocation(), in ActOnFunctionDeclarator()
10837 << NBA->getSpelling(); in ActOnFunctionDeclarator()
10840 Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition) in ActOnFunctionDeclarator()
10841 << NBA->getSpelling(); in ActOnFunctionDeclarator()
10851 !NewFD->isInvalidDecl() && in ActOnFunctionDeclarator()
10860 /// the class and nested classes -- this includes compiler-generated special
10861 /// member functions -- are put in the specified segment."
10872 const CXXRecordDecl *Parent = Method->getParent(); in getImplicitCodeSegAttrFromClass()
10873 if (const auto *SAttr = Parent->getAttr<CodeSegAttr>()) { in getImplicitCodeSegAttrFromClass()
10874 Attr *NewAttr = SAttr->clone(S.getASTContext()); in getImplicitCodeSegAttrFromClass()
10875 NewAttr->setImplicit(true); in getImplicitCodeSegAttrFromClass()
10884 while ((Parent = dyn_cast<CXXRecordDecl>(Parent->getParent()))) { in getImplicitCodeSegAttrFromClass()
10885 if (const auto *SAttr = Parent->getAttr<CodeSegAttr>()) { in getImplicitCodeSegAttrFromClass()
10886 Attr *NewAttr = SAttr->clone(S.getASTContext()); in getImplicitCodeSegAttrFromClass()
10887 NewAttr->setImplicit(true); in getImplicitCodeSegAttrFromClass()
10898 if (!FD->hasAttr<SectionAttr>() && IsDefinition && in getImplicitCodeSegOrSectionAttrForFunction()
10901 getASTContext(), CodeSegStack.CurrentValue->getString(), in getImplicitCodeSegOrSectionAttrForFunction()
10908 if (!NewD->getLexicalDeclContext()->isDependentContext()) in canFullyTypeCheckRedeclaration()
10911 // For dependently-typed local extern declarations and friends, we can't in canFullyTypeCheckRedeclaration()
10918 if (NewT->isDependentType() && in canFullyTypeCheckRedeclaration()
10919 (NewD->isLocalExternDecl() || NewD->getFriendObjectKind())) in canFullyTypeCheckRedeclaration()
10924 if (OldT->isDependentType() && OldD->isLocalExternDecl()) in canFullyTypeCheckRedeclaration()
10931 if (!D->getLexicalDeclContext()->isDependentContext()) in shouldLinkDependentDeclWithPrevious()
10944 // this by checking for a file-scope function. We do not want this to apply in shouldLinkDependentDeclWithPrevious()
10947 if (D->getFriendObjectKind() && D->getDeclContext()->isFileContext()) in shouldLinkDependentDeclWithPrevious()
10953 canFullyTypeCheckRedeclaration(VD, PrevVD, VD->getType(), in shouldLinkDependentDeclWithPrevious()
10954 PrevVD->getType()); in shouldLinkDependentDeclWithPrevious()
10962 const auto *TA = FD->getAttr<TargetAttr>(); in CheckMultiVersionValue()
10963 const auto *TVA = FD->getAttr<TargetVersionAttr>(); in CheckMultiVersionValue()
10972 S.getASTContext().getTargetInfo().parseTargetAttr(TA->getFeaturesStr()); in CheckMultiVersionValue()
10974 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) in CheckMultiVersionValue()
10980 if (Feat[0] == '-') { in CheckMultiVersionValue()
10981 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) in CheckMultiVersionValue()
10982 << Feature << ("no-" + BareFeat).str(); in CheckMultiVersionValue()
10988 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) in CheckMultiVersionValue()
10997 TVA->getFeatures(Feats); in CheckMultiVersionValue()
11000 S.Diag(FD->getLocation(), diag::err_bad_multiversion_option) in CheckMultiVersionValue()
11009 // Provide a white-list of attributes that are allowed to be combined with
11034 S.Diag(FD->getLocation(), diag::err_multiversion_disallowed_other_attr) in checkNonMultiVersionCompatAttributes()
11037 S.Diag(CausedFD->getLocation(), diag::note_multiversioning_caused_here); in checkNonMultiVersionCompatAttributes()
11041 for (const Attr *A : FD->attrs()) { in checkNonMultiVersionCompatAttributes()
11042 switch (A->getKind()) { in checkNonMultiVersionCompatAttributes()
11064 if (!AttrCompatibleWithMultiVersion(A->getKind(), MVKind)) in checkNonMultiVersionCompatAttributes()
11101 !OldFD->getType()->getAs<FunctionProtoType>()) { in areMultiversionVariantFunctionsCompatible()
11102 Diag(OldFD->getLocation(), NoProtoDiagID); in areMultiversionVariantFunctionsCompatible()
11108 !NewFD->getType()->getAs<FunctionProtoType>()) in areMultiversionVariantFunctionsCompatible()
11109 return Diag(NewFD->getLocation(), NoProtoDiagID); in areMultiversionVariantFunctionsCompatible()
11112 NewFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) in areMultiversionVariantFunctionsCompatible()
11117 if (NewCXXFD->isVirtual()) in areMultiversionVariantFunctionsCompatible()
11130 if (NewFD->isDeleted()) in areMultiversionVariantFunctionsCompatible()
11134 if (NewFD->isDefaulted()) in areMultiversionVariantFunctionsCompatible()
11138 if (!ConstexprSupported && NewFD->isConstexpr()) in areMultiversionVariantFunctionsCompatible()
11140 << (NewFD->isConsteval() ? ConstevalFuncs : ConstexprFuncs); in areMultiversionVariantFunctionsCompatible()
11142 QualType NewQType = Context.getCanonicalType(NewFD->getType()); in areMultiversionVariantFunctionsCompatible()
11144 QualType NewReturnType = NewType->getReturnType(); in areMultiversionVariantFunctionsCompatible()
11146 if (NewReturnType->isUndeducedType()) in areMultiversionVariantFunctionsCompatible()
11152 QualType OldQType = Context.getCanonicalType(OldFD->getType()); in areMultiversionVariantFunctionsCompatible()
11154 FunctionType::ExtInfo OldTypeInfo = OldType->getExtInfo(); in areMultiversionVariantFunctionsCompatible()
11155 FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo(); in areMultiversionVariantFunctionsCompatible()
11157 const auto *OldFPT = OldFD->getType()->getAs<FunctionProtoType>(); in areMultiversionVariantFunctionsCompatible()
11158 const auto *NewFPT = NewFD->getType()->getAs<FunctionProtoType>(); in areMultiversionVariantFunctionsCompatible()
11163 OldFPT->getAArch64SMEAttributes() ^ NewFPT->getAArch64SMEAttributes(); in areMultiversionVariantFunctionsCompatible()
11164 // Arm-streaming, arm-streaming-compatible and non-streaming versions in areMultiversionVariantFunctionsCompatible()
11174 QualType OldReturnType = OldType->getReturnType(); in areMultiversionVariantFunctionsCompatible()
11179 if (OldFD->getConstexprKind() != NewFD->getConstexprKind()) in areMultiversionVariantFunctionsCompatible()
11182 if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified()) in areMultiversionVariantFunctionsCompatible()
11185 if (OldFD->getFormalLinkage() != NewFD->getFormalLinkage()) in areMultiversionVariantFunctionsCompatible()
11188 if (!CLinkageMayDiffer && OldFD->isExternC() != NewFD->isExternC()) in areMultiversionVariantFunctionsCompatible()
11191 if (CheckEquivalentExceptionSpec(OldFPT, OldFD->getLocation(), NewFPT, in areMultiversionVariantFunctionsCompatible()
11192 NewFD->getLocation())) in areMultiversionVariantFunctionsCompatible()
11203 S.Diag(NewFD->getLocation(), diag::err_multiversion_not_supported); in CheckMultiVersionAdditionalRules()
11205 S.Diag(OldFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalRules()
11221 if (OldFD && CausesMV && OldFD->isUsed(false)) in CheckMultiVersionAdditionalRules()
11222 return S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used); in CheckMultiVersionAdditionalRules()
11226 PartialDiagnosticAt(NewFD->getLocation(), in CheckMultiVersionAdditionalRules()
11228 PartialDiagnosticAt(NewFD->getLocation(), in CheckMultiVersionAdditionalRules()
11231 PartialDiagnosticAt(NewFD->getLocation(), in CheckMultiVersionAdditionalRules()
11241 /// This sets NewFD->isInvalidDecl() to true if there was an error.
11245 MultiVersionKind MVKind = FD->getMultiVersionKind(); in CheckMultiVersionFirstFunction()
11248 const auto *TA = FD->getAttr<TargetAttr>(); in CheckMultiVersionFirstFunction()
11249 const auto *TVA = FD->getAttr<TargetVersionAttr>(); in CheckMultiVersionFirstFunction()
11252 if (TA && !TA->isDefaultVersion()) in CheckMultiVersionFirstFunction()
11256 if (TVA && TVA->isDefaultVersion()) in CheckMultiVersionFirstFunction()
11260 FD->setInvalidDecl(); in CheckMultiVersionFirstFunction()
11265 FD->setInvalidDecl(); in CheckMultiVersionFirstFunction()
11269 FD->setIsMultiVersion(); in CheckMultiVersionFirstFunction()
11274 for (const Decl *D = FD->getPreviousDecl(); D; D = D->getPreviousDecl()) { in PreviousDeclsHaveMultiVersionAttribute()
11275 if (D->getAsFunction()->getMultiVersionKind() != MultiVersionKind::None) in PreviousDeclsHaveMultiVersionAttribute()
11283 if (!From->getASTContext().getTargetInfo().getTriple().isAArch64()) in patchDefaultTargetVersion()
11286 MultiVersionKind MVKindFrom = From->getMultiVersionKind(); in patchDefaultTargetVersion()
11287 MultiVersionKind MVKindTo = To->getMultiVersionKind(); in patchDefaultTargetVersion()
11292 To->addAttr(TargetVersionAttr::CreateImplicit( in patchDefaultTargetVersion()
11293 To->getASTContext(), "default", To->getSourceRange())); in patchDefaultTargetVersion()
11301 assert(!OldFD->isMultiVersion() && "Unexpected MultiVersion"); in CheckDeclarationCausesMultiVersioning()
11308 const auto *NewTA = NewFD->getAttr<TargetAttr>(); in CheckDeclarationCausesMultiVersioning()
11309 const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); in CheckDeclarationCausesMultiVersioning()
11310 const auto *OldTA = OldFD->getAttr<TargetAttr>(); in CheckDeclarationCausesMultiVersioning()
11314 if (NewTA && !NewTA->isDefaultVersion() && in CheckDeclarationCausesMultiVersioning()
11315 (!OldTA || OldTA->getFeaturesStr() == NewTA->getFeaturesStr())) in CheckDeclarationCausesMultiVersioning()
11320 if (NewTVA && NewTVA->isDefaultVersion()) in CheckDeclarationCausesMultiVersioning()
11327 NewFD->setInvalidDecl(); in CheckDeclarationCausesMultiVersioning()
11332 NewFD->setInvalidDecl(); in CheckDeclarationCausesMultiVersioning()
11337 if (NewTA && NewTA->isDefaultVersion() && !OldTA) { in CheckDeclarationCausesMultiVersioning()
11340 OldFD->setIsMultiVersion(); in CheckDeclarationCausesMultiVersioning()
11341 NewFD->setIsMultiVersion(); in CheckDeclarationCausesMultiVersioning()
11346 S.Diag(NewFD->getLocation(), diag::note_multiversioning_caused_here); in CheckDeclarationCausesMultiVersioning()
11347 NewFD->setInvalidDecl(); in CheckDeclarationCausesMultiVersioning()
11354 OldTA->getFeaturesStr()); in CheckDeclarationCausesMultiVersioning()
11358 NewTA->getFeaturesStr()); in CheckDeclarationCausesMultiVersioning()
11362 S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate); in CheckDeclarationCausesMultiVersioning()
11363 S.Diag(OldFD->getLocation(), diag::note_previous_declaration); in CheckDeclarationCausesMultiVersioning()
11364 NewFD->setInvalidDecl(); in CheckDeclarationCausesMultiVersioning()
11369 for (const auto *FD : OldFD->redecls()) { in CheckDeclarationCausesMultiVersioning()
11370 const auto *CurTA = FD->getAttr<TargetAttr>(); in CheckDeclarationCausesMultiVersioning()
11371 const auto *CurTVA = FD->getAttr<TargetVersionAttr>(); in CheckDeclarationCausesMultiVersioning()
11375 ((NewTA && (!CurTA || CurTA->isInherited())) || in CheckDeclarationCausesMultiVersioning()
11376 (NewTVA && (!CurTVA || CurTVA->isInherited())))) { in CheckDeclarationCausesMultiVersioning()
11377 S.Diag(FD->getLocation(), diag::err_multiversion_required_in_redecl) in CheckDeclarationCausesMultiVersioning()
11379 S.Diag(NewFD->getLocation(), diag::note_multiversioning_caused_here); in CheckDeclarationCausesMultiVersioning()
11380 NewFD->setInvalidDecl(); in CheckDeclarationCausesMultiVersioning()
11385 OldFD->setIsMultiVersion(); in CheckDeclarationCausesMultiVersioning()
11386 NewFD->setIsMultiVersion(); in CheckDeclarationCausesMultiVersioning()
11394 MultiVersionKind OldKind = Old->getMultiVersionKind(); in MultiVersionTypesCompatible()
11395 MultiVersionKind NewKind = New->getMultiVersionKind(); in MultiVersionTypesCompatible()
11401 if (Old->getASTContext().getTargetInfo().getTriple().isAArch64()) { in MultiVersionTypesCompatible()
11432 S.Diag(NewFD->getLocation(), diag::err_multiversion_types_mixed); in CheckMultiVersionAdditionalDecl()
11433 S.Diag(OldFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11434 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11442 const auto *NewTA = NewFD->getAttr<TargetAttr>(); in CheckMultiVersionAdditionalDecl()
11443 const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); in CheckMultiVersionAdditionalDecl()
11444 MultiVersionKind NewMVKind = NewFD->getMultiVersionKind(); in CheckMultiVersionAdditionalDecl()
11445 [[maybe_unused]] MultiVersionKind OldMVKind = OldFD->getMultiVersionKind(); in CheckMultiVersionAdditionalDecl()
11450 NewTA->getFeaturesStr()); in CheckMultiVersionAdditionalDecl()
11455 NewTVA->getFeatures(NewFeats); in CheckMultiVersionAdditionalDecl()
11460 S.CurContext->isRecord() && !NewFD->getFriendObjectKind(); in CheckMultiVersionAdditionalDecl()
11465 // Next, check ALL non-invalid non-overloads to see if this is a redeclaration in CheckMultiVersionAdditionalDecl()
11468 FunctionDecl *CurFD = ND->getAsFunction(); in CheckMultiVersionAdditionalDecl()
11469 if (!CurFD || CurFD->isInvalidDecl()) in CheckMultiVersionAdditionalDecl()
11481 const auto *CurTA = CurFD->getAttr<TargetAttr>(); in CheckMultiVersionAdditionalDecl()
11482 if (CurTA->getFeaturesStr() == NewTA->getFeaturesStr()) { in CheckMultiVersionAdditionalDecl()
11483 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11491 CurTA->getFeaturesStr()); in CheckMultiVersionAdditionalDecl()
11494 S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate); in CheckMultiVersionAdditionalDecl()
11495 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11496 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11502 if (const auto *CurTVA = CurFD->getAttr<TargetVersionAttr>()) { in CheckMultiVersionAdditionalDecl()
11503 if (CurTVA->getName() == NewTVA->getName()) { in CheckMultiVersionAdditionalDecl()
11504 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11510 CurTVA->getFeatures(CurFeats); in CheckMultiVersionAdditionalDecl()
11514 S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate); in CheckMultiVersionAdditionalDecl()
11515 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11516 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11519 } else if (const auto *CurClones = CurFD->getAttr<TargetClonesAttr>()) { in CheckMultiVersionAdditionalDecl()
11524 for (unsigned I = 0; I < CurClones->featuresStrs_size(); ++I) { in CheckMultiVersionAdditionalDecl()
11526 CurClones->getFeatures(CurFeats, I); in CheckMultiVersionAdditionalDecl()
11530 S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate); in CheckMultiVersionAdditionalDecl()
11531 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11532 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11541 if (const auto *CurClones = CurFD->getAttr<TargetClonesAttr>()) { in CheckMultiVersionAdditionalDecl()
11542 if (CurClones->featuresStrs_size() != NewClones->featuresStrs_size() || in CheckMultiVersionAdditionalDecl()
11543 !std::equal(CurClones->featuresStrs_begin(), in CheckMultiVersionAdditionalDecl()
11544 CurClones->featuresStrs_end(), in CheckMultiVersionAdditionalDecl()
11545 NewClones->featuresStrs_begin())) { in CheckMultiVersionAdditionalDecl()
11546 S.Diag(NewFD->getLocation(), diag::err_target_clone_doesnt_match); in CheckMultiVersionAdditionalDecl()
11547 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11548 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11551 } else if (const auto *CurTVA = CurFD->getAttr<TargetVersionAttr>()) { in CheckMultiVersionAdditionalDecl()
11553 CurTVA->getFeatures(CurFeats); in CheckMultiVersionAdditionalDecl()
11560 for (unsigned I = 0; I < NewClones->featuresStrs_size(); ++I) { in CheckMultiVersionAdditionalDecl()
11562 NewClones->getFeatures(NewFeats, I); in CheckMultiVersionAdditionalDecl()
11566 S.Diag(NewFD->getLocation(), diag::err_multiversion_duplicate); in CheckMultiVersionAdditionalDecl()
11567 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11568 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11576 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11581 const auto *CurCPUSpec = CurFD->getAttr<CPUSpecificAttr>(); in CheckMultiVersionAdditionalDecl()
11582 const auto *CurCPUDisp = CurFD->getAttr<CPUDispatchAttr>(); in CheckMultiVersionAdditionalDecl()
11587 CurFD->hasAttr<CPUDispatchAttr>()) { in CheckMultiVersionAdditionalDecl()
11588 if (CurCPUDisp->cpus_size() == NewCPUDisp->cpus_size() && in CheckMultiVersionAdditionalDecl()
11590 CurCPUDisp->cpus_begin(), CurCPUDisp->cpus_end(), in CheckMultiVersionAdditionalDecl()
11591 NewCPUDisp->cpus_begin(), in CheckMultiVersionAdditionalDecl()
11593 return Cur->getName() == New->getName(); in CheckMultiVersionAdditionalDecl()
11595 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11602 S.Diag(NewFD->getLocation(), diag::err_cpu_dispatch_mismatch); in CheckMultiVersionAdditionalDecl()
11603 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11604 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11608 if (CurCPUSpec->cpus_size() == NewCPUSpec->cpus_size() && in CheckMultiVersionAdditionalDecl()
11610 CurCPUSpec->cpus_begin(), CurCPUSpec->cpus_end(), in CheckMultiVersionAdditionalDecl()
11611 NewCPUSpec->cpus_begin(), in CheckMultiVersionAdditionalDecl()
11613 return Cur->getName() == New->getName(); in CheckMultiVersionAdditionalDecl()
11615 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11622 for (const IdentifierInfo *CurII : CurCPUSpec->cpus()) { in CheckMultiVersionAdditionalDecl()
11623 for (const IdentifierInfo *NewII : NewCPUSpec->cpus()) { in CheckMultiVersionAdditionalDecl()
11625 S.Diag(NewFD->getLocation(), diag::err_cpu_specific_multiple_defs) in CheckMultiVersionAdditionalDecl()
11627 S.Diag(CurFD->getLocation(), diag::note_previous_declaration); in CheckMultiVersionAdditionalDecl()
11628 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11639 // Else, this is simply a non-redecl case. Checking the 'value' is only in CheckMultiVersionAdditionalDecl()
11645 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11650 !OldFD->isMultiVersion(), NewMVKind)) { in CheckMultiVersionAdditionalDecl()
11651 NewFD->setInvalidDecl(); in CheckMultiVersionAdditionalDecl()
11656 if (!OldFD->isMultiVersion()) { in CheckMultiVersionAdditionalDecl()
11657 OldFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11658 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11664 NewFD->setIsMultiVersion(); in CheckMultiVersionAdditionalDecl()
11674 /// This sets NewFD->isInvalidDecl() to true if there was an error.
11680 const auto *NewTA = NewFD->getAttr<TargetAttr>(); in CheckMultiVersionFunction()
11681 const auto *NewTVA = NewFD->getAttr<TargetVersionAttr>(); in CheckMultiVersionFunction()
11682 const auto *NewCPUDisp = NewFD->getAttr<CPUDispatchAttr>(); in CheckMultiVersionFunction()
11683 const auto *NewCPUSpec = NewFD->getAttr<CPUSpecificAttr>(); in CheckMultiVersionFunction()
11684 const auto *NewClones = NewFD->getAttr<TargetClonesAttr>(); in CheckMultiVersionFunction()
11685 MultiVersionKind MVKind = NewFD->getMultiVersionKind(); in CheckMultiVersionFunction()
11690 if (NewFD->isMain()) { in CheckMultiVersionFunction()
11692 !(MVKind == MultiVersionKind::Target && !NewTA->isDefaultVersion()) && in CheckMultiVersionFunction()
11694 NewTVA->isDefaultVersion())) { in CheckMultiVersionFunction()
11695 S.Diag(NewFD->getLocation(), diag::err_multiversion_not_allowed_on_main); in CheckMultiVersionFunction()
11696 NewFD->setInvalidDecl(); in CheckMultiVersionFunction()
11712 if (!OldDecl || !OldDecl->getAsFunction() || in CheckMultiVersionFunction()
11713 !OldDecl->getDeclContext()->getRedeclContext()->Equals( in CheckMultiVersionFunction()
11714 NewFD->getDeclContext()->getRedeclContext())) { in CheckMultiVersionFunction()
11722 FunctionDecl *OldFD = OldDecl->getAsFunction(); in CheckMultiVersionFunction()
11724 if (!OldFD->isMultiVersion() && MVKind == MultiVersionKind::None) in CheckMultiVersionFunction()
11729 if (OldFD->isMultiVersion() && MVKind == MultiVersionKind::None && in CheckMultiVersionFunction()
11730 OldFD->getMultiVersionKind() != MultiVersionKind::TargetClones && in CheckMultiVersionFunction()
11731 OldFD->getMultiVersionKind() != MultiVersionKind::TargetVersion) { in CheckMultiVersionFunction()
11732 S.Diag(NewFD->getLocation(), diag::err_multiversion_required_in_redecl) in CheckMultiVersionFunction()
11733 << (OldFD->getMultiVersionKind() != MultiVersionKind::Target); in CheckMultiVersionFunction()
11734 NewFD->setInvalidDecl(); in CheckMultiVersionFunction()
11738 if (!OldFD->isMultiVersion()) { in CheckMultiVersionFunction()
11745 if (OldFD->isUsed(false)) { in CheckMultiVersionFunction()
11746 NewFD->setInvalidDecl(); in CheckMultiVersionFunction()
11747 return S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used); in CheckMultiVersionFunction()
11749 OldFD->setIsMultiVersion(); in CheckMultiVersionFunction()
11768 bool IsPure = NewFD->hasAttr<PureAttr>(); in CheckConstPureAttributesUsage()
11769 bool IsConst = NewFD->hasAttr<ConstAttr>(); in CheckConstPureAttributesUsage()
11780 S.Diag(NewFD->getLocation(), diag::warn_const_attr_with_pure_attr); in CheckConstPureAttributesUsage()
11781 NewFD->dropAttrs<PureAttr>(); in CheckConstPureAttributesUsage()
11786 if (NewFD->getReturnType()->isVoidType()) { in CheckConstPureAttributesUsage()
11787 S.Diag(NewFD->getLocation(), diag::warn_pure_function_returns_void) in CheckConstPureAttributesUsage()
11789 NewFD->dropAttrs<PureAttr, ConstAttr>(); in CheckConstPureAttributesUsage()
11797 assert(!NewFD->getReturnType()->isVariablyModifiedType() && in CheckFunctionDeclaration()
11853 if (OldDecl->hasAttr<OverloadableAttr>() || in CheckFunctionDeclaration()
11854 NewFD->hasAttr<OverloadableAttr>()) { in CheckFunctionDeclaration()
11867 // PPC MMA non-pointer types are not allowed as function return types. in CheckFunctionDeclaration()
11869 PPC().CheckPPCMMAType(NewFD->getReturnType(), NewFD->getLocation())) { in CheckFunctionDeclaration()
11870 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
11878 // function body contains a return statement with a non-type-dependent in CheckFunctionDeclaration()
11882 // An id-expression is type-dependent if it is a template-id that is not a in CheckFunctionDeclaration()
11883 // concept-id and is dependent; or if its terminal name is: in CheckFunctionDeclaration()
11884 // - [...] in CheckFunctionDeclaration()
11885 // - associated by name lookup with one or more declarations of member in CheckFunctionDeclaration()
11888 // - [...] in CheckFunctionDeclaration()
11895 (NewFD->isDependentContext() && in CheckFunctionDeclaration()
11896 NewFD->getReturnType()->isUndeducedType())) { in CheckFunctionDeclaration()
11898 NewFD->getType()->castAs<FunctionProtoType>(); in CheckFunctionDeclaration()
11899 QualType NewReturnType = SubstAutoTypeDependent(FPT->getReturnType()); in CheckFunctionDeclaration()
11900 NewFD->setType(Context.getFunctionType(NewReturnType, FPT->getParamTypes(), in CheckFunctionDeclaration()
11901 FPT->getExtProtoInfo())); in CheckFunctionDeclaration()
11905 // A constexpr specifier for a non-static member function that is not in CheckFunctionDeclaration()
11908 // This needs to be delayed until we know whether this is an out-of-line in CheckFunctionDeclaration()
11914 if (!getLangOpts().CPlusPlus14 && MD && MD->isConstexpr() && in CheckFunctionDeclaration()
11915 !MD->isStatic() && !isa<CXXConstructorDecl>(MD) && in CheckFunctionDeclaration()
11916 !isa<CXXDestructorDecl>(MD) && !MD->getMethodQualifiers().hasConst()) { in CheckFunctionDeclaration()
11919 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->getAsFunction()); in CheckFunctionDeclaration()
11920 if (!OldMD || !OldMD->isStatic()) { in CheckFunctionDeclaration()
11922 MD->getType()->castAs<FunctionProtoType>(); in CheckFunctionDeclaration()
11923 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); in CheckFunctionDeclaration()
11925 MD->setType(Context.getFunctionType(FPT->getReturnType(), in CheckFunctionDeclaration()
11926 FPT->getParamTypes(), EPI)); in CheckFunctionDeclaration()
11932 if (FunctionTypeLoc FTL = MD->getTypeSourceInfo()->getTypeLoc() in CheckFunctionDeclaration()
11936 Diag(MD->getLocation(), diag::warn_cxx14_compat_constexpr_not_const) in CheckFunctionDeclaration()
11947 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
11956 auto *OldFD = OldTemplateDecl->getTemplatedDecl(); in CheckFunctionDeclaration()
11958 = NewFD->getDescribedFunctionTemplate(); in CheckFunctionDeclaration()
11959 assert(NewTemplateDecl && "Template/non-template mismatch"); in CheckFunctionDeclaration()
11964 NewTemplateDecl->mergePrevDecl(OldTemplateDecl); in CheckFunctionDeclaration()
11966 NewFD->setPreviousDeclaration(OldFD); in CheckFunctionDeclaration()
11967 if (NewFD->isCXXClassMember()) { in CheckFunctionDeclaration()
11968 NewFD->setAccess(OldTemplateDecl->getAccess()); in CheckFunctionDeclaration()
11969 NewTemplateDecl->setAccess(OldTemplateDecl->getAccess()); in CheckFunctionDeclaration()
11975 NewTemplateDecl->getInstantiatedFromMemberTemplate()) { in CheckFunctionDeclaration()
11976 NewTemplateDecl->setMemberSpecialization(); in CheckFunctionDeclaration()
11977 assert(OldTemplateDecl->isMemberSpecialization()); in CheckFunctionDeclaration()
11980 if (OldFD->isDeleted()) { in CheckFunctionDeclaration()
11982 assert(OldFD->getCanonicalDecl() == OldFD); in CheckFunctionDeclaration()
11984 OldFD->setDeletedAsWritten(false); in CheckFunctionDeclaration()
11992 NewFD->setPreviousDeclaration(OldFD); in CheckFunctionDeclaration()
11993 if (NewFD->isCXXClassMember()) in CheckFunctionDeclaration()
11994 NewFD->setAccess(OldFD->getAccess()); in CheckFunctionDeclaration()
11998 !NewFD->getAttr<OverloadableAttr>()) { in CheckFunctionDeclaration()
12002 return ND->hasAttr<OverloadableAttr>(); in CheckFunctionDeclaration()
12004 "Non-redecls shouldn't happen without overloadable present"); in CheckFunctionDeclaration()
12008 return FD && !FD->hasAttr<OverloadableAttr>(); in CheckFunctionDeclaration()
12012 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12014 Diag((*OtherUnmarkedIter)->getLocation(), in CheckFunctionDeclaration()
12018 NewFD->addAttr(OverloadableAttr::CreateImplicit(Context)); in CheckFunctionDeclaration()
12028 // C++-specific checks. in CheckFunctionDeclaration()
12039 if (NewFD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None || in CheckFunctionDeclaration()
12040 !Destructor->getFunctionObjectParameterType()->isDependentType()) { in CheckFunctionDeclaration()
12041 CXXRecordDecl *Record = Destructor->getParent(); in CheckFunctionDeclaration()
12046 if (NewFD->getDeclName() != Name) { in CheckFunctionDeclaration()
12047 Diag(NewFD->getLocation(), diag::err_destructor_name); in CheckFunctionDeclaration()
12048 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
12053 if (auto *TD = Guide->getDescribedFunctionTemplate()) in CheckFunctionDeclaration()
12058 if (Guide->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) in CheckFunctionDeclaration()
12059 Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized) in CheckFunctionDeclaration()
12065 if (!Method->isFunctionTemplateSpecialization() && in CheckFunctionDeclaration()
12066 !Method->getDescribedFunctionTemplate() && in CheckFunctionDeclaration()
12067 Method->isCanonicalDecl()) { in CheckFunctionDeclaration()
12068 AddOverriddenMethods(Method->getParent(), Method); in CheckFunctionDeclaration()
12070 if (Method->isVirtual() && NewFD->getTrailingRequiresClause()) in CheckFunctionDeclaration()
12072 // A virtual method shall not have a requires-clause. in CheckFunctionDeclaration()
12073 Diag(NewFD->getTrailingRequiresClause()->getBeginLoc(), in CheckFunctionDeclaration()
12076 if (Method->isStatic()) in CheckFunctionDeclaration()
12084 if (NewFD->isOverloadedOperator() && in CheckFunctionDeclaration()
12086 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
12091 if (NewFD->getLiteralIdentifier() && in CheckFunctionDeclaration()
12093 NewFD->setInvalidDecl(); in CheckFunctionDeclaration()
12100 if (!CurContext->isRecord()) in CheckFunctionDeclaration()
12107 if (Previous.empty() && NewFD->isExternC()) { in CheckFunctionDeclaration()
12108 QualType R = NewFD->getReturnType(); in CheckFunctionDeclaration()
12109 if (R->isIncompleteType() && !R->isVoidType()) in CheckFunctionDeclaration()
12110 Diag(NewFD->getLocation(), diag::warn_return_value_udt_incomplete) in CheckFunctionDeclaration()
12112 else if (!R.isPODType(Context) && !R->isVoidType() && in CheckFunctionDeclaration()
12113 !R->isObjCObjectPointerType()) in CheckFunctionDeclaration()
12114 Diag(NewFD->getLocation(), diag::warn_return_value_udt) << NewFD << R; in CheckFunctionDeclaration()
12118 // [...] whether the function has a non-throwing exception-specification in CheckFunctionDeclaration()
12122 // declared type includes an exception-specification in a parameter or in CheckFunctionDeclaration()
12126 if (!getLangOpts().CPlusPlus17 && !NewFD->getPrimaryTemplate()) { in CheckFunctionDeclaration()
12127 auto HasNoexcept = [&](QualType T) -> bool { in CheckFunctionDeclaration()
12131 if (auto *RT = T->getAs<ReferenceType>()) in CheckFunctionDeclaration()
12132 T = RT->getPointeeType(); in CheckFunctionDeclaration()
12133 else if (T->isAnyPointerType()) in CheckFunctionDeclaration()
12134 T = T->getPointeeType(); in CheckFunctionDeclaration()
12135 else if (auto *MPT = T->getAs<MemberPointerType>()) in CheckFunctionDeclaration()
12136 T = MPT->getPointeeType(); in CheckFunctionDeclaration()
12137 if (auto *FPT = T->getAs<FunctionProtoType>()) in CheckFunctionDeclaration()
12138 if (FPT->isNothrow()) in CheckFunctionDeclaration()
12143 auto *FPT = NewFD->getType()->castAs<FunctionProtoType>(); in CheckFunctionDeclaration()
12144 bool AnyNoexcept = HasNoexcept(FPT->getReturnType()); in CheckFunctionDeclaration()
12145 for (QualType T : FPT->param_types()) in CheckFunctionDeclaration()
12148 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12159 // function returns or uses arguments with VL-based types. in CheckFunctionDeclaration()
12161 const auto *Attr = NewFD->getAttr<ArmNewAttr>(); in CheckFunctionDeclaration()
12162 bool UsesSM = NewFD->hasAttr<ArmLocallyStreamingAttr>(); in CheckFunctionDeclaration()
12163 bool UsesZA = Attr && Attr->isNewZA(); in CheckFunctionDeclaration()
12164 bool UsesZT0 = Attr && Attr->isNewZT0(); in CheckFunctionDeclaration()
12166 if (NewFD->hasAttr<ArmLocallyStreamingAttr>()) { in CheckFunctionDeclaration()
12167 if (NewFD->getReturnType()->isSizelessVectorType()) in CheckFunctionDeclaration()
12168 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12171 if (llvm::any_of(NewFD->parameters(), [](ParmVarDecl *P) { in CheckFunctionDeclaration()
12172 return P->getOriginalType()->isSizelessVectorType(); in CheckFunctionDeclaration()
12174 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12178 if (const auto *FPT = NewFD->getType()->getAs<FunctionProtoType>()) { in CheckFunctionDeclaration()
12179 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); in CheckFunctionDeclaration()
12193 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12196 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12204 Diag(NewFD->getLocation(), in CheckFunctionDeclaration()
12216 // constexpr is ill-formed. in CheckMain()
12221 if (FD->getStorageClass() == SC_Static) in CheckMain()
12225 if (FD->isInlineSpecified()) in CheckMain()
12235 if (FD->isConstexpr()) { in CheckMain()
12237 << FD->isConsteval() in CheckMain()
12239 FD->setConstexprKind(ConstexprSpecKind::Unspecified); in CheckMain()
12243 Diag(FD->getLocation(), diag::err_opencl_no_main) in CheckMain()
12244 << FD->hasAttr<OpenCLKernelAttr>(); in CheckMain()
12245 FD->setInvalidDecl(); in CheckMain()
12254 QualType T = FD->getType(); in CheckMain()
12255 assert(T->isFunctionType() && "function decl is not of function type"); in CheckMain()
12256 const FunctionType* FT = T->castAs<FunctionType>(); in CheckMain()
12259 if (FT->getCallConv() != CC_C) { in CheckMain()
12260 FT = Context.adjustFunctionType(FT, FT->getExtInfo().withCallingConv(CC_C)); in CheckMain()
12261 FD->setType(QualType(FT, 0)); in CheckMain()
12262 T = Context.getCanonicalType(FD->getType()); in CheckMain()
12266 // In C with GNU extensions we allow main() to have non-integer return in CheckMain()
12268 // implicit-return-zero rule. in CheckMain()
12271 if (Context.hasSameUnqualifiedType(FT->getReturnType(), Context.IntTy)) in CheckMain()
12272 FD->setHasImplicitReturnZero(true); in CheckMain()
12274 Diag(FD->getTypeSpecStartLoc(), diag::ext_main_returns_nonint); in CheckMain()
12275 SourceRange RTRange = FD->getReturnTypeSourceRange(); in CheckMain()
12286 if (Context.hasSameType(FT->getReturnType(), Context.IntTy)) in CheckMain()
12287 FD->setHasImplicitReturnZero(true); in CheckMain()
12289 // Otherwise, this is just a flat-out error. in CheckMain()
12290 SourceRange RTRange = FD->getReturnTypeSourceRange(); in CheckMain()
12291 Diag(FD->getTypeSpecStartLoc(), diag::err_main_returns_nonint) in CheckMain()
12294 FD->setInvalidDecl(true); in CheckMain()
12302 unsigned nparams = FTP->getNumParams(); in CheckMain()
12303 assert(FD->getNumParams() == nparams); in CheckMain()
12307 if (FTP->isVariadic()) { in CheckMain()
12308 Diag(FD->getLocation(), diag::ext_variadic_main); in CheckMain()
12320 Diag(FD->getLocation(), diag::err_main_surplus_args) << nparams; in CheckMain()
12321 FD->setInvalidDecl(true); in CheckMain()
12333 QualType AT = FTP->getParamType(i); in CheckMain()
12347 if ((PT = qs.strip(AT)->getAs<PointerType>()) && in CheckMain()
12348 (PT = qs.strip(PT->getPointeeType())->getAs<PointerType>()) && in CheckMain()
12349 Context.hasSameType(QualType(qs.strip(PT->getPointeeType()), 0), in CheckMain()
12357 Diag(FD->getLocation(), diag::err_main_arg_wrong) << i << Expected[i]; in CheckMain()
12359 FD->setInvalidDecl(true); in CheckMain()
12363 if (nparams == 1 && !FD->isInvalidDecl()) { in CheckMain()
12364 Diag(FD->getLocation(), diag::warn_main_one_arg); in CheckMain()
12367 if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) { in CheckMain()
12368 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD; in CheckMain()
12369 FD->setInvalidDecl(); in CheckMain()
12376 if (FD->getName() == "main" || FD->getName() == "wmain") in isDefaultStdCall()
12393 QualType T = FD->getType(); in CheckMSVCRTEntryPoint()
12394 assert(T->isFunctionType() && "function decl is not of function type"); in CheckMSVCRTEntryPoint()
12395 const FunctionType *FT = T->castAs<FunctionType>(); in CheckMSVCRTEntryPoint()
12399 if (FT->getReturnType()->isIntegralOrEnumerationType() || in CheckMSVCRTEntryPoint()
12400 FT->getReturnType()->isAnyPointerType() || in CheckMSVCRTEntryPoint()
12401 FT->getReturnType()->isNullPtrType()) in CheckMSVCRTEntryPoint()
12403 if (FD->getName() != "DllMain") in CheckMSVCRTEntryPoint()
12404 FD->setHasImplicitReturnZero(true); in CheckMSVCRTEntryPoint()
12409 if (FT->getCallConv() != CC_X86StdCall) { in CheckMSVCRTEntryPoint()
12411 FT, FT->getExtInfo().withCallingConv(CC_X86StdCall)); in CheckMSVCRTEntryPoint()
12412 FD->setType(QualType(FT, 0)); in CheckMSVCRTEntryPoint()
12414 } else if (FT->getCallConv() != CC_C) { in CheckMSVCRTEntryPoint()
12416 FT->getExtInfo().withCallingConv(CC_C)); in CheckMSVCRTEntryPoint()
12417 FD->setType(QualType(FT, 0)); in CheckMSVCRTEntryPoint()
12421 if (!FD->isInvalidDecl() && FD->getDescribedFunctionTemplate()) { in CheckMSVCRTEntryPoint()
12422 Diag(FD->getLocation(), diag::err_mainlike_template_decl) << FD; in CheckMSVCRTEntryPoint()
12423 FD->setInvalidDecl(); in CheckMSVCRTEntryPoint()
12429 // any assignment, increment, decrement, function-calls, or in CheckForConstantInitializer()
12437 if (Init->isValueDependent()) { in CheckForConstantInitializer()
12438 assert(Init->containsErrors() && in CheckForConstantInitializer()
12439 "Dependent code should only occur in error-recovery path."); in CheckForConstantInitializer()
12443 if (Init->isConstantInitializer(Context, false, &Culprit)) in CheckForConstantInitializer()
12445 Diag(Culprit->getExprLoc(), DiagID) << Culprit->getSourceRange(); in CheckForConstantInitializer()
12473 isPODType = VD->getType().isPODType(S.Context); in SelfReferenceChecker()
12474 isRecordType = VD->getType()->isRecordType(); in SelfReferenceChecker()
12475 isReferenceType = VD->getType()->isReferenceType(); in SelfReferenceChecker()
12492 for (auto *Child : InitList->children()) { in CheckExpr()
12508 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl()); in CheckInitListMemberExpr()
12512 if (FD->getType()->isReferenceType()) in CheckInitListMemberExpr()
12514 Base = ME->getBase()->IgnoreParenImpCasts(); in CheckInitListMemberExpr()
12519 if (!DRE || DRE->getDecl() != OrigDecl) in CheckInitListMemberExpr()
12529 UsedFieldIndex.push_back(I->getFieldIndex()); in CheckInitListMemberExpr()
12554 E = E->IgnoreParens(); in HandleValue()
12561 Visit(CO->getCond()); in HandleValue()
12562 HandleValue(CO->getTrueExpr()); in HandleValue()
12563 HandleValue(CO->getFalseExpr()); in HandleValue()
12569 Visit(BCO->getCond()); in HandleValue()
12570 HandleValue(BCO->getFalseExpr()); in HandleValue()
12575 if (Expr *SE = OVE->getSourceExpr()) in HandleValue()
12581 if (BO->getOpcode() == BO_Comma) { in HandleValue()
12582 Visit(BO->getLHS()); in HandleValue()
12583 HandleValue(BO->getRHS()); in HandleValue()
12595 Expr *Base = E->IgnoreParenImpCasts(); in HandleValue()
12598 if (!isa<FieldDecl>(ME->getMemberDecl())) in HandleValue()
12600 Base = ME->getBase()->IgnoreParenImpCasts(); in HandleValue()
12611 // uses of references are bad, not just r-value uses.
12618 if (E->getCastKind() == CK_LValueToRValue) { in VisitImplicitCastExpr()
12619 HandleValue(E->getSubExpr()); in VisitImplicitCastExpr()
12633 if (E->getType()->canDecayToPointerType()) return; in VisitMemberExpr()
12635 // Warn when a non-static method call is followed by non-static member in VisitMemberExpr()
12637 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl()); in VisitMemberExpr()
12638 bool Warn = (MD && !MD->isStatic()); in VisitMemberExpr()
12639 Expr *Base = E->getBase()->IgnoreParenImpCasts(); in VisitMemberExpr()
12641 if (!isa<FieldDecl>(ME->getMemberDecl())) in VisitMemberExpr()
12643 Base = ME->getBase()->IgnoreParenImpCasts(); in VisitMemberExpr()
12658 Expr *Callee = E->getCallee(); in VisitCXXOperatorCallExpr()
12664 for (auto Arg: E->arguments()) in VisitCXXOperatorCallExpr()
12665 HandleValue(Arg->IgnoreParenImpCasts()); in VisitCXXOperatorCallExpr()
12669 // For POD record types, addresses of its own members are well-defined. in VisitUnaryOperator()
12670 if (E->getOpcode() == UO_AddrOf && isRecordType && in VisitUnaryOperator()
12671 isa<MemberExpr>(E->getSubExpr()->IgnoreParens())) { in VisitUnaryOperator()
12673 HandleValue(E->getSubExpr()); in VisitUnaryOperator()
12677 if (E->isIncrementDecrementOp()) { in VisitUnaryOperator()
12678 HandleValue(E->getSubExpr()); in VisitUnaryOperator()
12688 if (E->getConstructor()->isCopyConstructor()) { in VisitCXXConstructExpr()
12689 Expr *ArgExpr = E->getArg(0); in VisitCXXConstructExpr()
12691 if (ILE->getNumInits() == 1) in VisitCXXConstructExpr()
12692 ArgExpr = ILE->getInit(0); in VisitCXXConstructExpr()
12694 if (ICE->getCastKind() == CK_NoOp) in VisitCXXConstructExpr()
12695 ArgExpr = ICE->getSubExpr(); in VisitCXXConstructExpr()
12704 if (E->isCallToStdMove()) { in VisitCallExpr()
12705 HandleValue(E->getArg(0)); in VisitCallExpr()
12713 if (E->isCompoundAssignmentOp()) { in VisitBinaryOperator()
12714 HandleValue(E->getLHS()); in VisitBinaryOperator()
12715 Visit(E->getRHS()); in VisitBinaryOperator()
12726 Visit(E->getCond()); in VisitBinaryConditionalOperator()
12727 Visit(E->getFalseExpr()); in VisitBinaryConditionalOperator()
12731 Decl* ReferenceDecl = DRE->getDecl(); in HandleDeclRefExpr()
12736 } else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) { in HandleDeclRefExpr()
12738 } else if (isa<TranslationUnitDecl>(OrigDecl->getDeclContext()) || in HandleDeclRefExpr()
12739 isa<NamespaceDecl>(OrigDecl->getDeclContext()) || in HandleDeclRefExpr()
12740 DRE->getDecl()->getType()->isRecordType()) { in HandleDeclRefExpr()
12747 S.DiagRuntimeBehavior(DRE->getBeginLoc(), DRE, in HandleDeclRefExpr()
12749 << DRE->getDecl() << OrigDecl->getLocation() in HandleDeclRefExpr()
12750 << DRE->getSourceRange()); in HandleDeclRefExpr()
12754 /// CheckSelfReference - Warns if OrigDecl is used in expression E.
12762 E = E->IgnoreParens(); in CheckSelfReference()
12766 if (!DirectInit && !cast<VarDecl>(OrigDecl)->getType()->isRecordType()) in CheckSelfReference()
12768 if (ICE->getCastKind() == CK_LValueToRValue) in CheckSelfReference()
12769 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr())) in CheckSelfReference()
12770 if (DRE->getDecl() == OrigDecl) in CheckSelfReference()
12797 assert((!VDecl || !VDecl->isInitCapture()) && in deduceVarTypeFromInitializer()
12802 DeducedType *Deduced = Type->getContainedDeducedType(); in deduceVarTypeFromInitializer()
12803 assert(Deduced && "deduceVarTypeFromInitializer for non-deduced type"); in deduceVarTypeFromInitializer()
12806 if (getLangOpts().C23 && Type->isArrayType() && in deduceVarTypeFromInitializer()
12809 << (int)Deduced->getContainedAutoType()->getKeyword() in deduceVarTypeFromInitializer()
12821 VDecl->hasExternalStorage() || in deduceVarTypeFromInitializer()
12822 VDecl->isStaticDataMember()) { in deduceVarTypeFromInitializer()
12823 Diag(VDecl->getLocation(), diag::err_auto_var_requires_init) in deduceVarTypeFromInitializer()
12824 << VDecl->getDeclName() << Type; in deduceVarTypeFromInitializer()
12835 DeduceInits = PL->exprs(); in deduceVarTypeFromInitializer()
12838 assert(VDecl && "non-auto type for init capture deduction?"); in deduceVarTypeFromInitializer()
12841 VDecl->getLocation(), DirectInit, Init); in deduceVarTypeFromInitializer()
12850 DeduceInits = IL->inits(); in deduceVarTypeFromInitializer()
12857 Diag(Init->getBeginLoc(), IsInitCapture in deduceVarTypeFromInitializer()
12865 Diag(DeduceInits[1]->getBeginLoc(), in deduceVarTypeFromInitializer()
12874 Diag(Init->getBeginLoc(), IsInitCapture in deduceVarTypeFromInitializer()
12884 Init->getType() == Context.UnknownAnyTy && !IsInitCapture) { in deduceVarTypeFromInitializer()
12894 // If the assignment-expression [...] has array type A and no ref-qualifier in deduceVarTypeFromInitializer()
12898 DeduceInit->getType()->isConstantArrayType()) in deduceVarTypeFromInitializer()
12899 return Context.getQualifiedType(DeduceInit->getType(), in deduceVarTypeFromInitializer()
12903 TemplateDeductionInfo Info(DeduceInit->getExprLoc()); in deduceVarTypeFromInitializer()
12905 DeduceAutoType(TSI->getTypeLoc(), DeduceInit, DeducedType, Info); in deduceVarTypeFromInitializer()
12914 << (DeduceInit->getType().isNull() ? TSI->getType() in deduceVarTypeFromInitializer()
12915 : DeduceInit->getType()) in deduceVarTypeFromInitializer()
12916 << DeduceInit->getSourceRange(); in deduceVarTypeFromInitializer()
12919 << VN << TSI->getType() in deduceVarTypeFromInitializer()
12920 << (DeduceInit->getType().isNull() ? TSI->getType() in deduceVarTypeFromInitializer()
12921 : DeduceInit->getType()) in deduceVarTypeFromInitializer()
12922 << DeduceInit->getSourceRange(); in deduceVarTypeFromInitializer()
12925 // Warn if we deduced 'id'. 'auto' usually implies type-safety, but using in deduceVarTypeFromInitializer()
12931 !DeducedType.isNull() && DeducedType->isObjCIdType()) { in deduceVarTypeFromInitializer()
12932 SourceLocation Loc = TSI->getTypeLoc().getBeginLoc(); in deduceVarTypeFromInitializer()
12941 assert(!Init || !Init->containsErrors()); in DeduceVariableDeclarationType()
12943 VDecl, VDecl->getDeclName(), VDecl->getType(), VDecl->getTypeSourceInfo(), in DeduceVariableDeclarationType()
12944 VDecl->getSourceRange(), DirectInit, Init); in DeduceVariableDeclarationType()
12946 VDecl->setInvalidDecl(); in DeduceVariableDeclarationType()
12950 VDecl->setType(DeducedType); in DeduceVariableDeclarationType()
12951 assert(VDecl->isLinkageValid()); in DeduceVariableDeclarationType()
12955 VDecl->setInvalidDecl(); in DeduceVariableDeclarationType()
12962 if (VarDecl *Old = VDecl->getPreviousDecl()) { in DeduceVariableDeclarationType()
12970 return VDecl->isInvalidDecl(); in DeduceVariableDeclarationType()
12976 Init = EWC->getSubExpr(); in checkNonTrivialCUnionInInitializer()
12979 Init = CE->getSubExpr(); in checkNonTrivialCUnionInInitializer()
12981 QualType InitType = Init->getType(); in checkNonTrivialCUnionInInitializer()
12984 "shouldn't be called if type doesn't have a non-trivial C struct"); in checkNonTrivialCUnionInInitializer()
12986 for (auto *I : ILE->inits()) { in checkNonTrivialCUnionInInitializer()
12987 if (!I->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() && in checkNonTrivialCUnionInInitializer()
12988 !I->getType().hasNonTrivialToPrimitiveCopyCUnion()) in checkNonTrivialCUnionInInitializer()
12990 SourceLocation SL = I->getExprLoc(); in checkNonTrivialCUnionInInitializer()
13004 // copy-elision. in checkNonTrivialCUnionInInitializer()
13015 // defined in a system header and has non-trivial ObjC ownership in shouldIgnoreForRecordTriviality()
13017 // whether the containing union is non-trivial. in shouldIgnoreForRecordTriviality()
13018 return FD->hasAttr<UnavailableAttr>(); in shouldIgnoreForRecordTriviality()
13036 return this->asDerived().visit(S.Context.getBaseElementType(AT), FD, in visitWithKind()
13044 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCStrong()
13045 << 1 << 0 << QT << FD->getName(); in visitARCStrong()
13050 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCWeak()
13051 << 1 << 0 << QT << FD->getName(); in visitARCWeak()
13055 const RecordDecl *RD = QT->castAs<RecordType>()->getDecl(); in visitStruct()
13056 if (RD->isUnion()) { in visitStruct()
13059 if (auto *OrigRD = OrigTy->getAsRecordDecl()) in visitStruct()
13060 IsUnion = OrigRD->isUnion(); in visitStruct()
13070 S.Diag(RD->getLocation(), diag::note_non_trivial_c_union) in visitStruct()
13073 for (const FieldDecl *FD : RD->fields()) in visitStruct()
13075 asDerived().visit(FD->getType(), FD, InNonTrivialUnion); in visitStruct()
13080 // The non-trivial C union type or the struct/union type that contains a
13081 // non-trivial C union.
13101 return this->asDerived().visit(S.Context.getBaseElementType(AT), FD, in visitWithKind()
13109 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCStrong()
13110 << 1 << 1 << QT << FD->getName(); in visitARCStrong()
13115 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCWeak()
13116 << 1 << 1 << QT << FD->getName(); in visitARCWeak()
13120 const RecordDecl *RD = QT->castAs<RecordType>()->getDecl(); in visitStruct()
13121 if (RD->isUnion()) { in visitStruct()
13124 if (auto *OrigRD = OrigTy->getAsRecordDecl()) in visitStruct()
13125 IsUnion = OrigRD->isUnion(); in visitStruct()
13135 S.Diag(RD->getLocation(), diag::note_non_trivial_c_union) in visitStruct()
13138 for (const FieldDecl *FD : RD->fields()) in visitStruct()
13140 asDerived().visit(FD->getType(), FD, InNonTrivialUnion); in visitStruct()
13147 // The non-trivial C union type or the struct/union type that contains a
13148 // non-trivial C union.
13167 return this->asDerived().visit(S.Context.getBaseElementType(AT), FD, in visitWithKind()
13175 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCStrong()
13176 << 1 << 2 << QT << FD->getName(); in visitARCStrong()
13181 S.Diag(FD->getLocation(), diag::note_non_trivial_c_union) in visitARCWeak()
13182 << 1 << 2 << QT << FD->getName(); in visitARCWeak()
13186 const RecordDecl *RD = QT->castAs<RecordType>()->getDecl(); in visitStruct()
13187 if (RD->isUnion()) { in visitStruct()
13190 if (auto *OrigRD = OrigTy->getAsRecordDecl()) in visitStruct()
13191 IsUnion = OrigRD->isUnion(); in visitStruct()
13201 S.Diag(RD->getLocation(), diag::note_non_trivial_c_union) in visitStruct()
13204 for (const FieldDecl *FD : RD->fields()) in visitStruct()
13206 asDerived().visit(FD->getType(), FD, InNonTrivialUnion); in visitStruct()
13215 // The non-trivial C union type or the struct/union type that contains a
13216 // non-trivial C union.
13231 "shouldn't be called if type doesn't have a non-trivial C union"); in checkNonTrivialCUnion()
13255 if (!Method->isInvalidDecl()) { in AddInitializerToDecl()
13256 // Pure-specifiers are handled in ActOnPureSpecifier. in AddInitializerToDecl()
13257 Diag(Method->getLocation(), diag::err_member_function_initialization) in AddInitializerToDecl()
13258 << Method->getDeclName() << Init->getSourceRange(); in AddInitializerToDecl()
13259 Method->setInvalidDecl(); in AddInitializerToDecl()
13267 Diag(RealDecl->getLocation(), diag::err_illegal_initializer); in AddInitializerToDecl()
13268 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
13272 if (VDecl->isInvalidDecl()) { in AddInitializerToDecl()
13278 CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), SubExprs); in AddInitializerToDecl()
13280 VDecl->setInit(E); in AddInitializerToDecl()
13285 if (Init && !Init->getType().isNull() && in AddInitializerToDecl()
13286 Init->getType()->isWebAssemblyTableType()) { in AddInitializerToDecl()
13287 Diag(Init->getExprLoc(), diag::err_wasm_table_art) << 0; in AddInitializerToDecl()
13288 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13293 if (VDecl->getType()->isUndeducedType()) { in AddInitializerToDecl()
13301 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
13304 if (Res.get()->containsErrors()) { in AddInitializerToDecl()
13305 // Invalidate the decl as we don't know the type for recovery-expr yet. in AddInitializerToDecl()
13306 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
13307 VDecl->setInit(Res.get()); in AddInitializerToDecl()
13317 if (VDecl->hasAttr<DLLImportAttr>() && !VDecl->isStaticDataMember()) { in AddInitializerToDecl()
13318 Diag(VDecl->getLocation(), diag::err_attribute_dllimport_data_definition); in AddInitializerToDecl()
13319 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13327 if (VDecl->isLocalVarDecl() && VDecl->hasExternalStorage()) { in AddInitializerToDecl()
13328 Diag(VDecl->getLocation(), diag::err_block_extern_cant_init); in AddInitializerToDecl()
13329 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13333 if (!VDecl->getType()->isDependentType()) { in AddInitializerToDecl()
13337 QualType BaseDeclType = VDecl->getType(); in AddInitializerToDecl()
13339 BaseDeclType = Array->getElementType(); in AddInitializerToDecl()
13340 if (RequireCompleteType(VDecl->getLocation(), BaseDeclType, in AddInitializerToDecl()
13342 RealDecl->setInvalidDecl(); in AddInitializerToDecl()
13347 if (RequireNonAbstractType(VDecl->getLocation(), VDecl->getType(), in AddInitializerToDecl()
13350 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13356 !VDecl->isInvalidDecl() && VDecl->isThisDeclarationADefinition() && in AddInitializerToDecl()
13357 VDecl->getFormalLinkage() == Linkage::External && !VDecl->isInline() && in AddInitializerToDecl()
13358 !VDecl->isTemplated() && !isa<VarTemplateSpecializationDecl>(VDecl) && in AddInitializerToDecl()
13359 !VDecl->getInstantiatedFromStaticDataMember()) { in AddInitializerToDecl()
13360 Diag(VDecl->getLocation(), diag::err_extern_def_in_header_unit); in AddInitializerToDecl()
13361 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13367 if (VarDecl *Def = VDecl->getDefinition()) in AddInitializerToDecl()
13369 (!VDecl->isStaticDataMember() || VDecl->isOutOfLine()) && in AddInitializerToDecl()
13370 !VDecl->isThisDeclarationADemotedDefinition() && in AddInitializerToDecl()
13378 // specify a constant-initializer which shall be an integral in AddInitializerToDecl()
13385 // data members we also need to check whether there was an in-class in AddInitializerToDecl()
13387 if (VDecl->isStaticDataMember() && VDecl->getCanonicalDecl()->hasInit()) { in AddInitializerToDecl()
13388 Diag(Init->getExprLoc(), diag::err_static_data_member_reinitialization) in AddInitializerToDecl()
13389 << VDecl->getDeclName(); in AddInitializerToDecl()
13390 Diag(VDecl->getCanonicalDecl()->getInit()->getExprLoc(), in AddInitializerToDecl()
13396 if (VDecl->hasLocalStorage()) in AddInitializerToDecl()
13400 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13407 if (VDecl->getType().getAddressSpace() == LangAS::opencl_local) { in AddInitializerToDecl()
13408 Diag(VDecl->getLocation(), diag::err_local_cant_init); in AddInitializerToDecl()
13409 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13414 if (VDecl->hasAttr<LoaderUninitializedAttr>()) { in AddInitializerToDecl()
13415 Diag(VDecl->getLocation(), diag::err_loader_uninitialized_cant_init); in AddInitializerToDecl()
13416 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13422 QualType DclT = VDecl->getType(), SavT = DclT; in AddInitializerToDecl()
13425 // and we are assigning it to a variable of Objective-C pointer type. in AddInitializerToDecl()
13426 if (getLangOpts().DebuggerCastResultToId && DclT->isObjCObjectPointerType() && in AddInitializerToDecl()
13427 Init->getType() == Context.UnknownAnyTy) { in AddInitializerToDecl()
13430 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13439 if (!VDecl->isInvalidDecl()) { in AddInitializerToDecl()
13442 VDecl->getLocation(), DirectInit, Init); in AddInitializerToDecl()
13446 Args = MultiExprArg(CXXDirectInit->getExprs(), in AddInitializerToDecl()
13447 CXXDirectInit->getNumExprs()); in AddInitializerToDecl()
13458 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13463 if (VDecl->isInvalidDecl()) in AddInitializerToDecl()
13474 CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), Args); in AddInitializerToDecl()
13476 VDecl->setInit(RecoveryExpr.get()); in AddInitializerToDecl()
13481 // 2) if the var decl is a decomposition decl with a non-deduced type, in AddInitializerToDecl()
13485 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13491 InitSeq.step_begin()->Kind == in AddInitializerToDecl()
13493 QualType VDeclType = VDecl->getType(); in AddInitializerToDecl()
13494 if (Init && !Init->getType().isNull() && in AddInitializerToDecl()
13495 !Init->getType()->isDependentType() && !VDeclType->isDependentType() && in AddInitializerToDecl()
13497 Context.getAsIncompleteArrayType(Init->getType())) { in AddInitializerToDecl()
13500 Diag(VDecl->getLocation(), diag::err_typecheck_decl_incomplete_type) in AddInitializerToDecl()
13502 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13507 // Check for self-references within variable initializers. in AddInitializerToDecl()
13512 if (!VDecl->hasLocalStorage() || VDecl->getType()->isRecordType() || in AddInitializerToDecl()
13513 VDecl->getType()->isReferenceType()) in AddInitializerToDecl()
13520 if (!VDecl->isInvalidDecl() && (DclT != SavT)) in AddInitializerToDecl()
13521 VDecl->setType(DclT); in AddInitializerToDecl()
13523 if (!VDecl->isInvalidDecl()) { in AddInitializerToDecl()
13524 checkUnsafeAssigns(VDecl->getLocation(), VDecl->getType(), Init); in AddInitializerToDecl()
13526 if (VDecl->hasAttr<BlocksAttr>()) in AddInitializerToDecl()
13535 // -Wrepeated-use-of-weak is made flow-sensitive. in AddInitializerToDecl()
13536 if (FunctionScopeInfo *FSI = getCurFunction()) in AddInitializerToDecl() local
13537 if ((VDecl->getType().getObjCLifetime() == Qualifiers::OCL_Strong || in AddInitializerToDecl()
13538 VDecl->getType().isNonWeakInMRRWithObjCWeak(Context)) && in AddInitializerToDecl()
13540 Init->getBeginLoc())) in AddInitializerToDecl()
13541 FSI->markSafeWeakUse(Init); in AddInitializerToDecl()
13544 // The initialization is usually a full-expression. in AddInitializerToDecl()
13548 // full-expression. For instance, in: in AddInitializerToDecl()
13556 ActOnFinishFullExpr(Init, VDecl->getLocation(), in AddInitializerToDecl()
13557 /*DiscardedValue*/ false, VDecl->isConstexpr()); in AddInitializerToDecl()
13559 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13565 VDecl->setInit(Init); in AddInitializerToDecl()
13567 if (VDecl->isLocalVarDecl()) { in AddInitializerToDecl()
13569 if (VDecl->isInvalidDecl()) { in AddInitializerToDecl()
13572 // OpenCL v1.2 s6.5.3: __constant locals must be constant-initialized. in AddInitializerToDecl()
13574 } else if (VDecl->getType().getAddressSpace() == LangAS::opencl_constant) { in AddInitializerToDecl()
13583 } else if (VDecl->getStorageClass() == SC_Static) { in AddInitializerToDecl()
13590 } else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() && in AddInitializerToDecl()
13596 if (auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->IgnoreParens())) in AddInitializerToDecl()
13597 if (VDecl->hasLocalStorage()) in AddInitializerToDecl()
13598 BE->getBlockDecl()->setCanAvoidCopyToHeap(); in AddInitializerToDecl()
13599 } else if (VDecl->isStaticDataMember() && !VDecl->isInline() && in AddInitializerToDecl()
13600 VDecl->getLexicalDeclContext()->isRecord()) { in AddInitializerToDecl()
13601 // This is an in-class initialization for a static data member, e.g., in AddInitializerToDecl()
13608 // A member-declarator can contain a constant-initializer only in AddInitializerToDecl()
13613 // If a non-volatile non-inline const static data member is of integral in AddInitializerToDecl()
13615 // specify a brace-or-equal-initializer in which every initializer-clause in AddInitializerToDecl()
13616 // that is an assignment-expression is a constant expression. A static in AddInitializerToDecl()
13619 // brace-or-equal-initializer in which every initializer-clause that is in AddInitializerToDecl()
13620 // an assignment-expression is a constant expression. in AddInitializerToDecl()
13623 if (DclT->isDependentType()) { in AddInitializerToDecl()
13628 } else if (VDecl->isConstexpr()) { in AddInitializerToDecl()
13632 Diag(VDecl->getLocation(), diag::err_in_class_initializer_non_const) in AddInitializerToDecl()
13633 << Init->getSourceRange(); in AddInitializerToDecl()
13634 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13637 } else if (DclT->isIntegralOrEnumerationType()) { in AddInitializerToDecl()
13641 // In C++11, a non-constexpr const static data member with an in AddInitializerToDecl()
13642 // in-class initializer cannot be volatile. in AddInitializerToDecl()
13643 Diag(VDecl->getLocation(), diag::err_in_class_initializer_volatile); in AddInitializerToDecl()
13644 else if (Init->isValueDependent()) in AddInitializerToDecl()
13646 else if (Init->isIntegerConstantExpr(Context, &Loc)) in AddInitializerToDecl()
13648 else if (Init->getType()->isScopedEnumeralType() && in AddInitializerToDecl()
13649 Init->isCXX11ConstantExpr(Context)) in AddInitializerToDecl()
13650 ; // Ok, it is a scoped-enum constant expression. in AddInitializerToDecl()
13651 else if (Init->isEvaluatable(Context)) { in AddInitializerToDecl()
13653 // but report this as a use of an extension for -pedantic. in AddInitializerToDecl()
13655 << Init->getSourceRange(); in AddInitializerToDecl()
13660 << Init->getSourceRange(); in AddInitializerToDecl()
13661 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13664 // We allow foldable floating-point constants as an extension. in AddInitializerToDecl()
13665 } else if (DclT->isFloatingType()) { // also permits complex, which is ok in AddInitializerToDecl()
13669 Diag(VDecl->getLocation(), in AddInitializerToDecl()
13671 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
13672 Diag(VDecl->getBeginLoc(), in AddInitializerToDecl()
13674 << FixItHint::CreateInsertion(VDecl->getBeginLoc(), "constexpr "); in AddInitializerToDecl()
13676 Diag(VDecl->getLocation(), diag::ext_in_class_initializer_float_type) in AddInitializerToDecl()
13677 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
13679 if (!Init->isValueDependent() && !Init->isEvaluatable(Context)) { in AddInitializerToDecl()
13680 Diag(Init->getExprLoc(), diag::err_in_class_initializer_non_constant) in AddInitializerToDecl()
13681 << Init->getSourceRange(); in AddInitializerToDecl()
13682 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13687 } else if (getLangOpts().CPlusPlus11 && DclT->isLiteralType(Context)) { in AddInitializerToDecl()
13688 Diag(VDecl->getLocation(), diag::err_in_class_initializer_literal_type) in AddInitializerToDecl()
13689 << DclT << Init->getSourceRange() in AddInitializerToDecl()
13690 << FixItHint::CreateInsertion(VDecl->getBeginLoc(), "constexpr "); in AddInitializerToDecl()
13691 VDecl->setConstexpr(true); in AddInitializerToDecl()
13694 Diag(VDecl->getLocation(), diag::err_in_class_initializer_bad_type) in AddInitializerToDecl()
13695 << DclT << Init->getSourceRange(); in AddInitializerToDecl()
13696 VDecl->setInvalidDecl(); in AddInitializerToDecl()
13698 } else if (VDecl->isFileVarDecl()) { in AddInitializerToDecl()
13706 if (VDecl->getStorageClass() == SC_Extern && in AddInitializerToDecl()
13707 ((!getLangOpts().CPlusPlus && !VDecl->hasAttr<SelectAnyAttr>()) || in AddInitializerToDecl()
13708 !Context.getBaseElementType(VDecl->getType()).isConstQualified()) && in AddInitializerToDecl()
13709 !(getLangOpts().CPlusPlus && VDecl->isExternC()) && in AddInitializerToDecl()
13710 !isTemplateInstantiation(VDecl->getTemplateSpecializationKind())) in AddInitializerToDecl()
13711 Diag(VDecl->getLocation(), diag::warn_extern_init); in AddInitializerToDecl()
13717 getLangOpts().CPlusPlus && VDecl->getType().isConstQualified() && in AddInitializerToDecl()
13718 VDecl->hasAttr<DLLExportAttr>() && VDecl->getDefinition()) in AddInitializerToDecl()
13719 VDecl->setStorageClass(SC_Extern); in AddInitializerToDecl()
13723 if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl() && in AddInitializerToDecl()
13724 !VDecl->isConstexpr()) in AddInitializerToDecl()
13728 QualType InitType = Init->getType(); in AddInitializerToDecl()
13732 checkNonTrivialCUnionInInitializer(Init, Init->getExprLoc()); in AddInitializerToDecl()
13734 // We will represent direct-initialization similarly to copy-initialization: in AddInitializerToDecl()
13735 // int x(1); -as-> int x = 1; in AddInitializerToDecl()
13736 // ClassType x(a,b,c); -as-> ClassType x = ClassType(a,b,c); in AddInitializerToDecl()
13749 assert(DirectInit && "Call-style initializer must be direct init."); in AddInitializerToDecl()
13750 VDecl->setInitStyle(IsParenListInit ? VarDecl::ParenListInit in AddInitializerToDecl()
13753 // This must be list-initialization. No other way is direct-initialization. in AddInitializerToDecl()
13754 VDecl->setInitStyle(VarDecl::ListInit); in AddInitializerToDecl()
13759 VDecl->isFileVarDecl()) in AddInitializerToDecl()
13765 // Our main concern here is re-establishing invariants like "a in ActOnInitializerError()
13767 if (!D || D->isInvalidDecl()) return; in ActOnInitializerError()
13774 for (auto *BD : DD->bindings()) in ActOnInitializerError()
13775 BD->setInvalidDecl(); in ActOnInitializerError()
13778 if (VD->getType()->isUndeducedType()) { in ActOnInitializerError()
13779 D->setInvalidDecl(); in ActOnInitializerError()
13783 QualType Ty = VD->getType(); in ActOnInitializerError()
13784 if (Ty->isDependentType()) return; in ActOnInitializerError()
13787 if (RequireCompleteType(VD->getLocation(), in ActOnInitializerError()
13790 VD->setInvalidDecl(); in ActOnInitializerError()
13794 // Require a non-abstract type. in ActOnInitializerError()
13795 if (RequireNonAbstractType(VD->getLocation(), Ty, in ActOnInitializerError()
13798 VD->setInvalidDecl(); in ActOnInitializerError()
13812 QualType Type = Var->getType(); in ActOnUninitializedDecl()
13816 Diag(Var->getLocation(), diag::err_decomp_decl_requires_init) << Var; in ActOnUninitializedDecl()
13817 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13821 if (Type->isUndeducedType() && in ActOnUninitializedDecl()
13827 // a brace-or-equal-initializer. in ActOnUninitializedDecl()
13831 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() && in ActOnUninitializedDecl()
13832 !Var->isThisDeclarationADemotedDefinition()) { in ActOnUninitializedDecl()
13833 if (Var->isStaticDataMember()) { in ActOnUninitializedDecl()
13834 // C++1z removes the relevant rule; the in-class declaration is always in ActOnUninitializedDecl()
13838 Diag(Var->getLocation(), in ActOnUninitializedDecl()
13841 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13845 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl); in ActOnUninitializedDecl()
13846 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13853 if (!Var->isInvalidDecl() && in ActOnUninitializedDecl()
13854 Var->getType().getAddressSpace() == LangAS::opencl_constant && in ActOnUninitializedDecl()
13855 Var->getStorageClass() != SC_Extern && !Var->getInit()) { in ActOnUninitializedDecl()
13857 if (CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) { in ActOnUninitializedDecl()
13858 for (auto *Ctor : RD->ctors()) { in ActOnUninitializedDecl()
13859 if (Ctor->isConstexpr() && Ctor->getNumParams() == 0 && in ActOnUninitializedDecl()
13860 Ctor->getMethodQualifiers().getAddressSpace() == in ActOnUninitializedDecl()
13867 Diag(Var->getLocation(), diag::err_opencl_constant_no_init); in ActOnUninitializedDecl()
13868 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13873 if (!Var->isInvalidDecl() && RealDecl->hasAttr<LoaderUninitializedAttr>()) { in ActOnUninitializedDecl()
13874 if (Var->getStorageClass() == SC_Extern) { in ActOnUninitializedDecl()
13875 Diag(Var->getLocation(), diag::err_loader_uninitialized_extern_decl) in ActOnUninitializedDecl()
13877 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13880 if (RequireCompleteType(Var->getLocation(), Var->getType(), in ActOnUninitializedDecl()
13882 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13885 if (CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) { in ActOnUninitializedDecl()
13886 if (!RD->hasTrivialDefaultConstructor()) { in ActOnUninitializedDecl()
13887 Diag(Var->getLocation(), diag::err_loader_uninitialized_trivial_ctor); in ActOnUninitializedDecl()
13888 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13896 VarDecl::DefinitionKind DefKind = Var->isThisDeclarationADefinition(); in ActOnUninitializedDecl()
13897 if (!Var->isInvalidDecl() && DefKind != VarDecl::DeclarationOnly && in ActOnUninitializedDecl()
13898 Var->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion()) in ActOnUninitializedDecl()
13899 checkNonTrivialCUnion(Var->getType(), Var->getLocation(), in ActOnUninitializedDecl()
13905 if (!Var->isStaticDataMember() || !Var->getAnyInitializer()) in ActOnUninitializedDecl()
13908 // We have an out-of-line definition of a static data member in ActOnUninitializedDecl()
13909 // that has an in-class initializer, so we type-check this like in ActOnUninitializedDecl()
13920 if (!Type->isDependentType() && Var->isLocalVarDecl() && in ActOnUninitializedDecl()
13921 !Var->hasLinkage() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
13922 RequireCompleteType(Var->getLocation(), Type, in ActOnUninitializedDecl()
13924 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13927 if (!Type->isDependentType() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
13928 RequireNonAbstractType(Var->getLocation(), Type, in ActOnUninitializedDecl()
13931 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13932 if (!Type->isDependentType() && !Var->isInvalidDecl() && in ActOnUninitializedDecl()
13933 Var->getStorageClass() == SC_PrivateExtern) { in ActOnUninitializedDecl()
13934 Diag(Var->getLocation(), diag::warn_private_extern); in ActOnUninitializedDecl()
13935 Diag(Var->getLocation(), diag::note_private_extern); in ActOnUninitializedDecl()
13939 !Var->isInvalidDecl()) in ActOnUninitializedDecl()
13947 // storage-class specifier or with the storage-class specifier "static", in ActOnUninitializedDecl()
13950 if (!Var->isInvalidDecl()) { in ActOnUninitializedDecl()
13954 Var->getLocation(), ArrayT->getElementType(), in ActOnUninitializedDecl()
13956 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13957 } else if (Var->getStorageClass() == SC_Static) { in ActOnUninitializedDecl()
13967 if (Var->isFirstDecl()) in ActOnUninitializedDecl()
13968 RequireCompleteType(Var->getLocation(), Type, in ActOnUninitializedDecl()
13974 if (!Var->isInvalidDecl()) in ActOnUninitializedDecl()
13981 if (Type->isIncompleteArrayType()) { in ActOnUninitializedDecl()
13982 if (Var->isConstexpr()) in ActOnUninitializedDecl()
13983 Diag(Var->getLocation(), diag::err_constexpr_var_requires_const_init) in ActOnUninitializedDecl()
13986 Diag(Var->getLocation(), in ActOnUninitializedDecl()
13988 Var->setInvalidDecl(); in ActOnUninitializedDecl()
13994 if (Type->isReferenceType()) { in ActOnUninitializedDecl()
13995 Diag(Var->getLocation(), diag::err_reference_var_requires_init) in ActOnUninitializedDecl()
13996 << Var << SourceRange(Var->getLocation(), Var->getLocation()); in ActOnUninitializedDecl()
14000 // Do not attempt to type-check the default initializer for a in ActOnUninitializedDecl()
14002 if (Type->isDependentType()) in ActOnUninitializedDecl()
14005 if (Var->isInvalidDecl()) in ActOnUninitializedDecl()
14008 if (!Var->hasAttr<AliasAttr>()) { in ActOnUninitializedDecl()
14009 if (RequireCompleteType(Var->getLocation(), in ActOnUninitializedDecl()
14012 Var->setInvalidDecl(); in ActOnUninitializedDecl()
14020 if (RequireNonAbstractType(Var->getLocation(), Type, in ActOnUninitializedDecl()
14023 Var->setInvalidDecl(); in ActOnUninitializedDecl()
14033 // ill-formed unless the variable has scalar type, class type with a in ActOnUninitializedDecl()
14034 // trivial default constructor and a trivial destructor, a cv-qualified in ActOnUninitializedDecl()
14037 if (getLangOpts().CPlusPlus && Var->hasLocalStorage()) { in ActOnUninitializedDecl()
14039 = Context.getBaseElementType(Type)->getAs<RecordType>()) { in ActOnUninitializedDecl()
14040 CXXRecordDecl *CXXRecord = cast<CXXRecordDecl>(Record->getDecl()); in ActOnUninitializedDecl()
14044 if (!CXXRecord->isPOD()) in ActOnUninitializedDecl()
14051 Var->getType().getAddressSpace() == LangAS::opencl_local) in ActOnUninitializedDecl()
14055 // object is of (possibly cv-qualified) non-POD class type (or in ActOnUninitializedDecl()
14056 // array thereof), the object shall be default-initialized; if in ActOnUninitializedDecl()
14057 // the object is of const-qualified type, the underlying class in ActOnUninitializedDecl()
14058 // type shall have a user-declared default in ActOnUninitializedDecl()
14060 // a non- static object, the object and its subobjects, if in ActOnUninitializedDecl()
14062 // or any of its subobjects are of const-qualified type, the in ActOnUninitializedDecl()
14063 // program is ill-formed. in ActOnUninitializedDecl()
14066 // default-initialized; [...]. in ActOnUninitializedDecl()
14069 = InitializationKind::CreateDefault(Var->getLocation()); in ActOnUninitializedDecl()
14075 Var->setInit(MaybeCreateExprWithCleanups(Init.get())); in ActOnUninitializedDecl()
14077 Var->setInitStyle(VarDecl::CallInit); in ActOnUninitializedDecl()
14079 // If default-init fails, attach a recovery-expr initializer to track in ActOnUninitializedDecl()
14082 CreateRecoveryExpr(Var->getLocation(), Var->getLocation(), {}); in ActOnUninitializedDecl()
14084 Var->setInit(RecoveryExpr.get()); in ActOnUninitializedDecl()
14098 Diag(D->getLocation(), diag::err_for_range_decl_must_be_var); in ActOnCXXForRangeDecl()
14099 D->setInvalidDecl(); in ActOnCXXForRangeDecl()
14103 VD->setCXXForRangeDecl(true); in ActOnCXXForRangeDecl()
14105 // for-range-declaration cannot be given a storage class specifier. in ActOnCXXForRangeDecl()
14106 int Error = -1; in ActOnCXXForRangeDecl()
14107 switch (VD->getStorageClass()) { in ActOnCXXForRangeDecl()
14127 // for-range-declaration cannot be given a storage class specifier con't. in ActOnCXXForRangeDecl()
14128 switch (VD->getTSCSpec()) { in ActOnCXXForRangeDecl()
14138 if (Error != -1) { in ActOnCXXForRangeDecl()
14139 Diag(VD->getOuterLocStart(), diag::err_for_range_storage_class) in ActOnCXXForRangeDecl()
14141 D->setInvalidDecl(); in ActOnCXXForRangeDecl()
14149 // A range-based for statement of the form in ActOnCXXForRangeIdentifier()
14150 // for ( for-range-identifier : for-range-initializer ) statement in ActOnCXXForRangeIdentifier()
14152 // for ( auto&& for-range-identifier : for-range-initializer ) statement in ActOnCXXForRangeIdentifier()
14167 cast<VarDecl>(Var)->setCXXForRangeDecl(true); in ActOnCXXForRangeIdentifier()
14175 if (var->isInvalidDecl()) return; in CheckCompleteVariableDeclaration()
14180 // OpenCL v2.0 s6.12.5 - Every block variable declaration must have an in CheckCompleteVariableDeclaration()
14182 if (var->getTypeSourceInfo()->getType()->isBlockPointerType() && in CheckCompleteVariableDeclaration()
14183 !var->hasInit()) { in CheckCompleteVariableDeclaration()
14184 Diag(var->getLocation(), diag::err_opencl_invalid_block_declaration) in CheckCompleteVariableDeclaration()
14186 var->setInvalidDecl(); in CheckCompleteVariableDeclaration()
14191 // In Objective-C, don't allow jumps past the implicit initialization of a in CheckCompleteVariableDeclaration()
14194 var->hasLocalStorage()) { in CheckCompleteVariableDeclaration()
14195 switch (var->getType().getObjCLifetime()) { in CheckCompleteVariableDeclaration()
14208 if (var->hasLocalStorage() && in CheckCompleteVariableDeclaration()
14209 var->getType().isDestructedType() == QualType::DK_nontrivial_c_struct) in CheckCompleteVariableDeclaration()
14212 // Warn about externally-visible variables being defined without a in CheckCompleteVariableDeclaration()
14217 if (var->isThisDeclarationADefinition() && in CheckCompleteVariableDeclaration()
14218 var->getDeclContext()->getRedeclContext()->isFileContext() && in CheckCompleteVariableDeclaration()
14219 var->isExternallyVisible() && var->hasLinkage() && in CheckCompleteVariableDeclaration()
14220 !var->isInline() && !var->getDescribedVarTemplate() && in CheckCompleteVariableDeclaration()
14221 var->getStorageClass() != SC_Register && in CheckCompleteVariableDeclaration()
14223 !isTemplateInstantiation(var->getTemplateSpecializationKind()) && in CheckCompleteVariableDeclaration()
14225 var->getLocation())) { in CheckCompleteVariableDeclaration()
14227 VarDecl *prev = var->getPreviousDecl(); in CheckCompleteVariableDeclaration()
14228 while (prev && prev->isThisDeclarationADefinition()) in CheckCompleteVariableDeclaration()
14229 prev = prev->getPreviousDecl(); in CheckCompleteVariableDeclaration()
14232 Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var; in CheckCompleteVariableDeclaration()
14233 Diag(var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage) in CheckCompleteVariableDeclaration()
14243 CacheHasConstInit = var->getInit()->isConstantInitializer( in CheckCompleteVariableDeclaration()
14244 Context, var->getType()->isReferenceType(), &CacheCulprit); in CheckCompleteVariableDeclaration()
14248 if (var->getTLSKind() == VarDecl::TLS_Static) { in CheckCompleteVariableDeclaration()
14249 if (var->getType().isDestructedType()) { in CheckCompleteVariableDeclaration()
14252 // have a non-trivial destructor. in CheckCompleteVariableDeclaration()
14253 Diag(var->getLocation(), diag::err_thread_nontrivial_dtor); in CheckCompleteVariableDeclaration()
14255 Diag(var->getLocation(), diag::note_use_thread_local); in CheckCompleteVariableDeclaration()
14256 } else if (getLangOpts().CPlusPlus && var->hasInit()) { in CheckCompleteVariableDeclaration()
14262 Diag(CacheCulprit->getExprLoc(), diag::err_thread_dynamic_init) in CheckCompleteVariableDeclaration()
14263 << CacheCulprit->getSourceRange(); in CheckCompleteVariableDeclaration()
14265 Diag(var->getLocation(), diag::note_use_thread_local); in CheckCompleteVariableDeclaration()
14271 if (!var->getType()->isStructureType() && var->hasInit() && in CheckCompleteVariableDeclaration()
14272 isa<InitListExpr>(var->getInit())) { in CheckCompleteVariableDeclaration()
14273 const auto *ILE = cast<InitListExpr>(var->getInit()); in CheckCompleteVariableDeclaration()
14274 unsigned NumInits = ILE->getNumInits(); in CheckCompleteVariableDeclaration()
14277 const auto *Init = ILE->getInit(I); in CheckCompleteVariableDeclaration()
14280 const auto *SL = dyn_cast<StringLiteral>(Init->IgnoreImpCasts()); in CheckCompleteVariableDeclaration()
14284 unsigned NumConcat = SL->getNumConcatenated(); in CheckCompleteVariableDeclaration()
14288 if (NumConcat == 2 && !SL->getBeginLoc().isMacroID()) { in CheckCompleteVariableDeclaration()
14291 const auto *Init = ILE->getInit(J); in CheckCompleteVariableDeclaration()
14294 const auto *SLJ = dyn_cast<StringLiteral>(Init->IgnoreImpCasts()); in CheckCompleteVariableDeclaration()
14295 if (!SLJ || SLJ->getNumConcatenated() > 1) { in CheckCompleteVariableDeclaration()
14303 for (unsigned i = 0; i < NumConcat - 1; ++i) in CheckCompleteVariableDeclaration()
14305 PP.getLocForEndOfToken(SL->getStrTokenLoc(i)), ",")); in CheckCompleteVariableDeclaration()
14307 Diag(SL->getStrTokenLoc(1), in CheckCompleteVariableDeclaration()
14310 Diag(SL->getBeginLoc(), in CheckCompleteVariableDeclaration()
14320 QualType type = var->getType(); in CheckCompleteVariableDeclaration()
14322 if (var->hasAttr<BlocksAttr>()) in CheckCompleteVariableDeclaration()
14323 getCurFunction()->addByrefBlockVar(var); in CheckCompleteVariableDeclaration()
14325 Expr *Init = var->getInit(); in CheckCompleteVariableDeclaration()
14326 bool GlobalStorage = var->hasGlobalStorage(); in CheckCompleteVariableDeclaration()
14327 bool IsGlobal = GlobalStorage && !var->isStaticLocal(); in CheckCompleteVariableDeclaration()
14331 if (getLangOpts().C23 && var->isConstexpr() && !Init) in CheckCompleteVariableDeclaration()
14332 Diag(var->getLocation(), diag::err_constexpr_var_requires_const_init) in CheckCompleteVariableDeclaration()
14336 if ((getLangOpts().CPlusPlus || (getLangOpts().C23 && var->isConstexpr())) && in CheckCompleteVariableDeclaration()
14337 !type->isDependentType() && Init && !Init->isValueDependent() && in CheckCompleteVariableDeclaration()
14338 (GlobalStorage || var->isConstexpr() || in CheckCompleteVariableDeclaration()
14339 var->mightBeUsableInConstantExpressions(Context))) { in CheckCompleteVariableDeclaration()
14348 // in [expr.const]p2-6. in CheckCompleteVariableDeclaration()
14350 // -Wglobal-constructors. in CheckCompleteVariableDeclaration()
14356 (void)var->checkForConstantInitialization(Notes); in CheckCompleteVariableDeclaration()
14359 Notes.emplace_back(CacheCulprit->getExprLoc(), in CheckCompleteVariableDeclaration()
14361 Notes.back().second << CacheCulprit->getSourceRange(); in CheckCompleteVariableDeclaration()
14365 HasConstInit = var->checkForConstantInitialization(Notes); in CheckCompleteVariableDeclaration()
14370 } else if (var->isConstexpr()) { in CheckCompleteVariableDeclaration()
14371 SourceLocation DiagLoc = var->getLocation(); in CheckCompleteVariableDeclaration()
14380 << var << Init->getSourceRange(); in CheckCompleteVariableDeclaration()
14383 } else if (GlobalStorage && var->hasAttr<ConstInitAttr>()) { in CheckCompleteVariableDeclaration()
14384 auto *Attr = var->getAttr<ConstInitAttr>(); in CheckCompleteVariableDeclaration()
14385 Diag(var->getLocation(), diag::err_require_constant_init_failed) in CheckCompleteVariableDeclaration()
14386 << Init->getSourceRange(); in CheckCompleteVariableDeclaration()
14387 Diag(Attr->getLocation(), diag::note_declared_required_constant_init_here) in CheckCompleteVariableDeclaration()
14388 << Attr->getRange() << Attr->isConstinit(); in CheckCompleteVariableDeclaration()
14393 var->getLocation())) { in CheckCompleteVariableDeclaration()
14395 // warn about globals with a non-trivial destructor because we already in CheckCompleteVariableDeclaration()
14397 CXXRecordDecl *RD = baseType->getAsCXXRecordDecl(); in CheckCompleteVariableDeclaration()
14398 if (!(RD && !RD->hasTrivialDestructor())) { in CheckCompleteVariableDeclaration()
14403 Diag(var->getLocation(), diag::warn_global_constructor) in CheckCompleteVariableDeclaration()
14404 << Init->getSourceRange(); in CheckCompleteVariableDeclaration()
14410 if (GlobalStorage && var->isThisDeclarationADefinition() && in CheckCompleteVariableDeclaration()
14418 !(Reason = var->getType().isNonConstantStorage(Context, true, false))) { in CheckCompleteVariableDeclaration()
14422 Stack = var->hasInit() && HasConstInit ? &DataSegStack : &BSSSegStack; in CheckCompleteVariableDeclaration()
14424 if (const SectionAttr *SA = var->getAttr<SectionAttr>()) { in CheckCompleteVariableDeclaration()
14425 if (SA->getSyntax() == AttributeCommonInfo::AS_Declspec) in CheckCompleteVariableDeclaration()
14427 UnifySection(SA->getName(), SectionFlags, var); in CheckCompleteVariableDeclaration()
14428 } else if (Stack->CurrentValue) { in CheckCompleteVariableDeclaration()
14431 var->getType().isConstQualified()) { in CheckCompleteVariableDeclaration()
14435 Diag(var->getLocation(), diag::warn_section_msvc_compat) in CheckCompleteVariableDeclaration()
14441 auto SectionName = Stack->CurrentValue->getString(); in CheckCompleteVariableDeclaration()
14442 var->addAttr(SectionAttr::CreateImplicit(Context, SectionName, in CheckCompleteVariableDeclaration()
14443 Stack->CurrentPragmaLocation, in CheckCompleteVariableDeclaration()
14446 var->dropAttr<SectionAttr>(); in CheckCompleteVariableDeclaration()
14452 if (CurInitSeg && var->getInit()) in CheckCompleteVariableDeclaration()
14453 var->addAttr(InitSegAttr::CreateImplicit(Context, CurInitSeg->getString(), in CheckCompleteVariableDeclaration()
14467 if (!type->isDependentType()) in CheckCompleteVariableDeclaration()
14468 if (const RecordType *recordType = baseType->getAs<RecordType>()) in CheckCompleteVariableDeclaration()
14482 assert(VD->isStaticLocal()); in CheckStaticLocalForDllExport()
14484 auto *FD = dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod()); in CheckStaticLocalForDllExport()
14488 !FD->hasAttr<DLLExportStaticLocalAttr>() && in CheckStaticLocalForDllExport()
14489 !FD->hasAttr<DLLImportStaticLocalAttr>()) { in CheckStaticLocalForDllExport()
14490 FD = dyn_cast_or_null<FunctionDecl>(FD->getParentFunctionOrMethod()); in CheckStaticLocalForDllExport()
14498 auto *NewAttr = cast<InheritableAttr>(A->clone(getASTContext())); in CheckStaticLocalForDllExport()
14499 NewAttr->setInherited(true); in CheckStaticLocalForDllExport()
14500 VD->addAttr(NewAttr); in CheckStaticLocalForDllExport()
14501 } else if (Attr *A = FD->getAttr<DLLExportStaticLocalAttr>()) { in CheckStaticLocalForDllExport()
14503 NewAttr->setInherited(true); in CheckStaticLocalForDllExport()
14504 VD->addAttr(NewAttr); in CheckStaticLocalForDllExport()
14508 if (!FD->hasAttr<DLLExportAttr>()) in CheckStaticLocalForDllExport()
14509 FD->addAttr(NewAttr); in CheckStaticLocalForDllExport()
14511 } else if (Attr *A = FD->getAttr<DLLImportStaticLocalAttr>()) { in CheckStaticLocalForDllExport()
14513 NewAttr->setInherited(true); in CheckStaticLocalForDllExport()
14514 VD->addAttr(NewAttr); in CheckStaticLocalForDllExport()
14519 assert(VD->getTLSKind()); in CheckThreadLocalForLargeAlignment()
14521 // Perform TLS alignment check here after attributes attached to the variable in CheckThreadLocalForLargeAlignment()
14527 if (!VD->hasDependentAlignment()) { in CheckThreadLocalForLargeAlignment()
14530 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum) in CheckThreadLocalForLargeAlignment()
14547 if (VD->hasGlobalStorage() && VD->isThisDeclarationADefinition() && in FinalizeDeclaration()
14548 !inTemplateInstantiation() && !VD->hasAttr<SectionAttr>()) { in FinalizeDeclaration()
14550 VD->addAttr(PragmaClangBSSSectionAttr::CreateImplicit( in FinalizeDeclaration()
14554 VD->addAttr(PragmaClangDataSectionAttr::CreateImplicit( in FinalizeDeclaration()
14558 VD->addAttr(PragmaClangRodataSectionAttr::CreateImplicit( in FinalizeDeclaration()
14562 VD->addAttr(PragmaClangRelroSectionAttr::CreateImplicit( in FinalizeDeclaration()
14568 for (auto *BD : DD->bindings()) { in FinalizeDeclaration()
14575 if (VD->isStaticLocal()) in FinalizeDeclaration()
14578 if (VD->getTLSKind()) in FinalizeDeclaration()
14581 // Perform check for initializers of device-side global variables. in FinalizeDeclaration()
14592 // Imported static data members cannot be defined out-of-line. in FinalizeDeclaration()
14594 if (VD->isStaticDataMember() && VD->isOutOfLine() && in FinalizeDeclaration()
14595 VD->isThisDeclarationADefinition()) { in FinalizeDeclaration()
14599 cast<CXXRecordDecl>(VD->getFirstDecl()->getDeclContext()); in FinalizeDeclaration()
14602 Context->getDescribedClassTemplate(); in FinalizeDeclaration()
14604 Diag(VD->getLocation(), in FinalizeDeclaration()
14608 Diag(IA->getLocation(), diag::note_attribute); in FinalizeDeclaration()
14610 VD->setInvalidDecl(); in FinalizeDeclaration()
14616 if (DLLAttr && VD->getTLSKind()) { in FinalizeDeclaration()
14617 auto *F = dyn_cast_or_null<FunctionDecl>(VD->getParentFunctionOrMethod()); in FinalizeDeclaration()
14619 assert(VD->isStaticLocal()); in FinalizeDeclaration()
14624 Diag(VD->getLocation(), diag::err_attribute_dll_thread_local) << VD in FinalizeDeclaration()
14626 VD->setInvalidDecl(); in FinalizeDeclaration()
14630 if (UsedAttr *Attr = VD->getAttr<UsedAttr>()) { in FinalizeDeclaration()
14631 if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) { in FinalizeDeclaration()
14632 Diag(Attr->getLocation(), diag::warn_attribute_ignored_on_non_definition) in FinalizeDeclaration()
14634 VD->dropAttr<UsedAttr>(); in FinalizeDeclaration()
14637 if (RetainAttr *Attr = VD->getAttr<RetainAttr>()) { in FinalizeDeclaration()
14638 if (!Attr->isInherited() && !VD->isThisDeclarationADefinition()) { in FinalizeDeclaration()
14639 Diag(Attr->getLocation(), diag::warn_attribute_ignored_on_non_definition) in FinalizeDeclaration()
14641 VD->dropAttr<RetainAttr>(); in FinalizeDeclaration()
14645 const DeclContext *DC = VD->getDeclContext(); in FinalizeDeclaration()
14648 if (DC->getRedeclContext()->isFileContext() && VD->isExternallyVisible()) in FinalizeDeclaration()
14652 if (VD->isFileVarDecl() && !isa<VarTemplatePartialSpecializationDecl>(VD)) in FinalizeDeclaration()
14657 if (!VD->hasAttr<TypeTagForDatatypeAttr>() || in FinalizeDeclaration()
14658 !VD->getType()->isIntegralOrEnumerationType()) in FinalizeDeclaration()
14661 for (const auto *I : ThisDecl->specific_attrs<TypeTagForDatatypeAttr>()) { in FinalizeDeclaration()
14662 const Expr *MagicValueExpr = VD->getInit(); in FinalizeDeclaration()
14667 if (!(MagicValueInt = MagicValueExpr->getIntegerConstantExpr(Context))) { in FinalizeDeclaration()
14668 Diag(I->getRange().getBegin(), in FinalizeDeclaration()
14670 << LangOpts.CPlusPlus << MagicValueExpr->getSourceRange(); in FinalizeDeclaration()
14673 if (MagicValueInt->getActiveBits() > 64) { in FinalizeDeclaration()
14674 Diag(I->getRange().getBegin(), in FinalizeDeclaration()
14676 << LangOpts.CPlusPlus << MagicValueExpr->getSourceRange(); in FinalizeDeclaration()
14679 uint64_t MagicValue = MagicValueInt->getZExtValue(); in FinalizeDeclaration()
14680 RegisterTypeTagForDatatype(I->getArgumentKind(), in FinalizeDeclaration()
14682 I->getMatchingCType(), in FinalizeDeclaration()
14683 I->getLayoutCompatible(), in FinalizeDeclaration()
14684 I->getMustBeNull()); in FinalizeDeclaration()
14690 return VD && !VD->getType()->hasAutoForTrailingReturnType(); in hasDeducedAuto()
14712 LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() && in FinalizeDeclaratorGroup()
14713 VD->hasGlobalStorage()) in FinalizeDeclaratorGroup()
14715 // For declarators, there are some additional syntactic-ish checks we need in FinalizeDeclaratorGroup()
14730 Diag(FirstDecompDeclaratorInGroup->getLocation(), in FinalizeDeclaratorGroup()
14732 << FirstDeclaratorInGroup->getSourceRange() in FinalizeDeclaratorGroup()
14733 << DD->getSourceRange(); in FinalizeDeclaratorGroup()
14741 Diag(FirstNonDeducedAutoInGroup->getLocation(), in FinalizeDeclaratorGroup()
14743 << FirstNonDeducedAutoInGroup->getType() in FinalizeDeclaratorGroup()
14744 ->hasAutoForTrailingReturnType() in FinalizeDeclaratorGroup()
14745 << FirstDeclaratorInGroup->getSourceRange() in FinalizeDeclaratorGroup()
14746 << DD->getSourceRange(); in FinalizeDeclaratorGroup()
14758 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() && in FinalizeDeclaratorGroup()
14771 // deduction, the program is ill-formed. in BuildDeclaratorGroup()
14777 if (!D || D->isInvalidDecl()) in BuildDeclaratorGroup()
14779 DeducedType *DT = D->getType()->getContainedDeducedType(); in BuildDeclaratorGroup()
14780 if (!DT || DT->getDeducedType().isNull()) in BuildDeclaratorGroup()
14783 Deduced = DT->getDeducedType(); in BuildDeclaratorGroup()
14785 } else if (!Context.hasSameType(DT->getDeducedType(), Deduced)) { in BuildDeclaratorGroup()
14787 auto Dia = Diag(D->getTypeSourceInfo()->getTypeLoc().getBeginLoc(), in BuildDeclaratorGroup()
14789 << (AT ? (unsigned)AT->getKeyword() : 3) << Deduced in BuildDeclaratorGroup()
14790 << DeducedDecl->getDeclName() << DT->getDeducedType() in BuildDeclaratorGroup()
14791 << D->getDeclName(); in BuildDeclaratorGroup()
14792 if (DeducedDecl->hasInit()) in BuildDeclaratorGroup()
14793 Dia << DeducedDecl->getInit()->getSourceRange(); in BuildDeclaratorGroup()
14794 if (D->getInit()) in BuildDeclaratorGroup()
14795 Dia << D->getInit()->getSourceRange(); in BuildDeclaratorGroup()
14796 D->setInvalidDecl(); in BuildDeclaratorGroup()
14818 Group[0]->getLocation()) && in ActOnDocumentableDecls()
14820 Group[0]->getLocation())) in ActOnDocumentableDecls()
14855 // [dcl.meaning]p1: An unqualified-id occurring in a declarator-id shall be a in CheckFunctionOrTemplateParamDeclarator()
14885 "explicit parameter in non-cplusplus mode"); in CheckExplicitObjectParameter()
14888 << P->getSourceRange(); in CheckExplicitObjectParameter()
14892 if (P->isParameterPack()) { in CheckExplicitObjectParameter()
14893 S.Diag(P->getBeginLoc(), diag::err_explicit_object_parameter_pack) in CheckExplicitObjectParameter()
14894 << P->getSourceRange(); in CheckExplicitObjectParameter()
14897 P->setExplicitObjectParameterLoc(ExplicitThisLoc); in CheckExplicitObjectParameter()
14899 LSI->ExplicitObjectParameter = P; in CheckExplicitObjectParameter()
14944 QualType parmDeclType = TInfo->getType(); in ActOnParamDeclarator()
14954 if (R.isSingleResult() && PrevDecl->isTemplateParameter()) { in ActOnParamDeclarator()
14960 if (PrevDecl && S->isDeclScope(PrevDecl)) { in ActOnParamDeclarator()
14962 Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in ActOnParamDeclarator()
14979 New->setInvalidDecl(); in ActOnParamDeclarator()
14983 assert(S->isFunctionPrototypeScope()); in ActOnParamDeclarator()
14984 assert(S->getFunctionPrototypeDepth() >= 1); in ActOnParamDeclarator()
14985 New->setScopeInfo(S->getFunctionPrototypeDepth() - 1, in ActOnParamDeclarator()
14986 S->getNextFunctionPrototypeIndex()); in ActOnParamDeclarator()
14989 S->AddDecl(New); in ActOnParamDeclarator()
14996 Diag(New->getLocation(), diag::err_module_private_local) in ActOnParamDeclarator()
15000 if (New->hasAttr<BlocksAttr>()) { in ActOnParamDeclarator()
15001 Diag(New->getLocation(), diag::err_block_on_nonlocal); in ActOnParamDeclarator()
15019 Param->setImplicit(); in BuildParmVarDeclForTypedef()
15024 // Don't diagnose unused-parameter errors in template instantiations; we in DiagnoseUnusedParameters()
15030 if (!Parameter->isReferenced() && Parameter->getDeclName() && in DiagnoseUnusedParameters()
15031 !Parameter->hasAttr<UnusedAttr>() && in DiagnoseUnusedParameters()
15032 !Parameter->getIdentifier()->isPlaceholder()) { in DiagnoseUnusedParameters()
15033 Diag(Parameter->getLocation(), diag::warn_unused_parameter) in DiagnoseUnusedParameters()
15034 << Parameter->getDeclName(); in DiagnoseUnusedParameters()
15044 // Warn if the return value is pass-by-value and larger than the specified in DiagnoseSizeOfParametersAndReturnValue()
15046 if (!ReturnTy->isDependentType() && ReturnTy.isPODType(Context)) { in DiagnoseSizeOfParametersAndReturnValue()
15049 Diag(D->getLocation(), diag::warn_return_value_size) << D << Size; in DiagnoseSizeOfParametersAndReturnValue()
15052 // Warn if any parameter is pass-by-value and larger than the specified in DiagnoseSizeOfParametersAndReturnValue()
15055 QualType T = Parameter->getType(); in DiagnoseSizeOfParametersAndReturnValue()
15056 if (T->isDependentType() || !T.isPODType(Context)) in DiagnoseSizeOfParametersAndReturnValue()
15060 Diag(Parameter->getLocation(), diag::warn_parameter_size) in DiagnoseSizeOfParametersAndReturnValue()
15072 T->isObjCLifetimeType()) { in CheckParameter()
15077 // - if it's const, use __unsafe_unretained in CheckParameter()
15078 // - otherwise, it's an error in CheckParameter()
15079 if (T->isArrayType()) { in CheckParameter()
15087 << TSInfo->getTypeLoc().getSourceRange(); in CheckParameter()
15091 lifetime = T->getObjCARCImplicitLifetime(); in CheckParameter()
15103 if (New->isParameterPack()) in CheckParameter()
15105 LSI->LocalPacks.push_back(New); in CheckParameter()
15107 if (New->getType().hasNonTrivialToPrimitiveDestructCUnion() || in CheckParameter()
15108 New->getType().hasNonTrivialToPrimitiveCopyCUnion()) in CheckParameter()
15109 checkNonTrivialCUnion(New->getType(), New->getLocation(), in CheckParameter()
15114 if (T->isObjCObjectType()) { in CheckParameter()
15116 getLocForEndOfToken(TSInfo->getTypeLoc().getEndLoc()); in CheckParameter()
15121 New->setType(T); in CheckParameter()
15125 // duration shall not be qualified by an address-space qualifier." in CheckParameter()
15132 (T->isArrayType() || T.getAddressSpace() == LangAS::opencl_private)) && in CheckParameter()
15135 !(T->isFunctionPointerType() && in CheckParameter()
15138 New->setInvalidDecl(); in CheckParameter()
15141 // PPC MMA non-pointer types are not allowed as function argument types. in CheckParameter()
15143 PPC().CheckPPCMMAType(New->getOriginalType(), New->getLocation())) { in CheckParameter()
15144 New->setInvalidDecl(); in CheckParameter()
15166 --i; in ActOnFinishKNRParamDeclarations()
15171 << " int " << FTI.Params[i].Ident->getName() << ";\n"; in ActOnFinishKNRParamDeclarations()
15203 Scope *ParentScope = FnBodyScope->getParent(); in ActOnStartOfFunctionDef()
15206 // we define a non-templated function definition, we will create a declaration in ActOnStartOfFunctionDef()
15234 for (const FunctionDecl *Prev = FD->getPreviousDecl(); Prev; in FindPossiblePrototype()
15235 Prev = Prev->getPreviousDecl()) { in FindPossiblePrototype()
15238 if (Prev->getLexicalDeclContext()->isFunctionOrMethod()) in FindPossiblePrototype()
15242 return Prev->getType()->isFunctionProtoType(); in FindPossiblePrototype()
15251 if (FD->isInvalidDecl()) in ShouldWarnAboutMissingPrototype()
15255 if (!FD->isGlobal()) in ShouldWarnAboutMissingPrototype()
15263 if (isa<TranslationUnitDecl>(FD->getDeclContext()->getRedeclContext())) in ShouldWarnAboutMissingPrototype()
15264 if (IdentifierInfo *II = FD->getIdentifier()) in ShouldWarnAboutMissingPrototype()
15265 if (II->isStr("main") || II->isStr("efi_main")) in ShouldWarnAboutMissingPrototype()
15268 if (FD->isMSVCRTEntryPoint()) in ShouldWarnAboutMissingPrototype()
15272 if (FD->isInlined()) in ShouldWarnAboutMissingPrototype()
15276 if (FD->getDescribedFunctionTemplate()) in ShouldWarnAboutMissingPrototype()
15280 if (FD->isFunctionTemplateSpecialization()) in ShouldWarnAboutMissingPrototype()
15284 if (FD->hasAttr<OpenCLKernelAttr>()) in ShouldWarnAboutMissingPrototype()
15288 if (FD->isDeleted()) in ShouldWarnAboutMissingPrototype()
15291 // Don't warn on implicitly local functions (such as having local-typed in ShouldWarnAboutMissingPrototype()
15293 if (!FD->isExternallyVisible()) in ShouldWarnAboutMissingPrototype()
15309 !FD->isDefined(Definition, /*CheckForPendingFriendDefinition*/ true)) in CheckForFunctionRedefinition()
15312 if (Definition->getFriendObjectKind() != Decl::FOK_None) { in CheckForFunctionRedefinition()
15313 if (FunctionDecl *OrigDef = Definition->getInstantiatedFromMemberFunction()) { in CheckForFunctionRedefinition()
15314 if (FunctionDecl *OrigFD = FD->getInstantiatedFromMemberFunction()) { in CheckForFunctionRedefinition()
15318 declaresSameEntity(cast<Decl>(Definition->getLexicalDeclContext()), in CheckForFunctionRedefinition()
15319 cast<Decl>(FD->getLexicalDeclContext()))) in CheckForFunctionRedefinition()
15328 // Don't emit an error when this is redefinition of a typo-corrected in CheckForFunctionRedefinition()
15336 (Definition->getFormalLinkage() == Linkage::Internal || in CheckForFunctionRedefinition()
15337 Definition->isInlined() || Definition->getDescribedFunctionTemplate() || in CheckForFunctionRedefinition()
15338 Definition->getNumTemplateParameterLists())) { in CheckForFunctionRedefinition()
15339 SkipBody->ShouldSkip = true; in CheckForFunctionRedefinition()
15340 SkipBody->Previous = const_cast<FunctionDecl*>(Definition); in CheckForFunctionRedefinition()
15341 if (auto *TD = Definition->getDescribedFunctionTemplate()) in CheckForFunctionRedefinition()
15347 if (getLangOpts().GNUMode && Definition->isInlineSpecified() && in CheckForFunctionRedefinition()
15348 Definition->getStorageClass() == SC_Extern) in CheckForFunctionRedefinition()
15349 Diag(FD->getLocation(), diag::err_redefinition_extern_inline) in CheckForFunctionRedefinition()
15352 Diag(FD->getLocation(), diag::err_redefinition) << FD; in CheckForFunctionRedefinition()
15354 Diag(Definition->getLocation(), diag::note_previous_definition); in CheckForFunctionRedefinition()
15355 FD->setInvalidDecl(); in CheckForFunctionRedefinition()
15359 CXXRecordDecl *LambdaClass = CallOperator->getParent(); in RebuildLambdaScopeInfo()
15362 LSI->CallOperator = CallOperator; in RebuildLambdaScopeInfo()
15363 LSI->Lambda = LambdaClass; in RebuildLambdaScopeInfo()
15364 LSI->ReturnType = CallOperator->getReturnType(); in RebuildLambdaScopeInfo()
15368 LSI->AfterParameterList = false; in RebuildLambdaScopeInfo()
15369 const LambdaCaptureDefault LCD = LambdaClass->getLambdaCaptureDefault(); in RebuildLambdaScopeInfo()
15372 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_None; in RebuildLambdaScopeInfo()
15374 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_LambdaByval; in RebuildLambdaScopeInfo()
15376 LSI->ImpCaptureStyle = CapturingScopeInfo::ImpCap_LambdaByref; in RebuildLambdaScopeInfo()
15377 DeclarationNameInfo DNI = CallOperator->getNameInfo(); in RebuildLambdaScopeInfo()
15379 LSI->IntroducerRange = DNI.getCXXOperatorNameRange(); in RebuildLambdaScopeInfo()
15380 LSI->Mutable = !CallOperator->isConst(); in RebuildLambdaScopeInfo()
15381 if (CallOperator->isExplicitObjectMemberFunction()) in RebuildLambdaScopeInfo()
15382 LSI->ExplicitObjectParameter = CallOperator->getParamDecl(0); in RebuildLambdaScopeInfo()
15386 auto I = LambdaClass->field_begin(); in RebuildLambdaScopeInfo()
15387 for (const auto &C : LambdaClass->captures()) { in RebuildLambdaScopeInfo()
15390 if (VD->isInitCapture()) in RebuildLambdaScopeInfo()
15391 CurrentInstantiationScope->InstantiatedLocal(VD, VD); in RebuildLambdaScopeInfo()
15393 LSI->addCapture(VD, /*IsBlock*/false, ByRef, in RebuildLambdaScopeInfo()
15397 I->getType(), /*Invalid*/false); in RebuildLambdaScopeInfo()
15400 LSI->addThisCapture(/*Nested*/ false, C.getLocation(), I->getType(), in RebuildLambdaScopeInfo()
15403 LSI->addVLATypeCapture(C.getLocation(), I->getCapturedVLAType(), in RebuildLambdaScopeInfo()
15404 I->getType()); in RebuildLambdaScopeInfo()
15425 FD = FunTmpl->getTemplatedDecl(); in ActOnStartOfFunctionDef()
15434 // potentially evaluated and either: its innermost enclosing non-block scope in ActOnStartOfFunctionDef()
15437 FD->isConsteval() ? ExpressionEvaluationContext::ImmediateFunctionContext in ActOnStartOfFunctionDef()
15447 ExprEvalContexts.back().InImmediateFunctionContext = FD->isConsteval(); in ActOnStartOfFunctionDef()
15449 getLangOpts().CPlusPlus20 && FD->isImmediateEscalating(); in ActOnStartOfFunctionDef()
15452 if (const auto *Attr = FD->getAttr<AliasAttr>()) { in ActOnStartOfFunctionDef()
15453 Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0; in ActOnStartOfFunctionDef()
15454 FD->dropAttr<AliasAttr>(); in ActOnStartOfFunctionDef()
15455 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15457 if (const auto *Attr = FD->getAttr<IFuncAttr>()) { in ActOnStartOfFunctionDef()
15458 Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 1; in ActOnStartOfFunctionDef()
15459 FD->dropAttr<IFuncAttr>(); in ActOnStartOfFunctionDef()
15460 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15462 if (const auto *Attr = FD->getAttr<TargetVersionAttr>()) { in ActOnStartOfFunctionDef()
15464 !Attr->isDefaultVersion()) { in ActOnStartOfFunctionDef()
15466 // defined with non-default target_version attribute in ActOnStartOfFunctionDef()
15468 SkipBody->ShouldSkip = true; in ActOnStartOfFunctionDef()
15474 if (Ctor->getTemplateSpecializationKind() == TSK_ExplicitSpecialization && in ActOnStartOfFunctionDef()
15475 Ctor->isDefaultConstructor() && in ActOnStartOfFunctionDef()
15485 if (!FD->willHaveBody() && !FD->isLateTemplateParsed() && in ActOnStartOfFunctionDef()
15486 !FD->isThisDeclarationInstantiatedFromAFriendDefinition()) { in ActOnStartOfFunctionDef()
15490 if (SkipBody && SkipBody->ShouldSkip) in ActOnStartOfFunctionDef()
15497 FD->setWillHaveBody(); in ActOnStartOfFunctionDef()
15511 if (FD->getTemplateSpecializationInfo() in ActOnStartOfFunctionDef()
15512 ->isExplicitInstantiationOrSpecialization()) { in ActOnStartOfFunctionDef()
15513 Diag(FD->getLocation(), diag::err_lambda_explicit_spec); in ActOnStartOfFunctionDef()
15514 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15528 if (unsigned BuiltinID = FD->getBuiltinID()) { in ActOnStartOfFunctionDef()
15531 Diag(FD->getLocation(), diag::err_builtin_definition) << FD; in ActOnStartOfFunctionDef()
15532 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15539 // shall not be a (possibly cv-qualified) class type that is incomplete in ActOnStartOfFunctionDef()
15541 QualType ResultType = FD->getReturnType(); in ActOnStartOfFunctionDef()
15542 if (!ResultType->isDependentType() && !ResultType->isVoidType() && in ActOnStartOfFunctionDef()
15543 !FD->isInvalidDecl() && BodyKind != FnBodyKind::Delete && in ActOnStartOfFunctionDef()
15544 (RequireCompleteType(FD->getLocation(), ResultType, in ActOnStartOfFunctionDef()
15546 RequireNonAbstractType(FD->getLocation(), FD->getReturnType(), in ActOnStartOfFunctionDef()
15549 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15556 CheckParmsForFunctionDef(FD->parameters(), in ActOnStartOfFunctionDef()
15559 // Add non-parameter declarations already in the function to the current in ActOnStartOfFunctionDef()
15562 for (Decl *NPD : FD->decls()) { in ActOnStartOfFunctionDef()
15570 if (NonParmDecl->getDeclName()) in ActOnStartOfFunctionDef()
15576 for (auto *EI : ED->enumerators()) in ActOnStartOfFunctionDef()
15583 for (auto *Param : FD->parameters()) { in ActOnStartOfFunctionDef()
15584 Param->setOwningFunction(FD); in ActOnStartOfFunctionDef()
15587 if (Param->getIdentifier() && FnBodyScope) { in ActOnStartOfFunctionDef()
15600 !FD->isInvalidDecl() && !FD->isInlined() && in ActOnStartOfFunctionDef()
15602 FD->getFormalLinkage() == Linkage::External && !FD->isTemplated() && in ActOnStartOfFunctionDef()
15603 !FD->isTemplateInstantiation()) { in ActOnStartOfFunctionDef()
15604 assert(FD->isThisDeclarationADefinition()); in ActOnStartOfFunctionDef()
15605 Diag(FD->getLocation(), diag::err_extern_def_in_header_unit); in ActOnStartOfFunctionDef()
15606 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15610 if (const FunctionProtoType *FPT = FD->getType()->getAs<FunctionProtoType>()) in ActOnStartOfFunctionDef()
15611 ResolveExceptionSpec(D->getLocation(), FPT); in ActOnStartOfFunctionDef()
15613 // dllimport cannot be applied to non-inline function definitions. in ActOnStartOfFunctionDef()
15614 if (FD->hasAttr<DLLImportAttr>() && !FD->isInlined() && in ActOnStartOfFunctionDef()
15615 !FD->isTemplateInstantiation()) { in ActOnStartOfFunctionDef()
15616 assert(!FD->hasAttr<DLLExportAttr>()); in ActOnStartOfFunctionDef()
15617 Diag(FD->getLocation(), diag::err_attribute_dllimport_function_definition); in ActOnStartOfFunctionDef()
15618 FD->setInvalidDecl(); in ActOnStartOfFunctionDef()
15629 if (getCurLexicalContext()->isObjCContainer() && in ActOnStartOfFunctionDef()
15630 getCurLexicalContext()->getDeclKind() != Decl::ObjCCategoryImpl && in ActOnStartOfFunctionDef()
15631 getCurLexicalContext()->getDeclKind() != Decl::ObjCImplementation) in ActOnStartOfFunctionDef()
15632 Diag(FD->getLocation(), diag::warn_function_def_in_objc_container); in ActOnStartOfFunctionDef()
15638 if (!FD || FD->isInvalidDecl()) in applyFunctionAttributesBeforeParsingBody()
15641 FD = TD->getTemplatedDecl(); in applyFunctionAttributesBeforeParsingBody()
15642 if (FD && FD->hasAttr<OptimizeNoneAttr>()) { in applyFunctionAttributesBeforeParsingBody()
15652 ReturnStmt **Returns = Scope->Returns.data(); in computeNRVO()
15654 for (unsigned I = 0, E = Scope->Returns.size(); I != E; ++I) { in computeNRVO()
15655 if (const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) { in computeNRVO()
15656 if (!NRVOCandidate->isNRVOVariable()) in computeNRVO()
15657 Returns[I]->setNRVOCandidate(nullptr); in computeNRVO()
15670 // If the placeholder introduces a non-deduced trailing return type, in canDelayFunctionBody()
15673 const auto &Outer = D.getTypeObject(D.getNumTypeObjects() - 1); in canDelayFunctionBody()
15677 return Ty.isNull() || !Ty->isUndeducedType(); in canDelayFunctionBody()
15692 if (const FunctionDecl *FD = D->getAsFunction()) { in canSkipFunctionBody()
15693 if (FD->isConstexpr()) in canSkipFunctionBody()
15698 if (FD->getReturnType()->getContainedDeducedType()) in canSkipFunctionBody()
15707 if (FunctionDecl *FD = Decl->getAsFunction()) in ActOnSkippedFunctionBody()
15708 FD->setHasSkippedBody(); in ActOnSkippedFunctionBody()
15710 MD->setHasSkippedBody(); in ActOnSkippedFunctionBody()
15744 R = !CurBD->doesNotEscape(); in diagnoseImplicitlyRetainedSelf()
15747 CurBD = CurBD->getParent()->getInnermostBlockDecl(); in diagnoseImplicitlyRetainedSelf()
15759 << FixItHint::CreateInsertion(P.first, "self->"); in diagnoseImplicitlyRetainedSelf()
15763 return isa<CXXMethodDecl>(FD) && FD->param_empty() && in methodHasName()
15764 FD->getDeclName().isIdentifier() && FD->getName() == Name; in methodHasName()
15772 return FD->isStatic() && in CanBeGetReturnTypeOnAllocFailure()
15777 RecordDecl *RD = FD->getReturnType()->getAsRecordDecl(); in CheckCoroutineWrapper()
15778 if (!RD || !RD->getUnderlyingDecl()->hasAttr<CoroReturnTypeAttr>()) in CheckCoroutineWrapper()
15783 if (!FD->hasAttr<CoroWrapperAttr>()) in CheckCoroutineWrapper()
15784 Diag(FD->getLocation(), diag::err_coroutine_return_type) << RD; in CheckCoroutineWrapper()
15789 FunctionScopeInfo *FSI = getCurFunction(); in ActOnFinishFunctionBody() local
15790 FunctionDecl *FD = dcl ? dcl->getAsFunction() : nullptr; in ActOnFinishFunctionBody()
15792 if (FSI->UsesFPIntrin && FD && !FD->hasAttr<StrictFPAttr>()) in ActOnFinishFunctionBody()
15793 FD->addAttr(StrictFPAttr::CreateImplicit(Context)); in ActOnFinishFunctionBody()
15799 if (getLangOpts().Coroutines && FD && !FD->hasSkippedBody()) { in ActOnFinishFunctionBody()
15800 if (FSI->isCoroutine()) in ActOnFinishFunctionBody()
15813 // the declaration as deleted, and if the deleted-function-body contains in ActOnFinishFunctionBody()
15821 if (!FD->isDeletedAsWritten()) in ActOnFinishFunctionBody()
15822 FD->setBody(Body); in ActOnFinishFunctionBody()
15823 FD->setWillHaveBody(false); in ActOnFinishFunctionBody()
15824 CheckImmediateEscalatingFunctionDefinition(FD, FSI); in ActOnFinishFunctionBody()
15827 if (!FD->isInvalidDecl() && Body && !FD->isDependentContext() && in ActOnFinishFunctionBody()
15828 FD->getReturnType()->isUndeducedType()) { in ActOnFinishFunctionBody()
15831 // possibly cv-qualified or constrained, but not ref-qualified. in ActOnFinishFunctionBody()
15832 if (!FD->getReturnType()->getAs<AutoType>()) { in ActOnFinishFunctionBody()
15833 Diag(dcl->getLocation(), diag::err_auto_fn_no_return_but_not_auto) in ActOnFinishFunctionBody()
15834 << FD->getReturnType(); in ActOnFinishFunctionBody()
15835 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
15840 FD, dcl->getLocation(), Dummy, in ActOnFinishFunctionBody()
15841 FD->getReturnType()->getAs<AutoType>())) in ActOnFinishFunctionBody()
15842 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
15849 if (LSI->HasImplicitReturnType) { in ActOnFinishFunctionBody()
15853 // [...] if there are no return statements in the compound-statement in ActOnFinishFunctionBody()
15856 LSI->ReturnType.isNull() ? Context.VoidTy : LSI->ReturnType; in ActOnFinishFunctionBody()
15859 const auto *Proto = FD->getType()->castAs<FunctionProtoType>(); in ActOnFinishFunctionBody()
15860 FD->setType(Context.getFunctionType(RetType, Proto->getParamTypes(), in ActOnFinishFunctionBody()
15861 Proto->getExtProtoInfo())); in ActOnFinishFunctionBody()
15867 if (FD->hasImplicitReturnZero() || FD->hasAttr<NakedAttr>()) in ActOnFinishFunctionBody()
15871 // defined at class scope, warn about this non-standard construct. in ActOnFinishFunctionBody()
15872 if (getLangOpts().MicrosoftExt && FD->isPureVirtual() && in ActOnFinishFunctionBody()
15873 !FD->isOutOfLine()) in ActOnFinishFunctionBody()
15874 Diag(FD->getLocation(), diag::ext_pure_function_definition); in ActOnFinishFunctionBody()
15876 if (!FD->isInvalidDecl()) { in ActOnFinishFunctionBody()
15879 if (!FD->isDeleted() && !FD->isDefaulted() && !FD->hasSkippedBody() && in ActOnFinishFunctionBody()
15880 !FD->hasAttr<NakedAttr>()) in ActOnFinishFunctionBody()
15881 DiagnoseUnusedParameters(FD->parameters()); in ActOnFinishFunctionBody()
15882 DiagnoseSizeOfParametersAndReturnValue(FD->parameters(), in ActOnFinishFunctionBody()
15883 FD->getReturnType(), FD); in ActOnFinishFunctionBody()
15887 MarkVTableUsed(FD->getLocation(), Constructor->getParent()); in ActOnFinishFunctionBody()
15890 MarkVTableUsed(FD->getLocation(), Destructor->getParent()); in ActOnFinishFunctionBody()
15895 if (FD->getReturnType()->isRecordType() && in ActOnFinishFunctionBody()
15896 (!getLangOpts().CPlusPlus || !FD->isDependentContext())) in ActOnFinishFunctionBody()
15897 computeNRVO(Body, FSI); in ActOnFinishFunctionBody()
15900 // GNU warning -Wmissing-prototypes: in ActOnFinishFunctionBody()
15907 Diag(FD->getLocation(), diag::warn_missing_prototype) << FD; in ActOnFinishFunctionBody()
15911 // but that could be a zero-parameter prototype in ActOnFinishFunctionBody()
15912 if (TypeSourceInfo *TI = PossiblePrototype->getTypeSourceInfo()) { in ActOnFinishFunctionBody()
15913 TypeLoc TL = TI->getTypeLoc(); in ActOnFinishFunctionBody()
15915 Diag(PossiblePrototype->getLocation(), in ActOnFinishFunctionBody()
15917 << (FD->getNumParams() != 0) in ActOnFinishFunctionBody()
15918 << (FD->getNumParams() == 0 ? FixItHint::CreateInsertion( in ActOnFinishFunctionBody()
15939 StringRef StartTok(LexStart, Buffer.size() - LocInfo.second); in ActOnFinishFunctionBody()
15949 if ((FD->getReturnType()->isAnyPointerType() && in ActOnFinishFunctionBody()
15950 FD->getReturnType()->getPointeeType().isConstQualified()) || in ActOnFinishFunctionBody()
15951 FD->getReturnType().isConstQualified()) { in ActOnFinishFunctionBody()
15954 if (isLocAtConst(FD->getBeginLoc(), getSourceManager(), in ActOnFinishFunctionBody()
15957 return FD->getBeginLoc(); in ActOnFinishFunctionBody()
15959 return FD->getTypeSpecStartLoc(); in ActOnFinishFunctionBody()
15961 Diag(FD->getTypeSpecStartLoc(), in ActOnFinishFunctionBody()
15964 << (FD->getStorageClass() == SC_None in ActOnFinishFunctionBody()
15988 if (!FD->hasWrittenPrototype() && FD->getNumParams() != 0 && in ActOnFinishFunctionBody()
15989 (!PossiblePrototype || (!PossiblePrototype->hasWrittenPrototype() && in ActOnFinishFunctionBody()
15990 !PossiblePrototype->isImplicit()))) { in ActOnFinishFunctionBody()
16004 // -Wstrict-prototypes is enabled. If we already warned about it being in ActOnFinishFunctionBody()
16011 Diag(FD->getLocation(), diag::warn_non_prototype_changes_behavior) in ActOnFinishFunctionBody()
16014 // If we have a possible prototype for the function which is a user- in ActOnFinishFunctionBody()
16017 // note because it's the same behavior-changing problem as with the in ActOnFinishFunctionBody()
16020 Diag(PossiblePrototype->getLocation(), in ActOnFinishFunctionBody()
16027 if (FD->isMultiVersion() && FD->hasAttr<CPUDispatchAttr>() && Body) in ActOnFinishFunctionBody()
16029 if (!CmpndBody->body_empty()) in ActOnFinishFunctionBody()
16030 Diag(CmpndBody->body_front()->getBeginLoc(), in ActOnFinishFunctionBody()
16035 if (MD->isOutOfLine() && (MD = MD->getCanonicalDecl()) && in ActOnFinishFunctionBody()
16036 MD->isVirtual() && in ActOnFinishFunctionBody()
16037 (KeyFunction = Context.getCurrentKeyFunction(MD->getParent())) && in ActOnFinishFunctionBody()
16038 MD == KeyFunction->getCanonicalDecl()) { in ActOnFinishFunctionBody()
16039 // Update the key-function state if necessary for this ABI. in ActOnFinishFunctionBody()
16040 if (FD->isInlined() && in ActOnFinishFunctionBody()
16044 // If the newly-chosen key function is already defined, then we in ActOnFinishFunctionBody()
16046 KeyFunction = Context.getCurrentKeyFunction(MD->getParent()); in ActOnFinishFunctionBody()
16048 if (KeyFunction && KeyFunction->isDefined(Definition)) in ActOnFinishFunctionBody()
16049 MarkVTableUsed(Definition->getLocation(), MD->getParent(), true); in ActOnFinishFunctionBody()
16052 MarkVTableUsed(FD->getLocation(), MD->getParent(), true); in ActOnFinishFunctionBody()
16061 MD->setBody(Body); in ActOnFinishFunctionBody()
16062 if (!MD->isInvalidDecl()) { in ActOnFinishFunctionBody()
16063 DiagnoseSizeOfParametersAndReturnValue(MD->parameters(), in ActOnFinishFunctionBody()
16064 MD->getReturnType(), MD); in ActOnFinishFunctionBody()
16067 computeNRVO(Body, FSI); in ActOnFinishFunctionBody()
16069 if (FSI->ObjCShouldCallSuper) { in ActOnFinishFunctionBody()
16070 Diag(MD->getEndLoc(), diag::warn_objc_missing_super_call) in ActOnFinishFunctionBody()
16071 << MD->getSelector().getAsString(); in ActOnFinishFunctionBody()
16072 FSI->ObjCShouldCallSuper = false; in ActOnFinishFunctionBody()
16074 if (FSI->ObjCWarnForNoDesignatedInitChain) { in ActOnFinishFunctionBody()
16077 MD->isDesignatedInitializerForTheInterface(&InitMethod); in ActOnFinishFunctionBody()
16082 auto IFace = MD->getClassInterface(); in ActOnFinishFunctionBody()
16085 auto SuperD = IFace->getSuperClass(); in ActOnFinishFunctionBody()
16088 return SuperD->getIdentifier() == in ActOnFinishFunctionBody()
16089 ObjC().NSAPIObj->getNSClassId(NSAPI::ClassId_NSObject); in ActOnFinishFunctionBody()
16093 if (!MD->isUnavailable() && !superIsNSObject(MD)) { in ActOnFinishFunctionBody()
16094 Diag(MD->getLocation(), in ActOnFinishFunctionBody()
16096 Diag(InitMethod->getLocation(), in ActOnFinishFunctionBody()
16099 FSI->ObjCWarnForNoDesignatedInitChain = false; in ActOnFinishFunctionBody()
16101 if (FSI->ObjCWarnForNoInitDelegation) { in ActOnFinishFunctionBody()
16103 if (!MD->isUnavailable()) in ActOnFinishFunctionBody()
16104 Diag(MD->getLocation(), in ActOnFinishFunctionBody()
16106 FSI->ObjCWarnForNoInitDelegation = false; in ActOnFinishFunctionBody()
16117 if (Body && FSI->HasPotentialAvailabilityViolations) in ActOnFinishFunctionBody()
16120 assert(!FSI->ObjCShouldCallSuper && in ActOnFinishFunctionBody()
16124 // Verify and clean out per-function state. in ActOnFinishFunctionBody()
16125 if (Body && (!FD || !FD->isDefaulted())) { in ActOnFinishFunctionBody()
16126 // C++ constructors that have function-try-blocks can't have return in ActOnFinishFunctionBody()
16133 if (FSI->NeedsScopeChecking() && !PP.isCodeCompletionEnabled()) in ActOnFinishFunctionBody()
16137 if (!Destructor->getParent()->isDependentType()) in ActOnFinishFunctionBody()
16140 MarkBaseAndMemberDestructorsReferenced(Destructor->getLocation(), in ActOnFinishFunctionBody()
16141 Destructor->getParent()); in ActOnFinishFunctionBody()
16153 // Since the body is valid, issue any analysis-based warnings that are in ActOnFinishFunctionBody()
16159 (FD->isConstexpr() || FD->hasAttr<MSConstexprAttr>()) && in ActOnFinishFunctionBody()
16160 !FD->isInvalidDecl() && in ActOnFinishFunctionBody()
16162 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
16164 if (FD && FD->hasAttr<NakedAttr>()) { in ActOnFinishFunctionBody()
16165 for (const Stmt *S : Body->children()) { in ActOnFinishFunctionBody()
16170 for (const auto *Decl : DS->decls()) { in ActOnFinishFunctionBody()
16173 Var->hasAttr<AsmLabelAttr>() && !Var->hasInit(); in ActOnFinishFunctionBody()
16182 Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function); in ActOnFinishFunctionBody()
16183 Diag(FD->getAttr<NakedAttr>()->getLocation(), diag::note_attribute); in ActOnFinishFunctionBody()
16184 FD->setInvalidDecl(); in ActOnFinishFunctionBody()
16196 "Leftover expressions for odr-use checking"); in ActOnFinishFunctionBody()
16222 if (FD && !FD->isDeleted()) in ActOnFinishFunctionBody()
16223 checkTypeSupport(FD->getType(), FD->getLocation(), FD); in ActOnFinishFunctionBody()
16234 D = TD->getTemplatedDecl(); in ActOnFinishDelayedAttribute()
16239 if (Method->isStatic()) in ActOnFinishDelayedAttribute()
16255 while (!BlockScope->isCompoundStmtScope() && BlockScope->getParent()) in ImplicitlyDefineFunction()
16256 BlockScope = BlockScope->getParent(); in ImplicitlyDefineFunction()
16263 while (!ContextScope->getEntity() || in ImplicitlyDefineFunction()
16264 (!ContextScope->getEntity()->isFunctionOrMethod() && in ImplicitlyDefineFunction()
16265 !ContextScope->getEntity()->isTranslationUnit())) in ImplicitlyDefineFunction()
16266 ContextScope = ContextScope->getParent(); in ImplicitlyDefineFunction()
16267 ContextRAII SavedContext(*this, ContextScope->getEntity()); in ImplicitlyDefineFunction()
16270 // function, see whether there was a locally-scoped declaration of in ImplicitlyDefineFunction()
16272 // (non-visible) declaration, and complain about it. in ImplicitlyDefineFunction()
16276 // that later (non-call) uses can see it. in ImplicitlyDefineFunction()
16284 cast<FunctionDecl>(ExternCPrev)->getType(), in ImplicitlyDefineFunction()
16288 Diag(ExternCPrev->getLocation(), diag::note_previous_declaration); in ImplicitlyDefineFunction()
16297 // OpenCL v2.0 s6.9.u - Implicit function declaration is not supported. in ImplicitlyDefineFunction()
16308 // consumers use typo-correction callbacks to enhance the main diagnostic. in ImplicitlyDefineFunction()
16322 Diagnose = !D->isImplicit(); in ImplicitlyDefineFunction()
16368 FD->setImplicit(); in ImplicitlyDefineFunction()
16377 if (FD->isInvalidDecl()) in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16380 if (FD->getDeclName().getCXXOverloadedOperator() != OO_New && in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16381 FD->getDeclName().getCXXOverloadedOperator() != OO_Array_New) in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16386 if (!FD->isReplaceableGlobalAllocationFunction(&AlignmentParam, &IsNothrow)) in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16390 // An allocation function that has a non-throwing exception specification in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16395 // However, -fcheck-new invalidates this possible assumption, so don't add in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16397 if (!IsNothrow && !FD->hasAttr<ReturnsNonNullAttr>() && in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16399 FD->addAttr(ReturnsNonNullAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16408 // because there is an opt-out switch for it (-fno-assume-sane-operator-new) in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16415 if (!FD->hasAttr<AllocSizeAttr>()) { in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16416 FD->addAttr(AllocSizeAttr::CreateImplicit( in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16418 /*NumElemsParam=*/ParamIdx(), FD->getLocation())); in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16427 if (AlignmentParam && !FD->hasAttr<AllocAlignAttr>()) { in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16428 FD->addAttr(AllocAlignAttr::CreateImplicit( in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16429 Context, ParamIdx(*AlignmentParam, FD), FD->getLocation())); in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16438 // new-extended alignment ([basic.align]) and is no larger than the in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16441 // have new-extended alignment and is of the requested size. in AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction()
16445 if (FD->isInvalidDecl()) in AddKnownFunctionAttributes()
16448 // If this is a built-in function, map its builtin attributes to in AddKnownFunctionAttributes()
16450 if (unsigned BuiltinID = FD->getBuiltinID()) { in AddKnownFunctionAttributes()
16451 // Handle printf-formatting attributes. in AddKnownFunctionAttributes()
16455 if (!FD->hasAttr<FormatAttr>()) { in AddKnownFunctionAttributes()
16457 unsigned int NumParams = FD->getNumParams(); in AddKnownFunctionAttributes()
16459 FD->getParamDecl(FormatIdx)->getType()->isObjCObjectPointerType()) in AddKnownFunctionAttributes()
16461 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
16465 FD->getLocation())); in AddKnownFunctionAttributes()
16470 if (!FD->hasAttr<FormatAttr>()) in AddKnownFunctionAttributes()
16471 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
16475 FD->getLocation())); in AddKnownFunctionAttributes()
16480 if (!FD->hasAttr<CallbackAttr>() && in AddKnownFunctionAttributes()
16482 FD->addAttr(CallbackAttr::CreateImplicit( in AddKnownFunctionAttributes()
16483 Context, Encoding.data(), Encoding.size(), FD->getLocation())); in AddKnownFunctionAttributes()
16494 if (!FD->hasAttr<ConstAttr>() && in AddKnownFunctionAttributes()
16499 FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16506 !FD->hasAttr<ConstAttr>()) { in AddKnownFunctionAttributes()
16514 FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16522 !FD->hasAttr<ReturnsTwiceAttr>()) in AddKnownFunctionAttributes()
16523 FD->addAttr(ReturnsTwiceAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
16524 FD->getLocation())); in AddKnownFunctionAttributes()
16525 if (Context.BuiltinInfo.isNoThrow(BuiltinID) && !FD->hasAttr<NoThrowAttr>()) in AddKnownFunctionAttributes()
16526 FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16527 if (Context.BuiltinInfo.isPure(BuiltinID) && !FD->hasAttr<PureAttr>()) in AddKnownFunctionAttributes()
16528 FD->addAttr(PureAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16529 if (Context.BuiltinInfo.isConst(BuiltinID) && !FD->hasAttr<ConstAttr>()) in AddKnownFunctionAttributes()
16530 FD->addAttr(ConstAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16532 !FD->hasAttr<CUDADeviceAttr>() && !FD->hasAttr<CUDAHostAttr>()) { in AddKnownFunctionAttributes()
16538 FD->addAttr(CUDADeviceAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16540 FD->addAttr(CUDAHostAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16547 if (!FD->hasAttr<AllocAlignAttr>()) in AddKnownFunctionAttributes()
16548 FD->addAttr(AllocAlignAttr::CreateImplicit(Context, ParamIdx(1, FD), in AddKnownFunctionAttributes()
16549 FD->getLocation())); in AddKnownFunctionAttributes()
16558 FD->addAttr(AllocSizeAttr::CreateImplicit( in AddKnownFunctionAttributes()
16559 Context, ParamIdx(1, FD), ParamIdx(2, FD), FD->getLocation())); in AddKnownFunctionAttributes()
16564 FD->addAttr(AllocSizeAttr::CreateImplicit(Context, ParamIdx(2, FD), in AddKnownFunctionAttributes()
16565 ParamIdx(), FD->getLocation())); in AddKnownFunctionAttributes()
16568 FD->addAttr(AllocSizeAttr::CreateImplicit(Context, ParamIdx(1, FD), in AddKnownFunctionAttributes()
16569 ParamIdx(), FD->getLocation())); in AddKnownFunctionAttributes()
16585 if (ParmVarDecl *P = FD->getParamDecl(0u); in AddKnownFunctionAttributes()
16586 !P->hasAttr<LifetimeBoundAttr>()) in AddKnownFunctionAttributes()
16587 P->addAttr( in AddKnownFunctionAttributes()
16588 LifetimeBoundAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16601 FD->isExternC() && !FD->hasAttr<NoThrowAttr>()) { in AddKnownFunctionAttributes()
16602 const auto *FPT = FD->getType()->getAs<FunctionProtoType>(); in AddKnownFunctionAttributes()
16603 if (!FPT || FPT->getExceptionSpecType() == EST_None) in AddKnownFunctionAttributes()
16604 FD->addAttr(NoThrowAttr::CreateImplicit(Context, FD->getLocation())); in AddKnownFunctionAttributes()
16607 IdentifierInfo *Name = FD->getIdentifier(); in AddKnownFunctionAttributes()
16610 if ((!getLangOpts().CPlusPlus && FD->getDeclContext()->isTranslationUnit()) || in AddKnownFunctionAttributes()
16611 (isa<LinkageSpecDecl>(FD->getDeclContext()) && in AddKnownFunctionAttributes()
16612 cast<LinkageSpecDecl>(FD->getDeclContext())->getLanguage() == in AddKnownFunctionAttributes()
16614 // Okay: this could be a libc/libm/Objective-C function we know in AddKnownFunctionAttributes()
16619 if (Name->isStr("asprintf") || Name->isStr("vasprintf")) { in AddKnownFunctionAttributes()
16621 // target-specific builtins, perhaps? in AddKnownFunctionAttributes()
16622 if (!FD->hasAttr<FormatAttr>()) in AddKnownFunctionAttributes()
16623 FD->addAttr(FormatAttr::CreateImplicit(Context, in AddKnownFunctionAttributes()
16625 Name->isStr("vasprintf") ? 0 : 3, in AddKnownFunctionAttributes()
16626 FD->getLocation())); in AddKnownFunctionAttributes()
16629 if (Name->isStr("__CFStringMakeConstantString")) { in AddKnownFunctionAttributes()
16631 // but builds that use -fno-constant-cfstrings don't go through that. in AddKnownFunctionAttributes()
16632 if (!FD->hasAttr<FormatArgAttr>()) in AddKnownFunctionAttributes()
16633 FD->addAttr(FormatArgAttr::CreateImplicit(Context, ParamIdx(1, FD), in AddKnownFunctionAttributes()
16634 FD->getLocation())); in AddKnownFunctionAttributes()
16655 NewTD->setInvalidDecl(); in ParseTypedefDecl()
16660 if (CurContext->isFunctionOrMethod()) in ParseTypedefDecl()
16661 Diag(NewTD->getLocation(), diag::err_module_private_local) in ParseTypedefDecl()
16667 NewTD->setModulePrivate(); in ParseTypedefDecl()
16672 // enum), the first typedef-name declared by the declaration in ParseTypedefDecl()
16695 SourceLocation UnderlyingLoc = TI->getTypeLoc().getBeginLoc(); in CheckEnumUnderlyingType()
16696 QualType T = TI->getType(); in CheckEnumUnderlyingType()
16698 if (T->isDependentType()) in CheckEnumUnderlyingType()
16703 if (const BuiltinType *BT = T->getAs<BuiltinType>()) in CheckEnumUnderlyingType()
16704 if (BT->isInteger()) in CheckEnumUnderlyingType()
16708 << T << T->isBitIntType(); in CheckEnumUnderlyingType()
16714 if (IsScoped != Prev->isScoped()) { in CheckEnumRedeclaration()
16716 << Prev->isScoped(); in CheckEnumRedeclaration()
16717 Diag(Prev->getLocation(), diag::note_previous_declaration); in CheckEnumRedeclaration()
16721 if (IsFixed && Prev->isFixed()) { in CheckEnumRedeclaration()
16722 if (!EnumUnderlyingTy->isDependentType() && in CheckEnumRedeclaration()
16723 !Prev->getIntegerType()->isDependentType() && in CheckEnumRedeclaration()
16725 Prev->getIntegerType())) { in CheckEnumRedeclaration()
16728 << EnumUnderlyingTy << Prev->getIntegerType(); in CheckEnumRedeclaration()
16729 Diag(Prev->getLocation(), diag::note_previous_declaration) in CheckEnumRedeclaration()
16730 << Prev->getIntegerTypeRange(); in CheckEnumRedeclaration()
16733 } else if (IsFixed != Prev->isFixed()) { in CheckEnumRedeclaration()
16735 << Prev->isFixed(); in CheckEnumRedeclaration()
16736 Diag(Prev->getLocation(), diag::note_previous_declaration); in CheckEnumRedeclaration()
16760 /// Determine if tag kind is a class-key compatible with
16800 // The class-key or enum keyword present in the in isAcceptableTagRedeclaration()
16801 // elaborated-type-specifier shall agree in kind with the in isAcceptableTagRedeclaration()
16802 // declaration to which the name in the elaborated-type-specifier in isAcceptableTagRedeclaration()
16804 // elaborated-type-specifier that declares a class-name or in isAcceptableTagRedeclaration()
16807 // elaborated-type-specifier, the enum keyword shall be used to in isAcceptableTagRedeclaration()
16808 // refer to an enumeration (7.2), the union class-key shall be in isAcceptableTagRedeclaration()
16810 // struct class-key shall be used to refer to a class (clause 9) in isAcceptableTagRedeclaration()
16811 // declared using the class or struct class-key. in isAcceptableTagRedeclaration()
16812 TagTypeKind OldTag = Previous->getTagKind(); in isAcceptableTagRedeclaration()
16818 // Non-class tags can't be mismatched at this point. in isAcceptableTagRedeclaration()
16822 // Declarations for which -Wmismatched-tags is disabled are entirely ignored in isAcceptableTagRedeclaration()
16835 return IsIgnoredLoc(Tag->getLocation()); in isAcceptableTagRedeclaration()
16838 Previous = Previous->getPreviousDecl(); in isAcceptableTagRedeclaration()
16841 OldTag = Previous->getTagKind(); in isAcceptableTagRedeclaration()
16846 isTemplate = Record->getDescribedClassTemplate(); in isAcceptableTagRedeclaration()
16850 // In a template instantiation, do not offer fix-its for tag mismatches in isAcceptableTagRedeclaration()
16861 // On definitions, check all previous tags and issue a fix-it for each in isAcceptableTagRedeclaration()
16863 if (Previous->getDefinition()) { in isAcceptableTagRedeclaration()
16864 // Don't suggest fix-its for redefinitions. in isAcceptableTagRedeclaration()
16869 for (const TagDecl *I : Previous->redecls()) { in isAcceptableTagRedeclaration()
16870 if (I->getTagKind() != NewTag) { in isAcceptableTagRedeclaration()
16879 << getRedeclDiagFromTagKind(I->getTagKind()); in isAcceptableTagRedeclaration()
16881 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion) in isAcceptableTagRedeclaration()
16883 << FixItHint::CreateReplacement(I->getInnerLocStart(), in isAcceptableTagRedeclaration()
16891 // there is a non-ignored definition), or otherwise the kind of the prior in isAcceptableTagRedeclaration()
16892 // (non-ignored) declaration. in isAcceptableTagRedeclaration()
16893 const TagDecl *PrevDef = Previous->getDefinition(); in isAcceptableTagRedeclaration()
16897 if (Redecl->getTagKind() != NewTag) { in isAcceptableTagRedeclaration()
16901 Diag(Redecl->getLocation(), diag::note_previous_use); in isAcceptableTagRedeclaration()
16903 // If there is a previous definition, suggest a fix-it. in isAcceptableTagRedeclaration()
16906 << getRedeclDiagFromTagKind(Redecl->getTagKind()) in isAcceptableTagRedeclaration()
16908 TypeWithKeyword::getTagTypeKindName(Redecl->getTagKind())); in isAcceptableTagRedeclaration()
16930 DeclContext *DC = ND->getDeclContext()->getRedeclContext(); in createFriendTagNNSFixIt()
16931 for (; !DC->isTranslationUnit(); DC = DC->getParent()) { in createFriendTagNNSFixIt()
16935 if (!Namespace || Namespace->isAnonymousNamespace()) in createFriendTagNNSFixIt()
16937 IdentifierInfo *II = Namespace->getIdentifier(); in createFriendTagNNSFixIt()
16949 if (DC->isTranslationUnit()) in createFriendTagNNSFixIt()
16953 OS << II->getName() << "::"; in createFriendTagNNSFixIt()
16960 /// using-declaration).
16963 OldDC = OldDC->getRedeclContext(); in isAcceptableTagRedeclContext()
16964 NewDC = NewDC->getRedeclContext(); in isAcceptableTagRedeclContext()
16966 if (OldDC->Equals(NewDC)) in isAcceptableTagRedeclContext()
16972 (OldDC->Encloses(NewDC) || NewDC->Encloses(OldDC))) in isAcceptableTagRedeclContext()
17004 // for non-C++ cases. in ActOnTag()
17013 // If an elaborated-type-specifier is the sole constituent of a in ActOnTag()
17014 // declaration, the declaration is ill-formed unless it is an explicit in ActOnTag()
17018 // If the enum-head-name of an opaque-enum-declaration contains a in ActOnTag()
17019 // nested-name-specifier, the declaration shall be an explicit in ActOnTag()
17036 if (TemplateParams->size() > 0) { in ActOnTag()
17047 /*FriendLoc*/ SourceLocation(), TemplateParameterLists.size() - 1, in ActOnTag()
17052 Diag(TemplateParams->getTemplateLoc(), diag::err_template_tag_noparams) in ActOnTag()
17065 // If an elaborated-type-specifier appears with the friend specifier as in ActOnTag()
17066 // an entire member-declaration, the member-declaration shall have one in ActOnTag()
17068 // friend class-key nested-name-specifier(opt) identifier ; in ActOnTag()
17069 // friend class-key simple-template-id ; in ActOnTag()
17070 // friend class-key nested-name-specifier template(opt) in ActOnTag()
17071 // simple-template-id ; in ActOnTag()
17073 // Since enum is not a class-key, so declarations like "friend enum E;" in ActOnTag()
17074 // are ill-formed. Although CWG2363 reaffirms that such declarations are in ActOnTag()
17095 // C++0x 7.2p2: The type-specifier-seq of an enum-base shall name an in ActOnTag()
17096 // integral type; any cv-qualification is ignored. in ActOnTag()
17105 if (DiagnoseUnexpandedParameterPack(TI->getTypeLoc().getBeginLoc(), TI, in ActOnTag()
17112 // the underlying type unless the user enables -fms-compatibility. This in ActOnTag()
17128 /// Create a new tag decl in C/ObjC. Since the ODR-like semantics for ObjC/C in ActOnTag()
17131 auto createTagFromNewDecl = [&]() -> TagDecl * { in ActOnTag()
17148 ED->setIntegerTypeSourceInfo(TI); in ActOnTag()
17150 ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0)); in ActOnTag()
17151 QualType EnumTy = ED->getIntegerType(); in ActOnTag()
17152 ED->setPromotionType(Context.isPromotableIntegerType(EnumTy) in ActOnTag()
17172 (!SkipBody || !SkipBody->ShouldSkip)) { in ActOnTag()
17177 New->setLexicalDeclContext(CurContext); in ActOnTag()
17183 // We have a nested-name tag ('struct foo::bar'). in ActOnTag()
17212 // Look-up name inside 'foo::'. in ActOnTag()
17220 // nested-name-specifier refers to the current instantiation, in ActOnTag()
17223 // this as a dependent elaborated-type-specifier. in ActOnTag()
17224 // But this only makes any sense for reference-like lookups. in ActOnTag()
17242 // -- every member of class T that is itself a type in ActOnTag()
17261 if (!ND->getDeclContext()->getRedeclContext()->Equals( in ActOnTag()
17262 SearchDC->getRedeclContext())) in ActOnTag()
17270 // a template-id and the declaration is a function or an in ActOnTag()
17271 // elaborated-type-specifier, the lookup to determine whether in ActOnTag()
17282 DeclContext *EnclosingNS = SearchDC->getEnclosingNamespaceContext(); in ActOnTag()
17287 DeclContext *DC = ND->getDeclContext()->getRedeclContext(); in ActOnTag()
17288 if (DC->isFileContext() && in ActOnTag()
17289 !EnclosingNS->Encloses(ND->getDeclContext())) { in ActOnTag()
17317 SearchDC = SearchDC->getParent(); in ActOnTag()
17323 SearchDC = SearchDC->getParent(); in ActOnTag()
17329 SearchDC = SearchDC->getParent(); in ActOnTag()
17333 Previous.getFoundDecl()->isTemplateParameter()) { in ActOnTag()
17341 DC->Equals(getStdNamespace())) { in ActOnTag()
17342 if (Name->isStr("bad_alloc")) { in ActOnTag()
17351 } else if (Name->isStr("align_val_t")) { in ActOnTag()
17370 // -- for an elaborated-type-specifier of the form in ActOnTag()
17372 // class-key identifier in ActOnTag()
17374 // if the elaborated-type-specifier is used in the in ActOnTag()
17375 // decl-specifier-seq or parameter-declaration-clause of a in ActOnTag()
17377 // declared as a class-name in the namespace that contains in ActOnTag()
17380 // non-class, non-function-prototype scope that contains the in ActOnTag()
17406 // If a friend declaration in a non-local class first declares a in ActOnTag()
17409 SearchDC = RD->isLocalClass() ? RD->isLocalClass() in ActOnTag()
17410 : SearchDC->getEnclosingNamespaceContext(); in ActOnTag()
17417 // type declared by an elaborated-type-specifier. In C that is not correct in ActOnTag()
17431 if (Previous.empty() && SkipBody && SkipBody->Previous) in ActOnTag()
17432 Previous.addDecl(SkipBody->Previous); in ActOnTag()
17442 // This is also okay for elaborated-type-specifiers, which is in ActOnTag()
17445 // see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#407 in ActOnTag()
17448 if (const TagType *TT = TD->getUnderlyingType()->getAs<TagType>()) { in ActOnTag()
17449 TagDecl *Tag = TT->getDecl(); in ActOnTag()
17450 if (Tag->getDeclName() == Name && in ActOnTag()
17451 Tag->getDeclContext()->getRedeclContext() in ActOnTag()
17452 ->Equals(TD->getDeclContext()->getRedeclContext())) { in ActOnTag()
17471 *this, OldTag->getDeclContext(), SearchDC))) { in ActOnTag()
17473 Diag(Shadow->getTargetDecl()->getLocation(), in ActOnTag()
17475 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl) in ActOnTag()
17496 (PrevTagDecl->getTagKind() != TagTypeKind::Enum && in ActOnTag()
17502 PrevTagDecl->getKindName()); in ActOnTag()
17505 Diag(PrevTagDecl->getLocation(), diag::note_previous_use); in ActOnTag()
17508 Kind = PrevTagDecl->getTagKind(); in ActOnTag()
17518 PrevTagDecl->getTagKind() == TagTypeKind::Enum) { in ActOnTag()
17525 EnumUnderlyingTy = TI->getType().getUnqualifiedType(); in ActOnTag()
17539 // A member shall not be declared twice in the member-specification, in ActOnTag()
17542 if (TUK == TagUseKind::Declaration && PrevDecl->isCXXClassMember() && in ActOnTag()
17543 S->isDeclScope(PrevDecl)) { in ActOnTag()
17545 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration); in ActOnTag()
17556 (PrevTagDecl->getFriendObjectKind() == in ActOnTag()
17558 PrevDecl->getOwningModule() != getCurrentModule()) && in ActOnTag()
17567 if (!getTagInjectionContext(CurContext)->getRedeclContext() in ActOnTag()
17568 ->Equals(PrevDecl->getDeclContext()->getRedeclContext())) in ActOnTag()
17580 if (NamedDecl *Def = PrevTagDecl->getDefinition()) { in ActOnTag()
17588 RD->getTemplateSpecializationKind() != in ActOnTag()
17592 ED->getTemplateSpecializationKind() != in ActOnTag()
17596 // Note that clang allows ODR-like semantics for ObjC/C, i.e., do in ActOnTag()
17611 SkipBody->CheckSameAsPrevious = true; in ActOnTag()
17612 SkipBody->New = createTagFromNewDecl(); in ActOnTag()
17613 SkipBody->Previous = Def; in ActOnTag()
17616 SkipBody->ShouldSkip = true; in ActOnTag()
17617 SkipBody->Previous = Def; in ActOnTag()
17625 if (!getLangOpts().CPlusPlus && S->containedInPrototypeScope()) in ActOnTag()
17641 auto *TD = Context.getTagDeclType(PrevTagDecl)->getAsTagDecl(); in ActOnTag()
17642 if (TD->isBeingDefined()) { in ActOnTag()
17644 Diag(PrevTagDecl->getLocation(), in ActOnTag()
17660 SearchDC = PrevTagDecl->getDeclContext(); in ActOnTag()
17675 // is non-NULL, it's a definition of the tag declared by in ActOnTag()
17682 // Use a better diagnostic if an elaborated-type-specifier in ActOnTag()
17684 // (non-redeclaration) lookup. in ActOnTag()
17690 Diag(PrevDecl->getLocation(), diag::note_declared_at); in ActOnTag()
17702 Diag(PrevDecl->getLocation(), diag::note_previous_decl) << PrevDecl; in ActOnTag()
17711 << Name << Kind << TND->getUnderlyingType(); in ActOnTag()
17712 Diag(PrevDecl->getLocation(), diag::note_previous_decl) << PrevDecl; in ActOnTag()
17754 if (isStdAlignValT && (!StdAlignValT || getStdAlignValT()->isImplicit())) in ActOnTag()
17760 if (IsFixed && cast<EnumDecl>(New)->isFixed()) { in ActOnTag()
17761 // C++0x: 7.2p2: opaque-enum-declaration. in ActOnTag()
17764 else if (PrevDecl && (Def = cast<EnumDecl>(PrevDecl)->getDefinition())) { in ActOnTag()
17767 Diag(Def->getLocation(), diag::note_previous_definition); in ActOnTag()
17781 ED->setIntegerTypeSourceInfo(TI); in ActOnTag()
17783 ED->setIntegerType(QualType(EnumUnderlying.get<const Type *>(), 0)); in ActOnTag()
17784 QualType EnumTy = ED->getIntegerType(); in ActOnTag()
17785 ED->setPromotionType(Context.isPromotableIntegerType(EnumTy) in ActOnTag()
17788 assert(ED->isComplete() && "enum with type should be complete"); in ActOnTag()
17800 if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit())) in ActOnTag()
17810 Diag(New->getLocation(), diag::ext_type_defined_in_offsetof) in ActOnTag()
17811 << (OOK == OOK_Macro) << New->getSourceRange(); in ActOnTag()
17814 // A type-specifier-seq shall not define a class or enumeration [...]. in ActOnTag()
17818 Diag(New->getLocation(), diag::err_type_defined_in_type_specifier) in ActOnTag()
17824 DC->getDeclKind() == Decl::Enum) { in ActOnTag()
17825 Diag(New->getLocation(), diag::err_type_defined_in_enum) in ActOnTag()
17834 // nested-name-specifier against the current context. in ActOnTag()
17841 New->setQualifierInfo(SS.getWithLocInContext(Context)); in ActOnTag()
17843 New->setTemplateParameterListsInfo(Context, TemplateParameterLists); in ActOnTag()
17860 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) { in ActOnTag()
17868 Diag(New->getLocation(), diag::err_module_private_specialization) in ActOnTag()
17874 else if (!SearchDC->isFunctionOrMethod()) in ActOnTag()
17875 New->setModulePrivate(); in ActOnTag()
17887 getNonFieldDeclScope(S)->isFunctionPrototypeScope()) { in ActOnTag()
17902 New->setInvalidDecl(); in ActOnTag()
17906 New->setLexicalDeclContext(CurContext); in ActOnTag()
17913 New->setObjectOfFriendDecl(getLangOpts().MSVCCompat); in ActOnTag()
17916 if (!Invalid && SearchDC->isRecord()) in ActOnTag()
17922 if (TUK == TagUseKind::Definition && (!SkipBody || !SkipBody->ShouldSkip)) in ActOnTag()
17923 New->startDefinition(); in ActOnTag()
17933 New->setAccess(PrevDecl->getAccess()); in ActOnTag()
17935 DeclContext *DC = New->getDeclContext()->getRedeclContext(); in ActOnTag()
17936 DC->makeDeclVisibleInContext(New); in ActOnTag()
17944 CurContext->addDecl(New); in ActOnTag()
17948 if (IdentifierInfo *II = New->getIdentifier()) in ActOnTag()
17949 if (!New->isInvalidDecl() && in ActOnTag()
17950 New->getDeclContext()->getRedeclContext()->isTranslationUnit() && in ActOnTag()
17951 II->isStr("FILE")) in ActOnTag()
17966 if (isMemberSpecialization && !New->isInvalidDecl()) in ActOnTag()
17973 if (New->isBeingDefined()) in ActOnTag()
17975 RD->completeDefinition(); in ActOnTag()
17977 } else if (SkipBody && SkipBody->ShouldSkip) { in ActOnTag()
17978 return SkipBody->Previous; in ActOnTag()
18015 FieldCollector->StartClass(); in ActOnStartCXXMemberDeclarations()
18017 if (!Record->getIdentifier()) in ActOnStartCXXMemberDeclarations()
18021 Record->markAbstract(); in ActOnStartCXXMemberDeclarations()
18024 Record->addAttr(FinalAttr::Create(Context, FinalLoc, in ActOnStartCXXMemberDeclarations()
18030 // [...] The class-name is also inserted into the scope of the in ActOnStartCXXMemberDeclarations()
18031 // class itself; this is known as the injected-class-name. For in ActOnStartCXXMemberDeclarations()
18032 // purposes of access checking, the injected-class-name is treated in ActOnStartCXXMemberDeclarations()
18035 Context, Record->getTagKind(), CurContext, Record->getBeginLoc(), in ActOnStartCXXMemberDeclarations()
18036 Record->getLocation(), Record->getIdentifier(), in ActOnStartCXXMemberDeclarations()
18040 InjectedClassName->setImplicit(); in ActOnStartCXXMemberDeclarations()
18041 InjectedClassName->setAccess(AS_public); in ActOnStartCXXMemberDeclarations()
18042 if (ClassTemplateDecl *Template = Record->getDescribedClassTemplate()) in ActOnStartCXXMemberDeclarations()
18043 InjectedClassName->setDescribedClassTemplate(Template); in ActOnStartCXXMemberDeclarations()
18045 assert(InjectedClassName->isInjectedClassName() && in ActOnStartCXXMemberDeclarations()
18046 "Broken injected-class-name"); in ActOnStartCXXMemberDeclarations()
18053 Tag->setBraceRange(BraceRange); in ActOnTagFinishDefinition()
18056 if (Tag->isBeingDefined()) { in ActOnTagFinishDefinition()
18057 assert(Tag->isInvalidDecl() && "We should already have completed it"); in ActOnTagFinishDefinition()
18059 RD->completeDefinition(); in ActOnTagFinishDefinition()
18063 FieldCollector->FinishClass(); in ActOnTagFinishDefinition()
18064 if (RD->hasAttr<SYCLSpecialClassAttr>()) { in ActOnTagFinishDefinition()
18065 auto *Def = RD->getDefinition(); in ActOnTagFinishDefinition()
18068 for (auto *Method : Def->methods()) { in ActOnTagFinishDefinition()
18069 if (!Method->getIdentifier()) in ActOnTagFinishDefinition()
18071 if (Method->getName() == "__init") in ActOnTagFinishDefinition()
18074 if (NumInitMethods > 1 || !Def->hasInitMethod()) in ActOnTagFinishDefinition()
18075 Diag(RD->getLocation(), diag::err_sycl_special_type_num_init_method); in ActOnTagFinishDefinition()
18084 if (getCurrentModule() && getCurrentModule()->isInterfaceOrPartition()) in ActOnTagFinishDefinition()
18085 MarkVTableUsed(RD->getLocation(), RD, /*DefinitionRequired=*/true); in ActOnTagFinishDefinition()
18091 if (getCurLexicalContext()->isObjCContainer() && in ActOnTagFinishDefinition()
18092 Tag->getDeclContext()->isFileContext()) in ActOnTagFinishDefinition()
18093 Tag->setTopLevelDeclInObjCContainer(); in ActOnTagFinishDefinition()
18096 if (!Tag->isInvalidDecl()) in ActOnTagFinishDefinition()
18111 if (llvm::any_of(RD->fields(), in ActOnTagFinishDefinition()
18112 [](const FieldDecl *FD) { return FD->isBitField(); })) in ActOnTagFinishDefinition()
18120 Tag->setInvalidDecl(); in ActOnTagDefinitionError()
18123 if (Tag->isBeingDefined()) { in ActOnTagDefinitionError()
18125 RD->completeDefinition(); in ActOnTagDefinitionError()
18141 if (BitWidth->containsErrors()) in VerifyBitField()
18144 // C99 6.7.2.1p4 - verify the field type. in VerifyBitField()
18145 // C++ 9.6p3: A bit-field shall have integral or enumeration type. in VerifyBitField()
18146 if (!FieldTy->isDependentType() && !FieldTy->isIntegralOrEnumerationType()) { in VerifyBitField()
18153 << FieldName << FieldTy << BitWidth->getSourceRange(); in VerifyBitField()
18155 << FieldTy << BitWidth->getSourceRange(); in VerifyBitField()
18160 // If the bit-width is type- or value-dependent, don't try to check in VerifyBitField()
18162 if (BitWidth->isValueDependent() || BitWidth->isTypeDependent()) in VerifyBitField()
18171 // Zero-width bitfield is ok for anonymous field. in VerifyBitField()
18174 << FieldName << BitWidth->getSourceRange(); in VerifyBitField()
18184 // The size of the bit-field must not exceed our maximum permitted object in VerifyBitField()
18191 if (!FieldTy->isDependentType()) { in VerifyBitField()
18196 // Over-wide bitfields are an error in C or when using the MSVC bitfield in VerifyBitField()
18214 if (BitfieldIsOverwide && !FieldTy->isBooleanType() && FieldName) { in VerifyBitField()
18249 QualType T = TInfo->getType(); in HandleField()
18293 if (PrevDecl && PrevDecl->isTemplateParameter()) { in HandleField()
18310 if (NewFD->isInvalidDecl()) in HandleField()
18311 Record->setInvalidDecl(); in HandleField()
18314 NewFD->setModulePrivate(); in HandleField()
18316 if (NewFD->isInvalidDecl() && PrevDecl) { in HandleField()
18322 Record->addDecl(NewFD); in HandleField()
18337 if (D) InvalidDecl = D->isInvalidType(); in CheckFieldDecl()
18341 if (T.isNull() || T->containsErrors()) { in CheckFieldDecl()
18347 if (!EltTy->isDependentType() && !EltTy->containsErrors()) { in CheckFieldDecl()
18351 Record->setInvalidDecl(); in CheckFieldDecl()
18355 EltTy->isIncompleteType(&Def); in CheckFieldDecl()
18356 if (Def && Def->isInvalidDecl()) { in CheckFieldDecl()
18357 Record->setInvalidDecl(); in CheckFieldDecl()
18364 if (T.hasAddressSpace() || T->isDependentAddressSpaceType() || in CheckFieldDecl()
18365 T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) { in CheckFieldDecl()
18367 Record->setInvalidDecl(); in CheckFieldDecl()
18372 // OpenCL v1.2 s6.9b,r & OpenCL v2.0 s6.12.5 - The following types cannot be in CheckFieldDecl()
18374 if (T->isEventT() || T->isImageType() || T->isSamplerT() || in CheckFieldDecl()
18375 T->isBlockPointerType()) { in CheckFieldDecl()
18377 Record->setInvalidDecl(); in CheckFieldDecl()
18389 // Anonymous bit-fields cannot be cv-qualified (CWG 2229). in CheckFieldDecl()
18398 if (!InvalidDecl && T->isVariablyModifiedType()) { in CheckFieldDecl()
18412 // If this is declared as a bit-field, check the bit-field. in CheckFieldDecl()
18415 VerifyBitField(Loc, II, T, Record->isMsStruct(Context), BitWidth).get(); in CheckFieldDecl()
18425 if (T->isReferenceType()) in CheckFieldDecl()
18433 if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid()) in CheckFieldDecl()
18434 ErrLoc = D->getDeclSpec().getStorageClassSpecLoc(); in CheckFieldDecl()
18445 // brace-or-equal-initializer. in CheckFieldDecl()
18452 NewFD->setInvalidDecl(); in CheckFieldDecl()
18455 !PrevDecl->isPlaceholderVar(getLangOpts())) { in CheckFieldDecl()
18457 Diag(PrevDecl->getLocation(), diag::note_previous_declaration); in CheckFieldDecl()
18458 NewFD->setInvalidDecl(); in CheckFieldDecl()
18462 if (Record->isUnion()) { in CheckFieldDecl()
18463 if (const RecordType *RT = EltTy->getAs<RecordType>()) { in CheckFieldDecl()
18464 CXXRecordDecl* RDecl = cast<CXXRecordDecl>(RT->getDecl()); in CheckFieldDecl()
18465 if (RDecl->getDefinition()) { in CheckFieldDecl()
18466 // C++ [class.union]p1: An object of a class with a non-trivial in CheckFieldDecl()
18467 // constructor, a non-trivial copy constructor, a non-trivial in CheckFieldDecl()
18468 // destructor, or a non-trivial copy assignment operator in CheckFieldDecl()
18472 NewFD->setInvalidDecl(); in CheckFieldDecl()
18477 // the program is ill-formed, except when compiling with MSVC extensions in CheckFieldDecl()
18479 if (EltTy->isReferenceType()) { in CheckFieldDecl()
18480 Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? in CheckFieldDecl()
18483 << NewFD->getDeclName() << EltTy; in CheckFieldDecl()
18485 NewFD->setInvalidDecl(); in CheckFieldDecl()
18496 if (NewFD->hasAttrs()) in CheckFieldDecl()
18500 // In auto-retain/release, infer strong retension for fields of in CheckFieldDecl()
18503 NewFD->setInvalidDecl(); in CheckFieldDecl()
18508 // PPC MMA non-pointer types are not allowed as field types. in CheckFieldDecl()
18510 PPC().CheckPPCMMAType(T, NewFD->getLocation())) in CheckFieldDecl()
18511 NewFD->setInvalidDecl(); in CheckFieldDecl()
18513 NewFD->setAccess(AS); in CheckFieldDecl()
18521 if (FD->isInvalidDecl() || FD->getType()->isDependentType()) in CheckNontrivialField()
18524 QualType EltTy = Context.getBaseElementType(FD->getType()); in CheckNontrivialField()
18525 if (const RecordType *RT = EltTy->getAs<RecordType>()) { in CheckNontrivialField()
18526 CXXRecordDecl *RDecl = cast<CXXRecordDecl>(RT->getDecl()); in CheckNontrivialField()
18527 if (RDecl->getDefinition()) { in CheckNontrivialField()
18533 // We're required to check for any non-trivial constructors. Since the in CheckNontrivialField()
18535 // user-declared constructors, we just need to check that there is a in CheckNontrivialField()
18538 if (RDecl->hasNonTrivialCopyConstructor()) in CheckNontrivialField()
18540 else if (!RDecl->hasTrivialDefaultConstructor()) in CheckNontrivialField()
18542 else if (RDecl->hasNonTrivialCopyAssignment()) in CheckNontrivialField()
18544 else if (RDecl->hasNonTrivialDestructor()) in CheckNontrivialField()
18549 getLangOpts().ObjCAutoRefCount && RDecl->hasObjectMember()) { in CheckNontrivialField()
18550 // Objective-C++ ARC: it is an error to have a non-trivial field of in CheckNontrivialField()
18551 // a union. However, system headers in Objective-C programs in CheckNontrivialField()
18552 // occasionally have Objective-C lifetime objects within unions, in CheckNontrivialField()
18555 SourceLocation Loc = FD->getLocation(); in CheckNontrivialField()
18557 if (!FD->hasAttr<UnavailableAttr>()) in CheckNontrivialField()
18558 FD->addAttr(UnavailableAttr::CreateImplicit(Context, "", in CheckNontrivialField()
18565 FD->getLocation(), in CheckNontrivialField()
18569 << FD->getParent()->isUnion() << FD->getDeclName() in CheckNontrivialField()
18585 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1]; in ActOnLastBitfield()
18588 if (!Ivar->isBitField() || Ivar->isZeroLengthBitField(Context)) in ActOnLastBitfield()
18593 if (!CD->IsClassExtension()) in ActOnLastBitfield()
18623 if (!Record->hasUserDeclaredDestructor()) { in ComputeSelectedDestructor()
18627 SourceLocation Loc = Record->getLocation(); in ComputeSelectedDestructor()
18630 for (auto *Decl : Record->decls()) { in ComputeSelectedDestructor()
18632 if (DD->isInvalidDecl()) in ComputeSelectedDestructor()
18634 S.AddOverloadCandidate(DD, DeclAccessPair::make(DD, DD->getAccess()), {}, in ComputeSelectedDestructor()
18636 …assert(DD->isIneligibleOrNotSelected() && "Selecting a destructor but a destructor was already sel… in ComputeSelectedDestructor()
18650 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(Best->Function)); in ComputeSelectedDestructor()
18670 Record->setInvalidDecl(); in ComputeSelectedDestructor()
18677 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(OCS.begin()->Function)); in ComputeSelectedDestructor()
18683 /// - they are both default constructors,
18684 /// - they are both copy or move constructors with the same first parameter
18686 /// - they are both copy or move assignment operators with the same first
18687 /// parameter type and the same cv-qualifiers and ref-qualifier, if any.
18692 // We don't want to compare templates to non-templates: See in AreSpecialMemberFunctionsSameKind()
18693 // https://github.com/llvm/llvm-project/issues/59206 in AreSpecialMemberFunctionsSameKind()
18695 return bool(M1->getDescribedFunctionTemplate()) == in AreSpecialMemberFunctionsSameKind()
18696 bool(M2->getDescribedFunctionTemplate()); in AreSpecialMemberFunctionsSameKind()
18699 if (!Context.hasSameType(M1->getNonObjectParameter(0)->getType(), in AreSpecialMemberFunctionsSameKind()
18700 M2->getNonObjectParameter(0)->getType())) in AreSpecialMemberFunctionsSameKind()
18702 if (!Context.hasSameType(M1->getFunctionObjectParameterReferenceType(), in AreSpecialMemberFunctionsSameKind()
18703 M2->getFunctionObjectParameterReferenceType())) in AreSpecialMemberFunctionsSameKind()
18711 /// - the function is not deleted,
18712 /// - the associated constraints, if any, are satisfied, and
18713 /// - no special member function of the same kind whose associated constraints
18721 const Expr *Constraints = Method->getTrailingRequiresClause(); in SetEligibleMethods()
18738 if (FunctionDecl *MF = OrigMethod->getInstantiatedFromMemberFunction()) in SetEligibleMethods()
18741 const Expr *Constraints = OrigMethod->getTrailingRequiresClause(); in SetEligibleMethods()
18747 if (FunctionDecl *MF = OtherMethod->getInstantiatedFromMemberFunction()) in SetEligibleMethods()
18754 const Expr *OtherConstraints = OtherMethod->getTrailingRequiresClause(); in SetEligibleMethods()
18774 Method->setIneligibleOrNotSelected(false); in SetEligibleMethods()
18775 Record->addedEligibleSpecialMemberFunction(Method, in SetEligibleMethods()
18789 for (auto *Decl : Record->decls()) { in ComputeSpecialMemberFunctionsEligiblity()
18794 MD = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl()); in ComputeSpecialMemberFunctionsEligiblity()
18799 if (CD->isInvalidDecl()) in ComputeSpecialMemberFunctionsEligiblity()
18801 if (CD->isDefaultConstructor()) in ComputeSpecialMemberFunctionsEligiblity()
18803 else if (CD->isCopyConstructor()) in ComputeSpecialMemberFunctionsEligiblity()
18805 else if (CD->isMoveConstructor()) in ComputeSpecialMemberFunctionsEligiblity()
18807 } else if (MD->isCopyAssignmentOperator()) { in ComputeSpecialMemberFunctionsEligiblity()
18809 } else if (MD->isMoveAssignmentOperator()) { in ComputeSpecialMemberFunctionsEligiblity()
18832 // If this is an Objective-C @implementation or category and we have in ActOnFields()
18837 switch (DC->getKind()) { in ActOnFields()
18840 Context.ResetObjCLayout(cast<ObjCCategoryDecl>(DC)->getClassInterface()); in ActOnFields()
18844 ResetObjCLayout(cast<ObjCImplementationDecl>(DC)->getClassInterface()); in ActOnFields()
18856 for (const auto *I : Record->decls()) { in ActOnFields()
18858 if (IFD->getDeclName()) in ActOnFields()
18871 const Type *FDTy = FD->getType().getTypePtr(); in ActOnFields()
18873 if (!FD->isAnonymousStructOrUnion()) { in ActOnFields()
18880 if (FD->isInvalidDecl()) { in ActOnFields()
18881 EnclosingDecl->setInvalidDecl(); in ActOnFields()
18896 if (FDTy->isFunctionType()) { in ActOnFields()
18898 Diag(FD->getLocation(), diag::err_field_declared_as_function) in ActOnFields()
18899 << FD->getDeclName(); in ActOnFields()
18900 FD->setInvalidDecl(); in ActOnFields()
18901 EnclosingDecl->setInvalidDecl(); in ActOnFields()
18903 } else if (FDTy->isIncompleteArrayType() && in ActOnFields()
18911 if (!Record->isUnion() && !IsLastField) { in ActOnFields()
18912 Diag(FD->getLocation(), diag::err_flexible_array_not_at_end) in ActOnFields()
18913 << FD->getDeclName() << FD->getType() in ActOnFields()
18914 << llvm::to_underlying(Record->getTagKind()); in ActOnFields()
18915 Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration); in ActOnFields()
18916 FD->setInvalidDecl(); in ActOnFields()
18917 EnclosingDecl->setInvalidDecl(); in ActOnFields()
18919 } else if (Record->isUnion()) in ActOnFields()
18929 Diag(FD->getLocation(), DiagID) in ActOnFields()
18930 << FD->getDeclName() << llvm::to_underlying(Record->getTagKind()); in ActOnFields()
18936 if (CXXRecord && CXXRecord->getNumVBases() != 0) in ActOnFields()
18937 Diag(FD->getLocation(), diag::err_flexible_array_virtual_base) in ActOnFields()
18938 << FD->getDeclName() << llvm::to_underlying(Record->getTagKind()); in ActOnFields()
18940 Diag(FD->getLocation(), diag::ext_c99_flexible_array_member) in ActOnFields()
18941 << FD->getDeclName() << llvm::to_underlying(Record->getTagKind()); in ActOnFields()
18943 // If the element type has a non-trivial destructor, we would not in ActOnFields()
18948 QualType BaseElem = Context.getBaseElementType(FD->getType()); in ActOnFields()
18949 if (!BaseElem->isDependentType() && BaseElem.isDestructedType()) { in ActOnFields()
18950 Diag(FD->getLocation(), diag::err_flexible_array_has_nontrivial_dtor) in ActOnFields()
18951 << FD->getDeclName() << FD->getType(); in ActOnFields()
18952 FD->setInvalidDecl(); in ActOnFields()
18953 EnclosingDecl->setInvalidDecl(); in ActOnFields()
18957 Record->setHasFlexibleArrayMember(true); in ActOnFields()
18963 } else if (!FDTy->isDependentType() && in ActOnFields()
18965 FD->getLocation(), FD->getType(), in ActOnFields()
18968 FD->setInvalidDecl(); in ActOnFields()
18969 EnclosingDecl->setInvalidDecl(); in ActOnFields()
18971 } else if (const RecordType *FDTTy = FDTy->getAs<RecordType>()) { in ActOnFields()
18972 if (Record && FDTTy->getDecl()->hasFlexibleArrayMember()) { in ActOnFields()
18975 Record->setHasFlexibleArrayMember(true); in ActOnFields()
18976 if (!Record->isUnion()) { in ActOnFields()
18981 Diag(FD->getLocation(), diag::ext_variable_sized_type_in_struct) in ActOnFields()
18982 << FD->getDeclName() << FD->getType(); in ActOnFields()
18986 Diag(FD->getLocation(), diag::ext_flexible_array_in_struct) in ActOnFields()
18987 << FD->getDeclName(); in ActOnFields()
18992 RequireNonAbstractType(FD->getLocation(), FD->getType(), in ActOnFields()
18996 FD->setInvalidDecl(); in ActOnFields()
18998 if (Record && FDTTy->getDecl()->hasObjectMember()) in ActOnFields()
18999 Record->setHasObjectMember(true); in ActOnFields()
19000 if (Record && FDTTy->getDecl()->hasVolatileMember()) in ActOnFields()
19001 Record->setHasVolatileMember(true); in ActOnFields()
19002 } else if (FDTy->isObjCObjectType()) { in ActOnFields()
19003 /// A field cannot be an Objective-c object in ActOnFields()
19004 Diag(FD->getLocation(), diag::err_statically_allocated_object) in ActOnFields()
19005 << FixItHint::CreateInsertion(FD->getLocation(), "*"); in ActOnFields()
19006 QualType T = Context.getObjCObjectPointerType(FD->getType()); in ActOnFields()
19007 FD->setType(T); in ActOnFields()
19008 } else if (Record && Record->isUnion() && in ActOnFields()
19009 FD->getType().hasNonTrivialObjCLifetime() && in ActOnFields()
19010 getSourceManager().isInSystemHeader(FD->getLocation()) && in ActOnFields()
19011 !getLangOpts().CPlusPlus && !FD->hasAttr<UnavailableAttr>() && in ActOnFields()
19012 (FD->getType().getObjCLifetime() != Qualifiers::OCL_Strong || in ActOnFields()
19013 !Context.hasDirectOwnershipQualifier(FD->getType()))) { in ActOnFields()
19015 // headers that have non-trivial ObjC ownership qualifications are marked in ActOnFields()
19020 FD->addAttr(UnavailableAttr::CreateImplicit( in ActOnFields()
19022 FD->getLocation())); in ActOnFields()
19025 !Record->hasObjectMember()) { in ActOnFields()
19026 if (FD->getType()->isObjCObjectPointerType() || in ActOnFields()
19027 FD->getType().isObjCGCStrong()) in ActOnFields()
19028 Record->setHasObjectMember(true); in ActOnFields()
19029 else if (Context.getAsArrayType(FD->getType())) { in ActOnFields()
19030 QualType BaseType = Context.getBaseElementType(FD->getType()); in ActOnFields()
19031 if (BaseType->isRecordType() && in ActOnFields()
19032 BaseType->castAs<RecordType>()->getDecl()->hasObjectMember()) in ActOnFields()
19033 Record->setHasObjectMember(true); in ActOnFields()
19034 else if (BaseType->isObjCObjectPointerType() || in ActOnFields()
19036 Record->setHasObjectMember(true); in ActOnFields()
19042 QualType FT = FD->getType(); in ActOnFields()
19044 Record->setNonTrivialToPrimitiveDefaultInitialize(true); in ActOnFields()
19046 Record->isUnion()) in ActOnFields()
19047 Record->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(true); in ActOnFields()
19051 Record->setNonTrivialToPrimitiveCopy(true); in ActOnFields()
19052 if (FT.hasNonTrivialToPrimitiveCopyCUnion() || Record->isUnion()) in ActOnFields()
19053 Record->setHasNonTrivialToPrimitiveCopyCUnion(true); in ActOnFields()
19056 Record->setNonTrivialToPrimitiveDestroy(true); in ActOnFields()
19057 Record->setParamDestroyedInCallee(true); in ActOnFields()
19058 if (FT.hasNonTrivialToPrimitiveDestructCUnion() || Record->isUnion()) in ActOnFields()
19059 Record->setHasNonTrivialToPrimitiveDestructCUnion(true); in ActOnFields()
19062 if (const auto *RT = FT->getAs<RecordType>()) { in ActOnFields()
19063 if (RT->getDecl()->getArgPassingRestrictions() == in ActOnFields()
19065 Record->setArgPassingRestrictions( in ActOnFields()
19068 Record->setArgPassingRestrictions( in ActOnFields()
19072 if (Record && FD->getType().isVolatileQualified()) in ActOnFields()
19073 Record->setHasVolatileMember(true); in ActOnFields()
19075 if (FD->getIdentifier()) in ActOnFields()
19083 Scope *Parent = S->getParent(); in ActOnFields()
19084 if (Parent && Parent->isTypeAliasScope() && in ActOnFields()
19085 Parent->isTemplateParamScope()) in ActOnFields()
19086 Record->setInvalidDecl(); in ActOnFields()
19090 if (!CXXRecord->isInvalidDecl()) { in ActOnFields()
19091 // Set access bits correctly on the directly-declared conversions. in ActOnFields()
19093 I = CXXRecord->conversion_begin(), in ActOnFields()
19094 E = CXXRecord->conversion_end(); I != E; ++I) in ActOnFields()
19095 I.setAccess((*I)->getAccess()); in ActOnFields()
19098 // Add any implicitly-declared members to this class. in ActOnFields()
19101 if (!CXXRecord->isDependentType()) { in ActOnFields()
19102 if (!CXXRecord->isInvalidDecl()) { in ActOnFields()
19106 if (CXXRecord->getNumVBases()) { in ActOnFields()
19108 CXXRecord->getFinalOverriders(FinalOverriders); in ActOnFields()
19113 for (OverridingMethods::iterator SO = M->second.begin(), in ActOnFields()
19114 SOEnd = M->second.end(); in ActOnFields()
19116 assert(SO->second.size() > 0 && in ActOnFields()
19118 if (SO->second.size() == 1) in ActOnFields()
19124 // program is ill-formed. in ActOnFields()
19125 Diag(Record->getLocation(), diag::err_multiple_final_overriders) in ActOnFields()
19126 << (const NamedDecl *)M->first << Record; in ActOnFields()
19127 Diag(M->first->getLocation(), in ActOnFields()
19130 OM = SO->second.begin(), in ActOnFields()
19131 OMEnd = SO->second.end(); in ActOnFields()
19133 Diag(OM->Method->getLocation(), diag::note_final_overrider) in ActOnFields()
19134 << (const NamedDecl *)M->first << OM->Method->getParent(); in ActOnFields()
19136 Record->setInvalidDecl(); in ActOnFields()
19139 CXXRecord->completeDefinition(&FinalOverriders); in ActOnFields()
19149 Record->completeDefinition(); in ActOnFields()
19159 // Clang. This happens when a non-forward declared / defined type is in ActOnFields()
19170 return !TD->isCompleteDefinition(); in ActOnFields()
19173 QualType FieldType = FD->getType().getDesugaredType(Context); in ActOnFields()
19175 QualType PointeeType = cast<PointerType>(FieldType)->getPointeeType(); in ActOnFields()
19176 return PointeeType.getDesugaredType(Context)->isFunctionType(); in ActOnFields()
19184 (Record->hasAttr<RandomizeLayoutAttr>() || in ActOnFields()
19185 (!Record->hasAttr<NoRandomizeLayoutAttr>() && in ActOnFields()
19186 llvm::all_of(Record->decls(), IsFunctionPointerOrForwardDecl))) && in ActOnFields()
19187 !Record->isUnion() && !getLangOpts().RandstructSeed.empty() && in ActOnFields()
19188 !Record->isRandomized()) { in ActOnFields()
19192 Record->reorderDecls(NewDeclOrdering); in ActOnFields()
19197 auto *Dtor = CXXRecord->getDestructor(); in ActOnFields()
19198 if (Dtor && Dtor->isImplicit() && in ActOnFields()
19200 CXXRecord->setImplicitDestructorIsDeleted(); in ActOnFields()
19201 SetDeclDeleted(Dtor, CXXRecord->getLocation()); in ActOnFields()
19205 if (Record->hasAttrs()) { in ActOnFields()
19208 if (const MSInheritanceAttr *IA = Record->getAttr<MSInheritanceAttr>()) in ActOnFields()
19210 IA->getRange(), IA->getBestCase(), in ActOnFields()
19211 IA->getInheritanceModel()); in ActOnFields()
19224 CXXRecord->getLexicalDeclContext()->isExternCContext() && in ActOnFields()
19225 !CXXRecord->isDependentType() && !inTemplateInstantiation() && in ActOnFields()
19226 CXXRecord->isCLike(); in ActOnFields()
19232 for (RecordDecl::field_iterator I = Record->field_begin(), in ActOnFields()
19233 E = Record->field_end(); in ActOnFields()
19236 if (I->isUnnamedBitField()) { in ActOnFields()
19237 if (!I->isZeroLengthBitField(Context)) in ActOnFields()
19241 QualType FieldType = I->getType(); in ActOnFields()
19242 if (FieldType->isIncompleteType() || in ActOnFields()
19255 << IsEmpty << Record->isUnion() << (NonBitFields > 1); in ActOnFields()
19263 << Record->isUnion(); in ActOnFields()
19270 ID->setEndOfDefinitionLoc(RBrac); in ActOnFields()
19273 ClsFields[i]->setLexicalDeclContext(ID); in ActOnFields()
19274 ID->addDecl(ClsFields[i]); in ActOnFields()
19278 if (ID->getSuperClass()) in ActOnFields()
19279 ObjC().DiagnoseDuplicateIvars(ID, ID->getSuperClass()); in ActOnFields()
19282 assert(IMPDecl && "ActOnFields - missing ObjCImplementationDecl"); in ActOnFields()
19286 ClsFields[I]->setLexicalDeclContext(IMPDecl); in ActOnFields()
19289 IMPDecl->setIvarLBraceLoc(LBrac); in ActOnFields()
19290 IMPDecl->setIvarRBraceLoc(RBrac); in ActOnFields()
19296 // CDecl->setLocEnd(RBrac); in ActOnFields()
19299 ObjCInterfaceDecl *IDecl = CDecl->getClassInterface(); in ActOnFields()
19303 IDecl->getIvarDecl(ClsFields[i]->getIdentifier())) { in ActOnFields()
19304 Diag(ClsFields[i]->getLocation(), in ActOnFields()
19306 Diag(ClsIvar->getLocation(), diag::note_previous_definition); in ActOnFields()
19309 for (const auto *Ext : IDecl->known_extensions()) { in ActOnFields()
19311 = Ext->getIvarDecl(ClsFields[i]->getIdentifier())) { in ActOnFields()
19312 Diag(ClsFields[i]->getLocation(), in ActOnFields()
19314 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition); in ActOnFields()
19319 ClsFields[i]->setLexicalDeclContext(CDecl); in ActOnFields()
19320 CDecl->addDecl(ClsFields[i]); in ActOnFields()
19322 CDecl->setIvarLBraceLoc(LBrac); in ActOnFields()
19323 CDecl->setIvarRBraceLoc(RBrac); in ActOnFields()
19334 assert((T->isIntegralType(Context) || T->isEnumeralType()) && in isRepresentableIntegerValue()
19339 if (T->isSignedIntegerOrEnumerationType()) in isRepresentableIntegerValue()
19340 --BitWidth; in isRepresentableIntegerValue()
19351 assert((T->isIntegralType(Context) || in getNextLargerIntegralType()
19352 T->isEnumeralType()) && "Integral type required!"); in getNextLargerIntegralType()
19363 QualType *Types = T->isSignedIntegerOrEnumerationType()? SignedIntegralTypes in getNextLargerIntegralType()
19388 if (Enum->isDependentType() || Val->isTypeDependent() || in CheckEnumConstant()
19389 Val->containsErrors()) in CheckEnumConstant()
19394 if (getLangOpts().CPlusPlus11 && Enum->isFixed()) { in CheckEnumConstant()
19396 // constant-expression in the enumerator-definition shall be a converted in CheckEnumConstant()
19398 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
19406 } else if (!Val->isValueDependent() && in CheckEnumConstant()
19412 if (Enum->isComplete()) { in CheckEnumConstant()
19413 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
19415 // In Obj-C and Microsoft mode, require the enumeration value to be in CheckEnumConstant()
19417 // we perform a non-narrowing conversion as part of converted constant in CheckEnumConstant()
19431 EltTy->isBooleanType() ? CK_IntegralToBoolean in CheckEnumConstant()
19438 // - If an initializer is specified for an enumerator, the in CheckEnumConstant()
19440 EltTy = Val->getType(); in CheckEnumConstant()
19450 << toString(EnumVal, 10) << Val->getSourceRange() in CheckEnumConstant()
19452 else if (!Context.hasSameType(Val->getType(), Context.IntTy)) { in CheckEnumConstant()
19456 EltTy = Val->getType(); in CheckEnumConstant()
19463 if (Enum->isDependentType()) in CheckEnumConstant()
19469 // - If no initializer is specified for the first enumerator, the in CheckEnumConstant()
19474 if (Enum->isFixed()) { in CheckEnumConstant()
19475 EltTy = Enum->getIntegerType(); in CheckEnumConstant()
19482 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
19484 EltTy = LastEnumConst->getType(); in CheckEnumConstant()
19487 if (EnumVal < LastEnumConst->getInitVal()) { in CheckEnumConstant()
19492 // - Otherwise the type of the initializing value is the same as in CheckEnumConstant()
19497 // exists, the program is ill-formed. in CheckEnumConstant()
19499 if (T.isNull() || Enum->isFixed()) { in CheckEnumConstant()
19502 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
19505 if (Enum->isFixed()) in CheckEnumConstant()
19506 // When the underlying type is fixed, this is ill-formed. in CheckEnumConstant()
19520 EnumVal = LastEnumConst->getInitVal(); in CheckEnumConstant()
19521 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType()); in CheckEnumConstant()
19533 !EltTy->isDependentType() && in CheckEnumConstant()
19542 if (!EltTy->isDependentType()) { in CheckEnumConstant()
19546 EnumVal.setIsSigned(EltTy->isSignedIntegerOrEnumerationType()); in CheckEnumConstant()
19568 EnumDecl *PrevED = cast<EnumDecl>(PrevECD->getDeclContext()); in shouldSkipAnonEnumBody()
19570 if (!PrevED->getDeclName() && !hasVisibleDefinition(PrevED, &Hidden)) { in shouldSkipAnonEnumBody()
19598 if (PrevDecl && PrevDecl->isTemplateParameter()) { in ActOnEnumConstant()
19608 // - every enumerator of every member of class T that is an unscoped in ActOnEnumConstant()
19610 if (getLangOpts().CPlusPlus && !TheEnumDecl->isScoped()) in ActOnEnumConstant()
19611 DiagnoseClassNameShadow(TheEnumDecl->getDeclContext(), in ActOnEnumConstant()
19620 if (!TheEnumDecl->isScoped() && isa<ValueDecl>(PrevDecl)) { in ActOnEnumConstant()
19645 New->setAccess(TheEnumDecl->getAccess()); in ActOnEnumConstant()
19657 // Element2 = Element1 - 1
19660 Expr *InitExpr = ECD->getInitExpr(); in ValidDuplicateEnum()
19663 InitExpr = InitExpr->IgnoreImpCasts(); in ValidDuplicateEnum()
19666 if (!BO->isAdditiveOp()) in ValidDuplicateEnum()
19668 IntegerLiteral *IL = dyn_cast<IntegerLiteral>(BO->getRHS()); in ValidDuplicateEnum()
19671 if (IL->getValue() != 1) in ValidDuplicateEnum()
19674 InitExpr = BO->getLHS(); in ValidDuplicateEnum()
19682 EnumConstantDecl *EnumConstant = dyn_cast<EnumConstantDecl>(DRE->getDecl()); in ValidDuplicateEnum()
19686 if (cast<EnumDecl>(TagDecl::castFromDeclContext(ECD->getDeclContext())) != in ValidDuplicateEnum()
19698 if (!Enum->getIdentifier()) in CheckForDuplicateEnumValues()
19702 if (Enum->getNumPositiveBits() > 63 || Enum->getNumNegativeBits() > 64) in CheckForDuplicateEnumValues()
19705 if (S.Diags.isIgnored(diag::warn_duplicate_enum_values, Enum->getLocation())) in CheckForDuplicateEnumValues()
19718 llvm::APSInt Val = D->getInitVal(); in CheckForDuplicateEnumValues()
19731 // this constant. Skip this enum since it may be ill-formed. in CheckForDuplicateEnumValues()
19737 if (ECD->getInitExpr()) in CheckForDuplicateEnumValues()
19758 DeclOrVector& Entry = Iter->second; in CheckForDuplicateEnumValues()
19766 Vec->push_back(D); in CheckForDuplicateEnumValues()
19767 Vec->push_back(ECD); in CheckForDuplicateEnumValues()
19780 if (*Vec->begin() == ECD) in CheckForDuplicateEnumValues()
19783 Vec->push_back(ECD); in CheckForDuplicateEnumValues()
19788 assert(Vec->size() > 1 && "ECDVector should have at least 2 elements."); in CheckForDuplicateEnumValues()
19791 auto *FirstECD = Vec->front(); in CheckForDuplicateEnumValues()
19792 S.Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values) in CheckForDuplicateEnumValues()
19793 << FirstECD << toString(FirstECD->getInitVal(), 10) in CheckForDuplicateEnumValues()
19794 << FirstECD->getSourceRange(); in CheckForDuplicateEnumValues()
19799 S.Diag(ECD->getLocation(), diag::note_duplicate_element) in CheckForDuplicateEnumValues()
19800 << ECD << toString(ECD->getInitVal(), 10) in CheckForDuplicateEnumValues()
19801 << ECD->getSourceRange(); in CheckForDuplicateEnumValues()
19807 assert(ED->isClosedFlag() && "looking for value in non-flag or open enum"); in IsValueInFlagEnum()
19808 assert(ED->isCompleteDefinition() && "expected enum definition"); in IsValueInFlagEnum()
19811 llvm::APInt &FlagBits = R.first->second; in IsValueInFlagEnum()
19814 for (auto *E : ED->enumerators()) { in IsValueInFlagEnum()
19815 const auto &EVal = E->getInitVal(); in IsValueInFlagEnum()
19816 // Only single-bit enumerators introduce new flag values. in IsValueInFlagEnum()
19843 if (Enum->isDependentType()) { in ActOnEnumBody()
19849 ECD->setType(EnumType); in ActOnEnumBody()
19852 Enum->completeDefinition(Context.DependentTy, Context.DependentTy, 0, 0); in ActOnEnumBody()
19873 const llvm::APSInt &InitVal = ECD->getInitVal(); in ActOnEnumBody()
19889 // If the enumerator-list is empty, the values of the enumeration are as if in ActOnEnumBody()
19909 bool Packed = Enum->hasAttr<PackedAttr>(); in ActOnEnumBody()
19910 // -fshort-enums is the equivalent to specifying the packed attribute on all in ActOnEnumBody()
19917 if (Enum->isComplete()) { in ActOnEnumBody()
19918 BestType = Enum->getIntegerType(); in ActOnEnumBody()
19949 Diag(Enum->getLocation(), diag::ext_enum_too_large); in ActOnEnumBody()
19981 // This can happen with bit-precise integer types, but those are not in ActOnEnumBody()
19984 // a 128-bit integer, we should consider doing the same. in ActOnEnumBody()
19985 Diag(Enum->getLocation(), diag::ext_enum_too_large); in ActOnEnumBody()
20007 llvm::APSInt InitVal = ECD->getInitVal(); in ActOnEnumBody()
20015 !Enum->isFixed() && in ActOnEnumBody()
20020 } else if (ECD->getType() == BestType) { in ActOnEnumBody()
20024 // enum-specifier, each enumerator has the type of its in ActOnEnumBody()
20026 ECD->setType(EnumType); in ActOnEnumBody()
20031 NewSign = BestType->isSignedIntegerOrEnumerationType(); in ActOnEnumBody()
20037 ECD->setInitVal(Context, InitVal); in ActOnEnumBody()
20040 if (ECD->getInitExpr() && in ActOnEnumBody()
20041 !Context.hasSameType(NewTy, ECD->getInitExpr()->getType())) in ActOnEnumBody()
20042 ECD->setInitExpr(ImplicitCastExpr::Create( in ActOnEnumBody()
20043 Context, NewTy, CK_IntegralCast, ECD->getInitExpr(), in ActOnEnumBody()
20047 // enum-specifier, each enumerator has the type of its in ActOnEnumBody()
20049 ECD->setType(EnumType); in ActOnEnumBody()
20051 ECD->setType(NewTy); in ActOnEnumBody()
20054 Enum->completeDefinition(BestType, BestPromotionType, in ActOnEnumBody()
20059 if (Enum->isClosedFlag()) { in ActOnEnumBody()
20064 llvm::APSInt InitVal = ECD->getInitVal(); in ActOnEnumBody()
20067 Diag(ECD->getLocation(), diag::warn_flag_enum_constant_out_of_range) in ActOnEnumBody()
20073 if (Enum->hasAttrs()) in ActOnEnumBody()
20085 CurContext->addDecl(New); in ActOnFileScopeAsmDecl()
20091 CurContext->addDecl(New); in ActOnStartTopLevelStmtDecl()
20099 D->setStmt(Statement); in ActOnFinishTopLevelStmtDecl()
20115 Context, AliasName->getName(), /*IsLiteralLabel=*/true, Info); in ActOnPragmaRedefineExtname()
20123 PrevDecl->addAttr(Attr); in ActOnPragmaRedefineExtname()
20125 Diag(PrevDecl->getLocation(), diag::warn_redefine_extname_not_applied) in ActOnPragmaRedefineExtname()
20138 PrevDecl->addAttr(WeakAttr::CreateImplicit(Context, PragmaLoc)); in ActOnPragmaWeakID()
20154 if (!PrevDecl->hasAttr<AliasAttr>()) in ActOnPragmaWeakAlias()
20164 assert(FD && "Expected non-null FunctionDecl"); in getEmissionStatus()
20168 if (LangOpts.SYCLIsDevice && FD->hasAttr<SYCLKernelAttr>()) in getEmissionStatus()
20172 if (FD->isDependentContext()) in getEmissionStatus()
20177 // We have to check the GVA linkage of the function's *definition* -- if we in getEmissionStatus()
20180 const FunctionDecl *Def = FD->getDefinition(); in getEmissionStatus()
20190 OMPDeclareTargetDeclAttr::getDeviceType(FD->getCanonicalDecl()); in getEmissionStatus()
20212 OMPDeclareTargetDeclAttr::getDeviceType(FD->getCanonicalDecl()); in getEmissionStatus()
20224 // (Technically, we do emit a host-side stub for global functions, but this in getEmissionStatus()
20237 // Otherwise, the function is known-emitted if it's in our set of in getEmissionStatus()
20238 // known-emitted functions. in getEmissionStatus()
20243 // Host-side references to a __global__ function refer to the stub, so the in shouldIgnoreInHostDeviceCheck()
20249 // known-emitted. in shouldIgnoreInHostDeviceCheck()