Lines Matching +full:diag +full:- +full:version
1 //===--- SemaDeclAttr.cpp - Declaration Attribute Handling ----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements decl-related attribute processing.
11 //===----------------------------------------------------------------------===//
105 S.Diag(Expr->getExprLoc(), diag::err_ice_too_large) in checkPositiveIntArgument()
117 const auto *Literal = dyn_cast<StringLiteral>(E->IgnoreParenCasts()); in checkStringLiteralArgumentAttr()
119 *ArgLocation = E->getBeginLoc(); in checkStringLiteralArgumentAttr()
121 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) { in checkStringLiteralArgumentAttr()
122 Diag(E->getBeginLoc(), diag::err_attribute_argument_type) in checkStringLiteralArgumentAttr()
127 Str = Literal->getString(); in checkStringLiteralArgumentAttr()
137 Diag(Loc->Loc, diag::err_attribute_argument_type) in checkStringLiteralArgumentAttr()
139 << FixItHint::CreateInsertion(Loc->Loc, "\"") in checkStringLiteralArgumentAttr()
140 << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\""); in checkStringLiteralArgumentAttr()
141 Str = Loc->Ident->getName(); in checkStringLiteralArgumentAttr()
143 *ArgLocation = Loc->Loc; in checkStringLiteralArgumentAttr()
149 const auto *Literal = dyn_cast<StringLiteral>(ArgExpr->IgnoreParenCasts()); in checkStringLiteralArgumentAttr()
151 *ArgLocation = ArgExpr->getBeginLoc(); in checkStringLiteralArgumentAttr()
153 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) { in checkStringLiteralArgumentAttr()
154 Diag(ArgExpr->getBeginLoc(), diag::err_attribute_argument_type) in checkStringLiteralArgumentAttr()
158 Str = Literal->getString(); in checkStringLiteralArgumentAttr()
162 /// Check if the passed-in expression is of type int or bool.
164 QualType QT = Exp->getType(); in isIntOrBool()
165 return QT->isBooleanType() || QT->isIntegerType(); in isIntOrBool()
170 // it's a smart pointer if it defines both operator-> and operator*.
175 Record->lookup(S.Context.DeclarationNames.getCXXOperatorName(Op)); in threadSafetyCheckIsSmartPointer()
179 const RecordDecl *Record = RT->getDecl(); in threadSafetyCheckIsSmartPointer()
189 for (const auto &BaseSpecifier : CXXRecord->bases()) { in threadSafetyCheckIsSmartPointer()
192 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star); in threadSafetyCheckIsSmartPointer()
195 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow); in threadSafetyCheckIsSmartPointer()
210 QualType QT = VD->getType(); in threadSafetyCheckIsPointer()
211 if (QT->isAnyPointerType()) in threadSafetyCheckIsPointer()
214 if (const auto *RT = QT->getAs<RecordType>()) { in threadSafetyCheckIsPointer()
218 if (RT->isIncompleteType()) in threadSafetyCheckIsPointer()
225 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT; in threadSafetyCheckIsPointer()
232 if (const auto *RT = QT->getAs<RecordType>()) in getRecordType()
236 if (const auto *PT = QT->getAs<PointerType>()) in getRecordType()
237 return PT->getPointeeType()->getAs<RecordType>(); in getRecordType()
245 if (RD->hasAttr<AttrType>()) in checkRecordDeclForAttr()
250 if (!CRD->forallBases([](const CXXRecordDecl *Base) { in checkRecordDeclForAttr()
251 return !Base->hasAttr<AttrType>(); in checkRecordDeclForAttr()
265 if (RT->isIncompleteType()) in checkRecordTypeForCapability()
269 // FIXME -- Check the type that the smart pointer points to. in checkRecordTypeForCapability()
273 return checkRecordDeclForAttr<CapabilityAttr>(RT->getDecl()); in checkRecordTypeForCapability()
277 const auto *TD = Ty->getAs<TypedefType>(); in checkTypedefTypeForCapability()
281 TypedefNameDecl *TN = TD->getDecl(); in checkTypedefTypeForCapability()
285 return TN->hasAttr<CapabilityAttr>(); in checkTypedefTypeForCapability()
305 return isCapabilityExpr(S, E->getSubExpr()); in isCapabilityExpr()
307 return isCapabilityExpr(S, E->getSubExpr()); in isCapabilityExpr()
309 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf || in isCapabilityExpr()
310 E->getOpcode() == UO_Deref) in isCapabilityExpr()
311 return isCapabilityExpr(S, E->getSubExpr()); in isCapabilityExpr()
314 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr) in isCapabilityExpr()
315 return isCapabilityExpr(S, E->getLHS()) && in isCapabilityExpr()
316 isCapabilityExpr(S, E->getRHS()); in isCapabilityExpr()
320 return typeHasCapability(S, Ex->getType()); in isCapabilityExpr()
336 // a non-static method, and that the class is a (scoped) capability. in checkAttrArgsAreCapabilityObjs()
338 if (MD && !MD->isStatic()) { in checkAttrArgsAreCapabilityObjs()
339 const CXXRecordDecl *RD = MD->getParent(); in checkAttrArgsAreCapabilityObjs()
340 // FIXME -- need to check this again on template instantiation in checkAttrArgsAreCapabilityObjs()
343 S.Diag(AL.getLoc(), in checkAttrArgsAreCapabilityObjs()
344 diag::warn_thread_attribute_not_on_capability_member) in checkAttrArgsAreCapabilityObjs()
345 << AL << MD->getParent(); in checkAttrArgsAreCapabilityObjs()
347 S.Diag(AL.getLoc(), diag::warn_thread_attribute_not_on_non_static_member) in checkAttrArgsAreCapabilityObjs()
355 if (ArgExp->isTypeDependent()) { in checkAttrArgsAreCapabilityObjs()
356 // FIXME -- need to check this again on template instantiation in checkAttrArgsAreCapabilityObjs()
362 if (StrLit->getLength() == 0 || in checkAttrArgsAreCapabilityObjs()
363 (StrLit->isOrdinary() && StrLit->getString() == "*")) { in checkAttrArgsAreCapabilityObjs()
372 S.Diag(AL.getLoc(), diag::warn_thread_attribute_ignored) << AL; in checkAttrArgsAreCapabilityObjs()
377 QualType ArgTy = ArgExp->getType(); in checkAttrArgsAreCapabilityObjs()
380 // specially -- we need to look at the type of the member. in checkAttrArgsAreCapabilityObjs()
382 if (UOp->getOpcode() == UO_AddrOf) in checkAttrArgsAreCapabilityObjs()
383 if (const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr())) in checkAttrArgsAreCapabilityObjs()
384 if (DRE->getDecl()->isCXXInstanceMember()) in checkAttrArgsAreCapabilityObjs()
385 ArgTy = DRE->getDecl()->getType(); in checkAttrArgsAreCapabilityObjs()
395 unsigned int NumParams = FD->getNumParams(); in checkAttrArgsAreCapabilityObjs()
396 llvm::APInt ArgValue = IL->getValue(); in checkAttrArgsAreCapabilityObjs()
398 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1; in checkAttrArgsAreCapabilityObjs()
400 S.Diag(AL.getLoc(), in checkAttrArgsAreCapabilityObjs()
401 diag::err_attribute_argument_out_of_bounds_extra_info) in checkAttrArgsAreCapabilityObjs()
405 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType(); in checkAttrArgsAreCapabilityObjs()
414 S.Diag(AL.getLoc(), diag::warn_thread_attribute_argument_not_lockable) in checkAttrArgsAreCapabilityObjs()
421 //===----------------------------------------------------------------------===//
423 //===----------------------------------------------------------------------===//
429 D->addAttr(::new (S.Context) PtGuardedVarAttr(S.Context, AL)); in handlePtGuardedVarAttr()
451 D->addAttr(::new (S.Context) GuardedByAttr(S.Context, AL, Arg)); in handleGuardedByAttr()
462 D->addAttr(::new (S.Context) PtGuardedByAttr(S.Context, AL, Arg)); in handlePtGuardedByAttr()
471 QualType QT = cast<ValueDecl>(D)->getType(); in checkAcquireOrderAttrCommon()
472 if (!QT->isDependentType() && !typeHasCapability(S, QT)) { in checkAcquireOrderAttrCommon()
473 S.Diag(AL.getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL; in checkAcquireOrderAttrCommon()
491 D->addAttr(::new (S.Context) in handleAcquiredAfterAttr()
501 D->addAttr(::new (S.Context) in handleAcquiredBeforeAttr()
521 D->addAttr(::new (S.Context) in handleAssertSharedLockAttr()
533 D->addAttr(::new (S.Context) in handleAssertExclusiveLockAttr()
541 /// AttrArgNo is used to actually retrieve the argument, so it's base-0.
553 if (!ParamTy->isIntegerType() && !ParamTy->isCharType()) { in checkParamIsIntegerType()
554 SourceLocation SrcLoc = AttrArg->getBeginLoc(); in checkParamIsIntegerType()
555 S.Diag(SrcLoc, diag::err_attribute_integers_only) in checkParamIsIntegerType()
569 if (!RetTy->isPointerType()) { in handleAllocSizeAttr()
570 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) << AL; in handleAllocSizeAttr()
576 // Parameter indices are 1-indexed, hence Index=1 in handleAllocSizeAttr()
587 // Parameter indices are 1-based, hence Index=2 in handleAllocSizeAttr()
595 D->addAttr(::new (S.Context) in handleAllocSizeAttr()
605 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in checkTryLockFunAttrCommon()
622 D->addAttr(::new (S.Context) SharedTrylockFunctionAttr( in handleSharedTrylockFunctionAttr()
632 D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr( in handleExclusiveTrylockFunctionAttr()
644 D->addAttr(::new (S.Context) LockReturnedAttr(S.Context, AL, Args[0])); in handleLockReturnedAttr()
659 D->addAttr(::new (S.Context) in handleLocksExcludedAttr()
666 if (!Cond->isTypeDependent()) { in checkFunctionConditionAttr()
680 if (isa<FunctionDecl>(D) && !Cond->isValueDependent() && in checkFunctionConditionAttr()
683 S.Diag(AL.getLoc(), diag::err_attr_cond_never_constant_expr) << AL; in checkFunctionConditionAttr()
685 S.Diag(PDiag.first, PDiag.second); in checkFunctionConditionAttr()
692 S.Diag(AL.getLoc(), diag::ext_clang_enable_if); in handleEnableIfAttr()
697 D->addAttr(::new (S.Context) EnableIfAttr(S.Context, AL, Cond, Msg)); in handleEnableIfAttr()
705 D->addAttr(EA); in handleErrorAttr()
712 : D->getDeclContext()->getRedeclContext(); in handleExcludeFromExplicitInstantiationAttr()
713 if (const auto *RD = dyn_cast<CXXRecordDecl>(PD); RD && RD->isLocalClass()) { in handleExcludeFromExplicitInstantiationAttr()
714 S.Diag(AL.getLoc(), in handleExcludeFromExplicitInstantiationAttr()
715 diag::warn_attribute_exclude_from_explicit_instantiation_local_class) in handleExcludeFromExplicitInstantiationAttr()
719 D->addAttr(::new (S.Context) in handleExcludeFromExplicitInstantiationAttr()
738 ClassType = MD->getParent(); in ArgumentDependenceChecker()
742 Parms.insert(FD->param_begin(), FD->param_end()); in ArgumentDependenceChecker()
752 assert(E->getType()->getPointeeCXXRecordDecl() == ClassType && in VisitCXXThisExpr()
759 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) in VisitDeclRefExpr()
774 if (!MethodDecl->isStatic()) { in handleDiagnoseAsBuiltinAttr()
775 S.Diag(AL.getLoc(), diag::err_attribute_no_member_function) << AL; in handleDiagnoseAsBuiltinAttr()
781 auto Union = AL.getArg(Index - 1); in handleDiagnoseAsBuiltinAttr()
783 return Union.get<Expr *>()->getBeginLoc(); in handleDiagnoseAsBuiltinAttr()
784 return Union.get<IdentifierLoc *>()->Loc; in handleDiagnoseAsBuiltinAttr()
787 S.Diag(Loc, diag::err_attribute_argument_n_type) << AL << Index << T; in handleDiagnoseAsBuiltinAttr()
790 FunctionDecl *AttrFD = [&]() -> FunctionDecl * { in handleDiagnoseAsBuiltinAttr()
796 return dyn_cast_if_present<FunctionDecl>(F->getFoundDecl()); in handleDiagnoseAsBuiltinAttr()
799 if (!AttrFD || !AttrFD->getBuiltinID(true)) { in handleDiagnoseAsBuiltinAttr()
804 if (AttrFD->getNumParams() != AL.getNumArgs() - 1) { in handleDiagnoseAsBuiltinAttr()
805 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments_for) in handleDiagnoseAsBuiltinAttr()
806 << AL << AttrFD << AttrFD->getNumParams(); in handleDiagnoseAsBuiltinAttr()
824 if (Index > DeclFD->getNumParams()) { in handleDiagnoseAsBuiltinAttr()
825 S.Diag(AL.getLoc(), diag::err_attribute_bounds_for_function) in handleDiagnoseAsBuiltinAttr()
826 << AL << Index << DeclFD << DeclFD->getNumParams(); in handleDiagnoseAsBuiltinAttr()
830 QualType T1 = AttrFD->getParamDecl(I - 1)->getType(); in handleDiagnoseAsBuiltinAttr()
831 QualType T2 = DeclFD->getParamDecl(Index - 1)->getType(); in handleDiagnoseAsBuiltinAttr()
835 S.Diag(IndexExpr->getBeginLoc(), diag::err_attribute_parameter_types) in handleDiagnoseAsBuiltinAttr()
840 Indices.push_back(Index - 1); in handleDiagnoseAsBuiltinAttr()
843 D->addAttr(::new (S.Context) DiagnoseAsBuiltinAttr( in handleDiagnoseAsBuiltinAttr()
848 S.Diag(AL.getLoc(), diag::ext_clang_diagnose_if); in handleDiagnoseIfAttr()
861 S.Diag(AL.getArgAsExpr(2)->getBeginLoc(), in handleDiagnoseIfAttr()
862 diag::err_diagnose_if_invalid_diagnostic_type); in handleDiagnoseIfAttr()
869 D->addAttr(::new (S.Context) DiagnoseIfAttr( in handleDiagnoseIfAttr()
886 if (const auto *NBA = D->getAttr<NoBuiltinAttr>()) in handleNoBuiltinAttr()
887 for (StringRef BuiltinName : NBA->builtinNames()) in handleNoBuiltinAttr()
903 S.Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name) in handleNoBuiltinAttr()
913 S.Diag(D->getLocation(), in handleNoBuiltinAttr()
914 diag::err_attribute_no_builtin_wildcard_or_builtin_name) in handleNoBuiltinAttr()
917 if (D->hasAttr<NoBuiltinAttr>()) in handleNoBuiltinAttr()
918 D->dropAttr<NoBuiltinAttr>(); in handleNoBuiltinAttr()
919 D->addAttr(::new (S.Context) in handleNoBuiltinAttr()
924 if (D->hasAttr<PassObjectSizeAttr>()) { in handlePassObjectSizeAttr()
925 S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL; in handlePassObjectSizeAttr()
938 S.Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range) in handlePassObjectSizeAttr()
939 << AL << 0 << 3 << E->getSourceRange(); in handlePassObjectSizeAttr()
944 // kindness to users, we allow the parameter to be non-const for declarations. in handlePassObjectSizeAttr()
947 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) { in handlePassObjectSizeAttr()
948 S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1; in handlePassObjectSizeAttr()
952 D->addAttr(::new (S.Context) PassObjectSizeAttr(S.Context, AL, (int)Type)); in handlePassObjectSizeAttr()
960 if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(), in handleConsumableAttr()
962 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL in handleConsumableAttr()
963 << IL->Ident; in handleConsumableAttr()
967 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleConsumableAttr()
972 D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState)); in handleConsumableAttr()
977 QualType ThisType = MD->getFunctionObjectParameterType(); in checkForConsumableClass()
979 if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) { in checkForConsumableClass()
980 if (!RD->hasAttr<ConsumableAttr>()) { in checkForConsumableClass()
981 S.Diag(AL.getLoc(), diag::warn_attr_on_unconsumable_class) << RD; in checkForConsumableClass()
1005 StateString = Ident->Ident->getName(); in handleCallableWhenAttr()
1006 Loc = Ident->Loc; in handleCallableWhenAttr()
1014 S.Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString; in handleCallableWhenAttr()
1021 D->addAttr(::new (S.Context) in handleCallableWhenAttr()
1030 StringRef StateString = Ident->Ident->getName(); in handleParamTypestateAttr()
1034 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) in handleParamTypestateAttr()
1039 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleParamTypestateAttr()
1047 //QualType ReturnType = cast<ParmVarDecl>(D)->getType(); in handleParamTypestateAttr()
1048 //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl(); in handleParamTypestateAttr()
1050 //if (!RD || !RD->hasAttr<ConsumableAttr>()) { in handleParamTypestateAttr()
1051 // S.Diag(AL.getLoc(), diag::warn_return_state_for_unconsumable_type) << in handleParamTypestateAttr()
1056 D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState)); in handleParamTypestateAttr()
1064 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(), in handleReturnTypestateAttr()
1066 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL in handleReturnTypestateAttr()
1067 << IL->Ident; in handleReturnTypestateAttr()
1071 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleReturnTypestateAttr()
1082 // ReturnType = Param->getType(); in handleReturnTypestateAttr()
1086 // ReturnType = Constructor->getFunctionObjectParameterType(); in handleReturnTypestateAttr()
1090 // ReturnType = cast<FunctionDecl>(D)->getCallResultType(); in handleReturnTypestateAttr()
1093 // const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl(); in handleReturnTypestateAttr()
1095 // if (!RD || !RD->hasAttr<ConsumableAttr>()) { in handleReturnTypestateAttr()
1096 // S.Diag(Attr.getLoc(), diag::warn_return_state_for_unconsumable_type) << in handleReturnTypestateAttr()
1101 D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState)); in handleReturnTypestateAttr()
1111 StringRef Param = Ident->Ident->getName(); in handleSetTypestateAttr()
1113 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL in handleSetTypestateAttr()
1118 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleSetTypestateAttr()
1123 D->addAttr(::new (S.Context) SetTypestateAttr(S.Context, AL, NewState)); in handleSetTypestateAttr()
1133 StringRef Param = Ident->Ident->getName(); in handleTestTypestateAttr()
1135 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL in handleTestTypestateAttr()
1140 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleTestTypestateAttr()
1145 D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState)); in handleTestTypestateAttr()
1155 TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); in handlePackedAttr()
1157 bool BitfieldByteAligned = (!FD->getType()->isDependentType() && in handlePackedAttr()
1158 !FD->getType()->isIncompleteType() && in handlePackedAttr()
1159 FD->isBitField() && in handlePackedAttr()
1160 S.Context.getTypeAlign(FD->getType()) <= 8); in handlePackedAttr()
1165 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_for_field_of_type) in handlePackedAttr()
1166 << AL << FD->getType(); in handlePackedAttr()
1168 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); in handlePackedAttr()
1172 S.Diag(AL.getLoc(), diag::warn_attribute_packed_for_bitfield); in handlePackedAttr()
1174 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL)); in handlePackedAttr()
1178 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL; in handlePackedAttr()
1183 ClassTemplateDecl *CTD = RD->getDescribedClassTemplate(); in handlePreferredName()
1192 if (!T.hasQualifiers() && T->isTypedefNameType()) { in handlePreferredName()
1196 T->getAsCXXRecordDecl())) { in handlePreferredName()
1197 Template = CTSD->getSpecializedTemplate(); in handlePreferredName()
1198 } else if (const auto *TST = T->getAs<TemplateSpecializationType>()) { in handlePreferredName()
1199 while (TST && TST->isTypeAlias()) in handlePreferredName()
1200 TST = TST->getAliasedType()->getAs<TemplateSpecializationType>(); in handlePreferredName()
1202 Template = TST->getTemplateName().getAsTemplateDecl(); in handlePreferredName()
1206 D->addAttr(::new (S.Context) PreferredNameAttr(S.Context, AL, TSI)); in handlePreferredName()
1211 S.Diag(AL.getLoc(), diag::err_attribute_preferred_name_arg_invalid) in handlePreferredName()
1213 if (const auto *TT = T->getAs<TypedefType>()) in handlePreferredName()
1214 S.Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at) in handlePreferredName()
1215 << TT->getDecl(); in handlePreferredName()
1220 if (T->isReferenceType()) in isValidPointerAttrType()
1228 if (const RecordType *UT = T->getAsUnionType()) { in isValidPointerAttrType()
1229 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) { in isValidPointerAttrType()
1230 RecordDecl *UD = UT->getDecl(); in isValidPointerAttrType()
1231 for (const auto *I : UD->fields()) { in isValidPointerAttrType()
1232 QualType QT = I->getType(); in isValidPointerAttrType()
1233 if (QT->isAnyPointerType() || QT->isBlockPointerType()) in isValidPointerAttrType()
1239 return T->isAnyPointerType() || T->isBlockPointerType(); in isValidPointerAttrType()
1248 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) in attrNonNullArgCheck()
1251 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) in attrNonNullArgCheck()
1270 Ex->getSourceRange(), in handleNonNullAttr()
1287 if (T->isDependentType() || S.isValidPointerAttrType(T)) in handleNonNullAttr()
1292 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_no_pointers); in handleNonNullAttr()
1298 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size)); in handleNonNullAttr()
1304 if (D->getFunctionType()) { in handleNonNullAttrParameter()
1307 S.Diag(AL.getLoc(), diag::warn_attribute_nonnull_parm_no_args) in handleNonNullAttrParameter()
1308 << D->getSourceRange(); in handleNonNullAttrParameter()
1314 if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(), in handleNonNullAttrParameter()
1315 D->getSourceRange())) in handleNonNullAttrParameter()
1318 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, nullptr, 0)); in handleNonNullAttrParameter()
1328 D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL)); in handleReturnsNonNullAttr()
1332 if (D->isInvalidDecl()) in handleNoEscapeAttr()
1336 QualType T = cast<ParmVarDecl>(D)->getType(); in handleNoEscapeAttr()
1338 S.Diag(AL.getLoc(), diag::warn_attribute_pointers_only) in handleNoEscapeAttr()
1343 D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL)); in handleNoEscapeAttr()
1365 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) in AddAssumeAlignedAttr()
1370 if (!E->isValueDependent()) { in AddAssumeAlignedAttr()
1372 if (!(I = E->getIntegerConstantExpr(Context))) { in AddAssumeAlignedAttr()
1374 Diag(AttrLoc, diag::err_attribute_argument_n_type) in AddAssumeAlignedAttr()
1376 << E->getSourceRange(); in AddAssumeAlignedAttr()
1378 Diag(AttrLoc, diag::err_attribute_argument_type) in AddAssumeAlignedAttr()
1380 << E->getSourceRange(); in AddAssumeAlignedAttr()
1384 if (!I->isPowerOf2()) { in AddAssumeAlignedAttr()
1385 Diag(AttrLoc, diag::err_alignment_not_power_of_two) in AddAssumeAlignedAttr()
1386 << E->getSourceRange(); in AddAssumeAlignedAttr()
1391 Diag(CI.getLoc(), diag::warn_assume_aligned_too_great) in AddAssumeAlignedAttr()
1395 if (OE && !OE->isValueDependent() && !OE->isIntegerConstantExpr(Context)) { in AddAssumeAlignedAttr()
1396 Diag(AttrLoc, diag::err_attribute_argument_n_type) in AddAssumeAlignedAttr()
1398 << OE->getSourceRange(); in AddAssumeAlignedAttr()
1402 D->addAttr(::new (Context) AssumeAlignedAttr(Context, CI, E, OE)); in AddAssumeAlignedAttr()
1412 if (!ResultType->isDependentType() && in AddAllocAlignAttr()
1414 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only) in AddAllocAlignAttr()
1426 if (!Ty->isDependentType() && !Ty->isIntegralType(Context) && in AddAllocAlignAttr()
1427 !Ty->isAlignValT()) { in AddAllocAlignAttr()
1428 Diag(ParamExpr->getBeginLoc(), diag::err_attribute_integers_only) in AddAllocAlignAttr()
1430 << FuncDecl->getParamDecl(Idx.getASTIndex())->getSourceRange(); in AddAllocAlignAttr()
1434 D->addAttr(::new (Context) AllocAlignAttr(Context, CI, Idx)); in AddAllocAlignAttr()
1458 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleOwnershipAttr()
1472 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL << 2; in handleOwnershipAttr()
1478 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 1; in handleOwnershipAttr()
1484 IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident; in handleOwnershipAttr()
1486 StringRef ModuleName = Module->getName(); in handleOwnershipAttr()
1500 int Err = -1; // No error in handleOwnershipAttr()
1504 if (!T->isAnyPointerType() && !T->isBlockPointerType()) in handleOwnershipAttr()
1508 if (!T->isIntegerType()) in handleOwnershipAttr()
1512 if (-1 != Err) { in handleOwnershipAttr()
1513 S.Diag(AL.getLoc(), diag::err_ownership_type) << AL << Err in handleOwnershipAttr()
1514 << Ex->getSourceRange(); in handleOwnershipAttr()
1519 for (const auto *I : D->specific_attrs<OwnershipAttr>()) { in handleOwnershipAttr()
1522 if (I->getOwnKind() != K && llvm::is_contained(I->args(), Idx)) { in handleOwnershipAttr()
1523 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) in handleOwnershipAttr()
1526 I->isRegularKeywordAttribute()); in handleOwnershipAttr()
1529 I->getOwnKind() == OwnershipAttr::Returns) { in handleOwnershipAttr()
1532 if (!llvm::is_contained(I->args(), Idx)) { in handleOwnershipAttr()
1533 S.Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch) in handleOwnershipAttr()
1534 << I->args_begin()->getSourceIndex(); in handleOwnershipAttr()
1535 if (I->args_size()) in handleOwnershipAttr()
1536 S.Diag(AL.getLoc(), diag::note_ownership_returns_index_mismatch) in handleOwnershipAttr()
1537 << Idx.getSourceIndex() << Ex->getSourceRange(); in handleOwnershipAttr()
1548 D->addAttr(::new (S.Context) in handleOwnershipAttr()
1555 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; in handleWeakRefAttr()
1569 const DeclContext *Ctx = D->getDeclContext()->getRedeclContext(); in handleWeakRefAttr()
1570 if (!Ctx->isFileContext()) { in handleWeakRefAttr()
1571 S.Diag(AL.getLoc(), diag::err_attribute_weakref_not_global_context) in handleWeakRefAttr()
1598 // FIXME: it would be good for us to keep the WeakRefAttr as-written instead in handleWeakRefAttr()
1605 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str)); in handleWeakRefAttr()
1607 D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL)); in handleWeakRefAttr()
1612 // https://github.com/llvm/llvm-project/issues/88825). This should handle the
1629 if (MC->shouldMangleDeclName(ND)) { in markUsedForAliasOrIfunc()
1632 MC->mangleName(GlobalDecl(ND), Out); in markUsedForAliasOrIfunc()
1634 Name = ND->getIdentifier()->getName(); in markUsedForAliasOrIfunc()
1637 ND->markUsed(S.Context); in markUsedForAliasOrIfunc()
1649 if (FD->isThisDeclarationADefinition()) { in handleIFuncAttr()
1650 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 1; in handleIFuncAttr()
1655 D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str)); in handleIFuncAttr()
1664 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_darwin); in handleAliasAttr()
1669 CudaVersion Version = in handleAliasAttr() local
1671 if (Version != CudaVersion::UNKNOWN && Version < CudaVersion::CUDA_100) in handleAliasAttr()
1672 S.Diag(AL.getLoc(), diag::err_alias_not_supported_on_nvptx); in handleAliasAttr()
1677 if (FD->isThisDeclarationADefinition()) { in handleAliasAttr()
1678 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << FD << 0; in handleAliasAttr()
1683 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) { in handleAliasAttr()
1684 S.Diag(AL.getLoc(), diag::err_alias_is_definition) << VD << 0; in handleAliasAttr()
1690 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str)); in handleAliasAttr()
1701 if (Model != "global-dynamic" && Model != "local-dynamic" in handleTLSModelAttr()
1702 && Model != "initial-exec" && Model != "local-exec") { in handleTLSModelAttr()
1703 S.Diag(LiteralLoc, diag::err_attr_tlsmodel_arg); in handleTLSModelAttr()
1707 D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model)); in handleTLSModelAttr()
1712 if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) { in handleRestrictAttr()
1713 D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL)); in handleRestrictAttr()
1717 S.Diag(AL.getLoc(), diag::warn_attribute_return_pointers_only) in handleRestrictAttr()
1728 if (const auto *Other = D->getAttr<CPUDispatchAttr>()) { in handleCPUSpecificAttr()
1729 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL; in handleCPUSpecificAttr()
1730 S.Diag(Other->getLocation(), diag::note_conflicting_attribute); in handleCPUSpecificAttr()
1737 if (const auto *Other = D->getAttr<CPUSpecificAttr>()) { in handleCPUSpecificAttr()
1738 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL; in handleCPUSpecificAttr()
1739 S.Diag(Other->getLocation(), diag::note_conflicting_attribute); in handleCPUSpecificAttr()
1747 if (MD->getParent()->isLambda()) { in handleCPUSpecificAttr()
1748 S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL; in handleCPUSpecificAttr()
1759 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleCPUSpecificAttr()
1765 StringRef CPUName = CPUArg->Ident->getName().trim(); in handleCPUSpecificAttr()
1768 S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value) in handleCPUSpecificAttr()
1776 Target.CPUSpecificManglingCharacter(Cur->getName()); in handleCPUSpecificAttr()
1778 S.Diag(AL.getLoc(), diag::warn_multiversion_duplicate_entries); in handleCPUSpecificAttr()
1781 CPUs.push_back(CPUArg->Ident); in handleCPUSpecificAttr()
1784 FD->setIsMultiVersion(true); in handleCPUSpecificAttr()
1786 D->addAttr(::new (S.Context) in handleCPUSpecificAttr()
1789 D->addAttr(::new (S.Context) in handleCPUSpecificAttr()
1795 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) in handleCommonAttr()
1800 D->addAttr(::new (S.Context) CommonAttr(S.Context, AL)); in handleCommonAttr()
1809 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_on_arch) in handleNakedAttr()
1817 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type_str) in handleNakedAttr()
1818 << AL << AL.isRegularKeywordAttribute() << "non-member functions"; in handleNakedAttr()
1823 D->addAttr(::new (S.Context) NakedAttr(S.Context, AL)); in handleNakedAttr()
1830 S.Diag(Attrs.getLoc(), diag::warn_attribute_wrong_decl_type) in handleNoReturnAttr()
1836 D->addAttr(::new (S.Context) NoReturnAttr(S.Context, Attrs)); in handleNoReturnAttr()
1849 S.Diag(A.getLoc(), diag::warn_deprecated_noreturn_spelling) << A.getRange(); in handleStandardNoReturnAttr()
1851 D->addAttr(::new (S.Context) CXX11NoReturnAttr(S.Context, A)); in handleStandardNoReturnAttr()
1856 S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored); in handleNoCfCheckAttr()
1873 Diag(AL.getLoc(), AL.isRegularKeywordAttribute() in CheckAttrTarget()
1874 ? diag::err_keyword_not_supported_on_target in CheckAttrTarget()
1875 : diag::warn_unknown_attribute_ignored) in CheckAttrTarget()
1890 if (!VD || (!VD->getType()->isBlockPointerType() && in handleAnalyzerNoReturnAttr()
1891 !VD->getType()->isFunctionPointerType())) { in handleAnalyzerNoReturnAttr()
1892 S.Diag(AL.getLoc(), AL.isStandardAttributeSyntax() in handleAnalyzerNoReturnAttr()
1893 ? diag::err_attribute_wrong_decl_type in handleAnalyzerNoReturnAttr()
1894 : diag::warn_attribute_wrong_decl_type) in handleAnalyzerNoReturnAttr()
1901 D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(S.Context, AL)); in handleAnalyzerNoReturnAttr()
1904 // PS3 PPU-specific.
1930 if (VecReturnAttr *A = D->getAttr<VecReturnAttr>()) { in handleVecReturnAttr()
1931 S.Diag(AL.getLoc(), diag::err_repeat_attribute) << A; in handleVecReturnAttr()
1939 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member); in handleVecReturnAttr()
1943 if (!cast<CXXRecordDecl>(R)->isPOD()) { in handleVecReturnAttr()
1944 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_pod_record); in handleVecReturnAttr()
1948 for (const auto *I : R->fields()) { in handleVecReturnAttr()
1949 if ((count == 1) || !I->getType()->isVectorType()) { in handleVecReturnAttr()
1950 S.Diag(AL.getLoc(), diag::err_attribute_vecreturn_only_vector_member); in handleVecReturnAttr()
1956 D->addAttr(::new (S.Context) VecReturnAttr(S.Context, AL)); in handleVecReturnAttr()
1964 if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) { in handleDependencyAttr()
1965 S.Diag(AL.getLoc(), in handleDependencyAttr()
1966 diag::err_carries_dependency_param_not_function_decl); in handleDependencyAttr()
1971 D->addAttr(::new (S.Context) CarriesDependencyAttr(S.Context, AL)); in handleDependencyAttr()
1980 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; in handleUnusedAttr()
1982 D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL)); in handleUnusedAttr()
1988 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported); in handleConstructorAttr()
1995 D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority)); in handleConstructorAttr()
2004 D->addAttr(::new (S.Context) DestructorAttr(S.Context, AL, priority)); in handleDestructorAttr()
2014 D->addAttr(::new (S.Context) AttrTy(S.Context, AL, Str)); in handleAttrWithMessage()
2023 = AvailabilityAttr::getPrettyPlatformName(Platform->getName()); in checkAvailabilityAttr()
2025 PlatformName = Platform->getName(); in checkAvailabilityAttr()
2031 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) in checkAvailabilityAttr()
2039 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) in checkAvailabilityAttr()
2047 S.Diag(Range.getBegin(), diag::warn_availability_version_ordering) in checkAvailabilityAttr()
2058 /// If either version tuple is empty, then they are assumed to match. If
2098 if (D->hasAttrs()) { in mergeAvailabilityAttr()
2099 AttrVec &Attrs = D->getAttrs(); in mergeAvailabilityAttr()
2107 IdentifierInfo *OldPlatform = OldAA->getPlatform(); in mergeAvailabilityAttr()
2113 IdentifierInfo *OldEnvironment = OldAA->getEnvironment(); in mergeAvailabilityAttr()
2122 if (OldAA->getPriority() < Priority) in mergeAvailabilityAttr()
2128 if (OldAA->getPriority() > Priority) { in mergeAvailabilityAttr()
2130 --e; in mergeAvailabilityAttr()
2135 VersionTuple OldIntroduced = OldAA->getIntroduced(); in mergeAvailabilityAttr()
2136 VersionTuple OldDeprecated = OldAA->getDeprecated(); in mergeAvailabilityAttr()
2137 VersionTuple OldObsoleted = OldAA->getObsoleted(); in mergeAvailabilityAttr()
2138 bool OldIsUnavailable = OldAA->getUnavailable(); in mergeAvailabilityAttr()
2146 int Which = -1; in mergeAvailabilityAttr()
2163 if (Which == -1) { in mergeAvailabilityAttr()
2164 Diag(OldAA->getLocation(), in mergeAvailabilityAttr()
2165 diag::warn_mismatched_availability_override_unavail) in mergeAvailabilityAttr()
2166 << AvailabilityAttr::getPrettyPlatformName(Platform->getName()) in mergeAvailabilityAttr()
2177 Diag(OldAA->getLocation(), in mergeAvailabilityAttr()
2178 diag::warn_mismatched_availability_override) in mergeAvailabilityAttr()
2180 << AvailabilityAttr::getPrettyPlatformName(Platform->getName()) in mergeAvailabilityAttr()
2185 Diag(CI.getLoc(), diag::note_overridden_method); in mergeAvailabilityAttr()
2187 Diag(CI.getLoc(), diag::note_protocol_method); in mergeAvailabilityAttr()
2189 Diag(OldAA->getLocation(), diag::warn_mismatched_availability); in mergeAvailabilityAttr()
2190 Diag(CI.getLoc(), diag::note_previous_attribute); in mergeAvailabilityAttr()
2194 --e; in mergeAvailabilityAttr()
2209 if (checkAvailabilityAttr(*this, OldAA->getRange(), Platform, in mergeAvailabilityAttr()
2213 --e; in mergeAvailabilityAttr()
2238 Avail->setImplicit(Implicit); in mergeAvailabilityAttr()
2247 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using) in handleAvailabilityAttr()
2256 IdentifierInfo *II = Platform->Ident; in handleAvailabilityAttr()
2257 if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty()) in handleAvailabilityAttr()
2258 S.Diag(Platform->Loc, diag::warn_availability_unknown_platform) in handleAvailabilityAttr()
2259 << Platform->Ident; in handleAvailabilityAttr()
2272 Str = SE->getString(); in handleAvailabilityAttr()
2276 Replacement = SE->getString(); in handleAvailabilityAttr()
2278 if (II->isStr("swift")) { in handleAvailabilityAttr()
2281 S.Diag(AL.getLoc(), in handleAvailabilityAttr()
2282 diag::warn_availability_swift_unavailable_deprecated_only); in handleAvailabilityAttr()
2287 if (II->isStr("fuchsia")) { in handleAvailabilityAttr()
2289 if ((Min = Introduced.Version.getMinor()) || in handleAvailabilityAttr()
2290 (Sub = Introduced.Version.getSubminor())) { in handleAvailabilityAttr()
2291 S.Diag(AL.getLoc(), diag::warn_availability_fuchsia_unavailable_minor); in handleAvailabilityAttr()
2297 S.Diag(AL.getStrictLoc(), diag::err_availability_unexpected_parameter) in handleAvailabilityAttr()
2308 IIEnvironment = EnvironmentLoc->Ident; in handleAvailabilityAttr()
2310 EnvironmentLoc->Ident->getName()) == in handleAvailabilityAttr()
2312 S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment) in handleAvailabilityAttr()
2313 << EnvironmentLoc->Ident; in handleAvailabilityAttr()
2315 S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter) in handleAvailabilityAttr()
2321 ND, AL, II, false /*Implicit*/, Introduced.Version, Deprecated.Version, in handleAvailabilityAttr()
2322 Obsoleted.Version, IsUnavailable, Str, IsStrict, Replacement, in handleAvailabilityAttr()
2325 D->addAttr(NewAttr); in handleAvailabilityAttr()
2331 if (II->getName() == "ios") in handleAvailabilityAttr()
2333 else if (II->getName() == "ios_app_extension") in handleAvailabilityAttr()
2339 SDKInfo ? SDKInfo->getVersionMapping( in handleAvailabilityAttr()
2344 [IOSToWatchOSMapping](VersionTuple Version) -> VersionTuple { in handleAvailabilityAttr() argument
2345 if (Version.empty()) in handleAvailabilityAttr()
2346 return Version; in handleAvailabilityAttr()
2350 if (auto MappedVersion = IOSToWatchOSMapping->map( in handleAvailabilityAttr()
2351 Version, MinimumWatchOSVersion, std::nullopt)) { in handleAvailabilityAttr()
2356 auto Major = Version.getMajor(); in handleAvailabilityAttr()
2357 auto NewMajor = Major >= 9 ? Major - 7 : 0; in handleAvailabilityAttr()
2359 if (Version.getMinor()) { in handleAvailabilityAttr()
2360 if (Version.getSubminor()) in handleAvailabilityAttr()
2361 return VersionTuple(NewMajor, *Version.getMinor(), in handleAvailabilityAttr()
2362 *Version.getSubminor()); in handleAvailabilityAttr()
2364 return VersionTuple(NewMajor, *Version.getMinor()); in handleAvailabilityAttr()
2372 auto NewIntroduced = adjustWatchOSVersion(Introduced.Version); in handleAvailabilityAttr()
2373 auto NewDeprecated = adjustWatchOSVersion(Deprecated.Version); in handleAvailabilityAttr()
2374 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.Version); in handleAvailabilityAttr()
2382 D->addAttr(NewAttr); in handleAvailabilityAttr()
2388 if (II->getName() == "ios") in handleAvailabilityAttr()
2390 else if (II->getName() == "ios_app_extension") in handleAvailabilityAttr()
2396 SDKInfo ? SDKInfo->getVersionMapping( in handleAvailabilityAttr()
2401 [IOSToTvOSMapping](VersionTuple Version) -> VersionTuple { in handleAvailabilityAttr() argument
2402 if (Version.empty()) in handleAvailabilityAttr()
2403 return Version; in handleAvailabilityAttr()
2406 if (auto MappedVersion = IOSToTvOSMapping->map( in handleAvailabilityAttr()
2407 Version, VersionTuple(0, 0), std::nullopt)) { in handleAvailabilityAttr()
2411 return Version; in handleAvailabilityAttr()
2414 auto NewIntroduced = AdjustTvOSVersion(Introduced.Version); in handleAvailabilityAttr()
2415 auto NewDeprecated = AdjustTvOSVersion(Deprecated.Version); in handleAvailabilityAttr()
2416 auto NewObsoleted = AdjustTvOSVersion(Obsoleted.Version); in handleAvailabilityAttr()
2424 D->addAttr(NewAttr); in handleAvailabilityAttr()
2436 if (II->getName() == "ios") in handleAvailabilityAttr()
2438 else if (II->getName() == "ios_app_extension") in handleAvailabilityAttr()
2446 return VersionTuple(13, 1); // The min Mac Catalyst version is 13.1. in handleAvailabilityAttr()
2451 MinMacCatalystVersion(Introduced.Version), in handleAvailabilityAttr()
2452 MinMacCatalystVersion(Deprecated.Version), in handleAvailabilityAttr()
2453 MinMacCatalystVersion(Obsoleted.Version), IsUnavailable, Str, in handleAvailabilityAttr()
2457 D->addAttr(NewAttr); in handleAvailabilityAttr()
2458 } else if (II->getName() == "macos" && GetSDKInfo() && in handleAvailabilityAttr()
2459 (!Introduced.Version.empty() || !Deprecated.Version.empty() || in handleAvailabilityAttr()
2460 !Obsoleted.Version.empty())) { in handleAvailabilityAttr()
2462 GetSDKInfo()->getVersionMapping( in handleAvailabilityAttr()
2470 [&](const VersionTuple &V) -> std::optional<VersionTuple> { in handleAvailabilityAttr()
2476 // The minimum iosmac version is 13.1 in handleAvailabilityAttr()
2477 return MacOStoMacCatalystMapping->map(V, VersionTuple(13, 1), in handleAvailabilityAttr()
2481 RemapMacOSVersion(Introduced.Version), in handleAvailabilityAttr()
2483 RemapMacOSVersion(Deprecated.Version), in handleAvailabilityAttr()
2485 RemapMacOSVersion(Obsoleted.Version); in handleAvailabilityAttr()
2488 [](const std::optional<VersionTuple> &V) -> VersionTuple { in handleAvailabilityAttr()
2501 D->addAttr(NewAttr); in handleAvailabilityAttr()
2515 Language = SE->getString(); in handleExternalSourceSymbolAttr()
2518 DefinedIn = SE->getString(); in handleExternalSourceSymbolAttr()
2522 USR = SE->getString(); in handleExternalSourceSymbolAttr()
2524 D->addAttr(::new (S.Context) ExternalSourceSymbolAttr( in handleExternalSourceSymbolAttr()
2531 T *existingAttr = D->getAttr<T>(); in mergeVisibilityAttr()
2533 typename T::VisibilityType existingValue = existingAttr->getVisibility(); in mergeVisibilityAttr()
2536 S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility); in mergeVisibilityAttr()
2537 S.Diag(CI.getLoc(), diag::note_previous_attribute); in mergeVisibilityAttr()
2538 D->dropAttr<T>(); in mergeVisibilityAttr()
2559 S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL; in handleVisibilityAttr()
2566 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type) in handleVisibilityAttr()
2579 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL in handleVisibilityAttr()
2588 S.Diag(AL.getLoc(), diag::warn_attribute_protected_visibility); in handleVisibilityAttr()
2600 D->addAttr(newAttr); in handleVisibilityAttr()
2608 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) { in handleSentinelAttr()
2609 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleSentinelAttr()
2610 << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange(); in handleSentinelAttr()
2614 if (Idx->isSigned() && Idx->isNegative()) { in handleSentinelAttr()
2615 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_less_than_zero) in handleSentinelAttr()
2616 << E->getSourceRange(); in handleSentinelAttr()
2620 sentinel = Idx->getZExtValue(); in handleSentinelAttr()
2627 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) { in handleSentinelAttr()
2628 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleSentinelAttr()
2629 << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange(); in handleSentinelAttr()
2632 nullPos = Idx->getZExtValue(); in handleSentinelAttr()
2634 if ((Idx->isSigned() && Idx->isNegative()) || nullPos > 1) { in handleSentinelAttr()
2637 S.Diag(AL.getLoc(), diag::err_attribute_sentinel_not_zero_or_one) in handleSentinelAttr()
2638 << E->getSourceRange(); in handleSentinelAttr()
2644 const FunctionType *FT = FD->getType()->castAs<FunctionType>(); in handleSentinelAttr()
2646 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_named_arguments); in handleSentinelAttr()
2650 if (!cast<FunctionProtoType>(FT)->isVariadic()) { in handleSentinelAttr()
2651 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; in handleSentinelAttr()
2655 if (!MD->isVariadic()) { in handleSentinelAttr()
2656 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; in handleSentinelAttr()
2660 if (!BD->isVariadic()) { in handleSentinelAttr()
2661 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1; in handleSentinelAttr()
2665 QualType Ty = V->getType(); in handleSentinelAttr()
2666 if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) { in handleSentinelAttr()
2667 const FunctionType *FT = Ty->isFunctionPointerType() in handleSentinelAttr()
2668 ? D->getFunctionType() in handleSentinelAttr()
2669 : Ty->castAs<BlockPointerType>() in handleSentinelAttr()
2670 ->getPointeeType() in handleSentinelAttr()
2671 ->castAs<FunctionType>(); in handleSentinelAttr()
2672 if (!cast<FunctionProtoType>(FT)->isVariadic()) { in handleSentinelAttr()
2673 int m = Ty->isFunctionPointerType() ? 0 : 1; in handleSentinelAttr()
2674 S.Diag(AL.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m; in handleSentinelAttr()
2678 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in handleSentinelAttr()
2684 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in handleSentinelAttr()
2689 D->addAttr(::new (S.Context) SentinelAttr(S.Context, AL, sentinel, nullPos)); in handleSentinelAttr()
2693 if (D->getFunctionType() && in handleWarnUnusedResult()
2694 D->getFunctionType()->getReturnType()->isVoidType() && in handleWarnUnusedResult()
2696 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 0; in handleWarnUnusedResult()
2700 if (MD->getReturnType()->isVoidType()) { in handleWarnUnusedResult()
2701 S.Diag(AL.getLoc(), diag::warn_attribute_void_function_method) << AL << 1; in handleWarnUnusedResult()
2710 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type_str) in handleWarnUnusedResult()
2722 S.Diag(AL.getLoc(), diag::ext_cxx20_attr) << AL; in handleWarnUnusedResult()
2731 S.Diag(AL.getLoc(), diag::ext_cxx17_attr) << AL; in handleWarnUnusedResult()
2737 S.Diag(AL.getLoc(), diag::warn_unused_result_typedef_unsupported_spelling) in handleWarnUnusedResult()
2742 D->addAttr(::new (S.Context) WarnUnusedResultAttr(S.Context, AL, Str)); in handleWarnUnusedResult()
2748 if (!D->canBeWeakImported(isDef)) { in handleWeakImportAttr()
2750 S.Diag(AL.getLoc(), diag::warn_attribute_invalid_on_definition) in handleWeakImportAttr()
2757 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in handleWeakImportAttr()
2763 D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL)); in handleWeakImportAttr()
2776 S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero) in handleWorkGroupSize()
2777 << AL << E->getSourceRange(); in handleWorkGroupSize()
2782 WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>(); in handleWorkGroupSize()
2783 if (Existing && !(Existing->getXDim() == WGSize[0] && in handleWorkGroupSize()
2784 Existing->getYDim() == WGSize[1] && in handleWorkGroupSize()
2785 Existing->getZDim() == WGSize[2])) in handleWorkGroupSize()
2786 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; in handleWorkGroupSize()
2788 D->addAttr(::new (S.Context) in handleWorkGroupSize()
2794 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; in handleVecTypeHint()
2802 if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() && in handleVecTypeHint()
2803 (ParmType->isBooleanType() || in handleVecTypeHint()
2804 !ParmType->isIntegralType(S.getASTContext()))) { in handleVecTypeHint()
2805 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << 2 << AL; in handleVecTypeHint()
2809 if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) { in handleVecTypeHint()
2810 if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) { in handleVecTypeHint()
2811 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; in handleVecTypeHint()
2816 D->addAttr(::new (S.Context) VecTypeHintAttr(S.Context, AL, ParmTSI)); in handleVecTypeHint()
2825 FD->isFunctionTemplateSpecialization()) in mergeSectionAttr()
2828 if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) { in mergeSectionAttr()
2829 if (ExistingAttr->getName() == Name) in mergeSectionAttr()
2831 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) in mergeSectionAttr()
2833 Diag(CI.getLoc(), diag::note_previous_attribute); in mergeSectionAttr()
2853 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) in checkSectionName()
2873 D->addAttr(NewAttr); in handleSectionAttr()
2876 S.UnifySection(NewAttr->getName(), in handleSectionAttr()
2891 S.Diag(LiteralLoc, diag::err_attr_codemodel_arg) << Str; in handleCodeModelAttr()
2895 D->addAttr(::new (S.Context) CodeModelAttr(S.Context, AL, CM)); in handleCodeModelAttr()
2903 S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) in checkCodeSegName()
2904 << toString(std::move(E)) << 0 /*'code-seg'*/; in checkCodeSegName()
2916 if (FD->isFunctionTemplateSpecialization()) in mergeCodeSegAttr()
2919 if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) { in mergeCodeSegAttr()
2920 if (ExistingAttr->getName() == Name) in mergeCodeSegAttr()
2922 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) in mergeCodeSegAttr()
2924 Diag(CI.getLoc(), diag::note_previous_attribute); in mergeCodeSegAttr()
2937 if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) { in handleCodeSegAttr()
2938 if (!ExistingAttr->isImplicit()) { in handleCodeSegAttr()
2939 S.Diag(AL.getLoc(), in handleCodeSegAttr()
2940 ExistingAttr->getName() == Str in handleCodeSegAttr()
2941 ? diag::warn_duplicate_codeseg_attribute in handleCodeSegAttr()
2942 : diag::err_conflicting_codeseg_attribute); in handleCodeSegAttr()
2945 D->dropAttr<CodeSegAttr>(); in handleCodeSegAttr()
2948 D->addAttr(CSA); in handleCodeSegAttr()
2956 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
2962 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
2970 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
2975 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
2980 return Diag(LiteralLoc, diag::err_duplicate_target_attribute) in checkTargetAttr()
2984 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
2988 auto CurFeature = StringRef(Feature).drop_front(); // remove + or -. in checkTargetAttr()
2990 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
3001 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetAttr()
3002 << Unsupported << None << "branch-protection" << Target; in checkTargetAttr()
3003 return Diag(LiteralLoc, diag::err_invalid_branch_protection_spec) in checkTargetAttr()
3007 Diag(LiteralLoc, diag::warn_unsupported_branch_protection_spec) << DiagMsg; in checkTargetAttr()
3024 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetVersionAttr()
3038 D->addAttr(NewAttr); in handleTargetVersionAttr()
3049 D->addAttr(NewAttr); in handleTargetAttr()
3063 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3071 Literal->getLocationOfByte(Cur.data() - Literal->getString().data(), in checkTargetClonesAttrString()
3077 return Diag(CurLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3086 Diag(CurLoc, diag::warn_target_clone_duplicate_options); in checkTargetClonesAttrString()
3096 Diag(CurLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3113 Diag(CurLoc, diag::warn_target_clone_duplicate_options); in checkTargetClonesAttrString()
3117 Diag(CurLoc, diag::warn_target_clone_no_impact_options); in checkTargetClonesAttrString()
3127 Cur.drop_front(sizeof("arch=") - 1))) in checkTargetClonesAttrString()
3128 return Diag(CurLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3129 << Unsupported << CPU << Cur.drop_front(sizeof("arch=") - 1) in checkTargetClonesAttrString()
3135 return Diag(CurLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3138 Diag(CurLoc, diag::warn_target_clone_duplicate_options); in checkTargetClonesAttrString()
3144 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute) in checkTargetClonesAttrString()
3156 if (const auto *Other = D->getAttr<TargetClonesAttr>()) { in handleTargetClonesAttr()
3157 S.Diag(AL.getLoc(), diag::err_disallowed_duplicate_attribute) << AL; in handleTargetClonesAttr()
3158 S.Diag(Other->getLocation(), diag::note_conflicting_attribute); in handleTargetClonesAttr()
3174 cast<StringLiteral>(AL.getArgAsExpr(I)->IgnoreParenCasts()), D, in handleTargetClonesAttr()
3182 S.Diag(AL.getLoc(), diag::warn_target_clone_mixed_values); in handleTargetClonesAttr()
3191 S.Diag(AL.getLoc(), diag::err_target_clone_must_have_default); in handleTargetClonesAttr()
3198 if (MD->getParent()->isLambda()) { in handleTargetClonesAttr()
3199 S.Diag(D->getLocation(), diag::err_multiversion_doesnt_support) in handleTargetClonesAttr()
3206 // No multiversion if we have default version only. in handleTargetClonesAttr()
3210 cast<FunctionDecl>(D)->setIsMultiVersion(); in handleTargetClonesAttr()
3213 D->addAttr(NewAttr); in handleTargetClonesAttr()
3224 MinVectorWidthAttr *Existing = D->getAttr<MinVectorWidthAttr>(); in handleMinVectorWidthAttr()
3225 if (Existing && Existing->getVectorWidth() != VecWidth) { in handleMinVectorWidthAttr()
3226 S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL; in handleMinVectorWidthAttr()
3230 D->addAttr(::new (S.Context) MinVectorWidthAttr(S.Context, AL, VecWidth)); in handleMinVectorWidthAttr()
3235 SourceLocation Loc = E->getExprLoc(); in handleCleanupAttr()
3242 if (DRE->hasQualifier()) in handleCleanupAttr()
3243 S.Diag(Loc, diag::warn_cleanup_ext); in handleCleanupAttr()
3244 FD = dyn_cast<FunctionDecl>(DRE->getDecl()); in handleCleanupAttr()
3245 NI = DRE->getNameInfo(); in handleCleanupAttr()
3247 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1 in handleCleanupAttr()
3252 if (ULE->hasExplicitTemplateArgs()) in handleCleanupAttr()
3253 S.Diag(Loc, diag::warn_cleanup_ext); in handleCleanupAttr()
3255 NI = ULE->getNameInfo(); in handleCleanupAttr()
3257 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2 in handleCleanupAttr()
3259 if (ULE->getType() == S.Context.OverloadTy) in handleCleanupAttr()
3264 S.Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0; in handleCleanupAttr()
3268 if (FD->getNumParams() != 1) { in handleCleanupAttr()
3269 S.Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg) in handleCleanupAttr()
3276 QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType()); in handleCleanupAttr()
3277 QualType ParamTy = FD->getParamDecl(0)->getType(); in handleCleanupAttr()
3278 if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(), in handleCleanupAttr()
3280 S.Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type) in handleCleanupAttr()
3288 S.Context, NestedNameSpecifierLoc{}, FD->getLocation(), VD, false, in handleCleanupAttr()
3289 DeclarationNameInfo{VD->getDeclName(), VD->getLocation()}, VD->getType(), in handleCleanupAttr()
3296 S.Context.getPointerType(VD->getType()), VK_PRValue, OK_Ordinary, Loc, in handleCleanupAttr()
3305 FD->getType()->getAs<FunctionProtoType>())) { in handleCleanupAttr()
3309 D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD)); in handleCleanupAttr()
3315 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleEnumExtensibilityAttr()
3321 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; in handleEnumExtensibilityAttr()
3322 if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(), in handleEnumExtensibilityAttr()
3324 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; in handleEnumExtensibilityAttr()
3328 D->addAttr(::new (S.Context) in handleEnumExtensibilityAttr()
3333 /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
3345 (!Ty->isPointerType() || in handleFormatArgAttr()
3346 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) { in handleFormatArgAttr()
3347 S.Diag(AL.getLoc(), diag::err_format_attribute_not) in handleFormatArgAttr()
3348 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0); in handleFormatArgAttr()
3353 auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl(); in handleFormatArgAttr()
3354 if (Ty->getAs<TypedefType>() == Instancetype) in handleFormatArgAttr()
3356 if (auto *Interface = OMD->getClassInterface()) in handleFormatArgAttr()
3358 QualType(Interface->getTypeForDecl(), 0)); in handleFormatArgAttr()
3361 (!Ty->isPointerType() || in handleFormatArgAttr()
3362 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) { in handleFormatArgAttr()
3363 S.Diag(AL.getLoc(), diag::err_format_attribute_result_not) in handleFormatArgAttr()
3365 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0); in handleFormatArgAttr()
3369 D->addAttr(::new (S.Context) FormatArgAttr(S.Context, AL, Idx)); in handleFormatArgAttr()
3381 /// getFormatAttrKind - Map from format attribute names to supported format
3403 /// http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
3406 S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL; in handleInitPriorityAttr()
3411 S.Diag(AL.getLoc(), diag::err_hlsl_init_priority_unsupported); in handleInitPriorityAttr()
3416 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr); in handleInitPriorityAttr()
3420 QualType T = cast<VarDecl>(D)->getType(); in handleInitPriorityAttr()
3423 if (!T->getAs<RecordType>()) { in handleInitPriorityAttr()
3424 S.Diag(AL.getLoc(), diag::err_init_priority_object_attr); in handleInitPriorityAttr()
3441 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range) in handleInitPriorityAttr()
3442 << E->getSourceRange() << AL << 101 << 65535; in handleInitPriorityAttr()
3446 D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum)); in handleInitPriorityAttr()
3451 if (const auto *EA = D->getAttr<ErrorAttr>()) { in mergeErrorAttr()
3455 bool Match = (EA->isError() && NewAttr == "error") || in mergeErrorAttr()
3456 (EA->isWarning() && NewAttr == "warning"); in mergeErrorAttr()
3458 Diag(EA->getLocation(), diag::err_attributes_are_not_compatible) in mergeErrorAttr()
3461 EA->isRegularKeywordAttribute()); in mergeErrorAttr()
3462 Diag(CI.getLoc(), diag::note_conflicting_attribute); in mergeErrorAttr()
3465 if (EA->getUserDiagnostic() != NewUserDiagnostic) { in mergeErrorAttr()
3466 Diag(CI.getLoc(), diag::warn_duplicate_attribute) << EA; in mergeErrorAttr()
3467 Diag(EA->getLoc(), diag::note_previous_attribute); in mergeErrorAttr()
3469 D->dropAttr<ErrorAttr>(); in mergeErrorAttr()
3478 for (auto *F : D->specific_attrs<FormatAttr>()) { in mergeFormatAttr()
3479 if (F->getType() == Format && in mergeFormatAttr()
3480 F->getFormatIdx() == FormatIdx && in mergeFormatAttr()
3481 F->getFirstArg() == FirstArg) { in mergeFormatAttr()
3484 if (F->getLocation().isInvalid()) in mergeFormatAttr()
3485 F->setRange(CI.getRange()); in mergeFormatAttr()
3494 /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
3497 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleFormatAttr()
3507 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; in handleFormatAttr()
3508 StringRef Format = II->getName(); in handleFormatAttr()
3522 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) in handleFormatAttr()
3523 << AL << II->getName(); in handleFormatAttr()
3534 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleFormatAttr()
3535 << AL << 2 << IdxExpr->getSourceRange(); in handleFormatAttr()
3540 unsigned ArgIdx = Idx - 1; in handleFormatAttr()
3544 S.Diag(AL.getLoc(), in handleFormatAttr()
3545 diag::err_format_attribute_implicit_this_format_string) in handleFormatAttr()
3546 << IdxExpr->getSourceRange(); in handleFormatAttr()
3549 ArgIdx--; in handleFormatAttr()
3556 (!Ty->isPointerType() || in handleFormatAttr()
3557 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) { in handleFormatAttr()
3558 S.Diag(AL.getLoc(), diag::err_format_attribute_not) in handleFormatAttr()
3559 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, ArgIdx); in handleFormatAttr()
3574 S.Diag(AL.getLoc(), diag::err_format_strftime_third_parameter) in handleFormatAttr()
3575 << FirstArgExpr->getSourceRange() in handleFormatAttr()
3576 << FixItHint::CreateReplacement(FirstArgExpr->getSourceRange(), "0"); in handleFormatAttr()
3583 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleFormatAttr()
3584 << AL << 3 << FirstArgExpr->getSourceRange() in handleFormatAttr()
3585 << FixItHint::CreateReplacement(FirstArgExpr->getSourceRange(), in handleFormatAttr()
3591 S.Diag(D->getLocation(), diag::warn_gcc_requires_variadic_function) << AL; in handleFormatAttr()
3596 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleFormatAttr()
3597 << AL << 3 << FirstArgExpr->getSourceRange(); in handleFormatAttr()
3605 D->addAttr(NewAttr); in handleFormatAttr()
3612 S.Diag(AL.getLoc(), diag::err_callback_attribute_no_callee) in handleCallbackAttr()
3620 FunctionDecl *FD = D->getAsFunction(); in handleCallbackAttr()
3624 NameIdxMapping["__"] = -1; in handleCallbackAttr()
3629 for (const ParmVarDecl *PVD : FD->parameters()) in handleCallbackAttr()
3630 NameIdxMapping[PVD->getName()] = Idx++; in handleCallbackAttr()
3641 auto It = NameIdxMapping.find(IdLoc->Ident->getName()); in handleCallbackAttr()
3643 S.Diag(AL.getLoc(), diag::err_callback_attribute_argument_unknown) in handleCallbackAttr()
3644 << IdLoc->Ident << IdLoc->Loc; in handleCallbackAttr()
3648 SR = SourceRange(IdLoc->Loc); in handleCallbackAttr()
3649 ArgIdx = It->second; in handleCallbackAttr()
3656 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleCallbackAttr()
3657 << AL << (I + 1) << IdxExpr->getSourceRange(); in handleCallbackAttr()
3661 // Check oob, excluding the special values, 0 and -1. in handleCallbackAttr()
3662 if (ArgIdx < -1 || ArgIdx > NumArgs) { in handleCallbackAttr()
3663 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleCallbackAttr()
3664 << AL << (I + 1) << IdxExpr->getSourceRange(); in handleCallbackAttr()
3668 SR = IdxExpr->getSourceRange(); in handleCallbackAttr()
3674 S.Diag(AL.getLoc(), diag::err_callback_implicit_this_not_available) in handleCallbackAttr()
3682 ArgIdx -= 1; in handleCallbackAttr()
3689 // This means the "CalleeIdx" has to be non-negative if "HasImplicitThisParam" in handleCallbackAttr()
3692 S.Diag(AL.getLoc(), diag::err_callback_attribute_invalid_callee) in handleCallbackAttr()
3700 getFunctionOrMethodParamType(D, CalleeIdx - HasImplicitThisParam) in handleCallbackAttr()
3702 if (!CalleeType || !CalleeType->isFunctionPointerType()) { in handleCallbackAttr()
3703 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type) in handleCallbackAttr()
3709 CalleeType->getPointeeType()->getUnqualifiedDesugaredType(); in handleCallbackAttr()
3715 S.Diag(AL.getLoc(), diag::err_callback_callee_no_function_type) in handleCallbackAttr()
3720 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) { in handleCallbackAttr()
3721 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) in handleCallbackAttr()
3722 << AL << (unsigned)(EncodingIndices.size() - 1); in handleCallbackAttr()
3726 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) { in handleCallbackAttr()
3727 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) in handleCallbackAttr()
3728 << AL << (unsigned)(EncodingIndices.size() - 1); in handleCallbackAttr()
3732 if (CalleeFnProtoType->isVariadic()) { in handleCallbackAttr()
3733 S.Diag(AL.getLoc(), diag::err_callback_callee_is_variadic) << AL.getRange(); in handleCallbackAttr()
3738 if (D->hasAttr<CallbackAttr>()) { in handleCallbackAttr()
3739 S.Diag(AL.getLoc(), diag::err_callback_attribute_multiple) << AL.getRange(); in handleCallbackAttr()
3743 D->addAttr(::new (S.Context) CallbackAttr( in handleCallbackAttr()
3749 // 'called_once' is only supported in Objective-C and it has in isFunctionLike()
3757 QualType T = cast<ParmVarDecl>(D)->getType(); in handleCalledOnceAttr()
3760 S.Diag(AL.getLoc(), diag::err_called_once_attribute_wrong_type); in handleCalledOnceAttr()
3764 D->addAttr(::new (S.Context) CalledOnceAttr(S.Context, AL)); in handleCalledOnceAttr()
3771 if (TD && TD->getUnderlyingType()->isUnionType()) in handleTransparentUnionAttr()
3772 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl(); in handleTransparentUnionAttr()
3776 if (!RD || !RD->isUnion()) { in handleTransparentUnionAttr()
3777 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in handleTransparentUnionAttr()
3782 if (!RD->isCompleteDefinition()) { in handleTransparentUnionAttr()
3783 if (!RD->isBeingDefined()) in handleTransparentUnionAttr()
3784 S.Diag(AL.getLoc(), in handleTransparentUnionAttr()
3785 diag::warn_transparent_union_attribute_not_definition); in handleTransparentUnionAttr()
3789 RecordDecl::field_iterator Field = RD->field_begin(), in handleTransparentUnionAttr()
3790 FieldEnd = RD->field_end(); in handleTransparentUnionAttr()
3792 S.Diag(AL.getLoc(), diag::warn_transparent_union_attribute_zero_fields); in handleTransparentUnionAttr()
3797 QualType FirstType = FirstField->getType(); in handleTransparentUnionAttr()
3798 if (FirstType->hasFloatingRepresentation() || FirstType->isVectorType()) { in handleTransparentUnionAttr()
3799 S.Diag(FirstField->getLocation(), in handleTransparentUnionAttr()
3800 diag::warn_transparent_union_attribute_floating) in handleTransparentUnionAttr()
3801 << FirstType->isVectorType() << FirstType; in handleTransparentUnionAttr()
3805 if (FirstType->isIncompleteType()) in handleTransparentUnionAttr()
3810 QualType FieldType = Field->getType(); in handleTransparentUnionAttr()
3811 if (FieldType->isIncompleteType()) in handleTransparentUnionAttr()
3824 S.Diag(Field->getLocation(), in handleTransparentUnionAttr()
3825 diag::warn_transparent_union_attribute_field_size_align) in handleTransparentUnionAttr()
3828 S.Diag(FirstField->getLocation(), in handleTransparentUnionAttr()
3829 diag::note_transparent_union_first_field_size_align) in handleTransparentUnionAttr()
3835 RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL)); in handleTransparentUnionAttr()
3842 CI, MutableArrayRef<Expr *>(Attr->args_begin(), Attr->args_end()))) { in AddAnnotationAttr()
3843 D->addAttr(Attr); in AddAnnotationAttr()
3855 Args.reserve(AL.getNumArgs() - 1); in handleAnnotateAttr()
3874 T = TD->getUnderlyingType(); in AddAlignValueAttr()
3876 T = VD->getType(); in AddAlignValueAttr()
3880 if (!T->isDependentType() && !T->isAnyPointerType() && in AddAlignValueAttr()
3881 !T->isReferenceType() && !T->isMemberPointerType()) { in AddAlignValueAttr()
3882 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only) in AddAlignValueAttr()
3883 << &TmpAttr << T << D->getSourceRange(); in AddAlignValueAttr()
3887 if (!E->isValueDependent()) { in AddAlignValueAttr()
3890 E, &Alignment, diag::err_align_value_attribute_argument_not_int); in AddAlignValueAttr()
3895 Diag(AttrLoc, diag::err_alignment_not_power_of_two) in AddAlignValueAttr()
3896 << E->getSourceRange(); in AddAlignValueAttr()
3900 D->addAttr(::new (Context) AlignValueAttr(Context, CI, ICE.get())); in AddAlignValueAttr()
3905 D->addAttr(::new (Context) AlignValueAttr(Context, CI, E)); in AddAlignValueAttr()
3915 !TInfo->getType()->containsUnexpandedParameterPack()) { in handleAlignedAttr()
3916 S.Diag(AL.getEllipsisLoc(), in handleAlignedAttr()
3917 diag::err_pack_expansion_without_parameter_packs); in handleAlignedAttr()
3922 S.DiagnoseUnexpandedParameterPack(TInfo->getTypeLoc().getBeginLoc(), in handleAlignedAttr()
3932 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; in handleAlignedAttr()
3937 D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr)); in handleAlignedAttr()
3942 if (AL.isPackExpansion() && !E->containsUnexpandedParameterPack()) { in handleAlignedAttr()
3943 S.Diag(AL.getEllipsisLoc(), in handleAlignedAttr()
3944 diag::err_pack_expansion_without_parameter_packs); in handleAlignedAttr()
3957 /// An alignment-specifier may be applied to a variable or to a class
3958 /// data member, but it shall not be applied to a bit-field, a function
3961 /// alignment-specifier may also be applied to the declaration of a class
3968 /// a typedef, or a bit-field, or a function, or a parameter, or an
3969 /// object declared with the register storage-class specifier.
3973 int DiagKind = -1; in validateAlignasAppliedType()
3977 if (VD->getStorageClass() == SC_Register) in validateAlignasAppliedType()
3979 if (VD->isExceptionVariable()) in validateAlignasAppliedType()
3982 if (FD->isBitField()) in validateAlignasAppliedType()
3985 if (ED->getLangOpts().CPlusPlus) in validateAlignasAppliedType()
3988 return S.Diag(AttrLoc, diag::err_attribute_wrong_decl_type) in validateAlignasAppliedType()
3993 if (DiagKind != -1) { in validateAlignasAppliedType()
3994 return S.Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type) in validateAlignasAppliedType()
4010 if (E->isValueDependent()) { in AddAlignedAttr()
4011 // We can't support a dependent alignment on a non-dependent type, in AddAlignedAttr()
4012 // because we have no way to model that a type is "alignment-dependent" in AddAlignedAttr()
4015 if (!TND->getUnderlyingType()->isDependentType()) { in AddAlignedAttr()
4016 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name) in AddAlignedAttr()
4017 << E->getSourceRange(); in AddAlignedAttr()
4024 AA->setPackExpansion(IsPackExpansion); in AddAlignedAttr()
4025 D->addAttr(AA); in AddAlignedAttr()
4032 E, &Alignment, diag::err_aligned_attribute_argument_not_int); in AddAlignedAttr()
4040 Diag(AttrLoc, diag::err_attribute_aligned_too_great) in AddAlignedAttr()
4041 << MaximumAlignment << E->getSourceRange(); in AddAlignedAttr()
4047 // -- if the constant expression evaluates to zero, the alignment in AddAlignedAttr()
4053 Diag(AttrLoc, diag::err_alignment_not_power_of_two) in AddAlignedAttr()
4054 << E->getSourceRange(); in AddAlignedAttr()
4065 VD->getTLSKind() != VarDecl::TLS_None) { in AddAlignedAttr()
4066 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum) in AddAlignedAttr()
4075 const Type *Ty = VD->getType().getTypePtr(); in AddAlignedAttr()
4076 if (Ty->isVectorType() && AlignVal < 16) { in AddAlignedAttr()
4077 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned) in AddAlignedAttr()
4078 << VD->getType() << 16; in AddAlignedAttr()
4084 AA->setPackExpansion(IsPackExpansion); in AddAlignedAttr()
4085 AA->setCachedAlignmentValue( in AddAlignedAttr()
4087 D->addAttr(AA); in AddAlignedAttr()
4100 if (TS->getType()->isDependentType()) { in AddAlignedAttr()
4101 // We can't support a dependent alignment on a non-dependent type, in AddAlignedAttr()
4102 // because we have no way to model that a type is "type-dependent" in AddAlignedAttr()
4105 if (!TND->getUnderlyingType()->isDependentType()) { in AddAlignedAttr()
4106 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name) in AddAlignedAttr()
4107 << TS->getTypeLoc().getSourceRange(); in AddAlignedAttr()
4113 AA->setPackExpansion(IsPackExpansion); in AddAlignedAttr()
4114 D->addAttr(AA); in AddAlignedAttr()
4123 const Type *Ty = VD->getType().getTypePtr(); in AddAlignedAttr()
4124 if (Ty->isVectorType() && in AddAlignedAttr()
4126 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned) in AddAlignedAttr()
4127 << VD->getType() << 16; in AddAlignedAttr()
4133 AA->setPackExpansion(IsPackExpansion); in AddAlignedAttr()
4134 AA->setCachedAlignmentValue(AlignVal); in AddAlignedAttr()
4135 D->addAttr(AA); in AddAlignedAttr()
4139 assert(D->hasAttrs() && "no attributes on decl"); in CheckAlignasUnderalignment()
4143 UnderlyingTy = DiagTy = VD->getType(); in CheckAlignasUnderalignment()
4147 UnderlyingTy = ED->getIntegerType(); in CheckAlignasUnderalignment()
4149 if (DiagTy->isDependentType() || DiagTy->isIncompleteType()) in CheckAlignasUnderalignment()
4159 for (auto *I : D->specific_attrs<AlignedAttr>()) { in CheckAlignasUnderalignment()
4160 if (I->isAlignmentDependent()) in CheckAlignasUnderalignment()
4162 if (I->isAlignas()) in CheckAlignasUnderalignment()
4164 Align = std::max(Align, I->getAlignment(Context)); in CheckAlignasUnderalignment()
4168 if (Align && DiagTy->isSizelessType()) { in CheckAlignasUnderalignment()
4169 Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type) in CheckAlignasUnderalignment()
4175 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned) in CheckAlignasUnderalignment()
4183 assert(RD->hasDefinition() && "RD has no definition!"); in checkMSInheritanceAttrOnDefinition()
4187 if (!RD->getDefinition()->isCompleteDefinition()) in checkMSInheritanceAttrOnDefinition()
4195 if (RD->calculateInheritanceModel() == ExplicitModel) in checkMSInheritanceAttrOnDefinition()
4198 if (RD->calculateInheritanceModel() <= ExplicitModel) in checkMSInheritanceAttrOnDefinition()
4202 Diag(Range.getBegin(), diag::err_mismatched_ms_inheritance) in checkMSInheritanceAttrOnDefinition()
4204 Diag(RD->getDefinition()->getLocation(), diag::note_defined_here) << RD; in checkMSInheritanceAttrOnDefinition()
4208 /// parseModeAttrArg - Parses attribute mode string and returns parsed type
4234 case 'K': // KFmode - IEEE quad precision (__float128) in parseModeAttrArg()
4275 /// handleModeAttr - This attribute modifies the width of a decl with primitive
4285 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleModeAttr()
4290 IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident; in handleModeAttr()
4297 StringRef Str = Name->getName(); in AddModeAttr()
4320 Diag(AttrLoc, diag::warn_vector_mode_deprecated); in AddModeAttr()
4332 // FIXME: Make sure floating-point mappings are accurate in AddModeAttr()
4335 Diag(AttrLoc, diag::err_machine_mode) << 0 /*Unknown*/ << Name; in AddModeAttr()
4341 OldTy = TD->getUnderlyingType(); in AddModeAttr()
4345 OldTy = ED->getIntegerType(); in AddModeAttr()
4349 OldTy = cast<ValueDecl>(D)->getType(); in AddModeAttr()
4351 if (OldTy->isDependentType()) { in AddModeAttr()
4352 D->addAttr(::new (Context) ModeAttr(Context, CI, Name)); in AddModeAttr()
4359 if (const auto *VT = OldTy->getAs<VectorType>()) in AddModeAttr()
4360 OldElemTy = VT->getElementType(); in AddModeAttr()
4365 if ((isa<EnumDecl>(D) || OldElemTy->getAs<EnumType>()) && in AddModeAttr()
4367 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.getRange(); in AddModeAttr()
4370 bool IntegralOrAnyEnumType = (OldElemTy->isIntegralOrEnumerationType() && in AddModeAttr()
4371 !OldElemTy->isBitIntType()) || in AddModeAttr()
4372 OldElemTy->getAs<EnumType>(); in AddModeAttr()
4374 if (!OldElemTy->getAs<BuiltinType>() && !OldElemTy->isComplexType() && in AddModeAttr()
4376 Diag(AttrLoc, diag::err_mode_not_primitive); in AddModeAttr()
4379 Diag(AttrLoc, diag::err_mode_wrong_type); in AddModeAttr()
4381 if (!OldElemTy->isComplexType()) in AddModeAttr()
4382 Diag(AttrLoc, diag::err_mode_wrong_type); in AddModeAttr()
4384 if (!OldElemTy->isFloatingType()) in AddModeAttr()
4385 Diag(AttrLoc, diag::err_mode_wrong_type); in AddModeAttr()
4392 OldElemTy->isSignedIntegerType()); in AddModeAttr()
4397 // Only emit diagnostic on host for 128-bit mode attribute in AddModeAttr()
4399 Diag(AttrLoc, diag::err_machine_mode) << 1 /*Unsupported*/ << Name; in AddModeAttr()
4411 } else if (const auto *OldVT = OldTy->getAs<VectorType>()) { in AddModeAttr()
4414 Diag(AttrLoc, diag::err_complex_mode_vector_type); in AddModeAttr()
4418 OldVT->getNumElements() / in AddModeAttr()
4421 Context.getVectorType(NewElemTy, NumElements, OldVT->getVectorKind()); in AddModeAttr()
4425 Diag(AttrLoc, diag::err_mode_wrong_type); in AddModeAttr()
4431 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy); in AddModeAttr()
4433 ED->setIntegerType(NewTy); in AddModeAttr()
4435 cast<ValueDecl>(D)->setType(NewTy); in AddModeAttr()
4437 D->addAttr(::new (Context) ModeAttr(Context, CI, Name)); in AddModeAttr()
4441 D->addAttr(::new (S.Context) NoDebugAttr(S.Context, AL)); in handleNoDebugAttr()
4447 if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) { in mergeAlwaysInlineAttr()
4448 Diag(CI.getLoc(), diag::warn_attribute_ignored) << Ident; in mergeAlwaysInlineAttr()
4449 Diag(Optnone->getLocation(), diag::note_conflicting_attribute); in mergeAlwaysInlineAttr()
4453 if (D->hasAttr<AlwaysInlineAttr>()) in mergeAlwaysInlineAttr()
4464 if (VD->getKind() != Decl::Var) { in mergeInternalLinkageAttr()
4465 Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in mergeInternalLinkageAttr()
4471 // Attribute does not apply to non-static local variables. in mergeInternalLinkageAttr()
4472 if (VD->hasLocalStorage()) { in mergeInternalLinkageAttr()
4473 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage); in mergeInternalLinkageAttr()
4485 if (VD->getKind() != Decl::Var) { in mergeInternalLinkageAttr()
4486 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type) in mergeInternalLinkageAttr()
4492 // Attribute does not apply to non-static local variables. in mergeInternalLinkageAttr()
4493 if (VD->hasLocalStorage()) { in mergeInternalLinkageAttr()
4494 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage); in mergeInternalLinkageAttr()
4503 if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) { in mergeMinSizeAttr()
4504 Diag(CI.getLoc(), diag::warn_attribute_ignored) << "'minsize'"; in mergeMinSizeAttr()
4505 Diag(Optnone->getLocation(), diag::note_conflicting_attribute); in mergeMinSizeAttr()
4509 if (D->hasAttr<MinSizeAttr>()) in mergeMinSizeAttr()
4517 if (AlwaysInlineAttr *Inline = D->getAttr<AlwaysInlineAttr>()) { in mergeOptimizeNoneAttr()
4518 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline; in mergeOptimizeNoneAttr()
4519 Diag(CI.getLoc(), diag::note_conflicting_attribute); in mergeOptimizeNoneAttr()
4520 D->dropAttr<AlwaysInlineAttr>(); in mergeOptimizeNoneAttr()
4522 if (MinSizeAttr *MinSize = D->getAttr<MinSizeAttr>()) { in mergeOptimizeNoneAttr()
4523 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize; in mergeOptimizeNoneAttr()
4524 Diag(CI.getLoc(), diag::note_conflicting_attribute); in mergeOptimizeNoneAttr()
4525 D->dropAttr<MinSizeAttr>(); in mergeOptimizeNoneAttr()
4528 if (D->hasAttr<OptimizeNoneAttr>()) in mergeOptimizeNoneAttr()
4537 D->addAttr(Inline); in handleAlwaysInlineAttr()
4542 D->addAttr(MinSize); in handleMinSizeAttr()
4547 D->addAttr(Optnone); in handleOptimizeNoneAttr()
4552 if (VD->hasLocalStorage()) { in handleConstantAttr()
4553 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev); in handleConstantAttr()
4558 if (auto *A = D->getAttr<CUDAConstantAttr>()) { in handleConstantAttr()
4559 if (!A->isImplicit()) in handleConstantAttr()
4561 D->dropAttr<CUDAConstantAttr>(); in handleConstantAttr()
4563 D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL)); in handleConstantAttr()
4570 if (!S.getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() && in handleSharedAttr()
4571 !isa<IncompleteArrayType>(VD->getType())) { in handleSharedAttr()
4572 S.Diag(AL.getLoc(), diag::err_cuda_extern_shared) << VD; in handleSharedAttr()
4575 if (S.getLangOpts().CUDA && VD->hasLocalStorage() && in handleSharedAttr()
4576 S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared) in handleSharedAttr()
4579 D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL)); in handleSharedAttr()
4584 if (!FD->getReturnType()->isVoidType() && in handleGlobalAttr()
4585 !FD->getReturnType()->getAs<AutoType>() && in handleGlobalAttr()
4586 !FD->getReturnType()->isInstantiationDependentType()) { in handleGlobalAttr()
4587 SourceRange RTRange = FD->getReturnTypeSourceRange(); in handleGlobalAttr()
4588 S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return) in handleGlobalAttr()
4589 << FD->getType() in handleGlobalAttr()
4595 if (Method->isInstance()) { in handleGlobalAttr()
4596 S.Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method) in handleGlobalAttr()
4600 S.Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method; in handleGlobalAttr()
4603 if (FD->isInlineSpecified() && !S.getLangOpts().CUDAIsDevice) in handleGlobalAttr()
4604 S.Diag(FD->getBeginLoc(), diag::warn_kern_is_inline) << FD; in handleGlobalAttr()
4607 D->addAttr(::new (S.Context) NVPTXKernelAttr(S.Context, AL)); in handleGlobalAttr()
4609 D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL)); in handleGlobalAttr()
4615 D->addAttr(NoDebugAttr::CreateImplicit(S.Context)); in handleGlobalAttr()
4620 if (VD->hasLocalStorage()) { in handleDeviceAttr()
4621 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev); in handleDeviceAttr()
4626 if (auto *A = D->getAttr<CUDADeviceAttr>()) { in handleDeviceAttr()
4627 if (!A->isImplicit()) in handleDeviceAttr()
4629 D->dropAttr<CUDADeviceAttr>(); in handleDeviceAttr()
4631 D->addAttr(::new (S.Context) CUDADeviceAttr(S.Context, AL)); in handleDeviceAttr()
4636 if (VD->hasLocalStorage()) { in handleManagedAttr()
4637 S.Diag(AL.getLoc(), diag::err_cuda_nonstatic_constdev); in handleManagedAttr()
4641 if (!D->hasAttr<HIPManagedAttr>()) in handleManagedAttr()
4642 D->addAttr(::new (S.Context) HIPManagedAttr(S.Context, AL)); in handleManagedAttr()
4643 if (!D->hasAttr<CUDADeviceAttr>()) in handleManagedAttr()
4644 D->addAttr(CUDADeviceAttr::CreateImplicit(S.Context)); in handleManagedAttr()
4649 if (!Fn->isInlineSpecified()) { in handleGNUInlineAttr()
4650 S.Diag(AL.getLoc(), diag::warn_gnu_inline_attribute_requires_inline); in handleGNUInlineAttr()
4654 if (S.LangOpts.CPlusPlus && Fn->getStorageClass() != SC_Extern) in handleGNUInlineAttr()
4655 S.Diag(AL.getLoc(), diag::warn_gnu_inline_cplusplus_without_extern); in handleGNUInlineAttr()
4657 D->addAttr(::new (S.Context) GNUInlineAttr(S.Context, AL)); in handleGNUInlineAttr()
4664 // in the Decl node for syntactic reasoning, e.g., pretty-printing. in handleCallConvAttr()
4672 S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) in handleCallConvAttr()
4679 D->addAttr(::new (S.Context) FastCallAttr(S.Context, AL)); in handleCallConvAttr()
4682 D->addAttr(::new (S.Context) StdCallAttr(S.Context, AL)); in handleCallConvAttr()
4685 D->addAttr(::new (S.Context) ThisCallAttr(S.Context, AL)); in handleCallConvAttr()
4688 D->addAttr(::new (S.Context) CDeclAttr(S.Context, AL)); in handleCallConvAttr()
4691 D->addAttr(::new (S.Context) PascalAttr(S.Context, AL)); in handleCallConvAttr()
4694 D->addAttr(::new (S.Context) SwiftCallAttr(S.Context, AL)); in handleCallConvAttr()
4697 D->addAttr(::new (S.Context) SwiftAsyncCallAttr(S.Context, AL)); in handleCallConvAttr()
4700 D->addAttr(::new (S.Context) VectorCallAttr(S.Context, AL)); in handleCallConvAttr()
4703 D->addAttr(::new (S.Context) MSABIAttr(S.Context, AL)); in handleCallConvAttr()
4706 D->addAttr(::new (S.Context) SysVABIAttr(S.Context, AL)); in handleCallConvAttr()
4709 D->addAttr(::new (S.Context) RegCallAttr(S.Context, AL)); in handleCallConvAttr()
4724 D->addAttr(::new (S.Context) PcsAttr(S.Context, AL, PCS)); in handleCallConvAttr()
4728 D->addAttr(::new (S.Context) AArch64VectorPcsAttr(S.Context, AL)); in handleCallConvAttr()
4731 D->addAttr(::new (S.Context) AArch64SVEPcsAttr(S.Context, AL)); in handleCallConvAttr()
4734 D->addAttr(::new (S.Context) AMDGPUKernelCallAttr(S.Context, AL)); in handleCallConvAttr()
4737 D->addAttr(::new (S.Context) IntelOclBiccAttr(S.Context, AL)); in handleCallConvAttr()
4740 D->addAttr(::new (S.Context) PreserveMostAttr(S.Context, AL)); in handleCallConvAttr()
4743 D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL)); in handleCallConvAttr()
4746 D->addAttr(::new (S.Context) M68kRTDAttr(S.Context, AL)); in handleCallConvAttr()
4749 D->addAttr(::new (S.Context) PreserveNoneAttr(S.Context, AL)); in handleCallConvAttr()
4752 D->addAttr(::new (S.Context) RISCVVectorCCAttr(S.Context, AL)); in handleCallConvAttr()
4775 D->addAttr(::new (S.Context) in handleSuppressAttr()
4787 if (ParmType->isReferenceType()) in handleLifetimeCategoryAttr()
4789 else if (ParmType->isArrayType()) in handleLifetimeCategoryAttr()
4793 S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) in handleLifetimeCategoryAttr()
4804 D = D->getCanonicalDecl(); in handleLifetimeCategoryAttr()
4808 if (const auto *OAttr = D->getAttr<OwnerAttr>()) { in handleLifetimeCategoryAttr()
4809 const Type *ExistingDerefType = OAttr->getDerefTypeLoc() in handleLifetimeCategoryAttr()
4810 ? OAttr->getDerefType().getTypePtr() in handleLifetimeCategoryAttr()
4813 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) in handleLifetimeCategoryAttr()
4816 OAttr->isRegularKeywordAttribute()); in handleLifetimeCategoryAttr()
4817 S.Diag(OAttr->getLocation(), diag::note_conflicting_attribute); in handleLifetimeCategoryAttr()
4821 for (Decl *Redecl : D->redecls()) { in handleLifetimeCategoryAttr()
4822 Redecl->addAttr(::new (S.Context) OwnerAttr(S.Context, AL, DerefTypeLoc)); in handleLifetimeCategoryAttr()
4827 if (const auto *PAttr = D->getAttr<PointerAttr>()) { in handleLifetimeCategoryAttr()
4828 const Type *ExistingDerefType = PAttr->getDerefTypeLoc() in handleLifetimeCategoryAttr()
4829 ? PAttr->getDerefType().getTypePtr() in handleLifetimeCategoryAttr()
4832 S.Diag(AL.getLoc(), diag::err_attributes_are_not_compatible) in handleLifetimeCategoryAttr()
4835 PAttr->isRegularKeywordAttribute()); in handleLifetimeCategoryAttr()
4836 S.Diag(PAttr->getLocation(), diag::note_conflicting_attribute); in handleLifetimeCategoryAttr()
4840 for (Decl *Redecl : D->redecls()) { in handleLifetimeCategoryAttr()
4841 Redecl->addAttr(::new (S.Context) in handleLifetimeCategoryAttr()
4850 if (!D->hasAttr<RandomizeLayoutAttr>()) in handleRandomizeLayoutAttr()
4851 D->addAttr(::new (S.Context) RandomizeLayoutAttr(S.Context, AL)); in handleRandomizeLayoutAttr()
4858 if (!D->hasAttr<NoRandomizeLayoutAttr>()) in handleNoRandomizeLayoutAttr()
4859 D->addAttr(::new (S.Context) NoRandomizeLayoutAttr(S.Context, AL)); in handleNoRandomizeLayoutAttr()
4934 } else if (StrRef == "aapcs-vfp") { in CheckCallingConvAttr()
4940 Diag(Attrs.getLoc(), diag::err_invalid_pcs); in CheckCallingConvAttr()
4993 A = HostTI->checkCallingConvention(CC); in CheckCallingConvAttr()
4995 A = DeviceTI->checkCallingConvention(CC); in CheckCallingConvAttr()
5013 Diag(Attrs.getLoc(), diag::error_cconv_unsupported) in CheckCallingConvAttr()
5018 Diag(Attrs.getLoc(), diag::warn_cconv_unsupported) in CheckCallingConvAttr()
5025 IsCXXMethod = FD->isCXXInstanceMember(); in CheckCallingConvAttr()
5026 IsVariadic = FD->isVariadic(); in CheckCallingConvAttr()
5054 Diag(AL.getLoc(), diag::err_attribute_regparm_wrong_platform) in CheckRegparmAttr()
5055 << NumParamsExpr->getSourceRange(); in CheckRegparmAttr()
5062 Diag(AL.getLoc(), diag::err_attribute_regparm_invalid_number) in CheckRegparmAttr()
5063 << Context.getTargetInfo().getRegParmMax() << NumParamsExpr->getSourceRange(); in CheckRegparmAttr()
5081 // non-nullptr Expr result on success. Otherwise, it returns nullptr
5091 if (E->isValueDependent()) in makeLaunchBoundsArgExpr()
5095 if (!(I = E->getIntegerConstantExpr(S.Context))) { in makeLaunchBoundsArgExpr()
5096 S.Diag(E->getExprLoc(), diag::err_attribute_argument_n_type) in makeLaunchBoundsArgExpr()
5097 << &AL << Idx << AANT_ArgumentIntegerConstant << E->getSourceRange(); in makeLaunchBoundsArgExpr()
5101 if (!I->isIntN(32)) { in makeLaunchBoundsArgExpr()
5102 S.Diag(E->getExprLoc(), diag::err_ice_too_large) in makeLaunchBoundsArgExpr()
5107 S.Diag(E->getExprLoc(), diag::warn_attribute_argument_n_negative) in makeLaunchBoundsArgExpr()
5108 << &AL << Idx << E->getSourceRange(); in makeLaunchBoundsArgExpr()
5138 Diag(MaxBlocks->getBeginLoc(), diag::warn_cuda_maxclusterrank_sm_90) in CreateLaunchBoundsAttr()
5139 << OffloadArchToString(SM) << CI << MaxBlocks->getSourceRange(); in CreateLaunchBoundsAttr()
5157 D->addAttr(Attr); in AddLaunchBoundsAttr()
5172 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleArgumentWithTypeTagAttr()
5187 bool IsPointer = AL.getAttrName()->getName() == "pointer_with_type_tag"; in handleArgumentWithTypeTagAttr()
5192 !getFunctionOrMethodParamType(D, ArgumentIdxAST)->isPointerType()) in handleArgumentWithTypeTagAttr()
5193 S.Diag(AL.getLoc(), diag::err_attribute_pointers_only) << AL << 0; in handleArgumentWithTypeTagAttr()
5196 D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr( in handleArgumentWithTypeTagAttr()
5197 S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx, in handleArgumentWithTypeTagAttr()
5204 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleTypeTagForDatatypeAttr()
5213 S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type) in handleTypeTagForDatatypeAttr()
5218 IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident; in handleTypeTagForDatatypeAttr()
5223 D->addAttr(::new (S.Context) TypeTagForDatatypeAttr( in handleTypeTagForDatatypeAttr()
5237 D->addAttr(::new (S.Context) in handleXRayLogArgsAttr()
5244 S.Diag(AL.getLoc(), diag::err_aix_attr_unsupported) << AL; in handlePatchableFunctionEntryAttr()
5255 S.Diag(S.getAttrLoc(AL), diag::err_attribute_argument_out_of_range) in handlePatchableFunctionEntryAttr()
5256 << &AL << 0 << Count << Arg->getBeginLoc(); in handlePatchableFunctionEntryAttr()
5260 D->addAttr(::new (S.Context) in handlePatchableFunctionEntryAttr()
5266 S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) in handleBuiltinAliasAttr()
5271 IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident; in handleBuiltinAliasAttr()
5272 unsigned BuiltinID = Ident->getBuiltinID(); in handleBuiltinAliasAttr()
5273 StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName(); in handleBuiltinAliasAttr()
5284 S.Diag(AL.getLoc(), diag::err_attribute_builtin_alias) << AL; in handleBuiltinAliasAttr()
5288 D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident)); in handleBuiltinAliasAttr()
5296 !CRD || !(CRD->isClass() || CRD->isStruct())) { in handleNullableTypeAttr()
5297 S.Diag(AL.getRange().getBegin(), diag::err_attribute_wrong_decl_type_str) in handleNullableTypeAttr()
5307 S.Diag(AL.getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1; in handlePreferredTypeAttr()
5314 S.RequireCompleteType(ParmTSI->getTypeLoc().getBeginLoc(), QT, in handlePreferredTypeAttr()
5315 diag::err_incomplete_type); in handlePreferredTypeAttr()
5317 D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI)); in handlePreferredTypeAttr()
5320 //===----------------------------------------------------------------------===//
5322 //===----------------------------------------------------------------------===//
5326 if (const auto *UA = D->getAttr<UuidAttr>()) { in mergeUuidAttr()
5327 if (declaresSameEntity(UA->getGuidDecl(), GuidDecl)) in mergeUuidAttr()
5329 if (!UA->getGuid().empty()) { in mergeUuidAttr()
5330 Diag(UA->getLocation(), diag::err_mismatched_uuid); in mergeUuidAttr()
5331 Diag(CI.getLoc(), diag::note_previous_uuid); in mergeUuidAttr()
5332 D->dropAttr<UuidAttr>(); in mergeUuidAttr()
5341 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) in handleUuidAttr()
5351 // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or in handleUuidAttr()
5352 // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", normalize to the former. in handleUuidAttr()
5359 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); in handleUuidAttr()
5365 if (StrRef[i] != '-') { in handleUuidAttr()
5366 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); in handleUuidAttr()
5370 S.Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid); in handleUuidAttr()
5389 // Cf "SourceLocations of attribute list delimiters - [[ ... , ... ]] etc" in handleUuidAttr()
5390 // on cfe-dev. in handleUuidAttr()
5392 S.Diag(AL.getLoc(), diag::warn_atl_uuid_deprecated); in handleUuidAttr()
5396 D->addAttr(UA); in handleUuidAttr()
5401 S.Diag(AL.getLoc(), diag::err_attribute_not_supported_in_lang) in handleMSInheritanceAttr()
5408 D->addAttr(IA); in handleMSInheritanceAttr()
5416 S.Diag(AL.getLoc(), diag::err_thread_unsupported); in handleDeclspecThreadAttr()
5419 if (VD->getTSCSpec() != TSCS_unspecified) { in handleDeclspecThreadAttr()
5420 S.Diag(AL.getLoc(), diag::err_declspec_thread_on_thread_variable); in handleDeclspecThreadAttr()
5423 if (VD->hasLocalStorage()) { in handleDeclspecThreadAttr()
5424 S.Diag(AL.getLoc(), diag::err_thread_non_global) << "__declspec(thread)"; in handleDeclspecThreadAttr()
5427 D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL)); in handleDeclspecThreadAttr()
5432 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) in handleMSConstexprAttr()
5437 if (FD->isConstexprSpecified() || FD->isConsteval()) { in handleMSConstexprAttr()
5438 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied) in handleMSConstexprAttr()
5439 << FD->isConsteval() << FD; in handleMSConstexprAttr()
5443 if (!S.getLangOpts().CPlusPlus20 && MD->isVirtual()) { in handleMSConstexprAttr()
5444 S.Diag(AL.getLoc(), diag::err_ms_constexpr_cannot_be_applied) in handleMSConstexprAttr()
5449 D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL)); in handleMSConstexprAttr()
5462 if (!NS->isInline()) { in handleAbiTagAttr()
5463 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 0; in handleAbiTagAttr()
5466 if (NS->isAnonymousNamespace()) { in handleAbiTagAttr()
5467 S.Diag(AL.getLoc(), diag::warn_attr_abi_tag_namespace) << 1; in handleAbiTagAttr()
5471 Tags.push_back(NS->getName()); in handleAbiTagAttr()
5479 D->addAttr(::new (S.Context) in handleAbiTagAttr()
5484 for (const auto *I : D->specific_attrs<BTFDeclTagAttr>()) { in hasBTFDeclTagAttr()
5485 if (I->getBTFDeclTag() == Tag) in hasBTFDeclTagAttr()
5498 D->addAttr(::new (S.Context) BTFDeclTagAttr(S.Context, AL, Str)); in handleBTFDeclTagAttr()
5538 uint32_t Version; in handleLayoutVersion() local
5540 if (!S.checkUInt32Argument(AL, AL.getArgAsExpr(0), Version)) in handleLayoutVersion()
5543 // TODO: Investigate what happens with the next major version of MSVC. in handleLayoutVersion()
5544 if (Version != LangOptions::MSVC2015 / 100) { in handleLayoutVersion()
5545 S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds) in handleLayoutVersion()
5546 << AL << Version << VersionExpr->getSourceRange(); in handleLayoutVersion()
5550 // The attribute expects a "major" version number like 19, but new versions of in handleLayoutVersion()
5553 Version *= 100; in handleLayoutVersion()
5555 D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version)); in handleLayoutVersion()
5560 if (D->hasAttr<DLLExportAttr>()) { in mergeDLLImportAttr()
5561 Diag(CI.getLoc(), diag::warn_attribute_ignored) << "'dllimport'"; in mergeDLLImportAttr()
5565 if (D->hasAttr<DLLImportAttr>()) in mergeDLLImportAttr()
5573 if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) { in mergeDLLExportAttr()
5574 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import; in mergeDLLExportAttr()
5575 D->dropAttr<DLLImportAttr>(); in mergeDLLExportAttr()
5578 if (D->hasAttr<DLLExportAttr>()) in mergeDLLExportAttr()
5587 S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored) << A; in handleDLLAttr()
5592 if (FD->isInlined() && A.getKind() == ParsedAttr::AT_DLLImport && in handleDLLAttr()
5595 S.Diag(A.getRange().getBegin(), diag::warn_attribute_ignored_on_inline) in handleDLLAttr()
5603 MD->getParent()->isLambda()) { in handleDLLAttr()
5604 S.Diag(A.getRange().getBegin(), diag::err_attribute_dll_lambda) << A; in handleDLLAttr()
5613 D->addAttr(NewAttr); in handleDLLAttr()
5620 if (MSInheritanceAttr *IA = D->getAttr<MSInheritanceAttr>()) { in mergeMSInheritanceAttr()
5621 if (IA->getInheritanceModel() == Model) in mergeMSInheritanceAttr()
5623 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance) in mergeMSInheritanceAttr()
5625 Diag(CI.getLoc(), diag::note_previous_ms_inheritance); in mergeMSInheritanceAttr()
5626 D->dropAttr<MSInheritanceAttr>(); in mergeMSInheritanceAttr()
5630 if (RD->hasDefinition()) { in mergeMSInheritanceAttr()
5637 Diag(CI.getLoc(), diag::warn_ignored_ms_inheritance) in mergeMSInheritanceAttr()
5641 if (RD->getDescribedClassTemplate()) { in mergeMSInheritanceAttr()
5642 Diag(CI.getLoc(), diag::warn_ignored_ms_inheritance) in mergeMSInheritanceAttr()
5666 D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N)); in handleCapabilityAttr()
5674 D->addAttr(::new (S.Context) in handleAssertCapabilityAttr()
5684 D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(), in handleAcquireCapabilityAttr()
5694 D->addAttr(::new (S.Context) TryAcquireCapabilityAttr( in handleTryAcquireCapabilityAttr()
5704 D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(), in handleReleaseCapabilityAttr()
5722 D->addAttr(RCA); in handleRequiresCapabilityAttr()
5727 if (NSD->isAnonymousNamespace()) { in handleDeprecatedAttr()
5728 S.Diag(AL.getLoc(), diag::warn_deprecated_anonymous_namespace); in handleDeprecatedAttr()
5736 S.Diag(AL.getRange().getBegin(), diag::warn_deprecated_ignored_on_using) in handleDeprecatedAttr()
5755 S.Diag(AL.getLoc(), diag::ext_cxx14_attr) << AL; in handleDeprecatedAttr()
5757 D->addAttr(::new (S.Context) DeprecatedAttr(S.Context, AL, Str, Replacement)); in handleDeprecatedAttr()
5762 return S->hasGlobalStorage(); in isGlobalVar()
5787 S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName; in handleNoSanitizeAttr()
5789 S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global) in handleNoSanitizeAttr()
5794 D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(), in handleNoSanitizeAttr()
5800 StringRef AttrName = AL.getAttrName()->getName(); in handleNoSanitizeSpecificAttr()
5808 S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) in handleNoSanitizeSpecificAttr()
5816 // around the issue with hard-coded indices. This is critical for calling in handleNoSanitizeSpecificAttr()
5825 D->addAttr(::new (S.Context) in handleNoSanitizeSpecificAttr()
5831 D->addAttr(Internal); in handleInternalLinkageAttr()
5843 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) in handleZeroCallUsedRegsAttr()
5848 D->dropAttr<ZeroCallUsedRegsAttr>(); in handleZeroCallUsedRegsAttr()
5849 D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL)); in handleZeroCallUsedRegsAttr()
5888 FD->getType(), CountExpr, CountInBytes, OrNull); in handleCountedByAttrField()
5889 FD->setType(CAT); in handleCountedByAttrField()
5901 S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) in handleFunctionReturnThunksAttr()
5908 D->dropAttr<FunctionReturnThunksAttr>(); in handleFunctionReturnThunksAttr()
5909 D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL)); in handleFunctionReturnThunksAttr()
5920 if (VDecl && !VDecl->isFunctionPointerType()) { in handleNoMergeAttr()
5921 S.Diag(AL.getLoc(), diag::warn_attribute_ignored_non_function_pointer) in handleNoMergeAttr()
5925 D->addAttr(NoMergeAttr::Create(S.Context, AL)); in handleNoMergeAttr()
5929 D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL)); in handleNoUniqueAddressAttr()
5933 if (!cast<VarDecl>(D)->hasGlobalStorage()) { in handleDestroyAttr()
5934 S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var) in handleDestroyAttr()
5946 assert(cast<VarDecl>(D)->getStorageDuration() == SD_Automatic && in handleUninitializedAttr()
5948 D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL)); in handleUninitializedAttr()
5959 while (const auto *TT = T->getAs<TypedefType>()) { in handleMIGServerRoutineAttr()
5960 IsKernReturnT = (TT->getDecl()->getName() == "kern_return_t"); in handleMIGServerRoutineAttr()
5961 T = TT->desugar(); in handleMIGServerRoutineAttr()
5964 S.Diag(D->getBeginLoc(), in handleMIGServerRoutineAttr()
5965 diag::warn_mig_server_routine_does_not_return_kern_return_t); in handleMIGServerRoutineAttr()
5976 QualType RetTy = FD->getReturnType(); in handleMSAllocatorAttr()
5977 if (!RetTy->isPointerType() && !RetTy->isReferenceType()) { in handleMSAllocatorAttr()
5978 S.Diag(AL.getLoc(), diag::warn_declspec_allocator_nonpointer) in handleMSAllocatorAttr()
5992 if (PVD->getType()->isIntegerType()) { in handleAcquireHandleAttr()
5993 S.Diag(AL.getLoc(), diag::err_attribute_output_parameter) in handleAcquireHandleAttr()
6001 D->addAttr(AcquireHandleAttr::Create(S.Context, Argument, AL)); in handleAcquireHandleAttr()
6009 D->addAttr(Attr::Create(S.Context, Argument, AL)); in handleHandleAttr()
6014 D->addAttr(Attr::Create(S.Context, AL)); in handleUnsafeBufferUsage()
6021 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleCFGuardAttr()
6027 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; in handleCFGuardAttr()
6028 if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) { in handleCFGuardAttr()
6029 S.Diag(AL.getLoc(), diag::warn_attribute_type_not_supported) << AL << II; in handleCFGuardAttr()
6033 D->addAttr(::new (S.Context) CFGuardAttr(S.Context, AL, Arg)); in handleCFGuardAttr()
6039 auto Attrs = D->specific_attrs<AttrTy>(); in findEnforceTCBAttrByName()
6042 return A->getTCBName() == Name; in findEnforceTCBAttrByName()
6058 S.Diag(AL.getLoc(), diag::err_tcb_conflicting_attributes) in handleEnforceTCBAttr()
6059 << AL.getAttrName()->getName() << ConflictingAttr->getAttrName()->getName() in handleEnforceTCBAttr()
6062 // Error recovery: drop the non-leaf attribute so that to suppress in handleEnforceTCBAttr()
6065 D->dropAttr<EnforceTCBAttr>(); in handleEnforceTCBAttr()
6069 D->addAttr(AttrTy::Create(S.Context, Argument, AL)); in handleEnforceTCBAttr()
6074 // Check if the new redeclaration has different leaf-ness in the same TCB. in mergeEnforceTCBAttrImpl()
6078 S.Diag(ConflictingAttr->getLoc(), diag::err_tcb_conflicting_attributes) in mergeEnforceTCBAttrImpl()
6079 << ConflictingAttr->getAttrName()->getName() in mergeEnforceTCBAttrImpl()
6080 << AL.getAttrName()->getName() << TCBName; in mergeEnforceTCBAttrImpl()
6083 S.Diag(AL.getLoc(), diag::note_conflicting_attribute); in mergeEnforceTCBAttrImpl()
6086 D->dropAttr<EnforceTCBAttr>(); in mergeEnforceTCBAttrImpl()
6110 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4; in handleVTablePointerAuthentication()
6115 S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << AL; in handleVTablePointerAuthentication()
6120 if (D->getAttr<VTablePointerAuthenticationAttr>()) { in handleVTablePointerAuthentication()
6121 S.Diag(AL.getLoc(), diag::err_duplicated_vtable_pointer_auth) << Decl; in handleVTablePointerAuthentication()
6129 IL->Ident->getName(), KeyType)) { in handleVTablePointerAuthentication()
6130 S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident; in handleVTablePointerAuthentication()
6135 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 0; in handleVTablePointerAuthentication()
6139 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleVTablePointerAuthentication()
6150 ConvertStrToAddressDiscriminationMode(IL->Ident->getName(), in handleVTablePointerAuthentication()
6152 S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident; in handleVTablePointerAuthentication()
6158 S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1; in handleVTablePointerAuthentication()
6162 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleVTablePointerAuthentication()
6173 IL->Ident->getName(), ED)) { in handleVTablePointerAuthentication()
6174 S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident; in handleVTablePointerAuthentication()
6179 S.Diag(AL.getLoc(), diag::err_no_default_vtable_pointer_auth) << 2; in handleVTablePointerAuthentication()
6183 S.Diag(AL.getLoc(), diag::err_attribute_argument_type) in handleVTablePointerAuthentication()
6191 S.Diag(AL.getLoc(), diag::err_missing_custom_discrimination) << AL << 4; in handleVTablePointerAuthentication()
6196 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 4; in handleVTablePointerAuthentication()
6202 S.Diag(AL.getLoc(), diag::err_invalid_custom_discrimination); in handleVTablePointerAuthentication()
6206 S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << AL << 3; in handleVTablePointerAuthentication()
6210 Decl->addAttr(::new (S.Context) VTablePointerAuthenticationAttr( in handleVTablePointerAuthentication()
6215 //===----------------------------------------------------------------------===//
6217 //===----------------------------------------------------------------------===//
6229 bool IsLastAttrArg = I == (AttrNumArgs - 1); in MustDelayAttributeArguments()
6244 if (E->isValueDependent() && !ArgMemberCanHoldExpr) in MustDelayAttributeArguments()
6250 /// ProcessDeclAttribute - Apply the specific attribute to the specified decl if
6263 // structure member declaration because it is a type-specifier-qualifier in in ProcessDeclAttribute()
6270 // Unknown attributes are automatically warned on. Target-specific attributes in ProcessDeclAttribute()
6275 S.Diag(AL.getLoc(), in ProcessDeclAttribute()
6277 ? (unsigned)diag::err_keyword_not_supported_on_target in ProcessDeclAttribute()
6279 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored in ProcessDeclAttribute()
6280 : (unsigned)diag::warn_unknown_attribute_ignored) in ProcessDeclAttribute()
6302 assert(AL.isTypeAttr() && "Non-type attribute not handled"); in ProcessDeclAttribute()
6308 // Non-[[]] type attributes are handled in processTypeAttrs(); silently in ProcessDeclAttribute()
6318 // - we actually have a `DeclSpec`, i.e. if we're looking at a in ProcessDeclAttribute()
6320 // - we are looking at an alias-declaration, where historically we have in ProcessDeclAttribute()
6328 S.Diag(AL.getLoc(), diag::warn_type_attribute_deprecated_on_decl) in ProcessDeclAttribute()
6329 << AL << D->getLocation(); in ProcessDeclAttribute()
6354 // decl-specifier-seq). in ProcessDeclAttribute()
6362 // See https://github.com/llvm/llvm-project/issues/55790 for details. in ProcessDeclAttribute()
6371 S.Diag(AL.getLoc(), diag::err_attribute_invalid_on_decl) in ProcessDeclAttribute()
6372 << AL << AL.isRegularKeywordAttribute() << D->getLocation(); in ProcessDeclAttribute()
6646 diag::warn_ns_attribute_wrong_parameter_type, in ProcessDeclAttribute()
6647 /*Extra Args=*/AL, /*pointer-to-OSObject-pointer*/ 3, AL.getRange()); in ProcessDeclAttribute()
6652 diag::warn_ns_attribute_wrong_parameter_type, in ProcessDeclAttribute()
6653 /*Extra Args=*/AL, /*pointer-to-OSObject-poointer*/ 3, AL.getRange()); in ProcessDeclAttribute()
7119 if (D->hasAttr<WeakRefAttr>() && !D->hasAttr<AliasAttr>()) { in ProcessDeclAttributeList()
7120 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias) in ProcessDeclAttributeList()
7122 D->dropAttr<WeakRefAttr>(); in ProcessDeclAttributeList()
7130 if (!D->hasAttr<OpenCLKernelAttr>()) { in ProcessDeclAttributeList()
7131 // These attributes cannot be applied to a non-kernel function. in ProcessDeclAttributeList()
7132 if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) { in ProcessDeclAttributeList()
7134 // diag::err_attribute_wrong_decl_type + ExpectedKernelFunction. in ProcessDeclAttributeList()
7135 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; in ProcessDeclAttributeList()
7136 D->setInvalidDecl(); in ProcessDeclAttributeList()
7137 } else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) { in ProcessDeclAttributeList()
7138 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; in ProcessDeclAttributeList()
7139 D->setInvalidDecl(); in ProcessDeclAttributeList()
7140 } else if (const auto *A = D->getAttr<VecTypeHintAttr>()) { in ProcessDeclAttributeList()
7141 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; in ProcessDeclAttributeList()
7142 D->setInvalidDecl(); in ProcessDeclAttributeList()
7143 } else if (const auto *A = D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) { in ProcessDeclAttributeList()
7144 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A; in ProcessDeclAttributeList()
7145 D->setInvalidDecl(); in ProcessDeclAttributeList()
7146 } else if (!D->hasAttr<CUDAGlobalAttr>()) { in ProcessDeclAttributeList()
7147 if (const auto *A = D->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) { in ProcessDeclAttributeList()
7148 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) in ProcessDeclAttributeList()
7149 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction; in ProcessDeclAttributeList()
7150 D->setInvalidDecl(); in ProcessDeclAttributeList()
7151 } else if (const auto *A = D->getAttr<AMDGPUWavesPerEUAttr>()) { in ProcessDeclAttributeList()
7152 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) in ProcessDeclAttributeList()
7153 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction; in ProcessDeclAttributeList()
7154 D->setInvalidDecl(); in ProcessDeclAttributeList()
7155 } else if (const auto *A = D->getAttr<AMDGPUNumSGPRAttr>()) { in ProcessDeclAttributeList()
7156 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) in ProcessDeclAttributeList()
7157 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction; in ProcessDeclAttributeList()
7158 D->setInvalidDecl(); in ProcessDeclAttributeList()
7159 } else if (const auto *A = D->getAttr<AMDGPUNumVGPRAttr>()) { in ProcessDeclAttributeList()
7160 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type) in ProcessDeclAttributeList()
7161 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction; in ProcessDeclAttributeList()
7162 D->setInvalidDecl(); in ProcessDeclAttributeList()
7172 if (D->hasAttr<ObjCDesignatedInitializerAttr>() && in ProcessDeclAttributeList()
7173 cast<ObjCMethodDecl>(D)->getMethodFamily() != OMF_init) { in ProcessDeclAttributeList()
7174 Diag(D->getLocation(), diag::err_designated_init_attr_non_init); in ProcessDeclAttributeList()
7175 D->dropAttr<ObjCDesignatedInitializerAttr>(); in ProcessDeclAttributeList()
7189 if (D && D->hasAttr<BPFPreserveAccessIndexAttr>()) in ProcessDeclAttributeDelayed()
7200 Diag(AL.getLoc(), diag::err_only_annotate_after_access_spec); in ProcessAccessDeclAttributeList()
7207 /// checkUnusedDeclAttributes - Check a list of attributes to see if it
7211 // Only warn if the attribute is an unignored, non-type attribute. in checkUnusedDeclAttributes()
7218 S.Diag(AL.getLoc(), diag::warn_unknown_attribute_ignored) in checkUnusedDeclAttributes()
7221 S.Diag(AL.getLoc(), diag::warn_attribute_not_on_decl) << AL in checkUnusedDeclAttributes()
7246 FD->getASTContext(), FD->getDeclContext(), Loc, Loc, in DeclClonePragmaWeak()
7247 DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None, in DeclClonePragmaWeak()
7249 FD->hasPrototype(), ConstexprSpecKind::Unspecified, in DeclClonePragmaWeak()
7250 FD->getTrailingRequiresClause()); in DeclClonePragmaWeak()
7253 if (FD->getQualifier()) in DeclClonePragmaWeak()
7254 NewFD->setQualifierInfo(FD->getQualifierLoc()); in DeclClonePragmaWeak()
7258 QualType FDTy = FD->getType(); in DeclClonePragmaWeak()
7259 if (const auto *FT = FDTy->getAs<FunctionProtoType>()) { in DeclClonePragmaWeak()
7261 for (const auto &AI : FT->param_types()) { in DeclClonePragmaWeak()
7263 Param->setScopeInfo(0, Params.size()); in DeclClonePragmaWeak()
7266 NewFD->setParams(Params); in DeclClonePragmaWeak()
7269 NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(), in DeclClonePragmaWeak()
7270 VD->getInnerLocStart(), VD->getLocation(), II, in DeclClonePragmaWeak()
7271 VD->getType(), VD->getTypeSourceInfo(), in DeclClonePragmaWeak()
7272 VD->getStorageClass()); in DeclClonePragmaWeak()
7273 if (VD->getQualifier()) in DeclClonePragmaWeak()
7274 cast<VarDecl>(NewD)->setQualifierInfo(VD->getQualifierLoc()); in DeclClonePragmaWeak()
7281 IdentifierInfo *NDId = ND->getIdentifier(); in DeclApplyPragmaWeak()
7283 NewD->addAttr( in DeclApplyPragmaWeak()
7284 AliasAttr::CreateImplicit(Context, NDId->getName(), W.getLocation())); in DeclApplyPragmaWeak()
7285 NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); in DeclApplyPragmaWeak()
7291 NewD->setDeclContext(CurContext); in DeclApplyPragmaWeak()
7292 NewD->setLexicalDeclContext(CurContext); in DeclApplyPragmaWeak()
7296 ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation())); in DeclApplyPragmaWeak()
7301 // It's valid to "forward-declare" #pragma weak, in which case we in ProcessPragmaWeak()
7308 if (VD->isExternC()) in ProcessPragmaWeak()
7311 if (FD->isExternC()) in ProcessPragmaWeak()
7315 if (IdentifierInfo *Id = ND->getIdentifier()) { in ProcessPragmaWeak()
7318 auto &WeakInfos = I->second; in ProcessPragmaWeak()
7327 /// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in
7391 const DelayedDiagnostic &diag, in isForbiddenTypeAllowed() argument
7402 // -fno-objc-arc files. We do have to take some care against attempts in isForbiddenTypeAllowed()
7406 if (diag.getForbiddenTypeDiagnostic() == diag::err_arc_weak_disabled || in isForbiddenTypeAllowed()
7407 diag.getForbiddenTypeDiagnostic() == diag::err_arc_weak_no_runtime) { in isForbiddenTypeAllowed()
7414 if (S.Context.getSourceManager().isInSystemHeader(D->getLocation())) { in isForbiddenTypeAllowed()
7424 /// Handle a delayed forbidden-type diagnostic.
7430 D->addAttr(UnavailableAttr::CreateImplicit(S.Context, "", Reason, DD.Loc)); in handleDelayedForbiddenType()
7437 if (FD->hasAttr<UnavailableAttr>() && in handleDelayedForbiddenType()
7439 diag::err_arc_array_param_no_ownership) { in handleDelayedForbiddenType()
7445 S.Diag(DD.Loc, DD.getForbiddenTypeDiagnostic()) in handleDelayedForbiddenType()
7472 i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) { in PopParsingDeclaration()
7474 DelayedDiagnostic &diag = const_cast<DelayedDiagnostic&>(*i); in PopParsingDeclaration() local
7475 if (diag.Triggered) in PopParsingDeclaration()
7478 switch (diag.Kind) { in PopParsingDeclaration()
7482 if (!decl->isInvalidDecl()) in PopParsingDeclaration()
7483 handleDelayedAvailabilityCheck(diag, decl); in PopParsingDeclaration()
7492 HandleDelayedAccessCheck(diag, decl); in PopParsingDeclaration()
7493 if (diag.Triggered) in PopParsingDeclaration()
7498 handleDelayedForbiddenType(*this, diag, decl); in PopParsingDeclaration()
7502 } while ((pool = pool->getParent())); in PopParsingDeclaration()
7507 assert(curPool && "re-emitting in undelayed context not supported"); in redelayDiagnostics()
7508 curPool->steal(pool); in redelayDiagnostics()