41 #include "llvm/ADT/Optional.h"
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"
50 using namespace clang;
82 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
83 isa<ObjCPropertyDecl>(D);
91 return isa<FunctionProtoType>(FnTy);
92 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
100 return cast<FunctionProtoType>(FnTy)->getNumParams();
101 if (
const auto *BD = dyn_cast<BlockDecl>(D))
102 return BD->getNumParams();
103 return cast<ObjCMethodDecl>(D)->param_size();
108 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
109 return FD->getParamDecl(Idx);
110 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
111 return MD->getParamDecl(Idx);
112 if (
const auto *BD = dyn_cast<BlockDecl>(D))
113 return BD->getParamDecl(Idx);
119 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
120 if (
const auto *BD = dyn_cast<BlockDecl>(D))
121 return BD->getParamDecl(Idx)->getType();
123 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
128 return PVD->getSourceRange();
134 return FnTy->getReturnType();
135 return cast<ObjCMethodDecl>(D)->getReturnType();
139 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
140 return FD->getReturnTypeSourceRange();
141 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
142 return MD->getReturnTypeSourceRange();
148 return cast<FunctionProtoType>(FnTy)->isVariadic();
149 if (
const auto *BD = dyn_cast<BlockDecl>(D))
150 return BD->isVariadic();
151 return cast<ObjCMethodDecl>(D)->isVariadic();
155 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
156 return MethodDecl->isInstance();
161 bool AllowNSAttributedString =
false) {
172 if (AllowNSAttributedString &&
173 ClsName == &Ctx.
Idents.
get(
"NSAttributedString"))
176 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
177 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
203 template <
typename AttrInfo>
204 static std::enable_if_t<std::is_base_of<Attr, AttrInfo>::value,
SourceLocation>
206 return AL.getLocation();
215 template <
typename AttrInfo>
217 uint32_t &Val,
unsigned Idx =
UINT_MAX,
218 bool StrictlyUnsigned =
false) {
232 if (!I->isIntN(32)) {
234 <<
toString(*I, 10,
false) << 32 << 1;
238 if (StrictlyUnsigned && I->isSigned() && I->isNegative()) {
239 S.
Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
244 Val = (uint32_t)I->getZExtValue();
251 template <
typename AttrInfo>
253 int &Val,
unsigned Idx =
UINT_MAX) {
262 <<
toString(I, 10,
false) << 32 << 0;
272 template <
typename AttrTy>
274 if (
const auto *A = D->
getAttr<AttrTy>()) {
275 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
276 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
282 template <
typename AttrTy>
284 if (
const auto *A = D->
getAttr<AttrTy>()) {
285 S.
Diag(AL.
getLocation(), diag::err_attributes_are_not_compatible) << &AL
287 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
297 template <
typename AttrInfo>
299 Sema &S,
const Decl *D,
const AttrInfo &AI,
unsigned AttrArgNum,
300 const Expr *IdxExpr,
ParamIdx &Idx,
bool CanIndexImplicitThis =
false) {
320 unsigned IdxSource = IdxInt->getLimitedValue(
UINT_MAX);
321 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
322 S.
Diag(
getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
326 if (HasImplicitThisParam && !CanIndexImplicitThis) {
327 if (IdxSource == 1) {
328 S.
Diag(
getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
342 const Expr *E, StringRef &Str,
368 Diag(Loc->
Loc, diag::err_attribute_argument_type)
374 *ArgLocation = Loc->
Loc;
380 return checkStringLiteralArgumentAttr(AL, ArgExpr, Str, ArgLocation);
385 template <
typename AttrType>
391 template <
typename... DiagnosticArgs>
397 template <
typename T,
typename... DiagnosticArgs>
400 DiagnosticArgs &&... ExtraArgs) {
402 std::forward<DiagnosticArgs>(ExtraArgs)...);
409 template <
typename AttrType,
typename... DiagnosticArgs>
412 bool PassesCheck,
unsigned DiagID,
413 DiagnosticArgs &&... ExtraArgs) {
419 handleSimpleAttribute<AttrType>(S, D, CI);
432 auto IsOverloadedOperatorPresent = [&S](
const RecordDecl *Record,
436 return !Result.empty();
440 bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
441 bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
442 if (foundStarOperator && foundArrowOperator)
445 const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Record);
449 for (
auto BaseSpecifier : CXXRecord->bases()) {
450 if (!foundStarOperator)
451 foundStarOperator = IsOverloadedOperatorPresent(
452 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
453 if (!foundArrowOperator)
454 foundArrowOperator = IsOverloadedOperatorPresent(
455 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
458 if (foundStarOperator && foundArrowOperator)
469 const auto *VD = cast<ValueDecl>(D);
478 if (RT->isIncompleteType())
485 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
502 template <
typename AttrType>
509 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
511 return !Base->hasAttr<AttrType>();
533 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
545 return TN->
hasAttr<CapabilityAttr>();
564 if (
const auto *E = dyn_cast<CastExpr>(Ex))
566 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
568 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
569 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
570 E->getOpcode() == UO_Deref)
573 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
574 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
592 bool ParamIdxOk =
false) {
597 const auto *MD = dyn_cast<const CXXMethodDecl>(D);
598 if (MD && !MD->isStatic()) {
601 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
602 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
604 diag::warn_thread_attribute_not_on_capability_member)
605 << AL << MD->getParent();
607 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
612 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
617 Args.push_back(ArgExp);
621 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
622 if (StrLit->getLength() == 0 ||
623 (StrLit->isOrdinary() && StrLit->getString() == StringRef(
"*"))) {
626 Args.push_back(ArgExp);
632 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
633 Args.push_back(ArgExp);
641 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
642 if (UOp->getOpcode() == UO_AddrOf)
643 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
644 if (DRE->getDecl()->isCXXInstanceMember())
645 ArgTy = DRE->getDecl()->getType();
651 if(!RT && ParamIdxOk) {
652 const auto *FD = dyn_cast<FunctionDecl>(D);
653 const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
655 unsigned int NumParams = FD->getNumParams();
657 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
658 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
659 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
661 diag::err_attribute_argument_out_of_bounds_extra_info)
662 << AL << Idx + 1 << NumParams;
665 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
674 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
677 Args.push_back(ArgExp);
697 unsigned Size = Args.size();
731 QualType QT = cast<ValueDecl>(D)->getType();
733 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
750 Expr **StartArg = &Args[0];
752 AcquiredAfterAttr(S.
Context, AL, StartArg, Args.size()));
760 Expr **StartArg = &Args[0];
762 AcquiredBeforeAttr(S.
Context, AL, StartArg, Args.size()));
779 unsigned Size = Args.size();
780 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
782 AssertSharedLockAttr(S.
Context, AL, StartArg, Size));
791 unsigned Size = Args.size();
792 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
794 AssertExclusiveLockAttr(S.
Context, AL, StartArg, Size));
802 template <
typename AttrInfo>
804 unsigned AttrArgNo) {
805 assert(AI.isArgExpr(AttrArgNo) &&
"Expected expression argument");
806 Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
815 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
830 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only) << AL;
841 ParamIdx SizeArgNo(SizeArgNoVal, D);
856 AllocSizeAttr(S.
Context, AL, SizeArgNo, NumberArgNo));
865 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
900 unsigned Size = Args.size();
914 unsigned Size = Args.size();
917 Expr **StartArg = &Args[0];
920 LocksExcludedAttr(S.
Context, AL, StartArg, Size));
924 Expr *&Cond, StringRef &Msg) {
930 Cond = Converted.
get();
937 Msg =
"<no message provided>";
943 S.
Diag(AL.
getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
945 S.
Diag(PDiag.first, PDiag.second);
952 S.
Diag(AL.
getLoc(), diag::ext_clang_enable_if);
961 StringRef NewUserDiagnostic;
971 class ArgumentDependenceChecker
982 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
990 bool referencesArgs(
Expr *E) {
998 "`this` doesn't refer to the enclosing class?");
1004 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
1005 if (Parms.count(PVD)) {
1016 const auto *DeclFD = cast<FunctionDecl>(D);
1018 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(DeclFD))
1019 if (!MethodDecl->isStatic()) {
1020 S.
Diag(AL.
getLoc(), diag::err_attribute_no_member_function) << AL;
1026 auto Union = AL.
getArg(Index - 1);
1027 if (Union.is<
Expr *>())
1032 S.
Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
1038 auto *F = dyn_cast_or_null<DeclRefExpr>(AL.
getArgAsExpr(0));
1041 return dyn_cast_or_null<FunctionDecl>(F->getFoundDecl());
1050 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments_for)
1057 for (
unsigned I = 1; I < AL.
getNumArgs(); ++I) {
1069 if (Index > DeclFD->getNumParams()) {
1070 S.
Diag(AL.
getLoc(), diag::err_attribute_bounds_for_function)
1071 << AL << Index << DeclFD << DeclFD->getNumParams();
1076 QualType T2 = DeclFD->getParamDecl(Index - 1)->getType();
1081 << AL << Index << DeclFD << T2 << I << AttrFD << T1;
1085 Indices.push_back(Index - 1);
1089 S.
Context, AL, AttrFD, Indices.data(), Indices.size()));
1093 S.
Diag(AL.
getLoc(), diag::ext_clang_diagnose_if);
1100 StringRef DiagTypeStr;
1104 DiagnoseIfAttr::DiagnosticType DiagType;
1105 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1107 diag::err_diagnose_if_invalid_diagnostic_type);
1111 bool ArgDependent =
false;
1112 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1113 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1115 S.
Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D)));
1119 static constexpr
const StringRef kWildcard =
"*";
1122 bool HasWildcard =
false;
1124 const auto AddBuiltinName = [&Names, &HasWildcard](StringRef Name) {
1125 if (Name == kWildcard)
1127 Names.push_back(Name);
1131 if (
const auto *NBA = D->
getAttr<NoBuiltinAttr>())
1132 for (StringRef BuiltinName : NBA->builtinNames())
1133 AddBuiltinName(BuiltinName);
1137 AddBuiltinName(kWildcard);
1139 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
1140 StringRef BuiltinName;
1146 AddBuiltinName(BuiltinName);
1148 S.
Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
1149 << BuiltinName << AL;
1154 Names.erase(std::unique(Names.begin(), Names.end()), Names.end());
1157 if (HasWildcard && Names.size() > 1)
1159 diag::err_attribute_no_builtin_wildcard_or_builtin_name)
1162 if (D->
hasAttr<NoBuiltinAttr>())
1165 NoBuiltinAttr(S.
Context, AL, Names.data(), Names.size()));
1169 if (D->
hasAttr<PassObjectSizeAttr>()) {
1170 S.
Diag(D->
getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
1192 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1193 S.
Diag(D->
getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
1205 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1207 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1212 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1225 if (!RD->hasAttr<ConsumableAttr>()) {
1226 S.
Diag(AL.
getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
1243 for (
unsigned ArgIndex = 0; ArgIndex < AL.
getNumArgs(); ++ArgIndex) {
1246 StringRef StateString;
1257 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1259 S.
Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1263 States.push_back(CallableState);
1267 CallableWhenAttr(S.
Context, AL, States.data(), States.size()));
1277 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1279 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1280 << AL << StateString;
1284 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1309 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1311 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1316 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1357 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1358 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1363 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1379 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1380 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1385 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1399 if (
auto *TD = dyn_cast<TagDecl>(D))
1401 else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
1408 if (BitfieldByteAligned)
1410 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1416 if (BitfieldByteAligned)
1417 S.
Diag(AL.
getLoc(), diag::warn_attribute_packed_for_bitfield);
1423 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
1427 auto *RD = cast<CXXRecordDecl>(D);
1429 assert(CTD &&
"attribute does not appertain to this declaration");
1440 if (
const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
1442 Template = CTSD->getSpecializedTemplate();
1444 while (TST && TST->isTypeAlias())
1447 Template = TST->getTemplateName().getAsTemplateDecl();
1456 S.
Diag(AL.
getLoc(), diag::err_attribute_preferred_name_arg_invalid)
1459 S.
Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at)
1467 if (
const auto *VD = dyn_cast<ObjCIvarDecl>(D)) {
1469 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1470 << AL << VD->getType() << 0;
1474 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
1476 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1477 << AL << PD->getType() << 1;
1482 S.
Diag(AL.
getLoc(), diag::warn_attribute_iboutlet) << AL;
1500 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1515 S.
Diag(AL.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1531 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1532 : diag::err_iboutletcollection_type) << QT;
1550 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1552 for (
const auto *I : UD->
fields()) {
1566 bool isReturnValue =
false) {
1569 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1570 << AL << AttrParmRange << TypeRange;
1572 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1573 << AL << AttrParmRange << TypeRange << 0;
1581 for (
unsigned I = 0; I < AL.
getNumArgs(); ++I) {
1595 NonNullArgs.push_back(Idx);
1606 I != E && !AnyPointers; ++I) {
1613 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1616 ParamIdx *Start = NonNullArgs.data();
1617 unsigned Size = NonNullArgs.size();
1618 llvm::array_pod_sort(Start, Start + Size);
1628 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1657 QualType T = cast<ParmVarDecl>(D)->getType();
1659 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1682 AssumeAlignedAttr TmpAttr(Context, CI, E, OE);
1685 if (!isValidPointerAttrType(ResultType,
true)) {
1686 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1687 << &TmpAttr << TmpAttr.getRange() << SR;
1695 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1699 Diag(AttrLoc, diag::err_attribute_argument_type)
1705 if (!I->isPowerOf2()) {
1706 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1712 Diag(CI.
getLoc(), diag::warn_assume_aligned_too_great)
1717 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1723 D->
addAttr(::
new (Context) AssumeAlignedAttr(Context, CI, E, OE));
1730 AllocAlignAttr TmpAttr(Context, CI,
ParamIdx());
1734 !isValidPointerAttrType(ResultType,
true)) {
1735 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1741 const auto *FuncDecl = cast<FunctionDecl>(D);
1751 << FuncDecl->getParamDecl(Idx.
getASTIndex())->getSourceRange();
1755 D->
addAttr(::
new (Context) AllocAlignAttr(Context, CI, Idx));
1760 StringRef AssumptionStr) {
1761 if (llvm::KnownAssumptionStrings.count(AssumptionStr))
1764 unsigned BestEditDistance = 3;
1765 StringRef Suggestion;
1766 for (
const auto &KnownAssumptionIt : llvm::KnownAssumptionStrings) {
1767 unsigned EditDistance =
1768 AssumptionStr.edit_distance(KnownAssumptionIt.getKey());
1769 if (EditDistance < BestEditDistance) {
1770 Suggestion = KnownAssumptionIt.getKey();
1771 BestEditDistance = EditDistance;
1775 if (!Suggestion.empty())
1776 S.
Diag(Loc, diag::warn_assume_attribute_string_unknown_suggested)
1777 << AssumptionStr << Suggestion;
1779 S.
Diag(Loc, diag::warn_assume_attribute_string_unknown) << AssumptionStr;
1797 if (AttrName.size() > 4 && AttrName.startswith(
"__") &&
1798 AttrName.endswith(
"__")) {
1799 AttrName = AttrName.drop_front(2).drop_back(2);
1815 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1821 OwnershipAttr::OwnershipKind K =
1822 OwnershipAttr(S.
Context, AL,
nullptr,
nullptr, 0).getOwnKind();
1826 case OwnershipAttr::Takes:
1827 case OwnershipAttr::Holds:
1829 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1833 case OwnershipAttr::Returns:
1835 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1843 StringRef ModuleName =
Module->getName();
1849 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1859 case OwnershipAttr::Takes:
1860 case OwnershipAttr::Holds:
1864 case OwnershipAttr::Returns:
1870 S.
Diag(AL.
getLoc(), diag::err_ownership_type) << AL << Err
1879 if (I->getOwnKind() != K && I->args_end() !=
1880 std::find(I->args_begin(), I->args_end(), 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;
2340 uint32_t priority = DestructorAttr::DefaultPriority;
2348 template <
typename AttrTy>
2360 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2361 S.
Diag(AL.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
2371 VersionTuple Introduced,
2372 VersionTuple Deprecated,
2373 VersionTuple Obsoleted) {
2374 StringRef PlatformName
2375 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2376 if (PlatformName.empty())
2377 PlatformName = Platform->
getName();
2381 if (!Introduced.empty() && !Deprecated.empty() &&
2382 !(Introduced <= Deprecated)) {
2383 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2384 << 1 << PlatformName << Deprecated.getAsString()
2385 << 0 << Introduced.getAsString();
2389 if (!Introduced.empty() && !Obsoleted.empty() &&
2390 !(Introduced <= Obsoleted)) {
2391 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2392 << 2 << PlatformName << Obsoleted.getAsString()
2393 << 0 << Introduced.getAsString();
2397 if (!Deprecated.empty() && !Obsoleted.empty() &&
2398 !(Deprecated <= Obsoleted)) {
2399 S.
Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2400 << 2 << PlatformName << Obsoleted.getAsString()
2401 << 1 << Deprecated.getAsString();
2413 bool BeforeIsOkay) {
2414 if (
X.empty() || Y.empty())
2420 if (BeforeIsOkay &&
X < Y)
2428 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
2429 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
2432 VersionTuple MergedIntroduced = Introduced;
2433 VersionTuple MergedDeprecated = Deprecated;
2434 VersionTuple MergedObsoleted = Obsoleted;
2435 bool FoundAny =
false;
2436 bool OverrideOrImpl =
false;
2439 case AMK_Redeclaration:
2440 OverrideOrImpl =
false;
2444 case AMK_ProtocolImplementation:
2445 case AMK_OptionalProtocolImplementation:
2446 OverrideOrImpl =
true;
2452 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2453 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2460 if (OldPlatform != Platform) {
2468 if (OldAA->getPriority() <
Priority)
2474 if (OldAA->getPriority() >
Priority) {
2475 Attrs.erase(Attrs.begin() + i);
2481 VersionTuple OldIntroduced = OldAA->getIntroduced();
2482 VersionTuple OldDeprecated = OldAA->getDeprecated();
2483 VersionTuple OldObsoleted = OldAA->getObsoleted();
2484 bool OldIsUnavailable = OldAA->getUnavailable();
2486 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2487 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2489 !(OldIsUnavailable == IsUnavailable ||
2490 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2491 if (OverrideOrImpl) {
2493 VersionTuple FirstVersion;
2494 VersionTuple SecondVersion;
2495 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2497 FirstVersion = OldIntroduced;
2498 SecondVersion = Introduced;
2499 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2501 FirstVersion = Deprecated;
2502 SecondVersion = OldDeprecated;
2503 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2505 FirstVersion = Obsoleted;
2506 SecondVersion = OldObsoleted;
2510 Diag(OldAA->getLocation(),
2511 diag::warn_mismatched_availability_override_unavail)
2512 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2513 << (AMK == AMK_Override);
2514 }
else if (Which != 1 && AMK == AMK_OptionalProtocolImplementation) {
2523 Diag(OldAA->getLocation(),
2524 diag::warn_mismatched_availability_override)
2526 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2527 << FirstVersion.getAsString() << SecondVersion.getAsString()
2528 << (AMK == AMK_Override);
2530 if (AMK == AMK_Override)
2531 Diag(CI.
getLoc(), diag::note_overridden_method);
2533 Diag(CI.
getLoc(), diag::note_protocol_method);
2535 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2536 Diag(CI.
getLoc(), diag::note_previous_attribute);
2539 Attrs.erase(Attrs.begin() + i);
2544 VersionTuple MergedIntroduced2 = MergedIntroduced;
2545 VersionTuple MergedDeprecated2 = MergedDeprecated;
2546 VersionTuple MergedObsoleted2 = MergedObsoleted;
2548 if (MergedIntroduced2.empty())
2549 MergedIntroduced2 = OldIntroduced;
2550 if (MergedDeprecated2.empty())
2551 MergedDeprecated2 = OldDeprecated;
2552 if (MergedObsoleted2.empty())
2553 MergedObsoleted2 = OldObsoleted;
2556 MergedIntroduced2, MergedDeprecated2,
2557 MergedObsoleted2)) {
2558 Attrs.erase(Attrs.begin() + i);
2563 MergedIntroduced = MergedIntroduced2;
2564 MergedDeprecated = MergedDeprecated2;
2565 MergedObsoleted = MergedObsoleted2;
2571 MergedIntroduced == Introduced &&
2572 MergedDeprecated == Deprecated &&
2573 MergedObsoleted == Obsoleted)
2579 MergedDeprecated, MergedObsoleted) &&
2581 auto *Avail = ::new (Context) AvailabilityAttr(
2582 Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable,
2583 Message, IsStrict, Replacement,
Priority);
2584 Avail->setImplicit(Implicit);
2591 if (isa<UsingDecl, UnresolvedUsingTypenameDecl, UnresolvedUsingValueDecl>(
2603 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2604 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2607 auto *ND = dyn_cast<NamedDecl>(D);
2617 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getMessageExpr()))
2618 Str = SE->getString();
2619 StringRef Replacement;
2621 Replacement = SE->getString();
2623 if (II->
isStr(
"swift")) {
2625 (!IsUnavailable && !Deprecated.
isValid())) {
2627 diag::warn_availability_swift_unavailable_deprecated_only);
2632 if (II->
isStr(
"fuchsia")) {
2634 if ((Min = Introduced.
Version.getMinor()) ||
2636 S.
Diag(AL.
getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2646 Obsoleted.
Version, IsUnavailable, Str, IsStrict, Replacement,
2657 else if (II->
getName() ==
"ios_app_extension")
2662 const auto *IOSToWatchOSMapping =
2667 auto adjustWatchOSVersion =
2668 [IOSToWatchOSMapping](VersionTuple Version) -> VersionTuple {
2669 if (Version.empty())
2671 auto MinimumWatchOSVersion = VersionTuple(2, 0);
2673 if (IOSToWatchOSMapping) {
2674 if (
auto MappedVersion = IOSToWatchOSMapping->map(
2675 Version, MinimumWatchOSVersion, None)) {
2676 return MappedVersion.getValue();
2680 auto Major = Version.getMajor();
2681 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2682 if (NewMajor >= 2) {
2683 if (Version.getMinor()) {
2684 if (Version.getSubminor())
2685 return VersionTuple(NewMajor, Version.getMinor().getValue(),
2686 Version.getSubminor().getValue());
2688 return VersionTuple(NewMajor, Version.getMinor().getValue());
2690 return VersionTuple(NewMajor);
2693 return MinimumWatchOSVersion;
2696 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2697 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2698 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2701 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2702 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2714 else if (II->
getName() ==
"ios_app_extension")
2719 const auto *IOSToTvOSMapping =
2724 auto AdjustTvOSVersion =
2725 [IOSToTvOSMapping](VersionTuple Version) -> VersionTuple {
2726 if (Version.empty())
2729 if (IOSToTvOSMapping) {
2730 if (
auto MappedVersion =
2731 IOSToTvOSMapping->map(Version, VersionTuple(0, 0), None)) {
2732 return *MappedVersion;
2738 auto NewIntroduced = AdjustTvOSVersion(Introduced.
Version);
2739 auto NewDeprecated = AdjustTvOSVersion(Deprecated.
Version);
2740 auto NewObsoleted = AdjustTvOSVersion(Obsoleted.
Version);
2743 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2744 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2751 llvm::Triple::IOS &&
2753 auto GetSDKInfo = [&]() {
2762 else if (II->
getName() ==
"ios_app_extension")
2765 auto MinMacCatalystVersion = [](
const VersionTuple &
V) {
2768 if (
V.getMajor() < 13 ||
2769 (
V.getMajor() == 13 &&
V.getMinor() && *
V.getMinor() < 1))
2770 return VersionTuple(13, 1);
2775 MinMacCatalystVersion(Introduced.
Version),
2776 MinMacCatalystVersion(Deprecated.
Version),
2777 MinMacCatalystVersion(Obsoleted.
Version), IsUnavailable, Str,
2782 }
else if (II->
getName() ==
"macos" && GetSDKInfo() &&
2784 !Obsoleted.
Version.empty())) {
2785 if (
const auto *MacOStoMacCatalystMapping =
2786 GetSDKInfo()->getVersionMapping(
2793 auto RemapMacOSVersion =
2798 if (
V.getMajor() == 100000)
2799 return VersionTuple(100000);
2801 return MacOStoMacCatalystMapping->map(
V, VersionTuple(13, 1), None);
2804 RemapMacOSVersion(Introduced.
Version),
2806 RemapMacOSVersion(Deprecated.
Version),
2808 RemapMacOSVersion(Obsoleted.
Version);
2809 if (NewIntroduced || NewDeprecated || NewObsoleted) {
2810 auto VersionOrEmptyVersion =
2812 return V ? *
V : VersionTuple();
2816 VersionOrEmptyVersion(NewIntroduced),
2817 VersionOrEmptyVersion(NewDeprecated),
2818 VersionOrEmptyVersion(NewObsoleted),
false, Str,
2836 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(0)))
2838 StringRef DefinedIn;
2839 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(1)))
2840 DefinedIn = SE->getString();
2841 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2849 typename T::VisibilityType value) {
2850 T *existingAttr = D->
getAttr<T>();
2852 typename T::VisibilityType existingValue = existingAttr->getVisibility();
2853 if (existingValue == value)
2855 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2856 S.
Diag(CI.
getLoc(), diag::note_previous_attribute);
2864 VisibilityAttr::VisibilityType Vis) {
2865 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, CI, Vis);
2868 TypeVisibilityAttr *
2870 TypeVisibilityAttr::VisibilityType Vis) {
2871 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, CI, Vis);
2875 bool isTypeVisibility) {
2877 if (isa<TypedefNameDecl>(D)) {
2883 if (isTypeVisibility &&
2884 !(isa<TagDecl>(D) ||
2885 isa<ObjCInterfaceDecl>(D) ||
2886 isa<NamespaceDecl>(D))) {
2898 VisibilityAttr::VisibilityType
type;
2899 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr,
type)) {
2900 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2907 if (
type == VisibilityAttr::Protected &&
2909 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2910 type = VisibilityAttr::Default;
2914 if (isTypeVisibility) {
2916 D, AL, (TypeVisibilityAttr::VisibilityType)
type);
2927 S.
Diag(AL.
getLoc(), diag::err_objc_direct_on_protocol) <<
false;
2932 handleSimpleAttribute<ObjCDirectAttr>(S, D, AL);
2934 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2941 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
2943 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2948 const auto *M = cast<ObjCMethodDecl>(D);
2950 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2956 ObjCMethodFamilyAttr::FamilyKind F;
2957 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2958 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL << IL->
Ident;
2963 !M->getReturnType()->isObjCObjectPointerType()) {
2964 S.
Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2965 << M->getReturnType();
2974 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2975 QualType T = TD->getUnderlyingType();
2977 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2981 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2984 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
3001 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
3002 QualType T = TD->getUnderlyingType();
3004 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
3016 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3022 BlocksAttr::BlockType
type;
3023 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
3024 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3032 unsigned sentinel = (
unsigned)SentinelAttr::DefaultSentinel;
3037 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3042 if (Idx->isSigned() && Idx->isNegative()) {
3043 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
3048 sentinel = Idx->getZExtValue();
3051 unsigned nullPos = (
unsigned)SentinelAttr::DefaultNullPos;
3056 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3060 nullPos = Idx->getZExtValue();
3062 if ((Idx->isSigned() && Idx->isNegative()) || nullPos > 1) {
3065 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
3071 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3073 if (isa<FunctionNoProtoType>(FT)) {
3074 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
3078 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
3079 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
3082 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
3083 if (!MD->isVariadic()) {
3084 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
3087 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
3088 if (!BD->isVariadic()) {
3089 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
3092 }
else if (
const auto *
V = dyn_cast<VarDecl>(D)) {
3100 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
3102 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
3106 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3111 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3121 !isa<CXXConstructorDecl>(D)) {
3122 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
3125 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
3126 if (MD->getReturnType()->isVoidType()) {
3127 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
3135 if (isa<VarDecl>(D))
3136 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type_str)
3137 << AL <<
"functions, classes, or enumerations";
3146 if (LO.CPlusPlus && !LO.CPlusPlus20)
3147 S.
Diag(AL.
getLoc(), diag::ext_cxx20_attr) << AL;
3155 }
else if (LO.CPlusPlus && !LO.CPlusPlus17)
3156 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
3161 isa<TypedefNameDecl>(D)) {
3162 S.
Diag(AL.
getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
3175 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
3177 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
3179 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
3182 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3192 template <
typename WorkGroupAttr>
3195 for (
unsigned i = 0; i < 3; ++i) {
3200 if (WGSize[i] == 0) {
3201 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
3207 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
3208 if (Existing && !(Existing->getXDim() == WGSize[0] &&
3209 Existing->getYDim() == WGSize[1] &&
3210 Existing->getZDim() == WGSize[2]))
3211 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3214 WorkGroupAttr(S.
Context, AL, WGSize[0], WGSize[1], WGSize[2]));
3224 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
3229 OpenCLIntelReqdSubGroupSizeAttr *Existing =
3230 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
3231 if (Existing && Existing->getSubGroupSize() != SGSize)
3232 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3235 OpenCLIntelReqdSubGroupSizeAttr(S.
Context, AL, SGSize));
3240 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3246 assert(ParmTSI &&
"no type source info for attribute argument");
3251 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
3255 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
3257 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3269 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3274 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
3275 if (ExistingAttr->getName() == Name)
3277 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3279 Diag(CI.
getLoc(), diag::note_previous_attribute);
3282 return ::new (Context) SectionAttr(Context, CI, Name);
3296 return llvm::Error::success();
3299 StringRef Segment, Section;
3300 unsigned TAA, StubSize;
3302 return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
3303 TAA, HasTAA, StubSize);
3307 if (llvm::Error E = isValidSectionSpecifier(SecName)) {
3308 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3333 cast<NamedDecl>(D));
3340 StringRef CodeSegName) {
3342 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3354 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3358 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3359 if (ExistingAttr->getName() == Name)
3361 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3363 Diag(CI.
getLoc(), diag::note_previous_attribute);
3366 return ::new (Context) CodeSegAttr(Context, CI, Name);
3376 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3377 if (!ExistingAttr->isImplicit()) {
3379 ExistingAttr->getName() == Str
3380 ? diag::warn_duplicate_codeseg_attribute
3381 : diag::err_conflicting_codeseg_attribute);
3393 enum FirstParam {
Unsupported, Duplicate, Unknown };
3394 enum SecondParam { None, Architecture, Tune };
3396 if (AttrStr.contains(
"fpmath="))
3397 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3402 AttrStr.contains(
"tune="))
3403 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3410 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3413 if (!ParsedAttrs.
Tune.empty() &&
3415 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3416 << Unknown << Tune << ParsedAttrs.
Tune <<
Target;
3419 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3420 << Duplicate << None <<
"arch=" <<
Target;
3422 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3423 << Duplicate << None <<
"tune=" <<
Target;
3425 for (
const auto &Feature : ParsedAttrs.
Features) {
3426 auto CurFeature = StringRef(Feature).drop_front();
3428 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3439 if (DiagMsg.empty())
3440 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3442 return Diag(LiteralLoc, diag::err_invalid_branch_protection_spec)
3445 if (!DiagMsg.empty())
3446 Diag(LiteralLoc, diag::warn_unsupported_branch_protection_spec) << DiagMsg;
3458 TargetAttr *NewAttr = ::new (S.
Context) TargetAttr(S.
Context, AL, Str);
3464 bool &HasDefault,
bool &HasCommas,
3466 enum FirstParam {
Unsupported, Duplicate, Unknown };
3467 enum SecondParam { None, Architecture, Tune };
3469 HasCommas = HasCommas || Str.contains(
',');
3471 if (Str.size() == 0)
3472 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3475 std::pair<StringRef, StringRef> Parts = {{}, Str};
3476 while (!Parts.second.empty()) {
3477 Parts = Parts.second.split(
',');
3478 StringRef Cur = Parts.first.trim();
3480 Cur.data() -
Literal->getString().data(), getSourceManager(),
3483 bool DefaultIsDupe =
false;
3485 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3488 if (Cur.startswith(
"arch=")) {
3490 Cur.drop_front(
sizeof(
"arch=") - 1)))
3491 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3493 << Cur.drop_front(
sizeof(
"arch=") - 1) <<
TargetClones;
3494 }
else if (Cur ==
"default") {
3495 DefaultIsDupe = HasDefault;
3498 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3501 if (llvm::is_contained(Strings, Cur) || DefaultIsDupe)
3502 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3504 Strings.push_back(Cur);
3507 if (Str.rtrim().endswith(
","))
3508 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3516 if (
const auto *Other = D->
getAttr<TargetClonesAttr>()) {
3517 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3518 S.
Diag(Other->getLocation(), diag::note_conflicting_attribute);
3521 if (checkAttrMutualExclusion<TargetClonesAttr>(S, D, AL))
3525 bool HasCommas =
false, HasDefault =
false;
3527 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
3534 HasDefault, HasCommas, Strings))
3539 S.
Diag(AL.
getLoc(), diag::warn_target_clone_mixed_values);
3542 S.
Diag(AL.
getLoc(), diag::err_target_clone_must_have_default);
3548 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
3549 if (MD->getParent()->isLambda()) {
3557 cast<FunctionDecl>(D)->setIsMultiVersion();
3558 TargetClonesAttr *NewAttr = ::new (S.
Context)
3559 TargetClonesAttr(S.
Context, AL, Strings.data(), Strings.size());
3571 MinVectorWidthAttr *Existing = D->
getAttr<MinVectorWidthAttr>();
3572 if (Existing && Existing->getVectorWidth() != VecWidth) {
3573 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3588 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3590 S.
Diag(Loc, diag::warn_cleanup_ext);
3591 FD = dyn_cast<FunctionDecl>(DRE->
getDecl());
3594 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3598 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3599 if (ULE->hasExplicitTemplateArgs())
3600 S.
Diag(Loc, diag::warn_cleanup_ext);
3602 NI = ULE->getNameInfo();
3604 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3611 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3616 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3627 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3628 << NI.
getName() << ParamTy << Ty;
3638 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3645 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3646 ExtensibilityKind)) {
3647 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3652 EnumExtensibilityAttr(S.
Context, AL, ExtensibilityKind));
3667 if (NotNSStringTy &&
3671 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3679 if (
auto *OMD = dyn_cast<ObjCMethodDecl>(D))
3680 if (
auto *Interface = OMD->getClassInterface())
3682 QualType(Interface->getTypeForDecl(), 0));
3687 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3688 << (NotNSStringTy ?
"string type" :
"NSString")
3708 return llvm::StringSwitch<FormatAttrKind>(Format)
3722 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag",
IgnoredFormat)
3730 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3735 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3739 QualType T = cast<VarDecl>(D)->getType();
3743 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3749 uint32_t prioritynum;
3758 if ((prioritynum < 101 || prioritynum > 65535) &&
3760 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
3769 StringRef NewUserDiagnostic) {
3770 if (
const auto *EA = D->
getAttr<ErrorAttr>()) {
3772 assert((NewAttr ==
"error" || NewAttr ==
"warning") &&
3773 "unexpected normalized full name");
3774 bool Match = (EA->isError() && NewAttr ==
"error") ||
3775 (EA->isWarning() && NewAttr ==
"warning");
3777 Diag(EA->getLocation(), diag::err_attributes_are_not_compatible)
3779 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
3782 if (EA->getUserDiagnostic() != NewUserDiagnostic) {
3783 Diag(CI.
getLoc(), diag::warn_duplicate_attribute) << EA;
3784 Diag(EA->getLoc(), diag::note_previous_attribute);
3788 return ::new (Context) ErrorAttr(Context, CI, NewUserDiagnostic);
3796 if (F->getType() == Format &&
3797 F->getFormatIdx() == FormatIdx &&
3798 F->getFirstArg() == FirstArg) {
3801 if (F->getLocation().isInvalid())
3807 return ::new (Context) FormatAttr(Context, CI, Format, FormatIdx, FirstArg);
3814 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3825 StringRef Format = II->
getName();
3839 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3850 if (Idx < 1 || Idx > NumArgs) {
3851 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3857 unsigned ArgIdx = Idx - 1;
3859 if (HasImplicitThisParam) {
3862 diag::err_format_attribute_implicit_this_format_string)
3876 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3888 if (FirstArg != 0) {
3892 S.
Diag(D->
getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
3898 if (FirstArg != 0) {
3899 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
3904 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
3905 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3919 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_no_callee)
3928 assert(FD &&
"Expected a function declaration!");
3930 llvm::StringMap<int> NameIdxMapping;
3931 NameIdxMapping[
"__"] = -1;
3933 NameIdxMapping[
"this"] = 0;
3937 NameIdxMapping[PVD->getName()] = Idx++;
3939 auto UnknownName = NameIdxMapping.end();
3942 for (
unsigned I = 0, E = AL.
getNumArgs(); I < E; ++I) {
3948 auto It = NameIdxMapping.find(IdLoc->
Ident->
getName());
3949 if (It == UnknownName) {
3950 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_argument_unknown)
3956 ArgIdx = It->second;
3963 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3969 if (ArgIdx < -1 || ArgIdx > NumArgs) {
3970 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3977 llvm_unreachable(
"Unexpected ParsedAttr argument type!");
3980 if (ArgIdx == 0 && !HasImplicitThisParam) {
3981 S.
Diag(AL.
getLoc(), diag::err_callback_implicit_this_not_available)
3988 if (!HasImplicitThisParam && ArgIdx > 0)
3991 EncodingIndices.push_back(ArgIdx);
3994 int CalleeIdx = EncodingIndices.front();
3998 if (CalleeIdx < (
int)HasImplicitThisParam) {
3999 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_invalid_callee)
4006 const Type *CalleeType =
4010 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
4015 const Type *CalleeFnType =
4020 const auto *CalleeFnProtoType = dyn_cast<FunctionProtoType>(CalleeFnType);
4021 if (!CalleeFnProtoType) {
4022 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
4027 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
4028 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
4029 << AL << (
unsigned)(EncodingIndices.size() - 1);
4033 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
4034 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
4035 << AL << (
unsigned)(EncodingIndices.size() - 1);
4039 if (CalleeFnProtoType->isVariadic()) {
4045 if (D->
hasAttr<CallbackAttr>()) {
4051 S.
Context, AL, EncodingIndices.data(), EncodingIndices.size()));
4064 QualType T = cast<ParmVarDecl>(D)->getType();
4067 S.
Diag(AL.
getLoc(), diag::err_called_once_attribute_wrong_type);
4077 const auto *TD = dyn_cast<TypedefNameDecl>(D);
4078 if (TD && TD->getUnderlyingType()->isUnionType())
4079 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
4081 RD = dyn_cast<RecordDecl>(D);
4084 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type) << AL
4092 diag::warn_transparent_union_attribute_not_definition);
4098 if (Field == FieldEnd) {
4099 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
4107 diag::warn_transparent_union_attribute_floating)
4116 for (; Field != FieldEnd; ++Field) {
4117 QualType FieldType = Field->getType();
4131 S.
Diag(Field->getLocation(),
4132 diag::warn_transparent_union_attribute_field_size_align)
4133 << isSize << *Field << FieldBits;
4134 unsigned FirstBits = isSize ? FirstSize : FirstAlign;
4136 diag::note_transparent_union_first_field_size_align)
4137 << isSize << FirstBits;
4147 auto *
Attr = AnnotateAttr::Create(Context, Str, Args.data(), Args.size(), CI);
4148 if (ConstantFoldAttrArgs(
4163 for (
unsigned Idx = 1; Idx < AL.
getNumArgs(); Idx++) {
4176 AlignValueAttr TmpAttr(Context, CI, E);
4180 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4181 T = TD->getUnderlyingType();
4182 else if (
const auto *VD = dyn_cast<ValueDecl>(D))
4185 llvm_unreachable(
"Unknown decl type for align_value");
4189 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
4196 ExprResult ICE = VerifyIntegerConstantExpression(
4197 E, &Alignment, diag::err_align_value_attribute_argument_not_int);
4201 if (!Alignment.isPowerOf2()) {
4202 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
4207 D->
addAttr(::
new (Context) AlignValueAttr(Context, CI, ICE.
get()));
4212 D->
addAttr(::
new (Context) AlignValueAttr(Context, CI, E));
4218 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
4230 diag::err_pack_expansion_without_parameter_packs);
4241 bool IsPackExpansion) {
4242 AlignedAttr TmpAttr(Context, CI,
true, E);
4246 if (TmpAttr.isAlignas()) {
4262 if (isa<ParmVarDecl>(D)) {
4264 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4267 if (VD->isExceptionVariable())
4269 }
else if (
const auto *FD = dyn_cast<FieldDecl>(D)) {
4270 if (FD->isBitField())
4272 }
else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4273 if (ED->getLangOpts().CPlusPlus)
4275 }
else if (!isa<TagDecl>(D)) {
4276 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
4281 if (DiagKind != -1) {
4282 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
4283 << &TmpAttr << DiagKind;
4292 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
4293 if (!TND->getUnderlyingType()->isDependentType()) {
4294 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
4301 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
true, E);
4302 AA->setPackExpansion(IsPackExpansion);
4309 ExprResult ICE = VerifyIntegerConstantExpression(
4310 E, &Alignment, diag::err_aligned_attribute_argument_not_int);
4314 uint64_t AlignVal = Alignment.getZExtValue();
4318 if (AlignVal >= 16 && isa<FieldDecl>(D) &&
4327 if (!(TmpAttr.isAlignas() && !Alignment)) {
4328 if (!llvm::isPowerOf2_64(AlignVal)) {
4329 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
4338 if (AlignVal > MaximumAlignment) {
4339 Diag(AttrLoc, diag::err_attribute_aligned_too_great)
4344 const auto *VD = dyn_cast<VarDecl>(D);
4346 unsigned MaxTLSAlign =
4349 if (MaxTLSAlign && AlignVal > MaxTLSAlign &&
4351 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
4352 << (
unsigned)AlignVal << VD << MaxTLSAlign;
4360 const Type *Ty = VD->getType().getTypePtr();
4362 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4363 << VD->getType() << 16;
4368 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
true, ICE.
get());
4369 AA->setPackExpansion(IsPackExpansion);
4377 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
false, TS);
4378 AA->setPackExpansion(IsPackExpansion);
4383 assert(D->
hasAttrs() &&
"no attributes on decl");
4386 if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
4387 UnderlyingTy = DiagTy = VD->getType();
4389 UnderlyingTy = DiagTy = Context.
getTagDeclType(cast<TagDecl>(D));
4390 if (
const auto *ED = dyn_cast<EnumDecl>(D))
4391 UnderlyingTy = ED->getIntegerType();
4400 AlignedAttr *AlignasAttr =
nullptr;
4401 AlignedAttr *LastAlignedAttr =
nullptr;
4404 if (I->isAlignmentDependent())
4408 Align =
std::max(Align, I->getAlignment(Context));
4409 LastAlignedAttr = I;
4413 Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type)
4414 << LastAlignedAttr << DiagTy;
4415 }
else if (AlignasAttr && Align) {
4418 if (NaturalAlign > RequestedAlign)
4419 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
4446 Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance)
4455 bool &IntegerMode,
bool &ComplexMode,
4458 ComplexMode =
false;
4460 switch (Str.size()) {
4480 DestWidth = Str[1] ==
'I' ? 0 : 128;
4488 DestWidth = Str[1] ==
'I' ? 0 : 128;
4491 if (Str[1] ==
'F') {
4492 IntegerMode =
false;
4493 }
else if (Str[1] ==
'C') {
4494 IntegerMode =
false;
4496 }
else if (Str[1] !=
'I') {
4505 else if (Str ==
"byte")
4509 if (Str ==
"pointer")
4513 if (Str ==
"unwind_word")
4529 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
4541 StringRef Str = Name->getName();
4545 unsigned DestWidth = 0;
4546 bool IntegerMode =
true;
4547 bool ComplexMode =
false;
4550 if (Str.size() >= 4 && Str[0] ==
'V') {
4552 size_t StrSize = Str.size();
4553 size_t VectorStringLength = 0;
4554 while ((VectorStringLength + 1) < StrSize &&
4555 isdigit(Str[VectorStringLength + 1]))
4556 ++VectorStringLength;
4557 if (VectorStringLength &&
4558 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
4559 VectorSize.isPowerOf2()) {
4561 IntegerMode, ComplexMode, ExplicitType);
4563 if (!InInstantiation)
4564 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
4579 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
4584 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4585 OldTy = TD->getUnderlyingType();
4586 else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4589 OldTy = ED->getIntegerType();
4591 OldTy = Context.
IntTy;
4593 OldTy = cast<ValueDecl>(D)->getType();
4596 D->
addAttr(::
new (Context) ModeAttr(Context, CI, Name));
4604 OldElemTy = VT->getElementType();
4610 VectorSize.getBoolValue()) {
4611 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.
getRange();
4619 !IntegralOrAnyEnumType)
4620 Diag(AttrLoc, diag::err_mode_not_primitive);
4621 else if (IntegerMode) {
4622 if (!IntegralOrAnyEnumType)
4623 Diag(AttrLoc, diag::err_mode_wrong_type);
4624 }
else if (ComplexMode) {
4626 Diag(AttrLoc, diag::err_mode_wrong_type);
4629 Diag(AttrLoc, diag::err_mode_wrong_type);
4640 if (NewElemTy.
isNull()) {
4641 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4650 if (VectorSize.getBoolValue()) {
4651 NewTy = Context.
getVectorType(NewTy, VectorSize.getZExtValue(),
4656 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4659 unsigned NumElements = Context.
getTypeSize(OldElemTy) *
4660 OldVT->getNumElements() /
4663 Context.
getVectorType(NewElemTy, NumElements, OldVT->getVectorKind());
4667 Diag(AttrLoc, diag::err_mode_wrong_type);
4672 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
4673 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4674 else if (
auto *ED = dyn_cast<EnumDecl>(D))
4675 ED->setIntegerType(NewTy);
4677 cast<ValueDecl>(D)->setType(NewTy);
4679 D->
addAttr(::
new (Context) ModeAttr(Context, CI, Name));
4689 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4690 Diag(CI.
getLoc(), diag::warn_attribute_ignored) << Ident;
4691 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4695 if (D->
hasAttr<AlwaysInlineAttr>())
4698 return ::new (Context) AlwaysInlineAttr(Context, CI);
4703 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4706 if (VD->getKind() != Decl::Var) {
4707 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4713 if (VD->hasLocalStorage()) {
4714 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4719 return ::new (Context) InternalLinkageAttr(Context, AL);
4721 InternalLinkageAttr *
4723 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4726 if (VD->getKind() != Decl::Var) {
4727 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4733 if (VD->hasLocalStorage()) {
4734 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4739 return ::new (Context) InternalLinkageAttr(Context, AL);
4743 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4744 Diag(CI.
getLoc(), diag::warn_attribute_ignored) <<
"'minsize'";
4745 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4749 if (D->
hasAttr<MinSizeAttr>())
4752 return ::new (Context) MinSizeAttr(Context, CI);
4757 if (
const auto *PrevSNA = D->
getAttr<SwiftNameAttr>()) {
4758 if (PrevSNA->getName() != Name && !PrevSNA->isImplicit()) {
4759 Diag(PrevSNA->getLocation(), diag::err_attributes_are_not_compatible)
4761 Diag(SNA.getLoc(), diag::note_conflicting_attribute);
4766 return ::new (Context) SwiftNameAttr(Context, SNA, Name);
4771 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4772 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4773 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4776 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4777 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4778 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4782 if (D->
hasAttr<OptimizeNoneAttr>())
4785 return ::new (Context) OptimizeNoneAttr(Context, CI);
4789 if (AlwaysInlineAttr *Inline =
4805 const auto *VD = cast<VarDecl>(D);
4806 if (VD->hasLocalStorage()) {
4807 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4812 if (
auto *A = D->
getAttr<CUDAConstantAttr>()) {
4813 if (!A->isImplicit())
4821 const auto *VD = cast<VarDecl>(D);
4824 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4825 !isa<IncompleteArrayType>(VD->getType())) {
4826 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4829 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4837 const auto *FD = cast<FunctionDecl>(D);
4848 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4849 if (Method->isInstance()) {
4850 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4854 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4870 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4871 if (VD->hasLocalStorage()) {
4872 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4877 if (
auto *A = D->
getAttr<CUDADeviceAttr>()) {
4878 if (!A->isImplicit())
4886 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4887 if (VD->hasLocalStorage()) {
4888 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4892 if (!D->
hasAttr<HIPManagedAttr>())
4894 if (!D->
hasAttr<CUDADeviceAttr>())
4899 const auto *Fn = cast<FunctionDecl>(D);
4900 if (!Fn->isInlineSpecified()) {
4901 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4906 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_cplusplus_without_extern);
4920 if (!isa<ObjCMethodDecl>(D)) {
4921 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4927 case ParsedAttr::AT_FastCall:
4930 case ParsedAttr::AT_StdCall:
4933 case ParsedAttr::AT_ThisCall:
4936 case ParsedAttr::AT_CDecl:
4939 case ParsedAttr::AT_Pascal:
4942 case ParsedAttr::AT_SwiftCall:
4945 case ParsedAttr::AT_SwiftAsyncCall:
4948 case ParsedAttr::AT_VectorCall:
4951 case ParsedAttr::AT_MSABI:
4954 case ParsedAttr::AT_SysVABI:
4957 case ParsedAttr::AT_RegCall:
4960 case ParsedAttr::AT_Pcs: {
4961 PcsAttr::PCSType PCS;
4964 PCS = PcsAttr::AAPCS;
4967 PCS = PcsAttr::AAPCS_VFP;
4970 llvm_unreachable(
"unexpected calling convention in pcs attribute");
4976 case ParsedAttr::AT_AArch64VectorPcs:
4979 case ParsedAttr::AT_AArch64SVEPcs:
4982 case ParsedAttr::AT_AMDGPUKernelCall:
4985 case ParsedAttr::AT_IntelOclBicc:
4988 case ParsedAttr::AT_PreserveMost:
4991 case ParsedAttr::AT_PreserveAll:
4995 llvm_unreachable(
"unexpected attribute kind");
5003 std::vector<StringRef> DiagnosticIdentifiers;
5004 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
5012 DiagnosticIdentifiers.push_back(RuleName);
5015 SuppressAttr(S.
Context, AL, DiagnosticIdentifiers.data(),
5016 DiagnosticIdentifiers.size()));
5025 unsigned SelectIdx = ~0
U;
5031 if (SelectIdx != ~0
U) {
5032 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument)
5044 if (AL.
getKind() == ParsedAttr::AT_Owner) {
5045 if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
5047 if (
const auto *OAttr = D->
getAttr<OwnerAttr>()) {
5048 const Type *ExistingDerefType = OAttr->getDerefTypeLoc()
5049 ? OAttr->getDerefType().getTypePtr()
5052 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
5054 S.
Diag(OAttr->getLocation(), diag::note_conflicting_attribute);
5059 Redecl->addAttr(::
new (S.
Context) OwnerAttr(S.
Context, AL, DerefTypeLoc));
5062 if (checkAttrMutualExclusion<OwnerAttr>(S, D, AL))
5064 if (
const auto *PAttr = D->
getAttr<PointerAttr>()) {
5065 const Type *ExistingDerefType = PAttr->getDerefTypeLoc()
5066 ? PAttr->getDerefType().getTypePtr()
5069 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
5071 S.
Diag(PAttr->getLocation(), diag::note_conflicting_attribute);
5076 Redecl->addAttr(::
new (S.
Context)
5077 PointerAttr(S.
Context, AL, DerefTypeLoc));
5083 if (checkAttrMutualExclusion<NoRandomizeLayoutAttr>(S, D, AL))
5085 if (!D->
hasAttr<RandomizeLayoutAttr>())
5091 if (checkAttrMutualExclusion<RandomizeLayoutAttr>(S, D, AL))
5093 if (!D->
hasAttr<NoRandomizeLayoutAttr>())
5107 unsigned ReqArgs = Attrs.
getKind() == ParsedAttr::AT_Pcs ? 1 : 0;
5115 case ParsedAttr::AT_CDecl:
5118 case ParsedAttr::AT_FastCall:
5121 case ParsedAttr::AT_StdCall:
5124 case ParsedAttr::AT_ThisCall:
5127 case ParsedAttr::AT_Pascal:
5130 case ParsedAttr::AT_SwiftCall:
5133 case ParsedAttr::AT_SwiftAsyncCall:
5136 case ParsedAttr::AT_VectorCall:
5139 case ParsedAttr::AT_AArch64VectorPcs:
5142 case ParsedAttr::AT_AArch64SVEPcs:
5145 case ParsedAttr::AT_AMDGPUKernelCall:
5148 case ParsedAttr::AT_RegCall:
5151 case ParsedAttr::AT_MSABI:
5155 case ParsedAttr::AT_SysVABI:
5159 case ParsedAttr::AT_Pcs: {
5161 if (!checkStringLiteralArgumentAttr(Attrs, 0, StrRef)) {
5165 if (StrRef ==
"aapcs") {
5168 }
else if (StrRef ==
"aapcs-vfp") {
5177 case ParsedAttr::AT_IntelOclBicc:
5180 case ParsedAttr::AT_PreserveMost:
5183 case ParsedAttr::AT_PreserveAll:
5186 default: llvm_unreachable(
"unexpected attribute kind");
5195 if (LangOpts.CUDA) {
5197 auto CudaTarget = IdentifyCUDATarget(FD);
5198 bool CheckHost =
false, CheckDevice =
false;
5199 switch (CudaTarget) {
5200 case CFT_HostDevice:
5211 case CFT_InvalidTarget:
5212 llvm_unreachable(
"unexpected cuda target");
5214 auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI;
5215 auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux;
5216 if (CheckHost && HostTI)
5219 A = DeviceTI->checkCallingConvention(CC);
5237 Diag(Attrs.
getLoc(), diag::error_cconv_unsupported)
5238 << Attrs << (
int)CallingConventionIgnoredReason::ForThisTarget;
5242 Diag(Attrs.
getLoc(), diag::warn_cconv_unsupported)
5243 << Attrs << (
int)CallingConventionIgnoredReason::ForThisTarget;
5247 bool IsCXXMethod =
false, IsVariadic =
false;
5300 if (existingAttr->getABI() != abi) {
5301 Diag(CI.
getLoc(), diag::err_attributes_are_not_compatible)
5303 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute);
5310 llvm_unreachable(
"explicit attribute for ordinary parameter ABI?");
5314 Diag(CI.
getLoc(), diag::err_swift_abi_parameter_wrong_type)