42#include "llvm/ADT/STLExtras.h"
43#include "llvm/ADT/StringExtras.h"
44#include "llvm/IR/Assumptions.h"
45#include "llvm/MC/MCSectionMachO.h"
46#include "llvm/Support/Error.h"
47#include "llvm/Support/MathExtras.h"
48#include "llvm/Support/raw_ostream.h"
83 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
84 isa<ObjCPropertyDecl>(D);
92 return isa<FunctionProtoType>(FnTy);
93 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
101 return cast<FunctionProtoType>(FnTy)->getNumParams();
102 if (
const auto *BD = dyn_cast<BlockDecl>(D))
103 return BD->getNumParams();
104 return cast<ObjCMethodDecl>(D)->param_size();
109 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
110 return FD->getParamDecl(Idx);
111 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
112 return MD->getParamDecl(Idx);
113 if (
const auto *BD = dyn_cast<BlockDecl>(D))
114 return BD->getParamDecl(Idx);
120 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
121 if (
const auto *BD = dyn_cast<BlockDecl>(D))
122 return BD->getParamDecl(Idx)->getType();
124 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
129 return PVD->getSourceRange();
135 return FnTy->getReturnType();
136 return cast<ObjCMethodDecl>(D)->getReturnType();
140 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
141 return FD->getReturnTypeSourceRange();
142 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
143 return MD->getReturnTypeSourceRange();
149 return cast<FunctionProtoType>(FnTy)->isVariadic();
150 if (
const auto *BD = dyn_cast<BlockDecl>(D))
151 return BD->isVariadic();
152 return cast<ObjCMethodDecl>(D)->isVariadic();
156 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
157 return MethodDecl->isInstance();
162 bool AllowNSAttributedString =
false) {
173 if (AllowNSAttributedString &&
174 ClsName == &Ctx.
Idents.
get(
"NSAttributedString"))
177 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
178 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
204template <
typename AttrInfo>
205static std::enable_if_t<std::is_base_of_v<Attr, AttrInfo>,
SourceLocation>
207 return AL.getLocation();
216template <
typename AttrInfo>
218 uint32_t &Val,
unsigned Idx =
UINT_MAX,
219 bool StrictlyUnsigned =
false) {
220 std::optional<llvm::APSInt> I = llvm::APSInt(32);
233 if (!I->isIntN(32)) {
235 <<
toString(*I, 10,
false) << 32 << 1;
239 if (StrictlyUnsigned && I->isSigned() && I->isNegative()) {
240 S.
Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
245 Val = (uint32_t)I->getZExtValue();
252template <
typename AttrInfo>
254 int &Val,
unsigned Idx =
UINT_MAX) {
259 if (UVal > (uint32_t)std::numeric_limits<int>::max()) {
263 <<
toString(I, 10,
false) << 32 << 0;
273template <
typename AttrTy>
275 if (
const auto *A = D->
getAttr<AttrTy>()) {
276 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
277 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
283template <
typename AttrTy>
285 if (
const auto *A = D->
getAttr<AttrTy>()) {
286 S.
Diag(AL.
getLocation(), diag::err_attributes_are_not_compatible) << &AL
288 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
298template <
typename AttrInfo>
300 Sema &S,
const Decl *D,
const AttrInfo &AI,
unsigned AttrArgNum,
301 const Expr *IdxExpr,
ParamIdx &Idx,
bool CanIndexImplicitThis =
false) {
312 std::optional<llvm::APSInt> IdxInt;
321 unsigned IdxSource = IdxInt->getLimitedValue(
UINT_MAX);
322 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
323 S.
Diag(
getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
327 if (HasImplicitThisParam && !CanIndexImplicitThis) {
328 if (IdxSource == 1) {
329 S.
Diag(
getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
343 const Expr *E, StringRef &Str,
349 if (!Literal || !Literal->isOrdinary()) {
355 Str = Literal->getString();
369 Diag(Loc->
Loc, diag::err_attribute_argument_type)
375 *ArgLocation = Loc->
Loc;
386template <
typename AttrType>
392template <
typename... DiagnosticArgs>
398template <
typename T,
typename... DiagnosticArgs>
401 DiagnosticArgs &&... ExtraArgs) {
403 std::forward<DiagnosticArgs>(ExtraArgs)...);
410template <
typename AttrType,
typename... DiagnosticArgs>
413 bool PassesCheck,
unsigned DiagID,
414 DiagnosticArgs &&... ExtraArgs) {
420 handleSimpleAttribute<AttrType>(S, D, CI);
433 auto IsOverloadedOperatorPresent = [&S](
const RecordDecl *Record,
441 bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
442 bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
443 if (foundStarOperator && foundArrowOperator)
446 const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Record);
450 for (
auto BaseSpecifier : CXXRecord->bases()) {
451 if (!foundStarOperator)
452 foundStarOperator = IsOverloadedOperatorPresent(
453 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
454 if (!foundArrowOperator)
455 foundArrowOperator = IsOverloadedOperatorPresent(
456 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
459 if (foundStarOperator && foundArrowOperator)
470 const auto *VD = cast<ValueDecl>(D);
479 if (RT->isIncompleteType())
486 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
503template <
typename AttrType>
510 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
512 return !Base->hasAttr<AttrType>();
534 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
546 return TN->
hasAttr<CapabilityAttr>();
565 if (
const auto *E = dyn_cast<CastExpr>(Ex))
567 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
569 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
570 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
571 E->getOpcode() == UO_Deref)
574 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
575 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
593 bool ParamIdxOk =
false) {
598 const auto *MD = dyn_cast<const CXXMethodDecl>(D);
599 if (MD && !MD->isStatic()) {
602 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
603 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
605 diag::warn_thread_attribute_not_on_capability_member)
606 << AL << MD->getParent();
608 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
613 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
618 Args.push_back(ArgExp);
622 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
623 if (StrLit->getLength() == 0 ||
624 (StrLit->isOrdinary() && StrLit->getString() == StringRef(
"*"))) {
627 Args.push_back(ArgExp);
633 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
634 Args.push_back(ArgExp);
642 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
643 if (UOp->getOpcode() == UO_AddrOf)
644 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
645 if (DRE->getDecl()->isCXXInstanceMember())
646 ArgTy = DRE->getDecl()->getType();
652 if(!RT && ParamIdxOk) {
653 const auto *FD = dyn_cast<FunctionDecl>(D);
654 const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
656 unsigned int NumParams = FD->getNumParams();
657 llvm::APInt ArgValue = IL->getValue();
658 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
659 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
660 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
662 diag::err_attribute_argument_out_of_bounds_extra_info)
663 << AL << Idx + 1 << NumParams;
666 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
675 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
678 Args.push_back(ArgExp);
698 unsigned Size = Args.size();
732 QualType QT = cast<ValueDecl>(D)->getType();
734 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
751 Expr **StartArg = &Args[0];
753 AcquiredAfterAttr(S.
Context, AL, StartArg, Args.size()));
761 Expr **StartArg = &Args[0];
763 AcquiredBeforeAttr(S.
Context, AL, StartArg, Args.size()));
780 unsigned Size = Args.size();
781 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
783 AssertSharedLockAttr(S.
Context, AL, StartArg, Size));
792 unsigned Size = Args.size();
793 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
795 AssertExclusiveLockAttr(S.
Context, AL, StartArg, Size));
803template <
typename AttrInfo>
805 unsigned AttrArgNo) {
806 assert(AI.isArgExpr(AttrArgNo) &&
"Expected expression argument");
807 Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
816 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
831 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only) << AL;
842 ParamIdx SizeArgNo(SizeArgNoVal, D);
857 AllocSizeAttr(S.
Context, AL, SizeArgNo, NumberArgNo));
866 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
901 unsigned Size = Args.size();
915 unsigned Size = Args.size();
918 Expr **StartArg = &Args[0];
921 LocksExcludedAttr(S.
Context, AL, StartArg, Size));
925 Expr *&Cond, StringRef &Msg) {
931 Cond = Converted.
get();
938 Msg =
"<no message provided>";
944 S.
Diag(AL.
getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
946 S.
Diag(PDiag.first, PDiag.second);
953 S.
Diag(AL.
getLoc(), diag::ext_clang_enable_if);
962 StringRef NewUserDiagnostic;
972class ArgumentDependenceChecker
983 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
991 bool referencesArgs(
Expr *E) {
999 "`this` doesn't refer to the enclosing class?");
1005 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
1006 if (Parms.count(PVD)) {
1017 const auto *DeclFD = cast<FunctionDecl>(D);
1019 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(DeclFD))
1020 if (!MethodDecl->isStatic()) {
1021 S.
Diag(AL.
getLoc(), diag::err_attribute_no_member_function) << AL;
1033 S.
Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
1039 auto *F = dyn_cast_or_null<DeclRefExpr>(AL.
getArgAsExpr(0));
1042 return dyn_cast_or_null<FunctionDecl>(F->getFoundDecl());
1051 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments_for)
1058 for (
unsigned I = 1; I < AL.
getNumArgs(); ++I) {
1070 if (Index > DeclFD->getNumParams()) {
1071 S.
Diag(AL.
getLoc(), diag::err_attribute_bounds_for_function)
1072 << AL << Index << DeclFD << DeclFD->getNumParams();
1077 QualType T2 = DeclFD->getParamDecl(Index - 1)->getType();
1082 << AL << Index << DeclFD << T2 << I << AttrFD << T1;
1086 Indices.push_back(Index - 1);
1090 S.
Context, AL, AttrFD, Indices.data(), Indices.size()));
1094 S.
Diag(AL.
getLoc(), diag::ext_clang_diagnose_if);
1101 StringRef DiagTypeStr;
1105 DiagnoseIfAttr::DiagnosticType DiagType;
1106 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1108 diag::err_diagnose_if_invalid_diagnostic_type);
1112 bool ArgDependent =
false;
1113 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1114 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1116 S.
Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D)));
1120 static constexpr const StringRef kWildcard =
"*";
1123 bool HasWildcard =
false;
1125 const auto AddBuiltinName = [&Names, &HasWildcard](StringRef Name) {
1126 if (Name == kWildcard)
1128 Names.push_back(Name);
1132 if (
const auto *NBA = D->
getAttr<NoBuiltinAttr>())
1133 for (StringRef BuiltinName : NBA->builtinNames())
1134 AddBuiltinName(BuiltinName);
1138 AddBuiltinName(kWildcard);
1140 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
1141 StringRef BuiltinName;
1147 AddBuiltinName(BuiltinName);
1149 S.
Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
1150 << BuiltinName << AL;
1155 Names.erase(std::unique(Names.begin(), Names.end()), Names.end());
1158 if (HasWildcard && Names.size() > 1)
1160 diag::err_attribute_no_builtin_wildcard_or_builtin_name)
1163 if (D->
hasAttr<NoBuiltinAttr>())
1166 NoBuiltinAttr(S.
Context, AL, Names.data(), Names.size()));
1170 if (D->
hasAttr<PassObjectSizeAttr>()) {
1171 S.
Diag(D->
getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
1193 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1194 S.
Diag(D->
getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
1202 ConsumableAttr::ConsumedState DefaultState;
1206 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1208 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1213 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1226 if (!RD->hasAttr<ConsumableAttr>()) {
1227 S.
Diag(AL.
getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
1244 for (
unsigned ArgIndex = 0; ArgIndex < AL.
getNumArgs(); ++ArgIndex) {
1245 CallableWhenAttr::ConsumedState CallableState;
1247 StringRef StateString;
1258 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1260 S.
Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1264 States.push_back(CallableState);
1268 CallableWhenAttr(S.
Context, AL, States.data(), States.size()));
1272 ParamTypestateAttr::ConsumedState ParamState;
1278 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1280 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1281 << AL << StateString;
1285 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1306 ReturnTypestateAttr::ConsumedState ReturnState;
1310 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1312 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1317 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1354 SetTypestateAttr::ConsumedState NewState;
1358 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1359 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1364 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1376 TestTypestateAttr::ConsumedState TestState;
1380 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1381 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1386 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1400 if (
auto *TD = dyn_cast<TagDecl>(D))
1402 else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
1409 if (BitfieldByteAligned)
1411 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1417 if (BitfieldByteAligned)
1418 S.
Diag(AL.
getLoc(), diag::warn_attribute_packed_for_bitfield);
1424 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
1428 auto *RD = cast<CXXRecordDecl>(D);
1430 assert(CTD &&
"attribute does not appertain to this declaration");
1441 if (
const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
1443 Template = CTSD->getSpecializedTemplate();
1445 while (TST && TST->isTypeAlias())
1448 Template = TST->getTemplateName().getAsTemplateDecl();
1457 S.
Diag(AL.
getLoc(), diag::err_attribute_preferred_name_arg_invalid)
1460 S.
Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at)
1468 if (
const auto *VD = dyn_cast<ObjCIvarDecl>(D)) {
1470 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1471 << AL << VD->getType() << 0;
1475 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
1477 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1478 << AL << PD->getType() << 1;
1483 S.
Diag(AL.
getLoc(), diag::warn_attribute_iboutlet) << AL;
1501 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1516 S.
Diag(AL.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1532 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1533 : diag::err_iboutletcollection_type) << QT;
1551 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1553 for (
const auto *I : UD->
fields()) {
1567 bool isReturnValue =
false) {
1570 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1571 << AL << AttrParmRange << TypeRange;
1573 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1574 << AL << AttrParmRange << TypeRange << 0;
1582 for (
unsigned I = 0; I < AL.
getNumArgs(); ++I) {
1596 NonNullArgs.push_back(Idx);
1607 I != E && !AnyPointers; ++I) {
1614 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1617 ParamIdx *Start = NonNullArgs.data();
1618 unsigned Size = NonNullArgs.size();
1619 llvm::array_pod_sort(Start, Start + Size);
1629 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1658 QualType T = cast<ParmVarDecl>(D)->getType();
1660 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1683 AssumeAlignedAttr TmpAttr(
Context, CI, E, OE);
1687 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1688 << &TmpAttr << TmpAttr.getRange() << SR;
1693 std::optional<llvm::APSInt> I = llvm::APSInt(64);
1696 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1700 Diag(AttrLoc, diag::err_attribute_argument_type)
1706 if (!I->isPowerOf2()) {
1707 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1713 Diag(CI.
getLoc(), diag::warn_assume_aligned_too_great)
1718 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1736 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1742 const auto *FuncDecl = cast<FunctionDecl>(D);
1752 << FuncDecl->getParamDecl(Idx.
getASTIndex())->getSourceRange();
1761 StringRef AssumptionStr) {
1762 if (llvm::KnownAssumptionStrings.count(AssumptionStr))
1765 unsigned BestEditDistance = 3;
1766 StringRef Suggestion;
1767 for (
const auto &KnownAssumptionIt : llvm::KnownAssumptionStrings) {
1768 unsigned EditDistance =
1769 AssumptionStr.edit_distance(KnownAssumptionIt.getKey());
1770 if (EditDistance < BestEditDistance) {
1771 Suggestion = KnownAssumptionIt.getKey();
1772 BestEditDistance = EditDistance;
1776 if (!Suggestion.empty())
1777 S.
Diag(Loc, diag::warn_assume_attribute_string_unknown_suggested)
1778 << AssumptionStr << Suggestion;
1780 S.
Diag(Loc, diag::warn_assume_attribute_string_unknown) << AssumptionStr;
1798 if (AttrName.size() > 4 && AttrName.startswith(
"__") &&
1799 AttrName.endswith(
"__")) {
1800 AttrName = AttrName.drop_front(2).drop_back(2);
1816 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1822 OwnershipAttr::OwnershipKind K =
1823 OwnershipAttr(S.
Context, AL,
nullptr,
nullptr, 0).getOwnKind();
1827 case OwnershipAttr::Takes:
1828 case OwnershipAttr::Holds:
1830 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1834 case OwnershipAttr::Returns:
1836 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1844 StringRef ModuleName =
Module->getName();
1850 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1860 case OwnershipAttr::Takes:
1861 case OwnershipAttr::Holds:
1865 case OwnershipAttr::Returns:
1871 S.
Diag(AL.
getLoc(), diag::err_ownership_type) << AL << Err
1880 if (I->getOwnKind() != K && llvm::is_contained(I->args(), Idx)) {
1881 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << I;
1883 }
else if (K == OwnershipAttr::Returns &&
1884 I->getOwnKind() == OwnershipAttr::Returns) {
1887 if (!llvm::is_contained(I->args(), Idx)) {
1888 S.
Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1889 << I->args_begin()->getSourceIndex();
1891 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1897 OwnershipArgs.push_back(Idx);
1900 ParamIdx *Start = OwnershipArgs.data();
1901 unsigned Size = OwnershipArgs.size();
1902 llvm::array_pod_sort(Start, Start + Size);
1910 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1926 S.
Diag(AL.
getLoc(), diag::err_attribute_weakref_not_global_context)
1927 << cast<NamedDecl>(D);
1971 const auto *FD = cast<FunctionDecl>(D);
1973 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 1;
1986 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_darwin);
1990 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_nvptx);
1994 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1996 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 0;
2000 const auto *VD = cast<VarDecl>(D);
2001 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
2002 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << VD << 0;
2029 if (Model !=
"global-dynamic" && Model !=
"local-dynamic"
2030 && Model !=
"initial-exec" && Model !=
"local-exec") {
2031 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
2036 Model !=
"global-dynamic") {
2037 S.
Diag(LiteralLoc, diag::err_aix_attr_unsupported_tls_model) << Model;
2051 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
2059 if (checkAttrMutualExclusion<CPUSpecificAttr>(S, D, AL))
2062 if (
const auto *Other = D->
getAttr<CPUDispatchAttr>()) {
2063 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
2064 S.
Diag(Other->getLocation(), diag::note_conflicting_attribute);
2067 }
else if (AL.
getParsedKind() == ParsedAttr::AT_CPUSpecific) {
2068 if (checkAttrMutualExclusion<CPUDispatchAttr>(S, D, AL))
2071 if (
const auto *Other = D->
getAttr<CPUSpecificAttr>()) {
2072 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
2073 S.
Diag(Other->getLocation(), diag::note_conflicting_attribute);
2080 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
2081 if (MD->getParent()->isLambda()) {
2082 S.
Diag(AL.
getLoc(), diag::err_attribute_dll_lambda) << AL;
2093 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
2102 S.
Diag(CPUArg->
Loc, diag::err_invalid_cpu_specific_dispatch_value)
2103 << CPUName << (AL.
getKind() == ParsedAttr::AT_CPUDispatch);
2109 return Target.CPUSpecificManglingCharacter(CPUName) ==
2112 S.
Diag(AL.
getLoc(), diag::warn_multiversion_duplicate_entries);
2115 CPUs.push_back(CPUArg->
Ident);
2119 if (AL.
getKind() == ParsedAttr::AT_CPUSpecific)
2121 CPUSpecificAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
2124 CPUDispatchAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
2129 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
2139 S.
Diag(AL.
getLoc(), diag::err_attribute_not_clinkage) << AL;
2143 const auto *FD = cast<FunctionDecl>(D);
2145 S.
Diag(AL.
getLoc(), diag::warn_attribute_cmse_entry_static);
2155 const auto &Arch = Triple.getArch();
2156 if (Arch != llvm::Triple::x86 &&
2157 (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
2158 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_on_arch)
2159 << AL << Triple.getArchName();
2165 if (S.
getLangOpts().MSVCCompat && isa<CXXMethodDecl>(D)) {
2166 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_decl_type_str)
2167 << AL <<
"non-member functions";
2178 if (!isa<ObjCMethodDecl>(D)) {
2179 S.
Diag(Attrs.
getLoc(), diag::warn_attribute_wrong_decl_type)
2204 S.
Diag(Attrs.
getLoc(), diag::warn_nocf_check_attribute_ignored);
2206 handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);
2221 Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored)
2239 ? diag::err_attribute_wrong_decl_type
2240 : diag::warn_attribute_wrong_decl_type)
2275 if (VecReturnAttr *A = D->
getAttr<VecReturnAttr>()) {
2276 S.
Diag(AL.
getLoc(), diag::err_repeat_attribute) << A;
2280 const auto *R = cast<RecordDecl>(D);
2283 if (!isa<CXXRecordDecl>(R)) {
2284 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2288 if (!cast<CXXRecordDecl>(R)->isPOD()) {
2289 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2293 for (
const auto *I : R->fields()) {
2294 if ((count == 1) || !I->getType()->isVectorType()) {
2295 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2306 if (isa<ParmVarDecl>(D)) {
2311 diag::err_carries_dependency_param_not_function_decl);
2325 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2331 uint32_t priority = ConstructorAttr::DefaultPriority;
2333 S.
Diag(AL.
getLoc(), diag::err_hlsl_init_priority_unsupported);
2344 uint32_t priority = DestructorAttr::DefaultPriority;
2352template <
typename AttrTy>
2364 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2365 S.
Diag(AL.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
2375 VersionTuple Introduced,
2376 VersionTuple Deprecated,
2377 VersionTuple Obsoleted) {
2378 StringRef PlatformName
2379 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2380 if (PlatformName.empty())
2381 PlatformName = Platform->
getName();
2385 if (!Introduced.empty() && !Deprecated.empty() &&
2386 !(Introduced <= Deprecated)) {
2387 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2388 << 1 << PlatformName << Deprecated.getAsString()
2389 << 0 << Introduced.getAsString();
2393 if (!Introduced.empty() && !Obsoleted.empty() &&
2394 !(Introduced <= Obsoleted)) {
2395 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2396 << 2 << PlatformName << Obsoleted.getAsString()
2397 << 0 << Introduced.getAsString();
2401 if (!Deprecated.empty() && !Obsoleted.empty() &&
2402 !(Deprecated <= Obsoleted)) {
2403 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2404 << 2 << PlatformName << Obsoleted.getAsString()
2405 << 1 << Deprecated.getAsString();
2417 bool BeforeIsOkay) {
2418 if (
X.empty() || Y.empty())
2424 if (BeforeIsOkay &&
X < Y)
2432 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
2433 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
2436 VersionTuple MergedIntroduced = Introduced;
2437 VersionTuple MergedDeprecated = Deprecated;
2438 VersionTuple MergedObsoleted = Obsoleted;
2439 bool FoundAny =
false;
2440 bool OverrideOrImpl =
false;
2444 OverrideOrImpl =
false;
2450 OverrideOrImpl =
true;
2456 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2457 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2464 if (OldPlatform != Platform) {
2472 if (OldAA->getPriority() <
Priority)
2478 if (OldAA->getPriority() >
Priority) {
2479 Attrs.erase(Attrs.begin() + i);
2485 VersionTuple OldIntroduced = OldAA->getIntroduced();
2486 VersionTuple OldDeprecated = OldAA->getDeprecated();
2487 VersionTuple OldObsoleted = OldAA->getObsoleted();
2488 bool OldIsUnavailable = OldAA->getUnavailable();
2490 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2491 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2493 !(OldIsUnavailable == IsUnavailable ||
2494 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2495 if (OverrideOrImpl) {
2497 VersionTuple FirstVersion;
2498 VersionTuple SecondVersion;
2499 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2501 FirstVersion = OldIntroduced;
2502 SecondVersion = Introduced;
2503 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2505 FirstVersion = Deprecated;
2506 SecondVersion = OldDeprecated;
2507 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2509 FirstVersion = Obsoleted;
2510 SecondVersion = OldObsoleted;
2514 Diag(OldAA->getLocation(),
2515 diag::warn_mismatched_availability_override_unavail)
2516 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2527 Diag(OldAA->getLocation(),
2528 diag::warn_mismatched_availability_override)
2530 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2531 << FirstVersion.getAsString() << SecondVersion.getAsString()
2535 Diag(CI.
getLoc(), diag::note_overridden_method);
2537 Diag(CI.
getLoc(), diag::note_protocol_method);
2539 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2540 Diag(CI.
getLoc(), diag::note_previous_attribute);
2543 Attrs.erase(Attrs.begin() + i);
2548 VersionTuple MergedIntroduced2 = MergedIntroduced;
2549 VersionTuple MergedDeprecated2 = MergedDeprecated;
2550 VersionTuple MergedObsoleted2 = MergedObsoleted;
2552 if (MergedIntroduced2.empty())
2553 MergedIntroduced2 = OldIntroduced;
2554 if (MergedDeprecated2.empty())
2555 MergedDeprecated2 = OldDeprecated;
2556 if (MergedObsoleted2.empty())
2557 MergedObsoleted2 = OldObsoleted;
2560 MergedIntroduced2, MergedDeprecated2,
2561 MergedObsoleted2)) {
2562 Attrs.erase(Attrs.begin() + i);
2567 MergedIntroduced = MergedIntroduced2;
2568 MergedDeprecated = MergedDeprecated2;
2569 MergedObsoleted = MergedObsoleted2;
2575 MergedIntroduced == Introduced &&
2576 MergedDeprecated == Deprecated &&
2577 MergedObsoleted == Obsoleted)
2583 MergedDeprecated, MergedObsoleted) &&
2585 auto *Avail = ::new (
Context) AvailabilityAttr(
2586 Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable,
2587 Message, IsStrict, Replacement,
Priority);
2588 Avail->setImplicit(Implicit);
2595 if (isa<UsingDecl, UnresolvedUsingTypenameDecl, UnresolvedUsingValueDecl>(
2607 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2608 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2611 auto *ND = dyn_cast<NamedDecl>(D);
2621 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getMessageExpr()))
2622 Str = SE->getString();
2623 StringRef Replacement;
2625 Replacement = SE->getString();
2627 if (II->
isStr(
"swift")) {
2629 (!IsUnavailable && !Deprecated.
isValid())) {
2631 diag::warn_availability_swift_unavailable_deprecated_only);
2636 if (II->
isStr(
"fuchsia")) {
2637 std::optional<unsigned> Min, Sub;
2638 if ((Min = Introduced.
Version.getMinor()) ||
2639 (Sub = Introduced.
Version.getSubminor())) {
2640 S.
Diag(AL.
getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2650 Obsoleted.
Version, IsUnavailable, Str, IsStrict, Replacement,
2661 else if (II->
getName() ==
"ios_app_extension")
2666 const auto *IOSToWatchOSMapping =
2671 auto adjustWatchOSVersion =
2672 [IOSToWatchOSMapping](VersionTuple Version) -> VersionTuple {
2673 if (Version.empty())
2675 auto MinimumWatchOSVersion = VersionTuple(2, 0);
2677 if (IOSToWatchOSMapping) {
2678 if (
auto MappedVersion = IOSToWatchOSMapping->map(
2679 Version, MinimumWatchOSVersion, std::nullopt)) {
2680 return *MappedVersion;
2684 auto Major = Version.getMajor();
2685 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2686 if (NewMajor >= 2) {
2687 if (Version.getMinor()) {
2688 if (Version.getSubminor())
2689 return VersionTuple(NewMajor, *Version.getMinor(),
2690 *Version.getSubminor());
2692 return VersionTuple(NewMajor, *Version.getMinor());
2694 return VersionTuple(NewMajor);
2697 return MinimumWatchOSVersion;
2700 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2701 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2702 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2705 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2706 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2718 else if (II->
getName() ==
"ios_app_extension")
2723 const auto *IOSToTvOSMapping =
2728 auto AdjustTvOSVersion =
2729 [IOSToTvOSMapping](VersionTuple Version) -> VersionTuple {
2730 if (Version.empty())
2733 if (IOSToTvOSMapping) {
2734 if (
auto MappedVersion = IOSToTvOSMapping->map(
2735 Version, VersionTuple(0, 0), std::nullopt)) {
2736 return *MappedVersion;
2742 auto NewIntroduced = AdjustTvOSVersion(Introduced.
Version);
2743 auto NewDeprecated = AdjustTvOSVersion(Deprecated.
Version);
2744 auto NewObsoleted = AdjustTvOSVersion(Obsoleted.
Version);
2747 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2748 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2755 llvm::Triple::IOS &&
2757 auto GetSDKInfo = [&]() {
2766 else if (II->
getName() ==
"ios_app_extension")
2769 auto MinMacCatalystVersion = [](
const VersionTuple &
V) {
2772 if (
V.getMajor() < 13 ||
2773 (
V.getMajor() == 13 &&
V.getMinor() && *
V.getMinor() < 1))
2774 return VersionTuple(13, 1);
2779 MinMacCatalystVersion(Introduced.
Version),
2780 MinMacCatalystVersion(Deprecated.
Version),
2781 MinMacCatalystVersion(Obsoleted.
Version), IsUnavailable, Str,
2786 }
else if (II->
getName() ==
"macos" && GetSDKInfo() &&
2788 !Obsoleted.
Version.empty())) {
2789 if (
const auto *MacOStoMacCatalystMapping =
2790 GetSDKInfo()->getVersionMapping(
2797 auto RemapMacOSVersion =
2798 [&](
const VersionTuple &
V) -> std::optional<VersionTuple> {
2800 return std::nullopt;
2802 if (
V.getMajor() == 100000)
2803 return VersionTuple(100000);
2805 return MacOStoMacCatalystMapping->map(
V, VersionTuple(13, 1),
2808 std::optional<VersionTuple> NewIntroduced =
2809 RemapMacOSVersion(Introduced.
Version),
2811 RemapMacOSVersion(Deprecated.
Version),
2813 RemapMacOSVersion(Obsoleted.
Version);
2814 if (NewIntroduced || NewDeprecated || NewObsoleted) {
2815 auto VersionOrEmptyVersion =
2816 [](
const std::optional<VersionTuple> &
V) -> VersionTuple {
2817 return V ? *
V : VersionTuple();
2821 VersionOrEmptyVersion(NewIntroduced),
2822 VersionOrEmptyVersion(NewDeprecated),
2823 VersionOrEmptyVersion(NewObsoleted),
false, Str,
2841 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(0)))
2843 StringRef DefinedIn;
2844 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(1)))
2845 DefinedIn = SE->getString();
2846 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2848 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(3)))
2849 USR = SE->getString();
2857 typename T::VisibilityType value) {
2858 T *existingAttr = D->
getAttr<T>();
2860 typename T::VisibilityType existingValue = existingAttr->getVisibility();
2861 if (existingValue == value)
2863 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2864 S.
Diag(CI.
getLoc(), diag::note_previous_attribute);
2872 VisibilityAttr::VisibilityType Vis) {
2873 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, CI, Vis);
2878 TypeVisibilityAttr::VisibilityType Vis) {
2879 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, CI, Vis);
2883 bool isTypeVisibility) {
2885 if (isa<TypedefNameDecl>(D)) {
2891 if (isTypeVisibility &&
2892 !(isa<TagDecl>(D) ||
2893 isa<ObjCInterfaceDecl>(D) ||
2894 isa<NamespaceDecl>(D))) {
2906 VisibilityAttr::VisibilityType
type;
2907 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr,
type)) {
2908 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2915 if (
type == VisibilityAttr::Protected &&
2917 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2918 type = VisibilityAttr::Default;
2922 if (isTypeVisibility) {
2924 D, AL, (TypeVisibilityAttr::VisibilityType)
type);
2935 S.
Diag(AL.
getLoc(), diag::err_objc_direct_on_protocol) <<
false;
2940 handleSimpleAttribute<ObjCDirectAttr>(S, D, AL);
2942 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2949 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
2951 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2956 const auto *M = cast<ObjCMethodDecl>(D);
2958 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2964 ObjCMethodFamilyAttr::FamilyKind F;
2965 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2966 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL << IL->
Ident;
2970 if (F == ObjCMethodFamilyAttr::OMF_init &&
2971 !M->getReturnType()->isObjCObjectPointerType()) {
2972 S.
Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2973 << M->getReturnType();
2982 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2983 QualType T = TD->getUnderlyingType();
2985 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2989 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2992 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
3009 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
3010 QualType T = TD->getUnderlyingType();
3012 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
3024 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3030 BlocksAttr::BlockType
type;
3031 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
3032 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3040 unsigned sentinel = (
unsigned)SentinelAttr::DefaultSentinel;
3043 std::optional<llvm::APSInt> Idx = llvm::APSInt(32);
3045 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3050 if (Idx->isSigned() && Idx->isNegative()) {
3051 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
3056 sentinel = Idx->getZExtValue();
3059 unsigned nullPos = (
unsigned)SentinelAttr::DefaultNullPos;
3062 std::optional<llvm::APSInt> Idx = llvm::APSInt(32);
3064 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3068 nullPos = Idx->getZExtValue();
3070 if ((Idx->isSigned() && Idx->isNegative()) || nullPos > 1) {
3073 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
3079 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3081 if (isa<FunctionNoProtoType>(FT)) {
3082 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
3086 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
3087 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
3090 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
3091 if (!MD->isVariadic()) {
3092 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
3095 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
3096 if (!BD->isVariadic()) {
3097 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
3100 }
else if (
const auto *
V = dyn_cast<VarDecl>(D)) {
3108 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
3110 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
3114 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3119 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3129 !isa<CXXConstructorDecl>(D)) {
3130 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
3133 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
3134 if (MD->getReturnType()->isVoidType()) {
3135 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
3143 if (isa<VarDecl>(D))
3144 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type_str)
3145 << AL <<
"functions, classes, or enumerations";
3154 if (LO.CPlusPlus && !LO.CPlusPlus20)
3155 S.
Diag(AL.
getLoc(), diag::ext_cxx20_attr) << AL;
3163 }
else if (LO.CPlusPlus && !LO.CPlusPlus17)
3164 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
3169 isa<TypedefNameDecl>(D)) {
3170 S.
Diag(AL.
getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
3183 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
3185 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
3187 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
3190 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3200template <
typename WorkGroupAttr>
3203 for (
unsigned i = 0; i < 3; ++i) {
3208 if (WGSize[i] == 0) {
3209 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
3215 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
3216 if (Existing && !(Existing->getXDim() == WGSize[0] &&
3217 Existing->getYDim() == WGSize[1] &&
3218 Existing->getZDim() == WGSize[2]))
3219 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3222 WorkGroupAttr(S.
Context, AL, WGSize[0], WGSize[1], WGSize[2]));
3232 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
3237 OpenCLIntelReqdSubGroupSizeAttr *Existing =
3238 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
3239 if (Existing && Existing->getSubGroupSize() != SGSize)
3240 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3243 OpenCLIntelReqdSubGroupSizeAttr(S.
Context, AL, SGSize));
3248 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3254 assert(ParmTSI &&
"no type source info for attribute argument");
3259 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
3263 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
3265 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3277 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3282 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
3283 if (ExistingAttr->getName() == Name)
3285 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3287 Diag(CI.
getLoc(), diag::note_previous_attribute);
3304 return llvm::Error::success();
3307 StringRef Segment, Section;
3308 unsigned TAA, StubSize;
3310 return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
3311 TAA, HasTAA, StubSize);
3316 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3341 cast<NamedDecl>(D));
3348 StringRef CodeSegName) {
3350 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3362 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3366 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3367 if (ExistingAttr->getName() == Name)
3369 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3371 Diag(CI.
getLoc(), diag::note_previous_attribute);
3384 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3385 if (!ExistingAttr->isImplicit()) {
3387 ExistingAttr->getName() == Str
3388 ? diag::warn_duplicate_codeseg_attribute
3389 : diag::err_conflicting_codeseg_attribute);
3401 enum FirstParam { Unsupported, Duplicate,
Unknown };
3402 enum SecondParam {
None, CPU, Tune };
3404 if (AttrStr.contains(
"fpmath="))
3405 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3406 << Unsupported <<
None <<
"fpmath=" <<
Target;
3410 AttrStr.contains(
"tune="))
3411 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3417 if (!ParsedAttrs.
CPU.empty() &&
3419 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3422 if (!ParsedAttrs.
Tune.empty() &&
3424 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3428 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3431 for (
const auto &Feature : ParsedAttrs.
Features) {
3432 auto CurFeature = StringRef(Feature).drop_front();
3434 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3435 << Unsupported <<
None << CurFeature <<
Target;
3444 if (DiagMsg.empty())
3445 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3446 << Unsupported <<
None <<
"branch-protection" <<
Target;
3447 return Diag(LiteralLoc, diag::err_invalid_branch_protection_spec)
3450 if (!DiagMsg.empty())
3451 Diag(LiteralLoc, diag::warn_unsupported_branch_protection_spec) << DiagMsg;
3459 enum FirstParam { Unsupported };
3460 enum SecondParam {
None };
3462 if (AttrStr.trim() ==
"default")
3465 AttrStr.split(Features,
"+");
3466 for (
auto &CurFeature : Features) {
3467 CurFeature = CurFeature.trim();
3468 if (CurFeature ==
"default")
3471 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3480 bool isDefault =
false;
3486 TargetVersionAttr *NewAttr =
3499 TargetAttr *NewAttr = ::new (S.
Context) TargetAttr(S.
Context, AL, Str);
3505 bool &HasDefault,
bool &HasCommas,
bool &HasNotDefault,
3507 enum FirstParam { Unsupported, Duplicate,
Unknown };
3508 enum SecondParam {
None, CPU, Tune };
3510 HasCommas = HasCommas || Str.contains(
',');
3513 if (Str.size() == 0)
3514 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3517 std::pair<StringRef, StringRef> Parts = {{}, Str};
3518 while (!Parts.second.empty()) {
3519 Parts = Parts.second.split(
',');
3520 StringRef Cur = Parts.first.trim();
3522 Literal->getLocationOfByte(Cur.data() - Literal->getString().data(),
3525 bool DefaultIsDupe =
false;
3526 bool HasCodeGenImpact =
false;
3528 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3533 if (Cur ==
"default") {
3534 DefaultIsDupe = HasDefault;
3536 if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
3537 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3539 StringsBuffer.push_back(Cur);
3541 std::pair<StringRef, StringRef> CurParts = {{}, Cur};
3543 while (!CurParts.second.empty()) {
3544 CurParts = CurParts.second.split(
'+');
3545 StringRef CurFeature = CurParts.first.trim();
3547 Diag(CurLoc, diag::warn_unsupported_target_attribute)
3552 HasCodeGenImpact =
true;
3553 CurFeatures.push_back(CurFeature);
3556 llvm::sort(CurFeatures);
3558 for (
auto &CurFeat : CurFeatures) {
3559 if (!Res.equals(
""))
3561 Res.append(CurFeat);
3563 if (llvm::is_contained(StringsBuffer, Res) || DefaultIsDupe)
3564 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3565 else if (!HasCodeGenImpact)
3568 Diag(CurLoc, diag::warn_target_clone_no_impact_options);
3569 else if (!Res.empty()) {
3570 StringsBuffer.push_back(Res);
3571 HasNotDefault =
true;
3576 if (Cur.startswith(
"arch=")) {
3578 Cur.drop_front(
sizeof(
"arch=") - 1)))
3579 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3580 << Unsupported << CPU << Cur.drop_front(
sizeof(
"arch=") - 1)
3582 }
else if (Cur ==
"default") {
3583 DefaultIsDupe = HasDefault;
3586 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3588 if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
3589 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3591 StringsBuffer.push_back(Cur);
3594 if (Str.rtrim().endswith(
","))
3595 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3607 if (
const auto *Other = D->
getAttr<TargetClonesAttr>()) {
3608 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3609 S.
Diag(Other->getLocation(), diag::note_conflicting_attribute);
3612 if (checkAttrMutualExclusion<TargetClonesAttr>(S, D, AL))
3617 bool HasCommas =
false, HasDefault =
false, HasNotDefault =
false;
3619 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
3626 HasDefault, HasCommas, HasNotDefault, StringsBuffer))
3629 for (
auto &SmallStr : StringsBuffer)
3630 Strings.push_back(SmallStr.str());
3633 S.
Diag(AL.
getLoc(), diag::warn_target_clone_mixed_values);
3638 Strings.push_back(
"default");
3642 S.
Diag(AL.
getLoc(), diag::err_target_clone_must_have_default);
3648 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
3649 if (MD->getParent()->isLambda()) {
3661 cast<FunctionDecl>(D)->setIsMultiVersion();
3662 TargetClonesAttr *NewAttr = ::new (S.
Context)
3663 TargetClonesAttr(S.
Context, AL, Strings.data(), Strings.size());
3675 MinVectorWidthAttr *Existing = D->
getAttr<MinVectorWidthAttr>();
3676 if (Existing && Existing->getVectorWidth() != VecWidth) {
3677 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3692 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3694 S.
Diag(Loc, diag::warn_cleanup_ext);
3695 FD = dyn_cast<FunctionDecl>(DRE->
getDecl());
3698 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3702 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3703 if (ULE->hasExplicitTemplateArgs())
3704 S.
Diag(Loc, diag::warn_cleanup_ext);
3706 NI = ULE->getNameInfo();
3708 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3715 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3720 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3731 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3732 << NI.
getName() << ParamTy << Ty;
3742 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3747 EnumExtensibilityAttr::Kind ExtensibilityKind;
3749 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3750 ExtensibilityKind)) {
3751 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3756 EnumExtensibilityAttr(S.
Context, AL, ExtensibilityKind));
3771 if (NotNSStringTy &&
3775 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3783 if (
auto *OMD = dyn_cast<ObjCMethodDecl>(D))
3784 if (
auto *Interface = OMD->getClassInterface())
3786 QualType(Interface->getTypeForDecl(), 0));
3791 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3792 << (NotNSStringTy ?
"string type" :
"NSString")
3812 return llvm::StringSwitch<FormatAttrKind>(Format)
3826 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag",
IgnoredFormat)
3834 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3839 S.
Diag(AL.
getLoc(), diag::err_hlsl_init_priority_unsupported);
3844 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3848 QualType T = cast<VarDecl>(D)->getType();
3852 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3858 uint32_t prioritynum;
3867 if ((prioritynum < 101 || prioritynum > 65535) &&
3869 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
3878 StringRef NewUserDiagnostic) {
3879 if (
const auto *EA = D->
getAttr<ErrorAttr>()) {
3881 assert((NewAttr ==
"error" || NewAttr ==
"warning") &&
3882 "unexpected normalized full name");
3883 bool Match = (EA->isError() && NewAttr ==
"error") ||
3884 (EA->isWarning() && NewAttr ==
"warning");
3886 Diag(EA->getLocation(), diag::err_attributes_are_not_compatible)
3888 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
3891 if (EA->getUserDiagnostic() != NewUserDiagnostic) {
3892 Diag(CI.
getLoc(), diag::warn_duplicate_attribute) << EA;
3893 Diag(EA->getLoc(), diag::note_previous_attribute);
3897 return ::new (
Context) ErrorAttr(
Context, CI, NewUserDiagnostic);
3905 if (F->getType() == Format &&
3906 F->getFormatIdx() == FormatIdx &&
3907 F->getFirstArg() == FirstArg) {
3910 if (F->getLocation().isInvalid())
3916 return ::new (
Context) FormatAttr(
Context, CI, Format, FormatIdx, FirstArg);
3923 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3934 StringRef Format = II->
getName();
3948 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3959 if (Idx < 1 || Idx > NumArgs) {
3960 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3966 unsigned ArgIdx = Idx - 1;
3968 if (HasImplicitThisParam) {
3971 diag::err_format_attribute_implicit_this_format_string)
3985 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3997 if (FirstArg != 0) {
4001 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
4009 if (FirstArg != NumArgs + 1) {
4010 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
4013 std::to_string(NumArgs + 1));
4018 S.
Diag(D->
getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
4019 if (FirstArg <= Idx) {
4023 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
4039 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_no_callee)
4048 assert(FD &&
"Expected a function declaration!");
4050 llvm::StringMap<int> NameIdxMapping;
4051 NameIdxMapping[
"__"] = -1;
4053 NameIdxMapping[
"this"] = 0;
4057 NameIdxMapping[PVD->getName()] = Idx++;
4059 auto UnknownName = NameIdxMapping.end();
4062 for (
unsigned I = 0, E = AL.
getNumArgs(); I < E; ++I) {
4068 auto It = NameIdxMapping.find(IdLoc->
Ident->
getName());
4069 if (It == UnknownName) {
4070 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_argument_unknown)
4076 ArgIdx = It->second;
4083 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
4089 if (ArgIdx < -1 || ArgIdx > NumArgs) {
4090 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
4097 llvm_unreachable(
"Unexpected ParsedAttr argument type!");
4100 if (ArgIdx == 0 && !HasImplicitThisParam) {
4101 S.
Diag(AL.
getLoc(), diag::err_callback_implicit_this_not_available)
4108 if (!HasImplicitThisParam && ArgIdx > 0)
4111 EncodingIndices.push_back(ArgIdx);
4114 int CalleeIdx = EncodingIndices.front();
4118 if (CalleeIdx < (
int)HasImplicitThisParam) {
4119 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_invalid_callee)
4126 const Type *CalleeType =
4130 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
4135 const Type *CalleeFnType =
4140 const auto *CalleeFnProtoType = dyn_cast<FunctionProtoType>(CalleeFnType);
4141 if (!CalleeFnProtoType) {
4142 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
4147 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
4148 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
4149 << AL << (
unsigned)(EncodingIndices.size() - 1);
4153 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
4154 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
4155 << AL << (
unsigned)(EncodingIndices.size() - 1);
4159 if (CalleeFnProtoType->isVariadic()) {
4165 if (D->
hasAttr<CallbackAttr>()) {
4171 S.
Context, AL, EncodingIndices.data(), EncodingIndices.size()));
4184 QualType T = cast<ParmVarDecl>(D)->getType();
4187 S.
Diag(AL.
getLoc(), diag::err_called_once_attribute_wrong_type);
4197 const auto *TD = dyn_cast<TypedefNameDecl>(D);
4198 if (TD && TD->getUnderlyingType()->isUnionType())
4199 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
4201 RD = dyn_cast<RecordDecl>(D);
4204 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type) << AL
4212 diag::warn_transparent_union_attribute_not_definition);
4218 if (Field == FieldEnd) {
4219 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
4227 diag::warn_transparent_union_attribute_floating)
4236 for (; Field != FieldEnd; ++Field) {
4237 QualType FieldType = Field->getType();
4251 S.
Diag(Field->getLocation(),
4252 diag::warn_transparent_union_attribute_field_size_align)
4253 << isSize << *Field << FieldBits;
4254 unsigned FirstBits = isSize ? FirstSize : FirstAlign;
4256 diag::note_transparent_union_first_field_size_align)
4257 << isSize << FirstBits;
4267 auto *
Attr = AnnotateAttr::Create(
Context, Str, Args.data(), Args.size(), CI);
4283 for (
unsigned Idx = 1; Idx < AL.
getNumArgs(); Idx++) {
4296 AlignValueAttr TmpAttr(
Context, CI, E);
4300 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4301 T = TD->getUnderlyingType();
4302 else if (
const auto *VD = dyn_cast<ValueDecl>(D))
4305 llvm_unreachable(
"Unknown decl type for align_value");
4309 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
4315 llvm::APSInt Alignment;
4317 E, &Alignment, diag::err_align_value_attribute_argument_not_int);
4321 if (!Alignment.isPowerOf2()) {
4322 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
4338 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
4350 diag::err_pack_expansion_without_parameter_packs);
4361 bool IsPackExpansion) {
4362 AlignedAttr TmpAttr(
Context, CI,
true, E);
4366 if (TmpAttr.isAlignas()) {
4382 if (isa<ParmVarDecl>(D)) {
4384 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4387 if (VD->isExceptionVariable())
4389 }
else if (
const auto *FD = dyn_cast<FieldDecl>(D)) {
4390 if (FD->isBitField())
4392 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4393 if (ED->getLangOpts().CPlusPlus)
4395 }
else if (!isa<TagDecl>(D)) {
4396 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
4401 if (DiagKind != -1) {
4402 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
4403 << &TmpAttr << DiagKind;
4412 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
4413 if (!TND->getUnderlyingType()->isDependentType()) {
4414 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
4421 AlignedAttr *AA = ::new (
Context) AlignedAttr(
Context, CI,
true, E);
4422 AA->setPackExpansion(IsPackExpansion);
4428 llvm::APSInt Alignment;
4430 E, &Alignment, diag::err_aligned_attribute_argument_not_int);
4434 uint64_t AlignVal = Alignment.getZExtValue();
4440 if (!(TmpAttr.isAlignas() && !Alignment)) {
4441 if (!llvm::isPowerOf2_64(AlignVal)) {
4442 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
4452 Diag(AttrLoc, diag::err_attribute_aligned_too_great)
4457 const auto *VD = dyn_cast<VarDecl>(D);
4459 unsigned MaxTLSAlign =
4462 if (MaxTLSAlign && AlignVal > MaxTLSAlign &&
4464 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
4465 << (
unsigned)AlignVal << VD << MaxTLSAlign;
4473 const Type *Ty = VD->getType().getTypePtr();
4475 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4476 << VD->getType() << 16;
4482 AA->setPackExpansion(IsPackExpansion);
4490 AlignedAttr *AA = ::new (
Context) AlignedAttr(
Context, CI,
false, TS);
4491 AA->setPackExpansion(IsPackExpansion);
4496 assert(D->
hasAttrs() &&
"no attributes on decl");
4499 if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
4500 UnderlyingTy = DiagTy = VD->getType();
4503 if (
const auto *ED = dyn_cast<EnumDecl>(D))
4504 UnderlyingTy = ED->getIntegerType();
4513 AlignedAttr *AlignasAttr =
nullptr;
4514 AlignedAttr *LastAlignedAttr =
nullptr;
4517 if (I->isAlignmentDependent())
4521 Align = std::max(Align, I->getAlignment(
Context));
4522 LastAlignedAttr = I;
4526 Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type)
4527 << LastAlignedAttr << DiagTy;
4528 }
else if (AlignasAttr && Align) {
4531 if (NaturalAlign > RequestedAlign)
4532 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
4559 Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance)
4568 bool &IntegerMode,
bool &ComplexMode,
4571 ComplexMode =
false;
4573 switch (Str.size()) {
4593 DestWidth = Str[1] ==
'I' ? 0 : 128;
4601 DestWidth = Str[1] ==
'I' ? 0 : 128;
4604 if (Str[1] ==
'F') {
4605 IntegerMode =
false;
4606 }
else if (Str[1] ==
'C') {
4607 IntegerMode =
false;
4609 }
else if (Str[1] !=
'I') {
4618 else if (Str ==
"byte")
4622 if (Str ==
"pointer")
4626 if (Str ==
"unwind_word")
4642 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
4654 StringRef Str = Name->getName();
4658 unsigned DestWidth = 0;
4659 bool IntegerMode =
true;
4660 bool ComplexMode =
false;
4662 llvm::APInt VectorSize(64, 0);
4663 if (Str.size() >= 4 && Str[0] ==
'V') {
4665 size_t StrSize = Str.size();
4666 size_t VectorStringLength = 0;
4667 while ((VectorStringLength + 1) < StrSize &&
4668 isdigit(Str[VectorStringLength + 1]))
4669 ++VectorStringLength;
4670 if (VectorStringLength &&
4671 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
4672 VectorSize.isPowerOf2()) {
4674 IntegerMode, ComplexMode, ExplicitType);
4676 if (!InInstantiation)
4677 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
4692 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
4697 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4698 OldTy = TD->getUnderlyingType();
4699 else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4702 OldTy = ED->getIntegerType();
4706 OldTy = cast<ValueDecl>(D)->getType();
4717 OldElemTy = VT->getElementType();
4723 VectorSize.getBoolValue()) {
4724 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.
getRange();
4732 !IntegralOrAnyEnumType)
4733 Diag(AttrLoc, diag::err_mode_not_primitive);
4734 else if (IntegerMode) {
4735 if (!IntegralOrAnyEnumType)
4736 Diag(AttrLoc, diag::err_mode_wrong_type);
4737 }
else if (ComplexMode) {
4739 Diag(AttrLoc, diag::err_mode_wrong_type);
4742 Diag(AttrLoc, diag::err_mode_wrong_type);
4753 if (NewElemTy.
isNull()) {
4754 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4763 if (VectorSize.getBoolValue()) {
4769 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4773 OldVT->getNumElements() /
4780 Diag(AttrLoc, diag::err_mode_wrong_type);
4785 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
4786 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4787 else if (
auto *ED = dyn_cast<EnumDecl>(D))
4788 ED->setIntegerType(NewTy);
4790 cast<ValueDecl>(D)->setType(NewTy);
4802 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4803 Diag(CI.
getLoc(), diag::warn_attribute_ignored) << Ident;
4804 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4808 if (D->
hasAttr<AlwaysInlineAttr>())
4816 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4819 if (VD->getKind() != Decl::Var) {
4820 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4826 if (VD->hasLocalStorage()) {
4827 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4834InternalLinkageAttr *
4836 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4839 if (VD->getKind() != Decl::Var) {
4840 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4846 if (VD->hasLocalStorage()) {
4847 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4856 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4857 Diag(CI.
getLoc(), diag::warn_attribute_ignored) <<
"'minsize'";
4858 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4862 if (D->
hasAttr<MinSizeAttr>())
4870 if (
const auto *PrevSNA = D->
getAttr<SwiftNameAttr>()) {
4871 if (PrevSNA->getName() != Name && !PrevSNA->isImplicit()) {
4872 Diag(PrevSNA->getLocation(), diag::err_attributes_are_not_compatible)
4874 Diag(SNA.getLoc(), diag::note_conflicting_attribute);
4884 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4885 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4886 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4889 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4890 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4891 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4895 if (D->
hasAttr<OptimizeNoneAttr>())
4902 if (AlwaysInlineAttr *Inline =
4918 const auto *VD = cast<VarDecl>(D);
4919 if (VD->hasLocalStorage()) {
4920 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4925 if (
auto *A = D->
getAttr<CUDAConstantAttr>()) {
4926 if (!A->isImplicit())
4934 const auto *VD = cast<VarDecl>(D);
4937 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4938 !isa<IncompleteArrayType>(VD->getType())) {
4939 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4942 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4950 const auto *FD = cast<FunctionDecl>(D);
4961 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4962 if (Method->isInstance()) {
4963 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4967 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;