36 #include "llvm/ADT/STLExtras.h" 37 #include "llvm/ADT/StringExtras.h" 38 #include "llvm/Support/MathExtras.h" 40 using namespace clang;
72 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
73 isa<ObjCPropertyDecl>(D);
81 return isa<FunctionProtoType>(FnTy);
82 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
90 return cast<FunctionProtoType>(FnTy)->getNumParams();
91 if (
const auto *BD = dyn_cast<BlockDecl>(D))
92 return BD->getNumParams();
93 return cast<ObjCMethodDecl>(D)->param_size();
98 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
99 return FD->getParamDecl(Idx);
100 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
101 return MD->getParamDecl(Idx);
102 if (
const auto *BD = dyn_cast<BlockDecl>(D))
103 return BD->getParamDecl(Idx);
109 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
110 if (
const auto *BD = dyn_cast<BlockDecl>(D))
111 return BD->getParamDecl(Idx)->getType();
113 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
118 return PVD->getSourceRange();
124 return FnTy->getReturnType();
125 return cast<ObjCMethodDecl>(D)->getReturnType();
129 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
130 return FD->getReturnTypeSourceRange();
131 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
132 return MD->getReturnTypeSourceRange();
138 return cast<FunctionProtoType>(FnTy)->isVariadic();
139 if (
const auto *BD = dyn_cast<BlockDecl>(D))
140 return BD->isVariadic();
141 return cast<ObjCMethodDecl>(D)->isVariadic();
145 if (
const auto *MethodDecl = dyn_cast<CXXMethodDecl>(D))
146 return MethodDecl->isInstance();
162 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
163 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
187 template <
typename Compare>
189 unsigned Num,
unsigned Diag,
203 diag::err_attribute_wrong_number_arguments,
204 std::not_equal_to<unsigned>());
212 diag::err_attribute_too_few_arguments,
213 std::less<unsigned>());
221 diag::err_attribute_too_many_arguments,
222 std::greater<unsigned>());
227 template <
typename AttrInfo>
228 static typename std::enable_if<std::is_base_of<Attr, AttrInfo>::value,
231 return AL.getLocation();
240 template <
typename AttrInfo>
242 uint32_t &Val,
unsigned Idx =
UINT_MAX,
243 bool StrictlyUnsigned =
false) {
259 << I.toString(10,
false) << 32 << 1;
263 if (StrictlyUnsigned && I.isSigned() && I.isNegative()) {
264 S.
Diag(
getAttrLoc(AI), diag::err_attribute_requires_positive_integer)
269 Val = (uint32_t)I.getZExtValue();
276 template <
typename AttrInfo>
278 int &Val,
unsigned Idx =
UINT_MAX) {
287 << I.toString(10,
false) << 32 << 0;
297 template <
typename AttrTy>
299 if (
const auto *A = D->
getAttr<AttrTy>()) {
300 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible) << AL << A;
301 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
307 template <
typename AttrTy>
309 if (
const auto *A = D->
getAttr<AttrTy>()) {
310 S.
Diag(AL.
getLocation(), diag::err_attributes_are_not_compatible) << &AL
312 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
322 template <
typename AttrInfo>
324 Sema &S,
const Decl *D,
const AttrInfo &AI,
unsigned AttrArgNum,
325 const Expr *IdxExpr,
ParamIdx &Idx,
bool CanIndexImplicitThis =
false) {
345 unsigned IdxSource = IdxInt.getLimitedValue(
UINT_MAX);
346 if (IdxSource < 1 || (!IV && IdxSource > NumParams)) {
347 S.
Diag(
getAttrLoc(AI), diag::err_attribute_argument_out_of_bounds)
351 if (HasImplicitThisParam && !CanIndexImplicitThis) {
352 if (IdxSource == 1) {
353 S.
Diag(
getAttrLoc(AI), diag::err_attribute_invalid_implicit_this_argument)
373 Diag(Loc->
Loc, diag::err_attribute_argument_type)
379 *ArgLocation = Loc->
Loc;
389 if (!Literal || !Literal->isAscii()) {
395 Str = Literal->getString();
401 template <
typename AttrType>
403 unsigned SpellingIndex) {
407 template <
typename AttrType>
409 handleSimpleAttribute<AttrType>(S, D, AL.
getRange(),
414 template <
typename... DiagnosticArgs>
420 template <
typename T,
typename... DiagnosticArgs>
423 DiagnosticArgs &&... ExtraArgs) {
425 std::forward<DiagnosticArgs>(ExtraArgs)...);
432 template <
typename AttrType,
typename... DiagnosticArgs>
435 unsigned SpellingIndex,
437 unsigned DiagID, DiagnosticArgs&&... ExtraArgs) {
443 handleSimpleAttribute<AttrType>(S, D, SR, SpellingIndex);
446 template <
typename AttrType,
typename... DiagnosticArgs>
451 DiagnosticArgs&&... ExtraArgs) {
452 return handleSimpleAttributeOrDiagnose<AttrType>(
454 DiagID, std::forward<DiagnosticArgs>(ExtraArgs)...);
457 template <
typename AttrType>
458 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
460 handleSimpleAttribute<AttrType>(S, D, AL);
465 template <
typename AttrType,
typename IncompatibleAttrType,
466 typename... IncompatibleAttrTypes>
467 static void handleSimpleAttributeWithExclusions(
Sema &S,
Decl *D,
469 if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, AL))
471 handleSimpleAttributeWithExclusions<AttrType, IncompatibleAttrTypes...>(S, D,
476 static bool isIntOrBool(
Expr *Exp) {
484 static bool threadSafetyCheckIsSmartPointer(
Sema &S,
const RecordType* RT) {
485 auto IsOverloadedOperatorPresent = [&S](
const RecordDecl *Record,
489 return !Result.
empty();
493 bool foundStarOperator = IsOverloadedOperatorPresent(Record, OO_Star);
494 bool foundArrowOperator = IsOverloadedOperatorPresent(Record, OO_Arrow);
495 if (foundStarOperator && foundArrowOperator)
502 for (
auto BaseSpecifier : CXXRecord->
bases()) {
503 if (!foundStarOperator)
504 foundStarOperator = IsOverloadedOperatorPresent(
505 BaseSpecifier.getType()->getAsRecordDecl(), OO_Star);
506 if (!foundArrowOperator)
507 foundArrowOperator = IsOverloadedOperatorPresent(
508 BaseSpecifier.getType()->getAsRecordDecl(), OO_Arrow);
511 if (foundStarOperator && foundArrowOperator)
520 static bool threadSafetyCheckIsPointer(
Sema &S,
const Decl *D,
522 const auto *VD = cast<ValueDecl>(D);
524 if (QT->isAnyPointerType())
534 if (threadSafetyCheckIsSmartPointer(S, RT))
538 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_decl_not_pointer) << AL << QT;
555 template <
typename AttrType>
556 static bool checkRecordDeclForAttr(
const RecordDecl *RD) {
562 if (
const auto *CRD = dyn_cast<CXXRecordDecl>(RD)) {
564 if (CRD->lookupInBases(
566 const auto &Ty = *BS->getType();
568 if (Ty.isDependentType())
570 return Ty.getAs<RecordType>()->getDecl()->hasAttr<AttrType>();
578 static bool checkRecordTypeForCapability(
Sema &S,
QualType Ty) {
590 if (threadSafetyCheckIsSmartPointer(S, RT))
593 return checkRecordDeclForAttr<CapabilityAttr>(RT->
getDecl());
596 static bool checkTypedefTypeForCapability(
QualType Ty) {
605 return TN->
hasAttr<CapabilityAttr>();
609 if (checkTypedefTypeForCapability(Ty))
612 if (checkRecordTypeForCapability(S, Ty))
618 static bool isCapabilityExpr(
Sema &S,
const Expr *Ex) {
624 if (
const auto *E = dyn_cast<CastExpr>(Ex))
625 return isCapabilityExpr(S, E->getSubExpr());
626 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
627 return isCapabilityExpr(S, E->getSubExpr());
628 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
629 if (E->getOpcode() == UO_LNot || E->getOpcode() == UO_AddrOf ||
630 E->getOpcode() == UO_Deref)
631 return isCapabilityExpr(S, E->getSubExpr());
633 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
634 if (E->getOpcode() == BO_LAnd || E->getOpcode() == BO_LOr)
635 return isCapabilityExpr(S, E->getLHS()) &&
636 isCapabilityExpr(S, E->getRHS());
640 return typeHasCapability(S, Ex->
getType());
648 static void checkAttrArgsAreCapabilityObjs(
Sema &S,
Decl *D,
652 bool ParamIdxOk =
false) {
658 if (MD && !MD->isStatic()) {
661 if (!checkRecordDeclForAttr<CapabilityAttr>(RD) &&
662 !checkRecordDeclForAttr<ScopedLockableAttr>(RD))
664 diag::warn_thread_attribute_not_on_capability_member)
665 << AL << MD->getParent();
667 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_not_on_non_static_member)
672 for (
unsigned Idx = Sidx; Idx < AL.
getNumArgs(); ++Idx) {
677 Args.push_back(ArgExp);
681 if (
const auto *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
682 if (StrLit->getLength() == 0 ||
683 (StrLit->isAscii() && StrLit->getString() == StringRef(
"*"))) {
686 Args.push_back(ArgExp);
692 S.
Diag(AL.
getLoc(), diag::warn_thread_attribute_ignored) << AL;
693 Args.push_back(ArgExp);
701 if (
const auto *UOp = dyn_cast<UnaryOperator>(ArgExp))
702 if (UOp->getOpcode() == UO_AddrOf)
703 if (
const auto *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
704 if (DRE->getDecl()->isCXXInstanceMember())
705 ArgTy = DRE->getDecl()->getType();
711 if(!RT && ParamIdxOk) {
715 unsigned int NumParams = FD->getNumParams();
716 llvm::APInt ArgValue = IL->
getValue();
717 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
718 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
719 if (!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
720 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_range)
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)) {
1747 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
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)
2290 VersionTuple Introduced,
2291 VersionTuple Deprecated,
2292 VersionTuple Obsoleted,
2296 StringRef Replacement,
2297 AvailabilityMergeKind AMK,
2298 unsigned AttrSpellingListIndex) {
2299 VersionTuple MergedIntroduced = Introduced;
2300 VersionTuple MergedDeprecated = Deprecated;
2301 VersionTuple MergedObsoleted = Obsoleted;
2302 bool FoundAny =
false;
2303 bool OverrideOrImpl =
false;
2306 case AMK_Redeclaration:
2307 OverrideOrImpl =
false;
2311 case AMK_ProtocolImplementation:
2312 OverrideOrImpl =
true;
2318 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2319 const auto *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2326 if (OldPlatform != Platform) {
2334 if (!OldAA->isImplicit() && Implicit) {
2341 if (!Implicit && OldAA->isImplicit()) {
2342 Attrs.erase(Attrs.begin() + i);
2348 VersionTuple OldIntroduced = OldAA->getIntroduced();
2349 VersionTuple OldDeprecated = OldAA->getDeprecated();
2350 VersionTuple OldObsoleted = OldAA->getObsoleted();
2351 bool OldIsUnavailable = OldAA->getUnavailable();
2353 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2354 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2356 !(OldIsUnavailable == IsUnavailable ||
2357 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2358 if (OverrideOrImpl) {
2360 VersionTuple FirstVersion;
2361 VersionTuple SecondVersion;
2362 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2364 FirstVersion = OldIntroduced;
2365 SecondVersion = Introduced;
2366 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2368 FirstVersion = Deprecated;
2369 SecondVersion = OldDeprecated;
2370 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2372 FirstVersion = Obsoleted;
2373 SecondVersion = OldObsoleted;
2377 Diag(OldAA->getLocation(),
2378 diag::warn_mismatched_availability_override_unavail)
2379 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2380 << (AMK == AMK_Override);
2382 Diag(OldAA->getLocation(),
2383 diag::warn_mismatched_availability_override)
2385 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2386 << FirstVersion.getAsString() << SecondVersion.getAsString()
2387 << (AMK == AMK_Override);
2389 if (AMK == AMK_Override)
2394 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2398 Attrs.erase(Attrs.begin() + i);
2403 VersionTuple MergedIntroduced2 = MergedIntroduced;
2404 VersionTuple MergedDeprecated2 = MergedDeprecated;
2405 VersionTuple MergedObsoleted2 = MergedObsoleted;
2407 if (MergedIntroduced2.empty())
2408 MergedIntroduced2 = OldIntroduced;
2409 if (MergedDeprecated2.empty())
2410 MergedDeprecated2 = OldDeprecated;
2411 if (MergedObsoleted2.empty())
2412 MergedObsoleted2 = OldObsoleted;
2414 if (checkAvailabilityAttr(*
this, OldAA->getRange(), Platform,
2415 MergedIntroduced2, MergedDeprecated2,
2416 MergedObsoleted2)) {
2417 Attrs.erase(Attrs.begin() + i);
2422 MergedIntroduced = MergedIntroduced2;
2423 MergedDeprecated = MergedDeprecated2;
2424 MergedObsoleted = MergedObsoleted2;
2430 MergedIntroduced == Introduced &&
2431 MergedDeprecated == Deprecated &&
2432 MergedObsoleted == Obsoleted)
2437 if (!checkAvailabilityAttr(*
this, Range, Platform, MergedIntroduced,
2438 MergedDeprecated, MergedObsoleted) &&
2440 auto *Avail = ::new (Context) AvailabilityAttr(Range, Context, Platform,
2441 Introduced, Deprecated,
2442 Obsoleted, IsUnavailable, Message,
2443 IsStrict, Replacement,
2444 AttrSpellingListIndex);
2445 Avail->setImplicit(Implicit);
2458 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2459 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2472 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getMessageExpr()))
2473 Str = SE->getString();
2474 StringRef Replacement;
2476 Replacement = SE->getString();
2478 if (II->
isStr(
"swift")) {
2480 (!IsUnavailable && !Deprecated.
isValid())) {
2482 diag::warn_availability_swift_unavailable_deprecated_only);
2493 IsStrict, Replacement,
2505 else if (II->
getName() ==
"ios_app_extension")
2509 auto adjustWatchOSVersion = [](VersionTuple Version) -> VersionTuple {
2510 if (Version.empty())
2512 auto Major = Version.getMajor();
2513 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2514 if (NewMajor >= 2) {
2515 if (Version.getMinor().hasValue()) {
2516 if (Version.getSubminor().hasValue())
2517 return VersionTuple(NewMajor, Version.getMinor().getValue(),
2518 Version.getSubminor().getValue());
2520 return VersionTuple(NewMajor, Version.getMinor().getValue());
2524 return VersionTuple(2, 0);
2527 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2528 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2529 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2552 else if (II->
getName() ==
"ios_app_extension")
2574 static void handleExternalSourceSymbolAttr(
Sema &S,
Decl *D,
2579 "Invalid number of arguments in an external_source_symbol attribute");
2582 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(0)))
2583 Language = SE->getString();
2584 StringRef DefinedIn;
2585 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(AL.
getArgAsExpr(1)))
2586 DefinedIn = SE->getString();
2587 bool IsGeneratedDeclaration = AL.
getArgAsIdent(2) !=
nullptr;
2590 AL.
getRange(), S.
Context, Language, DefinedIn, IsGeneratedDeclaration,
2596 typename T::VisibilityType value,
2597 unsigned attrSpellingListIndex) {
2598 T *existingAttr = D->
getAttr<T>();
2600 typename T::VisibilityType existingValue = existingAttr->
getVisibility();
2601 if (existingValue == value)
2603 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2604 S.
Diag(range.
getBegin(), diag::note_previous_attribute);
2607 return ::new (S.
Context) T(range, S.
Context, value, attrSpellingListIndex);
2611 VisibilityAttr::VisibilityType Vis,
2612 unsigned AttrSpellingListIndex) {
2613 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, Range, Vis,
2614 AttrSpellingListIndex);
2618 TypeVisibilityAttr::VisibilityType Vis,
2619 unsigned AttrSpellingListIndex) {
2620 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, Range, Vis,
2621 AttrSpellingListIndex);
2625 bool isTypeVisibility) {
2627 if (isa<TypedefNameDecl>(D)) {
2633 if (isTypeVisibility &&
2634 !(isa<TagDecl>(D) ||
2635 isa<ObjCInterfaceDecl>(D) ||
2636 isa<NamespaceDecl>(D))) {
2648 VisibilityAttr::VisibilityType
type;
2649 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2650 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << AL
2657 if (type == VisibilityAttr::Protected &&
2659 S.
Diag(AL.
getLoc(), diag::warn_attribute_protected_visibility);
2665 if (isTypeVisibility) {
2667 (TypeVisibilityAttr::VisibilityType) type,
2677 const auto *M = cast<ObjCMethodDecl>(D);
2679 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2685 ObjCMethodFamilyAttr::FamilyKind F;
2686 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2687 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << AL << IL->
Ident;
2692 !M->getReturnType()->isObjCObjectPointerType()) {
2693 S.
Diag(M->getLocation(), diag::err_init_method_bad_return_type)
2694 << M->getReturnType();
2704 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2705 QualType T = TD->getUnderlyingType();
2707 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2711 else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
2714 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
2733 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
2734 QualType T = TD->getUnderlyingType();
2736 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2750 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2756 BlocksAttr::BlockType
type;
2757 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
2758 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
2768 unsigned sentinel = (unsigned)SentinelAttr::DefaultSentinel;
2771 llvm::APSInt Idx(32);
2774 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2779 if (Idx.isSigned() && Idx.isNegative()) {
2780 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2785 sentinel = Idx.getZExtValue();
2788 unsigned nullPos = (unsigned)SentinelAttr::DefaultNullPos;
2791 llvm::APSInt Idx(32);
2794 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
2798 nullPos = Idx.getZExtValue();
2800 if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2803 S.
Diag(AL.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2809 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2811 if (isa<FunctionNoProtoType>(FT)) {
2812 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2816 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2817 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2820 }
else if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
2822 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2825 }
else if (
const auto *BD = dyn_cast<BlockDecl>(D)) {
2826 if (!BD->isVariadic()) {
2827 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2830 }
else if (
const auto *V = dyn_cast<VarDecl>(D)) {
2836 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2838 S.
Diag(AL.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2842 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2847 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2859 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 0;
2862 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
2864 S.
Diag(AL.
getLoc(), diag::warn_attribute_void_function_method) << AL << 1;
2872 S.
Diag(AL.
getLoc(), diag::ext_cxx17_attr) << AL;
2884 S.
Diag(AL.
getLoc(), diag::warn_attribute_invalid_on_definition)
2886 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
2888 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
2891 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
2903 template <
typename WorkGroupAttr>
2906 for (
unsigned i = 0; i < 3; ++i) {
2911 if (WGSize[i] == 0) {
2912 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2918 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
2919 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2920 Existing->getYDim() == WGSize[1] &&
2921 Existing->getZDim() == WGSize[2]))
2922 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2925 WGSize[0], WGSize[1], WGSize[2],
2936 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_is_zero)
2941 OpenCLIntelReqdSubGroupSizeAttr *Existing =
2942 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
2943 if (Existing && Existing->getSubGroupSize() != SGSize)
2944 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2953 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
2959 assert(ParmTSI &&
"no type source info for attribute argument");
2964 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_vec_type_hint)
2969 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
2971 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
2983 unsigned AttrSpellingListIndex) {
2986 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2987 if (AttrSpellingListIndex == SectionAttr::Declspec_allocate &&
2991 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
2992 if (ExistingAttr->getName() == Name)
2994 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
2999 return ::new (Context) SectionAttr(Range, Context, Name,
3000 AttrSpellingListIndex);
3005 if (!Error.empty()) {
3006 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error
3026 if (!Error.empty()) {
3027 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3038 static bool checkCodeSegName(
Sema&S,
SourceLocation LiteralLoc, StringRef CodeSegName) {
3040 if (!Error.empty()) {
3041 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) << Error
3050 unsigned AttrSpellingListIndex) {
3053 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3057 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3058 if (ExistingAttr->getName() == Name)
3060 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section)
3065 return ::new (Context) CodeSegAttr(Range, Context, Name,
3066 AttrSpellingListIndex);
3074 if (!checkCodeSegName(S, LiteralLoc, Str))
3076 if (
const auto *ExistingAttr = D->
getAttr<CodeSegAttr>()) {
3077 if (!ExistingAttr->isImplicit()) {
3079 ExistingAttr->getName() == Str
3080 ? diag::warn_duplicate_codeseg_attribute
3081 : diag::err_conflicting_codeseg_attribute);
3095 enum SecondParam { None, Architecture };
3096 for (
auto Str : {
"tune=",
"fpmath="})
3097 if (AttrStr.find(Str) != StringRef::npos)
3098 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3101 TargetAttr::ParsedTargetAttr ParsedAttrs = TargetAttr::parse(AttrStr);
3103 if (!ParsedAttrs.Architecture.empty() &&
3105 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3106 <<
Unsupported << Architecture << ParsedAttrs.Architecture;
3108 if (ParsedAttrs.DuplicateArchitecture)
3109 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3110 << Duplicate << None <<
"arch=";
3112 for (
const auto &Feature : ParsedAttrs.Features) {
3113 auto CurFeature = StringRef(Feature).drop_front();
3115 return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
3130 TargetAttr *NewAttr =
3143 MinVectorWidthAttr *Existing = D->
getAttr<MinVectorWidthAttr>();
3144 if (Existing && Existing->getVectorWidth() != VecWidth) {
3145 S.
Diag(AL.
getLoc(), diag::warn_duplicate_attribute) << AL;
3162 if (
auto *DRE = dyn_cast<DeclRefExpr>(E)) {
3163 if (DRE->hasQualifier())
3164 S.
Diag(Loc, diag::warn_cleanup_ext);
3166 NI = DRE->getNameInfo();
3168 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3172 }
else if (
auto *ULE = dyn_cast<UnresolvedLookupExpr>(E)) {
3173 if (ULE->hasExplicitTemplateArgs())
3174 S.
Diag(Loc, diag::warn_cleanup_ext);
3176 NI = ULE->getNameInfo();
3178 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3185 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3190 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3201 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3202 << NI.
getName() << ParamTy << Ty;
3211 static void handleEnumExtensibilityAttr(
Sema &S,
Decl *D,
3214 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3221 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3222 ExtensibilityKind)) {
3223 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << II;
3244 if (NotNSStringTy &&
3248 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3258 S.
Diag(AL.
getLoc(), diag::err_format_attribute_result_not)
3259 << (NotNSStringTy ?
"string type" :
"NSString")
3268 enum FormatAttrKind {
3279 static FormatAttrKind getFormatAttrKind(StringRef Format) {
3280 return llvm::StringSwitch<FormatAttrKind>(Format)
3282 .Case(
"NSString", NSStringFormat)
3283 .Case(
"CFString", CFStringFormat)
3284 .Case(
"strftime", StrftimeFormat)
3287 .Cases(
"scanf",
"printf",
"printf0",
"strfmon", SupportedFormat)
3288 .Cases(
"cmn_err",
"vcmn_err",
"zcmn_err", SupportedFormat)
3289 .Case(
"kprintf", SupportedFormat)
3290 .Case(
"freebsd_kprintf", SupportedFormat)
3291 .Case(
"os_trace", SupportedFormat)
3292 .Case(
"os_log", SupportedFormat)
3294 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag", IgnoredFormat)
3295 .Default(InvalidFormat);
3302 S.
Diag(AL.
getLoc(), diag::warn_attribute_ignored) << AL;
3307 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3311 QualType T = cast<VarDecl>(D)->getType();
3315 S.
Diag(AL.
getLoc(), diag::err_init_priority_object_attr);
3321 uint32_t prioritynum;
3327 if (prioritynum < 101 || prioritynum > 65535) {
3328 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_outof_range)
3341 unsigned AttrSpellingListIndex) {
3344 if (F->getType() == Format &&
3345 F->getFormatIdx() == FormatIdx &&
3346 F->getFirstArg() == FirstArg) {
3349 if (F->getLocation().isInvalid())
3355 return ::new (Context) FormatAttr(Range, Context, Format, FormatIdx,
3356 FirstArg, AttrSpellingListIndex);
3363 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
3374 StringRef Format = II->
getName();
3376 if (normalizeName(Format)) {
3382 FormatAttrKind
Kind = getFormatAttrKind(Format);
3384 if (Kind == IgnoredFormat)
3387 if (Kind == InvalidFormat) {
3388 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
3399 if (Idx < 1 || Idx > NumArgs) {
3400 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3406 unsigned ArgIdx = Idx - 1;
3408 if (HasImplicitThisParam) {
3411 diag::err_format_attribute_implicit_this_format_string)
3421 if (Kind == CFStringFormat) {
3423 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3428 }
else if (Kind == NSStringFormat) {
3432 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3439 S.
Diag(AL.
getLoc(), diag::err_format_attribute_not)
3452 if (FirstArg != 0) {
3456 S.
Diag(D->
getLocation(), diag::err_format_attribute_requires_variadic);
3463 if (Kind == StrftimeFormat) {
3464 if (FirstArg != 0) {
3465 S.
Diag(AL.
getLoc(), diag::err_format_strftime_third_parameter)
3470 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
3471 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3487 if (TD && TD->getUnderlyingType()->isUnionType())
3488 RD = TD->getUnderlyingType()->getAsUnionType()->getDecl();
3493 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type) << AL
3501 diag::warn_transparent_union_attribute_not_definition);
3507 if (Field == FieldEnd) {
3508 S.
Diag(AL.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3516 diag::warn_transparent_union_attribute_floating)
3525 for (; Field != FieldEnd; ++Field) {
3526 QualType FieldType = Field->getType();
3540 S.
Diag(Field->getLocation(),
3541 diag::warn_transparent_union_attribute_field_size_align)
3542 << isSize << Field->getDeclName() << FieldBits;
3543 unsigned FirstBits = isSize? FirstSize : FirstAlign;
3545 diag::note_transparent_union_first_field_size_align)
3546 << isSize << FirstBits;
3565 if (I->getAnnotation() == Str)
3580 unsigned SpellingListIndex) {
3581 AlignValueAttr TmpAttr(AttrRange, Context, E, SpellingListIndex);
3585 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
3586 T = TD->getUnderlyingType();
3587 else if (
const auto *VD = dyn_cast<ValueDecl>(D))
3590 llvm_unreachable(
"Unknown decl type for align_value");
3594 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
3600 llvm::APSInt Alignment;
3602 = VerifyIntegerConstantExpression(E, &Alignment,
3603 diag::err_align_value_attribute_argument_not_int,
3608 if (!Alignment.isPowerOf2()) {
3609 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3615 AlignValueAttr(AttrRange, Context, ICE.
get(),
3616 SpellingListIndex));
3621 D->
addAttr(::
new (Context) AlignValueAttr(TmpAttr));
3627 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_number_arguments) << AL << 1;
3640 diag::err_pack_expansion_without_parameter_packs);
3652 unsigned SpellingListIndex,
bool IsPackExpansion) {
3653 AlignedAttr TmpAttr(AttrRange, Context,
true, E, SpellingListIndex);
3657 if (TmpAttr.isAlignas()) {
3670 if (isa<ParmVarDecl>(D)) {
3672 }
else if (
const auto *VD = dyn_cast<VarDecl>(D)) {
3675 if (VD->isExceptionVariable())
3677 }
else if (
const auto *FD = dyn_cast<FieldDecl>(D)) {
3678 if (FD->isBitField())
3680 }
else if (!isa<TagDecl>(D)) {
3681 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
3686 if (DiagKind != -1) {
3687 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
3688 << &TmpAttr << DiagKind;
3697 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
3698 if (!TND->getUnderlyingType()->isDependentType()) {
3699 Diag(AttrLoc, diag::err_alignment_dependent_typedef_name)
3706 AlignedAttr *AA = ::new (Context) AlignedAttr(TmpAttr);
3707 AA->setPackExpansion(IsPackExpansion);
3713 llvm::APSInt Alignment;
3715 = VerifyIntegerConstantExpression(E, &Alignment,
3716 diag::err_aligned_attribute_argument_not_int,
3721 uint64_t AlignVal = Alignment.getZExtValue();
3728 if (!(TmpAttr.isAlignas() && !Alignment)) {
3729 if (!llvm::isPowerOf2_64(AlignVal)) {
3730 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3737 unsigned MaxValidAlignment =
3740 if (AlignVal > MaxValidAlignment) {
3741 Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
3747 unsigned MaxTLSAlign =
3750 const auto *VD = dyn_cast<
VarDecl>(D);
3751 if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
3753 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
3754 << (
unsigned)AlignVal << VD << MaxTLSAlign;
3759 AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context,
true,
3760 ICE.
get(), SpellingListIndex);
3761 AA->setPackExpansion(IsPackExpansion);
3766 unsigned SpellingListIndex,
bool IsPackExpansion) {
3769 AlignedAttr *AA = ::new (Context) AlignedAttr(AttrRange, Context,
false, TS,
3771 AA->setPackExpansion(IsPackExpansion);
3776 assert(D->
hasAttrs() &&
"no attributes on decl");
3779 if (
const auto *VD = dyn_cast<ValueDecl>(D)) {
3780 UnderlyingTy = DiagTy = VD->getType();
3782 UnderlyingTy = DiagTy = Context.
getTagDeclType(cast<TagDecl>(D));
3783 if (
const auto *ED = dyn_cast<EnumDecl>(D))
3784 UnderlyingTy = ED->getIntegerType();
3786 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
3793 AlignedAttr *AlignasAttr =
nullptr;
3796 if (I->isAlignmentDependent())
3800 Align =
std::max(Align, I->getAlignment(Context));
3803 if (AlignasAttr && Align) {
3806 if (NaturalAlign > RequestedAlign)
3807 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
3808 << DiagTy << (
unsigned)NaturalAlign.
getQuantity();
3814 MSInheritanceAttr::Spelling SemanticSpelling) {
3823 if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance)
3834 Diag(Range.
getBegin(), diag::err_mismatched_ms_inheritance)
3843 static void parseModeAttrArg(
Sema &S, StringRef Str,
unsigned &DestWidth,
3844 bool &IntegerMode,
bool &ComplexMode) {
3846 ComplexMode =
false;
3847 switch (Str.size()) {
3869 if (Str[1] ==
'F') {
3870 IntegerMode =
false;
3871 }
else if (Str[1] ==
'C') {
3872 IntegerMode =
false;
3874 }
else if (Str[1] !=
'I') {
3883 else if (Str ==
"byte")
3887 if (Str ==
"pointer")
3891 if (Str ==
"unwind_word")
3907 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
3918 unsigned SpellingListIndex,
bool InInstantiation) {
3919 StringRef Str = Name->
getName();
3923 unsigned DestWidth = 0;
3924 bool IntegerMode =
true;
3925 bool ComplexMode =
false;
3926 llvm::APInt VectorSize(64, 0);
3927 if (Str.size() >= 4 && Str[0] ==
'V') {
3929 size_t StrSize = Str.size();
3930 size_t VectorStringLength = 0;
3931 while ((VectorStringLength + 1) < StrSize &&
3932 isdigit(Str[VectorStringLength + 1]))
3933 ++VectorStringLength;
3934 if (VectorStringLength &&
3935 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
3936 VectorSize.isPowerOf2()) {
3937 parseModeAttrArg(*
this, Str.substr(VectorStringLength + 1), DestWidth,
3938 IntegerMode, ComplexMode);
3940 if (!InInstantiation)
3941 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
3948 parseModeAttrArg(*
this, Str, DestWidth, IntegerMode, ComplexMode);
3955 Diag(AttrLoc, diag::err_machine_mode) << 0 << Name;
3960 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D))
3961 OldTy = TD->getUnderlyingType();
3962 else if (
const auto *ED = dyn_cast<EnumDecl>(D)) {
3965 OldTy = ED->getIntegerType();
3967 OldTy = Context.
IntTy;
3969 OldTy = cast<ValueDecl>(D)->getType();
3973 ModeAttr(AttrRange, Context, Name, SpellingListIndex));
3981 OldElemTy = VT->getElementType();
3987 VectorSize.getBoolValue()) {
3988 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << AttrRange;
3991 bool IntegralOrAnyEnumType =
3995 !IntegralOrAnyEnumType)
3996 Diag(AttrLoc, diag::err_mode_not_primitive);
3997 else if (IntegerMode) {
3998 if (!IntegralOrAnyEnumType)
3999 Diag(AttrLoc, diag::err_mode_wrong_type);
4000 }
else if (ComplexMode) {
4002 Diag(AttrLoc, diag::err_mode_wrong_type);
4005 Diag(AttrLoc, diag::err_mode_wrong_type);
4016 if (NewElemTy.
isNull()) {
4017 Diag(AttrLoc, diag::err_machine_mode) << 1 << Name;
4026 if (VectorSize.getBoolValue()) {
4027 NewTy = Context.
getVectorType(NewTy, VectorSize.getZExtValue(),
4032 Diag(AttrLoc, diag::err_complex_mode_vector_type);
4035 unsigned NumElements = Context.
getTypeSize(OldElemTy) *
4036 OldVT->getNumElements() /
4039 Context.
getVectorType(NewElemTy, NumElements, OldVT->getVectorKind());
4043 Diag(AttrLoc, diag::err_mode_wrong_type);
4048 if (
auto *TD = dyn_cast<TypedefNameDecl>(D))
4049 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
4050 else if (
auto *ED = dyn_cast<EnumDecl>(D))
4051 ED->setIntegerType(NewTy);
4053 cast<ValueDecl>(D)->setType(NewTy);
4056 ModeAttr(AttrRange, Context, Name, SpellingListIndex));
4067 unsigned AttrSpellingListIndex) {
4068 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4069 Diag(Range.
getBegin(), diag::warn_attribute_ignored) << Ident;
4070 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4074 if (D->
hasAttr<AlwaysInlineAttr>())
4077 return ::new (Context) AlwaysInlineAttr(Range, Context,
4078 AttrSpellingListIndex);
4082 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4085 return ::new (Context)
4090 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, AL))
4093 return ::new (Context)
4094 CommonAttr(AL.getRange(), Context, AL.getSpellingListIndex());
4099 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4102 if (VD->getKind() != Decl::Var) {
4103 Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4109 if (VD->hasLocalStorage()) {
4110 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4115 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4118 return ::new (Context) InternalLinkageAttr(
4121 InternalLinkageAttr *
4123 if (
const auto *VD = dyn_cast<VarDecl>(D)) {
4126 if (VD->getKind() != Decl::Var) {
4127 Diag(AL.getLocation(), diag::warn_attribute_wrong_decl_type)
4133 if (VD->hasLocalStorage()) {
4134 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
4139 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, AL))
4142 return ::new (Context)
4143 InternalLinkageAttr(AL.getRange(), Context, AL.getSpellingListIndex());
4147 unsigned AttrSpellingListIndex) {
4148 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4149 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'minsize'";
4150 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4154 if (D->
hasAttr<MinSizeAttr>())
4157 return ::new (Context) MinSizeAttr(Range, Context, AttrSpellingListIndex);
4161 unsigned AttrSpellingListIndex) {
4162 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4163 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4164 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4167 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4168 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4169 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4173 if (D->
hasAttr<OptimizeNoneAttr>())
4176 return ::new (Context) OptimizeNoneAttr(Range, Context,
4177 AttrSpellingListIndex);
4181 if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, AL))
4203 if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, AL))
4205 const auto *VD = cast<VarDecl>(D);
4206 if (!VD->hasGlobalStorage()) {
4207 S.
Diag(AL.
getLoc(), diag::err_cuda_nonglobal_constant);
4215 if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, AL))
4217 const auto *VD = cast<VarDecl>(D);
4220 if (!S.
getLangOpts().GPURelocatableDeviceCode && VD->hasExternalStorage() &&
4221 !isa<IncompleteArrayType>(VD->getType())) {
4222 S.
Diag(AL.
getLoc(), diag::err_cuda_extern_shared) << VD;
4225 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4234 if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, AL) ||
4235 checkAttrMutualExclusion<CUDAHostAttr>(S, D, AL)) {
4238 const auto *FD = cast<FunctionDecl>(D);
4247 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4248 if (Method->isInstance()) {
4249 S.
Diag(Method->getBeginLoc(), diag::err_kern_is_nonstatic_method)
4253 S.
Diag(Method->getBeginLoc(), diag::warn_kern_is_method) << Method;
4265 const auto *Fn = cast<FunctionDecl>(D);
4266 if (!Fn->isInlineSpecified()) {
4267 S.
Diag(AL.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4285 if (!isa<ObjCMethodDecl>(D)) {
4286 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
4292 case ParsedAttr::AT_FastCall:
4297 case ParsedAttr::AT_StdCall:
4302 case ParsedAttr::AT_ThisCall:
4307 case ParsedAttr::AT_CDecl:
4312 case ParsedAttr::AT_Pascal:
4317 case ParsedAttr::AT_SwiftCall:
4322 case ParsedAttr::AT_VectorCall:
4327 case ParsedAttr::AT_MSABI:
4332 case ParsedAttr::AT_SysVABI:
4337 case ParsedAttr::AT_RegCall:
4341 case ParsedAttr::AT_Pcs: {
4342 PcsAttr::PCSType PCS;
4345 PCS = PcsAttr::AAPCS;
4348 PCS = PcsAttr::AAPCS_VFP;
4351 llvm_unreachable(
"unexpected calling convention in pcs attribute");
4359 case ParsedAttr::AT_AArch64VectorPcs:
4364 case ParsedAttr::AT_IntelOclBicc:
4369 case ParsedAttr::AT_PreserveMost:
4373 case ParsedAttr::AT_PreserveAll:
4378 llvm_unreachable(
"unexpected attribute kind");
4386 std::vector<StringRef> DiagnosticIdentifiers;
4387 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
4395 DiagnosticIdentifiers.push_back(RuleName);
4412 unsigned ReqArgs = Attrs.
getKind() == ParsedAttr::AT_Pcs ? 1 : 0;
4420 case ParsedAttr::AT_CDecl:
4423 case ParsedAttr::AT_FastCall:
4426 case ParsedAttr::AT_StdCall:
4429 case ParsedAttr::AT_ThisCall:
4432 case ParsedAttr::AT_Pascal:
4435 case ParsedAttr::AT_SwiftCall:
4438 case ParsedAttr::AT_VectorCall:
4441 case ParsedAttr::AT_AArch64VectorPcs:
4444 case ParsedAttr::AT_RegCall:
4447 case ParsedAttr::AT_MSABI:
4451 case ParsedAttr::AT_SysVABI:
4455 case ParsedAttr::AT_Pcs: {
4457 if (!checkStringLiteralArgumentAttr(Attrs, 0, StrRef)) {
4461 if (StrRef ==
"aapcs") {
4464 }
else if (StrRef ==
"aapcs-vfp") {
4473 case ParsedAttr::AT_IntelOclBicc:
4476 case ParsedAttr::AT_PreserveMost:
4479 case ParsedAttr::AT_PreserveAll:
4482 default: llvm_unreachable(
"unexpected attribute kind");
4489 Diag(Attrs.
getLoc(), diag::warn_cconv_ignored) << Attrs;
4493 bool IsCXXMethod =
false, IsVariadic =
false;
4506 static bool isValidSwiftContextType(
QualType Ty) {
4513 static bool isValidSwiftIndirectResultType(
QualType Ty) {
4525 static bool isValidSwiftErrorResultType(
QualType Ty) {
4535 return isValidSwiftContextType(Ty);
4545 unsigned spellingIndex) {
4550 if (existingAttr->getABI() != abi) {
4551 Diag(range.
getBegin(), diag::err_attributes_are_not_compatible)
4553 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute);
4560 llvm_unreachable(
"explicit attribute for ordinary parameter ABI?");
4563 if (!isValidSwiftContextType(type)) {
4564 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4569 SwiftContextAttr(range, Context, spellingIndex));
4573 if (!isValidSwiftErrorResultType(type)) {
4574 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4579 SwiftErrorResultAttr(range, Context, spellingIndex));
4583 if (!isValidSwiftIndirectResultType(type)) {
4584 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4589 SwiftIndirectResultAttr(range, Context, spellingIndex));
4592 llvm_unreachable(
"bad parameter ABI attribute");
4614 Diag(AL.
getLoc(), diag::err_attribute_regparm_wrong_platform)
4622 Diag(AL.
getLoc(), diag::err_attribute_regparm_invalid_number)
4636 const CUDALaunchBoundsAttr &AL,
4637 const unsigned Idx) {
4653 if (!I.isIntN(32)) {
4654 S.
Diag(E->
getExprLoc(), diag::err_ice_too_large) << I.toString(10,
false)
4659 S.
Diag(E->
getExprLoc(), diag::warn_attribute_argument_n_negative)
4666 assert(!ValArg.isInvalid() &&
4667 "Unexpected PerformCopyInitialization() failure.");
4673 Expr *MinBlocks,
unsigned SpellingListIndex) {
4674 CUDALaunchBoundsAttr TmpAttr(AttrRange, Context, MaxThreads, MinBlocks,
4676 MaxThreads = makeLaunchBoundsArgExpr(*
this, MaxThreads, TmpAttr, 0);
4677 if (MaxThreads ==
nullptr)
4681 MinBlocks = makeLaunchBoundsArgExpr(*
this, MinBlocks, TmpAttr, 1);
4682 if (MinBlocks ==
nullptr)
4686 D->
addAttr(::
new (Context) CUDALaunchBoundsAttr(
4687 AttrRange, Context, MaxThreads, MinBlocks, SpellingListIndex));
4700 static void handleArgumentWithTypeTagAttr(
Sema &S,
Decl *D,
4703 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4718 bool IsPointer = AL.
getName()->
getName() ==
"pointer_with_type_tag";
4721 unsigned ArgumentIdxAST = ArgumentIdx.
getASTIndex();
4724 S.
Diag(AL.
getLoc(), diag::err_attribute_pointers_only) << AL << 0;
4732 static void handleTypeTagForDatatypeAttr(
Sema &S,
Decl *D,
4735 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
4743 if (!isa<VarDecl>(D)) {
4744 S.
Diag(AL.
getLoc(), diag::err_attribute_wrong_decl_type)
4752 assert(MatchingCTypeLoc &&
"no type source info for attribute argument");
4779 static bool isValidSubjectOfNSReturnsRetainedAttribute(
QualType QT) {
4783 static bool isValidSubjectOfNSAttribute(
QualType QT) {
4788 static bool isValidSubjectOfCFAttribute(
QualType QT) {
4790 isValidSubjectOfNSAttribute(QT);
4793 static bool isValidSubjectOfOSAttribute(
QualType QT) {
4801 RetainOwnershipKind K,
4802 bool IsTemplateInstantiation) {
4805 case RetainOwnershipKind::OS:
4806 handleSimpleAttributeOrDiagnose<OSConsumedAttr>(
4807 *
this, VD, SR, SpellingIndex, isValidSubjectOfOSAttribute(VD->getType()),
4808 diag::warn_ns_attribute_wrong_parameter_type,
4809 SR,
"os_consumed", 1);
4811 case RetainOwnershipKind::NS:
4812 handleSimpleAttributeOrDiagnose<NSConsumedAttr>(
4813 *
this, VD, SR, SpellingIndex, isValidSubjectOfNSAttribute(VD->getType()),
4819 ((IsTemplateInstantiation && getLangOpts().ObjCAutoRefCount)
4820 ? diag::err_ns_attribute_wrong_parameter_type
4821 : diag::warn_ns_attribute_wrong_parameter_type),
4822 SR,
"ns_consumed", 0);
4824 case RetainOwnershipKind::CF:
4825 handleSimpleAttributeOrDiagnose<CFConsumedAttr>(
4826 *
this, VD, SR, SpellingIndex,
4827 isValidSubjectOfCFAttribute(VD->getType()),
4828 diag::warn_ns_attribute_wrong_parameter_type,
4829 SR,
"cf_consumed", 1);
4835 parsedAttrToRetainOwnershipKind(
const ParsedAttr &AL) {
4837 case ParsedAttr::AT_CFConsumed:
4838 case ParsedAttr::AT_CFReturnsRetained:
4839 case ParsedAttr::AT_CFReturnsNotRetained:
4841 case ParsedAttr::AT_OSConsumesThis:
4842 case ParsedAttr::AT_OSConsumed:
4843 case ParsedAttr::AT_OSReturnsRetained:
4844 case ParsedAttr::AT_OSReturnsNotRetained:
4845 case ParsedAttr::AT_OSReturnsRetainedOnZero:
4846 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
4848 case ParsedAttr::AT_NSConsumesSelf:
4849 case ParsedAttr::AT_NSConsumed:
4850 case ParsedAttr::AT_NSReturnsRetained:
4851 case ParsedAttr::AT_NSReturnsNotRetained:
4852 case ParsedAttr::AT_NSReturnsAutoreleased:
4855 llvm_unreachable(
"Wrong argument supplied");
4860 if (isValidSubjectOfNSReturnsRetainedAttribute(QT))
4863 Diag(Loc, diag::warn_ns_attribute_wrong_return_type)
4864 <<
"'ns_returns_retained'" << 0 << 0;
4869 static bool isValidOSObjectOutParameter(
const Decl *D) {
4875 return !PT.
isNull() && isValidSubjectOfOSAttribute(PT);
4878 static void handleXReturnsXRetainedAttr(
Sema &S,
Decl *D,
4883 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
4886 (AL.
getKind() == ParsedAttr::AT_NSReturnsRetained)) {
4888 }
else if (
const auto *PD = dyn_cast<ObjCPropertyDecl>(D)) {
4889 ReturnType = PD->getType();
4890 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
4892 }
else if (
const auto *Param = dyn_cast<ParmVarDecl>(D)) {
4899 if (ReturnType.
isNull()) {
4900 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
4909 default: llvm_unreachable(
"invalid ownership attribute");
4910 case ParsedAttr::AT_NSReturnsRetained:
4911 case ParsedAttr::AT_NSReturnsAutoreleased:
4912 case ParsedAttr::AT_NSReturnsNotRetained:
4916 case ParsedAttr::AT_OSReturnsRetained:
4917 case ParsedAttr::AT_OSReturnsNotRetained:
4918 case ParsedAttr::AT_CFReturnsRetained:
4919 case ParsedAttr::AT_CFReturnsNotRetained:
4924 << AL.
getRange() << AL << ExpectedDeclKind;
4930 unsigned ParmDiagID = 2;
4932 default: llvm_unreachable(
"invalid ownership attribute");
4933 case ParsedAttr::AT_NSReturnsRetained:
4934 TypeOK = isValidSubjectOfNSReturnsRetainedAttribute(ReturnType);
4938 case ParsedAttr::AT_NSReturnsAutoreleased:
4939 case ParsedAttr::AT_NSReturnsNotRetained:
4940 TypeOK = isValidSubjectOfNSAttribute(ReturnType);
4944 case ParsedAttr::AT_CFReturnsRetained:
4945 case ParsedAttr::AT_CFReturnsNotRetained:
4946 TypeOK = isValidSubjectOfCFAttribute(ReturnType);
4950 case ParsedAttr::AT_OSReturnsRetained:
4951 case ParsedAttr::AT_OSReturnsNotRetained:
4952 TypeOK = isValidSubjectOfOSAttribute(ReturnType);
4962 if (isa<ParmVarDecl>(D)) {
4963 S.
Diag(D->
getBeginLoc(), diag::warn_ns_attribute_wrong_parameter_type)
4964 << AL << ParmDiagID << AL.
getRange();
4971 } SubjectKind = Function;
4972 if (isa<ObjCMethodDecl>(D))
4973 SubjectKind = Method;
4974 else if (isa<ObjCPropertyDecl>(D))
4977 << AL << SubjectKind << Cf << AL.
getRange();
4984 llvm_unreachable(
"invalid ownership attribute");
4985 case ParsedAttr::AT_NSReturnsAutoreleased:
4986 handleSimpleAttribute<NSReturnsAutoreleasedAttr>(S, D, AL);
4988 case ParsedAttr::AT_CFReturnsNotRetained:
4989 handleSimpleAttribute<CFReturnsNotRetainedAttr>(S, D, AL);
4991 case ParsedAttr::AT_NSReturnsNotRetained:
4992 handleSimpleAttribute<NSReturnsNotRetainedAttr>(S, D, AL);
4994 case ParsedAttr::AT_CFReturnsRetained:
4995 handleSimpleAttribute<CFReturnsRetainedAttr>(S, D, AL);
4997 case ParsedAttr::AT_NSReturnsRetained:
4998 handleSimpleAttribute<NSReturnsRetainedAttr>(S, D, AL);
5000 case ParsedAttr::AT_OSReturnsRetained:
5001 handleSimpleAttribute<OSReturnsRetainedAttr>(S, D, AL);
5003 case ParsedAttr::AT_OSReturnsNotRetained:
5004 handleSimpleAttribute<OSReturnsNotRetainedAttr>(S, D, AL);
5009 static void handleObjCReturnsInnerPointerAttr(
Sema &S,
Decl *D,
5011 const int EP_ObjCMethod = 1;
5012 const int EP_ObjCProperty = 2;
5016 if (isa<ObjCMethodDecl>(D))
5017 resultType = cast<ObjCMethodDecl>(D)->getReturnType();
5019 resultType = cast<ObjCPropertyDecl>(D)->getType();
5025 << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
5036 static void handleObjCRequiresSuperAttr(
Sema &S,
Decl *D,
5038 const auto *Method = cast<ObjCMethodDecl>(D);
5041 if (
const auto *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
5042 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5044 S.
Diag(PDecl->getLocation(), diag::note_protocol_decl);
5048 S.
Diag(D->
getBeginLoc(), diag::warn_objc_requires_super_protocol) << Attrs
5066 if (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
5068 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_id) << AL;
5073 QualType T = TD->getUnderlyingType();
5075 S.
Diag(AL.
getLoc(), diag::err_objc_attr_typedef_not_void_pointer);
5085 static void handleObjCBridgeMutableAttr(
Sema &S,
Decl *D,
5099 static void handleObjCBridgeRelatedAttr(
Sema &S,
Decl *D,
5103 if (!RelatedClass) {
5113 ClassMethod, InstanceMethod,
5117 static void handleObjCDesignatedInitializer(
Sema &S,
Decl *D,
5120 if (
auto *CatDecl = dyn_cast<ObjCCategoryDecl>(D->
getDeclContext()))
5121 IFace = CatDecl->getClassInterface();
5135 StringRef MetaDataName;
5149 bool notify =
false;
5158 ObjCBoxableAttr *BoxableAttr = ::new (S.
Context)
5166 L->AddedAttributeToRecord(BoxableAttr, RD);
5178 static void handleObjCPreciseLifetimeAttr(
Sema &S,
Decl *D,
5180 const auto *VD = cast<ValueDecl>(D);
5183 if (!QT->isDependentType() &&
5184 !QT->isObjCLifetimeType()) {
5185 S.
Diag(AL.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
5195 Lifetime = QT->getObjCARCImplicitLifetime();
5199 assert(QT->isDependentType() &&
5200 "didn't infer lifetime for non-dependent type?");
5209 S.
Diag(AL.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
5224 unsigned AttrSpellingListIndex, StringRef Uuid) {
5225 if (
const auto *UA = D->
getAttr<UuidAttr>()) {
5226 if (UA->getGuid().equals_lower(Uuid))
5228 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5233 return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex);
5238 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5250 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
5251 StrRef = StrRef.drop_front().drop_back();
5254 if (StrRef.size() != 36) {
5255 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5259 for (
unsigned i = 0; i < 36; ++i) {
5260 if (i == 8 || i == 13 || i == 18 || i == 23) {
5261 if (StrRef[i] !=
'-') {
5262 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5266 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5278 S.
Diag(AL.
getLoc(), diag::warn_atl_uuid_deprecated);
5288 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5303 const auto *VD = cast<VarDecl>(D);
5305 S.
Diag(AL.
getLoc(), diag::err_thread_unsupported);
5309 S.
Diag(AL.
getLoc(), diag::err_declspec_thread_on_thread_variable);
5312 if (VD->hasLocalStorage()) {
5313 S.
Diag(AL.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
5322 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
5326 Tags.push_back(Tag);
5329 if (
const auto *NS = dyn_cast<NamespaceDecl>(D)) {
5330 if (!NS->isInline()) {
5331 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5334 if (NS->isAnonymousNamespace()) {
5335 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5339 Tags.push_back(NS->getName());
5345 Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
5355 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5367 ARMInterruptAttr::InterruptType
Kind;
5368 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5369 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5405 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5411 llvm::APSInt NumParams(32);
5413 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5419 unsigned Num = NumParams.getLimitedValue(255);
5421 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5422 << AL << (
int)NumParams.getSExtValue()
5436 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5475 if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL))
5478 MipsInterruptAttr::InterruptType
Kind;
5479 if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5480 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
5481 << AL <<
"'" + std::string(Str) +
"'";
5498 cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
5499 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5506 diag::err_anyx86_interrupt_attribute)
5515 if (NumParams < 1 || NumParams > 2) {
5526 diag::err_anyx86_interrupt_attribute)
5538 if (NumParams == 2 &&
5542 diag::err_anyx86_interrupt_attribute)
5564 handleSimpleAttribute<AVRInterruptAttr>(S, D, AL);
5577 handleSimpleAttribute<AVRSignalAttr>(S, D, AL);
5581 static void handleRISCVInterruptAttr(
Sema &S,
Decl *D,
5584 if (
const auto *A = D->
getAttr<RISCVInterruptAttr>()) {
5586 diag::warn_riscv_repeated_interrupt_attribute);
5587 S.
Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute);
5627 RISCVInterruptAttr::InterruptType
Kind;
5628 if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5629 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5641 case llvm::Triple::msp430:
5642 handleMSP430InterruptAttr(S, D, AL);
5644 case llvm::Triple::mipsel:
5645 case llvm::Triple::mips:
5646 handleMipsInterruptAttr(S, D, AL);
5648 case llvm::Triple::x86:
5649 case llvm::Triple::x86_64:
5650 handleAnyX86InterruptAttr(S, D, AL);
5652 case llvm::Triple::avr:
5653 handleAVRInterruptAttr(S, D, AL);
5655 case llvm::Triple::riscv32:
5656 case llvm::Triple::riscv64:
5657 handleRISCVInterruptAttr(S, D, AL);
5660 handleARMInterruptAttr(S, D, AL);
5665 static void handleAMDGPUFlatWorkGroupSizeAttr(
Sema &S,
Decl *D,
5677 if (Min == 0 && Max != 0) {
5678 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
5682 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
5687 AMDGPUFlatWorkGroupSizeAttr(AL.
getLoc(), S.
Context, Min, Max,
5704 if (Min == 0 && Max != 0) {
5705 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
5708 if (Max != 0 && Min > Max) {
5709 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
5719 uint32_t NumSGPR = 0;
5730 uint32_t NumVGPR = 0;
5740 static void handleX86ForceAlignArgPointerAttr(
Sema &S,
Decl *D,
5745 const auto *VD = dyn_cast<
ValueDecl>(D);
5746 if (VD && VD->getType()->isFunctionPointerType())
5750 if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
5751 TD->getUnderlyingType()->isFunctionType()))
5754 if (!isa<FunctionDecl>(D)) {
5755 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5773 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5789 unsigned AttrSpellingListIndex) {
5790 if (D->
hasAttr<DLLExportAttr>()) {
5791 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'dllimport'";
5795 if (D->
hasAttr<DLLImportAttr>())
5798 return ::new (Context) DLLImportAttr(Range, Context, AttrSpellingListIndex);
5802 unsigned AttrSpellingListIndex) {
5803 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
5804 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
5808 if (D->
hasAttr<DLLExportAttr>())
5811 return ::new (Context) DLLExportAttr(Range, Context, AttrSpellingListIndex);
5815 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
5821 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5831 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
5840 Attr *NewAttr = A.
getKind() == ParsedAttr::AT_DLLExport
5849 unsigned AttrSpellingListIndex,
5850 MSInheritanceAttr::Spelling SemanticSpelling) {
5851 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
5852 if (IA->getSemanticSpelling() == SemanticSpelling)
5854 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
5856 Diag(Range.
getBegin(), diag::note_previous_ms_inheritance);
5860 auto *RD = cast<CXXRecordDecl>(D);
5861 if (RD->hasDefinition()) {
5862 if (checkMSInheritanceAttrOnDefinition(RD, Range, BestCase,
5863 SemanticSpelling)) {
5867 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
5868 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5872 if (RD->getDescribedClassTemplate()) {
5873 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5879 return ::new (Context)
5880 MSInheritanceAttr(Range, Context, BestCase, AttrSpellingListIndex);
5892 StringRef N(
"mutex");
5894 if (AL.
getKind() == ParsedAttr::AT_Capability &&
5900 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
5901 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
5909 if (!checkLockFunAttrCommon(S, D, AL, Args))
5913 Args.data(), Args.size(),
5917 static void handleAcquireCapabilityAttr(
Sema &S,
Decl *D,
5920 if (!checkLockFunAttrCommon(S, D, AL, Args))
5925 Args.data(), Args.size(),
5929 static void handleTryAcquireCapabilityAttr(
Sema &S,
Decl *D,
5932 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
5943 static void handleReleaseCapabilityAttr(
Sema &S,
Decl *D,
5947 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
5954 static void handleRequiresCapabilityAttr(
Sema &S,
Decl *D,
5961 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
5965 RequiresCapabilityAttr *RCA = ::new (S.
Context)
5973 if (
const auto *NSD = dyn_cast<NamespaceDecl>(D)) {
5974 if (NSD->isAnonymousNamespace()) {
5975 S.
Diag(AL.
getLoc(), diag::warn_deprecated_anonymous_namespace);
5984 StringRef Str, Replacement;
5997 S.
Diag(AL.
getLoc(), diag::ext_cxx14_attr) << AL;
6005 if (
const auto *S = dyn_cast<VarDecl>(D))
6006 return S->hasGlobalStorage();
6014 std::vector<StringRef> Sanitizers;
6016 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
6017 StringRef SanitizerName;
6024 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
6025 else if (
isGlobalVar(D) && SanitizerName !=
"address")
6028 Sanitizers.push_back(SanitizerName);
6036 static void handleNoSanitizeSpecificAttr(
Sema &S,
Decl *D,
6039 normalizeName(AttrName);
6040 StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName)
6041 .Case(
"no_address_safety_analysis",
"address")
6042 .Case(
"no_sanitize_address",
"address")
6043 .Case(
"no_sanitize_thread",
"thread")
6044 .Case(
"no_sanitize_memory",
"memory");
6059 if (S.
LangOpts.OpenCLVersion != 200)
6060 S.
Diag(AL.
getLoc(), diag::err_attribute_requires_opencl_version)
6061 << AL <<
"2.0" << 0;
6063 S.
Diag(AL.
getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL
6070 static bool handleCommonAttributeFeatures(
Sema &S,
Decl *D,
6115 if (D->
hasAttr<OpenCLAccessAttr>()) {
6116 if (D->
getAttr<OpenCLAccessAttr>()->getSemanticSpelling() ==
6118 S.
Diag(AL.
getLoc(), diag::warn_duplicate_declspec)
6121 S.
Diag(AL.
getLoc(), diag::err_opencl_multiple_access_qualifiers)
6133 if (
const auto *PDecl = dyn_cast<ParmVarDecl>(D)) {
6134 const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
6135 if (AL.
getName()->
getName().find(
"read_write") != StringRef::npos) {
6137 S.
Diag(AL.
getLoc(), diag::err_opencl_invalid_read_write)
6138 << AL << PDecl->getType() << DeclTy->
isImageType();
6150 if (!cast<VarDecl>(D)->hasGlobalStorage()) {
6152 << (A.
getKind() == ParsedAttr::AT_AlwaysDestroy);
6156 if (A.
getKind() == ParsedAttr::AT_AlwaysDestroy)
6157 handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A);
6159 handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A);
6163 assert(cast<VarDecl>(D)->getStorageDuration() ==
SD_Automatic &&
6164 "uninitialized is only valid on automatic duration variables");
6170 static bool tryMakeVariablePseudoStrong(
Sema &S,
VarDecl *VD,
6171 bool DiagnoseFailure) {
6174 if (DiagnoseFailure) {
6175 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6192 if (DiagnoseFailure) {
6193 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6207 static void handleObjCExternallyRetainedAttr(
Sema &S,
Decl *D,
6209 if (
auto *VD = dyn_cast<VarDecl>(D)) {
6210 assert(!isa<ParmVarDecl>(VD) &&
"should be diagnosed automatically");
6217 if (!tryMakeVariablePseudoStrong(S, VD,
true))
6220 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6238 tryMakeVariablePseudoStrong(S, PVD,
false);
6240 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6250 static void ProcessDeclAttribute(
Sema &S, Scope *scope,
Decl *D,
6252 bool IncludeCXX11Attributes) {
6268 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
6269 : (
unsigned)diag::warn_unknown_attribute_ignored)
6274 if (handleCommonAttributeFeatures(S, D, AL))
6281 assert(AL.
isTypeAttr() &&
"Non-type attribute not handled");
6284 S.
Diag(AL.
getLoc(), diag::err_stmt_attribute_invalid_on_decl)
6287 case ParsedAttr::AT_Interrupt:
6288 handleInterruptAttr(S, D, AL);
6290 case ParsedAttr::AT_X86ForceAlignArgPointer:
6291 handleX86ForceAlignArgPointerAttr(S, D, AL);
6293 case ParsedAttr::AT_DLLExport:
6294 case ParsedAttr::AT_DLLImport:
6295 handleDLLAttr(S, D, AL);
6297 case ParsedAttr::AT_Mips16:
6298 handleSimpleAttributeWithExclusions<Mips16Attr, MicroMipsAttr,
6299 MipsInterruptAttr>(S, D, AL);
6301 case ParsedAttr::AT_NoMips16:
6302 handleSimpleAttribute<NoMips16Attr>(S, D, AL);
6304 case ParsedAttr::AT_MicroMips:
6305 handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(S, D, AL);
6307 case ParsedAttr::AT_NoMicroMips:
6308 handleSimpleAttribute<NoMicroMipsAttr>(S, D, AL);
6310 case ParsedAttr::AT_MipsLongCall:
6311 handleSimpleAttributeWithExclusions<MipsLongCallAttr, MipsShortCallAttr>(
6314 case ParsedAttr::AT_MipsShortCall:
6315 handleSimpleAttributeWithExclusions<MipsShortCallAttr, MipsLongCallAttr>(
6318 case ParsedAttr::AT_AMDGPUFlatWorkGroupSize:
6319 handleAMDGPUFlatWorkGroupSizeAttr(S, D, AL);
6321 case ParsedAttr::AT_AMDGPUWavesPerEU:
6322 handleAMDGPUWavesPerEUAttr(S, D, AL);
6324 case ParsedAttr::AT_AMDGPUNumSGPR:
6325 handleAMDGPUNumSGPRAttr(S, D, AL);
6327 case ParsedAttr::AT_AMDGPUNumVGPR:
6328 handleAMDGPUNumVGPRAttr(S, D, AL);
6330 case ParsedAttr::AT_AVRSignal:
6331 handleAVRSignalAttr(S, D, AL);
6333 case ParsedAttr::AT_IBAction:
6334 handleSimpleAttribute<IBActionAttr>(S, D, AL);
6336 case ParsedAttr::AT_IBOutlet:
6337 handleIBOutlet(S, D, AL);
6339 case ParsedAttr::AT_IBOutletCollection:
6340 handleIBOutletCollection(S, D, AL);
6342 case ParsedAttr::AT_IFunc:
6343 handleIFuncAttr(S, D, AL);
6345 case ParsedAttr::AT_Alias:
6346 handleAliasAttr(S, D, AL);
6348 case ParsedAttr::AT_Aligned:
6349 handleAlignedAttr(S, D, AL);
6351 case ParsedAttr::AT_AlignValue:
6352 handleAlignValueAttr(S, D, AL);
6354 case ParsedAttr::AT_AllocSize:
6355 handleAllocSizeAttr(S, D, AL);
6357 case ParsedAttr::AT_AlwaysInline:
6358 handleAlwaysInlineAttr(S, D, AL);
6360 case ParsedAttr::AT_Artificial:
6361 handleSimpleAttribute<ArtificialAttr>(S, D, AL);
6363 case ParsedAttr::AT_AnalyzerNoReturn:
6364 handleAnalyzerNoReturnAttr(S, D, AL);
6366 case ParsedAttr::AT_TLSModel:
6367 handleTLSModelAttr(S, D, AL);
6369 case ParsedAttr::AT_Annotate:
6370 handleAnnotateAttr(S, D, AL);
6372 case ParsedAttr::AT_Availability:
6373 handleAvailabilityAttr(S, D, AL);
6375 case ParsedAttr::AT_CarriesDependency:
6376 handleDependencyAttr(S, scope, D, AL);
6378 case ParsedAttr::AT_CPUDispatch:
6379 case ParsedAttr::AT_CPUSpecific:
6380 handleCPUSpecificAttr(S, D, AL);
6382 case ParsedAttr::AT_Common:
6383 handleCommonAttr(S, D, AL);
6385 case ParsedAttr::AT_CUDAConstant:
6386 handleConstantAttr(S, D, AL);
6388 case ParsedAttr::AT_PassObjectSize:
6389 handlePassObjectSizeAttr(S, D, AL);
6391 case ParsedAttr::AT_Constructor:
6392 handleConstructorAttr(S, D, AL);
6394 case ParsedAttr::AT_CXX11NoReturn:
6395 handleSimpleAttribute<CXX11NoReturnAttr>(S, D, AL);
6397 case ParsedAttr::AT_Deprecated:
6398 handleDeprecatedAttr(S, D, AL);
6400 case ParsedAttr::AT_Destructor:
6401 handleDestructorAttr(S, D, AL);
6403 case ParsedAttr::AT_EnableIf:
6404 handleEnableIfAttr(S, D, AL);
6406 case ParsedAttr::AT_DiagnoseIf:
6407 handleDiagnoseIfAttr(S, D, AL);
6409 case ParsedAttr::AT_ExtVectorType:
6410 handleExtVectorTypeAttr(S, D, AL);
6412 case ParsedAttr::AT_ExternalSourceSymbol:
6413 handleExternalSourceSymbolAttr(S, D, AL);
6415 case ParsedAttr::AT_MinSize:
6416 handleMinSizeAttr(S, D, AL);
6418 case ParsedAttr::AT_OptimizeNone:
6419 handleOptimizeNoneAttr(S, D, AL);
6421 case ParsedAttr::AT_FlagEnum:
6422 handleSimpleAttribute<FlagEnumAttr>(S, D, AL);
6424 case ParsedAttr::AT_EnumExtensibility:
6425 handleEnumExtensibilityAttr(S, D, AL);
6427 case ParsedAttr::AT_Flatten:
6428 handleSimpleAttribute<FlattenAttr>(S, D, AL);
6430 case ParsedAttr::AT_Format:
6431 handleFormatAttr(S, D, AL);
6433 case ParsedAttr::AT_FormatArg:
6434 handleFormatArgAttr(S, D, AL);
6436 case ParsedAttr::AT_CUDAGlobal:
6437 handleGlobalAttr(S, D, AL);
6439 case ParsedAttr::AT_CUDADevice:
6440 handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(S, D,
6443 case ParsedAttr::AT_CUDAHost:
6444 handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(S, D, AL);
6446 case ParsedAttr::AT_GNUInline:
6447 handleGNUInlineAttr(S, D, AL);
6449 case ParsedAttr::AT_CUDALaunchBounds:
6450 handleLaunchBoundsAttr(S, D, AL);
6452 case ParsedAttr::AT_Restrict:
6453 handleRestrictAttr(S, D, AL);
6455 case ParsedAttr::AT_LifetimeBound:
6456 handleSimpleAttribute<LifetimeBoundAttr>(S, D, AL);
6458 case ParsedAttr::AT_MayAlias:
6459 handleSimpleAttribute<MayAliasAttr>(S, D, AL);
6461 case ParsedAttr::AT_Mode:
6462 handleModeAttr(S, D, AL);
6464 case ParsedAttr::AT_NoAlias:
6465 handleSimpleAttribute<NoAliasAttr>(S, D, AL);
6467 case ParsedAttr::AT_NoCommon:
6468 handleSimpleAttribute<NoCommonAttr>(S, D, AL);
6470 case ParsedAttr::AT_NoSplitStack:
6471 handleSimpleAttribute<NoSplitStackAttr>(S, D, AL);
6473 case ParsedAttr::AT_NonNull:
6474 if (
auto *PVD = dyn_cast<ParmVarDecl>(D))
6475 handleNonNullAttrParameter(S, PVD, AL);
6477 handleNonNullAttr(S, D, AL);
6479 case ParsedAttr::AT_ReturnsNonNull:
6480 handleReturnsNonNullAttr(S, D, AL);
6482 case ParsedAttr::AT_NoEscape:
6483 handleNoEscapeAttr(S, D, AL);
6485 case ParsedAttr::AT_AssumeAligned:
6486 handleAssumeAlignedAttr(S, D, AL);
6488 case ParsedAttr::AT_AllocAlign:
6489 handleAllocAlignAttr(S, D, AL);
6491 case ParsedAttr::AT_Overloadable:
6492 handleSimpleAttribute<OverloadableAttr>(S, D, AL);
6494 case ParsedAttr::AT_Ownership:
6495 handleOwnershipAttr(S, D, AL);
6497 case ParsedAttr::AT_Cold:
6498 handleSimpleAttributeWithExclusions<ColdAttr, HotAttr>(S, D, AL);
6500 case ParsedAttr::AT_Hot:
6501 handleSimpleAttributeWithExclusions<HotAttr, ColdAttr>(S, D, AL);
6503 case ParsedAttr::AT_Naked:
6504 handleNakedAttr(S, D, AL);
6506 case ParsedAttr::AT_NoReturn:
6507 handleNoReturnAttr(S, D, AL);
6509 case ParsedAttr::AT_AnyX86NoCfCheck:
6510 handleNoCfCheckAttr(S, D, AL);
6512 case ParsedAttr::AT_NoThrow:
6513 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6515 case ParsedAttr::AT_CUDAShared:
6516 handleSharedAttr(S, D, AL);
6518 case ParsedAttr::AT_VecReturn:
6519 handleVecReturnAttr(S, D, AL);
6521 case ParsedAttr::AT_ObjCOwnership:
6522 handleObjCOwnershipAttr(S, D, AL);
6524 case ParsedAttr::AT_ObjCPreciseLifetime:
6525 handleObjCPreciseLifetimeAttr(S, D, AL);
6527 case ParsedAttr::AT_ObjCReturnsInnerPointer:
6528 handleObjCReturnsInnerPointerAttr(S, D, AL);
6530 case ParsedAttr::AT_ObjCRequiresSuper:
6531 handleObjCRequiresSuperAttr(S, D, AL);
6533 case ParsedAttr::AT_ObjCBridge:
6534 handleObjCBridgeAttr(S, D, AL);
6536 case ParsedAttr::AT_ObjCBridgeMutable:
6537 handleObjCBridgeMutableAttr(S, D, AL);
6539 case ParsedAttr::AT_ObjCBridgeRelated:
6540 handleObjCBridgeRelatedAttr(S, D, AL);
6542 case ParsedAttr::AT_ObjCDesignatedInitializer:
6543 handleObjCDesignatedInitializer(S, D, AL);
6545 case ParsedAttr::AT_ObjCRuntimeName:
6546 handleObjCRuntimeName(S, D, AL);
6548 case ParsedAttr::AT_ObjCRuntimeVisible:
6549 handleSimpleAttribute<ObjCRuntimeVisibleAttr>(S, D, AL);
6551 case ParsedAttr::AT_ObjCBoxable:
6552 handleObjCBoxable(S, D, AL);
6554 case ParsedAttr::AT_CFAuditedTransfer:
6555 handleSimpleAttributeWithExclusions<CFAuditedTransferAttr,
6556 CFUnknownTransferAttr>(S, D, AL);
6558 case ParsedAttr::AT_CFUnknownTransfer:
6559 handleSimpleAttributeWithExclusions<CFUnknownTransferAttr,
6560 CFAuditedTransferAttr>(S, D, AL);
6562 case ParsedAttr::AT_CFConsumed:
6563 case ParsedAttr::AT_NSConsumed:
6564 case ParsedAttr::AT_OSConsumed:
6566 parsedAttrToRetainOwnershipKind(AL),
6569 case ParsedAttr::AT_NSConsumesSelf:
6570 handleSimpleAttribute<NSConsumesSelfAttr>(S, D, AL);
6572 case ParsedAttr::AT_OSConsumesThis:
6573 handleSimpleAttribute<OSConsumesThisAttr>(S, D, AL);
6575 case ParsedAttr::AT_OSReturnsRetainedOnZero:
6576 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnZeroAttr>(
6577 S, D, AL, isValidOSObjectOutParameter(D),
6578 diag::warn_ns_attribute_wrong_parameter_type,
6581 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
6582 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnNonZeroAttr>(
6583 S, D, AL, isValidOSObjectOutParameter(D),
6584 diag::warn_ns_attribute_wrong_parameter_type,
6585 AL, 3, AL.getRange());
6587 case ParsedAttr::AT_NSReturnsAutoreleased:
6588 case ParsedAttr::AT_NSReturnsNotRetained:
6589 case ParsedAttr::AT_NSReturnsRetained:
6590 case ParsedAttr::AT_CFReturnsNotRetained:
6591 case ParsedAttr::AT_CFReturnsRetained:
6592 case ParsedAttr::AT_OSReturnsNotRetained:
6593 case ParsedAttr::AT_OSReturnsRetained:
6594 handleXReturnsXRetainedAttr(S, D, AL);
6596 case ParsedAttr::AT_WorkGroupSizeHint:
6597 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
6599 case ParsedAttr::AT_ReqdWorkGroupSize:
6600 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
6602 case ParsedAttr::AT_OpenCLIntelReqdSubGroupSize:
6603 handleSubGroupSize(S, D, AL);
6605 case ParsedAttr::AT_VecTypeHint:
6606 handleVecTypeHint(S, D, AL);
6608 case ParsedAttr::AT_RequireConstantInit:
6609 handleSimpleAttribute<RequireConstantInitAttr>(S, D, AL);
6611 case ParsedAttr::AT_InitPriority:
6612 handleInitPriorityAttr(S, D, AL);
6614 case ParsedAttr::AT_Packed:
6615 handlePackedAttr(S, D, AL);
6617 case ParsedAttr::AT_Section:
6618 handleSectionAttr(S, D, AL);
6620 case ParsedAttr::AT_SpeculativeLoadHardening:
6621 handleSimpleAttribute<SpeculativeLoadHardeningAttr>(S, D, AL);
6623 case ParsedAttr::AT_CodeSeg:
6624 handleCodeSegAttr(S, D, AL);
6626 case ParsedAttr::AT_Target:
6627 handleTargetAttr(S, D, AL);
6629 case ParsedAttr::AT_MinVectorWidth:
6630 handleMinVectorWidthAttr(S, D, AL);
6632 case ParsedAttr::AT_Unavailable:
6633 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
6635 case ParsedAttr::AT_ArcWeakrefUnavailable:
6636 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, AL);
6638 case ParsedAttr::AT_ObjCRootClass:
6639 handleSimpleAttribute<ObjCRootClassAttr>(S, D, AL);
6641 case ParsedAttr::AT_ObjCSubclassingRestricted:
6642 handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(S, D, AL);
6644 case ParsedAttr::AT_ObjCExplicitProtocolImpl:
6645 handleObjCSuppresProtocolAttr(S, D, AL);
6647 case ParsedAttr::AT_ObjCRequiresPropertyDefs:
6648 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, AL);
6650 case ParsedAttr::AT_Unused:
6651 handleUnusedAttr(S, D, AL);
6653 case ParsedAttr::AT_ReturnsTwice:
6654 handleSimpleAttribute<ReturnsTwiceAttr>(S, D, AL);
6656 case ParsedAttr::AT_NotTailCalled:
6657 handleSimpleAttributeWithExclusions<NotTailCalledAttr, AlwaysInlineAttr>(
6660 case ParsedAttr::AT_DisableTailCalls:
6661 handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D,
6664 case ParsedAttr::AT_Used:
6665 handleSimpleAttribute<UsedAttr>(S, D, AL);
6667 case ParsedAttr::AT_Visibility:
6668 handleVisibilityAttr(S, D, AL,
false);
6670 case ParsedAttr::AT_TypeVisibility:
6671 handleVisibilityAttr(S, D, AL,
true);
6673 case ParsedAttr::AT_WarnUnused:
6674 handleSimpleAttribute<WarnUnusedAttr>(S, D, AL);
6676 case ParsedAttr::AT_WarnUnusedResult:
6677 handleWarnUnusedResult(S, D, AL);
6679 case ParsedAttr::AT_Weak:
6680 handleSimpleAttribute<WeakAttr>(S, D, AL);
6682 case ParsedAttr::AT_WeakRef:
6683 handleWeakRefAttr(S, D, AL);
6685 case ParsedAttr::AT_WeakImport:
6686 handleWeakImportAttr(S, D, AL);
6688 case ParsedAttr::AT_TransparentUnion:
6689 handleTransparentUnionAttr(S, D, AL);
6691 case ParsedAttr::AT_ObjCException:
6692 handleSimpleAttribute<ObjCExceptionAttr>(S, D, AL);
6694 case ParsedAttr::AT_ObjCMethodFamily:
6695 handleObjCMethodFamilyAttr(S, D, AL);
6697 case ParsedAttr::AT_ObjCNSObject:
6698 handleObjCNSObject(S, D, AL);
6700 case ParsedAttr::AT_ObjCIndependentClass:
6701 handleObjCIndependentClass(S, D, AL);
6703 case ParsedAttr::AT_Blocks:
6704 handleBlocksAttr(S, D, AL);
6706 case ParsedAttr::AT_Sentinel:
6707 handleSentinelAttr(S, D, AL);
6709 case ParsedAttr::AT_Const:
6710 handleSimpleAttribute<ConstAttr>(S, D, AL);
6712 case ParsedAttr::AT_Pure:
6713 handleSimpleAttribute<PureAttr>(S, D, AL);
6715 case ParsedAttr::AT_Cleanup:
6716 handleCleanupAttr(S, D, AL);
6718 case ParsedAttr::AT_NoDebug:
6719 handleNoDebugAttr(S, D, AL);
6721 case ParsedAttr::AT_NoDuplicate:
6722 handleSimpleAttribute<NoDuplicateAttr>(S, D, AL);
6724 case ParsedAttr::AT_Convergent:
6725 handleSimpleAttribute<ConvergentAttr>(S, D, AL);
6727 case ParsedAttr::AT_NoInline:
6728 handleSimpleAttribute<NoInlineAttr>(S, D, AL);
6730 case ParsedAttr::AT_NoInstrumentFunction:
6731 handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, AL);
6733 case ParsedAttr::AT_NoStackProtector:
6735 handleSimpleAttribute<NoStackProtectorAttr>(S, D, AL);
6737 case ParsedAttr::AT_StdCall:
6738 case ParsedAttr::AT_CDecl:
6739 case ParsedAttr::AT_FastCall:
6740 case ParsedAttr::AT_ThisCall:
6741 case ParsedAttr::AT_Pascal:
6742 case ParsedAttr::AT_RegCall:
6743 case ParsedAttr::AT_SwiftCall:
6744 case ParsedAttr::AT_VectorCall:
6745 case ParsedAttr::AT_MSABI:
6746 case ParsedAttr::AT_SysVABI:
6747 case ParsedAttr::AT_Pcs:
6748 case ParsedAttr::AT_IntelOclBicc:
6749 case ParsedAttr::AT_PreserveMost:
6750 case ParsedAttr::AT_PreserveAll:
6751 case ParsedAttr::AT_AArch64VectorPcs:
6752 handleCallConvAttr(S, D, AL);
6754 case ParsedAttr::AT_Suppress:
6757 case ParsedAttr::AT_OpenCLKernel:
6758 handleSimpleAttribute<OpenCLKernelAttr>(S, D, AL);
6760 case ParsedAttr::AT_OpenCLAccess:
6761 handleOpenCLAccessAttr(S, D, AL);
6763 case ParsedAttr::AT_OpenCLNoSVM:
6764 handleOpenCLNoSVMAttr(S, D, AL);
6766 case ParsedAttr::AT_SwiftContext:
6769 case ParsedAttr::AT_SwiftErrorResult:
6772 case ParsedAttr::AT_SwiftIndirectResult:
6775 case ParsedAttr::AT_InternalLinkage:
6776 handleInternalLinkageAttr(S, D, AL);
6778 case ParsedAttr::AT_ExcludeFromExplicitInstantiation:
6779 handleSimpleAttribute<ExcludeFromExplicitInstantiationAttr>(S, D, AL);
6781 case ParsedAttr::AT_LTOVisibilityPublic:
6782 handleSimpleAttribute<LTOVisibilityPublicAttr>(S, D, AL);
6786 case ParsedAttr::AT_EmptyBases:
6787 handleSimpleAttribute<EmptyBasesAttr>(S, D, AL);
6789 case ParsedAttr::AT_LayoutVersion:
6790 handleLayoutVersion(S, D, AL);
6792 case ParsedAttr::AT_TrivialABI:
6793 handleSimpleAttribute<TrivialABIAttr>(S, D, AL);
6795 case ParsedAttr::AT_MSNoVTable:
6796 handleSimpleAttribute<MSNoVTableAttr>(S, D, AL);
6798 case ParsedAttr::AT_MSStruct:
6799 handleSimpleAttribute<MSStructAttr>(S, D, AL);
6801 case ParsedAttr::AT_Uuid:
6802 handleUuidAttr(S, D, AL);
6804 case ParsedAttr::AT_MSInheritance:
6805 handleMSInheritanceAttr(S, D, AL);
6807 case ParsedAttr::AT_SelectAny:
6808 handleSimpleAttribute<SelectAnyAttr>(S, D, AL);
6810 case ParsedAttr::AT_Thread:
6811 handleDeclspecThreadAttr(S, D, AL);
6814 case ParsedAttr::AT_AbiTag:
6815 handleAbiTagAttr(S, D, AL);
6819 case ParsedAttr::AT_AssertExclusiveLock:
6820 handleAssertExclusiveLockAttr(S, D, AL);
6822 case ParsedAttr::AT_AssertSharedLock:
6823 handleAssertSharedLockAttr(S, D, AL);
6825 case ParsedAttr::AT_GuardedVar:
6826 handleSimpleAttribute<GuardedVarAttr>(S, D, AL);
6828 case ParsedAttr::AT_PtGuardedVar:
6829 handlePtGuardedVarAttr(S, D, AL);
6831 case ParsedAttr::AT_ScopedLockable:
6832 handleSimpleAttribute<ScopedLockableAttr>(S, D, AL);
6834 case ParsedAttr::AT_NoSanitize:
6835 handleNoSanitizeAttr(S, D, AL);
6837 case ParsedAttr::AT_NoSanitizeSpecific:
6838 handleNoSanitizeSpecificAttr(S, D, AL);
6840 case ParsedAttr::AT_NoThreadSafetyAnalysis:
6841 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, AL);
6843 case ParsedAttr::AT_GuardedBy:
6844 handleGuardedByAttr(S, D, AL);
6846 case ParsedAttr::AT_PtGuardedBy:
6847 handlePtGuardedByAttr(S, D, AL);
6849 case ParsedAttr::AT_ExclusiveTrylockFunction:
6850 handleExclusiveTrylockFunctionAttr(S, D, AL);
6852 case ParsedAttr::AT_LockReturned:
6853 handleLockReturnedAttr(S, D, AL);
6855 case ParsedAttr::AT_LocksExcluded:
6856 handleLocksExcludedAttr(S, D, AL);
6858 case ParsedAttr::AT_SharedTrylockFunction:
6859 handleSharedTrylockFunctionAttr(S, D, AL);
6861 case ParsedAttr::AT_AcquiredBefore:
6862 handleAcquiredBeforeAttr(S, D, AL);
6864 case ParsedAttr::AT_AcquiredAfter:
6865 handleAcquiredAfterAttr(S, D, AL);
6869 case ParsedAttr::AT_Capability:
6870 case ParsedAttr::AT_Lockable:
6871 handleCapabilityAttr(S, D, AL);
6873 case ParsedAttr::AT_RequiresCapability:
6874 handleRequiresCapabilityAttr(S, D, AL);
6877 case ParsedAttr::AT_AssertCapability:
6878 handleAssertCapabilityAttr(S, D, AL);
6880 case ParsedAttr::AT_AcquireCapability:
6881 handleAcquireCapabilityAttr(S, D, AL);
6883 case ParsedAttr::AT_ReleaseCapability:
6884 handleReleaseCapabilityAttr(S, D, AL);
6886 case ParsedAttr::AT_TryAcquireCapability:
6887 handleTryAcquireCapabilityAttr(S, D, AL);
6891 case ParsedAttr::AT_Consumable:
6892 handleConsumableAttr(S, D, AL);
6894 case ParsedAttr::AT_ConsumableAutoCast:
6895 handleSimpleAttribute<ConsumableAutoCastAttr>(S, D, AL);
6897 case ParsedAttr::AT_ConsumableSetOnRead:
6898 handleSimpleAttribute<ConsumableSetOnReadAttr>(S, D, AL);
6900 case ParsedAttr::AT_CallableWhen:
6901 handleCallableWhenAttr(S, D, AL);
6903 case ParsedAttr::AT_ParamTypestate:
6904 handleParamTypestateAttr(S, D, AL);
6906 case ParsedAttr::AT_ReturnTypestate:
6907 handleReturnTypestateAttr(S, D, AL);
6909 case ParsedAttr::AT_SetTypestate:
6910 handleSetTypestateAttr(S, D, AL);
6912 case ParsedAttr::AT_TestTypestate:
6913 handleTestTypestateAttr(S, D, AL);
6917 case ParsedAttr::AT_ArgumentWithTypeTag:
6918 handleArgumentWithTypeTagAttr(S, D, AL);
6920 case ParsedAttr::AT_TypeTagForDatatype:
6921 handleTypeTagForDatatypeAttr(S, D, AL);
6923 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters:
6924 handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL);
6926 case ParsedAttr::AT_RenderScriptKernel:
6927 handleSimpleAttribute<RenderScriptKernelAttr>(S, D, AL);
6930 case ParsedAttr::AT_XRayInstrument:
6931 handleSimpleAttribute<XRayInstrumentAttr>(S, D, AL);
6933 case ParsedAttr::AT_XRayLogArgs:
6934 handleXRayLogArgsAttr(S, D, AL);
6938 case ParsedAttr::AT_Reinitializes:
6939 handleSimpleAttribute<ReinitializesAttr>(S, D, AL);
6942 case ParsedAttr::AT_AlwaysDestroy:
6943 case ParsedAttr::AT_NoDestroy:
6944 handleDestroyAttr(S, D, AL);
6947 case ParsedAttr::AT_Uninitialized:
6948 handleUninitializedAttr(S, D, AL);
6951 case ParsedAttr::AT_ObjCExternallyRetained:
6952 handleObjCExternallyRetainedAttr(S, D, AL);
6961 bool IncludeCXX11Attributes) {
6962 if (AttrList.
empty())
6966 ProcessDeclAttribute(*
this, S, D, AL, IncludeCXX11Attributes);
6973 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias)
6974 << cast<NamedDecl>(D);
6983 if (!D->
hasAttr<OpenCLKernelAttr>()) {
6985 if (
const auto *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
6990 }
else if (
const auto *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
6993 }
else if (
const auto *A = D->
getAttr<VecTypeHintAttr>()) {
6996 }
else if (
const auto *A = D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
6999 }
else if (!D->
hasAttr<CUDAGlobalAttr>()) {
7000 if (
const auto *A = D->
getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
7004 }
else if (
const auto *A = D->
getAttr<AMDGPUWavesPerEUAttr>()) {
7008 }
else if (
const auto *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
7012 }
else if (
const auto *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
7025 if (AL.
getKind() == ParsedAttr::AT_TransparentUnion) {
7026 handleTransparentUnionAttr(*
this, D, AL);
7036 if (AL.
getKind() == ParsedAttr::AT_Annotate) {
7039 Diag(AL.
getLoc(), diag::err_only_annotate_after_access_spec);
7057 S.
Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored)
7060 S.
Diag(AL.
getLoc(), diag::warn_attribute_not_on_decl) << AL
7080 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
7082 if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
7104 for (
const auto &AI : FT->param_types()) {
7105 ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
7107 Params.push_back(Param);
7109 NewFD->setParams(Params);
7111 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
7130 NewD->
addAttr(AliasAttr::CreateImplicit(Context, NDId->
getName(),
7133 WeakTopLevelDecl.push_back(NewD);
7140 PushOnScopeChains(NewD, S);
7141 CurContext = SavedContext;
7150 LoadExternalWeakUndeclaredIdentifiers();
7151 if (!WeakUndeclaredIdentifiers.empty()) {
7153 if (
auto *VD = dyn_cast<VarDecl>(D))
7156 if (
auto *FD = dyn_cast<FunctionDecl>(D))
7161 auto I = WeakUndeclaredIdentifiers.find(
Id);
7162 if (I != WeakUndeclaredIdentifiers.end()) {
7164 DeclApplyPragmaWeak(S, ND, W);
7165 WeakUndeclaredIdentifiers[
Id] = W;
7192 AddPragmaAttributes(S, D);
7198 static bool isForbiddenTypeAllowed(
Sema &S,
Decl *D,
7200 UnavailableAttr::ImplicitReason &reason) {
7204 if (!isa<FieldDecl>(D) && !isa<ObjCPropertyDecl>(D) &&
7205 !isa<FunctionDecl>(D))
7213 if ((isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) {
7216 reason = UnavailableAttr::IR_ForbiddenWeak;
7225 reason = UnavailableAttr::IR_ARCForbiddenType;
7235 auto Reason = UnavailableAttr::IR_None;
7236 if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) {
7237 assert(Reason &&
"didn't set reason?");
7242 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
7245 if (FD->
hasAttr<UnavailableAttr>() &&
7247 diag::err_arc_array_param_no_ownership) {
7258 static const AvailabilityAttr *getAttrForPlatform(
ASTContext &Context,
7261 for (
const auto *A : D->
attrs()) {
7262 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
7268 StringRef ActualPlatform = Avail->getPlatform()->getName();
7269 StringRef RealizedPlatform = ActualPlatform;
7271 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
7272 if (suffix != StringRef::npos)
7273 RealizedPlatform = RealizedPlatform.slice(0, suffix);
7279 if (RealizedPlatform == TargetPlatform)
7294 static std::pair<AvailabilityResult, const NamedDecl *>
7295 ShouldDiagnoseAvailabilityOfDecl(
Sema &S,
const NamedDecl *D,
7296 std::string *Message,
7302 while (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
7304 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
7314 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
7315 if (IDecl->getDefinition()) {
7316 D = IDecl->getDefinition();
7321 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7324 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
7325 Result = TheEnumDecl->getAvailability(Message);
7331 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7335 if (Init && Result ==
AR_Available && MD->isClassMethod() &&
7336 MD->getSelector() == S.
NSAPIObj->getNewSelector() &&
7353 VersionTuple DeclVersion,
Decl *Ctx,
7355 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
7358 auto CheckContext = [&](
const Decl *C) {
7360 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, C))
7361 if (AA->getIntroduced() >= DeclVersion)
7364 if (C->isDeprecated())
7370 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
7371 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
7372 if (MD->getClassInterface() == Impl->getClassInterface())
7378 if (C->isUnavailable())
7384 if (CheckContext(Ctx))
7389 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
7390 if (MethodD->isClassMethod() &&
7391 MethodD->getSelector().getAsString() ==
"load")
7394 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
7396 if (CheckContext(Interface))
7400 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
7402 if (CheckContext(Interface))
7410 shouldDiagnoseAvailabilityByDefault(
const ASTContext &Context,
7411 const VersionTuple &DeploymentVersion,
7412 const VersionTuple &DeclVersion) {
7414 VersionTuple ForceAvailabilityFromVersion;
7415 switch (Triple.getOS()) {
7416 case llvm::Triple::IOS:
7417 case llvm::Triple::TvOS:
7418 ForceAvailabilityFromVersion = VersionTuple(11);
7420 case llvm::Triple::WatchOS:
7421 ForceAvailabilityFromVersion = VersionTuple(4);
7423 case llvm::Triple::Darwin:
7424 case llvm::Triple::MacOSX:
7425 ForceAvailabilityFromVersion = VersionTuple(10, 13);
7429 return Triple.getVendor() == llvm::Triple::Apple;
7431 return DeploymentVersion >= ForceAvailabilityFromVersion ||
7432 DeclVersion >= ForceAvailabilityFromVersion;
7435 static NamedDecl *findEnclosingDeclToAnnotate(
Decl *OrigCtx) {
7436 for (
Decl *Ctx = OrigCtx; Ctx;
7438 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
7439 return cast<NamedDecl>(Ctx);
7440 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
7441 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
7442 return Imp->getClassInterface();
7452 struct AttributeInsertion {
7457 static AttributeInsertion createInsertionAfter(
const NamedDecl *D) {
7460 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
7461 return {
" ", Loc,
""};
7463 static AttributeInsertion createInsertionBefore(
const NamedDecl *D) {
7482 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
7483 Name = Name.drop_front(1);
7486 Name.split(SlotNames,
':');
7488 if (Name.back() ==
':') {
7490 SlotNames.pop_back();
7491 NumParams = SlotNames.size();
7493 if (SlotNames.size() != 1)
7499 bool AllowDollar = LangOpts.DollarIdents;
7500 for (StringRef S : SlotNames) {
7514 if (isa<ObjCPropertyDecl>(D))
7515 return AttributeInsertion::createInsertionAfter(D);
7516 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7519 return AttributeInsertion::createInsertionAfter(D);
7521 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
7527 return AttributeInsertion::createInsertionAfter(Loc);
7529 return AttributeInsertion::createInsertionBefore(D);
7549 bool ObjCPropertyAccess) {
7551 unsigned diag, diag_message, diag_fwdclass_message;
7552 unsigned diag_available_here = diag::note_availability_specified_here;
7556 unsigned property_note_select;
7559 unsigned available_here_select_kind;
7561 VersionTuple DeclVersion;
7562 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, OffendingDecl))
7563 DeclVersion = AA->getIntroduced();
7565 if (!ShouldDiagnoseAvailabilityInContext(S, K, DeclVersion, Ctx,
7573 const AvailabilityAttr *A = getAttrForPlatform(S.
Context, OffendingDecl);
7574 if (A && A->isInherited()) {
7577 const AvailabilityAttr *AForRedecl =
7578 getAttrForPlatform(S.
Context, Redecl);
7579 if (AForRedecl && !AForRedecl->isInherited()) {
7582 NoteLocation = Redecl->getLocation();
7594 const AvailabilityAttr *AA =
7596 VersionTuple Introduced = AA->getIntroduced();
7598 bool UseNewWarning = shouldDiagnoseAvailabilityByDefault(
7601 unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
7602 : diag::warn_unguarded_availability;
7604 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
7607 S.
Diag(Loc, Warning) << OffendingDecl << PlatformName
7608 << Introduced.getAsString();
7611 diag::note_partial_availability_specified_here)
7612 << OffendingDecl << PlatformName << Introduced.getAsString()
7615 if (
const auto *Enclosing = findEnclosingDeclToAnnotate(Ctx)) {
7616 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
7617 if (TD->getDeclName().isEmpty()) {
7618 S.
Diag(TD->getLocation(),
7619 diag::note_decl_unguarded_availability_silence)
7620 << 1 << TD->getKindName();
7623 auto FixitNoteDiag =
7624 S.
Diag(Enclosing->getLocation(),
7625 diag::note_decl_unguarded_availability_silence)
7628 if (Enclosing->hasAttr<AvailabilityAttr>())
7636 std::string PlatformName =
7637 AvailabilityAttr::getPlatformNameSourceSpelling(
7640 std::string Introduced =
7644 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
7645 "(" + Introduced +
"))" + Insertion->Suffix)
7651 diag = !ObjCPropertyAccess ? diag::warn_deprecated
7652 : diag::warn_property_method_deprecated;
7653 diag_message = diag::warn_deprecated_message;
7654 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
7655 property_note_select = 0;
7656 available_here_select_kind = 2;
7657 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
7658 NoteLocation = AL->getLocation();
7662 diag = !ObjCPropertyAccess ? diag::err_unavailable
7663 : diag::err_property_method_unavailable;
7664 diag_message = diag::err_unavailable_message;
7665 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
7666 property_note_select = 1;
7667 available_here_select_kind = 0;
7669 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
7670 if (AL->isImplicit() && AL->getImplicitReason()) {
7673 auto flagARCError = [&] {
7677 diag = diag::err_unavailable_in_arc;
7680 switch (AL->getImplicitReason()) {
7681 case UnavailableAttr::IR_None:
break;
7683 case UnavailableAttr::IR_ARCForbiddenType:
7685 diag_available_here = diag::note_arc_forbidden_type;
7688 case UnavailableAttr::IR_ForbiddenWeak:
7690 diag_available_here = diag::note_arc_weak_disabled;
7692 diag_available_here = diag::note_arc_weak_no_runtime;
7695 case UnavailableAttr::IR_ARCForbiddenConversion:
7697 diag_available_here = diag::note_performs_forbidden_arc_conversion;
7700 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
7702 diag_available_here = diag::note_arc_init_returns_unrelated;
7705 case UnavailableAttr::IR_ARCFieldWithOwnership:
7707 diag_available_here = diag::note_arc_field_with_ownership;
7715 llvm_unreachable(
"Warning for availability of available declaration?");
7720 StringRef Replacement;
7721 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
7722 Replacement = AL->getReplacement();
7723 if (
auto AL = getAttrForPlatform(S.
Context, OffendingDecl))
7724 Replacement = AL->getReplacement();
7727 if (!Replacement.empty())
7731 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
7732 Selector Sel = MethodDecl->getSelector();
7736 if (NumParams && NumParams.getValue() == Sel.
getNumArgs()) {
7737 assert(SelectorSlotNames.size() == Locs.size());
7738 for (
unsigned I = 0; I < Locs.size(); ++I) {
7743 NameRange, SelectorSlotNames[I]));
7755 if (!Message.empty()) {
7756 S.
Diag(Loc, diag_message) << ReferringDecl << Message << FixIts;
7759 << ObjCProperty->
getDeclName() << property_note_select;
7760 }
else if (!UnknownObjCClass) {
7761 S.
Diag(Loc, diag) << ReferringDecl << FixIts;
7764 << ObjCProperty->
getDeclName() << property_note_select;
7766 S.
Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
7770 S.
Diag(NoteLocation, diag_available_here)
7771 << OffendingDecl << available_here_select_kind;
7777 "Expected an availability diagnostic here");
7780 DoEmitAvailabilityWarning(
7788 assert(DelayedDiagnostics.getCurrentPool());
7790 DelayedDiagnostics.popWithoutEmitting(
state);
7806 bool AnyAccessFailures =
false;
7814 switch (diag.
Kind) {
7819 handleDelayedAvailabilityCheck(*
this, diag, decl);
7826 if (AnyAccessFailures && isa<DecompositionDecl>(decl))
7828 HandleDelayedAccessCheck(diag, decl);
7830 AnyAccessFailures =
true;
7834 handleDelayedForbiddenType(*
this, diag, decl);
7846 assert(curPool &&
"re-emitting in undelayed context not supported");
7847 curPool->
steal(pool);
7857 bool ObjCPropertyAccess) {
7862 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
7863 ObjCProperty, Message, ObjCPropertyAccess));
7868 DoEmitAvailabilityWarning(S, AR, Ctx, ReferringDecl, OffendingDecl,
7869 Message, Locs, UnknownObjCClass, ObjCProperty,
7870 ObjCPropertyAccess);
7878 case Stmt::IfStmtClass:
7879 return cast<IfStmt>(
Parent)->getThen() == S ||
7880 cast<IfStmt>(
Parent)->getElse() == S;
7881 case Stmt::WhileStmtClass:
7882 return cast<WhileStmt>(
Parent)->getBody() == S;
7883 case Stmt::DoStmtClass:
7884 return cast<DoStmt>(
Parent)->getBody() == S;
7885 case Stmt::ForStmtClass:
7886 return cast<ForStmt>(
Parent)->getBody() == S;
7887 case Stmt::CXXForRangeStmtClass:
7888 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
7889 case Stmt::ObjCForCollectionStmtClass:
7890 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
7891 case Stmt::CaseStmtClass:
7892 case Stmt::DefaultStmtClass:
7893 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
7903 bool VisitStmt(
Stmt *S) {
return S != Target; }
7906 static bool isContained(
const Stmt *Target,
const Decl *D) {
7907 StmtUSEFinder Visitor;
7908 Visitor.Target = Target;
7909 return !Visitor.TraverseDecl(const_cast<Decl *>(D));
7925 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
7927 LastDeclUSEFinder Visitor;
7931 if (!Visitor.TraverseStmt(const_cast<Stmt *>(S)))
7944 class DiagnoseUnguardedAvailability
7959 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
7960 : SemaRef(SemaRef), Ctx(Ctx) {
7961 AvailabilityStack.push_back(
7965 bool TraverseDecl(
Decl *D) {
7967 if (!D || isa<FunctionDecl>(D))
7969 return Base::TraverseDecl(D);
7972 bool TraverseStmt(
Stmt *S) {
7975 StmtStack.push_back(S);
7976 bool Result = Base::TraverseStmt(S);
7977 StmtStack.pop_back();
7981 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
7983 bool TraverseIfStmt(
IfStmt *If);
7985 bool TraverseLambdaExpr(
LambdaExpr *E) {
return true; }
8004 DiagnoseDeclAvailability(
8011 DiagnoseDeclAvailability(DRE->
getDecl(),
8028 bool VisitTypeLoc(
TypeLoc Ty);
8031 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
8035 std::tie(Result, OffendingDecl) =
8036 ShouldDiagnoseAvailabilityOfDecl(SemaRef, D,
nullptr, ReceiverClass);
8043 const AvailabilityAttr *AA =
8044 getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
8045 VersionTuple Introduced = AA->getIntroduced();
8047 if (AvailabilityStack.back() >= Introduced)
8052 if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx,
8061 shouldDiagnoseAvailabilityByDefault(
8063 SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced)
8064 ? diag::warn_unguarded_availability_new
8065 : diag::warn_unguarded_availability;
8067 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8068 SemaRef.getASTContext().getTargetInfo().getPlatformName());
8070 SemaRef.Diag(Range.
getBegin(), DiagKind)
8071 << Range << D << PlatformName << Introduced.getAsString();
8074 diag::note_partial_availability_specified_here)
8075 << OffendingDecl << PlatformName << Introduced.getAsString()
8076 << SemaRef.Context.getTargetInfo()
8077 .getPlatformMinVersion()
8081 SemaRef.Diag(Range.
getBegin(), diag::note_unguarded_available_silence)
8083 << (SemaRef.getLangOpts().ObjC ? 0
8087 if (StmtStack.empty())
8089 const Stmt *StmtOfUse = StmtStack.back();
8091 for (
const Stmt *S : llvm::reverse(StmtStack)) {
8092 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
8096 if (isBodyLikeChildStmt(StmtOfUse, S)) {
8104 const Stmt *LastStmtOfUse =
nullptr;
8105 if (isa<DeclStmt>(StmtOfUse) && Scope) {
8106 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
8107 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
8108 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope);
8119 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
8125 const char *ExtraIndentation =
" ";
8126 std::string FixItString;
8127 llvm::raw_string_ostream FixItOS(FixItString);
8128 FixItOS <<
"if (" << (SemaRef.getLangOpts().ObjC ?
"@available" 8129 :
"__builtin_available")
8131 << AvailabilityAttr::getPlatformNameSourceSpelling(
8132 SemaRef.getASTContext().getTargetInfo().getPlatformName())
8133 <<
" " << Introduced.getAsString() <<
", *)) {\n" 8134 << Indentation << ExtraIndentation;
8137 StmtEndLoc, tok::semi, SM, SemaRef.getLangOpts(),
8139 if (ElseInsertionLoc.isInvalid())
8142 FixItOS.str().clear();
8144 << Indentation <<
"} else {\n" 8145 << Indentation << ExtraIndentation
8146 <<
"// Fallback on earlier versions\n" 8147 << Indentation <<
"}";
8152 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
8159 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
8161 DiagnoseDeclAvailability(TD, Range);
8163 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
8165 DiagnoseDeclAvailability(D, Range);
8167 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
8168 if (
NamedDecl *D = ObjCO->getInterface())
8169 DiagnoseDeclAvailability(D, Range);
8175 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
8176 VersionTuple CondVersion;
8177 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->
getCond())) {
8178 CondVersion = E->getVersion();
8182 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
8183 return TraverseStmt(If->
getThen()) && TraverseStmt(If->
getElse());
8186 return Base::TraverseIfStmt(If);
8189 AvailabilityStack.push_back(CondVersion);
8190 bool ShouldContinue = TraverseStmt(If->
getThen());
8191 AvailabilityStack.pop_back();
8193 return ShouldContinue && TraverseStmt(If->
getElse());
8199 Stmt *Body =
nullptr;
8208 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
8210 else if (
auto *BD = dyn_cast<BlockDecl>(D))
8211 Body = BD->getBody();
8213 assert(Body &&
"Need a body here!");
8215 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
8221 bool ObjCPropertyAccess,
8222 bool AvoidPartialAvailabilityChecks,
8224 std::string Message;
8228 std::tie(Result, OffendingDecl) =
8229 ShouldDiagnoseAvailabilityOfDecl(*
this, D, &Message, ClassReceiver);
8234 if (AvoidPartialAvailabilityChecks)
8240 if (getCurFunctionOrMethodDecl()) {
8241 getEnclosingFunction()->HasPotentialAvailabilityViolations =
true;
8243 }
else if (getCurBlock() || getCurLambda()) {
8244 getCurFunction()->HasPotentialAvailabilityViolations =
true;
8250 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
8253 if (PDeclResult == Result)
8258 EmitAvailabilityWarning(*
this, Result, D, OffendingDecl, Message, Locs,
8259 UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess);
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...
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...
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.
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
Returns 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.
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.
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)
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.
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, unsigned AttrSpellingListIndex)
Attribute merging methods. Return true if a new attribute was added.
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)
bool isLambda() const
Determine whether this class describes a lambda function object.
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
unsigned getMinArgs() const
Scope - A scope is a transient data structure that is used while parsing the program.
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.
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.
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, bool isConstexprSpecified=false)
const LangOptions & LangOpts
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
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.
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...
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)
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)
CUDADiagBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a CUDADiagBuilder that emits the diagnostic if the current context is "used as host code"...
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)
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
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.
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
Returns 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.
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?
__DEVICE__ int max(int __a, int __b)
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.
Automatic storage duration (most local variables).
static bool isFunctionOrMethodVariadic(const Decl *D)
Describes an entity that is being initialized.
bool isFunctionPointerType() const
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
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