35 #include "llvm/ADT/STLExtras.h" 36 #include "llvm/ADT/StringExtras.h" 37 #include "llvm/Support/MathExtras.h" 39 using namespace clang;
71 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
72 isa<ObjCPropertyDecl>(D);
80 return isa<FunctionProtoType>(FnTy);
81 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
89 return cast<FunctionProtoType>(FnTy)->getNumParams();
90 if (
const auto *BD = dyn_cast<BlockDecl>(D))
91 return BD->getNumParams();
92 return cast<ObjCMethodDecl>(D)->param_size();
97 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
98 return FD->getParamDecl(Idx);
99 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
100 return MD->getParamDecl(Idx);
101 if (
const auto *BD = dyn_cast<BlockDecl>(D))
102 return BD->getParamDecl(Idx);
108 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
109 if (
const auto *BD = dyn_cast<BlockDecl>(D))
110 return BD->getParamDecl(Idx)->getType();
112 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
117 return PVD->getSourceRange();
123 return FnTy->getReturnType();
124 return cast<ObjCMethodDecl>(D)->getReturnType();
128 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
129 return FD->getReturnTypeSourceRange();
130 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
131 return MD->getReturnTypeSourceRange();
137 return cast<FunctionProtoType>(FnTy)->isVariadic();
138 if (
const auto *BD = dyn_cast<BlockDecl>(D))
139 return BD->isVariadic();
140 return cast<ObjCMethodDecl>(D)->isVariadic();
144 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
145 return MethodDecl->isInstance();
161 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
162 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
186 template <
typename Compare>
188 unsigned Num,
unsigned Diag,
202 diag::err_attribute_wrong_number_arguments,
203 std::not_equal_to<unsigned>());
211 diag::err_attribute_too_few_arguments,
212 std::less<unsigned>());
220 diag::err_attribute_too_many_arguments,
221 std::greater<unsigned>());
226 template <
typename AttrInfo>
227 static typename std::enable_if<std::is_base_of<Attr, AttrInfo>::value,
230 return AL.getLocation();
239 template <
typename AttrInfo>
241 uint32_t &Val,
unsigned Idx =
UINT_MAX,
242 bool StrictlyUnsigned =
false) {
258 << I.toString(10,
false) << 32 << 1;
262 if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
263 S.
Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
268 Val = (uint32_t)I.getZExtValue();
275 template <
typename AttrInfo>
277 int &Val,
unsigned Idx =
UINT_MAX) {
286 << I.toString(10,
false) << 32 << 0;
296 template <
typename AttrTy>
298 if (
const auto *A = D->
getAttr<AttrTy>()) {
299 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
300 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
306 template <
typename AttrTy>
308 if (
const auto *A = D->
getAttr<AttrTy>()) {
309 S.
Diag(AL.
getLocation(), diag::err_attributes_are_not_compatible) << &AL
311 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
321 template <
typename AttrInfo>
323 Sema &S,
const Decl *D,
const AttrInfo &AI,
unsigned AttrArgNum,
324 const Expr *IdxExpr,
ParamIdx &Idx,
bool CanIndexImplicitThis =
false) {
344 unsigned IdxSource = IdxInt.getLimitedValue(
UINT_MAX);
345 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
346 S.
Diag(
getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
350 if (HasImplicitThisParam && !CanIndexImplicitThis) {
351 if (IdxSource == 1) {
352 S.
Diag(
getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
372 Diag(Loc->
Loc, diag::err_attribute_argument_type)
378 *ArgLocation = Loc->
Loc;
388 if (!Literal || !Literal->isAscii()) {
394 Str = Literal->getString();
400 template <
typename AttrType>
402 unsigned SpellingIndex) {
406 template <
typename AttrType>
408 handleSimpleAttribute<AttrType>(S, D, AL.
getRange(),
413 template <
typename... DiagnosticArgs>
419 template <
typename T,
typename... DiagnosticArgs>
422 DiagnosticArgs &&... ExtraArgs) {
424 std::forward<DiagnosticArgs>(ExtraArgs)...);
431 template <
typename AttrType,
typename... DiagnosticArgs>
434 unsigned SpellingIndex,
436 unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
442 handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
445 template <
typename AttrType,
typename... DiagnosticArgs>
450 DiagnosticArgs&&... ExtraArgs) {
451 return handleSimpleAttributeOrDiagnose<AttrType>(
453 DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...);
456 template <
typename AttrType>
457 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
459 handleSimpleAttribute<AttrType>(S, D, AL);
464 template <
typename AttrType,
typename IncompatibleAttrType,
465 typename... IncompatibleAttrTypes>
466 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
468 if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
470 handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
475 static bool isIntOrBool(
Expr *Exp) {
483 static bool threadSafetyCheckIsSmartPointer(
Sema &S,
const RecordType* RT) {
484 auto IsOverloadedOperatorPresent = [&S](
const RecordDecl *Record,
488 return !Result.
empty();
492 bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
493 bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
494 if (foundStarOperator && foundArrowOperator)
501 for (
auto BaseSpecifier : CXXRecord->
bases()) {
502 if (!foundStarOperator)
503 foundStarOperator = IsOverloadedOperatorPresent(
504 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
505 if (!foundArrowOperator)
506 foundArrowOperator = IsOverloadedOperatorPresent(
507 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
510 if (foundStarOperator && foundArrowOperator)
519 static bool threadSafetyCheckIsPointer(
Sema &S,
const Decl *D,
521 const auto *VD = cast<ValueDecl>(D);
523 if (QT->isAnyPointerType())
533 if (threadSafetyCheckIsSmartPointer(S, RT))
537 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
554 template <
typename AttrType>
555 static bool checkRecordDeclForAttr(
const RecordDecl *RD) {
561 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
563 if (CRD->lookupInBases(
565 const auto &Ty = *BS->getType();
567 if (Ty.isDependentType())
569 return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
577 static bool checkRecordTypeForCapability(
Sema &S,
QualType Ty) {
589 if (threadSafetyCheckIsSmartPointer(S, RT))
592 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
595 static bool checkTypedefTypeForCapability(
QualType Ty) {
604 return TN->
hasAttr<CapabilityAttr>();
608 if (checkTypedefTypeForCapability(Ty))
611 if (checkRecordTypeForCapability(S, Ty))
617 static bool isCapabilityExpr(
Sema &S,
const Expr *Ex) {
623 if (
const auto *E = dyn_cast<CastExpr>(Ex))
624 return isCapabilityExpr(S, E->getSubExpr());
625 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
626 return isCapabilityExpr(S, E->getSubExpr());
627 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
628 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
629 E->getOpcode() == UO_Deref)
630 return isCapabilityExpr(S, E->getSubExpr());
632 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
633 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
634 return isCapabilityExpr(S, E->getLHS()) &&
635 isCapabilityExpr(S, E->getRHS());
639 return typeHasCapability(S, Ex->
getType());
647 static void checkAttrArgsAreCapabilityObjs(
Sema &S,
Decl *D,
651 bool ParamIdxOk =
false) {
657 if (MD && !MD->isStatic()) {
660 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
661 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
663 diag::warn_thread_attribute_not_on_capability_member)
664 << AL << MD->getParent();
666 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
671 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
676 Args.push_back(ArgExp);
680 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
681 if (StrLit->getLength() == 0 ||
682 (StrLit->isAscii() && StrLit->getString() == StringRef(
"*"))) {
685 Args.push_back(ArgExp);
691 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
692 Args.push_back(ArgExp);
700 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
701 if (UOp->getOpcode() == UO_AddrOf)
702 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
703 if (DRE->getDecl()->isCXXInstanceMember())
704 ArgTy = DRE->getDecl()->getType();
710 if(!RT && ParamIdxOk) {
714 unsigned int NumParams = FD->getNumParams();
715 llvm::APInt ArgValue = IL->
getValue();
716 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
717 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
718 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
720 diag::err_attribute_argument_out_of_bounds_extra_info)
721 << AL << Idx + 1 << NumParams;
724 ArgTy = FD->getParamDecl(ParamIdxFromZero)->getType();
732 if (!typeHasCapability(S, ArgTy) && !isCapabilityExpr(S, ArgExp))
733 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
736 Args.push_back(ArgExp);
745 if (!threadSafetyCheckIsPointer(S, D, AL))
757 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
758 unsigned Size = Args.size();
769 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
778 if (!checkGuardedByAttrCommon(S, D, AL, Arg))
781 if (!threadSafetyCheckIsPointer(S, D, AL))
794 QualType QT = cast<ValueDecl>(D)->getType();
796 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_lockable) << AL;
801 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
810 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
813 Expr **StartArg = &Args[0];
821 if (!checkAcquireOrderAttrCommon(S, D, AL, Args))
824 Expr **StartArg = &Args[0];
834 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
841 if (!checkLockFunAttrCommon(S, D, AL, Args))
844 unsigned Size = Args.size();
845 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
851 static void handleAssertExclusiveLockAttr(
Sema &S,
Decl *D,
854 if (!checkLockFunAttrCommon(S, D, AL, Args))
857 unsigned Size = Args.size();
858 Expr **StartArg = Size == 0 ? nullptr : &Args[0];
869 template <
typename AttrInfo>
871 const AttrInfo &AI,
unsigned AttrArgNo) {
872 assert(AI.isArgExpr(AttrArgNo) &&
"Expected expression argument");
873 Expr *AttrArg = AI.getArgAsExpr(AttrArgNo);
882 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
894 const auto *FD = cast<FunctionDecl>(D);
896 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only) << AL;
905 if (!checkParamIsIntegerType(S, FD, AL, 0))
907 ParamIdx SizeArgNo(SizeArgNoVal, D);
916 if (!checkParamIsIntegerType(S, FD, AL, 1))
932 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
938 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 1);
943 static void handleSharedTrylockFunctionAttr(
Sema &S,
Decl *D,
946 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
954 static void handleExclusiveTrylockFunctionAttr(
Sema &S,
Decl *D,
957 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
968 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
969 unsigned Size = Args.size();
984 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
985 unsigned Size = Args.size();
988 Expr **StartArg = &Args[0];
996 Expr *&Cond, StringRef &Msg) {
1002 Cond = Converted.
get();
1009 Msg =
"<no message provided>";
1015 S.
Diag(AL.
getLoc(), diag::err_attr_cond_never_constant_expr) << AL;
1017 S.
Diag(PDiag.first, PDiag.second);
1024 S.
Diag(AL.
getLoc(), diag::ext_clang_enable_if);
1028 if (checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1037 class ArgumentDependenceChecker
1042 llvm::SmallPtrSet<const ParmVarDecl *, 16> Parms;
1048 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
1051 ClassType =
nullptr;
1056 bool referencesArgs(
Expr *E) {
1064 "`this` doesn't refer to the enclosing class?");
1070 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
1071 if (Parms.count(PVD)) {
1081 S.
Diag(AL.
getLoc(), diag::ext_clang_diagnose_if);
1085 if (!checkFunctionConditionAttr(S, D, AL, Cond, Msg))
1088 StringRef DiagTypeStr;
1092 DiagnoseIfAttr::DiagnosticType DiagType;
1093 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1095 diag::err_diagnose_if_invalid_diagnostic_type);
1099 bool ArgDependent =
false;
1100 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1101 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1108 if (D->
hasAttr<PassObjectSizeAttr>()) {
1109 S.
Diag(D->
getBeginLoc(), diag::err_attribute_only_once_per_parameter) << AL;
1131 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1132 S.
Diag(D->
getBeginLoc(), diag::err_attribute_pointers_only) << AL << 1;
1145 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1147 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1152 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1167 if (!RD->
hasAttr<ConsumableAttr>()) {
1168 S.
Diag(AL.
getLoc(), diag::warn_attr_on_unconsumable_class) <<
1182 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1186 for (
unsigned ArgIndex = 0; ArgIndex < AL.
getNumArgs(); ++ArgIndex) {
1189 StringRef StateString;
1200 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1202 S.
Diag(Loc, diag::warn_attribute_type_not_supported) << AL << StateString;
1206 States.push_back(CallableState);
1221 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1223 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1224 << AL << StateString;
1228 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1255 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1257 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL
1262 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1298 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1305 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1306 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1311 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1322 if (!checkForConsumableClass(S, cast<CXXMethodDecl>(D), AL))
1329 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1330 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported) << AL
1335 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1351 if (
auto *TD = dyn_cast<TagDecl>(D))
1354 else if (
auto *FD = dyn_cast<FieldDecl>(D)) {
1361 if (BitfieldByteAligned)
1363 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1370 if (BitfieldByteAligned)
1371 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))
1420 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1424 if (!checkIBOutletCommon(S, D, AL))
1435 S.
Diag(AL.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1451 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1452 : diag::err_iboutletcollection_type) << QT;
1472 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1474 for (
const auto *I : UD->
fields()) {
1488 bool isReturnValue =
false) {
1491 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1492 << AL << AttrParmRange << TypeRange;
1494 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1495 << AL << AttrParmRange << TypeRange << 0;
1503 for (
unsigned I = 0; I < AL.
getNumArgs(); ++I) {
1511 !attrNonNullArgCheck(
1517 NonNullArgs.push_back(Idx);
1528 I != E && !AnyPointers; ++I) {
1535 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1538 ParamIdx *Start = NonNullArgs.data();
1539 unsigned Size = NonNullArgs.size();
1540 llvm::array_pod_sort(Start, Start + Size);
1550 handleNonNullAttr(S, D, AL);
1552 S.
Diag(AL.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1571 if (!attrNonNullArgCheck(S, ResultType, AL,
SourceRange(), SR,
1585 QualType T = cast<ParmVarDecl>(D)->getType();
1587 S.
Diag(AL.
getLoc(), diag::warn_attribute_pointers_only)
1609 Expr *OE,
unsigned SpellingListIndex) {
1613 AssumeAlignedAttr TmpAttr(AttrRange, Context, E, OE, SpellingListIndex);
1616 if (!isValidPointerAttrType(ResultType,
true)) {
1617 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1618 << &TmpAttr << AttrRange << SR;
1626 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1630 Diag(AttrLoc, diag::err_attribute_argument_type)
1636 if (!I.isPowerOf2()) {
1637 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1647 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1656 AssumeAlignedAttr(AttrRange, Context, E, OE, SpellingListIndex));
1660 unsigned SpellingListIndex) {
1663 AllocAlignAttr TmpAttr(AttrRange, Context,
ParamIdx(), SpellingListIndex);
1667 !isValidPointerAttrType(ResultType,
true)) {
1668 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1674 const auto *FuncDecl = cast<FunctionDecl>(D);
1688 AllocAlignAttr(AttrRange, Context, Idx, SpellingListIndex));
1693 static bool normalizeName(StringRef &AttrName) {
1694 if (AttrName.size() > 4 && AttrName.startswith(
"__") &&
1695 AttrName.endswith(
"__")) {
1696 AttrName = AttrName.drop_front(2).drop_back(2);
1712 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1718 OwnershipAttr::OwnershipKind K =
1724 case OwnershipAttr::Takes:
1725 case OwnershipAttr::Holds:
1727 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments) << AL << 2;
1731 case OwnershipAttr::Returns:
1733 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
1741 StringRef ModuleName = Module->
getName();
1742 if (normalizeName(ModuleName)) {
1757 case OwnershipAttr::Takes:
1758 case OwnershipAttr::Holds:
1762 case OwnershipAttr::Returns:
1768 S.
Diag(AL.
getLoc(), diag::err_ownership_type) << AL << Err
1777 if (I->getOwnKind() != K && I->args_end() !=
1778 std::find(I->args_begin(), I->args_end(), Idx)) {
1779 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << I;
1781 }
else if (K == OwnershipAttr::Returns &&
1782 I->getOwnKind() == OwnershipAttr::Returns) {
1785 if (std::find(I->args_begin(), I->args_end(), Idx) == I->args_end()) {
1786 S.
Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1787 << I->args_begin()->getSourceIndex();
1789 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1795 OwnershipArgs.push_back(Idx);
1798 ParamIdx *Start = OwnershipArgs.data();
1799 unsigned Size = OwnershipArgs.size();
1800 llvm::array_pod_sort(Start, Start + Size);
1809 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
1825 S.
Diag(AL.
getLoc(), diag::err_attribute_weakref_not_global_context)
1826 << cast<NamedDecl>(D);
1873 const auto *FD = cast<FunctionDecl>(D);
1875 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 1;
1889 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_darwin);
1893 S.
Diag(AL.
getLoc(), diag::err_alias_not_supported_on_nvptx);
1897 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1899 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << FD << 0;
1903 const auto *VD = cast<VarDecl>(D);
1904 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1905 S.
Diag(AL.
getLoc(), diag::err_alias_is_definition) << VD << 0;
1933 if (Model !=
"global-dynamic" && Model !=
"local-dynamic" 1934 && Model !=
"initial-exec" && Model !=
"local-exec") {
1935 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1952 S.
Diag(AL.
getLoc(), diag::warn_attribute_return_pointers_only)
1959 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
1961 S.
Diag(AL.
getLoc(), diag::err_attribute_dll_lambda) << AL;
1972 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
1981 S.
Diag(CPUArg->
Loc, diag::err_invalid_cpu_specific_dispatch_value)
1982 << CPUName << (AL.
getKind() == ParsedAttr::AT_CPUDispatch);
1987 if (llvm::any_of(CPUs, [CPUName, &Target](
const IdentifierInfo *Cur) {
1991 S.
Diag(AL.
getLoc(), diag::warn_multiversion_duplicate_entries);
1994 CPUs.push_back(CPUArg->
Ident);
1998 if (AL.
getKind() == ParsedAttr::AT_CPUSpecific)
2010 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
2020 if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, AL))
2025 const auto &Arch = Triple.getArch();
2026 if (Arch != llvm::Triple::x86 &&
2027 (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
2028 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_on_arch)
2029 << AL << Triple.getArchName();
2041 if (!isa<ObjCMethodDecl>(D)) {
2042 S.
Diag(Attrs.
getLoc(), diag::warn_attribute_wrong_decl_type)
2053 S.
Diag(Attrs.
getLoc(), diag::warn_nocf_check_attribute_ignored);
2055 handleSimpleAttribute<AnyX86NoCfCheckAttr>(S, D, Attrs);
2070 Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored) << AL;
2087 ? diag::err_attribute_wrong_decl_type
2088 : diag::warn_attribute_wrong_decl_type)
2125 if (VecReturnAttr *A = D->
getAttr<VecReturnAttr>()) {
2126 S.
Diag(AL.
getLoc(), diag::err_repeat_attribute) << A;
2130 const auto *R = cast<RecordDecl>(D);
2133 if (!isa<CXXRecordDecl>(R)) {
2134 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2138 if (!cast<CXXRecordDecl>(R)->isPOD()) {
2139 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2143 for (
const auto *I : R->fields()) {
2144 if ((count == 1) || !I->getType()->isVectorType()) {
2145 S.
Diag(AL.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2157 if (isa<ParmVarDecl>(D)) {
2162 diag::err_carries_dependency_param_not_function_decl);
2178 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2185 uint32_t priority = ConstructorAttr::DefaultPriority;
2196 uint32_t priority = DestructorAttr::DefaultPriority;
2206 template <
typename AttrTy>
2217 static void handleObjCSuppresProtocolAttr(
Sema &S,
Decl *D,
2219 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2220 S.
Diag(AL.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
2232 VersionTuple Introduced,
2233 VersionTuple Deprecated,
2234 VersionTuple Obsoleted) {
2235 StringRef PlatformName
2236 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2237 if (PlatformName.empty())
2238 PlatformName = Platform->
getName();
2242 if (!Introduced.empty() && !Deprecated.empty() &&
2243 !(Introduced <= Deprecated)) {
2244 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2245 << 1 << PlatformName << Deprecated.getAsString()
2246 << 0 << Introduced.getAsString();
2250 if (!Introduced.empty() && !Obsoleted.empty() &&
2251 !(Introduced <= Obsoleted)) {
2252 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2253 << 2 << PlatformName << Obsoleted.getAsString()
2254 << 0 << Introduced.getAsString();
2258 if (!Deprecated.empty() && !Obsoleted.empty() &&
2259 !(Deprecated <= Obsoleted)) {
2260 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2261 << 2 << PlatformName << Obsoleted.getAsString()
2262 << 1 << Deprecated.getAsString();
2273 static bool versionsMatch(
const VersionTuple &
X,
const VersionTuple &Y,
2274 bool BeforeIsOkay) {
2275 if (
X.empty() || Y.empty())
2281 if (BeforeIsOkay &&
X < Y)
2289 VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted,
2290 bool IsUnavailable, StringRef Message,
bool IsStrict, StringRef Replacement,
2291 AvailabilityMergeKind AMK,
int Priority,
unsigned AttrSpellingListIndex) {
2292 VersionTuple MergedIntroduced = Introduced;
2293 VersionTuple MergedDeprecated = Deprecated;
2294 VersionTuple MergedObsoleted = Obsoleted;
2295 bool FoundAny =
false;
2296 bool OverrideOrImpl =
false;
2299 case AMK_Redeclaration:
2300 OverrideOrImpl =
false;
2304 case AMK_ProtocolImplementation:
2305 OverrideOrImpl =
true;
2311 for (
unsigned i = 0, e = Attrs.size();
i != e;) {
2312 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[
i]);
2319 if (OldPlatform != Platform) {
2327 if (OldAA->getPriority() < Priority)
2333 if (OldAA->getPriority() > Priority) {
2334 Attrs.erase(Attrs.begin() +
i);
2340 VersionTuple OldIntroduced = OldAA->getIntroduced();
2341 VersionTuple OldDeprecated = OldAA->getDeprecated();
2342 VersionTuple OldObsoleted = OldAA->getObsoleted();
2343 bool OldIsUnavailable = OldAA->getUnavailable();
2345 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2346 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2348 !(OldIsUnavailable == IsUnavailable ||
2349 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2350 if (OverrideOrImpl) {
2352 VersionTuple FirstVersion;
2353 VersionTuple SecondVersion;
2354 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2356 FirstVersion = OldIntroduced;
2357 SecondVersion = Introduced;
2358 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2360 FirstVersion = Deprecated;
2361 SecondVersion = OldDeprecated;
2362 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2364 FirstVersion = Obsoleted;
2365 SecondVersion = OldObsoleted;
2369 Diag(OldAA->getLocation(),
2370 diag::warn_mismatched_availability_override_unavail)
2371 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2372 << (AMK == AMK_Override);
2374 Diag(OldAA->getLocation(),
2375 diag::warn_mismatched_availability_override)
2377 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2378 << FirstVersion.getAsString() << SecondVersion.getAsString()
2379 << (AMK == AMK_Override);
2381 if (AMK == AMK_Override)
2386 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2390 Attrs.erase(Attrs.begin() +
i);
2395 VersionTuple MergedIntroduced2 = MergedIntroduced;
2396 VersionTuple MergedDeprecated2 = MergedDeprecated;
2397 VersionTuple MergedObsoleted2 = MergedObsoleted;
2399 if (MergedIntroduced2.empty())
2400 MergedIntroduced2 = OldIntroduced;
2401 if (MergedDeprecated2.empty())
2402 MergedDeprecated2 = OldDeprecated;
2403 if (MergedObsoleted2.empty())
2404 MergedObsoleted2 = OldObsoleted;
2406 if (checkAvailabilityAttr(*
this, OldAA->getRange(), Platform,
2407 MergedIntroduced2, MergedDeprecated2,
2408 MergedObsoleted2)) {
2409 Attrs.erase(Attrs.begin() +
i);
2414 MergedIntroduced = MergedIntroduced2;
2415 MergedDeprecated = MergedDeprecated2;
2416 MergedObsoleted = MergedObsoleted2;
2422 MergedIntroduced == Introduced &&
2423 MergedDeprecated == Deprecated &&
2424 MergedObsoleted == Obsoleted)
2429 if (!checkAvailabilityAttr(*
this, Range, Platform, MergedIntroduced,
2430 MergedDeprecated, MergedObsoleted) &&
2432 auto *Avail = ::new (Context)
2433 AvailabilityAttr(Range, Context, Platform, Introduced, Deprecated,
2434 Obsoleted, IsUnavailable, Message, IsStrict,
2435 Replacement, Priority, AttrSpellingListIndex);
2436 Avail->setImplicit(Implicit);
2449 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2450 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2463 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getMessageExpr()))
2464 Str = SE->getString();
2465 StringRef Replacement;
2467 Replacement = SE->getString();
2469 if (II->
isStr(
"swift")) {
2471 (!IsUnavailable && !Deprecated.
isValid())) {
2473 diag::warn_availability_swift_unavailable_deprecated_only);
2483 Deprecated.
Version, Obsoleted.
Version, IsUnavailable, Str, IsStrict,
2494 else if (II->
getName() ==
"ios_app_extension")
2498 auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
2499 if (Version.empty())
2501 auto Major = Version.getMajor();
2502 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2503 if (NewMajor >= 2) {
2504 if (Version.getMinor().hasValue()) {
2505 if (Version.getSubminor().hasValue())
2506 return VersionTuple(NewMajor, Version.getMinor().getValue(),
2507 Version.getSubminor().getValue());
2509 return VersionTuple(NewMajor, Version.getMinor().getValue());
2511 return VersionTuple(NewMajor);
2514 return VersionTuple(2, 0);
2517 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2518 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2519 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2522 ND, AL.
getRange(), NewII,
true , NewIntroduced,
2523 NewDeprecated, NewObsoleted, IsUnavailable, Str, IsStrict,
2535 else if (II->
getName() ==
"ios_app_extension")
2541 Deprecated.
Version, Obsoleted.
Version, IsUnavailable, Str, IsStrict,
2550 static void handleExternalSourceSymbolAttr(
Sema &S,
Decl *D,
2555 "Invalid number of arguments in an external_source_symbol attribute");
2558 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(0)))
2559 Language = SE->getString();
2560 StringRef DefinedIn;
2561 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(1)))
2562 DefinedIn = SE->getString();
2563 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2566 AL.
getRange(), S.
Context, Language, DefinedIn, IsGeneratedDeclaration,
2572 typename T::VisibilityType value,
2573 unsigned attrSpellingListIndex) {
2574 T *existingAttr = D->
getAttr<T>();
2576 typename T::VisibilityType existingValue = existingAttr->
getVisibility();
2577 if (existingValue == value)
2579 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2580 S.
Diag(range.
getBegin(), diag::note_previous_attribute);
2583 return ::new (S.
Context) T(range, S.
Context, value, attrSpellingListIndex);
2587 VisibilityAttr::VisibilityType Vis,
2588 unsigned AttrSpellingListIndex) {
2589 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, Range, Vis,
2590 AttrSpellingListIndex);
2594 TypeVisibilityAttr::VisibilityType Vis,
2595 unsigned AttrSpellingListIndex) {
2596 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, Range, Vis,
2597 AttrSpellingListIndex);
2601 bool isTypeVisibility) {
2603 if (isa<TypedefNameDecl>(D)) {
2609 if (isTypeVisibility &&
2610 !(isa<TagDecl>(D) ||
2611 isa<ObjCInterfaceDecl>(D) ||
2612 isa<NamespaceDecl>(D))) {
2624 VisibilityAttr::VisibilityType
type;
2625 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2626 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2633 if (type == VisibilityAttr::Protected &&
2635 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2641 if (isTypeVisibility) {
2643 (TypeVisibilityAttr::VisibilityType) type,
2653 const auto *M = cast<ObjCMethodDecl>(D);
2655 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2661 ObjCMethodFamilyAttr::FamilyKind F;
2662 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2663 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL << IL->
Ident;
2668 !M->getReturnType()->isObjCObjectPointerType()) {
2669 S.
Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2670 << M->getReturnType();
2680 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2681 QualType T = TD->getUnderlyingType();
2683 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2687 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2690 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
2709 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2710 QualType T = TD->getUnderlyingType();
2712 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2726 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2732 BlocksAttr::BlockType
type;
2733 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
2734 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
2744 unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
2747 llvm::APSInt Idx(32);
2750 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2755 if (Idx.isSigned() && Idx.isNegative()) {
2756 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2761 sentinel = Idx.getZExtValue();
2764 unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
2767 llvm::APSInt Idx(32);
2770 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2774 nullPos = Idx.getZExtValue();
2776 if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2779 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2785 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2787 if (isa<FunctionNoProtoType>(FT)) {
2788 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2792 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2793 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2796 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
2798 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2801 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
2802 if (!BD->isVariadic()) {
2803 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2806 }
else if (
const auto *
V = dyn_cast<VarDecl>(D)) {
2812 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2814 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2818 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2823 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2835 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2838 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
2840 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2848 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2860 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
2862 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
2864 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
2867 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2879 template <
typename WorkGroupAttr>
2882 for (
unsigned i = 0;
i < 3; ++
i) {
2887 if (WGSize[i] == 0) {
2888 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2894 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
2895 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2896 Existing->getYDim() == WGSize[1] &&
2897 Existing->getZDim() == WGSize[2]))
2898 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2901 WGSize[0], WGSize[1], WGSize[2],
2912 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2917 OpenCLIntelReqdSubGroupSizeAttr *Existing =
2918 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
2919 if (Existing && Existing->getSubGroupSize() != SGSize)
2920 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2929 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2935 assert(ParmTSI &&
"no type source info for attribute argument");
2940 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_vec_type_hint)
2945 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
2947 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2959 unsigned AttrSpellingListIndex) {
2962 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2963 if (AttrSpellingListIndex == SectionAttr::Declspec_allocate &&
2967 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
2968 if (ExistingAttr->getName() == Name)
2970 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2975 return ::new (Context) SectionAttr(Range, Context, Name,
2976 AttrSpellingListIndex);
2981 if (!Error.empty()) {
2982 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error
3002 if (!Error.empty()) {
3003 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3017 StringRef CodeSegName) {
3020 if (!Error.empty()) {
3021 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3031 unsigned AttrSpellingListIndex) {
3034 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3038 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3039 if (ExistingAttr->getName() == Name)
3041 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3046 return ::new (Context) CodeSegAttr(Range, Context, Name,
3047 AttrSpellingListIndex);
3055 if (!checkCodeSegName(S, LiteralLoc, Str))
3057 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3058 if (!ExistingAttr->isImplicit()) {
3060 ExistingAttr->getName() == Str
3061 ? diag::warn_duplicate_codeseg_attribute
3062 : diag::err_conflicting_codeseg_attribute);
3076 enum SecondParam { None, Architecture };
3077 for (
auto Str : {
"tune=",
"fpmath="})
3078 if (AttrStr.find(Str) != StringRef::npos)
3079 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3082 TargetAttr::ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr);
3084 if (!ParsedAttrs.Architecture.empty() &&
3086 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3087 <<
Unsupported << Architecture << ParsedAttrs.Architecture;
3089 if (ParsedAttrs.DuplicateArchitecture)
3090 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3091 << Duplicate << None <<
"arch=";
3093 for (
const auto &Feature : ParsedAttrs.Features) {
3094 auto CurFeature = StringRef(Feature).drop_front();
3096 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3111 TargetAttr *NewAttr =
3124 MinVectorWidthAttr *Existing = D->
getAttr<MinVectorWidthAttr>();
3125 if (Existing && Existing->getVectorWidth() != VecWidth) {
3126 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3143 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3144 if (DRE->hasQualifier())
3145 S.
Diag(Loc, diag::warn_cleanup_ext);
3147 NI = DRE->getNameInfo();
3149 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3153 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3154 if (ULE->hasExplicitTemplateArgs())
3155 S.
Diag(Loc, diag::warn_cleanup_ext);
3157 NI = ULE->getNameInfo();
3159 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3166 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3171 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3182 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3183 << NI.
getName() << ParamTy << Ty;
3192 static void handleEnumExtensibilityAttr(
Sema &S,
Decl *D,
3195 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3202 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3203 ExtensibilityKind)) {
3204 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3225 if (NotNSStringTy &&
3229 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3239 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3240 << (NotNSStringTy ?
"string type" :
"NSString")
3249 enum FormatAttrKind {
3260 static FormatAttrKind getFormatAttrKind(StringRef Format) {
3261 return llvm::StringSwitch<FormatAttrKind>(Format)
3263 .Case(
"NSString", NSStringFormat)
3264 .Case(
"CFString", CFStringFormat)
3265 .Case(
"strftime", StrftimeFormat)
3268 .Cases(
"scanf",
"printf",
"printf0",
"strfmon", SupportedFormat)
3269 .Cases(
"cmn_err",
"vcmn_err",
"zcmn_err", SupportedFormat)
3270 .Case(
"kprintf", SupportedFormat)
3271 .Case(
"freebsd_kprintf", SupportedFormat)
3272 .Case(
"os_trace", SupportedFormat)
3273 .Case(
"os_log", SupportedFormat)
3275 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag", IgnoredFormat)
3276 .Default(InvalidFormat);
3283 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3288 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3292 QualType T = cast<VarDecl>(D)->getType();
3296 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3302 uint32_t prioritynum;
3308 if (prioritynum < 101 || prioritynum > 65535) {
3309 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
3322 unsigned AttrSpellingListIndex) {
3325 if (F->getType() == Format &&
3326 F->getFormatIdx() == FormatIdx &&
3327 F->getFirstArg() == FirstArg) {
3330 if (F->getLocation().isInvalid())
3336 return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx,
3337 FirstArg, AttrSpellingListIndex);
3344 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3355 StringRef Format = II->
getName();
3357 if (normalizeName(Format)) {
3363 FormatAttrKind
Kind = getFormatAttrKind(Format);
3365 if (Kind == IgnoredFormat)
3368 if (Kind == InvalidFormat) {
3369 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3380 if (Idx < 1 || Idx > NumArgs) {
3381 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3387 unsigned ArgIdx = Idx - 1;
3389 if (HasImplicitThisParam) {
3392 diag::err_format_attribute_implicit_this_format_string)
3402 if (Kind == CFStringFormat) {
3404 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3409 }
else if (Kind == NSStringFormat) {
3413 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3420 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3433 if (FirstArg != 0) {
3437 S.
Diag(D->
getLocation(), diag::err_format_attribute_requires_variadic);
3444 if (Kind == StrftimeFormat) {
3445 if (FirstArg != 0) {
3446 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
3451 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
3452 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3468 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_no_callee)
3477 assert(FD &&
"Expected a function declaration!");
3479 llvm::StringMap<int> NameIdxMapping;
3480 NameIdxMapping[
"__"] = -1;
3482 NameIdxMapping[
"this"] = 0;
3486 NameIdxMapping[PVD->getName()] = Idx++;
3488 auto UnknownName = NameIdxMapping.end();
3491 for (
unsigned I = 0, E = AL.
getNumArgs(); I < E; ++I) {
3497 auto It = NameIdxMapping.find(IdLoc->
Ident->
getName());
3498 if (It == UnknownName) {
3499 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_argument_unknown)
3505 ArgIdx = It->second;
3512 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3518 if (ArgIdx < -1 || ArgIdx > NumArgs) {
3519 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3526 llvm_unreachable(
"Unexpected ParsedAttr argument type!");
3529 if (ArgIdx == 0 && !HasImplicitThisParam) {
3530 S.
Diag(AL.
getLoc(), diag::err_callback_implicit_this_not_available)
3537 if (!HasImplicitThisParam && ArgIdx > 0)
3540 EncodingIndices.push_back(ArgIdx);
3543 int CalleeIdx = EncodingIndices.front();
3547 if (CalleeIdx < (
int)HasImplicitThisParam) {
3548 S.
Diag(AL.
getLoc(), diag::err_callback_attribute_invalid_callee)
3555 const Type *CalleeType =
3559 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3564 const Type *CalleeFnType =
3570 if (!CalleeFnProtoType) {
3571 S.
Diag(AL.
getLoc(), diag::err_callback_callee_no_function_type)
3576 if (CalleeFnProtoType->getNumParams() > EncodingIndices.size() - 1) {
3577 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3578 << AL << (
unsigned)(EncodingIndices.size() - 1);
3582 if (CalleeFnProtoType->getNumParams() < EncodingIndices.size() - 1) {
3583 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments)
3584 << AL << (
unsigned)(EncodingIndices.size() - 1);
3588 if (CalleeFnProtoType->isVariadic()) {
3594 if (D->
hasAttr<CallbackAttr>()) {
3600 AL.
getRange(), S.
Context, EncodingIndices.data(), EncodingIndices.size(),
3608 if (TD && TD->getUnderlyingType()->isUnionType())
3609 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
3614 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type) << AL
3622 diag::warn_transparent_union_attribute_not_definition);
3628 if (Field == FieldEnd) {
3629 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3637 diag::warn_transparent_union_attribute_floating)
3646 for (; Field != FieldEnd; ++Field) {
3647 QualType FieldType = Field->getType();
3661 S.
Diag(Field->getLocation(),
3662 diag::warn_transparent_union_attribute_field_size_align)
3663 << isSize << Field->getDeclName() << FieldBits;
3664 unsigned FirstBits = isSize? FirstSize : FirstAlign;
3666 diag::note_transparent_union_first_field_size_align)
3667 << isSize << FirstBits;
3686 if (I->getAnnotation() == Str)
3701 unsigned SpellingListIndex) {
3702 AlignValueAttr TmpAttr(AttrRange, Context, E, SpellingListIndex);
3706 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
3707 T = TD->getUnderlyingType();
3708 else if (
const auto *VD = dyn_cast<ValueDecl>(D))
3711 llvm_unreachable(
"Unknown decl type for align_value");
3715 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
3721 llvm::APSInt Alignment;
3723 = VerifyIntegerConstantExpression(E, &Alignment,
3724 diag::err_align_value_attribute_argument_not_int,
3729 if (!Alignment.isPowerOf2()) {
3730 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3736 AlignValueAttr(AttrRange, Context, ICE.
get(),
3737 SpellingListIndex));
3742 D->
addAttr(::
new (Context) AlignValueAttr(TmpAttr));
3748 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3761 diag::err_pack_expansion_without_parameter_packs);
3773 unsigned SpellingListIndex,
bool IsPackExpansion) {
3774 AlignedAttr TmpAttr(AttrRange, Context,
true, E, SpellingListIndex);
3778 if (TmpAttr.isAlignas()) {
3791 if (isa<ParmVarDecl>(D)) {
3793 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
3796 if (VD->isExceptionVariable())
3798 }
else if (
const auto *FD = dyn_cast<FieldDecl>(D)) {
3799 if (FD->isBitField())
3801 }
else if (!isa<TagDecl>(D)) {
3802 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
3807 if (DiagKind != -1) {
3808 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
3809 << &TmpAttr << DiagKind;
3818 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
3819 if (!TND->getUnderlyingType()->isDependentType()) {
3820 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
3827 AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr);
3828 AA->setPackExpansion(IsPackExpansion);
3834 llvm::APSInt Alignment;
3836 = VerifyIntegerConstantExpression(E, &Alignment,
3837 diag::err_aligned_attribute_argument_not_int,
3842 uint64_t AlignVal = Alignment.getZExtValue();
3849 if (!(TmpAttr.isAlignas() && !Alignment)) {
3850 if (!llvm::isPowerOf2_64(AlignVal)) {
3851 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3858 unsigned MaxValidAlignment =
3861 if (AlignVal > MaxValidAlignment) {
3862 Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
3868 unsigned MaxTLSAlign =
3871 const auto *VD = dyn_cast<
VarDecl>(D);
3872 if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
3874 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
3875 << (
unsigned)AlignVal << VD << MaxTLSAlign;
3880 AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context,
true,
3881 ICE.
get(), SpellingListIndex);
3882 AA->setPackExpansion(IsPackExpansion);
3887 unsigned SpellingListIndex,
bool IsPackExpansion) {
3890 AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context,
false, TS,
3892 AA->setPackExpansion(IsPackExpansion);
3897 assert(D->
hasAttrs() &&
"no attributes on decl");
3900 if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
3901 UnderlyingTy = DiagTy = VD->getType();
3903 UnderlyingTy = DiagTy = Context.
getTagDeclType(cast<TagDecl>(D));
3904 if (
const auto *ED = dyn_cast<EnumDecl>(D))
3905 UnderlyingTy = ED->getIntegerType();
3907 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
3914 AlignedAttr *AlignasAttr =
nullptr;
3917 if (I->isAlignmentDependent())
3921 Align =
std::max(Align, I->getAlignment(Context));
3924 if (AlignasAttr && Align) {
3927 if (NaturalAlign > RequestedAlign)
3928 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
3929 << DiagTy << (
unsigned)NaturalAlign.
getQuantity();
3935 MSInheritanceAttr::Spelling SemanticSpelling) {
3944 if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance)
3955 Diag(Range.
getBegin(), diag::err_mismatched_ms_inheritance)
3964 static void parseModeAttrArg(
Sema &S, StringRef Str,
unsigned &DestWidth,
3965 bool &IntegerMode,
bool &ComplexMode) {
3967 ComplexMode =
false;
3968 switch (Str.size()) {
3990 if (Str[1] ==
'F') {
3991 IntegerMode =
false;
3992 }
else if (Str[1] ==
'C') {
3993 IntegerMode =
false;
3995 }
else if (Str[1] !=
'I') {
4004 else if (Str ==
"byte")
4008 if (Str ==
"pointer")
4012 if (Str ==
"unwind_word")
4028 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
4039 unsigned SpellingListIndex,
bool InInstantiation) {
4040 StringRef Str = Name->
getName();
4044 unsigned DestWidth = 0;
4045 bool IntegerMode =
true;
4046 bool ComplexMode =
false;
4047 llvm::APInt VectorSize(64, 0);
4048 if (Str.size() >= 4 && Str[0] ==
'V') {
4050 size_t StrSize = Str.size();
4051 size_t VectorStringLength = 0;
4052 while ((VectorStringLength + 1) < StrSize &&
4053 isdigit(Str[VectorStringLength + 1]))
4054 ++VectorStringLength;
4055 if (VectorStringLength &&
4056 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
4057 VectorSize.isPowerOf2()) {
4058 parseModeAttrArg(*
this, Str.substr(VectorStringLength + 1), DestWidth,
4059 IntegerMode, ComplexMode);
4061 if (!InInstantiation)
4062 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
4069 parseModeAttrArg(*
this, Str, DestWidth, IntegerMode, ComplexMode);
4076 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
4081 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
4082 OldTy = TD->getUnderlyingType();
4083 else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
4086 OldTy = ED->getIntegerType();
4088 OldTy = Context.
IntTy;
4090 OldTy = cast<ValueDecl>(D)->getType();
4094 ModeAttr(AttrRange, Context, Name, SpellingListIndex));
4102 OldElemTy = VT->getElementType();
4108 VectorSize.getBoolValue()) {
4109 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << AttrRange;
4112 bool IntegralOrAnyEnumType =
4116 !IntegralOrAnyEnumType)
4117 Diag(AttrLoc, diag::err_mode_not_primitive);
4118 else if (IntegerMode) {
4119 if (!IntegralOrAnyEnumType)
4120 Diag(AttrLoc, diag::err_mode_wrong_type);
4121 }
else if (ComplexMode) {
4123 Diag(AttrLoc, diag::err_mode_wrong_type);
4126 Diag(AttrLoc, diag::err_mode_wrong_type);
4137 if (NewElemTy.
isNull()) {
4138 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4147 if (VectorSize.getBoolValue()) {
4148 NewTy = Context.
getVectorType(NewTy, VectorSize.getZExtValue(),
4153 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4156 unsigned NumElements = Context.
getTypeSize(OldElemTy) *
4157 OldVT->getNumElements() /
4160 Context.
getVectorType(NewElemTy, NumElements, OldVT->getVectorKind());
4164 Diag(AttrLoc, diag::err_mode_wrong_type);
4169 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
4170 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4171 else if (
auto *ED = dyn_cast<EnumDecl>(D))
4172 ED->setIntegerType(NewTy);
4174 cast<ValueDecl>(D)->setType(NewTy);
4177 ModeAttr(AttrRange, Context, Name, SpellingListIndex));
4188 unsigned AttrSpellingListIndex) {
4189 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4190 Diag(Range.
getBegin(), diag::warn_attribute_ignored) << Ident;
4191 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4195 if (D->
hasAttr<AlwaysInlineAttr>())
4198 return ::new (Context) AlwaysInlineAttr(Range, Context,
4199 AttrSpellingListIndex);
4203 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4206 return ::new (Context)
4211 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4214 return ::new (Context)
4215 CommonAttr(AL.getRange(), Context, AL.getSpellingListIndex());
4220 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4223 if (VD->getKind() != Decl::Var) {
4224 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4230 if (VD->hasLocalStorage()) {
4231 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4236 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4239 return ::new (Context) InternalLinkageAttr(
4242 InternalLinkageAttr *
4244 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4247 if (VD->getKind() != Decl::Var) {
4248 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4254 if (VD->hasLocalStorage()) {
4255 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4260 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4263 return ::new (Context)
4264 InternalLinkageAttr(AL.getRange(), Context, AL.getSpellingListIndex());
4268 unsigned AttrSpellingListIndex) {
4269 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4270 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'minsize'";
4271 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4275 if (D->
hasAttr<MinSizeAttr>())
4278 return ::new (Context) MinSizeAttr(Range, Context, AttrSpellingListIndex);
4282 Decl *D,
const NoSpeculativeLoadHardeningAttr &AL) {
4283 if (checkAttrMutualExclusion<SpeculativeLoadHardeningAttr>(*
this, D, AL))
4286 return ::new (Context) NoSpeculativeLoadHardeningAttr(
4287 AL.getRange(), Context, AL.getSpellingListIndex());
4291 unsigned AttrSpellingListIndex) {
4292 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4293 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4294 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4297 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4298 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4299 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4303 if (D->
hasAttr<OptimizeNoneAttr>())
4306 return ::new (Context) OptimizeNoneAttr(Range, Context,
4307 AttrSpellingListIndex);
4311 Decl *D,
const SpeculativeLoadHardeningAttr &AL) {
4312 if (checkAttrMutualExclusion<NoSpeculativeLoadHardeningAttr>(*
this, D, AL))
4315 return ::new (Context) SpeculativeLoadHardeningAttr(
4316 AL.getRange(), Context, AL.getSpellingListIndex());
4320 if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL))
4342 if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL))
4344 const auto *VD = cast<VarDecl>(D);
4345 if (!VD->hasGlobalStorage()) {
4346 S.
Diag(AL.
getLoc(), diag::err_cuda_nonglobal_constant);
4354 if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL))
4356 const auto *VD = cast<VarDecl>(D);
4359 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4360 !isa<IncompleteArrayType>(VD->getType())) {
4361 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4364 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4373 if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL) ||
4374 checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL)) {
4377 const auto *FD = cast<FunctionDecl>(D);
4386 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4387 if (Method->isInstance()) {
4388 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4392 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4404 const auto *Fn = cast<FunctionDecl>(D);
4405 if (!Fn->isInlineSpecified()) {
4406 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4424 if (!isa<ObjCMethodDecl>(D)) {
4425 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4431 case ParsedAttr::AT_FastCall:
4436 case ParsedAttr::AT_StdCall:
4441 case ParsedAttr::AT_ThisCall:
4446 case ParsedAttr::AT_CDecl:
4451 case ParsedAttr::AT_Pascal:
4456 case ParsedAttr::AT_SwiftCall:
4461 case ParsedAttr::AT_VectorCall:
4466 case ParsedAttr::AT_MSABI:
4471 case ParsedAttr::AT_SysVABI:
4476 case ParsedAttr::AT_RegCall:
4480 case ParsedAttr::AT_Pcs: {
4481 PcsAttr::PCSType PCS;
4484 PCS = PcsAttr::AAPCS;
4487 PCS = PcsAttr::AAPCS_VFP;
4490 llvm_unreachable(
"unexpected calling convention in pcs attribute");
4498 case ParsedAttr::AT_AArch64VectorPcs:
4503 case ParsedAttr::AT_IntelOclBicc:
4508 case ParsedAttr::AT_PreserveMost:
4512 case ParsedAttr::AT_PreserveAll:
4517 llvm_unreachable(
"unexpected attribute kind");
4525 std::vector<StringRef> DiagnosticIdentifiers;
4526 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
4534 DiagnosticIdentifiers.push_back(RuleName);
4551 unsigned ReqArgs = Attrs.
getKind() == ParsedAttr::AT_Pcs ? 1 : 0;
4559 case ParsedAttr::AT_CDecl:
4562 case ParsedAttr::AT_FastCall:
4565 case ParsedAttr::AT_StdCall:
4568 case ParsedAttr::AT_ThisCall:
4571 case ParsedAttr::AT_Pascal:
4574 case ParsedAttr::AT_SwiftCall:
4577 case ParsedAttr::AT_VectorCall:
4580 case ParsedAttr::AT_AArch64VectorPcs:
4583 case ParsedAttr::AT_RegCall:
4586 case ParsedAttr::AT_MSABI:
4590 case ParsedAttr::AT_SysVABI:
4594 case ParsedAttr::AT_Pcs: {
4596 if (!checkStringLiteralArgumentAttr(Attrs, 0, StrRef)) {
4600 if (StrRef ==
"aapcs") {
4603 }
else if (StrRef ==
"aapcs-vfp") {
4612 case ParsedAttr::AT_IntelOclBicc:
4615 case ParsedAttr::AT_PreserveMost:
4618 case ParsedAttr::AT_PreserveAll:
4621 default: llvm_unreachable(
"unexpected attribute kind");
4630 if (LangOpts.CUDA) {
4632 auto CudaTarget = IdentifyCUDATarget(FD);
4633 bool CheckHost =
false, CheckDevice =
false;
4634 switch (CudaTarget) {
4635 case CFT_HostDevice:
4646 case CFT_InvalidTarget:
4647 llvm_unreachable(
"unexpected cuda target");
4649 auto *HostTI = LangOpts.CUDAIsDevice ? Aux : &TI;
4650 auto *DeviceTI = LangOpts.CUDAIsDevice ? &TI : Aux;
4651 if (CheckHost && HostTI)
4654 A = DeviceTI->checkCallingConvention(CC);
4672 Diag(Attrs.
getLoc(), diag::warn_cconv_unsupported)
4673 << Attrs << (
int)CallingConventionIgnoredReason::ForThisTarget;
4677 bool IsCXXMethod =
false, IsVariadic =
false;
4692 static bool isValidSwiftContextType(
QualType Ty) {
4699 static bool isValidSwiftIndirectResultType(
QualType Ty) {
4711 static bool isValidSwiftErrorResultType(
QualType Ty) {
4721 return isValidSwiftContextType(Ty);
4731 unsigned spellingIndex) {
4736 if (existingAttr->getABI() != abi) {
4737 Diag(range.
getBegin(), diag::err_attributes_are_not_compatible)
4739 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute);
4746 llvm_unreachable(
"explicit attribute for ordinary parameter ABI?");
4749 if (!isValidSwiftContextType(type)) {
4750 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4755 SwiftContextAttr(range, Context, spellingIndex));
4759 if (!isValidSwiftErrorResultType(type)) {
4760 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4765 SwiftErrorResultAttr(range, Context, spellingIndex));
4769 if (!isValidSwiftIndirectResultType(type)) {
4770 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4775 SwiftIndirectResultAttr(range, Context, spellingIndex));
4778 llvm_unreachable(
"bad parameter ABI attribute");
4800 Diag(AL.
getLoc(), diag::err_attribute_regparm_wrong_platform)
4808 Diag(AL.
getLoc(), diag::err_attribute_regparm_invalid_number)
4822 const CUDALaunchBoundsAttr &AL,
4823 const unsigned Idx) {
4839 if (!I.isIntN(32)) {
4840 S.
Diag(E->
getExprLoc(), diag::err_ice_too_large) << I.toString(10,
false)
4845 S.
Diag(E->
getExprLoc(), diag::warn_attribute_argument_n_negative)
4852 assert(!ValArg.isInvalid() &&
4853 "Unexpected PerformCopyInitialization() failure.");
4859 Expr *MinBlocks,
unsigned SpellingListIndex) {
4860 CUDALaunchBoundsAttr TmpAttr(AttrRange, Context, MaxThreads, MinBlocks,
4862 MaxThreads = makeLaunchBoundsArgExpr(*
this, MaxThreads, TmpAttr, 0);
4863 if (MaxThreads ==
nullptr)
4867 MinBlocks = makeLaunchBoundsArgExpr(*
this, MinBlocks, TmpAttr, 1);
4868 if (MinBlocks ==
nullptr)
4872 D->
addAttr(::
new (Context) CUDALaunchBoundsAttr(
4873 AttrRange, Context, MaxThreads, MinBlocks, SpellingListIndex));
4886 static void handleArgumentWithTypeTagAttr(
Sema &S,
Decl *D,
4889 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4904 bool IsPointer = AL.
getName()->
getName() ==
"pointer_with_type_tag";
4907 unsigned ArgumentIdxAST = ArgumentIdx.
getASTIndex();
4910 S.
Diag(AL.
getLoc(), diag::err_attribute_pointers_only) << AL << 0;
4918 static void handleTypeTagForDatatypeAttr(
Sema &S,
Decl *D,
4921 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4929 if (!isa<VarDecl>(D)) {
4930 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_decl_type)
4938 assert(MatchingCTypeLoc &&
"no type source info for attribute argument");
4965 static bool isValidSubjectOfNSReturnsRetainedAttribute(
QualType QT) {
4969 static bool isValidSubjectOfNSAttribute(
QualType QT) {
4974 static bool isValidSubjectOfCFAttribute(
QualType QT) {
4976 isValidSubjectOfNSAttribute(QT);
4979 static bool isValidSubjectOfOSAttribute(
QualType QT) {
4987 RetainOwnershipKind K,
4988 bool IsTemplateInstantiation) {
4991 case RetainOwnershipKind::OS:
4992 handleSimpleAttributeOrDiagnose<OSConsumedAttr>(
4993 *
this, VD, SR, SpellingIndex, isValidSubjectOfOSAttribute(VD->getType()),
4994 diag::warn_ns_attribute_wrong_parameter_type,
4995 SR,
"os_consumed", 1);
4997 case RetainOwnershipKind::NS:
4998 handleSimpleAttributeOrDiagnose<NSConsumedAttr>(
4999 *
this, VD, SR, SpellingIndex, isValidSubjectOfNSAttribute(VD->getType()),
5005 ((IsTemplateInstantiation && getLangOpts().ObjCAutoRefCount)
5006 ? diag::err_ns_attribute_wrong_parameter_type
5007 : diag::warn_ns_attribute_wrong_parameter_type),
5008 SR,
"ns_consumed", 0);
5010 case RetainOwnershipKind::CF:
5011 handleSimpleAttributeOrDiagnose<CFConsumedAttr>(
5012 *
this, VD, SR, SpellingIndex,
5013 isValidSubjectOfCFAttribute(VD->getType()),
5014 diag::warn_ns_attribute_wrong_parameter_type,
5015 SR,
"cf_consumed", 1);
5021 parsedAttrToRetainOwnershipKind(
const ParsedAttr &AL) {
5023 case ParsedAttr::AT_CFConsumed:
5024 case ParsedAttr::AT_CFReturnsRetained:
5025 case ParsedAttr::AT_CFReturnsNotRetained:
5027 case ParsedAttr::AT_OSConsumesThis:
5028 case ParsedAttr::AT_OSConsumed:
5029 case ParsedAttr::AT_OSReturnsRetained:
5030 case ParsedAttr::AT_OSReturnsNotRetained:
5031 case ParsedAttr::AT_OSReturnsRetainedOnZero:
5032 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
5034 case ParsedAttr::AT_NSConsumesSelf:
5035 case ParsedAttr::AT_NSConsumed:
5036 case ParsedAttr::AT_NSReturnsRetained:
5037 case ParsedAttr::AT_NSReturnsNotRetained:
5038 case ParsedAttr::AT_NSReturnsAutoreleased:
5041 llvm_unreachable(
"Wrong argument supplied");
5046 if (isValidSubjectOfNSReturnsRetainedAttribute(QT))
5049 Diag(Loc, diag::warn_ns_attribute_wrong_return_type)
5050 <<
"'ns_returns_retained'" << 0 << 0;
5055 static bool isValidOSObjectOutParameter(
const Decl *D) {
5061 return !PT.
isNull() && isValidSubjectOfOSAttribute(PT);
5064 static void handleXReturnsXRetainedAttr(
Sema &S,
Decl *D,
5069 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
5072 (AL.
getKind() == ParsedAttr::AT_NSReturnsRetained)) {
5074 }
else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
5075 ReturnType = PD->getType();
5076 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5078 }
else if (
const auto *Param = dyn_cast<ParmVarDecl>(D)) {
5085 if (ReturnType.
isNull()) {
5086 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
5095 default: llvm_unreachable(
"invalid ownership attribute");
5096 case ParsedAttr::AT_NSReturnsRetained:
5097 case ParsedAttr::AT_NSReturnsAutoreleased:
5098 case ParsedAttr::AT_NSReturnsNotRetained:
5102 case ParsedAttr::AT_OSReturnsRetained:
5103 case ParsedAttr::AT_OSReturnsNotRetained:
5104 case ParsedAttr::AT_CFReturnsRetained:
5105 case ParsedAttr::AT_CFReturnsNotRetained:
5110 << AL.
getRange() << AL << ExpectedDeclKind;
5116 unsigned ParmDiagID = 2;
5118 default: llvm_unreachable(
"invalid ownership attribute");
5119 case ParsedAttr::AT_NSReturnsRetained:
5120 TypeOK = isValidSubjectOfNSReturnsRetainedAttribute(ReturnType);
5124 case ParsedAttr::AT_NSReturnsAutoreleased:
5125 case ParsedAttr::AT_NSReturnsNotRetained:
5126 TypeOK = isValidSubjectOfNSAttribute(ReturnType);
5130 case ParsedAttr::AT_CFReturnsRetained:
5131 case ParsedAttr::AT_CFReturnsNotRetained:
5132 TypeOK = isValidSubjectOfCFAttribute(ReturnType);
5136 case ParsedAttr::AT_OSReturnsRetained:
5137 case ParsedAttr::AT_OSReturnsNotRetained:
5138 TypeOK = isValidSubjectOfOSAttribute(ReturnType);
5148 if (isa<ParmVarDecl>(D)) {
5149 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
5150 << AL << ParmDiagID << AL.
getRange();
5157 } SubjectKind = Function;
5158 if (isa<ObjCMethodDecl>(D))
5159 SubjectKind = Method;
5160 else if (isa<ObjCPropertyDecl>(D))
5163 << AL << SubjectKind << Cf << AL.
getRange();
5170 llvm_unreachable(
"invalid ownership attribute");
5171 case ParsedAttr::AT_NSReturnsAutoreleased:
5172 handleSimpleAttribute<NSReturnsAutoreleasedAttr>(S, D, AL);
5174 case ParsedAttr::AT_CFReturnsNotRetained:
5175 handleSimpleAttribute<CFReturnsNotRetainedAttr>(S, D, AL);
5177 case ParsedAttr::AT_NSReturnsNotRetained:
5178 handleSimpleAttribute<NSReturnsNotRetainedAttr>(S, D, AL);
5180 case ParsedAttr::AT_CFReturnsRetained:
5181 handleSimpleAttribute<CFReturnsRetainedAttr>(S, D, AL);
5183 case ParsedAttr::AT_NSReturnsRetained:
5184 handleSimpleAttribute<NSReturnsRetainedAttr>(S, D, AL);
5186 case ParsedAttr::AT_OSReturnsRetained:
5187 handleSimpleAttribute<OSReturnsRetainedAttr>(S, D, AL);
5189 case ParsedAttr::AT_OSReturnsNotRetained:
5190 handleSimpleAttribute<OSReturnsNotRetainedAttr>(S, D, AL);
5195 static void handleObjCReturnsInnerPointerAttr(
Sema &S,
Decl *D,
5197 const int EP_ObjCMethod = 1;
5198 const int EP_ObjCProperty = 2;
5202 if (isa<ObjCMethodDecl>(D))
5203 resultType = cast<ObjCMethodDecl>(D)->getReturnType();
5205 resultType = cast<ObjCPropertyDecl>(D)->getType();
5211 << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
5222 static void handleObjCRequiresSuperAttr(
Sema &S,
Decl *D,
5224 const auto *Method = cast<ObjCMethodDecl>(D);
5227 if (
const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
5228 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5230 S.
Diag(PDecl->getLocation(), diag::note_protocol_decl);
5234 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5252 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
5254 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_id) << AL;
5259 QualType T = TD->getUnderlyingType();
5261 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_void_pointer);
5271 static void handleObjCBridgeMutableAttr(
Sema &S,
Decl *D,
5285 static void handleObjCBridgeRelatedAttr(
Sema &S,
Decl *D,
5289 if (!RelatedClass) {
5299 ClassMethod, InstanceMethod,
5303 static void handleObjCDesignatedInitializer(
Sema &S,
Decl *D,
5309 if (!isa<ObjCInterfaceDecl>(Ctx) &&
5310 !(isa<ObjCCategoryDecl>(Ctx) &&
5311 cast<ObjCCategoryDecl>(Ctx)->IsClassExtension())) {
5317 if (
auto *CatDecl = dyn_cast<ObjCCategoryDecl>(Ctx))
5318 IFace = CatDecl->getClassInterface();
5320 IFace = cast<ObjCInterfaceDecl>(Ctx);
5332 StringRef MetaDataName;
5346 bool notify =
false;
5355 ObjCBoxableAttr *BoxableAttr = ::new (S.
Context)
5363 L->AddedAttributeToRecord(BoxableAttr, RD);
5375 static void handleObjCPreciseLifetimeAttr(
Sema &S,
Decl *D,
5377 const auto *VD = cast<ValueDecl>(D);
5380 if (!QT->isDependentType() &&
5381 !QT->isObjCLifetimeType()) {
5382 S.
Diag(AL.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
5392 Lifetime = QT->getObjCARCImplicitLifetime();
5396 assert(QT->isDependentType() &&
5397 "didn't infer lifetime for non-dependent type?");
5406 S.
Diag(AL.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
5421 unsigned AttrSpellingListIndex, StringRef Uuid) {
5422 if (
const auto *UA = D->
getAttr<UuidAttr>()) {
5423 if (UA->getGuid().equals_lower(Uuid))
5425 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5430 return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex);
5435 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5447 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
5448 StrRef = StrRef.drop_front().drop_back();
5451 if (StrRef.size() != 36) {
5452 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5456 for (
unsigned i = 0;
i < 36; ++
i) {
5457 if (
i == 8 ||
i == 13 ||
i == 18 ||
i == 23) {
5458 if (StrRef[
i] !=
'-') {
5459 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5463 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5475 S.
Diag(AL.
getLoc(), diag::warn_atl_uuid_deprecated);
5485 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5500 const auto *VD = cast<VarDecl>(D);
5502 S.
Diag(AL.
getLoc(), diag::err_thread_unsupported);
5506 S.
Diag(AL.
getLoc(), diag::err_declspec_thread_on_thread_variable);
5509 if (VD->hasLocalStorage()) {
5510 S.
Diag(AL.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
5519 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
5523 Tags.push_back(Tag);
5526 if (
const auto *NS = dyn_cast<NamespaceDecl>(D)) {
5527 if (!NS->isInline()) {
5528 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5531 if (NS->isAnonymousNamespace()) {
5532 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5536 Tags.push_back(NS->getName());
5542 Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
5552 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5564 ARMInterruptAttr::InterruptType
Kind;
5565 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5566 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5602 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5608 llvm::APSInt NumParams(32);
5610 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5616 unsigned Num = NumParams.getLimitedValue(255);
5618 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5619 << AL << (
int)NumParams.getSExtValue()
5633 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5672 if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL))
5675 MipsInterruptAttr::InterruptType
Kind;
5676 if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5677 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
5678 << AL <<
"'" + std::string(Str) +
"'";
5695 cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
5696 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5703 diag::err_anyx86_interrupt_attribute)
5712 if (NumParams < 1 || NumParams > 2) {
5723 diag::err_anyx86_interrupt_attribute)
5735 if (NumParams == 2 &&
5739 diag::err_anyx86_interrupt_attribute)
5761 handleSimpleAttribute<AVRInterruptAttr>(S, D, AL);
5774 handleSimpleAttribute<AVRSignalAttr>(S, D, AL);
5777 static void handleWebAssemblyImportModuleAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5784 auto *FD = cast<FunctionDecl>(D);
5800 static void handleWebAssemblyImportNameAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5807 auto *FD = cast<FunctionDecl>(D);
5823 static void handleRISCVInterruptAttr(
Sema &S,
Decl *D,
5826 if (
const auto *A = D->
getAttr<RISCVInterruptAttr>()) {
5828 diag::warn_riscv_repeated_interrupt_attribute);
5829 S.
Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute);
5871 RISCVInterruptAttr::InterruptType
Kind;
5872 if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5873 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5885 case llvm::Triple::msp430:
5886 handleMSP430InterruptAttr(S, D, AL);
5888 case llvm::Triple::mipsel:
5889 case llvm::Triple::mips:
5890 handleMipsInterruptAttr(S, D, AL);
5892 case llvm::Triple::x86:
5893 case llvm::Triple::x86_64:
5894 handleAnyX86InterruptAttr(S, D, AL);
5896 case llvm::Triple::avr:
5897 handleAVRInterruptAttr(S, D, AL);
5899 case llvm::Triple::riscv32:
5900 case llvm::Triple::riscv64:
5901 handleRISCVInterruptAttr(S, D, AL);
5904 handleARMInterruptAttr(S, D, AL);
5910 checkAMDGPUFlatWorkGroupSizeArguments(
Sema &S,
Expr *MinExpr,
Expr *MaxExpr,
5911 const AMDGPUFlatWorkGroupSizeAttr &
Attr) {
5925 if (Min == 0 && Max != 0) {
5926 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5931 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5941 unsigned SpellingListIndex) {
5942 AMDGPUFlatWorkGroupSizeAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr,
5945 if (checkAMDGPUFlatWorkGroupSizeArguments(*
this, MinExpr, MaxExpr, TmpAttr))
5948 D->
addAttr(::
new (Context) AMDGPUFlatWorkGroupSizeAttr(
5949 AttrRange, Context, MinExpr, MaxExpr, SpellingListIndex));
5952 static void handleAMDGPUFlatWorkGroupSizeAttr(
Sema &S,
Decl *D,
5961 static bool checkAMDGPUWavesPerEUArguments(
Sema &S,
Expr *MinExpr,
5963 const AMDGPUWavesPerEUAttr &
Attr) {
5981 if (Min == 0 && Max != 0) {
5982 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5986 if (Max != 0 && Min > Max) {
5987 S.
Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
5997 unsigned SpellingListIndex) {
5998 AMDGPUWavesPerEUAttr TmpAttr(AttrRange, Context, MinExpr, MaxExpr,
6001 if (checkAMDGPUWavesPerEUArguments(*
this, MinExpr, MaxExpr, TmpAttr))
6004 D->
addAttr(::
new (Context) AMDGPUWavesPerEUAttr(AttrRange, Context, MinExpr,
6005 MaxExpr, SpellingListIndex));
6021 uint32_t NumSGPR = 0;
6032 uint32_t NumVGPR = 0;
6042 static void handleX86ForceAlignArgPointerAttr(
Sema &S,
Decl *D,
6047 const auto *VD = dyn_cast<
ValueDecl>(D);
6048 if (VD && VD->getType()->isFunctionPointerType())
6052 if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
6053 TD->getUnderlyingType()->isFunctionType()))
6056 if (!isa<FunctionDecl>(D)) {
6057 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
6075 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
6091 unsigned AttrSpellingListIndex) {
6092 if (D->
hasAttr<DLLExportAttr>()) {
6093 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'dllimport'";
6097 if (D->
hasAttr<DLLImportAttr>())
6100 return ::new (Context) DLLImportAttr(Range, Context, AttrSpellingListIndex);
6104 unsigned AttrSpellingListIndex) {
6105 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
6106 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
6110 if (D->
hasAttr<DLLExportAttr>())
6113 return ::new (Context) DLLExportAttr(Range, Context, AttrSpellingListIndex);
6117 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
6123 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
6133 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
6142 Attr *NewAttr = A.
getKind() == ParsedAttr::AT_DLLExport
6151 unsigned AttrSpellingListIndex,
6152 MSInheritanceAttr::Spelling SemanticSpelling) {
6153 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
6154 if (IA->getSemanticSpelling() == SemanticSpelling)
6156 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
6158 Diag(Range.
getBegin(), diag::note_previous_ms_inheritance);
6162 auto *RD = cast<CXXRecordDecl>(D);
6163 if (RD->hasDefinition()) {
6164 if (checkMSInheritanceAttrOnDefinition(RD, Range, BestCase,
6165 SemanticSpelling)) {
6169 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
6170 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
6174 if (RD->getDescribedClassTemplate()) {
6175 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
6181 return ::new (Context)
6182 MSInheritanceAttr(Range, Context, BestCase, AttrSpellingListIndex);
6194 StringRef N(
"mutex");
6196 if (AL.
getKind() == ParsedAttr::AT_Capability &&
6202 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
6203 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
6211 if (!checkLockFunAttrCommon(S, D, AL, Args))
6215 Args.data(), Args.size(),
6219 static void handleAcquireCapabilityAttr(
Sema &S,
Decl *D,
6222 if (!checkLockFunAttrCommon(S, D, AL, Args))
6227 Args.data(), Args.size(),
6231 static void handleTryAcquireCapabilityAttr(
Sema &S,
Decl *D,
6234 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
6245 static void handleReleaseCapabilityAttr(
Sema &S,
Decl *D,
6249 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
6256 static void handleRequiresCapabilityAttr(
Sema &S,
Decl *D,
6263 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
6267 RequiresCapabilityAttr *RCA = ::new (S.
Context)
6275 if (
const auto *NSD = dyn_cast<NamespaceDecl>(D)) {
6276 if (NSD->isAnonymousNamespace()) {
6277 S.
Diag(AL.
getLoc(), diag::warn_deprecated_anonymous_namespace);
6286 StringRef Str, Replacement;
6299 S.
Diag(AL.
getLoc(), diag::ext_cxx14_attr) << AL;
6307 if (
const auto *S = dyn_cast<VarDecl>(D))
6308 return S->hasGlobalStorage();
6316 std::vector<StringRef> Sanitizers;
6318 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
6319 StringRef SanitizerName;
6327 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
6328 else if (
isGlobalVar(D) && SanitizerName !=
"address")
6331 Sanitizers.push_back(SanitizerName);
6339 static void handleNoSanitizeSpecificAttr(
Sema &S,
Decl *D,
6342 normalizeName(AttrName);
6343 StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName)
6344 .Case(
"no_address_safety_analysis",
"address")
6345 .Case(
"no_sanitize_address",
"address")
6346 .Case(
"no_sanitize_thread",
"thread")
6347 .Case(
"no_sanitize_memory",
"memory");
6360 unsigned TranslatedSpellingIndex = 0;
6362 TranslatedSpellingIndex = 1;
6365 AL.
getRange(), S.
Context, &SanitizerName, 1, TranslatedSpellingIndex));
6374 if (S.
LangOpts.OpenCLVersion != 200)
6375 S.
Diag(AL.
getLoc(), diag::err_attribute_requires_opencl_version)
6376 << AL <<
"2.0" << 0;
6378 S.
Diag(AL.
getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL
6385 static bool handleCommonAttributeFeatures(
Sema &S,
Decl *D,
6430 if (D->
hasAttr<OpenCLAccessAttr>()) {
6431 if (D->
getAttr<OpenCLAccessAttr>()->getSemanticSpelling() ==
6433 S.
Diag(AL.
getLoc(), diag::warn_duplicate_declspec)
6436 S.
Diag(AL.
getLoc(), diag::err_opencl_multiple_access_qualifiers)
6448 if (
const auto *PDecl = dyn_cast<ParmVarDecl>(D)) {
6449 const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
6450 if (AL.
getName()->
getName().find(
"read_write") != StringRef::npos) {
6454 S.
Diag(AL.
getLoc(), diag::err_opencl_invalid_read_write)
6455 << AL << PDecl->getType() << DeclTy->
isImageType();
6467 if (!cast<VarDecl>(D)->hasGlobalStorage()) {
6469 << (A.
getKind() == ParsedAttr::AT_AlwaysDestroy);
6473 if (A.
getKind() == ParsedAttr::AT_AlwaysDestroy)
6474 handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A);
6476 handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A);
6480 assert(cast<VarDecl>(D)->getStorageDuration() ==
SD_Automatic &&
6481 "uninitialized is only valid on automatic duration variables");
6487 static bool tryMakeVariablePseudoStrong(
Sema &S,
VarDecl *VD,
6488 bool DiagnoseFailure) {
6491 if (DiagnoseFailure) {
6492 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6509 if (DiagnoseFailure) {
6510 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6524 static void handleObjCExternallyRetainedAttr(
Sema &S,
Decl *D,
6526 if (
auto *VD = dyn_cast<VarDecl>(D)) {
6527 assert(!isa<ParmVarDecl>(VD) &&
"should be diagnosed automatically");
6534 if (!tryMakeVariablePseudoStrong(S, VD,
true))
6537 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6555 tryMakeVariablePseudoStrong(S, PVD,
false);
6557 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6565 if (!isa<BlockDecl>(D)) {
6567 bool IsKernReturnT =
false;
6569 IsKernReturnT = (TT->getDecl()->getName() ==
"kern_return_t");
6574 diag::warn_mig_server_routine_does_not_return_kern_return_t);
6579 handleSimpleAttribute<MIGServerRoutineAttr>(S, D, AL);
6584 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
6587 S.
Diag(AL.
getLoc(), diag::warn_declspec_allocator_nonpointer)
6593 handleSimpleAttribute<MSAllocatorAttr>(S, D, AL);
6603 static void ProcessDeclAttribute(
Sema &S, Scope *scope,
Decl *D,
6605 bool IncludeCXX11Attributes) {
6621 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
6622 : (
unsigned)diag::warn_unknown_attribute_ignored)
6627 if (handleCommonAttributeFeatures(S, D, AL))
6634 assert(AL.
isTypeAttr() &&
"Non-type attribute not handled");
6637 S.
Diag(AL.
getLoc(), diag::err_stmt_attribute_invalid_on_decl)
6640 case ParsedAttr::AT_Interrupt:
6641 handleInterruptAttr(S, D, AL);
6643 case ParsedAttr::AT_X86ForceAlignArgPointer:
6644 handleX86ForceAlignArgPointerAttr(S, D, AL);
6646 case ParsedAttr::AT_DLLExport:
6647 case ParsedAttr::AT_DLLImport:
6648 handleDLLAttr(S, D, AL);
6650 case ParsedAttr::AT_Mips16:
6651 handleSimpleAttributeWithExclusions<Mips16Attr, MicroMipsAttr,
6652 MipsInterruptAttr>(S, D, AL);
6654 case ParsedAttr::AT_NoMips16:
6655 handleSimpleAttribute<NoMips16Attr>(S, D, AL);
6657 case ParsedAttr::AT_MicroMips:
6658 handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(S, D, AL);
6660 case ParsedAttr::AT_NoMicroMips:
6661 handleSimpleAttribute<NoMicroMipsAttr>(S, D, AL);
6663 case ParsedAttr::AT_MipsLongCall:
6664 handleSimpleAttributeWithExclusions<MipsLongCallAttr, MipsShortCallAttr>(
6667 case ParsedAttr::AT_MipsShortCall:
6668 handleSimpleAttributeWithExclusions<MipsShortCallAttr, MipsLongCallAttr>(
6671 case ParsedAttr::AT_AMDGPUFlatWorkGroupSize:
6672 handleAMDGPUFlatWorkGroupSizeAttr(S, D, AL);
6674 case ParsedAttr::AT_AMDGPUWavesPerEU:
6675 handleAMDGPUWavesPerEUAttr(S, D, AL);
6677 case ParsedAttr::AT_AMDGPUNumSGPR:
6678 handleAMDGPUNumSGPRAttr(S, D, AL);
6680 case ParsedAttr::AT_AMDGPUNumVGPR:
6681 handleAMDGPUNumVGPRAttr(S, D, AL);
6683 case ParsedAttr::AT_AVRSignal:
6684 handleAVRSignalAttr(S, D, AL);
6686 case ParsedAttr::AT_WebAssemblyImportModule:
6687 handleWebAssemblyImportModuleAttr(S, D, AL);
6689 case ParsedAttr::AT_WebAssemblyImportName:
6690 handleWebAssemblyImportNameAttr(S, D, AL);
6692 case ParsedAttr::AT_IBAction:
6693 handleSimpleAttribute<IBActionAttr>(S, D, AL);
6695 case ParsedAttr::AT_IBOutlet:
6696 handleIBOutlet(S, D, AL);
6698 case ParsedAttr::AT_IBOutletCollection:
6699 handleIBOutletCollection(S, D, AL);
6701 case ParsedAttr::AT_IFunc:
6702 handleIFuncAttr(S, D, AL);
6704 case ParsedAttr::AT_Alias:
6705 handleAliasAttr(S, D, AL);
6707 case ParsedAttr::AT_Aligned:
6708 handleAlignedAttr(S, D, AL);
6710 case ParsedAttr::AT_AlignValue:
6711 handleAlignValueAttr(S, D, AL);
6713 case ParsedAttr::AT_AllocSize:
6714 handleAllocSizeAttr(S, D, AL);
6716 case ParsedAttr::AT_AlwaysInline:
6717 handleAlwaysInlineAttr(S, D, AL);
6719 case ParsedAttr::AT_Artificial:
6720 handleSimpleAttribute<ArtificialAttr>(S, D, AL);
6722 case ParsedAttr::AT_AnalyzerNoReturn:
6723 handleAnalyzerNoReturnAttr(S, D, AL);
6725 case ParsedAttr::AT_TLSModel:
6726 handleTLSModelAttr(S, D, AL);
6728 case ParsedAttr::AT_Annotate:
6729 handleAnnotateAttr(S, D, AL);
6731 case ParsedAttr::AT_Availability:
6732 handleAvailabilityAttr(S, D, AL);
6734 case ParsedAttr::AT_CarriesDependency:
6735 handleDependencyAttr(S, scope, D, AL);
6737 case ParsedAttr::AT_CPUDispatch:
6738 case ParsedAttr::AT_CPUSpecific:
6739 handleCPUSpecificAttr(S, D, AL);
6741 case ParsedAttr::AT_Common:
6742 handleCommonAttr(S, D, AL);
6744 case ParsedAttr::AT_CUDAConstant:
6745 handleConstantAttr(S, D, AL);
6747 case ParsedAttr::AT_PassObjectSize:
6748 handlePassObjectSizeAttr(S, D, AL);
6750 case ParsedAttr::AT_Constructor:
6751 handleConstructorAttr(S, D, AL);
6753 case ParsedAttr::AT_CXX11NoReturn:
6754 handleSimpleAttribute<CXX11NoReturnAttr>(S, D, AL);
6756 case ParsedAttr::AT_Deprecated:
6757 handleDeprecatedAttr(S, D, AL);
6759 case ParsedAttr::AT_Destructor:
6760 handleDestructorAttr(S, D, AL);
6762 case ParsedAttr::AT_EnableIf:
6763 handleEnableIfAttr(S, D, AL);
6765 case ParsedAttr::AT_DiagnoseIf:
6766 handleDiagnoseIfAttr(S, D, AL);
6768 case ParsedAttr::AT_ExtVectorType:
6769 handleExtVectorTypeAttr(S, D, AL);
6771 case ParsedAttr::AT_ExternalSourceSymbol:
6772 handleExternalSourceSymbolAttr(S, D, AL);
6774 case ParsedAttr::AT_MinSize:
6775 handleMinSizeAttr(S, D, AL);
6777 case ParsedAttr::AT_OptimizeNone:
6778 handleOptimizeNoneAttr(S, D, AL);
6780 case ParsedAttr::AT_FlagEnum:
6781 handleSimpleAttribute<FlagEnumAttr>(S, D, AL);
6783 case ParsedAttr::AT_EnumExtensibility:
6784 handleEnumExtensibilityAttr(S, D, AL);
6786 case ParsedAttr::AT_Flatten:
6787 handleSimpleAttribute<FlattenAttr>(S, D, AL);
6789 case ParsedAttr::AT_Format:
6790 handleFormatAttr(S, D, AL);
6792 case ParsedAttr::AT_FormatArg:
6793 handleFormatArgAttr(S, D, AL);
6795 case ParsedAttr::AT_Callback:
6796 handleCallbackAttr(S, D, AL);
6798 case ParsedAttr::AT_CUDAGlobal:
6799 handleGlobalAttr(S, D, AL);
6801 case ParsedAttr::AT_CUDADevice:
6802 handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(S, D,
6805 case ParsedAttr::AT_CUDAHost:
6806 handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(S, D, AL);
6808 case ParsedAttr::AT_HIPPinnedShadow:
6809 handleSimpleAttributeWithExclusions<HIPPinnedShadowAttr, CUDADeviceAttr,
6810 CUDAConstantAttr>(S, D, AL);
6812 case ParsedAttr::AT_GNUInline:
6813 handleGNUInlineAttr(S, D, AL);
6815 case ParsedAttr::AT_CUDALaunchBounds:
6816 handleLaunchBoundsAttr(S, D, AL);
6818 case ParsedAttr::AT_Restrict:
6819 handleRestrictAttr(S, D, AL);
6821 case ParsedAttr::AT_LifetimeBound:
6822 handleSimpleAttribute<LifetimeBoundAttr>(S, D, AL);
6824 case ParsedAttr::AT_MayAlias:
6825 handleSimpleAttribute<MayAliasAttr>(S, D, AL);
6827 case ParsedAttr::AT_Mode:
6828 handleModeAttr(S, D, AL);
6830 case ParsedAttr::AT_NoAlias:
6831 handleSimpleAttribute<NoAliasAttr>(S, D, AL);
6833 case ParsedAttr::AT_NoCommon:
6834 handleSimpleAttribute<NoCommonAttr>(S, D, AL);
6836 case ParsedAttr::AT_NoSplitStack:
6837 handleSimpleAttribute<NoSplitStackAttr>(S, D, AL);
6839 case ParsedAttr::AT_NoUniqueAddress:
6840 handleSimpleAttribute<NoUniqueAddressAttr>(S, D, AL);
6842 case ParsedAttr::AT_NonNull:
6843 if (
auto *PVD = dyn_cast<ParmVarDecl>(D))
6844 handleNonNullAttrParameter(S, PVD, AL);
6846 handleNonNullAttr(S, D, AL);
6848 case ParsedAttr::AT_ReturnsNonNull:
6849 handleReturnsNonNullAttr(S, D, AL);
6851 case ParsedAttr::AT_NoEscape:
6852 handleNoEscapeAttr(S, D, AL);
6854 case ParsedAttr::AT_AssumeAligned:
6855 handleAssumeAlignedAttr(S, D, AL);
6857 case ParsedAttr::AT_AllocAlign:
6858 handleAllocAlignAttr(S, D, AL);
6860 case ParsedAttr::AT_Overloadable:
6861 handleSimpleAttribute<OverloadableAttr>(S, D, AL);
6863 case ParsedAttr::AT_Ownership:
6864 handleOwnershipAttr(S, D, AL);
6866 case ParsedAttr::AT_Cold:
6867 handleSimpleAttributeWithExclusions<ColdAttr, HotAttr>(S, D, AL);
6869 case ParsedAttr::AT_Hot:
6870 handleSimpleAttributeWithExclusions<HotAttr, ColdAttr>(S, D, AL);
6872 case ParsedAttr::AT_Naked:
6873 handleNakedAttr(S, D, AL);
6875 case ParsedAttr::AT_NoReturn:
6876 handleNoReturnAttr(S, D, AL);
6878 case ParsedAttr::AT_AnyX86NoCfCheck:
6879 handleNoCfCheckAttr(S, D, AL);
6881 case ParsedAttr::AT_NoThrow:
6883 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6885 case ParsedAttr::AT_CUDAShared:
6886 handleSharedAttr(S, D, AL);
6888 case ParsedAttr::AT_VecReturn:
6889 handleVecReturnAttr(S, D, AL);
6891 case ParsedAttr::AT_ObjCOwnership:
6892 handleObjCOwnershipAttr(S, D, AL);
6894 case ParsedAttr::AT_ObjCPreciseLifetime:
6895 handleObjCPreciseLifetimeAttr(S, D, AL);
6897 case ParsedAttr::AT_ObjCReturnsInnerPointer:
6898 handleObjCReturnsInnerPointerAttr(S, D, AL);
6900 case ParsedAttr::AT_ObjCRequiresSuper:
6901 handleObjCRequiresSuperAttr(S, D, AL);
6903 case ParsedAttr::AT_ObjCBridge:
6904 handleObjCBridgeAttr(S, D, AL);
6906 case ParsedAttr::AT_ObjCBridgeMutable:
6907 handleObjCBridgeMutableAttr(S, D, AL);
6909 case ParsedAttr::AT_ObjCBridgeRelated:
6910 handleObjCBridgeRelatedAttr(S, D, AL);
6912 case ParsedAttr::AT_ObjCDesignatedInitializer:
6913 handleObjCDesignatedInitializer(S, D, AL);
6915 case ParsedAttr::AT_ObjCRuntimeName:
6916 handleObjCRuntimeName(S, D, AL);
6918 case ParsedAttr::AT_ObjCRuntimeVisible:
6919 handleSimpleAttribute<ObjCRuntimeVisibleAttr>(S, D, AL);
6921 case ParsedAttr::AT_ObjCBoxable:
6922 handleObjCBoxable(S, D, AL);
6924 case ParsedAttr::AT_CFAuditedTransfer:
6925 handleSimpleAttributeWithExclusions<CFAuditedTransferAttr,
6926 CFUnknownTransferAttr>(S, D, AL);
6928 case ParsedAttr::AT_CFUnknownTransfer:
6929 handleSimpleAttributeWithExclusions<CFUnknownTransferAttr,
6930 CFAuditedTransferAttr>(S, D, AL);
6932 case ParsedAttr::AT_CFConsumed:
6933 case ParsedAttr::AT_NSConsumed:
6934 case ParsedAttr::AT_OSConsumed:
6936 parsedAttrToRetainOwnershipKind(AL),
6939 case ParsedAttr::AT_NSConsumesSelf:
6940 handleSimpleAttribute<NSConsumesSelfAttr>(S, D, AL);
6942 case ParsedAttr::AT_OSConsumesThis:
6943 handleSimpleAttribute<OSConsumesThisAttr>(S, D, AL);
6945 case ParsedAttr::AT_OSReturnsRetainedOnZero:
6946 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnZeroAttr>(
6947 S, D, AL, isValidOSObjectOutParameter(D),
6948 diag::warn_ns_attribute_wrong_parameter_type,
6951 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
6952 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnNonZeroAttr>(
6953 S, D, AL, isValidOSObjectOutParameter(D),
6954 diag::warn_ns_attribute_wrong_parameter_type,
6955 AL, 3, AL.getRange());
6957 case ParsedAttr::AT_NSReturnsAutoreleased:
6958 case ParsedAttr::AT_NSReturnsNotRetained:
6959 case ParsedAttr::AT_NSReturnsRetained:
6960 case ParsedAttr::AT_CFReturnsNotRetained:
6961 case ParsedAttr::AT_CFReturnsRetained:
6962 case ParsedAttr::AT_OSReturnsNotRetained:
6963 case ParsedAttr::AT_OSReturnsRetained:
6964 handleXReturnsXRetainedAttr(S, D, AL);
6966 case ParsedAttr::AT_WorkGroupSizeHint:
6967 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
6969 case ParsedAttr::AT_ReqdWorkGroupSize:
6970 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
6972 case ParsedAttr::AT_OpenCLIntelReqdSubGroupSize:
6973 handleSubGroupSize(S, D, AL);
6975 case ParsedAttr::AT_VecTypeHint:
6976 handleVecTypeHint(S, D, AL);
6978 case ParsedAttr::AT_RequireConstantInit:
6979 handleSimpleAttribute<RequireConstantInitAttr>(S, D, AL);
6981 case ParsedAttr::AT_InitPriority:
6982 handleInitPriorityAttr(S, D, AL);
6984 case ParsedAttr::AT_Packed:
6985 handlePackedAttr(S, D, AL);
6987 case ParsedAttr::AT_Section:
6988 handleSectionAttr(S, D, AL);
6990 case ParsedAttr::AT_SpeculativeLoadHardening:
6991 handleSimpleAttributeWithExclusions<SpeculativeLoadHardeningAttr,
6992 NoSpeculativeLoadHardeningAttr>(S, D,
6995 case ParsedAttr::AT_NoSpeculativeLoadHardening:
6996 handleSimpleAttributeWithExclusions<NoSpeculativeLoadHardeningAttr,
6997 SpeculativeLoadHardeningAttr>(S, D, AL);
6999 case ParsedAttr::AT_CodeSeg:
7000 handleCodeSegAttr(S, D, AL);
7002 case ParsedAttr::AT_Target:
7003 handleTargetAttr(S, D, AL);
7005 case ParsedAttr::AT_MinVectorWidth:
7006 handleMinVectorWidthAttr(S, D, AL);
7008 case ParsedAttr::AT_Unavailable:
7009 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
7011 case ParsedAttr::AT_ArcWeakrefUnavailable:
7012 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, AL);
7014 case ParsedAttr::AT_ObjCRootClass:
7015 handleSimpleAttribute<ObjCRootClassAttr>(S, D, AL);
7017 case ParsedAttr::AT_ObjCNonLazyClass:
7018 handleSimpleAttribute<ObjCNonLazyClassAttr>(S, D, AL);
7020 case ParsedAttr::AT_ObjCSubclassingRestricted:
7021 handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(S, D, AL);
7023 case ParsedAttr::AT_ObjCClassStub:
7024 handleSimpleAttribute<ObjCClassStubAttr>(S, D, AL);
7026 case ParsedAttr::AT_ObjCExplicitProtocolImpl:
7027 handleObjCSuppresProtocolAttr(S, D, AL);
7029 case ParsedAttr::AT_ObjCRequiresPropertyDefs:
7030 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, AL);
7032 case ParsedAttr::AT_Unused:
7033 handleUnusedAttr(S, D, AL);
7035 case ParsedAttr::AT_ReturnsTwice:
7036 handleSimpleAttribute<ReturnsTwiceAttr>(S, D, AL);
7038 case ParsedAttr::AT_NotTailCalled:
7039 handleSimpleAttributeWithExclusions<NotTailCalledAttr, AlwaysInlineAttr>(
7042 case ParsedAttr::AT_DisableTailCalls:
7043 handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D,
7046 case ParsedAttr::AT_Used:
7047 handleSimpleAttribute<UsedAttr>(S, D, AL);
7049 case ParsedAttr::AT_Visibility:
7050 handleVisibilityAttr(S, D, AL,
false);
7052 case ParsedAttr::AT_TypeVisibility:
7053 handleVisibilityAttr(S, D, AL,
true);
7055 case ParsedAttr::AT_WarnUnused:
7056 handleSimpleAttribute<WarnUnusedAttr>(S, D, AL);
7058 case ParsedAttr::AT_WarnUnusedResult:
7059 handleWarnUnusedResult(S, D, AL);
7061 case ParsedAttr::AT_Weak:
7062 handleSimpleAttribute<WeakAttr>(S, D, AL);
7064 case ParsedAttr::AT_WeakRef:
7065 handleWeakRefAttr(S, D, AL);
7067 case ParsedAttr::AT_WeakImport:
7068 handleWeakImportAttr(S, D, AL);
7070 case ParsedAttr::AT_TransparentUnion:
7071 handleTransparentUnionAttr(S, D, AL);
7073 case ParsedAttr::AT_ObjCException:
7074 handleSimpleAttribute<ObjCExceptionAttr>(S, D, AL);
7076 case ParsedAttr::AT_ObjCMethodFamily:
7077 handleObjCMethodFamilyAttr(S, D, AL);
7079 case ParsedAttr::AT_ObjCNSObject:
7080 handleObjCNSObject(S, D, AL);
7082 case ParsedAttr::AT_ObjCIndependentClass:
7083 handleObjCIndependentClass(S, D, AL);
7085 case ParsedAttr::AT_Blocks:
7086 handleBlocksAttr(S, D, AL);
7088 case ParsedAttr::AT_Sentinel:
7089 handleSentinelAttr(S, D, AL);
7091 case ParsedAttr::AT_Const:
7092 handleSimpleAttribute<ConstAttr>(S, D, AL);
7094 case ParsedAttr::AT_Pure:
7095 handleSimpleAttribute<PureAttr>(S, D, AL);
7097 case ParsedAttr::AT_Cleanup:
7098 handleCleanupAttr(S, D, AL);
7100 case ParsedAttr::AT_NoDebug:
7101 handleNoDebugAttr(S, D, AL);
7103 case ParsedAttr::AT_NoDuplicate:
7104 handleSimpleAttribute<NoDuplicateAttr>(S, D, AL);
7106 case ParsedAttr::AT_Convergent:
7107 handleSimpleAttribute<ConvergentAttr>(S, D, AL);
7109 case ParsedAttr::AT_NoInline:
7110 handleSimpleAttribute<NoInlineAttr>(S, D, AL);
7112 case ParsedAttr::AT_NoInstrumentFunction:
7113 handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, AL);
7115 case ParsedAttr::AT_NoStackProtector:
7117 handleSimpleAttribute<NoStackProtectorAttr>(S, D, AL);
7119 case ParsedAttr::AT_StdCall:
7120 case ParsedAttr::AT_CDecl:
7121 case ParsedAttr::AT_FastCall:
7122 case ParsedAttr::AT_ThisCall:
7123 case ParsedAttr::AT_Pascal:
7124 case ParsedAttr::AT_RegCall:
7125 case ParsedAttr::AT_SwiftCall:
7126 case ParsedAttr::AT_VectorCall:
7127 case ParsedAttr::AT_MSABI:
7128 case ParsedAttr::AT_SysVABI:
7129 case ParsedAttr::AT_Pcs:
7130 case ParsedAttr::AT_IntelOclBicc:
7131 case ParsedAttr::AT_PreserveMost:
7132 case ParsedAttr::AT_PreserveAll:
7133 case ParsedAttr::AT_AArch64VectorPcs:
7134 handleCallConvAttr(S, D, AL);
7136 case ParsedAttr::AT_Suppress:
7139 case ParsedAttr::AT_OpenCLKernel:
7140 handleSimpleAttribute<OpenCLKernelAttr>(S, D, AL);
7142 case ParsedAttr::AT_OpenCLAccess:
7143 handleOpenCLAccessAttr(S, D, AL);
7145 case ParsedAttr::AT_OpenCLNoSVM:
7146 handleOpenCLNoSVMAttr(S, D, AL);
7148 case ParsedAttr::AT_SwiftContext:
7151 case ParsedAttr::AT_SwiftErrorResult:
7154 case ParsedAttr::AT_SwiftIndirectResult:
7157 case ParsedAttr::AT_InternalLinkage:
7158 handleInternalLinkageAttr(S, D, AL);
7160 case ParsedAttr::AT_ExcludeFromExplicitInstantiation:
7161 handleSimpleAttribute<ExcludeFromExplicitInstantiationAttr>(S, D, AL);
7163 case ParsedAttr::AT_LTOVisibilityPublic:
7164 handleSimpleAttribute<LTOVisibilityPublicAttr>(S, D, AL);
7168 case ParsedAttr::AT_EmptyBases:
7169 handleSimpleAttribute<EmptyBasesAttr>(S, D, AL);
7171 case ParsedAttr::AT_LayoutVersion:
7172 handleLayoutVersion(S, D, AL);
7174 case ParsedAttr::AT_TrivialABI:
7175 handleSimpleAttribute<TrivialABIAttr>(S, D, AL);
7177 case ParsedAttr::AT_MSNoVTable:
7178 handleSimpleAttribute<MSNoVTableAttr>(S, D, AL);
7180 case ParsedAttr::AT_MSStruct:
7181 handleSimpleAttribute<MSStructAttr>(S, D, AL);
7183 case ParsedAttr::AT_Uuid:
7184 handleUuidAttr(S, D, AL);
7186 case ParsedAttr::AT_MSInheritance:
7187 handleMSInheritanceAttr(S, D, AL);
7189 case ParsedAttr::AT_SelectAny:
7190 handleSimpleAttribute<SelectAnyAttr>(S, D, AL);
7192 case ParsedAttr::AT_Thread:
7193 handleDeclspecThreadAttr(S, D, AL);
7196 case ParsedAttr::AT_AbiTag:
7197 handleAbiTagAttr(S, D, AL);
7201 case ParsedAttr::AT_AssertExclusiveLock:
7202 handleAssertExclusiveLockAttr(S, D, AL);
7204 case ParsedAttr::AT_AssertSharedLock:
7205 handleAssertSharedLockAttr(S, D, AL);
7207 case ParsedAttr::AT_GuardedVar:
7208 handleSimpleAttribute<GuardedVarAttr>(S, D, AL);
7210 case ParsedAttr::AT_PtGuardedVar:
7211 handlePtGuardedVarAttr(S, D, AL);
7213 case ParsedAttr::AT_ScopedLockable:
7214 handleSimpleAttribute<ScopedLockableAttr>(S, D, AL);
7216 case ParsedAttr::AT_NoSanitize:
7217 handleNoSanitizeAttr(S, D, AL);
7219 case ParsedAttr::AT_NoSanitizeSpecific:
7220 handleNoSanitizeSpecificAttr(S, D, AL);
7222 case ParsedAttr::AT_NoThreadSafetyAnalysis:
7223 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, AL);
7225 case ParsedAttr::AT_GuardedBy:
7226 handleGuardedByAttr(S, D, AL);
7228 case ParsedAttr::AT_PtGuardedBy:
7229 handlePtGuardedByAttr(S, D, AL);
7231 case ParsedAttr::AT_ExclusiveTrylockFunction:
7232 handleExclusiveTrylockFunctionAttr(S, D, AL);
7234 case ParsedAttr::AT_LockReturned:
7235 handleLockReturnedAttr(S, D, AL);
7237 case ParsedAttr::AT_LocksExcluded:
7238 handleLocksExcludedAttr(S, D, AL);
7240 case ParsedAttr::AT_SharedTrylockFunction:
7241 handleSharedTrylockFunctionAttr(S, D, AL);
7243 case ParsedAttr::AT_AcquiredBefore:
7244 handleAcquiredBeforeAttr(S, D, AL);
7246 case ParsedAttr::AT_AcquiredAfter:
7247 handleAcquiredAfterAttr(S, D, AL);
7251 case ParsedAttr::AT_Capability:
7252 case ParsedAttr::AT_Lockable:
7253 handleCapabilityAttr(S, D, AL);
7255 case ParsedAttr::AT_RequiresCapability:
7256 handleRequiresCapabilityAttr(S, D, AL);
7259 case ParsedAttr::AT_AssertCapability:
7260 handleAssertCapabilityAttr(S, D, AL);
7262 case ParsedAttr::AT_AcquireCapability:
7263 handleAcquireCapabilityAttr(S, D, AL);
7265 case ParsedAttr::AT_ReleaseCapability:
7266 handleReleaseCapabilityAttr(S, D, AL);
7268 case ParsedAttr::AT_TryAcquireCapability:
7269 handleTryAcquireCapabilityAttr(S, D, AL);
7273 case ParsedAttr::AT_Consumable:
7274 handleConsumableAttr(S, D, AL);
7276 case ParsedAttr::AT_ConsumableAutoCast:
7277 handleSimpleAttribute<ConsumableAutoCastAttr>(S, D, AL);
7279 case ParsedAttr::AT_ConsumableSetOnRead:
7280 handleSimpleAttribute<ConsumableSetOnReadAttr>(S, D, AL);
7282 case ParsedAttr::AT_CallableWhen:
7283 handleCallableWhenAttr(S, D, AL);
7285 case ParsedAttr::AT_ParamTypestate:
7286 handleParamTypestateAttr(S, D, AL);
7288 case ParsedAttr::AT_ReturnTypestate:
7289 handleReturnTypestateAttr(S, D, AL);
7291 case ParsedAttr::AT_SetTypestate:
7292 handleSetTypestateAttr(S, D, AL);
7294 case ParsedAttr::AT_TestTypestate:
7295 handleTestTypestateAttr(S, D, AL);
7299 case ParsedAttr::AT_ArgumentWithTypeTag:
7300 handleArgumentWithTypeTagAttr(S, D, AL);
7302 case ParsedAttr::AT_TypeTagForDatatype:
7303 handleTypeTagForDatatypeAttr(S, D, AL);
7305 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters:
7306 handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL);
7308 case ParsedAttr::AT_RenderScriptKernel:
7309 handleSimpleAttribute<RenderScriptKernelAttr>(S, D, AL);
7312 case ParsedAttr::AT_XRayInstrument:
7313 handleSimpleAttribute<XRayInstrumentAttr>(S, D, AL);
7315 case ParsedAttr::AT_XRayLogArgs:
7316 handleXRayLogArgsAttr(S, D, AL);
7320 case ParsedAttr::AT_Reinitializes:
7321 handleSimpleAttribute<ReinitializesAttr>(S, D, AL);
7324 case ParsedAttr::AT_AlwaysDestroy:
7325 case ParsedAttr::AT_NoDestroy:
7326 handleDestroyAttr(S, D, AL);
7329 case ParsedAttr::AT_Uninitialized:
7330 handleUninitializedAttr(S, D, AL);
7333 case ParsedAttr::AT_ObjCExternallyRetained:
7334 handleObjCExternallyRetainedAttr(S, D, AL);
7337 case ParsedAttr::AT_MIGServerRoutine:
7338 handleMIGServerRoutineAttr(S, D, AL);
7341 case ParsedAttr::AT_MSAllocator:
7342 handleMSAllocatorAttr(S, D, AL);
7351 bool IncludeCXX11Attributes) {
7352 if (AttrList.
empty())
7356 ProcessDeclAttribute(*
this, S, D, AL, IncludeCXX11Attributes);
7363 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias)
7364 << cast<NamedDecl>(D);
7373 if (!D->
hasAttr<OpenCLKernelAttr>()) {
7375 if (
const auto *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
7380 }
else if (
const auto *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
7383 }
else if (
const auto *A = D->
getAttr<VecTypeHintAttr>()) {
7386 }
else if (
const auto *A = D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
7389 }
else if (!D->
hasAttr<CUDAGlobalAttr>()) {
7390 if (
const auto *A = D->
getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
7394 }
else if (
const auto *A = D->
getAttr<AMDGPUWavesPerEUAttr>()) {
7398 }
else if (
const auto *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
7402 }
else if (
const auto *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
7415 if (D->
hasAttr<ObjCDesignatedInitializerAttr>() &&
7416 cast<ObjCMethodDecl>(D)->getMethodFamily() !=
OMF_init) {
7418 D->
dropAttr<ObjCDesignatedInitializerAttr>();
7426 if (AL.
getKind() == ParsedAttr::AT_TransparentUnion) {
7427 handleTransparentUnionAttr(*
this, D, AL);
7437 if (AL.
getKind() == ParsedAttr::AT_Annotate) {
7440 Diag(AL.
getLoc(), diag::err_only_annotate_after_access_spec);
7458 S.
Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored)
7461 S.
Diag(AL.
getLoc(), diag::warn_attribute_not_on_decl) << AL
7481 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
7483 if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
7503 for (
const auto &AI : FT->param_types()) {
7504 ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
7506 Params.push_back(Param);
7508 NewFD->setParams(Params);
7510 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
7529 NewD->
addAttr(AliasAttr::CreateImplicit(Context, NDId->
getName(),
7532 WeakTopLevelDecl.push_back(NewD);
7539 PushOnScopeChains(NewD, S);
7540 CurContext = SavedContext;
7549 LoadExternalWeakUndeclaredIdentifiers();
7550 if (!WeakUndeclaredIdentifiers.empty()) {
7552 if (
auto *VD = dyn_cast<VarDecl>(D))
7555 if (
auto *FD = dyn_cast<FunctionDecl>(D))
7560 auto I = WeakUndeclaredIdentifiers.find(
Id);
7561 if (I != WeakUndeclaredIdentifiers.end()) {
7563 DeclApplyPragmaWeak(S, ND, W);
7564 WeakUndeclaredIdentifiers[
Id] = W;
7591 AddPragmaAttributes(S, D);
7597 static bool isForbiddenTypeAllowed(
Sema &S,
Decl *D,
7599 UnavailableAttr::ImplicitReason &reason) {
7603 if (!isa<FieldDecl>(D) && !isa<ObjCPropertyDecl>(D) &&
7604 !isa<FunctionDecl>(D))
7612 if ((isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) {
7615 reason = UnavailableAttr::IR_ForbiddenWeak;
7624 reason = UnavailableAttr::IR_ARCForbiddenType;
7634 auto Reason = UnavailableAttr::IR_None;
7635 if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) {
7636 assert(Reason &&
"didn't set reason?");
7641 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
7644 if (FD->
hasAttr<UnavailableAttr>() &&
7646 diag::err_arc_array_param_no_ownership) {
7657 static const AvailabilityAttr *getAttrForPlatform(
ASTContext &Context,
7660 for (
const auto *A : D->
attrs()) {
7661 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
7667 StringRef ActualPlatform = Avail->getPlatform()->getName();
7668 StringRef RealizedPlatform = ActualPlatform;
7670 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
7671 if (suffix != StringRef::npos)
7672 RealizedPlatform = RealizedPlatform.slice(0, suffix);
7678 if (RealizedPlatform == TargetPlatform)
7693 static std::pair<AvailabilityResult, const NamedDecl *>
7694 ShouldDiagnoseAvailabilityOfDecl(
Sema &S,
const NamedDecl *D,
7695 std::string *Message,
7701 while (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
7703 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
7713 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
7714 if (IDecl->getDefinition()) {
7715 D = IDecl->getDefinition();
7720 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7723 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
7724 Result = TheEnumDecl->getAvailability(Message);
7730 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7734 if (Init && Result ==
AR_Available && MD->isClassMethod() &&
7735 MD->getSelector() == S.
NSAPIObj->getNewSelector() &&
7752 VersionTuple DeclVersion,
Decl *Ctx,
7754 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
7757 auto CheckContext = [&](
const Decl *C) {
7759 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, C))
7760 if (AA->getIntroduced() >= DeclVersion)
7763 if (C->isDeprecated())
7769 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
7770 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
7771 if (MD->getClassInterface() == Impl->getClassInterface())
7777 if (C->isUnavailable())
7783 if (CheckContext(Ctx))
7788 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
7789 if (MethodD->isClassMethod() &&
7790 MethodD->getSelector().getAsString() ==
"load")
7793 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
7795 if (CheckContext(Interface))
7799 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
7801 if (CheckContext(Interface))
7809 shouldDiagnoseAvailabilityByDefault(
const ASTContext &Context,
7810 const VersionTuple &DeploymentVersion,
7811 const VersionTuple &DeclVersion) {
7813 VersionTuple ForceAvailabilityFromVersion;
7814 switch (Triple.getOS()) {
7815 case llvm::Triple::IOS:
7816 case llvm::Triple::TvOS:
7817 ForceAvailabilityFromVersion = VersionTuple(11);
7819 case llvm::Triple::WatchOS:
7820 ForceAvailabilityFromVersion = VersionTuple(4);
7822 case llvm::Triple::Darwin:
7823 case llvm::Triple::MacOSX:
7824 ForceAvailabilityFromVersion = VersionTuple(10, 13);
7828 return Triple.getVendor() == llvm::Triple::Apple;
7830 return DeploymentVersion >= ForceAvailabilityFromVersion ||
7831 DeclVersion >= ForceAvailabilityFromVersion;
7834 static NamedDecl *findEnclosingDeclToAnnotate(
Decl *OrigCtx) {
7835 for (
Decl *Ctx = OrigCtx; Ctx;
7837 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
7838 return cast<NamedDecl>(Ctx);
7839 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
7840 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
7841 return Imp->getClassInterface();
7851 struct AttributeInsertion {
7856 static AttributeInsertion createInsertionAfter(
const NamedDecl *D) {
7859 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
7860 return {
" ", Loc,
""};
7862 static AttributeInsertion createInsertionBefore(
const NamedDecl *D) {
7881 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
7882 Name = Name.drop_front(1);
7885 Name.split(SlotNames,
':');
7887 if (Name.back() ==
':') {
7889 SlotNames.pop_back();
7890 NumParams = SlotNames.size();
7892 if (SlotNames.size() != 1)
7898 bool AllowDollar = LangOpts.DollarIdents;
7899 for (StringRef S : SlotNames) {
7913 if (isa<ObjCPropertyDecl>(D))
7914 return AttributeInsertion::createInsertionAfter(D);
7915 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7918 return AttributeInsertion::createInsertionAfter(D);
7920 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
7926 return AttributeInsertion::createInsertionAfter(Loc);
7928 return AttributeInsertion::createInsertionBefore(D);
7948 bool ObjCPropertyAccess) {
7950 unsigned diag, diag_message, diag_fwdclass_message;
7951 unsigned diag_available_here = diag::note_availability_specified_here;
7955 unsigned property_note_select;
7958 unsigned available_here_select_kind;
7960 VersionTuple DeclVersion;
7961 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, OffendingDecl))
7962 DeclVersion = AA->getIntroduced();
7964 if (!ShouldDiagnoseAvailabilityInContext(S, K, DeclVersion, Ctx,
7972 const AvailabilityAttr *A = getAttrForPlatform(S.
Context, OffendingDecl);
7973 if (A && A->isInherited()) {
7976 const AvailabilityAttr *AForRedecl =
7977 getAttrForPlatform(S.
Context, Redecl);
7978 if (AForRedecl && !AForRedecl->isInherited()) {
7981 NoteLocation = Redecl->getLocation();
7993 const AvailabilityAttr *AA =
7995 VersionTuple Introduced = AA->getIntroduced();
7997 bool UseNewWarning = shouldDiagnoseAvailabilityByDefault(
8000 unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
8001 : diag::warn_unguarded_availability;
8003 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8006 S.
Diag(Loc, Warning) << OffendingDecl << PlatformName
8007 << Introduced.getAsString();
8010 diag::note_partial_availability_specified_here)
8011 << OffendingDecl << PlatformName << Introduced.getAsString()
8014 if (
const auto *Enclosing = findEnclosingDeclToAnnotate(Ctx)) {
8015 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
8016 if (TD->getDeclName().isEmpty()) {
8017 S.
Diag(TD->getLocation(),
8018 diag::note_decl_unguarded_availability_silence)
8019 << 1 << TD->getKindName();
8022 auto FixitNoteDiag =
8023 S.
Diag(Enclosing->getLocation(),
8024 diag::note_decl_unguarded_availability_silence)
8027 if (Enclosing->hasAttr<AvailabilityAttr>())
8035 std::string PlatformName =
8036 AvailabilityAttr::getPlatformNameSourceSpelling(
8039 std::string Introduced =
8043 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
8044 "(" + Introduced +
"))" + Insertion->Suffix)
8050 diag = !ObjCPropertyAccess ? diag::warn_deprecated
8051 : diag::warn_property_method_deprecated;
8052 diag_message = diag::warn_deprecated_message;
8053 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
8054 property_note_select = 0;
8055 available_here_select_kind = 2;
8056 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
8057 NoteLocation = AL->getLocation();
8061 diag = !ObjCPropertyAccess ? diag::err_unavailable
8062 : diag::err_property_method_unavailable;
8063 diag_message = diag::err_unavailable_message;
8064 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
8065 property_note_select = 1;
8066 available_here_select_kind = 0;
8068 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
8069 if (AL->isImplicit() && AL->getImplicitReason()) {
8072 auto flagARCError = [&] {
8076 diag = diag::err_unavailable_in_arc;
8079 switch (AL->getImplicitReason()) {
8080 case UnavailableAttr::IR_None:
break;
8082 case UnavailableAttr::IR_ARCForbiddenType:
8084 diag_available_here = diag::note_arc_forbidden_type;
8087 case UnavailableAttr::IR_ForbiddenWeak:
8089 diag_available_here = diag::note_arc_weak_disabled;
8091 diag_available_here = diag::note_arc_weak_no_runtime;
8094 case UnavailableAttr::IR_ARCForbiddenConversion:
8096 diag_available_here = diag::note_performs_forbidden_arc_conversion;
8099 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
8101 diag_available_here = diag::note_arc_init_returns_unrelated;
8104 case UnavailableAttr::IR_ARCFieldWithOwnership:
8106 diag_available_here = diag::note_arc_field_with_ownership;
8114 llvm_unreachable(
"Warning for availability of available declaration?");
8119 StringRef Replacement;
8120 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
8121 Replacement = AL->getReplacement();
8122 if (
auto AL = getAttrForPlatform(S.
Context, OffendingDecl))
8123 Replacement = AL->getReplacement();
8126 if (!Replacement.empty())
8130 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
8131 Selector Sel = MethodDecl->getSelector();
8135 if (NumParams && NumParams.getValue() == Sel.
getNumArgs()) {
8136 assert(SelectorSlotNames.size() == Locs.size());
8137 for (
unsigned I = 0; I < Locs.size(); ++I) {
8142 NameRange, SelectorSlotNames[I]));
8154 if (!Message.empty()) {
8155 S.
Diag(Loc, diag_message) << ReferringDecl << Message << FixIts;
8158 << ObjCProperty->
getDeclName() << property_note_select;
8159 }
else if (!UnknownObjCClass) {
8160 S.
Diag(Loc, diag) << ReferringDecl << FixIts;
8163 << ObjCProperty->
getDeclName() << property_note_select;
8165 S.
Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
8169 S.
Diag(NoteLocation, diag_available_here)
8170 << OffendingDecl << available_here_select_kind;
8176 "Expected an availability diagnostic here");
8179 DoEmitAvailabilityWarning(
8187 assert(DelayedDiagnostics.getCurrentPool());
8189 DelayedDiagnostics.popWithoutEmitting(
state);
8205 bool AnyAccessFailures =
false;
8213 switch (diag.
Kind) {
8218 handleDelayedAvailabilityCheck(*
this, diag, decl);
8225 if (AnyAccessFailures && isa<DecompositionDecl>(decl))
8227 HandleDelayedAccessCheck(diag, decl);
8229 AnyAccessFailures =
true;
8233 handleDelayedForbiddenType(*
this, diag, decl);
8245 assert(curPool &&
"re-emitting in undelayed context not supported");
8246 curPool->
steal(pool);
8256 bool ObjCPropertyAccess) {
8261 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
8262 ObjCProperty, Message, ObjCPropertyAccess));
8267 DoEmitAvailabilityWarning(S, AR, Ctx, ReferringDecl, OffendingDecl,
8268 Message, Locs, UnknownObjCClass, ObjCProperty,
8269 ObjCPropertyAccess);
8277 case Stmt::IfStmtClass:
8278 return cast<IfStmt>(
Parent)->getThen() == S ||
8279 cast<IfStmt>(
Parent)->getElse() == S;
8280 case Stmt::WhileStmtClass:
8281 return cast<WhileStmt>(
Parent)->getBody() == S;
8282 case Stmt::DoStmtClass:
8283 return cast<DoStmt>(
Parent)->getBody() == S;
8284 case Stmt::ForStmtClass:
8285 return cast<ForStmt>(
Parent)->getBody() == S;
8286 case Stmt::CXXForRangeStmtClass:
8287 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
8288 case Stmt::ObjCForCollectionStmtClass:
8289 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
8290 case Stmt::CaseStmtClass:
8291 case Stmt::DefaultStmtClass:
8292 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
8302 bool VisitStmt(
Stmt *S) {
return S != Target; }
8305 static bool isContained(
const Stmt *Target,
const Decl *D) {
8306 StmtUSEFinder Visitor;
8307 Visitor.Target = Target;
8308 return !Visitor.TraverseDecl(const_cast<Decl *>(D));
8324 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
8326 LastDeclUSEFinder Visitor;
8330 if (!Visitor.TraverseStmt(const_cast<Stmt *>(S)))
8343 class DiagnoseUnguardedAvailability
8358 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
8359 : SemaRef(SemaRef), Ctx(Ctx) {
8360 AvailabilityStack.push_back(
8364 bool TraverseDecl(
Decl *D) {
8366 if (!D || isa<FunctionDecl>(D))
8368 return Base::TraverseDecl(D);
8371 bool TraverseStmt(
Stmt *S) {
8374 StmtStack.push_back(S);
8375 bool Result = Base::TraverseStmt(S);
8376 StmtStack.pop_back();
8380 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
8382 bool TraverseIfStmt(
IfStmt *If);
8384 bool TraverseLambdaExpr(
LambdaExpr *E) {
return true; }
8403 DiagnoseDeclAvailability(
8410 DiagnoseDeclAvailability(DRE->
getDecl(),
8427 bool VisitTypeLoc(
TypeLoc Ty);
8430 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
8434 std::tie(Result, OffendingDecl) =
8435 ShouldDiagnoseAvailabilityOfDecl(SemaRef, D,
nullptr, ReceiverClass);
8442 const AvailabilityAttr *AA =
8443 getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
8444 VersionTuple Introduced = AA->getIntroduced();
8446 if (AvailabilityStack.back() >= Introduced)
8451 if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx,
8460 shouldDiagnoseAvailabilityByDefault(
8462 SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced)
8463 ? diag::warn_unguarded_availability_new
8464 : diag::warn_unguarded_availability;
8466 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8467 SemaRef.getASTContext().getTargetInfo().getPlatformName());
8469 SemaRef.Diag(Range.
getBegin(), DiagKind)
8470 << Range << D << PlatformName << Introduced.getAsString();
8473 diag::note_partial_availability_specified_here)
8474 << OffendingDecl << PlatformName << Introduced.getAsString()
8475 << SemaRef.Context.getTargetInfo()
8476 .getPlatformMinVersion()
8480 SemaRef.Diag(Range.
getBegin(), diag::note_unguarded_available_silence)
8482 << (SemaRef.getLangOpts().ObjC ? 0
8486 if (StmtStack.empty())
8488 const Stmt *StmtOfUse = StmtStack.back();
8490 for (
const Stmt *S : llvm::reverse(StmtStack)) {
8491 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
8495 if (isBodyLikeChildStmt(StmtOfUse, S)) {
8503 const Stmt *LastStmtOfUse =
nullptr;
8504 if (isa<DeclStmt>(StmtOfUse) && Scope) {
8505 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
8506 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
8507 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope);
8518 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
8524 const char *ExtraIndentation =
" ";
8525 std::string FixItString;
8526 llvm::raw_string_ostream FixItOS(FixItString);
8527 FixItOS <<
"if (" << (SemaRef.getLangOpts().ObjC ?
"@available" 8528 :
"__builtin_available")
8530 << AvailabilityAttr::getPlatformNameSourceSpelling(
8531 SemaRef.getASTContext().getTargetInfo().getPlatformName())
8532 <<
" " << Introduced.getAsString() <<
", *)) {\n" 8533 << Indentation << ExtraIndentation;
8536 StmtEndLoc, tok::semi, SM, SemaRef.getLangOpts(),
8538 if (ElseInsertionLoc.isInvalid())
8541 FixItOS.str().clear();
8543 << Indentation <<
"} else {\n" 8544 << Indentation << ExtraIndentation
8545 <<
"// Fallback on earlier versions\n" 8546 << Indentation <<
"}";
8551 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
8558 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
8560 DiagnoseDeclAvailability(TD, Range);
8562 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
8564 DiagnoseDeclAvailability(D, Range);
8566 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
8567 if (
NamedDecl *D = ObjCO->getInterface())
8568 DiagnoseDeclAvailability(D, Range);
8574 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
8575 VersionTuple CondVersion;
8576 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->
getCond())) {
8577 CondVersion = E->getVersion();
8581 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
8582 return TraverseStmt(If->
getThen()) && TraverseStmt(If->
getElse());
8585 return Base::TraverseIfStmt(If);
8588 AvailabilityStack.push_back(CondVersion);
8589 bool ShouldContinue = TraverseStmt(If->
getThen());
8590 AvailabilityStack.pop_back();
8592 return ShouldContinue && TraverseStmt(If->
getElse());
8598 Stmt *Body =
nullptr;
8607 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
8609 else if (
auto *BD = dyn_cast<BlockDecl>(D))
8610 Body = BD->getBody();
8612 assert(Body &&
"Need a body here!");
8614 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
8620 bool ObjCPropertyAccess,
8621 bool AvoidPartialAvailabilityChecks,
8623 std::string Message;
8627 std::tie(Result, OffendingDecl) =
8628 ShouldDiagnoseAvailabilityOfDecl(*
this, D, &Message, ClassReceiver);
8633 if (AvoidPartialAvailabilityChecks)
8639 if (getCurFunctionOrMethodDecl()) {
8640 getEnclosingFunction()->HasPotentialAvailabilityViolations =
true;
8642 }
else if (getCurBlock() || getCurLambda()) {
8643 getCurFunction()->HasPotentialAvailabilityViolations =
true;
8649 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
8652 if (PDeclResult == Result)
8657 EmitAvailabilityWarning(*
this, Result, D, OffendingDecl, Message, Locs,
8658 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.
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...
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)
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.
QualType getPointeeType() const
A (possibly-)qualified type.
bool isBlockPointerType() const
static void handleSimpleAttribute(Sema &S, Decl *D, SourceRange SR, unsigned SpellingIndex)
Applies the given attribute to the Decl without performing any additional semantic checking...
NoSpeculativeLoadHardeningAttr * mergeNoSpeculativeLoadHardeningAttr(Decl *D, const NoSpeculativeLoadHardeningAttr &AL)
bool isMemberPointerType() const
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
bool isDeclspecAttribute() const
bool isExternC() const
Determines whether this function is a function with external, C linkage.
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...
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.
void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex, bool IsPackExpansion)
AddAlignedAttr - Adds an aligned attribute to a particular declaration.
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.
void AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr, unsigned SpellingListIndex)
AddAllocAlignAttr - Adds an alloc_align attribute to a particular declaration.
AvailabilityAttr * mergeAvailabilityAttr(NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, bool Implicit, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool IsStrict, StringRef Replacement, AvailabilityMergeKind AMK, int Priority, unsigned AttrSpellingListIndex)
Attribute merging methods. Return true if a new attribute was added.
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.
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 PopParsingDeclaration(ParsingDeclState state, Decl *decl)
Defines the C++ template declaration subclasses.
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
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
SourceLocation getEndLoc() const LLVM_READONLY
QualType withConst() const
const TargetInfo & getTargetInfo() const
A container of type source information.
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.
void AddModeAttr(SourceRange AttrRange, Decl *D, IdentifierInfo *Name, unsigned SpellingListIndex, bool InInstantiation=false)
AddModeAttr - Adds a mode attribute to a particular declaration.
SourceLocation getEndLoc() const LLVM_READONLY
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
Represents a variable declaration or definition.
Information about one declarator, including the parsed type information and the identifier.
QualType getReturnType() const
const T * getAs() const
Member-template getAs<specific type>'.
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
ObjCInterfaceDecl * getClassReceiver() const
ObjCMethodDecl - Represents an instance or class method declaration.
bool isCXX11Attribute() const
bool isInvalidDecl() const
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.
MSInheritanceAttr::Spelling calculateInheritanceModel() const
Calculate what the inheritance model would be for this class.
Represents a struct/union/class.
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.
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.
unsigned getAttributeSpellingListIndex() const
Get an index into the attribute spelling list defined in Attr.td.
static StringRef getIndentationForLine(SourceLocation Loc, const SourceManager &SM)
Returns the leading whitespace for line that corresponds to the given location Loc.
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
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, SourceRange Range, TypeVisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
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
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 CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, const FunctionDecl *FD=nullptr)
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...
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.
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
FormatAttr * mergeFormatAttr(Decl *D, SourceRange Range, IdentifierInfo *Format, int FormatIdx, int FirstArg, unsigned AttrSpellingListIndex)
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.
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...
SourceLocation getTypeSpecStartLoc() const
MinSizeAttr * mergeMinSizeAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling)
VersionTuple Version
The version number at which the change occurred.
const LangOptions & LangOpts
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...
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.
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.
MSInheritanceAttr * mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, unsigned AttrSpellingListIndex, MSInheritanceAttr::Spelling SemanticSpelling)
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.
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.
bool isC2xAttribute() const
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
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.
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)
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.
VisibilityAttr * mergeVisibilityAttr(Decl *D, SourceRange Range, VisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
SourceLocation getLocation() const
void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex)
AddAlignValueAttr - Adds an align_value attribute to a particular declaration.
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
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
SourceLocation getEllipsisLoc() const
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
void AddParameterABIAttr(SourceRange AttrRange, Decl *D, ParameterABI ABI, unsigned SpellingListIndex)
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
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.
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.
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)
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
void AddXConsumedAttr(Decl *D, SourceRange SR, unsigned SpellingIndex, RetainOwnershipKind K, bool IsTemplateInstantiation)
void addAMDGPUFlatWorkGroupSizeAttr(SourceRange AttrRange, Decl *D, Expr *Min, Expr *Max, unsigned SpellingListIndex)
addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size attribute to a particular declar...
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
SectionAttr * mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
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
AvailabilityResult getAvailabilityResult() const
Represents one property declaration in an Objective-C interface.
const ObjCMethodDecl * getMethodDecl() const
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
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.
SourceRange getRange() const
UuidAttr * mergeUuidAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex, StringRef Uuid)
DLLImportAttr * mergeDLLImportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
StringRef getName() const
Return the actual identifier string.
void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE, unsigned SpellingListIndex)
AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular declaration.
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.
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)
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
A runtime availability query.
void addAMDGPUWavesPerEUAttr(SourceRange AttrRange, Decl *D, Expr *Min, Expr *Max, unsigned SpellingListIndex)
addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a particular declaration.
SmallVectorImpl< DelayedDiagnostic >::const_iterator pool_iterator
bool isPackExpansion() const
The name of a declaration.
StmtClass getStmtClass() const
bool isMicrosoftAttribute() const
SourceLocation getLoc() 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 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...
IdentifierInfo * getName() const
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::APInt getValue() const
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)
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.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
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).
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.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
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
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?
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)
OptimizeNoneAttr * mergeOptimizeNoneAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
bool isPointerType() const
DLLExportAttr * mergeDLLExportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
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
void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, Expr *MinBlocks, unsigned SpellingListIndex)
AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular declaration. ...
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)
IdentifierLoc * getArgAsIdent(unsigned Arg) const
CodeSegAttr * mergeCodeSegAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
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
IdentifierInfo * getScopeName() 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.
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
unsigned getProcessingCache() const
const Expr * getReplacementExpr() const