Lines Matching defs:S

96 static bool checkPositiveIntArgument(Sema &S, const AttrInfo &AI, const Expr *Expr,
99 if (!S.checkUInt32Argument(AI, Expr, UVal, Idx))
105 S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
171 static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType* RT) {
172 auto IsOverloadedOperatorPresent = [&S](const RecordDecl *Record,
175 Record->lookup(S.Context.DeclarationNames.getCXXOperatorName(Op));
207 static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D,
221 if (threadSafetyCheckIsSmartPointer(S, RT))
225 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
258 static bool checkRecordTypeForCapability(Sema &S, QualType Ty) {
270 if (threadSafetyCheckIsSmartPointer(S, RT))
288 static bool typeHasCapability(Sema &S, QualType Ty) {
292 if (checkRecordTypeForCapability(S, Ty))
298 static bool isCapabilityExpr(Sema &S, const Expr *Ex) {
305 return isCapabilityExpr(S, E->getSubExpr());
307 return isCapabilityExpr(S, E->getSubExpr());
311 return isCapabilityExpr(S, E->getSubExpr());
315 return isCapabilityExpr(S, E->getLHS()) &&
316 isCapabilityExpr(S, E->getRHS());
320 return typeHasCapability(S, Ex->getType());
328 static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D,
343 S.Diag(AL.getLoc(),
347 S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
372 S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL;
400 S.Diag(AL.getLoc(),
413 if (!typeHasCapability(S, ArgTy) && !isCapabilityExpr(S, ArgExp))
414 S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable)
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))
472 if (!QT->isDependentType() && !typeHasCapability(S, QT)) {
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))
491 D->addAttr(::new (S.Context)
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))
501 D->addAttr(::new (S.Context)
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))
521 D->addAttr(::new (S.Context)
522 AssertSharedLockAttr(S.Context, AL, StartArg, Size));
525 static void handleAssertExclusiveLockAttr(Sema &S, Decl *D,
528 if (!checkLockFunAttrCommon(S, D, AL, Args))
533 D->addAttr(::new (S.Context)
534 AssertExclusiveLockAttr(S.Context, AL, StartArg, Size));
543 static bool checkParamIsIntegerType(Sema &S, const Decl *D, const AttrInfo &AI,
548 if (!S.checkFunctionOrMethodParameterIndex(D, AI, AttrArgNo + 1, AttrArg,
555 S.Diag(SrcLoc, diag::err_attribute_integers_only)
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;
577 if (!checkPositiveIntArgument(S, AL, SizeExpr, SizeArgNoVal, /*Idx=*/1))
579 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/0))
588 if (!checkPositiveIntArgument(S, AL, NumberExpr, Val, /*Idx=*/2))
590 if (!checkParamIsIntegerType(S, D, AL, /*AttrArgNo=*/1))
595 D->addAttr(::new (S.Context)
596 AllocSizeAttr(S.Context, AL, SizeArgNo, NumberArgNo));
599 static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const ParsedAttr &AL,
601 if (!AL.checkAtLeastNumArgs(S, 1))
605 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
611 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
616 static void handleSharedTrylockFunctionAttr(Sema &S, Decl *D,
619 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
622 D->addAttr(::new (S.Context) SharedTrylockFunctionAttr(
623 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
626 static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D,
629 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
632 D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr(
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);
659 D->addAttr(::new (S.Context)
660 LocksExcludedAttr(S.Context, AL, StartArg, Size));
663 static bool checkFunctionConditionAttr(Sema &S, Decl *D, const ParsedAttr &AL,
667 ExprResult Converted = S.PerformContextuallyConvertToBool(Cond);
673 if (!S.checkStringLiteralArgumentAttr(AL, 1, Msg))
683 S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
685 S.Diag(PDiag.first, PDiag.second);
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))
708 static void handleExcludeFromExplicitInstantiationAttr(Sema &S, Decl *D,
714 S.Diag(AL.getLoc(),
719 D->addAttr(::new (S.Context)
720 ExcludeFromExplicitInstantiationAttr(S.Context, AL));
769 static void handleDiagnoseAsBuiltinAttr(Sema &S, Decl *D,
775 S.Diag(AL.getLoc(), diag::err_attribute_no_member_function) << AL;
787 S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T;
805 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments_for)
821 if (!S.checkUInt32Argument(AL, IndexExpr, Index, I + 1, false))
825 S.Diag(AL.getLoc(), diag::err_attribute_bounds_for_function)
835 S.Diag(IndexExpr->getBeginLoc(), diag::err_attribute_parameter_types)
843 D->addAttr(::new (S.Context) DiagnoseAsBuiltinAttr(
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(),
869 D->addAttr(::new (S.Context) DiagnoseIfAttr(
870 S.Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D)));
873 static void handleNoBuiltinAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
897 if (!S.checkStringLiteralArgumentAttr(AL, I, BuiltinName, &LiteralLoc))
903 S.Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
913 S.Diag(D->getLocation(),
919 D->addAttr(::new (S.Context)
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;
931 if (!S.checkUInt32Argument(AL, E, Type, /*Idx=*/1))
938 S.Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
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) {
962 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
967 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
972 D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState));
975 static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD,
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))
1008 if (!S.checkStringLiteralArgumentAttr(AL, ArgIndex, StateString, &Loc))
1014 S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1021 D->addAttr(::new (S.Context)
1022 CallableWhenAttr(S.Context, AL, States.data(), States.size()));
1025 static void handleParamTypestateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1034 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
1039 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
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) {
1066 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1071 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1096 // S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) <<
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))
1113 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1118 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
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))
1135 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1140 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1145 D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState));
1148 static void handleExtVectorTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1150 S.ExtVectorDecls.push_back(cast<TypedefNameDecl>(D));
1153 static void handlePackedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1155 TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1160 S.Context.getTypeAlign(FD->getType()) <= 8);
1162 if (S.getASTContext().getTargetInfo().getTriple().isPS()) {
1165 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type)
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) {
1188 QualType T = S.GetTypeFromParser(PT, &TSI);
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)
1214 S.Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at)
1242 static bool attrNonNullArgCheck(Sema &S, QualType T, const ParsedAttr &AL,
1246 if (!S.isValidPointerAttrType(T)) {
1248 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only)
1251 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1258 static void handleNonNullAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1263 if (!S.checkFunctionOrMethodParameterIndex(D, AL, I + 1, Ex, Idx))
1269 S, getFunctionOrMethodParamType(D, Idx.getASTIndex()), AL,
1282 !S.inTemplateInstantiation()) {
1287 if (T->isDependentType() || S.isValidPointerAttrType(T))
1292 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers);
1298 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size));
1301 static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D,
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) {
1337 if (!S.isValidPointerAttrType(T, /* RefOkay */ true)) {
1338 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only)
1343 D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
1346 static void handleAssumeAlignedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
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) {
1458 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
1465 OwnershipAttr(S.Context, AL, nullptr, nullptr, 0).getOwnKind();
1472 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1478 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1488 Module = &S.PP.getIdentifierTable().get(ModuleName);
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)
1533 S.Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1536 S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch)
1548 D->addAttr(::new (S.Context)
1549 OwnershipAttr(S.Context, AL, Module, Start, Size));
1552 static void handleWeakRefAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
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,
1617 if (S.getASTContext().getCXXABIKind() != TargetCXXABI::Microsoft)
1619 std::unique_ptr<MangleContext> MC(S.Context.createMangleContext());
1623 &S.Context.Idents.get(Demangled ? Demangled.get() : Str), AL.getLoc());
1624 LookupResult LR(S, Target, Sema::LookupOrdinaryName);
1625 if (S.LookupName(LR, S.TUScope)) {
1637 ND->markUsed(S.Context);
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))
1663 if (S.Context.getTargetInfo().getTriple().isOSDarwin()) {
1664 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin);
1668 if (S.Context.getTargetInfo().getTriple().isNVPTX()) {
1670 ToCudaVersion(S.Context.getTargetInfo().getSDKVersion());
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))
1703 S.Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
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)
1721 static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1725 if (checkAttrMutualExclusion<CPUSpecificAttr>(S, D, AL))
1729 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1730 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
1734 if (checkAttrMutualExclusion<CPUDispatchAttr>(S, D, AL))
1738 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
1739 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
1748 S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL;
1753 if (!AL.checkAtLeastNumArgs(S, 1))
1759 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
1767 if (!S.Context.getTargetInfo().validateCPUSpecificCPUDispatch(CPUName)) {
1768 S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value)
1773 const TargetInfo &Target = S.Context.getTargetInfo();
1778 S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries);
1786 D->addAttr(::new (S.Context)
1787 CPUSpecificAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1789 D->addAttr(::new (S.Context)
1790 CPUDispatchAttr(S.Context, AL, CPUs.data(), CPUs.size()));
1793 static void handleCommonAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1794 if (S.LangOpts.CPlusPlus) {
1795 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
1800 D->addAttr(::new (S.Context) CommonAttr(S.Context, AL));
1803 static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1805 const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
1809 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch)
1816 if (S.getLangOpts().MSVCCompat && isa<CXXMethodDecl>(D)) {
1817 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type_str)
1823 D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));
1826 static void handleNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
1830 S.Diag(Attrs.getLoc(), diag::warn_attribute_wrong_decl_type)
1836 D->addAttr(::new (S.Context) NoReturnAttr(S.Context, Attrs));
1839 static void handleStandardNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &A) {
1845 if (!S.getLangOpts().CPlusPlus &&
1848 S.getSourceManager().isInSystemMacro(A.getLoc())))
1849 S.Diag(A.getLoc(), diag::warn_deprecated_noreturn_spelling) << A.getRange();
1851 D->addAttr(::new (S.Context) CXX11NoReturnAttr(S.Context, A));
1854 static void handleNoCfCheckAttr(Sema &S, Decl *D, const ParsedAttr &Attrs) {
1855 if (!S.getLangOpts().CFProtectionBranch)
1856 S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored);
1858 handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);
1884 static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
1892 S.Diag(AL.getLoc(), AL.isStandardAttributeSyntax()
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));
1959 static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D,
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) {
1979 if (!S.getLangOpts().CPlusPlus17 && IsCXX17Attr)
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);
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) {
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));
2017 static bool checkAvailabilityAttr(Sema &S, SourceRange Range,
2031 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2039 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2047 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering)
2244 static void handleAvailabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2247 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using)
2252 if (!AL.checkExactlyNumArgs(S, 1))
2258 S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
2281 S.Diag(AL.getLoc(),
2291 S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor);
2296 if (S.getLangOpts().HLSL && IsStrict)
2297 S.Diag(AL.getStrictLoc(), diag::err_availability_unexpected_parameter)
2307 if (S.getLangOpts().HLSL) {
2312 S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment)
2315 S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter)
2320 AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2329 if (S.Context.getTargetInfo().getTriple().isWatchOS()) {
2332 NewII = &S.Context.Idents.get("watchos");
2334 NewII = &S.Context.Idents.get("watchos_app_extension");
2337 const auto *SDKInfo = S.getDarwinSDKInfoForAvailabilityChecking();
2376 AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2384 } else if (S.Context.getTargetInfo().getTriple().isTvOS()) {
2389 NewII = &S.Context.Idents.get("tvos");
2391 NewII = &S.Context.Idents.get("tvos_app_extension");
2394 const auto *SDKInfo = S.getDarwinSDKInfoForAvailabilityChecking();
2418 AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2426 } else if (S.Context.getTargetInfo().getTriple().getOS() ==
2428 S.Context.getTargetInfo().getTriple().isMacCatalystEnvironment()) {
2430 return S.getDarwinSDKInfoForAvailabilityChecking(AL.getRange().getBegin(),
2437 NewII = &S.Context.Idents.get("maccatalyst");
2439 NewII = &S.Context.Idents.get("maccatalyst_app_extension");
2449 AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2468 NewII = &S.Context.Idents.get("maccatalyst");
2491 AvailabilityAttr *NewAttr = S.mergeAvailabilityAttr(
2508 static void handleExternalSourceSymbolAttr(Sema &S, Decl *D,
2510 if (!AL.checkAtLeastNumArgs(S, 1) || !AL.checkAtMostNumArgs(S, 4))
2524 D->addAttr(::new (S.Context) ExternalSourceSymbolAttr(
2525 S.Context, AL, Language, DefinedIn, IsGeneratedDeclaration, USR));
2529 static T *mergeVisibilityAttr(Sema &S, Decl *D, const AttributeCommonInfo &CI,
2536 S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2537 S.Diag(CI.getLoc(), diag::note_previous_attribute);
2540 return ::new (S.Context) T(S.Context, CI, value);
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)
2574 if (!S.checkStringLiteralArgumentAttr(AL, 0, TypeStr, &LiteralLoc))
2579 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2587 !S.Context.getTargetInfo().hasProtectedVisibility()) {
2588 S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility);
2594 newAttr = S.mergeTypeVisibilityAttr(
2597 newAttr = S.mergeVisibilityAttr(D, AL, type);
2603 static void handleSentinelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2608 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) {
2609 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
2615 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero)
2627 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) {
2628 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
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)
2684 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
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;
2710 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str)
2719 const LangOptions &LO = S.getLangOpts();
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;
2737 S.Diag(AL.getLoc(), diag::warn_unused_result_typedef_unsupported_spelling)
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)
2753 (S.Context.getTargetInfo().getTriple().isOSDarwin() &&
2757 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
2763 D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL));
2768 static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
2772 if (!S.checkUInt32Argument(AL, E, WGSize[i], i,
2776 S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2786 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
2788 D->addAttr(::new (S.Context)
2789 WorkGroupAttr(S.Context, AL, WGSize[0], WGSize[1], WGSize[2]));
2792 static void handleVecTypeHint(Sema &S, Decl *D, const ParsedAttr &AL) {
2794 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2799 QualType ParmType = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
2804 !ParmType->isIntegralType(S.getASTContext()))) {
2805 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
2810 if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) {
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))
2868 if (!S.checkSectionName(LiteralLoc, Str))
2871 SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
2876 S.UnifySection(NewAttr->getName(),
2882 static void handleCodeModelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2886 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2891 S.Diag(LiteralLoc, diag::err_attr_codemodel_arg) << Str;
2895 D->addAttr(::new (S.Context) CodeModelAttr(S.Context, AL, CM));
2900 static bool checkCodeSegName(Sema &S, SourceLocation LiteralLoc,
2902 if (llvm::Error E = S.isValidSectionSpecifier(CodeSegName)) {
2903 S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
2930 static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
2933 if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc))
2935 if (!checkCodeSegName(S, LiteralLoc, Str))
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) ||
3034 S.checkTargetVersionAttr(LiteralLoc, D, Str))
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) ||
3045 S.checkTargetAttr(LiteralLoc, Str))
3048 TargetAttr *NewAttr = ::new (S.Context) TargetAttr(S.Context, AL, Str);
3149 static void handleTargetClonesAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3150 if (S.Context.getTargetInfo().getTriple().isAArch64() &&
3151 !S.Context.getTargetInfo().hasFeature("fmv"))
3157 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL;
3158 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
3161 if (checkAttrMutualExclusion<TargetClonesAttr>(S, D, AL))
3171 if (!S.checkStringLiteralArgumentAttr(AL, I, CurStr, &LiteralLoc) ||
3172 S.checkTargetClonesAttrString(
3182 S.Diag(AL.getLoc(), diag::warn_target_clone_mixed_values);
3184 if (S.Context.getTargetInfo().getTriple().isAArch64() && !HasDefault) {
3191 S.Diag(AL.getLoc(), diag::err_target_clone_must_have_default);
3199 S.Diag(D->getLocation(), diag::err_multiversion_doesnt_support)
3207 if (S.Context.getTargetInfo().getTriple().isAArch64() && !HasNotDefault)
3211 TargetClonesAttr *NewAttr = ::new (S.Context)
3212 TargetClonesAttr(S.Context, AL, Strings.data(), Strings.size());
3216 static void handleMinVectorWidthAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3219 if (!S.checkUInt32Argument(AL, E, VecWidth)) {
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) {
3243 S.Diag(Loc, diag::warn_cleanup_ext);
3247 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3253 S.Diag(Loc, diag::warn_cleanup_ext);
3254 FD = S.ResolveSingleFunctionTemplateSpecialization(ULE, true);
3257 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3259 if (ULE->getType() == S.Context.OverloadTy)
3260 S.NoteAllOverloadCandidates(ULE);
3264 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3269 S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3276 QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType());
3278 if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
3280 S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3288 S.Context, NestedNameSpecifierLoc{}, FD->getLocation(), VD, false,
3295 S.Context, VariableReference, UnaryOperatorKind::UO_AddrOf,
3296 S.Context.getPointerType(VD->getType()), VK_PRValue, OK_Ordinary, Loc,
3301 CallExpr::Create(S.Context, E, ArrayRef{AddressOfVariable},
3302 S.Context.VoidTy, VK_PRValue, Loc, FPOptionsOverride{});
3304 if (S.CheckFunctionCall(FD, FunctionCallExpression,
3309 D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD));
3312 static void handleEnumExtensibilityAttr(Sema &S, Decl *D,
3315 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3324 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3328 D->addAttr(::new (S.Context)
3329 EnumExtensibilityAttr(S.Context, AL, ExtensibilityKind));
3334 static void handleFormatArgAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3337 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, IdxExpr, Idx))
3343 bool NotNSStringTy = !S.ObjC().isNSStringType(Ty);
3344 if (NotNSStringTy && !S.ObjC().isCFStringType(Ty) &&
3347 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
3353 auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl();
3357 Ty = S.Context.getObjCObjectPointerType(
3359 if (!S.ObjC().isNSStringType(Ty, /*AllowNSAttributedString=*/true) &&
3360 !S.ObjC().isCFStringType(Ty) &&
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) {
3405 if (!S.getLangOpts().CPlusPlus) {
3406 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL;
3410 if (S.getLangOpts().HLSL) {
3411 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported);
3415 if (S.getCurFunctionOrMethodDecl()) {
3416 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3421 if (S.Context.getAsArrayType(T))
3422 T = S.Context.getBaseElementType(T);
3424 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr);
3431 if (!S.checkUInt32Argument(AL, E, prioritynum)) {
3440 !S.getSourceManager().isInSystemHeader(AL.getLoc())) {
3441 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range)
3446 D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
3495 static void handleFormatAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3497 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
3512 II = &S.Context.Idents.get(Format);
3522 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported)
3530 if (!S.checkUInt32Argument(AL, IdxExpr, Idx, 2))
3534 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3544 S.Diag(AL.getLoc(),
3555 if (!S.ObjC().isNSStringType(Ty, true) && !S.ObjC().isCFStringType(Ty) &&
3558 S.Diag(AL.getLoc(), diag::err_format_attribute_not)
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)
3591 S.Diag(D->getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
3596 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3603 FormatAttr *NewAttr = S.mergeFormatAttr(D, AL, II, Idx, FirstArg);
3609 static void handleCallbackAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
3612 S.Diag(AL.getLoc(), diag::err_callback_attribute_no_callee)
3643 S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown)
3654 if (!S.checkUInt32Argument(AL, IdxExpr, (uint32_t &)ArgIdx, I + 1,
3656 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3663 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
3674 S.Diag(AL.getLoc(), diag::err_callback_implicit_this_not_available)
3692 S.Diag(AL.getLoc(), diag::err_callback_attribute_invalid_callee)
3703 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3715 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type)
3721 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
3727 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments)
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();
3743 D->addAttr(::new (S.Context) CallbackAttr(
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)
3784 S.Diag(AL.getLoc(),
3792 S.Diag(AL.getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3799 S.Diag(FirstField->getLocation(),
3807 uint64_t FirstSize = S.Context.getTypeSize(FirstType);
3808 uint64_t FirstAlign = S.Context.getTypeAlign(FirstType);
3818 if (S.Context.getTypeSize(FieldType) != FirstSize ||
3819 S.Context.getTypeAlign(FieldType) > FirstAlign) {
3821 bool isSize = S.Context.getTypeSize(FieldType) != FirstSize;
3822 unsigned FieldBits = isSize ? S.Context.getTypeSize(FieldType)
3823 : S.Context.getTypeAlign(FieldType);
3824 S.Diag(Field->getLocation(),
3828 S.Diag(FirstField->getLocation(),
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))
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) {
3912 (void)S.GetTypeFromParser(
3916 S.Diag(AL.getEllipsisLoc(),
3922 S.DiagnoseUnexpandedParameterPack(TInfo->getTypeLoc().getBeginLoc(),
3926 S.AddAlignedAttr(D, AL, TInfo, AL.isPackExpansion());
3932 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3937 D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr));
3943 S.Diag(AL.getEllipsisLoc(),
3948 if (!AL.isPackExpansion() && S.DiagnoseUnexpandedParameterPack(E))
3951 S.AddAlignedAttr(D, AL, E, AL.isPackExpansion());
3970 static bool validateAlignasAppliedType(Sema &S, Decl *D,
3988 return S.Diag(AttrLoc, diag::err_attribute_wrong_decl_type)
3994 return S.Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
4210 static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth,
4225 case 'S':
4260 DestWidth = S.Context.getTargetInfo().getRegisterWidth();
4262 DestWidth = S.Context.getTargetInfo().getCharWidth();
4266 DestWidth = S.Context.getTargetInfo().getPointerWidth(LangAS::Default);
4270 DestWidth = S.Context.getTargetInfo().getUnwindWordWidth();
4281 static void handleModeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4285 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
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));
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) {
4570 if (!S.getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4572 S.Diag(AL.getLoc(), diag::err_cuda_extern_shared) << VD;
4575 if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
4576 S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
4577 << llvm::to_underlying(S.CUDA().CurrentTarget()))
4579 D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
4582 static void handleGlobalAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4588 S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
4596 S.Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4600 S.Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4603 if (FD->isInlineSpecified() && !S.getLangOpts().CUDAIsDevice)
4604 S.Diag(FD->getBeginLoc(), diag::warn_kern_is_inline) << FD;
4607 D->addAttr(::new (S.Context) NVPTXKernelAttr(S.Context, AL));
4609 D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL));
4614 if (S.LangOpts.HIP && !S.LangOpts.CUDAIsDevice)
4615 D->addAttr(NoDebugAttr::CreateImplicit(S.Context));
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));
4644 D->addAttr(CUDADeviceAttr::CreateImplicit(S.Context));
4647 static void handleGNUInlineAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4650 S.Diag(AL.getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4654 if (S.LangOpts.CPlusPlus && Fn->getStorageClass() != SC_Extern)
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) {
4666 if (S.CheckCallingConvAttr(
4668 S.CUDA().IdentifyTarget(dyn_cast<FunctionDecl>(D))))
4672 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type)
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) {
4762 if (!AL.checkAtLeastNumArgs(S, 1))
4770 if (!S.checkStringLiteralArgumentAttr(AL, I, RuleName, nullptr))
4775 D->addAttr(::new (S.Context)
4776 SuppressAttr(S.Context, AL, DiagnosticIdentifiers.data(),
4780 static void handleLifetimeCategoryAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
4784 ParmType = S.GetTypeFromParser(AL.getTypeArg(), &DerefTypeLoc);
4793 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument)
4806 if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
4813 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible)
4817 S.Diag(OAttr->getLocation(), diag::note_conflicting_attribute);
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)
4836 S.Diag(PAttr->getLocation(), diag::note_conflicting_attribute);
4841 Redecl->addAttr(::new (S.Context)
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));
4854 static void handleNoRandomizeLayoutAttr(Sema &S, Decl *D,
4856 if (checkAttrMutualExclusion<RandomizeLayoutAttr>(S, D, AL))
4859 D->addAttr(::new (S.Context) NoRandomizeLayoutAttr(S.Context, AL));
5083 static Expr *makeLaunchBoundsArgExpr(Sema &S, Expr *E,
5086 if (S.DiagnoseUnexpandedParameterPack(E))
5095 if (!(I = E->getIntegerConstantExpr(S.Context))) {
5096 S.Diag(E->getExprLoc(), diag::err_attribute_argument_n_type)
5102 S.Diag(E->getExprLoc(), diag::err_ice_too_large)
5107 S.Diag(E->getExprLoc(), diag::warn_attribute_argument_n_negative)
5112 S.Context, S.Context.getConstType(S.Context.IntTy), /*consume*/ false);
5113 ExprResult ValArg = S.PerformCopyInitialization(Entity, SourceLocation(), E);
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),
5169 static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D,
5172 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5178 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 2, AL.getArgAsExpr(1),
5183 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 3, AL.getArgAsExpr(2),
5193 S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0;
5196 D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
5197 S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx,
5201 static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D,
5204 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5209 if (!AL.checkExactlyNumArgs(S, 1))
5213 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type)
5220 S.GetTypeFromParser(AL.getMatchingCType(), &MatchingCTypeLoc);
5223 D->addAttr(::new (S.Context) TypeTagForDatatypeAttr(
5224 S.Context, AL, PointerKind, MatchingCTypeLoc, AL.getLayoutCompatible(),
5228 static void handleXRayLogArgsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5231 if (!S.checkFunctionOrMethodParameterIndex(D, AL, 1, AL.getArgAsExpr(0),
5237 D->addAttr(::new (S.Context)
5238 XRayLogArgsAttr(S.Context, AL, ArgCount.getSourceIndex()));
5241 static void handlePatchableFunctionEntryAttr(Sema &S, Decl *D,
5243 if (S.Context.getTargetInfo().getTriple().isOSAIX()) {
5244 S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL;
5248 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Count, 0, true))
5252 if (!S.checkUInt32Argument(AL, Arg, Offset, 1, true))
5255 S.Diag(S.getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
5260 D->addAttr(::new (S.Context)
5261 PatchableFunctionEntryAttr(S.Context, AL, Count, Offset));
5264 static void handleBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5266 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type)
5275 bool IsAArch64 = S.Context.getTargetInfo().getTriple().isAArch64();
5276 bool IsARM = S.Context.getTargetInfo().getTriple().isARM();
5277 bool IsRISCV = S.Context.getTargetInfo().getTriple().isRISCV();
5278 bool IsHLSL = S.Context.getLangOpts().HLSL;
5279 if ((IsAArch64 && !S.ARM().SveAliasValid(BuiltinID, AliasName)) ||
5280 (IsARM && !S.ARM().MveAliasValid(BuiltinID, AliasName) &&
5281 !S.ARM().CdeAliasValid(BuiltinID, AliasName)) ||
5282 (IsRISCV && !S.RISCV().isAliasValid(BuiltinID, AliasName)) ||
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) {
5297 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type_str)
5302 handleSimpleAttribute<TypeNullableAttr>(S, D, AL);
5305 static void handlePreferredTypeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5307 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
5312 QualType QT = S.GetTypeFromParser(AL.getTypeArg(), &ParmTSI);
5314 S.RequireCompleteType(ParmTSI->getTypeLoc().getBeginLoc(), QT,
5317 D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
5339 static void handleUuidAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5340 if (!S.LangOpts.CPlusPlus) {
5341 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5348 if (!S.checkStringLiteralArgumentAttr(AL, 0, OrigStrRef, &LiteralLoc))
5359 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5366 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5370 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5383 MSGuidDecl *Guid = S.Context.getMSGuidDecl(Parsed);
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) {
5400 if (!S.LangOpts.CPlusPlus) {
5401 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang)
5405 MSInheritanceAttr *IA = S.mergeMSInheritanceAttr(
5409 S.Consumer.AssignInheritanceModel(cast<CXXRecordDecl>(D));
5413 static void handleDeclspecThreadAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5415 if (!S.Context.getTargetInfo().isTLSSupported()) {
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) {
5431 if (!S.getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2022_3)) {
5432 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
5438 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied)
5443 if (!S.getLangOpts().CPlusPlus20 && MD->isVirtual()) {
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) {
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;
5472 } else if (!AL.checkAtLeastNumArgs(S, 1))
5479 D->addAttr(::new (S.Context)
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));
5507 static void handleInterruptAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5509 switch (S.Context.getTargetInfo().getTriple().getArch()) {
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) {
5540 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Version))
5545 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)
5555 D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version));
5584 static void handleDLLAttr(Sema &S, Decl *D, const ParsedAttr &A) {
5586 (S.Context.getTargetInfo().shouldDLLImportComdatSymbols())) {
5587 S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A;
5593 !(S.Context.getTargetInfo().shouldDLLImportComdatSymbols())) {
5595 S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored_on_inline)
5602 if ((S.Context.getTargetInfo().shouldDLLImportComdatSymbols()) &&
5604 S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A;
5610 ? (Attr *)S.mergeDLLExportAttr(D, A)
5611 : (Attr *)S.mergeDLLImportAttr(D, A);
5651 static void handleCapabilityAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
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))
5674 D->addAttr(::new (S.Context)
5675 AssertCapabilityAttr(S.Context, AL, Args.data(), Args.size()));
5678 static void handleAcquireCapabilityAttr(Sema &S, Decl *D,
5681 if (!checkLockFunAttrCommon(S, D, AL, Args))
5684 D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(),
5688 static void handleTryAcquireCapabilityAttr(Sema &S, Decl *D,
5691 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
5694 D->addAttr(::new (S.Context) TryAcquireCapabilityAttr(
5695 S.Context, AL, AL.getArgAsExpr(0), Args.data(), Args.size()));
5698 static void handleReleaseCapabilityAttr(Sema &S, Decl *D,
5702 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0, true);
5704 D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(),
5708 static void handleRequiresCapabilityAttr(Sema &S, Decl *D,
5710 if (!AL.checkAtLeastNumArgs(S, 1))
5715 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
5719 RequiresCapabilityAttr *RCA = ::new (S.Context)
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)
5744 !S.checkStringLiteralArgumentAttr(AL, 0, Str))
5749 AL.checkAtMostNumArgs(S, 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));
5761 if (const auto *S = dyn_cast<VarDecl>(D))
5762 return S->hasGlobalStorage();
5771 static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5772 if (!AL.checkAtLeastNumArgs(S, 1))
5781 if (!S.checkStringLiteralArgumentAttr(AL, I, SanitizerName, &LiteralLoc))
5787 S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
5789 S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global)
5794 D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(),
5798 static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D,
5808 S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
5825 D->addAttr(::new (S.Context)
5826 NoSanitizeAttr(S.Context, Info, &SanitizerName, 1));
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))
5843 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
5849 D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
5852 static void handleCountedByAttrField(Sema &S, Decl *D, const ParsedAttr &AL) {
5884 if (S.CheckCountedByAttrOnField(FD, CountExpr, Decls, CountInBytes, OrNull))
5887 QualType CAT = S.BuildCountAttributedArrayOrPointerType(
5892 static void handleFunctionReturnThunksAttr(Sema &S, Decl *D,
5896 if (!S.checkStringLiteralArgumentAttr(AL, 0, KindStr, &LiteralLoc))
5901 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
5909 D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
5912 static void handleAvailableOnlyInDefaultEvalMethod(Sema &S, Decl *D,
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)
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));
5932 static void handleDestroyAttr(Sema &S, Decl *D, const ParsedAttr &A) {
5934 S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var)
5940 handleSimpleAttribute<AlwaysDestroyAttr>(S, D, A);
5942 handleSimpleAttribute<NoDestroyAttr>(S, D, A);
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) {
5963 if (!IsKernReturnT || T.getCanonicalType() != S.getASTContext().IntTy) {
5964 S.Diag(D->getBeginLoc(),
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)
5984 handleSimpleAttribute<MSAllocatorAttr>(S, D, AL);
5987 static void handleAcquireHandleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
5993 S.Diag(AL.getLoc(), diag::err_attribute_output_parameter)
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) {
6021 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
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)
6069 D->addAttr(AttrTy::Create(S.Context, Argument, AL));
6073 static AttrTy *mergeEnforceTCBAttrImpl(Sema &S, Decl *D, const AttrTy &AL) {
6078 S.Diag(ConflictingAttr->getLoc(), diag::err_tcb_conflicting_attributes)
6083 S.Diag(AL.getLoc(), diag::note_conflicting_attribute);
6090 ASTContext &Context = S.getASTContext();
6105 static void handleVTablePointerAuthentication(Sema &S, Decl *D,
6110 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6115 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL;
6121 S.Diag(AL.getLoc(), diag::err_duplicated_vtable_pointer_auth) << Decl;
6130 S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident;
6134 !S.getLangOpts().PointerAuthCalls) {
6135 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 0;
6139 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6152 S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident;
6157 !S.getLangOpts().PointerAuthCalls) {
6158 S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1;
6162 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6174 S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident;
6178 !S.getLangOpts().PointerAuthCalls) {
6179 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 2;
6183 S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
6191 S.Diag(AL.getLoc(), diag::err_missing_custom_discrimination) << AL << 4;
6196 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4;
6200 if (!AL.isArgExpr(3) || !S.checkUInt32Argument(AL, AL.getArgAsExpr(3),
6202 S.Diag(AL.getLoc(), diag::err_invalid_custom_discrimination);
6206 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 3;
6210 Decl->addAttr(::new (S.Context) VTablePointerAuthenticationAttr(
6211 S.Context, AL, KeyType, AddressDiversityMode, ED,
6254 ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
6265 if ((S.getLangOpts().CPlusPlus ? AL.isCXX11Attribute()
6274 !AL.existsInTarget(S.Context.getTargetInfo())) {
6275 S.Diag(AL.getLoc(),
6289 if (S.checkCommonAttributeFeatures(D, AL, MustDelayArgs))
6293 AL.handleAttrWithDelayedArgs(S, D);
6299 if (AL.getInfo().handleDeclAttribute(S, D, AL) != ParsedAttrInfo::NotHandled)
6328 S.Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl)
6371 S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl)
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);
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),
6651 S, D, AL, S.ObjC().isValidOSObjectOutParameter(D),
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);
7107 Scope *S, Decl *D, const ParsedAttributesView &AttrList,
7113 ProcessDeclAttribute(*this, S, D, AL, Options);
7209 static void checkUnusedDeclAttributes(Sema &S, const ParsedAttributesView &A) {
7218 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored)
7221 S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL
7279 void Sema::DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W) {
7293 PushOnScopeChains(NewD, S);
7300 void Sema::ProcessPragmaWeak(Scope *S, Decl *D) {
7320 DeclApplyPragmaWeak(S, ND, W);
7330 void Sema::ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD) {
7353 ProcessDeclAttributeList(S, D, NonSlidingAttrs, Options);
7371 ProcessDeclAttributeList(S, D, PD.getTypeObject(i).getAttrs(),
7378 ProcessDeclAttributeList(S, D, PD.getAttributes());
7381 AddPragmaAttributes(S, D);
7390 static bool isForbiddenTypeAllowed(Sema &S, Decl *D,
7414 if (S.Context.getSourceManager().isInSystemHeader(D->getLocation())) {
7425 static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &DD,
7428 if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) {
7430 D->addAttr(UnavailableAttr::CreateImplicit(S.Context, "", Reason, DD.Loc));
7433 if (S.getLangOpts().ObjCAutoRefCount)
7445 S.Diag(DD.Loc, DD.getForbiddenTypeDiagnostic())