62#include "llvm/ADT/STLExtras.h"
63#include "llvm/ADT/STLForwardCompat.h"
64#include "llvm/ADT/StringExtras.h"
65#include "llvm/Demangle/Demangle.h"
66#include "llvm/IR/Assumptions.h"
67#include "llvm/MC/MCSectionMachO.h"
68#include "llvm/Support/Error.h"
69#include "llvm/Support/MathExtras.h"
70#include "llvm/Support/raw_ostream.h"
71#include "llvm/TargetParser/Triple.h"
95template <
typename AttrInfo>
102 if (UVal > (uint32_t)std::numeric_limits<int>::max()) {
106 <<
toString(I, 10,
false) << 32 << 0;
115 const Expr *
E, StringRef &Str,
121 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) {
127 Str = Literal->getString();
137 Diag(
Loc->Loc, diag::err_attribute_argument_type)
141 Str =
Loc->Ident->getName();
143 *ArgLocation =
Loc->Loc;
153 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) {
158 Str = Literal->getString();
180 bool foundStarOperator = IsOverloadedOperatorPresent(
Record, OO_Star);
181 bool foundArrowOperator = IsOverloadedOperatorPresent(
Record, OO_Arrow);
182 if (foundStarOperator && foundArrowOperator)
189 for (
const auto &BaseSpecifier : CXXRecord->bases()) {
190 if (!foundStarOperator)
191 foundStarOperator = IsOverloadedOperatorPresent(
192 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
193 if (!foundArrowOperator)
194 foundArrowOperator = IsOverloadedOperatorPresent(
195 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
198 if (foundStarOperator && foundArrowOperator)
209 const auto *VD = cast<ValueDecl>(
D);
218 if (RT->isIncompleteType())
225 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
242template <
typename AttrType>
249 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
251 return !Base->hasAttr<AttrType>();
273 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
285 return TN->
hasAttr<CapabilityAttr>();
304 if (
const auto *
E = dyn_cast<CastExpr>(Ex))
306 else if (
const auto *
E = dyn_cast<ParenExpr>(Ex))
308 else if (
const auto *
E = dyn_cast<UnaryOperator>(Ex)) {
309 if (
E->getOpcode() == UO_LNot ||
E->getOpcode() == UO_AddrOf ||
310 E->getOpcode() == UO_Deref)
313 }
else if (
const auto *
E = dyn_cast<BinaryOperator>(Ex)) {
314 if (
E->getOpcode() == BO_LAnd ||
E->getOpcode() == BO_LOr)
332 bool ParamIdxOk =
false) {
337 const auto *MD = dyn_cast<const CXXMethodDecl>(
D);
338 if (MD && !MD->isStatic()) {
341 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
342 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
344 diag::warn_thread_attribute_not_on_capability_member)
345 << AL << MD->getParent();
347 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
352 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
357 Args.push_back(ArgExp);
361 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
362 if (StrLit->getLength() == 0 ||
363 (StrLit->isOrdinary() && StrLit->getString() ==
"*")) {
366 Args.push_back(ArgExp);
372 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
373 Args.push_back(ArgExp);
381 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
382 if (UOp->getOpcode() == UO_AddrOf)
383 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
384 if (DRE->getDecl()->isCXXInstanceMember())
385 ArgTy = DRE->getDecl()->getType();
391 if(!RT && ParamIdxOk) {
392 const auto *FD = dyn_cast<FunctionDecl>(
D);
393 const auto *IL = dyn_cast<IntegerLiteral>(ArgExp);
395 unsigned int NumParams = FD->getNumParams();
396 llvm::APInt ArgValue = IL->getValue();
397 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
398 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
399 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
401 diag::err_attribute_argument_out_of_bounds_extra_info)
402 << AL << Idx + 1 << NumParams;
405 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
414 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
417 Args.push_back(ArgExp);
437 unsigned Size = Args.size();
471 QualType QT = cast<ValueDecl>(
D)->getType();
473 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
490 Expr **StartArg = &Args[0];
492 AcquiredAfterAttr(S.
Context, AL, StartArg, Args.size()));
500 Expr **StartArg = &Args[0];
502 AcquiredBeforeAttr(S.
Context, AL, StartArg, Args.size()));
519 unsigned Size = Args.size();
520 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
522 AssertSharedLockAttr(S.
Context, AL, StartArg, Size));
531 unsigned Size = Args.size();
532 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
534 AssertExclusiveLockAttr(S.
Context, AL, StartArg, Size));
542template <
typename AttrInfo>
544 unsigned AttrArgNo) {
545 assert(AI.isArgExpr(AttrArgNo) &&
"Expected expression argument");
546 Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
555 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
570 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only) << AL;
596 AllocSizeAttr(S.
Context, AL, SizeArgNo, NumberArgNo));
605 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
640 unsigned Size = Args.size();
654 unsigned Size = Args.size();
657 Expr **StartArg = &Args[0];
660 LocksExcludedAttr(S.
Context, AL, StartArg, Size));
664 Expr *&Cond, StringRef &Msg) {
670 Cond = Converted.
get();
677 Msg =
"<no message provided>";
683 S.
Diag(AL.
getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
685 S.
Diag(PDiag.first, PDiag.second);
692 S.
Diag(AL.
getLoc(), diag::ext_clang_enable_if);
701 StringRef NewUserDiagnostic;
710 const auto *PD = isa<CXXRecordDecl>(
D)
711 ? cast<DeclContext>(
D)
713 if (
const auto *RD = dyn_cast<CXXRecordDecl>(PD); RD && RD->isLocalClass()) {
715 diag::warn_attribute_exclude_from_explicit_instantiation_local_class)
716 << AL << !isa<CXXRecordDecl>(
D);
720 ExcludeFromExplicitInstantiationAttr(S.
Context, AL));
726class ArgumentDependenceChecker
737 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
745 bool referencesArgs(
Expr *
E) {
753 "`this` doesn't refer to the enclosing class?");
759 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
760 if (Parms.count(PVD)) {
771 const auto *DeclFD = cast<FunctionDecl>(
D);
773 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(DeclFD))
774 if (!MethodDecl->isStatic()) {
775 S.
Diag(AL.
getLoc(), diag::err_attribute_no_member_function) << AL;
787 S.
Diag(
Loc, diag::err_attribute_argument_n_type) << AL << Index <<
T;
793 auto *F = dyn_cast_if_present<DeclRefExpr>(AL.
getArgAsExpr(0));
796 return dyn_cast_if_present<FunctionDecl>(F->getFoundDecl());
805 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments_for)
812 for (
unsigned I = 1; I < AL.
getNumArgs(); ++I) {
824 if (Index > DeclFD->getNumParams()) {
825 S.
Diag(AL.
getLoc(), diag::err_attribute_bounds_for_function)
826 << AL << Index << DeclFD << DeclFD->getNumParams();
831 QualType T2 = DeclFD->getParamDecl(Index - 1)->getType();
836 << AL << Index << DeclFD << T2 << I << AttrFD << T1;
840 Indices.push_back(Index - 1);
844 S.
Context, AL, AttrFD, Indices.data(), Indices.size()));
848 S.
Diag(AL.
getLoc(), diag::ext_clang_diagnose_if);
855 StringRef DiagTypeStr;
859 DiagnoseIfAttr::DiagnosticType DiagType;
860 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
862 diag::err_diagnose_if_invalid_diagnostic_type);
866 bool ArgDependent =
false;
867 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
868 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
870 S.
Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(
D)));
874 static constexpr const StringRef kWildcard =
"*";
877 bool HasWildcard =
false;
879 const auto AddBuiltinName = [&Names, &HasWildcard](StringRef Name) {
880 if (Name == kWildcard)
882 Names.push_back(Name);
886 if (
const auto *NBA =
D->
getAttr<NoBuiltinAttr>())
887 for (StringRef BuiltinName : NBA->builtinNames())
888 AddBuiltinName(BuiltinName);
892 AddBuiltinName(kWildcard);
894 for (
unsigned I = 0,
E = AL.
getNumArgs(); I !=
E; ++I) {
895 StringRef BuiltinName;
901 AddBuiltinName(BuiltinName);
903 S.
Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
904 << BuiltinName << AL;
909 Names.erase(std::unique(Names.begin(), Names.end()), Names.end());
912 if (HasWildcard && Names.size() > 1)
914 diag::err_attribute_no_builtin_wildcard_or_builtin_name)
920 NoBuiltinAttr(S.
Context, AL, Names.data(), Names.size()));
924 if (
D->
hasAttr<PassObjectSizeAttr>()) {
925 S.
Diag(
D->
getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
947 if (!cast<ParmVarDecl>(
D)->getType()->isPointerType()) {
956 ConsumableAttr::ConsumedState DefaultState;
960 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
962 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
967 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
980 if (!RD->hasAttr<ConsumableAttr>()) {
981 S.
Diag(AL.
getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
998 for (
unsigned ArgIndex = 0; ArgIndex < AL.
getNumArgs(); ++ArgIndex) {
999 CallableWhenAttr::ConsumedState CallableState;
1001 StringRef StateString;
1012 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1014 S.
Diag(
Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1018 States.push_back(CallableState);
1022 CallableWhenAttr(S.
Context, AL, States.data(), States.size()));
1026 ParamTypestateAttr::ConsumedState ParamState;
1032 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1034 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1035 << AL << StateString;
1039 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1060 ReturnTypestateAttr::ConsumedState ReturnState;
1064 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1066 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1071 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1108 SetTypestateAttr::ConsumedState NewState;
1112 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1113 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1118 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1130 TestTypestateAttr::ConsumedState TestState;
1134 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1135 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1140 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1154 if (
auto *TD = dyn_cast<TagDecl>(
D))
1156 else if (
auto *FD = dyn_cast<FieldDecl>(
D)) {
1163 if (BitfieldByteAligned)
1165 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1171 if (BitfieldByteAligned)
1172 S.
Diag(AL.
getLoc(), diag::warn_attribute_packed_for_bitfield);
1178 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
1182 auto *RD = cast<CXXRecordDecl>(
D);
1184 assert(CTD &&
"attribute does not appertain to this declaration");
1195 if (
const auto *CTSD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
1197 Template = CTSD->getSpecializedTemplate();
1199 while (TST && TST->isTypeAlias())
1202 Template = TST->getTemplateName().getAsTemplateDecl();
1211 S.
Diag(AL.
getLoc(), diag::err_attribute_preferred_name_arg_invalid)
1214 S.
Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at)
1223 T =
T.getNonReferenceType();
1229 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1231 for (
const auto *I : UD->
fields()) {
1245 bool isReturnValue =
false) {
1248 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1249 << AL << AttrParmRange << TypeRange;
1251 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1252 << AL << AttrParmRange << TypeRange << 0;
1260 for (
unsigned I = 0; I < AL.
getNumArgs(); ++I) {
1274 NonNullArgs.push_back(Idx);
1285 I !=
E && !AnyPointers; ++I) {
1292 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1295 ParamIdx *Start = NonNullArgs.data();
1296 unsigned Size = NonNullArgs.size();
1297 llvm::array_pod_sort(Start, Start + Size);
1307 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1336 QualType T = cast<ParmVarDecl>(
D)->getType();
1338 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1361 AssumeAlignedAttr TmpAttr(
Context, CI,
E, OE);
1365 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1366 << &TmpAttr << TmpAttr.getRange() << SR;
1371 std::optional<llvm::APSInt> I = llvm::APSInt(64);
1374 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1378 Diag(AttrLoc, diag::err_attribute_argument_type)
1384 if (!I->isPowerOf2()) {
1385 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1391 Diag(CI.
getLoc(), diag::warn_assume_aligned_too_great)
1396 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1414 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1420 const auto *FuncDecl = cast<FunctionDecl>(
D);
1430 << FuncDecl->getParamDecl(Idx.
getASTIndex())->getSourceRange();
1440 if (AttrName.size() > 4 && AttrName.starts_with(
"__") &&
1441 AttrName.ends_with(
"__")) {
1442 AttrName = AttrName.drop_front(2).drop_back(2);
1458 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1464 OwnershipAttr::OwnershipKind K =
1465 OwnershipAttr(S.
Context, AL,
nullptr,
nullptr, 0).getOwnKind();
1469 case OwnershipAttr::Takes:
1470 case OwnershipAttr::Holds:
1472 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1476 case OwnershipAttr::Returns:
1478 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1486 if (K == OwnershipAttr::Returns &&
1488 S.
Diag(AL.
getLoc(), diag::err_ownership_takes_return_type) << AL;
1494 StringRef ModuleName =
Module->getName();
1500 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1510 case OwnershipAttr::Takes:
1511 case OwnershipAttr::Holds:
1515 case OwnershipAttr::Returns:
1521 S.
Diag(AL.
getLoc(), diag::err_ownership_type) << AL << Err
1530 if (I->getOwnKind() != K && llvm::is_contained(I->args(), Idx)) {
1531 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
1534 I->isRegularKeywordAttribute());
1536 }
else if (K == OwnershipAttr::Returns &&
1537 I->getOwnKind() == OwnershipAttr::Returns) {
1540 if (!llvm::is_contained(I->args(), Idx)) {
1541 S.
Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1542 << I->args_begin()->getSourceIndex();
1544 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1548 }
else if (K == OwnershipAttr::Takes &&
1549 I->getOwnKind() == OwnershipAttr::Takes) {
1550 if (I->getModule()->getName() != ModuleName) {
1551 S.
Diag(I->getLocation(), diag::err_ownership_takes_class_mismatch)
1552 << I->getModule()->getName();
1553 S.
Diag(AL.
getLoc(), diag::note_ownership_takes_class_mismatch)
1560 OwnershipArgs.push_back(Idx);
1563 ParamIdx *Start = OwnershipArgs.data();
1564 unsigned Size = OwnershipArgs.size();
1565 llvm::array_pod_sort(Start, Start + Size);
1573 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1589 S.
Diag(AL.
getLoc(), diag::err_attribute_weakref_not_global_context)
1590 << cast<NamedDecl>(
D);
1634 std::unique_ptr<char, llvm::FreeDeleter> Demangled;
1636 Demangled.reset(llvm::itaniumDemangle(Str,
false));
1645 if (!isa<FunctionDecl>(ND) && !isa<VarDecl>(ND))
1647 if (MC->shouldMangleDeclName(ND)) {
1648 llvm::raw_svector_ostream Out(Name);
1652 Name = ND->getIdentifier()->getName();
1666 const auto *FD = cast<FunctionDecl>(
D);
1668 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 1;
1682 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_darwin);
1690 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_nvptx);
1694 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
1696 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 0;
1700 const auto *VD = cast<VarDecl>(
D);
1701 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1702 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << VD << 0;
1719 if (Model !=
"global-dynamic" && Model !=
"local-dynamic"
1720 && Model !=
"initial-exec" && Model !=
"local-exec") {
1721 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1735 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1743 if (checkAttrMutualExclusion<CPUSpecificAttr>(S,
D, AL))
1747 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1748 S.
Diag(
Other->getLocation(), diag::note_conflicting_attribute);
1751 }
else if (AL.
getParsedKind() == ParsedAttr::AT_CPUSpecific) {
1752 if (checkAttrMutualExclusion<CPUDispatchAttr>(S,
D, AL))
1756 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1757 S.
Diag(
Other->getLocation(), diag::note_conflicting_attribute);
1764 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
D)) {
1765 if (MD->getParent()->isLambda()) {
1766 S.
Diag(AL.
getLoc(), diag::err_attribute_dll_lambda) << AL;
1777 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1786 S.
Diag(CPUArg->
Loc, diag::err_invalid_cpu_specific_dispatch_value)
1787 << CPUName << (AL.
getKind() == ParsedAttr::AT_CPUDispatch);
1793 return Target.CPUSpecificManglingCharacter(CPUName) ==
1796 S.
Diag(AL.
getLoc(), diag::warn_multiversion_duplicate_entries);
1799 CPUs.push_back(CPUArg->
Ident);
1803 if (AL.
getKind() == ParsedAttr::AT_CPUSpecific)
1805 CPUSpecificAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
1808 CPUDispatchAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
1813 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
1824 const auto &Arch = Triple.getArch();
1825 if (Arch != llvm::Triple::x86 &&
1826 (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
1827 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_on_arch)
1828 << AL << Triple.getArchName();
1834 if (S.
getLangOpts().MSVCCompat && isa<CXXMethodDecl>(
D)) {
1835 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_decl_type_str)
1847 if (!isa<ObjCMethodDecl>(
D)) {
1848 S.
Diag(Attrs.
getLoc(), diag::warn_attribute_wrong_decl_type)
1874 S.
Diag(Attrs.
getLoc(), diag::warn_nocf_check_attribute_ignored);
1876 handleSimpleAttribute<AnyX86NoCfCheckAttr>(S,
D, Attrs);
1892 ? diag::err_keyword_not_supported_on_target
1893 : diag::warn_unknown_attribute_ignored)
1911 ? diag::err_attribute_wrong_decl_type
1912 : diag::warn_attribute_wrong_decl_type)
1948 if (VecReturnAttr *A =
D->
getAttr<VecReturnAttr>()) {
1949 S.
Diag(AL.
getLoc(), diag::err_repeat_attribute) << A;
1953 const auto *R = cast<RecordDecl>(
D);
1956 if (!isa<CXXRecordDecl>(R)) {
1957 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1961 if (!cast<CXXRecordDecl>(R)->isPOD()) {
1962 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
1966 for (
const auto *I : R->fields()) {
1967 if ((count == 1) || !I->getType()->isVectorType()) {
1968 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1979 if (isa<ParmVarDecl>(
D)) {
1984 diag::err_carries_dependency_param_not_function_decl);
1998 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2004 uint32_t priority = ConstructorAttr::DefaultPriority;
2006 S.
Diag(AL.
getLoc(), diag::err_hlsl_init_priority_unsupported);
2017 uint32_t priority = DestructorAttr::DefaultPriority;
2025template <
typename AttrTy>
2037 VersionTuple Introduced,
2038 VersionTuple Deprecated,
2039 VersionTuple Obsoleted) {
2040 StringRef PlatformName
2041 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2042 if (PlatformName.empty())
2043 PlatformName = Platform->
getName();
2047 if (!Introduced.empty() && !Deprecated.empty() &&
2048 !(Introduced <= Deprecated)) {
2050 << 1 << PlatformName << Deprecated.getAsString()
2051 << 0 << Introduced.getAsString();
2055 if (!Introduced.empty() && !Obsoleted.empty() &&
2056 !(Introduced <= Obsoleted)) {
2058 << 2 << PlatformName << Obsoleted.getAsString()
2059 << 0 << Introduced.getAsString();
2063 if (!Deprecated.empty() && !Obsoleted.empty() &&
2064 !(Deprecated <= Obsoleted)) {
2066 << 2 << PlatformName << Obsoleted.getAsString()
2067 << 1 << Deprecated.getAsString();
2079 bool BeforeIsOkay) {
2080 if (
X.empty() || Y.empty())
2086 if (BeforeIsOkay &&
X < Y)
2094 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
2095 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
2098 VersionTuple MergedIntroduced = Introduced;
2099 VersionTuple MergedDeprecated = Deprecated;
2100 VersionTuple MergedObsoleted = Obsoleted;
2101 bool FoundAny =
false;
2102 bool OverrideOrImpl =
false;
2106 OverrideOrImpl =
false;
2112 OverrideOrImpl =
true;
2118 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2119 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2126 if (OldPlatform != Platform) {
2132 if (OldEnvironment != Environment) {
2140 if (OldAA->getPriority() <
Priority)
2146 if (OldAA->getPriority() >
Priority) {
2147 Attrs.erase(Attrs.begin() + i);
2153 VersionTuple OldIntroduced = OldAA->getIntroduced();
2154 VersionTuple OldDeprecated = OldAA->getDeprecated();
2155 VersionTuple OldObsoleted = OldAA->getObsoleted();
2156 bool OldIsUnavailable = OldAA->getUnavailable();
2158 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2159 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2161 !(OldIsUnavailable == IsUnavailable ||
2162 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2163 if (OverrideOrImpl) {
2165 VersionTuple FirstVersion;
2166 VersionTuple SecondVersion;
2167 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2169 FirstVersion = OldIntroduced;
2170 SecondVersion = Introduced;
2171 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2173 FirstVersion = Deprecated;
2174 SecondVersion = OldDeprecated;
2175 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2177 FirstVersion = Obsoleted;
2178 SecondVersion = OldObsoleted;
2182 Diag(OldAA->getLocation(),
2183 diag::warn_mismatched_availability_override_unavail)
2184 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2195 Diag(OldAA->getLocation(),
2196 diag::warn_mismatched_availability_override)
2198 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2199 << FirstVersion.getAsString() << SecondVersion.getAsString()
2203 Diag(CI.
getLoc(), diag::note_overridden_method);
2205 Diag(CI.
getLoc(), diag::note_protocol_method);
2207 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2208 Diag(CI.
getLoc(), diag::note_previous_attribute);
2211 Attrs.erase(Attrs.begin() + i);
2216 VersionTuple MergedIntroduced2 = MergedIntroduced;
2217 VersionTuple MergedDeprecated2 = MergedDeprecated;
2218 VersionTuple MergedObsoleted2 = MergedObsoleted;
2220 if (MergedIntroduced2.empty())
2221 MergedIntroduced2 = OldIntroduced;
2222 if (MergedDeprecated2.empty())
2223 MergedDeprecated2 = OldDeprecated;
2224 if (MergedObsoleted2.empty())
2225 MergedObsoleted2 = OldObsoleted;
2228 MergedIntroduced2, MergedDeprecated2,
2229 MergedObsoleted2)) {
2230 Attrs.erase(Attrs.begin() + i);
2235 MergedIntroduced = MergedIntroduced2;
2236 MergedDeprecated = MergedDeprecated2;
2237 MergedObsoleted = MergedObsoleted2;
2243 MergedIntroduced == Introduced &&
2244 MergedDeprecated == Deprecated &&
2245 MergedObsoleted == Obsoleted)
2251 MergedDeprecated, MergedObsoleted) &&
2253 auto *Avail = ::new (
Context) AvailabilityAttr(
2254 Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable,
2255 Message, IsStrict, Replacement,
Priority, Environment);
2263 if (isa<UsingDecl, UnresolvedUsingTypenameDecl, UnresolvedUsingValueDecl>(
2275 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2276 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2279 auto *ND = dyn_cast<NamedDecl>(
D);
2289 if (
const auto *SE = dyn_cast_if_present<StringLiteral>(AL.
getMessageExpr()))
2290 Str = SE->getString();
2291 StringRef Replacement;
2292 if (
const auto *SE =
2294 Replacement = SE->getString();
2296 if (II->
isStr(
"swift")) {
2298 (!IsUnavailable && !Deprecated.
isValid())) {
2300 diag::warn_availability_swift_unavailable_deprecated_only);
2305 if (II->
isStr(
"fuchsia")) {
2306 std::optional<unsigned>
Min, Sub;
2308 (Sub = Introduced.
Version.getSubminor())) {
2309 S.
Diag(AL.
getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2324 if (EnvironmentLoc) {
2326 IIEnvironment = EnvironmentLoc->
Ident;
2327 if (AvailabilityAttr::getEnvironmentType(
2329 llvm::Triple::EnvironmentType::UnknownEnvironment)
2330 S.
Diag(EnvironmentLoc->
Loc, diag::warn_availability_unknown_environment)
2331 << EnvironmentLoc->
Ident;
2333 S.
Diag(EnvironmentLoc->
Loc, diag::err_availability_unexpected_parameter)
2334 <<
"environment" << 1;
2340 Obsoleted.
Version, IsUnavailable, Str, IsStrict, Replacement,
2351 else if (II->
getName() ==
"ios_app_extension")
2356 const auto *IOSToWatchOSMapping =
2361 auto adjustWatchOSVersion =
2362 [IOSToWatchOSMapping](VersionTuple Version) -> VersionTuple {
2363 if (Version.empty())
2365 auto MinimumWatchOSVersion = VersionTuple(2, 0);
2367 if (IOSToWatchOSMapping) {
2368 if (
auto MappedVersion = IOSToWatchOSMapping->map(
2369 Version, MinimumWatchOSVersion, std::nullopt)) {
2370 return *MappedVersion;
2374 auto Major = Version.getMajor();
2375 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2376 if (NewMajor >= 2) {
2377 if (Version.getMinor()) {
2378 if (Version.getSubminor())
2379 return VersionTuple(NewMajor, *Version.getMinor(),
2380 *Version.getSubminor());
2382 return VersionTuple(NewMajor, *Version.getMinor());
2384 return VersionTuple(NewMajor);
2387 return MinimumWatchOSVersion;
2390 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2391 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2392 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2395 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2396 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2408 else if (II->
getName() ==
"ios_app_extension")
2413 const auto *IOSToTvOSMapping =
2418 auto AdjustTvOSVersion =
2419 [IOSToTvOSMapping](VersionTuple Version) -> VersionTuple {
2420 if (Version.empty())
2423 if (IOSToTvOSMapping) {
2424 if (
auto MappedVersion = IOSToTvOSMapping->map(
2425 Version, VersionTuple(0, 0), std::nullopt)) {
2426 return *MappedVersion;
2432 auto NewIntroduced = AdjustTvOSVersion(Introduced.
Version);
2433 auto NewDeprecated = AdjustTvOSVersion(Deprecated.
Version);
2434 auto NewObsoleted = AdjustTvOSVersion(Obsoleted.
Version);
2437 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2438 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2445 llvm::Triple::IOS &&
2447 auto GetSDKInfo = [&]() {
2456 else if (II->
getName() ==
"ios_app_extension")
2459 auto MinMacCatalystVersion = [](
const VersionTuple &
V) {
2462 if (
V.getMajor() < 13 ||
2463 (
V.getMajor() == 13 &&
V.getMinor() && *
V.getMinor() < 1))
2464 return VersionTuple(13, 1);
2468 ND, AL, NewII,
true ,
2469 MinMacCatalystVersion(Introduced.
Version),
2470 MinMacCatalystVersion(Deprecated.
Version),
2471 MinMacCatalystVersion(Obsoleted.
Version), IsUnavailable, Str,
2476 }
else if (II->
getName() ==
"macos" && GetSDKInfo() &&
2478 !Obsoleted.
Version.empty())) {
2479 if (
const auto *MacOStoMacCatalystMapping =
2480 GetSDKInfo()->getVersionMapping(
2487 auto RemapMacOSVersion =
2488 [&](
const VersionTuple &
V) -> std::optional<VersionTuple> {
2490 return std::nullopt;
2492 if (
V.getMajor() == 100000)
2493 return VersionTuple(100000);
2495 return MacOStoMacCatalystMapping->map(
V, VersionTuple(13, 1),
2498 std::optional<VersionTuple> NewIntroduced =
2499 RemapMacOSVersion(Introduced.
Version),
2501 RemapMacOSVersion(Deprecated.
Version),
2503 RemapMacOSVersion(Obsoleted.
Version);
2504 if (NewIntroduced || NewDeprecated || NewObsoleted) {
2505 auto VersionOrEmptyVersion =
2506 [](
const std::optional<VersionTuple> &
V) -> VersionTuple {
2507 return V ? *
V : VersionTuple();
2510 ND, AL, NewII,
true ,
2511 VersionOrEmptyVersion(NewIntroduced),
2512 VersionOrEmptyVersion(NewDeprecated),
2513 VersionOrEmptyVersion(NewObsoleted),
false, Str,
2532 if (
const auto *SE = dyn_cast_if_present<StringLiteral>(AL.
getArgAsExpr(0)))
2534 StringRef DefinedIn;
2535 if (
const auto *SE = dyn_cast_if_present<StringLiteral>(AL.
getArgAsExpr(1)))
2536 DefinedIn = SE->getString();
2537 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2539 if (
const auto *SE = dyn_cast_if_present<StringLiteral>(AL.
getArgAsExpr(3)))
2540 USR = SE->getString();
2548 typename T::VisibilityType value) {
2551 typename T::VisibilityType existingValue = existingAttr->
getVisibility();
2552 if (existingValue == value)
2554 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2555 S.
Diag(CI.
getLoc(), diag::note_previous_attribute);
2563 VisibilityAttr::VisibilityType Vis) {
2564 return ::mergeVisibilityAttr<VisibilityAttr>(*
this,
D, CI, Vis);
2569 TypeVisibilityAttr::VisibilityType Vis) {
2570 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this,
D, CI, Vis);
2574 bool isTypeVisibility) {
2576 if (isa<TypedefNameDecl>(
D)) {
2582 if (isTypeVisibility && !(isa<TagDecl>(
D) || isa<ObjCInterfaceDecl>(
D) ||
2583 isa<NamespaceDecl>(
D))) {
2595 VisibilityAttr::VisibilityType
type;
2596 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr,
type)) {
2597 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2604 if (
type == VisibilityAttr::Protected &&
2606 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2607 type = VisibilityAttr::Default;
2611 if (isTypeVisibility) {
2613 D, AL, (TypeVisibilityAttr::VisibilityType)
type);
2622 unsigned sentinel = (
unsigned)SentinelAttr::DefaultSentinel;
2625 std::optional<llvm::APSInt> Idx = llvm::APSInt(32);
2627 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2632 if (Idx->isSigned() && Idx->isNegative()) {
2633 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2638 sentinel = Idx->getZExtValue();
2641 unsigned nullPos = (
unsigned)SentinelAttr::DefaultNullPos;
2644 std::optional<llvm::APSInt> Idx = llvm::APSInt(32);
2646 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2650 nullPos = Idx->getZExtValue();
2652 if ((Idx->isSigned() && Idx->isNegative()) || nullPos > 1) {
2655 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2661 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
2663 if (isa<FunctionNoProtoType>(FT)) {
2664 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2668 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2669 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2672 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D)) {
2673 if (!MD->isVariadic()) {
2674 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2677 }
else if (
const auto *BD = dyn_cast<BlockDecl>(
D)) {
2678 if (!BD->isVariadic()) {
2679 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2682 }
else if (
const auto *
V = dyn_cast<VarDecl>(
D)) {
2690 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2692 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2696 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2702 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2713 !isa<CXXConstructorDecl>(
D)) {
2714 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2717 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(
D))
2718 if (MD->getReturnType()->isVoidType()) {
2719 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2727 if (isa<VarDecl>(
D))
2728 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type_str)
2730 <<
"functions, classes, or enumerations";
2739 if (LO.CPlusPlus && !LO.CPlusPlus20)
2740 S.
Diag(AL.
getLoc(), diag::ext_cxx20_attr) << AL;
2748 }
else if (LO.CPlusPlus && !LO.CPlusPlus17)
2749 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2754 isa<TypedefNameDecl>(
D)) {
2755 S.
Diag(AL.
getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
2768 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
2770 else if (isa<ObjCPropertyDecl>(
D) || isa<ObjCMethodDecl>(
D) ||
2772 (isa<ObjCInterfaceDecl>(
D) || isa<EnumDecl>(
D)))) {
2775 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2785template <
typename WorkGroupAttr>
2788 for (
unsigned i = 0; i < 3; ++i) {
2793 if (WGSize[i] == 0) {
2794 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2800 WorkGroupAttr *Existing =
D->
getAttr<WorkGroupAttr>();
2801 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2802 Existing->getYDim() == WGSize[1] &&
2803 Existing->getZDim() == WGSize[2]))
2804 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2807 WorkGroupAttr(S.
Context, AL, WGSize[0], WGSize[1], WGSize[2]));
2812 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2818 assert(ParmTSI &&
"no type source info for attribute argument");
2823 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
2827 if (VecTypeHintAttr *A =
D->
getAttr<VecTypeHintAttr>()) {
2829 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2841 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
2846 if (SectionAttr *ExistingAttr =
D->
getAttr<SectionAttr>()) {
2847 if (ExistingAttr->getName() == Name)
2849 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2851 Diag(CI.
getLoc(), diag::note_previous_attribute);
2859 return llvm::Error::success();
2862 StringRef Segment, Section;
2863 unsigned TAA, StubSize;
2865 return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
2866 TAA, HasTAA, StubSize);
2871 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
2896 cast<NamedDecl>(
D));
2907 llvm::CodeModel::Model CM;
2908 if (!CodeModelAttr::ConvertStrToModel(Str, CM)) {
2909 S.
Diag(LiteralLoc, diag::err_attr_codemodel_arg) << Str;
2919 StringRef CodeSegName) {
2921 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
2933 if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
2937 if (
const auto *ExistingAttr =
D->
getAttr<CodeSegAttr>()) {
2938 if (ExistingAttr->getName() == Name)
2940 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2942 Diag(CI.
getLoc(), diag::note_previous_attribute);
2955 if (
const auto *ExistingAttr =
D->
getAttr<CodeSegAttr>()) {
2956 if (!ExistingAttr->isImplicit()) {
2958 ExistingAttr->getName() == Str
2959 ? diag::warn_duplicate_codeseg_attribute
2960 : diag::err_conflicting_codeseg_attribute);
2970 enum FirstParam { Unsupported, Duplicate,
Unknown };
2971 enum SecondParam {
None, CPU, Tune };
2973 if (AttrStr.contains(
"fpmath="))
2974 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
2975 << Unsupported <<
None <<
"fpmath=" <<
Target;
2979 AttrStr.contains(
"tune="))
2980 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
2986 if (!ParsedAttrs.
CPU.empty() &&
2988 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
2991 if (!ParsedAttrs.
Tune.empty() &&
2993 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
2998 return Diag(LiteralLoc, diag::err_duplicate_target_attribute)
3002 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3005 for (
const auto &Feature : ParsedAttrs.
Features) {
3006 auto CurFeature = StringRef(Feature).drop_front();
3008 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3009 << Unsupported <<
None << CurFeature <<
Target;
3018 if (DiagMsg.empty())
3019 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3020 << Unsupported <<
None <<
"branch-protection" <<
Target;
3021 return Diag(LiteralLoc, diag::err_invalid_branch_protection_spec)
3024 if (!DiagMsg.empty())
3025 Diag(LiteralLoc, diag::warn_unsupported_branch_protection_spec) << DiagMsg;
3031 StringRef AttrStr) {
3032 enum FirstParam { Unsupported };
3033 enum SecondParam {
None };
3036 AttrStr.split(Features,
"+");
3037 for (
auto &CurFeature : Features) {
3038 CurFeature = CurFeature.trim();
3039 if (CurFeature ==
"default")
3042 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3054 TargetVersionAttr *NewAttr =
3066 TargetAttr *NewAttr = ::new (S.
Context) TargetAttr(S.
Context, AL, Str);
3072 Decl *
D,
bool &HasDefault,
bool &HasCommas,
bool &HasNotDefault,
3074 enum FirstParam { Unsupported, Duplicate,
Unknown };
3075 enum SecondParam {
None, CPU, Tune };
3077 HasCommas = HasCommas || Str.contains(
',');
3080 if (Str.size() == 0)
3081 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3084 std::pair<StringRef, StringRef> Parts = {{}, Str};
3085 while (!Parts.second.empty()) {
3086 Parts = Parts.second.split(
',');
3087 StringRef Cur = Parts.first.trim();
3089 Literal->getLocationOfByte(Cur.data() - Literal->getString().data(),
3092 bool DefaultIsDupe =
false;
3093 bool HasCodeGenImpact =
false;
3095 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3100 if (Cur ==
"default") {
3101 DefaultIsDupe = HasDefault;
3103 if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
3104 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3106 StringsBuffer.push_back(Cur);
3108 std::pair<StringRef, StringRef> CurParts = {{}, Cur};
3110 while (!CurParts.second.empty()) {
3111 CurParts = CurParts.second.split(
'+');
3112 StringRef CurFeature = CurParts.first.trim();
3114 Diag(CurLoc, diag::warn_unsupported_target_attribute)
3119 HasCodeGenImpact =
true;
3120 CurFeatures.push_back(CurFeature);
3123 llvm::sort(CurFeatures);
3125 for (
auto &CurFeat : CurFeatures) {
3128 Res.append(CurFeat);
3130 if (llvm::is_contained(StringsBuffer, Res) || DefaultIsDupe)
3131 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3132 else if (!HasCodeGenImpact)
3135 Diag(CurLoc, diag::warn_target_clone_no_impact_options);
3136 else if (!Res.empty()) {
3137 StringsBuffer.push_back(Res);
3138 HasNotDefault =
true;
3143 if (Cur.starts_with(
"arch=")) {
3145 Cur.drop_front(
sizeof(
"arch=") - 1)))
3146 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3147 << Unsupported << CPU << Cur.drop_front(
sizeof(
"arch=") - 1)
3149 }
else if (Cur ==
"default") {
3150 DefaultIsDupe = HasDefault;
3153 return Diag(CurLoc, diag::warn_unsupported_target_attribute)
3155 if (llvm::is_contained(StringsBuffer, Cur) || DefaultIsDupe)
3156 Diag(CurLoc, diag::warn_target_clone_duplicate_options);
3158 StringsBuffer.push_back(Cur);
3161 if (Str.rtrim().ends_with(
","))
3162 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3175 S.
Diag(AL.
getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3176 S.
Diag(
Other->getLocation(), diag::note_conflicting_attribute);
3179 if (checkAttrMutualExclusion<TargetClonesAttr>(S,
D, AL))
3184 bool HasCommas =
false, HasDefault =
false, HasNotDefault =
false;
3186 for (
unsigned I = 0,
E = AL.
getNumArgs(); I !=
E; ++I) {
3193 HasDefault, HasCommas, HasNotDefault, StringsBuffer))
3196 for (
auto &SmallStr : StringsBuffer)
3197 Strings.push_back(SmallStr.str());
3200 S.
Diag(AL.
getLoc(), diag::warn_target_clone_mixed_values);
3205 Strings.push_back(
"default");
3209 S.
Diag(AL.
getLoc(), diag::err_target_clone_must_have_default);
3215 if (
const auto *MD = dyn_cast<CXXMethodDecl>(
D)) {
3216 if (MD->getParent()->isLambda()) {
3228 cast<FunctionDecl>(
D)->setIsMultiVersion();
3229 TargetClonesAttr *NewAttr = ::new (S.
Context)
3230 TargetClonesAttr(S.
Context, AL, Strings.data(), Strings.size());
3242 MinVectorWidthAttr *Existing =
D->
getAttr<MinVectorWidthAttr>();
3243 if (Existing && Existing->getVectorWidth() != VecWidth) {
3244 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3259 if (
auto *DRE = dyn_cast<DeclRefExpr>(
E)) {
3261 S.
Diag(
Loc, diag::warn_cleanup_ext);
3262 FD = dyn_cast<FunctionDecl>(DRE->
getDecl());
3265 S.
Diag(
Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3269 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(
E)) {
3270 if (ULE->hasExplicitTemplateArgs())
3271 S.
Diag(
Loc, diag::warn_cleanup_ext);
3273 NI = ULE->getNameInfo();
3275 S.
Diag(
Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3282 S.
Diag(
Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3287 S.
Diag(
Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3298 S.
Diag(
Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3299 << NI.
getName() << ParamTy << Ty;
3313 S.
Context, VariableReference, UnaryOperatorKind::UO_AddrOf,
3333 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3338 EnumExtensibilityAttr::Kind ExtensibilityKind;
3340 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3341 ExtensibilityKind)) {
3342 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3347 EnumExtensibilityAttr(S.
Context, AL, ExtensibilityKind));
3365 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3373 if (
auto *OMD = dyn_cast<ObjCMethodDecl>(
D))
3374 if (
auto *
Interface = OMD->getClassInterface())
3381 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3382 << (NotNSStringTy ?
"string type" :
"NSString")
3402 return llvm::StringSwitch<FormatAttrKind>(Format)
3416 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag",
IgnoredFormat)
3424 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3429 S.
Diag(AL.
getLoc(), diag::err_hlsl_init_priority_unsupported);
3434 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3442 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3448 uint32_t prioritynum;
3457 if ((prioritynum < 101 || prioritynum > 65535) &&
3459 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
3468 StringRef NewUserDiagnostic) {
3469 if (
const auto *EA =
D->
getAttr<ErrorAttr>()) {
3471 assert((NewAttr ==
"error" || NewAttr ==
"warning") &&
3472 "unexpected normalized full name");
3473 bool Match = (EA->isError() && NewAttr ==
"error") ||
3474 (EA->isWarning() && NewAttr ==
"warning");
3476 Diag(EA->getLocation(), diag::err_attributes_are_not_compatible)
3479 EA->isRegularKeywordAttribute());
3480 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
3483 if (EA->getUserDiagnostic() != NewUserDiagnostic) {
3484 Diag(CI.
getLoc(), diag::warn_duplicate_attribute) << EA;
3485 Diag(EA->getLoc(), diag::note_previous_attribute);
3489 return ::new (
Context) ErrorAttr(
Context, CI, NewUserDiagnostic);
3497 if (F->getType() == Format &&
3498 F->getFormatIdx() == FormatIdx &&
3499 F->getFirstArg() == FirstArg) {
3502 if (F->getLocation().isInvalid())
3508 return ::new (
Context) FormatAttr(
Context, CI, Format, FormatIdx, FirstArg);
3515 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3526 StringRef Format = II->
getName();
3540 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3551 if (Idx < 1 || Idx > NumArgs) {
3552 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3558 unsigned ArgIdx = Idx - 1;
3560 if (HasImplicitThisParam) {
3563 diag::err_format_attribute_implicit_this_format_string)
3576 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3588 if (FirstArg != 0) {
3592 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
3600 if (FirstArg != NumArgs + 1) {
3601 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3604 std::to_string(NumArgs + 1));
3610 if (FirstArg <= Idx) {
3614 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3630 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_no_callee)
3639 assert(FD &&
"Expected a function declaration!");
3641 llvm::StringMap<int> NameIdxMapping;
3642 NameIdxMapping[
"__"] = -1;
3644 NameIdxMapping[
"this"] = 0;
3648 NameIdxMapping[PVD->getName()] = Idx++;
3650 auto UnknownName = NameIdxMapping.end();
3653 for (
unsigned I = 0,
E = AL.
getNumArgs(); I <
E; ++I) {
3659 auto It = NameIdxMapping.find(IdLoc->
Ident->
getName());
3660 if (It == UnknownName) {
3661 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_argument_unknown)
3667 ArgIdx = It->second;
3674 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3680 if (ArgIdx < -1 || ArgIdx > NumArgs) {
3681 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3688 llvm_unreachable(
"Unexpected ParsedAttr argument type!");
3691 if (ArgIdx == 0 && !HasImplicitThisParam) {
3692 S.
Diag(AL.
getLoc(), diag::err_callback_implicit_this_not_available)
3699 if (!HasImplicitThisParam && ArgIdx > 0)
3702 EncodingIndices.push_back(ArgIdx);
3705 int CalleeIdx = EncodingIndices.front();
3709 if (CalleeIdx < (
int)HasImplicitThisParam) {
3710 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_invalid_callee)
3717 const Type *CalleeType =
3721 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3726 const Type *CalleeFnType =
3731 const auto *CalleeFnProtoType = dyn_cast<FunctionProtoType>(CalleeFnType);
3732 if (!CalleeFnProtoType) {
3733 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3738 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
3739 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3740 << AL << (
unsigned)(EncodingIndices.size() - 1);
3744 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
3745 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3746 << AL << (
unsigned)(EncodingIndices.size() - 1);
3750 if (CalleeFnProtoType->isVariadic()) {
3762 S.
Context, AL, EncodingIndices.data(), EncodingIndices.size()));
3775 QualType T = cast<ParmVarDecl>(
D)->getType();
3778 S.
Diag(AL.
getLoc(), diag::err_called_once_attribute_wrong_type);
3788 const auto *TD = dyn_cast<TypedefNameDecl>(
D);
3789 if (TD && TD->getUnderlyingType()->isUnionType())
3790 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
3792 RD = dyn_cast<RecordDecl>(
D);
3795 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
3803 diag::warn_transparent_union_attribute_not_definition);
3809 if (Field == FieldEnd) {
3810 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3818 diag::warn_transparent_union_attribute_floating)
3827 for (; Field != FieldEnd; ++Field) {
3828 QualType FieldType = Field->getType();
3842 S.
Diag(Field->getLocation(),
3843 diag::warn_transparent_union_attribute_field_size_align)
3844 << isSize << *Field << FieldBits;
3845 unsigned FirstBits = isSize ? FirstSize : FirstAlign;
3847 diag::note_transparent_union_first_field_size_align)
3848 << isSize << FirstBits;
3858 auto *
Attr = AnnotateAttr::Create(
Context, Str, Args.data(), Args.size(), CI);
3874 for (
unsigned Idx = 1; Idx < AL.
getNumArgs(); Idx++) {
3887 AlignValueAttr TmpAttr(
Context, CI,
E);
3891 if (
const auto *TD = dyn_cast<TypedefNameDecl>(
D))
3892 T = TD->getUnderlyingType();
3893 else if (
const auto *VD = dyn_cast<ValueDecl>(
D))
3896 llvm_unreachable(
"Unknown decl type for align_value");
3900 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
3906 llvm::APSInt Alignment;
3908 E, &Alignment, diag::err_align_value_attribute_argument_not_int);
3912 if (!Alignment.isPowerOf2()) {
3913 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3935 diag::err_pack_expansion_without_parameter_packs);
3950 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3962 diag::err_pack_expansion_without_parameter_packs);
3989 const AlignedAttr &
Attr,
3992 if (isa<ParmVarDecl>(
D)) {
3994 }
else if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
3997 if (VD->isExceptionVariable())
3999 }
else if (
const auto *FD = dyn_cast<FieldDecl>(
D)) {
4000 if (FD->isBitField())
4002 }
else if (
const auto *ED = dyn_cast<EnumDecl>(
D)) {
4003 if (ED->getLangOpts().CPlusPlus)
4005 }
else if (!isa<TagDecl>(
D)) {
4006 return S.
Diag(AttrLoc, diag::err_attribute_wrong_decl_type)
4011 if (DiagKind != -1) {
4012 return S.
Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
4013 << &
Attr << DiagKind;
4019 bool IsPackExpansion) {
4020 AlignedAttr TmpAttr(
Context, CI,
true,
E);
4024 if (TmpAttr.isAlignas() &&
4032 if (
const auto *TND = dyn_cast<TypedefNameDecl>(
D)) {
4033 if (!TND->getUnderlyingType()->isDependentType()) {
4034 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
4042 AA->setPackExpansion(IsPackExpansion);
4048 llvm::APSInt Alignment;
4050 E, &Alignment, diag::err_aligned_attribute_argument_not_int);
4058 Diag(AttrLoc, diag::err_attribute_aligned_too_great)
4063 uint64_t AlignVal = Alignment.getZExtValue();
4069 if (!(TmpAttr.isAlignas() && !Alignment)) {
4070 if (!llvm::isPowerOf2_64(AlignVal)) {
4071 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
4077 const auto *VD = dyn_cast<VarDecl>(
D);
4079 unsigned MaxTLSAlign =
4082 if (MaxTLSAlign && AlignVal > MaxTLSAlign &&
4084 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
4085 << (
unsigned)AlignVal << VD << MaxTLSAlign;
4093 const Type *Ty = VD->getType().getTypePtr();
4095 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4096 << VD->getType() << 16;
4102 AA->setPackExpansion(IsPackExpansion);
4103 AA->setCachedAlignmentValue(
4110 AlignedAttr TmpAttr(
Context, CI,
false, TS);
4114 if (TmpAttr.isAlignas() &&
4122 if (
const auto *TND = dyn_cast<TypedefNameDecl>(
D)) {
4123 if (!TND->getUnderlyingType()->isDependentType()) {
4124 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
4130 AlignedAttr *AA = ::new (
Context) AlignedAttr(
Context, CI,
false, TS);
4131 AA->setPackExpansion(IsPackExpansion);
4136 const auto *VD = dyn_cast<VarDecl>(
D);
4137 unsigned AlignVal = TmpAttr.getAlignment(
Context);
4141 const Type *Ty = VD->getType().getTypePtr();
4144 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4145 << VD->getType() << 16;
4150 AlignedAttr *AA = ::new (
Context) AlignedAttr(
Context, CI,
false, TS);
4151 AA->setPackExpansion(IsPackExpansion);
4152 AA->setCachedAlignmentValue(AlignVal);
4157 assert(
D->
hasAttrs() &&
"no attributes on decl");
4160 if (
const auto *VD = dyn_cast<ValueDecl>(
D)) {
4161 UnderlyingTy = DiagTy = VD->getType();
4164 if (
const auto *ED = dyn_cast<EnumDecl>(
D))
4165 UnderlyingTy = ED->getIntegerType();
4174 AlignedAttr *AlignasAttr =
nullptr;
4175 AlignedAttr *LastAlignedAttr =
nullptr;
4178 if (I->isAlignmentDependent())
4182 Align = std::max(Align, I->getAlignment(
Context));
4183 LastAlignedAttr = I;
4187 Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type)
4188 << LastAlignedAttr << DiagTy;
4189 }
else if (AlignasAttr && Align) {
4192 if (NaturalAlign > RequestedAlign)
4193 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
4229 bool &IntegerMode,
bool &ComplexMode,
4232 ComplexMode =
false;
4234 switch (Str.size()) {
4254 DestWidth = Str[1] ==
'I' ? 0 : 128;
4262 DestWidth = Str[1] ==
'I' ? 0 : 128;
4265 if (Str[1] ==
'F') {
4266 IntegerMode =
false;
4267 }
else if (Str[1] ==
'C') {
4268 IntegerMode =
false;
4270 }
else if (Str[1] !=
'I') {
4279 else if (Str ==
"byte")
4283 if (Str ==
"pointer")
4287 if (Str ==
"unwind_word")
4303 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
4315 StringRef Str = Name->getName();
4319 unsigned DestWidth = 0;
4320 bool IntegerMode =
true;
4321 bool ComplexMode =
false;
4323 llvm::APInt VectorSize(64, 0);
4324 if (Str.size() >= 4 && Str[0] ==
'V') {
4326 size_t StrSize = Str.size();
4327 size_t VectorStringLength = 0;
4328 while ((VectorStringLength + 1) < StrSize &&
4329 isdigit(Str[VectorStringLength + 1]))
4330 ++VectorStringLength;
4331 if (VectorStringLength &&
4332 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
4333 VectorSize.isPowerOf2()) {
4335 IntegerMode, ComplexMode, ExplicitType);
4337 if (!InInstantiation)
4338 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
4353 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
4358 if (
const auto *TD = dyn_cast<TypedefNameDecl>(
D))
4359 OldTy = TD->getUnderlyingType();
4360 else if (
const auto *ED = dyn_cast<EnumDecl>(
D)) {
4363 OldTy = ED->getIntegerType();
4367 OldTy = cast<ValueDecl>(
D)->getType();
4378 OldElemTy = VT->getElementType();
4384 VectorSize.getBoolValue()) {
4385 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.
getRange();
4393 !IntegralOrAnyEnumType)
4394 Diag(AttrLoc, diag::err_mode_not_primitive);
4395 else if (IntegerMode) {
4396 if (!IntegralOrAnyEnumType)
4397 Diag(AttrLoc, diag::err_mode_wrong_type);
4398 }
else if (ComplexMode) {
4400 Diag(AttrLoc, diag::err_mode_wrong_type);
4403 Diag(AttrLoc, diag::err_mode_wrong_type);
4414 if (NewElemTy.
isNull()) {
4416 if (!(DestWidth == 128 &&
getLangOpts().CUDAIsDevice))
4417 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4426 if (VectorSize.getBoolValue()) {
4432 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4436 OldVT->getNumElements() /
4443 Diag(AttrLoc, diag::err_mode_wrong_type);
4448 if (
auto *TD = dyn_cast<TypedefNameDecl>(
D))
4449 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4450 else if (
auto *ED = dyn_cast<EnumDecl>(
D))
4451 ED->setIntegerType(NewTy);
4453 cast<ValueDecl>(
D)->setType(NewTy);
4465 if (OptimizeNoneAttr *Optnone =
D->
getAttr<OptimizeNoneAttr>()) {
4466 Diag(CI.
getLoc(), diag::warn_attribute_ignored) << Ident;
4467 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4471 if (
D->
hasAttr<AlwaysInlineAttr>())
4479 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
4482 if (VD->getKind() != Decl::Var) {
4483 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4490 if (VD->hasLocalStorage()) {
4491 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4498InternalLinkageAttr *
4500 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
4503 if (VD->getKind() != Decl::Var) {
4504 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4505 << &AL << AL.isRegularKeywordAttribute()
4511 if (VD->hasLocalStorage()) {
4512 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4521 if (OptimizeNoneAttr *Optnone =
D->
getAttr<OptimizeNoneAttr>()) {
4522 Diag(CI.
getLoc(), diag::warn_attribute_ignored) <<
"'minsize'";
4523 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4535 if (AlwaysInlineAttr *Inline =
D->
getAttr<AlwaysInlineAttr>()) {
4536 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4537 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4540 if (MinSizeAttr *MinSize =
D->
getAttr<MinSizeAttr>()) {
4541 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4542 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4546 if (
D->
hasAttr<OptimizeNoneAttr>())
4553 if (AlwaysInlineAttr *Inline =
4569 const auto *VD = cast<VarDecl>(
D);
4570 if (VD->hasLocalStorage()) {
4571 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4576 if (
auto *A =
D->
getAttr<CUDAConstantAttr>()) {
4577 if (!A->isImplicit())
4585 const auto *VD = cast<VarDecl>(
D);
4588 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4589 !isa<IncompleteArrayType>(VD->getType())) {
4590 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4593 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4601 const auto *FD = cast<FunctionDecl>(
D);
4612 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4613 if (Method->isInstance()) {
4614 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4618 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4624 if (AL.
getKind() == ParsedAttr::AT_NVPTXKernel)
4637 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
4638 if (VD->hasLocalStorage()) {
4639 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);
4644 if (
auto *A =
D->
getAttr<CUDADeviceAttr>()) {
4645 if (!A->isImplicit())
4653 if (
const auto *VD = dyn_cast<VarDecl>(
D)) {
4654 if (VD->hasLocalStorage()) {
4655 S.
Diag(AL.
getLoc(), diag::err_cuda_nonstatic_constdev);