36 #include "llvm/ADT/STLExtras.h" 37 #include "llvm/ADT/StringExtras.h" 38 #include "llvm/Support/MathExtras.h" 40 using namespace clang;
72 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
73 isa<ObjCPropertyDecl>(D);
81 return isa<FunctionProtoType>(FnTy);
82 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
90 return cast<FunctionProtoType>(FnTy)->getNumParams();
91 if (
const auto *BD = dyn_cast<BlockDecl>(D))
92 return BD->getNumParams();
93 return cast<ObjCMethodDecl>(D)->param_size();
98 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
99 return FD->getParamDecl(Idx);
100 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
101 return MD->getParamDecl(Idx);
102 if (
const auto *BD = dyn_cast<BlockDecl>(D))
103 return BD->getParamDecl(Idx);
109 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
110 if (
const auto *BD = dyn_cast<BlockDecl>(D))
111 return BD->getParamDecl(Idx)->getType();
113 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
118 return PVD->getSourceRange();
124 return FnTy->getReturnType();
125 return cast<ObjCMethodDecl>(D)->getReturnType();
129 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
130 return FD->getReturnTypeSourceRange();
131 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
132 return MD->getReturnTypeSourceRange();
138 return cast<FunctionProtoType>(FnTy)->isVariadic();
139 if (
const auto *BD = dyn_cast<BlockDecl>(D))
140 return BD->isVariadic();
141 return cast<ObjCMethodDecl>(D)->isVariadic();
145 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
146 return MethodDecl->isInstance();
162 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
163 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
187 template <
typename Compare>
189 unsigned Num,
unsigned Diag,
203 diag::err_attribute_wrong_number_arguments,
204 std::not_equal_to<unsigned>());
212 diag::err_attribute_too_few_arguments,
213 std::less<unsigned>());
221 diag::err_attribute_too_many_arguments,
222 std::greater<unsigned>());
227 template <
typename AttrInfo>
228 static typename std::enable_if<std::is_base_of<Attr, AttrInfo>::value,
231 return AL.getLocation();
240 template <
typename AttrInfo>
242 uint32_t &Val,
unsigned Idx =
UINT_MAX,
243 bool StrictlyUnsigned =
false) {
259 << I.toString(10,
false) << 32 << 1;
263 if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
264 S.
Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
269 Val = (uint32_t)I.getZExtValue();
276 template <
typename AttrInfo>
278 int &Val,
unsigned Idx =
UINT_MAX) {
287 << I.toString(10,
false) << 32 << 0;
297 template <
typename AttrTy>
299 if (
const auto *A = D->
getAttr<AttrTy>()) {
300 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
301 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
307 template <
typename AttrTy>
309 if (
const auto *A = D->
getAttr<AttrTy>()) {
310 S.
Diag(AL.
getLocation(), diag::err_attributes_are_not_compatible) << &AL
312 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
322 template <
typename AttrInfo>
324 Sema &S,
const Decl *D,
const AttrInfo &AI,
unsigned AttrArgNum,
325 const Expr *IdxExpr,
ParamIdx &Idx,
bool CanIndexImplicitThis =
false) {
345 unsigned IdxSource = IdxInt.getLimitedValue(
UINT_MAX);
346 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
347 S.
Diag(
getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
351 if (HasImplicitThisParam && !CanIndexImplicitThis) {
352 if (IdxSource == 1) {
353 S.
Diag(
getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
373 Diag(Loc->
Loc, diag::err_attribute_argument_type)
379 *ArgLocation = Loc->
Loc;
389 if (!Literal || !Literal->isAscii()) {
395 Str = Literal->getString();
401 template <
typename AttrType>
407 template <
typename... DiagnosticArgs>
413 template <
typename T,
typename... DiagnosticArgs>
416 DiagnosticArgs &&... ExtraArgs) {
418 std::forward<DiagnosticArgs>(ExtraArgs)...);
425 template <
typename AttrType,
typename... DiagnosticArgs>
426 static void handleSimpleAttributeOrDiagnose(
Sema &S,
Decl *D,
428 bool PassesCheck,
unsigned DiagID,
429 DiagnosticArgs &&... ExtraArgs) {
435 handleSimpleAttribute<AttrType>(S, D, CI);
438 template <
typename AttrType>
439 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
441 handleSimpleAttribute<AttrType>(S, D, AL);
446 template <
typename AttrType,
typename IncompatibleAttrType,
447 typename... IncompatibleAttrTypes>
448 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
450 if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
452 handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
457 static bool isIntOrBool(
Expr *Exp) {
465 static bool threadSafetyCheckIsSmartPointer(
Sema &S,
const RecordType* RT) {
466 auto IsOverloadedOperatorPresent = [&S](
const RecordDecl *Record,
470 return !Result.
empty();
474 bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
475 bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
476 if (foundStarOperator && foundArrowOperator)
483 for (
auto BaseSpecifier : CXXRecord->
bases()) {
484 if (!foundStarOperator)
485 foundStarOperator = IsOverloadedOperatorPresent(
486 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
487 if (!foundArrowOperator)
488 foundArrowOperator = IsOverloadedOperatorPresent(
489 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
492 if (foundStarOperator && foundArrowOperator)
501 static bool threadSafetyCheckIsPointer(
Sema &S,
const Decl *D,
503 const auto *VD = cast<ValueDecl>(D);
505 if (QT->isAnyPointerType())
515 if (threadSafetyCheckIsSmartPointer(S, RT))
519 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
536 template <
typename AttrType>
537 static bool checkRecordDeclForAttr(
const RecordDecl *RD) {
543 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
545 if (CRD->lookupInBases(
547 const auto &Ty = *BS->getType();
549 if (Ty.isDependentType())
551 return Ty.castAs<RecordType>()->getDecl()->hasAttr<AttrType>();
559 static bool checkRecordTypeForCapability(
Sema &S,
QualType Ty) {
571 if (threadSafetyCheckIsSmartPointer(S, RT))
574 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
577 static bool checkTypedefTypeForCapability(
QualType Ty) {
586 return TN->
hasAttr<CapabilityAttr>();
590 if (checkTypedefTypeForCapability(Ty))
593 if (checkRecordTypeForCapability(S, Ty))
599 static bool isCapabilityExpr(
Sema &S,
const Expr *Ex) {
605 if (
const auto *E = dyn_cast<CastExpr>(Ex))
606 return isCapabilityExpr(S, E->getSubExpr());
607 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
608 return isCapabilityExpr(S, E->getSubExpr());
609 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
610 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
611 E->getOpcode() == UO_Deref)
612 return isCapabilityExpr(S, E->getSubExpr());
614 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
615 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
616 return isCapabilityExpr(S, E->getLHS()) &&
617 isCapabilityExpr(S, E->getRHS());
621 return typeHasCapability(S, Ex->
getType());
629 static void checkAttrArgsAreCapabilityObjs(
Sema &S,
Decl *D,
633 bool ParamIdxOk =
false) {
639 if (MD && !MD->isStatic()) {
642 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
643 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
645 diag::warn_thread_attribute_not_on_capability_member)
646 << AL << MD->getParent();
648 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
653 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
658 Args.push_back(ArgExp);
662 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
663 if (StrLit->getLength() == 0 ||
664 (StrLit->isAscii() && StrLit->getString() == StringRef(
"*"))) {
667 Args.push_back(ArgExp);
673 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
674 Args.push_back(ArgExp);
682 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
683 if (UOp->getOpcode() == UO_AddrOf)
684 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
685 if (DRE->getDecl()->isCXXInstanceMember())
686 ArgTy = DRE->getDecl()->getType();
692 if(!RT && ParamIdxOk) {
696 unsigned int NumParams = FD->getNumParams();
698 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
699 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
700 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
702 diag::err_attribute_argument_out_of_bounds_extra_info)
703 << AL << Idx + 1 << NumParams;
706 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
714 if (!typeHasCapability(S, ArgTy) && !isCapabilityExpr(S, ArgExp))
715 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
718 Args.push_back(ArgExp);
727 if (!threadSafetyCheckIsPointer(S, D, AL))
737 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
738 unsigned Size = Args.size();
749 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
757 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
760 if (!threadSafetyCheckIsPointer(S, D, AL))
772 QualType QT = cast<ValueDecl>(D)->getType();
774 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
779 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
788 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
791 Expr **StartArg = &Args[0];
793 AcquiredAfterAttr(S.
Context, AL, StartArg, Args.size()));
798 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
801 Expr **StartArg = &Args[0];
803 AcquiredBeforeAttr(S.
Context, AL, StartArg, Args.size()));
810 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
817 if (!checkLockFunAttrCommon(S, D, AL, Args))
820 unsigned Size = Args.size();
821 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
823 AssertSharedLockAttr(S.
Context, AL, StartArg, Size));
826 static void handleAssertExclusiveLockAttr(
Sema &S,
Decl *D,
829 if (!checkLockFunAttrCommon(S, D, AL, Args))
832 unsigned Size = Args.size();
833 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
835 AssertExclusiveLockAttr(S.
Context, AL, StartArg, Size));
843 template <
typename AttrInfo>
845 const AttrInfo &AI,
unsigned AttrArgNo) {
846 assert(AI.isArgExpr(AttrArgNo) &&
"Expected expression argument");
847 Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
856 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
868 const auto *FD = cast<FunctionDecl>(D);
870 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only) << AL;
879 if (!checkParamIsIntegerType(S, FD, AL, 0))
881 ParamIdx SizeArgNo(SizeArgNoVal, D);
890 if (!checkParamIsIntegerType(S, FD, AL, 1))
896 AllocSizeAttr(S.
Context, AL, SizeArgNo, NumberArgNo));
905 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
911 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
916 static void handleSharedTrylockFunctionAttr(
Sema &S,
Decl *D,
919 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
926 static void handleExclusiveTrylockFunctionAttr(
Sema &S,
Decl *D,
929 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
939 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
940 unsigned Size = Args.size();
953 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
954 unsigned Size = Args.size();
957 Expr **StartArg = &Args[0];
960 LocksExcludedAttr(S.
Context, AL, StartArg, Size));
964 Expr *&Cond, StringRef &Msg) {
970 Cond = Converted.
get();
977 Msg =
"<no message provided>";
983 S.
Diag(AL.
getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
985 S.
Diag(PDiag.first, PDiag.second);
992 S.
Diag(AL.
getLoc(), diag::ext_clang_enable_if);
996 if (checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1003 class ArgumentDependenceChecker
1008 llvm::SmallPtrSet<const ParmVarDecl *, 16> Parms;
1014 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1017 ClassType =
nullptr;
1022 bool referencesArgs(
Expr *E) {
1030 "`this` doesn't refer to the enclosing class?");
1036 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
1037 if (Parms.count(PVD)) {
1047 S.
Diag(AL.
getLoc(), diag::ext_clang_diagnose_if);
1051 if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1054 StringRef DiagTypeStr;
1058 DiagnoseIfAttr::DiagnosticType DiagType;
1059 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1061 diag::err_diagnose_if_invalid_diagnostic_type);
1065 bool ArgDependent =
false;
1066 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1067 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1069 S.
Context, AL, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D)));
1073 static constexpr
const StringRef kWildcard =
"*";
1076 bool HasWildcard =
false;
1078 const auto AddBuiltinName = [&Names, &HasWildcard](StringRef Name) {
1079 if (Name == kWildcard)
1081 Names.push_back(Name);
1085 if (
const auto *NBA = D->
getAttr<NoBuiltinAttr>())
1086 for (StringRef BuiltinName : NBA->builtinNames())
1087 AddBuiltinName(BuiltinName);
1091 AddBuiltinName(kWildcard);
1093 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
1094 StringRef BuiltinName;
1100 AddBuiltinName(BuiltinName);
1102 S.
Diag(LiteralLoc, diag::warn_attribute_no_builtin_invalid_builtin_name)
1108 Names.erase(std::unique(Names.begin(), Names.end()), Names.end());
1111 if (HasWildcard && Names.size() > 1)
1113 diag::err_attribute_no_builtin_wildcard_or_builtin_name)
1116 if (D->
hasAttr<NoBuiltinAttr>())
1119 NoBuiltinAttr(S.
Context, AL, Names.data(), Names.size()));
1123 if (D->
hasAttr<PassObjectSizeAttr>()) {
1124 S.
Diag(D->
getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
1146 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1147 S.
Diag(D->
getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
1159 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1161 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1166 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1179 if (!RD->
hasAttr<ConsumableAttr>()) {
1180 S.
Diag(AL.
getLoc(), diag::warn_attr_on_unconsumable_class) <<
1194 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1198 for (
unsigned ArgIndex = 0; ArgIndex < AL.
getNumArgs(); ++ArgIndex) {
1201 StringRef StateString;
1212 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1214 S.
Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1218 States.push_back(CallableState);
1222 CallableWhenAttr(S.
Context, AL, States.data(), States.size()));
1232 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1234 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1235 << AL << StateString;
1239 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1264 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1266 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1271 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1305 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1312 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1313 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1318 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1327 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1334 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1335 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1340 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1354 if (
auto *TD = dyn_cast<TagDecl>(D))
1356 else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
1363 if (BitfieldByteAligned)
1365 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1371 if (BitfieldByteAligned)
1372 S.
Diag(AL.
getLoc(), diag::warn_attribute_packed_for_bitfield);
1378 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
1385 if (
const auto *VD = dyn_cast<ObjCIvarDecl>(D)) {
1387 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1388 << AL << VD->getType() << 0;
1392 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
1394 S.
Diag(AL.
getLoc(), diag::warn_iboutlet_object_type)
1395 << AL << PD->getType() << 1;
1400 S.
Diag(AL.
getLoc(), diag::warn_attribute_iboutlet) << AL;
1408 if (!checkIBOutletCommon(S, D, AL))
1418 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1422 if (!checkIBOutletCommon(S, D, AL))
1433 S.
Diag(AL.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1449 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1450 : diag::err_iboutletcollection_type) << QT;
1468 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1470 for (
const auto *I : UD->
fields()) {
1484 bool isReturnValue =
false) {
1487 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1488 << AL << AttrParmRange << TypeRange;
1490 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1491 << AL << AttrParmRange << TypeRange << 0;
1499 for (
unsigned I = 0; I < AL.
getNumArgs(); ++I) {
1507 !attrNonNullArgCheck(
1513 NonNullArgs.push_back(Idx);
1524 I != E && !AnyPointers; ++I) {
1531 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1534 ParamIdx *Start = NonNullArgs.data();
1535 unsigned Size = NonNullArgs.size();
1536 llvm::array_pod_sort(Start, Start + Size);
1544 handleNonNullAttr(S, D, AL);
1546 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1563 if (!attrNonNullArgCheck(S, ResultType, AL,
SourceRange(), SR,
1575 QualType T = cast<ParmVarDecl>(D)->getType();
1577 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1600 AssumeAlignedAttr TmpAttr(Context, CI, E, OE);
1603 if (!isValidPointerAttrType(ResultType,
true)) {
1604 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1605 << &TmpAttr << TmpAttr.getRange() << SR;
1613 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1617 Diag(AttrLoc, diag::err_attribute_argument_type)
1623 if (!I.isPowerOf2()) {
1624 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1634 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1642 D->
addAttr(::
new (Context) AssumeAlignedAttr(Context, CI, E, OE));
1649 AllocAlignAttr TmpAttr(Context, CI,
ParamIdx());
1653 !isValidPointerAttrType(ResultType,
true)) {
1654 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1660 const auto *FuncDecl = cast<FunctionDecl>(D);
1673 D->
addAttr(::
new (Context) AllocAlignAttr(Context, CI, Idx));
1678 static bool normalizeName(StringRef &AttrName) {
1679 if (AttrName.size() > 4 && AttrName.startswith(
"__") &&
1680 AttrName.endswith(
"__")) {
1681 AttrName = AttrName.drop_front(2).drop_back(2);
1697 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1703 OwnershipAttr::OwnershipKind K =
1704 OwnershipAttr(S.
Context, AL,
nullptr,
nullptr, 0).getOwnKind();
1708 case OwnershipAttr::Takes:
1709 case OwnershipAttr::Holds:
1711 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1715 case OwnershipAttr::Returns:
1717 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1725 StringRef ModuleName = Module->
getName();
1726 if (normalizeName(ModuleName)) {
1731 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1741 case OwnershipAttr::Takes:
1742 case OwnershipAttr::Holds:
1746 case OwnershipAttr::Returns:
1752 S.
Diag(AL.
getLoc(), diag::err_ownership_type) << AL << Err
1761 if (I->getOwnKind() != K && I->args_end() !=
1762 std::find(I->args_begin(), I->args_end(), Idx)) {
1763 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << I;
1765 }
else if (K == OwnershipAttr::Returns &&
1766 I->getOwnKind() == OwnershipAttr::Returns) {
1769 if (std::find(I->args_begin(), I->args_end(), Idx) == I->args_end()) {
1770 S.
Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1771 << I->args_begin()->getSourceIndex();
1773 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1779 OwnershipArgs.push_back(Idx);
1782 ParamIdx *Start = OwnershipArgs.data();
1783 unsigned Size = OwnershipArgs.size();
1784 llvm::array_pod_sort(Start, Start + Size);
1786 OwnershipAttr(S.
Context, AL, Module, Start, Size));
1792 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1808 S.
Diag(AL.
getLoc(), diag::err_attribute_weakref_not_global_context)
1809 << cast<NamedDecl>(D);
1853 const auto *FD = cast<FunctionDecl>(D);
1855 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 1;
1868 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_darwin);
1872 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_nvptx);
1876 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1878 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 0;
1882 const auto *VD = cast<VarDecl>(D);
1883 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1884 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << VD << 0;
1911 if (Model !=
"global-dynamic" && Model !=
"local-dynamic" 1912 && Model !=
"initial-exec" && Model !=
"local-exec") {
1913 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1927 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1934 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1936 S.
Diag(AL.
getLoc(), diag::err_attribute_dll_lambda) << AL;
1947 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1956 S.
Diag(CPUArg->
Loc, diag::err_invalid_cpu_specific_dispatch_value)
1957 << CPUName << (AL.
getKind() == ParsedAttr::AT_CPUDispatch);
1962 if (llvm::any_of(CPUs, [CPUName, &Target](
const IdentifierInfo *Cur) {
1966 S.
Diag(AL.
getLoc(), diag::warn_multiversion_duplicate_entries);
1969 CPUs.push_back(CPUArg->
Ident);
1973 if (AL.
getKind() == ParsedAttr::AT_CPUSpecific)
1975 CPUSpecificAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
1978 CPUDispatchAttr(S.
Context, AL, CPUs.data(), CPUs.size()));
1983 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
1993 if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL))
1998 const auto &Arch = Triple.getArch();
1999 if (Arch != llvm::Triple::x86 &&
2000 (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
2001 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_on_arch)
2002 << AL << Triple.getArchName();
2013 if (!isa<ObjCMethodDecl>(D)) {
2014 S.
Diag(Attrs.
getLoc(), diag::warn_attribute_wrong_decl_type)
2024 S.
Diag(Attrs.
getLoc(), diag::warn_nocf_check_attribute_ignored);
2026 handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);
2041 Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored) << AL;
2058 ? diag::err_attribute_wrong_decl_type
2059 : diag::warn_attribute_wrong_decl_type)
2094 if (VecReturnAttr *A = D->
getAttr<VecReturnAttr>()) {
2095 S.
Diag(AL.
getLoc(), diag::err_repeat_attribute) << A;
2099 const auto *R = cast<RecordDecl>(D);
2102 if (!isa<CXXRecordDecl>(R)) {
2103 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2107 if (!cast<CXXRecordDecl>(R)->isPOD()) {
2108 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2112 for (
const auto *I : R->fields()) {
2113 if ((count == 1) || !I->getType()->isVectorType()) {
2114 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2125 if (isa<ParmVarDecl>(D)) {
2130 diag::err_carries_dependency_param_not_function_decl);
2144 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2150 uint32_t priority = ConstructorAttr::DefaultPriority;
2159 uint32_t priority = DestructorAttr::DefaultPriority;
2167 template <
typename AttrTy>
2177 static void handleObjCSuppresProtocolAttr(
Sema &S,
Decl *D,
2179 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2180 S.
Diag(AL.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
2190 VersionTuple Introduced,
2191 VersionTuple Deprecated,
2192 VersionTuple Obsoleted) {
2193 StringRef PlatformName
2194 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2195 if (PlatformName.empty())
2196 PlatformName = Platform->
getName();
2200 if (!Introduced.empty() && !Deprecated.empty() &&
2201 !(Introduced <= Deprecated)) {
2202 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2203 << 1 << PlatformName << Deprecated.getAsString()
2204 << 0 << Introduced.getAsString();
2208 if (!Introduced.empty() && !Obsoleted.empty() &&
2209 !(Introduced <= Obsoleted)) {
2210 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2211 << 2 << PlatformName << Obsoleted.getAsString()
2212 << 0 << Introduced.getAsString();
2216 if (!Deprecated.empty() && !Obsoleted.empty() &&
2217 !(Deprecated <= Obsoleted)) {
2218 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2219 << 2 << PlatformName << Obsoleted.getAsString()
2220 << 1 << Deprecated.getAsString();
2231 static bool versionsMatch(
const VersionTuple &
X,
const VersionTuple &Y,
2232 bool BeforeIsOkay) {
2233 if (
X.empty() || Y.empty())
2239 if (BeforeIsOkay &&
X < Y)
2247 bool Implicit, VersionTuple Introduced, VersionTuple Deprecated,
2248 VersionTuple Obsoleted,
bool IsUnavailable, StringRef Message,
2249 bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK,
2251 VersionTuple MergedIntroduced = Introduced;
2252 VersionTuple MergedDeprecated = Deprecated;
2253 VersionTuple MergedObsoleted = Obsoleted;
2254 bool FoundAny =
false;
2255 bool OverrideOrImpl =
false;
2258 case AMK_Redeclaration:
2259 OverrideOrImpl =
false;
2263 case AMK_ProtocolImplementation:
2264 OverrideOrImpl =
true;
2270 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2271 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2278 if (OldPlatform != Platform) {
2286 if (OldAA->getPriority() <
Priority)
2292 if (OldAA->getPriority() >
Priority) {
2293 Attrs.erase(Attrs.begin() + i);
2299 VersionTuple OldIntroduced = OldAA->getIntroduced();
2300 VersionTuple OldDeprecated = OldAA->getDeprecated();
2301 VersionTuple OldObsoleted = OldAA->getObsoleted();
2302 bool OldIsUnavailable = OldAA->getUnavailable();
2304 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2305 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2307 !(OldIsUnavailable == IsUnavailable ||
2308 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2309 if (OverrideOrImpl) {
2311 VersionTuple FirstVersion;
2312 VersionTuple SecondVersion;
2313 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2315 FirstVersion = OldIntroduced;
2316 SecondVersion = Introduced;
2317 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2319 FirstVersion = Deprecated;
2320 SecondVersion = OldDeprecated;
2321 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2323 FirstVersion = Obsoleted;
2324 SecondVersion = OldObsoleted;
2328 Diag(OldAA->getLocation(),
2329 diag::warn_mismatched_availability_override_unavail)
2330 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2331 << (AMK == AMK_Override);
2333 Diag(OldAA->getLocation(),
2334 diag::warn_mismatched_availability_override)
2336 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2337 << FirstVersion.getAsString() << SecondVersion.getAsString()
2338 << (AMK == AMK_Override);
2340 if (AMK == AMK_Override)
2341 Diag(CI.
getLoc(), diag::note_overridden_method);
2343 Diag(CI.
getLoc(), diag::note_protocol_method);
2345 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2346 Diag(CI.
getLoc(), diag::note_previous_attribute);
2349 Attrs.erase(Attrs.begin() + i);
2354 VersionTuple MergedIntroduced2 = MergedIntroduced;
2355 VersionTuple MergedDeprecated2 = MergedDeprecated;
2356 VersionTuple MergedObsoleted2 = MergedObsoleted;
2358 if (MergedIntroduced2.empty())
2359 MergedIntroduced2 = OldIntroduced;
2360 if (MergedDeprecated2.empty())
2361 MergedDeprecated2 = OldDeprecated;
2362 if (MergedObsoleted2.empty())
2363 MergedObsoleted2 = OldObsoleted;
2365 if (checkAvailabilityAttr(*
this, OldAA->getRange(), Platform,
2366 MergedIntroduced2, MergedDeprecated2,
2367 MergedObsoleted2)) {
2368 Attrs.erase(Attrs.begin() + i);
2373 MergedIntroduced = MergedIntroduced2;
2374 MergedDeprecated = MergedDeprecated2;
2375 MergedObsoleted = MergedObsoleted2;
2381 MergedIntroduced == Introduced &&
2382 MergedDeprecated == Deprecated &&
2383 MergedObsoleted == Obsoleted)
2388 if (!checkAvailabilityAttr(*
this, CI.
getRange(), Platform, MergedIntroduced,
2389 MergedDeprecated, MergedObsoleted) &&
2391 auto *Avail = ::new (Context) AvailabilityAttr(
2392 Context, CI, Platform, Introduced, Deprecated, Obsoleted, IsUnavailable,
2393 Message, IsStrict, Replacement, Priority);
2394 Avail->setImplicit(Implicit);
2406 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2407 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2420 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getMessageExpr()))
2421 Str = SE->getString();
2422 StringRef Replacement;
2424 Replacement = SE->getString();
2426 if (II->
isStr(
"swift")) {
2428 (!IsUnavailable && !Deprecated.
isValid())) {
2430 diag::warn_availability_swift_unavailable_deprecated_only);
2440 Obsoleted.
Version, IsUnavailable, Str, IsStrict, Replacement,
2451 else if (II->
getName() ==
"ios_app_extension")
2455 auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
2456 if (Version.empty())
2458 auto Major = Version.getMajor();
2459 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2460 if (NewMajor >= 2) {
2461 if (Version.getMinor().hasValue()) {
2462 if (Version.getSubminor().hasValue())
2463 return VersionTuple(NewMajor, Version.getMinor().getValue(),
2464 Version.getSubminor().getValue());
2466 return VersionTuple(NewMajor, Version.getMinor().getValue());
2468 return VersionTuple(NewMajor);
2471 return VersionTuple(2, 0);
2474 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2475 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2476 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2479 ND, AL, NewII,
true , NewIntroduced, NewDeprecated,
2480 NewObsoleted, IsUnavailable, Str, IsStrict, Replacement,
2492 else if (II->
getName() ==
"ios_app_extension")
2497 ND, AL, NewII,
true , Introduced.
Version,
2498 Deprecated.
Version, Obsoleted.
Version, IsUnavailable, Str, IsStrict,
2507 static void handleExternalSourceSymbolAttr(
Sema &S,
Decl *D,
2512 "Invalid number of arguments in an external_source_symbol attribute");
2515 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(0)))
2516 Language = SE->getString();
2517 StringRef DefinedIn;
2518 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(1)))
2519 DefinedIn = SE->getString();
2520 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2523 S.
Context, AL, Language, DefinedIn, IsGeneratedDeclaration));
2528 typename T::VisibilityType value) {
2529 T *existingAttr = D->
getAttr<T>();
2531 typename T::VisibilityType existingValue = existingAttr->
getVisibility();
2532 if (existingValue == value)
2534 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2535 S.
Diag(CI.
getLoc(), diag::note_previous_attribute);
2543 VisibilityAttr::VisibilityType Vis) {
2544 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, CI, Vis);
2547 TypeVisibilityAttr *
2549 TypeVisibilityAttr::VisibilityType Vis) {
2550 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, CI, Vis);
2554 bool isTypeVisibility) {
2556 if (isa<TypedefNameDecl>(D)) {
2562 if (isTypeVisibility &&
2563 !(isa<TagDecl>(D) ||
2564 isa<ObjCInterfaceDecl>(D) ||
2565 isa<NamespaceDecl>(D))) {
2577 VisibilityAttr::VisibilityType
type;
2578 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2579 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2586 if (type == VisibilityAttr::Protected &&
2588 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2593 if (isTypeVisibility) {
2595 D, AL, (TypeVisibilityAttr::VisibilityType)type);
2606 S.
Diag(AL.
getLoc(), diag::err_objc_direct_on_protocol) <<
false;
2611 handleSimpleAttribute<ObjCDirectAttr>(S, D, AL);
2613 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2617 static void handleObjCDirectMembersAttr(
Sema &S,
Decl *D,
2620 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
2622 S.
Diag(AL.
getLoc(), diag::warn_objc_direct_ignored) << AL;
2627 const auto *M = cast<ObjCMethodDecl>(D);
2629 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2635 ObjCMethodFamilyAttr::FamilyKind F;
2636 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2637 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL << IL->
Ident;
2642 !M->getReturnType()->isObjCObjectPointerType()) {
2643 S.
Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2644 << M->getReturnType();
2653 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2654 QualType T = TD->getUnderlyingType();
2656 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2660 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2663 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
2680 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2681 QualType T = TD->getUnderlyingType();
2683 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2695 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2701 BlocksAttr::BlockType
type;
2702 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
2703 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
2711 unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
2717 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2722 if (Idx.isSigned() && Idx.isNegative()) {
2723 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2728 sentinel = Idx.getZExtValue();
2731 unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
2737 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2741 nullPos = Idx.getZExtValue();
2743 if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2746 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2752 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2754 if (isa<FunctionNoProtoType>(FT)) {
2755 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2759 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2760 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2763 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
2765 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2768 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
2769 if (!BD->isVariadic()) {
2770 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2773 }
else if (
const auto *
V = dyn_cast<VarDecl>(D)) {
2779 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2781 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2785 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2790 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2800 !isa<CXXConstructorDecl>(D)) {
2801 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2804 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
2806 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2819 if (LO.CPlusPlus && !LO.CPlusPlus2a)
2820 S.
Diag(AL.
getLoc(), diag::ext_cxx2a_attr) << AL;
2828 }
else if (LO.CPlusPlus && !LO.CPlusPlus17)
2829 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2840 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
2842 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
2844 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
2847 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2857 template <
typename WorkGroupAttr>
2860 for (
unsigned i = 0; i < 3; ++i) {
2865 if (WGSize[i] == 0) {
2866 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2872 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
2873 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2874 Existing->getYDim() == WGSize[1] &&
2875 Existing->getZDim() == WGSize[2]))
2876 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2879 WorkGroupAttr(S.
Context, AL, WGSize[0], WGSize[1], WGSize[2]));
2889 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2894 OpenCLIntelReqdSubGroupSizeAttr *Existing =
2895 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
2896 if (Existing && Existing->getSubGroupSize() != SGSize)
2897 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2900 OpenCLIntelReqdSubGroupSizeAttr(S.
Context, AL, SGSize));
2905 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2911 assert(ParmTSI &&
"no type source info for attribute argument");
2916 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument) << 2 << AL;
2920 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
2922 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2934 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2939 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
2940 if (ExistingAttr->getName() == Name)
2942 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2944 Diag(CI.
getLoc(), diag::note_previous_attribute);
2947 return ::new (Context) SectionAttr(Context, CI, Name);
2952 if (!Error.empty()) {
2953 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error
2973 if (!Error.empty()) {
2974 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
2987 StringRef CodeSegName) {
2990 if (!Error.empty()) {
2991 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3003 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3007 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3008 if (ExistingAttr->getName() == Name)
3010 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3012 Diag(CI.
getLoc(), diag::note_previous_attribute);
3015 return ::new (Context) CodeSegAttr(Context, CI, Name);
3023 if (!checkCodeSegName(S, LiteralLoc, Str))
3025 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3026 if (!ExistingAttr->isImplicit()) {
3028 ExistingAttr->getName() == Str
3029 ? diag::warn_duplicate_codeseg_attribute
3030 : diag::err_conflicting_codeseg_attribute);
3043 enum SecondParam { None, Architecture };
3044 for (
auto Str : {
"tune=",
"fpmath="})
3045 if (AttrStr.find(Str) != StringRef::npos)
3046 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3053 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3057 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3058 << Duplicate << None <<
"arch=";
3060 for (
const auto &Feature : ParsedAttrs.
Features) {
3061 auto CurFeature = StringRef(Feature).drop_front();
3063 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3073 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3076 return Diag(LiteralLoc, diag::err_invalid_branch_protection_spec)
3090 TargetAttr *NewAttr = ::new (S.
Context) TargetAttr(S.
Context, AL, Str);
3102 MinVectorWidthAttr *Existing = D->
getAttr<MinVectorWidthAttr>();
3103 if (Existing && Existing->getVectorWidth() != VecWidth) {
3104 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3119 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3120 if (DRE->hasQualifier())
3121 S.
Diag(Loc, diag::warn_cleanup_ext);
3123 NI = DRE->getNameInfo();
3125 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3129 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3130 if (ULE->hasExplicitTemplateArgs())
3131 S.
Diag(Loc, diag::warn_cleanup_ext);
3133 NI = ULE->getNameInfo();
3135 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3142 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3147 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3158 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3159 << NI.
getName() << ParamTy << Ty;
3166 static void handleEnumExtensibilityAttr(
Sema &S,
Decl *D,
3169 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3176 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3177 ExtensibilityKind)) {
3178 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3183 EnumExtensibilityAttr(S.
Context, AL, ExtensibilityKind));
3198 if (NotNSStringTy &&
3202 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3212 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3213 << (NotNSStringTy ?
"string type" :
"NSString")
3221 enum FormatAttrKind {
3232 static FormatAttrKind getFormatAttrKind(StringRef Format) {
3233 return llvm::StringSwitch<FormatAttrKind>(Format)
3235 .Case(
"NSString", NSStringFormat)
3236 .Case(
"CFString", CFStringFormat)
3237 .Case(
"strftime", StrftimeFormat)
3240 .Cases(
"scanf",
"printf",
"printf0",
"strfmon", SupportedFormat)
3241 .Cases(
"cmn_err",
"vcmn_err",
"zcmn_err", SupportedFormat)
3242 .Case(
"kprintf", SupportedFormat)
3243 .Case(
"freebsd_kprintf", SupportedFormat)
3244 .Case(
"os_trace", SupportedFormat)
3245 .Case(
"os_log", SupportedFormat)
3247 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag", IgnoredFormat)
3248 .Default(InvalidFormat);
3255 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3260 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3264 QualType T = cast<VarDecl>(D)->getType();
3268 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3274 uint32_t prioritynum;
3280 if (prioritynum < 101 || prioritynum > 65535) {
3281 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
3294 if (F->getType() == Format &&
3295 F->getFormatIdx() == FormatIdx &&
3296 F->getFirstArg() == FirstArg) {
3299 if (F->getLocation().isInvalid())
3305 return ::new (Context) FormatAttr(Context, CI, Format, FormatIdx, FirstArg);
3312 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3323 StringRef Format = II->
getName();
3325 if (normalizeName(Format)) {
3331 FormatAttrKind
Kind = getFormatAttrKind(Format);
3333 if (Kind == IgnoredFormat)
3336 if (Kind == InvalidFormat) {
3337 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3348 if (Idx < 1 || Idx > NumArgs) {
3349 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3355 unsigned ArgIdx = Idx - 1;
3357 if (HasImplicitThisParam) {
3360 diag::err_format_attribute_implicit_this_format_string)
3370 if (Kind == CFStringFormat) {
3372 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3377 }
else if (Kind == NSStringFormat) {
3381 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3388 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3401 if (FirstArg != 0) {
3405 S.
Diag(D->
getLocation(), diag::err_format_attribute_requires_variadic);
3412 if (Kind == StrftimeFormat) {
3413 if (FirstArg != 0) {
3414 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
3419 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
3420 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3434 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_no_callee)
3443 assert(FD &&
"Expected a function declaration!");
3445 llvm::StringMap<int> NameIdxMapping;
3446 NameIdxMapping[
"__"] = -1;
3448 NameIdxMapping[
"this"] = 0;
3452 NameIdxMapping[PVD->getName()] = Idx++;
3454 auto UnknownName = NameIdxMapping.end();
3457 for (
unsigned I = 0, E = AL.
getNumArgs(); I < E; ++I) {
3463 auto It = NameIdxMapping.find(IdLoc->
Ident->
getName());
3464 if (It == UnknownName) {
3465 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_argument_unknown)
3471 ArgIdx = It->second;
3478 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3484 if (ArgIdx < -1 || ArgIdx > NumArgs) {
3485 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3492 llvm_unreachable(
"Unexpected ParsedAttr argument type!");
3495 if (ArgIdx == 0 && !HasImplicitThisParam) {
3496 S.
Diag(AL.
getLoc(), diag::err_callback_implicit_this_not_available)
3503 if (!HasImplicitThisParam && ArgIdx > 0)
3506 EncodingIndices.push_back(ArgIdx);
3509 int CalleeIdx = EncodingIndices.front();
3513 if (CalleeIdx < (
int)HasImplicitThisParam) {
3514 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_invalid_callee)
3521 const Type *CalleeType =
3525 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3530 const Type *CalleeFnType =
3536 if (!CalleeFnProtoType) {
3537 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3542 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
3543 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3544 << AL << (
unsigned)(EncodingIndices.size() - 1);
3548 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
3549 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3550 << AL << (
unsigned)(EncodingIndices.size() - 1);
3554 if (CalleeFnProtoType->isVariadic()) {
3560 if (D->
hasAttr<CallbackAttr>()) {
3566 S.
Context, AL, EncodingIndices.data(), EncodingIndices.size()));
3573 if (TD && TD->getUnderlyingType()->isUnionType())
3574 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
3579 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type) << AL
3587 diag::warn_transparent_union_attribute_not_definition);
3593 if (Field == FieldEnd) {
3594 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3602 diag::warn_transparent_union_attribute_floating)
3611 for (; Field != FieldEnd; ++Field) {
3612 QualType FieldType = Field->getType();
3626 S.
Diag(Field->getLocation(),
3627 diag::warn_transparent_union_attribute_field_size_align)
3628 << isSize << Field->getDeclName() << FieldBits;
3629 unsigned FirstBits = isSize? FirstSize : FirstAlign;
3631 diag::note_transparent_union_first_field_size_align)
3632 << isSize << FirstBits;
3649 if (I->getAnnotation() == Str)
3661 AlignValueAttr TmpAttr(Context, CI, E);
3665 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
3666 T = TD->getUnderlyingType();
3667 else if (
const auto *VD = dyn_cast<ValueDecl>(D))
3670 llvm_unreachable(
"Unknown decl type for align_value");
3674 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
3682 = VerifyIntegerConstantExpression(E, &Alignment,
3683 diag::err_align_value_attribute_argument_not_int,
3688 if (!Alignment.isPowerOf2()) {
3689 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3694 D->
addAttr(::
new (Context) AlignValueAttr(Context, CI, ICE.
get()));
3699 D->
addAttr(::
new (Context) AlignValueAttr(Context, CI, E));
3705 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3717 diag::err_pack_expansion_without_parameter_packs);
3728 bool IsPackExpansion) {
3729 AlignedAttr TmpAttr(Context, CI,
true, E);
3733 if (TmpAttr.isAlignas()) {
3746 if (isa<ParmVarDecl>(D)) {
3748 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
3751 if (VD->isExceptionVariable())
3753 }
else if (
const auto *FD = dyn_cast<FieldDecl>(D)) {
3754 if (FD->isBitField())
3756 }
else if (!isa<TagDecl>(D)) {
3757 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
3762 if (DiagKind != -1) {
3763 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
3764 << &TmpAttr << DiagKind;
3773 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
3774 if (!TND->getUnderlyingType()->isDependentType()) {
3775 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
3782 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
true, E);
3783 AA->setPackExpansion(IsPackExpansion);
3791 = VerifyIntegerConstantExpression(E, &Alignment,
3792 diag::err_aligned_attribute_argument_not_int,
3797 uint64_t AlignVal = Alignment.getZExtValue();
3804 if (!(TmpAttr.isAlignas() && !Alignment)) {
3805 if (!llvm::isPowerOf2_64(AlignVal)) {
3806 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3813 unsigned MaxValidAlignment =
3816 if (AlignVal > MaxValidAlignment) {
3817 Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
3823 unsigned MaxTLSAlign =
3826 const auto *VD = dyn_cast<
VarDecl>(D);
3827 if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
3829 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
3830 << (
unsigned)AlignVal << VD << MaxTLSAlign;
3835 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
true, ICE.
get());
3836 AA->setPackExpansion(IsPackExpansion);
3844 AlignedAttr *AA = ::new (Context) AlignedAttr(Context, CI,
false, TS);
3845 AA->setPackExpansion(IsPackExpansion);
3850 assert(D->
hasAttrs() &&
"no attributes on decl");
3853 if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
3854 UnderlyingTy = DiagTy = VD->getType();
3856 UnderlyingTy = DiagTy = Context.
getTagDeclType(cast<TagDecl>(D));
3857 if (
const auto *ED = dyn_cast<EnumDecl>(D))
3858 UnderlyingTy = ED->getIntegerType();
3860 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
3867 AlignedAttr *AlignasAttr =
nullptr;
3870 if (I->isAlignmentDependent())
3874 Align =
std::max(Align, I->getAlignment(Context));
3877 if (AlignasAttr && Align) {
3880 if (NaturalAlign > RequestedAlign)
3881 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
3882 << DiagTy << (
unsigned)NaturalAlign.
getQuantity();
3908 Diag(Range.
getBegin(), diag::err_mismatched_ms_inheritance)
3917 static void parseModeAttrArg(
Sema &S, StringRef Str,
unsigned &DestWidth,
3918 bool &IntegerMode,
bool &ComplexMode) {
3920 ComplexMode =
false;
3921 switch (Str.size()) {
3943 if (Str[1] ==
'F') {
3944 IntegerMode =
false;
3945 }
else if (Str[1] ==
'C') {
3946 IntegerMode =
false;
3948 }
else if (Str[1] !=
'I') {
3957 else if (Str ==
"byte")
3961 if (Str ==
"pointer")
3965 if (Str ==
"unwind_word")
3981 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
3993 StringRef Str = Name->
getName();
3997 unsigned DestWidth = 0;
3998 bool IntegerMode =
true;
3999 bool ComplexMode =
false;
4001 if (Str.size() >= 4 && Str[0] ==
'V') {
4003 size_t StrSize = Str.size();
4004 size_t VectorStringLength = 0;
4005 while ((VectorStringLength + 1) < StrSize &&
4006 isdigit(Str[VectorStringLength + 1]))
4007 ++VectorStringLength;
4008 if (VectorStringLength &&
4009 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
4010 VectorSize.isPowerOf2()) {
4011 parseModeAttrArg(*
this, Str.substr(VectorStringLength + 1), DestWidth,
4012 IntegerMode, ComplexMode);
4014 if (!InInstantiation)
4015 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
4022 parseModeAttrArg(*
this, Str, DestWidth, IntegerMode, ComplexMode);
4029 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
4034 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4035 OldTy = TD->getUnderlyingType();
4036 else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4039 OldTy = ED->getIntegerType();
4041 OldTy = Context.
IntTy;
4043 OldTy = cast<ValueDecl>(D)->getType();
4046 D->
addAttr(::
new (Context) ModeAttr(Context, CI, Name));
4054 OldElemTy = VT->getElementType();
4060 VectorSize.getBoolValue()) {
4061 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << CI.
getRange();
4064 bool IntegralOrAnyEnumType =
4068 !IntegralOrAnyEnumType)
4069 Diag(AttrLoc, diag::err_mode_not_primitive);
4070 else if (IntegerMode) {
4071 if (!IntegralOrAnyEnumType)
4072 Diag(AttrLoc, diag::err_mode_wrong_type);
4073 }
else if (ComplexMode) {
4075 Diag(AttrLoc, diag::err_mode_wrong_type);
4078 Diag(AttrLoc, diag::err_mode_wrong_type);
4089 if (NewElemTy.
isNull()) {
4090 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4099 if (VectorSize.getBoolValue()) {
4100 NewTy = Context.
getVectorType(NewTy, VectorSize.getZExtValue(),
4105 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4108 unsigned NumElements = Context.
getTypeSize(OldElemTy) *
4109 OldVT->getNumElements() /
4112 Context.
getVectorType(NewElemTy, NumElements, OldVT->getVectorKind());
4116 Diag(AttrLoc, diag::err_mode_wrong_type);
4121 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
4122 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4123 else if (
auto *ED = dyn_cast<EnumDecl>(D))
4124 ED->setIntegerType(NewTy);
4126 cast<ValueDecl>(D)->setType(NewTy);
4128 D->
addAttr(::
new (Context) ModeAttr(Context, CI, Name));
4138 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4139 Diag(CI.
getLoc(), diag::warn_attribute_ignored) << Ident;
4140 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4144 if (D->
hasAttr<AlwaysInlineAttr>())
4147 return ::new (Context) AlwaysInlineAttr(Context, CI);
4151 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4154 return ::new (Context) CommonAttr(Context, AL);
4158 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4161 return ::new (Context) CommonAttr(Context, AL);
4166 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4169 if (VD->getKind() != Decl::Var) {
4170 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4176 if (VD->hasLocalStorage()) {
4177 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4182 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4185 return ::new (Context) InternalLinkageAttr(Context, AL);
4187 InternalLinkageAttr *
4189 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4192 if (VD->getKind() != Decl::Var) {
4193 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4199 if (VD->hasLocalStorage()) {
4200 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4205 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4208 return ::new (Context) InternalLinkageAttr(Context, AL);
4212 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4213 Diag(CI.
getLoc(), diag::warn_attribute_ignored) <<
"'minsize'";
4214 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4218 if (D->
hasAttr<MinSizeAttr>())
4221 return ::new (Context) MinSizeAttr(Context, CI);
4225 Decl *D,
const NoSpeculativeLoadHardeningAttr &AL) {
4226 if (checkAttrMutualExclusion<SpeculativeLoadHardeningAttr>(*
this, D, AL))
4229 return ::new (Context) NoSpeculativeLoadHardeningAttr(Context, AL);
4234 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4235 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4236 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4239 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4240 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4241 Diag(CI.
getLoc(), diag::note_conflicting_attribute);
4245 if (D->
hasAttr<OptimizeNoneAttr>())
4248 return ::new (Context) OptimizeNoneAttr(Context, CI);
4252 Decl *D,
const SpeculativeLoadHardeningAttr &AL) {
4253 if (checkAttrMutualExclusion<NoSpeculativeLoadHardeningAttr>(*
this, D, AL))
4256 return ::new (Context) SpeculativeLoadHardeningAttr(Context, AL);
4260 if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL))
4263 if (AlwaysInlineAttr *Inline =
4279 if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL))
4281 const auto *VD = cast<VarDecl>(D);
4282 if (!VD->hasGlobalStorage()) {
4283 S.
Diag(AL.
getLoc(), diag::err_cuda_nonglobal_constant);
4290 if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL))
4292 const auto *VD = cast<VarDecl>(D);
4295 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4296 !isa<IncompleteArrayType>(VD->getType())) {
4297 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4300 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4308 if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL) ||
4309 checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL)) {
4312 const auto *FD = cast<FunctionDecl>(D);
4323 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4324 if (Method->isInstance()) {
4325 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4329 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4339 const auto *Fn = cast<FunctionDecl>(D);
4340 if (!Fn->isInlineSpecified()) {
4341 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4346 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_cplusplus_without_extern);
4360 if (!isa<ObjCMethodDecl>(D)) {
4361 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4367 case ParsedAttr::AT_FastCall:
4370 case ParsedAttr::AT_StdCall:
4373 case ParsedAttr::AT_ThisCall:
4376 case ParsedAttr::AT_CDecl:
4379 case ParsedAttr::AT_Pascal:
4382 case ParsedAttr::AT_SwiftCall:
4385 case ParsedAttr::AT_VectorCall:
4388 case ParsedAttr::AT_MSABI:
4391 case ParsedAttr::AT_SysVABI:
4394 case ParsedAttr::AT_RegCall:
4397 case ParsedAttr::AT_Pcs: {
4398 PcsAttr::PCSType PCS;
4401 PCS = PcsAttr::AAPCS;
4404 PCS = PcsAttr::AAPCS_VFP;
4407 llvm_unreachable(
"unexpected calling convention in pcs attribute");
4413 case ParsedAttr::AT_AArch64VectorPcs:
4416 case ParsedAttr::AT_IntelOclBicc:
4419 case ParsedAttr::AT_PreserveMost:
4422 case ParsedAttr::AT_PreserveAll:
4426 llvm_unreachable(
"unexpected attribute kind");
4434 std::vector<StringRef> DiagnosticIdentifiers;
4435 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
4443 DiagnosticIdentifiers.push_back(RuleName);
4446 SuppressAttr(S.
Context, AL, DiagnosticIdentifiers.data(),
4447 DiagnosticIdentifiers.size()));
4456 unsigned SelectIdx = ~0U;
4462 if (SelectIdx != ~0U) {
4463 S.
Diag(AL.
getLoc(), diag::err_attribute_invalid_argument)
4472 if (AL.
getKind() == ParsedAttr::AT_Owner) {
4473 if (checkAttrMutualExclusion<PointerAttr>(S, D, AL))
4475 if (
const auto *OAttr = D->
getAttr<OwnerAttr>()) {
4476 const Type *ExistingDerefType = OAttr->getDerefTypeLoc()
4477 ? OAttr->getDerefType().getTypePtr()
4480 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
4482 S.
Diag(OAttr->getLocation(), diag::note_conflicting_attribute);
4487 Redecl->addAttr(::
new (S.
Context) OwnerAttr(S.
Context, AL, DerefTypeLoc));
4490 if (checkAttrMutualExclusion<OwnerAttr>(S, D, AL))
4492 if (
const auto *PAttr = D->
getAttr<PointerAttr>()) {
4493 const Type *ExistingDerefType = PAttr->getDerefTypeLoc()
4494 ? PAttr->getDerefType().getTypePtr()
4497 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
4499 S.
Diag(PAttr->getLocation(), diag::note_conflicting_attribute);
4504 Redecl->addAttr(::
new (S.
Context)
4505 PointerAttr(S.
Context, AL, DerefTypeLoc));
4520 unsigned ReqArgs = Attrs.
getKind() == ParsedAttr::AT_Pcs ? 1 : 0;
4528 case ParsedAttr::AT_CDecl:
4531 case ParsedAttr::AT_FastCall:
4534 case ParsedAttr::AT_StdCall:
4537 case ParsedAttr::AT_ThisCall:
4540 case ParsedAttr::AT_Pascal:
4543 case ParsedAttr::AT_SwiftCall:
4546 case ParsedAttr::AT_VectorCall:
4549 case ParsedAttr::AT_AArch64VectorPcs:
4552 case ParsedAttr::AT_RegCall:
4555 case ParsedAttr::AT_MSABI:
4559 case ParsedAttr::AT_SysVABI:
4563 case ParsedAttr::AT_Pcs: {
4565 if (!checkStringLiteralArgumentAttr(Attrs, 0, StrRef)) {
4569 if (StrRef ==
"aapcs") {
4572 }
else if (StrRef ==
"aapcs-vfp") {
4581 case ParsedAttr::AT_IntelOclBicc:
4584 case ParsedAttr::AT_PreserveMost:
4587 case ParsedAttr::AT_PreserveAll:
4590 default: llvm_unreachable(
"unexpected attribute kind");
4599 if (LangOpts.CUDA) {
4601 auto CudaTarget = IdentifyCUDATarget(FD);
4602 bool CheckHost =
false, CheckDevice =
false;
4603 switch (CudaTarget) {
4604 case CFT_HostDevice:
4615 case CFT_InvalidTarget:
4616 llvm_unreachable(
"unexpected cuda target");
4618 auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI;
4619 auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux;
4620 if (CheckHost && HostTI)
4623 A = DeviceTI->checkCallingConvention(CC);
4641 Diag(Attrs.
getLoc(), diag::error_cconv_unsupported)
4642 << Attrs << (
int)CallingConventionIgnoredReason::ForThisTarget;
4646 Diag(Attrs.
getLoc(), diag::warn_cconv_unsupported)
4647 << Attrs << (
int)CallingConventionIgnoredReason::ForThisTarget;
4651 bool IsCXXMethod =
false, IsVariadic =
false;
4666 static bool isValidSwiftContextType(
QualType Ty) {
4673 static bool isValidSwiftIndirectResultType(
QualType Ty) {
4685 static bool isValidSwiftErrorResultType(
QualType Ty) {
4695 return isValidSwiftContextType(Ty);
4704 if (existingAttr->getABI() != abi) {
4705 Diag(CI.
getLoc(), diag::err_attributes_are_not_compatible)
4707 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute);
4714 llvm_unreachable(
"explicit attribute for ordinary parameter ABI?");
4717 if (!isValidSwiftContextType(type)) {
4718 Diag(CI.
getLoc(), diag::err_swift_abi_parameter_wrong_type)
4721 D->
addAttr(::
new (Context) SwiftContextAttr(Context, CI));
4725 if (!isValidSwiftErrorResultType(type)) {
4726 Diag(CI.
getLoc(), diag::err_swift_abi_parameter_wrong_type)
4729 D->
addAttr(::
new (Context) SwiftErrorResultAttr(Context, CI));
4733 if (!isValidSwiftIndirectResultType(type)) {
4734 Diag(CI.
getLoc(), diag::err_swift_abi_parameter_wrong_type)
4737 D->
addAttr(::
new (Context) SwiftIndirectResultAttr(Context, CI));
4740 llvm_unreachable(
"bad parameter ABI attribute");
4762 Diag(AL.
getLoc(), diag::err_attribute_regparm_wrong_platform)
4770 Diag(AL.
getLoc(), diag::err_attribute_regparm_invalid_number)
4784 const CUDALaunchBoundsAttr &AL,
4785 const unsigned Idx) {
4801 if (!I.isIntN(32)) {
4802 S.
Diag(E->
getExprLoc(), diag::err_ice_too_large) << I.toString(10,
false)
4807 S.
Diag(E->
getExprLoc(), diag::warn_attribute_argument_n_negative)
4814 assert(!ValArg.isInvalid() &&
4815 "Unexpected PerformCopyInitialization() failure.");
4821 Expr *MaxThreads,
Expr *MinBlocks) {
4822 CUDALaunchBoundsAttr TmpAttr(Context, CI, MaxThreads, MinBlocks);
4823 MaxThreads = makeLaunchBoundsArgExpr(*
this, MaxThreads, TmpAttr, 0);
4824 if (MaxThreads ==
nullptr)
4828 MinBlocks = makeLaunchBoundsArgExpr(*
this, MinBlocks, TmpAttr, 1);
4829 if (MinBlocks ==
nullptr)
4834 CUDALaunchBoundsAttr(Context, CI, MaxThreads, MinBlocks));
4846 static void handleArgumentWithTypeTagAttr(
Sema &S,
Decl *D,
4849 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4867 unsigned ArgumentIdxAST = ArgumentIdx.
getASTIndex();
4870 S.
Diag(AL.
getLoc(), diag::err_attribute_pointers_only) << AL << 0;
4878 static void handleTypeTagForDatatypeAttr(
Sema &S,
Decl *D,
4881 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4889 if (!isa<VarDecl>(D)) {
4890 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_decl_type)
4898 assert(MatchingCTypeLoc &&
"no type source info for attribute argument");
4918 static void handlePatchableFunctionEntryAttr(
Sema &S,
Decl *D,
4920 uint32_t Count = 0,
Offset = 0;
4928 S.
Diag(
getAttrLoc(AL), diag::err_attribute_argument_out_of_range)
4937 static bool ArmMveAliasValid(
unsigned BuiltinID, StringRef AliasName) {
4938 if (AliasName.startswith(
"__arm_"))
4939 AliasName = AliasName.substr(6);
4940 switch (BuiltinID) {
4941 #include "clang/Basic/arm_mve_builtin_aliases.inc" 4949 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4957 if (!ArmMveAliasValid(BuiltinID,
4959 S.
Diag(AL.
getLoc(), diag::err_attribute_arm_mve_alias);
4969 static bool isValidSubjectOfNSReturnsRetainedAttribute(
QualType QT) {
4973 static bool isValidSubjectOfNSAttribute(
QualType QT) {
4978 static bool isValidSubjectOfCFAttribute(
QualType QT) {
4980 isValidSubjectOfNSAttribute(QT);
4983 static bool isValidSubjectOfOSAttribute(
QualType QT) {
4991 RetainOwnershipKind K,
4992 bool IsTemplateInstantiation) {
4995 case RetainOwnershipKind::OS:
4996 handleSimpleAttributeOrDiagnose<OSConsumedAttr>(
4997 *
this, VD, CI, isValidSubjectOfOSAttribute(VD->getType()),
4998 diag::warn_ns_attribute_wrong_parameter_type,
5001 case RetainOwnershipKind::NS:
5002 handleSimpleAttributeOrDiagnose<NSConsumedAttr>(
5003 *
this, VD, CI, isValidSubjectOfNSAttribute(VD->getType()),
5009 ((IsTemplateInstantiation && getLangOpts().ObjCAutoRefCount)
5010 ? diag::err_ns_attribute_wrong_parameter_type
5011 : diag::warn_ns_attribute_wrong_parameter_type),
5012 CI.getRange(),
"ns_consumed", 0);
5014 case RetainOwnershipKind::CF:
5015 handleSimpleAttributeOrDiagnose<CFConsumedAttr>(
5016 *
this, VD, CI, isValidSubjectOfCFAttribute(VD->getType()),
5017 diag::warn_ns_attribute_wrong_parameter_type,
5018 CI.getRange(),
"cf_consumed", 1);
5024 parsedAttrToRetainOwnershipKind(
const ParsedAttr &AL) {
5026 case ParsedAttr::AT_CFConsumed:
5027 case ParsedAttr::AT_CFReturnsRetained:
5028 case ParsedAttr::AT_CFReturnsNotRetained:
5030 case ParsedAttr::AT_OSConsumesThis:
5031 case ParsedAttr::AT_OSConsumed:
5032 case ParsedAttr::AT_OSReturnsRetained:
5033 case ParsedAttr::AT_OSReturnsNotRetained:
5034 case ParsedAttr::AT_OSReturnsRetainedOnZero:
5035 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
5037 case ParsedAttr::AT_NSConsumesSelf:
5038 case ParsedAttr::AT_NSConsumed:
5039 case ParsedAttr::AT_NSReturnsRetained:
5040 case ParsedAttr::AT_NSReturnsNotRetained:
5041 case ParsedAttr::AT_NSReturnsAutoreleased:
5044 llvm_unreachable(
"Wrong argument supplied");
5049 if (isValidSubjectOfNSReturnsRetainedAttribute(QT))
5052 Diag(Loc, diag::warn_ns_attribute_wrong_return_type)
5053 <<
"'ns_returns_retained'" << 0 << 0;
5058 static bool isValidOSObjectOutParameter(
const Decl *D) {
5064 return !PT.
isNull() && isValidSubjectOfOSAttribute(PT);
5067 static void handleXReturnsXRetainedAttr(
Sema &S,
Decl *D,
5072 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
5075 (AL.
getKind() == ParsedAttr::AT_NSReturnsRetained)) {
5077 }
else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
5078 ReturnType = PD->getType();
5079 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5081 }
else if (
const auto *Param = dyn_cast<ParmVarDecl>(D)) {
5088 if (ReturnType.
isNull()) {
5089 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
5098 default: llvm_unreachable(
"invalid ownership attribute");
5099 case ParsedAttr::AT_NSReturnsRetained:
5100 case ParsedAttr::AT_NSReturnsAutoreleased:
5101 case ParsedAttr::AT_NSReturnsNotRetained:
5105 case ParsedAttr::AT_OSReturnsRetained:
5106 case ParsedAttr::AT_OSReturnsNotRetained:
5107 case ParsedAttr::AT_CFReturnsRetained:
5108 case ParsedAttr::AT_CFReturnsNotRetained:
5113 << AL.
getRange() << AL << ExpectedDeclKind;
5119 unsigned ParmDiagID = 2;
5121 default: llvm_unreachable(
"invalid ownership attribute");
5122 case ParsedAttr::AT_NSReturnsRetained:
5123 TypeOK = isValidSubjectOfNSReturnsRetainedAttribute(ReturnType);
5127 case ParsedAttr::AT_NSReturnsAutoreleased:
5128 case ParsedAttr::AT_NSReturnsNotRetained:
5129 TypeOK = isValidSubjectOfNSAttribute(ReturnType);
5133 case ParsedAttr::AT_CFReturnsRetained:
5134 case ParsedAttr::AT_CFReturnsNotRetained:
5135 TypeOK = isValidSubjectOfCFAttribute(ReturnType);
5139 case ParsedAttr::AT_OSReturnsRetained:
5140 case ParsedAttr::AT_OSReturnsNotRetained:
5141 TypeOK = isValidSubjectOfOSAttribute(ReturnType);
5151 if (isa<ParmVarDecl>(D)) {
5152 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
5153 << AL << ParmDiagID << AL.
getRange();
5160 } SubjectKind = Function;
5161 if (isa<ObjCMethodDecl>(D))
5162 SubjectKind = Method;
5163 else if (isa<ObjCPropertyDecl>(D))
5166 << AL << SubjectKind << Cf << AL.
getRange();
5173 llvm_unreachable(
"invalid ownership attribute");
5174 case ParsedAttr::AT_NSReturnsAutoreleased:
5175 handleSimpleAttribute<NSReturnsAutoreleasedAttr>(S, D, AL);
5177 case ParsedAttr::AT_CFReturnsNotRetained:
5178 handleSimpleAttribute<CFReturnsNotRetainedAttr>(S, D, AL);
5180 case ParsedAttr::AT_NSReturnsNotRetained:
5181 handleSimpleAttribute<NSReturnsNotRetainedAttr>(S, D, AL);
5183 case ParsedAttr::AT_CFReturnsRetained:
5184 handleSimpleAttribute<CFReturnsRetainedAttr>(S, D, AL);
5186 case ParsedAttr::AT_NSReturnsRetained:
5187 handleSimpleAttribute<NSReturnsRetainedAttr>(S, D, AL);
5189 case ParsedAttr::AT_OSReturnsRetained:
5190 handleSimpleAttribute<OSReturnsRetainedAttr>(S, D, AL);
5192 case ParsedAttr::AT_OSReturnsNotRetained:
5193 handleSimpleAttribute<OSReturnsNotRetainedAttr>(S, D, AL);
5198 static void handleObjCReturnsInnerPointerAttr(
Sema &S,
Decl *D,
5200 const int EP_ObjCMethod = 1;
5201 const int EP_ObjCProperty = 2;
5205 if (isa<ObjCMethodDecl>(D))
5206 resultType = cast<ObjCMethodDecl>(D)->getReturnType();
5208 resultType = cast<ObjCPropertyDecl>(D)->getType();
5214 << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
5224 static void handleObjCRequiresSuperAttr(
Sema &S,
Decl *D,
5226 const auto *Method = cast<ObjCMethodDecl>(D);
5229 if (
const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
5230 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5232 S.
Diag(PDecl->getLocation(), diag::note_protocol_decl);
5236 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5253 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
5255 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_id) << AL;
5260 QualType T = TD->getUnderlyingType();
5262 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_void_pointer);
5270 static void handleObjCBridgeMutableAttr(
Sema &S,
Decl *D,
5283 static void handleObjCBridgeRelatedAttr(
Sema &S,
Decl *D,
5287 if (!RelatedClass) {
5296 S.
Context, AL, RelatedClass, ClassMethod, InstanceMethod));
5299 static void handleObjCDesignatedInitializer(
Sema &S,
Decl *D,
5305 if (!isa<ObjCInterfaceDecl>(Ctx) &&
5306 !(isa<ObjCCategoryDecl>(Ctx) &&
5307 cast<ObjCCategoryDecl>(Ctx)->IsClassExtension())) {
5313 if (
auto *CatDecl = dyn_cast<ObjCCategoryDecl>(Ctx))
5314 IFace = CatDecl->getClassInterface();
5316 IFace = cast<ObjCInterfaceDecl>(Ctx);
5326 StringRef MetaDataName;
5330 ObjCRuntimeNameAttr(S.
Context, AL, MetaDataName));
5338 bool notify =
false;
5347 ObjCBoxableAttr *BoxableAttr =
5354 L->AddedAttributeToRecord(BoxableAttr, RD);
5366 static void handleObjCPreciseLifetimeAttr(
Sema &S,
Decl *D,
5368 const auto *VD = cast<ValueDecl>(D);
5371 if (!QT->isDependentType() &&
5372 !QT->isObjCLifetimeType()) {
5373 S.
Diag(AL.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
5383 Lifetime = QT->getObjCARCImplicitLifetime();
5387 assert(QT->isDependentType() &&
5388 "didn't infer lifetime for non-dependent type?");
5397 S.
Diag(AL.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
5411 if (
const auto *UA = D->
getAttr<UuidAttr>()) {
5412 if (UA->getGuid().equals_lower(Uuid))
5414 if (!UA->getGuid().empty()) {
5415 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5421 return ::new (Context) UuidAttr(Context, CI, Uuid);
5426 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5438 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
5439 StrRef = StrRef.drop_front().drop_back();
5442 if (StrRef.size() != 36) {
5443 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5447 for (
unsigned i = 0; i < 36; ++i) {
5448 if (i == 8 || i == 13 || i == 18 || i == 23) {
5449 if (StrRef[i] !=
'-') {
5450 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5454 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5466 S.
Diag(AL.
getLoc(), diag::warn_atl_uuid_deprecated);
5475 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5488 const auto *VD = cast<VarDecl>(D);
5490 S.
Diag(AL.
getLoc(), diag::err_thread_unsupported);
5494 S.
Diag(AL.
getLoc(), diag::err_declspec_thread_on_thread_variable);
5497 if (VD->hasLocalStorage()) {
5498 S.
Diag(AL.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
5506 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
5510 Tags.push_back(Tag);
5513 if (
const auto *NS = dyn_cast<NamespaceDecl>(D)) {
5514 if (!NS->isInline()) {
5515 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5518 if (NS->isAnonymousNamespace()) {
5519 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5523 Tags.push_back(NS->getName());
5529 Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
5532 AbiTagAttr(S.
Context, AL, Tags.data(), Tags.size()));
5538 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5550 ARMInterruptAttr::InterruptType
Kind;
5551 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5552 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5586 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5594 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5600 unsigned Num = NumParams.getLimitedValue(255);
5602 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5603 << AL << (
int)NumParams.getSExtValue()
5615 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5654 if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL))
5657 MipsInterruptAttr::InterruptType
Kind;
5658 if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5659 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
5660 << AL <<
"'" + std::string(Str) +
"'";
5676 cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
5677 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5684 diag::err_anyx86_interrupt_attribute)
5693 if (NumParams < 1 || NumParams > 2) {
5704 diag::err_anyx86_interrupt_attribute)
5716 if (NumParams == 2 &&
5720 diag::err_anyx86_interrupt_attribute)
5741 handleSimpleAttribute<AVRInterruptAttr>(S, D, AL);
5754 handleSimpleAttribute<AVRSignalAttr>(S, D, AL);
5759 for (
auto D : RD->
decls()) {
5760 if (D->
hasAttr<BPFPreserveAccessIndexAttr>())
5763 D->
addAttr(BPFPreserveAccessIndexAttr::CreateImplicit(S.
Context));
5764 if (
auto *Rec = dyn_cast<RecordDecl>(D))
5765 handleBPFPreserveAIRecord(S, Rec);
5769 static void handleBPFPreserveAccessIndexAttr(
Sema &S,
Decl *D,
5771 auto *Rec = cast<RecordDecl>(D);
5772 handleBPFPreserveAIRecord(S, Rec);
5773 Rec->addAttr(::
new (S.
Context) BPFPreserveAccessIndexAttr(S.
Context, AL));
5776 static void handleWebAssemblyExportNameAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5783 auto *FD = cast<FunctionDecl>(D);
5798 static void handleWebAssemblyImportModuleAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5805 auto *FD = cast<FunctionDecl>(D);
5817 WebAssemblyImportModuleAttr(S.
Context, AL, Str));
5820 static void handleWebAssemblyImportNameAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5827 auto *FD = cast<FunctionDecl>(D);
5841 static void handleRISCVInterruptAttr(
Sema &S,
Decl *D,
5844 if (
const auto *A = D->
getAttr<RISCVInterruptAttr>()) {
5846 diag::warn_riscv_repeated_interrupt_attribute);
5847 S.
Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute);
5889 RISCVInterruptAttr::InterruptType
Kind;
5890 if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5891 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5902 case llvm::Triple::msp430:
5903 handleMSP430InterruptAttr(S, D, AL);
5905 case llvm::Triple::mipsel:
5906 case llvm::Triple::mips:
5907 handleMipsInterruptAttr(S, D, AL);
5909 case llvm::Triple::x86:
5910 case llvm::Triple::x86_64:
5911 handleAnyX86InterruptAttr(S, D, AL);
5913 case llvm::Triple::avr:
5914 handleAVRInterruptAttr(S, D, AL);
5916 case llvm::Triple::riscv32:
5917 case llvm::Triple::riscv64:
5918 handleRISCVInterruptAttr(S, D, AL);
5921 handleARMInterruptAttr(S, D, AL);
5927 checkAMDGPUFlatWorkGroupSizeArguments(
Sema &S,
Expr *MinExpr,
Expr *MaxExpr,
5928 const AMDGPUFlatWorkGroupSizeAttr &
Attr) {
5942 if (Min == 0 && Max != 0) {
5943 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5948 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5959 AMDGPUFlatWorkGroupSizeAttr TmpAttr(Context, CI, MinExpr, MaxExpr);
5961 if (checkAMDGPUFlatWorkGroupSizeArguments(*
this, MinExpr, MaxExpr, TmpAttr))
5965 AMDGPUFlatWorkGroupSizeAttr(Context, CI, MinExpr, MaxExpr));
5968 static void handleAMDGPUFlatWorkGroupSizeAttr(
Sema &S,
Decl *D,
5976 static bool checkAMDGPUWavesPerEUArguments(
Sema &S,
Expr *MinExpr,
5978 const AMDGPUWavesPerEUAttr &
Attr) {
5996 if (Min == 0 && Max != 0) {
5997 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
6001 if (Max != 0 && Min > Max) {
6002 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
6012 AMDGPUWavesPerEUAttr TmpAttr(Context, CI, MinExpr, MaxExpr);
6014 if (checkAMDGPUWavesPerEUArguments(*
this, MinExpr, MaxExpr, TmpAttr))
6018 AMDGPUWavesPerEUAttr(Context, CI, MinExpr, MaxExpr));
6033 uint32_t NumSGPR = 0;
6042 uint32_t NumVGPR = 0;
6050 static void handleX86ForceAlignArgPointerAttr(
Sema &S,
Decl *D,
6055 const auto *VD = dyn_cast<
ValueDecl>(D);
6056 if (VD && VD->getType()->isFunctionPointerType())
6060 if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
6061 TD->getUnderlyingType()->isFunctionType()))
6064 if (!isa<FunctionDecl>(D)) {
6065 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
6081 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
6096 if (D->
hasAttr<DLLExportAttr>()) {
6097 Diag(CI.
getLoc(), diag::warn_attribute_ignored) <<
"'dllimport'";
6101 if (D->
hasAttr<DLLImportAttr>())
6104 return ::new (Context) DLLImportAttr(Context, CI);
6109 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
6110 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
6114 if (D->
hasAttr<DLLExportAttr>())
6117 return ::new (Context) DLLExportAttr(Context, CI);
6121 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
6127 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
6137 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
6145 Attr *NewAttr = A.
getKind() == ParsedAttr::AT_DLLExport
6156 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
6157 if (IA->getInheritanceModel() == Model)
6159 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
6161 Diag(CI.
getLoc(), diag::note_previous_ms_inheritance);
6165 auto *RD = cast<CXXRecordDecl>(D);
6166 if (RD->hasDefinition()) {
6167 if (checkMSInheritanceAttrOnDefinition(RD, CI.
getRange(), BestCase,
6172 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
6173 Diag(CI.
getLoc(), diag::warn_ignored_ms_inheritance)
6177 if (RD->getDescribedClassTemplate()) {
6178 Diag(CI.
getLoc(), diag::warn_ignored_ms_inheritance)
6184 return ::new (Context) MSInheritanceAttr(Context, CI, BestCase);
6196 StringRef N(
"mutex");
6198 if (AL.
getKind() == ParsedAttr::AT_Capability &&
6204 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
6205 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
6212 if (!checkLockFunAttrCommon(S, D, AL, Args))
6216 AssertCapabilityAttr(S.
Context, AL, Args.data(), Args.size()));
6219 static void handleAcquireCapabilityAttr(
Sema &S,
Decl *D,
6222 if (!checkLockFunAttrCommon(S, D, AL, Args))
6229 static void handleTryAcquireCapabilityAttr(
Sema &S,
Decl *D,
6232 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
6239 static void handleReleaseCapabilityAttr(
Sema &S,
Decl *D,
6243 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
6249 static void handleRequiresCapabilityAttr(
Sema &S,
Decl *D,
6256 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
6260 RequiresCapabilityAttr *RCA = ::new (S.
Context)
6261 RequiresCapabilityAttr(S.
Context, AL, Args.data(), Args.size());
6267 if (
const auto *NSD = dyn_cast<NamespaceDecl>(D)) {
6268 if (NSD->isAnonymousNamespace()) {
6269 S.
Diag(AL.
getLoc(), diag::warn_deprecated_anonymous_namespace);
6278 StringRef Str, Replacement;
6291 S.
Diag(AL.
getLoc(), diag::ext_cxx14_attr) << AL;
6297 if (
const auto *S = dyn_cast<VarDecl>(D))
6298 return S->hasGlobalStorage();
6306 std::vector<StringRef> Sanitizers;
6308 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
6309 StringRef SanitizerName;
6317 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
6318 else if (
isGlobalVar(D) && SanitizerName !=
"address")
6321 Sanitizers.push_back(SanitizerName);
6325 Sanitizers.size()));
6328 static void handleNoSanitizeSpecificAttr(
Sema &S,
Decl *D,
6331 normalizeName(AttrName);
6332 StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName)
6333 .Case(
"no_address_safety_analysis",
"address")
6334 .Case(
"no_sanitize_address",
"address")
6335 .Case(
"no_sanitize_thread",
"thread")
6336 .Case(
"no_sanitize_memory",
"memory");
6349 unsigned TranslatedSpellingIndex = 0;
6351 TranslatedSpellingIndex = 1;
6356 NoSanitizeAttr(S.
Context, Info, &SanitizerName, 1));
6365 if (S.
LangOpts.OpenCLVersion != 200)
6366 S.
Diag(AL.
getLoc(), diag::err_attribute_requires_opencl_version)
6367 << AL <<
"2.0" << 0;
6369 S.
Diag(AL.
getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL
6376 static bool handleCommonAttributeFeatures(
Sema &S,
Decl *D,
6421 if (D->
hasAttr<OpenCLAccessAttr>()) {
6422 if (D->
getAttr<OpenCLAccessAttr>()->getSemanticSpelling() ==
6424 S.
Diag(AL.
getLoc(), diag::warn_duplicate_declspec)
6427 S.
Diag(AL.
getLoc(), diag::err_opencl_multiple_access_qualifiers)
6439 if (
const auto *PDecl = dyn_cast<ParmVarDecl>(D)) {
6440 const Type *
DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
6445 S.
Diag(AL.
getLoc(), diag::err_opencl_invalid_read_write)
6446 << AL << PDecl->getType() << DeclTy->
isImageType();
6458 const auto *FD = cast<FunctionDecl>(D);
6460 assert(FT &&
"Function template is expected");
6464 if (TL->
size() < 2) {
6465 S.
Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_template_params);
6470 for (
unsigned I = 0; I < 2; ++I) {
6472 if (isa<NonTypeTemplateParmDecl>(TParam)) {
6473 S.
Diag(FT->getLocation(),
6474 diag::warn_sycl_kernel_invalid_template_param_type);
6481 S.
Diag(FT->getLocation(), diag::warn_sycl_kernel_num_of_function_params);
6488 S.
Diag(FT->getLocation(), diag::warn_sycl_kernel_return_type);
6492 handleSimpleAttribute<SYCLKernelAttr>(S, D, AL);
6496 if (!cast<VarDecl>(D)->hasGlobalStorage()) {
6498 << (A.
getKind() == ParsedAttr::AT_AlwaysDestroy);
6502 if (A.
getKind() == ParsedAttr::AT_AlwaysDestroy)
6503 handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A);
6505 handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A);
6509 assert(cast<VarDecl>(D)->getStorageDuration() ==
SD_Automatic &&
6510 "uninitialized is only valid on automatic duration variables");
6514 static bool tryMakeVariablePseudoStrong(
Sema &S,
VarDecl *VD,
6515 bool DiagnoseFailure) {
6518 if (DiagnoseFailure) {
6519 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6536 if (DiagnoseFailure) {
6537 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6551 static void handleObjCExternallyRetainedAttr(
Sema &S,
Decl *D,
6553 if (
auto *VD = dyn_cast<VarDecl>(D)) {
6554 assert(!isa<ParmVarDecl>(VD) &&
"should be diagnosed automatically");
6561 if (!tryMakeVariablePseudoStrong(S, VD,
true))
6564 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6582 tryMakeVariablePseudoStrong(S, PVD,
false);
6584 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6592 if (!isa<BlockDecl>(D)) {
6594 bool IsKernReturnT =
false;
6596 IsKernReturnT = (TT->getDecl()->getName() ==
"kern_return_t");
6601 diag::warn_mig_server_routine_does_not_return_kern_return_t);
6606 handleSimpleAttribute<MIGServerRoutineAttr>(S, D, AL);
6611 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
6614 S.
Diag(AL.
getLoc(), diag::warn_declspec_allocator_nonpointer)
6620 handleSimpleAttribute<MSAllocatorAttr>(S, D, AL);
6627 if (
const auto *PVD = dyn_cast<ParmVarDecl>(D)) {
6628 if (PVD->getType()->isIntegerType()) {
6629 S.
Diag(AL.
getLoc(), diag::err_attribute_output_parameter)
6640 template<
typename Attr>
6652 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
6657 CFGuardAttr::GuardArg Arg;
6659 if (!CFGuardAttr::ConvertStrToGuardArg(II->
getName(), Arg)) {
6660 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
6674 static void ProcessDeclAttribute(
Sema &S, Scope *scope,
Decl *D,
6676 bool IncludeCXX11Attributes) {
6692 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
6693 : (
unsigned)diag::warn_unknown_attribute_ignored)
6698 if (handleCommonAttributeFeatures(S, D, AL))
6705 assert(AL.
isTypeAttr() &&
"Non-type attribute not handled");
6708 S.
Diag(AL.
getLoc(), diag::err_stmt_attribute_invalid_on_decl)
6711 case ParsedAttr::AT_Interrupt:
6712 handleInterruptAttr(S, D, AL);
6714 case ParsedAttr::AT_X86ForceAlignArgPointer:
6715 handleX86ForceAlignArgPointerAttr(S, D, AL);
6717 case ParsedAttr::AT_DLLExport:
6718 case ParsedAttr::AT_DLLImport:
6719 handleDLLAttr(S, D, AL);
6721 case ParsedAttr::AT_Mips16:
6722 handleSimpleAttributeWithExclusions<Mips16Attr, MicroMipsAttr,
6723 MipsInterruptAttr>(S, D, AL);
6725 case ParsedAttr::AT_NoMips16:
6726 handleSimpleAttribute<NoMips16Attr>(S, D, AL);
6728 case ParsedAttr::AT_MicroMips:
6729 handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(S, D, AL);
6731 case ParsedAttr::AT_NoMicroMips:
6732 handleSimpleAttribute<NoMicroMipsAttr>(S, D, AL);
6734 case ParsedAttr::AT_MipsLongCall:
6735 handleSimpleAttributeWithExclusions<MipsLongCallAttr, MipsShortCallAttr>(
6738 case ParsedAttr::AT_MipsShortCall:
6739 handleSimpleAttributeWithExclusions<MipsShortCallAttr, MipsLongCallAttr>(
6742 case ParsedAttr::AT_AMDGPUFlatWorkGroupSize:
6743 handleAMDGPUFlatWorkGroupSizeAttr(S, D, AL);
6745 case ParsedAttr::AT_AMDGPUWavesPerEU:
6746 handleAMDGPUWavesPerEUAttr(S, D, AL);
6748 case ParsedAttr::AT_AMDGPUNumSGPR:
6749 handleAMDGPUNumSGPRAttr(S, D, AL);
6751 case ParsedAttr::AT_AMDGPUNumVGPR:
6752 handleAMDGPUNumVGPRAttr(S, D, AL);
6754 case ParsedAttr::AT_AVRSignal:
6755 handleAVRSignalAttr(S, D, AL);
6757 case ParsedAttr::AT_BPFPreserveAccessIndex:
6758 handleBPFPreserveAccessIndexAttr(S, D, AL);
6760 case ParsedAttr::AT_WebAssemblyExportName:
6761 handleWebAssemblyExportNameAttr(S, D, AL);
6763 case ParsedAttr::AT_WebAssemblyImportModule:
6764 handleWebAssemblyImportModuleAttr(S, D, AL);
6766 case ParsedAttr::AT_WebAssemblyImportName:
6767 handleWebAssemblyImportNameAttr(S, D, AL);
6769 case ParsedAttr::AT_IBAction:
6770 handleSimpleAttribute<IBActionAttr>(S, D, AL);
6772 case ParsedAttr::AT_IBOutlet:
6773 handleIBOutlet(S, D, AL);
6775 case ParsedAttr::AT_IBOutletCollection:
6776 handleIBOutletCollection(S, D, AL);
6778 case ParsedAttr::AT_IFunc:
6779 handleIFuncAttr(S, D, AL);
6781 case ParsedAttr::AT_Alias:
6782 handleAliasAttr(S, D, AL);
6784 case ParsedAttr::AT_Aligned:
6785 handleAlignedAttr(S, D, AL);
6787 case ParsedAttr::AT_AlignValue:
6788 handleAlignValueAttr(S, D, AL);
6790 case ParsedAttr::AT_AllocSize:
6791 handleAllocSizeAttr(S, D, AL);
6793 case ParsedAttr::AT_AlwaysInline:
6794 handleAlwaysInlineAttr(S, D, AL);
6796 case ParsedAttr::AT_Artificial:
6797 handleSimpleAttribute<ArtificialAttr>(S, D, AL);
6799 case ParsedAttr::AT_AnalyzerNoReturn:
6800 handleAnalyzerNoReturnAttr(S, D, AL);
6802 case ParsedAttr::AT_TLSModel:
6803 handleTLSModelAttr(S, D, AL);
6805 case ParsedAttr::AT_Annotate:
6806 handleAnnotateAttr(S, D, AL);
6808 case ParsedAttr::AT_Availability:
6809 handleAvailabilityAttr(S, D, AL);
6811 case ParsedAttr::AT_CarriesDependency:
6812 handleDependencyAttr(S, scope, D, AL);
6814 case ParsedAttr::AT_CPUDispatch:
6815 case ParsedAttr::AT_CPUSpecific:
6816 handleCPUSpecificAttr(S, D, AL);
6818 case ParsedAttr::AT_Common:
6819 handleCommonAttr(S, D, AL);
6821 case ParsedAttr::AT_CUDAConstant:
6822 handleConstantAttr(S, D, AL);
6824 case ParsedAttr::AT_PassObjectSize:
6825 handlePassObjectSizeAttr(S, D, AL);
6827 case ParsedAttr::AT_Constructor:
6828 handleConstructorAttr(S, D, AL);
6830 case ParsedAttr::AT_CXX11NoReturn:
6831 handleSimpleAttribute<CXX11NoReturnAttr>(S, D, AL);
6833 case ParsedAttr::AT_Deprecated:
6834 handleDeprecatedAttr(S, D, AL);
6836 case ParsedAttr::AT_Destructor:
6837 handleDestructorAttr(S, D, AL);
6839 case ParsedAttr::AT_EnableIf:
6840 handleEnableIfAttr(S, D, AL);
6842 case ParsedAttr::AT_DiagnoseIf:
6843 handleDiagnoseIfAttr(S, D, AL);
6845 case ParsedAttr::AT_NoBuiltin:
6846 handleNoBuiltinAttr(S, D, AL);
6848 case ParsedAttr::AT_ExtVectorType:
6849 handleExtVectorTypeAttr(S, D, AL);
6851 case ParsedAttr::AT_ExternalSourceSymbol:
6852 handleExternalSourceSymbolAttr(S, D, AL);
6854 case ParsedAttr::AT_MinSize:
6855 handleMinSizeAttr(S, D, AL);
6857 case ParsedAttr::AT_OptimizeNone:
6858 handleOptimizeNoneAttr(S, D, AL);
6860 case ParsedAttr::AT_FlagEnum:
6861 handleSimpleAttribute<FlagEnumAttr>(S, D, AL);
6863 case ParsedAttr::AT_EnumExtensibility:
6864 handleEnumExtensibilityAttr(S, D, AL);
6866 case ParsedAttr::AT_Flatten:
6867 handleSimpleAttribute<FlattenAttr>(S, D, AL);
6869 case ParsedAttr::AT_SYCLKernel:
6870 handleSYCLKernelAttr(S, D, AL);
6872 case ParsedAttr::AT_Format:
6873 handleFormatAttr(S, D, AL);
6875 case ParsedAttr::AT_FormatArg:
6876 handleFormatArgAttr(S, D, AL);
6878 case ParsedAttr::AT_Callback:
6879 handleCallbackAttr(S, D, AL);
6881 case ParsedAttr::AT_CUDAGlobal:
6882 handleGlobalAttr(S, D, AL);
6884 case ParsedAttr::AT_CUDADevice:
6885 handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(S, D,
6888 case ParsedAttr::AT_CUDAHost:
6889 handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(S, D, AL);
6891 case ParsedAttr::AT_HIPPinnedShadow:
6892 handleSimpleAttributeWithExclusions<HIPPinnedShadowAttr, CUDADeviceAttr,
6893 CUDAConstantAttr>(S, D, AL);
6895 case ParsedAttr::AT_GNUInline:
6896 handleGNUInlineAttr(S, D, AL);
6898 case ParsedAttr::AT_CUDALaunchBounds:
6899 handleLaunchBoundsAttr(S, D, AL);
6901 case ParsedAttr::AT_Restrict:
6902 handleRestrictAttr(S, D, AL);
6904 case ParsedAttr::AT_LifetimeBound:
6905 handleSimpleAttribute<LifetimeBoundAttr>(S, D, AL);
6907 case ParsedAttr::AT_MayAlias:
6908 handleSimpleAttribute<MayAliasAttr>(S, D, AL);
6910 case ParsedAttr::AT_Mode:
6911 handleModeAttr(S, D, AL);
6913 case ParsedAttr::AT_NoAlias:
6914 handleSimpleAttribute<NoAliasAttr>(S, D, AL);
6916 case ParsedAttr::AT_NoCommon:
6917 handleSimpleAttribute<NoCommonAttr>(S, D, AL);
6919 case ParsedAttr::AT_NoSplitStack:
6920 handleSimpleAttribute<NoSplitStackAttr>(S, D, AL);
6922 case ParsedAttr::AT_NoUniqueAddress:
6923 handleSimpleAttribute<NoUniqueAddressAttr>(S, D, AL);
6925 case ParsedAttr::AT_NonNull:
6926 if (
auto *PVD = dyn_cast<ParmVarDecl>(D))
6927 handleNonNullAttrParameter(S, PVD, AL);
6929 handleNonNullAttr(S, D, AL);
6931 case ParsedAttr::AT_ReturnsNonNull:
6932 handleReturnsNonNullAttr(S, D, AL);
6934 case ParsedAttr::AT_NoEscape:
6935 handleNoEscapeAttr(S, D, AL);
6937 case ParsedAttr::AT_AssumeAligned:
6938 handleAssumeAlignedAttr(S, D, AL);
6940 case ParsedAttr::AT_AllocAlign:
6941 handleAllocAlignAttr(S, D, AL);
6943 case ParsedAttr::AT_Overloadable:
6944 handleSimpleAttribute<OverloadableAttr>(S, D, AL);
6946 case ParsedAttr::AT_Ownership:
6947 handleOwnershipAttr(S, D, AL);
6949 case ParsedAttr::AT_Cold:
6950 handleSimpleAttributeWithExclusions<ColdAttr, HotAttr>(S, D, AL);
6952 case ParsedAttr::AT_Hot:
6953 handleSimpleAttributeWithExclusions<HotAttr, ColdAttr>(S, D, AL);
6955 case ParsedAttr::AT_Naked:
6956 handleNakedAttr(S, D, AL);
6958 case ParsedAttr::AT_NoReturn:
6959 handleNoReturnAttr(S, D, AL);
6961 case ParsedAttr::AT_AnyX86NoCfCheck:
6962 handleNoCfCheckAttr(S, D, AL);
6964 case ParsedAttr::AT_NoThrow:
6966 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6968 case ParsedAttr::AT_CUDAShared:
6969 handleSharedAttr(S, D, AL);
6971 case ParsedAttr::AT_VecReturn:
6972 handleVecReturnAttr(S, D, AL);
6974 case ParsedAttr::AT_ObjCOwnership:
6975 handleObjCOwnershipAttr(S, D, AL);
6977 case ParsedAttr::AT_ObjCPreciseLifetime:
6978 handleObjCPreciseLifetimeAttr(S, D, AL);
6980 case ParsedAttr::AT_ObjCReturnsInnerPointer:
6981 handleObjCReturnsInnerPointerAttr(S, D, AL);
6983 case ParsedAttr::AT_ObjCRequiresSuper:
6984 handleObjCRequiresSuperAttr(S, D, AL);
6986 case ParsedAttr::AT_ObjCBridge:
6987 handleObjCBridgeAttr(S, D, AL);
6989 case ParsedAttr::AT_ObjCBridgeMutable:
6990 handleObjCBridgeMutableAttr(S, D, AL);
6992 case ParsedAttr::AT_ObjCBridgeRelated:
6993 handleObjCBridgeRelatedAttr(S, D, AL);
6995 case ParsedAttr::AT_ObjCDesignatedInitializer:
6996 handleObjCDesignatedInitializer(S, D, AL);
6998 case ParsedAttr::AT_ObjCRuntimeName:
6999 handleObjCRuntimeName(S, D, AL);
7001 case ParsedAttr::AT_ObjCRuntimeVisible:
7002 handleSimpleAttribute<ObjCRuntimeVisibleAttr>(S, D, AL);
7004 case ParsedAttr::AT_ObjCBoxable:
7005 handleObjCBoxable(S, D, AL);
7007 case ParsedAttr::AT_CFAuditedTransfer:
7008 handleSimpleAttributeWithExclusions<CFAuditedTransferAttr,
7009 CFUnknownTransferAttr>(S, D, AL);
7011 case ParsedAttr::AT_CFUnknownTransfer:
7012 handleSimpleAttributeWithExclusions<CFUnknownTransferAttr,
7013 CFAuditedTransferAttr>(S, D, AL);
7015 case ParsedAttr::AT_CFConsumed:
7016 case ParsedAttr::AT_NSConsumed:
7017 case ParsedAttr::AT_OSConsumed:
7018 S.AddXConsumedAttr(D, AL, parsedAttrToRetainOwnershipKind(AL),
7021 case ParsedAttr::AT_NSConsumesSelf:
7022 handleSimpleAttribute<NSConsumesSelfAttr>(S, D, AL);
7024 case ParsedAttr::AT_OSConsumesThis:
7025 handleSimpleAttribute<OSConsumesThisAttr>(S, D, AL);
7027 case ParsedAttr::AT_OSReturnsRetainedOnZero:
7028 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnZeroAttr>(
7029 S, D, AL, isValidOSObjectOutParameter(D),
7030 diag::warn_ns_attribute_wrong_parameter_type,
7033 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
7034 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnNonZeroAttr>(
7035 S, D, AL, isValidOSObjectOutParameter(D),
7036 diag::warn_ns_attribute_wrong_parameter_type,
7037 AL, 3, AL.getRange());
7039 case ParsedAttr::AT_NSReturnsAutoreleased:
7040 case ParsedAttr::AT_NSReturnsNotRetained:
7041 case ParsedAttr::AT_NSReturnsRetained:
7042 case ParsedAttr::AT_CFReturnsNotRetained:
7043 case ParsedAttr::AT_CFReturnsRetained:
7044 case ParsedAttr::AT_OSReturnsNotRetained:
7045 case ParsedAttr::AT_OSReturnsRetained:
7046 handleXReturnsXRetainedAttr(S, D, AL);
7048 case ParsedAttr::AT_WorkGroupSizeHint:
7049 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
7051 case ParsedAttr::AT_ReqdWorkGroupSize:
7052 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
7054 case ParsedAttr::AT_OpenCLIntelReqdSubGroupSize:
7055 handleSubGroupSize(S, D, AL);
7057 case ParsedAttr::AT_VecTypeHint:
7058 handleVecTypeHint(S, D, AL);
7060 case ParsedAttr::AT_ConstInit:
7061 handleSimpleAttribute<ConstInitAttr>(S, D, AL);
7063 case ParsedAttr::AT_InitPriority:
7064 handleInitPriorityAttr(S, D, AL);
7066 case ParsedAttr::AT_Packed:
7067 handlePackedAttr(S, D, AL);
7069 case ParsedAttr::AT_Section:
7070 handleSectionAttr(S, D, AL);
7072 case ParsedAttr::AT_SpeculativeLoadHardening:
7073 handleSimpleAttributeWithExclusions<SpeculativeLoadHardeningAttr,
7074 NoSpeculativeLoadHardeningAttr>(S, D,
7077 case ParsedAttr::AT_NoSpeculativeLoadHardening:
7078 handleSimpleAttributeWithExclusions<NoSpeculativeLoadHardeningAttr,
7079 SpeculativeLoadHardeningAttr>(S, D, AL);
7081 case ParsedAttr::AT_CodeSeg:
7082 handleCodeSegAttr(S, D, AL);
7084 case ParsedAttr::AT_Target:
7085 handleTargetAttr(S, D, AL);
7087 case ParsedAttr::AT_MinVectorWidth:
7088 handleMinVectorWidthAttr(S, D, AL);
7090 case ParsedAttr::AT_Unavailable:
7091 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
7093 case ParsedAttr::AT_ArcWeakrefUnavailable:
7094 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, AL);
7096 case ParsedAttr::AT_ObjCRootClass:
7097 handleSimpleAttribute<ObjCRootClassAttr>(S, D, AL);
7099 case ParsedAttr::AT_ObjCDirect:
7100 handleObjCDirectAttr(S, D, AL);
7102 case ParsedAttr::AT_ObjCDirectMembers:
7103 handleObjCDirectMembersAttr(S, D, AL);
7104 handleSimpleAttribute<ObjCDirectMembersAttr>(S, D, AL);
7106 case ParsedAttr::AT_ObjCNonLazyClass:
7107 handleSimpleAttribute<ObjCNonLazyClassAttr>(S, D, AL);
7109 case ParsedAttr::AT_ObjCSubclassingRestricted:
7110 handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(S, D, AL);
7112 case ParsedAttr::AT_ObjCClassStub:
7113 handleSimpleAttribute<ObjCClassStubAttr>(S, D, AL);
7115 case ParsedAttr::AT_ObjCExplicitProtocolImpl:
7116 handleObjCSuppresProtocolAttr(S, D, AL);
7118 case ParsedAttr::AT_ObjCRequiresPropertyDefs:
7119 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, AL);
7121 case ParsedAttr::AT_Unused:
7122 handleUnusedAttr(S, D, AL);
7124 case ParsedAttr::AT_ReturnsTwice:
7125 handleSimpleAttribute<ReturnsTwiceAttr>(S, D, AL);
7127 case ParsedAttr::AT_NotTailCalled:
7128 handleSimpleAttributeWithExclusions<NotTailCalledAttr, AlwaysInlineAttr>(
7131 case ParsedAttr::AT_DisableTailCalls:
7132 handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D,
7135 case ParsedAttr::AT_Used:
7136 handleSimpleAttribute<UsedAttr>(S, D, AL);
7138 case ParsedAttr::AT_Visibility:
7139 handleVisibilityAttr(S, D, AL,
false);
7141 case ParsedAttr::AT_TypeVisibility:
7142 handleVisibilityAttr(S, D, AL,
true);
7144 case ParsedAttr::AT_WarnUnused:
7145 handleSimpleAttribute<WarnUnusedAttr>(S, D, AL);
7147 case ParsedAttr::AT_WarnUnusedResult:
7148 handleWarnUnusedResult(S, D, AL);
7150 case ParsedAttr::AT_Weak:
7151 handleSimpleAttribute<WeakAttr>(S, D, AL);
7153 case ParsedAttr::AT_WeakRef:
7154 handleWeakRefAttr(S, D, AL);
7156 case ParsedAttr::AT_WeakImport:
7157 handleWeakImportAttr(S, D, AL);
7159 case ParsedAttr::AT_TransparentUnion:
7160 handleTransparentUnionAttr(S, D, AL);
7162 case ParsedAttr::AT_ObjCException:
7163 handleSimpleAttribute<ObjCExceptionAttr>(S, D, AL);
7165 case ParsedAttr::AT_ObjCMethodFamily:
7166 handleObjCMethodFamilyAttr(S, D, AL);
7168 case ParsedAttr::AT_ObjCNSObject:
7169 handleObjCNSObject(S, D, AL);
7171 case ParsedAttr::AT_ObjCIndependentClass:
7172 handleObjCIndependentClass(S, D, AL);
7174 case ParsedAttr::AT_Blocks:
7175 handleBlocksAttr(S, D, AL);
7177 case ParsedAttr::AT_Sentinel:
7178 handleSentinelAttr(S, D, AL);
7180 case ParsedAttr::AT_Const:
7181 handleSimpleAttribute<ConstAttr>(S, D, AL);
7183 case ParsedAttr::AT_Pure:
7184 handleSimpleAttribute<PureAttr>(S, D, AL);
7186 case ParsedAttr::AT_Cleanup:
7187 handleCleanupAttr(S, D, AL);
7189 case ParsedAttr::AT_NoDebug:
7190 handleNoDebugAttr(S, D, AL);
7192 case ParsedAttr::AT_NoDuplicate:
7193 handleSimpleAttribute<NoDuplicateAttr>(S, D, AL);
7195 case ParsedAttr::AT_Convergent:
7196 handleSimpleAttribute<ConvergentAttr>(S, D, AL);
7198 case ParsedAttr::AT_NoInline:
7199 handleSimpleAttribute<NoInlineAttr>(S, D, AL);
7201 case ParsedAttr::AT_NoInstrumentFunction:
7202 handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, AL);
7204 case ParsedAttr::AT_NoStackProtector:
7206 handleSimpleAttribute<NoStackProtectorAttr>(S, D, AL);
7208 case ParsedAttr::AT_CFICanonicalJumpTable:
7209 handleSimpleAttribute<CFICanonicalJumpTableAttr>(S, D, AL);
7211 case ParsedAttr::AT_StdCall:
7212 case ParsedAttr::AT_CDecl:
7213 case ParsedAttr::AT_FastCall:
7214 case ParsedAttr::AT_ThisCall:
7215 case ParsedAttr::AT_Pascal:
7216 case ParsedAttr::AT_RegCall:
7217 case ParsedAttr::AT_SwiftCall:
7218 case ParsedAttr::AT_VectorCall:
7219 case ParsedAttr::AT_MSABI:
7220 case ParsedAttr::AT_SysVABI:
7221 case ParsedAttr::AT_Pcs:
7222 case ParsedAttr::AT_IntelOclBicc:
7223 case ParsedAttr::AT_PreserveMost:
7224 case ParsedAttr::AT_PreserveAll:
7225 case ParsedAttr::AT_AArch64VectorPcs:
7226 handleCallConvAttr(S, D, AL);
7228 case ParsedAttr::AT_Suppress:
7231 case ParsedAttr::AT_Owner:
7232 case ParsedAttr::AT_Pointer:
7233 handleLifetimeCategoryAttr(S, D, AL);
7235 case ParsedAttr::AT_OpenCLKernel:
7236 handleSimpleAttribute<OpenCLKernelAttr>(S, D, AL);
7238 case ParsedAttr::AT_OpenCLAccess:
7239 handleOpenCLAccessAttr(S, D, AL);
7241 case ParsedAttr::AT_OpenCLNoSVM:
7242 handleOpenCLNoSVMAttr(S, D, AL);
7244 case ParsedAttr::AT_SwiftContext:
7247 case ParsedAttr::AT_SwiftErrorResult:
7250 case ParsedAttr::AT_SwiftIndirectResult:
7253 case ParsedAttr::AT_InternalLinkage:
7254 handleInternalLinkageAttr(S, D, AL);
7256 case ParsedAttr::AT_ExcludeFromExplicitInstantiation:
7257 handleSimpleAttribute<ExcludeFromExplicitInstantiationAttr>(S, D, AL);
7259 case ParsedAttr::AT_LTOVisibilityPublic:
7260 handleSimpleAttribute<LTOVisibilityPublicAttr>(S, D, AL);
7264 case ParsedAttr::AT_EmptyBases:
7265 handleSimpleAttribute<EmptyBasesAttr>(S, D, AL);
7267 case ParsedAttr::AT_LayoutVersion:
7268 handleLayoutVersion(S, D, AL);
7270 case ParsedAttr::AT_TrivialABI:
7271 handleSimpleAttribute<TrivialABIAttr>(S, D, AL);
7273 case ParsedAttr::AT_MSNoVTable:
7274 handleSimpleAttribute<MSNoVTableAttr>(S, D, AL);
7276 case ParsedAttr::AT_MSStruct:
7277 handleSimpleAttribute<MSStructAttr>(S, D, AL);
7279 case ParsedAttr::AT_Uuid:
7280 handleUuidAttr(S, D, AL);
7282 case ParsedAttr::AT_MSInheritance:
7283 handleMSInheritanceAttr(S, D, AL);
7285 case ParsedAttr::AT_SelectAny:
7286 handleSimpleAttribute<SelectAnyAttr>(S, D, AL);
7288 case ParsedAttr::AT_Thread:
7289 handleDeclspecThreadAttr(S, D, AL);
7292 case ParsedAttr::AT_AbiTag:
7293 handleAbiTagAttr(S, D, AL);
7295 case ParsedAttr::AT_CFGuard:
7296 handleCFGuardAttr(S, D, AL);
7300 case ParsedAttr::AT_AssertExclusiveLock:
7301 handleAssertExclusiveLockAttr(S, D, AL);
7303 case ParsedAttr::AT_AssertSharedLock:
7304 handleAssertSharedLockAttr(S, D, AL);
7306 case ParsedAttr::AT_GuardedVar:
7307 handleSimpleAttribute<GuardedVarAttr>(S, D, AL);
7309 case ParsedAttr::AT_PtGuardedVar:
7310 handlePtGuardedVarAttr(S, D, AL);
7312 case ParsedAttr::AT_ScopedLockable:
7313 handleSimpleAttribute<ScopedLockableAttr>(S, D, AL);
7315 case ParsedAttr::AT_NoSanitize:
7316 handleNoSanitizeAttr(S, D, AL);
7318 case ParsedAttr::AT_NoSanitizeSpecific:
7319 handleNoSanitizeSpecificAttr(S, D, AL);
7321 case ParsedAttr::AT_NoThreadSafetyAnalysis:
7322 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, AL);
7324 case ParsedAttr::AT_GuardedBy:
7325 handleGuardedByAttr(S, D, AL);
7327 case ParsedAttr::AT_PtGuardedBy:
7328 handlePtGuardedByAttr(S, D, AL);
7330 case ParsedAttr::AT_ExclusiveTrylockFunction:
7331 handleExclusiveTrylockFunctionAttr(S, D, AL);
7333 case ParsedAttr::AT_LockReturned:
7334 handleLockReturnedAttr(S, D, AL);
7336 case ParsedAttr::AT_LocksExcluded:
7337 handleLocksExcludedAttr(S, D, AL);
7339 case ParsedAttr::AT_SharedTrylockFunction:
7340 handleSharedTrylockFunctionAttr(S, D, AL);
7342 case ParsedAttr::AT_AcquiredBefore:
7343 handleAcquiredBeforeAttr(S, D, AL);
7345 case ParsedAttr::AT_AcquiredAfter:
7346 handleAcquiredAfterAttr(S, D, AL);
7350 case ParsedAttr::AT_Capability:
7351 case ParsedAttr::AT_Lockable:
7352 handleCapabilityAttr(S, D, AL);
7354 case ParsedAttr::AT_RequiresCapability:
7355 handleRequiresCapabilityAttr(S, D, AL);
7358 case ParsedAttr::AT_AssertCapability:
7359 handleAssertCapabilityAttr(S, D, AL);
7361 case ParsedAttr::AT_AcquireCapability:
7362 handleAcquireCapabilityAttr(S, D, AL);
7364 case ParsedAttr::AT_ReleaseCapability:
7365 handleReleaseCapabilityAttr(S, D, AL);
7367 case ParsedAttr::AT_TryAcquireCapability:
7368 handleTryAcquireCapabilityAttr(S, D, AL);
7372 case ParsedAttr::AT_Consumable:
7373 handleConsumableAttr(S, D, AL);
7375 case ParsedAttr::AT_ConsumableAutoCast:
7376 handleSimpleAttribute<ConsumableAutoCastAttr>(S, D, AL);
7378 case ParsedAttr::AT_ConsumableSetOnRead:
7379 handleSimpleAttribute<ConsumableSetOnReadAttr>(S, D, AL);
7381 case ParsedAttr::AT_CallableWhen:
7382 handleCallableWhenAttr(S, D, AL);
7384 case ParsedAttr::AT_ParamTypestate:
7385 handleParamTypestateAttr(S, D, AL);
7387 case ParsedAttr::AT_ReturnTypestate:
7388 handleReturnTypestateAttr(S, D, AL);
7390 case ParsedAttr::AT_SetTypestate:
7391 handleSetTypestateAttr(S, D, AL);
7393 case ParsedAttr::AT_TestTypestate:
7394 handleTestTypestateAttr(S, D, AL);
7398 case ParsedAttr::AT_ArgumentWithTypeTag:
7399 handleArgumentWithTypeTagAttr(S, D, AL);
7401 case ParsedAttr::AT_TypeTagForDatatype:
7402 handleTypeTagForDatatypeAttr(S, D, AL);
7404 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters:
7405 handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL);
7407 case ParsedAttr::AT_RenderScriptKernel:
7408 handleSimpleAttribute<RenderScriptKernelAttr>(S, D, AL);
7411 case ParsedAttr::AT_XRayInstrument:
7412 handleSimpleAttribute<XRayInstrumentAttr>(S, D, AL);
7414 case ParsedAttr::AT_XRayLogArgs:
7415 handleXRayLogArgsAttr(S, D, AL);
7418 case ParsedAttr::AT_PatchableFunctionEntry:
7419 handlePatchableFunctionEntryAttr(S, D, AL);
7423 case ParsedAttr::AT_Reinitializes:
7424 handleSimpleAttribute<ReinitializesAttr>(S, D, AL);
7427 case ParsedAttr::AT_AlwaysDestroy:
7428 case ParsedAttr::AT_NoDestroy:
7429 handleDestroyAttr(S, D, AL);
7432 case ParsedAttr::AT_Uninitialized:
7433 handleUninitializedAttr(S, D, AL);
7436 case ParsedAttr::AT_ObjCExternallyRetained:
7437 handleObjCExternallyRetainedAttr(S, D, AL);
7440 case ParsedAttr::AT_MIGServerRoutine:
7441 handleMIGServerRoutineAttr(S, D, AL);
7444 case ParsedAttr::AT_MSAllocator:
7445 handleMSAllocatorAttr(S, D, AL);
7448 case ParsedAttr::AT_ArmMveAlias:
7449 handleArmMveAliasAttr(S, D, AL);
7452 case ParsedAttr::AT_AcquireHandle:
7453 handeAcquireHandleAttr(S, D, AL);
7456 case ParsedAttr::AT_ReleaseHandle:
7457 handleHandleAttr<ReleaseHandleAttr>(S, D, AL);
7460 case ParsedAttr::AT_UseHandle:
7461 handleHandleAttr<UseHandleAttr>(S, D, AL);
7470 bool IncludeCXX11Attributes) {
7471 if (AttrList.
empty())
7475 ProcessDeclAttribute(*
this, S, D, AL, IncludeCXX11Attributes);
7482 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias)
7483 << cast<NamedDecl>(D);
7492 if (!D->
hasAttr<OpenCLKernelAttr>()) {
7494 if (
const auto *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
7499 }
else if (
const auto *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
7502 }
else if (
const auto *A = D->
getAttr<VecTypeHintAttr>()) {
7505 }
else if (
const auto *A = D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
7508 }
else if (!D->
hasAttr<CUDAGlobalAttr>()) {
7509 if (
const auto *A = D->
getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
7513 }
else if (
const auto *A = D->
getAttr<AMDGPUWavesPerEUAttr>()) {
7517 }
else if (
const auto *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
7521 }
else if (
const auto *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
7534 if (D->
hasAttr<ObjCDesignatedInitializerAttr>() &&
7535 cast<ObjCMethodDecl>(D)->getMethodFamily() !=
OMF_init) {
7537 D->
dropAttr<ObjCDesignatedInitializerAttr>();
7546 if (AL.
getKind() == ParsedAttr::AT_TransparentUnion) {
7547 handleTransparentUnionAttr(*
this, D, AL);
7553 if (D && D->
hasAttr<BPFPreserveAccessIndexAttr>())
7554 handleBPFPreserveAIRecord(*
this, cast<RecordDecl>(D));
7562 if (AL.
getKind() == ParsedAttr::AT_Annotate) {
7565 Diag(AL.
getLoc(), diag::err_only_annotate_after_access_spec);
7583 S.
Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored)
7586 S.
Diag(AL.
getLoc(), diag::warn_attribute_not_on_decl) << AL
7606 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
7608 if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
7629 for (
const auto &AI : FT->param_types()) {
7630 ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
7632 Params.push_back(Param);
7634 NewFD->setParams(Params);
7636 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
7659 WeakTopLevelDecl.push_back(NewD);
7666 PushOnScopeChains(NewD, S);
7667 CurContext = SavedContext;
7677 LoadExternalWeakUndeclaredIdentifiers();
7678 if (!WeakUndeclaredIdentifiers.empty()) {
7680 if (
auto *VD = dyn_cast<VarDecl>(D))
7683 if (
auto *FD = dyn_cast<FunctionDecl>(D))
7688 auto I = WeakUndeclaredIdentifiers.find(
Id);
7689 if (I != WeakUndeclaredIdentifiers.end()) {
7691 DeclApplyPragmaWeak(S, ND, W);
7692 WeakUndeclaredIdentifiers[
Id] = W;
7719 AddPragmaAttributes(S, D);
7725 static bool isForbiddenTypeAllowed(
Sema &S,
Decl *D,
7727 UnavailableAttr::ImplicitReason &reason) {
7731 if (!isa<FieldDecl>(D) && !isa<ObjCPropertyDecl>(D) &&
7732 !isa<FunctionDecl>(D))
7740 if ((isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) {
7743 reason = UnavailableAttr::IR_ForbiddenWeak;
7752 reason = UnavailableAttr::IR_ARCForbiddenType;
7762 auto Reason = UnavailableAttr::IR_None;
7763 if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) {
7764 assert(Reason &&
"didn't set reason?");
7769 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
7772 if (FD->
hasAttr<UnavailableAttr>() &&
7774 diag::err_arc_array_param_no_ownership) {
7785 static const AvailabilityAttr *getAttrForPlatform(
ASTContext &Context,
7788 for (
const auto *A : D->
attrs()) {
7789 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
7795 StringRef ActualPlatform = Avail->getPlatform()->getName();
7796 StringRef RealizedPlatform = ActualPlatform;
7798 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
7799 if (suffix != StringRef::npos)
7800 RealizedPlatform = RealizedPlatform.slice(0, suffix);
7806 if (RealizedPlatform == TargetPlatform)
7821 static std::pair<AvailabilityResult, const NamedDecl *>
7822 ShouldDiagnoseAvailabilityOfDecl(
Sema &S,
const NamedDecl *D,
7823 std::string *Message,
7829 while (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
7831 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
7841 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
7842 if (IDecl->getDefinition()) {
7843 D = IDecl->getDefinition();
7848 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7851 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
7852 Result = TheEnumDecl->getAvailability(Message);
7858 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7862 if (Init && Result ==
AR_Available && MD->isClassMethod() &&
7863 MD->getSelector() == S.
NSAPIObj->getNewSelector() &&
7880 VersionTuple DeclVersion,
Decl *Ctx,
7882 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
7885 auto CheckContext = [&](
const Decl *C) {
7887 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, C))
7888 if (AA->getIntroduced() >= DeclVersion)
7891 if (C->isDeprecated())
7897 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
7898 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
7899 if (MD->getClassInterface() == Impl->getClassInterface())
7905 if (C->isUnavailable())
7911 if (CheckContext(Ctx))
7916 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
7917 if (MethodD->isClassMethod() &&
7918 MethodD->getSelector().getAsString() ==
"load")
7921 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
7923 if (CheckContext(Interface))
7927 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
7929 if (CheckContext(Interface))
7937 shouldDiagnoseAvailabilityByDefault(
const ASTContext &Context,
7938 const VersionTuple &DeploymentVersion,
7939 const VersionTuple &DeclVersion) {
7941 VersionTuple ForceAvailabilityFromVersion;
7942 switch (Triple.getOS()) {
7943 case llvm::Triple::IOS:
7944 case llvm::Triple::TvOS:
7945 ForceAvailabilityFromVersion = VersionTuple(11);
7947 case llvm::Triple::WatchOS:
7948 ForceAvailabilityFromVersion = VersionTuple(4);
7950 case llvm::Triple::Darwin:
7951 case llvm::Triple::MacOSX:
7952 ForceAvailabilityFromVersion = VersionTuple(10, 13);
7956 return Triple.getVendor() == llvm::Triple::Apple;
7958 return DeploymentVersion >= ForceAvailabilityFromVersion ||
7959 DeclVersion >= ForceAvailabilityFromVersion;
7962 static NamedDecl *findEnclosingDeclToAnnotate(
Decl *OrigCtx) {
7963 for (
Decl *Ctx = OrigCtx; Ctx;
7965 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
7966 return cast<NamedDecl>(Ctx);
7967 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
7968 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
7969 return Imp->getClassInterface();
7979 struct AttributeInsertion {
7984 static AttributeInsertion createInsertionAfter(
const NamedDecl *D) {
7987 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
7988 return {
" ", Loc,
""};
7990 static AttributeInsertion createInsertionBefore(
const NamedDecl *D) {
8009 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
8010 Name = Name.drop_front(1);
8013 Name.split(SlotNames,
':');
8015 if (Name.back() ==
':') {
8017 SlotNames.pop_back();
8018 NumParams = SlotNames.size();
8020 if (SlotNames.size() != 1)
8026 bool AllowDollar = LangOpts.DollarIdents;
8027 for (StringRef S : SlotNames) {
8041 if (isa<ObjCPropertyDecl>(D))
8042 return AttributeInsertion::createInsertionAfter(D);
8043 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
8046 return AttributeInsertion::createInsertionAfter(D);
8048 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
8054 return AttributeInsertion::createInsertionAfter(Loc);
8056 return AttributeInsertion::createInsertionBefore(D);
8076 bool ObjCPropertyAccess) {
8078 unsigned diag, diag_message, diag_fwdclass_message;
8079 unsigned diag_available_here = diag::note_availability_specified_here;
8083 unsigned property_note_select;
8086 unsigned available_here_select_kind;
8088 VersionTuple DeclVersion;
8089 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, OffendingDecl))
8090 DeclVersion = AA->getIntroduced();
8092 if (!ShouldDiagnoseAvailabilityInContext(S, K, DeclVersion, Ctx,
8100 const AvailabilityAttr *A = getAttrForPlatform(S.
Context, OffendingDecl);
8101 if (A && A->isInherited()) {
8104 const AvailabilityAttr *AForRedecl =
8105 getAttrForPlatform(S.
Context, Redecl);
8106 if (AForRedecl && !AForRedecl->isInherited()) {
8109 NoteLocation = Redecl->getLocation();
8121 const AvailabilityAttr *AA =
8123 VersionTuple Introduced = AA->getIntroduced();
8125 bool UseNewWarning = shouldDiagnoseAvailabilityByDefault(
8128 unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
8129 : diag::warn_unguarded_availability;
8131 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8134 S.
Diag(Loc, Warning) << OffendingDecl << PlatformName
8135 << Introduced.getAsString();
8138 diag::note_partial_availability_specified_here)
8139 << OffendingDecl << PlatformName << Introduced.getAsString()
8142 if (
const auto *Enclosing = findEnclosingDeclToAnnotate(Ctx)) {
8143 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
8144 if (TD->getDeclName().isEmpty()) {
8145 S.
Diag(TD->getLocation(),
8146 diag::note_decl_unguarded_availability_silence)
8147 << 1 << TD->getKindName();
8150 auto FixitNoteDiag =
8151 S.
Diag(Enclosing->getLocation(),
8152 diag::note_decl_unguarded_availability_silence)
8155 if (Enclosing->hasAttr<AvailabilityAttr>())
8163 std::string PlatformName =
8164 AvailabilityAttr::getPlatformNameSourceSpelling(
8167 std::string Introduced =
8171 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
8172 "(" + Introduced +
"))" + Insertion->Suffix)
8178 diag = !ObjCPropertyAccess ? diag::warn_deprecated
8179 : diag::warn_property_method_deprecated;
8180 diag_message = diag::warn_deprecated_message;
8181 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
8182 property_note_select = 0;
8183 available_here_select_kind = 2;
8184 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
8185 NoteLocation = AL->getLocation();
8189 diag = !ObjCPropertyAccess ? diag::err_unavailable
8190 : diag::err_property_method_unavailable;
8191 diag_message = diag::err_unavailable_message;
8192 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
8193 property_note_select = 1;
8194 available_here_select_kind = 0;
8196 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
8197 if (AL->isImplicit() && AL->getImplicitReason()) {
8200 auto flagARCError = [&] {
8204 diag = diag::err_unavailable_in_arc;
8207 switch (AL->getImplicitReason()) {
8208 case UnavailableAttr::IR_None:
break;
8210 case UnavailableAttr::IR_ARCForbiddenType:
8212 diag_available_here = diag::note_arc_forbidden_type;
8215 case UnavailableAttr::IR_ForbiddenWeak:
8217 diag_available_here = diag::note_arc_weak_disabled;
8219 diag_available_here = diag::note_arc_weak_no_runtime;
8222 case UnavailableAttr::IR_ARCForbiddenConversion:
8224 diag_available_here = diag::note_performs_forbidden_arc_conversion;
8227 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
8229 diag_available_here = diag::note_arc_init_returns_unrelated;
8232 case UnavailableAttr::IR_ARCFieldWithOwnership:
8234 diag_available_here = diag::note_arc_field_with_ownership;
8242 llvm_unreachable(
"Warning for availability of available declaration?");
8247 StringRef Replacement;
8248 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
8249 Replacement = AL->getReplacement();
8250 if (
auto AL = getAttrForPlatform(S.
Context, OffendingDecl))
8251 Replacement = AL->getReplacement();
8254 if (!Replacement.empty())
8258 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
8259 Selector Sel = MethodDecl->getSelector();
8263 if (NumParams && NumParams.getValue() == Sel.
getNumArgs()) {
8264 assert(SelectorSlotNames.size() == Locs.size());
8265 for (
unsigned I = 0; I < Locs.size(); ++I) {
8270 NameRange, SelectorSlotNames[I]));
8282 if (!Message.empty()) {
8283 S.
Diag(Loc, diag_message) << ReferringDecl << Message << FixIts;
8286 << ObjCProperty->
getDeclName() << property_note_select;
8287 }
else if (!UnknownObjCClass) {
8288 S.
Diag(Loc, diag) << ReferringDecl << FixIts;
8291 << ObjCProperty->
getDeclName() << property_note_select;
8293 S.
Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
8297 S.
Diag(NoteLocation, diag_available_here)
8298 << OffendingDecl << available_here_select_kind;
8304 "Expected an availability diagnostic here");
8307 DoEmitAvailabilityWarning(
8315 assert(DelayedDiagnostics.getCurrentPool());
8317 DelayedDiagnostics.popWithoutEmitting(
state);
8333 bool AnyAccessFailures =
false;
8341 switch (diag.
Kind) {
8346 handleDelayedAvailabilityCheck(*
this, diag, decl);
8353 if (AnyAccessFailures && isa<DecompositionDecl>(decl))
8355 HandleDelayedAccessCheck(diag, decl);
8357 AnyAccessFailures =
true;
8361 handleDelayedForbiddenType(*
this, diag, decl);
8373 assert(curPool &&
"re-emitting in undelayed context not supported");
8374 curPool->
steal(pool);
8384 bool ObjCPropertyAccess) {
8389 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
8390 ObjCProperty, Message, ObjCPropertyAccess));
8395 DoEmitAvailabilityWarning(S, AR, Ctx, ReferringDecl, OffendingDecl,
8396 Message, Locs, UnknownObjCClass, ObjCProperty,
8397 ObjCPropertyAccess);
8405 case Stmt::IfStmtClass:
8406 return cast<IfStmt>(
Parent)->getThen() == S ||
8407 cast<IfStmt>(
Parent)->getElse() == S;
8408 case Stmt::WhileStmtClass:
8409 return cast<WhileStmt>(
Parent)->getBody() == S;
8410 case Stmt::DoStmtClass:
8411 return cast<DoStmt>(
Parent)->getBody() == S;
8412 case Stmt::ForStmtClass:
8413 return cast<ForStmt>(
Parent)->getBody() == S;
8414 case Stmt::CXXForRangeStmtClass:
8415 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
8416 case Stmt::ObjCForCollectionStmtClass:
8417 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
8418 case Stmt::CaseStmtClass:
8419 case Stmt::DefaultStmtClass:
8420 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
8430 bool VisitStmt(
Stmt *S) {
return S != Target; }
8433 static bool isContained(
const Stmt *Target,
const Decl *D) {
8434 StmtUSEFinder Visitor;
8435 Visitor.Target = Target;
8436 return !Visitor.TraverseDecl(const_cast<Decl *>(D));
8452 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
8454 LastDeclUSEFinder Visitor;
8458 if (!Visitor.TraverseStmt(const_cast<Stmt *>(S)))
8471 class DiagnoseUnguardedAvailability
8486 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
8487 : SemaRef(SemaRef), Ctx(Ctx) {
8488 AvailabilityStack.push_back(
8492 bool TraverseDecl(
Decl *D) {
8494 if (!D || isa<FunctionDecl>(D))
8496 return Base::TraverseDecl(D);
8499 bool TraverseStmt(
Stmt *S) {
8502 StmtStack.push_back(S);
8503 bool Result = Base::TraverseStmt(S);
8504 StmtStack.pop_back();
8508 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
8510 bool TraverseIfStmt(
IfStmt *If);
8512 bool TraverseLambdaExpr(
LambdaExpr *E) {
return true; }
8531 DiagnoseDeclAvailability(
8538 DiagnoseDeclAvailability(DRE->
getDecl(),
8555 bool VisitTypeLoc(
TypeLoc Ty);
8558 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
8562 std::tie(Result, OffendingDecl) =
8563 ShouldDiagnoseAvailabilityOfDecl(SemaRef, D,
nullptr, ReceiverClass);
8570 const AvailabilityAttr *AA =
8571 getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
8572 VersionTuple Introduced = AA->getIntroduced();
8574 if (AvailabilityStack.back() >= Introduced)
8579 if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx,
8588 shouldDiagnoseAvailabilityByDefault(
8590 SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced)
8591 ? diag::warn_unguarded_availability_new
8592 : diag::warn_unguarded_availability;
8594 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8595 SemaRef.getASTContext().getTargetInfo().getPlatformName());
8597 SemaRef.Diag(Range.
getBegin(), DiagKind)
8598 << Range << D << PlatformName << Introduced.getAsString();
8601 diag::note_partial_availability_specified_here)
8602 << OffendingDecl << PlatformName << Introduced.getAsString()
8603 << SemaRef.Context.getTargetInfo()
8604 .getPlatformMinVersion()
8608 SemaRef.Diag(Range.
getBegin(), diag::note_unguarded_available_silence)
8610 << (SemaRef.getLangOpts().ObjC ? 0
8614 if (StmtStack.empty())
8616 const Stmt *StmtOfUse = StmtStack.back();
8618 for (
const Stmt *S : llvm::reverse(StmtStack)) {
8619 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
8623 if (isBodyLikeChildStmt(StmtOfUse, S)) {
8631 const Stmt *LastStmtOfUse =
nullptr;
8632 if (isa<DeclStmt>(StmtOfUse) && Scope) {
8633 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
8634 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
8635 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope);
8646 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
8652 const char *ExtraIndentation =
" ";
8653 std::string FixItString;
8654 llvm::raw_string_ostream FixItOS(FixItString);
8655 FixItOS <<
"if (" << (SemaRef.getLangOpts().ObjC ?
"@available" 8656 :
"__builtin_available")
8658 << AvailabilityAttr::getPlatformNameSourceSpelling(
8659 SemaRef.getASTContext().getTargetInfo().getPlatformName())
8660 <<
" " << Introduced.getAsString() <<
", *)) {\n" 8661 << Indentation << ExtraIndentation;
8664 StmtEndLoc, tok::semi, SM, SemaRef.getLangOpts(),
8666 if (ElseInsertionLoc.isInvalid())
8669 FixItOS.str().clear();
8671 << Indentation <<
"} else {\n" 8672 << Indentation << ExtraIndentation
8673 <<
"// Fallback on earlier versions\n" 8674 << Indentation <<
"}";
8679 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
8686 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
8688 DiagnoseDeclAvailability(TD, Range);
8690 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
8692 DiagnoseDeclAvailability(D, Range);
8694 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
8695 if (
NamedDecl *D = ObjCO->getInterface())
8696 DiagnoseDeclAvailability(D, Range);
8702 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
8703 VersionTuple CondVersion;
8704 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->
getCond())) {
8705 CondVersion = E->getVersion();
8709 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
8710 return TraverseStmt(If->
getThen()) && TraverseStmt(If->
getElse());
8713 return Base::TraverseIfStmt(If);
8716 AvailabilityStack.push_back(CondVersion);
8717 bool ShouldContinue = TraverseStmt(If->
getThen());
8718 AvailabilityStack.pop_back();
8720 return ShouldContinue && TraverseStmt(If->
getElse());
8726 Stmt *Body =
nullptr;
8735 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
8737 else if (
auto *BD = dyn_cast<BlockDecl>(D))
8738 Body = BD->getBody();
8740 assert(Body &&
"Need a body here!");
8742 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
8748 bool ObjCPropertyAccess,
8749 bool AvoidPartialAvailabilityChecks,
8751 std::string Message;
8755 std::tie(Result, OffendingDecl) =
8756 ShouldDiagnoseAvailabilityOfDecl(*
this, D, &Message, ClassReceiver);
8761 if (AvoidPartialAvailabilityChecks)
8767 if (getCurFunctionOrMethodDecl()) {
8768 getEnclosingFunction()->HasPotentialAvailabilityViolations =
true;
8770 }
else if (getCurBlock() || getCurLambda()) {
8771 getCurFunction()->HasPotentialAvailabilityViolations =
true;
8777 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
8780 if (PDeclResult == Result)
8785 EmitAvailabilityWarning(*
this, Result, D, OffendingDecl, Message, Locs,
8786 UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess);
The availability attribute was specified explicitly next to the declaration.
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
static std::enable_if< std::is_base_of< Attr, AttrInfo >::value, SourceLocation >::type getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
std::vector< std::string > Features
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
unsigned getRegParmMax() const
static bool hasFunctionProto(const Decl *D)
hasFunctionProto - Return true if the given decl has a argument information.
SourceLocation getBeginLoc() const LLVM_READONLY
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Represents a function declaration or definition.
void DiagnoseUnguardedAvailabilityViolations(Decl *FD)
Issue any -Wunguarded-availability warnings in FD.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
ExtVectorDeclsType ExtVectorDecls
ExtVectorDecls - This is a list all the extended vector types.
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
ExprResult PerformContextuallyConvertToBool(Expr *From)
PerformContextuallyConvertToBool - Perform a contextual conversion of the expression From to bool (C+...
Smart pointer class that efficiently represents Objective-C method names.
PointerType - C99 6.7.5.1 - Pointer Declarators.
unsigned llvm::PointerUnion< const Decl *, const Expr * > DeclTy
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
NoSpeculativeLoadHardeningAttr * mergeNoSpeculativeLoadHardeningAttr(Decl *D, const NoSpeculativeLoadHardeningAttr &AL)
bool isMemberPointerType() const
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
bool isC2xAttribute() const
bool isExternC() const
Determines whether this function is a function with external, C linkage.
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, const AttributeCommonInfo &CI, const IdentifierInfo *Ident)
SpeculativeLoadHardeningAttr * mergeSpeculativeLoadHardeningAttr(Decl *D, const SpeculativeLoadHardeningAttr &AL)
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
SourceLocation getLoc() const
static QualType getFunctionOrMethodResultType(const Decl *D)
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
IfStmt - This represents an if/then/else.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Defines the SourceManager interface.
QualType getThisType() const
Return the type of the this pointer.
virtual bool isValidFeatureName(StringRef Feature) const
Determine whether this TargetInfo supports the given feature.
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
const ObjCObjectType * getAsObjCInterfaceType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
static void handleSimpleAttribute(Sema &S, Decl *D, const AttributeCommonInfo &CI)
Applies the given attribute to the Decl without performing any additional semantic checking...
void ProcessDeclAttributeList(Scope *S, Decl *D, const ParsedAttributesView &AL, bool IncludeCXX11Attributes=true)
SourceLocation getBeginLoc() const LLVM_READONLY
CommonAttr * mergeCommonAttr(Decl *D, const ParsedAttr &AL)
bool isExtVectorType() const
void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a particular declaration.
void PopParsingDeclaration(ParsingDeclState state, Decl *decl)
Defines the C++ template declaration subclasses.
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
Expr * getArgAsExpr(unsigned Arg) const
The base class of the type hierarchy.
bool getMustBeNull() const
OptimizeNoneAttr * mergeOptimizeNoneAttr(Decl *D, const AttributeCommonInfo &CI)
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, TypeVisibilityAttr::VisibilityType Vis)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
SourceLocation getEndLoc() const LLVM_READONLY
NamedDecl * getParam(unsigned Idx)
QualType withConst() const
const TargetInfo & getTargetInfo() const
A container of type source information.
static FunctionDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation NLoc, DeclarationName N, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified=false, bool hasWrittenPrototype=true, ConstexprSpecKind ConstexprKind=CSK_unspecified, Expr *TrailingRequiresClause=nullptr)
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
bool hasParsedType() const
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
unsigned getCharWidth() const
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
SourceLocation getEndLoc() const
Get the end source location.
const ParsedAttributes & getAttributes() const
IdentifierInfo * getAlias() const
QualType getConstType(QualType T) const
Return the uniqued reference to the type for a const qualified type.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
SourceLocation getEndLoc() const LLVM_READONLY
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
DLLImportAttr * mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI)
Represents a variable declaration or definition.
Information about one declarator, including the parsed type information and the identifier.
bool allowsDirectDispatch() const
Does this runtime supports direct dispatch.
QualType getReturnType() const
const T * getAs() const
Member-template getAs<specific type>'.
virtual bool validateBranchProtection(StringRef Spec, BranchProtectionInfo &BPI, StringRef &Err) const
Determine if this TargetInfo supports the given branch protection specification.
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
ObjCInterfaceDecl * getClassReceiver() const
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
ObjCMethodDecl - Represents an instance or class method declaration.
bool isInvalidDecl() const
Stores a list of template parameters for a TemplateDecl and its derived classes.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=nullptr, bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, bool IsClassTemplateDeductionContext=true, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
bool hasDefinition() const
Represents a parameter to a function.
QualType getLocalUnqualifiedType() const
Return this type with all of the instance-specific qualifiers removed, but without removing any quali...
pool_iterator pool_begin() const
Defines the clang::Expr interface and subclasses for C++ expressions.
const Type * getTypePtr() const
bool hasFloatingRepresentation() const
Determine whether this type has a floating-point representation of some sort, e.g., it is a floating-point type or a vector thereof.
const ObjCPropertyDecl * getObjCProperty() const
const NamedDecl * getAvailabilityReferringDecl() const
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Base wrapper for a particular "section" of type source info.
Represents a struct/union/class.
void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, Expr *Min, Expr *Max)
addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size attribute to a particular declar...
void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E)
AddAlignValueAttr - Adds an align_value attribute to a particular declaration.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
const ParsedType & getMatchingCType() const
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
CodeSegAttr * mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name)
One of these records is kept for each identifier that is lexed.
std::unique_ptr< NSAPI > NSAPIObj
Caches identifiers/selectors for NSFoundation APIs.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
static StringRef getIndentationForLine(SourceLocation Loc, const SourceManager &SM)
Returns the leading whitespace for line that corresponds to the given location Loc.
MSInheritanceModel calculateInheritanceModel() const
Calculate what the inheritance model would be for this class.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
ObjCMethodDecl * lookupInstanceMethod(Selector Sel) const
Lookup an instance method for a given selector.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
The results of name lookup within a DeclContext.
bool CheckAttrTarget(const ParsedAttr &CurrAttr)
static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D, const AttrInfo &AI, unsigned AttrArgNum, const Expr *IdxExpr, ParamIdx &Idx, bool CanIndexImplicitThis=false)
Check if IdxExpr is a valid parameter index for a function or instance method D.
field_range fields() const
NamedDecl * DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, SourceLocation Loc)
SourceLocation getBeginLoc() const LLVM_READONLY
bool isObjCIdType() const
Represents a member of a struct/union/class.
unsigned getSourceIndex() const
Get the parameter index as it would normally be encoded for attributes at the source level of represe...
bool isGlobalVar(Expr *E)
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
bool isReferenceType() const
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
__DEVICE__ int max(int __a, int __b)
Represents an access specifier followed by colon ':'.
SourceLocation getBeginLoc() const LLVM_READONLY
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static bool checkUInt32Argument(Sema &S, const AttrInfo &AI, const Expr *Expr, uint32_t &Val, unsigned Idx=UINT_MAX, bool StrictlyUnsigned=false)
If Expr is a valid integer constant, get the value of the integer expression and return success or fa...
i32 captured_struct **param SharedsTy A type which contains references the shared variables *param Shareds Context with the list of shared variables from the p *TaskFunction *param Data Additional data for task generation like final * state
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
Describes a module or submodule.
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
void setARCPseudoStrong(bool PS)
ArrayRef< ParmVarDecl * > parameters() const
const NamedDecl * getAvailabilityOffendingDecl() const
MinSizeAttr * mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI)
AttributeCommonInfo::Kind getKind() const
bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value)
virtual std::string isValidSectionSpecifier(StringRef SR) const
An optional hook that targets can implement to perform semantic checking on attribute((section("foo")...
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
Represents the results of name lookup.
void checkUnusedDeclAttributes(Declarator &D)
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
TagKind getTagKind() const
CharUnits - This is an opaque type for sizes expressed in character units.
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceModel SemanticSpelling)
bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD=nullptr)
void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, Expr *ParamExpr)
AddAllocAlignAttr - Adds an alloc_align attribute to a particular declaration.
AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, QualType LHSType, QualType RHSType)
CheckAssignmentConstraints - Perform type checking for assignment, argument passing, variable initialization, and function return values.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
Visibility getVisibility() const
Determine the visibility of this type.
MSInheritanceModel
Assigned inheritance model for a class in the MS C++ ABI.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str)
bool existsInTarget(const TargetInfo &Target) const
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
bool isClassReceiver() const
The availability attribute was applied using '#pragma clang attribute'.
bool isLambda() const
Determine whether this class describes a lambda function object.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
unsigned getMinArgs() const
Scope - A scope is a transient data structure that is used while parsing the program.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
field_iterator field_begin() const
CaseStmt - Represent a case statement.
bool hasVariadicArg() const
Represents information about a change in availability for an entity, which is part of the encoding of...
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
const LangOptions & getLangOpts() const
bool isTypeDependent() const
isTypeDependent - Determines whether this expression is type-dependent (C++ [temp.dep.expr]), which means that its type could change from one template instantiation to the next.
void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, RetainOwnershipKind K, bool IsTemplateInstantiation)
virtual unsigned getRegisterWidth() const
Return the "preferred" register width on this target.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs, typeofs, etc., as well as any qualifiers.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
const IdentifierInfo * getAttrName() const
SourceLocation getTypeSpecStartLoc() const
VersionTuple Version
The version number at which the change occurred.
const LangOptions & LangOpts
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod, bool IsBuiltin=false) const
Retrieves the default calling convention for the current target.
bool hasCustomParsing() const
static SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx)
This object can be modified without requiring retains or releases.
param_iterator param_begin()
Represents the this expression in C++.
void setInvalid(bool b=true) const
static bool checkPositiveIntArgument(Sema &S, const AttrInfo &AI, const Expr *Expr, int &Val, unsigned Idx=UINT_MAX)
Wrapper around checkUInt32Argument, with an extra check to be sure that the result will fit into a re...
void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, bool InInstantiation=false)
AddModeAttr - Adds a mode attribute to a particular declaration.
Language
The language for the input, used to select and validate the language standard and possible actions...
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
AvailabilityResult
Captures the result of checking the availability of a declaration.
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool isExternC() const
Determines whether this variable is a variable with external, C linkage.
llvm::StringRef getParameterABISpelling(ParameterABI kind)
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
static bool checkAttributeAtLeastNumArgs(Sema &S, const ParsedAttr &AL, unsigned Num)
Check if the attribute has at least as many args as Num.
void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W)
Sema - This implements semantic analysis and AST building for C.
Contains information gathered from parsing the contents of TargetAttr.
static Attr * handleSuppressAttr(Sema &S, Stmt *St, const ParsedAttr &A, SourceRange Range)
CompoundStmt - This represents a group of statements like { stmt stmt }.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a prototype with parameter type info, e.g.
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple(), StringRef *RealizedPlatform=nullptr) const
Determine the availability of the given declaration.
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
static bool checkAttributeNumArgs(Sema &S, const ParsedAttr &AL, unsigned Num)
Check if the attribute has exactly as many args as Num.
static const Sema::SemaDiagnosticBuilder & appendDiagnostics(const Sema::SemaDiagnosticBuilder &Bldr)
DeclarationNameTable DeclarationNames
bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, const ParsedAttributesView &AttrList)
const ParsedAttributesView & getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible. ...
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Captures information about a #pragma weak directive.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
Exposes information about the current target.
const ObjCInterfaceDecl * getUnknownObjCClass() const
void CheckAlignasUnderalignment(Decl *D)
static bool isCFStringType(QualType T, ASTContext &Ctx)
SourceLocation getBeginLoc() const
Get the begin source location.
A single parameter index whose accessors require each use to make explicit the parameter index encodi...
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, Expr *OE)
AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular declaration.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorType::VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
virtual bool hasProtectedVisibility() const
Does this target support "protected" visibility?
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Represents a character-granular source range.
bool isVariadic() const
Whether this function is variadic.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
static bool hasDeclarator(const Decl *D)
Return true if the given decl has a declarator that should have been processed by Sema::GetTypeForDec...
SourceLocation getEndLoc() const LLVM_READONLY
static SourceLocation findLocationAfterToken(SourceLocation loc, tok::TokenKind TKind, const SourceManager &SM, const LangOptions &LangOpts, bool SkipTrailingWhitespaceAndNewLine)
Checks that the given token is the first token that occurs after the given location (this excludes co...
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
bool isObjCRetainableType() const
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
SourceLocation getEndLoc() const LLVM_READONLY
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
const AvailabilityChange & getAvailabilityObsoleted() const
Defines the clang::Preprocessor interface.
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
field_iterator field_end() const
ObjCLifetime getObjCLifetime() const
bool isFileContext() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
DeclContext * getDeclContext()
CXXRecordDecl * getDefinition() const
VisibilityAttr * mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, VisibilityAttr::VisibilityType Vis)
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
bool isDeclspecAttribute() const
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
bool isFunctionTemplateSpecialization() const
Determine whether this function is a function template specialization.
FunctionDecl * ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, bool Complain=false, DeclAccessPair *Found=nullptr)
Given an expression that refers to an overloaded function, try to resolve that overloaded function ex...
bool isValid() const
Determine whether this availability change is valid.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
void ProcessPragmaWeak(Scope *S, Decl *D)
DLLExportAttr * mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI)
clang::ObjCRuntime ObjCRuntime
DeclContext * getParent()
getParent - Returns the containing DeclContext.
An expression that sends a message to the given Objective-C object or class.
static bool isNSStringType(QualType T, ASTContext &Ctx)
Preprocessor & getPreprocessor() const
Represents a GCC generic vector type.
unsigned getNumArgs() const
Wraps an identifier and optional source location for the identifier.
void setAttributeSpellingListIndex(unsigned V)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
static StringRef getIdentifier(const Token &Tok)
SourceLocation getLocation() const
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
static CharSourceRange getCharRange(SourceRange R)
bool getLayoutCompatible() const
This is a scope that corresponds to the parameters within a function prototype for a function declara...
bool isVoidPointerType() const
void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, bool IsPackExpansion)
AddAlignedAttr - Adds an aligned attribute to a particular declaration.
SourceLocation getEllipsisLoc() const
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
RecordDecl * getDecl() const
static bool checkAttributeAtMostNumArgs(Sema &S, const ParsedAttr &AL, unsigned Num)
Check if the attribute has at most as many args as Num.
InternalLinkageAttr * mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL)
ArrayRef< SourceLocation > getAvailabilitySelectorLocs() const
Expr * getTrailingRequiresClause()
Get the constraint-expression introduced by the trailing requires-clause in the function/member decla...
unsigned getASTIndex() const
Get the parameter index as it would normally be encoded at the AST level of representation: zero-orig...
A parameter attribute which changes the argument-passing ABI rule for the parameter.
static bool isFunctionOrMethodOrBlock(const Decl *D)
Return true if the given decl has function type (function or function-typed variable) or an Objective...
There is no lifetime qualification on this type.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Assigning into this object requires the old value to be released and the new value to be retained...
QualType getCanonicalType() const
bool isBuiltinType() const
Helper methods to distinguish type categories.
not a target-specific vector type
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
LLVM_READONLY bool isValidIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, Expr *MaxThreads, Expr *MinBlocks)
AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular declaration. ...
ASTContext & getASTContext() const
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
unsigned getForbiddenTypeDiagnostic() const
The diagnostic ID to emit.
VersionTuple getVersionIntroduced() const
Retrieve the version of the target platform in which this declaration was introduced.
Encodes a location in the source.
unsigned getForbiddenTypeArgument() const
QualType getReturnType() const
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
LangAS getAddressSpace() const
Return the address space of this type.
const ParsedType & getTypeArg() const
void setUsed(bool Used=true)
AvailabilityAttr * mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, IdentifierInfo *Platform, bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, int Priority)
Attribute merging methods. Return true if a new attribute was added.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
DeclarationName getName() const
getName - Returns the embedded declaration name.
Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
IdentifierTable & getIdentifierTable()
ParsedAttr - Represents a syntactic attribute.
reverse_body_iterator body_rend()
void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass, bool ObjCPropertyAccess, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReceiver=nullptr)
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
Represents a static or instance method of a struct/union/class.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
bool hasProcessingCache() const
bool isUsedAsTypeAttr() const
const ParmVarDecl * getParamDecl(unsigned i) const
SourceLocation getLocation() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
void push_back(const T &LocalValue)
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
pool_iterator pool_end() const
bool isObjCObjectPointerType() const
bool isAnyPointerType() const
bool isArgExpr(unsigned Arg) const
bool diagnoseLangOpts(class Sema &S) const
SourceRange getRange() const
AvailabilityResult getAvailabilityResult() const
Represents one property declaration in an Objective-C interface.
const ObjCMethodDecl * getMethodDecl() const
bool isVectorType() const
Assigning into this object requires a lifetime extension.
ParameterABI
Kinds of parameter ABI.
CUDAFunctionTarget CurrentCUDATarget()
Gets the CUDA target for the current context.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
static bool isBuiltinFunc(llvm::StringRef Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
StringRef getName() const
Return the actual identifier string.
StringRef BranchProtection
bool isMacroDefined(StringRef Id)
void setProcessingCache(unsigned value) const
Base class for declarations which introduce a typedef-name.
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
static DelayedDiagnostic makeAvailability(AvailabilityResult AR, ArrayRef< SourceLocation > Locs, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess)
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
ComparisonCategoryResult Compare(const T &X, const T &Y)
Helper to compare two comparable types.
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
Don't merge availability attributes at all.
void ProcessDeclAttributeDelayed(Decl *D, const ParsedAttributesView &AttrList)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
QualType getForbiddenTypeOperand() const
virtual char CPUSpecificManglingCharacter(StringRef Name) const
static unsigned getNumAttributeArgs(const ParsedAttr &AL)
static std::string getName(const CallEvent &Call)
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
ASTMutationListener * getASTMutationListener() const
void redelayDiagnostics(sema::DelayedDiagnosticPool &pool)
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const ParsedAttr &AL)
Diagnose mutually exclusive attributes when present on a given declaration.
const AvailabilityChange & getAvailabilityIntroduced() const
UuidAttr * mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Uuid)
A runtime availability query.
SmallVectorImpl< DelayedDiagnostic >::const_iterator pool_iterator
bool isPackExpansion() const
The name of a declaration.
StmtClass getStmtClass() const
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
bool isBooleanType() const
SourceLocation getStrictLoc() const
bool isCXX11Attribute() const
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
isIntegerConstantExpr - Return true if this expression is a valid integer constant expression...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
NamedDecl * getCurFunctionOrMethodDecl()
getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method or C function we're in...
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
const AvailabilityChange & getAvailabilityDeprecated() const
param_iterator param_end()
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
static bool checkAttributeNumArgsImpl(Sema &S, const ParsedAttr &AL, unsigned Num, unsigned Diag, Compare Comp)
bool CheckAttrNoArgs(const ParsedAttr &CurrAttr)
QualType getClassReceiver() const
Returns the type of a class message send, or NULL if the message is not a class message.
Represents a pointer to an Objective C object.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
The availability attribute for a specific platform was inferred from an availability attribute for an...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
SourceLocation getBeginLoc() const
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
static bool isFunctionOrMethod(const Decl *D)
isFunctionOrMethod - Return true if the given decl has function type (function or function-typed vari...
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
FormatAttr * mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Format, int FormatIdx, int FirstArg)
TypeSourceInfo * getTypeSourceInfo() const
DeclContext * getCurLexicalContext() const
virtual bool isValidCPUName(StringRef Name) const
brief Determine whether this TargetInfo supports the given CPU name.
Base for LValueReferenceType and RValueReferenceType.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
SourceLocation getEnd() const
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
CharSourceRange getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
const DelayedDiagnosticPool * getParent() const
bool isValidPointerAttrType(QualType T, bool RefOkay=false)
Determine if type T is a valid subject for a nonnull and similar attributes.
Represents a base class of a C++ class.
bool isMicrosoftAttribute() const
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
const Type * getTypePtrOrNull() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
SourceManager & getSourceManager()
bool isObjCObjectType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Scope * getScopeForContext(DeclContext *Ctx)
Determines the active Scope associated with the given declaration context.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
unsigned getMaxArgs() const
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
Reading or writing from this object requires a barrier call.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
MSInheritanceAttr * mergeMSInheritanceAttr(Decl *D, const AttributeCommonInfo &CI, bool BestCase, MSInheritanceModel Model)
TranslationUnitDecl * getTranslationUnitDecl() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
static bool isInstanceMethod(const Decl *D)
Represents a C++ struct/union/class.
Compatible - the types are compatible according to the standard.
static unsigned getFunctionOrMethodNumParams(const Decl *D)
getFunctionOrMethodNumParams - Return number of function or method parameters.
SourceLocation getSelectorStartLoc() const
reverse_body_iterator body_rbegin()
A diagnostic message which has been conditionally emitted pending the complete parsing of the current...
bool isTLSSupported() const
Whether the target supports thread-local storage.
bool DuplicateArchitecture
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
unsigned getAttributeSpellingListIndex() const
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y)
Check whether the two versions match.
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const
Return the implicit lifetime for this type, which must not be dependent.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
This class is used for builtin types like 'int'.
static SourceRange getFunctionOrMethodResultSourceRange(const Decl *D)
SourceManager & getSourceManager() const
void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, ParameterABI ABI)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
const Expr * getMessageExpr() const
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
const IdentifierInfo * getScopeName() const
SectionAttr * mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name)
QualType getRealTypeForBitwidth(unsigned DestWidth) const
getRealTypeForBitwidth - sets floating point QualTy according to specified bitwidth.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
SourceLocation getBeginLoc() const LLVM_READONLY
A reference to a declared variable, function, enum, etc.
NamedDecl * getMostRecentDecl()
static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx)
bool isPointerType() const
bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument ArgNum of Attr is a ASCII string literal.
SourceLocation getReceiverLocation() const
void NoteAllOverloadCandidates(Expr *E, QualType DestType=QualType(), bool TakingAddress=false)
BasePaths - Represents the set of paths from a derived class to one of its (direct or indirect) bases...
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
class clang::Sema::DelayedDiagnostics DelayedDiagnostics
A collection of diagnostics which were delayed.
void setIsMultiVersion(bool V=true)
Sets the multiversion state for this declaration and all of its redeclarations.
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExprUnevaluted - Return true if this expression might be usable in a constant expr...
bool isFloatingType() const
bool isArgIdent(unsigned Arg) const
A trivial tuple used to represent a source range.
void setLexicalDeclContext(DeclContext *DC)
This represents a decl that may have a name.
const TargetInfo * getAuxTargetInfo() const
Automatic storage duration (most local variables).
static bool isFunctionOrMethodVariadic(const Decl *D)
Describes an entity that is being initialized.
bool isFunctionPointerType() const
bool isPragmaClangAttribute() const
True if the attribute is specified using '#pragma clang attribute'.
void setHasDesignatedInitializers()
Indicate that this interface decl contains at least one initializer marked with the 'objc_designated_...
StringRef getAvailabilityMessage() const
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
void setType(QualType newType)
SourceLocation getBegin() const
SourceLocation getUnavailableLoc() const
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
const LangOptions & getLangOpts() const
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type)
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
This class handles loading and caching of source files into memory.
static const ParmVarDecl * getFunctionOrMethodParam(const Decl *D, unsigned Idx)
Declaration of a template function.
IdentifierLoc * getArgAsIdent(unsigned Arg) const
bool isObjCNSObjectType() const
Attr - This represents one attribute.
ParsedAttributes & getAttributes()
SourceLocation getLocation() const
DeviceDiagBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a DeviceDiagBuilder that emits the diagnostic if the current context is "used as host code"...
bool isBeingDefined() const
Return true if this decl is currently being defined.
This parameter (which must have pointer type) is a Swift indirect result parameter.
virtual unsigned getUnwindWordWidth() const
virtual bool validateCPUSpecificCPUDispatch(StringRef Name) const
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth, signed/unsigned.
Helper class that creates diagnostics with optional template instantiation stacks.
static OMPLinearClause * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef< Expr *> VL, ArrayRef< Expr *> PL, ArrayRef< Expr *> IL, Expr *Step, Expr *CalcStep, Stmt *PreInit, Expr *PostUpdate)
Creates clause with a list of variables VL and a linear step Step.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
unsigned getProcessingCache() const
const Expr * getReplacementExpr() const