63#include "llvm/ADT/ArrayRef.h"
64#include "llvm/ADT/STLForwardCompat.h"
65#include "llvm/ADT/ScopeExit.h"
66#include "llvm/ADT/SmallPtrSet.h"
67#include "llvm/ADT/SmallString.h"
68#include "llvm/ADT/StringExtras.h"
69#include "llvm/ADT/StringRef.h"
70#include "llvm/Support/SaveAndRestore.h"
71#include "llvm/TargetParser/Triple.h"
75#include <unordered_map>
82 Decl *Group[2] = { OwnedType, Ptr };
93 TypeNameValidatorCCC(
bool AllowInvalid,
bool WantClass =
false,
94 bool AllowTemplates =
false,
95 bool AllowNonTemplates =
true)
96 : AllowInvalidDecl(AllowInvalid), WantClassName(WantClass),
97 AllowTemplates(AllowTemplates), AllowNonTemplates(AllowNonTemplates) {
98 WantExpressionKeywords =
false;
99 WantCXXNamedCasts =
false;
100 WantRemainingKeywords =
false;
103 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
105 if (!AllowInvalidDecl && ND->isInvalidDecl())
109 return AllowTemplates;
115 if (AllowNonTemplates)
120 if (AllowTemplates) {
121 auto *RD = dyn_cast<CXXRecordDecl>(ND);
122 if (!RD || !RD->isInjectedClassName())
125 return RD->getDescribedClassTemplate() ||
132 return !WantClassName && candidate.
isKeyword();
135 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
136 return std::make_unique<TypeNameValidatorCCC>(*
this);
140 bool AllowInvalidDecl;
143 bool AllowNonTemplates;
150 auto *LookupRD = dyn_cast_or_null<CXXRecordDecl>(LookupCtx);
151 auto *FoundRD = dyn_cast<CXXRecordDecl>(TD);
153 FoundRD->isInjectedClassName() &&
157 ? diag::ext_out_of_line_qualified_id_type_names_constructor
158 : diag::err_out_of_line_qualified_id_type_names_constructor)
168enum class UnqualifiedTypeNameLookupResult {
179static UnqualifiedTypeNameLookupResult
184 return UnqualifiedTypeNameLookupResult::NotFound;
186 UnqualifiedTypeNameLookupResult FoundTypeDecl =
187 UnqualifiedTypeNameLookupResult::NotFound;
191 }
else if (
auto *TST = dyn_cast<TemplateSpecializationType>(
192 Base.getType().getCanonicalType())) {
195 if (!TST->isDependentType())
197 auto *TD = TST->getTemplateName().getAsTemplateDecl();
200 if (
auto *BasePrimaryTemplate =
201 dyn_cast_or_null<CXXRecordDecl>(TD->getTemplatedDecl())) {
203 BaseRD = BasePrimaryTemplate;
204 else if (
auto *CTD = dyn_cast<ClassTemplateDecl>(TD)) {
206 CTD->findPartialSpecialization(
Base.getType()))
215 return UnqualifiedTypeNameLookupResult::FoundNonType;
216 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
218 if (FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound) {
220 case UnqualifiedTypeNameLookupResult::FoundNonType:
221 return UnqualifiedTypeNameLookupResult::FoundNonType;
222 case UnqualifiedTypeNameLookupResult::FoundType:
223 FoundTypeDecl = UnqualifiedTypeNameLookupResult::FoundType;
225 case UnqualifiedTypeNameLookupResult::NotFound:
232 return FoundTypeDecl;
240 UnqualifiedTypeNameLookupResult FoundTypeDecl =
241 UnqualifiedTypeNameLookupResult::NotFound;
243 DC && FoundTypeDecl == UnqualifiedTypeNameLookupResult::NotFound;
247 RD = dyn_cast<CXXRecordDecl>(DC);
251 if (FoundTypeDecl != UnqualifiedTypeNameLookupResult::FoundType)
257 S.
Diag(NameLoc, diag::ext_found_in_dependent_base) << &II;
277 bool HasTrailingDot,
ParsedType ObjectTypePtr,
278 bool IsCtorOrDtorName,
279 bool WantNontrivialTypeSourceInfo,
280 bool IsClassTemplateDeductionContext,
283 bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
285 bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
311 if (IsImplicitTypename) {
316 auto DB =
DiagCompat(QualifiedLoc, diag_compat::implicit_typename)
325 if (WantNontrivialTypeSourceInfo)
361 if (ObjectTypePtr &&
Result.empty()) {
385 switch (
Result.getResultKind()) {
388 TypeNameValidatorCCC CCC(
true, isClassName,
389 AllowDeducedTemplate);
395 bool MemberOfUnknownSpecialization;
404 if (Correction && (NNS || NewII != &II) &&
410 Template, MemberOfUnknownSpecialization))) {
412 isClassName, HasTrailingDot, ObjectTypePtr,
414 WantNontrivialTypeSourceInfo,
415 IsClassTemplateDeductionContext);
418 PDiag(diag::err_unknown_type_or_class_name_suggest)
419 <<
Result.getLookupName() << isClassName);
422 *CorrectedII = NewII;
427 Result.suppressDiagnostics();
443 Result.suppressDiagnostics();
453 Result.suppressDiagnostics();
459 Res != ResEnd; ++Res) {
468 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*Res);
480 Result.suppressDiagnostics();
491 IIDecl =
Result.getFoundDecl();
492 FoundUsingShadow = dyn_cast<UsingShadowDecl>(*
Result.begin());
496 assert(IIDecl &&
"Didn't find decl");
499 if (
TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
505 if (FoundUsingShadow) {
509 if (!WantNontrivialTypeSourceInfo)
515 }
else if (
auto *Tag = dyn_cast<TagDecl>(TD)) {
519 if (!WantNontrivialTypeSourceInfo)
525 TL.setNameLoc(NameLoc);
526 }
else if (
auto *TN = dyn_cast<TypedefNameDecl>(TD);
530 if (!WantNontrivialTypeSourceInfo)
536 }
else if (
auto *UD = dyn_cast<UnresolvedUsingTypenameDecl>(TD)) {
540 if (!WantNontrivialTypeSourceInfo)
548 if (!WantNontrivialTypeSourceInfo)
559 if (
auto *TD = dyn_cast_or_null<TemplateDecl>(
563 if (!ShorthandTy.
isNull())
570 if (!HasTrailingDot) {
573 if (!WantNontrivialTypeSourceInfo)
578 TL.setNameEndLoc(NameLoc);
581 }
else if (
auto *UD = dyn_cast<UnresolvedUsingIfExistsDecl>(IIDecl)) {
585 }
else if (AllowDeducedTemplate) {
587 assert(!FoundUsingShadow || FoundUsingShadow->
getTargetDecl() == TD);
597 TL.setNameLoc(NameLoc);
605 Result.suppressDiagnostics();
614 auto *ND = dyn_cast<NamespaceDecl>(DC);
615 if (ND && !ND->isInline() && !ND->isAnonymousNamespace())
617 if (
auto *RD = dyn_cast<CXXRecordDecl>(DC))
622 llvm_unreachable(
"something isn't in TU scope?");
633 if (
const auto *MD = dyn_cast<CXXMethodDecl>(DC))
634 if (MD->getParent()->hasAnyDependentBases())
642 bool IsTemplateTypeArg) {
643 assert(
getLangOpts().MSVCCompat &&
"shouldn't be called in non-MSVC mode");
646 if (IsTemplateTypeArg &&
getCurScope()->isTemplateParamScope()) {
655 Diag(NameLoc, diag::ext_ms_delayed_template_argument) << &II;
664 Diag(NameLoc, diag::ext_undeclared_unqual_id_with_dependent_base) << &II
692 R.suppressDiagnostics();
695 switch (TD->getTagKind()) {
736 bool IsTemplateName) {
741 SuggestedType =
nullptr;
745 TypeNameValidatorCCC CCC(
false,
false,
752 bool CanRecover = !IsTemplateName;
753 if (Corrected.isKeyword()) {
756 PDiag(IsTemplateName ? diag::err_no_template_suggest
757 : diag::err_unknown_typename_suggest)
759 II = Corrected.getCorrectionAsIdentifierInfo();
762 if (!SS || !SS->
isSet()) {
764 PDiag(IsTemplateName ? diag::err_no_template_suggest
765 : diag::err_unknown_typename_suggest)
768 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
769 bool DroppedSpecifier =
770 Corrected.WillReplaceSpecifier() && II->
getName() == CorrectedStr;
773 ? diag::err_no_member_template_suggest
774 : diag::err_unknown_nested_typename_suggest)
775 << II << DC << DroppedSpecifier << SS->
getRange(),
778 llvm_unreachable(
"could not have corrected a typo here");
785 if (Corrected.getCorrectionSpecifier())
790 getTypeName(*Corrected.getCorrectionAsIdentifierInfo(), IILoc, S,
791 tmpSS.
isSet() ? &tmpSS : SS,
false,
false,
nullptr,
804 bool MemberOfUnknownSpecialization;
806 Name,
nullptr,
true, TemplateResult,
817 Diag(IILoc, IsTemplateName ? diag::err_no_template
818 : diag::err_unknown_typename)
821 Diag(IILoc, IsTemplateName ? diag::err_no_member_template
822 : diag::err_typename_nested_not_found)
828 unsigned DiagID = diag::err_typename_missing;
830 DiagID = diag::ext_typename_missing;
841 "Invalid scope specifier has already been diagnosed");
848 bool CheckTemplate = R.getSema().getLangOpts().CPlusPlus &&
849 NextToken.
is(tok::less);
869 StringRef FixItTagName;
870 switch (Tag->getTagKind()) {
872 FixItTagName =
"class ";
876 FixItTagName =
"enum ";
880 FixItTagName =
"struct ";
884 FixItTagName =
"__interface ";
888 FixItTagName =
"union ";
892 StringRef TagName = FixItTagName.drop_back();
893 SemaRef.
Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
894 << Name << TagName << SemaRef.
getLangOpts().CPlusPlus
899 SemaRef.
Diag((*I)->getLocation(), diag::note_decl_hiding_tag_type)
914 const Token &NextToken,
919 assert(NextToken.
isNot(tok::coloncolon) &&
920 "parse nested name specifiers before calling ClassifyName");
961 bool SecondTry =
false;
962 bool IsFilteredTemplateName =
false;
965 switch (
Result.getResultKind()) {
969 if (SS.
isEmpty() && NextToken.
is(tok::l_paren)) {
1015 if (!SecondTry && CCC) {
1020 unsigned UnqualifiedDiag = diag::err_undeclared_var_use_suggest;
1021 unsigned QualifiedDiag = diag::err_no_member_suggest;
1024 NamedDecl *UnderlyingFirstDecl = Corrected.getCorrectionDecl();
1027 UnqualifiedDiag = diag::err_no_template_suggest;
1028 QualifiedDiag = diag::err_no_member_template_suggest;
1029 }
else if (UnderlyingFirstDecl &&
1033 UnqualifiedDiag = diag::err_unknown_typename_suggest;
1034 QualifiedDiag = diag::err_unknown_nested_typename_suggest;
1040 std::string CorrectedStr(Corrected.getAsString(
getLangOpts()));
1041 bool DroppedSpecifier = Corrected.WillReplaceSpecifier() &&
1042 Name->
getName() == CorrectedStr;
1045 << DroppedSpecifier << SS.
getRange());
1049 Name = Corrected.getCorrectionAsIdentifierInfo();
1052 if (Corrected.isKeyword())
1058 Result.setLookupName(Corrected.getCorrection());
1080 Result.suppressDiagnostics();
1122 if (!
Result.isAmbiguous()) {
1123 IsFilteredTemplateName =
true;
1133 (IsFilteredTemplateName ||
1149 if (!IsFilteredTemplateName)
1152 bool IsFunctionTemplate;
1156 IsFunctionTemplate =
true;
1159 }
else if (!
Result.empty()) {
1167 dyn_cast<UsingShadowDecl>(*
Result.begin());
1168 assert(!FoundUsingShadow ||
1177 IsFunctionTemplate =
true;
1181 if (IsFunctionTemplate) {
1185 Result.suppressDiagnostics();
1197 if (
const auto *USD = dyn_cast<UsingShadowDecl>(
Found)) {
1209 TTL.setNameLoc(NameLoc);
1236 dyn_cast<ObjCCompatibleAliasDecl>(
FirstDecl))
1237 Class = Alias->getClassInterface();
1243 if (NextToken.
is(tok::period)) {
1246 Result.suppressDiagnostics();
1256 if (
auto *USD = dyn_cast<UsingShadowDecl>(
Result.getRepresentativeDecl()))
1262 if (
auto *EmptyD = dyn_cast<UnresolvedUsingIfExistsDecl>(
FirstDecl)) {
1275 bool NextIsOp = NextToken.
isOneOf(tok::amp, tok::star);
1276 if ((NextToken.
is(tok::identifier) ||
1278 FirstDecl->getUnderlyingDecl()->isFunctionOrFunctionTemplate())) &&
1290 if (
Result.isSingleResult() && !ADL &&
1295 Result.suppressDiagnostics();
1315 bool IsAddressOfOperand) {
1318 NameInfo, IsAddressOfOperand,
1325 const Token &NextToken) {
1327 if (
auto *Ivar = dyn_cast<ObjCIvarDecl>(
Found->getUnderlyingDecl()))
1343 if ((*ULE->decls_begin())->isCXXClassMember()) {
1345 SS.
Adopt(ULE->getQualifierLoc());
1350 Result.setNamingClass(ULE->getNamingClass());
1351 for (
auto I = ULE->decls_begin(), E = ULE->decls_end(); I != E; ++I)
1352 Result.addDecl(*I, I.getAccess());
1385 "The next DeclContext should be lexically contained in the current one.");
1392 assert(
CurContext &&
"DeclContext imbalance!");
1395 assert(
CurContext &&
"Popped translation unit!");
1405 assert(
CurContext &&
"skipping definition of undefined tag");
1433 assert(!S->
getEntity() &&
"scope already has entity");
1466 "expected to be initializing a template parameter scope");
1494 cast<Decl>(DC)->getDescribedTemplateParams()) {
1495 unsigned DCDepth = TPL->getDepth() + 1;
1496 if (DCDepth > ScopeDepth)
1498 if (ScopeDepth == DCDepth)
1510 if (Param->getIdentifier()) {
1520 if (Param->getIdentifier()) {
1536 "The next DeclContext should be lexically contained in the current one.");
1546 assert(
CurContext &&
"DeclContext imbalance!");
1548 assert(
CurContext &&
"Popped translation unit!");
1562 if (Context.getLangOpts().CPlusPlus ||
New->hasAttr<OverloadableAttr>())
1577 return ND->
hasAttr<OverloadableAttr>();
1580 return Previous.getFoundDecl()->hasAttr<OverloadableAttr>();
1635 for (; I != IEnd; ++I) {
1668 bool AllowInlineNamespace)
const {
1669 return IdResolver.isDeclInScope(D, Ctx, S, AllowInlineNamespace);
1673 bool AllowInlineNamespace)
const {
1677 if (
auto *Shadow = dyn_cast<UsingShadowDecl>(D))
1678 return isDeclInScope(Shadow->getTargetDecl(), Ctx, S, AllowInlineNamespace);
1687 if (ScopeDC->getPrimaryContext() == TargetDC)
1699 bool ConsiderLinkage,
1700 bool AllowInlineNamespace) {
1718 if (
auto *VD = dyn_cast<VarDecl>(D))
1720 if (
auto *FD = dyn_cast<FunctionDecl>(D))
1722 if (
auto *RD = dyn_cast<CXXRecordDecl>(D))
1736 if (
New->getFriendObjectKind() &&
1777 if (NewIsModuleInterface || OldIsModuleInterface) {
1781 Diag(
New->getLocation(), diag::err_mismatched_owning_module)
1783 << NewIsModuleInterface
1785 << OldIsModuleInterface
1788 New->setInvalidDecl();
1801 if (!
New->getLexicalDeclContext()
1802 ->getNonTransparentContext()
1803 ->isFileContext() ||
1809 bool IsNewExported =
New->isInExportDeclContext();
1813 if (!IsNewExported && !IsOldExported)
1825 New->getOwningModule()->isImplicitGlobalModule())
1828 assert(IsNewExported);
1836 Diag(
New->getLocation(), diag::err_redeclaration_non_exported) <<
New << S;
1854 "New and Old are not the same definition, we should diagnostic it "
1855 "immediately instead of checking it.");
1858 "We shouldn't see unreachable definitions here.");
1906 return OldM == NewM;
1943 return CD->isCopyConstructor();
1950 if (
const RecordDecl *RD = dyn_cast<RecordDecl>(DC)){
1951 if (!RD->hasNameForLinkage())
1972 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
1978 FD->getMemberSpecializationInfo() && !FD->isOutOfLine())
1981 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
1990 if (FD->doesThisDeclarationHaveABody() &&
1991 Context.DeclMustBeEmitted(FD))
1993 }
else if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2000 if (
Context.DeclMustBeEmitted(VD))
2003 if (VD->isStaticDataMember() &&
2006 if (VD->isStaticDataMember() &&
2008 VD->getMemberSpecializationInfo() && !VD->isOutOfLine())
2020 return mightHaveNonExternalLinkage(D);
2027 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2033 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2048 if (
const auto *DD = dyn_cast<DecompositionDecl>(D)) {
2052 bool IsAllIgnored =
true;
2053 for (
const auto *BD : DD->bindings()) {
2054 if (BD->isReferenced())
2056 IsAllIgnored = IsAllIgnored && (BD->isPlaceholderVar(LangOpts) ||
2057 BD->hasAttr<UnusedAttr>());
2070 if (D->
hasAttr<UnusedAttr>() || D->
hasAttr<ObjCPreciseLifetimeAttr>() ||
2080 if (
const auto *R = dyn_cast<CXXRecordDecl>(D->
getDeclContext()))
2083 WithinFunction || (R->isLocalClass() && !R->isDependentType());
2084 if (!WithinFunction)
2095 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2098 if (
const auto *Cleanups = dyn_cast_if_present<ExprWithCleanups>(
Init))
2099 Init = Cleanups->getSubExpr();
2101 const auto *Ty = VD->getType().getTypePtr();
2106 if (TT->getDecl()->hasAttr<UnusedAttr>())
2112 if (
const auto *MTE = dyn_cast_if_present<MaterializeTemporaryExpr>(
Init);
2113 MTE && MTE->getExtendingDecl()) {
2114 Ty = VD->getType().getNonReferenceType().getTypePtr();
2115 Init = MTE->getSubExpr()->IgnoreImplicitAsWritten();
2120 if (Ty->isIncompleteType() || Ty->isDependentType())
2125 Ty = Ty->getBaseElementTypeUnsafe();
2127 if (
const TagDecl *Tag = Ty->getAsTagDecl()) {
2128 if (Tag->hasAttr<UnusedAttr>())
2131 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
2132 if (!RD->hasTrivialDestructor() && !RD->hasAttr<WarnUnusedAttr>())
2136 const auto *Construct =
2137 dyn_cast<CXXConstructExpr>(
Init->IgnoreImpCasts());
2138 if (Construct && !Construct->isElidable()) {
2140 if (!CD->
isTrivial() && !RD->hasAttr<WarnUnusedAttr>() &&
2141 (VD->getInit()->isValueDependent() || !VD->evaluateValue()))
2147 if (
Init->isTypeDependent()) {
2149 if (!Ctor->isTrivial())
2190 for (
auto *TmpD : D->
decls()) {
2191 if (
const auto *
T = dyn_cast<TypedefNameDecl>(TmpD))
2193 else if(
const auto *R = dyn_cast<RecordDecl>(TmpD))
2207 if (
auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2219 DiagID = diag::warn_unused_exception_param;
2221 DiagID = diag::warn_unused_label;
2223 DiagID = diag::warn_unused_variable;
2242 if (Ty->isReferenceType() || Ty->isDependentType())
2245 if (
const TagDecl *Tag = Ty->getAsTagDecl()) {
2246 if (Tag->hasAttr<UnusedAttr>())
2250 if (
const auto *RD = dyn_cast<CXXRecordDecl>(Tag);
2251 RD && !RD->hasAttr<WarnUnusedAttr>())
2263 if (VD->
hasAttr<BlocksAttr>() && Ty->isObjCObjectPointerType())
2269 if (VD->
hasAttr<ObjCPreciseLifetimeAttr>() && Ty->isObjCObjectPointerType())
2276 assert(iter->getSecond() >= 0 &&
2277 "Found a negative number of references to a VarDecl");
2278 if (
int RefCnt = iter->getSecond(); RefCnt > 0) {
2288 bool UnusedCXXCondDecl = VD->
isCXXCondDecl() && (RefCnt == 1);
2289 if (!UnusedCXXCondDecl)
2295 DiagID = diag::warn_unused_but_set_parameter;
2297 DiagID = diag::warn_unused_but_set_global;
2299 DiagID = diag::warn_unused_but_set_variable;
2309 bool Diagnose =
false;
2313 Diagnose = L->
getStmt() ==
nullptr;
2324 "Scope shouldn't contain decls!");
2331 std::optional<SourceLocation> PreviousDeclLoc;
2336 DeclDiags.push_back(LocAndDiag{Loc, std::nullopt, std::move(PD)});
2341 DeclDiags.push_back(LocAndDiag{Loc, PreviousDeclLoc, std::move(PD)});
2344 for (
auto *TmpD : S->
decls()) {
2345 assert(TmpD &&
"This decl didn't get pushed??");
2353 if (
const auto *RD = dyn_cast<RecordDecl>(D))
2356 if (
auto *VD = dyn_cast<VarDecl>(D);
2357 VD && !VD->isInternalLinkageFileVar()) {
2366 if (
LabelDecl *LD = dyn_cast<LabelDecl>(D))
2377 auto ShadowI = ShadowingDecls.find(D);
2378 if (ShadowI != ShadowingDecls.end()) {
2379 if (
const auto *FD = dyn_cast<FieldDecl>(ShadowI->second)) {
2380 addDiagWithPrev(D->
getLocation(), FD->getLocation(),
2381 PDiag(diag::warn_ctor_parm_shadows_field)
2382 << D << FD << FD->getParent());
2384 ShadowingDecls.erase(ShadowI);
2388 llvm::sort(DeclDiags,
2389 [](
const LocAndDiag &LHS,
const LocAndDiag &RHS) ->
bool {
2394 return LHS.Loc.getRawEncoding() < RHS.Loc.getRawEncoding();
2396 for (
const LocAndDiag &D : DeclDiags) {
2398 if (D.PreviousDeclLoc)
2399 Diag(*D.PreviousDeclLoc, diag::note_previous_declaration);
2423 return "ucontext.h";
2425 llvm_unreachable(
"unhandled error kind");
2436 Parent->
addDecl(CLinkageDecl);
2437 Parent = CLinkageDecl;
2441 if (
Context.BuiltinInfo.isImmediate(ID)) {
2443 "consteval builtins should only be available in C++20 mode");
2452 New->addAttr(BuiltinAttr::CreateImplicit(
Context, ID));
2458 for (
unsigned i = 0, e = FT->getNumParams(); i != e; ++i) {
2461 FT->getParamType(i),
nullptr,
SC_None,
nullptr);
2463 Params.push_back(parm);
2465 New->setParams(Params);
2473 Scope *S,
bool ForRedeclaration,
2480 if (!ForRedeclaration)
2486 Context.BuiltinInfo.allowTypeMismatch(ID))
2492 Diag(Loc, diag::warn_implicit_decl_no_jmp_buf)
2493 <<
Context.BuiltinInfo.getName(ID);
2499 Diag(Loc, diag::warn_implicit_decl_requires_sysheader)
2501 <<
Context.BuiltinInfo.getName(ID);
2505 if (!ForRedeclaration &&
2506 (
Context.BuiltinInfo.isPredefinedLibFunction(ID) ||
2507 Context.BuiltinInfo.isHeaderDependentFunction(ID))) {
2508 Diag(Loc,
LangOpts.C99 ? diag::ext_implicit_lib_function_decl_c99
2509 : diag::ext_implicit_lib_function_decl)
2510 <<
Context.BuiltinInfo.getName(ID) << R;
2511 if (
const char *Header =
Context.BuiltinInfo.getHeaderName(ID))
2512 Diag(Loc, diag::note_include_header_or_declare)
2513 << Header <<
Context.BuiltinInfo.getName(ID);
2549 while (Filter.hasNext()) {
2558 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2560 Decl->getUnderlyingType()))
2565 if (OldTD->getAnonDeclWithTypedefName(
true) &&
2566 Decl->getAnonDeclWithTypedefName())
2578 if (
const TypedefNameDecl *OldTypedef = dyn_cast<TypedefNameDecl>(Old))
2579 OldType = OldTypedef->getUnderlyingType();
2581 OldType =
Context.getTypeDeclType(Old);
2587 Diag(
New->getLocation(), diag::err_redefinition_variably_modified_typedef)
2591 New->setInvalidDecl();
2595 if (OldType != NewType &&
2598 !
Context.hasSameType(OldType, NewType)) {
2600 Diag(
New->getLocation(), diag::err_redefinition_different_typedef)
2601 << Kind << NewType << OldType;
2604 New->setInvalidDecl();
2614 if (
New->isInvalidDecl())
return;
2620 switch (TypeID->getLength()) {
2624 if (!TypeID->isStr(
"id"))
2627 if (!
T->isPointerType())
2629 if (!
T->isVoidPointerType()) {
2634 Context.setObjCIdRedefinitionType(
T);
2636 New->setModedTypeSourceInfo(
New->getTypeSourceInfo(),
2641 if (!TypeID->isStr(
"Class"))
2643 Context.setObjCClassRedefinitionType(
New->getUnderlyingType());
2645 New->setModedTypeSourceInfo(
New->getTypeSourceInfo(),
2649 if (!TypeID->isStr(
"SEL"))
2651 Context.setObjCSelRedefinitionType(
New->getUnderlyingType());
2653 New->setModedTypeSourceInfo(
New->getTypeSourceInfo(),
2663 Diag(
New->getLocation(), diag::err_redefinition_different_kind)
2664 <<
New->getDeclName();
2670 return New->setInvalidDecl();
2675 return New->setInvalidDecl();
2677 if (
auto *OldTD = dyn_cast<TypedefNameDecl>(Old)) {
2678 auto *OldTag = OldTD->getAnonDeclWithTypedefName(
true);
2679 auto *
NewTag =
New->getAnonDeclWithTypedefName();
2682 OldTag->getCanonicalDecl() !=
NewTag->getCanonicalDecl() &&
2686 if (OldTD->isModed())
2687 New->setModedTypeSourceInfo(OldTD->getTypeSourceInfo(),
2688 OldTD->getUnderlyingType());
2690 New->setTypeSourceInfo(OldTD->getTypeSourceInfo());
2703 if (
auto *NewEnum = dyn_cast<EnumDecl>(
NewTag)) {
2704 if (
auto *OldEnum = dyn_cast<EnumDecl>(OldTag)) {
2705 NewEnum->setPreviousDecl(OldEnum);
2707 for (
auto *ECD : NewEnum->enumerators())
2708 ECD->setType(EnumType);
2767 Diag(
New->getLocation(), diag::err_redefinition)
2768 <<
New->getDeclName();
2770 return New->setInvalidDecl();
2785 Context.getSourceManager().isInSystemHeader(
New->getLocation())))
2788 Diag(
New->getLocation(), diag::ext_redefinition_of_typedef)
2789 <<
New->getDeclName();
2796 if (
auto *ED = dyn_cast<EnumDecl>(
New); ED && !ED->isScoped()) {
2798 for (
auto *ECD : ED->enumerators()) {
2809 const OwnershipAttr *OA = dyn_cast<OwnershipAttr>(A);
2810 const AnnotateAttr *Ann = dyn_cast<AnnotateAttr>(A);
2811 for (
const auto *i : D->
attrs())
2812 if (i->getKind() == A->
getKind()) {
2828 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
2829 return VD->isThisDeclarationADefinition();
2830 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
2831 return TD->isCompleteDefinition() || TD->isBeingDefined();
2842 AlignedAttr *OldAlignasAttr =
nullptr;
2843 AlignedAttr *OldStrictestAlignAttr =
nullptr;
2844 unsigned OldAlign = 0;
2852 if (I->isAlignmentDependent())
2858 unsigned Align = I->getAlignment(S.
Context);
2859 if (Align > OldAlign) {
2861 OldStrictestAlignAttr = I;
2866 AlignedAttr *NewAlignasAttr =
nullptr;
2867 unsigned NewAlign = 0;
2868 for (
auto *I :
New->specific_attrs<AlignedAttr>()) {
2869 if (I->isAlignmentDependent())
2875 unsigned Align = I->getAlignment(S.
Context);
2876 if (Align > NewAlign)
2880 if (OldAlignasAttr && NewAlignasAttr && OldAlign != NewAlign) {
2888 if (OldAlign == 0 || NewAlign == 0) {
2901 if (OldAlign != NewAlign) {
2902 S.
Diag(NewAlignasAttr->getLocation(), diag::err_alignas_mismatch)
2905 S.
Diag(OldAlignasAttr->getLocation(), diag::note_previous_declaration);
2918 S.
Diag(
New->getLocation(), diag::err_alignas_missing_on_definition)
2920 S.
Diag(OldAlignasAttr->getLocation(), diag::note_alignas_on_declaration)
2924 bool AnyAdded =
false;
2927 if (OldAlign > NewAlign) {
2928 AlignedAttr *Clone = OldStrictestAlignAttr->clone(S.
Context);
2929 Clone->setInherited(
true);
2930 New->addAttr(Clone);
2935 if (OldAlignasAttr && !NewAlignasAttr &&
2936 !(AnyAdded && OldStrictestAlignAttr->isAlignas())) {
2937 AlignedAttr *Clone = OldAlignasAttr->clone(S.
Context);
2938 Clone->setInherited(
true);
2939 New->addAttr(Clone);
2946#define WANT_DECL_MERGE_LOGIC
2947#include "clang/Sema/AttrParsedAttrImpl.inc"
2948#undef WANT_DECL_MERGE_LOGIC
2955 if (!DiagnoseMutualExclusions(S, D,
Attr))
2966 if (
const auto *AA = dyn_cast<AvailabilityAttr>(
Attr)) {
2968 if (AvailabilityAttr *
Inf = AA->getInferredAttrAs())
2969 InferredPlatformII =
Inf->getPlatform();
2971 D, *AA, AA->getPlatform(), AA->
isImplicit(), AA->getIntroduced(),
2972 AA->getDeprecated(), AA->getObsoleted(), AA->getUnavailable(),
2973 AA->getMessage(), AA->getStrict(), AA->getReplacement(), AMK,
2974 AA->getPriority(), AA->getEnvironment(), InferredPlatformII);
2975 }
else if (
const auto *VA = dyn_cast<VisibilityAttr>(
Attr))
2977 else if (
const auto *VA = dyn_cast<TypeVisibilityAttr>(
Attr))
2979 else if (
const auto *ImportA = dyn_cast<DLLImportAttr>(
Attr))
2981 else if (
const auto *ExportA = dyn_cast<DLLExportAttr>(
Attr))
2983 else if (
const auto *EA = dyn_cast<ErrorAttr>(
Attr))
2985 else if (
const auto *FA = dyn_cast<FormatAttr>(
Attr))
2986 NewAttr = S.
mergeFormatAttr(D, *FA, FA->getType(), FA->getFormatIdx(),
2988 else if (
const auto *FMA = dyn_cast<FormatMatchesAttr>(
Attr))
2990 D, *FMA, FMA->getType(), FMA->getFormatIdx(), FMA->getFormatString());
2991 else if (
const auto *MFA = dyn_cast<ModularFormatAttr>(
Attr))
2993 D, *MFA, MFA->getModularImplFn(), MFA->getImplName(),
2995 else if (
const auto *SA = dyn_cast<SectionAttr>(
Attr))
2997 else if (
const auto *CSA = dyn_cast<CodeSegAttr>(
Attr))
2999 else if (
const auto *IA = dyn_cast<MSInheritanceAttr>(
Attr))
3001 IA->getInheritanceModel());
3002 else if (
const auto *AA = dyn_cast<AlwaysInlineAttr>(
Attr))
3011 }
else if (
const auto *MA = dyn_cast<MinSizeAttr>(
Attr))
3013 else if (
const auto *SNA = dyn_cast<SwiftNameAttr>(
Attr))
3015 else if (
const auto *SAA = dyn_cast<SwiftAttrAttr>(
Attr))
3017 else if (
const auto *OA = dyn_cast<OptimizeNoneAttr>(
Attr))
3019 else if (
const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(
Attr))
3030 else if (
const auto *UA = dyn_cast<UuidAttr>(
Attr))
3031 NewAttr = S.
mergeUuidAttr(D, *UA, UA->getGuid(), UA->getGuidDecl());
3032 else if (
const auto *IMA = dyn_cast<WebAssemblyImportModuleAttr>(
Attr))
3034 else if (
const auto *INA = dyn_cast<WebAssemblyImportNameAttr>(
Attr))
3036 else if (
const auto *ENA = dyn_cast<WebAssemblyExportNameAttr>(
Attr))
3038 else if (
const auto *TCBA = dyn_cast<EnforceTCBAttr>(
Attr))
3040 else if (
const auto *TCBLA = dyn_cast<EnforceTCBLeafAttr>(
Attr))
3042 else if (
const auto *BTFA = dyn_cast<BTFDeclTagAttr>(
Attr))
3044 else if (
const auto *NT = dyn_cast<HLSLNumThreadsAttr>(
Attr))
3047 else if (
const auto *WS = dyn_cast<HLSLWaveSizeAttr>(
Attr))
3050 WS->getSpelledArgsCount());
3051 else if (
const auto *CI = dyn_cast<HLSLVkConstantIdAttr>(
Attr))
3053 else if (
const auto *SA = dyn_cast<HLSLShaderAttr>(
Attr))
3058 else if (
const auto *RD = dyn_cast<OpenACCRoutineDeclAttr>(
Attr))
3062 else if (
const auto *PA = dyn_cast<PersonalityAttr>(
Attr))
3077 if (
const TagDecl *TD = dyn_cast<TagDecl>(D)) {
3078 if (
const auto *Def = TD->getDefinition(); Def && !Def->isBeingDefined())
3082 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
3088 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
3090 if (FD->isDefined(Def,
true))
3097 for (
const auto *Attribute : D->
attrs())
3098 if (Attribute->getKind() == Kind)
3106 if (!
New->hasAttrs())
3110 if (!Def || Def ==
New)
3114 for (
unsigned I = 0, E = NewAttributes.size(); I != E;) {
3115 Attr *NewAttribute = NewAttributes[I];
3124 NewAttributes.erase(NewAttributes.begin() + I);
3132 ? diag::err_alias_after_tentative
3133 : diag::err_redefinition;
3135 if (
Diag == diag::err_redefinition)
3145 if (
const VarDecl *VD = dyn_cast<VarDecl>(Def)) {
3192 }
else if (
const AlignedAttr *AA = dyn_cast<AlignedAttr>(NewAttribute)) {
3193 if (AA->isAlignas()) {
3204 S.
Diag(NewAttribute->
getLocation(), diag::note_alignas_on_declaration)
3206 NewAttributes.erase(NewAttributes.begin() + I);
3216 diag::err_loader_uninitialized_redeclaration);
3218 NewAttributes.erase(NewAttributes.begin() + I);
3241 diag::err_sycl_entry_point_after_definition)
3254 diag::warn_attribute_precede_definition);
3256 NewAttributes.erase(NewAttributes.begin() + I);
3262 const ConstInitAttr *CIAttr,
3263 bool AttrBeforeInit) {
3270 std::string SuitableSpelling;
3272 SuitableSpelling = std::string(
3274 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3276 InsertLoc, {tok::l_square, tok::l_square,
3277 S.PP.getIdentifierInfo(
"clang"), tok::coloncolon,
3278 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3279 tok::r_square, tok::r_square}));
3280 if (SuitableSpelling.empty())
3282 InsertLoc, {tok::kw___attribute, tok::l_paren, tok::r_paren,
3283 S.PP.getIdentifierInfo(
"require_constant_initialization"),
3284 tok::r_paren, tok::r_paren}));
3285 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus20)
3286 SuitableSpelling =
"constinit";
3287 if (SuitableSpelling.empty() && S.
getLangOpts().CPlusPlus11)
3288 SuitableSpelling =
"[[clang::require_constant_initialization]]";
3289 if (SuitableSpelling.empty())
3290 SuitableSpelling =
"__attribute__((require_constant_initialization))";
3291 SuitableSpelling +=
" ";
3293 if (AttrBeforeInit) {
3296 assert(CIAttr->isConstinit() &&
"should not diagnose this for attribute");
3299 S.
Diag(CIAttr->getLocation(), diag::note_constinit_specified_here);
3303 S.
Diag(CIAttr->getLocation(),
3304 CIAttr->isConstinit() ? diag::err_constinit_added_too_late
3305 : diag::warn_require_const_init_added_too_late)
3308 << CIAttr->isConstinit()
3316 UsedAttr *NewAttr = OldAttr->clone(
Context);
3317 NewAttr->setInherited(
true);
3318 New->addAttr(NewAttr);
3321 RetainAttr *NewAttr = OldAttr->clone(
Context);
3322 NewAttr->setInherited(
true);
3323 New->addAttr(NewAttr);
3332 const auto *OldConstInit = Old->
getAttr<ConstInitAttr>();
3333 const auto *NewConstInit =
New->getAttr<ConstInitAttr>();
3334 if (
bool(OldConstInit) !=
bool(NewConstInit)) {
3342 (NewVD->hasInit() || NewVD->isThisDeclarationADefinition()))
3345 if (InitDecl == NewVD) {
3349 if (OldConstInit && OldConstInit->isConstinit())
3352 }
else if (NewConstInit) {
3356 if (InitDecl && InitDecl != NewVD) {
3359 NewVD->dropAttr<ConstInitAttr>();
3367 if (AsmLabelAttr *NewA =
New->getAttr<AsmLabelAttr>()) {
3368 if (AsmLabelAttr *OldA = Old->
getAttr<AsmLabelAttr>()) {
3369 if (!OldA->isEquivalent(NewA)) {
3371 Diag(
New->getLocation(), diag::err_different_asm_label);
3372 Diag(OldA->getLocation(), diag::note_previous_declaration);
3374 }
else if (Old->
isUsed()) {
3377 Diag(
New->getLocation(), diag::err_late_asm_label_name)
3383 if (
const auto *NewAbiTagAttr =
New->getAttr<AbiTagAttr>()) {
3384 if (
const auto *OldAbiTagAttr = Old->
getAttr<AbiTagAttr>()) {
3385 for (
const auto &
NewTag : NewAbiTagAttr->tags()) {
3386 if (!llvm::is_contained(OldAbiTagAttr->tags(),
NewTag)) {
3387 Diag(NewAbiTagAttr->getLocation(),
3388 diag::err_new_abi_tag_on_redeclaration)
3390 Diag(OldAbiTagAttr->getLocation(), diag::note_previous_declaration);
3394 Diag(NewAbiTagAttr->getLocation(), diag::err_abi_tag_on_redeclaration);
3400 if (
New->hasAttr<SectionAttr>() && !Old->
hasAttr<SectionAttr>()) {
3401 if (
auto *VD = dyn_cast<VarDecl>(
New)) {
3403 Diag(
New->getLocation(), diag::warn_attribute_section_on_redeclaration);
3410 const auto *NewCSA =
New->getAttr<CodeSegAttr>();
3411 if (NewCSA && !Old->
hasAttr<CodeSegAttr>() &&
3413 Diag(
New->getLocation(), diag::warn_mismatched_section)
3421 bool foundAny =
New->hasAttrs();
3454 if (
auto *FD = dyn_cast<FunctionDecl>(
New);
3467 if (!foundAny)
New->dropAttrs();
3472 checkAttrIsTypeDependent(D, A);
3483 newAttr->setInherited(
true);
3505 foundAny |= std::forward<F>(propagator)(To, From) != 0;
3531 auto NoSizeInfo = [&Ctx](
QualType Ty) {
3532 if (Ty->isIncompleteArrayType() || Ty->isPointerType())
3540 if (NoSizeInfo(Old) && NoSizeInfo(
New))
3572 if (*Oldnullability != *Newnullability) {
3573 S.
Diag(NewParam->
getLocation(), diag::warn_mismatched_nullability_attr)
3590 const auto *OldParamDT = dyn_cast<DecayedType>(OldParam->
getType());
3591 const auto *NewParamDT = dyn_cast<DecayedType>(NewParam->
getType());
3592 if (OldParamDT && NewParamDT &&
3593 OldParamDT->getPointeeType() == NewParamDT->getPointeeType()) {
3594 QualType OldParamOT = OldParamDT->getOriginalType();
3595 QualType NewParamOT = NewParamDT->getOriginalType();
3598 << NewParam << NewParamOT;
3609struct GNUCompatibleParamWarning {
3610 ParmVarDecl *OldParm;
3611 ParmVarDecl *NewParm;
3612 QualType PromotedType;
3619template <
typename T>
3620static std::pair<diag::kind, SourceLocation>
3624 if (Old->isThisDeclarationADefinition())
3625 PrevDiag = diag::note_previous_definition;
3626 else if (Old->isImplicit()) {
3627 PrevDiag = diag::note_previous_implicit_declaration;
3628 if (
const auto *FD = dyn_cast<FunctionDecl>(Old)) {
3629 if (FD->getBuiltinID())
3630 PrevDiag = diag::note_previous_builtin_declaration;
3633 OldLocation =
New->getLocation();
3635 PrevDiag = diag::note_previous_declaration;
3636 return std::make_pair(PrevDiag, OldLocation);
3644 return ((FD->
hasAttr<GNUInlineAttr>() || LangOpts.GNUInline) &&
3645 !LangOpts.CPlusPlus &&
3651 const AttributedType *AT =
T->getAs<AttributedType>();
3652 while (AT && !AT->isCallingConv())
3653 AT = AT->getModifiedType()->getAs<AttributedType>();
3657template <
typename T>
3671template<
typename T>
static bool isExternC(
T *D) {
return D->isExternC(); }
3678template<
typename ExpectedDecl>
3700 !Old->getDeclContext()->getRedeclContext()->Equals(
3701 New->getDeclContext()->getRedeclContext()) &&
3706 S.
Diag(
New->getLocation(), diag::err_using_decl_conflict_reverse);
3719 const auto *AttrA = A->
getAttr<PassObjectSizeAttr>();
3720 const auto *AttrB = B->
getAttr<PassObjectSizeAttr>();
3723 return AttrA && AttrB && AttrA->getType() == AttrB->getType() &&
3724 AttrA->isDynamic() == AttrB->isDynamic();
3750 if (NamedDC->Equals(SemaDC))
3753 assert((NamedDC->InEnclosingNamespaceSetOf(SemaDC) ||
3755 "unexpected context for redeclaration");
3766 if (
auto *FD = dyn_cast<FunctionDecl>(NewD))
3767 FixSemaDC(FD->getDescribedFunctionTemplate());
3768 else if (
auto *VD = dyn_cast<VarDecl>(NewD))
3769 FixSemaDC(VD->getDescribedVarTemplate());
3773 bool MergeTypeWithOld,
bool NewDeclIsDefn) {
3781 Diag(
New->getLocation(), diag::err_using_decl_friend);
3782 Diag(Shadow->getTargetDecl()->getLocation(),
3783 diag::note_using_decl_target);
3784 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
3792 New->getDescribedFunctionTemplate()) {
3804 Diag(
New->getLocation(), diag::err_redefinition_different_kind)
3805 <<
New->getDeclName();
3829 std::tie(PrevDiag, OldLocation) =
3839 !
New->getTemplateSpecializationInfo() &&
3842 Diag(
New->getLocation(), diag::ext_static_non_static) <<
New;
3843 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3845 Diag(
New->getLocation(), diag::err_static_non_static)
3847 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
3852 if (
const auto *ILA =
New->getAttr<InternalLinkageAttr>())
3853 if (!Old->
hasAttr<InternalLinkageAttr>()) {
3854 Diag(
New->getLocation(), diag::err_attribute_missing_on_first_decl)
3857 New->dropAttr<InternalLinkageAttr>();
3860 if (
auto *EA =
New->getAttr<ErrorAttr>()) {
3861 if (!Old->
hasAttr<ErrorAttr>()) {
3862 Diag(EA->getLocation(), diag::err_attribute_missing_on_first_decl) << EA;
3864 New->dropAttr<ErrorAttr>();
3872 bool OldOvl = Old->
hasAttr<OverloadableAttr>();
3873 if (OldOvl !=
New->hasAttr<OverloadableAttr>() && !Old->
isImplicit()) {
3874 Diag(
New->getLocation(), diag::err_attribute_overloadable_mismatch)
3883 const Decl *DiagOld = Old;
3885 auto OldIter = llvm::find_if(Old->
redecls(), [](
const Decl *D) {
3886 const auto *A = D->getAttr<OverloadableAttr>();
3887 return A && !A->isImplicit();
3896 diag::note_attribute_overloadable_prev_overload)
3900 New->addAttr(OverloadableAttr::CreateImplicit(
Context));
3902 New->dropAttr<OverloadableAttr>();
3909 Diag(
New->getLocation(), diag::err_sme_attr_mismatch)
3911 Diag(OldLocation, diag::note_previous_declaration);
3934 bool RequiresAdjustment =
false;
3936 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC()) {
3942 if (!NewCCExplicit) {
3946 RequiresAdjustment =
true;
3954 Diag(
New->getLocation(), diag::warn_cconv_unsupported)
3958 RequiresAdjustment =
true;
3962 Diag(
New->getLocation(), diag::err_cconv_change)
3965 << (!FirstCCExplicit ?
"" :
3969 Diag(
First->getLocation(), diag::note_previous_declaration);
3977 RequiresAdjustment =
true;
3989 NewQType =
Context.getFunctionType(FPT2->getReturnType(),
3990 FPT2->getParamTypes(), EPI2);
3992 New->setType(NewQType);
4001 Diag(
New->getLocation(), diag::err_regparm_mismatch)
4004 Diag(OldLocation, diag::note_previous_declaration);
4009 RequiresAdjustment =
true;
4015 Diag(
New->getLocation(), diag::err_function_attribute_mismatch)
4016 <<
"'ns_returns_retained'";
4017 Diag(OldLocation, diag::note_previous_declaration);
4022 RequiresAdjustment =
true;
4028 AnyX86NoCallerSavedRegistersAttr *
Attr =
4029 New->getAttr<AnyX86NoCallerSavedRegistersAttr>();
4030 Diag(
New->getLocation(), diag::err_function_attribute_mismatch) <<
Attr;
4031 Diag(OldLocation, diag::note_previous_declaration);
4036 RequiresAdjustment =
true;
4039 if (RequiresAdjustment) {
4043 NewQType =
Context.getCanonicalType(
New->getType());
4048 if (!Old->
isInlined() &&
New->isInlined() && !
New->hasAttr<GNUInlineAttr>() &&
4056 if (
New->hasAttr<GNUInlineAttr>() &&
4065 Diag(
New->getLocation(), diag::err_different_pass_object_size_params)
4066 <<
New->getDeclName();
4067 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4071 QualType OldQTypeForComparison = OldQType;
4072 if (
Context.hasAnyFunctionEffects()) {
4074 const auto NewFX =
New->getFunctionEffects();
4075 if (OldFX != NewFX) {
4077 for (
const auto &Diff : Diffs) {
4078 if (Diff.shouldDiagnoseRedeclaration(*Old, OldFX, *
New, NewFX)) {
4080 diag::warn_mismatched_func_effect_redeclaration)
4081 << Diff.effectName();
4092 if (!MergeErrs.empty())
4099 NewFPT->getParamTypes(), EPI);
4101 New->setType(ModQT);
4102 NewQType =
New->getType();
4107 EPI = OldFPT->getExtProtoInfo();
4109 OldQTypeForComparison =
Context.getFunctionType(
4110 OldFPT->getReturnType(), OldFPT->getParamTypes(), EPI);
4112 if (OldFX.empty()) {
4123 NewQType =
Context.getCanonicalType(
New->getType());
4131 QualType NewDeclaredReturnType =
New->getDeclaredReturnType();
4132 if (!
Context.hasSameType(OldDeclaredReturnType, NewDeclaredReturnType) &&
4134 OldDeclaredReturnType)) {
4139 ResQT =
Context.mergeObjCGCQualifiers(NewQType, OldQType);
4141 if (
New->isCXXClassMember() &&
New->isOutOfLine())
4142 Diag(
New->getLocation(), diag::err_member_def_does_not_match_ret_type)
4143 <<
New <<
New->getReturnTypeSourceRange();
4145 !Old->
hasAttr<OverloadableAttr>() &&
4146 !
New->hasAttr<OverloadableAttr>())
4147 Diag(
New->getLocation(), diag::err_conflicting_types) <<
New;
4149 Diag(
New->getLocation(), diag::err_ovl_diff_return_type)
4150 <<
New->getReturnTypeSourceRange();
4151 Diag(OldLocation, PrevDiag) << Old << Old->
getType()
4161 if (OldReturnType != NewReturnType) {
4165 if (OldAT && OldAT->isDeduced()) {
4166 QualType DT = OldAT->getDeducedType();
4177 const CXXMethodDecl *OldMethod = dyn_cast<CXXMethodDecl>(Old);
4179 if (OldMethod && NewMethod) {
4186 bool IsClassScopeExplicitSpecialization =
4192 !IsClassScopeExplicitSpecialization) {
4197 Diag(
New->getLocation(), diag::err_ovl_static_nonstatic_member);
4198 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4209 NewDiag = diag::err_constructor_redeclared;
4211 NewDiag = diag::err_destructor_redeclared;
4213 NewDiag = diag::err_conv_function_redeclared;
4215 NewDiag = diag::err_member_redeclared;
4217 Diag(
New->getLocation(), NewDiag);
4219 Diag(
New->getLocation(), diag::err_member_redeclared_in_instantiation)
4220 <<
New <<
New->getType();
4222 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4235 diag::err_definition_of_implicitly_declared_member)
4241 diag::err_definition_of_explicitly_defaulted_member)
4264 if (
const auto *NRA =
New->getAttr<CXX11NoReturnAttr>())
4265 if (!Old->
hasAttr<CXX11NoReturnAttr>()) {
4266 Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
4276 const SYCLExternalAttr *SEA =
New->getAttr<SYCLExternalAttr>();
4277 if (SEA && !Old->
hasAttr<SYCLExternalAttr>()) {
4278 Diag(SEA->getLocation(), diag::warn_sycl_external_missing_on_first_decl)
4293 OldQTypeForComparison =
QualType(OldTypeForComparison, 0);
4307 Diag(
New->getLocation(), diag::ext_retained_language_linkage) <<
New;
4308 Diag(OldLocation, PrevDiag);
4310 Diag(
New->getLocation(), diag::err_different_language_linkage) <<
New;
4311 Diag(OldLocation, PrevDiag);
4318 if (
HLSL().CheckCompatibleParameterABI(
New, Old))
4326 if (
Context.hasSameFunctionTypeIgnoringParamABI(OldQTypeForComparison,
4336 if (
Context.hasSameFunctionTypeIgnoringExceptionSpec(OldQTypeForComparison,
4364 if (Old->
hasPrototype() && !
New->hasWrittenPrototype() && NewDeclIsDefn &&
4368 Diag(
New->getLocation(), diag::err_conflicting_types) <<
New;
4386 if (
New->hasWrittenPrototype()) {
4398 bool IsWithoutProtoADef =
false, IsWithProtoADef =
false;
4399 if (WithoutProto ==
New)
4400 IsWithoutProtoADef = NewDeclIsDefn;
4402 IsWithProtoADef = NewDeclIsDefn;
4404 diag::warn_non_prototype_changes_behavior)
4405 << IsWithoutProtoADef << (WithoutProto->
getNumParams() ? 0 : 1)
4406 << (WithoutProto == Old) << IsWithProtoADef;
4416 !IsWithoutProtoADef)
4422 if (
Context.typesAreCompatible(OldQType, NewQType)) {
4427 (OldProto = dyn_cast<FunctionProtoType>(OldFuncType))) {
4430 assert(!OldProto->hasExceptionSpec() &&
"Exception spec in C");
4431 NewQType =
Context.getFunctionType(NewFuncType->getReturnType(),
4432 OldProto->getParamTypes(),
4433 OldProto->getExtProtoInfo());
4434 New->setType(NewQType);
4435 New->setHasInheritedPrototype();
4439 for (
const auto &ParamType : OldProto->param_types()) {
4442 ParamType,
nullptr,
SC_None,
nullptr);
4443 Param->setScopeInfo(0, Params.size());
4444 Param->setImplicit();
4445 Params.push_back(Param);
4448 New->setParams(Params);
4457 if (
Context.hasSameFunctionTypeIgnoringPtrSizes(OldQType, NewQType))
4484 NewProto->getReturnType());
4485 bool LooseCompatible = !MergedReturn.isNull();
4487 LooseCompatible && Idx != End; ++Idx) {
4491 NewProto->getParamType(Idx))) {
4492 ArgTypes.push_back(NewParm->
getType());
4496 GNUCompatibleParamWarning Warn = { OldParm, NewParm,
4497 NewProto->getParamType(Idx) };
4498 Warnings.push_back(Warn);
4499 ArgTypes.push_back(NewParm->
getType());
4501 LooseCompatible =
false;
4504 if (LooseCompatible) {
4505 for (
unsigned Warn = 0; Warn < Warnings.size(); ++Warn) {
4506 Diag(Warnings[Warn].NewParm->getLocation(),
4507 diag::ext_param_promoted_not_compatible_with_prototype)
4508 << Warnings[Warn].PromotedType
4509 << Warnings[Warn].OldParm->getType();
4510 if (Warnings[Warn].OldParm->getLocation().isValid())
4511 Diag(Warnings[Warn].OldParm->getLocation(),
4512 diag::note_previous_declaration);
4515 if (MergeTypeWithOld)
4516 New->setType(
Context.getFunctionType(MergedReturn, ArgTypes,
4533 if (
Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID)) {
4534 Diag(
New->getLocation(), diag::warn_redecl_library_builtin) <<
New;
4535 Diag(OldLocation, diag::note_previous_builtin_declaration)
4540 PrevDiag = diag::note_previous_builtin_declaration;
4543 Diag(
New->getLocation(), diag::err_conflicting_types) <<
New->getDeclName();
4544 Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4549 Scope *S,
bool MergeTypeWithOld) {
4555 New->setIsPureVirtual();
4564 for (
unsigned i = 0, e =
New->getNumParams(); i != e; ++i) {
4578 if (!Merged.isNull() && MergeTypeWithOld)
4579 New->setType(Merged);
4603 ni != ne && oi != oe; ++ni, ++oi)
4612 S.
Diag(
New->getLocation(),
New->isThisDeclarationADefinition()
4613 ? diag::err_redefinition_different_type
4614 : diag::err_redeclaration_different_type)
4619 std::tie(PrevDiag, OldLocation)
4621 S.
Diag(OldLocation, PrevDiag) << Old << Old->
getType();
4622 New->setInvalidDecl();
4626 bool MergeTypeWithOld) {
4632 if (
New->getType()->isUndeducedType()) {
4654 QualType PrevVDTy = PrevVD->getType();
4658 if (!
Context.hasSameType(
New->getType(), PrevVDTy))
4666 MergedT =
New->getType();
4677 else if (
New->getType()->isObjCObjectPointerType() &&
4679 MergedT =
Context.mergeObjCGCQualifiers(
New->getType(),
4694 if ((
New->getType()->isDependentType() ||
4699 if (!
New->getType()->isDependentType() && MergeTypeWithOld)
4708 if (MergeTypeWithOld)
4709 New->setType(MergedT);
4743 if (
New->isInvalidDecl())
4756 OldTemplate = dyn_cast<VarTemplateDecl>(
Previous.getFoundDecl());
4760 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4762 return New->setInvalidDecl();
4764 Old = dyn_cast<VarDecl>(
Previous.getFoundDecl());
4767 dyn_cast<UsingShadowDecl>(
Previous.getRepresentativeDecl()))
4769 return New->setInvalidDecl();
4773 Diag(
New->getLocation(), diag::err_redefinition_different_kind)
4774 <<
New->getDeclName();
4776 New->getLocation());
4777 return New->setInvalidDecl();
4789 return New->setInvalidDecl();
4796 Diag(
New->getLocation(), diag::err_duplicate_member)
4797 <<
New->getIdentifier();
4799 New->setInvalidDecl();
4802 if (NewTemplate && OldTemplate)
4809 if (
New->hasAttr<WeakImportAttr>())
4812 Diag(
New->getLocation(), diag::warn_weak_import) <<
New->getDeclName();
4815 New->dropAttr<WeakImportAttr>();
4820 if (
const auto *ILA =
New->getAttr<InternalLinkageAttr>())
4821 if (!Old->
hasAttr<InternalLinkageAttr>()) {
4822 Diag(
New->getLocation(), diag::err_attribute_missing_on_first_decl)
4825 New->dropAttr<InternalLinkageAttr>();
4830 if (MostRecent != Old) {
4833 if (
New->isInvalidDecl())
4838 if (
New->isInvalidDecl())
4843 std::tie(PrevDiag, OldLocation) =
4848 !
New->isStaticDataMember() &&
4851 Diag(
New->getLocation(), diag::ext_static_non_static)
4852 <<
New->getDeclName();
4853 Diag(OldLocation, PrevDiag);
4858 Diag(
New->getLocation(), diag::err_static_non_static)
4859 <<
New->getDeclName()
4861 Diag(OldLocation, PrevDiag);
4862 return New->setInvalidDecl();
4878 New->hasExternalStorage() &&
Previous.isShadowed() &&
4880 Diag(
New->getLocation(), diag::err_internal_extern_mismatch)
4882 Diag(OldLocation, diag::note_previous_declaration);
4883 return New->setInvalidDecl();
4897 else if (
New->getCanonicalDecl()->getStorageClass() !=
SC_Static &&
4898 !
New->isStaticDataMember() &&
4900 Diag(
New->getLocation(), diag::err_non_static_static) <<
New->getDeclName();
4901 Diag(OldLocation, PrevDiag);
4902 return New->setInvalidDecl();
4906 if (
New->hasExternalStorage() &&
4908 Diag(
New->getLocation(), diag::err_extern_non_extern) <<
New->getDeclName();
4909 Diag(OldLocation, PrevDiag);
4910 return New->setInvalidDecl();
4913 !
New->hasExternalStorage()) {
4914 Diag(
New->getLocation(), diag::err_non_extern_extern) <<
New->getDeclName();
4915 Diag(OldLocation, PrevDiag);
4916 return New->setInvalidDecl();
4926 if (!
New->hasExternalStorage() && !
New->isFileVarDecl() &&
4929 !
New->getLexicalDeclContext()->isRecord())) {
4930 Diag(
New->getLocation(), diag::err_redefinition) <<
New->getDeclName();
4931 Diag(OldLocation, PrevDiag);
4932 return New->setInvalidDecl();
4940 Diag(
New->getLocation(), diag::err_inline_decl_follows_def) <<
New;
4941 Diag(Def->getLocation(), diag::note_previous_definition);
4955 Diag(
New->getLocation(), diag::err_thread_non_thread) <<
New->getDeclName();
4956 Diag(OldLocation, PrevDiag);
4957 }
else if (!
New->getTLSKind()) {
4958 Diag(
New->getLocation(), diag::err_non_thread_thread) <<
New->getDeclName();
4959 Diag(OldLocation, PrevDiag);
4965 Diag(
New->getLocation(), diag::err_thread_thread_different_kind)
4967 Diag(OldLocation, PrevDiag);
4977 diag::warn_deprecated_redundant_constexpr_static_def);
4983 New->setInvalidDecl();
4998 Diag(
New->getLocation(), diag::warn_cxx_compat_tentative_definition)
5005 Diag(
New->getLocation(), diag::err_different_language_linkage) <<
New;
5006 Diag(OldLocation, PrevDiag);
5007 New->setInvalidDecl();
5016 New->setPreviousDecl(Old);
5026 New->setImplicitlyInline();
5031 auto FNewDecLoc =
SrcMgr.getDecomposedLoc(
New);
5033 auto *FNew =
SrcMgr.getFileEntryForID(FNewDecLoc.first);
5034 auto FOld =
SrcMgr.getFileEntryRefForID(FOldDecLoc.first);
5035 auto &HSI =
PP.getHeaderSearchInfo();
5036 StringRef HdrFilename =
5039 auto noteFromModuleOrInclude = [&](
Module *Mod,
5045 if (IncLoc.isValid()) {
5047 Diag(IncLoc, diag::note_redefinition_modules_same_file)
5053 Diag(IncLoc, diag::note_redefinition_include_same_file)
5054 << HdrFilename.str();
5064 if (FNew == FOld && FNewDecLoc.second == FOldDecLoc.second) {
5072 if (FOld && !HSI.isFileMultipleIncludeGuarded(*FOld))
5089 New->getDescribedVarTemplate() ||
5090 !
New->getTemplateParameterLists().empty() ||
5091 New->getDeclContext()->isDependentContext() ||
5092 New->hasAttr<SelectAnyAttr>())) {
5095 New->demoteThisDefinitionToDeclaration();
5103 Diag(
New->getLocation(), diag::err_redefinition) <<
New;
5105 New->setInvalidDecl();
5131 if (!
Context.getLangOpts().CPlusPlus)
5137 if (!Tag->getName().empty() || Tag->getTypedefNameForAnonDecl())
5140 Context.getManglingNumberContext(Tag->getParent());
5149 Decl *ManglingContextDecl;
5150 std::tie(MCtx, ManglingContextDecl) =
5160struct NonCLikeKind {
5172 explicit operator bool() {
return Kind !=
None; }
5180 return {NonCLikeKind::Invalid, {}};
5187 return {NonCLikeKind::BaseClass,
5199 if (
auto *FD = dyn_cast<FieldDecl>(D)) {
5200 if (FD->hasInClassInitializer()) {
5201 auto *
Init = FD->getInClassInitializer();
5202 return {NonCLikeKind::DefaultMemberInit,
5218 auto *MemberRD = dyn_cast<CXXRecordDecl>(D);
5226 if (MemberRD->isLambda())
5227 return {NonCLikeKind::Lambda, MemberRD->getSourceRange()};
5231 if (MemberRD->isThisDeclarationADefinition()) {
5237 return {
Invalid ? NonCLikeKind::Invalid : NonCLikeKind::None, {}};
5254 Context.getCanonicalTagType(TagFromDeclSpec))) {
5256 Context.addTypedefNameForUnnamedTagDecl(TagFromDeclSpec, NewTD);
5267 const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TagFromDeclSpec);
5271 if (NonCLike || ChangesLinkage) {
5272 if (NonCLike.Kind == NonCLikeKind::Invalid)
5275 unsigned DiagID = diag::ext_non_c_like_anon_struct_in_typedef;
5276 if (ChangesLinkage) {
5278 if (NonCLike.Kind == NonCLikeKind::None)
5279 DiagID = diag::err_typedef_changes_linkage;
5281 DiagID = diag::err_non_c_like_anon_struct_in_typedef;
5287 TextToInsert +=
' ';
5290 Diag(FixitLoc, DiagID)
5293 if (NonCLike.Kind != NonCLikeKind::None) {
5294 Diag(NonCLike.Range.
getBegin(), diag::note_non_c_like_anon_struct)
5295 << NonCLike.Kind - 1 << NonCLike.Range;
5298 << NewTD << isa<TypeAliasDecl>(NewTD);
5323 if (
const auto *ED = dyn_cast<EnumDecl>(DS.
getRepAsDecl())) {
5324 if (ED->isScopedUsingClassTag())
5331 llvm_unreachable(
"unexpected type specifier");
5339 bool IsExplicitInstantiation,
5342 Decl *TagD =
nullptr;
5360 Tag = CTD->getTemplatedDecl();
5365 Tag->setFreeStanding();
5366 if (Tag->isInvalidDecl())
5375 diag::err_typecheck_invalid_restrict_not_pointer_noarg)
5412 "Friend ellipsis but not friend-specified?");
5415 bool DeclaresAnything =
true;
5419 if (!
Record->getDeclName() &&
Record->isCompleteDefinition() &&
5422 Record->getDeclContext()->isRecord()) {
5436 DeclaresAnything =
false;
5455 if ((Tag && Tag->getDeclName()) ||
5465 DeclaresAnything =
false;
5477 if (
Enum->enumerators().empty() && !
Enum->getIdentifier() &&
5478 !
Enum->isInvalidDecl())
5479 DeclaresAnything =
false;
5487 DeclaresAnything =
false;
5491 Tag && Tag->getDeclContext()->isFunctionOrMethod())
5493 << Tag->getTagKind()
5506 if (!DeclaresAnything) {
5509 Diag(DS.
getBeginLoc(), (IsExplicitInstantiation || !TemplateParams.empty())
5510 ? diag::err_no_declarators
5511 : diag::ext_no_declarators)
5524 unsigned DiagID = diag::warn_standalone_specifier;
5526 DiagID = diag::ext_standalone_specifier;
5567 auto EmitAttributeDiagnostic = [
this, &DS](
const ParsedAttr &AL) {
5568 unsigned DiagnosticId = diag::warn_declspec_attribute_ignored;
5570 DiagnosticId = diag::warn_attribute_ignored;
5571 else if (AL.isRegularKeywordAttribute())
5572 DiagnosticId = diag::err_declspec_keyword_has_no_effect;
5574 DiagnosticId = diag::warn_declspec_attribute_ignored;
5575 Diag(AL.getLoc(), DiagnosticId)
5579 llvm::for_each(DS.
getAttributes(), EmitAttributeDiagnostic);
5580 llvm::for_each(DeclAttrs, EmitAttributeDiagnostic);
5603 NamedDecl *PrevDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
5604 assert(PrevDecl &&
"Expected a non-null Decl");
5617 SemaRef.
Diag(NameLoc, diag::err_anonymous_record_member_redecl)
5619 SemaRef.
Diag(PrevDecl->
getLocation(), diag::note_previous_declaration);
5625 if (
auto *RD = dyn_cast_if_present<RecordDecl>(D))
5635 if (
Record->isAnonymousStructOrUnion())
5640 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
5674 for (
auto *D : AnonRecord->
decls()) {
5697 unsigned OldChainingSize = Chaining.size();
5699 Chaining.append(IF->chain_begin(), IF->chain_end());
5701 Chaining.push_back(VD);
5703 assert(Chaining.size() >= 2);
5706 for (
unsigned i = 0; i < Chaining.size(); i++)
5707 NamedChain[i] = Chaining[i];
5711 VD->
getType(), {NamedChain, Chaining.size()});
5725 Chaining.resize(OldChainingSize);
5739 "Parser allowed 'typedef' as storage class VarDecl.");
5740 switch (StorageClassSpec) {
5754 llvm_unreachable(
"unknown storage class specifier");
5758 assert(
Record->hasInClassInitializer());
5760 for (
const auto *I :
Record->decls()) {
5761 const auto *FD = dyn_cast<FieldDecl>(I);
5762 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
5763 FD = IFD->getAnonField();
5764 if (FD && FD->hasInClassInitializer())
5765 return FD->getLocation();
5768 llvm_unreachable(
"couldn't find in-class initializer");
5776 S.
Diag(DefaultInitLoc, diag::err_multiple_mem_union_initialization);
5796 Diag(
Record->getLocation(), diag::ext_anonymous_union);
5798 Diag(
Record->getLocation(), diag::ext_gnu_anonymous_struct);
5800 Diag(
Record->getLocation(), diag::ext_c11_anonymous_struct);
5806 const char *PrevSpec =
nullptr;
5818 Diag(
Record->getLocation(), diag::err_anonymous_union_not_static)
5823 PrevSpec, DiagID, Policy);
5831 diag::err_anonymous_union_with_storage_spec)
5837 PrevSpec, DiagID,
Context.getPrintingPolicy());
5845 <<
Record->isUnion() <<
"const"
5849 diag::ext_anonymous_struct_union_qualified)
5850 <<
Record->isUnion() <<
"volatile"
5854 diag::ext_anonymous_struct_union_qualified)
5855 <<
Record->isUnion() <<
"restrict"
5859 diag::ext_anonymous_struct_union_qualified)
5860 <<
Record->isUnion() <<
"_Atomic"
5864 diag::ext_anonymous_struct_union_qualified)
5865 <<
Record->isUnion() <<
"__unaligned"
5875 for (
auto *Mem :
Record->decls()) {
5877 if (Mem->isInvalidDecl())
5880 if (
auto *FD = dyn_cast<FieldDecl>(Mem)) {
5884 assert(FD->getAccess() !=
AS_none);
5886 Diag(FD->getLocation(), diag::err_anonymous_record_nonpublic_member)
5898 }
else if (Mem->isImplicit()) {
5905 }
else if (
auto *MemRecord = dyn_cast<RecordDecl>(Mem)) {
5906 if (!MemRecord->isAnonymousStructOrUnion() &&
5907 MemRecord->getDeclName()) {
5910 Diag(MemRecord->getLocation(), diag::ext_anonymous_record_with_type)
5914 Diag(MemRecord->getLocation(), diag::err_anonymous_record_with_type)
5922 Diag(MemRecord->getLocation(),
5923 diag::ext_anonymous_record_with_anonymous_type)
5933 unsigned DK = diag::err_anonymous_record_bad_member;
5935 DK = diag::err_anonymous_record_with_type;
5937 DK = diag::err_anonymous_record_with_function;
5939 DK = diag::err_anonymous_record_with_static;
5943 DK == diag::err_anonymous_record_with_type)
5944 Diag(Mem->getLocation(), diag::ext_anonymous_record_with_type)
5947 Diag(Mem->getLocation(), DK) <<
Record->isUnion();
5963 Diag(
Record->getLocation(), diag::err_anonymous_struct_not_member)
5984 assert(TInfo &&
"couldn't build declarator info for anonymous struct/union");
5988 if (
RecordDecl *OwningClass = dyn_cast<RecordDecl>(Owner)) {
6004 Diag(
Record->getLocation(), diag::err_mutable_nonmember);
6010 Record->getLocation(),
nullptr,
6026 Record->setAnonymousStructOrUnion(
true);
6037 Chain.push_back(Anon);
6043 if (
VarDecl *NewVD = dyn_cast<VarDecl>(Anon)) {
6046 Decl *ManglingContextDecl;
6047 std::tie(MCtx, ManglingContextDecl) =
6066 assert(
Record &&
"expected a record!");
6071 assert(TInfo &&
"couldn't build declarator info for anonymous struct");
6079 nullptr, RecTy, TInfo,
6091 Chain.push_back(Anon);
6095 diag::err_field_incomplete_or_sizeless) ||
6100 ParentDecl->setInvalidDecl();
6137 diag::err_deduction_guide_name_not_class_template)
6157 NameInfo.
setName(
Context.DeclarationNames.getCXXLiteralOperatorName(
6167 NameInfo.
setName(
Context.DeclarationNames.getCXXConversionFunctionName(
6168 Context.getCanonicalType(Ty)));
6179 Context.getCanonicalType(Ty)));
6200 Context.DeclarationNames.getCXXConstructorName(CurClassType));
6212 Context.getCanonicalType(Ty)));
6220 return Context.getNameForTemplate(TName, TNameLoc);
6225 llvm_unreachable(
"Unknown name kind");
6253 for (
unsigned Idx = 0; Idx <
Declaration->param_size(); ++Idx) {
6258 if (Context.hasSameUnqualifiedType(DefParamTy, DeclParamTy))
6266 if (Context.hasSameUnqualifiedType(DeclParamBaseTy, DefParamBaseTy) ||
6267 (DeclTyName && DeclTyName == DefTyName))
6268 Params.push_back(Idx);
6295#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case DeclSpec::TST_##Trait:
6296#include "clang/Basic/BuiltinTraits.inc"
6301 if (
T.isNull() || !
T->isInstantiationDependentType())
break;
6311 if (!TSI)
return true;
6324 if (
Result.isInvalid())
return true;
6369 << D << static_cast<int>(Status);
6380 if (
OpenMP().getOMPTraitInfoForSurroundingScope()->isExtensionActive(
6381 llvm::omp::TraitProperty::
6382 implementation_extension_bind_to_declaration))
6407 Diag(NameInfo.
getLoc(), diag::err_member_name_of_class) << Name;
6418 bool IsMemberSpecialization) {
6419 assert(SS.
isValid() &&
"diagnoseQualifiedDeclaration called for declaration "
6420 "without nested-name-specifier");
6436 Diag(Loc,
LangOpts.MicrosoftExt ? diag::warn_member_extra_qualification
6437 : diag::err_member_extra_qualification)
6441 Diag(Loc, diag::warn_namespace_member_extra_qualification) << Name;
6449 if (!Cur->
Encloses(DC) && !(TemplateId || IsMemberSpecialization)) {
6452 Diag(Loc, diag::err_member_qualification)
6455 Diag(Loc, diag::err_invalid_declarator_global_scope)
6458 Diag(Loc, diag::err_invalid_declarator_in_function)
6461 Diag(Loc, diag::err_invalid_declarator_in_block)
6465 Diag(Loc, diag::err_export_non_namespace_scope_name)
6472 Diag(Loc, diag::err_invalid_declarator_scope)
6482 if (IsMemberSpecialization)
6486 Diag(Loc, diag::err_member_qualification)
6513 Diag(Loc, diag::ext_template_after_declarative_nns)
6518 TL = std::exchange(NextTL,
TypeLoc())) {
6520 switch (TL.getTypeLocClass()) {
6521 case TypeLoc::TemplateSpecialization: {
6523 TemplateKeywordLoc = TST.getTemplateKeywordLoc();
6524 if (
auto *
T = TST.getTypePtr();
T->isDependentType() &&
T->isTypeAlias())
6525 Diag(Loc, diag::ext_alias_template_in_declarative_nns)
6526 << TST.getLocalSourceRange();
6529 case TypeLoc::Decltype:
6530 case TypeLoc::PackIndexing: {
6531 const Type *
T = TL.getTypePtr();
6538 Diag(Loc, diag::err_computed_type_in_declarative_nns)
6539 <<
T->isDecltypeType() << TL.getSourceRange();
6542 case TypeLoc::DependentName:
6549 if (TemplateKeywordLoc.
isValid())
6550 Diag(Loc, diag::ext_template_after_declarative_nns)
6591 diag::err_template_qualified_declarator_no_match)
6598 if (!IsDependentContext &&
6605 diag::err_member_def_undefined_record)
6628 if (EnteringContext && IsDependentContext &&
6629 TemplateParamLists.size() != 0) {
6648 bool IsLinkageLookup =
false;
6649 bool CreateBuiltins =
false;
6662 R->isFunctionType())) {
6663 IsLinkageLookup =
true;
6665 CurContext->getEnclosingNamespaceContext()->isTranslationUnit();
6666 }
else if (
CurContext->getRedeclContext()->isTranslationUnit() &&
6668 CreateBuiltins =
true;
6670 if (IsLinkageLookup) {
6712 bool AllowForCompatibility =
false;
6715 AllowForCompatibility = DeclParent->Contains(*TemplateParamParent) &&
6716 TemplateParamParent->isDeclScope(TPD);
6719 AllowForCompatibility);
6736 (TemplateParamLists.size() == 0 || R->isFunctionType()))
6749 bool AddToScope =
true;
6751 if (TemplateParamLists.size()) {
6757 }
else if (R->isFunctionType()) {
6773 if (
New->getDeclName() && AddToScope)
6776 if (
OpenMP().isInOpenMPDeclareTargetContext())
6787 bool &SizeIsNegative,
6788 llvm::APSInt &Oversized) {
6793 SizeIsNegative =
false;
6796 if (
T->isDependentType())
6802 if (
const PointerType* PTy = dyn_cast<PointerType>(Ty)) {
6807 if (FixedType.
isNull())
return FixedType;
6808 FixedType = Context.getPointerType(FixedType);
6809 return Qs.
apply(Context, FixedType);
6811 if (
const ParenType* PTy = dyn_cast<ParenType>(Ty)) {
6812 QualType Inner = PTy->getInnerType();
6816 if (FixedType.
isNull())
return FixedType;
6817 FixedType = Context.getParenType(FixedType);
6818 return Qs.
apply(Context, FixedType);
6828 SizeIsNegative, Oversized);
6838 llvm::APSInt Res =
Result.Val.getInt();
6841 if (Res.isSigned() && Res.isNegative()) {
6842 SizeIsNegative =
true;
6847 unsigned ActiveSizeBits =
6851 : Res.getActiveBits();
6853 Oversized = std::move(Res);
6857 QualType FoldedArrayType = Context.getConstantArrayType(
6859 return Qs.
apply(Context, FoldedArrayType);
6884 TypeLoc DstElemTL = DstATL.getElementLoc();
6903 bool &SizeIsNegative,
6904 llvm::APSInt &Oversized) {
6907 SizeIsNegative, Oversized);
6910 TypeSourceInfo *FixedTInfo = Context.getTrivialTypeSourceInfo(FixedTy);
6918 unsigned FailedFoldDiagID) {
6919 bool SizeIsNegative;
6920 llvm::APSInt Oversized;
6922 TInfo,
Context, SizeIsNegative, Oversized);
6924 Diag(Loc, diag::ext_vla_folded_to_constant);
6931 Diag(Loc, diag::err_typecheck_negative_array_size);
6932 else if (Oversized.getBoolValue())
6934 Oversized, 10, Oversized.isSigned(),
false,
6936 else if (FailedFoldDiagID)
6937 Diag(Loc, FailedFoldDiagID);
6949 Context.getExternCContextDecl()->makeDeclVisibleInContext(ND);
6954 auto Result =
Context.getExternCContextDecl()->lookup(Name);
6963 diag::err_virtual_non_function);
6967 diag::err_explicit_non_function);
6971 diag::err_noreturn_non_function);
6992 ? diag::warn_ms_inline_non_function
6993 : diag::err_inline_non_function)
6997 << 1 <<
static_cast<int>(D.
getDeclSpec().getConstexprSpecifier());
7002 diag::err_deduction_guide_invalid_specifier)
7011 if (!NewTD)
return nullptr;
7032 if (
T->isVariablyModifiedType()) {
7036 bool SizeIsNegative;
7037 llvm::APSInt Oversized;
7048 else if (
T->isVariableArrayType())
7050 else if (Oversized.getBoolValue())
7087 switch (II->getNotableIdentifierID()) {
7088 case tok::NotableIdentifierKind::FILE:
7091 case tok::NotableIdentifierKind::jmp_buf:
7092 Context.setjmp_bufDecl(NewTD);
7094 case tok::NotableIdentifierKind::sigjmp_buf:
7095 Context.setsigjmp_bufDecl(NewTD);
7097 case tok::NotableIdentifierKind::ucontext_t:
7098 Context.setucontext_tDecl(NewTD);
7100 case tok::NotableIdentifierKind::float_t:
7101 case tok::NotableIdentifierKind::double_t:
7102 NewTD->
addAttr(AvailableOnlyInDefaultEvalMethodAttr::Create(
Context));
7139 if (Context.getLangOpts().CPlusPlus) {
7163 if (!OuterContext->
Equals(PrevOuterContext))
7172 if (!SS.
isSet())
return;
7189 const WeakAttr &
Attr) {
7193 if (
const auto *FD = dyn_cast<FunctionDecl>(&ND))
7196 return DiagnoseMutualExclusions(S, D, &
Attr);
7214 if (WeakRefAttr *
Attr = ND.
getAttr<WeakRefAttr>()) {
7223 if (
auto *VD = dyn_cast<VarDecl>(&ND)) {
7224 if (VD->hasInit()) {
7225 if (
const auto *
Attr = VD->getAttr<AliasAttr>()) {
7226 assert(VD->isThisDeclarationADefinition() &&
7227 "Broken AliasAttr handled late!");
7229 VD->dropAttr<AliasAttr>();
7238 if (SelectAnyAttr *
Attr = ND.
getAttr<SelectAnyAttr>()) {
7241 diag::err_attribute_selectany_non_extern_data);
7248 if (HybridPatchableAttr *
Attr = ND.
getAttr<HybridPatchableAttr>()) {
7251 diag::warn_attribute_hybrid_patchable_non_extern);
7257 auto *VD = dyn_cast<VarDecl>(&ND);
7258 bool IsAnonymousNS =
false;
7261 const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(VD->getDeclContext());
7262 while (NS && !IsAnonymousNS) {
7264 NS = dyn_cast<NamespaceDecl>(NS->
getParent());
7271 bool AnonNSInMicrosoftMode = IsAnonymousNS && IsMicrosoft;
7273 (!AnonNSInMicrosoftMode &&
7284 if (
const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
7285 FD = FD->getMostRecentDecl();
7290 for (
TypeLoc TL = FD->getTypeSourceInfo()->getTypeLoc();
7296 if (
const auto *A = ATL.
getAttrAs<LifetimeBoundAttr>()) {
7297 const auto *MD = dyn_cast<CXXMethodDecl>(FD);
7298 int NoImplicitObjectError = -1;
7300 NoImplicitObjectError = 0;
7301 else if (MD->isStatic())
7302 NoImplicitObjectError = 1;
7303 else if (MD->isExplicitObjectMemberFunction())
7304 NoImplicitObjectError = 2;
7305 if (NoImplicitObjectError != -1) {
7306 S.
Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
7307 << NoImplicitObjectError << A->getRange();
7309 S.
Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
7311 }
else if (MD->getReturnType()->isVoidType()) {
7315 err_lifetimebound_implicit_object_parameter_void_return_type);
7320 for (
unsigned int I = 0; I < FD->getNumParams(); ++I) {
7325 if (
auto *A = P->
getAttr<LifetimeBoundAttr>()) {
7327 S.
Diag(A->getLocation(),
7328 diag::err_lifetimebound_parameter_void_return_type);
7336 if (ND.
hasAttr<ModularFormatAttr>() && !ND.
hasAttr<FormatAttr>())
7337 S.
Diag(ND.
getLocation(), diag::err_modular_format_attribute_no_format);
7356 bool IsSpecialization,
7357 bool IsDefinition) {
7361 bool IsTemplate =
false;
7362 if (
TemplateDecl *OldTD = dyn_cast<TemplateDecl>(OldDecl)) {
7363 OldDecl = OldTD->getTemplatedDecl();
7365 if (!IsSpecialization)
7366 IsDefinition =
false;
7368 if (
TemplateDecl *NewTD = dyn_cast<TemplateDecl>(NewDecl)) {
7369 NewDecl = NewTD->getTemplatedDecl();
7373 if (!OldDecl || !NewDecl)
7376 const DLLImportAttr *OldImportAttr = OldDecl->
getAttr<DLLImportAttr>();
7377 const DLLExportAttr *OldExportAttr = OldDecl->
getAttr<DLLExportAttr>();
7378 const DLLImportAttr *NewImportAttr = NewDecl->
getAttr<DLLImportAttr>();
7379 const DLLExportAttr *NewExportAttr = NewDecl->
getAttr<DLLExportAttr>();
7383 bool HasNewAttr = (NewImportAttr && !NewImportAttr->isInherited()) ||
7384 (NewExportAttr && !NewExportAttr->isInherited());
7390 bool AddsAttr = !(OldImportAttr || OldExportAttr) && HasNewAttr;
7392 if (AddsAttr && !IsSpecialization && !OldDecl->
isImplicit()) {
7394 bool JustWarn =
false;
7396 auto *VD = dyn_cast<VarDecl>(OldDecl);
7397 if (VD && !VD->getDescribedVarTemplate())
7399 auto *FD = dyn_cast<FunctionDecl>(OldDecl);
7411 unsigned DiagID = JustWarn ? diag::warn_attribute_dll_redeclaration
7412 : diag::err_attribute_dll_redeclaration;
7415 << (NewImportAttr ? (
const Attr *)NewImportAttr : NewExportAttr);
7428 bool IsInline =
false, IsStaticDataMember =
false, IsQualifiedFriend =
false;
7430 if (
const auto *VD = dyn_cast<VarDecl>(NewDecl)) {
7433 IsStaticDataMember = VD->isStaticDataMember();
7434 IsDefinition = VD->isThisDeclarationADefinition(S.
Context) !=
7436 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(NewDecl)) {
7437 IsInline = FD->isInlined();
7438 IsQualifiedFriend = FD->getQualifier() &&
7442 if (OldImportAttr && !HasNewAttr &&
7443 (!IsInline || (IsMicrosoftABI && IsTemplate)) && !IsStaticDataMember &&
7445 if (IsMicrosoftABI && IsDefinition) {
7446 if (IsSpecialization) {
7449 diag::err_attribute_dllimport_function_specialization_definition);
7450 S.
Diag(OldImportAttr->getLocation(), diag::note_attribute);
7451 NewDecl->
dropAttr<DLLImportAttr>();
7454 diag::warn_redeclaration_without_import_attribute)
7457 NewDecl->
dropAttr<DLLImportAttr>();
7458 NewDecl->
addAttr(DLLExportAttr::CreateImplicit(
7459 S.
Context, NewImportAttr->getRange()));
7461 }
else if (IsMicrosoftABI && IsSpecialization) {
7462 assert(!IsDefinition);
7466 diag::warn_redeclaration_without_attribute_prev_attribute_ignored)
7467 << NewDecl << OldImportAttr;
7469 S.
Diag(OldImportAttr->getLocation(), diag::note_previous_attribute);
7470 OldDecl->
dropAttr<DLLImportAttr>();
7471 NewDecl->
dropAttr<DLLImportAttr>();
7473 }
else if (IsInline && OldImportAttr && !IsMicrosoftABI) {
7476 OldDecl->
dropAttr<DLLImportAttr>();
7477 NewDecl->
dropAttr<DLLImportAttr>();
7479 diag::warn_dllimport_dropped_from_inline_function)
7480 << NewDecl << OldImportAttr;
7487 if (
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(NewDecl)) {
7489 !NewImportAttr && !NewExportAttr) {
7490 if (
const DLLExportAttr *ParentExportAttr =
7491 MD->getParent()->getAttr<DLLExportAttr>()) {
7492 DLLExportAttr *NewAttr = ParentExportAttr->clone(S.
Context);
7493 NewAttr->setInherited(
true);
7545 return D->isExternC();
7562 llvm_unreachable(
"Unexpected context");
7572 llvm_unreachable(
"Unexpected context");
7617 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
7618 return FD->isExternC();
7619 if (
const auto *VD = dyn_cast<VarDecl>(D))
7620 return VD->isExternC();
7622 llvm_unreachable(
"Unknown type of decl!");
7633 if (R->isImageType() || R->isPipeType()) {
7635 diag::err_opencl_type_can_only_be_used_as_function_parameter)
7647 if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
7649 diag::err_invalid_type_for_program_scope_var)
7659 QualType NR = R.getCanonicalType();
7678 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_half_declaration) << R;
7687 if (R->isEventT()) {
7695 if (R->isSamplerT()) {
7710 R.isConstQualified())) {
7711 Se.
Diag(NewVD->
getLocation(), diag::err_opencl_nonconst_global_sampler);
7721template <
typename AttrTy>
7724 if (
const auto *Attribute = TND->
getAttr<AttrTy>()) {
7725 AttrTy *Clone = Attribute->clone(S.
Context);
7726 Clone->setInherited(
true);
7754 if (
const auto *ConstDecl = RD->
getAttr<ReadOnlyPlacementAttr>()) {
7756 S.
Diag(ConstDecl->getLocation(), diag::note_enforce_read_only_placement);
7763 "NewD is not a function or variable");
7772 if (IdentName ==
nullptr)
7776 auto &Label = PendingName->second;
7782 Diag(Label.NameLoc, diag::warn_pragma_not_applied) <<
"export" << NewD;
7792 (VD->
getDeclContext()->getRedeclContext()->isTranslationUnit() ||
7807 if (
R->isIncompleteType())
7813 Diag(E->
getExprLoc(), diag::warn_asm_label_on_auto_decl) << Label;
7817 if (!
Context.getTargetInfo().isValidGCCRegisterName(Label) &&
7819 Diag(E->
getExprLoc(), diag::err_asm_unknown_register_name) << Label;
7829 const auto &TI =
Context.getTargetInfo();
7830 bool HasSizeMismatch;
7832 if (!TI.isValidGCCRegisterName(Label))
7833 Diag(E->
getExprLoc(), diag::err_asm_unknown_register_name) << Label;
7834 else if (!TI.validateGlobalRegisterVariable(Label,
Context.getTypeSize(R),
7836 Diag(E->
getExprLoc(), diag::err_asm_invalid_global_var_reg) << Label;
7837 else if (HasSizeMismatch)
7838 Diag(E->
getExprLoc(), diag::err_asm_register_size_mismatch) << Label;
7841 if (!
R->isIntegralType(
Context) && !
R->isPointerType()) {
7843 diag::err_asm_unsupported_register_type)
7858 bool IsPlaceholderVariable =
false;
7864 if (!Decomp.bindings().empty()) {
7865 II = Decomp.bindings()[0].Name;
7879 IsPlaceholderVariable =
true;
7887 if (IsPlaceholderVariable)
7901 bool IsLocalExternDecl = SC ==
SC_Extern &&
7920 : diag::warn_deprecated_register)
7943 const AutoType *AT = TL.getTypePtr();
7947 bool IsMemberSpecialization =
false;
7948 bool IsVariableTemplateSpecialization =
false;
7950 bool IsVariableTemplate =
false;
7958 if (R->getContainedDeducedType())
7979 false, IsMemberSpecialization,
Invalid);
7981 if (TemplateParams) {
7988 if (!TemplateParams->
size() &&
7993 diag::err_template_variable_noparams)
7997 TemplateParams =
nullptr;
8005 IsVariableTemplateSpecialization =
true;
8009 IsVariableTemplate =
true;
8017 if (!TemplateParamLists.empty() && IsMemberSpecialization &&
8022 "should have a 'template<>' for this decl");
8025 bool IsExplicitSpecialization =
8036 (IsExplicitSpecialization || IsMemberSpecialization)) {
8038 diag::ext_explicit_specialization_storage_class)
8044 if (
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
8050 if (Ctxt->isFunctionOrMethod()) {
8051 FunctionOrMethod = Ctxt;
8054 const CXXRecordDecl *ParentDecl = dyn_cast<CXXRecordDecl>(Ctxt);
8056 AnonStruct = ParentDecl;
8060 if (FunctionOrMethod) {
8064 diag::err_static_data_member_not_allowed_in_local_class)
8065 << Name << RD->getDeclName() << RD->getTagKind();
8067 }
else if (AnonStruct) {
8072 diag::err_static_data_member_not_allowed_in_anon_struct)
8075 }
else if (RD->isUnion()) {
8079 diag_compat::static_data_member_in_union)
8097 diag::err_static_out_of_line)
8110 diag::err_storage_class_for_static_member)
8115 llvm_unreachable(
"C storage class in c++!");
8119 if (IsVariableTemplateSpecialization) {
8121 TemplateParamLists.size() > 0
8122 ? TemplateParamLists[0]->getTemplateLoc()
8125 S, D, TInfo,
Previous, TemplateKWLoc, TemplateParams, SC,
8140 if (IsVariableTemplate) {
8143 TemplateParams, NewVD);
8149 if (R->getContainedDeducedType())
8164 unsigned VDTemplateParamLists =
8165 (TemplateParams && !IsExplicitSpecialization) ? 1 : 0;
8166 if (TemplateParamLists.size() > VDTemplateParamLists)
8168 Context, TemplateParamLists.drop_back(VDTemplateParamLists));
8175 }
else if (
CurContext->isFunctionOrMethod()) {
8178 diag::err_inline_declaration_block_scope) << Name
8183 : diag::compat_pre_cxx17_inline_variable);
8194 if (IsLocalExternDecl) {
8197 B->setLocalExternDecl();
8202 bool EmitTLSUnsupportedError =
false;
8215 diag::err_thread_non_global)
8217 else if (!
Context.getTargetInfo().isTLSSupported()) {
8222 EmitTLSUnsupportedError =
true;
8229 diag::err_thread_unsupported);
8240 diag::err_constexpr_wrong_decl_kind)
8241 <<
static_cast<int>(D.
getDeclSpec().getConstexprSpecifier());
8251 Context.getTargetInfo().getCXXABI().isMicrosoft()))
8258 diag::err_constinit_local_variable);
8262 ConstInitAttr::Keyword_constinit));
8280 diag::warn_static_local_in_extern_inline);
8286 if (IsVariableTemplateSpecialization)
8291 else if (IsMemberSpecialization)
8306 B->setModulePrivate();
8316 diag::err_opencl_unknown_type_specifier)
8326 if (
const auto *ATy = dyn_cast<ArrayType>(NewVD->
getType())) {
8327 if (ATy && ATy->getElementType().isWebAssemblyReferenceType() &&
8345 llvm::MapVector<IdentifierInfo *, AsmLabelAttr *>::iterator I =
8372 if (R->isFunctionPointerType())
8377 if (EmitTLSUnsupportedError &&
8380 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(NewVD))))
8382 diag::err_thread_unsupported);
8384 if (EmitTLSUnsupportedError &&
8391 (NewVD->
hasAttr<CUDASharedAttr>() ||
8392 NewVD->
hasAttr<CUDAConstantAttr>())) {
8400 assert(!NewVD->
hasAttr<DLLImportAttr>() ||
8401 NewVD->
getAttr<DLLImportAttr>()->isInherited() ||
8406 if (
getLangOpts().ObjCAutoRefCount &&
ObjC().inferObjCARCLifetime(NewVD))
8413 CheckAsmLabel(S, D.
getAsmLabel(), SC, TInfo, NewVD);
8425 IsMemberSpecialization ||
8426 IsVariableTemplateSpecialization);
8440 if (IsMemberSpecialization && !IsVariableTemplate &&
8441 !IsVariableTemplateSpecialization && !NewVD->
isInvalidDecl() &&
8458 !IsVariableTemplateSpecialization) {
8469 if (NewTemplate && IsMemberSpecialization) {
8481 if (!IsPlaceholderVariable)
8512 if (IsMemberSpecialization) {
8517 ->setMemberSpecialization();
8536 Decl *ManglingContextDecl;
8537 std::tie(MCtx, ManglingContextDecl) =
8629 return !Diags.
isIgnored(diag::warn_decl_shadow, R.getNameLoc());
8641 NamedDecl *ShadowedDecl = R.getFoundDecl();
8655 NamedDecl *ShadowedDecl = R.getFoundDecl();
8664 NamedDecl *ShadowedDecl = R.getFoundDecl();
8673 if (
FieldDecl *FD = dyn_cast<FieldDecl>(ShadowedDecl)) {
8675 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FnDC)) {
8678 if (MD->isStatic() || MD->isExplicitObjectMemberFunction())
8690 if (
const auto PVD = dyn_cast<ParmVarDecl>(D)) {
8693 ShadowingDecls.insert({PVD->getCanonicalDecl(), FD});
8698 if (
VarDecl *shadowedVar = dyn_cast<VarDecl>(ShadowedDecl))
8699 if (shadowedVar->isExternC()) {
8702 for (
auto *I : shadowedVar->redecls())
8703 if (I->isFileVarDecl()) {
8711 unsigned WarningDiag = diag::warn_decl_shadow;
8714 if (
const auto *RD = dyn_cast<CXXRecordDecl>(NewDC->
getParent())) {
8720 if (RD->getLambdaCaptureDefault() ==
LCD_None) {
8726 WarningDiag = diag::warn_decl_shadow_uncaptured_local;
8732 ->ShadowingDecls.push_back({D, VD});
8743 ->ShadowingDecls.push_back({D, ShadowedDecl});
8749 bool HasLocalStorage =
false;
8750 if (
const auto *VD = dyn_cast<VarDecl>(ShadowedDecl))
8751 HasLocalStorage = VD->hasLocalStorage();
8752 else if (
const auto *BD = dyn_cast<BindingDecl>(ShadowedDecl))
8756 if (HasLocalStorage) {
8761 ParentDC && !ParentDC->
Equals(OldDC);
8802 Diag(R.getNameLoc(), WarningDiag) << Name << Kind << OldDC;
8804 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8811 const NamedDecl *ShadowedDecl = Shadow.ShadowedDecl;
8817 Diag(Shadow.VD->getLocation(),
8818 CaptureLoc.
isInvalid() ? diag::warn_decl_shadow_uncaptured_local
8819 : diag::warn_decl_shadow)
8820 << Shadow.VD->getDeclName()
8823 Diag(CaptureLoc, diag::note_var_explicitly_captured_here)
8824 << Shadow.VD->getDeclName() << 0;
8827 Diag(Shadow.VD->getLocation(),
8829 : diag::warn_decl_shadow_uncaptured_local)
8830 << Shadow.VD->getDeclName()
8856 auto *DRE = dyn_cast<DeclRefExpr>(E);
8860 auto I = ShadowingDecls.find(D);
8861 if (I == ShadowingDecls.end())
8863 const NamedDecl *ShadowedDecl = I->second;
8865 Diag(Loc, diag::warn_modifying_shadowing_decl) << D << OldDC;
8870 ShadowingDecls.erase(I);
8878 assert(S.
getLangOpts().CPlusPlus &&
"only C++ has extern \"C\"");
8937 assert(Prev &&
"should have found a previous declaration to diagnose");
8939 Prev = FD->getFirstDecl();
8943 S.
Diag(ND->getLocation(), diag::err_extern_c_global_conflict)
8965 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit()) {
8977 if (ND->getDeclContext()->getRedeclContext()->isTranslationUnit())
8997 SemaRef.
Diag(VarLoc, diag::err_c23_constexpr_invalid_type) <<
T;
9007 SemaRef.
Diag(VarLoc, diag::err_c23_constexpr_invalid_type) <<
T;
9015 return CheckC23ConstexprVarType(SemaRef, VarLoc, F->getType());
9035 if (
T->isUndeducedType())
9041 if (
T->isObjCObjectType()) {
9044 T =
Context.getObjCObjectPointerType(
T);
9053 Diag(NewVD->
getLocation(), diag::err_sycl_address_space_qualified_object)
9087 if (NewVD->
hasAttr<BlocksAttr>()) {
9092 if (
T->isBlockPointerType()) {
9095 if (!
T.isConstQualified()) {
9096 Diag(NewVD->
getLocation(), diag::err_opencl_invalid_block_declaration)
9102 Diag(NewVD->
getLocation(), diag::err_opencl_extern_block_declaration);
9111 if (!
T->isSamplerT() && !
T->isDependentType() &&
9118 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
9119 <<
Scope <<
"global or constant";
9121 Diag(NewVD->
getLocation(), diag::err_opencl_global_invalid_addr_space)
9122 <<
Scope <<
"constant";
9136 bool AllowFunctionScopeLocalVariables =
9139 "__cl_clang_function_scope_local_variables",
getLangOpts());
9140 if (AllowFunctionScopeLocalVariables) {
9147 if (FD && !FD->
hasAttr<DeviceKernelAttr>()) {
9159 if (FD && FD->
hasAttr<DeviceKernelAttr>()) {
9184 && !NewVD->
hasAttr<BlocksAttr>()) {
9195 if (
T->isWebAssemblyTableType()) {
9206 const auto *ATy = dyn_cast<ConstantArrayType>(
T.getTypePtr());
9207 if (!ATy || ATy->getZExtSize() != 0) {
9209 diag::err_typecheck_wasm_table_must_have_zero_length);
9219 (FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>())) {
9222 ArrayT && ArrayT->isZeroSize()) {
9228 bool isVM =
T->isVariablyModifiedType();
9229 if (isVM || NewVD->
hasAttr<CleanupAttr>() ||
9235 bool SizeIsNegative;
9236 llvm::APSInt Oversized;
9241 FixedT = FixedTInfo->
getType();
9242 else if (FixedTInfo) {
9248 if ((!FixedTInfo || FixedT.
isNull()) &&
T->isVariableArrayType()) {
9281 if (
T->isVoidType()) {
9293 !
T.isWebAssemblyReferenceType() && !
T->isHLSLSpecificType()) {
9299 if (isVM && NewVD->
hasAttr<BlocksAttr>()) {
9301 << diag::NotAllowedBlockVarReason::VariablyModifiedType;
9313 !
T->isDependentType() &&
9315 diag::err_constexpr_var_non_literal)) {
9321 if (
Context.getTargetInfo().getTriple().isPPC64() &&
9331 llvm::StringMap<bool> CallerFeatureMap;
9332 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
9334 CallerFeatureMap)) {
9342 llvm::StringMap<bool> CallerFeatureMap;
9343 Context.getFunctionFeatureMap(CallerFeatureMap, FD);
9348 if (
Context.getTargetInfo().hasAMDGPUTypes()) {
9355 if (
T.hasAddressSpace() &&
9389 CXXRecordDecl *BaseRecord = Specifier->getType()->getAsCXXRecordDecl();
9394 Name =
Context.DeclarationNames.getCXXDestructorName(
9395 Context.getCanonicalTagType(BaseRecord));
9400 dyn_cast<CXXMethodDecl>(BaseND->getCanonicalDecl());
9407 if (Overridden.insert(BaseMD).second) {
9424 return !Overridden.empty();
9430 struct ActOnFDArgs {
9444 DifferentNameValidatorCCC(ASTContext &Context, FunctionDecl *TypoFD,
9445 CXXRecordDecl *Parent)
9446 : Context(Context), OriginalFD(TypoFD),
9449 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
9453 SmallVector<unsigned, 1> MismatchedParams;
9455 CDeclEnd = candidate.
end();
9456 CDecl != CDeclEnd; ++CDecl) {
9457 FunctionDecl *FD = dyn_cast<FunctionDecl>(*CDecl);
9461 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
9462 CXXRecordDecl *Parent = MD->getParent();
9465 }
else if (!ExpectedParent) {
9474 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
9475 return std::make_unique<DifferentNameValidatorCCC>(*
this);
9479 ASTContext &Context;
9480 FunctionDecl *OriginalFD;
9481 CXXRecordDecl *ExpectedParent;
9501 ActOnFDArgs &ExtraArgs,
bool IsLocalFriend,
Scope *S) {
9509 IsLocalFriend ? diag::err_no_matching_local_friend :
9511 diag::err_member_decl_does_not_match;
9523 "Cannot have an ambiguity in previous-declaration lookup");
9525 DifferentNameValidatorCCC CCC(SemaRef.
Context, NewFD,
9527 if (!Prev.
empty()) {
9536 MismatchedParams.empty() ? 0 : MismatchedParams.front() + 1;
9537 NearMatches.push_back(std::make_pair(FD, ParamNum));
9545 IsLocalFriend ?
nullptr : NewDC))) {
9552 CDeclEnd = Correction.
end();
9553 CDecl != CDeclEnd; ++CDecl) {
9573 ExtraArgs.S, ExtraArgs.D,
9576 ExtraArgs.AddToScope);
9584 Decl *Canonical =
Result->getCanonicalDecl();
9587 if ((*I)->getCanonicalDecl() == Canonical)
9594 SemaRef.
PDiag(IsLocalFriend
9595 ? diag::err_no_matching_local_friend_suggest
9596 : diag::err_member_decl_does_not_match_suggest)
9597 << Name << NewDC << IsDefinition);
9610 << Name << NewDC << IsDefinition << NewFD->
getLocation();
9613 if (NewMD && DiagMsg == diag::err_member_decl_does_not_match) {
9619 bool NewFDisConst = NewMD && NewMD->
isConst();
9622 NearMatch = NearMatches.begin(), NearMatchEnd = NearMatches.end();
9623 NearMatch != NearMatchEnd; ++NearMatch) {
9626 bool FDisConst = MD && MD->
isConst();
9627 bool IsMember = MD || !IsLocalFriend;
9630 if (
unsigned Idx = NearMatch->second) {
9634 SemaRef.
Diag(Loc, IsMember ? diag::note_member_def_close_param_match
9635 : diag::note_local_decl_close_param_match)
9638 }
else if (FDisConst != NewFDisConst) {
9640 diag::note_member_def_close_const_match)
9645 else if (FTI.hasMethodTypeQualifiers() &&
9646 FTI.getConstQualifierLoc().isValid())
9650 IsMember ? diag::note_member_def_close_match
9651 : diag::note_local_decl_close_match);
9659 default: llvm_unreachable(
"Unknown storage class!");
9664 diag::err_typecheck_sclass_func);
9681 diag::err_static_block_func);
9697 bool &IsVirtualOkay) {
9711 diag::err_c23_constexpr_not_variable);
9714 diag::err_constexpr_wrong_decl_kind)
9715 <<
static_cast<int>(ConstexprKind);
9736 (!R->getAsAdjusted<
FunctionType>() && R->isFunctionProtoType());
9739 "Strict prototypes are required");
9760 "Constructors can only be declared in a member context");
9766 isInline,
false, ConstexprKind,
9777 false, ConstexprKind,
9778 TrailingRequiresClause);
9781 if (
Record->isBeingDefined())
9790 IsVirtualOkay =
true;
9802 true, ConstexprKind, TrailingRequiresClause);
9808 diag::err_conv_function_not_member);
9816 IsVirtualOkay =
true;
9821 TrailingRequiresClause);
9848 IsVirtualOkay = !Ret->isStatic();
9862 true , ConstexprKind, TrailingRequiresClause);
9879 StringRef SizeTypeNames[] = {
"size_t",
"intptr_t",
"uintptr_t",
"ptrdiff_t"};
9887 if (Names.end() !=
Match)
9892 }
while (DesugaredTy != Ty);
9931 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts())) {
9933 bool IsStandardLayoutType =
true;
9939 if (!CXXRec->hasDefinition())
9940 CXXRec = CXXRec->getTemplateInstantiationPattern();
9941 if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
9942 IsStandardLayoutType =
false;
9945 !IsStandardLayoutType)
9993 "__cl_clang_non_portable_kernel_param_types", S.
getLangOpts()) &&
10007 llvm::SmallPtrSetImpl<const Type *> &ValidTypes) {
10020 S.
Diag(Param->getLocation(), diag::err_opencl_ptrptr_kernel_param);
10029 S.
Diag(Param->getLocation(), diag::err_kernel_arg_address_space);
10046 S.
Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
10054 S.
Diag(Loc, diag::note_entity_declared_at) << PT;
10055 PT = Typedef->desugar();
10077 HistoryStack.push_back(
nullptr);
10082 VisitStack.push_back(PD);
10083 assert(VisitStack.back() &&
"First decl null?");
10086 const Decl *
Next = VisitStack.pop_back_val();
10088 assert(!HistoryStack.empty());
10090 if (
const FieldDecl *Hist = HistoryStack.pop_back_val())
10091 ValidTypes.insert(Hist->getType().getTypePtr());
10100 HistoryStack.push_back(Field);
10102 QualType FieldTy = Field->getType();
10106 "Unexpected type.");
10115 VisitStack.push_back(
nullptr);
10117 for (
const auto *FD : RD->
fields()) {
10128 VisitStack.push_back(FD);
10139 S.
Diag(Param->getLocation(),
10140 diag::err_record_with_pointers_kernel_param)
10144 S.
Diag(Param->getLocation(), diag::err_bad_kernel_param_type) << PT;
10147 S.
Diag(PD->getLocation(), diag::note_within_field_of_type)
10148 << PD->getDeclName();
10153 I = HistoryStack.begin() + 1,
10154 E = HistoryStack.end();
10167 }
while (!VisitStack.empty());
10184 (LangOpts.CPlusPlus &&
10194 unsigned BuiltinID) {
10195 switch (BuiltinID) {
10196 case Builtin::BI__GetExceptionInfo:
10200 case Builtin::BIaddressof:
10201 case Builtin::BI__addressof:
10202 case Builtin::BIforward:
10203 case Builtin::BIforward_like:
10204 case Builtin::BImove:
10205 case Builtin::BImove_if_noexcept:
10206 case Builtin::BIas_const: {
10211 return FPT->
getNumParams() == 1 && !FPT->isVariadic();
10225 switch (FT->getCallConv()) {
10226#define CC_VLS_CASE(ABI_VLEN) \
10227 case CC_RISCVVLSCall_##ABI_VLEN: \
10228 Tag = "riscv_vls_cc_" #ABI_VLEN; \
10248 AbiTagAttr *Old = Existing.empty() ?
nullptr : Existing.front();
10252 llvm::append_range(Tags, Old->tags());
10253 if (llvm::is_contained(Tags, Tag))
10255 Tags.push_back(Tag);
10257 AbiTagAttr *Merged =
10258 Old ? AbiTagAttr::Create(
Context, Tags.data(), Tags.size(), *Old)
10259 : AbiTagAttr::CreateImplicit(
Context, Tags.data(), Tags.size(),
10263 for (
size_t I = 1, E = Existing.size(); I < E; ++I)
10271 bool &AddToScope) {
10274 assert(R->isFunctionType());
10279 llvm::append_range(TemplateParamLists, TemplateParamListsRef);
10281 if (!TemplateParamLists.empty() && !TemplateParamLists.back()->empty() &&
10282 Invented->getDepth() == TemplateParamLists.back()->getDepth())
10283 TemplateParamLists.back() = Invented;
10285 TemplateParamLists.push_back(Invented);
10295 diag::err_invalid_thread)
10303 bool isFriend =
false;
10305 bool isMemberSpecialization =
false;
10306 bool isFunctionTemplateSpecialization =
false;
10308 bool HasExplicitTemplateArgs =
false;
10311 bool isVirtualOkay =
false;
10318 if (!NewFD)
return nullptr;
10328 if (IsLocalExternDecl)
10338 bool ImplicitInlineCXX20 = !
getLangOpts().CPlusPlusModules ||
10366 if (isVirtual && Parent->isUnion()) {
10370 if ((Parent->isClass() || Parent->isStruct()) &&
10371 Parent->hasAttr<SYCLSpecialClassAttr>() &&
10374 if (
auto *Def = Parent->getDefinition())
10375 Def->setInitMethod(
true);
10380 isMemberSpecialization =
false;
10381 isFunctionTemplateSpecialization =
false;
10396 isMemberSpecialization,
Invalid);
10397 if (TemplateParams) {
10402 if (TemplateParams->
size() > 0) {
10410 }
else if (TemplateId) {
10427 Name, TemplateParams,
10433 if (TemplateParamLists.size() > 1) {
10440 isFunctionTemplateSpecialization =
true;
10442 if (TemplateParamLists.size() > 0)
10462 << Name << RemoveRange
10468 HasExplicitTemplateArgs =
true;
10475 if (!TemplateParamLists.empty() && isMemberSpecialization &&
10481 if (TemplateParamLists.size() > 0)
10486 if (isFriend && TemplateId)
10487 isFunctionTemplateSpecialization =
true;
10493 if (isFunctionTemplateSpecialization && TemplateId) {
10494 HasExplicitTemplateArgs =
true;
10525 if (!isVirtualOkay) {
10527 diag::err_virtual_non_function);
10531 diag::err_virtual_out_of_class)
10537 diag::err_virtual_member_function_template)
10556 diag::err_inline_declaration_block_scope) << Name
10570 diag::err_explicit_out_of_class)
10577 diag::err_explicit_non_ctor_or_conv_function)
10595 <<
static_cast<int>(ConstexprKind);
10606 diag::err_invalid_consteval_decl_kind)
10614 if (isFunctionTemplateSpecialization) {
10617 Diag(ModulePrivateLoc, diag::err_module_private_specialization)
10663 if (!isFriend && SC !=
SC_None) {
10671 if (isFunctionTemplateSpecialization || isMemberSpecialization) {
10673 diag::ext_explicit_specialization_storage_class)
10680 "Out-of-line member function should be a CXXMethodDecl");
10697 ? diag::ext_static_out_of_line
10698 : diag::err_static_out_of_line)
10723 PendingInlineFuncDecls.insert(NewFD);
10730 isMemberSpecialization ||
10731 isFunctionTemplateSpecialization);
10742 llvm::MapVector<IdentifierInfo *, AsmLabelAttr *>::iterator I =
10769 for (
unsigned i = 0, e = FTI.
NumParams; i != e; ++i) {
10771 assert(Param->getDeclContext() != NewFD &&
"Was set before ?");
10772 Param->setDeclContext(NewFD);
10773 Params.push_back(Param);
10775 if (Param->isInvalidDecl())
10788 auto *TD = dyn_cast<TagDecl>(NonParmDecl);
10793 if (
auto *ECD = dyn_cast<EnumConstantDecl>(NonParmDecl))
10798 DeclContext *TagDC = TD->getLexicalDeclContext();
10802 TD->setDeclContext(NewFD);
10810 if (TagDC != PrototypeTagContext)
10811 TD->setLexicalDeclContext(TagDC);
10825 for (
const auto &AI : FT->param_types()) {
10828 Param->setScopeInfo(0, Params.size());
10829 Params.push_back(Param);
10832 assert(R->isFunctionNoProtoType() && NewFD->
getNumParams() == 0 &&
10833 "Should not need args for typedef of non-prototype fn");
10837 NewFD->setParams(Params);
10862 !NewFD->
hasAttr<SectionAttr>())
10863 NewFD->
addAttr(PragmaClangTextSectionAttr::CreateImplicit(
10869 !NewFD->
hasAttr<SectionAttr>()) {
10870 NewFD->
addAttr(SectionAttr::CreateImplicit(
10872 CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate));
10883 !NewFD->
hasAttr<StrictGuardStackCheckAttr>())
10884 NewFD->
addAttr(StrictGuardStackCheckAttr::CreateImplicit(
10889 if (!NewFD->
hasAttr<CodeSegAttr>()) {
10899 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
10900 if (
Context.getTargetInfo().getTriple().isAArch64() && NewTVA &&
10901 !NewTVA->isDefaultVersion() &&
10902 !
Context.getTargetInfo().hasFeature(
"fmv")) {
10904 AddToScope =
false;
10916 Diag(NewFD->
getLocation(), diag::err_return_value_with_address_space);
10931 isMemberSpecialization,
10938 "previous declaration set still overloaded");
10950 CC ==
CC_X86StdCall ? diag::warn_cconv_knr : diag::err_cconv_knr;
10973 diag::ext_operator_new_delete_declared_inline)
11000 if (isFunctionTemplateSpecialization || isMemberSpecialization) {
11012 Diag(TRC->getBeginLoc(), diag::err_non_temp_spec_requires_clause)
11020 diag::err_non_temp_friend_decl_with_requires_clause_must_be_def);
11024 Diag(TRC->getBeginLoc(),
11025 diag::err_constrained_non_templated_function);
11042 if (isFunctionTemplateSpecialization) {
11043 bool isDependentSpecialization =
false;
11049 isDependentSpecialization =
11052 (HasExplicitTemplateArgs &&
11053 TemplateSpecializationType::
11054 anyInstantiationDependentTemplateArguments(
11056 assert((!isDependentSpecialization ||
11057 (HasExplicitTemplateArgs == isDependentSpecialization)) &&
11058 "dependent friend function specialization without template "
11064 isDependentSpecialization =
11069 HasExplicitTemplateArgs ? &TemplateArgs :
nullptr;
11070 if (isDependentSpecialization) {
11077 NewFD, ExplicitTemplateArgs,
Previous))
11098 isMemberSpecialization,
11107 "previous declaration set still overloaded");
11148 struct ActOnFDArgs ExtraArgs = { S, D, TemplateParamLists,
11194 *
this,
Previous, NewFD, ExtraArgs,
false,
nullptr)) {
11195 AddToScope = ExtraArgs.AddToScope;
11204 *
this,
Previous, NewFD, ExtraArgs,
true, S)) {
11205 AddToScope = ExtraArgs.AddToScope;
11211 !isFriend && !isFunctionTemplateSpecialization &&
11212 !isMemberSpecialization) {
11230 if (NewFD->
hasAttr<HLSLShaderAttr>())
11234 if (
const NoInlineAttr *NoInline = NewFD->
getAttr<NoInlineAttr>()) {
11236 QualType ParamTy = PVD->getType().getNonReferenceType();
11244 Diag(PVD->getLocation(),
11245 diag::err_hlsl_resource_param_in_noinline_function)
11247 Diag(NoInline->getLocation(), diag::note_attribute);
11257 if (
unsigned BuiltinID = II->getBuiltinID()) {
11258 bool InStdNamespace =
Context.BuiltinInfo.isInStdNamespace(BuiltinID);
11259 if (!InStdNamespace &&
11264 if (
Context.BuiltinInfo.allowTypeMismatch(BuiltinID)) {
11265 NewFD->
addAttr(BuiltinAttr::CreateImplicit(
Context, BuiltinID));
11272 Context.hasSameFunctionTypeIgnoringExceptionSpec(
11274 NewFD->
addAttr(BuiltinAttr::CreateImplicit(
Context, BuiltinID));
11279 NewFD->
addAttr(BuiltinAttr::CreateImplicit(
Context, BuiltinID));
11295 if (NewFD->
hasAttr<OverloadableAttr>() &&
11298 diag::err_attribute_overloadable_no_prototype)
11300 NewFD->
dropAttr<OverloadableAttr>();
11333 isMemberSpecialization ||
11334 isFunctionTemplateSpecialization,
11345 Context.setcudaConfigureCallDecl(NewFD);
11347 if (II->isStr(
CUDA().getGetParameterBufferFuncName()) &&
11353 Context.setcudaGetParameterBufferDecl(NewFD);
11355 if (II->isStr(
CUDA().getLaunchDeviceFuncName()) &&
11361 Context.setcudaLaunchDeviceDecl(NewFD);
11412 diag::err_friend_decl_with_enclosing_temp_constraint_must_be_def);
11432 if (
getLangOpts().getOpenCLCompatibleVersion() >= 200) {
11434 QualType ElemTy = PipeTy->getElementType();
11436 Diag(Param->getTypeSpecStartLoc(), diag::err_reference_pipe_type);
11442 if (
Context.getTargetInfo().getTriple().isWasm()) {
11444 Diag(Param->getTypeSpecStartLoc(),
11445 diag::err_wasm_table_as_function_parameter);
11453 if (
const auto *
attr = NewFD->
getAttr<AvailabilityAttr>()) {
11454 if (NewFD->
hasAttr<ConstructorAttr>()) {
11455 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
11457 NewFD->
dropAttr<AvailabilityAttr>();
11459 if (NewFD->
hasAttr<DestructorAttr>()) {
11460 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
11462 NewFD->
dropAttr<AvailabilityAttr>();
11473 if (
const auto *NBA = NewFD->
getAttr<NoBuiltinAttr>())
11477 Diag(NBA->getLocation(),
11478 diag::err_attribute_no_builtin_on_defaulted_deleted_function)
11479 << NBA->getSpelling();
11482 Diag(NBA->getLocation(), diag::err_attribute_no_builtin_on_non_definition)
11483 << NBA->getSpelling();
11492 if (
Context.getTargetInfo().allowDebugInfoForExternalRef() &&
11516 const auto *Method = dyn_cast<CXXMethodDecl>(FD);
11520 if (
const auto *SAttr = Parent->
getAttr<CodeSegAttr>()) {
11531 while ((Parent = dyn_cast<CXXRecordDecl>(Parent->
getParent()))) {
11532 if (
const auto *SAttr = Parent->
getAttr<CodeSegAttr>()) {
11542 bool IsDefinition) {
11545 if (!FD->
hasAttr<SectionAttr>() && IsDefinition &&
11547 return SectionAttr::CreateImplicit(
11549 CodeSegStack.CurrentPragmaLocation, SectionAttr::Declspec_allocate);
11597 auto *VD = dyn_cast<ValueDecl>(D);
11598 auto *PrevVD = dyn_cast<ValueDecl>(PrevDecl);
11599 return !VD || !PrevVD ||
11601 PrevVD->getType());
11609 const auto *TA = FD->
getAttr<TargetAttr>();
11610 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
11612 assert((TA || TVA) &&
"Expecting target or target_version attribute");
11625 for (
const auto &Feat : ParseInfo.
Features) {
11626 auto BareFeat = StringRef{Feat}.substr(1);
11627 if (Feat[0] ==
'-') {
11629 <<
Feature << (
"no-" + BareFeat);
11649 for (
auto &Feat : ParseInfo.
Features)
11650 Feats.push_back(StringRef{Feat}.substr(1));
11653 TVA->getFeatures(Feats);
11655 for (
const auto &Feat : Feats) {
11675 case attr::ArmLocallyStreaming:
11680 case attr::NonNull:
11681 case attr::NoThrow:
11690 const auto Diagnose = [FD, CausedFD, MVKind](
Sema &S,
const Attr *A) {
11691 S.
Diag(FD->
getLocation(), diag::err_multiversion_disallowed_other_attr)
11692 <<
static_cast<unsigned>(MVKind) << A;
11694 S.
Diag(CausedFD->
getLocation(), diag::note_multiversioning_caused_here);
11699 switch (A->getKind()) {
11700 case attr::CPUDispatch:
11701 case attr::CPUSpecific:
11704 return Diagnose(S, A);
11708 return Diagnose(S, A);
11710 case attr::TargetVersion:
11713 return Diagnose(S, A);
11715 case attr::TargetClones:
11718 return Diagnose(S, A);
11722 return Diagnose(S, A);
11735 bool ConstexprSupported,
bool CLinkageMayDiffer) {
11736 enum DoesntSupport {
11743 DefaultedFuncs = 6,
11744 ConstexprFuncs = 7,
11745 ConstevalFuncs = 8,
11757 if (NoProtoDiagID.
getDiagID() != 0 && OldFD &&
11760 Diag(NoteCausedDiagIDAt.first, NoteCausedDiagIDAt.second);
11768 if (!TemplatesSupported &&
11770 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11773 if (
const auto *NewCXXFD = dyn_cast<CXXMethodDecl>(NewFD)) {
11774 if (NewCXXFD->isVirtual())
11775 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11779 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11783 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11788 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11792 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11796 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11797 << (NewFD->
isConsteval() ? ConstevalFuncs : ConstexprFuncs);
11801 QualType NewReturnType = NewType->getReturnType();
11804 return Diag(NoSupportDiagIDAt.first, NoSupportDiagIDAt.second)
11817 bool ArmStreamingCCMismatched =
false;
11818 if (OldFPT && NewFPT) {
11825 ArmStreamingCCMismatched =
true;
11828 if (OldTypeInfo.
getCC() != NewTypeInfo.
getCC() || ArmStreamingCCMismatched)
11831 QualType OldReturnType = OldType->getReturnType();
11833 if (OldReturnType != NewReturnType)
11834 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ReturnType;
11837 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << ConstexprSpec;
11840 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) << InlineSpec;
11843 return Diag(DiffDiagIDAt.first, DiffDiagIDAt.second) <<
Linkage;
11866 bool IsCPUSpecificCPUDispatchMVKind =
11870 if (CausesMV && OldFD &&
11878 if (OldFD && CausesMV && OldFD->
isUsed(
false)) {
11885 OldFD, NewFD, S.
PDiag(diag::err_multiversion_noproto),
11887 S.
PDiag(diag::note_multiversioning_caused_here)),
11889 S.
PDiag(diag::err_multiversion_doesnt_support)
11890 <<
static_cast<unsigned>(MVKind)),
11892 S.
PDiag(diag::err_multiversion_diff)),
11894 !IsCPUSpecificCPUDispatchMVKind,
11907 "Function lacks multiversion attribute");
11908 const auto *TA = FD->
getAttr<TargetAttr>();
11909 const auto *TVA = FD->
getAttr<TargetVersionAttr>();
11912 if (TA && !TA->isDefaultVersion())
11949 To->
addAttr(TargetVersionAttr::CreateImplicit(
11960 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
11961 const auto *OldTA = OldFD->
getAttr<TargetAttr>();
11962 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
11963 const auto *OldTVA = OldFD->
getAttr<TargetVersionAttr>();
11965 assert((NewTA || NewTVA) &&
"Excpecting target or target_version attribute");
11974 if (NewTA && !NewTA->isDefaultVersion() &&
11975 (!OldTA || OldTA->getFeaturesStr() == NewTA->getFeaturesStr()))
11992 if ((NewTA && NewTA->isDefaultVersion() && !OldTA) ||
11993 (NewTVA && NewTVA->isDefaultVersion() && !OldTVA)) {
12002 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
12010 OldTA->getFeaturesStr());
12014 NewTA->getFeaturesStr());
12017 if (OldParsed == NewParsed) {
12025 for (
const auto *FD : OldFD->
redecls()) {
12026 const auto *CurTA = FD->
getAttr<TargetAttr>();
12027 const auto *CurTVA = FD->
getAttr<TargetVersionAttr>();
12031 ((NewTA && (!CurTA || CurTA->isInherited())) ||
12032 (NewTVA && (!CurTVA || CurTVA->isInherited())))) {
12034 << (NewTA ? 0 : 2);
12035 S.
Diag(NewFD->
getLocation(), diag::note_multiversioning_caused_here);
12082 const CPUDispatchAttr *NewCPUDisp,
const CPUSpecificAttr *NewCPUSpec,
12098 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
12099 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
12106 NewTA->getFeaturesStr());
12111 NewTVA->getFeatures(NewFeats);
12112 llvm::sort(NewFeats);
12115 bool UseMemberUsingDeclRules =
12118 bool MayNeedOverloadableChecks =
12127 if (MayNeedOverloadableChecks &&
12128 S.
IsOverload(NewFD, CurFD, UseMemberUsingDeclRules))
12131 switch (NewMVKind) {
12134 "Only target_clones can be omitted in subsequent declarations");
12137 const auto *CurTA = CurFD->
getAttr<TargetAttr>();
12138 if (CurTA->getFeaturesStr() == NewTA->getFeaturesStr()) {
12147 CurTA->getFeaturesStr());
12149 if (CurParsed == NewParsed) {
12158 if (
const auto *CurTVA = CurFD->
getAttr<TargetVersionAttr>()) {
12159 if (CurTVA->getName() == NewTVA->getName()) {
12166 CurTVA->getFeatures(CurFeats);
12167 llvm::sort(CurFeats);
12169 if (CurFeats == NewFeats) {
12175 }
else if (
const auto *CurClones = CurFD->
getAttr<TargetClonesAttr>()) {
12177 if (NewFeats.empty())
12180 for (
unsigned I = 0; I < CurClones->featuresStrs_size(); ++I) {
12182 CurClones->getFeatures(CurFeats, I);
12183 llvm::sort(CurFeats);
12185 if (CurFeats == NewFeats) {
12196 assert(NewClones &&
"MultiVersionKind does not match attribute type");
12197 if (
const auto *CurClones = CurFD->
getAttr<TargetClonesAttr>()) {
12198 if (CurClones->featuresStrs_size() != NewClones->featuresStrs_size() ||
12199 !std::equal(CurClones->featuresStrs_begin(),
12200 CurClones->featuresStrs_end(),
12201 NewClones->featuresStrs_begin())) {
12207 }
else if (
const auto *CurTVA = CurFD->
getAttr<TargetVersionAttr>()) {
12209 CurTVA->getFeatures(CurFeats);
12210 llvm::sort(CurFeats);
12213 if (CurFeats.empty())
12216 for (
unsigned I = 0; I < NewClones->featuresStrs_size(); ++I) {
12218 NewClones->getFeatures(NewFeats, I);
12219 llvm::sort(NewFeats);
12221 if (CurFeats == NewFeats) {
12237 const auto *CurCPUSpec = CurFD->
getAttr<CPUSpecificAttr>();
12238 const auto *CurCPUDisp = CurFD->
getAttr<CPUDispatchAttr>();
12243 CurFD->
hasAttr<CPUDispatchAttr>()) {
12244 if (CurCPUDisp->cpus_size() == NewCPUDisp->cpus_size() &&
12246 CurCPUDisp->cpus_begin(), CurCPUDisp->cpus_end(),
12247 NewCPUDisp->cpus_begin(),
12249 return Cur->getName() == New->getName();
12264 if (CurCPUSpec->cpus_size() == NewCPUSpec->cpus_size() &&
12266 CurCPUSpec->cpus_begin(), CurCPUSpec->cpus_end(),
12267 NewCPUSpec->cpus_begin(),
12269 return Cur->getName() == New->getName();
12280 if (CurII == NewII) {
12350 const auto *NewTA = NewFD->
getAttr<TargetAttr>();
12351 const auto *NewTVA = NewFD->
getAttr<TargetVersionAttr>();
12352 const auto *NewCPUDisp = NewFD->
getAttr<CPUDispatchAttr>();
12353 const auto *NewCPUSpec = NewFD->
getAttr<CPUSpecificAttr>();
12354 const auto *NewClones = NewFD->
getAttr<TargetClonesAttr>();
12364 NewTVA->isDefaultVersion())) {
12365 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_not_allowed_on_main);
12373 if (NewTA && TI.
getTriple().isAArch64())
12400 S.
Diag(NewFD->
getLocation(), diag::err_multiversion_required_in_redecl)
12413 if (OldFD->
isUsed(
false)) {
12415 return S.
Diag(NewFD->
getLocation(), diag::err_multiversion_after_used);
12437 bool IsPure = NewFD->
hasAttr<PureAttr>();
12438 bool IsConst = NewFD->
hasAttr<ConstAttr>();
12441 if (!IsPure && !IsConst)
12448 if (IsPure && IsConst) {
12458 NewFD->
dropAttrs<PureAttr, ConstAttr>();
12464 bool IsMemberSpecialization,
12467 "Variably modified return types are not handled here");
12472 bool MergeTypeWithPrevious = !
getLangOpts().CPlusPlus &&
12477 bool MayNeedOverloadableChecks =
false;
12489 if (shouldLinkPossiblyHiddenDecl(Candidate, NewFD)) {
12491 OldDecl = Candidate;
12494 MayNeedOverloadableChecks =
true;
12519 OldDecl =
Previous.getFoundDecl();
12520 MergeTypeWithPrevious =
false;
12523 if (OldDecl->
hasAttr<OverloadableAttr>() ||
12524 NewFD->
hasAttr<OverloadableAttr>()) {
12526 MayNeedOverloadableChecks =
true;
12538 if (
Context.getTargetInfo().getTriple().isPPC64() &&
12589 OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->
getAsFunction());
12590 if (!OldMD || !OldMD->
isStatic()) {
12625 dyn_cast<FunctionTemplateDecl>(OldDecl)) {
12626 auto *OldFD = OldTemplateDecl->getTemplatedDecl();
12629 assert(NewTemplateDecl &&
"Template/non-template mismatch");
12638 NewFD->
setAccess(OldTemplateDecl->getAccess());
12639 NewTemplateDecl->
setAccess(OldTemplateDecl->getAccess());
12644 if (IsMemberSpecialization &&
12647 assert(OldTemplateDecl->isMemberSpecialization());
12650 if (OldFD->isDeleted()) {
12652 assert(OldFD->getCanonicalDecl() == OldFD);
12654 OldFD->setDeletedAsWritten(
false);
12668 !NewFD->
getAttr<OverloadableAttr>()) {
12672 return ND->hasAttr<OverloadableAttr>();
12674 "Non-redecls shouldn't happen without overloadable present");
12677 const auto *FD = dyn_cast<FunctionDecl>(ND);
12678 return FD && !FD->
hasAttr<OverloadableAttr>();
12681 if (OtherUnmarkedIter !=
Previous.end()) {
12683 diag::err_attribute_overloadable_multiple_unmarked_overloads);
12684 Diag((*OtherUnmarkedIter)->getLocation(),
12685 diag::note_attribute_overloadable_prev_overload)
12695 if (NewFD->
hasAttr<SYCLKernelEntryPointAttr>())
12698 if (NewFD->
hasAttr<SYCLExternalAttr>())
12708 dyn_cast<CXXDestructorDecl>(NewFD)) {
12716 (!
Destructor->getFunctionObjectParameterType()->isDependentType() &&
12717 !
Destructor->getDeclName().isDependentName())) {
12722 Context.DeclarationNames.getCXXDestructorName(ClassType);
12729 }
else if (
auto *Guide = dyn_cast<CXXDeductionGuideDecl>(NewFD)) {
12730 if (
auto *TD = Guide->getDescribedFunctionTemplate())
12736 Diag(Guide->getBeginLoc(), diag::err_deduction_guide_specialized)
12742 if (!
Method->isFunctionTemplateSpecialization() &&
12743 !
Method->getDescribedFunctionTemplate() &&
12744 Method->isCanonicalDecl()) {
12751 diag::err_constrained_virtual_method);
12786 if (R->isIncompleteType() && !R->isVoidType())
12789 else if (!R.isPODType(
Context) && !R->isVoidType() &&
12790 !R->isObjCObjectPointerType())
12791 Diag(NewFD->
getLocation(), diag::warn_return_value_udt) << NewFD << R;
12804 auto HasNoexcept = [&](
QualType T) ->
bool {
12809 T = RT->getPointeeType();
12810 else if (
T->isAnyPointerType())
12811 T =
T->getPointeeType();
12813 T = MPT->getPointeeType();
12815 if (FPT->isNothrow())
12821 bool AnyNoexcept = HasNoexcept(FPT->getReturnType());
12823 AnyNoexcept |= HasNoexcept(
T);
12826 diag::warn_cxx17_compat_exception_spec_in_signature)
12831 bool IsKernel = NewFD->
hasAttr<CUDAGlobalAttr>();
12833 if (!Parm->getType()->isDependentType() &&
12834 Parm->hasAttr<CUDAGridConstantAttr>() &&
12835 !(IsKernel && Parm->getType().isConstQualified()))
12836 Diag(Parm->getAttr<CUDAGridConstantAttr>()->getLocation(),
12837 diag::err_cuda_grid_constant_not_allowed);
12843 if (DeclIsDefn &&
Context.getTargetInfo().getTriple().isAArch64())
12853 Diag(FD->
getLocation(), diag::ext_main_invalid_linkage_specification);
12864 ? diag::err_static_main : diag::warn_static_main)
12872 Diag(NoreturnLoc, diag::ext_noreturn_main);
12873 Diag(NoreturnLoc, diag::note_main_remove_noreturn)
12885 << FD->
hasAttr<DeviceKernelAttr>();
12890 if (FD->
hasAttr<SYCLExternalAttr>()) {
12892 << FD->
getAttr<SYCLExternalAttr>();
12903 assert(
T->isFunctionType() &&
"function decl is not of function type");
12925 Diag(RTRange.
getBegin(), diag::note_main_change_return_type)
12950 Diag(start, diag::warn_main_in_named_module)
12962 bool HasExtraParameters = (nparams > 3);
12973 if (nparams == 4 &&
Context.getTargetInfo().getTriple().isOSDarwin())
12974 HasExtraParameters =
false;
12976 if (HasExtraParameters) {
12989 for (
unsigned i = 0; i < nparams; ++i) {
12992 bool mismatch =
true;
13009 mismatch = !qs.
empty();
13038 if (
T.isOSCygMing())
13043 if (
T.isOSWindows() &&
T.getArch() == llvm::Triple::x86)
13051 assert(
T->isFunctionType() &&
"function decl is not of function type");
13060 if (FD->
getName() !=
"DllMain")
13067 FT =
Context.adjustFunctionType(
13072 FT =
Context.adjustFunctionType(FT,
13094 if (
Init->isValueDependent()) {
13095 assert(
Init->containsErrors() &&
13096 "Dependent code should only occur in error-recovery path.");
13099 const Expr *Culprit;
13100 if (
Init->isConstantInitializer(
Context,
false, &Culprit))
13124 if (
const auto *ALE = dyn_cast<ObjCArrayLiteral>(CulpritLiteral)) {
13125 for (
const Expr *Elm : ALE->elements()) {
13127 !Elm->isConstantInitializer(
Context)) {
13128 Diag(Elm->getExprLoc(),
13129 diag::err_objc_literal_nonconstant_at_file_scope)
13136 if (
const auto *DLE = dyn_cast<ObjCDictionaryLiteral>(CulpritLiteral)) {
13137 for (
size_t I = 0, N = DLE->getNumElements(); I != N; ++I) {
13144 diag::err_objc_literal_nonconstant_at_file_scope)
13153 diag::err_objc_literal_nonconstant_at_file_scope)
13161 diag::err_objc_literal_nonconstant_at_file_scope)
13173 class SelfReferenceChecker
13179 bool isReferenceType;
13180 bool isInCXXOperatorCall;
13188 SelfReferenceChecker(
Sema &S,
Decl *OrigDecl) : Inherited(S.Context),
13189 S(S), OrigDecl(OrigDecl) {
13192 isReferenceType =
false;
13193 isInCXXOperatorCall =
false;
13194 isInitList =
false;
13195 if (
ValueDecl *VD = dyn_cast<ValueDecl>(OrigDecl)) {
13196 isPODType = VD->getType().isPODType(S.
Context);
13198 isReferenceType = VD->getType()->isReferenceType();
13205 void CheckExpr(Expr *E) {
13206 InitListExpr *InitList = dyn_cast<InitListExpr>(E);
13214 InitFieldIndex.push_back(0);
13215 for (
auto *Child : InitList->
children()) {
13217 ++InitFieldIndex.back();
13219 InitFieldIndex.pop_back();
13224 bool CheckInitListMemberExpr(MemberExpr *E,
bool CheckReference) {
13225 llvm::SmallVector<FieldDecl*, 4> Fields;
13227 bool ReferenceField =
false;
13230 while (MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
13231 FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl());
13234 Fields.push_back(FD);
13236 ReferenceField =
true;
13237 Base = ME->getBase()->IgnoreParenImpCasts();
13241 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base);
13242 if (!DRE || DRE->
getDecl() != OrigDecl)
13246 if (CheckReference && !ReferenceField)
13250 llvm::SmallVector<unsigned, 4> UsedFieldIndex;
13251 for (
const FieldDecl *I : llvm::reverse(Fields))
13252 UsedFieldIndex.push_back(I->getFieldIndex());
13257 for (
auto UsedIter = UsedFieldIndex.begin(),
13258 UsedEnd = UsedFieldIndex.end(),
13259 OrigIter = InitFieldIndex.begin(),
13260 OrigEnd = InitFieldIndex.end();
13261 UsedIter != UsedEnd && OrigIter != OrigEnd; ++UsedIter, ++OrigIter) {
13262 if (*UsedIter < *OrigIter)
13264 if (*UsedIter > *OrigIter)
13269 HandleDeclRefExpr(DRE);
13276 void HandleValue(Expr *E) {
13278 if (DeclRefExpr* DRE = dyn_cast<DeclRefExpr>(E)) {
13279 HandleDeclRefExpr(DRE);
13283 if (ConditionalOperator *CO = dyn_cast<ConditionalOperator>(E)) {
13284 Visit(CO->getCond());
13285 HandleValue(CO->getTrueExpr());
13286 HandleValue(CO->getFalseExpr());
13290 if (BinaryConditionalOperator *BCO =
13291 dyn_cast<BinaryConditionalOperator>(E)) {
13292 Visit(BCO->getCond());
13293 HandleValue(BCO->getFalseExpr());
13297 if (OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(E)) {
13298 if (Expr *SE = OVE->getSourceExpr())
13303 if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
13304 if (BO->getOpcode() == BO_Comma) {
13305 Visit(BO->getLHS());
13306 HandleValue(BO->getRHS());
13319 while (MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
13323 Base = ME->getBase()->IgnoreParenImpCasts();
13325 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base))
13326 HandleDeclRefExpr(DRE);
13335 void VisitDeclRefExpr(DeclRefExpr *E) {
13336 if (isReferenceType)
13337 HandleDeclRefExpr(E);
13340 void VisitImplicitCastExpr(ImplicitCastExpr *E) {
13346 Inherited::VisitImplicitCastExpr(E);
13349 void VisitMemberExpr(MemberExpr *E) {
13351 if (CheckInitListMemberExpr(E,
true ))
13360 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->
getMemberDecl());
13361 bool Warn = (MD && !MD->
isStatic());
13363 while (MemberExpr *ME = dyn_cast<MemberExpr>(Base)) {
13366 Base = ME->getBase()->IgnoreParenImpCasts();
13369 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Base)) {
13371 HandleDeclRefExpr(DRE);
13380 void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
13381 llvm::SaveAndRestore CxxOpCallScope(isInCXXOperatorCall,
true);
13385 return Inherited::VisitCXXOperatorCallExpr(E);
13389 HandleValue(Arg->IgnoreParenImpCasts());
13393 if (!isInCXXOperatorCall) {
13394 Inherited::VisitLambdaExpr(E);
13399 if (DeclRefExpr *DRE = dyn_cast_if_present<DeclRefExpr>(
Init))
13400 HandleDeclRefExpr(DRE);
13405 void VisitUnaryOperator(UnaryOperator *E) {
13419 Inherited::VisitUnaryOperator(E);
13422 void VisitObjCMessageExpr(ObjCMessageExpr *E) {}
13424 void VisitCXXConstructExpr(CXXConstructExpr *E) {
13426 Expr *ArgExpr = E->
getArg(0);
13427 if (InitListExpr *ILE = dyn_cast<InitListExpr>(ArgExpr))
13428 if (ILE->getNumInits() == 1)
13429 ArgExpr = ILE->getInit(0);
13430 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(ArgExpr))
13431 if (ICE->getCastKind() == CK_NoOp)
13432 ArgExpr = ICE->getSubExpr();
13433 HandleValue(ArgExpr);
13436 Inherited::VisitCXXConstructExpr(E);
13439 void VisitCallExpr(CallExpr *E) {
13442 HandleValue(E->
getArg(0));
13446 Inherited::VisitCallExpr(E);
13449 void VisitBinaryOperator(BinaryOperator *E) {
13451 HandleValue(E->
getLHS());
13456 Inherited::VisitBinaryOperator(E);
13462 void VisitBinaryConditionalOperator(BinaryConditionalOperator *E) {
13467 void HandleDeclRefExpr(DeclRefExpr *DRE) {
13469 if (OrigDecl != ReferenceDecl)
return;
13471 if (isReferenceType) {
13472 diag = diag::warn_uninit_self_reference_in_reference_init;
13474 diag = diag::warn_static_self_reference_in_init;
13478 diag = diag::warn_uninit_self_reference_in_init;
13492 static void CheckSelfReference(Sema &S, Decl* OrigDecl, Expr *E,
13502 if (
auto *VD = dyn_cast<VarDecl>(OrigDecl);
13503 VD && VD->isConstexpr() && VD->isFileVarDecl())
13511 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(E))
13512 if (ICE->getCastKind() == CK_LValueToRValue)
13513 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr()))
13514 if (DRE->
getDecl() == OrigDecl)
13517 SelfReferenceChecker(S, OrigDecl).CheckExpr(E);
13524 struct VarDeclOrName {
13526 DeclarationName Name;
13528 friend const Sema::SemaDiagnosticBuilder &
13529 operator<<(
const Sema::SemaDiagnosticBuilder &
Diag, VarDeclOrName VN) {
13530 return VN.VDecl ?
Diag << VN.VDecl :
Diag << VN.Name;
13540 bool IsInitCapture = !VDecl;
13542 "init captures are expected to be deduced prior to initialization");
13544 VarDeclOrName VN{VDecl, Name};
13547 assert(
Deduced &&
"deduceVarTypeFromInitializer for non-deduced type");
13551 !isa_and_present<StringLiteral, InitListExpr>(
Init)) {
13552 Diag(Range.getBegin(), diag::err_auto_not_allowed)
13553 << (int)
Deduced->getContainedAutoType()->getKeyword()
13560 assert(VDecl &&
"no init for init capture deduction?");
13575 DeduceInits =
Init;
13577 auto *PL = dyn_cast_if_present<ParenListExpr>(
Init);
13579 DeduceInits = PL->exprs();
13582 assert(VDecl &&
"non-auto type for init capture deduction?");
13593 if (
auto *IL = dyn_cast<InitListExpr>(
Init))
13594 DeduceInits = IL->inits();
13598 if (DeduceInits.empty()) {
13601 Diag(
Init->getBeginLoc(), IsInitCapture
13602 ? diag::err_init_capture_no_expression
13603 : diag::err_auto_var_init_no_expression)
13604 << VN <<
Type << Range;
13608 if (DeduceInits.size() > 1) {
13609 Diag(DeduceInits[1]->getBeginLoc(),
13610 IsInitCapture ? diag::err_init_capture_multiple_expressions
13611 : diag::err_auto_var_init_multiple_expressions)
13612 << VN <<
Type << Range;
13616 Expr *DeduceInit = DeduceInits[0];
13618 Diag(
Init->getBeginLoc(), IsInitCapture
13619 ? diag::err_init_capture_paren_braces
13620 : diag::err_auto_var_init_paren_braces)
13626 bool DefaultedAnyToId =
false;
13628 Init->getType() ==
Context.UnknownAnyTy && !IsInitCapture) {
13630 if (
Result.isInvalid()) {
13634 DefaultedAnyToId =
true;
13644 Type.getQualifiers());
13652 if (!IsInitCapture)
13655 Diag(Range.getBegin(),
13656 diag::err_init_capture_deduction_failure_from_init_list)
13662 Diag(Range.getBegin(), diag::err_init_capture_deduction_failure)
13677 Diag(Loc, diag::warn_auto_var_is_id) << VN << Range;
13680 return DeducedType;
13685 assert(!
Init || !
Init->containsErrors());
13689 if (DeducedType.
isNull()) {
13698 if (
getLangOpts().ObjCAutoRefCount &&
ObjC().inferObjCARCLifetime(VDecl))
13722 if (
auto *EWC = dyn_cast<ExprWithCleanups>(
Init))
13723 Init = EWC->getSubExpr();
13725 if (
auto *CE = dyn_cast<ConstantExpr>(
Init))
13726 Init = CE->getSubExpr();
13731 "shouldn't be called if type doesn't have a non-trivial C struct");
13732 if (
auto *ILE = dyn_cast<InitListExpr>(
Init)) {
13733 for (
auto *I : ILE->inits()) {
13734 if (!I->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion() &&
13735 !I->getType().hasNonTrivialToPrimitiveCopyCUnion())
13761bool shouldIgnoreForRecordTriviality(
const FieldDecl *FD) {
13767 return FD->
hasAttr<UnavailableAttr>();
13770struct DiagNonTrivalCUnionDefaultInitializeVisitor
13777 DiagNonTrivalCUnionDefaultInitializeVisitor(
13780 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13783 const FieldDecl *FD,
bool InNonTrivialUnion) {
13786 InNonTrivialUnion);
13787 return Super::visitWithKind(PDIK, QT, FD, InNonTrivialUnion);
13790 void visitARCStrong(QualType QT,
const FieldDecl *FD,
13791 bool InNonTrivialUnion) {
13792 if (InNonTrivialUnion)
13794 << 1 << 0 << QT << FD->
getName();
13797 void visitARCWeak(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13798 if (InNonTrivialUnion)
13800 << 1 << 0 << QT << FD->
getName();
13803 void visitStruct(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13805 if (RD->isUnion()) {
13806 if (OrigLoc.isValid()) {
13807 bool IsUnion =
false;
13808 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13809 IsUnion = OrigRD->isUnion();
13810 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13811 << 0 << OrigTy << IsUnion << UseContext;
13813 OrigLoc = SourceLocation();
13815 InNonTrivialUnion =
true;
13818 if (InNonTrivialUnion)
13819 S.
Diag(RD->getLocation(), diag::note_non_trivial_c_union)
13822 for (
const FieldDecl *FD : RD->fields())
13823 if (!shouldIgnoreForRecordTriviality(FD))
13824 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13827 void visitTrivial(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {}
13832 SourceLocation OrigLoc;
13837struct DiagNonTrivalCUnionDestructedTypeVisitor
13840 DestructedTypeVisitor<DiagNonTrivalCUnionDestructedTypeVisitor, void>;
13842 DiagNonTrivalCUnionDestructedTypeVisitor(QualType OrigTy,
13843 SourceLocation OrigLoc,
13846 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13849 const FieldDecl *FD,
bool InNonTrivialUnion) {
13852 InNonTrivialUnion);
13853 return Super::visitWithKind(DK, QT, FD, InNonTrivialUnion);
13856 void visitARCStrong(QualType QT,
const FieldDecl *FD,
13857 bool InNonTrivialUnion) {
13858 if (InNonTrivialUnion)
13860 << 1 << 1 << QT << FD->
getName();
13863 void visitARCWeak(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13864 if (InNonTrivialUnion)
13866 << 1 << 1 << QT << FD->
getName();
13869 void visitStruct(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13871 if (RD->isUnion()) {
13872 if (OrigLoc.isValid()) {
13873 bool IsUnion =
false;
13874 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13875 IsUnion = OrigRD->isUnion();
13876 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13877 << 1 << OrigTy << IsUnion << UseContext;
13879 OrigLoc = SourceLocation();
13881 InNonTrivialUnion =
true;
13884 if (InNonTrivialUnion)
13885 S.
Diag(RD->getLocation(), diag::note_non_trivial_c_union)
13888 for (
const FieldDecl *FD : RD->fields())
13889 if (!shouldIgnoreForRecordTriviality(FD))
13890 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13893 void visitTrivial(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {}
13894 void visitCXXDestructor(QualType QT,
const FieldDecl *FD,
13895 bool InNonTrivialUnion) {}
13900 SourceLocation OrigLoc;
13905struct DiagNonTrivalCUnionCopyVisitor
13907 using Super = CopiedTypeVisitor<DiagNonTrivalCUnionCopyVisitor, false, void>;
13909 DiagNonTrivalCUnionCopyVisitor(QualType OrigTy, SourceLocation OrigLoc,
13911 : OrigTy(OrigTy), OrigLoc(OrigLoc), UseContext(UseContext), S(S) {}
13914 const FieldDecl *FD,
bool InNonTrivialUnion) {
13917 InNonTrivialUnion);
13918 return Super::visitWithKind(PCK, QT, FD, InNonTrivialUnion);
13921 void visitARCStrong(QualType QT,
const FieldDecl *FD,
13922 bool InNonTrivialUnion) {
13923 if (InNonTrivialUnion)
13925 << 1 << 2 << QT << FD->
getName();
13928 void visitARCWeak(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13929 if (InNonTrivialUnion)
13931 << 1 << 2 << QT << FD->
getName();
13934 void visitStruct(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13936 if (RD->isUnion()) {
13937 if (OrigLoc.isValid()) {
13938 bool IsUnion =
false;
13939 if (
auto *OrigRD = OrigTy->getAsRecordDecl())
13940 IsUnion = OrigRD->isUnion();
13941 S.
Diag(OrigLoc, diag::err_non_trivial_c_union_in_invalid_context)
13942 << 2 << OrigTy << IsUnion << UseContext;
13944 OrigLoc = SourceLocation();
13946 InNonTrivialUnion =
true;
13949 if (InNonTrivialUnion)
13950 S.
Diag(RD->getLocation(), diag::note_non_trivial_c_union)
13953 for (
const FieldDecl *FD : RD->fields())
13954 if (!shouldIgnoreForRecordTriviality(FD))
13955 asDerived().visit(FD->
getType(), FD, InNonTrivialUnion);
13958 void visitPtrAuth(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {
13959 if (InNonTrivialUnion)
13961 << 1 << 2 << QT << FD->
getName();
13965 const FieldDecl *FD,
bool InNonTrivialUnion) {}
13966 void visitTrivial(QualType QT,
const FieldDecl *FD,
bool InNonTrivialUnion) {}
13967 void visitVolatileTrivial(QualType QT,
const FieldDecl *FD,
13968 bool InNonTrivialUnion) {}
13973 SourceLocation OrigLoc;
13982 unsigned NonTrivialKind) {
13986 "shouldn't be called if type doesn't have a non-trivial C union");
13990 DiagNonTrivalCUnionDefaultInitializeVisitor(QT, Loc, UseContext, *
this)
13991 .visit(QT,
nullptr,
false);
13994 DiagNonTrivalCUnionDestructedTypeVisitor(QT, Loc, UseContext, *
this)
13995 .visit(QT,
nullptr,
false);
13997 DiagNonTrivalCUnionCopyVisitor(QT, Loc, UseContext, *
this)
13998 .visit(QT,
nullptr,
false);
14022 bool TargetIsInline = Dcl->
isInline();
14023 bool TargetWasTemplated =
14040 TargetWasTemplated =
14050 if (!TargetIsInline || TargetWasTemplated)
14060 if (
Context.getTargetInfo().shouldDLLImportComdatSymbols()) {
14061 if (
Target->hasAttr<DLLExportAttr>() ||
Target->hasAttr<DLLImportAttr>())
14067 dyn_cast<CXXRecordDecl>(
Target->getDeclContext());
14068 if (Ctx && (Ctx->
hasAttr<DLLExportAttr>() || Ctx->
hasAttr<DLLImportAttr>()))
14090 T =
T.getNonReferenceType();
14091 if (
T->isFunctionType())
14093 if (!
T.isConstant(Ctx))
14095 if (
T->isPointerType())
14113 Diag(VD->
getLocation(), diag::warn_possible_object_duplication_mutable)
14114 << VD <<
Context.getTargetInfo().shouldDLLImportComdatSymbols();
14126 Diag(
Init->getExprLoc(), diag::warn_possible_object_duplication_init)
14127 << VD <<
Context.getTargetInfo().shouldDLLImportComdatSymbols();
14133 llvm::scope_exit ResetDeclForInitializer([
this]() {
14144 if (
auto *
Method = dyn_cast<CXXMethodDecl>(RealDecl)) {
14145 if (!
Method->isInvalidDecl()) {
14147 Diag(
Method->getLocation(), diag::err_member_function_initialization)
14148 <<
Method->getDeclName() <<
Init->getSourceRange();
14149 Method->setInvalidDecl();
14154 VarDecl *VDecl = dyn_cast<VarDecl>(RealDecl);
14156 assert(!
isa<FieldDecl>(RealDecl) &&
"field init shouldn't get here");
14165 if (
Expr *E = Recovery.
get())
14172 Context.AMDGPUFeaturePredicateTy) {
14174 diag::err_amdgcn_predicate_type_is_not_constructible)
14181 if (!
Init->getType().isNull() &&
Init->getType()->isWebAssemblyTableType()) {
14182 Diag(
Init->getExprLoc(), diag::err_wasm_table_art) << 0;
14189 if (
Init->containsErrors()) {
14198 "decl should be invalidated when deduce fails");
14210 if (VDecl->
hasAttr<HLSLGroupSharedAddressSpaceAttr>()) {
14217 Diag(VDecl->
getLocation(), diag::err_attribute_dllimport_data_definition);
14237 if (
const ArrayType *Array =
Context.getAsIncompleteArrayType(BaseDeclType))
14238 BaseDeclType = Array->getElementType();
14240 diag::err_typecheck_decl_incomplete_type)) {
14247 diag::err_abstract_type_in_decl,
14265 !(VDecl->
hasAttr<SelectAnyAttr>() || VDecl->
hasAttr<WeakAttr>())) {
14274 if (Def != VDecl &&
14294 Diag(
Init->getExprLoc(), diag::err_static_data_member_reinitialization)
14297 diag::note_previous_initializer)
14322 if (VDecl->
hasAttr<LoaderUninitializedAttr>()) {
14323 Diag(VDecl->
getLocation(), diag::err_loader_uninitialized_cant_init);
14329 if (!
HLSL().handleInitialization(VDecl,
Init))
14341 if (!
Result.isUsable()) {
14349 bool InitializedFromParenListExpr =
false;
14350 bool IsParenListInit =
false;
14357 if (
auto *CXXDirectInit = dyn_cast<ParenListExpr>(
Init)) {
14359 MultiExprArg(CXXDirectInit->getExprs(), CXXDirectInit->getNumExprs());
14360 InitializedFromParenListExpr =
true;
14361 }
else if (
auto *CXXDirectInit = dyn_cast<CXXParenListInitExpr>(
Init)) {
14362 Args = CXXDirectInit->getInitExprs();
14363 InitializedFromParenListExpr =
true;
14370 if (!
Result.isUsable()) {
14390 IsParenListInit = !InitSeq.
steps().empty() &&
14394 if (!
Init->getType().isNull() && !
Init->getType()->isDependentType() &&
14396 Context.getAsIncompleteArrayType(VDeclType) &&
14397 Context.getAsIncompleteArrayType(
Init->getType())) {
14426 if (VDecl->
hasAttr<BlocksAttr>())
14439 !
Diags.isIgnored(diag::warn_arc_repeated_use_of_weak,
14440 Init->getBeginLoc()))
14441 FSI->markSafeWeakUse(
Init);
14462 if (!
Result.isUsable()) {
14502 if (
auto *E = dyn_cast<ExprWithCleanups>(
Init))
14503 if (
auto *BE = dyn_cast<BlockExpr>(E->getSubExpr()->
IgnoreParens()))
14505 BE->getBlockDecl()->setCanAvoidCopyToHeap();
14540 <<
Init->getSourceRange();
14556 diag::ext_in_class_initializer_float_type_cxx11)
14557 << DclT <<
Init->getSourceRange();
14559 diag::note_in_class_initializer_float_type_cxx11)
14562 Diag(VDecl->
getLocation(), diag::ext_in_class_initializer_float_type)
14563 << DclT <<
Init->getSourceRange();
14566 Diag(
Init->getExprLoc(), diag::err_in_class_initializer_non_constant)
14567 <<
Init->getSourceRange();
14574 Diag(VDecl->
getLocation(), diag::err_in_class_initializer_literal_type)
14575 << DclT <<
Init->getSourceRange()
14581 << DclT <<
Init->getSourceRange();
14594 !
Context.getBaseElementType(VDecl->
getType()).isConstQualified()) &&
14602 if (
Context.getTargetInfo().getCXXABI().isMicrosoft() &&
14615 if (!InitType.
isNull() &&
14633 if (InitializedFromParenListExpr) {
14634 assert(
DirectInit &&
"Call-style initializer must be direct init.");
14657 VarDecl *VD = dyn_cast<VarDecl>(D);
14661 if (
auto *DD = dyn_cast<DecompositionDecl>(D))
14662 for (
auto *BD : DD->bindings())
14663 BD->setInvalidDecl();
14676 Context.getBaseElementType(Ty),
14677 diag::err_typecheck_decl_incomplete_type)) {
14684 diag::err_abstract_type_in_decl,
14699 if (
VarDecl *Var = dyn_cast<VarDecl>(RealDecl)) {
14703 Diag(Var->getLocation(),
14704 diag::err_amdgcn_predicate_type_is_not_constructible)
14706 Var->setInvalidDecl();
14715 dyn_cast<DecompositionDecl>(RealDecl)->getRSquareLoc();
14717 RSquareLoc,
PP.getSourceManager(),
PP.getLangOpts()))
14718 Loc =
Next->getLocation();
14719 Diag(Loc, diag::err_decomp_decl_requires_init) << Var;
14720 Var->setInvalidDecl();
14736 if (Var->isConstexpr() && !Var->isThisDeclarationADefinition() &&
14737 !Var->isThisDeclarationADemotedDefinition()) {
14738 if (Var->isStaticDataMember()) {
14742 !
Context.getTargetInfo().getCXXABI().isMicrosoft()) {
14743 Diag(Var->getLocation(),
14744 diag::err_constexpr_static_mem_var_requires_init)
14746 Var->setInvalidDecl();
14750 Diag(Var->getLocation(), diag::err_invalid_constexpr_var_decl);
14751 Var->setInvalidDecl();
14758 if (!Var->isInvalidDecl() &&
14760 Var->getStorageClass() !=
SC_Extern && !Var->getInit()) {
14761 bool HasConstExprDefaultConstructor =
false;
14762 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
14763 for (
auto *Ctor : RD->ctors()) {
14764 if (Ctor->isConstexpr() && Ctor->getNumParams() == 0 &&
14765 Ctor->getMethodQualifiers().getAddressSpace() ==
14767 HasConstExprDefaultConstructor =
true;
14771 if (!HasConstExprDefaultConstructor) {
14772 Diag(Var->getLocation(), diag::err_opencl_constant_no_init);
14773 Var->setInvalidDecl();
14779 if (!Var->isInvalidDecl() && Var->hasAttr<HLSLVkConstantIdAttr>()) {
14780 Diag(Var->getLocation(), diag::err_specialization_const);
14781 Var->setInvalidDecl();
14785 if (!Var->isInvalidDecl() && RealDecl->
hasAttr<LoaderUninitializedAttr>()) {
14786 if (Var->getStorageClass() ==
SC_Extern) {
14787 Diag(Var->getLocation(), diag::err_loader_uninitialized_extern_decl)
14789 Var->setInvalidDecl();
14793 diag::err_typecheck_decl_incomplete_type)) {
14794 Var->setInvalidDecl();
14797 if (
CXXRecordDecl *RD = Var->getType()->getAsCXXRecordDecl()) {
14798 if (!RD->hasTrivialDefaultConstructor()) {
14799 Diag(Var->getLocation(), diag::err_loader_uninitialized_trivial_ctor);
14800 Var->setInvalidDecl();
14810 Var->getType().hasNonTrivialToPrimitiveDefaultInitializeCUnion())
14817 if (!Var->isStaticDataMember() || !Var->getAnyInitializer())
14833 !Var->hasLinkage() && !Var->isInvalidDecl() &&
14835 diag::err_typecheck_decl_incomplete_type))
14836 Var->setInvalidDecl();
14841 diag::err_abstract_type_in_decl,
14843 Var->setInvalidDecl();
14846 Diag(Var->getLocation(), diag::warn_private_extern);
14847 Diag(Var->getLocation(), diag::note_private_extern);
14850 if (
Context.getTargetInfo().allowDebugInfoForExternalRef() &&
14851 !Var->isInvalidDecl())
14862 if (!Var->isInvalidDecl()) {
14866 Var->getLocation(), ArrayT->getElementType(),
14867 diag::err_array_incomplete_or_sizeless_type))
14868 Var->setInvalidDecl();
14870 if (Var->getStorageClass() ==
SC_Static) {
14880 if (Var->isFirstDecl())
14882 diag::ext_typecheck_decl_incomplete_type,
14888 if (!Var->isInvalidDecl())
14899 if (Var->isConstexpr())
14900 Diag(Var->getLocation(), diag::err_constexpr_var_requires_const_init)
14903 Diag(Var->getLocation(),
14904 diag::err_typecheck_incomplete_array_needs_initializer);
14905 Var->setInvalidDecl();
14912 Diag(Var->getLocation(), diag::err_reference_var_requires_init)
14913 << Var <<
SourceRange(Var->getLocation(), Var->getLocation());
14922 if (Var->isInvalidDecl())
14925 if (!Var->hasAttr<AliasAttr>()) {
14928 diag::err_typecheck_decl_incomplete_type)) {
14929 Var->setInvalidDecl();
14938 diag::err_abstract_type_in_decl,
14940 Var->setInvalidDecl();
14947 unsigned DiagID = diag::warn_default_init_const_unsafe;
14948 if (Var->getStorageDuration() ==
SD_Static ||
14949 Var->getStorageDuration() ==
SD_Thread)
14950 DiagID = diag::warn_default_init_const;
14952 bool EmitCppCompat = !
Diags.isIgnored(
14953 diag::warn_cxx_compat_hack_fake_diagnostic_do_not_emit,
14954 Var->getLocation());
14956 Diag(Var->getLocation(), DiagID) <<
Type << EmitCppCompat;
14970 if (
const auto *CXXRecord =
14971 Context.getBaseElementType(
Type)->getAsCXXRecordDecl()) {
14975 if (!CXXRecord->isPOD())
15020 }
else if (
Init.isInvalid()) {
15038 VarDecl *VD = dyn_cast<VarDecl>(D);
15041 << InExpansionStmt;
15083 << InExpansionStmt << VD <<
Error;
15098 const char *PrevSpec;
15123 Context.getAttributedType(
Attr, MethodType, MethodType);
15134 if (var->isInvalidDecl())
return;
15141 if (var->getTypeSourceInfo()->getType()->isBlockPointerType() &&
15143 Diag(var->getLocation(), diag::err_opencl_invalid_block_declaration)
15145 var->setInvalidDecl();
15153 var->hasLocalStorage()) {
15154 switch (var->getType().getObjCLifetime()) {
15167 if (var->hasLocalStorage() &&
15176 if (var->isThisDeclarationADefinition() &&
15177 var->getDeclContext()->getRedeclContext()->isFileContext() &&
15178 var->isExternallyVisible() && var->hasLinkage() &&
15179 !var->isInline() && !var->getDescribedVarTemplate() &&
15183 !
getDiagnostics().isIgnored(diag::warn_missing_variable_declarations,
15184 var->getLocation())) {
15186 VarDecl *prev = var->getPreviousDecl();
15191 Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var;
15192 Diag(var->getTypeSpecStartLoc(), diag::note_static_for_internal_linkage)
15198 std::optional<bool> CacheHasConstInit;
15199 const Expr *CacheCulprit =
nullptr;
15200 auto checkConstInit = [&]()
mutable {
15201 const Expr *
Init = var->getInit();
15202 if (
Init->isInstantiationDependent())
15205 if (!CacheHasConstInit)
15206 CacheHasConstInit = var->getInit()->isConstantInitializer(
15207 Context, var->getType()->isReferenceType(), &CacheCulprit);
15208 return *CacheHasConstInit;
15212 if (var->getType().isDestructedType()) {
15216 Diag(var->getLocation(), diag::err_thread_nontrivial_dtor);
15218 Diag(var->getLocation(), diag::note_use_thread_local);
15220 if (!checkConstInit()) {
15228 Diag(var->getLocation(), diag::note_use_thread_local);
15234 if (!var->getType()->isStructureType() && var->hasInit() &&
15237 unsigned NumInits = ILE->getNumInits();
15239 for (
unsigned I = 0; I < NumInits; ++I) {
15240 const auto *
Init = ILE->getInit(I);
15243 const auto *SL = dyn_cast<StringLiteral>(
Init->IgnoreImpCasts());
15247 unsigned NumConcat = SL->getNumConcatenated();
15251 if (NumConcat == 2 && !SL->getBeginLoc().isMacroID()) {
15252 bool OnlyOneMissingComma =
true;
15253 for (
unsigned J = I + 1; J < NumInits; ++J) {
15254 const auto *
Init = ILE->getInit(J);
15257 const auto *SLJ = dyn_cast<StringLiteral>(
Init->IgnoreImpCasts());
15258 if (!SLJ || SLJ->getNumConcatenated() > 1) {
15259 OnlyOneMissingComma =
false;
15264 if (OnlyOneMissingComma) {
15266 for (
unsigned i = 0; i < NumConcat - 1; ++i)
15268 PP.getLocForEndOfToken(SL->getStrTokenLoc(i)),
","));
15270 Diag(SL->getStrTokenLoc(1),
15271 diag::warn_concatenated_literal_array_init)
15273 Diag(SL->getBeginLoc(),
15274 diag::note_concatenated_string_literal_silence);
15285 if (var->hasAttr<BlocksAttr>())
15289 bool GlobalStorage = var->hasGlobalStorage();
15290 bool IsGlobal = GlobalStorage && !var->isStaticLocal();
15292 bool HasConstInit =
true;
15295 Diag(var->getLocation(), diag::err_constexpr_var_requires_const_init)
15300 !
type->isDependentType() &&
Init && !
Init->isValueDependent() &&
15301 (GlobalStorage || var->isConstexpr() ||
15302 var->mightBeUsableInConstantExpressions(
Context))) {
15314 HasConstInit = checkConstInit();
15318 if (HasConstInit) {
15319 if (var->isStaticDataMember() && !var->isInline() &&
15320 var->getLexicalDeclContext()->isRecord() &&
15321 type->isIntegralOrEnumerationType()) {
15326 diag::ext_in_class_initializer_non_constant)
15327 <<
Init->getSourceRange();
15330 (void)var->checkForConstantInitialization(Notes);
15332 }
else if (CacheCulprit) {
15333 Notes.emplace_back(CacheCulprit->
getExprLoc(),
15334 PDiag(diag::note_invalid_subexpr_in_const_expr));
15339 HasConstInit = var->checkForConstantInitialization(Notes);
15342 if (HasConstInit) {
15344 }
else if (var->isConstexpr()) {
15348 if (Notes.size() == 1 && Notes[0].second.getDiagID() ==
15349 diag::note_invalid_subexpr_in_const_expr) {
15350 DiagLoc = Notes[0].first;
15353 Diag(DiagLoc, diag::err_constexpr_var_requires_const_init)
15354 << var <<
Init->getSourceRange();
15355 for (
unsigned I = 0, N = Notes.size(); I != N; ++I)
15356 Diag(Notes[I].first, Notes[I].second);
15357 }
else if (GlobalStorage && var->hasAttr<ConstInitAttr>()) {
15358 auto *
Attr = var->getAttr<ConstInitAttr>();
15359 Diag(var->getLocation(), diag::err_require_constant_init_failed)
15360 <<
Init->getSourceRange();
15363 for (
auto &it : Notes)
15364 Diag(it.first, it.second);
15365 }
else if (var->isStaticDataMember() && !var->isInline() &&
15366 var->getLexicalDeclContext()->isRecord()) {
15367 Diag(var->getLocation(), diag::err_in_class_initializer_non_constant)
15368 <<
Init->getSourceRange();
15369 for (
auto &it : Notes)
15370 Diag(it.first, it.second);
15371 var->setInvalidDecl();
15372 }
else if (IsGlobal &&
15374 var->getLocation())) {
15383 if (!checkConstInit())
15384 Diag(var->getLocation(), diag::warn_global_constructor)
15385 <<
Init->getSourceRange();
15391 if (GlobalStorage && var->isThisDeclarationADefinition() &&
15396 Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment();
15397 std::optional<QualType::NonConstantStorageReason> Reason;
15398 if (HasConstInit &&
15399 !(Reason = var->getType().isNonConstantStorage(
Context,
true,
false))) {
15405 if (
const SectionAttr *SA = var->getAttr<SectionAttr>()) {
15412 var->getType().isConstQualified()) {
15414 NonConstNonReferenceType) &&
15415 "This case should've already been handled elsewhere");
15416 Diag(var->getLocation(), diag::warn_section_msvc_compat)
15417 << var <<
ConstSegStack.CurrentValue << (int)(!HasConstInit
15423 var->addAttr(SectionAttr::CreateImplicit(
Context, SectionName,
15425 SectionAttr::Declspec_allocate));
15427 var->dropAttr<SectionAttr>();
15442 if (
Context.DeclMustBeEmitted(var) && !ModuleScopes.empty())
15443 Context.addModuleInitializer(ModuleScopes.back().Module, var);
15450 if (!
type->isDependentType())
15459 if (
Context.DeclMustBeEmitted(var) && !ModuleScopes.empty()) {
15461 if (ModuleScopes.back().Module->isHeaderLikeModule() ||
15464 Context.addModuleInitializer(ModuleScopes.back().Module, var);
15468 if (
auto *DD = dyn_cast<DecompositionDecl>(var))
15479 !FD->
hasAttr<DLLExportStaticLocalAttr>() &&
15480 !FD->
hasAttr<DLLImportStaticLocalAttr>()) {
15490 NewAttr->setInherited(
true);
15492 }
else if (
Attr *A = FD->
getAttr<DLLExportStaticLocalAttr>()) {
15493 auto *NewAttr = DLLExportAttr::CreateImplicit(
getASTContext(), *A);
15494 NewAttr->setInherited(
true);
15499 if (!FD->
hasAttr<DLLExportAttr>())
15502 }
else if (
Attr *A = FD->
getAttr<DLLImportStaticLocalAttr>()) {
15503 auto *NewAttr = DLLImportAttr::CreateImplicit(
getASTContext(), *A);
15504 NewAttr->setInherited(
true);
15515 if (
unsigned MaxAlign =
Context.getTargetInfo().getMaxTLSAlign()) {
15520 if (
Context.getDeclAlign(VD) > MaxAlignChars) {
15533 VarDecl *VD = dyn_cast_or_null<VarDecl>(ThisDecl);
15545 VD->
addAttr(PragmaClangBSSSectionAttr::CreateImplicit(
15549 VD->
addAttr(PragmaClangDataSectionAttr::CreateImplicit(
15553 VD->
addAttr(PragmaClangRodataSectionAttr::CreateImplicit(
15557 VD->
addAttr(PragmaClangRelroSectionAttr::CreateImplicit(
15562 if (
auto *DD = dyn_cast<DecompositionDecl>(ThisDecl)) {
15563 for (
auto *BD : DD->bindings()) {
15568 CheckInvalidBuiltinCountedByRef(VD->
getInit(),
15591 if (
const auto *IA = dyn_cast_or_null<DLLImportAttr>(DLLAttr)) {
15598 bool IsClassTemplateMember =
15600 Context->getDescribedClassTemplate();
15603 IsClassTemplateMember
15604 ? diag::warn_attribute_dllimport_static_field_definition
15605 : diag::err_attribute_dllimport_static_field_definition);
15606 Diag(IA->getLocation(), diag::note_attribute);
15607 if (!IsClassTemplateMember)
15636 if (RetainAttr *
Attr = VD->
getAttr<RetainAttr>()) {
15657 if (!VD->
hasAttr<TypeTagForDatatypeAttr>() ||
15661 for (
const auto *I : ThisDecl->
specific_attrs<TypeTagForDatatypeAttr>()) {
15663 if (!MagicValueExpr) {
15666 std::optional<llvm::APSInt> MagicValueInt;
15668 Diag(I->getRange().getBegin(),
15669 diag::err_type_tag_for_datatype_not_ice)
15673 if (MagicValueInt->getActiveBits() > 64) {
15674 Diag(I->getRange().getBegin(),
15675 diag::err_type_tag_for_datatype_too_large)
15679 uint64_t MagicValue = MagicValueInt->getZExtValue();
15682 I->getMatchingCType(),
15683 I->getLayoutCompatible(),
15684 I->getMustBeNull());
15689 auto *VD = dyn_cast<VarDecl>(DD);
15690 return VD && !VD->getType()->hasAutoForTrailingReturnType();
15702 bool DiagnosedMultipleDecomps =
false;
15704 bool DiagnosedNonDeducedAuto =
false;
15706 for (
Decl *D : Group) {
15711 if (
auto *VD = dyn_cast<VarDecl>(D);
15712 LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() &&
15713 VD->hasGlobalStorage())
15717 if (
auto *DD = dyn_cast<DeclaratorDecl>(D)) {
15718 if (!FirstDeclaratorInGroup)
15719 FirstDeclaratorInGroup = DD;
15720 if (!FirstDecompDeclaratorInGroup)
15721 FirstDecompDeclaratorInGroup = dyn_cast<DecompositionDecl>(D);
15724 FirstNonDeducedAutoInGroup = DD;
15726 if (FirstDeclaratorInGroup != DD) {
15729 if (FirstDecompDeclaratorInGroup && !DiagnosedMultipleDecomps) {
15731 diag::err_decomp_decl_not_alone)
15733 << DD->getSourceRange();
15734 DiagnosedMultipleDecomps =
true;
15740 if (FirstNonDeducedAutoInGroup && !DiagnosedNonDeducedAuto) {
15742 diag::err_auto_non_deduced_not_alone)
15743 << FirstNonDeducedAutoInGroup->
getType()
15746 << DD->getSourceRange();
15747 DiagnosedNonDeducedAuto =
true;
15752 Decls.push_back(D);
15758 if (FirstDeclaratorInGroup && !Tag->hasNameForLinkage() &&
15760 Context.addDeclaratorForUnnamedTagDecl(Tag, FirstDeclaratorInGroup);
15772 if (Group.size() > 1) {
15774 VarDecl *DeducedDecl =
nullptr;
15775 for (
unsigned i = 0, e = Group.size(); i != e; ++i) {
15776 VarDecl *D = dyn_cast<VarDecl>(Group[i]);
15780 if (!DT || DT->getDeducedType().isNull())
15783 Deduced = DT->getDeducedType();
15785 }
else if (!
Context.hasSameType(DT->getDeducedType(),
Deduced)) {
15786 auto *AT = dyn_cast<AutoType>(DT);
15788 diag::err_auto_different_deductions)
15790 << DeducedDecl->
getDeclName() << DT->getDeducedType()
15814 if (Group.empty() || !Group[0])
15820 if (Group.size() >= 2) {
15828 Decl *MaybeTagDecl = Group[0];
15830 Group = Group.slice(1);
15883 const auto *VD = dyn_cast<ValueDecl>(D);
15897 unsigned Kind = TD->isEnum() ? 2 : TD->isUnion() ? 1 : 0;
15899 Diag(TD->getLocation(), diag::note_declared_at);
15905 if (!ExplicitThisLoc.
isValid())
15908 "explicit parameter in non-cplusplus mode");
15910 S.
Diag(ExplicitThisLoc, diag::err_cxx20_deducing_this)
15922 LSI->ExplicitObjectParameter = P;
15945 ? diag::ext_register_storage_class
15946 : diag::warn_deprecated_register)
15952 diag::err_invalid_storage_class_in_func_decl)
15961 diag::err_invalid_storage_class_in_func_decl);
15973 << 0 <<
static_cast<int>(D.
getDeclSpec().getConstexprSpecifier());
15994 PrevDecl =
nullptr;
16016 diag::err_hlsl_incomplete_resource_array_in_function_param);
16029 New->setInvalidDecl();
16048 Diag(
New->getLocation(), diag::err_module_private_local)
16052 if (
New->hasAttr<BlocksAttr>())
16053 Diag(
New->getLocation(), diag::err_block_not_allowed_on)
16054 << diag::NotAllowedBlockVarReason::NonlocalVariable;
16068 T,
Context.getTrivialTypeSourceInfo(
T, Loc),
16070 Param->setImplicit();
16083 !
Parameter->getIdentifier()->isPlaceholder()) {
16084 Diag(
Parameter->getLocation(), diag::warn_unused_parameter)
16092 if (
LangOpts.NumLargeByValueCopy == 0)
16098 unsigned Size =
Context.getTypeSizeInChars(ReturnTy).getQuantity();
16099 if (Size >
LangOpts.NumLargeByValueCopy)
16107 if (
T->isDependentType() || !
T.isPODType(
Context))
16109 unsigned Size =
Context.getTypeSizeInChars(
T).getQuantity();
16110 if (Size >
LangOpts.NumLargeByValueCopy)
16123 T->isObjCLifetimeType()) {
16130 if (
T->isArrayType()) {
16131 if (!
T.isConstQualified()) {
16135 NameLoc, diag::err_arc_array_param_no_ownership,
T,
false));
16137 Diag(NameLoc, diag::err_arc_array_param_no_ownership)
16142 lifetime =
T->getObjCARCImplicitLifetime();
16144 T =
Context.getLifetimeQualifiedType(
T, lifetime);
16149 if (
T->isArrayType() && !
T.hasAddressSpace()) {
16155 T =
Context.getAddrSpaceQualType(
T, ImplAS);
16162 Context.getAdjustedParameterType(
T),
16163 TSInfo, SC,
nullptr);
16168 if (
New->isParameterPack())
16170 CSI->LocalPacks.push_back(
New);
16172 if (
New->getType().hasNonTrivialToPrimitiveDestructCUnion() ||
16173 New->getType().hasNonTrivialToPrimitiveCopyCUnion())
16180 if (
T->isObjCObjectType()) {
16184 diag::err_object_cannot_be_passed_returned_by_value) << 1 <<
T
16186 T =
Context.getObjCObjectPointerType(
T);
16191 if (
T.getPointerAuth()) {
16192 Diag(NameLoc, diag::err_ptrauth_qualifier_invalid) <<
T << 1;
16193 New->setInvalidDecl();
16207 !(
T->isFunctionPointerType() &&
16213 Diag(NameLoc, diag::err_arg_with_address_space);
16214 New->setInvalidDecl();
16218 if (
Context.getTargetInfo().getTriple().isPPC64() &&
16219 PPC().CheckPPCMMAType(
New->getOriginalType(),
New->getLocation())) {
16220 New->setInvalidDecl();
16241 for (
int i = FTI.
NumParams; i != 0; ) {
16246 llvm::raw_svector_ostream(Code)
16257 const char* PrevSpec;
16260 DiagID,
Context.getPrintingPolicy());
16289 if (
LangOpts.OpenMP &&
OpenMP().isInOpenMPDeclareVariantScope())
16291 ParentScope, D, TemplateParameterLists, Bases);
16297 if (!Bases.empty())
16305 Consumer.HandleInlineFunctionDefinition(D);
16314 if (Prev->getLexicalDeclContext()->isFunctionOrMethod())
16317 PossiblePrototype = Prev;
16341 if (II->isStr(
"main") || II->isStr(
"efi_main"))
16360 if (FD->
hasAttr<DeviceKernelAttr>())
16409 bool DefinitionVisible =
false;
16412 DefinitionVisible) &&
16415 !
Definition->getTemplateParameterLists().empty())) {
16418 if (!DefinitionVisible) {
16419 if (
auto *TD =
Definition->getDescribedFunctionTemplate())
16433 Diag(
Definition->getLocation(), diag::note_previous_definition);
16442 LSI->
Lambda = LambdaClass;
16482 for (
const auto &
C : LambdaClass->
captures()) {
16483 if (
C.capturesVariable()) {
16487 const bool ByRef =
C.getCaptureKind() ==
LCK_ByRef;
16489 true,
C.getLocation(),
16490 C.isPackExpansion()
16492 I->getType(),
false);
16494 }
else if (
C.capturesThis()) {
16520 FD = FunTmpl->getTemplatedDecl();
16531 if (
const auto *
Attr = FD->
getAttr<AliasAttr>()) {
16536 if (
const auto *
Attr = FD->
getAttr<IFuncAttr>()) {
16541 if (
const auto *
Attr = FD->
getAttr<TargetVersionAttr>()) {
16542 if (
Context.getTargetInfo().getTriple().isAArch64() &&
16543 !
Context.getTargetInfo().hasFeature(
"fmv") &&
16544 !
Attr->isDefaultVersion()) {
16553 if (
auto *Ctor = dyn_cast<CXXConstructorDecl>(FD)) {
16555 Ctor->isDefaultConstructor() &&
16556 Context.getTargetInfo().getCXXABI().isMicrosoft()) {
16559 if (DLLExportAttr *
Attr = Ctor->getAttr<DLLExportAttr>())
16602 "There should be an active template instantiation on the stack "
16603 "when instantiating a generic lambda!");
16613 if (!
Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID) &&
16614 !
Context.BuiltinInfo.isPredefinedRuntimeFunction(BuiltinID)) {
16629 diag::err_func_def_incomplete_result) ||
16631 diag::err_abstract_type_in_decl,
16647 auto *NonParmDecl = dyn_cast<NamedDecl>(NPD);
16651 "parameters should not be in newly created FD yet");
16654 if (NonParmDecl->getDeclName())
16659 if (
auto *ED = dyn_cast<EnumDecl>(NonParmDecl)) {
16660 for (
auto *EI : ED->enumerators())
16668 Param->setOwningFunction(FD);
16671 if (Param->getIdentifier() && FnBodyScope) {
16708 assert(!FD->
hasAttr<DLLExportAttr>());
16709 Diag(FD->
getLocation(), diag::err_attribute_dllimport_function_definition);
16739 const auto *SKEPAttr = FD->
getAttr<SYCLKernelEntryPointAttr>();
16740 if (!SKEPAttr->isInvalidAttr()) {
16760 if (
auto *TD = dyn_cast<FunctionTemplateDecl>(FD))
16761 FD = TD->getTemplatedDecl();
16762 if (FD && FD->
hasAttr<OptimizeNoneAttr>()) {
16774 for (
unsigned I = 0, E =
Scope->Returns.size(); I != E; ++I) {
16775 if (
const VarDecl *NRVOCandidate = Returns[I]->getNRVOCandidate()) {
16776 if (!NRVOCandidate->isNRVOVariable()) {
16777 Diag(Returns[I]->getRetValue()->getExprLoc(),
16778 diag::warn_not_eliding_copy_on_return);
16798 Outer.Fun.hasTrailingReturnType()) {
16816 if (FD->isConstexpr())
16821 if (FD->getReturnType()->getContainedDeducedType())
16824 return Consumer.shouldSkipFunctionBody(D);
16831 FD->setHasSkippedBody();
16844 S.PopExpressionEvaluationContext();
16849 bool IsLambda =
false;
16853 llvm::DenseMap<const BlockDecl *, bool> EscapeInfo;
16855 auto IsOrNestedInEscapingBlock = [&](
const BlockDecl *BD) {
16856 auto [It, Inserted] = EscapeInfo.try_emplace(BD);
16870 return It->second = R;
16875 for (
const std::pair<SourceLocation, const BlockDecl *> &P :
16877 if (IsOrNestedInEscapingBlock(P.second))
16878 S.
Diag(P.first, diag::warn_implicitly_retains_self)
16893 methodHasName(FD,
"get_return_object_on_allocation_failure");
16903 if (!FD->
hasAttr<CoroWrapperAttr>())
16908 bool RetainFunctionScopeInfo) {
16935 SYCLKernelEntryPointAttr *SKEPAttr =
16936 FD->
getAttr<SYCLKernelEntryPointAttr>();
16938 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16939 << SKEPAttr << diag::InvalidSKEPReason::DefaultedFn;
16940 SKEPAttr->setInvalidAttr();
16942 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16943 << SKEPAttr << diag::InvalidSKEPReason::DeletedFn;
16944 SKEPAttr->setInvalidAttr();
16946 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16947 << SKEPAttr << diag::InvalidSKEPReason::Coroutine;
16948 SKEPAttr->setInvalidAttr();
16950 Diag(SKEPAttr->getLocation(), diag::err_sycl_entry_point_invalid)
16951 << SKEPAttr << diag::InvalidSKEPReason::FunctionTryBlock;
16952 SKEPAttr->setInvalidAttr();
16960 if (Body && !SKEPAttr->isInvalidAttr()) {
16990 SYCLExternalAttr *SEAttr = FD->
getAttr<SYCLExternalAttr>();
16992 Diag(SEAttr->getLocation(),
16993 diag::err_sycl_external_invalid_deleted_function)
17023 Expr *Dummy =
nullptr;
17034 if (LSI->HasImplicitReturnType) {
17041 LSI->ReturnType.isNull() ?
Context.VoidTy : LSI->ReturnType;
17045 FD->
setType(
Context.getFunctionType(RetType, Proto->getParamTypes(),
17046 Proto->getExtProtoInfo()));
17079 dyn_cast<CXXDestructorDecl>(FD))
17099 if (PossiblePrototype) {
17103 TypeLoc TL = TI->getTypeLoc();
17106 diag::note_declaration_not_a_prototype)
17109 FTL.getRParenLoc(),
"void")
17117 if (LocInfo.first.isInvalid())
17121 StringRef Buffer = SM.getBufferData(LocInfo.first, &
Invalid);
17125 if (LocInfo.second > Buffer.size())
17128 const char *LexStart = Buffer.data() + LocInfo.second;
17129 StringRef StartTok(LexStart, Buffer.size() - LocInfo.second);
17131 return StartTok.consume_front(
"const") &&
17133 StartTok.starts_with(
"/*") || StartTok.starts_with(
"//"));
17136 auto findBeginLoc = [&]() {
17152 diag::note_static_for_internal_linkage)
17163 if (!PossiblePrototype)
17209 if (PossiblePrototype)
17211 diag::warn_non_prototype_changes_behavior)
17218 if (
const auto *CmpndBody = dyn_cast<CompoundStmt>(Body))
17219 if (!CmpndBody->body_empty())
17220 Diag(CmpndBody->body_front()->getBeginLoc(),
17221 diag::warn_dispatch_body_ignored);
17223 if (
auto *MD = dyn_cast<CXXMethodDecl>(FD)) {
17231 !
Context.getTargetInfo().getCXXABI().canKeyFunctionBeInline()) {
17232 Context.setNonKeyFunction(MD);
17248 "Function parsing confused");
17249 }
else if (
ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
17261 << MD->getSelector().getAsString();
17266 bool isDesignated =
17267 MD->isDesignatedInitializerForTheInterface(&InitMethod);
17268 assert(isDesignated && InitMethod);
17269 (void)isDesignated;
17272 auto IFace = MD->getClassInterface();
17275 auto SuperD = IFace->getSuperClass();
17285 diag::warn_objc_designated_init_missing_super_call);
17287 diag::note_objc_designated_init_marked_here);
17295 diag::warn_objc_secondary_init_missing_init_call);
17310 else if (
AMDGPU().HasPotentiallyUnguardedBuiltinUsage(FD))
17315 "This should only be set for ObjC methods, which should have been "
17316 "handled in the block above.");
17331 if (!
Destructor->getParent()->isDependentType())
17349 ActivePolicy = &WP;
17352 if (!IsInstantiation && FD &&
17358 if (FD && FD->
hasAttr<NakedAttr>()) {
17362 bool RegisterVariables =
false;
17363 if (
auto *DS = dyn_cast<DeclStmt>(S)) {
17364 for (
const auto *
Decl : DS->decls()) {
17365 if (
const auto *Var = dyn_cast<VarDecl>(
Decl)) {
17366 RegisterVariables =
17367 Var->hasAttr<AsmLabelAttr>() && !Var->hasInit();
17368 if (!RegisterVariables)
17373 if (RegisterVariables)
17376 Diag(S->getBeginLoc(), diag::err_non_asm_stmt_in_naked_function);
17377 Diag(FD->
getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
17386 "Leftover temporaries in function");
17387 assert(!
Cleanup.exprNeedsCleanups() &&
17388 "Unaccounted cleanups in function");
17390 "Leftover expressions for odr-use checking");
17399 if (!IsInstantiation)
17402 if (!RetainFunctionScopeInfo)
17431 D = TD->getTemplatedDecl();
17443 assert(
LangOpts.implicitFunctionsAllowed() &&
17444 "Implicit function declarations aren't allowed in this language mode");
17451 Scope *BlockScope = S;
17459 Scope *ContextScope = BlockScope;
17463 ContextScope = ContextScope->
getParent();
17483 Diag(Loc, diag::ext_use_out_of_scope_declaration)
17486 return ExternCPrev;
17492 if (II.
getName().starts_with(
"__builtin_"))
17493 diag_id = diag::warn_builtin_unknown;
17496 diag_id = diag::ext_implicit_function_decl_c99;
17498 diag_id = diag::warn_implicit_function_decl;
17506 if (S && !ExternCPrev &&
17513 Diag(Loc, diag_id) << &II;
17529 return ExternCPrev;
17537 Context.getPrintingPolicy());
17539 assert(!
Error &&
"Error setting up implicit decl!");
17582 bool IsNothrow =
false;
17594 if (!IsNothrow && !FD->
hasAttr<ReturnsNonNullAttr>() &&
17612 if (!FD->
hasAttr<AllocSizeAttr>()) {
17613 FD->
addAttr(AllocSizeAttr::CreateImplicit(
17624 if (AlignmentParam && !FD->
hasAttr<AllocAlignAttr>()) {
17625 FD->
addAttr(AllocAlignAttr::CreateImplicit(
17649 unsigned FormatIdx;
17651 if (
Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) {
17652 if (!FD->
hasAttr<FormatAttr>()) {
17653 const char *fmt =
"printf";
17655 if (FormatIdx < NumParams &&
17661 HasVAListArg ? 0 : FormatIdx+2,
17665 if (
Context.BuiltinInfo.isScanfLike(BuiltinID, FormatIdx,
17667 if (!FD->
hasAttr<FormatAttr>())
17669 &
Context.Idents.get(
"scanf"),
17671 HasVAListArg ? 0 : FormatIdx+2,
17677 if (!FD->
hasAttr<CallbackAttr>() &&
17678 Context.BuiltinInfo.performsCallback(BuiltinID, Encoding))
17679 FD->
addAttr(CallbackAttr::CreateImplicit(
17685 bool NoExceptions =
17687 bool ConstWithoutErrnoAndExceptions =
17688 Context.BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID);
17689 bool ConstWithoutExceptions =
17690 Context.BuiltinInfo.isConstWithoutExceptions(BuiltinID);
17691 if (!FD->
hasAttr<ConstAttr>() &&
17692 (ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) &&
17693 (!ConstWithoutErrnoAndExceptions ||
17695 (!ConstWithoutExceptions || NoExceptions))
17701 const llvm::Triple &Trip =
Context.getTargetInfo().getTriple();
17702 if ((Trip.isGNUEnvironment() || Trip.isOSMSVCRT()) &&
17704 switch (BuiltinID) {
17705 case Builtin::BI__builtin_fma:
17706 case Builtin::BI__builtin_fmaf:
17707 case Builtin::BI__builtin_fmal:
17708 case Builtin::BIfma:
17709 case Builtin::BIfmaf:
17710 case Builtin::BIfmal:
17720 if (
Context.BuiltinInfo.isNonNull(BuiltinID, Indxs, OptMode) &&
17721 !FD->
hasAttr<NonNullAttr>()) {
17723 for (
int I : Indxs) {
17726 T =
Context.getAttributedType(attr::TypeNonNull,
T,
T);
17731 for (
int I : Indxs)
17732 ParamIndxs.push_back(
ParamIdx(I + 1, FD));
17733 FD->
addAttr(NonNullAttr::CreateImplicit(
Context, ParamIndxs.data(),
17734 ParamIndxs.size()));
17737 if (
Context.BuiltinInfo.isReturnsTwice(BuiltinID) &&
17738 !FD->
hasAttr<ReturnsTwiceAttr>())
17741 if (
Context.BuiltinInfo.isNoThrow(BuiltinID) && !FD->
hasAttr<NoThrowAttr>())
17743 if (
Context.BuiltinInfo.isPure(BuiltinID) && !FD->
hasAttr<PureAttr>())
17745 if (
Context.BuiltinInfo.isConst(BuiltinID) && !FD->
hasAttr<ConstAttr>())
17748 !FD->
hasAttr<CUDADeviceAttr>() && !FD->
hasAttr<CUDAHostAttr>()) {
17753 Context.BuiltinInfo.isAuxBuiltinID(BuiltinID))
17760 switch (BuiltinID) {
17761 case Builtin::BImemalign:
17762 case Builtin::BIaligned_alloc:
17763 if (!FD->
hasAttr<AllocAlignAttr>())
17772 switch (BuiltinID) {
17773 case Builtin::BIcalloc:
17774 FD->
addAttr(AllocSizeAttr::CreateImplicit(
17777 case Builtin::BImemalign:
17778 case Builtin::BIaligned_alloc:
17779 case Builtin::BIrealloc:
17783 case Builtin::BImalloc:
17803 if (!FPT || FPT->getExceptionSpecType() ==
EST_None)
17819 if (Name->
isStr(
"asprintf") || Name->
isStr(
"vasprintf")) {
17822 if (!FD->
hasAttr<FormatAttr>())
17824 &
Context.Idents.get(
"printf"), 2,
17825 Name->
isStr(
"vasprintf") ? 0 : 3,
17829 if (Name->
isStr(
"__CFStringMakeConstantString")) {
17832 if (!FD->
hasAttr<FormatArgAttr>())
17840 assert(D.
getIdentifier() &&
"Wrong callback for declspec without declarator");
17841 assert(!
T.isNull() &&
"GetTypeForDeclarator() returned null type");
17844 assert(D.
isInvalidType() &&
"no declarator info for valid type");
17845 TInfo =
Context.getTrivialTypeSourceInfo(
T);
17898 if (
T->isDependentType())
17908 if (
T->isAtomicType())
17909 Diag(UnderlyingLoc, diag::warn_atomic_stripped_in_enum);
17912 std::optional<unsigned> QualSelect;
17914 QualSelect = diag::CVQualList::Both;
17916 QualSelect = diag::CVQualList::Const;
17918 QualSelect = diag::CVQualList::Volatile;
17921 Diag(UnderlyingLoc, diag::warn_cv_stripped_in_enum) << *QualSelect;
17923 T =
T.getAtomicUnqualifiedType();
17928 if (BT->isInteger())
17931 return Diag(UnderlyingLoc, diag::err_enum_invalid_underlying)
17932 <<
T <<
T->isBitIntType();
17936 QualType EnumUnderlyingTy,
bool IsFixed,
17938 if (IsScoped != Prev->
isScoped()) {
17939 Diag(EnumLoc, diag::err_enum_redeclare_scoped_mismatch)
17945 if (IsFixed && Prev->
isFixed()) {
17948 !
Context.hasSameUnqualifiedType(EnumUnderlyingTy,
17951 Diag(EnumLoc, diag::err_enum_redeclare_type_mismatch)
17957 }
else if (IsFixed != Prev->
isFixed()) {
17958 Diag(EnumLoc, diag::err_enum_redeclare_fixed_mismatch)
17980 default: llvm_unreachable(
"Invalid tag kind for redecl diagnostic!");
18016 llvm_unreachable(
"invalid TTK");
18055 if (IsIgnoredLoc(NewTagLoc))
18058 auto IsIgnored = [&](
const TagDecl *Tag) {
18059 return IsIgnoredLoc(Tag->getLocation());
18076 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
18084 if (isDefinition) {
18092 bool previousMismatch =
false;
18094 if (I->getTagKind() !=
NewTag) {
18099 if (!previousMismatch) {
18100 previousMismatch =
true;
18101 Diag(NewTagLoc, diag::warn_struct_class_previous_tag_mismatch)
18105 Diag(I->getInnerLocStart(), diag::note_struct_class_suggestion)
18118 if (PrevDef && IsIgnored(PrevDef))
18122 Diag(NewTagLoc, diag::warn_struct_class_tag_mismatch)
18129 Diag(NewTagLoc, diag::note_struct_class_suggestion)
18159 if (!Namespace || Namespace->isAnonymousNamespace())
18162 Namespaces.push_back(II);
18165 if (Lookup == Namespace)
18172 llvm::raw_svector_ostream OS(Insertion);
18175 std::reverse(Namespaces.begin(), Namespaces.end());
18176 for (
auto *II : Namespaces)
18177 OS << II->getName() <<
"::";
18190 if (OldDC->
Equals(NewDC))
18209 bool ScopedEnumUsesClassTag,
TypeResult UnderlyingType,
18210 bool IsTypeSpecifier,
bool IsTemplateParamOrArg,
18215 "Nameless record must be a definition!");
18220 bool ScopedEnum = ScopedEnumKWLoc.
isValid();
18223 bool isMemberSpecialization =
false;
18224 bool IsInjectedClassName =
false;
18230 if (TemplateParameterLists.size() > 0 ||
18234 KWLoc, NameLoc, SS,
nullptr, TemplateParameterLists,
18251 !isMemberSpecialization)
18252 Diag(SS.
getBeginLoc(), diag::err_standalone_class_nested_name_specifier)
18255 if (TemplateParams) {
18257 Diag(KWLoc, diag::err_enum_template);
18261 if (TemplateParams->
size() > 0) {
18270 S, TagSpec, TUK, KWLoc, SS, Name, NameLoc, Attrs, TemplateParams,
18271 AS, ModulePrivateLoc,
18273 TemplateParameterLists.data(), isMemberSpecialization, SkipBody);
18279 isMemberSpecialization =
true;
18283 if (!TemplateParameterLists.empty() && isMemberSpecialization &&
18302 ScopedEnum ?
SourceRange(KWLoc, ScopedEnumKWLoc) : KWLoc);
18303 assert(ScopedEnum || !ScopedEnumUsesClassTag);
18304 Diag(KWLoc, diag::note_enum_friend)
18305 << (ScopedEnum + ScopedEnumUsesClassTag);
18311 llvm::PointerUnion<const Type*, TypeSourceInfo*> EnumUnderlying;
18312 bool IsFixed = !UnderlyingType.
isUnset() || ScopedEnum;
18315 if (UnderlyingType.
isInvalid() || (!UnderlyingType.
get() && ScopedEnum) ||
18319 EnumUnderlying =
Context.IntTy.getTypePtr();
18320 }
else if (UnderlyingType.
get()) {
18328 EnumUnderlying = TI;
18332 EnumUnderlying =
Context.IntTy.getTypePtr();
18336 EnumUnderlying =
Context.IntTy.getTypePtr();
18346 if (
TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying);
18347 TI && TI->
getType()->isAtomicType())
18350 }
else if (
Context.getTargetInfo().getTriple().isWindowsMSVCEnvironment()) {
18356 EnumUnderlying =
Context.IntTy.getTypePtr();
18362 bool isStdBadAlloc =
false;
18363 bool isStdAlignValT =
false;
18372 auto createTagFromNewDecl = [&]() ->
TagDecl * {
18382 ScopedEnum, ScopedEnumUsesClassTag, IsFixed);
18386 if (EnumUnderlying) {
18388 if (
TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
18394 ?
Context.getPromotedIntegerType(EnumTy)
18415 RD->addAttr(PackedAttr::CreateImplicit(
Context));
18431 goto CreateNewDecl;
18439 IsDependent =
true;
18468 if (
Previous.wasNotFoundInCurrentInstantiation() &&
18470 IsDependent =
true;
18475 Diag(NameLoc, diag::err_not_tag_in_scope)
18476 << Kind << Name << DC << SS.
getRange();
18479 goto CreateNewDecl;
18527 bool FriendSawTagOutsideEnclosingNamespace =
false;
18534 FriendSawTagOutsideEnclosingNamespace =
true;
18543 if (
Previous.isSingleResult() && FriendSawTagOutsideEnclosingNamespace) {
18545 Diag(NameLoc, diag::ext_friend_tag_redecl_outside_namespace)
18576 Previous.getFoundDecl()->isTemplateParameter()) {
18585 if (Name->
isStr(
"bad_alloc")) {
18587 isStdBadAlloc =
true;
18594 }
else if (Name->
isStr(
"align_val_t")) {
18595 isStdAlignValT =
true;
18607 IsTemplateParamOrArg)) {
18608 if (
Invalid)
goto CreateNewDecl;
18691 if (
TagDecl *Tag = TD->getUnderlyingType()->getAsTagDecl()) {
18692 if (Tag->getDeclName() == Name &&
18693 Tag->getDeclContext()->getRedeclContext()
18694 ->Equals(TD->getDeclContext()->getRedeclContext())) {
18707 if (
auto *Shadow = dyn_cast<UsingShadowDecl>(DirectPrevDecl)) {
18708 auto *OldTag = dyn_cast<TagDecl>(PrevDecl);
18711 isDeclInScope(Shadow, SearchDC, S, isMemberSpecialization) &&
18713 *
this, OldTag->getDeclContext(), SearchDC))) {
18714 Diag(KWLoc, diag::err_using_decl_conflict_reverse);
18715 Diag(Shadow->getTargetDecl()->getLocation(),
18716 diag::note_using_decl_target);
18717 Diag(Shadow->getIntroducer()->getLocation(), diag::note_using_decl)
18721 goto CreateNewDecl;
18725 if (
TagDecl *PrevTagDecl = dyn_cast<TagDecl>(PrevDecl)) {
18732 isMemberSpecialization)) {
18734 if (
auto *RD = dyn_cast<CXXRecordDecl>(PrevDecl);
18735 RD && RD->isInjectedClassName()) {
18742 IsInjectedClassName =
true;
18750 bool SafeToContinue =
18753 if (SafeToContinue)
18754 Diag(KWLoc, diag::err_use_with_wrong_tag)
18757 PrevTagDecl->getKindName());
18759 Diag(KWLoc, diag::err_use_with_wrong_tag) << Name;
18760 Diag(PrevTagDecl->getLocation(), diag::note_previous_use);
18762 if (SafeToContinue)
18763 Kind = PrevTagDecl->getTagKind();
18776 return PrevTagDecl;
18780 dyn_cast_if_present<TypeSourceInfo *>(EnumUnderlying))
18781 EnumUnderlyingTy = TI->getType().getUnqualifiedType();
18782 else if (
const Type *
T =
18783 dyn_cast_if_present<const Type *>(EnumUnderlying))
18790 ScopedEnum, EnumUnderlyingTy,
18791 IsFixed, PrevEnum))
18801 Diag(NameLoc, diag::ext_member_redeclared);
18802 Diag(PrevTagDecl->getLocation(), diag::note_previous_declaration);
18811 if (
const auto *OutermostClass = dyn_cast<CXXRecordDecl>(PrevDecl)) {
18812 while (
const auto *ParentClass =
18813 dyn_cast<CXXRecordDecl>(OutermostClass->getParent()))
18814 OutermostClass = ParentClass;
18816 if (OutermostClass->isLocalClass() &&
18818 Diag(NameLoc, diag::err_local_nested_class_invalid_scope)
18819 << Name << OutermostClass;
18820 Diag(OutermostClass->getLocation(), diag::note_defined_here)
18830 if (!Attrs.
empty()) {
18834 (PrevTagDecl->getFriendObjectKind() ==
18847 return PrevTagDecl;
18852 return PrevTagDecl;
18861 if (Def->isBeingDefined()) {
18862 Diag(NameLoc, diag::err_nested_redefinition) << Name;
18863 Diag(PrevTagDecl->getLocation(),
18864 diag::note_previous_definition);
18872 bool IsExplicitSpecializationAfterInstantiation =
false;
18873 if (isMemberSpecialization) {
18875 IsExplicitSpecializationAfterInstantiation =
18876 RD->getTemplateSpecializationKind() !=
18878 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(Def))
18879 IsExplicitSpecializationAfterInstantiation =
18880 ED->getTemplateSpecializationKind() !=
18889 bool HiddenDefVisible =
false;
18891 HiddenDefVisible) ||
18903 SkipBody->
New = createTagFromNewDecl();
18912 if (!HiddenDefVisible && Hidden)
18917 }
else if (!IsExplicitSpecializationAfterInstantiation) {
18922 Diag(NameLoc, diag::warn_redefinition_in_param_list)
18925 Diag(NameLoc, diag::err_redefinition) << Name;
18927 NameLoc.
isValid() ? NameLoc : KWLoc);
18946 IsInjectedClassName) {
18947 SearchDC = PrevTagDecl->getDeclContext();
18975 Diag(NameLoc, diag::err_tag_reference_non_tag)
18976 << PrevDecl << NTK << Kind;
18982 SS.
isNotEmpty() || isMemberSpecialization)) {
18988 Diag(NameLoc, diag::err_tag_reference_conflict) << NTK;
18994 }
else if (
TypedefNameDecl *TND = dyn_cast<TypedefNameDecl>(PrevDecl)) {
18997 Diag(NameLoc, diag::err_tag_definition_of_typedef)
18998 << Name << Kind << TND->getUnderlyingType();
19006 Diag(NameLoc, diag::err_redefinition_different_kind) << Name;
19038 cast_or_null<EnumDecl>(PrevDecl), ScopedEnum,
19039 ScopedEnumUsesClassTag, IsFixed);
19043 KWLoc, ScopedEnumKWLoc.
isValid() ? ScopedEnumKWLoc : KWLoc));
19051 if (IsFixed && ED->
isFixed()) {
19054 }
else if (PrevDecl &&
19056 Diag(Loc, diag::ext_forward_ref_enum_def)
19060 unsigned DiagID = diag::ext_forward_ref_enum;
19062 DiagID = diag::ext_ms_forward_ref_enum;
19064 DiagID = diag::err_forward_ref_enum;
19069 if (EnumUnderlying) {
19071 if (
TypeSourceInfo *TI = dyn_cast<TypeSourceInfo *>(EnumUnderlying))
19077 ?
Context.getPromotedIntegerType(EnumTy)
19079 assert(ED->
isComplete() &&
"enum with type should be complete");
19089 cast_or_null<CXXRecordDecl>(PrevDecl));
19095 cast_or_null<RecordDecl>(PrevDecl));
19101 Diag(
New->getLocation(), diag::ext_type_defined_in_offsetof)
19107 (IsTypeSpecifier || IsTemplateParamOrArg) &&
19109 Diag(
New->getLocation(), diag::err_type_defined_in_type_specifier)
19116 Diag(
New->getLocation(), diag::err_type_defined_in_enum)
19129 isMemberSpecialization))
19133 if (TemplateParameterLists.size() > 0) {
19134 New->setTemplateParameterListsInfo(
Context, TemplateParameterLists);
19153 RD->addAttr(PackedAttr::CreateImplicit(
Context));
19159 if (ModulePrivateLoc.
isValid()) {
19160 if (isMemberSpecialization)
19161 Diag(
New->getLocation(), diag::err_module_private_specialization)
19168 New->setModulePrivate();
19188 Diag(Loc, diag::err_type_defined_in_param_type)
19194 }
else if (!PrevDecl) {
19198 Diag(Loc, diag::warn_decl_in_param_list)
19204 New->setInvalidDecl();
19231 New->startDefinition();
19233 New->setCompleteDefinition();
19234 New->demoteThisDefinitionToDeclaration();
19262 if (!
New->isInvalidDecl() &&
19263 New->getDeclContext()->getRedeclContext()->isTranslationUnit() &&
19270 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(
New)) {
19283 if (isMemberSpecialization && !
New->isInvalidDecl())
19290 if (
New->isBeingDefined())
19291 if (
auto RD = dyn_cast<RecordDecl>(
New))
19292 RD->completeDefinition();
19294 }
else if (SkipBody && SkipBody->
ShouldSkip) {
19328 bool IsFinalSpelledSealed,
19336 if (!
Record->getIdentifier())
19344 IsFinalSpelledSealed
19345 ? FinalAttr::Keyword_sealed
19346 : FinalAttr::Keyword_final));
19364 "Broken injected-class-name");
19371 Tag->setBraceRange(BraceRange);
19374 if (Tag->isBeingDefined()) {
19375 assert(Tag->isInvalidDecl() &&
"We should already have completed it");
19376 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
19377 RD->completeDefinition();
19380 if (
auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
19382 if (RD->hasAttr<SYCLSpecialClassAttr>()) {
19383 auto *Def = RD->getDefinition();
19384 assert(Def &&
"The record is expected to have a completed definition");
19385 unsigned NumInitMethods = 0;
19386 for (
auto *
Method : Def->methods()) {
19387 if (!
Method->getIdentifier())
19389 if (
Method->getName() ==
"__init")
19392 if (NumInitMethods > 1 || !Def->hasInitMethod())
19393 Diag(RD->getLocation(), diag::err_sycl_special_type_num_init_method);
19411 Tag->setTopLevelDeclInObjCContainer();
19414 if (!Tag->isInvalidDecl())
19415 Consumer.HandleTagDeclDefinition(Tag);
19419 if (
Context.getTargetInfo().getTriple().isOSAIX() &&
19425 const RecordDecl *RD = dyn_cast<RecordDecl>(Tag);
19429 if (llvm::any_of(RD->
fields(),
19430 [](
const FieldDecl *FD) { return FD->isBitField(); }))
19431 Diag(BraceRange.
getBegin(), diag::warn_pragma_align_not_xl_compatible);
19438 Tag->setInvalidDecl();
19441 if (Tag->isBeingDefined()) {
19442 if (
RecordDecl *RD = dyn_cast<RecordDecl>(Tag))
19443 RD->completeDefinition();
19456 QualType FieldTy,
bool IsMsStruct,
19467 diag::err_field_incomplete_or_sizeless))
19470 return Diag(FieldLoc, diag::err_not_integral_type_bitfield)
19472 return Diag(FieldLoc, diag::err_not_integral_type_anon_bitfield)
19482 llvm::APSInt
Value;
19487 BitWidth = ICE.
get();
19490 if (
Value == 0 && FieldName)
19491 return Diag(FieldLoc, diag::err_bitfield_has_zero_width)
19494 if (
Value.isSigned() &&
Value.isNegative()) {
19496 return Diag(FieldLoc, diag::err_bitfield_has_negative_width)
19498 return Diag(FieldLoc, diag::err_anon_bitfield_has_negative_width)
19505 return Diag(FieldLoc, diag::err_bitfield_too_wide)
19510 uint64_t TypeStorageSize =
Context.getTypeSize(FieldTy);
19511 uint64_t TypeWidth =
Context.getIntWidth(FieldTy);
19512 bool BitfieldIsOverwide =
Value.ugt(TypeWidth);
19516 bool CStdConstraintViolation =
19518 bool MSBitfieldViolation =
Value.ugt(TypeStorageSize) && IsMsStruct;
19519 if (CStdConstraintViolation || MSBitfieldViolation) {
19520 unsigned DiagWidth =
19521 CStdConstraintViolation ? TypeWidth : TypeStorageSize;
19522 return Diag(FieldLoc, diag::err_bitfield_width_exceeds_type_width)
19524 << !CStdConstraintViolation << DiagWidth;
19530 if (BitfieldIsOverwide && !FieldTy->
isBooleanType() && FieldName) {
19531 Diag(FieldLoc, diag::warn_bitfield_width_exceeds_type_width)
19574 TInfo =
Context.getTrivialTypeSourceInfo(
T, Loc);
19585 diag::err_invalid_thread)
19593 switch (
Previous.getResultKind()) {
19600 PrevDecl =
Previous.getRepresentativeDecl();
19614 PrevDecl =
nullptr;
19618 PrevDecl =
nullptr;
19625 TSSL, AS, PrevDecl, &D);
19628 Record->setInvalidDecl();
19647 bool Mutable,
Expr *BitWidth,
19653 bool InvalidDecl =
false;
19658 if (
T.isNull() ||
T->containsErrors()) {
19659 InvalidDecl =
true;
19665 bool isIncomplete =
19669 diag::err_field_incomplete_or_sizeless);
19670 if (isIncomplete) {
19672 Record->setInvalidDecl();
19673 InvalidDecl =
true;
19678 Record->setInvalidDecl();
19679 InvalidDecl =
true;
19685 if (
T.hasAddressSpace() ||
T->isDependentAddressSpaceType() ||
19686 T->getBaseElementTypeUnsafe()->isDependentAddressSpaceType()) {
19687 Diag(Loc, diag::err_field_with_address_space);
19688 Record->setInvalidDecl();
19689 InvalidDecl =
true;
19695 if (
T->isEventT() ||
T->isImageType() ||
T->isSamplerT() ||
19696 T->isBlockPointerType()) {
19697 Diag(Loc, diag::err_opencl_type_struct_or_union_field) <<
T;
19698 Record->setInvalidDecl();
19699 InvalidDecl =
true;
19704 "__cl_clang_bitfields",
LangOpts)) {
19705 Diag(Loc, diag::err_opencl_bitfields);
19706 InvalidDecl =
true;
19712 T.hasQualifiers()) {
19713 InvalidDecl =
true;
19714 Diag(Loc, diag::err_anon_bitfield_qualifiers);
19719 if (!InvalidDecl &&
T->isVariablyModifiedType()) {
19721 TInfo,
T, Loc, diag::err_typecheck_field_variable_size))
19722 InvalidDecl =
true;
19727 diag::err_abstract_type_in_decl,
19729 InvalidDecl =
true;
19732 BitWidth =
nullptr;
19738 InvalidDecl =
true;
19739 BitWidth =
nullptr;
19744 if (!InvalidDecl && Mutable) {
19745 unsigned DiagID = 0;
19746 if (
T->isReferenceType())
19747 DiagID =
getLangOpts().MSVCCompat ? diag::ext_mutable_reference
19748 : diag::err_mutable_reference;
19749 else if (
T.isConstQualified())
19750 DiagID = diag::err_mutable_const;
19756 Diag(ErrLoc, DiagID);
19757 if (DiagID != diag::ext_mutable_reference) {
19759 InvalidDecl =
true;
19771 BitWidth, Mutable, InitStyle);
19780 Diag(Loc, diag::err_duplicate_member) << II;
19786 if (
Record->isUnion()) {
19788 RD && (RD->isBeingDefined() || RD->isCompleteDefinition())) {
19803 const bool HaveMSExt =
19808 HaveMSExt ? diag::ext_union_member_of_reference_type
19809 : diag::err_union_member_of_reference_type)
19829 if (
getLangOpts().ObjCAutoRefCount &&
ObjC().inferObjCARCLifetime(NewFD))
19832 if (
T.isObjCGCWeak())
19833 Diag(Loc, diag::warn_attribute_weak_on_field);
19836 if (
Context.getTargetInfo().getTriple().isPPC64() &&
19840 if (
Context.getTargetInfo().hasAMDGPUTypes()) {
19858 RDecl && (RDecl->isBeingDefined() || RDecl->isCompleteDefinition())) {
19869 if (RDecl->hasNonTrivialCopyConstructor())
19871 else if (!RDecl->hasTrivialDefaultConstructor())
19873 else if (RDecl->hasNonTrivialCopyAssignment())
19875 else if (RDecl->hasNonTrivialDestructor())
19880 RDecl->hasObjectMember()) {
19888 if (!FD->
hasAttr<UnavailableAttr>())
19889 FD->
addAttr(UnavailableAttr::CreateImplicit(
19890 Context,
"", UnavailableAttr::IR_ARCFieldWithOwnership, Loc));
19897 ? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
19898 : diag::err_illegal_union_or_anon_struct_member)
19910 if (
LangOpts.ObjCRuntime.isFragile() || AllIvarDecls.empty())
19913 Decl *ivarDecl = AllIvarDecls[AllIvarDecls.size()-1];
19921 if (!CD->IsClassExtension())
19938 AllIvarDecls.push_back(Ivar);
19950 if (!
Record->hasUserDeclaredDestructor()) {
19958 if (
auto *DD = dyn_cast<CXXDestructorDecl>(
Decl)) {
19959 if (DD->isInvalidDecl())
19963 assert(DD->isIneligibleOrNotSelected() &&
"Selecting a destructor but a destructor was already selected.");
19977 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(Best->Function));
19981 Msg = diag::err_ambiguous_destructor;
19986 Msg = diag::err_no_viable_destructor;
19997 Record->setInvalidDecl();
20004 Record->addedSelectedDestructor(dyn_cast<CXXDestructorDecl>(OCS.
begin()->Function));
20048 if (!Method->getTrailingRequiresClause())
20049 SatisfactionStatus.push_back(
true);
20053 SatisfactionStatus.push_back(
false);
20055 SatisfactionStatus.push_back(Satisfaction.
IsSatisfied);
20059 for (
size_t i = 0; i < Methods.size(); i++) {
20060 if (!SatisfactionStatus[i])
20068 bool AnotherMethodIsMoreConstrained =
false;
20069 for (
size_t j = 0; j < Methods.size(); j++) {
20070 if (i == j || !SatisfactionStatus[j])
20084 AnotherMethodIsMoreConstrained =
true;
20088 AnotherMethodIsMoreConstrained)) {
20091 AnotherMethodIsMoreConstrained =
true;
20093 if (AnotherMethodIsMoreConstrained)
20098 if (!AnotherMethodIsMoreConstrained) {
20099 Method->setIneligibleOrNotSelected(
false);
20100 Record->addedEligibleSpecialMemberFunction(Method,
20101 1 << llvm::to_underlying(CSM));
20115 auto *MD = dyn_cast<CXXMethodDecl>(
Decl);
20117 auto *FTD = dyn_cast<FunctionTemplateDecl>(
Decl);
20119 MD = dyn_cast<CXXMethodDecl>(FTD->getTemplatedDecl());
20123 if (
auto *CD = dyn_cast<CXXConstructorDecl>(MD)) {
20124 if (CD->isInvalidDecl())
20126 if (CD->isDefaultConstructor())
20127 DefaultConstructors.push_back(MD);
20128 else if (CD->isCopyConstructor())
20129 CopyConstructors.push_back(MD);
20130 else if (CD->isMoveConstructor())
20131 MoveConstructors.push_back(MD);
20133 CopyAssignmentOperators.push_back(MD);
20135 MoveAssignmentOperators.push_back(MD);
20153 auto IsFunctionPointerOrForwardDecl = [&](
const Decl *D) {
20154 const FieldDecl *FD = dyn_cast<FieldDecl>(D);
20167 if (
const auto *TD = dyn_cast<TagDecl>(D))
20168 return !TD->isCompleteDefinition();
20183 return llvm::all_of(
Record->decls(), IsFunctionPointerOrForwardDecl);
20190 assert(EnclosingDecl &&
"missing record or interface decl");
20199 case Decl::ObjCCategory:
20202 case Decl::ObjCImplementation:
20210 CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(EnclosingDecl);
20214 unsigned NumNamedMembers = 0;
20216 for (
const auto *I :
Record->decls()) {
20217 if (
const auto *IFD = dyn_cast<IndirectFieldDecl>(I))
20218 if (IFD->getDeclName())
20225 const FieldDecl *PreviousField =
nullptr;
20235 RecFields.push_back(FD);
20255 bool IsLastField = (i + 1 == Fields.end());
20270 unsigned DiagID = 0;
20271 if (!
Record->isUnion() && !IsLastField) {
20274 Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
20278 }
else if (
Record->isUnion())
20280 ? diag::ext_flexible_array_union_ms
20281 : diag::ext_flexible_array_union_gnu;
20282 else if (NumNamedMembers < 1)
20284 ? diag::ext_flexible_array_empty_aggregate_ms
20285 : diag::ext_flexible_array_empty_aggregate_gnu;
20295 if (CXXRecord && CXXRecord->getNumVBases() != 0)
20309 Diag(FD->
getLocation(), diag::err_flexible_array_has_nontrivial_dtor)
20316 Record->setHasFlexibleArrayMember(
true);
20325 diag::err_incomplete_type)
20328 diag::err_field_incomplete_or_sizeless))) {
20334 if (
Record && RD->hasFlexibleArrayMember()) {
20337 Record->setHasFlexibleArrayMember(
true);
20338 if (!
Record->isUnion()) {
20355 diag::err_abstract_type_in_decl,
20360 if (
Record && RD->hasObjectMember())
20361 Record->setHasObjectMember(
true);
20362 if (
Record && RD->hasVolatileMember())
20363 Record->setHasVolatileMember(
true);
20382 FD->
addAttr(UnavailableAttr::CreateImplicit(
20383 Context,
"", UnavailableAttr::IR_ARCFieldWithOwnership,
20387 !
Record->hasObjectMember()) {
20390 Record->setHasObjectMember(
true);
20393 if (
const auto *RD = BaseType->getAsRecordDecl();
20394 RD && RD->hasObjectMember())
20395 Record->setHasObjectMember(
true);
20396 else if (BaseType->isObjCObjectPointerType() ||
20397 BaseType.isObjCGCStrong())
20398 Record->setHasObjectMember(
true);
20403 !shouldIgnoreForRecordTriviality(FD)) {
20406 Record->setNonTrivialToPrimitiveDefaultInitialize(
true);
20409 Record->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(
true);
20413 Record->setNonTrivialToPrimitiveCopy(
true);
20415 Record->setHasNonTrivialToPrimitiveCopyCUnion(
true);
20417 if (FD->
hasAttr<ExplicitInitAttr>())
20418 Record->setHasUninitializedExplicitInitFields(
true);
20420 Record->setNonTrivialToPrimitiveDestroy(
true);
20421 Record->setParamDestroyedInCallee(
true);
20423 Record->setHasNonTrivialToPrimitiveDestructCUnion(
true);
20427 if (RD->getArgPassingRestrictions() ==
20429 Record->setArgPassingRestrictions(
20432 Record->setArgPassingRestrictions(
20436 Record->setArgPassingRestrictions(
20438 Record->setNonTrivialToPrimitiveCopy(
true);
20443 Record->setHasVolatileMember(
true);
20444 bool ReportMSBitfieldStoragePacking =
20445 Record && PreviousField &&
20446 !
Diags.isIgnored(diag::warn_ms_bitfield_mismatched_storage_packing,
20448 auto IsNonDependentBitField = [](
const FieldDecl *FD) {
20452 if (ReportMSBitfieldStoragePacking && IsNonDependentBitField(FD) &&
20453 IsNonDependentBitField(PreviousField)) {
20457 if (FDStorageSize != PreviousFieldStorageSize) {
20459 diag::warn_ms_bitfield_mismatched_storage_packing)
20463 diag::note_ms_bitfield_mismatched_storage_size_previous)
20464 << PreviousField << PreviousField->
getType();
20474 bool Completed =
false;
20479 Record->setInvalidDecl();
20483 if (!CXXRecord->isInvalidDecl()) {
20486 I = CXXRecord->conversion_begin(),
20487 E = CXXRecord->conversion_end(); I != E; ++I)
20488 I.setAccess((*I)->getAccess());
20494 if (!CXXRecord->isDependentType()) {
20495 if (!CXXRecord->isInvalidDecl()) {
20499 if (CXXRecord->getNumVBases()) {
20501 CXXRecord->getFinalOverriders(FinalOverriders);
20503 for (CXXFinalOverriderMap::iterator M = FinalOverriders.begin(),
20504 MEnd = FinalOverriders.end();
20507 SOEnd = M->second.end();
20508 SO != SOEnd; ++SO) {
20509 assert(SO->second.size() > 0 &&
20510 "Virtual function without overriding functions?");
20511 if (SO->second.size() == 1)
20518 Diag(
Record->getLocation(), diag::err_multiple_final_overriders)
20520 Diag(M->first->getLocation(),
20521 diag::note_overridden_virtual_function);
20523 OM = SO->second.begin(),
20524 OMEnd = SO->second.end();
20526 Diag(OM->Method->getLocation(), diag::note_final_overrider)
20527 << (
const NamedDecl *)M->first << OM->Method->getParent();
20529 Record->setInvalidDecl();
20532 CXXRecord->completeDefinition(&FinalOverriders);
20542 Record->completeDefinition();
20551 (
Record->hasAttr<RandomizeLayoutAttr>() ||
20552 (!
Record->hasAttr<NoRandomizeLayoutAttr>() &&
20553 EntirelyFunctionPointers(
Record)))) {
20557 Record->reorderDecls(NewDeclOrdering);
20562 auto *Dtor = CXXRecord->getDestructor();
20563 if (Dtor && Dtor->isImplicit() &&
20565 CXXRecord->setImplicitDestructorIsDeleted();
20570 if (
Record->hasAttrs()) {
20573 if (
const MSInheritanceAttr *IA =
Record->getAttr<MSInheritanceAttr>())
20575 IA->getRange(), IA->getBestCase(),
20576 IA->getInheritanceModel());
20582 bool CheckForZeroSize;
20584 CheckForZeroSize =
true;
20589 CXXRecord->getLexicalDeclContext()->isExternCContext() &&
20591 CXXRecord->isCLike();
20593 if (CheckForZeroSize) {
20594 bool ZeroSize =
true;
20595 bool IsEmpty =
true;
20596 unsigned NonBitFields = 0;
20598 E =
Record->field_end();
20599 (NonBitFields == 0 || ZeroSize) && I != E; ++I) {
20601 if (I->isUnnamedBitField()) {
20602 if (!I->isZeroLengthBitField())
20606 QualType FieldType = I->getType();
20608 !
Context.getTypeSizeInChars(FieldType).isZero())
20618 diag::warn_zero_size_struct_union_in_extern_c :
20619 diag::warn_zero_size_struct_union_compat)
20620 << IsEmpty <<
Record->isUnion() << (NonBitFields > 1);
20627 Diag(RecLoc, IsEmpty ? diag::ext_empty_struct_union
20628 : diag::ext_no_named_members_in_struct_union)
20636 ID->setEndOfDefinitionLoc(RBrac);
20638 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
20640 ID->addDecl(ClsFields[i]);
20644 if (ID->getSuperClass())
20647 dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {
20648 assert(IMPDecl &&
"ActOnFields - missing ObjCImplementationDecl");
20649 for (
unsigned I = 0, N = RecFields.size(); I != N; ++I)
20655 IMPDecl->setIvarLBraceLoc(LBrac);
20656 IMPDecl->setIvarRBraceLoc(RBrac);
20658 dyn_cast<ObjCCategoryDecl>(EnclosingDecl)) {
20666 for (
unsigned i = 0, e = RecFields.size(); i != e; ++i) {
20670 Diag(ClsFields[i]->getLocation(),
20671 diag::err_duplicate_ivar_declaration);
20672 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
20678 Diag(ClsFields[i]->getLocation(),
20679 diag::err_duplicate_ivar_declaration);
20680 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
20686 CDecl->addDecl(ClsFields[i]);
20688 CDecl->setIvarLBraceLoc(LBrac);
20689 CDecl->setIvarRBraceLoc(RBrac);
20705 assert((
T->isIntegralType(Context) ||
20706 T->isEnumeralType()) &&
"Integral type required!");
20707 const unsigned NumTypes = 4;
20708 QualType SignedIntegralTypes[NumTypes] = {
20709 Context.ShortTy, Context.IntTy, Context.LongTy, Context.LongLongTy
20711 QualType UnsignedIntegralTypes[NumTypes] = {
20712 Context.UnsignedShortTy, Context.UnsignedIntTy, Context.UnsignedLongTy,
20713 Context.UnsignedLongLongTy
20720 unsigned BitWidth = Context.getIntWidth(
T);
20721 QualType *Types =
T->isSignedIntegerOrEnumerationType()? SignedIntegralTypes
20722 : UnsignedIntegralTypes;
20723 for (
unsigned I = 0; I != NumTypes; ++I)
20724 if (Context.getTypeSize(Types[I]) > BitWidth)
20735 unsigned IntWidth =
Context.getTargetInfo().getIntWidth();
20736 llvm::APSInt EnumVal(IntWidth);
20756 EltTy =
Enum->getIntegerType();
20762 Val = Converted.
get();
20769 if (
Enum->isComplete()) {
20770 EltTy =
Enum->getIntegerType();
20776 if (!
Context.isRepresentableIntegerValue(EnumVal, EltTy)) {
20779 .isWindowsMSVCEnvironment()) {
20780 Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy;
20782 Diag(IdLoc, diag::err_enumerator_too_large) << EltTy;
20805 if (!
Context.isRepresentableIntegerValue(EnumVal,
Context.IntTy)) {
20807 ? diag::warn_c17_compat_enum_value_not_int
20808 : diag::ext_c23_enum_value_not_int)
20810 << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
20822 if (
Enum->isDependentType())
20824 else if (!LastEnumConst) {
20833 if (
Enum->isFixed()) {
20834 EltTy =
Enum->getIntegerType();
20843 EltTy = LastEnumConst->
getType();
20846 if (EnumVal < LastEnumConst->getInitVal()) {
20858 if (
T.isNull() ||
Enum->isFixed()) {
20862 EnumVal = EnumVal.zext(EnumVal.getBitWidth() * 2);
20864 if (
Enum->isFixed())
20866 Diag(IdLoc, diag::err_enumerator_wrapped)
20870 Diag(IdLoc, diag::ext_enumerator_increment_too_large)
20881 EnumVal = EnumVal.zextOrTrunc(
Context.getIntWidth(EltTy));
20893 ? diag::warn_c17_compat_enum_value_not_int
20894 : diag::ext_c23_enum_value_not_int)
20895 << 1 <<
toString(EnumVal, 10) << 1;
20897 !
Context.isRepresentableIntegerValue(EnumVal, EltTy)) {
20900 : diag::ext_c23_enum_value_not_int)
20901 << 1 <<
toString(EnumVal, 10) << 1;
20909 EnumVal = EnumVal.extOrTrunc(
Context.getIntWidth(EltTy));
20928 auto *PrevECD = dyn_cast_or_null<EnumConstantDecl>(PrevDecl);
20936 Skip.Previous = Hidden;
20950 cast_or_null<EnumConstantDecl>(lastEnumConst);
20967 PrevDecl =
nullptr;
20994 "Received TagDecl when not in C++!");
20997 Diag(IdLoc, diag::err_redefinition_of_enumerator) << Id;
20999 Diag(IdLoc, diag::err_redefinition) << Id;
21032 if (!BO->isAdditiveOp())
21040 InitExpr = BO->getLHS();
21044 DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(InitExpr);
21064 if (!
Enum->getIdentifier())
21068 if (
Enum->getNumPositiveBits() > 63 ||
Enum->getNumNegativeBits() > 64)
21077 typedef llvm::PointerUnion<EnumConstantDecl*, ECDVector*> DeclOrVector;
21080 typedef std::unordered_map<int64_t, DeclOrVector> ValueToVectorMap;
21084 llvm::APSInt Val = D->getInitVal();
21085 return Val.isSigned() ? Val.getSExtValue() : Val.getZExtValue();
21088 DuplicatesVector DupVector;
21089 ValueToVectorMap EnumMap;
21093 for (
auto *Element : Elements) {
21107 EnumMap.insert({EnumConstantToKey(ECD), ECD});
21110 if (EnumMap.size() == 0)
21114 for (
auto *Element : Elements) {
21120 auto Iter = EnumMap.find(EnumConstantToKey(ECD));
21121 if (Iter == EnumMap.end())
21124 DeclOrVector& Entry = Iter->second;
21131 auto Vec = std::make_unique<ECDVector>();
21133 Vec->push_back(ECD);
21140 DupVector.emplace_back(std::move(Vec));
21146 if (*Vec->begin() == ECD)
21149 Vec->push_back(ECD);
21153 for (
const auto &Vec : DupVector) {
21154 assert(Vec->size() > 1 &&
"ECDVector should have at least 2 elements.");
21157 auto *FirstECD = Vec->front();
21158 S.
Diag(FirstECD->getLocation(), diag::warn_duplicate_enum_values)
21159 << FirstECD <<
toString(FirstECD->getInitVal(), 10)
21160 << FirstECD->getSourceRange();
21164 for (
auto *ECD : llvm::drop_begin(*Vec))
21165 S.
Diag(ECD->getLocation(), diag::note_duplicate_element)
21166 << ECD <<
toString(ECD->getInitVal(), 10)
21167 << ECD->getSourceRange();
21172 bool AllowMask)
const {
21173 assert(ED->
isClosedFlag() &&
"looking for value in non-flag or open enum");
21177 llvm::APInt &FlagBits = R.first->second;
21181 const auto &EVal = E->getInitVal();
21183 if (EVal.isPowerOf2())
21184 FlagBits = FlagBits.zext(EVal.getBitWidth()) | EVal;
21196 llvm::APInt FlagMask = ~FlagBits.zextOrTrunc(Val.getBitWidth());
21197 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
21204 bool HasBitwiseOp =
false;
21209 for (
const auto *ECD :
Enum->enumerators()) {
21210 const Expr *InitExpr = ECD->getInitExpr();
21216 if (
const auto *BinOp = dyn_cast<BinaryOperator>(E)) {
21220 if (BinOp->isBitwiseOp() || BinOp->isShiftOp()) {
21221 HasBitwiseOp =
true;
21222 }
else if (Op == BO_LT || Op == BO_GT) {
21225 if (
const auto *IntLiteral = dyn_cast<IntegerLiteral>(LHS)) {
21227 if (IntLiteral->getValue() == 1)
21228 SuspiciousCompares.push_back(BinOp);
21236 if (HasBitwiseOp) {
21237 for (
const auto *BinOp : SuspiciousCompares) {
21238 StringRef SuggestedOp = (BinOp->getOpcode() == BO_LT)
21243 Sema.
Diag(OperatorLoc, diag::warn_comparison_in_enum_initializer)
21244 << BinOp->getOpcodeStr() << SuggestedOp;
21246 Sema.
Diag(OperatorLoc, diag::note_enum_compare_typo_suggest)
21262 if (
Enum->isDependentType()) {
21263 for (
unsigned i = 0, e = Elements.size(); i != e; ++i) {
21265 cast_or_null<EnumConstantDecl>(Elements[i]);
21266 if (!ECD)
continue;
21277 unsigned NumNegativeBits = 0;
21278 unsigned NumPositiveBits = 0;
21279 bool MembersRepresentableByInt =
21280 Context.computeEnumBits(Elements, NumNegativeBits, NumPositiveBits);
21284 unsigned BestWidth;
21305 if (
Enum->isComplete()) {
21306 BestType =
Enum->getIntegerType();
21307 if (
Context.isPromotableIntegerType(BestType))
21308 BestPromotionType =
Context.getPromotedIntegerType(BestType);
21310 BestPromotionType = BestType;
21312 BestWidth =
Context.getIntWidth(BestType);
21314 bool EnumTooLarge =
Context.computeBestEnumTypes(
21315 Packed, NumNegativeBits, NumPositiveBits, BestType, BestPromotionType);
21316 BestWidth =
Context.getIntWidth(BestType);
21318 Diag(
Enum->getLocation(), diag::ext_enum_too_large);
21323 for (
auto *D : Elements) {
21324 auto *ECD = cast_or_null<EnumConstantDecl>(D);
21325 if (!ECD)
continue;
21334 llvm::APSInt InitVal = ECD->getInitVal();
21342 MembersRepresentableByInt) {
21350 NewWidth =
Context.getTargetInfo().getIntWidth();
21352 }
else if (ECD->getType() == BestType) {
21360 ECD->setType(EnumType);
21364 NewWidth = BestWidth;
21369 InitVal = InitVal.extOrTrunc(NewWidth);
21370 InitVal.setIsSigned(NewSign);
21371 ECD->setInitVal(
Context, InitVal);
21374 if (ECD->getInitExpr() &&
21375 !
Context.hasSameType(NewTy, ECD->getInitExpr()->getType()))
21377 Context, NewTy, CK_IntegralCast, ECD->getInitExpr(),
21386 ECD->setType(EnumType);
21388 ECD->setType(NewTy);
21391 Enum->completeDefinition(BestType, BestPromotionType,
21392 NumPositiveBits, NumNegativeBits);
21397 if (
Enum->isClosedFlag()) {
21398 for (
Decl *D : Elements) {
21400 if (!ECD)
continue;
21403 if (InitVal != 0 && !InitVal.isPowerOf2() &&
21411 if (
Enum->hasAttrs())
21450 AsmLabelAttr *
Attr =
21451 AsmLabelAttr::CreateImplicit(
Context, AliasName->
getName(), Info);
21461 Diag(PrevDecl->
getLocation(), diag::warn_redefine_extname_not_applied)
21475 auto *
Attr = WeakAttr::CreateImplicit(
Context, PragmaLoc);
21493 if (!PrevDecl->
hasAttr<AliasAttr>())
21494 if (
NamedDecl *ND = dyn_cast<NamedDecl>(PrevDecl))
21503 assert(FD &&
"Expected non-null FunctionDecl");
21510 FD->
hasAttr<SYCLKernelEntryPointAttr>() ||
21511 FD->
hasAttr<SYCLExternalAttr>()))
21515 auto IsEmittedForExternalSymbol = [
this, FD]() {
21527 if (
LangOpts.OpenMPIsTargetDevice) {
21530 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
21537 if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
21541 if (
OpenMP().isInOpenMPDeclareTargetContext() || DevTy)
21542 if (IsEmittedForExternalSymbol())
21548 }
else if (
LangOpts.OpenMP > 45) {
21552 std::optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
21555 if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
21574 if (IsEmittedForExternalSymbol())
Defines the clang::ASTContext interface.
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
This file defines the classes used to store parsed information about declaration-specifiers and decla...
Defines the C++ template declaration subclasses.
static bool isDeclExternC(const T &D)
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines helper utilities for supporting the HLSL runtime environment.
static const Decl * getCanonicalDecl(const Decl *D)
Result
Implement __builtin_bit_cast and related operations.
#define CC_VLS_CASE(ABI_VLEN)
static const GlobalDecl isTemplate(GlobalDecl GD, const TemplateArgumentList *&TemplateArgs)
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Architecture Architecture
llvm::MachO::Record Record
static bool isExternC(const NamedDecl *ND)
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
Defines the clang::Preprocessor interface.
RedeclarationKind
Specifies whether (or how) name lookup is being performed for a redeclaration (vs.
@ NotForRedeclaration
The lookup is a reference to this name that is not for the purpose of redeclaring the name.
@ ForExternalRedeclaration
The lookup results will be used for redeclaration of a name with external linkage; non-visible lookup...
@ ForVisibleRedeclaration
The lookup results will be used for redeclaration of a name, if an entity by that name already exists...
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
This file declares semantic analysis functions specific to AMDGPU.
This file declares semantic analysis functions specific to ARM.
static bool hasAttr(const Decl *D, bool IgnoreImplicitAttr)
This file declares semantic analysis for CUDA constructs.
static void diagnoseImplicitlyRetainedSelf(Sema &S)
static void SetNestedNameSpecifier(Sema &S, DeclaratorDecl *DD, Declarator &D)
static UnqualifiedTypeNameLookupResult lookupUnqualifiedTypeNameInBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc, const CXXRecordDecl *RD)
Tries to perform unqualified lookup of the type decls in bases for dependent class.
static bool ShouldWarnAboutMissingPrototype(const FunctionDecl *FD, const FunctionDecl *&PossiblePrototype)
static bool isMainVar(DeclarationName Name, VarDecl *VD)
static bool PreviousDeclsHaveMultiVersionAttribute(const FunctionDecl *FD)
static ParsedType recoverFromTypeInKnownDependentBase(Sema &S, const IdentifierInfo &II, SourceLocation NameLoc)
static void mergeParamDeclTypes(ParmVarDecl *NewParam, const ParmVarDecl *OldParam, Sema &S)
static void checkHybridPatchableAttr(Sema &S, NamedDecl &ND)
static void adjustDeclContextForDeclaratorDecl(DeclaratorDecl *NewD, DeclaratorDecl *OldD)
If necessary, adjust the semantic declaration context for a qualified declaration to name the correct...
static bool isResultTypeOrTemplate(LookupResult &R, const Token &NextToken)
Determine whether the given result set contains either a type name or.
static void FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL)
static bool AllowOverloadingOfFunction(const LookupResult &Previous, ASTContext &Context, const FunctionDecl *New)
Determine whether overloading is allowed for a new function declaration considering prior declaration...
static TypeSourceInfo * TryToFixInvalidVariablyModifiedTypeSourceInfo(TypeSourceInfo *TInfo, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
static StringRef getHeaderName(Builtin::Context &BuiltinInfo, unsigned ID, ASTContext::GetBuiltinTypeError Error)
static StorageClass getFunctionStorageClass(Sema &SemaRef, Declarator &D)
static bool checkUsingShadowRedecl(Sema &S, UsingShadowDecl *OldS, ExpectedDecl *New)
Check whether a redeclaration of an entity introduced by a using-declaration is valid,...
static ShadowedDeclKind computeShadowedDeclKind(const NamedDecl *ShadowedDecl, const DeclContext *OldDC)
Determine what kind of declaration we're shadowing.
static void checkIsValidOpenCLKernelParameter(Sema &S, Declarator &D, ParmVarDecl *Param, llvm::SmallPtrSetImpl< const Type * > &ValidTypes)
static void mergeParamDeclAttributes(ParmVarDecl *newDecl, const ParmVarDecl *oldDecl, Sema &S)
mergeParamDeclAttributes - Copy attributes from the old parameter to the new one.
static bool CheckC23ConstexprVarType(Sema &SemaRef, SourceLocation VarLoc, QualType T)
static bool CheckMultiVersionFunction(Sema &S, FunctionDecl *NewFD, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
Check the validity of a mulitversion function declaration.
static bool mergeAlignedAttrs(Sema &S, NamedDecl *New, Decl *Old)
Merge alignment attributes from Old to New, taking into account the special semantics of C11's _Align...
static bool mergeTypeWithPrevious(Sema &S, VarDecl *NewVD, VarDecl *OldVD, LookupResult &Previous)
static void CheckConstPureAttributesUsage(Sema &S, FunctionDecl *NewFD)
static bool FindPossiblePrototype(const FunctionDecl *FD, const FunctionDecl *&PossiblePrototype)
static bool MultiVersionTypesCompatible(FunctionDecl *Old, FunctionDecl *New)
static NestedNameSpecifier synthesizeCurrentNestedNameSpecifier(ASTContext &Context, DeclContext *DC)
static void GenerateFixForUnusedDecl(const NamedDecl *D, ASTContext &Ctx, FixItHint &Hint)
static void CheckExplicitObjectParameter(Sema &S, ParmVarDecl *P, SourceLocation ExplicitThisLoc)
static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND)
static void patchDefaultTargetVersion(FunctionDecl *From, FunctionDecl *To)
static bool isFunctionDefinitionDiscarded(Sema &S, FunctionDecl *FD)
Given that we are within the definition of the given function, will that definition behave like C99's...
static void CheckForDuplicateEnumValues(Sema &S, ArrayRef< Decl * > Elements, EnumDecl *Enum, QualType EnumType)
static unsigned GetDiagnosticTypeSpecifierID(const DeclSpec &DS)
static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old)
checkNewAttributesAfterDef - If we already have a definition, check that there are no new attributes ...
static bool isClassCompatTagKind(TagTypeKind Tag)
Determine if tag kind is a class-key compatible with class for redeclaration (class,...
static bool hasIdenticalPassObjectSizeAttrs(const FunctionDecl *A, const FunctionDecl *B)
static void checkAttributesAfterMerging(Sema &S, NamedDecl &ND)
static bool hasSimilarParameters(ASTContext &Context, FunctionDecl *Declaration, FunctionDecl *Definition, SmallVectorImpl< unsigned > &Params)
hasSimilarParameters - Determine whether the C++ functions Declaration and Definition have "nearly" m...
static NonCLikeKind getNonCLikeKindForAnonymousStruct(const CXXRecordDecl *RD)
Determine whether a class is C-like, according to the rules of C++ [dcl.typedef] for anonymous classe...
static unsigned propagateAttribute(ParmVarDecl *To, const ParmVarDecl *From, Sema &S)
static FunctionDecl * CreateNewFunctionDecl(Sema &SemaRef, Declarator &D, DeclContext *DC, QualType &R, TypeSourceInfo *TInfo, StorageClass SC, bool &IsVirtualOkay)
static bool checkWeakAttrCompatibility(Sema &S, const NamedDecl &ND, const WeakAttr &Attr)
static Scope * getTagInjectionScope(Scope *S, const LangOptions &LangOpts)
Find the Scope in which a tag is implicitly declared if we see an elaborated type specifier in the sp...
static bool methodHasName(const FunctionDecl *FD, StringRef Name)
static std::pair< diag::kind, SourceLocation > getNoteDiagForInvalidRedeclaration(const T *Old, const T *New)
static bool checkForConflictWithNonVisibleExternC(Sema &S, const T *ND, LookupResult &Previous)
Apply special rules for handling extern "C" declarations.
static bool DeclHasAttr(const Decl *D, const Attr *A)
DeclhasAttr - returns true if decl Declaration already has the target attribute.
static bool isOpenCLSizeDependentType(ASTContext &C, QualType Ty)
static void diagnoseMissingConstinit(Sema &S, const VarDecl *InitDecl, const ConstInitAttr *CIAttr, bool AttrBeforeInit)
static bool shouldWarnIfShadowedDecl(const DiagnosticsEngine &Diags, const LookupResult &R)
static FixItHint createFriendTagNNSFixIt(Sema &SemaRef, NamedDecl *ND, Scope *S, SourceLocation NameLoc)
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
static bool CheckAnonMemberRedeclaration(Sema &SemaRef, Scope *S, DeclContext *Owner, DeclarationName Name, SourceLocation NameLoc, bool IsUnion, StorageClass SC)
We are trying to inject an anonymous member into the given scope; check if there's an existing declar...
static bool checkGlobalOrExternCConflict(Sema &S, const T *ND, bool IsGlobal, LookupResult &Previous)
Check for conflict between this global or extern "C" declaration and previous global or extern "C" de...
static bool ShouldDiagnoseUnusedDecl(const LangOptions &LangOpts, const NamedDecl *D)
static bool isStdBuiltin(ASTContext &Ctx, FunctionDecl *FD, unsigned BuiltinID)
Determine whether a declaration matches a known function in namespace std.
static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S, DeclContext *Owner, RecordDecl *AnonRecord, AccessSpecifier AS, StorageClass SC, SmallVectorImpl< NamedDecl * > &Chaining)
InjectAnonymousStructOrUnionMembers - Inject the members of the anonymous struct or union AnonRecord ...
@ InvalidAddrSpacePtrKernelParam
static bool isFromSystemHeader(SourceManager &SM, const Decl *D)
Returns true if the declaration is declared in a system header or from a system macro.
static SourceLocation getCaptureLocation(const LambdaScopeInfo *LSI, const ValueDecl *VD)
Return the location of the capture if the given lambda captures the given variable VD,...
static bool AreSpecialMemberFunctionsSameKind(ASTContext &Context, CXXMethodDecl *M1, CXXMethodDecl *M2, CXXSpecialMemberKind CSM)
[class.mem.special]p5 Two special member functions are of the same kind if:
static const CXXRecordDecl * findRecordWithDependentBasesOfEnclosingMethod(const DeclContext *DC)
Find the parent class with dependent bases of the innermost enclosing method context.
static void ComputeSelectedDestructor(Sema &S, CXXRecordDecl *Record)
[class.dtor]p4: At the end of the definition of a class, overload resolution is performed among the p...
static bool shouldConsiderLinkage(const VarDecl *VD)
static SourceLocation findDefaultInitializer(const CXXRecordDecl *Record)
static bool CheckMultiVersionAdditionalRules(Sema &S, const FunctionDecl *OldFD, const FunctionDecl *NewFD, bool CausesMV, MultiVersionKind MVKind)
static DeclContext * getTagInjectionContext(DeclContext *DC)
Find the DeclContext in which a tag is implicitly declared if we see an elaborated type specifier in ...
static bool EquivalentArrayTypes(QualType Old, QualType New, const ASTContext &Ctx)
static bool haveIncompatibleLanguageLinkages(const T *Old, const T *New)
static unsigned getRedeclDiagFromTagKind(TagTypeKind Tag)
Get diagnostic select index for tag kind for redeclaration diagnostic message.
static void checkInheritableAttr(Sema &S, NamedDecl &ND)
static void CheckPoppedLabel(LabelDecl *L, Sema &S, Sema::DiagReceiverTy DiagReceiver)
static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl *Old)
static NamedDecl * DiagnoseInvalidRedeclaration(Sema &SemaRef, LookupResult &Previous, FunctionDecl *NewFD, ActOnFDArgs &ExtraArgs, bool IsLocalFriend, Scope *S)
Generate diagnostics for an invalid function redeclaration.
static bool RebuildDeclaratorInCurrentInstantiation(Sema &S, Declarator &D, DeclarationName Name)
RebuildDeclaratorInCurrentInstantiation - Checks whether the given declarator needs to be rebuilt in ...
static void SetEligibleMethods(Sema &S, CXXRecordDecl *Record, ArrayRef< CXXMethodDecl * > Methods, CXXSpecialMemberKind CSM)
[class.mem.special]p6: An eligible special member function is a special member function for which:
static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result, Scope *S, CXXScopeSpec &SS, IdentifierInfo *&Name, SourceLocation NameLoc)
static bool hasParsedAttr(Scope *S, const Declarator &PD, ParsedAttr::Kind Kind)
ShadowedDeclKind
Enum describing the select options in diag::warn_decl_shadow.
static unsigned getMSManglingNumber(const LangOptions &LO, Scope *S)
static void CheckForComparisonInEnumInitializer(SemaBase &Sema, const EnumDecl *Enum)
static void emitReadOnlyPlacementAttrWarning(Sema &S, const VarDecl *VD)
static bool canRedefineFunction(const FunctionDecl *FD, const LangOptions &LangOpts)
canRedefineFunction - checks if a function can be redefined.
static void checkWeakAttr(Sema &S, NamedDecl &ND)
static void checkModularFormatAttr(Sema &S, NamedDecl &ND)
static void checkSelectAnyAttr(Sema &S, NamedDecl &ND)
static bool isImplicitInstantiation(NamedDecl *D)
static OpenCLParamType getOpenCLKernelParameterType(Sema &S, QualType PT)
static void checkDuplicateDefaultInit(Sema &S, CXXRecordDecl *Parent, SourceLocation DefaultInitLoc)
static bool isDefaultStdCall(FunctionDecl *FD, Sema &S)
static bool diagnoseOpenCLTypes(Sema &Se, VarDecl *NewVD)
Returns true if there hasn't been any invalid type diagnosed.
static void RemoveUsingDecls(LookupResult &R)
Removes using shadow declarations not at class scope from the lookup results.
static void ComputeSpecialMemberFunctionsEligiblity(Sema &S, CXXRecordDecl *Record)
static bool AttrCompatibleWithMultiVersion(attr::Kind Kind, MultiVersionKind MVKind)
static bool looksMutable(QualType T, const ASTContext &Ctx)
static bool isUsingDeclNotAtClassScope(NamedDecl *D)
static void propagateAttributes(ParmVarDecl *To, const ParmVarDecl *From, F &&propagator)
static const NamedDecl * getDefinition(const Decl *D)
static QualType TryToFixInvalidVariablyModifiedType(QualType T, ASTContext &Context, bool &SizeIsNegative, llvm::APSInt &Oversized)
Helper method to turn variable array types into constant array types in certain situations which woul...
static bool hasDeducedAuto(DeclaratorDecl *DD)
static void copyAttrFromTypedefToDecl(Sema &S, Decl *D, const TypedefType *TT)
static QualType getCoreType(QualType Ty)
static bool mergeDeclAttribute(Sema &S, NamedDecl *D, const InheritableAttr *Attr, AvailabilityMergeKind AMK)
static bool CheckMultiVersionValue(Sema &S, const FunctionDecl *FD)
Check the target or target_version attribute of the function for MultiVersion validity.
static bool isOutOfScopePreviousDeclaration(NamedDecl *, DeclContext *, ASTContext &)
Determines whether the given declaration is an out-of-scope previous declaration.
static StorageClass StorageClassSpecToVarDeclStorageClass(const DeclSpec &DS)
StorageClassSpecToVarDeclStorageClass - Maps a DeclSpec::SCS to a VarDecl::StorageClass.
static bool CheckMultiVersionAdditionalDecl(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, const CPUDispatchAttr *NewCPUDisp, const CPUSpecificAttr *NewCPUSpec, const TargetClonesAttr *NewClones, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
Check the validity of a new function declaration being added to an existing multiversioned declaratio...
static bool CheckMultiVersionFirstFunction(Sema &S, FunctionDecl *FD)
Check the validity of a multiversion function declaration that is the first of its kind.
static bool isSYCLAddressSpace(LangAS AS)
static void checkDLLAttributeRedeclaration(Sema &S, NamedDecl *OldDecl, NamedDecl *NewDecl, bool IsSpecialization, bool IsDefinition)
static bool checkNonMultiVersionCompatAttributes(Sema &S, const FunctionDecl *FD, const FunctionDecl *CausedFD, MultiVersionKind MVKind)
static void checkAliasAttr(Sema &S, NamedDecl &ND)
static void filterNonConflictingPreviousTypedefDecls(Sema &S, const TypedefNameDecl *Decl, LookupResult &Previous)
Typedef declarations don't have linkage, but they still denote the same entity if their types are the...
static bool ValidDuplicateEnum(EnumConstantDecl *ECD, EnumDecl *Enum)
static QualType getNextLargerIntegralType(ASTContext &Context, QualType T)
static void checkWeakRefAttr(Sema &S, NamedDecl &ND)
static bool isIncompleteDeclExternC(Sema &S, const T *D)
Determine whether a variable is extern "C" prior to attaching an initializer.
static bool isAttributeTargetADefinition(Decl *D)
static Attr * getImplicitCodeSegAttrFromClass(Sema &S, const FunctionDecl *FD)
Return a CodeSegAttr from a containing class.
static bool CheckDeclarationCausesMultiVersioning(Sema &S, FunctionDecl *OldFD, FunctionDecl *NewFD, bool &Redeclaration, NamedDecl *&OldDecl, LookupResult &Previous)
static bool IsDisallowedCopyOrAssign(const CXXMethodDecl *D)
Check for this common pattern:
static bool isAcceptableTagRedeclContext(Sema &S, DeclContext *OldDC, DeclContext *NewDC)
Determine whether a tag originally declared in context OldDC can be redeclared with an unqualified na...
static bool isRecordType(QualType T)
This file declares semantic analysis for HLSL constructs.
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis functions specific to PowerPC.
This file declares semantic analysis functions specific to RISC-V.
This file declares semantic analysis for SYCL constructs.
This file declares semantic analysis functions specific to Swift.
This file declares semantic analysis functions specific to Wasm.
static CharSourceRange getRange(const CharSourceRange &EditRange, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeMacroExpansion)
Defines the SourceManager interface.
static QualType getPointeeType(const MemRegion *R)
C Language Family Type Representation.
@ GE_Missing_stdio
Missing a type from <stdio.h>
@ GE_Missing_type
Missing a type.
@ GE_Missing_ucontext
Missing a type from <ucontext.h>
@ GE_Missing_setjmp
Missing a type from <setjmp.h>
RAII object that pops an ExpressionEvaluationContext when exiting a function body.
ExitFunctionBodyRAII(Sema &S, bool IsLambda)
llvm::APInt getValue() const
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
const ConstantArrayType * getAsConstantArrayType(QualType T) const
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
const LangOptions & getLangOpts() const
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
GVALinkage GetGVALinkageForFunction(const FunctionDecl *FD) const
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
const VariableArrayType * getAsVariableArrayType(QualType T) const
const TargetInfo & getTargetInfo() const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType getCanonicalTagType(const TagDecl *TD) const
@ GE_Missing_type
Missing a type.
@ GE_Missing_setjmp
Missing a type from <setjmp.h>
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Wrapper for source info for arrays.
SourceLocation getLBracketLoc() const
Expr * getSizeExpr() const
TypeLoc getElementLoc() const
SourceLocation getRBracketLoc() const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
Attr - This represents one attribute.
attr::Kind getKind() const
bool isImplicit() const
Returns true if the attribute has been implicitly created instead of explicitly written by the user.
Attr * clone(ASTContext &C) const
SourceLocation getLocation() const
@ AS_Declspec
__declspec(...)
SourceRange getRange() const
bool isStandardAttributeSyntax() const
The attribute is spelled [[]] in either C or C++ mode, including standard attributes spelled with a k...
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
AttributeFactory & getFactory() const
Type source information for an attributed type.
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
void setAttr(const Attr *A)
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression which will be evaluated if the condition evaluates to false; ...
Expr * getCond() const
getCond - Return the condition expression; this is defined in terms of the opaque value.
A builtin binary operation expression such as "x + y" or "x <= y".
StringRef getOpcodeStr() const
static bool isCompoundAssignmentOp(Opcode Opc)
A binding in a decomposition declaration.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
bool doesNotEscape() const
This class is used for builtin types like 'int'.
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
const char * getHeaderName(unsigned ID) const
If this is a library function that comes from a specific header, retrieve that header name.
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Represents a base class of a C++ class.
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getEndLoc() const LLVM_READONLY
Expr * getArg(unsigned Arg)
Return the specified argument.
CXXConstructorDecl * getConstructor() const
Get the constructor that this expression will (ultimately) call.
Represents a C++ constructor within a class.
bool isCopyConstructor(unsigned &TypeQuals) const
Whether this constructor is a copy constructor (C++ [class.copy]p2, which can be used to copy the cla...
static CXXConstructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, InheritedConstructor Inherited=InheritedConstructor(), const AssociatedConstraint &TrailingRequiresClause={})
Represents a C++ conversion function within a class.
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})
static CXXDeductionGuideDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl *Ctor=nullptr, DeductionCandidate Kind=DeductionCandidate::Normal, const AssociatedConstraint &TrailingRequiresClause={}, const CXXDeductionGuideDecl *SourceDG=nullptr, SourceDeductionGuideKind SK=SourceDeductionGuideKind::None)
Represents a C++ destructor within a class.
static CXXDestructorDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind, const AssociatedConstraint &TrailingRequiresClause={})
A mapping from each virtual member function to its set of final overriders.
Represents a static or instance method of a struct/union/class.
bool isExplicitObjectMemberFunction() const
[C++2b][dcl.fct]/p7 An explicit object member function is a non-static member function with an explic...
void addOverriddenMethod(const CXXMethodDecl *MD)
CXXSpecialMemberKind getSpecialMemberKind() const
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin, bool isInline, ConstexprSpecKind ConstexprKind, SourceLocation EndLocation, const AssociatedConstraint &TrailingRequiresClause={})
QualType getFunctionObjectParameterReferenceType() const
Return the type of the object pointed by this.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
Qualifiers getMethodQualifiers() const
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ struct/union/class.
static CXXRecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, CXXRecordDecl *PrevDecl=nullptr)
base_class_iterator bases_end()
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
const FunctionDecl * isLocalClass() const
If the class is a local class [class.local], returns the enclosing function declaration.
unsigned getNumBases() const
Retrieves the number of base classes of this class.
bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths, bool LookupInDependent=false) const
Look for entities within the base classes of this C++ class, transitively searching all base class su...
base_class_iterator bases_begin()
capture_const_range captures() const
bool hasInClassInitializer() const
Whether this class has any in-class initializers for non-static data members (including those in anon...
bool hasDefinition() const
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
bool isInjectedClassName() const
Determines whether this declaration represents the injected class name.
LambdaCaptureDefault getLambdaCaptureDefault() const
UnresolvedSetIterator conversion_iterator
void setDescribedClassTemplate(ClassTemplateDecl *Template)
CXXRecordDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ nested-name-specifier or a global scope specifier.
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
char * location_data() const
Retrieve the data associated with the source-location information.
bool isValid() const
A scope specifier is present, and it refers to a real scope.
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
SourceRange getRange() const
SourceLocation getBeginLoc() const
bool isSet() const
Deprecated.
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
bool isInvalid() const
An error occurred during parsing of the scope specifier.
bool isEmpty() const
No scope specifier.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
bool isCallToStdMove() const
CastKind getCastKind() const
static CharSourceRange getCharRange(SourceRange R)
This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
Declaration of a class template.
Represents the canonical version of C arrays with a specified constant size.
static unsigned getNumAddressingBits(const ASTContext &Context, QualType ElementType, const llvm::APInt &NumElements)
Determine the number of bits required to address a member of.
static unsigned getMaxSizeBits(const ASTContext &Context)
Determine the maximum number of active bits that an array's size can require, which limits the maximu...
llvm::APInt getSize() const
Return the constant array size as an APInt.
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclListNode::iterator iterator
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC.
bool isFileContext() const
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
DeclContextLookupResult lookup_result
bool isTransparentContext() const
isTransparentContext - Determines whether this context is a "transparent" context,...
Decl * getNonClosureAncestor()
Find the nearest non-closure ancestor of this context, i.e.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
const BlockDecl * getInnermostBlockDecl() const
Return this DeclContext if it is a BlockDecl.
bool isTranslationUnit() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
void removeDecl(Decl *D)
Removes a declaration from this context.
void addDecl(Decl *D)
Add the declaration D into this context.
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
bool isFunctionOrMethod() const
Returns true if this DeclContext is a function, Objective-C method, or block, or a DeclContext that c...
DeclContext * getLookupParent()
Find the parent context of this context that will be used for unqualified name lookup.
bool isExternCContext() const
Determines whether this context or some of its ancestors is a linkage specification context that spec...
bool Encloses(const DeclContext *DC) const
Determine whether this declaration context semantically encloses the declaration context DC.
Decl::Kind getDeclKind() const
DeclContext * getNonTransparentContext()
DeclContext * getEnclosingNonExpansionStatementContext()
Retrieve the innermost enclosing context that doesn't belong to an expansion statement.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
A reference to a declared variable, function, enum, etc.
SourceLocation getBeginLoc() const
Captures information about "declaration specifiers".
bool isVirtualSpecified() const
bool isModulePrivateSpecified() const
static const TST TST_typeof_unqualType
bool hasAutoTypeSpec() const
static const TST TST_typename
bool SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec and return false if there was no error.
ThreadStorageClassSpecifier TSCS
void ClearStorageClassSpecs()
bool isNoreturnSpecified() const
TST getTypeSpecType() const
SourceLocation getStorageClassSpecLoc() const
SCS getStorageClassSpec() const
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
SourceLocation getBeginLoc() const LLVM_READONLY
SourceRange getSourceRange() const LLVM_READONLY
void SetRangeEnd(SourceLocation Loc)
static const TST TST_interface
static const TST TST_typeofExpr
unsigned getTypeQualifiers() const
getTypeQualifiers - Return a set of TQs.
void SetRangeStart(SourceLocation Loc)
SourceLocation getNoreturnSpecLoc() const
bool isExternInLinkageSpec() const
static const TST TST_union
SCS
storage-class-specifier
SourceLocation getExplicitSpecLoc() const
SourceLocation getModulePrivateSpecLoc() const
bool isMissingDeclaratorOk()
Checks if this DeclSpec can stand alone, without a Declarator.
ParsedType getRepAsType() const
void UpdateTypeRep(ParsedType Rep)
TSCS getThreadStorageClassSpec() const
ParsedAttributes & getAttributes()
void ClearTypeQualifiers()
Clear out all of the type qualifiers.
SourceLocation getConstSpecLoc() const
SourceRange getExplicitSpecRange() const
Expr * getRepAsExpr() const
static const TST TST_enum
static const TST TST_decltype
static bool isDeclRep(TST T)
bool isInlineSpecified() const
SourceLocation getRestrictSpecLoc() const
static const TST TST_typeof_unqualExpr
static const TST TST_class
static const TST TST_void
void ClearConstexprSpec()
static const char * getSpecifierName(DeclSpec::TST T, const PrintingPolicy &Policy)
Turn a type-specifier-type into a string like "_Bool" or "union".
static const TST TST_atomic
SourceLocation getThreadStorageClassSpecLoc() const
Decl * getRepAsDecl() const
static const TST TST_unspecified
SourceLocation getAtomicSpecLoc() const
SourceLocation getVirtualSpecLoc() const
SourceLocation getConstexprSpecLoc() const
SourceLocation getTypeSpecTypeLoc() const
void UpdateExprRep(Expr *Rep)
static const TSCS TSCS_thread_local
static const TST TST_error
ExplicitSpecifier getExplicitSpecifier() const
bool isTypeSpecOwned() const
SourceLocation getInlineSpecLoc() const
SourceLocation getUnalignedSpecLoc() const
SourceLocation getVolatileSpecLoc() const
FriendSpecified isFriendSpecified() const
bool hasExplicitSpecifier() const
bool hasConstexprSpecifier() const
static const TST TST_typeofType
static const TST TST_auto
ConstexprSpecKind getConstexprSpecifier() const
static const TST TST_struct
Decl - This represents one declaration (or definition), e.g.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration,...
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
bool isInStdNamespace() const
SourceLocation getEndLoc() const LLVM_READONLY
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
bool isFromGlobalModule() const
Whether this declaration comes from global module.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
void setAttrs(const AttrVec &Attrs)
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked 'unavailable'.
bool isInNamedModule() const
Whether this declaration comes from a named module.
void setLocalExternDecl()
Changes the namespace of this declaration to reflect that it's a function-local extern declaration.
virtual bool isOutOfLine() const
Determine whether this declaration is declared out of line (outside its semantic context).
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void setTopLevelDeclInObjCContainer(bool V=true)
bool isInIdentifierNamespace(unsigned NS) const
@ FOK_Undeclared
A friend of a previously-undeclared entity.
@ FOK_None
Not a friend object.
@ FOK_Declared
A friend of a previously-declared entity.
bool isTemplated() const
Determine whether this declaration is a templated entity (whether it is.
bool isInExportDeclContext() const
Whether this declaration was exported in a lexical context.
bool isReferenced() const
Whether any declaration of this entity was referenced.
bool isInAnotherModuleUnit() const
Whether this declaration comes from another module unit.
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
@ OBJC_TQ_CSNullability
The nullability qualifier is set when the nullability of the result or parameter was expressed via a ...
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
bool isTemplateParameter() const
isTemplateParameter - Determines whether this declaration is a template parameter.
bool isInvalidDecl() const
bool isLocalExternDecl() const
Determine whether this is a block-scope declaration with linkage.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
void setAccess(AccessSpecifier AS)
SourceLocation getLocation() const
@ IDNS_Ordinary
Ordinary names.
void setImplicit(bool I=true)
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
SourceLocation getBeginLoc() const LLVM_READONLY
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Module * getOwningModuleForLinkage() const
Get the module that owns this declaration for linkage purposes.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
void setNonMemberOperator()
Specifies that this declaration is a C++ overloaded non-member.
void setLexicalDeclContext(DeclContext *DC)
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
bool isAnyOperatorNewOrDelete() const
bool isAnyOperatorDelete() const
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
@ CXXConversionFunctionName
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
bool isIdentifier() const
Predicate functions for querying what type of name this is.
Represents a ValueDecl that came out of a declarator.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
SourceLocation getOuterLocStart() const
Return start of source range taking into account any outer template declarations.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
SourceLocation getTypeSpecStartLoc() const
SourceLocation getBeginLoc() const LLVM_READONLY
const AssociatedConstraint & getTrailingRequiresClause() const
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
void setTypeSourceInfo(TypeSourceInfo *TI)
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
NestedNameSpecifier getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
TypeSourceInfo * getTypeSourceInfo() const
void setTemplateParameterListsInfo(ASTContext &Context, ArrayRef< TemplateParameterList * > TPLists)
Information about one declarator, including the parsed type information and the identifier.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Expr * getAsmLabel() const
FunctionDefinitionKind getFunctionDefinitionKind() const
const ParsedAttributes & getAttributes() const
void setRedeclaration(bool Val)
SourceLocation getIdentifierLoc() const
void SetIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Set the name of this declarator to be the given identifier.
SourceLocation getEndLoc() const LLVM_READONLY
Expr * getTrailingRequiresClause()
Sets a trailing requires clause for this declarator.
void takeAttributesAppending(ParsedAttributes &attrs)
takeAttributesAppending - Takes attributes from the given ParsedAttributes set and add them to this d...
void setInvalidType(bool Val=true)
TemplateParameterList * getInventedTemplateParameterList() const
The template parameter list generated from the explicit template parameters along with any invented t...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
bool isRedeclaration() const
const ParsedAttributesView & getDeclarationAttributes() const
const DecompositionDeclarator & getDecompositionDeclarator() const
SourceLocation getBeginLoc() const LLVM_READONLY
bool isCtorOrDtor()
Returns true if this declares a constructor or a destructor.
bool isFunctionDefinition() const
UnqualifiedId & getName()
Retrieve the name specified by this declarator.
bool hasInitializer() const
void setFunctionDefinitionKind(FunctionDefinitionKind Val)
const CXXScopeSpec & getCXXScopeSpec() const
getCXXScopeSpec - Return the C++ scope specifier (global scope or nested-name-specifier) that is part...
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
bool isInvalidType() const
bool isExplicitObjectMemberFunction()
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isDecompositionDeclarator() const
Return whether this declarator is a decomposition declarator.
bool isFirstDeclarationOfMember()
Returns true if this declares a real member and not a friend.
bool isStaticMember()
Returns true if this declares a static member.
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
const IdentifierInfo * getIdentifier() const
A decomposition declaration.
static DecompositionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation LSquareLoc, SourceLocation RSquareLoc, QualType T, TypeSourceInfo *TInfo, StorageClass S, ArrayRef< BindingDecl * > Bindings)
A parsed C++17 decomposition declarator of the form '[' identifier-list ']'.
SourceRange getSourceRange() const
SourceLocation getLSquareLoc() const
void setElaboratedKeywordLoc(SourceLocation Loc)
void setNameLoc(SourceLocation Loc)
void setElaboratedKeywordLoc(SourceLocation Loc)
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Concrete class used by the front-end to report problems and issues.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
An instance of this object exists for each enum constant that is defined.
llvm::APSInt getInitVal() const
static EnumConstantDecl * Create(ASTContext &C, EnumDecl *DC, SourceLocation L, IdentifierInfo *Id, QualType T, Expr *E, const llvm::APSInt &V)
const Expr * getInitExpr() const
enumerator_range enumerators() const
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
void setIntegerType(QualType T)
Set the underlying integer type.
void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo)
Set the underlying integer type source info.
bool isComplete() const
Returns true if this can be considered a complete type.
static EnumDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl, bool IsScoped, bool IsScopedUsingClassTag, bool IsFixed)
bool isClosedFlag() const
Returns true if this enum is annotated with flag_enum and isn't annotated with enum_extensibility(ope...
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
SourceRange getIntegerTypeRange() const LLVM_READONLY
Retrieve the source range that covers the underlying type if specified.
void setPromotionType(QualType T)
Set the promotion type.
void setEnumKeyRange(SourceRange Range)
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
EvaluatedExprVisitor - This class visits 'Expr *'s.
Store information needed for an explicit specifier.
This represents one expression.
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects, bool InConstantContext=false) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer,...
bool isValueDependent() const
Determines whether the value of this expression depends on.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
bool containsErrors() const
Whether this expression contains subexpressions which had errors.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool isConstantInitializer(ASTContext &Ctx, bool ForRef=false, const Expr **Culprit=nullptr) const
Returns true if this expression can be emitted to IR as a constant, and thus can be used as a constan...
std::optional< llvm::APSInt > getIntegerConstantExpr(const ASTContext &Ctx, bool AllowRelaxedEval=false) const
isIntegerConstantExpr - Return the value if this expression is a valid integer constant expression.
Expr * IgnoreImpCasts() LLVM_READONLY
Skip past any implicit casts which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents difference between two FPOptions values.
void setDisallowOptimizations()
bool isFPConstrained() const
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
bool isAnonymousStructOrUnion() const
Determines whether this field is a representative for an anonymous struct or union.
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
bool isZeroLengthBitField() const
Is this a zero-length bit-field?
static FileScopeAsmDecl * Create(ASTContext &C, DeclContext *DC, Expr *Str, SourceLocation AsmLoc, SourceLocation RParenLoc)
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Represents a function declaration or definition.
bool isMultiVersion() const
True if this function is considered a multiversioned function.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin=false, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=ConstexprSpecKind::Unspecified, const AssociatedConstraint &TrailingRequiresClause={})
const ParmVarDecl * getParamDecl(unsigned i) const
ConstexprSpecKind getConstexprKind() const
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
void setPreviousDeclaration(FunctionDecl *PrevDecl)
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
void setIsPureVirtual(bool P=true)
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
void setHasSkippedBody(bool Skipped=true)
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
param_iterator param_end()
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool isCPUSpecificMultiVersion() const
True if this function is a multiversioned processor specific function as a part of the cpu_specific/c...
bool isExplicitlyDefaulted() const
Whether this function is explicitly defaulted.
bool isTrivial() const
Whether this function is "trivial" in some specialized C++ senses.
LanguageLinkage getLanguageLinkage() const
Compute the language linkage.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
bool hasWrittenPrototype() const
Whether this function has a written prototype.
void setWillHaveBody(bool V=true)
bool isReplaceableGlobalAllocationFunction(UnsignedOrNone *AlignmentParam=nullptr, bool *IsNothrow=nullptr) const
Determines whether this function is one of the replaceable global allocation functions:
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
param_iterator param_begin()
const ParmVarDecl * getNonObjectParameter(unsigned I) const
bool doesThisDeclarationHaveABody() const
Returns whether this specific declaration of the function has a body.
bool isDeleted() const
Whether this function has been deleted.
FunctionEffectsRef getFunctionEffects() const
bool isMSVCRTEntryPoint() const
Determines whether this function is a MSVCRT user defined entry point.
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
@ TK_MemberSpecialization
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isOutOfLine() const override
Determine whether this is or was instantiated from an out-of-line definition of a member function.
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
bool isDeletedAsWritten() const
redecl_iterator redecls_end() const
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
bool isExternC() const
Determines whether this function is a function with external, C linkage.
bool isLateTemplateParsed() const
Whether this templated function will be late parsed.
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
bool hasImplicitReturnZero() const
Whether falling off this function implicitly returns null/zero.
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
bool hasSkippedBody() const
True if the function was a definition but its body was skipped.
FunctionDecl * getDefinition()
Get the definition for this declaration.
bool isMain() const
Determines whether this function is "main", which is the entry point into an executable program.
void setImplicitlyInline(bool I=true)
Flag that this function is implicitly inline.
bool isThisDeclarationInstantiatedFromAFriendDefinition() const
Determine whether this specific declaration of the function is a friend declaration that was instanti...
void setRangeEnd(SourceLocation E)
bool isCPUDispatchMultiVersion() const
True if this function is a multiversioned dispatch function as a part of the cpu_specific/cpu_dispatc...
bool isDefaulted() const
Whether this function is defaulted.
void setIneligibleOrNotSelected(bool II)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool isOverloadedOperator() const
Whether this function declaration represents an C++ overloaded operator, e.g., "operator+".
const IdentifierInfo * getLiteralIdentifier() const
getLiteralIdentifier - The literal suffix identifier this function represents, if any.
void setConstexprKind(ConstexprSpecKind CSK)
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
void setDefaulted(bool D=true)
QualType getDeclaredReturnType() const
Get the declared return type, which may differ from the actual return type if the return type is dedu...
bool isGlobal() const
Determines whether this is a global function.
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
bool hasInheritedPrototype() const
Whether this function inherited its prototype from a previous declaration.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
DeclarationNameInfo getNameInfo() const
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
void setHasImplicitReturnZero(bool IRZ)
State that falling off this function implicitly returns null/zero.
bool isDefined(const FunctionDecl *&Definition, bool CheckForPendingFriendDefinition=false) const
Returns true if the function has a definition that does not need to be instantiated.
FunctionDecl * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
MultiVersionKind getMultiVersionKind() const
Gets the kind of multiversioning attribute this declaration has.
bool willHaveBody() const
True if this function will eventually have a body, once it's fully parsed.
A mutable set of FunctionEffects and possibly conditions attached to them.
SmallVector< Conflict > Conflicts
static FunctionEffectSet getUnion(FunctionEffectsRef LHS, FunctionEffectsRef RHS, Conflicts &Errs)
An immutable set of FunctionEffects and possibly conditions attached to them.
Represents a prototype with parameter type info, e.g.
unsigned getNumParams() const
QualType getParamType(unsigned i) const
unsigned getAArch64SMEAttributes() const
Return a bitmask describing the SME attributes on the function type, see AArch64SMETypeAttributes for...
bool hasExceptionSpec() const
Return whether this function has any kind of exception spec.
bool isVariadic() const
Whether this function prototype is variadic.
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > getParamTypes() const
Declaration of a template function.
FunctionTemplateDecl * getInstantiatedFromMemberTemplate() const
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
void mergePrevDecl(FunctionTemplateDecl *Prev)
Merge Prev with our RedeclarableTemplateDecl::Common.
bool isExplicitSpecialization() const
Wrapper for source info for functions.
A class which abstracts out some details necessary for making a call.
ExtInfo withCallingConv(CallingConv cc) const
CallingConv getCC() const
ExtInfo withProducesResult(bool producesResult) const
unsigned getRegParm() const
bool getNoCallerSavedRegs() const
ExtInfo withNoReturn(bool noReturn) const
bool getHasRegParm() const
bool getProducesResult() const
ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const
ExtInfo withRegParm(unsigned RegParm) const
FunctionType - C99 6.7.5.3 - Function Declarators.
ExtInfo getExtInfo() const
static StringRef getNameForCallConv(CallingConv CC)
@ SME_PStateSMEnabledMask
@ SME_PStateSMCompatibleMask
unsigned getRegParmType() const
CallingConv getCallConv() const
QualType getReturnType() const
bool getCmseNSCallAttr() const
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
bool isPlaceholder() const
StringRef getName() const
Return the actual identifier string.
iterator - Iterate over the decls of a specified declaration name.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Represents a C array with an unspecified size.
Represents a field injected from an anonymous union/struct into the parent scope.
static IndirectFieldDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id, QualType T, MutableArrayRef< NamedDecl * > CH)
void setInherited(bool I)
Description of a constructor that was inherited from a base class.
Describes the kind of initialization being performed, along with location information for tokens rela...
static InitializationKind CreateDefault(SourceLocation InitLoc)
Create a default initialization.
static InitializationKind CreateForInit(SourceLocation Loc, bool DirectInit, Expr *Init)
Create an initialization from an initializer (which, for direct initialization from a parenthesized l...
step_iterator step_begin() const
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence.
@ SK_ParenthesizedListInit
Initialize an aggreagate with parenthesized list of values.
Describes an entity that is being initialized.
static InitializedEntity InitializeVariable(VarDecl *Var)
Create the initialization entity for a variable.
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Represents the declaration of a label.
bool isResolvedMSAsmLabel() const
LabelStmt * getStmt() const
bool isMSAsmLabel() const
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
FPExceptionModeKind getDefaultExceptionMode() const
bool requiresStrictPrototypes() const
Returns true if functions without prototypes or functions with an identifier list (aka K&R C function...
std::string getOpenCLVersionString() const
Return the OpenCL C or C++ for OpenCL language name and version as a string.
bool isCompatibleWithMSVC() const
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
static std::optional< Token > findNextToken(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts, bool IncludeComments=false)
Finds the token that comes right after the given location.
Visibility getVisibility() const
Linkage getLinkage() const
Represents a linkage specification.
static LinkageSpecDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation ExternLoc, SourceLocation LangLoc, LinkageSpecLanguageIDs Lang, bool HasBraces)
A class for iterating through a result set and possibly filtering out results.
void erase()
Erase the last element returned from this iterator.
Represents the results of name lookup.
DeclClass * getAsSingle() const
bool empty() const
Return true if no decls were found.
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
UnresolvedSetImpl::iterator iterator
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
virtual unsigned getManglingNumber(const CXXMethodDecl *CallOperator)=0
Retrieve the mangling number of a new lambda expression with the given call operator within this cont...
virtual unsigned getStaticLocalNumber(const VarDecl *VD)=0
Static locals are numbered by source order.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
A pointer to member type per C++ 8.3.3 - Pointers to members.
Describes a module or submodule.
SourceLocation DefinitionLoc
The location of the module definition.
Module * Parent
The parent of this module.
bool isPrivateModule() const
bool isHeaderLikeModule() const
Is this module have similar semantics as headers.
bool isModuleImplementation() const
Is this a module implementation.
bool isModulePartition() const
Is this a module partition.
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
bool isNamedModule() const
Does this Module is a named module of a standard named module?
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
bool isLinkageValid() const
True if the computed linkage is valid.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
bool isPlaceholderVar(const LangOptions &LangOpts) const
Visibility getVisibility() const
Determines the visibility of this entity.
bool hasLinkageBeenComputed() const
True if something has required us to compute the linkage of this declaration.
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
bool declarationReplaces(const NamedDecl *OldD, bool IsKnownNewer=true) const
Determine whether this declaration, if known to be well-formed within its context,...
Linkage getFormalLinkage() const
Get the linkage from a semantic point of view.
void setModulePrivate()
Specify that this declaration was marked as being private to the module in which it was defined.
bool hasLinkage() const
Determine whether this declaration has linkage.
bool isExternallyVisible() const
ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const
Determine if the declaration obeys the reserved identifier rules of the given language.
bool isCXXClassMember() const
Determine whether this declaration is a C++ class member.
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
A C++ nested-name-specifier augmented with source location information.
TypeLoc getAsTypeLoc() const
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
static constexpr NestedNameSpecifier getGlobal()
bool containsErrors() const
Whether this nested name specifier contains an error.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
const Type * getAsType() const
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Type
A type, stored as a Type*.
ObjCCategoryDecl - Represents a category declaration.
ObjCCompatibleAliasDecl - Represents alias of a class.
ObjCContainerDecl - Represents a container for method declarations.
ObjCIvarDecl * getIvarDecl(IdentifierInfo *Id) const
getIvarDecl - This method looks up an ivar in this ContextDecl.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
known_extensions_range known_extensions() const
Wrapper for source info for ObjC interfaces.
void setNameLoc(SourceLocation Loc)
ObjCIvarDecl - Represents an ObjC instance variable.
static ObjCIvarDecl * Create(ASTContext &C, ObjCContainerDecl *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, AccessControl ac, Expr *BW=nullptr, bool synthesized=false)
ObjCMethodDecl - Represents an instance or class method declaration.
param_const_iterator param_end() const
param_const_iterator param_begin() const
const ParmVarDecl *const * param_const_iterator
ParmVarDecl *const * param_iterator
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
static OpaquePtr make(DeclGroupRef P)
bool isAvailableOption(llvm::StringRef Ext, const LangOptions &LO) const
OverloadCandidateSet - A set of overload candidates, used in C++ overload resolution (C++ 13....
@ CSK_Normal
Normal lookup.
SmallVectorImpl< OverloadCandidate >::iterator iterator
void NoteCandidates(PartialDiagnosticAt PA, Sema &S, OverloadCandidateDisplayKind OCD, ArrayRef< Expr * > Args, StringRef Opc="", SourceLocation Loc=SourceLocation(), llvm::function_ref< bool(OverloadCandidate &)> Filter=[](OverloadCandidate &) { return true;})
When overload resolution fails, prints diagnostic messages containing the candidates in the candidate...
OverloadingResult BestViableFunction(Sema &S, SourceLocation Loc, OverloadCandidateSet::iterator &Best)
Find the best viable function on this overload set, if it exists.
MapType::iterator iterator
SmallVectorImpl< UniqueVirtualMethod >::iterator overriding_iterator
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
void setRParenLoc(SourceLocation Loc)
TypeLoc getInnerLoc() const
void setLParenLoc(SourceLocation Loc)
Sugar for parentheses used when specifying types.
Represents a parameter to a function.
ObjCDeclQualifier getObjCDeclQualifier() const
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
void setExplicitObjectParameterLoc(SourceLocation Loc)
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
ParsedAttr - Represents a syntactic attribute.
static const ParsedAttributesView & none()
bool hasAttribute(ParsedAttr::Kind K) const
ParsedAttributes - A collection of parsed attributes.
AttributePool & getPool() const
unsigned getDiagID() const
Pointer-authentication qualifiers.
bool isAddressDiscriminated() const
TypeLoc getPointeeLoc() const
Wrapper for source info for pointers.
void setStarLoc(SourceLocation Loc)
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
A (possibly-)qualified type.
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
bool isRestrictQualified() const
Determine whether this type is restrict-qualified.
bool hasNonTrivialToPrimitiveCopyCUnion() const
Check if this is or contains a C union that is non-trivial to copy, which is a union that has a membe...
PointerAuthQualifier getPointerAuth() const
PrimitiveDefaultInitializeKind
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const
const IdentifierInfo * getBaseTypeIdentifier() const
Retrieves a pointer to the name of the base type.
QualType withoutLocalFastQualifiers() const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const
Check if this is a non-trivial type that would cause a C struct transitively containing this type to ...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
LangAS getAddressSpace() const
Return the address space of this type.
bool hasNonTrivialToPrimitiveDestructCUnion() const
Check if this is or contains a C union that is non-trivial to destruct, which is a union that has a m...
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getCanonicalType() const
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
PrimitiveDefaultInitializeKind isNonTrivialToPrimitiveDefaultInitialize() const
Functions to query basic properties of non-trivial C struct types.
bool isObjCGCStrong() const
true when Type is objc's strong.
bool isConstQualified() const
Determine whether this type is const-qualified.
bool hasAddressSpace() const
Check if this type has any address space qualifier.
QualType getAtomicUnqualifiedType() const
Remove all qualifiers including _Atomic.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
QualType getSingleStepDesugaredType(const ASTContext &Context) const
Return the specified type with one level of "sugar" removed from the type.
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
bool hasNonTrivialObjCLifetime() const
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
@ PCK_Trivial
The type does not fall into any of the following categories.
@ PCK_VolatileTrivial
The type would be trivial except that it is volatile-qualified.
bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const
Check if this is or contains a C union that is non-trivial to default-initialize, which is a union th...
A qualifier set is used to build a set of qualifiers.
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
The collection of all-type qualifiers we support.
@ OCL_Strong
Assigning into this object requires the old value to be released and the new value to be retained.
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
@ OCL_Weak
Reading or writing from this object requires a barrier call.
@ OCL_Autoreleasing
Assigning into this object requires a lifetime extension.
ObjCLifetime getObjCLifetime() const
static std::string getAddrSpaceAsString(LangAS AS)
Represents a struct/union/class.
field_range fields() const
static RecordDecl * Create(const ASTContext &C, TagKind TK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, RecordDecl *PrevDecl=nullptr)
specific_decl_iterator< FieldDecl > field_iterator
field_iterator field_begin() const
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
void setMemberSpecialization()
Note that this member template is a specialization.
void setInstantiatedFromMemberTemplate(RedeclarableTemplateDecl *TD)
decl_type * getFirstDecl()
Return the first declaration of this declaration or itself if this is the only declaration.
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Base for LValueReferenceType and RValueReferenceType.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
void setNRVOCandidate(const VarDecl *Var)
Set the variable that might be used for the named return value optimization.
Scope - A scope is a transient data structure that is used while parsing the program.
void setEntity(DeclContext *E)
bool isClassScope() const
isClassScope - Return true if this scope is a class/struct/union scope.
unsigned getDepth() const
Returns the depth of this scope. The translation-unit has scope depth 0.
unsigned getNextFunctionPrototypeIndex()
Return the number of parameters declared in this function prototype, increasing it by one for the nex...
const Scope * getFnParent() const
getFnParent - Return the closest scope that is a function body.
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isTypeAliasScope() const
Determine whether this scope is a type alias scope.
bool isDeclScope(const Decl *D) const
isDeclScope - Return true if this is the scope that the specified decl is declared in.
void setLookupEntity(DeclContext *E)
unsigned getMSLastManglingNumber() const
DeclContext * getEntity() const
Get the entity corresponding to this scope.
unsigned getMSCurManglingNumber() const
bool isTemplateParamScope() const
isTemplateParamScope - Return true if this scope is a C++ template parameter scope.
unsigned getFunctionPrototypeDepth() const
Returns the number of function prototype scopes in this scope chain.
bool isCompoundStmtScope() const
Determine whether this scope is a compound statement scope.
bool containedInPrototypeScope() const
containedInPrototypeScope - Return true if this or a parent scope is a FunctionPrototypeScope.
const Scope * getParent() const
getParent - Return the scope that this is nested in.
bool isFunctionPrototypeScope() const
isFunctionPrototypeScope - Return true if this scope is a function prototype scope.
bool hasUnrecoverableErrorOccurred() const
Determine whether any unrecoverable errors have occurred within this scope.
Scope * getTemplateParamParent()
@ TemplateParamScope
This is a scope that corresponds to the template parameters of a C++ template.
@ DeclScope
This is a scope that can contain a declaration.
void DiagnoseUnguardedBuiltinUsage(FunctionDecl *FD)
void checkNamedBarrierWrapper(RecordDecl *R)
Called in ActOnFields - whenever a C/C++ Record is being finalized.
void CheckSMEFunctionDefAttributes(const FunctionDecl *FD)
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
SemaDiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagId)
Emit a compatibility diagnostic.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
void checkAllowedInitializer(VarDecl *VD)
std::string getConfigureFuncName() const
Returns the name of the launch configuration function.
CUDAFunctionTarget IdentifyTarget(const FunctionDecl *D, bool IgnoreImplicitHDAttr=false)
Determines whether the given function is a CUDA device/host/kernel/etc.
void maybeAddHostDeviceAttrs(FunctionDecl *FD, const LookupResult &Previous)
May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, depending on FD and the current co...
void checkTargetOverload(FunctionDecl *NewFD, const LookupResult &Previous)
Check whether NewFD is a valid overload for CUDA.
void MaybeAddConstantAttr(VarDecl *VD)
May add implicit CUDAConstantAttr attribute to VD, depending on VD and current compilation settings.
void CheckEntryPoint(FunctionDecl *FD)
HLSLVkConstantIdAttr * mergeVkConstantIdAttr(Decl *D, const AttributeCommonInfo &AL, int Id)
HLSLNumThreadsAttr * mergeNumThreadsAttr(Decl *D, const AttributeCommonInfo &AL, int X, int Y, int Z)
void deduceAddressSpace(VarDecl *Decl)
QualType ActOnTemplateShorthand(TemplateDecl *Template, SourceLocation NameLoc)
void ActOnTopLevelFunction(FunctionDecl *FD)
HLSLShaderAttr * mergeShaderAttr(Decl *D, const AttributeCommonInfo &AL, llvm::Triple::EnvironmentType ShaderType)
HLSLWaveSizeAttr * mergeWaveSizeAttr(Decl *D, const AttributeCommonInfo &AL, int Min, int Max, int Preferred, int SpelledArgsCount)
void ActOnVariableDeclarator(VarDecl *VD)
ObjCLiteralKind CheckLiteralKind(Expr *FromE)
void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID)
DiagnoseDuplicateIvars - Check for duplicate ivars in the entire class at the start of @implementatio...
void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, const ObjCMethodDecl *Overridden)
Check whether the given new method is a valid override of the given overridden method,...
DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, IdentifierInfo *II)
The parser has read a name in, and Sema has detected that we're currently inside an ObjC method.
void checkRetainCycles(ObjCMessageExpr *msg)
checkRetainCycles - Check whether an Objective-C message send might create an obvious retain cycle.
ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV)
void AddCFAuditedAttribute(Decl *D)
AddCFAuditedAttribute - Check whether we're currently within '#pragma clang arc_cf_code_audited' and,...
void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, ObjCIvarDecl **Fields, unsigned nIvars, SourceLocation Loc)
CheckImplementationIvars - This routine checks if the instance variables listed in the implelementati...
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
void ActOnVariableDeclarator(VarDecl *VD)
Function called when a variable declarator is created, which lets us implement the 'routine' 'functio...
OpenACCRoutineDeclAttr * mergeRoutineDeclAttr(const OpenACCRoutineDeclAttr &Old)
void ActOnFunctionDeclarator(FunctionDecl *FD)
Called when a function decl is created, which lets us implement the 'routine' 'doesn't match next thi...
void ActOnVariableInit(VarDecl *VD, QualType InitType)
Called when a variable is initialized, so we can implement the 'routine 'doesn't match the next thing...
void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D)
Act on D, a function definition inside of an omp [begin/end] assumes.
void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(Decl *D, SmallVectorImpl< FunctionDecl * > &Bases)
Register D as specialization of all base functions in Bases in the current omp begin/end declare vari...
void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, SmallVectorImpl< FunctionDecl * > &Bases)
The declarator D defines a function in the scope S which is nested in an omp begin/end declare varian...
void ActOnOpenMPDeclareTargetInitializer(Decl *D)
Adds OMPDeclareTargetDeclAttr to referenced variables in declare target directive.
void checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, SourceLocation IdLoc=SourceLocation())
Check declaration inside target region.
void checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D, const llvm::StringMap< bool > &FeatureMap)
StmtResult BuildUnresolvedSYCLKernelCallStmt(CompoundStmt *Body, Expr *LaunchIdExpr)
Builds an UnresolvedSYCLKernelCallStmt to wrap 'Body'.
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body, Expr *LaunchIdExpr)
Builds a SYCLKernelCallStmt to wrap 'Body' and to be used as the body of 'FD'.
void CheckSYCLExternalFunctionDecl(FunctionDecl *FD)
void CheckSYCLEntryPointFunctionDecl(FunctionDecl *FD)
ExprResult BuildSYCLKernelLaunchIdExpr(FunctionDecl *FD, QualType KernelName)
Builds an expression for the lookup of a 'sycl_kernel_launch' template with 'KernelName' as an explic...
SwiftNameAttr * mergeNameAttr(Decl *D, const SwiftNameAttr &SNA, StringRef Name)
SwiftAttrAttr * mergeAttrAttr(Decl *D, const SwiftAttrAttr &SAA)
WebAssemblyExportNameAttr * mergeExportNameAttr(Decl *D, const WebAssemblyExportNameAttr &AL)
WebAssemblyImportNameAttr * mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL)
WebAssemblyImportModuleAttr * mergeImportModuleAttr(Decl *D, const WebAssemblyImportModuleAttr &AL)
Mode getAlignMode() const
A class which encapsulates the logic for delaying diagnostics during parsing and other processing.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
static NameClassification DependentNonType()
static NameClassification VarTemplate(TemplateName Name)
static NameClassification Unknown()
static NameClassification OverloadSet(ExprResult E)
static NameClassification UndeclaredTemplate(TemplateName Name)
static NameClassification FunctionTemplate(TemplateName Name)
static NameClassification NonType(NamedDecl *D)
static NameClassification Concept(TemplateName Name)
static NameClassification UndeclaredNonType()
static NameClassification TypeTemplate(TemplateName Name)
static NameClassification Error()
RAII class used to determine whether SFINAE has trapped any errors that occur during template argumen...
bool hasErrorOccurred() const
Determine whether any SFINAE errors have been trapped.
Sema - This implements semantic analysis and AST building for C.
StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, IdentifierInfo *Ident, ParsedAttributes &Attrs)
QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement)
Substitute Replacement for auto in TypeWithAuto.
bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S)
MergeCXXFunctionDecl - Merge two declarations of the same C++ function, once we already know that the...
Attr * getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, bool IsDefinition)
Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a containing class.
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
SmallVector< DeclaratorDecl *, 4 > ExternalDeclarations
All the external declarations encoutered and used in the TU.
void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D)
LocalInstantiationScope * CurrentInstantiationScope
The current instantiation scope used to store local variables.
sema::CapturingScopeInfo * getEnclosingLambdaOrBlock() const
Get the innermost lambda or block enclosing the current location, if any.
Scope * getCurScope() const
Retrieve the parser's current scope.
void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, LookupResult &OldDecls)
MergeTypedefNameDecl - We just parsed a typedef 'New' which has the same name and scope as a previous...
bool hasStructuralCompatLayout(Decl *D, Decl *Suggested)
Determine if D and Suggested have a structurally compatible layout as described in C11 6....
void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S)
Register the given locally-scoped extern "C" declaration so that it can be found later for redeclarat...
BTFDeclTagAttr * mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL)
NamedDecl * ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope)
bool CheckExplicitObjectOverride(CXXMethodDecl *New, const CXXMethodDecl *Old)
bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S=nullptr, bool AllowInlineNamespace=false) const
isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true if 'D' is in Scope 'S',...
bool IsOverload(FunctionDecl *New, FunctionDecl *Old, bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs=true)
void DiagnoseUnusedParameters(ArrayRef< ParmVarDecl * > Parameters)
Diagnose any unused parameters in the given sequence of ParmVarDecl pointers.
void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old)
Merge the exception specifications of two variable declarations.
bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, const Ts &...Args)
bool isFromSameSingleIncludeHeader(const Decl *PrevD, SourceLocation NewLoc)
Determine if a definition at NewLoc coincides with PrevD.
LookupNameKind
Describes the kind of name lookup to perform.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
@ LookupLocalFriendName
Look up a friend of a local class.
@ LookupRedeclarationWithLinkage
Look up an ordinary name that is going to be redeclared as a name with linkage.
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
void DiagnoseFunctionSpecifiers(const DeclSpec &DS)
Diagnose function specifiers on a declaration of an identifier that does not identify a function.
void ActOnPopScope(SourceLocation Loc, Scope *S)
void ActOnDefinedDeclarationSpecifier(Decl *D)
Called once it is known whether a tag declaration is an anonymous union or struct.
EnforceTCBAttr * mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL)
Decl * ActOnSkippedFunctionBody(Decl *Decl)
QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, QualType Type, TypeSourceInfo *TSI, SourceRange Range, bool DirectInit, Expr *Init)
bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, NamedDecl *PrevMemberDecl, AccessSpecifier LexicalAS)
SetMemberAccessSpecifier - Set the access specifier of a member.
void deduceOpenCLAddressSpace(VarDecl *decl)
bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, bool MergeTypeWithOld, bool NewDeclIsDefn)
MergeFunctionDecl - We just parsed a function 'New' from declarator D which has the same name and sco...
void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, uint64_t MagicValue, QualType Type, bool LayoutCompatible, bool MustBeNull)
Register a magic integral constant to be used as a type tag.
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, DeclarationName Name, SourceLocation Loc, TemplateIdAnnotation *TemplateId, bool IsMemberSpecialization)
Diagnose a declaration whose declarator-id has the given nested-name-specifier.
Decl * ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, SourceLocation IdLoc, IdentifierInfo *Id, const ParsedAttributesView &Attrs, SourceLocation EqualLoc, Expr *Val, SkipBodyInfo *SkipBody=nullptr)
void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID)
void ActOnTagDefinitionError(Scope *S, Decl *TagDecl)
ActOnTagDefinitionError - Invoked when there was an unrecoverable error parsing the definition of a t...
void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body)
NamedDecl * ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, bool &AddToScope, ArrayRef< BindingDecl * > Bindings={})
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, TypeVisibilityAttr::VisibilityType Vis)
void CheckExplicitObjectMemberFunction(Declarator &D, DeclarationName Name, QualType R, bool IsLambda, DeclContext *DC=nullptr)
bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info)
DiagnoseClassNameShadow - Implement C++ [class.mem]p13: If T is the name of a class,...
void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, CXXRecordDecl *Record)
MarkBaseAndMemberDestructorsReferenced - Given a record decl, mark all the non-trivial destructors of...
void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, SourceRange BraceRange)
ActOnTagFinishDefinition - Invoked once we have finished parsing the definition of a tag (enumeration...
FunctionEmissionStatus
Status of the function emission on the CUDA/HIP/OpenMP host/device attrs.
PragmaClangSection PragmaClangRodataSection
NamedDecl * ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, Scope *S)
ImplicitlyDefineFunction - An undeclared identifier was used in a function call, forming a call to an...
std::unique_ptr< CXXFieldCollector > FieldCollector
FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
bool areDocumentationDiagsEnabled(SourceLocation Loc)
Returns true if any of the documentation warnings is enabled at Loc.
Decl * ActOnParamDeclarator(Scope *S, Declarator &D, SourceLocation ExplicitThisLoc={})
ActOnParamDeclarator - Called from Parser::ParseFunctionDeclarator() to introduce parameters into fun...
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the '#pragma clang attribute push' directives to t...
TemplateDecl * AdjustDeclIfTemplate(Decl *&Decl)
AdjustDeclIfTemplate - If the given decl happens to be a template, reset the parameter D to reference...
void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, ExpressionEvaluationContextRecord::ExpressionKind Type=ExpressionEvaluationContextRecord::EK_Other)
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
bool TemplateParameterListsAreEqual(const TemplateCompareNewDeclInfo &NewInstFrom, TemplateParameterList *New, const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, TemplateParameterListEqualKind Kind, SourceLocation TemplateArgLoc=SourceLocation())
Determine whether the given template parameter lists are equivalent.
bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMemberKind CSM, InheritedConstructorInfo *ICI=nullptr, bool Diagnose=false)
Determine if a special member function should have a deleted definition when it is defaulted.
void ActOnExitFunctionContext()
void inferLifetimeCaptureByAttribute(FunctionDecl *FD)
Add [[clang:lifetime_capture_by(this)]] to STL container methods.
ExprResult RebuildExprInCurrentInstantiation(Expr *E)
Preprocessor & getPreprocessor() const
PragmaStack< FPOptionsOverride > FpPragmaStack
PragmaStack< StringLiteral * > CodeSegStack
void AddRangeBasedOptnone(FunctionDecl *FD)
Only called on function definitions; if there is a pragma in scope with the effect of a range-based o...
bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, const CXXMethodDecl *Old)
CheckIfOverriddenFunctionIsMarkedFinal - Checks whether a virtual member function overrides a virtual...
DLLImportAttr * mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI)
static NamedDecl * getAsTemplateNameDecl(NamedDecl *D, bool AllowFunctionTemplates=true, bool AllowDependent=true)
Try to interpret the lookup result D as a template-name.
NamedDecl * HandleDeclarator(Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists)
bool CheckOverridingFunctionAttributes(CXXMethodDecl *New, const CXXMethodDecl *Old)
TemplateParameterList * MatchTemplateParametersToScopeSpecifier(SourceLocation DeclStartLoc, SourceLocation DeclLoc, const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, ArrayRef< TemplateParameterList * > ParamLists, bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, bool SuppressDiagnostic=false)
Match the given template parameter lists to the given scope specifier, returning the template paramet...
void handleTagNumbering(const TagDecl *Tag, Scope *TagScope)
void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl)
AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared special functions,...
void AddAlignmentAttributesForRecord(RecordDecl *RD)
AddAlignmentAttributesForRecord - Adds any needed alignment attributes to a the record decl,...
ErrorAttr * mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, StringRef NewUserDiagnostic)
Decl * ActOnConversionDeclarator(CXXConversionDecl *Conversion)
ActOnConversionDeclarator - Called by ActOnDeclarator to complete the declaration of the given C++ co...
void CheckMain(FunctionDecl *FD, const DeclSpec &D)
void AddKnownFunctionAttributes(FunctionDecl *FD)
Adds any function attributes that we know a priori based on the declaration of this function.
void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver)
If VD is set but not otherwise used, diagnose, for a parameter or a variable.
@ Delete
deleted-function-body
ExprResult VerifyBitField(SourceLocation FieldLoc, const IdentifierInfo *FieldName, QualType FieldTy, bool IsMsStruct, Expr *BitWidth)
VerifyBitField - verifies that a bit field expression is an ICE and has the correct width,...
FieldDecl * HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, Declarator &D, Expr *BitfieldWidth, InClassInitStyle InitStyle, AccessSpecifier AS)
HandleField - Analyze a field of a C struct or a C++ data member.
bool CheckVarDeclSizeAddressSpace(const VarDecl *VD, LangAS AS)
Check whether the given variable declaration has a size that fits within the address space it is decl...
Decl * ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation=false, bool RetainFunctionScopeInfo=false)
Performs semantic analysis at the end of a function body.
ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, bool isAddressOfOperand, const TemplateArgumentListInfo *TemplateArgs)
ActOnDependentIdExpression - Handle a dependent id-expression that was just parsed.
void CheckThreadLocalForLargeAlignment(VarDecl *VD)
PersonalityAttr * mergePersonalityAttr(Decl *D, FunctionDecl *Routine, const AttributeCommonInfo &CI)
NamedDecl * LookupSingleName(Scope *S, DeclarationName Name, SourceLocation Loc, LookupNameKind NameKind, RedeclarationKind Redecl=RedeclarationKind::NotForRedeclaration)
Look up a name, looking for a single declaration.
void ActOnCXXForRangeDecl(Decl *D, bool InExpansionStmt)
void ActOnReenterFunctionContext(Scope *S, Decl *D)
Push the parameters of D, which must be a function, into scope.
sema::LambdaScopeInfo * RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator)
FunctionDecl * getCurFunctionDecl(bool AllowLambda=false) const
Returns a pointer to the innermost enclosing function, or nullptr if the current context is not insid...
const AttributedType * getCallingConvAttributedType(QualType T) const
Get the outermost AttributedType node that sets a calling convention.
TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S)
isTagName() - This method is called for error recovery purposes only to determine if the specified na...
bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old)
[module.interface]p6: A redeclaration of an entity X is implicitly exported if X was introduced by an...
void CheckConversionDeclarator(Declarator &D, QualType &R, StorageClass &SC)
CheckConversionDeclarator - Called by ActOnDeclarator to check the well-formednes of the conversion f...
AvailabilityAttr * mergeAndInferAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, const IdentifierInfo *Platform, bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, int Priority, const IdentifierInfo *IIEnvironment, const IdentifierInfo *InferredPlatformII)
VisibilityAttr * mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, VisibilityAttr::VisibilityType Vis)
Decl * ActOnFileScopeAsmDecl(Expr *expr, SourceLocation AsmLoc, SourceLocation RParenLoc)
ParmVarDecl * BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, QualType T)
Synthesizes a variable for a parameter arising from a typedef.
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
void LazyProcessLifetimeCaptureByParams(FunctionDecl *FD)
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReceiver=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
DeclarationNameInfo GetNameForDeclarator(Declarator &D)
GetNameForDeclarator - Determine the full declaration name for the given Declarator.
llvm::DenseMap< IdentifierInfo *, PendingPragmaInfo > PendingExportedNames
DiagnosticsEngine & getDiagnostics() const
void ActOnFinishTopLevelStmtDecl(TopLevelStmtDecl *D, Stmt *Statement)
void ActOnReenterFunctionPrototypeParams(Scope *S, ArrayRef< ParmVarDecl * > Params)
Add Params to scope, so a late-parsed attribute can name them.
void * SkippedDefinitionContext
bool LookupBuiltin(LookupResult &R)
Lookup a builtin function, when name lookup would otherwise fail.
bool InOverflowBehaviorAssignmentContext
Track if we're currently analyzing overflow behavior types in assignment context.
void DiagPlaceholderFieldDeclDefinitions(RecordDecl *Record)
Emit diagnostic warnings for placeholder members.
void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, TypedefNameDecl *NewTD)
DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType=nullptr)
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
PragmaStack< bool > StrictGuardStackCheckStack
UnusedFileScopedDeclsType UnusedFileScopedDecls
The set of file scoped decls seen so far that have not been used and must warn if not used.
NamedDecl * LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S, bool ForRedeclaration, SourceLocation Loc)
LazilyCreateBuiltin - The specified Builtin-ID was first used at file scope.
ASTContext & getASTContext() const
void translateTemplateArguments(const ASTTemplateArgsPtr &In, TemplateArgumentListInfo &Out)
Translates template arguments as provided by the parser into template arguments used by semantic anal...
void CheckCoroutineWrapper(FunctionDecl *FD)
bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS=nullptr)
isCurrentClassName - Determine whether the identifier II is the name of the class type currently bein...
bool IsRedefinitionInModule(const NamedDecl *New, const NamedDecl *Old) const
Check the redefinition in C++20 Modules.
bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method)
Check whether 'this' shows up in the type of a static member function after the (naturally empty) cv-...
void DiagnoseUnguardedAvailabilityViolations(Decl *FD)
Issue any -Wunguarded-availability warnings in FD.
PragmaStack< StringLiteral * > ConstSegStack
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKin