Lines Matching defs:AL
83 static unsigned getNumAttributeArgs(const ParsedAttr &AL) {
85 return AL.getNumArgs() + AL.hasParsedType();
88 SourceLocation Sema::getAttrLoc(const ParsedAttr &AL) { return AL.getLoc(); }
129 bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
133 if (AL.isArgIdent(ArgNum)) {
134 IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum);
136 << AL << AANT_ArgumentString
146 Expr *ArgExpr = AL.getArgAsExpr(ArgNum);
153 << AL << AANT_ArgumentString;
157 return checkStringLiteralArgumentAttr(AL, ArgExpr, Str, ArgLocation);
206 const ParsedAttr &AL) {
223 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
340 const ParsedAttr &AL,
344 if (Sidx == AL.getNumArgs()) {
354 S.Diag(AL.getLoc(),
356 << AL << MD->getParent();
358 S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
359 << AL;
363 for (unsigned Idx = Sidx; Idx < AL.getNumArgs(); ++Idx) {
364 Expr *ArgExp = AL.getArgAsExpr(Idx);
383 S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL;
411 S.Diag(AL.getLoc(),
413 << AL << Idx + 1 << NumParams;
425 S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
426 << AL << ArgTy;
434 const ParsedAttr &AL) {
440 S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_scoped_lockable_param)
441 << AL;
449 static void handlePtGuardedVarAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
450 if (!threadSafetyCheckIsPointer(S, D, AL))
453 D->addAttr(::new (S.Context) PtGuardedVarAttr(S.Context, AL));
456 static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
460 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
470 static void handleGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
472 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
475 D->addAttr(::new (S.Context) GuardedByAttr(S.Context, AL, Arg));
478 static void handlePtGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
480 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
483 if (!threadSafetyCheckIsPointer(S, D, AL))
486 D->addAttr(::new (S.Context) PtGuardedByAttr(S.Context, AL, Arg));
489 static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
491 if (!AL.checkAtLeastNumArgs(S, 1))
497 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
502 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
509 static void handleAcquiredAfterAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
511 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
516 AcquiredAfterAttr(S.Context, AL, StartArg, Args.size()));
519 static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
521 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
526 AcquiredBeforeAttr(S.Context, AL, StartArg, Args.size()));
529 static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
533 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, /*ParamIdxOk=*/true);
538 static void handleAssertSharedLockAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
540 if (!checkLockFunAttrCommon(S, D, AL, Args))
546 AssertSharedLockAttr(S.Context, AL, StartArg, Size));
550 const ParsedAttr &AL) {
552 if (!checkLockFunAttrCommon(S, D, AL, Args))
558 AssertExclusiveLockAttr(S.Context, AL, StartArg, Size));
586 static void handleAllocSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
587 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 2))
594 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL;
598 const Expr *SizeExpr = AL.getArgAsExpr(0);
601 if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNoVal, /*Idx=*/1))
603 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/0))
608 if (AL.getNumArgs() == 2) {
609 const Expr *NumberExpr = AL.getArgAsExpr(1);
612 if (!checkPositiveIntArgument(S, AL, NumberExpr, Val, /*Idx=*/2))
614 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/1))
620 AllocSizeAttr(S.Context, AL, SizeArgNo, NumberArgNo));
623 static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
625 if (!AL.checkAtLeastNumArgs(S, 1))
628 if (!isIntOrBool(AL.getArgAsExpr(0))) {
629 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
630 << AL << 1 << AANT_ArgumentIntOrBool;
635 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
641 const ParsedAttr &AL) {
643 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
647 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
651 const ParsedAttr &AL) {
653 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
657 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
660 static void handleLockReturnedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
663 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
668 D->addAttr(::new (S.Context) LockReturnedAttr(S.Context, AL, Args[0]));
671 static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
673 ParmDecl && !checkFunParamsAreScopedLockable(S, ParmDecl, AL))
676 if (!AL.checkAtLeastNumArgs(S, 1))
681 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
688 LocksExcludedAttr(S.Context, AL, StartArg, Size));
691 static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL,
693 Cond = AL.getArgAsExpr(0);
701 if (!S.checkStringLiteralArgumentAttr(AL, 1, Msg))
711 S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
719 static void handleEnableIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
720 S.Diag(AL.getLoc(), diag::ext_clang_enable_if);
724 if (checkFunctionConditionAttr(S, D, AL, Cond, Msg))
725 D->addAttr(::new (S.Context) EnableIfAttr(S.Context, AL, Cond, Msg));
728 static void handleErrorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
730 if (!S.checkStringLiteralArgumentAttr(AL, 0, NewUserDiagnostic))
732 if (ErrorAttr *EA = S.mergeErrorAttr(D, AL, NewUserDiagnostic))
737 const ParsedAttr &AL) {
742 S.Diag(AL.getLoc(),
744 << AL << /*IsMember=*/!isa<CXXRecordDecl>(D);
748 ExcludeFromExplicitInstantiationAttr(S.Context, AL));
797 const ParsedAttr &AL) {
802 S.Diag(AL.getLoc(), diag::err_attribute_no_member_function) << AL;
808 auto Union = AL.getArg(Index - 1);
814 S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
818 if (!AL.isArgExpr(0))
820 auto *F = dyn_cast_if_present<DeclRefExpr>(AL.getArgAsExpr(0));
831 if (AttrFD->getNumParams() != AL.getNumArgs() - 1) {
832 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments_for)
833 << AL << AttrFD << AttrFD->getNumParams();
839 for (unsigned I = 1; I < AL.getNumArgs(); ++I) {
840 if (!AL.isArgExpr(I)) {
845 const Expr *IndexExpr = AL.getArgAsExpr(I);
848 if (!S.checkUInt32Argument(AL, IndexExpr, Index, I + 1, false))
852 S.Diag(AL.getLoc(), diag::err_attribute_bounds_for_function)
853 << AL << Index << DeclFD << DeclFD->getNumParams();
863 << AL << Index << DeclFD << T2 << I << AttrFD << T1;
871 S.Context, AL, AttrFD, Indices.data(), Indices.size()));
874 static void handleDiagnoseIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
875 S.Diag(AL.getLoc(), diag::ext_clang_diagnose_if);
879 if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg))
883 if (!S.checkStringLiteralArgumentAttr(AL, 2, DefaultSevStr))
888 S.Diag(AL.getArgAsExpr(2)->getBeginLoc(),
895 if (AL.getNumArgs() > 3) {
896 if (!S.checkStringLiteralArgumentAttr(AL, 3, WarningGroup))
901 S.Diag(AL.getArgAsExpr(3)->getBeginLoc(),
912 S.Context, AL, Cond, Msg, DefaultSev, WarningGroup, ArgDependent,
916 static void handleNoBuiltinAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
934 if (AL.getNumArgs() == 0)
937 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
940 if (!S.checkStringLiteralArgumentAttr(AL, I, BuiltinName, &LiteralLoc))
947 << BuiltinName << AL;
958 << AL;
963 NoBuiltinAttr(S.Context, AL, Names.data(), Names.size()));
966 static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
968 S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
972 Expr *E = AL.getArgAsExpr(0);
974 if (!S.checkUInt32Argument(AL, E, Type, /*Idx=*/1))
982 << AL << 0 << 3 << E->getSourceRange();
991 S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
995 D->addAttr(::new (S.Context) PassObjectSizeAttr(S.Context, AL, (int)Type));
998 static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1001 if (AL.isArgIdent(0)) {
1002 IdentifierLoc *IL = AL.getArgAsIdent(0);
1005 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1010 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1011 << AL << AANT_ArgumentIdentifier;
1015 D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState));
1019 const ParsedAttr &AL) {
1024 S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
1033 static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1034 if (!AL.checkAtLeastNumArgs(S, 1))
1037 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1041 for (unsigned ArgIndex = 0; ArgIndex < AL.getNumArgs(); ++ArgIndex) {
1046 if (AL.isArgIdent(ArgIndex)) {
1047 IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex);
1051 if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc))
1057 S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1065 CallableWhenAttr(S.Context, AL, States.data(), States.size()));
1068 static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1071 if (AL.isArgIdent(0)) {
1072 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1078 << AL << StateString;
1082 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1083 << AL << AANT_ArgumentIdentifier;
1094 // S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
1099 D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
1102 static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1105 if (AL.isArgIdent(0)) {
1106 IdentifierLoc *IL = AL.getArgAsIdent(0);
1109 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1114 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1115 << AL << AANT_ArgumentIdentifier;
1144 D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
1147 static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1148 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1152 if (AL.isArgIdent(0)) {
1153 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1156 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1161 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1162 << AL << AANT_ArgumentIdentifier;
1166 D->addAttr(::new (S.Context) SetTypestateAttr(S.Context, AL, NewState));
1169 static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1170 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1174 if (AL.isArgIdent(0)) {
1175 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1178 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1183 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1184 << AL << AANT_ArgumentIdentifier;
1188 D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState));
1191 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1196 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1198 TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1208 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1209 << AL << FD->getType();
1211 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1215 S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield);
1217 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1221 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
1224 static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
1229 ParsedType PT = AL.getTypeArg();
1233 TSI = S.Context.getTrivialTypeSourceInfo(T, AL.getLoc());
1249 D->addAttr(::new (S.Context) PreferredNameAttr(S.Context, AL, TSI));
1254 S.Diag(AL.getLoc(), diag::err_attribute_preferred_name_arg_invalid)
1261 static void handleNoSpecializations(Sema &S, Decl *D, const ParsedAttr &AL) {
1263 if (AL.getNumArgs() != 0)
1264 S.checkStringLiteralArgumentAttr(AL, 0, Message);
1266 NoSpecializationsAttr::Create(S.Context, Message, AL));
1295 static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL,
1301 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1302 << AL << AttrParmRange << TypeRange;
1304 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1305 << AL << AttrParmRange << TypeRange << 0;
1311 static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1313 for (unsigned I = 0; I < AL.getNumArgs(); ++I) {
1314 Expr *Ex = AL.getArgAsExpr(I);
1316 if (!S.checkFunctionOrMethodParameterIndex(D, AL, I + 1, Ex, Idx))
1322 S, getFunctionOrMethodParamType(D, Idx.getASTIndex()), AL,
1334 if (NonNullArgs.empty() && AL.getLoc().isFileID() &&
1345 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers);
1351 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size));
1355 const ParsedAttr &AL) {
1356 if (AL.getNumArgs() > 0) {
1358 handleNonNullAttr(S, D, AL);
1360 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1367 if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(),
1371 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, nullptr, 0));
1374 static void handleReturnsNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1377 if (!attrNonNullArgCheck(S, ResultType, AL, SourceRange(), SR,
1381 D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL));
1384 static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1391 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1392 << AL << AL.getRange() << 0;
1396 D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
1399 static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1400 Expr *E = AL.getArgAsExpr(0),
1401 *OE = AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr;
1402 S.AddAssumeAlignedAttr(D, AL, E, OE);
1405 static void handleAllocAlignAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1406 S.AddAllocAlignAttr(D, AL, AL.getArgAsExpr(0));
1500 static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1509 if (!AL.isArgIdent(0)) {
1510 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
1511 << AL << 1 << AANT_ArgumentIdentifier;
1517 OwnershipAttr(S.Context, AL, nullptr, nullptr, 0).getOwnKind();
1523 if (AL.getNumArgs() < 2) {
1524 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1529 if (AL.getNumArgs() > 2) {
1530 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1540 S.Diag(AL.getLoc(), diag::err_ownership_takes_return_type) << AL;
1544 IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
1552 for (unsigned i = 1; i < AL.getNumArgs(); ++i) {
1553 Expr *Ex = AL.getArgAsExpr(i);
1555 if (!S.checkFunctionOrMethodParameterIndex(D, AL, i, Ex, Idx))
1573 S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err
1583 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
1584 << AL << I
1585 << (AL.isRegularKeywordAttribute() ||
1596 S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch)
1605 S.Diag(AL.getLoc(), diag::note_ownership_takes_class_mismatch)
1619 OwnershipAttr(S.Context, AL, Module, Start, Size));
1622 static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1624 if (AL.getNumArgs() > 1) {
1625 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1641 S.Diag(AL.getLoc(), diag::err_attribute_weakref_not_global_context)
1672 if (AL.getNumArgs() && S.checkStringLiteralArgumentAttr(AL, 0, Str))
1675 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1677 D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
1684 static void markUsedForAliasOrIfunc(Sema &S, Decl *D, const ParsedAttr &AL,
1693 &S.Context.Idents.get(Demangled ? Demangled.get() : Str), AL.getLoc());
1712 static void handleIFuncAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1714 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1720 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 1;
1724 markUsedForAliasOrIfunc(S, D, AL, Str);
1725 D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
1728 static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1730 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1734 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin);
1742 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx);
1748 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 0;
1754 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << VD << 0;
1759 markUsedForAliasOrIfunc(S, D, AL, Str);
1760 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1763 static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1767 if (!S.checkStringLiteralArgumentAttr(AL, 0, Model, &LiteralLoc))
1777 D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model));
1780 static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1783 D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL));
1787 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1788 << AL << getFunctionOrMethodResultSourceRange(D);
1791 static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1794 if (AL.getParsedKind() == ParsedAttr::AT_CPUDispatch) {
1795 if (checkAttrMutualExclusion<CPUSpecificAttr>(S, D, AL))
1799 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1803 } else if (AL.getParsedKind() == ParsedAttr::AT_CPUSpecific) {
1804 if (checkAttrMutualExclusion<CPUDispatchAttr>(S, D, AL))
1808 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1818 S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL;
1823 if (!AL.checkAtLeastNumArgs(S, 1))
1827 for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
1828 if (!AL.isArgIdent(ArgNo)) {
1829 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1830 << AL << AANT_ArgumentIdentifier;
1834 IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo);
1839 << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch);
1848 S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries);
1855 if (AL.getKind() == ParsedAttr::AT_CPUSpecific)
1857 CPUSpecificAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1860 CPUDispatchAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1863 static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1865 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
1866 << AL << AttributeLangSupport::Cpp;
1870 D->addAttr(::new (S.Context) CommonAttr(S.Context, AL));
1873 static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1874 if (AL.isDeclspecAttribute()) {
1879 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch)
1880 << AL << Triple.getArchName();
1887 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
1888 << AL << AL.isRegularKeywordAttribute() << ExpectedNonMemberFunction;
1893 D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));
1940 bool Sema::CheckAttrTarget(const ParsedAttr &AL) {
1942 if (!AL.existsInTarget(Context.getTargetInfo())) {
1943 Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
1946 << AL << AL.getRange();
1947 AL.setInvalid();
1954 static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1962 S.Diag(AL.getLoc(), AL.isStandardAttributeSyntax()
1965 << AL << AL.isRegularKeywordAttribute()
1971 D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(S.Context, AL));
1975 static void handleVecReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2001 S.Diag(AL.getLoc(), diag::err_repeat_attribute) << A;
2009 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2014 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2020 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2026 D->addAttr(::new (S.Context) VecReturnAttr(S.Context, AL));
2030 const ParsedAttr &AL) {
2035 S.Diag(AL.getLoc(),
2041 D->addAttr(::new (S.Context) CarriesDependencyAttr(S.Context, AL));
2044 static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2045 bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName();
2050 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
2052 D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL));
2055 static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2057 if (S.getLangOpts().HLSL && AL.getNumArgs()) {
2058 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported);
2061 if (AL.getNumArgs() &&
2062 !S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority))
2065 D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority));
2068 static void handleDestructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2070 if (AL.getNumArgs() &&
2071 !S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority))
2074 D->addAttr(::new (S.Context) DestructorAttr(S.Context, AL, priority));
2078 static void handleAttrWithMessage(Sema &S, Decl *D, const ParsedAttr &AL) {
2081 if (AL.getNumArgs() == 1 && !S.checkStringLiteralArgumentAttr(AL, 0, Str))
2084 D->addAttr(::new (S.Context) AttrTy(S.Context, AL, Str));
2314 static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2317 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using)
2318 << AL;
2322 if (!AL.checkExactlyNumArgs(S, 1))
2324 IdentifierLoc *Platform = AL.getArgAsIdent(0);
2335 AvailabilityChange Introduced = AL.getAvailabilityIntroduced();
2336 AvailabilityChange Deprecated = AL.getAvailabilityDeprecated();
2337 AvailabilityChange Obsoleted = AL.getAvailabilityObsoleted();
2338 bool IsUnavailable = AL.getUnavailableLoc().isValid();
2339 bool IsStrict = AL.getStrictLoc().isValid();
2341 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getMessageExpr()))
2345 dyn_cast_if_present<StringLiteral>(AL.getReplacementExpr()))
2351 S.Diag(AL.getLoc(),
2361 S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2367 S.Diag(AL.getStrictLoc(), diag::err_availability_unexpected_parameter)
2370 int PriorityModifier = AL.isPragmaClangAttribute()
2374 const IdentifierLoc *EnvironmentLoc = AL.getEnvironment();
2391 ND, AL, II, false /*Implicit*/, Introduced.Version, Deprecated.Version,
2447 ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
2489 ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
2500 return S.getDarwinSDKInfoForAvailabilityChecking(AL.getRange().getBegin(),
2520 ND, AL, NewII, true /*Implicit*/,
2562 ND, AL, NewII, true /*Implicit*/,
2579 const ParsedAttr &AL) {
2580 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 4))
2584 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(0)))
2587 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(1)))
2589 bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr;
2591 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(3)))
2595 S.Context, AL, Language, DefinedIn, IsGeneratedDeclaration, USR));
2625 static void handleVisibilityAttr(Sema &S, Decl *D, const ParsedAttr &AL,
2629 S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
2636 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
2637 << AL << AL.isRegularKeywordAttribute() << ExpectedTypeOrNamespace;
2644 if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, &LiteralLoc))
2649 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2658 S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility);
2665 D, AL, (TypeVisibilityAttr::VisibilityType)type);
2667 newAttr = S.mergeVisibilityAttr(D, AL, type);
2673 static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2675 if (AL.getNumArgs() > 0) {
2676 Expr *E = AL.getArgAsExpr(0);
2679 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2680 << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2685 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero)
2694 if (AL.getNumArgs() > 1) {
2695 Expr *E = AL.getArgAsExpr(1);
2698 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2699 << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2707 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2716 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments);
2721 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2726 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2731 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2744 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2748 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2749 << AL << AL.isRegularKeywordAttribute()
2754 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2755 << AL << AL.isRegularKeywordAttribute()
2759 D->addAttr(::new (S.Context) SentinelAttr(S.Context, AL, sentinel, nullPos));
2762 static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
2766 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2771 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2776 if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
2780 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2781 << AL << AL.isRegularKeywordAttribute()
2790 if (AL.getNumArgs() == 1) {
2792 S.Diag(AL.getLoc(), diag::ext_cxx20_attr) << AL;
2798 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, nullptr))
2801 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
2804 if ((!AL.isGNUAttribute() &&
2805 !(AL.isStandardAttributeSyntax() && AL.isClangScope())) &&
2807 S.Diag(AL.getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
2808 << AL.isGNUScope();
2812 D->addAttr(::new (S.Context) WarnUnusedResultAttr(S.Context, AL, Str));
2815 static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2820 S.Diag(AL.getLoc(), diag::warn_attribute_invalid_on_definition)
2827 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2828 << AL << AL.isRegularKeywordAttribute() << ExpectedVariableOrFunction;
2833 D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL));
2838 static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2841 const Expr *E = AL.getArgAsExpr(i);
2842 if (!S.checkUInt32Argument(AL, E, WGSize[i], i,
2846 S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2847 << AL << E->getSourceRange();
2856 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2859 WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
2862 static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
2863 if (!AL.hasParsedType()) {
2864 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2869 QualType ParmType = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
2875 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
2881 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2886 D->addAttr(::new (S.Context) VecTypeHintAttr(S.Context, AL, ParmTSI));
2930 static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2935 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2941 SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
2952 static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2956 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2965 D->addAttr(::new (S.Context) CodeModelAttr(S.Context, AL, CM));
3000 static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3003 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
3009 S.Diag(AL.getLoc(),
3017 if (CodeSegAttr *CSA = S.mergeCodeSegAttr(D, AL, Str))
3155 static void handleTargetVersionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3158 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3162 ::new (S.Context) TargetVersionAttr(S.Context, AL, Str);
3166 static void handleTargetAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3169 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3173 TargetAttr *NewAttr = ::new (S.Context) TargetAttr(S.Context, AL, Str);
3324 static void handleTargetClonesAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3332 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3336 if (checkAttrMutualExclusion<TargetClonesAttr>(S, D, AL))
3343 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
3346 if (!S.checkStringLiteralArgumentAttr(AL, I, CurStr, &LiteralLoc) ||
3349 cast<StringLiteral>(AL.getArgAsExpr(I)->IgnoreParenCasts()), D,
3356 if (HasCommas && AL.getNumArgs() > 1)
3357 S.Diag(AL.getLoc(), diag::warn_target_clone_mixed_values);
3366 S.Diag(AL.getLoc(), diag::err_target_clone_must_have_default);
3387 TargetClonesAttr(S.Context, AL, Strings.data(), Strings.size());
3391 static void handleMinVectorWidthAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3392 Expr *E = AL.getArgAsExpr(0);
3394 if (!S.checkUInt32Argument(AL, E, VecWidth)) {
3395 AL.setInvalid();
3401 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
3405 D->addAttr(::new (S.Context) MinVectorWidthAttr(S.Context, AL, VecWidth));
3408 static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3409 Expr *E = AL.getArgAsExpr(0);
3484 D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD));
3488 const ParsedAttr &AL) {
3489 if (!AL.isArgIdent(0)) {
3490 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3491 << AL << 0 << AANT_ArgumentIdentifier;
3496 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3499 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3504 EnumExtensibilityAttr(S.Context, AL, ExtensibilityKind));
3509 static void handleFormatArgAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3510 const Expr *IdxExpr = AL.getArgAsExpr(0);
3512 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, IdxExpr, Idx))
3522 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3538 S.Diag(AL.getLoc(), diag::err_format_attribute_result_not)
3544 D->addAttr(::new (S.Context) FormatArgAttr(S.Context, AL, Idx));
3579 static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3581 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
3586 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported);
3591 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3592 AL.setInvalid();
3599 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3600 AL.setInvalid();
3604 Expr *E = AL.getArgAsExpr(0);
3606 if (!S.checkUInt32Argument(AL, E, prioritynum)) {
3607 AL.setInvalid();
3615 !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
3616 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
3617 << E->getSourceRange() << AL << 101 << 65535;
3618 AL.setInvalid();
3621 D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
3670 static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3671 if (!AL.isArgIdent(0)) {
3672 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3673 << AL << 1 << AANT_ArgumentIdentifier;
3682 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3697 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
3698 << AL << II->getName();
3703 Expr *IdxExpr = AL.getArgAsExpr(1);
3705 if (!S.checkUInt32Argument(AL, IdxExpr, Idx, 2))
3709 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3710 << AL << 2 << IdxExpr->getSourceRange();
3719 S.Diag(AL.getLoc(),
3733 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3739 Expr *FirstArgExpr = AL.getArgAsExpr(2);
3741 if (!S.checkUInt32Argument(AL, FirstArgExpr, FirstArg, 3))
3749 S.Diag(AL.getLoc(), diag::err_format_strftime_third_parameter)
3758 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3759 << AL << 3 << FirstArgExpr->getSourceRange()
3766 S.Diag(D->getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
3771 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3772 << AL << 3 << FirstArgExpr->getSourceRange();
3778 FormatAttr *NewAttr = S.mergeFormatAttr(D, AL, II, Idx, FirstArg);
3784 static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3786 if (AL.getNumArgs() == 0) {
3787 S.Diag(AL.getLoc(), diag::err_callback_attribute_no_callee)
3788 << AL.getRange();
3810 for (unsigned I = 0, E = AL.getNumArgs(); I < E; ++I) {
3814 if (AL.isArgIdent(I)) {
3815 IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
3818 S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown)
3825 } else if (AL.isArgExpr(I)) {
3826 Expr *IdxExpr = AL.getArgAsExpr(I);
3829 if (!S.checkUInt32Argument(AL, IdxExpr, (uint32_t &)ArgIdx, I + 1,
3831 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3832 << AL << (I + 1) << IdxExpr->getSourceRange();
3838 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3839 << AL << (I + 1) << IdxExpr->getSourceRange();
3849 S.Diag(AL.getLoc(), diag::err_callback_implicit_this_not_available)
3867 S.Diag(AL.getLoc(), diag::err_callback_attribute_invalid_callee)
3868 << AL.getRange();
3878 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3879 << AL.getRange();
3890 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3891 << AL.getRange();
3896 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
3897 << AL << (unsigned)(EncodingIndices.size() - 1);
3902 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
3903 << AL << (unsigned)(EncodingIndices.size() - 1);
3908 S.Diag(AL.getLoc(), diag::err_callback_callee_is_variadic) << AL.getRange();
3914 S.Diag(AL.getLoc(), diag::err_callback_attribute_multiple) << AL.getRange();
3919 S.Context, AL, EncodingIndices.data(), EncodingIndices.size()));
3922 LifetimeCaptureByAttr *Sema::ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
3925 if (AL.getNumArgs() == 0) {
3926 Diag(AL.getLoc(), diag::err_capture_by_attribute_no_entity)
3927 << AL.getRange();
3930 unsigned N = AL.getNumArgs();
3937 if (AL.isArgExpr(I)) {
3938 Expr *E = AL.getArgAsExpr(I);
3944 assert(AL.isArgIdent(I));
3945 IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
3958 LifetimeCaptureByAttr::Create(Context, FakeParamIndices.data(), N, AL);
3964 const ParsedAttr &AL) {
3967 S.Diag(AL.getLoc(), diag::err_capture_by_attribute_multiple)
3968 << AL.getRange();
3973 auto *CaptureByAttr = S.ParseLifetimeCaptureByAttr(AL, PVD->getName());
4043 static void handleCalledOnceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4048 S.Diag(AL.getLoc(), diag::err_called_once_attribute_wrong_type);
4052 D->addAttr(::new (S.Context) CalledOnceAttr(S.Context, AL));
4055 static void handleTransparentUnionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4065 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
4066 << AL << AL.isRegularKeywordAttribute() << ExpectedUnion;
4072 S.Diag(AL.getLoc(),
4080 S.Diag(AL.getLoc(), diag::warn_transparent_union_attribute_zero_fields);
4123 RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL));
4126 static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4127 auto *Attr = S.CreateAnnotationAttr(AL);
4133 static void handleAlignValueAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4134 S.AddAlignValueAttr(D, AL, AL.getArgAsExpr(0));
4177 static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4178 if (AL.hasParsedType()) {
4179 const ParsedType &TypeArg = AL.getTypeArg();
4183 if (AL.isPackExpansion() &&
4185 S.Diag(AL.getEllipsisLoc(),
4190 if (!AL.isPackExpansion() &&
4195 S.AddAlignedAttr(D, AL, TInfo, AL.isPackExpansion());
4200 if (AL.getNumArgs() > 1) {
4201 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
4205 if (AL.getNumArgs() == 0) {
4206 D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr));
4210 Expr *E = AL.getArgAsExpr(0);
4211 if (AL.isPackExpansion() && !E->containsUnexpandedParameterPack()) {
4212 S.Diag(AL.getEllipsisLoc(),
4217 if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))
4220 S.AddAlignedAttr(D, AL, E, AL.isPackExpansion());
4298 // FIXME: Cache the number on the AL object?
4550 static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4553 if (!AL.isArgIdent(0)) {
4554 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
4555 << AL << AANT_ArgumentIdentifier;
4559 IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident;
4561 S.AddModeAttr(D, AL, Name);
4709 static void handleNoDebugAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4710 D->addAttr(::new (S.Context) NoDebugAttr(S.Context, AL));
4729 const ParsedAttr &AL) {
4734 Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
4735 << AL << AL.isRegularKeywordAttribute()
4747 return ::new (Context) InternalLinkageAttr(Context, AL);
4750 Sema::mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL) {
4755 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4756 << &AL << AL.isRegularKeywordAttribute()
4768 return ::new (Context) InternalLinkageAttr(Context, AL);
4803 static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4805 S.mergeAlwaysInlineAttr(D, AL, AL.getAttrName()))
4809 static void handleMinSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4810 if (MinSizeAttr *MinSize = S.mergeMinSizeAttr(D, AL))
4814 static void handleOptimizeNoneAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4815 if (OptimizeNoneAttr *Optnone = S.mergeOptimizeNoneAttr(D, AL))
4819 static void handleConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4822 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4832 D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL));
4835 static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4841 S.Diag(AL.getLoc(), diag::err_cuda_extern_shared) << VD;
4845 S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
4848 D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
4851 static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4875 if (AL.getKind() == ParsedAttr::AT_NVPTXKernel)
4876 D->addAttr(::new (S.Context) NVPTXKernelAttr(S.Context, AL));
4878 D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL));
4887 static void handleDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4890 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4900 D->addAttr(::new (S.Context) CUDADeviceAttr(S.Context, AL));
4903 static void handleManagedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4906 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4911 D->addAttr(::new (S.Context) HIPManagedAttr(S.Context, AL));
4916 static void handleGridConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4922 D->addAttr(::new (S.Context) CUDAGridConstantAttr(S.Context, AL));
4925 static void handleGNUInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4928 S.Diag(AL.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4933 S.Diag(AL.getLoc(), diag::warn_gnu_inline_cplusplus_without_extern);
4935 D->addAttr(::new (S.Context) GNUInlineAttr(S.Context, AL));
4938 static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4941 // Diagnostic is emitted elsewhere: here we store the (valid) AL
4945 AL, CC, /*FD*/ nullptr,
4950 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
4951 << AL << AL.isRegularKeywordAttribute() << ExpectedFunctionOrMethod;
4955 switch (AL.getKind()) {
4957 D->addAttr(::new (S.Context) FastCallAttr(S.Context, AL));
4960 D->addAttr(::new (S.Context) StdCallAttr(S.Context, AL));
4963 D->addAttr(::new (S.Context) ThisCallAttr(S.Context, AL));
4966 D->addAttr(::new (S.Context) CDeclAttr(S.Context, AL));
4969 D->addAttr(::new (S.Context) PascalAttr(S.Context, AL));
4972 D->addAttr(::new (S.Context) SwiftCallAttr(S.Context, AL));
4975 D->addAttr(::new (S.Context) SwiftAsyncCallAttr(S.Context, AL));
4978 D->addAttr(::new (S.Context) VectorCallAttr(S.Context, AL));
4981 D->addAttr(::new (S.Context) MSABIAttr(S.Context, AL));
4984 D->addAttr(::new (S.Context) SysVABIAttr(S.Context, AL));
4987 D->addAttr(::new (S.Context) RegCallAttr(S.Context, AL));
5002 D->addAttr(::new (S.Context) PcsAttr(S.Context, AL, PCS));
5006 D->addAttr(::new (S.Context) AArch64VectorPcsAttr(S.Context, AL));
5009 D->addAttr(::new (S.Context) AArch64SVEPcsAttr(S.Context, AL));
5012 D->addAttr(::new (S.Context) AMDGPUKernelCallAttr(S.Context, AL));
5015 D->addAttr(::new (S.Context) IntelOclBiccAttr(S.Context, AL));
5018 D->addAttr(::new (S.Context) PreserveMostAttr(S.Context, AL));
5021 D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL));
5024 D->addAttr(::new (S.Context) M68kRTDAttr(S.Context, AL));
5027 D->addAttr(::new (S.Context) PreserveNoneAttr(S.Context, AL));
5030 D->addAttr(::new (S.Context) RISCVVectorCCAttr(S.Context, AL));
5037 static void handleSuppressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5038 if (AL.getAttributeSpellingListIndex() == SuppressAttr::CXX11_gsl_suppress) {
5040 if (!AL.checkAtLeastNumArgs(S, 1))
5045 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
5048 if (!S.checkStringLiteralArgumentAttr(AL, I, RuleName, nullptr))
5054 SuppressAttr(S.Context, AL, DiagnosticIdentifiers.data(),
5058 static void handleLifetimeCategoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5061 if (AL.hasParsedType()) {
5062 ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
5071 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)
5072 << SelectIdx << AL;
5083 if (AL.getKind() == ParsedAttr::AT_Owner) {
5084 if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
5091 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
5092 << AL << OAttr
5093 << (AL.isRegularKeywordAttribute() ||
5100 Redecl->addAttr(::new (S.Context) OwnerAttr(S.Context, AL, DerefTypeLoc));
5103 if (checkAttrMutualExclusion<OwnerAttr>(S, D, AL))
5110 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
5111 << AL << PAttr
5112 << (AL.isRegularKeywordAttribute() ||
5120 PointerAttr(S.Context, AL, DerefTypeLoc));
5125 static void handleRandomizeLayoutAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5126 if (checkAttrMutualExclusion<NoRandomizeLayoutAttr>(S, D, AL))
5129 D->addAttr(::new (S.Context) RandomizeLayoutAttr(S.Context, AL));
5133 const ParsedAttr &AL) {
5134 if (checkAttrMutualExclusion<RandomizeLayoutAttr>(S, D, AL))
5137 D->addAttr(::new (S.Context) NoRandomizeLayoutAttr(S.Context, AL));
5315 bool Sema::CheckRegparmAttr(const ParsedAttr &AL, unsigned &numParams) {
5316 if (AL.isInvalid())
5319 if (!AL.checkExactlyNumArgs(*this, 1)) {
5320 AL.setInvalid();
5325 Expr *NumParamsExpr = AL.getArgAsExpr(0);
5326 if (!checkUInt32Argument(AL, NumParamsExpr, NP)) {
5327 AL.setInvalid();
5332 Diag(AL.getLoc(), diag::err_attribute_regparm_wrong_platform)
5334 AL.setInvalid();
5340 Diag(AL.getLoc(), diag::err_attribute_regparm_invalid_number)
5342 AL.setInvalid();
5362 const CUDALaunchBoundsAttr &AL,
5375 << &AL << Idx << AANT_ArgumentIntegerConstant << E->getSourceRange();
5386 << &AL << Idx << E->getSourceRange();
5438 static void handleLaunchBoundsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5439 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 3))
5442 S.AddLaunchBoundsAttr(D, AL, AL.getArgAsExpr(0),
5443 AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr,
5444 AL.getNumArgs() > 2 ? AL.getArgAsExpr(2) : nullptr);
5448 const ParsedAttr &AL) {
5449 if (!AL.isArgIdent(0)) {
5450 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5451 << AL << /* arg num = */ 1 << AANT_ArgumentIdentifier;
5456 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 2, AL.getArgAsExpr(1),
5461 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 3, AL.getArgAsExpr(2),
5465 bool IsPointer = AL.getAttrName()->getName() == "pointer_with_type_tag";
5471 S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0;
5475 S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx,
5480 const ParsedAttr &AL) {
5481 if (!AL.isArgIdent(0)) {
5482 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5483 << AL << 1 << AANT_ArgumentIdentifier;
5487 if (!AL.checkExactlyNumArgs(S, 1))
5491 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
5492 << AL << AL.isRegularKeywordAttribute() << ExpectedVariable;
5496 IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident;
5498 S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc);
5502 S.Context, AL, PointerKind, MatchingCTypeLoc, AL.getLayoutCompatible(),
5503 AL.getMustBeNull()));
5506 static void handleXRayLogArgsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5509 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, AL.getArgAsExpr(0),
5516 XRayLogArgsAttr(S.Context, AL, ArgCount.getSourceIndex()));
5520 const ParsedAttr &AL) {
5522 S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
5526 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Count, 0, true))
5528 if (AL.getNumArgs() == 2) {
5529 Expr *Arg = AL.getArgAsExpr(1);
5530 if (!S.checkUInt32Argument(AL, Arg, Offset, 1, true))
5533 S.Diag(S.getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
5534 << &AL << 0 << Count << Arg->getBeginLoc();
5539 PatchableFunctionEntryAttr(S.Context, AL, Count, Offset));
5542 static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5543 if (!AL.isArgIdent(0)) {
5544 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5545 << AL << 1 << AANT_ArgumentIdentifier;
5549 IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident;
5562 S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias) << AL;
5566 D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident));
5569 static void handleNullableTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5570 if (AL.isUsedAsTypeAttr())
5575 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
5576 << AL << AL.isRegularKeywordAttribute() << ExpectedClass;
5580 handleSimpleAttribute<TypeNullableAttr>(S, D, AL);
5583 static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5584 if (!AL.hasParsedType()) {
5585 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
5590 QualType QT = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
5595 D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
5617 static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5619 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5620 << AL << AttributeLangSupport::C;
5626 if (!S.checkStringLiteralArgumentAttr(AL, 0, OrigStrRef, &LiteralLoc))
5669 if (AL.isMicrosoftAttribute()) // Check for [uuid(...)] spelling.
5670 S.Diag(AL.getLoc(), diag::warn_atl_uuid_deprecated);
5672 UuidAttr *UA = S.mergeUuidAttr(D, AL, OrigStrRef, Guid);
5677 static void handleMSInheritanceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5679 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5680 << AL << AttributeLangSupport::C;
5684 D, AL, /*BestCase=*/true, (MSInheritanceModel)AL.getSemanticSpelling());
5691 static void handleDeclspecThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5694 S.Diag(AL.getLoc(), diag::err_thread_unsupported);
5698 S.Diag(AL.getLoc(), diag::err_declspec_thread_on_thread_variable);
5702 S.Diag(AL.getLoc(), diag::err_thread_non_global) << "__declspec(thread)";
5705 D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
5708 static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5710 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
5711 << AL << AL.getRange();
5716 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied)
5722 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied)
5727 D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
5730 static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5732 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
5734 if (!S.checkStringLiteralArgumentAttr(AL, I, Tag))
5741 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5745 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5748 if (AL.getNumArgs() == 0)
5750 } else if (!AL.checkAtLeastNumArgs(S, 1))
5758 AbiTagAttr(S.Context, AL, Tags.data(), Tags.size()));
5769 static void handleBTFDeclTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5771 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
5776 D->addAttr(::new (S.Context) BTFDeclTagAttr(S.Context, AL, Str));
5779 BTFDeclTagAttr *Sema::mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL) {
5780 if (hasBTFDeclTagAttr(D, AL.getBTFDeclTag()))
5782 return ::new (Context) BTFDeclTagAttr(Context, AL, AL.getBTFDeclTag());
5785 static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5789 S.MSP430().handleInterruptAttr(D, AL);
5793 S.MIPS().handleInterruptAttr(D, AL);
5796 S.M68k().handleInterruptAttr(D, AL);
5800 S.X86().handleAnyInterruptAttr(D, AL);
5803 S.AVR().handleInterruptAttr(D, AL);
5807 S.RISCV().handleInterruptAttr(D, AL);
5810 S.ARM().handleInterruptAttr(D, AL);
5815 static void handleLayoutVersion(Sema &S, Decl *D, const ParsedAttr &AL) {
5817 Expr *VersionExpr = static_cast<Expr *>(AL.getArgAsExpr(0));
5818 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Version))
5823 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
5824 << AL << Version << VersionExpr->getSourceRange();
5833 D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version));
5929 static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5940 if (AL.getKind() == ParsedAttr::AT_Capability &&
5941 !S.checkStringLiteralArgumentAttr(AL, 0, N, &LiteralLoc))
5944 D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N));
5947 static void handleAssertCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5949 if (!checkLockFunAttrCommon(S, D, AL, Args))
5953 AssertCapabilityAttr(S.Context, AL, Args.data(), Args.size()));
5957 const ParsedAttr &AL) {
5959 ParmDecl && !checkFunParamsAreScopedLockable(S, ParmDecl, AL))
5963 if (!checkLockFunAttrCommon(S, D, AL, Args))
5966 D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(),
5971 const ParsedAttr &AL) {
5973 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
5977 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
5981 const ParsedAttr &AL) {
5983 ParmDecl && !checkFunParamsAreScopedLockable(S, ParmDecl, AL))
5987 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, true);
5989 D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(),
5994 const ParsedAttr &AL) {
5996 ParmDecl && !checkFunParamsAreScopedLockable(S, ParmDecl, AL))
5999 if (!AL.checkAtLeastNumArgs(S, 1))
6004 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
6009 RequiresCapabilityAttr(S.Context, AL, Args.data(), Args.size());
6014 static void handleDeprecatedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6017 S.Diag(AL.getLoc(), diag::warn_deprecated_anonymous_namespace);
6025 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using)
6026 << AL;
6032 if (AL.isArgExpr(0) && AL.getArgAsExpr(0) &&
6033 !S.checkStringLiteralArgumentAttr(AL, 0, Str))
6037 if (AL.isDeclspecAttribute() || AL.isStandardAttributeSyntax())
6038 AL.checkAtMostNumArgs(S, 1);
6039 else if (AL.isArgExpr(1) && AL.getArgAsExpr(1) &&
6040 !S.checkStringLiteralArgumentAttr(AL, 1, Replacement))
6043 if (!S.getLangOpts().CPlusPlus14 && AL.isCXX11Attribute() && !AL.isGNUScope())
6044 S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL;
6046 D->addAttr(::new (S.Context) DeprecatedAttr(S.Context, AL, Str, Replacement));
6060 static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6061 if (!AL.checkAtLeastNumArgs(S, 1))
6066 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
6070 if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, &LiteralLoc))
6079 << AL << SanitizerName;
6083 D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(),
6088 const ParsedAttr &AL) {
6089 StringRef AttrName = AL.getAttrName()->getName();
6098 << AL << AL.isRegularKeywordAttribute() << ExpectedFunction;
6109 if (AL.isStandardAttributeSyntax())
6112 AttributeCommonInfo Info = AL;
6118 static void handleInternalLinkageAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6119 if (InternalLinkageAttr *Internal = S.mergeInternalLinkageAttr(D, AL))
6123 static void handleZeroCallUsedRegsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6127 if (!S.checkStringLiteralArgumentAttr(AL, 0, KindStr, &LiteralLoc))
6133 << AL << KindStr;
6138 D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
6141 static void handleCountedByAttrField(Sema &S, Decl *D, const ParsedAttr &AL) {
6145 auto *CountExpr = AL.getArgAsExpr(0);
6151 switch (AL.getKind()) {
6181 const ParsedAttr &AL) {
6184 if (!S.checkStringLiteralArgumentAttr(AL, 0, KindStr, &LiteralLoc))
6190 << AL << KindStr;
6197 D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
6201 const ParsedAttr &AL) {
6203 handleSimpleAttribute<AvailableOnlyInDefaultEvalMethodAttr>(S, D, AL);
6206 static void handleNoMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6209 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_non_function_pointer)
6210 << AL << VDecl;
6213 D->addAttr(NoMergeAttr::Create(S.Context, AL));
6216 static void handleNoUniqueAddressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6217 D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL));
6233 static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6236 D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
6239 static void handleMIGServerRoutineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6258 handleSimpleAttribute<MIGServerRoutineAttr>(S, D, AL);
6261 static void handleMSAllocatorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6266 S.Diag(AL.getLoc(), diag::warn_declspec_allocator_nonpointer)
6267 << AL.getRange() << RetTy;
6272 handleSimpleAttribute<MSAllocatorAttr>(S, D, AL);
6275 static void handleAcquireHandleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6276 if (AL.isUsedAsTypeAttr())
6281 S.Diag(AL.getLoc(), diag::err_attribute_output_parameter)
6282 << AL.getRange();
6287 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6289 D->addAttr(AcquireHandleAttr::Create(S.Context, Argument, AL));
6293 static void handleHandleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6295 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6297 D->addAttr(Attr::Create(S.Context, Argument, AL));
6301 static void handleUnsafeBufferUsage(Sema &S, Decl *D, const ParsedAttr &AL) {
6302 D->addAttr(Attr::Create(S.Context, AL));
6305 static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6308 if (!AL.isArgIdent(0)) {
6309 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6310 << AL << AANT_ArgumentIdentifier;
6315 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
6317 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
6321 D->addAttr(::new (S.Context) CFGuardAttr(S.Context, AL, Arg));
6336 static void handleEnforceTCBAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6338 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6346 S.Diag(AL.getLoc(), diag::err_tcb_conflicting_attributes)
6347 << AL.getAttrName()->getName() << ConflictingAttr->getAttrName()->getName()
6357 D->addAttr(AttrTy::Create(S.Context, Argument, AL));
6361 static AttrTy *mergeEnforceTCBAttrImpl(Sema &S, Decl *D, const AttrTy &AL) {
6363 StringRef TCBName = AL.getTCBName();
6368 << AL.getAttrName()->getName() << TCBName;
6371 S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
6379 return ::new(Context) AttrTy(Context, AL, AL.getTCBName());
6382 EnforceTCBAttr *Sema::mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL) {
6384 *this, D, AL);
6388 Decl *D, const EnforceTCBLeafAttr &AL) {
6390 *this, D, AL);
6394 const ParsedAttr &AL) {
6396 const uint32_t NumArgs = AL.getNumArgs();
6398 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6399 AL.setInvalid();
6403 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL;
6404 AL.setInvalid();
6409 S.Diag(AL.getLoc(), diag::err_duplicated_vtable_pointer_auth) << Decl;
6410 AL.setInvalid();
6414 if (AL.isArgIdent(0)) {
6415 IdentifierLoc *IL = AL.getArgAsIdent(0);
6419 AL.setInvalid();
6423 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 0;
6424 AL.setInvalid();
6427 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6428 << AL << AANT_ArgumentIdentifier;
6434 if (AL.getNumArgs() > 1) {
6435 if (AL.isArgIdent(1)) {
6436 IdentifierLoc *IL = AL.getArgAsIdent(1);
6441 AL.setInvalid();
6447 AL.setInvalid();
6450 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6451 << AL << AANT_ArgumentIdentifier;
6457 if (AL.getNumArgs() > 2) {
6458 if (AL.isArgIdent(2)) {
6459 IdentifierLoc *IL = AL.getArgAsIdent(2);
6463 AL.setInvalid();
6467 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 2;
6468 AL.setInvalid();
6471 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6472 << AL << AANT_ArgumentIdentifier;
6479 S.Diag(AL.getLoc(), diag::err_missing_custom_discrimination) << AL << 4;
6480 AL.setInvalid();
6484 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6485 AL.setInvalid();
6488 if (!AL.isArgExpr(3) || !S.checkUInt32Argument(AL, AL.getArgAsExpr(3),
6490 S.Diag(AL.getLoc(), diag::err_invalid_custom_discrimination);
6491 AL.setInvalid();
6494 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 3;
6495 AL.setInvalid();
6499 S.Context, AL, KeyType, AddressDiversityMode, ED,
6509 static bool MustDelayAttributeArguments(const ParsedAttr &AL) {
6511 if (!AL.acceptsExprPack())
6514 bool AttrHasVariadicArg = AL.hasVariadicArg();
6515 unsigned AttrNumArgs = AL.getNumArgMembers();
6516 for (size_t I = 0; I < std::min(AL.getNumArgs(), AttrNumArgs); ++I) {
6522 Expr *E = AL.getArgAsExpr(I);
6523 bool ArgMemberCanHoldExpr = AL.isParamExpr(I);
6542 ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
6544 if (AL.isInvalid() || AL.getKind() == ParsedAttr::IgnoredAttribute)
6553 if ((S.getLangOpts().CPlusPlus ? AL.isCXX11Attribute()
6554 : AL.isC23Attribute()) &&
6561 if (AL.getKind() == ParsedAttr::UnknownAttribute ||
6562 !AL.existsInTarget(S.Context.getTargetInfo())) {
6563 S.Diag(AL.getLoc(),
6564 AL.isRegularKeywordAttribute()
6566 : AL.isDeclspecAttribute()
6569 << AL << AL.getRange();
6574 bool MustDelayArgs = MustDelayAttributeArguments(AL);
6577 if (S.checkCommonAttributeFeatures(D, AL, MustDelayArgs))
6581 AL.handleAttrWithDelayedArgs(S, D);
6585 switch (AL.getKind()) {
6587 if (AL.getInfo().handleDeclAttribute(S, D, AL) != ParsedAttrInfo::NotHandled)
6589 if (!AL.isStmtAttr()) {
6590 assert(AL.isTypeAttr() && "Non-type attribute not handled");
6592 if (AL.isTypeAttr()) {
6595 if (!AL.isStandardAttributeSyntax() && !AL.isRegularKeywordAttribute()) {
6610 if (AL.slidesFromDeclToDeclSpecLegacyBehavior() &&
6615 if (AL.isClangScope()) {
6616 S.Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl)
6617 << AL << D->getLocation();
6625 if (AL.getKind() == ParsedAttr::AT_Regparm) {
6638 if (AL.getKind() == ParsedAttr::AT_VectorSize) {
6648 if (AL.getKind() == ParsedAttr::AT_NoDeref) {
6659 S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)
6660 << AL << AL.isRegularKeywordAttribute() << D->getLocation();
6663 handleInterruptAttr(S, D, AL);
6666 S.X86().handleForceAlignArgPointerAttr(D, AL);
6669 handleSimpleAttribute<ReadOnlyPlacementAttr>(S, D, AL);
6673 handleDLLAttr(S, D, AL);
6676 S.AMDGPU().handleAMDGPUFlatWorkGroupSizeAttr(D, AL);
6679 S.AMDGPU().handleAMDGPUWavesPerEUAttr(D, AL);
6682 S.AMDGPU().handleAMDGPUNumSGPRAttr(D, AL);
6685 S.AMDGPU().handleAMDGPUNumVGPRAttr(D, AL);
6688 S.AMDGPU().handleAMDGPUMaxNumWorkGroupsAttr(D, AL);
6691 S.AVR().handleSignalAttr(D, AL);
6694 S.BPF().handlePreserveAccessIndexAttr(D, AL);
6697 handleSimpleAttribute<BPFPreserveStaticOffsetAttr>(S, D, AL);
6700 handleBTFDeclTagAttr(S, D, AL);
6703 S.Wasm().handleWebAssemblyExportNameAttr(D, AL);
6706 S.Wasm().handleWebAssemblyImportModuleAttr(D, AL);
6709 S.Wasm().handleWebAssemblyImportNameAttr(D, AL);
6712 S.ObjC().handleIBOutlet(D, AL);
6715 S.ObjC().handleIBOutletCollection(D, AL);
6718 handleIFuncAttr(S, D, AL);
6721 handleAliasAttr(S, D, AL);
6724 handleAlignedAttr(S, D, AL);
6727 handleAlignValueAttr(S, D, AL);
6730 handleAllocSizeAttr(S, D, AL);
6733 handleAlwaysInlineAttr(S, D, AL);
6736 handleAnalyzerNoReturnAttr(S, D, AL);
6739 handleTLSModelAttr(S, D, AL);
6742 handleAnnotateAttr(S, D, AL);
6745 handleAvailabilityAttr(S, D, AL);
6748 handleDependencyAttr(S, scope, D, AL);
6752 handleCPUSpecificAttr(S, D, AL);
6755 handleCommonAttr(S, D, AL);
6758 handleConstantAttr(S, D, AL);
6761 handlePassObjectSizeAttr(S, D, AL);
6764 handleConstructorAttr(S, D, AL);
6767 handleDeprecatedAttr(S, D, AL);
6770 handleDestructorAttr(S, D, AL);
6773 handleEnableIfAttr(S, D, AL);
6776 handleErrorAttr(S, D, AL);
6779 handleExcludeFromExplicitInstantiationAttr(S, D, AL);
6782 handleDiagnoseIfAttr(S, D, AL);
6785 handleDiagnoseAsBuiltinAttr(S, D, AL);
6788 handleNoBuiltinAttr(S, D, AL);
6791 handleExtVectorTypeAttr(S, D, AL);
6794 handleExternalSourceSymbolAttr(S, D, AL);
6797 handleMinSizeAttr(S, D, AL);
6800 handleOptimizeNoneAttr(S, D, AL);
6803 handleEnumExtensibilityAttr(S, D, AL);
6806 S.SYCL().handleKernelAttr(D, AL);
6809 S.SYCL().handleKernelEntryPointAttr(D, AL);
6812 handleSimpleAttribute<SYCLSpecialClassAttr>(S, D, AL);
6815 handleFormatAttr(S, D, AL);
6818 handleFormatArgAttr(S, D, AL);
6821 handleCallbackAttr(S, D, AL);
6824 handleLifetimeCaptureByAttr(S, D, AL);
6827 handleCalledOnceAttr(S, D, AL);
6831 handleGlobalAttr(S, D, AL);
6834 handleDeviceAttr(S, D, AL);
6837 handleGridConstantAttr(S, D, AL);
6840 handleManagedAttr(S, D, AL);
6843 handleGNUInlineAttr(S, D, AL);
6846 handleLaunchBoundsAttr(S, D, AL);
6849 handleRestrictAttr(S, D, AL);
6852 handleModeAttr(S, D, AL);
6856 handleNonNullAttrParameter(S, PVD, AL);
6858 handleNonNullAttr(S, D, AL);
6861 handleReturnsNonNullAttr(S, D, AL);
6864 handleNoEscapeAttr(S, D, AL);
6867 handleSimpleAttribute<MaybeUndefAttr>(S, D, AL);
6870 handleAssumeAlignedAttr(S, D, AL);
6873 handleAllocAlignAttr(S, D, AL);
6876 handleOwnershipAttr(S, D, AL);
6879 handleNakedAttr(S, D, AL);
6882 handleNoReturnAttr(S, D, AL);
6885 handleStandardNoReturnAttr(S, D, AL);
6888 handleNoCfCheckAttr(S, D, AL);
6891 if (!AL.isUsedAsTypeAttr())
6892 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6895 handleSharedAttr(S, D, AL);
6898 handleVecReturnAttr(S, D, AL);
6901 S.ObjC().handleOwnershipAttr(D, AL);
6904 S.ObjC().handlePreciseLifetimeAttr(D, AL);
6907 S.ObjC().handleReturnsInnerPointerAttr(D, AL);
6910 S.ObjC().handleRequiresSuperAttr(D, AL);
6913 S.ObjC().handleBridgeAttr(D, AL);
6916 S.ObjC().handleBridgeMutableAttr(D, AL);
6919 S.ObjC().handleBridgeRelatedAttr(D, AL);
6922 S.ObjC().handleDesignatedInitializer(D, AL);
6925 S.ObjC().handleRuntimeName(D, AL);
6928 S.ObjC().handleBoxable(D, AL);
6931 S.ObjC().handleNSErrorDomain(D, AL);
6936 S.ObjC().AddXConsumedAttr(D, AL,
6937 S.ObjC().parsedAttrToRetainOwnershipKind(AL),
6942 S, D, AL, S.ObjC().isValidOSObjectOutParameter(D),
6944 /*Extra Args=*/AL, /*pointer-to-OSObject-pointer*/ 3, AL.getRange());
6948 S, D, AL, S.ObjC().isValidOSObjectOutParameter(D),
6950 /*Extra Args=*/AL, /*pointer-to-OSObject-poointer*/ 3, AL.getRange());
6959 S.ObjC().handleXReturnsXRetainedAttr(D, AL);
6962 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
6965 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
6968 S.OpenCL().handleSubGroupSize(D, AL);
6971 handleVecTypeHint(S, D, AL);
6974 handleInitPriorityAttr(S, D, AL);
6977 handlePackedAttr(S, D, AL);
6980 handlePreferredName(S, D, AL);
6983 handleNoSpecializations(S, D, AL);
6986 handleSectionAttr(S, D, AL);
6989 handleCodeModelAttr(S, D, AL);
6992 handleRandomizeLayoutAttr(S, D, AL);
6995 handleNoRandomizeLayoutAttr(S, D, AL);
6998 handleCodeSegAttr(S, D, AL);
7001 handleTargetAttr(S, D, AL);
7004 handleTargetVersionAttr(S, D, AL);
7007 handleTargetClonesAttr(S, D, AL);
7010 handleMinVectorWidthAttr(S, D, AL);
7013 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
7016 S.OpenMP().handleOMPAssumeAttr(D, AL);
7019 S.ObjC().handleDirectAttr(D, AL);
7022 S.ObjC().handleDirectMembersAttr(D, AL);
7023 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
7026 S.ObjC().handleSuppresProtocolAttr(D, AL);
7029 handleUnusedAttr(S, D, AL);
7032 handleVisibilityAttr(S, D, AL, false);
7035 handleVisibilityAttr(S, D, AL, true);
7038 handleWarnUnusedResult(S, D, AL);
7041 handleWeakRefAttr(S, D, AL);
7044 handleWeakImportAttr(S, D, AL);
7047 handleTransparentUnionAttr(S, D, AL);
7050 S.ObjC().handleMethodFamilyAttr(D, AL);
7053 S.ObjC().handleNSObject(D, AL);
7056 S.ObjC().handleIndependentClass(D, AL);
7059 S.ObjC().handleBlocksAttr(D, AL);
7062 handleSentinelAttr(S, D, AL);
7065 handleCleanupAttr(S, D, AL);
7068 handleNoDebugAttr(S, D, AL);
7071 S.ARM().handleCmseNSEntryAttr(D, AL);
7094 handleCallConvAttr(S, D, AL);
7097 handleSuppressAttr(S, D, AL);
7101 handleLifetimeCategoryAttr(S, D, AL);
7104 S.OpenCL().handleAccessAttr(D, AL);
7107 S.OpenCL().handleNoSVMAttr(D, AL);
7110 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftContext);
7113 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftAsyncContext);
7116 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftErrorResult);
7119 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftIndirectResult);
7122 handleInternalLinkageAttr(S, D, AL);
7125 handleZeroCallUsedRegsAttr(S, D, AL);
7128 handleFunctionReturnThunksAttr(S, D, AL);
7131 handleNoMergeAttr(S, D, AL);
7134 handleNoUniqueAddressAttr(S, D, AL);
7138 handleAvailableOnlyInDefaultEvalMethod(S, D, AL);
7145 handleCountedByAttrField(S, D, AL);
7150 handleLayoutVersion(S, D, AL);
7153 handleUuidAttr(S, D, AL);
7156 handleMSInheritanceAttr(S, D, AL);
7159 handleDeclspecThreadAttr(S, D, AL);
7162 handleMSConstexprAttr(S, D, AL);
7165 handleSimpleAttribute<HybridPatchableAttr>(S, D, AL);
7170 S.HLSL().handleNumThreadsAttr(D, AL);
7173 S.HLSL().handleWaveSizeAttr(D, AL);
7176 S.HLSL().handleSV_GroupThreadIDAttr(D, AL);
7179 S.HLSL().handleSV_GroupIDAttr(D, AL);
7182 handleSimpleAttribute<HLSLSV_GroupIndexAttr>(S, D, AL);
7185 handleSimpleAttribute<HLSLGroupSharedAddressSpaceAttr>(S, D, AL);
7188 S.HLSL().handleSV_DispatchThreadIDAttr(D, AL);
7191 S.HLSL().handlePackOffsetAttr(D, AL);
7194 S.HLSL().handleShaderAttr(D, AL);
7197 S.HLSL().handleResourceBindingAttr(D, AL);
7200 S.HLSL().handleParamModifierAttr(D, AL);
7204 handleAbiTagAttr(S, D, AL);
7207 handleCFGuardAttr(S, D, AL);
7212 handleAssertExclusiveLockAttr(S, D, AL);
7215 handleAssertSharedLockAttr(S, D, AL);
7218 handlePtGuardedVarAttr(S, D, AL);
7221 handleNoSanitizeAttr(S, D, AL);
7224 handleNoSanitizeSpecificAttr(S, D, AL);
7227 handleGuardedByAttr(S, D, AL);
7230 handlePtGuardedByAttr(S, D, AL);
7233 handleExclusiveTrylockFunctionAttr(S, D, AL);
7236 handleLockReturnedAttr(S, D, AL);
7239 handleLocksExcludedAttr(S, D, AL);
7242 handleSharedTrylockFunctionAttr(S, D, AL);
7245 handleAcquiredBeforeAttr(S, D, AL);
7248 handleAcquiredAfterAttr(S, D, AL);
7254 handleCapabilityAttr(S, D, AL);
7257 handleRequiresCapabilityAttr(S, D, AL);
7261 handleAssertCapabilityAttr(S, D, AL);
7264 handleAcquireCapabilityAttr(S, D, AL);
7267 handleReleaseCapabilityAttr(S, D, AL);
7270 handleTryAcquireCapabilityAttr(S, D, AL);
7275 handleConsumableAttr(S, D, AL);
7278 handleCallableWhenAttr(S, D, AL);
7281 handleParamTypestateAttr(S, D, AL);
7284 handleReturnTypestateAttr(S, D, AL);
7287 handleSetTypestateAttr(S, D, AL);
7290 handleTestTypestateAttr(S, D, AL);
7295 handleArgumentWithTypeTagAttr(S, D, AL);
7298 handleTypeTagForDatatypeAttr(S, D, AL);
7303 S.Swift().handleAsyncName(D, AL);
7306 S.Swift().handleAttrAttr(D, AL);
7309 S.Swift().handleBridge(D, AL);
7312 S.Swift().handleError(D, AL);
7315 S.Swift().handleName(D, AL);
7318 S.Swift().handleNewType(D, AL);
7321 S.Swift().handleAsyncAttr(D, AL);
7324 S.Swift().handleAsyncError(D, AL);
7329 handleXRayLogArgsAttr(S, D, AL);
7333 handlePatchableFunctionEntryAttr(S, D, AL);
7338 handleDestroyAttr(S, D, AL);
7342 handleUninitializedAttr(S, D, AL);
7346 S.ObjC().handleExternallyRetainedAttr(D, AL);
7350 handleMIGServerRoutineAttr(S, D, AL);
7354 handleMSAllocatorAttr(S, D, AL);
7358 S.ARM().handleBuiltinAliasAttr(D, AL);
7362 handleSimpleAttribute<ArmLocallyStreamingAttr>(S, D, AL);
7366 S.ARM().handleNewAttr(D, AL);
7370 handleAcquireHandleAttr(S, D, AL);
7374 handleHandleAttr<ReleaseHandleAttr>(S, D, AL);
7378 handleUnsafeBufferUsage<UnsafeBufferUsageAttr>(S, D, AL);
7382 handleHandleAttr<UseHandleAttr>(S, D, AL);
7386 handleEnforceTCBAttr<EnforceTCBAttr, EnforceTCBLeafAttr>(S, D, AL);
7390 handleEnforceTCBAttr<EnforceTCBLeafAttr, EnforceTCBAttr>(S, D, AL);
7394 handleBuiltinAliasAttr(S, D, AL);
7398 handlePreferredTypeAttr(S, D, AL);
7402 handleSimpleAttribute<UsingIfExistsAttr>(S, D, AL);
7406 handleNullableTypeAttr(S, D, AL);
7410 handleVTablePointerAuthentication(S, D, AL);
7428 for (const ParsedAttr &AL : AttrList)
7429 ProcessDeclAttribute(*this, S, D, AL, Options);
7500 for (const ParsedAttr &AL : AttrList)
7501 if (AL.getKind() == ParsedAttr::AT_TransparentUnion) {
7502 handleTransparentUnionAttr(*this, D, AL);
7514 for (const ParsedAttr &AL : AttrList) {
7515 if (AL.getKind() == ParsedAttr::AT_Annotate) {
7516 ProcessDeclAttribute(*this, nullptr, ASDecl, AL,
7519 Diag(AL.getLoc(), diag::err_only_annotate_after_access_spec);
7529 for (const ParsedAttr &AL : A) {
7531 if (AL.isUsedAsTypeAttr() || AL.isInvalid())
7533 if (AL.getKind() == ParsedAttr::IgnoredAttribute)
7536 if (AL.getKind() == ParsedAttr::UnknownAttribute) {
7537 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
7538 << AL << AL.getRange();
7540 S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL
7541 << AL.getRange();
7657 for (ParsedAttr &AL : Src) {
7661 if ((AL.isStandardAttributeSyntax() || AL.isAlignas()) &&
7662 AL.slidesFromDeclToDeclSpecLegacyBehavior()) {
7667 AL.diagnoseAppertainsTo(*this, D);
7669 NonSlidingAttrs.addAtEnd(&AL);