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,
5123 if (!isa<ObjCInterfaceDecl>(Ctx) &&
5124 !(isa<ObjCCategoryDecl>(Ctx) &&
5125 cast<ObjCCategoryDecl>(Ctx)->IsClassExtension())) {
5131 if (
auto *CatDecl = dyn_cast<ObjCCategoryDecl>(Ctx))
5132 IFace = CatDecl->getClassInterface();
5134 IFace = cast<ObjCInterfaceDecl>(Ctx);
5146 StringRef MetaDataName;
5160 bool notify =
false;
5169 ObjCBoxableAttr *BoxableAttr = ::new (S.
Context)
5177 L->AddedAttributeToRecord(BoxableAttr, RD);
5189 static void handleObjCPreciseLifetimeAttr(
Sema &S,
Decl *D,
5191 const auto *VD = cast<ValueDecl>(D);
5194 if (!QT->isDependentType() &&
5195 !QT->isObjCLifetimeType()) {
5196 S.
Diag(AL.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
5206 Lifetime = QT->getObjCARCImplicitLifetime();
5210 assert(QT->isDependentType() &&
5211 "didn't infer lifetime for non-dependent type?");
5220 S.
Diag(AL.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
5235 unsigned AttrSpellingListIndex, StringRef Uuid) {
5236 if (
const auto *UA = D->
getAttr<UuidAttr>()) {
5237 if (UA->getGuid().equals_lower(Uuid))
5239 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5244 return ::new (Context) UuidAttr(Range, Context, Uuid, AttrSpellingListIndex);
5249 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5261 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
5262 StrRef = StrRef.drop_front().drop_back();
5265 if (StrRef.size() != 36) {
5266 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5270 for (
unsigned i = 0; i < 36; ++i) {
5271 if (i == 8 || i == 13 || i == 18 || i == 23) {
5272 if (StrRef[i] !=
'-') {
5273 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5277 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5289 S.
Diag(AL.
getLoc(), diag::warn_atl_uuid_deprecated);
5299 S.
Diag(AL.
getLoc(), diag::err_attribute_not_supported_in_lang)
5314 const auto *VD = cast<VarDecl>(D);
5316 S.
Diag(AL.
getLoc(), diag::err_thread_unsupported);
5320 S.
Diag(AL.
getLoc(), diag::err_declspec_thread_on_thread_variable);
5323 if (VD->hasLocalStorage()) {
5324 S.
Diag(AL.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
5333 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
5337 Tags.push_back(Tag);
5340 if (
const auto *NS = dyn_cast<NamespaceDecl>(D)) {
5341 if (!NS->isInline()) {
5342 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5345 if (NS->isAnonymousNamespace()) {
5346 S.
Diag(AL.
getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5350 Tags.push_back(NS->getName());
5356 Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
5366 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5378 ARMInterruptAttr::InterruptType
Kind;
5379 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5380 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5416 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5422 llvm::APSInt NumParams(32);
5424 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_type)
5430 unsigned Num = NumParams.getLimitedValue(255);
5432 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5433 << AL << (
int)NumParams.getSExtValue()
5447 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments) << AL << 1;
5486 if (checkAttrMutualExclusion<Mips16Attr>(S, D, AL))
5489 MipsInterruptAttr::InterruptType
Kind;
5490 if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5491 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported)
5492 << AL <<
"'" + std::string(Str) +
"'";
5509 cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
5510 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5517 diag::err_anyx86_interrupt_attribute)
5526 if (NumParams < 1 || NumParams > 2) {
5537 diag::err_anyx86_interrupt_attribute)
5549 if (NumParams == 2 &&
5553 diag::err_anyx86_interrupt_attribute)
5575 handleSimpleAttribute<AVRInterruptAttr>(S, D, AL);
5588 handleSimpleAttribute<AVRSignalAttr>(S, D, AL);
5591 static void handleWebAssemblyImportModuleAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5598 auto *FD = cast<FunctionDecl>(D);
5614 static void handleWebAssemblyImportNameAttr(
Sema &S,
Decl *D,
const ParsedAttr &AL) {
5621 auto *FD = cast<FunctionDecl>(D);
5637 static void handleRISCVInterruptAttr(
Sema &S,
Decl *D,
5640 if (
const auto *A = D->
getAttr<RISCVInterruptAttr>()) {
5642 diag::warn_riscv_repeated_interrupt_attribute);
5643 S.
Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute);
5683 RISCVInterruptAttr::InterruptType
Kind;
5684 if (!RISCVInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5685 S.
Diag(AL.
getLoc(), diag::warn_attribute_type_not_supported) << AL << Str
5697 case llvm::Triple::msp430:
5698 handleMSP430InterruptAttr(S, D, AL);
5700 case llvm::Triple::mipsel:
5701 case llvm::Triple::mips:
5702 handleMipsInterruptAttr(S, D, AL);
5704 case llvm::Triple::x86:
5705 case llvm::Triple::x86_64:
5706 handleAnyX86InterruptAttr(S, D, AL);
5708 case llvm::Triple::avr:
5709 handleAVRInterruptAttr(S, D, AL);
5711 case llvm::Triple::riscv32:
5712 case llvm::Triple::riscv64:
5713 handleRISCVInterruptAttr(S, D, AL);
5716 handleARMInterruptAttr(S, D, AL);
5721 static void handleAMDGPUFlatWorkGroupSizeAttr(
Sema &S,
Decl *D,
5733 if (Min == 0 && Max != 0) {
5734 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
5738 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
5743 AMDGPUFlatWorkGroupSizeAttr(AL.
getLoc(), S.
Context, Min, Max,
5760 if (Min == 0 && Max != 0) {
5761 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 0;
5764 if (Max != 0 && Min > Max) {
5765 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_invalid) << AL << 1;
5775 uint32_t NumSGPR = 0;
5786 uint32_t NumVGPR = 0;
5796 static void handleX86ForceAlignArgPointerAttr(
Sema &S,
Decl *D,
5801 const auto *VD = dyn_cast<
ValueDecl>(D);
5802 if (VD && VD->getType()->isFunctionPointerType())
5806 if (TD && (TD->getUnderlyingType()->isFunctionPointerType() ||
5807 TD->getUnderlyingType()->isFunctionType()))
5810 if (!isa<FunctionDecl>(D)) {
5811 S.
Diag(AL.
getLoc(), diag::warn_attribute_wrong_decl_type)
5829 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5845 unsigned AttrSpellingListIndex) {
5846 if (D->
hasAttr<DLLExportAttr>()) {
5847 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'dllimport'";
5851 if (D->
hasAttr<DLLImportAttr>())
5854 return ::new (Context) DLLImportAttr(Range, Context, AttrSpellingListIndex);
5858 unsigned AttrSpellingListIndex) {
5859 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
5860 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
5864 if (D->
hasAttr<DLLExportAttr>())
5867 return ::new (Context) DLLExportAttr(Range, Context, AttrSpellingListIndex);
5871 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
5877 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5887 if (
const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
5896 Attr *NewAttr = A.
getKind() == ParsedAttr::AT_DLLExport
5905 unsigned AttrSpellingListIndex,
5906 MSInheritanceAttr::Spelling SemanticSpelling) {
5907 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
5908 if (IA->getSemanticSpelling() == SemanticSpelling)
5910 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
5912 Diag(Range.
getBegin(), diag::note_previous_ms_inheritance);
5916 auto *RD = cast<CXXRecordDecl>(D);
5917 if (RD->hasDefinition()) {
5918 if (checkMSInheritanceAttrOnDefinition(RD, Range, BestCase,
5919 SemanticSpelling)) {
5923 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
5924 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5928 if (RD->getDescribedClassTemplate()) {
5929 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5935 return ::new (Context)
5936 MSInheritanceAttr(Range, Context, BestCase, AttrSpellingListIndex);
5948 StringRef N(
"mutex");
5950 if (AL.
getKind() == ParsedAttr::AT_Capability &&
5956 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
5957 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
5965 if (!checkLockFunAttrCommon(S, D, AL, Args))
5969 Args.data(), Args.size(),
5973 static void handleAcquireCapabilityAttr(
Sema &S,
Decl *D,
5976 if (!checkLockFunAttrCommon(S, D, AL, Args))
5981 Args.data(), Args.size(),
5985 static void handleTryAcquireCapabilityAttr(
Sema &S,
Decl *D,
5988 if (!checkTryLockFunAttrCommon(S, D, AL, Args))
5999 static void handleReleaseCapabilityAttr(
Sema &S,
Decl *D,
6003 checkAttrArgsAreCapabilityObjs(S, D, AL, Args, 0,
true);
6010 static void handleRequiresCapabilityAttr(
Sema &S,
Decl *D,
6017 checkAttrArgsAreCapabilityObjs(S, D, AL, Args);
6021 RequiresCapabilityAttr *RCA = ::new (S.
Context)
6029 if (
const auto *NSD = dyn_cast<NamespaceDecl>(D)) {
6030 if (NSD->isAnonymousNamespace()) {
6031 S.
Diag(AL.
getLoc(), diag::warn_deprecated_anonymous_namespace);
6040 StringRef Str, Replacement;
6053 S.
Diag(AL.
getLoc(), diag::ext_cxx14_attr) << AL;
6061 if (
const auto *S = dyn_cast<VarDecl>(D))
6062 return S->hasGlobalStorage();
6070 std::vector<StringRef> Sanitizers;
6072 for (
unsigned I = 0, E = AL.
getNumArgs(); I != E; ++I) {
6073 StringRef SanitizerName;
6080 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
6081 else if (
isGlobalVar(D) && SanitizerName !=
"address")
6084 Sanitizers.push_back(SanitizerName);
6092 static void handleNoSanitizeSpecificAttr(
Sema &S,
Decl *D,
6095 normalizeName(AttrName);
6096 StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName)
6097 .Case(
"no_address_safety_analysis",
"address")
6098 .Case(
"no_sanitize_address",
"address")
6099 .Case(
"no_sanitize_thread",
"thread")
6100 .Case(
"no_sanitize_memory",
"memory");
6115 if (S.
LangOpts.OpenCLVersion != 200)
6116 S.
Diag(AL.
getLoc(), diag::err_attribute_requires_opencl_version)
6117 << AL <<
"2.0" << 0;
6119 S.
Diag(AL.
getLoc(), diag::warn_opencl_attr_deprecated_ignored) << AL
6126 static bool handleCommonAttributeFeatures(
Sema &S,
Decl *D,
6171 if (D->
hasAttr<OpenCLAccessAttr>()) {
6172 if (D->
getAttr<OpenCLAccessAttr>()->getSemanticSpelling() ==
6174 S.
Diag(AL.
getLoc(), diag::warn_duplicate_declspec)
6177 S.
Diag(AL.
getLoc(), diag::err_opencl_multiple_access_qualifiers)
6189 if (
const auto *PDecl = dyn_cast<ParmVarDecl>(D)) {
6190 const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
6191 if (AL.
getName()->
getName().find(
"read_write") != StringRef::npos) {
6193 S.
Diag(AL.
getLoc(), diag::err_opencl_invalid_read_write)
6194 << AL << PDecl->getType() << DeclTy->
isImageType();
6206 if (!cast<VarDecl>(D)->hasGlobalStorage()) {
6208 << (A.
getKind() == ParsedAttr::AT_AlwaysDestroy);
6212 if (A.
getKind() == ParsedAttr::AT_AlwaysDestroy)
6213 handleSimpleAttributeWithExclusions<AlwaysDestroyAttr, NoDestroyAttr>(S, D, A);
6215 handleSimpleAttributeWithExclusions<NoDestroyAttr, AlwaysDestroyAttr>(S, D, A);
6219 assert(cast<VarDecl>(D)->getStorageDuration() ==
SD_Automatic &&
6220 "uninitialized is only valid on automatic duration variables");
6226 static bool tryMakeVariablePseudoStrong(
Sema &S,
VarDecl *VD,
6227 bool DiagnoseFailure) {
6230 if (DiagnoseFailure) {
6231 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6248 if (DiagnoseFailure) {
6249 S.
Diag(VD->
getBeginLoc(), diag::warn_ignored_objc_externally_retained)
6263 static void handleObjCExternallyRetainedAttr(
Sema &S,
Decl *D,
6265 if (
auto *VD = dyn_cast<VarDecl>(D)) {
6266 assert(!isa<ParmVarDecl>(VD) &&
"should be diagnosed automatically");
6273 if (!tryMakeVariablePseudoStrong(S, VD,
true))
6276 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6294 tryMakeVariablePseudoStrong(S, PVD,
false);
6296 handleSimpleAttribute<ObjCExternallyRetainedAttr>(S, D, AL);
6306 static void ProcessDeclAttribute(
Sema &S, Scope *scope,
Decl *D,
6308 bool IncludeCXX11Attributes) {
6324 ? (unsigned)diag::warn_unhandled_ms_attribute_ignored
6325 : (
unsigned)diag::warn_unknown_attribute_ignored)
6330 if (handleCommonAttributeFeatures(S, D, AL))
6337 assert(AL.
isTypeAttr() &&
"Non-type attribute not handled");
6340 S.
Diag(AL.
getLoc(), diag::err_stmt_attribute_invalid_on_decl)
6343 case ParsedAttr::AT_Interrupt:
6344 handleInterruptAttr(S, D, AL);
6346 case ParsedAttr::AT_X86ForceAlignArgPointer:
6347 handleX86ForceAlignArgPointerAttr(S, D, AL);
6349 case ParsedAttr::AT_DLLExport:
6350 case ParsedAttr::AT_DLLImport:
6351 handleDLLAttr(S, D, AL);
6353 case ParsedAttr::AT_Mips16:
6354 handleSimpleAttributeWithExclusions<Mips16Attr, MicroMipsAttr,
6355 MipsInterruptAttr>(S, D, AL);
6357 case ParsedAttr::AT_NoMips16:
6358 handleSimpleAttribute<NoMips16Attr>(S, D, AL);
6360 case ParsedAttr::AT_MicroMips:
6361 handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(S, D, AL);
6363 case ParsedAttr::AT_NoMicroMips:
6364 handleSimpleAttribute<NoMicroMipsAttr>(S, D, AL);
6366 case ParsedAttr::AT_MipsLongCall:
6367 handleSimpleAttributeWithExclusions<MipsLongCallAttr, MipsShortCallAttr>(
6370 case ParsedAttr::AT_MipsShortCall:
6371 handleSimpleAttributeWithExclusions<MipsShortCallAttr, MipsLongCallAttr>(
6374 case ParsedAttr::AT_AMDGPUFlatWorkGroupSize:
6375 handleAMDGPUFlatWorkGroupSizeAttr(S, D, AL);
6377 case ParsedAttr::AT_AMDGPUWavesPerEU:
6378 handleAMDGPUWavesPerEUAttr(S, D, AL);
6380 case ParsedAttr::AT_AMDGPUNumSGPR:
6381 handleAMDGPUNumSGPRAttr(S, D, AL);
6383 case ParsedAttr::AT_AMDGPUNumVGPR:
6384 handleAMDGPUNumVGPRAttr(S, D, AL);
6386 case ParsedAttr::AT_AVRSignal:
6387 handleAVRSignalAttr(S, D, AL);
6389 case ParsedAttr::AT_WebAssemblyImportModule:
6390 handleWebAssemblyImportModuleAttr(S, D, AL);
6392 case ParsedAttr::AT_WebAssemblyImportName:
6393 handleWebAssemblyImportNameAttr(S, D, AL);
6395 case ParsedAttr::AT_IBAction:
6396 handleSimpleAttribute<IBActionAttr>(S, D, AL);
6398 case ParsedAttr::AT_IBOutlet:
6399 handleIBOutlet(S, D, AL);
6401 case ParsedAttr::AT_IBOutletCollection:
6402 handleIBOutletCollection(S, D, AL);
6404 case ParsedAttr::AT_IFunc:
6405 handleIFuncAttr(S, D, AL);
6407 case ParsedAttr::AT_Alias:
6408 handleAliasAttr(S, D, AL);
6410 case ParsedAttr::AT_Aligned:
6411 handleAlignedAttr(S, D, AL);
6413 case ParsedAttr::AT_AlignValue:
6414 handleAlignValueAttr(S, D, AL);
6416 case ParsedAttr::AT_AllocSize:
6417 handleAllocSizeAttr(S, D, AL);
6419 case ParsedAttr::AT_AlwaysInline:
6420 handleAlwaysInlineAttr(S, D, AL);
6422 case ParsedAttr::AT_Artificial:
6423 handleSimpleAttribute<ArtificialAttr>(S, D, AL);
6425 case ParsedAttr::AT_AnalyzerNoReturn:
6426 handleAnalyzerNoReturnAttr(S, D, AL);
6428 case ParsedAttr::AT_TLSModel:
6429 handleTLSModelAttr(S, D, AL);
6431 case ParsedAttr::AT_Annotate:
6432 handleAnnotateAttr(S, D, AL);
6434 case ParsedAttr::AT_Availability:
6435 handleAvailabilityAttr(S, D, AL);
6437 case ParsedAttr::AT_CarriesDependency:
6438 handleDependencyAttr(S, scope, D, AL);
6440 case ParsedAttr::AT_CPUDispatch:
6441 case ParsedAttr::AT_CPUSpecific:
6442 handleCPUSpecificAttr(S, D, AL);
6444 case ParsedAttr::AT_Common:
6445 handleCommonAttr(S, D, AL);
6447 case ParsedAttr::AT_CUDAConstant:
6448 handleConstantAttr(S, D, AL);
6450 case ParsedAttr::AT_PassObjectSize:
6451 handlePassObjectSizeAttr(S, D, AL);
6453 case ParsedAttr::AT_Constructor:
6454 handleConstructorAttr(S, D, AL);
6456 case ParsedAttr::AT_CXX11NoReturn:
6457 handleSimpleAttribute<CXX11NoReturnAttr>(S, D, AL);
6459 case ParsedAttr::AT_Deprecated:
6460 handleDeprecatedAttr(S, D, AL);
6462 case ParsedAttr::AT_Destructor:
6463 handleDestructorAttr(S, D, AL);
6465 case ParsedAttr::AT_EnableIf:
6466 handleEnableIfAttr(S, D, AL);
6468 case ParsedAttr::AT_DiagnoseIf:
6469 handleDiagnoseIfAttr(S, D, AL);
6471 case ParsedAttr::AT_ExtVectorType:
6472 handleExtVectorTypeAttr(S, D, AL);
6474 case ParsedAttr::AT_ExternalSourceSymbol:
6475 handleExternalSourceSymbolAttr(S, D, AL);
6477 case ParsedAttr::AT_MinSize:
6478 handleMinSizeAttr(S, D, AL);
6480 case ParsedAttr::AT_OptimizeNone:
6481 handleOptimizeNoneAttr(S, D, AL);
6483 case ParsedAttr::AT_FlagEnum:
6484 handleSimpleAttribute<FlagEnumAttr>(S, D, AL);
6486 case ParsedAttr::AT_EnumExtensibility:
6487 handleEnumExtensibilityAttr(S, D, AL);
6489 case ParsedAttr::AT_Flatten:
6490 handleSimpleAttribute<FlattenAttr>(S, D, AL);
6492 case ParsedAttr::AT_Format:
6493 handleFormatAttr(S, D, AL);
6495 case ParsedAttr::AT_FormatArg:
6496 handleFormatArgAttr(S, D, AL);
6498 case ParsedAttr::AT_CUDAGlobal:
6499 handleGlobalAttr(S, D, AL);
6501 case ParsedAttr::AT_CUDADevice:
6502 handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(S, D,
6505 case ParsedAttr::AT_CUDAHost:
6506 handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(S, D, AL);
6508 case ParsedAttr::AT_GNUInline:
6509 handleGNUInlineAttr(S, D, AL);
6511 case ParsedAttr::AT_CUDALaunchBounds:
6512 handleLaunchBoundsAttr(S, D, AL);
6514 case ParsedAttr::AT_Restrict:
6515 handleRestrictAttr(S, D, AL);
6517 case ParsedAttr::AT_LifetimeBound:
6518 handleSimpleAttribute<LifetimeBoundAttr>(S, D, AL);
6520 case ParsedAttr::AT_MayAlias:
6521 handleSimpleAttribute<MayAliasAttr>(S, D, AL);
6523 case ParsedAttr::AT_Mode:
6524 handleModeAttr(S, D, AL);
6526 case ParsedAttr::AT_NoAlias:
6527 handleSimpleAttribute<NoAliasAttr>(S, D, AL);
6529 case ParsedAttr::AT_NoCommon:
6530 handleSimpleAttribute<NoCommonAttr>(S, D, AL);
6532 case ParsedAttr::AT_NoSplitStack:
6533 handleSimpleAttribute<NoSplitStackAttr>(S, D, AL);
6535 case ParsedAttr::AT_NonNull:
6536 if (
auto *PVD = dyn_cast<ParmVarDecl>(D))
6537 handleNonNullAttrParameter(S, PVD, AL);
6539 handleNonNullAttr(S, D, AL);
6541 case ParsedAttr::AT_ReturnsNonNull:
6542 handleReturnsNonNullAttr(S, D, AL);
6544 case ParsedAttr::AT_NoEscape:
6545 handleNoEscapeAttr(S, D, AL);
6547 case ParsedAttr::AT_AssumeAligned:
6548 handleAssumeAlignedAttr(S, D, AL);
6550 case ParsedAttr::AT_AllocAlign:
6551 handleAllocAlignAttr(S, D, AL);
6553 case ParsedAttr::AT_Overloadable:
6554 handleSimpleAttribute<OverloadableAttr>(S, D, AL);
6556 case ParsedAttr::AT_Ownership:
6557 handleOwnershipAttr(S, D, AL);
6559 case ParsedAttr::AT_Cold:
6560 handleSimpleAttributeWithExclusions<ColdAttr, HotAttr>(S, D, AL);
6562 case ParsedAttr::AT_Hot:
6563 handleSimpleAttributeWithExclusions<HotAttr, ColdAttr>(S, D, AL);
6565 case ParsedAttr::AT_Naked:
6566 handleNakedAttr(S, D, AL);
6568 case ParsedAttr::AT_NoReturn:
6569 handleNoReturnAttr(S, D, AL);
6571 case ParsedAttr::AT_AnyX86NoCfCheck:
6572 handleNoCfCheckAttr(S, D, AL);
6574 case ParsedAttr::AT_NoThrow:
6575 handleSimpleAttribute<NoThrowAttr>(S, D, AL);
6577 case ParsedAttr::AT_CUDAShared:
6578 handleSharedAttr(S, D, AL);
6580 case ParsedAttr::AT_VecReturn:
6581 handleVecReturnAttr(S, D, AL);
6583 case ParsedAttr::AT_ObjCOwnership:
6584 handleObjCOwnershipAttr(S, D, AL);
6586 case ParsedAttr::AT_ObjCPreciseLifetime:
6587 handleObjCPreciseLifetimeAttr(S, D, AL);
6589 case ParsedAttr::AT_ObjCReturnsInnerPointer:
6590 handleObjCReturnsInnerPointerAttr(S, D, AL);
6592 case ParsedAttr::AT_ObjCRequiresSuper:
6593 handleObjCRequiresSuperAttr(S, D, AL);
6595 case ParsedAttr::AT_ObjCBridge:
6596 handleObjCBridgeAttr(S, D, AL);
6598 case ParsedAttr::AT_ObjCBridgeMutable:
6599 handleObjCBridgeMutableAttr(S, D, AL);
6601 case ParsedAttr::AT_ObjCBridgeRelated:
6602 handleObjCBridgeRelatedAttr(S, D, AL);
6604 case ParsedAttr::AT_ObjCDesignatedInitializer:
6605 handleObjCDesignatedInitializer(S, D, AL);
6607 case ParsedAttr::AT_ObjCRuntimeName:
6608 handleObjCRuntimeName(S, D, AL);
6610 case ParsedAttr::AT_ObjCRuntimeVisible:
6611 handleSimpleAttribute<ObjCRuntimeVisibleAttr>(S, D, AL);
6613 case ParsedAttr::AT_ObjCBoxable:
6614 handleObjCBoxable(S, D, AL);
6616 case ParsedAttr::AT_CFAuditedTransfer:
6617 handleSimpleAttributeWithExclusions<CFAuditedTransferAttr,
6618 CFUnknownTransferAttr>(S, D, AL);
6620 case ParsedAttr::AT_CFUnknownTransfer:
6621 handleSimpleAttributeWithExclusions<CFUnknownTransferAttr,
6622 CFAuditedTransferAttr>(S, D, AL);
6624 case ParsedAttr::AT_CFConsumed:
6625 case ParsedAttr::AT_NSConsumed:
6626 case ParsedAttr::AT_OSConsumed:
6628 parsedAttrToRetainOwnershipKind(AL),
6631 case ParsedAttr::AT_NSConsumesSelf:
6632 handleSimpleAttribute<NSConsumesSelfAttr>(S, D, AL);
6634 case ParsedAttr::AT_OSConsumesThis:
6635 handleSimpleAttribute<OSConsumesThisAttr>(S, D, AL);
6637 case ParsedAttr::AT_OSReturnsRetainedOnZero:
6638 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnZeroAttr>(
6639 S, D, AL, isValidOSObjectOutParameter(D),
6640 diag::warn_ns_attribute_wrong_parameter_type,
6643 case ParsedAttr::AT_OSReturnsRetainedOnNonZero:
6644 handleSimpleAttributeOrDiagnose<OSReturnsRetainedOnNonZeroAttr>(
6645 S, D, AL, isValidOSObjectOutParameter(D),
6646 diag::warn_ns_attribute_wrong_parameter_type,
6647 AL, 3, AL.getRange());
6649 case ParsedAttr::AT_NSReturnsAutoreleased:
6650 case ParsedAttr::AT_NSReturnsNotRetained:
6651 case ParsedAttr::AT_NSReturnsRetained:
6652 case ParsedAttr::AT_CFReturnsNotRetained:
6653 case ParsedAttr::AT_CFReturnsRetained:
6654 case ParsedAttr::AT_OSReturnsNotRetained:
6655 case ParsedAttr::AT_OSReturnsRetained:
6656 handleXReturnsXRetainedAttr(S, D, AL);
6658 case ParsedAttr::AT_WorkGroupSizeHint:
6659 handleWorkGroupSize<WorkGroupSizeHintAttr>(S, D, AL);
6661 case ParsedAttr::AT_ReqdWorkGroupSize:
6662 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(S, D, AL);
6664 case ParsedAttr::AT_OpenCLIntelReqdSubGroupSize:
6665 handleSubGroupSize(S, D, AL);
6667 case ParsedAttr::AT_VecTypeHint:
6668 handleVecTypeHint(S, D, AL);
6670 case ParsedAttr::AT_RequireConstantInit:
6671 handleSimpleAttribute<RequireConstantInitAttr>(S, D, AL);
6673 case ParsedAttr::AT_InitPriority:
6674 handleInitPriorityAttr(S, D, AL);
6676 case ParsedAttr::AT_Packed:
6677 handlePackedAttr(S, D, AL);
6679 case ParsedAttr::AT_Section:
6680 handleSectionAttr(S, D, AL);
6682 case ParsedAttr::AT_SpeculativeLoadHardening:
6683 handleSimpleAttribute<SpeculativeLoadHardeningAttr>(S, D, AL);
6685 case ParsedAttr::AT_CodeSeg:
6686 handleCodeSegAttr(S, D, AL);
6688 case ParsedAttr::AT_Target:
6689 handleTargetAttr(S, D, AL);
6691 case ParsedAttr::AT_MinVectorWidth:
6692 handleMinVectorWidthAttr(S, D, AL);
6694 case ParsedAttr::AT_Unavailable:
6695 handleAttrWithMessage<UnavailableAttr>(S, D, AL);
6697 case ParsedAttr::AT_ArcWeakrefUnavailable:
6698 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(S, D, AL);
6700 case ParsedAttr::AT_ObjCRootClass:
6701 handleSimpleAttribute<ObjCRootClassAttr>(S, D, AL);
6703 case ParsedAttr::AT_ObjCSubclassingRestricted:
6704 handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(S, D, AL);
6706 case ParsedAttr::AT_ObjCExplicitProtocolImpl:
6707 handleObjCSuppresProtocolAttr(S, D, AL);
6709 case ParsedAttr::AT_ObjCRequiresPropertyDefs:
6710 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(S, D, AL);
6712 case ParsedAttr::AT_Unused:
6713 handleUnusedAttr(S, D, AL);
6715 case ParsedAttr::AT_ReturnsTwice:
6716 handleSimpleAttribute<ReturnsTwiceAttr>(S, D, AL);
6718 case ParsedAttr::AT_NotTailCalled:
6719 handleSimpleAttributeWithExclusions<NotTailCalledAttr, AlwaysInlineAttr>(
6722 case ParsedAttr::AT_DisableTailCalls:
6723 handleSimpleAttributeWithExclusions<DisableTailCallsAttr, NakedAttr>(S, D,
6726 case ParsedAttr::AT_Used:
6727 handleSimpleAttribute<UsedAttr>(S, D, AL);
6729 case ParsedAttr::AT_Visibility:
6730 handleVisibilityAttr(S, D, AL,
false);
6732 case ParsedAttr::AT_TypeVisibility:
6733 handleVisibilityAttr(S, D, AL,
true);
6735 case ParsedAttr::AT_WarnUnused:
6736 handleSimpleAttribute<WarnUnusedAttr>(S, D, AL);
6738 case ParsedAttr::AT_WarnUnusedResult:
6739 handleWarnUnusedResult(S, D, AL);
6741 case ParsedAttr::AT_Weak:
6742 handleSimpleAttribute<WeakAttr>(S, D, AL);
6744 case ParsedAttr::AT_WeakRef:
6745 handleWeakRefAttr(S, D, AL);
6747 case ParsedAttr::AT_WeakImport:
6748 handleWeakImportAttr(S, D, AL);
6750 case ParsedAttr::AT_TransparentUnion:
6751 handleTransparentUnionAttr(S, D, AL);
6753 case ParsedAttr::AT_ObjCException:
6754 handleSimpleAttribute<ObjCExceptionAttr>(S, D, AL);
6756 case ParsedAttr::AT_ObjCMethodFamily:
6757 handleObjCMethodFamilyAttr(S, D, AL);
6759 case ParsedAttr::AT_ObjCNSObject:
6760 handleObjCNSObject(S, D, AL);
6762 case ParsedAttr::AT_ObjCIndependentClass:
6763 handleObjCIndependentClass(S, D, AL);
6765 case ParsedAttr::AT_Blocks:
6766 handleBlocksAttr(S, D, AL);
6768 case ParsedAttr::AT_Sentinel:
6769 handleSentinelAttr(S, D, AL);
6771 case ParsedAttr::AT_Const:
6772 handleSimpleAttribute<ConstAttr>(S, D, AL);
6774 case ParsedAttr::AT_Pure:
6775 handleSimpleAttribute<PureAttr>(S, D, AL);
6777 case ParsedAttr::AT_Cleanup:
6778 handleCleanupAttr(S, D, AL);
6780 case ParsedAttr::AT_NoDebug:
6781 handleNoDebugAttr(S, D, AL);
6783 case ParsedAttr::AT_NoDuplicate:
6784 handleSimpleAttribute<NoDuplicateAttr>(S, D, AL);
6786 case ParsedAttr::AT_Convergent:
6787 handleSimpleAttribute<ConvergentAttr>(S, D, AL);
6789 case ParsedAttr::AT_NoInline:
6790 handleSimpleAttribute<NoInlineAttr>(S, D, AL);
6792 case ParsedAttr::AT_NoInstrumentFunction:
6793 handleSimpleAttribute<NoInstrumentFunctionAttr>(S, D, AL);
6795 case ParsedAttr::AT_NoStackProtector:
6797 handleSimpleAttribute<NoStackProtectorAttr>(S, D, AL);
6799 case ParsedAttr::AT_StdCall:
6800 case ParsedAttr::AT_CDecl:
6801 case ParsedAttr::AT_FastCall:
6802 case ParsedAttr::AT_ThisCall:
6803 case ParsedAttr::AT_Pascal:
6804 case ParsedAttr::AT_RegCall:
6805 case ParsedAttr::AT_SwiftCall:
6806 case ParsedAttr::AT_VectorCall:
6807 case ParsedAttr::AT_MSABI:
6808 case ParsedAttr::AT_SysVABI:
6809 case ParsedAttr::AT_Pcs:
6810 case ParsedAttr::AT_IntelOclBicc:
6811 case ParsedAttr::AT_PreserveMost:
6812 case ParsedAttr::AT_PreserveAll:
6813 case ParsedAttr::AT_AArch64VectorPcs:
6814 handleCallConvAttr(S, D, AL);
6816 case ParsedAttr::AT_Suppress:
6819 case ParsedAttr::AT_OpenCLKernel:
6820 handleSimpleAttribute<OpenCLKernelAttr>(S, D, AL);
6822 case ParsedAttr::AT_OpenCLAccess:
6823 handleOpenCLAccessAttr(S, D, AL);
6825 case ParsedAttr::AT_OpenCLNoSVM:
6826 handleOpenCLNoSVMAttr(S, D, AL);
6828 case ParsedAttr::AT_SwiftContext:
6831 case ParsedAttr::AT_SwiftErrorResult:
6834 case ParsedAttr::AT_SwiftIndirectResult:
6837 case ParsedAttr::AT_InternalLinkage:
6838 handleInternalLinkageAttr(S, D, AL);
6840 case ParsedAttr::AT_ExcludeFromExplicitInstantiation:
6841 handleSimpleAttribute<ExcludeFromExplicitInstantiationAttr>(S, D, AL);
6843 case ParsedAttr::AT_LTOVisibilityPublic:
6844 handleSimpleAttribute<LTOVisibilityPublicAttr>(S, D, AL);
6848 case ParsedAttr::AT_EmptyBases:
6849 handleSimpleAttribute<EmptyBasesAttr>(S, D, AL);
6851 case ParsedAttr::AT_LayoutVersion:
6852 handleLayoutVersion(S, D, AL);
6854 case ParsedAttr::AT_TrivialABI:
6855 handleSimpleAttribute<TrivialABIAttr>(S, D, AL);
6857 case ParsedAttr::AT_MSNoVTable:
6858 handleSimpleAttribute<MSNoVTableAttr>(S, D, AL);
6860 case ParsedAttr::AT_MSStruct:
6861 handleSimpleAttribute<MSStructAttr>(S, D, AL);
6863 case ParsedAttr::AT_Uuid:
6864 handleUuidAttr(S, D, AL);
6866 case ParsedAttr::AT_MSInheritance:
6867 handleMSInheritanceAttr(S, D, AL);
6869 case ParsedAttr::AT_SelectAny:
6870 handleSimpleAttribute<SelectAnyAttr>(S, D, AL);
6872 case ParsedAttr::AT_Thread:
6873 handleDeclspecThreadAttr(S, D, AL);
6876 case ParsedAttr::AT_AbiTag:
6877 handleAbiTagAttr(S, D, AL);
6881 case ParsedAttr::AT_AssertExclusiveLock:
6882 handleAssertExclusiveLockAttr(S, D, AL);
6884 case ParsedAttr::AT_AssertSharedLock:
6885 handleAssertSharedLockAttr(S, D, AL);
6887 case ParsedAttr::AT_GuardedVar:
6888 handleSimpleAttribute<GuardedVarAttr>(S, D, AL);
6890 case ParsedAttr::AT_PtGuardedVar:
6891 handlePtGuardedVarAttr(S, D, AL);
6893 case ParsedAttr::AT_ScopedLockable:
6894 handleSimpleAttribute<ScopedLockableAttr>(S, D, AL);
6896 case ParsedAttr::AT_NoSanitize:
6897 handleNoSanitizeAttr(S, D, AL);
6899 case ParsedAttr::AT_NoSanitizeSpecific:
6900 handleNoSanitizeSpecificAttr(S, D, AL);
6902 case ParsedAttr::AT_NoThreadSafetyAnalysis:
6903 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(S, D, AL);
6905 case ParsedAttr::AT_GuardedBy:
6906 handleGuardedByAttr(S, D, AL);
6908 case ParsedAttr::AT_PtGuardedBy:
6909 handlePtGuardedByAttr(S, D, AL);
6911 case ParsedAttr::AT_ExclusiveTrylockFunction:
6912 handleExclusiveTrylockFunctionAttr(S, D, AL);
6914 case ParsedAttr::AT_LockReturned:
6915 handleLockReturnedAttr(S, D, AL);
6917 case ParsedAttr::AT_LocksExcluded:
6918 handleLocksExcludedAttr(S, D, AL);
6920 case ParsedAttr::AT_SharedTrylockFunction:
6921 handleSharedTrylockFunctionAttr(S, D, AL);
6923 case ParsedAttr::AT_AcquiredBefore:
6924 handleAcquiredBeforeAttr(S, D, AL);
6926 case ParsedAttr::AT_AcquiredAfter:
6927 handleAcquiredAfterAttr(S, D, AL);
6931 case ParsedAttr::AT_Capability:
6932 case ParsedAttr::AT_Lockable:
6933 handleCapabilityAttr(S, D, AL);
6935 case ParsedAttr::AT_RequiresCapability:
6936 handleRequiresCapabilityAttr(S, D, AL);
6939 case ParsedAttr::AT_AssertCapability:
6940 handleAssertCapabilityAttr(S, D, AL);
6942 case ParsedAttr::AT_AcquireCapability:
6943 handleAcquireCapabilityAttr(S, D, AL);
6945 case ParsedAttr::AT_ReleaseCapability:
6946 handleReleaseCapabilityAttr(S, D, AL);
6948 case ParsedAttr::AT_TryAcquireCapability:
6949 handleTryAcquireCapabilityAttr(S, D, AL);
6953 case ParsedAttr::AT_Consumable:
6954 handleConsumableAttr(S, D, AL);
6956 case ParsedAttr::AT_ConsumableAutoCast:
6957 handleSimpleAttribute<ConsumableAutoCastAttr>(S, D, AL);
6959 case ParsedAttr::AT_ConsumableSetOnRead:
6960 handleSimpleAttribute<ConsumableSetOnReadAttr>(S, D, AL);
6962 case ParsedAttr::AT_CallableWhen:
6963 handleCallableWhenAttr(S, D, AL);
6965 case ParsedAttr::AT_ParamTypestate:
6966 handleParamTypestateAttr(S, D, AL);
6968 case ParsedAttr::AT_ReturnTypestate:
6969 handleReturnTypestateAttr(S, D, AL);
6971 case ParsedAttr::AT_SetTypestate:
6972 handleSetTypestateAttr(S, D, AL);
6974 case ParsedAttr::AT_TestTypestate:
6975 handleTestTypestateAttr(S, D, AL);
6979 case ParsedAttr::AT_ArgumentWithTypeTag:
6980 handleArgumentWithTypeTagAttr(S, D, AL);
6982 case ParsedAttr::AT_TypeTagForDatatype:
6983 handleTypeTagForDatatypeAttr(S, D, AL);
6985 case ParsedAttr::AT_AnyX86NoCallerSavedRegisters:
6986 handleSimpleAttribute<AnyX86NoCallerSavedRegistersAttr>(S, D, AL);
6988 case ParsedAttr::AT_RenderScriptKernel:
6989 handleSimpleAttribute<RenderScriptKernelAttr>(S, D, AL);
6992 case ParsedAttr::AT_XRayInstrument:
6993 handleSimpleAttribute<XRayInstrumentAttr>(S, D, AL);
6995 case ParsedAttr::AT_XRayLogArgs:
6996 handleXRayLogArgsAttr(S, D, AL);
7000 case ParsedAttr::AT_Reinitializes:
7001 handleSimpleAttribute<ReinitializesAttr>(S, D, AL);
7004 case ParsedAttr::AT_AlwaysDestroy:
7005 case ParsedAttr::AT_NoDestroy:
7006 handleDestroyAttr(S, D, AL);
7009 case ParsedAttr::AT_Uninitialized:
7010 handleUninitializedAttr(S, D, AL);
7013 case ParsedAttr::AT_ObjCExternallyRetained:
7014 handleObjCExternallyRetainedAttr(S, D, AL);
7023 bool IncludeCXX11Attributes) {
7024 if (AttrList.
empty())
7028 ProcessDeclAttribute(*
this, S, D, AL, IncludeCXX11Attributes);
7035 Diag(AttrList.begin()->getLoc(), diag::err_attribute_weakref_without_alias)
7036 << cast<NamedDecl>(D);
7045 if (!D->
hasAttr<OpenCLKernelAttr>()) {
7047 if (
const auto *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
7052 }
else if (
const auto *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
7055 }
else if (
const auto *A = D->
getAttr<VecTypeHintAttr>()) {
7058 }
else if (
const auto *A = D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
7061 }
else if (!D->
hasAttr<CUDAGlobalAttr>()) {
7062 if (
const auto *A = D->
getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
7066 }
else if (
const auto *A = D->
getAttr<AMDGPUWavesPerEUAttr>()) {
7070 }
else if (
const auto *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
7074 }
else if (
const auto *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
7087 if (D->
hasAttr<ObjCDesignatedInitializerAttr>() &&
7088 cast<ObjCMethodDecl>(D)->getMethodFamily() !=
OMF_init) {
7090 D->
dropAttr<ObjCDesignatedInitializerAttr>();
7098 if (AL.
getKind() == ParsedAttr::AT_TransparentUnion) {
7099 handleTransparentUnionAttr(*
this, D, AL);
7109 if (AL.
getKind() == ParsedAttr::AT_Annotate) {
7112 Diag(AL.
getLoc(), diag::err_only_annotate_after_access_spec);
7130 S.
Diag(AL.
getLoc(), diag::warn_unknown_attribute_ignored)
7133 S.
Diag(AL.
getLoc(), diag::warn_attribute_not_on_decl) << AL
7153 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
7155 if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
7177 for (
const auto &AI : FT->param_types()) {
7178 ParmVarDecl *Param = BuildParmVarDeclForTypedef(NewFD, Loc, AI);
7180 Params.push_back(Param);
7182 NewFD->setParams(Params);
7184 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
7203 NewD->
addAttr(AliasAttr::CreateImplicit(Context, NDId->
getName(),
7206 WeakTopLevelDecl.push_back(NewD);
7213 PushOnScopeChains(NewD, S);
7214 CurContext = SavedContext;
7223 LoadExternalWeakUndeclaredIdentifiers();
7224 if (!WeakUndeclaredIdentifiers.empty()) {
7226 if (
auto *VD = dyn_cast<VarDecl>(D))
7229 if (
auto *FD = dyn_cast<FunctionDecl>(D))
7234 auto I = WeakUndeclaredIdentifiers.find(
Id);
7235 if (I != WeakUndeclaredIdentifiers.end()) {
7237 DeclApplyPragmaWeak(S, ND, W);
7238 WeakUndeclaredIdentifiers[
Id] = W;
7265 AddPragmaAttributes(S, D);
7271 static bool isForbiddenTypeAllowed(
Sema &S,
Decl *D,
7273 UnavailableAttr::ImplicitReason &reason) {
7277 if (!isa<FieldDecl>(D) && !isa<ObjCPropertyDecl>(D) &&
7278 !isa<FunctionDecl>(D))
7286 if ((isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) {
7289 reason = UnavailableAttr::IR_ForbiddenWeak;
7298 reason = UnavailableAttr::IR_ARCForbiddenType;
7308 auto Reason = UnavailableAttr::IR_None;
7309 if (D && isForbiddenTypeAllowed(S, D, DD, Reason)) {
7310 assert(Reason &&
"didn't set reason?");
7315 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
7318 if (FD->
hasAttr<UnavailableAttr>() &&
7320 diag::err_arc_array_param_no_ownership) {
7331 static const AvailabilityAttr *getAttrForPlatform(
ASTContext &Context,
7334 for (
const auto *A : D->
attrs()) {
7335 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
7341 StringRef ActualPlatform = Avail->getPlatform()->getName();
7342 StringRef RealizedPlatform = ActualPlatform;
7344 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
7345 if (suffix != StringRef::npos)
7346 RealizedPlatform = RealizedPlatform.slice(0, suffix);
7352 if (RealizedPlatform == TargetPlatform)
7367 static std::pair<AvailabilityResult, const NamedDecl *>
7368 ShouldDiagnoseAvailabilityOfDecl(
Sema &S,
const NamedDecl *D,
7369 std::string *Message,
7375 while (
const auto *TD = dyn_cast<TypedefNameDecl>(D)) {
7377 if (
const auto *TT = TD->getUnderlyingType()->getAs<
TagType>()) {
7387 if (
const auto *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
7388 if (IDecl->getDefinition()) {
7389 D = IDecl->getDefinition();
7394 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
7397 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
7398 Result = TheEnumDecl->getAvailability(Message);
7404 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7408 if (Init && Result ==
AR_Available && MD->isClassMethod() &&
7409 MD->getSelector() == S.
NSAPIObj->getNewSelector() &&
7426 VersionTuple DeclVersion,
Decl *Ctx,
7428 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
7431 auto CheckContext = [&](
const Decl *C) {
7433 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, C))
7434 if (AA->getIntroduced() >= DeclVersion)
7437 if (C->isDeprecated())
7443 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(OffendingDecl)) {
7444 if (
const auto *Impl = dyn_cast<ObjCImplDecl>(C)) {
7445 if (MD->getClassInterface() == Impl->getClassInterface())
7451 if (C->isUnavailable())
7457 if (CheckContext(Ctx))
7462 if (
const auto *MethodD = dyn_cast<ObjCMethodDecl>(Ctx))
7463 if (MethodD->isClassMethod() &&
7464 MethodD->getSelector().getAsString() ==
"load")
7467 if (
const auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
7469 if (CheckContext(Interface))
7473 else if (
const auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
7475 if (CheckContext(Interface))
7483 shouldDiagnoseAvailabilityByDefault(
const ASTContext &Context,
7484 const VersionTuple &DeploymentVersion,
7485 const VersionTuple &DeclVersion) {
7487 VersionTuple ForceAvailabilityFromVersion;
7488 switch (Triple.getOS()) {
7489 case llvm::Triple::IOS:
7490 case llvm::Triple::TvOS:
7491 ForceAvailabilityFromVersion = VersionTuple(11);
7493 case llvm::Triple::WatchOS:
7494 ForceAvailabilityFromVersion = VersionTuple(4);
7496 case llvm::Triple::Darwin:
7497 case llvm::Triple::MacOSX:
7498 ForceAvailabilityFromVersion = VersionTuple(10, 13);
7502 return Triple.getVendor() == llvm::Triple::Apple;
7504 return DeploymentVersion >= ForceAvailabilityFromVersion ||
7505 DeclVersion >= ForceAvailabilityFromVersion;
7508 static NamedDecl *findEnclosingDeclToAnnotate(
Decl *OrigCtx) {
7509 for (
Decl *Ctx = OrigCtx; Ctx;
7511 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
7512 return cast<NamedDecl>(Ctx);
7513 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
7514 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
7515 return Imp->getClassInterface();
7525 struct AttributeInsertion {
7530 static AttributeInsertion createInsertionAfter(
const NamedDecl *D) {
7533 static AttributeInsertion createInsertionAfter(
SourceLocation Loc) {
7534 return {
" ", Loc,
""};
7536 static AttributeInsertion createInsertionBefore(
const NamedDecl *D) {
7555 if (!Name.empty() && (Name.front() ==
'-' || Name.front() ==
'+'))
7556 Name = Name.drop_front(1);
7559 Name.split(SlotNames,
':');
7561 if (Name.back() ==
':') {
7563 SlotNames.pop_back();
7564 NumParams = SlotNames.size();
7566 if (SlotNames.size() != 1)
7572 bool AllowDollar = LangOpts.DollarIdents;
7573 for (StringRef S : SlotNames) {
7587 if (isa<ObjCPropertyDecl>(D))
7588 return AttributeInsertion::createInsertionAfter(D);
7589 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
7592 return AttributeInsertion::createInsertionAfter(D);
7594 if (
const auto *TD = dyn_cast<TagDecl>(D)) {
7600 return AttributeInsertion::createInsertionAfter(Loc);
7602 return AttributeInsertion::createInsertionBefore(D);
7622 bool ObjCPropertyAccess) {
7624 unsigned diag, diag_message, diag_fwdclass_message;
7625 unsigned diag_available_here = diag::note_availability_specified_here;
7629 unsigned property_note_select;
7632 unsigned available_here_select_kind;
7634 VersionTuple DeclVersion;
7635 if (
const AvailabilityAttr *AA = getAttrForPlatform(S.
Context, OffendingDecl))
7636 DeclVersion = AA->getIntroduced();
7638 if (!ShouldDiagnoseAvailabilityInContext(S, K, DeclVersion, Ctx,
7646 const AvailabilityAttr *A = getAttrForPlatform(S.
Context, OffendingDecl);
7647 if (A && A->isInherited()) {
7650 const AvailabilityAttr *AForRedecl =
7651 getAttrForPlatform(S.
Context, Redecl);
7652 if (AForRedecl && !AForRedecl->isInherited()) {
7655 NoteLocation = Redecl->getLocation();
7667 const AvailabilityAttr *AA =
7669 VersionTuple Introduced = AA->getIntroduced();
7671 bool UseNewWarning = shouldDiagnoseAvailabilityByDefault(
7674 unsigned Warning = UseNewWarning ? diag::warn_unguarded_availability_new
7675 : diag::warn_unguarded_availability;
7677 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
7680 S.
Diag(Loc, Warning) << OffendingDecl << PlatformName
7681 << Introduced.getAsString();
7684 diag::note_partial_availability_specified_here)
7685 << OffendingDecl << PlatformName << Introduced.getAsString()
7688 if (
const auto *Enclosing = findEnclosingDeclToAnnotate(Ctx)) {
7689 if (
const auto *TD = dyn_cast<TagDecl>(Enclosing))
7690 if (TD->getDeclName().isEmpty()) {
7691 S.
Diag(TD->getLocation(),
7692 diag::note_decl_unguarded_availability_silence)
7693 << 1 << TD->getKindName();
7696 auto FixitNoteDiag =
7697 S.
Diag(Enclosing->getLocation(),
7698 diag::note_decl_unguarded_availability_silence)
7701 if (Enclosing->hasAttr<AvailabilityAttr>())
7709 std::string PlatformName =
7710 AvailabilityAttr::getPlatformNameSourceSpelling(
7713 std::string Introduced =
7717 (llvm::Twine(Insertion->Prefix) +
"API_AVAILABLE(" + PlatformName +
7718 "(" + Introduced +
"))" + Insertion->Suffix)
7724 diag = !ObjCPropertyAccess ? diag::warn_deprecated
7725 : diag::warn_property_method_deprecated;
7726 diag_message = diag::warn_deprecated_message;
7727 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
7728 property_note_select = 0;
7729 available_here_select_kind = 2;
7730 if (
const auto *AL = OffendingDecl->
getAttr<DeprecatedAttr>())
7731 NoteLocation = AL->getLocation();
7735 diag = !ObjCPropertyAccess ? diag::err_unavailable
7736 : diag::err_property_method_unavailable;
7737 diag_message = diag::err_unavailable_message;
7738 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
7739 property_note_select = 1;
7740 available_here_select_kind = 0;
7742 if (
auto AL = OffendingDecl->
getAttr<UnavailableAttr>()) {
7743 if (AL->isImplicit() && AL->getImplicitReason()) {
7746 auto flagARCError = [&] {
7750 diag = diag::err_unavailable_in_arc;
7753 switch (AL->getImplicitReason()) {
7754 case UnavailableAttr::IR_None:
break;
7756 case UnavailableAttr::IR_ARCForbiddenType:
7758 diag_available_here = diag::note_arc_forbidden_type;
7761 case UnavailableAttr::IR_ForbiddenWeak:
7763 diag_available_here = diag::note_arc_weak_disabled;
7765 diag_available_here = diag::note_arc_weak_no_runtime;
7768 case UnavailableAttr::IR_ARCForbiddenConversion:
7770 diag_available_here = diag::note_performs_forbidden_arc_conversion;
7773 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
7775 diag_available_here = diag::note_arc_init_returns_unrelated;
7778 case UnavailableAttr::IR_ARCFieldWithOwnership:
7780 diag_available_here = diag::note_arc_field_with_ownership;
7788 llvm_unreachable(
"Warning for availability of available declaration?");
7793 StringRef Replacement;
7794 if (
auto AL = OffendingDecl->
getAttr<DeprecatedAttr>())
7795 Replacement = AL->getReplacement();
7796 if (
auto AL = getAttrForPlatform(S.
Context, OffendingDecl))
7797 Replacement = AL->getReplacement();
7800 if (!Replacement.empty())
7804 if (
const auto *MethodDecl = dyn_cast<ObjCMethodDecl>(ReferringDecl)) {
7805 Selector Sel = MethodDecl->getSelector();
7809 if (NumParams && NumParams.getValue() == Sel.
getNumArgs()) {
7810 assert(SelectorSlotNames.size() == Locs.size());
7811 for (
unsigned I = 0; I < Locs.size(); ++I) {
7816 NameRange, SelectorSlotNames[I]));
7828 if (!Message.empty()) {
7829 S.
Diag(Loc, diag_message) << ReferringDecl << Message << FixIts;
7832 << ObjCProperty->
getDeclName() << property_note_select;
7833 }
else if (!UnknownObjCClass) {
7834 S.
Diag(Loc, diag) << ReferringDecl << FixIts;
7837 << ObjCProperty->
getDeclName() << property_note_select;
7839 S.
Diag(Loc, diag_fwdclass_message) << ReferringDecl << FixIts;
7843 S.
Diag(NoteLocation, diag_available_here)
7844 << OffendingDecl << available_here_select_kind;
7850 "Expected an availability diagnostic here");
7853 DoEmitAvailabilityWarning(
7861 assert(DelayedDiagnostics.getCurrentPool());
7863 DelayedDiagnostics.popWithoutEmitting(
state);
7879 bool AnyAccessFailures =
false;
7887 switch (diag.
Kind) {
7892 handleDelayedAvailabilityCheck(*
this, diag, decl);
7899 if (AnyAccessFailures && isa<DecompositionDecl>(decl))
7901 HandleDelayedAccessCheck(diag, decl);
7903 AnyAccessFailures =
true;
7907 handleDelayedForbiddenType(*
this, diag, decl);
7919 assert(curPool &&
"re-emitting in undelayed context not supported");
7920 curPool->
steal(pool);
7930 bool ObjCPropertyAccess) {
7935 AR, Locs, ReferringDecl, OffendingDecl, UnknownObjCClass,
7936 ObjCProperty, Message, ObjCPropertyAccess));
7941 DoEmitAvailabilityWarning(S, AR, Ctx, ReferringDecl, OffendingDecl,
7942 Message, Locs, UnknownObjCClass, ObjCProperty,
7943 ObjCPropertyAccess);
7951 case Stmt::IfStmtClass:
7952 return cast<IfStmt>(
Parent)->getThen() == S ||
7953 cast<IfStmt>(
Parent)->getElse() == S;
7954 case Stmt::WhileStmtClass:
7955 return cast<WhileStmt>(
Parent)->getBody() == S;
7956 case Stmt::DoStmtClass:
7957 return cast<DoStmt>(
Parent)->getBody() == S;
7958 case Stmt::ForStmtClass:
7959 return cast<ForStmt>(
Parent)->getBody() == S;
7960 case Stmt::CXXForRangeStmtClass:
7961 return cast<CXXForRangeStmt>(
Parent)->getBody() == S;
7962 case Stmt::ObjCForCollectionStmtClass:
7963 return cast<ObjCForCollectionStmt>(
Parent)->getBody() == S;
7964 case Stmt::CaseStmtClass:
7965 case Stmt::DefaultStmtClass:
7966 return cast<SwitchCase>(
Parent)->getSubStmt() == S;
7976 bool VisitStmt(
Stmt *S) {
return S != Target; }
7979 static bool isContained(
const Stmt *Target,
const Decl *D) {
7980 StmtUSEFinder Visitor;
7981 Visitor.Target = Target;
7982 return !Visitor.TraverseDecl(const_cast<Decl *>(D));
7998 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
8000 LastDeclUSEFinder Visitor;
8004 if (!Visitor.TraverseStmt(const_cast<Stmt *>(S)))
8017 class DiagnoseUnguardedAvailability
8032 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
8033 : SemaRef(SemaRef), Ctx(Ctx) {
8034 AvailabilityStack.push_back(
8038 bool TraverseDecl(
Decl *D) {
8040 if (!D || isa<FunctionDecl>(D))
8042 return Base::TraverseDecl(D);
8045 bool TraverseStmt(
Stmt *S) {
8048 StmtStack.push_back(S);
8049 bool Result = Base::TraverseStmt(S);
8050 StmtStack.pop_back();
8054 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
8056 bool TraverseIfStmt(
IfStmt *If);
8058 bool TraverseLambdaExpr(
LambdaExpr *E) {
return true; }
8077 DiagnoseDeclAvailability(
8084 DiagnoseDeclAvailability(DRE->
getDecl(),
8101 bool VisitTypeLoc(
TypeLoc Ty);
8104 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
8108 std::tie(Result, OffendingDecl) =
8109 ShouldDiagnoseAvailabilityOfDecl(SemaRef, D,
nullptr, ReceiverClass);
8116 const AvailabilityAttr *AA =
8117 getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
8118 VersionTuple Introduced = AA->getIntroduced();
8120 if (AvailabilityStack.back() >= Introduced)
8125 if (!ShouldDiagnoseAvailabilityInContext(SemaRef, Result, Introduced, Ctx,
8134 shouldDiagnoseAvailabilityByDefault(
8136 SemaRef.Context.getTargetInfo().getPlatformMinVersion(), Introduced)
8137 ? diag::warn_unguarded_availability_new
8138 : diag::warn_unguarded_availability;
8140 std::string PlatformName = AvailabilityAttr::getPrettyPlatformName(
8141 SemaRef.getASTContext().getTargetInfo().getPlatformName());
8143 SemaRef.Diag(Range.
getBegin(), DiagKind)
8144 << Range << D << PlatformName << Introduced.getAsString();
8147 diag::note_partial_availability_specified_here)
8148 << OffendingDecl << PlatformName << Introduced.getAsString()
8149 << SemaRef.Context.getTargetInfo()
8150 .getPlatformMinVersion()
8154 SemaRef.Diag(Range.
getBegin(), diag::note_unguarded_available_silence)
8156 << (SemaRef.getLangOpts().ObjC ? 0
8160 if (StmtStack.empty())
8162 const Stmt *StmtOfUse = StmtStack.back();
8164 for (
const Stmt *S : llvm::reverse(StmtStack)) {
8165 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
8169 if (isBodyLikeChildStmt(StmtOfUse, S)) {
8177 const Stmt *LastStmtOfUse =
nullptr;
8178 if (isa<DeclStmt>(StmtOfUse) && Scope) {
8179 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
8180 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
8181 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope);
8192 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getEndLoc())
8198 const char *ExtraIndentation =
" ";
8199 std::string FixItString;
8200 llvm::raw_string_ostream FixItOS(FixItString);
8201 FixItOS <<
"if (" << (SemaRef.getLangOpts().ObjC ?
"@available" 8202 :
"__builtin_available")
8204 << AvailabilityAttr::getPlatformNameSourceSpelling(
8205 SemaRef.getASTContext().getTargetInfo().getPlatformName())
8206 <<
" " << Introduced.getAsString() <<
", *)) {\n" 8207 << Indentation << ExtraIndentation;
8210 StmtEndLoc, tok::semi, SM, SemaRef.getLangOpts(),
8212 if (ElseInsertionLoc.isInvalid())
8215 FixItOS.str().clear();
8217 << Indentation <<
"} else {\n" 8218 << Indentation << ExtraIndentation
8219 <<
"// Fallback on earlier versions\n" 8220 << Indentation <<
"}";
8225 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
8232 if (
const auto *TT = dyn_cast<TagType>(TyPtr)) {
8234 DiagnoseDeclAvailability(TD, Range);
8236 }
else if (
const auto *TD = dyn_cast<TypedefType>(TyPtr)) {
8238 DiagnoseDeclAvailability(D, Range);
8240 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
8241 if (
NamedDecl *D = ObjCO->getInterface())
8242 DiagnoseDeclAvailability(D, Range);
8248 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
8249 VersionTuple CondVersion;
8250 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->
getCond())) {
8251 CondVersion = E->getVersion();
8255 if (CondVersion.empty() || CondVersion <= AvailabilityStack.back())
8256 return TraverseStmt(If->
getThen()) && TraverseStmt(If->
getElse());
8259 return Base::TraverseIfStmt(If);
8262 AvailabilityStack.push_back(CondVersion);
8263 bool ShouldContinue = TraverseStmt(If->
getThen());
8264 AvailabilityStack.pop_back();
8266 return ShouldContinue && TraverseStmt(If->
getElse());
8272 Stmt *Body =
nullptr;
8281 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
8283 else if (
auto *BD = dyn_cast<BlockDecl>(D))
8284 Body = BD->getBody();
8286 assert(Body &&
"Need a body here!");
8288 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
8294 bool ObjCPropertyAccess,
8295 bool AvoidPartialAvailabilityChecks,
8297 std::string Message;
8301 std::tie(Result, OffendingDecl) =
8302 ShouldDiagnoseAvailabilityOfDecl(*
this, D, &Message, ClassReceiver);
8307 if (AvoidPartialAvailabilityChecks)
8313 if (getCurFunctionOrMethodDecl()) {
8314 getEnclosingFunction()->HasPotentialAvailabilityViolations =
true;
8316 }
else if (getCurBlock() || getCurLambda()) {
8317 getCurFunction()->HasPotentialAvailabilityViolations =
true;
8323 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
8326 if (PDeclResult == Result)
8331 EmitAvailabilityWarning(*
this, Result, D, OffendingDecl, Message, Locs,
8332 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