Lines Matching +full:oe +full:- +full:extra +full:- +full:delay
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 //===----------------------------------------------------------------------===//
92 /// Wrapper around checkUInt32Argument, with an extra check to be sure
105 S.Diag(Expr->getExprLoc(), diag::err_ice_too_large)
117 const auto *Literal = dyn_cast<StringLiteral>(E->IgnoreParenCasts());
119 *ArgLocation = E->getBeginLoc();
121 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) {
122 Diag(E->getBeginLoc(), diag::err_attribute_argument_type)
127 Str = Literal->getString();
137 Diag(Loc->Loc, diag::err_attribute_argument_type)
139 << FixItHint::CreateInsertion(Loc->Loc, "\"")
140 << FixItHint::CreateInsertion(getLocForEndOfToken(Loc->Loc), "\"");
141 Str = Loc->Ident->getName();
143 *ArgLocation = Loc->Loc;
149 const auto *Literal = dyn_cast<StringLiteral>(ArgExpr->IgnoreParenCasts());
151 *ArgLocation = ArgExpr->getBeginLoc();
153 if (!Literal || (!Literal->isUnevaluated() && !Literal->isOrdinary())) {
154 Diag(ArgExpr->getBeginLoc(), diag::err_attribute_argument_type)
158 Str = Literal->getString();
162 /// Check if the passed-in expression is of type int or bool.
164 QualType QT = Exp->getType();
165 return QT->isBooleanType() || QT->isIntegerType();
170 // it's a smart pointer if it defines both operator-> and operator*.
175 Record->lookup(S.Context.DeclarationNames.getCXXOperatorName(Op));
179 const RecordDecl *Record = RT->getDecl();
189 for (const auto &BaseSpecifier : CXXRecord->bases()) {
192 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
195 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
210 QualType QT = VD->getType();
211 if (QT->isAnyPointerType())
214 if (const auto *RT = QT->getAs<RecordType>()) {
218 if (RT->isIncompleteType())
232 if (const auto *RT = QT->getAs<RecordType>())
236 if (const auto *PT = QT->getAs<PointerType>())
237 return PT->getPointeeType()->getAs<RecordType>();
245 if (RD->hasAttr<AttrType>())
250 if (!CRD->forallBases([](const CXXRecordDecl *Base) {
251 return !Base->hasAttr<AttrType>();
265 if (RT->isIncompleteType())
269 // FIXME -- Check the type that the smart pointer points to.
273 return checkRecordDeclForAttr<CapabilityAttr>(RT->getDecl());
277 const auto *TD = Ty->getAs<TypedefType>();
281 TypedefNameDecl *TN = TD->getDecl();
285 return TN->hasAttr<CapabilityAttr>();
305 return isCapabilityExpr(S, E->getSubExpr());
307 return isCapabilityExpr(S, E->getSubExpr());
309 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
310 E->getOpcode() == UO_Deref)
311 return isCapabilityExpr(S, E->getSubExpr());
314 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
315 return isCapabilityExpr(S, E->getLHS()) &&
316 isCapabilityExpr(S, E->getRHS());
320 return typeHasCapability(S, Ex->getType());
336 // a non-static method, and that the class is a (scoped) capability.
338 if (MD && !MD->isStatic()) {
339 const CXXRecordDecl *RD = MD->getParent();
340 // FIXME -- need to check this again on template instantiation
345 << AL << MD->getParent();
355 if (ArgExp->isTypeDependent()) {
356 // FIXME -- need to check this again on template instantiation
362 if (StrLit->getLength() == 0 ||
363 (StrLit->isOrdinary() && StrLit->getString() == "*")) {
377 QualType ArgTy = ArgExp->getType();
380 // specially -- we need to look at the type of the member.
382 if (UOp->getOpcode() == UO_AddrOf)
383 if (const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
384 if (DRE->getDecl()->isCXXInstanceMember())
385 ArgTy = DRE->getDecl()->getType();
395 unsigned int NumParams = FD->getNumParams();
396 llvm::APInt ArgValue = IL->getValue();
398 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
405 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
421 //===----------------------------------------------------------------------===//
423 //===----------------------------------------------------------------------===//
429 D->addAttr(::new (S.Context) PtGuardedVarAttr(S.Context, AL));
451 D->addAttr(::new (S.Context) GuardedByAttr(S.Context, AL, Arg));
462 D->addAttr(::new (S.Context) PtGuardedByAttr(S.Context, AL, Arg));
471 QualType QT = cast<ValueDecl>(D)->getType();
472 if (!QT->isDependentType() && !typeHasCapability(S, QT)) {
491 D->addAttr(::new (S.Context)
501 D->addAttr(::new (S.Context)
521 D->addAttr(::new (S.Context)
533 D->addAttr(::new (S.Context)
541 /// AttrArgNo is used to actually retrieve the argument, so it's base-0.
553 if (!ParamTy->isIntegerType() && !ParamTy->isCharType()) {
554 SourceLocation SrcLoc = AttrArg->getBeginLoc();
569 if (!RetTy->isPointerType()) {
576 // Parameter indices are 1-indexed, hence Index=1
587 // Parameter indices are 1-based, hence Index=2
595 D->addAttr(::new (S.Context)
622 D->addAttr(::new (S.Context) SharedTrylockFunctionAttr(
632 D->addAttr(::new (S.Context) ExclusiveTrylockFunctionAttr(
644 D->addAttr(::new (S.Context) LockReturnedAttr(S.Context, AL, Args[0]));
659 D->addAttr(::new (S.Context)
666 if (!Cond->isTypeDependent()) {
680 if (isa<FunctionDecl>(D) && !Cond->isValueDependent() &&
697 D->addAttr(::new (S.Context) EnableIfAttr(S.Context, AL, Cond, Msg));
705 D->addAttr(EA);
712 : D->getDeclContext()->getRedeclContext();
713 if (const auto *RD = dyn_cast<CXXRecordDecl>(PD); RD && RD->isLocalClass()) {
719 D->addAttr(::new (S.Context)
738 ClassType = MD->getParent();
742 Parms.insert(FD->param_begin(), FD->param_end());
752 assert(E->getType()->getPointeeCXXRecordDecl() == ClassType &&
759 if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl()))
774 if (!MethodDecl->isStatic()) {
781 auto Union = AL.getArg(Index - 1);
783 return Union.get<Expr *>()->getBeginLoc();
784 return Union.get<IdentifierLoc *>()->Loc;
790 FunctionDecl *AttrFD = [&]() -> FunctionDecl * {
796 return dyn_cast_if_present<FunctionDecl>(F->getFoundDecl());
799 if (!AttrFD || !AttrFD->getBuiltinID(true)) {
804 if (AttrFD->getNumParams() != AL.getNumArgs() - 1) {
806 << AL << AttrFD << AttrFD->getNumParams();
824 if (Index > DeclFD->getNumParams()) {
826 << AL << Index << DeclFD << DeclFD->getNumParams();
830 QualType T1 = AttrFD->getParamDecl(I - 1)->getType();
831 QualType T2 = DeclFD->getParamDecl(Index - 1)->getType();
835 S.Diag(IndexExpr->getBeginLoc(), diag::err_attribute_parameter_types)
840 Indices.push_back(Index - 1);
843 D->addAttr(::new (S.Context) DiagnoseAsBuiltinAttr(
861 S.Diag(AL.getArgAsExpr(2)->getBeginLoc(),
869 D->addAttr(::new (S.Context) DiagnoseIfAttr(
886 if (const auto *NBA = D->getAttr<NoBuiltinAttr>())
887 for (StringRef BuiltinName : NBA->builtinNames())
913 S.Diag(D->getLocation(),
917 if (D->hasAttr<NoBuiltinAttr>())
918 D->dropAttr<NoBuiltinAttr>();
919 D->addAttr(::new (S.Context)
924 if (D->hasAttr<PassObjectSizeAttr>()) {
925 S.Diag(D->getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
938 S.Diag(E->getBeginLoc(), diag::err_attribute_argument_out_of_range)
939 << AL << 0 << 3 << E->getSourceRange();
944 // kindness to users, we allow the parameter to be non-const for declarations.
947 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
948 S.Diag(D->getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
952 D->addAttr(::new (S.Context) PassObjectSizeAttr(S.Context, AL, (int)Type));
960 if (!ConsumableAttr::ConvertStrToConsumedState(IL->Ident->getName(),
962 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
963 << IL->Ident;
972 D->addAttr(::new (S.Context) ConsumableAttr(S.Context, AL, DefaultState));
977 QualType ThisType = MD->getFunctionObjectParameterType();
979 if (const CXXRecordDecl *RD = ThisType->getAsCXXRecordDecl()) {
980 if (!RD->hasAttr<ConsumableAttr>()) {
1005 StateString = Ident->Ident->getName();
1006 Loc = Ident->Loc;
1021 D->addAttr(::new (S.Context)
1030 StringRef StateString = Ident->Ident->getName();
1034 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported)
1047 //QualType ReturnType = cast<ParmVarDecl>(D)->getType();
1048 //const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
1050 //if (!RD || !RD->hasAttr<ConsumableAttr>()) {
1056 D->addAttr(::new (S.Context) ParamTypestateAttr(S.Context, AL, ParamState));
1064 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->Ident->getName(),
1066 S.Diag(IL->Loc, diag::warn_attribute_type_not_supported) << AL
1067 << IL->Ident;
1082 // ReturnType = Param->getType();
1086 // ReturnType = Constructor->getFunctionObjectParameterType();
1090 // ReturnType = cast<FunctionDecl>(D)->getCallResultType();
1093 // const CXXRecordDecl *RD = ReturnType->getAsCXXRecordDecl();
1095 // if (!RD || !RD->hasAttr<ConsumableAttr>()) {
1101 D->addAttr(::new (S.Context) ReturnTypestateAttr(S.Context, AL, ReturnState));
1111 StringRef Param = Ident->Ident->getName();
1113 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1123 D->addAttr(::new (S.Context) SetTypestateAttr(S.Context, AL, NewState));
1133 StringRef Param = Ident->Ident->getName();
1135 S.Diag(Ident->Loc, diag::warn_attribute_type_not_supported) << AL
1145 D->addAttr(::new (S.Context) TestTypestateAttr(S.Context, AL, TestState));
1155 TD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1157 bool BitfieldByteAligned = (!FD->getType()->isDependentType() &&
1158 !FD->getType()->isIncompleteType() &&
1159 FD->isBitField() &&
1160 S.Context.getTypeAlign(FD->getType()) <= 8);
1166 << AL << FD->getType();
1168 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1174 FD->addAttr(::new (S.Context) PackedAttr(S.Context, AL));
1183 ClassTemplateDecl *CTD = RD->getDescribedClassTemplate();
1192 if (!T.hasQualifiers() && T->isTypedefNameType()) {
1196 T->getAsCXXRecordDecl())) {
1197 Template = CTSD->getSpecializedTemplate();
1198 } else if (const auto *TST = T->getAs<TemplateSpecializationType>()) {
1199 while (TST && TST->isTypeAlias())
1200 TST = TST->getAliasedType()->getAs<TemplateSpecializationType>();
1202 Template = TST->getTemplateName().getAsTemplateDecl();
1206 D->addAttr(::new (S.Context) PreferredNameAttr(S.Context, AL, TSI));
1213 if (const auto *TT = T->getAs<TypedefType>())
1214 S.Diag(TT->getDecl()->getLocation(), diag::note_entity_declared_at)
1215 << TT->getDecl();
1220 if (T->isReferenceType())
1228 if (const RecordType *UT = T->getAsUnionType()) {
1229 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1230 RecordDecl *UD = UT->getDecl();
1231 for (const auto *I : UD->fields()) {
1232 QualType QT = I->getType();
1233 if (QT->isAnyPointerType() || QT->isBlockPointerType())
1239 return T->isAnyPointerType() || T->isBlockPointerType();
1270 Ex->getSourceRange(),
1287 if (T->isDependentType() || S.isValidPointerAttrType(T))
1298 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, Start, Size));
1304 if (D->getFunctionType()) {
1308 << D->getSourceRange();
1314 if (!attrNonNullArgCheck(S, D->getType(), AL, SourceRange(),
1315 D->getSourceRange()))
1318 D->addAttr(::new (S.Context) NonNullAttr(S.Context, AL, nullptr, 0));
1328 D->addAttr(::new (S.Context) ReturnsNonNullAttr(S.Context, AL));
1332 if (D->isInvalidDecl())
1336 QualType T = cast<ParmVarDecl>(D)->getType();
1343 D->addAttr(::new (S.Context) NoEscapeAttr(S.Context, AL));
1348 *OE = AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr;
1349 S.AddAssumeAlignedAttr(D, AL, E, OE);
1357 Expr *OE) {
1361 AssumeAlignedAttr TmpAttr(Context, CI, E, OE);
1370 if (!E->isValueDependent()) {
1372 if (!(I = E->getIntegerConstantExpr(Context))) {
1373 if (OE)
1376 << E->getSourceRange();
1380 << E->getSourceRange();
1384 if (!I->isPowerOf2()) {
1386 << E->getSourceRange();
1395 if (OE && !OE->isValueDependent() && !OE->isIntegerConstantExpr(Context)) {
1398 << OE->getSourceRange();
1402 D->addAttr(::new (Context) AssumeAlignedAttr(Context, CI, E, OE));
1412 if (!ResultType->isDependentType() &&
1426 if (!Ty->isDependentType() && !Ty->isIntegralType(Context) &&
1427 !Ty->isAlignValT()) {
1428 Diag(ParamExpr->getBeginLoc(), diag::err_attribute_integers_only)
1430 << FuncDecl->getParamDecl(Idx.getASTIndex())->getSourceRange();
1434 D->addAttr(::new (Context) AllocAlignAttr(Context, CI, Idx));
1484 IdentifierInfo *Module = AL.getArgAsIdent(0)->Ident;
1486 StringRef ModuleName = Module->getName();
1500 int Err = -1; // No error
1504 if (!T->isAnyPointerType() && !T->isBlockPointerType())
1508 if (!T->isIntegerType())
1512 if (-1 != Err) {
1514 << Ex->getSourceRange();
1519 for (const auto *I : D->specific_attrs<OwnershipAttr>()) {
1522 if (I->getOwnKind() != K && llvm::is_contained(I->args(), Idx)) {
1526 I->isRegularKeywordAttribute());
1529 I->getOwnKind() == OwnershipAttr::Returns) {
1532 if (!llvm::is_contained(I->args(), Idx)) {
1533 S.Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1534 << I->args_begin()->getSourceIndex();
1535 if (I->args_size())
1537 << Idx.getSourceIndex() << Ex->getSourceRange();
1548 D->addAttr(::new (S.Context)
1569 const DeclContext *Ctx = D->getDeclContext()->getRedeclContext();
1570 if (!Ctx->isFileContext()) {
1598 // FIXME: it would be good for us to keep the WeakRefAttr as-written instead
1605 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1607 D->addAttr(::new (S.Context) WeakRefAttr(S.Context, AL));
1612 // https://github.com/llvm/llvm-project/issues/88825). This should handle the
1629 if (MC->shouldMangleDeclName(ND)) {
1632 MC->mangleName(GlobalDecl(ND), Out);
1634 Name = ND->getIdentifier()->getName();
1637 ND->markUsed(S.Context);
1649 if (FD->isThisDeclarationADefinition()) {
1655 D->addAttr(::new (S.Context) IFuncAttr(S.Context, AL, Str));
1677 if (FD->isThisDeclarationADefinition()) {
1683 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1690 D->addAttr(::new (S.Context) AliasAttr(S.Context, AL, Str));
1701 if (Model != "global-dynamic" && Model != "local-dynamic"
1702 && Model != "initial-exec" && Model != "local-exec") {
1707 D->addAttr(::new (S.Context) TLSModelAttr(S.Context, AL, Model));
1712 if (ResultType->isAnyPointerType() || ResultType->isBlockPointerType()) {
1713 D->addAttr(::new (S.Context) RestrictAttr(S.Context, AL));
1728 if (const auto *Other = D->getAttr<CPUDispatchAttr>()) {
1730 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
1737 if (const auto *Other = D->getAttr<CPUSpecificAttr>()) {
1739 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
1747 if (MD->getParent()->isLambda()) {
1765 StringRef CPUName = CPUArg->Ident->getName().trim();
1768 S.Diag(CPUArg->Loc, diag::err_invalid_cpu_specific_dispatch_value)
1776 Target.CPUSpecificManglingCharacter(Cur->getName());
1781 CPUs.push_back(CPUArg->Ident);
1784 FD->setIsMultiVersion(true);
1786 D->addAttr(::new (S.Context)
1789 D->addAttr(::new (S.Context)
1800 D->addAttr(::new (S.Context) CommonAttr(S.Context, AL));
1818 << AL << AL.isRegularKeywordAttribute() << "non-member functions";
1823 D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));
1836 D->addAttr(::new (S.Context) NoReturnAttr(S.Context, Attrs));
1851 D->addAttr(::new (S.Context) CXX11NoReturnAttr(S.Context, A));
1890 if (!VD || (!VD->getType()->isBlockPointerType() &&
1891 !VD->getType()->isFunctionPointerType())) {
1901 D->addAttr(::new (S.Context) AnalyzerNoReturnAttr(S.Context, AL));
1904 // PS3 PPU-specific.
1930 if (VecReturnAttr *A = D->getAttr<VecReturnAttr>()) {
1943 if (!cast<CXXRecordDecl>(R)->isPOD()) {
1948 for (const auto *I : R->fields()) {
1949 if ((count == 1) || !I->getType()->isVectorType()) {
1956 D->addAttr(::new (S.Context) VecReturnAttr(S.Context, AL));
1964 if (!(Scope->getFlags() & clang::Scope::FunctionDeclarationScope)) {
1971 D->addAttr(::new (S.Context) CarriesDependencyAttr(S.Context, AL));
1982 D->addAttr(::new (S.Context) UnusedAttr(S.Context, AL));
1995 D->addAttr(::new (S.Context) ConstructorAttr(S.Context, AL, priority));
2004 D->addAttr(::new (S.Context) DestructorAttr(S.Context, AL, priority));
2014 D->addAttr(::new (S.Context) AttrTy(S.Context, AL, Str));
2023 = AvailabilityAttr::getPrettyPlatformName(Platform->getName());
2025 PlatformName = Platform->getName();
2098 if (D->hasAttrs()) {
2099 AttrVec &Attrs = D->getAttrs();
2107 IdentifierInfo *OldPlatform = OldAA->getPlatform();
2113 IdentifierInfo *OldEnvironment = OldAA->getEnvironment();
2122 if (OldAA->getPriority() < Priority)
2128 if (OldAA->getPriority() > Priority) {
2130 --e;
2135 VersionTuple OldIntroduced = OldAA->getIntroduced();
2136 VersionTuple OldDeprecated = OldAA->getDeprecated();
2137 VersionTuple OldObsoleted = OldAA->getObsoleted();
2138 bool OldIsUnavailable = OldAA->getUnavailable();
2146 int Which = -1;
2163 if (Which == -1) {
2164 Diag(OldAA->getLocation(),
2166 << AvailabilityAttr::getPrettyPlatformName(Platform->getName())
2177 Diag(OldAA->getLocation(),
2180 << AvailabilityAttr::getPrettyPlatformName(Platform->getName())
2189 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2194 --e;
2209 if (checkAvailabilityAttr(*this, OldAA->getRange(), Platform,
2213 --e;
2238 Avail->setImplicit(Implicit);
2256 IdentifierInfo *II = Platform->Ident;
2257 if (AvailabilityAttr::getPrettyPlatformName(II->getName()).empty())
2258 S.Diag(Platform->Loc, diag::warn_availability_unknown_platform)
2259 << Platform->Ident;
2272 Str = SE->getString();
2276 Replacement = SE->getString();
2278 if (II->isStr("swift")) {
2287 if (II->isStr("fuchsia")) {
2308 IIEnvironment = EnvironmentLoc->Ident;
2310 EnvironmentLoc->Ident->getName()) ==
2312 S.Diag(EnvironmentLoc->Loc, diag::warn_availability_unknown_environment)
2313 << EnvironmentLoc->Ident;
2315 S.Diag(EnvironmentLoc->Loc, diag::err_availability_unexpected_parameter)
2325 D->addAttr(NewAttr);
2331 if (II->getName() == "ios")
2333 else if (II->getName() == "ios_app_extension")
2339 SDKInfo ? SDKInfo->getVersionMapping(
2344 [IOSToWatchOSMapping](VersionTuple Version) -> VersionTuple {
2350 if (auto MappedVersion = IOSToWatchOSMapping->map(
2357 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2382 D->addAttr(NewAttr);
2388 if (II->getName() == "ios")
2390 else if (II->getName() == "ios_app_extension")
2396 SDKInfo ? SDKInfo->getVersionMapping(
2401 [IOSToTvOSMapping](VersionTuple Version) -> VersionTuple {
2406 if (auto MappedVersion = IOSToTvOSMapping->map(
2424 D->addAttr(NewAttr);
2436 if (II->getName() == "ios")
2438 else if (II->getName() == "ios_app_extension")
2457 D->addAttr(NewAttr);
2458 } else if (II->getName() == "macos" && GetSDKInfo() &&
2462 GetSDKInfo()->getVersionMapping(
2470 [&](const VersionTuple &V) -> std::optional<VersionTuple> {
2477 return MacOStoMacCatalystMapping->map(V, VersionTuple(13, 1),
2488 [](const std::optional<VersionTuple> &V) -> VersionTuple {
2501 D->addAttr(NewAttr);
2515 Language = SE->getString();
2518 DefinedIn = SE->getString();
2522 USR = SE->getString();
2524 D->addAttr(::new (S.Context) ExternalSourceSymbolAttr(
2531 T *existingAttr = D->getAttr<T>();
2533 typename T::VisibilityType existingValue = existingAttr->getVisibility();
2536 S.Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2538 D->dropAttr<T>();
2600 D->addAttr(newAttr);
2608 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) {
2610 << AL << 1 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2614 if (Idx->isSigned() && Idx->isNegative()) {
2616 << E->getSourceRange();
2620 sentinel = Idx->getZExtValue();
2627 if (E->isTypeDependent() || !(Idx = E->getIntegerConstantExpr(S.Context))) {
2629 << AL << 2 << AANT_ArgumentIntegerConstant << E->getSourceRange();
2632 nullPos = Idx->getZExtValue();
2634 if ((Idx->isSigned() && Idx->isNegative()) || nullPos > 1) {
2638 << E->getSourceRange();
2644 const FunctionType *FT = FD->getType()->castAs<FunctionType>();
2650 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2655 if (!MD->isVariadic()) {
2660 if (!BD->isVariadic()) {
2665 QualType Ty = V->getType();
2666 if (Ty->isBlockPointerType() || Ty->isFunctionPointerType()) {
2667 const FunctionType *FT = Ty->isFunctionPointerType()
2668 ? D->getFunctionType()
2669 : Ty->castAs<BlockPointerType>()
2670 ->getPointeeType()
2671 ->castAs<FunctionType>();
2672 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2673 int m = Ty->isFunctionPointerType() ? 0 : 1;
2689 D->addAttr(::new (S.Context) SentinelAttr(S.Context, AL, sentinel, nullPos));
2693 if (D->getFunctionType() &&
2694 D->getFunctionType()->getReturnType()->isVoidType() &&
2700 if (MD->getReturnType()->isVoidType()) {
2742 D->addAttr(::new (S.Context) WarnUnusedResultAttr(S.Context, AL, Str));
2748 if (!D->canBeWeakImported(isDef)) {
2763 D->addAttr(::new (S.Context) WeakImportAttr(S.Context, AL));
2777 << AL << E->getSourceRange();
2782 WorkGroupAttr *Existing = D->getAttr<WorkGroupAttr>();
2783 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2784 Existing->getYDim() == WGSize[1] &&
2785 Existing->getZDim() == WGSize[2]))
2788 D->addAttr(::new (S.Context)
2802 if (!ParmType->isExtVectorType() && !ParmType->isFloatingType() &&
2803 (ParmType->isBooleanType() ||
2804 !ParmType->isIntegralType(S.getASTContext()))) {
2809 if (VecTypeHintAttr *A = D->getAttr<VecTypeHintAttr>()) {
2810 if (!S.Context.hasSameType(A->getTypeHint(), ParmType)) {
2816 D->addAttr(::new (S.Context) VecTypeHintAttr(S.Context, AL, ParmTSI));
2825 FD->isFunctionTemplateSpecialization())
2828 if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {
2829 if (ExistingAttr->getName() == Name)
2831 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2873 D->addAttr(NewAttr);
2876 S.UnifySection(NewAttr->getName(),
2895 D->addAttr(::new (S.Context) CodeModelAttr(S.Context, AL, CM));
2904 << toString(std::move(E)) << 0 /*'code-seg'*/;
2916 if (FD->isFunctionTemplateSpecialization())
2919 if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) {
2920 if (ExistingAttr->getName() == Name)
2922 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2937 if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) {
2938 if (!ExistingAttr->isImplicit()) {
2940 ExistingAttr->getName() == Str
2945 D->dropAttr<CodeSegAttr>();
2948 D->addAttr(CSA);
2988 auto CurFeature = StringRef(Feature).drop_front(); // remove + or -.
3002 << Unsupported << None << "branch-protection" << Target;
3038 D->addAttr(NewAttr);
3049 D->addAttr(NewAttr);
3071 Literal->getLocationOfByte(Cur.data() - Literal->getString().data(),
3127 Cur.drop_front(sizeof("arch=") - 1)))
3129 << Unsupported << CPU << Cur.drop_front(sizeof("arch=") - 1)
3156 if (const auto *Other = D->getAttr<TargetClonesAttr>()) {
3158 S.Diag(Other->getLocation(), diag::note_conflicting_attribute);
3174 cast<StringLiteral>(AL.getArgAsExpr(I)->IgnoreParenCasts()), D,
3198 if (MD->getParent()->isLambda()) {
3199 S.Diag(D->getLocation(), diag::err_multiversion_doesnt_support)
3210 cast<FunctionDecl>(D)->setIsMultiVersion();
3213 D->addAttr(NewAttr);
3224 MinVectorWidthAttr *Existing = D->getAttr<MinVectorWidthAttr>();
3225 if (Existing && Existing->getVectorWidth() != VecWidth) {
3230 D->addAttr(::new (S.Context) MinVectorWidthAttr(S.Context, AL, VecWidth));
3235 SourceLocation Loc = E->getExprLoc();
3242 if (DRE->hasQualifier())
3244 FD = dyn_cast<FunctionDecl>(DRE->getDecl());
3245 NI = DRE->getNameInfo();
3252 if (ULE->hasExplicitTemplateArgs())
3255 NI = ULE->getNameInfo();
3259 if (ULE->getType() == S.Context.OverloadTy)
3268 if (FD->getNumParams() != 1) {
3276 QualType Ty = S.Context.getPointerType(cast<VarDecl>(D)->getType());
3277 QualType ParamTy = FD->getParamDecl(0)->getType();
3278 if (S.CheckAssignmentConstraints(FD->getParamDecl(0)->getLocation(),
3288 S.Context, NestedNameSpecifierLoc{}, FD->getLocation(), VD, false,
3289 DeclarationNameInfo{VD->getDeclName(), VD->getLocation()}, VD->getType(),
3296 S.Context.getPointerType(VD->getType()), VK_PRValue, OK_Ordinary, Loc,
3305 FD->getType()->getAs<FunctionProtoType>())) {
3309 D->addAttr(::new (S.Context) CleanupAttr(S.Context, AL, FD));
3321 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3322 if (!EnumExtensibilityAttr::ConvertStrToKind(II->getName(),
3328 D->addAttr(::new (S.Context)
3333 /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
3345 (!Ty->isPointerType() ||
3346 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) {
3348 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0);
3353 auto Instancetype = S.Context.getObjCInstanceTypeDecl()->getTypeForDecl();
3354 if (Ty->getAs<TypedefType>() == Instancetype)
3356 if (auto *Interface = OMD->getClassInterface())
3358 QualType(Interface->getTypeForDecl(), 0));
3361 (!Ty->isPointerType() ||
3362 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) {
3365 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, 0);
3369 D->addAttr(::new (S.Context) FormatArgAttr(S.Context, AL, Idx));
3381 /// getFormatAttrKind - Map from format attribute names to supported format
3403 /// http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Attributes.html
3420 QualType T = cast<VarDecl>(D)->getType();
3423 if (!T->getAs<RecordType>()) {
3442 << E->getSourceRange() << AL << 101 << 65535;
3446 D->addAttr(::new (S.Context) InitPriorityAttr(S.Context, AL, prioritynum));
3451 if (const auto *EA = D->getAttr<ErrorAttr>()) {
3455 bool Match = (EA->isError() && NewAttr == "error") ||
3456 (EA->isWarning() && NewAttr == "warning");
3458 Diag(EA->getLocation(), diag::err_attributes_are_not_compatible)
3461 EA->isRegularKeywordAttribute());
3465 if (EA->getUserDiagnostic() != NewUserDiagnostic) {
3467 Diag(EA->getLoc(), diag::note_previous_attribute);
3469 D->dropAttr<ErrorAttr>();
3478 for (auto *F : D->specific_attrs<FormatAttr>()) {
3479 if (F->getType() == Format &&
3480 F->getFormatIdx() == FormatIdx &&
3481 F->getFirstArg() == FirstArg) {
3484 if (F->getLocation().isInvalid())
3485 F->setRange(CI.getRange());
3494 /// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
3507 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
3508 StringRef Format = II->getName();
3523 << AL << II->getName();
3535 << AL << 2 << IdxExpr->getSourceRange();
3540 unsigned ArgIdx = Idx - 1;
3546 << IdxExpr->getSourceRange();
3549 ArgIdx--;
3556 (!Ty->isPointerType() ||
3557 !Ty->castAs<PointerType>()->getPointeeType()->isCharType())) {
3559 << IdxExpr->getSourceRange() << getFunctionOrMethodParamRange(D, ArgIdx);
3575 << FirstArgExpr->getSourceRange()
3576 << FixItHint::CreateReplacement(FirstArgExpr->getSourceRange(), "0");
3584 << AL << 3 << FirstArgExpr->getSourceRange()
3585 << FixItHint::CreateReplacement(FirstArgExpr->getSourceRange(),
3591 S.Diag(D->getLocation(), diag::warn_gcc_requires_variadic_function) << AL;
3597 << AL << 3 << FirstArgExpr->getSourceRange();
3605 D->addAttr(NewAttr);
3620 FunctionDecl *FD = D->getAsFunction();
3624 NameIdxMapping["__"] = -1;
3629 for (const ParmVarDecl *PVD : FD->parameters())
3630 NameIdxMapping[PVD->getName()] = Idx++;
3641 auto It = NameIdxMapping.find(IdLoc->Ident->getName());
3644 << IdLoc->Ident << IdLoc->Loc;
3648 SR = SourceRange(IdLoc->Loc);
3649 ArgIdx = It->second;
3657 << AL << (I + 1) << IdxExpr->getSourceRange();
3661 // Check oob, excluding the special values, 0 and -1.
3662 if (ArgIdx < -1 || ArgIdx > NumArgs) {
3664 << AL << (I + 1) << IdxExpr->getSourceRange();
3668 SR = IdxExpr->getSourceRange();
3682 ArgIdx -= 1;
3689 // This means the "CalleeIdx" has to be non-negative if "HasImplicitThisParam"
3700 getFunctionOrMethodParamType(D, CalleeIdx - HasImplicitThisParam)
3702 if (!CalleeType || !CalleeType->isFunctionPointerType()) {
3709 CalleeType->getPointeeType()->getUnqualifiedDesugaredType();
3720 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
3722 << AL << (unsigned)(EncodingIndices.size() - 1);
3726 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
3728 << AL << (unsigned)(EncodingIndices.size() - 1);
3732 if (CalleeFnProtoType->isVariadic()) {
3738 if (D->hasAttr<CallbackAttr>()) {
3743 D->addAttr(::new (S.Context) CallbackAttr(
3749 // 'called_once' is only supported in Objective-C and it has
3757 QualType T = cast<ParmVarDecl>(D)->getType();
3764 D->addAttr(::new (S.Context) CalledOnceAttr(S.Context, AL));
3771 if (TD && TD->getUnderlyingType()->isUnionType())
3772 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
3776 if (!RD || !RD->isUnion()) {
3782 if (!RD->isCompleteDefinition()) {
3783 if (!RD->isBeingDefined())
3789 RecordDecl::field_iterator Field = RD->field_begin(),
3790 FieldEnd = RD->field_end();
3797 QualType FirstType = FirstField->getType();
3798 if (FirstType->hasFloatingRepresentation() || FirstType->isVectorType()) {
3799 S.Diag(FirstField->getLocation(),
3801 << FirstType->isVectorType() << FirstType;
3805 if (FirstType->isIncompleteType())
3810 QualType FieldType = Field->getType();
3811 if (FieldType->isIncompleteType())
3824 S.Diag(Field->getLocation(),
3828 S.Diag(FirstField->getLocation(),
3835 RD->addAttr(::new (S.Context) TransparentUnionAttr(S.Context, AL));
3842 CI, MutableArrayRef<Expr *>(Attr->args_begin(), Attr->args_end()))) {
3843 D->addAttr(Attr);
3855 Args.reserve(AL.getNumArgs() - 1);
3874 T = TD->getUnderlyingType();
3876 T = VD->getType();
3880 if (!T->isDependentType() && !T->isAnyPointerType() &&
3881 !T->isReferenceType() && !T->isMemberPointerType()) {
3883 << &TmpAttr << T << D->getSourceRange();
3887 if (!E->isValueDependent()) {
3896 << E->getSourceRange();
3900 D->addAttr(::new (Context) AlignValueAttr(Context, CI, ICE.get()));
3905 D->addAttr(::new (Context) AlignValueAttr(Context, CI, E));
3915 !TInfo->getType()->containsUnexpandedParameterPack()) {
3922 S.DiagnoseUnexpandedParameterPack(TInfo->getTypeLoc().getBeginLoc(),
3937 D->addAttr(::new (S.Context) AlignedAttr(S.Context, AL, true, nullptr));
3942 if (AL.isPackExpansion() && !E->containsUnexpandedParameterPack()) {
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;
3977 if (VD->getStorageClass() == SC_Register)
3979 if (VD->isExceptionVariable())
3982 if (FD->isBitField())
3985 if (ED->getLangOpts().CPlusPlus)
3993 if (DiagKind != -1) {
4010 if (E->isValueDependent()) {
4011 // We can't support a dependent alignment on a non-dependent type,
4012 // because we have no way to model that a type is "alignment-dependent"
4015 if (!TND->getUnderlyingType()->isDependentType()) {
4017 << E->getSourceRange();
4024 AA->setPackExpansion(IsPackExpansion);
4025 D->addAttr(AA);
4041 << MaximumAlignment << E->getSourceRange();
4047 // -- if the constant expression evaluates to zero, the alignment
4054 << E->getSourceRange();
4065 VD->getTLSKind() != VarDecl::TLS_None) {
4066 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
4075 const Type *Ty = VD->getType().getTypePtr();
4076 if (Ty->isVectorType() && AlignVal < 16) {
4077 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4078 << VD->getType() << 16;
4084 AA->setPackExpansion(IsPackExpansion);
4085 AA->setCachedAlignmentValue(
4087 D->addAttr(AA);
4100 if (TS->getType()->isDependentType()) {
4101 // We can't support a dependent alignment on a non-dependent type,
4102 // because we have no way to model that a type is "type-dependent"
4105 if (!TND->getUnderlyingType()->isDependentType()) {
4107 << TS->getTypeLoc().getSourceRange();
4113 AA->setPackExpansion(IsPackExpansion);
4114 D->addAttr(AA);
4123 const Type *Ty = VD->getType().getTypePtr();
4124 if (Ty->isVectorType() &&
4126 Diag(VD->getLocation(), diag::warn_aligned_attr_underaligned)
4127 << VD->getType() << 16;
4133 AA->setPackExpansion(IsPackExpansion);
4134 AA->setCachedAlignmentValue(AlignVal);
4135 D->addAttr(AA);
4139 assert(D->hasAttrs() && "no attributes on decl");
4143 UnderlyingTy = DiagTy = VD->getType();
4147 UnderlyingTy = ED->getIntegerType();
4149 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
4159 for (auto *I : D->specific_attrs<AlignedAttr>()) {
4160 if (I->isAlignmentDependent())
4162 if (I->isAlignas())
4164 Align = std::max(Align, I->getAlignment(Context));
4168 if (Align && DiagTy->isSizelessType()) {
4169 Diag(LastAlignedAttr->getLocation(), diag::err_attribute_sizeless_type)
4175 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
4183 assert(RD->hasDefinition() && "RD has no definition!");
4187 if (!RD->getDefinition()->isCompleteDefinition())
4195 if (RD->calculateInheritanceModel() == ExplicitModel)
4198 if (RD->calculateInheritanceModel() <= ExplicitModel)
4204 Diag(RD->getDefinition()->getLocation(), diag::note_defined_here) << RD;
4208 /// parseModeAttrArg - Parses attribute mode string and returns parsed type
4234 case 'K': // KFmode - IEEE quad precision (__float128)
4275 /// handleModeAttr - This attribute modifies the width of a decl with primitive
4290 IdentifierInfo *Name = AL.getArgAsIdent(0)->Ident;
4297 StringRef Str = Name->getName();
4332 // FIXME: Make sure floating-point mappings are accurate
4341 OldTy = TD->getUnderlyingType();
4345 OldTy = ED->getIntegerType();
4349 OldTy = cast<ValueDecl>(D)->getType();
4351 if (OldTy->isDependentType()) {
4352 D->addAttr(::new (Context) ModeAttr(Context, CI, Name));
4359 if (const auto *VT = OldTy->getAs<VectorType>())
4360 OldElemTy = VT->getElementType();
4365 if ((isa<EnumDecl>(D) || OldElemTy->getAs<EnumType>()) &&
4370 bool IntegralOrAnyEnumType = (OldElemTy->isIntegralOrEnumerationType() &&
4371 !OldElemTy->isBitIntType()) ||
4372 OldElemTy->getAs<EnumType>();
4374 if (!OldElemTy->getAs<BuiltinType>() && !OldElemTy->isComplexType() &&
4381 if (!OldElemTy->isComplexType())
4384 if (!OldElemTy->isFloatingType())
4392 OldElemTy->isSignedIntegerType());
4397 // Only emit diagnostic on host for 128-bit mode attribute
4411 } else if (const auto *OldVT = OldTy->getAs<VectorType>()) {
4418 OldVT->getNumElements() /
4421 Context.getVectorType(NewElemTy, NumElements, OldVT->getVectorKind());
4431 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4433 ED->setIntegerType(NewTy);
4435 cast<ValueDecl>(D)->setType(NewTy);
4437 D->addAttr(::new (Context) ModeAttr(Context, CI, Name));
4441 D->addAttr(::new (S.Context) NoDebugAttr(S.Context, AL));
4447 if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) {
4449 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4453 if (D->hasAttr<AlwaysInlineAttr>())
4464 if (VD->getKind() != Decl::Var) {
4471 // Attribute does not apply to non-static local variables.
4472 if (VD->hasLocalStorage()) {
4473 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4485 if (VD->getKind() != Decl::Var) {
4492 // Attribute does not apply to non-static local variables.
4493 if (VD->hasLocalStorage()) {
4494 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4503 if (OptimizeNoneAttr *Optnone = D->getAttr<OptimizeNoneAttr>()) {
4505 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4509 if (D->hasAttr<MinSizeAttr>())
4517 if (AlwaysInlineAttr *Inline = D->getAttr<AlwaysInlineAttr>()) {
4518 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4520 D->dropAttr<AlwaysInlineAttr>();
4522 if (MinSizeAttr *MinSize = D->getAttr<MinSizeAttr>()) {
4523 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4525 D->dropAttr<MinSizeAttr>();
4528 if (D->hasAttr<OptimizeNoneAttr>())
4537 D->addAttr(Inline);
4542 D->addAttr(MinSize);
4547 D->addAttr(Optnone);
4552 if (VD->hasLocalStorage()) {
4558 if (auto *A = D->getAttr<CUDAConstantAttr>()) {
4559 if (!A->isImplicit())
4561 D->dropAttr<CUDAConstantAttr>();
4563 D->addAttr(::new (S.Context) CUDAConstantAttr(S.Context, AL));
4570 if (!S.getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4571 !isa<IncompleteArrayType>(VD->getType())) {
4575 if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
4579 D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
4584 if (!FD->getReturnType()->isVoidType() &&
4585 !FD->getReturnType()->getAs<AutoType>() &&
4586 !FD->getReturnType()->isInstantiationDependentType()) {
4587 SourceRange RTRange = FD->getReturnTypeSourceRange();
4588 S.Diag(FD->getTypeSpecStartLoc(), diag::err_kern_type_not_void_return)
4589 << FD->getType()
4595 if (Method->isInstance()) {
4596 S.Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4600 S.Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4603 if (FD->isInlineSpecified() && !S.getLangOpts().CUDAIsDevice)
4604 S.Diag(FD->getBeginLoc(), diag::warn_kern_is_inline) << FD;
4607 D->addAttr(::new (S.Context) NVPTXKernelAttr(S.Context, AL));
4609 D->addAttr(::new (S.Context) CUDAGlobalAttr(S.Context, AL));
4615 D->addAttr(NoDebugAttr::CreateImplicit(S.Context));
4620 if (VD->hasLocalStorage()) {
4626 if (auto *A = D->getAttr<CUDADeviceAttr>()) {
4627 if (!A->isImplicit())
4629 D->dropAttr<CUDADeviceAttr>();
4631 D->addAttr(::new (S.Context) CUDADeviceAttr(S.Context, AL));
4636 if (VD->hasLocalStorage()) {
4641 if (!D->hasAttr<HIPManagedAttr>())
4642 D->addAttr(::new (S.Context) HIPManagedAttr(S.Context, AL));
4643 if (!D->hasAttr<CUDADeviceAttr>())
4644 D->addAttr(CUDADeviceAttr::CreateImplicit(S.Context));
4649 if (!Fn->isInlineSpecified()) {
4654 if (S.LangOpts.CPlusPlus && Fn->getStorageClass() != SC_Extern)
4657 D->addAttr(::new (S.Context) GNUInlineAttr(S.Context, AL));
4664 // in the Decl node for syntactic reasoning, e.g., pretty-printing.
4679 D->addAttr(::new (S.Context) FastCallAttr(S.Context, AL));
4682 D->addAttr(::new (S.Context) StdCallAttr(S.Context, AL));
4685 D->addAttr(::new (S.Context) ThisCallAttr(S.Context, AL));
4688 D->addAttr(::new (S.Context) CDeclAttr(S.Context, AL));
4691 D->addAttr(::new (S.Context) PascalAttr(S.Context, AL));
4694 D->addAttr(::new (S.Context) SwiftCallAttr(S.Context, AL));
4697 D->addAttr(::new (S.Context) SwiftAsyncCallAttr(S.Context, AL));
4700 D->addAttr(::new (S.Context) VectorCallAttr(S.Context, AL));
4703 D->addAttr(::new (S.Context) MSABIAttr(S.Context, AL));
4706 D->addAttr(::new (S.Context) SysVABIAttr(S.Context, AL));
4709 D->addAttr(::new (S.Context) RegCallAttr(S.Context, AL));
4724 D->addAttr(::new (S.Context) PcsAttr(S.Context, AL, PCS));
4728 D->addAttr(::new (S.Context) AArch64VectorPcsAttr(S.Context, AL));
4731 D->addAttr(::new (S.Context) AArch64SVEPcsAttr(S.Context, AL));
4734 D->addAttr(::new (S.Context) AMDGPUKernelCallAttr(S.Context, AL));
4737 D->addAttr(::new (S.Context) IntelOclBiccAttr(S.Context, AL));
4740 D->addAttr(::new (S.Context) PreserveMostAttr(S.Context, AL));
4743 D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL));
4746 D->addAttr(::new (S.Context) M68kRTDAttr(S.Context, AL));
4749 D->addAttr(::new (S.Context) PreserveNoneAttr(S.Context, AL));
4752 D->addAttr(::new (S.Context) RISCVVectorCCAttr(S.Context, AL));
4775 D->addAttr(::new (S.Context)
4787 if (ParmType->isReferenceType())
4789 else if (ParmType->isArrayType())
4804 D = D->getCanonicalDecl();
4808 if (const auto *OAttr = D->getAttr<OwnerAttr>()) {
4809 const Type *ExistingDerefType = OAttr->getDerefTypeLoc()
4810 ? OAttr->getDerefType().getTypePtr()
4816 OAttr->isRegularKeywordAttribute());
4817 S.Diag(OAttr->getLocation(), diag::note_conflicting_attribute);
4821 for (Decl *Redecl : D->redecls()) {
4822 Redecl->addAttr(::new (S.Context) OwnerAttr(S.Context, AL, DerefTypeLoc));
4827 if (const auto *PAttr = D->getAttr<PointerAttr>()) {
4828 const Type *ExistingDerefType = PAttr->getDerefTypeLoc()
4829 ? PAttr->getDerefType().getTypePtr()
4835 PAttr->isRegularKeywordAttribute());
4836 S.Diag(PAttr->getLocation(), diag::note_conflicting_attribute);
4840 for (Decl *Redecl : D->redecls()) {
4841 Redecl->addAttr(::new (S.Context)
4850 if (!D->hasAttr<RandomizeLayoutAttr>())
4851 D->addAttr(::new (S.Context) RandomizeLayoutAttr(S.Context, AL));
4858 if (!D->hasAttr<NoRandomizeLayoutAttr>())
4859 D->addAttr(::new (S.Context) NoRandomizeLayoutAttr(S.Context, AL));
4934 } else if (StrRef == "aapcs-vfp") {
4993 A = HostTI->checkCallingConvention(CC);
4995 A = DeviceTI->checkCallingConvention(CC);
5025 IsCXXMethod = FD->isCXXInstanceMember();
5026 IsVariadic = FD->isVariadic();
5055 << NumParamsExpr->getSourceRange();
5063 << Context.getTargetInfo().getRegParmMax() << NumParamsExpr->getSourceRange();
5081 // non-nullptr Expr result on success. Otherwise, it returns nullptr
5091 if (E->isValueDependent())
5095 if (!(I = E->getIntegerConstantExpr(S.Context))) {
5096 S.Diag(E->getExprLoc(), diag::err_attribute_argument_n_type)
5097 << &AL << Idx << AANT_ArgumentIntegerConstant << E->getSourceRange();
5101 if (!I->isIntN(32)) {
5102 S.Diag(E->getExprLoc(), diag::err_ice_too_large)
5107 S.Diag(E->getExprLoc(), diag::warn_attribute_argument_n_negative)
5108 << &AL << Idx << E->getSourceRange();
5138 Diag(MaxBlocks->getBeginLoc(), diag::warn_cuda_maxclusterrank_sm_90)
5139 << OffloadArchToString(SM) << CI << MaxBlocks->getSourceRange();
5157 D->addAttr(Attr);
5187 bool IsPointer = AL.getAttrName()->getName() == "pointer_with_type_tag";
5192 !getFunctionOrMethodParamType(D, ArgumentIdxAST)->isPointerType())
5196 D->addAttr(::new (S.Context) ArgumentWithTypeTagAttr(
5197 S.Context, AL, AL.getArgAsIdent(0)->Ident, ArgumentIdx, TypeTagIdx,
5218 IdentifierInfo *PointerKind = AL.getArgAsIdent(0)->Ident;
5223 D->addAttr(::new (S.Context) TypeTagForDatatypeAttr(
5237 D->addAttr(::new (S.Context)
5256 << &AL << 0 << Count << Arg->getBeginLoc();
5260 D->addAttr(::new (S.Context)
5271 IdentifierInfo *Ident = AL.getArgAsIdent(0)->Ident;
5272 unsigned BuiltinID = Ident->getBuiltinID();
5273 StringRef AliasName = cast<FunctionDecl>(D)->getIdentifier()->getName();
5288 D->addAttr(::new (S.Context) BuiltinAliasAttr(S.Context, AL, Ident));
5296 !CRD || !(CRD->isClass() || CRD->isStruct())) {
5314 S.RequireCompleteType(ParmTSI->getTypeLoc().getBeginLoc(), QT,
5317 D->addAttr(::new (S.Context) PreferredTypeAttr(S.Context, AL, ParmTSI));
5320 //===----------------------------------------------------------------------===//
5322 //===----------------------------------------------------------------------===//
5326 if (const auto *UA = D->getAttr<UuidAttr>()) {
5327 if (declaresSameEntity(UA->getGuidDecl(), GuidDecl))
5329 if (!UA->getGuid().empty()) {
5330 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5332 D->dropAttr<UuidAttr>();
5351 // GUID format is "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" or
5352 // "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}", normalize to the former.
5365 if (StrRef[i] != '-') {
5389 // Cf "SourceLocations of attribute list delimiters - [[ ... , ... ]] etc"
5390 // on cfe-dev.
5396 D->addAttr(UA);
5408 D->addAttr(IA);
5419 if (VD->getTSCSpec() != TSCS_unspecified) {
5423 if (VD->hasLocalStorage()) {
5427 D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
5437 if (FD->isConstexprSpecified() || FD->isConsteval()) {
5439 << FD->isConsteval() << FD;
5443 if (!S.getLangOpts().CPlusPlus20 && MD->isVirtual()) {
5449 D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
5462 if (!NS->isInline()) {
5466 if (NS->isAnonymousNamespace()) {
5471 Tags.push_back(NS->getName());
5479 D->addAttr(::new (S.Context)
5484 for (const auto *I : D->specific_attrs<BTFDeclTagAttr>()) {
5485 if (I->getBTFDeclTag() == Tag)
5498 D->addAttr(::new (S.Context) BTFDeclTagAttr(S.Context, AL, Str));
5546 << AL << Version << VersionExpr->getSourceRange();
5555 D->addAttr(::new (S.Context) LayoutVersionAttr(S.Context, AL, Version));
5560 if (D->hasAttr<DLLExportAttr>()) {
5565 if (D->hasAttr<DLLImportAttr>())
5573 if (DLLImportAttr *Import = D->getAttr<DLLImportAttr>()) {
5574 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
5575 D->dropAttr<DLLImportAttr>();
5578 if (D->hasAttr<DLLExportAttr>())
5592 if (FD->isInlined() && A.getKind() == ParsedAttr::AT_DLLImport &&
5603 MD->getParent()->isLambda()) {
5613 D->addAttr(NewAttr);
5620 if (MSInheritanceAttr *IA = D->getAttr<MSInheritanceAttr>()) {
5621 if (IA->getInheritanceModel() == Model)
5623 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
5626 D->dropAttr<MSInheritanceAttr>();
5630 if (RD->hasDefinition()) {
5641 if (RD->getDescribedClassTemplate()) {
5666 D->addAttr(::new (S.Context) CapabilityAttr(S.Context, AL, N));
5674 D->addAttr(::new (S.Context)
5684 D->addAttr(::new (S.Context) AcquireCapabilityAttr(S.Context, AL, Args.data(),
5694 D->addAttr(::new (S.Context) TryAcquireCapabilityAttr(
5704 D->addAttr(::new (S.Context) ReleaseCapabilityAttr(S.Context, AL, Args.data(),
5722 D->addAttr(RCA);
5727 if (NSD->isAnonymousNamespace()) {
5757 D->addAttr(::new (S.Context) DeprecatedAttr(S.Context, AL, Str, Replacement));
5762 return S->hasGlobalStorage();
5789 S.Diag(D->getLocation(), diag::warn_attribute_type_not_supported_global)
5794 D->addAttr(::new (S.Context) NoSanitizeAttr(S.Context, AL, Sanitizers.data(),
5800 StringRef AttrName = AL.getAttrName()->getName();
5808 S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
5816 // around the issue with hard-coded indices. This is critical for calling
5825 D->addAttr(::new (S.Context)
5831 D->addAttr(Internal);
5848 D->dropAttr<ZeroCallUsedRegsAttr>();
5849 D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
5888 FD->getType(), CountExpr, CountInBytes, OrNull);
5889 FD->setType(CAT);
5908 D->dropAttr<FunctionReturnThunksAttr>();
5909 D->addAttr(FunctionReturnThunksAttr::Create(S.Context, Kind, AL));
5920 if (VDecl && !VDecl->isFunctionPointerType()) {
5925 D->addAttr(NoMergeAttr::Create(S.Context, AL));
5929 D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL));
5933 if (!cast<VarDecl>(D)->hasGlobalStorage()) {
5934 S.Diag(D->getLocation(), diag::err_destroy_attr_on_non_static_var)
5946 assert(cast<VarDecl>(D)->getStorageDuration() == SD_Automatic &&
5948 D->addAttr(::new (S.Context) UninitializedAttr(S.Context, AL));
5959 while (const auto *TT = T->getAs<TypedefType>()) {
5960 IsKernReturnT = (TT->getDecl()->getName() == "kern_return_t");
5961 T = TT->desugar();
5964 S.Diag(D->getBeginLoc(),
5976 QualType RetTy = FD->getReturnType();
5977 if (!RetTy->isPointerType() && !RetTy->isReferenceType()) {
5992 if (PVD->getType()->isIntegerType()) {
6001 D->addAttr(AcquireHandleAttr::Create(S.Context, Argument, AL));
6009 D->addAttr(Attr::Create(S.Context, Argument, AL));
6014 D->addAttr(Attr::Create(S.Context, AL));
6027 IdentifierInfo *II = AL.getArgAsIdent(0)->Ident;
6028 if (!CFGuardAttr::ConvertStrToGuardArg(II->getName(), Arg)) {
6033 D->addAttr(::new (S.Context) CFGuardAttr(S.Context, AL, Arg));
6039 auto Attrs = D->specific_attrs<AttrTy>();
6042 return A->getTCBName() == Name;
6059 << AL.getAttrName()->getName() << ConflictingAttr->getAttrName()->getName()
6062 // Error recovery: drop the non-leaf attribute so that to suppress
6065 D->dropAttr<EnforceTCBAttr>();
6069 D->addAttr(AttrTy::Create(S.Context, Argument, AL));
6074 // Check if the new redeclaration has different leaf-ness in the same TCB.
6078 S.Diag(ConflictingAttr->getLoc(), diag::err_tcb_conflicting_attributes)
6079 << ConflictingAttr->getAttrName()->getName()
6080 << AL.getAttrName()->getName() << TCBName;
6086 D->dropAttr<EnforceTCBAttr>();
6120 if (D->getAttr<VTablePointerAuthenticationAttr>()) {
6129 IL->Ident->getName(), KeyType)) {
6130 S.Diag(IL->Loc, diag::err_invalid_authentication_key) << IL->Ident;
6150 ConvertStrToAddressDiscriminationMode(IL->Ident->getName(),
6152 S.Diag(IL->Loc, diag::err_invalid_address_discrimination) << IL->Ident;
6158 S.Diag(IL->Loc, diag::err_no_default_vtable_pointer_auth) << 1;
6173 IL->Ident->getName(), ED)) {
6174 S.Diag(IL->Loc, diag::err_invalid_extra_discrimination) << IL->Ident;
6210 Decl->addAttr(::new (S.Context) VTablePointerAuthenticationAttr(
6215 //===----------------------------------------------------------------------===//
6217 //===----------------------------------------------------------------------===//
6219 // Returns true if the attribute must delay setting its arguments until after
6222 // Only attributes that accept expression parameter packs can delay arguments.
6229 bool IsLastAttrArg = I == (AttrNumArgs - 1);
6241 // Last case is if the expression is value dependent then it must delay
6244 if (E->isValueDependent() && !ArgMemberCanHoldExpr)
6250 /// ProcessDeclAttribute - Apply the specific attribute to the specified decl if
6263 // structure member declaration because it is a type-specifier-qualifier in
6270 // Unknown attributes are automatically warned on. Target-specific attributes
6302 assert(AL.isTypeAttr() && "Non-type attribute not handled");
6308 // Non-[[]] type attributes are handled in processTypeAttrs(); silently
6318 // - we actually have a `DeclSpec`, i.e. if we're looking at a
6320 // - we are looking at an alias-declaration, where historically we have
6329 << AL << D->getLocation();
6354 // decl-specifier-seq).
6362 // See https://github.com/llvm/llvm-project/issues/55790 for details.
6372 << AL << AL.isRegularKeywordAttribute() << D->getLocation();
6647 /*Extra Args=*/AL, /*pointer-to-OSObject-pointer*/ 3, AL.getRange());
6653 /*Extra Args=*/AL, /*pointer-to-OSObject-poointer*/ 3, AL.getRange());
7119 if (D->hasAttr<WeakRefAttr>() && !D->hasAttr<AliasAttr>()) {
7120 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias)
7122 D->dropAttr<WeakRefAttr>();
7130 if (!D->hasAttr<OpenCLKernelAttr>()) {
7131 // These attributes cannot be applied to a non-kernel function.
7132 if (const auto *A = D->getAttr<ReqdWorkGroupSizeAttr>()) {
7135 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
7136 D->setInvalidDecl();
7137 } else if (const auto *A = D->getAttr<WorkGroupSizeHintAttr>()) {
7138 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
7139 D->setInvalidDecl();
7140 } else if (const auto *A = D->getAttr<VecTypeHintAttr>()) {
7141 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
7142 D->setInvalidDecl();
7143 } else if (const auto *A = D->getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
7144 Diag(D->getLocation(), diag::err_opencl_kernel_attr) << A;
7145 D->setInvalidDecl();
7146 } else if (!D->hasAttr<CUDAGlobalAttr>()) {
7147 if (const auto *A = D->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
7148 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
7149 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction;
7150 D->setInvalidDecl();
7151 } else if (const auto *A = D->getAttr<AMDGPUWavesPerEUAttr>()) {
7152 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
7153 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction;
7154 D->setInvalidDecl();
7155 } else if (const auto *A = D->getAttr<AMDGPUNumSGPRAttr>()) {
7156 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
7157 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction;
7158 D->setInvalidDecl();
7159 } else if (const auto *A = D->getAttr<AMDGPUNumVGPRAttr>()) {
7160 Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
7161 << A << A->isRegularKeywordAttribute() << ExpectedKernelFunction;
7162 D->setInvalidDecl();
7172 if (D->hasAttr<ObjCDesignatedInitializerAttr>() &&
7173 cast<ObjCMethodDecl>(D)->getMethodFamily() != OMF_init) {
7174 Diag(D->getLocation(), diag::err_designated_init_attr_non_init);
7175 D->dropAttr<ObjCDesignatedInitializerAttr>();
7189 if (D && D->hasAttr<BPFPreserveAccessIndexAttr>())
7207 /// checkUnusedDeclAttributes - Check a list of attributes to see if it
7211 // Only warn if the attribute is an unignored, non-type attribute.
7246 FD->getASTContext(), FD->getDeclContext(), Loc, Loc,
7247 DeclarationName(II), FD->getType(), FD->getTypeSourceInfo(), SC_None,
7249 FD->hasPrototype(), ConstexprSpecKind::Unspecified,
7250 FD->getTrailingRequiresClause());
7253 if (FD->getQualifier())
7254 NewFD->setQualifierInfo(FD->getQualifierLoc());
7258 QualType FDTy = FD->getType();
7259 if (const auto *FT = FDTy->getAs<FunctionProtoType>()) {
7261 for (const auto &AI : FT->param_types()) {
7263 Param->setScopeInfo(0, Params.size());
7266 NewFD->setParams(Params);
7269 NewD = VarDecl::Create(VD->getASTContext(), VD->getDeclContext(),
7270 VD->getInnerLocStart(), VD->getLocation(), II,
7271 VD->getType(), VD->getTypeSourceInfo(),
7272 VD->getStorageClass());
7273 if (VD->getQualifier())
7274 cast<VarDecl>(NewD)->setQualifierInfo(VD->getQualifierLoc());
7281 IdentifierInfo *NDId = ND->getIdentifier();
7283 NewD->addAttr(
7284 AliasAttr::CreateImplicit(Context, NDId->getName(), W.getLocation()));
7285 NewD->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation()));
7291 NewD->setDeclContext(CurContext);
7292 NewD->setLexicalDeclContext(CurContext);
7296 ND->addAttr(WeakAttr::CreateImplicit(Context, W.getLocation()));
7301 // It's valid to "forward-declare" #pragma weak, in which case we
7308 if (VD->isExternC())
7311 if (FD->isExternC())
7315 if (IdentifierInfo *Id = ND->getIdentifier()) {
7318 auto &WeakInfos = I->second;
7327 /// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in
7402 // -fno-objc-arc files. We do have to take some care against attempts
7414 if (S.Context.getSourceManager().isInSystemHeader(D->getLocation())) {
7424 /// Handle a delayed forbidden-type diagnostic.
7430 D->addAttr(UnavailableAttr::CreateImplicit(S.Context, "", Reason, DD.Loc));
7437 if (FD->hasAttr<UnavailableAttr>() &&
7472 i = pool->pool_begin(), e = pool->pool_end(); i != e; ++i) {
7482 if (!decl->isInvalidDecl())
7502 } while ((pool = pool->getParent()));
7507 assert(curPool && "re-emitting in undelayed context not supported");
7508 curPool->steal(pool);