Lines Matching defs:AL

85 static unsigned getNumAttributeArgs(const ParsedAttr &AL) {
87 return AL.getNumArgs() + AL.hasParsedType();
90 SourceLocation Sema::getAttrLoc(const ParsedAttr &AL) { return AL.getLoc(); }
131 bool Sema::checkStringLiteralArgumentAttr(const ParsedAttr &AL, unsigned ArgNum,
135 if (AL.isArgIdent(ArgNum)) {
136 IdentifierLoc *Loc = AL.getArgAsIdent(ArgNum);
138 << AL << AANT_ArgumentString
148 Expr *ArgExpr = AL.getArgAsExpr(ArgNum);
155 << AL << AANT_ArgumentString;
159 return checkStringLiteralArgumentAttr(AL, ArgExpr, Str, ArgLocation);
208 const ParsedAttr &AL) {
225 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
329 const ParsedAttr &AL,
333 if (Sidx == AL.getNumArgs()) {
343 S.Diag(AL.getLoc(),
345 << AL << MD->getParent();
347 S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
348 << AL;
352 for (unsigned Idx = Sidx; Idx < AL.getNumArgs(); ++Idx) {
353 Expr *ArgExp = AL.getArgAsExpr(Idx);
372 S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL;
400 S.Diag(AL.getLoc(),
402 << AL << Idx + 1 << NumParams;
414 S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
415 << AL << ArgTy;
425 static void handlePtGuardedVarAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
426 if (!threadSafetyCheckIsPointer(S, D, AL))
429 D->addAttr(::new (S.Context) PtGuardedVarAttr(S.Context, AL));
432 static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
436 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
446 static void handleGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
448 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
451 D->addAttr(::new (S.Context) GuardedByAttr(S.Context, AL, Arg));
454 static void handlePtGuardedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
456 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
459 if (!threadSafetyCheckIsPointer(S, D, AL))
462 D->addAttr(::new (S.Context) PtGuardedByAttr(S.Context, AL, Arg));
465 static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
467 if (!AL.checkAtLeastNumArgs(S, 1))
473 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
478 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
485 static void handleAcquiredAfterAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
487 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
492 AcquiredAfterAttr(S.Context, AL, StartArg, Args.size()));
495 static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
497 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
502 AcquiredBeforeAttr(S.Context, AL, StartArg, Args.size()));
505 static bool checkLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
509 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, /*ParamIdxOk=*/true);
514 static void handleAssertSharedLockAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
516 if (!checkLockFunAttrCommon(S, D, AL, Args))
522 AssertSharedLockAttr(S.Context, AL, StartArg, Size));
526 const ParsedAttr &AL) {
528 if (!checkLockFunAttrCommon(S, D, AL, Args))
534 AssertExclusiveLockAttr(S.Context, AL, StartArg, Size));
562 static void handleAllocSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
563 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 2))
570 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL;
574 const Expr *SizeExpr = AL.getArgAsExpr(0);
577 if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNoVal, /*Idx=*/1))
579 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/0))
584 if (AL.getNumArgs() == 2) {
585 const Expr *NumberExpr = AL.getArgAsExpr(1);
588 if (!checkPositiveIntArgument(S, AL, NumberExpr, Val, /*Idx=*/2))
590 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/1))
596 AllocSizeAttr(S.Context, AL, SizeArgNo, NumberArgNo));
599 static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
601 if (!AL.checkAtLeastNumArgs(S, 1))
604 if (!isIntOrBool(AL.getArgAsExpr(0))) {
605 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
606 << AL << 1 << AANT_ArgumentIntOrBool;
611 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
617 const ParsedAttr &AL) {
619 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
623 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
627 const ParsedAttr &AL) {
629 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
633 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
636 static void handleLockReturnedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
639 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
644 D->addAttr(::new (S.Context) LockReturnedAttr(S.Context, AL, Args[0]));
647 static void handleLocksExcludedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
648 if (!AL.checkAtLeastNumArgs(S, 1))
653 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
660 LocksExcludedAttr(S.Context, AL, StartArg, Size));
663 static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL,
665 Cond = AL.getArgAsExpr(0);
673 if (!S.checkStringLiteralArgumentAttr(AL, 1, Msg))
683 S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
691 static void handleEnableIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
692 S.Diag(AL.getLoc(), diag::ext_clang_enable_if);
696 if (checkFunctionConditionAttr(S, D, AL, Cond, Msg))
697 D->addAttr(::new (S.Context) EnableIfAttr(S.Context, AL, Cond, Msg));
700 static void handleErrorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
702 if (!S.checkStringLiteralArgumentAttr(AL, 0, NewUserDiagnostic))
704 if (ErrorAttr *EA = S.mergeErrorAttr(D, AL, NewUserDiagnostic))
709 const ParsedAttr &AL) {
714 S.Diag(AL.getLoc(),
716 << AL << /*IsMember=*/!isa<CXXRecordDecl>(D);
720 ExcludeFromExplicitInstantiationAttr(S.Context, AL));
770 const ParsedAttr &AL) {
775 S.Diag(AL.getLoc(), diag::err_attribute_no_member_function) << AL;
781 auto Union = AL.getArg(Index - 1);
787 S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
791 if (!AL.isArgExpr(0))
793 auto *F = dyn_cast_if_present<DeclRefExpr>(AL.getArgAsExpr(0));
804 if (AttrFD->getNumParams() != AL.getNumArgs() - 1) {
805 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments_for)
806 << AL << AttrFD << AttrFD->getNumParams();
812 for (unsigned I = 1; I < AL.getNumArgs(); ++I) {
813 if (!AL.isArgExpr(I)) {
818 const Expr *IndexExpr = AL.getArgAsExpr(I);
821 if (!S.checkUInt32Argument(AL, IndexExpr, Index, I + 1, false))
825 S.Diag(AL.getLoc(), diag::err_attribute_bounds_for_function)
826 << AL << Index << DeclFD << DeclFD->getNumParams();
836 << AL << Index << DeclFD << T2 << I << AttrFD << T1;
844 S.Context, AL, AttrFD, Indices.data(), Indices.size()));
847 static void handleDiagnoseIfAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
848 S.Diag(AL.getLoc(), diag::ext_clang_diagnose_if);
852 if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg))
856 if (!S.checkStringLiteralArgumentAttr(AL, 2, DiagTypeStr))
861 S.Diag(AL.getArgAsExpr(2)->getBeginLoc(),
870 S.Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D)));
873 static void handleNoBuiltinAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
891 if (AL.getNumArgs() == 0)
894 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
897 if (!S.checkStringLiteralArgumentAttr(AL, I, BuiltinName, &LiteralLoc))
904 << BuiltinName << AL;
915 << AL;
920 NoBuiltinAttr(S.Context, AL, Names.data(), Names.size()));
923 static void handlePassObjectSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
925 S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
929 Expr *E = AL.getArgAsExpr(0);
931 if (!S.checkUInt32Argument(AL, E, Type, /*Idx=*/1))
939 << AL << 0 << 3 << E->getSourceRange();
948 S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
952 D->addAttr(::new (S.Context) PassObjectSizeAttr(S.Context, AL, (int)Type));
955 static void handleConsumableAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
958 if (AL.isArgIdent(0)) {
959 IdentifierLoc *IL = AL.getArgAsIdent(0);
962 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
967 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
968 << AL << AANT_ArgumentIdentifier;
972 D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState));
976 const ParsedAttr &AL) {
981 S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) << RD;
990 static void handleCallableWhenAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
991 if (!AL.checkAtLeastNumArgs(S, 1))
994 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
998 for (unsigned ArgIndex = 0; ArgIndex < AL.getNumArgs(); ++ArgIndex) {
1003 if (AL.isArgIdent(ArgIndex)) {
1004 IdentifierLoc *Ident = AL.getArgAsIdent(ArgIndex);
1008 if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc))
1014 S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1022 CallableWhenAttr(S.Context, AL, States.data(), States.size()));
1025 static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1028 if (AL.isArgIdent(0)) {
1029 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1035 << AL << StateString;
1039 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1040 << AL << AANT_ArgumentIdentifier;
1051 // S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
1056 D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
1059 static void handleReturnTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1062 if (AL.isArgIdent(0)) {
1063 IdentifierLoc *IL = AL.getArgAsIdent(0);
1066 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1071 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1072 << AL << AANT_ArgumentIdentifier;
1101 D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
1104 static void handleSetTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1105 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1109 if (AL.isArgIdent(0)) {
1110 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1113 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1118 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1119 << AL << AANT_ArgumentIdentifier;
1123 D->addAttr(::new (S.Context) SetTypestateAttr(S.Context, AL, NewState));
1126 static void handleTestTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1127 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1131 if (AL.isArgIdent(0)) {
1132 IdentifierLoc *Ident = AL.getArgAsIdent(0);
1135 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1140 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1141 << AL << AANT_ArgumentIdentifier;
1145 D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState));
1148 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1153 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1155 TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1165 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1166 << AL << FD->getType();
1168 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1172 S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield);
1174 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1178 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
1181 static void handlePreferredName(Sema &S, Decl *D, const ParsedAttr &AL) {
1186 ParsedType PT = AL.getTypeArg();
1190 TSI = S.Context.getTrivialTypeSourceInfo(T, AL.getLoc());
1206 D->addAttr(::new (S.Context) PreferredNameAttr(S.Context, AL, TSI));
1211 S.Diag(AL.getLoc(), diag::err_attribute_preferred_name_arg_invalid)
1242 static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL,
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;
1258 static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1260 for (unsigned I = 0; I < AL.getNumArgs(); ++I) {
1261 Expr *Ex = AL.getArgAsExpr(I);
1263 if (!S.checkFunctionOrMethodParameterIndex(D, AL, I + 1, Ex, Idx))
1269 S, getFunctionOrMethodParamType(D, Idx.getASTIndex()), AL,
1281 if (NonNullArgs.empty() && AL.getLoc().isFileID() &&
1292 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers);
1298 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size));
1302 const ParsedAttr &AL) {
1303 if (AL.getNumArgs() > 0) {
1305 handleNonNullAttr(S, D, AL);
1307 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1314 if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(),
1318 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, nullptr, 0));
1321 static void handleReturnsNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1324 if (!attrNonNullArgCheck(S, ResultType, AL, SourceRange(), SR,
1328 D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL));
1331 static void handleNoEscapeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1338 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1339 << AL << AL.getRange() << 0;
1343 D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
1346 static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1347 Expr *E = AL.getArgAsExpr(0),
1348 *OE = AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr;
1349 S.AddAssumeAlignedAttr(D, AL, E, OE);
1352 static void handleAllocAlignAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1353 S.AddAllocAlignAttr(D, AL, AL.getArgAsExpr(0));
1448 static void handleOwnershipAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1457 if (!AL.isArgIdent(0)) {
1458 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
1459 << AL << 1 << AANT_ArgumentIdentifier;
1465 OwnershipAttr(S.Context, AL, nullptr, nullptr, 0).getOwnKind();
1471 if (AL.getNumArgs() < 2) {
1472 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1477 if (AL.getNumArgs() > 2) {
1478 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1484 IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
1492 for (unsigned i = 1; i < AL.getNumArgs(); ++i) {
1493 Expr *Ex = AL.getArgAsExpr(i);
1495 if (!S.checkFunctionOrMethodParameterIndex(D, AL, i, Ex, Idx))
1513 S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err
1523 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
1524 << AL << I
1525 << (AL.isRegularKeywordAttribute() ||
1536 S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch)
1549 OwnershipAttr(S.Context, AL, Module, Start, Size));
1552 static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1554 if (AL.getNumArgs() > 1) {
1555 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1571 S.Diag(AL.getLoc(), diag::err_attribute_weakref_not_global_context)
1602 if (AL.getNumArgs() && S.checkStringLiteralArgumentAttr(AL, 0, Str))
1605 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1607 D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
1614 static void markUsedForAliasOrIfunc(Sema &S, Decl *D, const ParsedAttr &AL,
1623 &S.Context.Idents.get(Demangled ? Demangled.get() : Str), AL.getLoc());
1642 static void handleIFuncAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1644 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1650 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 1;
1654 markUsedForAliasOrIfunc(S, D, AL, Str);
1655 D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
1658 static void handleAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1660 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
1664 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin);
1672 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx);
1678 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 0;
1684 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << VD << 0;
1689 markUsedForAliasOrIfunc(S, D, AL, Str);
1690 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1693 static void handleTLSModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1697 if (!S.checkStringLiteralArgumentAttr(AL, 0, Model, &LiteralLoc))
1707 D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model));
1710 static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1713 D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL));
1717 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1718 << AL << getFunctionOrMethodResultSourceRange(D);
1721 static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1724 if (AL.getParsedKind() == ParsedAttr::AT_CPUDispatch) {
1725 if (checkAttrMutualExclusion<CPUSpecificAttr>(S, D, AL))
1729 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1733 } else if (AL.getParsedKind() == ParsedAttr::AT_CPUSpecific) {
1734 if (checkAttrMutualExclusion<CPUDispatchAttr>(S, D, AL))
1738 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1748 S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL;
1753 if (!AL.checkAtLeastNumArgs(S, 1))
1757 for (unsigned ArgNo = 0; ArgNo < getNumAttributeArgs(AL); ++ArgNo) {
1758 if (!AL.isArgIdent(ArgNo)) {
1759 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1760 << AL << AANT_ArgumentIdentifier;
1764 IdentifierLoc *CPUArg = AL.getArgAsIdent(ArgNo);
1769 << CPUName << (AL.getKind() == ParsedAttr::AT_CPUDispatch);
1778 S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries);
1785 if (AL.getKind() == ParsedAttr::AT_CPUSpecific)
1787 CPUSpecificAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1790 CPUDispatchAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1793 static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1795 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
1796 << AL << AttributeLangSupport::Cpp;
1800 D->addAttr(::new (S.Context) CommonAttr(S.Context, AL));
1803 static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1804 if (AL.isDeclspecAttribute()) {
1809 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch)
1810 << AL << Triple.getArchName();
1817 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type_str)
1818 << AL << AL.isRegularKeywordAttribute() << "non-member functions";
1823 D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));
1870 bool Sema::CheckAttrTarget(const ParsedAttr &AL) {
1872 if (!AL.existsInTarget(Context.getTargetInfo())) {
1873 Diag(AL.getLoc(), AL.isRegularKeywordAttribute()
1876 << AL << AL.getRange();
1877 AL.setInvalid();
1884 static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1892 S.Diag(AL.getLoc(), AL.isStandardAttributeSyntax()
1895 << AL << AL.isRegularKeywordAttribute()
1901 D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(S.Context, AL));
1905 static void handleVecReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1931 S.Diag(AL.getLoc(), diag::err_repeat_attribute) << A;
1939 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1944 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record);
1950 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1956 D->addAttr(::new (S.Context) VecReturnAttr(S.Context, AL));
1960 const ParsedAttr &AL) {
1965 S.Diag(AL.getLoc(),
1971 D->addAttr(::new (S.Context) CarriesDependencyAttr(S.Context, AL));
1974 static void handleUnusedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1975 bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName();
1980 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
1982 D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL));
1985 static void handleConstructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1987 if (S.getLangOpts().HLSL && AL.getNumArgs()) {
1988 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported);
1991 if (AL.getNumArgs() &&
1992 !S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority))
1995 D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority));
1998 static void handleDestructorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2000 if (AL.getNumArgs() &&
2001 !S.checkUInt32Argument(AL, AL.getArgAsExpr(0), priority))
2004 D->addAttr(::new (S.Context) DestructorAttr(S.Context, AL, priority));
2008 static void handleAttrWithMessage(Sema &S, Decl *D, const ParsedAttr &AL) {
2011 if (AL.getNumArgs() == 1 && !S.checkStringLiteralArgumentAttr(AL, 0, Str))
2014 D->addAttr(::new (S.Context) AttrTy(S.Context, AL, Str));
2244 static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2247 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using)
2248 << AL;
2252 if (!AL.checkExactlyNumArgs(S, 1))
2254 IdentifierLoc *Platform = AL.getArgAsIdent(0);
2265 AvailabilityChange Introduced = AL.getAvailabilityIntroduced();
2266 AvailabilityChange Deprecated = AL.getAvailabilityDeprecated();
2267 AvailabilityChange Obsoleted = AL.getAvailabilityObsoleted();
2268 bool IsUnavailable = AL.getUnavailableLoc().isValid();
2269 bool IsStrict = AL.getStrictLoc().isValid();
2271 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getMessageExpr()))
2275 dyn_cast_if_present<StringLiteral>(AL.getReplacementExpr()))
2281 S.Diag(AL.getLoc(),
2291 S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2297 S.Diag(AL.getStrictLoc(), diag::err_availability_unexpected_parameter)
2300 int PriorityModifier = AL.isPragmaClangAttribute()
2304 const IdentifierLoc *EnvironmentLoc = AL.getEnvironment();
2321 ND, AL, II, false /*Implicit*/, Introduced.Version, Deprecated.Version,
2377 ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
2419 ND, AL, NewII, true /*Implicit*/, NewIntroduced, NewDeprecated,
2430 return S.getDarwinSDKInfoForAvailabilityChecking(AL.getRange().getBegin(),
2450 ND, AL, NewII, true /*Implicit*/,
2492 ND, AL, NewII, true /*Implicit*/,
2509 const ParsedAttr &AL) {
2510 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 4))
2514 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(0)))
2517 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(1)))
2519 bool IsGeneratedDeclaration = AL.getArgAsIdent(2) != nullptr;
2521 if (const auto *SE = dyn_cast_if_present<StringLiteral>(AL.getArgAsExpr(3)))
2525 S.Context, AL, Language, DefinedIn, IsGeneratedDeclaration, USR));
2555 static void handleVisibilityAttr(Sema &S, Decl *D, const ParsedAttr &AL,
2559 S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL;
2566 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type)
2567 << AL << AL.isRegularKeywordAttribute() << ExpectedTypeOrNamespace;
2574 if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, &LiteralLoc))
2579 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2588 S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility);
2595 D, AL, (TypeVisibilityAttr::VisibilityType)type);
2597 newAttr = S.mergeVisibilityAttr(D, AL, type);
2603 static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2605 if (AL.getNumArgs() > 0) {
2606 Expr *E = AL.getArgAsExpr(0);
2609 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2610 << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2615 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero)
2624 if (AL.getNumArgs() > 1) {
2625 Expr *E = AL.getArgAsExpr(1);
2628 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2629 << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2637 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2646 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments);
2651 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2656 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2661 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2674 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2678 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2679 << AL << AL.isRegularKeywordAttribute()
2684 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2685 << AL << AL.isRegularKeywordAttribute()
2689 D->addAttr(::new (S.Context) SentinelAttr(S.Context, AL, sentinel, nullPos));
2692 static void handleWarnUnusedResult(Sema &S, Decl *D, const ParsedAttr &AL) {
2696 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2701 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2706 if (AL.isStandardAttributeSyntax() && !AL.getScopeName()) {
2710 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
2711 << AL << AL.isRegularKeywordAttribute()
2720 if (AL.getNumArgs() == 1) {
2722 S.Diag(AL.getLoc(), diag::ext_cxx20_attr) << AL;
2728 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, nullptr))
2731 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL;
2734 if ((!AL.isGNUAttribute() &&
2735 !(AL.isStandardAttributeSyntax() && AL.isClangScope())) &&
2737 S.Diag(AL.getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
2738 << AL.isGNUScope();
2742 D->addAttr(::new (S.Context) WarnUnusedResultAttr(S.Context, AL, Str));
2745 static void handleWeakImportAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2750 S.Diag(AL.getLoc(), diag::warn_attribute_invalid_on_definition)
2757 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2758 << AL << AL.isRegularKeywordAttribute() << ExpectedVariableOrFunction;
2763 D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL));
2768 static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2771 const Expr *E = AL.getArgAsExpr(i);
2772 if (!S.checkUInt32Argument(AL, E, WGSize[i], i,
2776 S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2777 << AL << E->getSourceRange();
2786 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2789 WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
2792 static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
2793 if (!AL.hasParsedType()) {
2794 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2799 QualType ParmType = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
2805 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
2811 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2816 D->addAttr(::new (S.Context) VecTypeHintAttr(S.Context, AL, ParmTSI));
2860 static void handleSectionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2865 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2871 SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
2882 static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2886 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2895 D->addAttr(::new (S.Context) CodeModelAttr(S.Context, AL, CM));
2930 static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2933 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2939 S.Diag(AL.getLoc(),
2947 if (CodeSegAttr *CSA = S.mergeCodeSegAttr(D, AL, Str))
3030 static void handleTargetVersionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3033 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3037 ::new (S.Context) TargetVersionAttr(S.Context, AL, Str);
3041 static void handleTargetAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3044 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc) ||
3048 TargetAttr *NewAttr = ::new (S.Context) TargetAttr(S.Context, AL, Str);
3149 static void handleTargetClonesAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3157 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3161 if (checkAttrMutualExclusion<TargetClonesAttr>(S, D, AL))
3168 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
3171 if (!S.checkStringLiteralArgumentAttr(AL, I, CurStr, &LiteralLoc) ||
3174 cast<StringLiteral>(AL.getArgAsExpr(I)->IgnoreParenCasts()), D,
3181 if (HasCommas && AL.getNumArgs() > 1)
3182 S.Diag(AL.getLoc(), diag::warn_target_clone_mixed_values);
3191 S.Diag(AL.getLoc(), diag::err_target_clone_must_have_default);
3212 TargetClonesAttr(S.Context, AL, Strings.data(), Strings.size());
3216 static void handleMinVectorWidthAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3217 Expr *E = AL.getArgAsExpr(0);
3219 if (!S.checkUInt32Argument(AL, E, VecWidth)) {
3220 AL.setInvalid();
3226 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
3230 D->addAttr(::new (S.Context) MinVectorWidthAttr(S.Context, AL, VecWidth));
3233 static void handleCleanupAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3234 Expr *E = AL.getArgAsExpr(0);
3309 D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD));
3313 const ParsedAttr &AL) {
3314 if (!AL.isArgIdent(0)) {
3315 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3316 << AL << 0 << AANT_ArgumentIdentifier;
3321 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3324 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3329 EnumExtensibilityAttr(S.Context, AL, ExtensibilityKind));
3334 static void handleFormatArgAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3335 const Expr *IdxExpr = AL.getArgAsExpr(0);
3337 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, IdxExpr, Idx))
3347 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3363 S.Diag(AL.getLoc(), diag::err_format_attribute_result_not)
3369 D->addAttr(::new (S.Context) FormatArgAttr(S.Context, AL, Idx));
3404 static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3406 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
3411 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported);
3416 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3417 AL.setInvalid();
3424 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3425 AL.setInvalid();
3429 Expr *E = AL.getArgAsExpr(0);
3431 if (!S.checkUInt32Argument(AL, E, prioritynum)) {
3432 AL.setInvalid();
3440 !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
3441 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
3442 << E->getSourceRange() << AL << 101 << 65535;
3443 AL.setInvalid();
3446 D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
3495 static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3496 if (!AL.isArgIdent(0)) {
3497 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3498 << AL << 1 << AANT_ArgumentIdentifier;
3507 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3522 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
3523 << AL << II->getName();
3528 Expr *IdxExpr = AL.getArgAsExpr(1);
3530 if (!S.checkUInt32Argument(AL, IdxExpr, Idx, 2))
3534 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3535 << AL << 2 << IdxExpr->getSourceRange();
3544 S.Diag(AL.getLoc(),
3558 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3564 Expr *FirstArgExpr = AL.getArgAsExpr(2);
3566 if (!S.checkUInt32Argument(AL, FirstArgExpr, FirstArg, 3))
3574 S.Diag(AL.getLoc(), diag::err_format_strftime_third_parameter)
3583 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3584 << AL << 3 << FirstArgExpr->getSourceRange()
3591 S.Diag(D->getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
3596 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3597 << AL << 3 << FirstArgExpr->getSourceRange();
3603 FormatAttr *NewAttr = S.mergeFormatAttr(D, AL, II, Idx, FirstArg);
3609 static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3611 if (AL.getNumArgs() == 0) {
3612 S.Diag(AL.getLoc(), diag::err_callback_attribute_no_callee)
3613 << AL.getRange();
3635 for (unsigned I = 0, E = AL.getNumArgs(); I < E; ++I) {
3639 if (AL.isArgIdent(I)) {
3640 IdentifierLoc *IdLoc = AL.getArgAsIdent(I);
3643 S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown)
3650 } else if (AL.isArgExpr(I)) {
3651 Expr *IdxExpr = AL.getArgAsExpr(I);
3654 if (!S.checkUInt32Argument(AL, IdxExpr, (uint32_t &)ArgIdx, I + 1,
3656 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3657 << AL << (I + 1) << IdxExpr->getSourceRange();
3663 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3664 << AL << (I + 1) << IdxExpr->getSourceRange();
3674 S.Diag(AL.getLoc(), diag::err_callback_implicit_this_not_available)
3692 S.Diag(AL.getLoc(), diag::err_callback_attribute_invalid_callee)
3693 << AL.getRange();
3703 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3704 << AL.getRange();
3715 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3716 << AL.getRange();
3721 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
3722 << AL << (unsigned)(EncodingIndices.size() - 1);
3727 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
3728 << AL << (unsigned)(EncodingIndices.size() - 1);
3733 S.Diag(AL.getLoc(), diag::err_callback_callee_is_variadic) << AL.getRange();
3739 S.Diag(AL.getLoc(), diag::err_callback_attribute_multiple) << AL.getRange();
3744 S.Context, AL, EncodingIndices.data(), EncodingIndices.size()));
3755 static void handleCalledOnceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3760 S.Diag(AL.getLoc(), diag::err_called_once_attribute_wrong_type);
3764 D->addAttr(::new (S.Context) CalledOnceAttr(S.Context, AL));
3767 static void handleTransparentUnionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3777 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
3778 << AL << AL.isRegularKeywordAttribute() << ExpectedUnion;
3784 S.Diag(AL.getLoc(),
3792 S.Diag(AL.getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3835 RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL));
3847 static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3851 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
3855 Args.reserve(AL.getNumArgs() - 1);
3856 for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
3857 assert(!AL.isArgIdent(Idx));
3858 Args.push_back(AL.getArgAsExpr(Idx));
3861 S.AddAnnotationAttr(D, AL, Str, Args);
3864 static void handleAlignValueAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3865 S.AddAlignValueAttr(D, AL, AL.getArgAsExpr(0));
3908 static void handleAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3909 if (AL.hasParsedType()) {
3910 const ParsedType &TypeArg = AL.getTypeArg();
3914 if (AL.isPackExpansion() &&
3916 S.Diag(AL.getEllipsisLoc(),
3921 if (!AL.isPackExpansion() &&
3926 S.AddAlignedAttr(D, AL, TInfo, AL.isPackExpansion());
3931 if (AL.getNumArgs() > 1) {
3932 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3936 if (AL.getNumArgs() == 0) {
3937 D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr));
3941 Expr *E = AL.getArgAsExpr(0);
3942 if (AL.isPackExpansion() && !E->containsUnexpandedParameterPack()) {
3943 S.Diag(AL.getEllipsisLoc(),
3948 if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))
3951 S.AddAlignedAttr(D, AL, E, AL.isPackExpansion());
4029 // FIXME: Cache the number on the AL object?
4281 static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4284 if (!AL.isArgIdent(0)) {
4285 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
4286 << AL << AANT_ArgumentIdentifier;
4290 IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident;
4292 S.AddModeAttr(D, AL, Name);
4440 static void handleNoDebugAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4441 D->addAttr(::new (S.Context) NoDebugAttr(S.Context, AL));
4460 const ParsedAttr &AL) {
4465 Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
4466 << AL << AL.isRegularKeywordAttribute()
4478 return ::new (Context) InternalLinkageAttr(Context, AL);
4481 Sema::mergeInternalLinkageAttr(Decl *D, const InternalLinkageAttr &AL) {
4486 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4487 << &AL << AL.isRegularKeywordAttribute()
4499 return ::new (Context) InternalLinkageAttr(Context, AL);
4534 static void handleAlwaysInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4536 S.mergeAlwaysInlineAttr(D, AL, AL.getAttrName()))
4540 static void handleMinSizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4541 if (MinSizeAttr *MinSize = S.mergeMinSizeAttr(D, AL))
4545 static void handleOptimizeNoneAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4546 if (OptimizeNoneAttr *Optnone = S.mergeOptimizeNoneAttr(D, AL))
4550 static void handleConstantAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4553 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4563 D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL));
4566 static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4572 S.Diag(AL.getLoc(), diag::err_cuda_extern_shared) << VD;
4576 S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
4579 D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
4582 static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4606 if (AL.getKind() == ParsedAttr::AT_NVPTXKernel)
4607 D->addAttr(::new (S.Context) NVPTXKernelAttr(S.Context, AL));
4609 D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL));
4618 static void handleDeviceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4621 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4631 D->addAttr(::new (S.Context) CUDADeviceAttr(S.Context, AL));
4634 static void handleManagedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4637 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev);
4642 D->addAttr(::new (S.Context) HIPManagedAttr(S.Context, AL));
4647 static void handleGNUInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4650 S.Diag(AL.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4655 S.Diag(AL.getLoc(), diag::warn_gnu_inline_cplusplus_without_extern);
4657 D->addAttr(::new (S.Context) GNUInlineAttr(S.Context, AL));
4660 static void handleCallConvAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4663 // Diagnostic is emitted elsewhere: here we store the (valid) AL
4667 AL, CC, /*FD*/ nullptr,
4672 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
4673 << AL << AL.isRegularKeywordAttribute() << ExpectedFunctionOrMethod;
4677 switch (AL.getKind()) {
4679 D->addAttr(::new (S.Context) FastCallAttr(S.Context, AL));
4682 D->addAttr(::new (S.Context) StdCallAttr(S.Context, AL));
4685 D->addAttr(::new (S.Context) ThisCallAttr(S.Context, AL));
4688 D->addAttr(::new (S.Context) CDeclAttr(S.Context, AL));
4691 D->addAttr(::new (S.Context) PascalAttr(S.Context, AL));
4694 D->addAttr(::new (S.Context) SwiftCallAttr(S.Context, AL));
4697 D->addAttr(::new (S.Context) SwiftAsyncCallAttr(S.Context, AL));
4700 D->addAttr(::new (S.Context) VectorCallAttr(S.Context, AL));
4703 D->addAttr(::new (S.Context) MSABIAttr(S.Context, AL));
4706 D->addAttr(::new (S.Context) SysVABIAttr(S.Context, AL));
4709 D->addAttr(::new (S.Context) RegCallAttr(S.Context, AL));
4724 D->addAttr(::new (S.Context) PcsAttr(S.Context, AL, PCS));
4728 D->addAttr(::new (S.Context) AArch64VectorPcsAttr(S.Context, AL));
4731 D->addAttr(::new (S.Context) AArch64SVEPcsAttr(S.Context, AL));
4734 D->addAttr(::new (S.Context) AMDGPUKernelCallAttr(S.Context, AL));
4737 D->addAttr(::new (S.Context) IntelOclBiccAttr(S.Context, AL));
4740 D->addAttr(::new (S.Context) PreserveMostAttr(S.Context, AL));
4743 D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL));
4746 D->addAttr(::new (S.Context) M68kRTDAttr(S.Context, AL));
4749 D->addAttr(::new (S.Context) PreserveNoneAttr(S.Context, AL));
4752 D->addAttr(::new (S.Context) RISCVVectorCCAttr(S.Context, AL));
4759 static void handleSuppressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4760 if (AL.getAttributeSpellingListIndex() == SuppressAttr::CXX11_gsl_suppress) {
4762 if (!AL.checkAtLeastNumArgs(S, 1))
4767 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
4770 if (!S.checkStringLiteralArgumentAttr(AL, I, RuleName, nullptr))
4776 SuppressAttr(S.Context, AL, DiagnosticIdentifiers.data(),
4780 static void handleLifetimeCategoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4783 if (AL.hasParsedType()) {
4784 ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
4793 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)
4794 << SelectIdx << AL;
4805 if (AL.getKind() == ParsedAttr::AT_Owner) {
4806 if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
4813 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
4814 << AL << OAttr
4815 << (AL.isRegularKeywordAttribute() ||
4822 Redecl->addAttr(::new (S.Context) OwnerAttr(S.Context, AL, DerefTypeLoc));
4825 if (checkAttrMutualExclusion<OwnerAttr>(S, D, AL))
4832 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
4833 << AL << PAttr
4834 << (AL.isRegularKeywordAttribute() ||
4842 PointerAttr(S.Context, AL, DerefTypeLoc));
4847 static void handleRandomizeLayoutAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4848 if (checkAttrMutualExclusion<NoRandomizeLayoutAttr>(S, D, AL))
4851 D->addAttr(::new (S.Context) RandomizeLayoutAttr(S.Context, AL));
4855 const ParsedAttr &AL) {
4856 if (checkAttrMutualExclusion<RandomizeLayoutAttr>(S, D, AL))
4859 D->addAttr(::new (S.Context) NoRandomizeLayoutAttr(S.Context, AL));
5037 bool Sema::CheckRegparmAttr(const ParsedAttr &AL, unsigned &numParams) {
5038 if (AL.isInvalid())
5041 if (!AL.checkExactlyNumArgs(*this, 1)) {
5042 AL.setInvalid();
5047 Expr *NumParamsExpr = AL.getArgAsExpr(0);
5048 if (!checkUInt32Argument(AL, NumParamsExpr, NP)) {
5049 AL.setInvalid();
5054 Diag(AL.getLoc(), diag::err_attribute_regparm_wrong_platform)
5056 AL.setInvalid();
5062 Diag(AL.getLoc(), diag::err_attribute_regparm_invalid_number)
5064 AL.setInvalid();
5084 const CUDALaunchBoundsAttr &AL,
5097 << &AL << Idx << AANT_ArgumentIntegerConstant << E->getSourceRange();
5108 << &AL << Idx << E->getSourceRange();
5160 static void handleLaunchBoundsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5161 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 3))
5164 S.AddLaunchBoundsAttr(D, AL, AL.getArgAsExpr(0),
5165 AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr,
5166 AL.getNumArgs() > 2 ? AL.getArgAsExpr(2) : nullptr);
5170 const ParsedAttr &AL) {
5171 if (!AL.isArgIdent(0)) {
5172 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5173 << AL << /* arg num = */ 1 << AANT_ArgumentIdentifier;
5178 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 2, AL.getArgAsExpr(1),
5183 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 3, AL.getArgAsExpr(2),
5187 bool IsPointer = AL.getAttrName()->getName() == "pointer_with_type_tag";
5193 S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0;
5197 S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx,
5202 const ParsedAttr &AL) {
5203 if (!AL.isArgIdent(0)) {
5204 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5205 << AL << 1 << AANT_ArgumentIdentifier;
5209 if (!AL.checkExactlyNumArgs(S, 1))
5213 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
5214 << AL << AL.isRegularKeywordAttribute() << ExpectedVariable;
5218 IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident;
5220 S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc);
5224 S.Context, AL, PointerKind, MatchingCTypeLoc, AL.getLayoutCompatible(),
5225 AL.getMustBeNull()));
5228 static void handleXRayLogArgsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5231 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, AL.getArgAsExpr(0),
5238 XRayLogArgsAttr(S.Context, AL, ArgCount.getSourceIndex()));
5242 const ParsedAttr &AL) {
5244 S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
5248 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Count, 0, true))
5250 if (AL.getNumArgs() == 2) {
5251 Expr *Arg = AL.getArgAsExpr(1);
5252 if (!S.checkUInt32Argument(AL, Arg, Offset, 1, true))
5255 S.Diag(S.getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
5256 << &AL << 0 << Count << Arg->getBeginLoc();
5261 PatchableFunctionEntryAttr(S.Context, AL, Count, Offset));
5264 static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5265 if (!AL.isArgIdent(0)) {
5266 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5267 << AL << 1 << AANT_ArgumentIdentifier;
5271 IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident;
5284 S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias) << AL;
5288 D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident));
5291 static void handleNullableTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5292 if (AL.isUsedAsTypeAttr())
5297 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type_str)
5298 << AL << AL.isRegularKeywordAttribute() << "classes";
5302 handleSimpleAttribute<TypeNullableAttr>(S, D, AL);
5305 static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5306 if (!AL.hasParsedType()) {
5307 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
5312 QualType QT = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
5317 D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
5339 static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5341 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5342 << AL << AttributeLangSupport::C;
5348 if (!S.checkStringLiteralArgumentAttr(AL, 0, OrigStrRef, &LiteralLoc))
5391 if (AL.isMicrosoftAttribute()) // Check for [uuid(...)] spelling.
5392 S.Diag(AL.getLoc(), diag::warn_atl_uuid_deprecated);
5394 UuidAttr *UA = S.mergeUuidAttr(D, AL, OrigStrRef, Guid);
5399 static void handleMSInheritanceAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5401 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5402 << AL << AttributeLangSupport::C;
5406 D, AL, /*BestCase=*/true, (MSInheritanceModel)AL.getSemanticSpelling());
5413 static void handleDeclspecThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5416 S.Diag(AL.getLoc(), diag::err_thread_unsupported);
5420 S.Diag(AL.getLoc(), diag::err_declspec_thread_on_thread_variable);
5424 S.Diag(AL.getLoc(), diag::err_thread_non_global) << "__declspec(thread)";
5427 D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
5430 static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5432 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
5433 << AL << AL.getRange();
5438 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied)
5444 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied)
5449 D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
5452 static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5454 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
5456 if (!S.checkStringLiteralArgumentAttr(AL, I, Tag))
5463 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5467 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5470 if (AL.getNumArgs() == 0)
5472 } else if (!AL.checkAtLeastNumArgs(S, 1))
5480 AbiTagAttr(S.Context, AL, Tags.data(), Tags.size()));
5491 static void handleBTFDeclTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5493 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str))
5498 D->addAttr(::new (S.Context) BTFDeclTagAttr(S.Context, AL, Str));
5501 BTFDeclTagAttr *Sema::mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL) {
5502 if (hasBTFDeclTagAttr(D, AL.getBTFDeclTag()))
5504 return ::new (Context) BTFDeclTagAttr(Context, AL, AL.getBTFDeclTag());
5507 static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5511 S.MSP430().handleInterruptAttr(D, AL);
5515 S.MIPS().handleInterruptAttr(D, AL);
5518 S.M68k().handleInterruptAttr(D, AL);
5522 S.X86().handleAnyInterruptAttr(D, AL);
5525 S.AVR().handleInterruptAttr(D, AL);
5529 S.RISCV().handleInterruptAttr(D, AL);
5532 S.ARM().handleInterruptAttr(D, AL);
5537 static void handleLayoutVersion(Sema &S, Decl *D, const ParsedAttr &AL) {
5539 Expr *VersionExpr = static_cast<Expr *>(AL.getArgAsExpr(0));
5540 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Version))
5545 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
5546 << AL << Version << VersionExpr->getSourceRange();
5555 D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version));
5651 static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5662 if (AL.getKind() == ParsedAttr::AT_Capability &&
5663 !S.checkStringLiteralArgumentAttr(AL, 0, N, &LiteralLoc))
5666 D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N));
5669 static void handleAssertCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5671 if (!checkLockFunAttrCommon(S, D, AL, Args))
5675 AssertCapabilityAttr(S.Context, AL, Args.data(), Args.size()));
5679 const ParsedAttr &AL) {
5681 if (!checkLockFunAttrCommon(S, D, AL, Args))
5684 D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(),
5689 const ParsedAttr &AL) {
5691 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
5695 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
5699 const ParsedAttr &AL) {
5702 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, true);
5704 D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(),
5709 const ParsedAttr &AL) {
5710 if (!AL.checkAtLeastNumArgs(S, 1))
5715 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
5720 RequiresCapabilityAttr(S.Context, AL, Args.data(), Args.size());
5725 static void handleDeprecatedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5728 S.Diag(AL.getLoc(), diag::warn_deprecated_anonymous_namespace);
5736 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using)
5737 << AL;
5743 if (AL.isArgExpr(0) && AL.getArgAsExpr(0) &&
5744 !S.checkStringLiteralArgumentAttr(AL, 0, Str))
5748 if (AL.isDeclspecAttribute() || AL.isStandardAttributeSyntax())
5749 AL.checkAtMostNumArgs(S, 1);
5750 else if (AL.isArgExpr(1) && AL.getArgAsExpr(1) &&
5751 !S.checkStringLiteralArgumentAttr(AL, 1, Replacement))
5754 if (!S.getLangOpts().CPlusPlus14 && AL.isCXX11Attribute() && !AL.isGNUScope())
5755 S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL;
5757 D->addAttr(::new (S.Context) DeprecatedAttr(S.Context, AL, Str, Replacement));
5771 static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5772 if (!AL.checkAtLeastNumArgs(S, 1))
5777 for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
5781 if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, &LiteralLoc))
5790 << AL << SanitizerName;
5794 D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(),
5799 const ParsedAttr &AL) {
5800 StringRef AttrName = AL.getAttrName()->getName();
5809 << AL << AL.isRegularKeywordAttribute() << ExpectedFunction;
5820 if (AL.isStandardAttributeSyntax())
5823 AttributeCommonInfo Info = AL;
5829 static void handleInternalLinkageAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5830 if (InternalLinkageAttr *Internal = S.mergeInternalLinkageAttr(D, AL))
5834 static void handleZeroCallUsedRegsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5838 if (!S.checkStringLiteralArgumentAttr(AL, 0, KindStr, &LiteralLoc))
5844 << AL << KindStr;
5849 D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
5852 static void handleCountedByAttrField(Sema &S, Decl *D, const ParsedAttr &AL) {
5856 auto *CountExpr = AL.getArgAsExpr(0);
5862 switch (AL.getKind()) {
5893 const ParsedAttr &AL) {
5896 if (!S.checkStringLiteralArgumentAttr(AL, 0, KindStr, &LiteralLoc))
5902 << AL << KindStr;
5909 D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
5913 const ParsedAttr &AL) {
5915 handleSimpleAttribute<AvailableOnlyInDefaultEvalMethodAttr>(S, D, AL);
5918 static void handleNoMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5921 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_non_function_pointer)
5922 << AL << VDecl;
5925 D->addAttr(NoMergeAttr::Create(S.Context, AL));
5928 static void handleNoUniqueAddressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5929 D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL));
5945 static void handleUninitializedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5948 D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
5951 static void handleMIGServerRoutineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5970 handleSimpleAttribute<MIGServerRoutineAttr>(S, D, AL);
5973 static void handleMSAllocatorAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5978 S.Diag(AL.getLoc(), diag::warn_declspec_allocator_nonpointer)
5979 << AL.getRange() << RetTy;
5984 handleSimpleAttribute<MSAllocatorAttr>(S, D, AL);
5987 static void handleAcquireHandleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5988 if (AL.isUsedAsTypeAttr())
5993 S.Diag(AL.getLoc(), diag::err_attribute_output_parameter)
5994 << AL.getRange();
5999 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6001 D->addAttr(AcquireHandleAttr::Create(S.Context, Argument, AL));
6005 static void handleHandleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6007 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6009 D->addAttr(Attr::Create(S.Context, Argument, AL));
6013 static void handleUnsafeBufferUsage(Sema &S, Decl *D, const ParsedAttr &AL) {
6014 D->addAttr(Attr::Create(S.Context, AL));
6017 static void handleCFGuardAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6020 if (!AL.isArgIdent(0)) {
6021 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6022 << AL << AANT_ArgumentIdentifier;
6027 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
6029 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
6033 D->addAttr(::new (S.Context) CFGuardAttr(S.Context, AL, Arg));
6048 static void handleEnforceTCBAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
6050 if (!S.checkStringLiteralArgumentAttr(AL, 0, Argument))
6058 S.Diag(AL.getLoc(), diag::err_tcb_conflicting_attributes)
6059 << AL.getAttrName()->getName() << ConflictingAttr->getAttrName()->getName()
6069 D->addAttr(AttrTy::Create(S.Context, Argument, AL));
6073 static AttrTy *mergeEnforceTCBAttrImpl(Sema &S, Decl *D, const AttrTy &AL) {
6075 StringRef TCBName = AL.getTCBName();
6080 << AL.getAttrName()->getName() << TCBName;
6083 S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
6091 return ::new(Context) AttrTy(Context, AL, AL.getTCBName());
6094 EnforceTCBAttr *Sema::mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL) {
6096 *this, D, AL);
6100 Decl *D, const EnforceTCBLeafAttr &AL) {
6102 *this, D, AL);
6106 const ParsedAttr &AL) {
6108 const uint32_t NumArgs = AL.getNumArgs();
6110 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6111 AL.setInvalid();
6115 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL;
6116 AL.setInvalid();
6121 S.Diag(AL.getLoc(), diag::err_duplicated_vtable_pointer_auth) << Decl;
6122 AL.setInvalid();
6126 if (AL.isArgIdent(0)) {
6127 IdentifierLoc *IL = AL.getArgAsIdent(0);
6131 AL.setInvalid();
6135 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 0;
6136 AL.setInvalid();
6139 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6140 << AL << AANT_ArgumentIdentifier;
6146 if (AL.getNumArgs() > 1) {
6147 if (AL.isArgIdent(1)) {
6148 IdentifierLoc *IL = AL.getArgAsIdent(1);
6153 AL.setInvalid();
6159 AL.setInvalid();
6162 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6163 << AL << AANT_ArgumentIdentifier;
6169 if (AL.getNumArgs() > 2) {
6170 if (AL.isArgIdent(2)) {
6171 IdentifierLoc *IL = AL.getArgAsIdent(2);
6175 AL.setInvalid();
6179 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 2;
6180 AL.setInvalid();
6183 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6184 << AL << AANT_ArgumentIdentifier;
6191 S.Diag(AL.getLoc(), diag::err_missing_custom_discrimination) << AL << 4;
6192 AL.setInvalid();
6196 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6197 AL.setInvalid();
6200 if (!AL.isArgExpr(3) || !S.checkUInt32Argument(AL, AL.getArgAsExpr(3),
6202 S.Diag(AL.getLoc(), diag::err_invalid_custom_discrimination);
6203 AL.setInvalid();
6206 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 3;
6207 AL.setInvalid();
6211 S.Context, AL, KeyType, AddressDiversityMode, ED,
6221 static bool MustDelayAttributeArguments(const ParsedAttr &AL) {
6223 if (!AL.acceptsExprPack())
6226 bool AttrHasVariadicArg = AL.hasVariadicArg();
6227 unsigned AttrNumArgs = AL.getNumArgMembers();
6228 for (size_t I = 0; I < std::min(AL.getNumArgs(), AttrNumArgs); ++I) {
6234 Expr *E = AL.getArgAsExpr(I);
6235 bool ArgMemberCanHoldExpr = AL.isParamExpr(I);
6254 ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
6256 if (AL.isInvalid() || AL.getKind() == ParsedAttr::IgnoredAttribute)
6265 if ((S.getLangOpts().CPlusPlus ? AL.isCXX11Attribute()
6266 : AL.isC23Attribute()) &&
6273 if (AL.getKind() == ParsedAttr::UnknownAttribute ||
6274 !AL.existsInTarget(S.Context.getTargetInfo())) {
6275 S.Diag(AL.getLoc(),
6276 AL.isRegularKeywordAttribute()
6278 : AL.isDeclspecAttribute()
6281 << AL << AL.getRange();
6286 bool MustDelayArgs = MustDelayAttributeArguments(AL);
6289 if (S.checkCommonAttributeFeatures(D, AL, MustDelayArgs))
6293 AL.handleAttrWithDelayedArgs(S, D);
6297 switch (AL.getKind()) {
6299 if (AL.getInfo().handleDeclAttribute(S, D, AL) != ParsedAttrInfo::NotHandled)
6301 if (!AL.isStmtAttr()) {
6302 assert(AL.isTypeAttr() && "Non-type attribute not handled");
6304 if (AL.isTypeAttr()) {
6307 if (!AL.isStandardAttributeSyntax() && !AL.isRegularKeywordAttribute()) {
6322 if (AL.slidesFromDeclToDeclSpecLegacyBehavior() &&
6327 if (AL.isClangScope()) {
6328 S.Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl)
6329 << AL << D->getLocation();
6337 if (AL.getKind() == ParsedAttr::AT_Regparm) {
6350 if (AL.getKind() == ParsedAttr::AT_VectorSize) {
6360 if (AL.getKind() == ParsedAttr::AT_NoDeref) {
6371 S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)
6372 << AL << AL.isRegularKeywordAttribute() << D->getLocation();
6375 handleInterruptAttr(S, D, AL);
6378 S.X86().handleForceAlignArgPointerAttr(D, AL);
6381 handleSimpleAttribute<ReadOnlyPlacementAttr>(S, D, AL);
6385 handleDLLAttr(S, D, AL);
6388 S.AMDGPU().handleAMDGPUFlatWorkGroupSizeAttr(D, AL);
6391 S.AMDGPU().handleAMDGPUWavesPerEUAttr(D, AL);
6394 S.AMDGPU().handleAMDGPUNumSGPRAttr(D, AL);
6397 S.AMDGPU().handleAMDGPUNumVGPRAttr(D, AL);
6400 S.AMDGPU().handleAMDGPUMaxNumWorkGroupsAttr(D, AL);
6403 S.AVR().handleSignalAttr(D, AL);
6406 S.BPF().handlePreserveAccessIndexAttr(D, AL);
6409 handleSimpleAttribute<BPFPreserveStaticOffsetAttr>(S, D, AL);
6412 handleBTFDeclTagAttr(S, D, AL);
6415 S.Wasm().handleWebAssemblyExportNameAttr(D, AL);
6418 S.Wasm().handleWebAssemblyImportModuleAttr(D, AL);
6421 S.Wasm().handleWebAssemblyImportNameAttr(D, AL);
6424 S.ObjC().handleIBOutlet(D, AL);
6427 S.ObjC().handleIBOutletCollection(D, AL);
6430 handleIFuncAttr(S, D, AL);
6433 handleAliasAttr(S, D, AL);
6436 handleAlignedAttr(S, D, AL);
6439 handleAlignValueAttr(S, D, AL);
6442 handleAllocSizeAttr(S, D, AL);
6445 handleAlwaysInlineAttr(S, D, AL);
6448 handleAnalyzerNoReturnAttr(S, D, AL);
6451 handleTLSModelAttr(S, D, AL);
6454 handleAnnotateAttr(S, D, AL);
6457 handleAvailabilityAttr(S, D, AL);
6460 handleDependencyAttr(S, scope, D, AL);
6464 handleCPUSpecificAttr(S, D, AL);
6467 handleCommonAttr(S, D, AL);
6470 handleConstantAttr(S, D, AL);
6473 handlePassObjectSizeAttr(S, D, AL);
6476 handleConstructorAttr(S, D, AL);
6479 handleDeprecatedAttr(S, D, AL);
6482 handleDestructorAttr(S, D, AL);
6485 handleEnableIfAttr(S, D, AL);
6488 handleErrorAttr(S, D, AL);
6491 handleExcludeFromExplicitInstantiationAttr(S, D, AL);
6494 handleDiagnoseIfAttr(S, D, AL);
6497 handleDiagnoseAsBuiltinAttr(S, D, AL);
6500 handleNoBuiltinAttr(S, D, AL);
6503 handleExtVectorTypeAttr(S, D, AL);
6506 handleExternalSourceSymbolAttr(S, D, AL);
6509 handleMinSizeAttr(S, D, AL);
6512 handleOptimizeNoneAttr(S, D, AL);
6515 handleEnumExtensibilityAttr(S, D, AL);
6518 S.SYCL().handleKernelAttr(D, AL);
6521 handleSimpleAttribute<SYCLSpecialClassAttr>(S, D, AL);
6524 handleFormatAttr(S, D, AL);
6527 handleFormatArgAttr(S, D, AL);
6530 handleCallbackAttr(S, D, AL);
6533 handleCalledOnceAttr(S, D, AL);
6537 handleGlobalAttr(S, D, AL);
6540 handleDeviceAttr(S, D, AL);
6543 handleManagedAttr(S, D, AL);
6546 handleGNUInlineAttr(S, D, AL);
6549 handleLaunchBoundsAttr(S, D, AL);
6552 handleRestrictAttr(S, D, AL);
6555 handleModeAttr(S, D, AL);
6559 handleNonNullAttrParameter(S, PVD, AL);
6561 handleNonNullAttr(S, D, AL);
6564 handleReturnsNonNullAttr(S, D, AL);
6567 handleNoEscapeAttr(S, D, AL);
6570 handleSimpleAttribute<MaybeUndefAttr>(S, D, AL);
6573 handleAssumeAlignedAttr(S, D, AL);
6576 handleAllocAlignAttr(S, D, AL);
6579 handleOwnershipAttr(S, D, AL);
6582 handleNakedAttr(S, D, AL);
6585 handleNoReturnAttr(S, D, AL);
6588 handleStandardNoReturnAttr(S, D, AL);
6591 handleNoCfCheckAttr(S, D, AL);
6594 if (!AL.isUsedAsTypeAttr())
6595 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6598 handleSharedAttr(S, D, AL);
6601 handleVecReturnAttr(S, D, AL);
6604 S.ObjC().handleOwnershipAttr(D, AL);
6607 S.ObjC().handlePreciseLifetimeAttr(D, AL);
6610 S.ObjC().handleReturnsInnerPointerAttr(D, AL);
6613 S.ObjC().handleRequiresSuperAttr(D, AL);
6616 S.ObjC().handleBridgeAttr(D, AL);
6619 S.ObjC().handleBridgeMutableAttr(D, AL);
6622 S.ObjC().handleBridgeRelatedAttr(D, AL);
6625 S.ObjC().handleDesignatedInitializer(D, AL);
6628 S.ObjC().handleRuntimeName(D, AL);
6631 S.ObjC().handleBoxable(D, AL);
6634 S.ObjC().handleNSErrorDomain(D, AL);
6639 S.ObjC().AddXConsumedAttr(D, AL,
6640 S.ObjC().parsedAttrToRetainOwnershipKind(AL),
6645 S, D, AL, S.ObjC().isValidOSObjectOutParameter(D),
6647 /*Extra Args=*/AL, /*pointer-to-OSObject-pointer*/ 3, AL.getRange());
6651 S, D, AL, S.ObjC().isValidOSObjectOutParameter(D),
6653 /*Extra Args=*/AL, /*pointer-to-OSObject-poointer*/ 3, AL.getRange());
6662 S.ObjC().handleXReturnsXRetainedAttr(D, AL);
6665 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
6668 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
6671 S.OpenCL().handleSubGroupSize(D, AL);
6674 handleVecTypeHint(S, D, AL);
6677 handleInitPriorityAttr(S, D, AL);
6680 handlePackedAttr(S, D, AL);
6683 handlePreferredName(S, D, AL);
6686 handleSectionAttr(S, D, AL);
6689 handleCodeModelAttr(S, D, AL);
6692 handleRandomizeLayoutAttr(S, D, AL);
6695 handleNoRandomizeLayoutAttr(S, D, AL);
6698 handleCodeSegAttr(S, D, AL);
6701 handleTargetAttr(S, D, AL);
6704 handleTargetVersionAttr(S, D, AL);
6707 handleTargetClonesAttr(S, D, AL);
6710 handleMinVectorWidthAttr(S, D, AL);
6713 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
6716 S.OpenMP().handleOMPAssumeAttr(D, AL);
6719 S.ObjC().handleDirectAttr(D, AL);
6722 S.ObjC().handleDirectMembersAttr(D, AL);
6723 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
6726 S.ObjC().handleSuppresProtocolAttr(D, AL);
6729 handleUnusedAttr(S, D, AL);
6732 handleVisibilityAttr(S, D, AL, false);
6735 handleVisibilityAttr(S, D, AL, true);
6738 handleWarnUnusedResult(S, D, AL);
6741 handleWeakRefAttr(S, D, AL);
6744 handleWeakImportAttr(S, D, AL);
6747 handleTransparentUnionAttr(S, D, AL);
6750 S.ObjC().handleMethodFamilyAttr(D, AL);
6753 S.ObjC().handleNSObject(D, AL);
6756 S.ObjC().handleIndependentClass(D, AL);
6759 S.ObjC().handleBlocksAttr(D, AL);
6762 handleSentinelAttr(S, D, AL);
6765 handleCleanupAttr(S, D, AL);
6768 handleNoDebugAttr(S, D, AL);
6771 S.ARM().handleCmseNSEntryAttr(D, AL);
6794 handleCallConvAttr(S, D, AL);
6797 handleSuppressAttr(S, D, AL);
6801 handleLifetimeCategoryAttr(S, D, AL);
6804 S.OpenCL().handleAccessAttr(D, AL);
6807 S.OpenCL().handleNoSVMAttr(D, AL);
6810 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftContext);
6813 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftAsyncContext);
6816 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftErrorResult);
6819 S.Swift().AddParameterABIAttr(D, AL, ParameterABI::SwiftIndirectResult);
6822 handleInternalLinkageAttr(S, D, AL);
6825 handleZeroCallUsedRegsAttr(S, D, AL);
6828 handleFunctionReturnThunksAttr(S, D, AL);
6831 handleNoMergeAttr(S, D, AL);
6834 handleNoUniqueAddressAttr(S, D, AL);
6838 handleAvailableOnlyInDefaultEvalMethod(S, D, AL);
6845 handleCountedByAttrField(S, D, AL);
6850 handleLayoutVersion(S, D, AL);
6853 handleUuidAttr(S, D, AL);
6856 handleMSInheritanceAttr(S, D, AL);
6859 handleDeclspecThreadAttr(S, D, AL);
6862 handleMSConstexprAttr(S, D, AL);
6865 handleSimpleAttribute<HybridPatchableAttr>(S, D, AL);
6870 S.HLSL().handleNumThreadsAttr(D, AL);
6873 handleSimpleAttribute<HLSLSV_GroupIndexAttr>(S, D, AL);
6876 S.HLSL().handleSV_DispatchThreadIDAttr(D, AL);
6879 S.HLSL().handlePackOffsetAttr(D, AL);
6882 S.HLSL().handleShaderAttr(D, AL);
6885 S.HLSL().handleResourceBindingAttr(D, AL);
6888 S.HLSL().handleResourceClassAttr(D, AL);
6891 S.HLSL().handleParamModifierAttr(D, AL);
6895 handleAbiTagAttr(S, D, AL);
6898 handleCFGuardAttr(S, D, AL);
6903 handleAssertExclusiveLockAttr(S, D, AL);
6906 handleAssertSharedLockAttr(S, D, AL);
6909 handlePtGuardedVarAttr(S, D, AL);
6912 handleNoSanitizeAttr(S, D, AL);
6915 handleNoSanitizeSpecificAttr(S, D, AL);
6918 handleGuardedByAttr(S, D, AL);
6921 handlePtGuardedByAttr(S, D, AL);
6924 handleExclusiveTrylockFunctionAttr(S, D, AL);
6927 handleLockReturnedAttr(S, D, AL);
6930 handleLocksExcludedAttr(S, D, AL);
6933 handleSharedTrylockFunctionAttr(S, D, AL);
6936 handleAcquiredBeforeAttr(S, D, AL);
6939 handleAcquiredAfterAttr(S, D, AL);
6945 handleCapabilityAttr(S, D, AL);
6948 handleRequiresCapabilityAttr(S, D, AL);
6952 handleAssertCapabilityAttr(S, D, AL);
6955 handleAcquireCapabilityAttr(S, D, AL);
6958 handleReleaseCapabilityAttr(S, D, AL);
6961 handleTryAcquireCapabilityAttr(S, D, AL);
6966 handleConsumableAttr(S, D, AL);
6969 handleCallableWhenAttr(S, D, AL);
6972 handleParamTypestateAttr(S, D, AL);
6975 handleReturnTypestateAttr(S, D, AL);
6978 handleSetTypestateAttr(S, D, AL);
6981 handleTestTypestateAttr(S, D, AL);
6986 handleArgumentWithTypeTagAttr(S, D, AL);
6989 handleTypeTagForDatatypeAttr(S, D, AL);
6994 S.Swift().handleAsyncName(D, AL);
6997 S.Swift().handleAttrAttr(D, AL);
7000 S.Swift().handleBridge(D, AL);
7003 S.Swift().handleError(D, AL);
7006 S.Swift().handleName(D, AL);
7009 S.Swift().handleNewType(D, AL);
7012 S.Swift().handleAsyncAttr(D, AL);
7015 S.Swift().handleAsyncError(D, AL);
7020 handleXRayLogArgsAttr(S, D, AL);
7024 handlePatchableFunctionEntryAttr(S, D, AL);
7029 handleDestroyAttr(S, D, AL);
7033 handleUninitializedAttr(S, D, AL);
7037 S.ObjC().handleExternallyRetainedAttr(D, AL);
7041 handleMIGServerRoutineAttr(S, D, AL);
7045 handleMSAllocatorAttr(S, D, AL);
7049 S.ARM().handleBuiltinAliasAttr(D, AL);
7053 handleSimpleAttribute<ArmLocallyStreamingAttr>(S, D, AL);
7057 S.ARM().handleNewAttr(D, AL);
7061 handleAcquireHandleAttr(S, D, AL);
7065 handleHandleAttr<ReleaseHandleAttr>(S, D, AL);
7069 handleUnsafeBufferUsage<UnsafeBufferUsageAttr>(S, D, AL);
7073 handleHandleAttr<UseHandleAttr>(S, D, AL);
7077 handleEnforceTCBAttr<EnforceTCBAttr, EnforceTCBLeafAttr>(S, D, AL);
7081 handleEnforceTCBAttr<EnforceTCBLeafAttr, EnforceTCBAttr>(S, D, AL);
7085 handleBuiltinAliasAttr(S, D, AL);
7089 handlePreferredTypeAttr(S, D, AL);
7093 handleSimpleAttribute<UsingIfExistsAttr>(S, D, AL);
7097 handleNullableTypeAttr(S, D, AL);
7101 handleVTablePointerAuthentication(S, D, AL);
7112 for (const ParsedAttr &AL : AttrList)
7113 ProcessDeclAttribute(*this, S, D, AL, Options);
7181 for (const ParsedAttr &AL : AttrList)
7182 if (AL.getKind() == ParsedAttr::AT_TransparentUnion) {
7183 handleTransparentUnionAttr(*this, D, AL);
7195 for (const ParsedAttr &AL : AttrList) {
7196 if (AL.getKind() == ParsedAttr::AT_Annotate) {
7197 ProcessDeclAttribute(*this, nullptr, ASDecl, AL,
7200 Diag(AL.getLoc(), diag::err_only_annotate_after_access_spec);
7210 for (const ParsedAttr &AL : A) {
7212 if (AL.isUsedAsTypeAttr() || AL.isInvalid())
7214 if (AL.getKind() == ParsedAttr::IgnoredAttribute)
7217 if (AL.getKind() == ParsedAttr::UnknownAttribute) {
7218 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
7219 << AL << AL.getRange();
7221 S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL
7222 << AL.getRange();
7338 for (ParsedAttr &AL : Src) {
7342 if ((AL.isStandardAttributeSyntax() || AL.isAlignas()) &&
7343 AL.slidesFromDeclToDeclSpecLegacyBehavior()) {
7348 AL.diagnoseAppertainsTo(*this, D);
7350 NonSlidingAttrs.addAtEnd(&AL);