35 #include "llvm/ADT/STLExtras.h"
36 #include "llvm/ADT/StringExtras.h"
37 #include "llvm/Support/MathExtras.h"
39 using namespace clang;
42 namespace AttributeLangSupport {
71 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
72 isa<ObjCPropertyDecl>(D);
80 return isa<FunctionProtoType>(FnTy);
81 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
89 return cast<FunctionProtoType>(FnTy)->getNumParams();
90 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
91 return BD->getNumParams();
92 return cast<ObjCMethodDecl>(D)->param_size();
97 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
98 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
99 return BD->getParamDecl(Idx)->getType();
101 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
105 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
106 return FD->getParamDecl(Idx)->getSourceRange();
107 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
108 return MD->parameters()[Idx]->getSourceRange();
109 if (
const auto *BD = dyn_cast<BlockDecl>(D))
110 return BD->getParamDecl(Idx)->getSourceRange();
116 return cast<FunctionType>(FnTy)->getReturnType();
117 return cast<ObjCMethodDecl>(D)->getReturnType();
121 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
122 return FD->getReturnTypeSourceRange();
123 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
124 return MD->getReturnTypeSourceRange();
133 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
134 return BD->isVariadic();
136 return cast<ObjCMethodDecl>(D)->isVariadic();
140 if (
const CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(D))
141 return MethodDecl->isInstance();
157 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
158 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
182 template <
typename Compare>
184 unsigned Num,
unsigned Diag,
199 diag::err_attribute_wrong_number_arguments,
200 std::not_equal_to<unsigned>());
208 diag::err_attribute_too_few_arguments,
209 std::less<unsigned>());
217 diag::err_attribute_too_many_arguments,
218 std::greater<unsigned>());
223 template <
typename AttrInfo>
224 static typename std::enable_if<std::is_base_of<clang::Attr, AttrInfo>::value,
227 return Attr.getLocation();
235 template <
typename AttrInfo>
236 static typename std::enable_if<std::is_base_of<clang::Attr, AttrInfo>::value,
247 template<
typename AttrInfo>
249 uint32_t &Val,
unsigned Idx =
UINT_MAX) {
266 << I.toString(10,
false) << 32 << 1;
270 Val = (uint32_t)I.getZExtValue();
277 template<
typename AttrInfo>
279 int &Val,
unsigned Idx =
UINT_MAX) {
288 << I.toString(10,
false) << 32 << 0;
298 template <
typename AttrTy>
301 if (AttrTy *A = D->
getAttr<AttrTy>()) {
302 S.
Diag(Range.
getBegin(), diag::err_attributes_are_not_compatible) << Ident
304 S.
Diag(A->getLocation(), diag::note_conflicting_attribute);
314 template <
typename AttrInfo>
316 Sema &
S,
const Decl *D,
const AttrInfo &
Attr,
unsigned AttrArgNum,
317 const Expr *IdxExpr, uint64_t &Idx,
bool AllowImplicitThis =
false) {
337 Idx = IdxInt.getLimitedValue();
338 if (Idx < 1 || (!IV && Idx > NumParams)) {
339 S.
Diag(
getAttrLoc(Attr), diag::err_attribute_argument_out_of_bounds)
344 if (HasImplicitThisParam && !AllowImplicitThis) {
347 diag::err_attribute_invalid_implicit_this_argument)
362 unsigned ArgNum, StringRef &Str,
367 Diag(Loc->
Loc, diag::err_attribute_argument_type)
373 *ArgLocation = Loc->
Loc;
383 if (!Literal || !Literal->
isAscii()) {
395 template <
typename AttrType>
402 template <
typename AttrType>
405 handleSimpleAttribute<AttrType>(
S, D, Attr);
410 template <
typename AttrType,
typename IncompatibleAttrType,
411 typename... IncompatibleAttrTypes>
414 if (checkAttrMutualExclusion<IncompatibleAttrType>(S, D, Attr.
getRange(),
449 const ValueDecl *vd = cast<ValueDecl>(D);
451 if (QT->isAnyPointerType())
458 if (RT->isIncompleteType())
465 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_decl_not_pointer)
500 if (RD->
hasAttr<CapabilityAttr>())
508 return Type->getDecl()->hasAttr<CapabilityAttr>();
524 return TN->
hasAttr<CapabilityAttr>();
543 if (
const auto *
E = dyn_cast<DeclRefExpr>(Ex))
545 else if (
const auto *
E = dyn_cast<CastExpr>(Ex))
547 else if (
const auto *
E = dyn_cast<ParenExpr>(Ex))
549 else if (
const auto *
E = dyn_cast<UnaryOperator>(Ex)) {
550 if (
E->getOpcode() == UO_LNot)
553 }
else if (
const auto *
E = dyn_cast<BinaryOperator>(Ex)) {
554 if (
E->getOpcode() == BO_LAnd ||
E->getOpcode() == BO_LOr)
572 bool ParamIdxOk =
false) {
573 for (
unsigned Idx = Sidx; Idx < Attr.
getNumArgs(); ++Idx) {
578 Args.push_back(ArgExp);
582 if (
StringLiteral *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
583 if (StrLit->getLength() == 0 ||
584 (StrLit->isAscii() && StrLit->getString() == StringRef(
"*"))) {
587 Args.push_back(ArgExp);
593 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_ignored) <<
595 Args.push_back(ArgExp);
604 if (UOp->getOpcode() == UO_AddrOf)
605 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
606 if (DRE->getDecl()->isCXXInstanceMember())
607 ArgTy = DRE->getDecl()->getType();
613 if(!RT && ParamIdxOk) {
618 llvm::APInt ArgValue = IL->getValue();
619 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
620 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
621 if(!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
622 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_range)
623 << Attr.
getName() << Idx + 1 << NumParams;
635 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
638 Args.push_back(ArgExp);
662 unsigned Size = Args.size();
701 QualType QT = cast<ValueDecl>(D)->getType();
703 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_decl_not_lockable)
722 Expr **StartArg = &Args[0];
725 StartArg, Args.size(),
735 Expr **StartArg = &Args[0];
738 StartArg, Args.size(),
758 unsigned Size = Args.size();
759 Expr **StartArg = Size == 0 ?
nullptr : &Args[0];
771 unsigned Size = Args.size();
772 Expr **StartArg = Size == 0 ?
nullptr : &Args[0];
785 template <
typename AttrInfo>
787 const AttrInfo &
Attr,
Expr *AttrArg,
788 unsigned FuncParamNo,
unsigned AttrArgNo,
789 bool AllowDependentType =
false) {
800 S.
Diag(SrcLoc, diag::err_attribute_integers_only)
814 unsigned FuncParamNo,
unsigned AttrArgNo,
815 bool AllowDependentType =
false) {
816 assert(Attr.
isArgExpr(AttrArgNo) &&
"Expected expression argument");
818 FuncParamNo, AttrArgNo, AllowDependentType);
826 const auto *FD = cast<FunctionDecl>(D);
827 if (!FD->getReturnType()->isPointerType()) {
828 S.
Diag(Attr.
getLoc(), diag::warn_attribute_return_pointers_only)
867 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
887 Args.data(), Args.size(),
907 unsigned Size = Args.size();
924 unsigned Size = Args.size();
927 Expr **StartArg = &Args[0];
936 Expr *&Cond, StringRef &Msg) {
942 Cond = Converted.
get();
949 Msg =
"<no message provided>";
955 S.
Diag(Attr.
getLoc(), diag::err_attr_cond_never_constant_expr)
958 S.
Diag(PDiag.first, PDiag.second);
965 S.
Diag(Attr.
getLoc(), diag::ext_clang_enable_if);
978 class ArgumentDependenceChecker
983 llvm::SmallPtrSet<const ParmVarDecl *, 16> Parms;
989 if (
const auto *MD = dyn_cast<CXXMethodDecl>(FD))
990 ClassType = MD->getParent();
997 bool referencesArgs(
Expr *
E) {
1005 "`this` doesn't refer to the enclosing class?");
1011 if (
const auto *PVD = dyn_cast<ParmVarDecl>(DRE->
getDecl()))
1012 if (Parms.count(PVD)) {
1022 S.
Diag(Attr.
getLoc(), diag::ext_clang_diagnose_if);
1029 StringRef DiagTypeStr;
1033 DiagnoseIfAttr::DiagnosticType DiagType;
1034 if (!DiagnoseIfAttr::ConvertStrToDiagnosticType(DiagTypeStr, DiagType)) {
1036 diag::err_diagnose_if_invalid_diagnostic_type);
1040 bool ArgDependent =
false;
1041 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1042 ArgDependent = ArgumentDependenceChecker(FD).referencesArgs(Cond);
1044 Attr.
getRange(), S.
Context, Cond, Msg, DiagType, ArgDependent, cast<NamedDecl>(D),
1050 if (D->
hasAttr<PassObjectSizeAttr>()) {
1074 if (!cast<ParmVarDecl>(D)->getType()->isPointerType()) {
1090 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1092 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported)
1097 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type)
1113 if (!RD->hasAttr<ConsumableAttr>()) {
1114 S.
Diag(Attr.
getLoc(), diag::warn_attr_on_unconsumable_class) <<
1115 RD->getNameAsString();
1133 for (
unsigned ArgIndex = 0; ArgIndex < Attr.
getNumArgs(); ++ArgIndex) {
1136 StringRef StateString;
1147 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
1149 S.
Diag(Loc, diag::warn_attribute_type_not_supported)
1150 << Attr.
getName() << StateString;
1154 States.push_back(CallableState);
1170 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
1172 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1173 << Attr.
getName() << StateString;
1177 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1205 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
1207 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported)
1212 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1255 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
1256 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1261 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1280 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1281 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1286 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1303 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
1306 else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
1311 S.
Diag(Attr.
getLoc(), diag::warn_attribute_packed_for_bitfield);
1323 if (
const ObjCIvarDecl *VD = dyn_cast<ObjCIvarDecl>(D)) {
1325 S.
Diag(Attr.
getLoc(), diag::warn_iboutlet_object_type)
1326 << Attr.
getName() << VD->getType() << 0;
1332 S.
Diag(Attr.
getLoc(), diag::warn_iboutlet_object_type)
1333 << Attr.
getName() << PD->getType() << 1;
1359 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
1375 S.
Diag(Attr.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1391 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1392 : diag::err_iboutletcollection_type) << QT;
1412 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1414 for (
const auto *
I : UD->
fields()) {
1428 bool isReturnValue =
false) {
1431 S.
Diag(Attr.
getLoc(), diag::warn_attribute_return_pointers_only)
1432 << Attr.
getName() << AttrParmRange << TypeRange;
1434 S.
Diag(Attr.
getLoc(), diag::warn_attribute_pointers_only)
1435 << Attr.
getName() << AttrParmRange << TypeRange << 0;
1456 NonNullArgs.push_back(Idx);
1467 I != E && !AnyPointers; ++
I) {
1474 S.
Diag(Attr.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1477 unsigned *Start = NonNullArgs.data();
1478 unsigned Size = NonNullArgs.size();
1479 llvm::array_pod_sort(Start, Start + Size);
1491 S.
Diag(Attr.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1535 Expr *OE,
unsigned SpellingListIndex) {
1539 AssumeAlignedAttr TmpAttr(AttrRange,
Context, E, OE, SpellingListIndex);
1543 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1544 << &TmpAttr << AttrRange << SR;
1552 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1556 Diag(AttrLoc, diag::err_attribute_argument_type)
1562 if (!I.isPowerOf2()) {
1563 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1573 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1582 AssumeAlignedAttr(AttrRange,
Context, E, OE, SpellingListIndex));
1586 unsigned SpellingListIndex) {
1589 AllocAlignAttr TmpAttr(AttrRange,
Context, 0, SpellingListIndex);
1594 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1600 const auto *FuncDecl = cast<FunctionDecl>(D);
1609 << &TmpAttr << FuncDecl->getParamDecl(IndexVal)->getSourceRange();
1620 AttrRange,
Context, Val.getZExtValue(), SpellingListIndex));
1626 if (AttrName.size() > 4 && AttrName.startswith(
"__") &&
1627 AttrName.endswith(
"__")) {
1628 AttrName = AttrName.drop_front(2).drop_back(2);
1644 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1650 OwnershipAttr::OwnershipKind K =
1656 case OwnershipAttr::Takes:
1657 case OwnershipAttr::Holds:
1659 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments)
1664 case OwnershipAttr::Returns:
1666 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments)
1675 StringRef ModuleName = Module->
getName();
1681 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1691 case OwnershipAttr::Takes:
1692 case OwnershipAttr::Holds:
1696 case OwnershipAttr::Returns:
1711 if (
I->getOwnKind() != K &&
I->args_end() !=
1712 std::find(
I->args_begin(),
I->args_end(), Idx)) {
1713 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
1716 }
else if (K == OwnershipAttr::Returns &&
1717 I->getOwnKind() == OwnershipAttr::Returns) {
1721 if (std::find(
I->args_begin(),
I->args_end(), Idx) ==
I->args_end()) {
1722 S.
Diag(
I->getLocation(), diag::err_ownership_returns_index_mismatch)
1723 << *(
I->args_begin()) + 1;
1725 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1731 OwnershipArgs.push_back(Idx);
1734 unsigned* start = OwnershipArgs.data();
1735 unsigned size = OwnershipArgs.size();
1736 llvm::array_pod_sort(start, start + size);
1746 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
1764 if (!Ctx->isFileContext()) {
1765 S.
Diag(Attr.
getLoc(), diag::err_attribute_weakref_not_global_context)
1813 const auto *FD = cast<FunctionDecl>(D);
1815 S.
Diag(Attr.
getLoc(), diag::err_alias_is_definition) << FD << 1;
1820 llvm::Triple::ELF) {
1835 S.
Diag(Attr.
getLoc(), diag::err_alias_not_supported_on_darwin);
1839 S.
Diag(Attr.
getLoc(), diag::err_alias_not_supported_on_nvptx);
1843 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1845 S.
Diag(Attr.
getLoc(), diag::err_alias_is_definition) << FD << 0;
1849 const auto *VD = cast<VarDecl>(D);
1850 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1851 S.
Diag(Attr.
getLoc(), diag::err_alias_is_definition) << VD << 0;
1863 if (checkAttrMutualExclusion<HotAttr>(S, D, Attr.
getRange(), Attr.
getName()))
1871 if (checkAttrMutualExclusion<ColdAttr>(S, D, Attr.
getRange(), Attr.
getName()))
1887 if (Model !=
"global-dynamic" && Model !=
"local-dynamic"
1888 && Model !=
"initial-exec" && Model !=
"local-exec") {
1889 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1906 S.
Diag(Attr.
getLoc(), diag::warn_attribute_return_pointers_only)
1912 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
1923 if (checkAttrMutualExclusion<DisableTailCallsAttr>(S, D, Attr.
getRange(),
1929 const auto &Arch = Triple.getArch();
1930 if (Arch != llvm::Triple::x86 &&
1931 (Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
1932 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_on_arch)
1933 << Attr.
getName() << Triple.getArchName();
1948 if (!isa<ObjCMethodDecl>(D)) {
1949 S.
Diag(attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2003 : diag::warn_attribute_wrong_decl_type)
2039 if (VecReturnAttr *A = D->
getAttr<VecReturnAttr>()) {
2040 S.
Diag(Attr.
getLoc(), diag::err_repeat_attribute) << A;
2047 if (!isa<CXXRecordDecl>(record)) {
2048 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2052 if (!cast<CXXRecordDecl>(record)->isPOD()) {
2053 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
2057 for (
const auto *
I : record->
fields()) {
2058 if ((count == 1) || !
I->getType()->isVectorType()) {
2059 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
2072 if (isa<ParmVarDecl>(D)) {
2077 diag::err_carries_dependency_param_not_function_decl);
2089 if (checkAttrMutualExclusion<AlwaysInlineAttr>(S, D, Attr.
getRange(),
2099 if (checkAttrMutualExclusion<NakedAttr>(S, D, Attr.
getRange(),
2108 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
2109 if (VD->hasLocalStorage()) {
2114 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2127 if (IsCXX1zAttr && isa<VarDecl>(D)) {
2131 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2147 uint32_t priority = ConstructorAttr::DefaultPriority;
2158 uint32_t priority = DestructorAttr::DefaultPriority;
2168 template <
typename AttrTy>
2182 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
2183 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
2198 StringRef PlatformName
2199 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
2200 if (PlatformName.empty())
2201 PlatformName = Platform->
getName();
2205 if (!Introduced.
empty() && !Deprecated.
empty() &&
2206 !(Introduced <= Deprecated)) {
2207 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2213 if (!Introduced.
empty() && !Obsoleted.
empty() &&
2214 !(Introduced <= Obsoleted)) {
2215 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2221 if (!Deprecated.
empty() && !Obsoleted.
empty() &&
2222 !(Deprecated <= Obsoleted)) {
2223 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
2237 bool BeforeIsOkay) {
2244 if (BeforeIsOkay && X < Y)
2261 unsigned AttrSpellingListIndex) {
2265 bool FoundAny =
false;
2266 bool OverrideOrImpl =
false;
2270 OverrideOrImpl =
false;
2275 OverrideOrImpl =
true;
2281 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
2282 const AvailabilityAttr *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
2289 if (OldPlatform != Platform) {
2297 if (!OldAA->isImplicit() && Implicit) {
2304 if (!Implicit && OldAA->isImplicit()) {
2305 Attrs.erase(Attrs.begin() + i);
2314 bool OldIsUnavailable = OldAA->getUnavailable();
2316 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl) ||
2317 !
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl) ||
2319 !(OldIsUnavailable == IsUnavailable ||
2320 (OverrideOrImpl && !OldIsUnavailable && IsUnavailable))) {
2321 if (OverrideOrImpl) {
2325 if (!
versionsMatch(OldIntroduced, Introduced, OverrideOrImpl)) {
2327 FirstVersion = OldIntroduced;
2328 SecondVersion = Introduced;
2329 }
else if (!
versionsMatch(Deprecated, OldDeprecated, OverrideOrImpl)) {
2331 FirstVersion = Deprecated;
2332 SecondVersion = OldDeprecated;
2333 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, OverrideOrImpl)) {
2335 FirstVersion = Obsoleted;
2336 SecondVersion = OldObsoleted;
2340 Diag(OldAA->getLocation(),
2341 diag::warn_mismatched_availability_override_unavail)
2342 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2345 Diag(OldAA->getLocation(),
2346 diag::warn_mismatched_availability_override)
2348 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
2357 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
2361 Attrs.erase(Attrs.begin() + i);
2370 if (MergedIntroduced2.
empty())
2371 MergedIntroduced2 = OldIntroduced;
2372 if (MergedDeprecated2.
empty())
2373 MergedDeprecated2 = OldDeprecated;
2374 if (MergedObsoleted2.
empty())
2375 MergedObsoleted2 = OldObsoleted;
2378 MergedIntroduced2, MergedDeprecated2,
2379 MergedObsoleted2)) {
2380 Attrs.erase(Attrs.begin() + i);
2385 MergedIntroduced = MergedIntroduced2;
2386 MergedDeprecated = MergedDeprecated2;
2387 MergedObsoleted = MergedObsoleted2;
2393 MergedIntroduced == Introduced &&
2394 MergedDeprecated == Deprecated &&
2395 MergedObsoleted == Obsoleted)
2401 MergedDeprecated, MergedObsoleted) &&
2403 auto *Avail = ::new (
Context) AvailabilityAttr(Range,
Context, Platform,
2404 Introduced, Deprecated,
2405 Obsoleted, IsUnavailable, Message,
2406 IsStrict, Replacement,
2407 AttrSpellingListIndex);
2408 Avail->setImplicit(Implicit);
2422 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
2423 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
2438 Str = SE->getString();
2442 Replacement = SE->getString();
2462 else if (II->
getName() ==
"ios_app_extension")
2467 if (Version.empty())
2470 auto NewMajor = Major >= 9 ? Major - 7 : 0;
2471 if (NewMajor >= 2) {
2472 if (Version.getMinor().hasValue()) {
2473 if (Version.getSubminor().hasValue())
2474 return VersionTuple(NewMajor, Version.getMinor().getValue(),
2475 Version.getSubminor().getValue());
2477 return VersionTuple(NewMajor, Version.getMinor().getValue());
2484 auto NewIntroduced = adjustWatchOSVersion(Introduced.
Version);
2485 auto NewDeprecated = adjustWatchOSVersion(Deprecated.
Version);
2486 auto NewObsoleted = adjustWatchOSVersion(Obsoleted.
Version);
2509 else if (II->
getName() ==
"ios_app_extension")
2536 "Invalid number of arguments in an external_source_symbol attribute");
2539 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(Attr.
getArgAsExpr(0)))
2540 Language = SE->getString();
2541 StringRef DefinedIn;
2542 if (
const auto *SE = dyn_cast_or_null<StringLiteral>(Attr.
getArgAsExpr(1)))
2543 DefinedIn = SE->getString();
2544 bool IsGeneratedDeclaration = Attr.
getArgAsIdent(2) !=
nullptr;
2547 Attr.
getRange(), S.
Context, Language, DefinedIn, IsGeneratedDeclaration,
2553 typename T::VisibilityType value,
2554 unsigned attrSpellingListIndex) {
2555 T *existingAttr = D->
getAttr<T>();
2557 typename T::VisibilityType existingValue = existingAttr->getVisibility();
2558 if (existingValue == value)
2560 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
2561 S.
Diag(range.
getBegin(), diag::note_previous_attribute);
2564 return ::new (S.
Context) T(range, S.
Context, value, attrSpellingListIndex);
2568 VisibilityAttr::VisibilityType Vis,
2569 unsigned AttrSpellingListIndex) {
2570 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, Range, Vis,
2571 AttrSpellingListIndex);
2575 TypeVisibilityAttr::VisibilityType Vis,
2576 unsigned AttrSpellingListIndex) {
2577 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, Range, Vis,
2578 AttrSpellingListIndex);
2582 bool isTypeVisibility) {
2584 if (isa<TypedefNameDecl>(D)) {
2591 if (isTypeVisibility &&
2592 !(isa<TagDecl>(D) ||
2593 isa<ObjCInterfaceDecl>(D) ||
2594 isa<NamespaceDecl>(D))) {
2606 VisibilityAttr::VisibilityType
type;
2607 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2608 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
2615 if (type == VisibilityAttr::Protected &&
2617 S.
Diag(Attr.
getLoc(), diag::warn_attribute_protected_visibility);
2623 if (isTypeVisibility) {
2625 (TypeVisibilityAttr::VisibilityType) type,
2638 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2644 ObjCMethodFamilyAttr::FamilyKind F;
2645 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2646 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << Attr.
getName()
2666 QualType T = TD->getUnderlyingType();
2668 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2675 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
2695 QualType T = TD->getUnderlyingType();
2697 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2711 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2717 BlocksAttr::BlockType
type;
2718 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
2719 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
2730 unsigned sentinel = (
unsigned)SentinelAttr::DefaultSentinel;
2733 llvm::APSInt Idx(32);
2736 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2742 if (Idx.isSigned() && Idx.isNegative()) {
2743 S.
Diag(Attr.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2748 sentinel = Idx.getZExtValue();
2751 unsigned nullPos = (
unsigned)SentinelAttr::DefaultNullPos;
2754 llvm::APSInt Idx(32);
2757 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2762 nullPos = Idx.getZExtValue();
2764 if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2767 S.
Diag(Attr.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2775 if (isa<FunctionNoProtoType>(FT)) {
2776 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2780 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2781 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2785 if (!MD->isVariadic()) {
2786 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2789 }
else if (
BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2790 if (!BD->isVariadic()) {
2791 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2794 }
else if (
const VarDecl *V = dyn_cast<VarDecl>(D)) {
2800 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2802 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2806 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2811 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2823 S.
Diag(Attr.
getLoc(), diag::warn_attribute_void_function_method)
2828 if (MD->getReturnType()->isVoidType()) {
2829 S.
Diag(Attr.
getLoc(), diag::warn_attribute_void_function_method)
2850 S.
Diag(Attr.
getLoc(), diag::warn_attribute_invalid_on_definition)
2852 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
2854 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
2857 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2869 template <
typename WorkGroupAttr>
2873 for (
unsigned i = 0; i < 3; ++i) {
2877 if (WGSize[i] == 0) {
2878 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_is_zero)
2884 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
2885 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2886 Existing->getYDim() == WGSize[1] &&
2887 Existing->getZDim() == WGSize[2]))
2891 WGSize[0], WGSize[1], WGSize[2],
2902 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_is_zero)
2907 OpenCLIntelReqdSubGroupSizeAttr *Existing =
2908 D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>();
2909 if (Existing && Existing->getSubGroupSize() != SGSize)
2919 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
2926 assert(ParmTSI &&
"no type source info for attribute argument");
2931 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_vec_type_hint)
2936 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
2950 unsigned AttrSpellingListIndex) {
2951 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
2952 if (ExistingAttr->getName() ==
Name)
2954 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section);
2959 AttrSpellingListIndex);
2964 if (!Error.empty()) {
2965 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) <<
Error;
2984 if (!Error.empty()) {
2985 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
3001 for (
auto Str : {
"tune=",
"fpmath="})
3002 if (AttrStr.find(Str) != StringRef::npos)
3003 Diag(LiteralLoc, diag::warn_unsupported_target_attribute) << Str;
3013 TargetAttr *NewAttr =
3019 VarDecl *VD = cast<VarDecl>(D);
3032 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
3034 S.
Diag(Loc, diag::warn_cleanup_ext);
3038 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
3043 if (ULE->hasExplicitTemplateArgs())
3044 S.
Diag(Loc, diag::warn_cleanup_ext);
3046 NI = ULE->getNameInfo();
3048 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
3055 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
3060 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
3071 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
3072 << NI.
getName() << ParamTy << Ty;
3084 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
3091 if (!EnumExtensibilityAttr::ConvertStrToKind(II->
getName(),
3092 ExtensibilityKind)) {
3093 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
3115 if (NotNSStringTy &&
3119 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
3129 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_result_not)
3130 << (NotNSStringTy ?
"string type" :
"NSString")
3158 return llvm::StringSwitch<FormatAttrKind>(Format)
3172 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag",
IgnoredFormat)
3186 S.
Diag(Attr.
getLoc(), diag::err_init_priority_object_attr);
3190 QualType T = cast<VarDecl>(D)->getType();
3194 S.
Diag(Attr.
getLoc(), diag::err_init_priority_object_attr);
3200 uint32_t prioritynum;
3206 if (prioritynum < 101 || prioritynum > 65535) {
3207 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_outof_range)
3220 unsigned AttrSpellingListIndex) {
3223 if (F->getType() == Format &&
3224 F->getFormatIdx() == FormatIdx &&
3225 F->getFirstArg() == FirstArg) {
3228 if (F->getLocation().isInvalid())
3234 return ::new (
Context) FormatAttr(Range,
Context, Format, FormatIdx,
3235 FirstArg, AttrSpellingListIndex);
3242 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
3253 StringRef Format = II->
getName();
3267 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
3278 if (Idx < 1 || Idx > NumArgs) {
3279 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3285 unsigned ArgIdx = Idx - 1;
3287 if (HasImplicitThisParam) {
3290 diag::err_format_attribute_implicit_this_format_string)
3302 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
3311 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
3318 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
3331 if (FirstArg != 0) {
3335 S.
Diag(D->
getLocation(), diag::err_format_attribute_requires_variadic);
3343 if (FirstArg != 0) {
3344 S.
Diag(Attr.
getLoc(), diag::err_format_strftime_third_parameter)
3349 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
3350 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
3373 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
3381 diag::warn_transparent_union_attribute_not_definition);
3387 if (Field == FieldEnd) {
3388 S.
Diag(Attr.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
3396 diag::warn_transparent_union_attribute_floating)
3405 for (; Field != FieldEnd; ++Field) {
3406 QualType FieldType = Field->getType();
3420 S.
Diag(Field->getLocation(),
3421 diag::warn_transparent_union_attribute_field_size_align)
3422 << isSize << Field->getDeclName() << FieldBits;
3423 unsigned FirstBits = isSize? FirstSize : FirstAlign;
3425 diag::note_transparent_union_first_field_size_align)
3426 << isSize << FirstBits;
3445 if (
I->getAnnotation() == Str)
3461 unsigned SpellingListIndex) {
3462 AlignValueAttr TmpAttr(AttrRange,
Context, E, SpellingListIndex);
3467 T = TD->getUnderlyingType();
3468 else if (
ValueDecl *VD = dyn_cast<ValueDecl>(D))
3471 llvm_unreachable(
"Unknown decl type for align_value");
3475 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
3481 llvm::APSInt Alignment;
3484 diag::err_align_value_attribute_argument_not_int,
3489 if (!Alignment.isPowerOf2()) {
3490 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3496 AlignValueAttr(AttrRange,
Context, ICE.
get(),
3497 SpellingListIndex));
3508 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
3522 diag::err_pack_expansion_without_parameter_packs);
3530 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
3531 if (!TND->getUnderlyingType()->isDependentType()) {
3532 S.
Diag(Attr.
getLoc(), diag::err_alignment_dependent_typedef_name)
3544 unsigned SpellingListIndex,
bool IsPackExpansion) {
3545 AlignedAttr TmpAttr(AttrRange,
Context,
true, E, SpellingListIndex);
3549 if (TmpAttr.isAlignas()) {
3562 if (isa<ParmVarDecl>(D)) {
3564 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
3567 if (VD->isExceptionVariable())
3569 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
3570 if (FD->isBitField())
3572 }
else if (!isa<TagDecl>(D)) {
3573 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
3578 if (DiagKind != -1) {
3579 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
3580 << &TmpAttr << DiagKind;
3587 AlignedAttr *AA = ::new (
Context) AlignedAttr(TmpAttr);
3588 AA->setPackExpansion(IsPackExpansion);
3594 llvm::APSInt Alignment;
3597 diag::err_aligned_attribute_argument_not_int,
3602 uint64_t AlignVal = Alignment.getZExtValue();
3609 if (!(TmpAttr.isAlignas() && !Alignment)) {
3610 if (!llvm::isPowerOf2_64(AlignVal)) {
3611 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
3618 unsigned MaxValidAlignment =
3621 if (AlignVal > MaxValidAlignment) {
3622 Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
3628 unsigned MaxTLSAlign =
3631 auto *VD = dyn_cast<
VarDecl>(D);
3632 if (MaxTLSAlign && AlignVal > MaxTLSAlign && VD &&
3634 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
3635 << (
unsigned)AlignVal << VD << MaxTLSAlign;
3640 AlignedAttr *AA = ::new (
Context) AlignedAttr(AttrRange,
Context,
true,
3641 ICE.
get(), SpellingListIndex);
3642 AA->setPackExpansion(IsPackExpansion);
3647 unsigned SpellingListIndex,
bool IsPackExpansion) {
3650 AlignedAttr *AA = ::new (
Context) AlignedAttr(AttrRange,
Context,
false, TS,
3652 AA->setPackExpansion(IsPackExpansion);
3657 assert(D->
hasAttrs() &&
"no attributes on decl");
3660 if (
ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
3661 UnderlyingTy = DiagTy = VD->getType();
3664 if (
EnumDecl *ED = dyn_cast<EnumDecl>(D))
3665 UnderlyingTy = ED->getIntegerType();
3667 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
3674 AlignedAttr *AlignasAttr =
nullptr;
3677 if (
I->isAlignmentDependent())
3684 if (AlignasAttr && Align) {
3687 if (NaturalAlign > RequestedAlign)
3688 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
3689 << DiagTy << (
unsigned)NaturalAlign.
getQuantity();
3695 MSInheritanceAttr::Spelling SemanticSpelling) {
3704 if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance)
3715 Diag(Range.
getBegin(), diag::err_mismatched_ms_inheritance)
3725 bool &IntegerMode,
bool &ComplexMode) {
3727 ComplexMode =
false;
3728 switch (Str.size()) {
3750 if (Str[1] ==
'F') {
3751 IntegerMode =
false;
3752 }
else if (Str[1] ==
'C') {
3753 IntegerMode =
false;
3755 }
else if (Str[1] !=
'I') {
3764 else if (Str ==
"byte")
3768 if (Str ==
"pointer")
3772 if (Str ==
"unwind_word")
3799 unsigned SpellingListIndex,
bool InInstantiation) {
3800 StringRef Str = Name->
getName();
3804 unsigned DestWidth = 0;
3805 bool IntegerMode =
true;
3806 bool ComplexMode =
false;
3807 llvm::APInt VectorSize(64, 0);
3808 if (Str.size() >= 4 && Str[0] ==
'V') {
3810 size_t StrSize = Str.size();
3811 size_t VectorStringLength = 0;
3812 while ((VectorStringLength + 1) < StrSize &&
3813 isdigit(Str[VectorStringLength + 1]))
3814 ++VectorStringLength;
3815 if (VectorStringLength &&
3816 !Str.substr(1, VectorStringLength).getAsInteger(10, VectorSize) &&
3817 VectorSize.isPowerOf2()) {
3819 IntegerMode, ComplexMode);
3821 if (!InInstantiation)
3822 Diag(AttrLoc, diag::warn_vector_mode_deprecated);
3836 Diag(AttrLoc, diag::err_machine_mode) << 0 <<
Name;
3842 OldTy = TD->getUnderlyingType();
3843 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D)) {
3846 OldTy = ED->getIntegerType();
3850 OldTy = cast<ValueDecl>(D)->getType();
3854 ModeAttr(AttrRange,
Context, Name, SpellingListIndex));
3862 OldElemTy = VT->getElementType();
3868 VectorSize.getBoolValue()) {
3869 Diag(AttrLoc, diag::err_enum_mode_vector_type) << Name << AttrRange;
3872 bool IntegralOrAnyEnumType =
3876 !IntegralOrAnyEnumType)
3877 Diag(AttrLoc, diag::err_mode_not_primitive);
3878 else if (IntegerMode) {
3879 if (!IntegralOrAnyEnumType)
3880 Diag(AttrLoc, diag::err_mode_wrong_type);
3881 }
else if (ComplexMode) {
3883 Diag(AttrLoc, diag::err_mode_wrong_type);
3886 Diag(AttrLoc, diag::err_mode_wrong_type);
3897 if (NewElemTy.
isNull()) {
3898 Diag(AttrLoc, diag::err_machine_mode) << 1 <<
Name;
3907 if (VectorSize.getBoolValue()) {
3913 Diag(AttrLoc, diag::err_complex_mode_vector_type);
3917 OldVT->getNumElements() /
3924 Diag(AttrLoc, diag::err_mode_wrong_type);
3930 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
3931 else if (
EnumDecl *ED = dyn_cast<EnumDecl>(D))
3932 ED->setIntegerType(NewTy);
3934 cast<ValueDecl>(D)->setType(NewTy);
3937 ModeAttr(AttrRange,
Context, Name, SpellingListIndex));
3948 unsigned AttrSpellingListIndex) {
3949 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
3950 Diag(Range.
getBegin(), diag::warn_attribute_ignored) << Ident;
3951 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
3955 if (D->
hasAttr<AlwaysInlineAttr>())
3959 AttrSpellingListIndex);
3964 unsigned AttrSpellingListIndex) {
3965 if (checkAttrMutualExclusion<InternalLinkageAttr>(*
this, D, Range, Ident))
3968 return ::new (
Context) CommonAttr(Range,
Context, AttrSpellingListIndex);
3971 InternalLinkageAttr *
3974 unsigned AttrSpellingListIndex) {
3975 if (
auto VD = dyn_cast<VarDecl>(D)) {
3978 if (VD->getKind() != Decl::Var) {
3979 Diag(Range.
getBegin(), diag::warn_attribute_wrong_decl_type)
3985 if (VD->hasLocalStorage()) {
3986 Diag(VD->getLocation(), diag::warn_internal_linkage_local_storage);
3991 if (checkAttrMutualExclusion<CommonAttr>(*
this, D, Range, Ident))
3995 InternalLinkageAttr(Range,
Context, AttrSpellingListIndex);
3999 unsigned AttrSpellingListIndex) {
4000 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
4001 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'minsize'";
4002 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
4006 if (D->
hasAttr<MinSizeAttr>())
4009 return ::new (
Context) MinSizeAttr(Range,
Context, AttrSpellingListIndex);
4013 unsigned AttrSpellingListIndex) {
4014 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
4015 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
4016 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4019 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
4020 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
4021 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
4025 if (D->
hasAttr<OptimizeNoneAttr>())
4029 AttrSpellingListIndex);
4034 if (checkAttrMutualExclusion<NotTailCalledAttr>(S, D, Attr.
getRange(),
4058 if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, Attr.
getRange(),
4061 auto *VD = cast<VarDecl>(D);
4062 if (!VD->hasGlobalStorage()) {
4063 S.
Diag(Attr.
getLoc(), diag::err_cuda_nonglobal_constant);
4071 if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, Attr.
getRange(),
4074 auto *VD = cast<VarDecl>(D);
4077 if (VD->hasExternalStorage() && !isa<IncompleteArrayType>(VD->getType())) {
4078 S.
Diag(Attr.
getLoc(), diag::err_cuda_extern_shared) << VD;
4081 if (S.
getLangOpts().CUDA && VD->hasLocalStorage() &&
4090 if (checkAttrMutualExclusion<CUDADeviceAttr>(S, D, Attr.
getRange(),
4092 checkAttrMutualExclusion<CUDAHostAttr>(S, D, Attr.
getRange(),
4105 if (
const auto *Method = dyn_cast<CXXMethodDecl>(FD)) {
4106 if (Method->isInstance()) {
4107 S.
Diag(Method->getLocStart(), diag::err_kern_is_nonstatic_method)
4111 S.
Diag(Method->getLocStart(), diag::warn_kern_is_method) << Method;
4125 S.
Diag(Attr.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
4143 if (!isa<ObjCMethodDecl>(D)) {
4144 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
4150 case AttributeList::AT_FastCall:
4155 case AttributeList::AT_StdCall:
4160 case AttributeList::AT_ThisCall:
4165 case AttributeList::AT_CDecl:
4170 case AttributeList::AT_Pascal:
4175 case AttributeList::AT_SwiftCall:
4180 case AttributeList::AT_VectorCall:
4185 case AttributeList::AT_MSABI:
4190 case AttributeList::AT_SysVABI:
4195 case AttributeList::AT_RegCall:
4199 case AttributeList::AT_Pcs: {
4200 PcsAttr::PCSType PCS;
4203 PCS = PcsAttr::AAPCS;
4206 PCS = PcsAttr::AAPCS_VFP;
4209 llvm_unreachable(
"unexpected calling convention in pcs attribute");
4217 case AttributeList::AT_IntelOclBicc:
4222 case AttributeList::AT_PreserveMost:
4226 case AttributeList::AT_PreserveAll:
4231 llvm_unreachable(
"unexpected attribute kind");
4239 std::vector<StringRef> DiagnosticIdentifiers;
4248 DiagnosticIdentifiers.push_back(RuleName);
4265 unsigned ReqArgs = attr.
getKind() == AttributeList::AT_Pcs ? 1 : 0;
4273 case AttributeList::AT_CDecl: CC =
CC_C;
break;
4277 case AttributeList::AT_Pascal: CC =
CC_X86Pascal;
break;
4278 case AttributeList::AT_SwiftCall: CC =
CC_Swift;
break;
4281 case AttributeList::AT_MSABI:
4285 case AttributeList::AT_SysVABI:
4289 case AttributeList::AT_Pcs: {
4295 if (StrRef ==
"aapcs") {
4298 }
else if (StrRef ==
"aapcs-vfp") {
4310 default: llvm_unreachable(
"unexpected attribute kind");
4321 bool IsCXXMethod =
false, IsVariadic =
false;
4373 unsigned spellingIndex) {
4378 if (existingAttr->getABI() != abi) {
4379 Diag(range.
getBegin(), diag::err_attributes_are_not_compatible)
4381 Diag(existingAttr->getLocation(), diag::note_conflicting_attribute);
4388 llvm_unreachable(
"explicit attribute for ordinary parameter ABI?");
4392 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4397 SwiftContextAttr(range,
Context, spellingIndex));
4402 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4407 SwiftErrorResultAttr(range,
Context, spellingIndex));
4412 Diag(range.
getBegin(), diag::err_swift_abi_parameter_wrong_type)
4417 SwiftIndirectResultAttr(range,
Context, spellingIndex));
4420 llvm_unreachable(
"bad parameter ABI attribute");
4442 Diag(Attr.
getLoc(), diag::err_attribute_regparm_wrong_platform)
4450 Diag(Attr.
getLoc(), diag::err_attribute_regparm_invalid_number)
4464 const CUDALaunchBoundsAttr &
Attr,
4465 const unsigned Idx) {
4481 if (!I.isIntN(32)) {
4482 S.
Diag(E->
getExprLoc(), diag::err_ice_too_large) << I.toString(10,
false)
4487 S.
Diag(E->
getExprLoc(), diag::warn_attribute_argument_n_negative)
4494 assert(!ValArg.isInvalid() &&
4495 "Unexpected PerformCopyInitialization() failure.");
4501 Expr *MinBlocks,
unsigned SpellingListIndex) {
4502 CUDALaunchBoundsAttr TmpAttr(AttrRange,
Context, MaxThreads, MinBlocks,
4505 if (MaxThreads ==
nullptr)
4510 if (MinBlocks ==
nullptr)
4515 AttrRange,
Context, MaxThreads, MinBlocks, SpellingListIndex));
4532 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
4543 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_decl_type)
4548 uint64_t ArgumentIdx;
4553 uint64_t TypeTagIdx;
4558 bool IsPointer = (Attr.
getName()->
getName() ==
"pointer_with_type_tag");
4563 S.
Diag(Attr.
getLoc(), diag::err_attribute_pointers_only)
4570 ArgumentIdx, TypeTagIdx, IsPointer,
4577 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
4585 if (!isa<VarDecl>(D)) {
4586 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_decl_type)
4594 assert(MatchingCTypeLoc &&
"no type source info for attribute argument");
4642 Attr.
getKind() == AttributeList::AT_NSConsumed,
4647 unsigned spellingIndex,
bool isNSConsumed,
4664 (isTemplateInstantiation && isNSConsumed &&
4666 ? diag::err_ns_attribute_wrong_parameter_type
4667 : diag::warn_ns_attribute_wrong_parameter_type))
4669 << (isNSConsumed ?
"ns_consumed" :
"cf_consumed")
4670 << (isNSConsumed ? 0 : 1);
4676 NSConsumedAttr(attrRange,
Context, spellingIndex));
4679 CFConsumedAttr(attrRange,
Context, spellingIndex));
4687 Diag(loc, diag::warn_ns_attribute_wrong_return_type)
4688 <<
"'ns_returns_retained'" << 0 << 0;
4697 returnType = MD->getReturnType();
4699 (Attr.
getKind() == AttributeList::AT_NSReturnsRetained))
4702 returnType = PD->getType();
4705 else if (
auto *Param = dyn_cast<ParmVarDecl>(D)) {
4707 if (returnType.
isNull()) {
4708 S.
Diag(D->
getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
4718 default: llvm_unreachable(
"invalid ownership attribute");
4719 case AttributeList::AT_NSReturnsRetained:
4720 case AttributeList::AT_NSReturnsAutoreleased:
4721 case AttributeList::AT_NSReturnsNotRetained:
4725 case AttributeList::AT_CFReturnsRetained:
4726 case AttributeList::AT_CFReturnsNotRetained:
4738 default: llvm_unreachable(
"invalid ownership attribute");
4739 case AttributeList::AT_NSReturnsRetained:
4744 case AttributeList::AT_NSReturnsAutoreleased:
4745 case AttributeList::AT_NSReturnsNotRetained:
4750 case AttributeList::AT_CFReturnsRetained:
4751 case AttributeList::AT_CFReturnsNotRetained:
4761 if (isa<ParmVarDecl>(D)) {
4762 S.
Diag(D->
getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
4771 } SubjectKind = Function;
4772 if (isa<ObjCMethodDecl>(D))
4773 SubjectKind = Method;
4774 else if (isa<ObjCPropertyDecl>(D))
4777 << Attr.
getName() << SubjectKind << cf
4785 llvm_unreachable(
"invalid ownership attribute");
4786 case AttributeList::AT_NSReturnsAutoreleased:
4790 case AttributeList::AT_CFReturnsNotRetained:
4794 case AttributeList::AT_NSReturnsNotRetained:
4798 case AttributeList::AT_CFReturnsRetained:
4802 case AttributeList::AT_NSReturnsRetained:
4811 const int EP_ObjCMethod = 1;
4812 const int EP_ObjCProperty = 2;
4816 if (isa<ObjCMethodDecl>(D))
4817 resultType = cast<ObjCMethodDecl>(D)->getReturnType();
4819 resultType = cast<ObjCPropertyDecl>(D)->getType();
4826 << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
4842 if (
const ObjCProtocolDecl *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
4845 S.
Diag(PDecl->getLocation(), diag::note_protocol_decl);
4861 if (checkAttrMutualExclusion<CFUnknownTransferAttr>(S, D, Attr.
getRange(),
4872 if (checkAttrMutualExclusion<CFAuditedTransferAttr>(S, D, Attr.
getRange(),
4891 if (
auto TD = dyn_cast<TypedefNameDecl>(D)) {
4893 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_typedef_not_id)
4899 QualType T = TD->getUnderlyingType();
4901 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_typedef_not_void_pointer);
4929 if (!RelatedClass) {
4939 ClassMethod, InstanceMethod,
4948 IFace = CatDecl->getClassInterface();
4963 StringRef MetaDataName;
4977 bool notify =
false;
4986 ObjCBoxableAttr *BoxableAttr = ::new (S.
Context)
4994 L->AddedAttributeToRecord(BoxableAttr, RD);
5012 if (!type->isDependentType() &&
5013 !type->isObjCLifetimeType()) {
5014 S.
Diag(Attr.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
5024 lifetime = type->getObjCARCImplicitLifetime();
5028 assert(type->isDependentType() &&
5029 "didn't infer lifetime for non-dependent type?");
5038 S.
Diag(Attr.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
5053 unsigned AttrSpellingListIndex, StringRef Uuid) {
5054 if (
const auto *UA = D->
getAttr<UuidAttr>()) {
5055 if (UA->getGuid().equals_lower(Uuid))
5057 Diag(UA->getLocation(), diag::err_mismatched_uuid);
5062 return ::new (
Context) UuidAttr(Range,
Context, Uuid, AttrSpellingListIndex);
5067 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
5079 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
5080 StrRef = StrRef.drop_front().drop_back();
5083 if (StrRef.size() != 36) {
5084 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5088 for (
unsigned i = 0; i < 36; ++i) {
5089 if (i == 8 || i == 13 || i == 18 || i == 23) {
5090 if (StrRef[i] !=
'-') {
5091 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5095 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
5107 S.
Diag(Attr.
getLoc(), diag::warn_atl_uuid_deprecated);
5117 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
5133 VarDecl *VD = cast<VarDecl>(D);
5135 S.
Diag(Attr.
getLoc(), diag::err_thread_unsupported);
5139 S.
Diag(Attr.
getLoc(), diag::err_declspec_thread_on_thread_variable);
5143 S.
Diag(Attr.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
5156 Tags.push_back(Tag);
5159 if (
const auto *NS = dyn_cast<NamespaceDecl>(D)) {
5160 if (!NS->isInline()) {
5161 S.
Diag(Attr.
getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
5164 if (NS->isAnonymousNamespace()) {
5165 S.
Diag(Attr.
getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
5169 Tags.push_back(NS->getName());
5174 std::sort(Tags.begin(), Tags.end());
5175 Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
5186 S.
Diag(Attr.
getLoc(), diag::err_attribute_too_many_arguments)
5199 ARMInterruptAttr::InterruptType
Kind;
5200 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5201 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
5202 << Attr.
getName() << Str << ArgLoc;
5225 llvm::APSInt NumParams(32);
5227 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type)
5233 unsigned Num = NumParams.getLimitedValue(255);
5234 if ((Num & 1) || Num > 30) {
5235 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5236 << Attr.
getName() << (int)NumParams.getSExtValue()
5251 S.
Diag(Attr.
getLoc(), diag::err_attribute_too_many_arguments)
5291 if (checkAttrMutualExclusion<Mips16Attr>(S, D, Attr.
getRange(),
5295 MipsInterruptAttr::InterruptType
Kind;
5296 if (!MipsInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
5297 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
5298 << Attr.
getName() <<
"'" + std::string(Str) +
"'";
5316 cast<NamedDecl>(D)->getDeclName().getCXXOverloadedOperator())) {
5317 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
5324 diag::err_anyx86_interrupt_attribute)
5333 if (NumParams < 1 || NumParams > 2) {
5344 diag::err_anyx86_interrupt_attribute)
5356 if (NumParams == 2 &&
5360 diag::err_anyx86_interrupt_attribute)
5382 handleSimpleAttribute<AVRInterruptAttr>(
S, D, Attr);
5395 handleSimpleAttribute<AVRSignalAttr>(
S, D, Attr);
5401 case llvm::Triple::msp430:
5404 case llvm::Triple::mipsel:
5405 case llvm::Triple::mips:
5408 case llvm::Triple::x86:
5409 case llvm::Triple::x86_64:
5412 case llvm::Triple::avr:
5433 if (Min == 0 && Max != 0) {
5434 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_invalid)
5439 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_invalid)
5445 AMDGPUFlatWorkGroupSizeAttr(Attr.
getLoc(), S.
Context, Min, Max,
5463 if (Min == 0 && Max != 0) {
5464 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_invalid)
5468 if (Max != 0 && Min > Max) {
5469 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_invalid)
5481 uint32_t NumSGPR = 0;
5493 uint32_t NumVGPR = 0;
5517 if (!isa<FunctionDecl>(D)) {
5518 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
5536 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
5547 unsigned AttrSpellingListIndex) {
5548 if (D->
hasAttr<DLLExportAttr>()) {
5549 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'dllimport'";
5553 if (D->
hasAttr<DLLImportAttr>())
5556 return ::new (
Context) DLLImportAttr(Range,
Context, AttrSpellingListIndex);
5560 unsigned AttrSpellingListIndex) {
5561 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
5562 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
5566 if (D->
hasAttr<DLLExportAttr>())
5569 return ::new (
Context) DLLExportAttr(Range,
Context, AttrSpellingListIndex);
5573 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
5590 if (
auto *MD = dyn_cast<CXXMethodDecl>(D)) {
5592 MD->getParent()->isLambda()) {
5599 Attr *NewAttr = A.
getKind() == AttributeList::AT_DLLExport
5608 unsigned AttrSpellingListIndex,
5609 MSInheritanceAttr::Spelling SemanticSpelling) {
5610 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
5611 if (IA->getSemanticSpelling() == SemanticSpelling)
5613 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
5615 Diag(Range.
getBegin(), diag::note_previous_ms_inheritance);
5622 SemanticSpelling)) {
5626 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
5627 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5632 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
5639 MSInheritanceAttr(Range,
Context, BestCase, AttrSpellingListIndex);
5651 StringRef N(
"mutex");
5653 if (Attr.
getKind() == AttributeList::AT_Capability &&
5659 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
5660 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
5681 Args.data(), Args.size(),
5721 RequiresCapabilityAttr *RCA = ::new (S.
Context)
5729 if (
auto *NSD = dyn_cast<NamespaceDecl>(D)) {
5730 if (NSD->isAnonymousNamespace()) {
5731 S.
Diag(Attr.
getLoc(), diag::warn_deprecated_anonymous_namespace);
5763 if (
const auto *
S = dyn_cast<VarDecl>(D))
5764 return S->hasGlobalStorage();
5772 std::vector<StringRef> Sanitizers;
5775 StringRef SanitizerName;
5782 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
5783 else if (
isGlobalVar(D) && SanitizerName !=
"address")
5786 Sanitizers.push_back(SanitizerName);
5798 StringRef SanitizerName = llvm::StringSwitch<StringRef>(AttrName)
5799 .Case(
"no_address_safety_analysis",
"address")
5800 .Case(
"no_sanitize_address",
"address")
5801 .Case(
"no_sanitize_thread",
"thread")
5802 .Case(
"no_sanitize_memory",
"memory");
5813 if (InternalLinkageAttr *Internal =
5820 if (S.
LangOpts.OpenCLVersion != 200)
5821 S.
Diag(Attr.
getLoc(), diag::err_attribute_requires_opencl_version)
5822 << Attr.
getName() <<
"2.0" << 0;
5824 S.
Diag(Attr.
getLoc(), diag::warn_opencl_attr_deprecated_ignored)
5874 if (D->
hasAttr<OpenCLAccessAttr>()) {
5875 S.
Diag(Attr.
getLoc(), diag::err_opencl_multiple_access_qualifiers)
5886 if (
const ParmVarDecl *PDecl = dyn_cast<ParmVarDecl>(D)) {
5887 const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
5888 if (Attr.
getName()->
getName().find(
"read_write") != StringRef::npos) {
5890 S.
Diag(Attr.
getLoc(), diag::err_opencl_invalid_read_write)
5911 bool IncludeCXX11Attributes) {
5926 ? diag::warn_unhandled_ms_attribute_ignored
5927 : diag::warn_unknown_attribute_ignored)
5939 assert(Attr.
isTypeAttr() &&
"Non-type attribute not handled");
5942 S.
Diag(Attr.
getLoc(), diag::err_stmt_attribute_invalid_on_decl)
5945 case AttributeList::AT_Interrupt:
5948 case AttributeList::AT_X86ForceAlignArgPointer:
5951 case AttributeList::AT_DLLExport:
5952 case AttributeList::AT_DLLImport:
5955 case AttributeList::AT_Mips16:
5957 MipsInterruptAttr>(
S, D, Attr);
5959 case AttributeList::AT_NoMips16:
5960 handleSimpleAttribute<NoMips16Attr>(
S, D, Attr);
5962 case AttributeList::AT_MicroMips:
5963 handleSimpleAttributeWithExclusions<MicroMipsAttr, Mips16Attr>(
S, D, Attr);
5965 case AttributeList::AT_NoMicroMips:
5966 handleSimpleAttribute<NoMicroMipsAttr>(
S, D, Attr);
5968 case AttributeList::AT_AMDGPUFlatWorkGroupSize:
5971 case AttributeList::AT_AMDGPUWavesPerEU:
5974 case AttributeList::AT_AMDGPUNumSGPR:
5977 case AttributeList::AT_AMDGPUNumVGPR:
5980 case AttributeList::AT_AVRSignal:
5983 case AttributeList::AT_IBAction:
5984 handleSimpleAttribute<IBActionAttr>(
S, D, Attr);
5986 case AttributeList::AT_IBOutlet:
5989 case AttributeList::AT_IBOutletCollection:
5992 case AttributeList::AT_IFunc:
5995 case AttributeList::AT_Alias:
5998 case AttributeList::AT_Aligned:
6001 case AttributeList::AT_AlignValue:
6004 case AttributeList::AT_AllocSize:
6007 case AttributeList::AT_AlwaysInline:
6010 case AttributeList::AT_AnalyzerNoReturn:
6013 case AttributeList::AT_TLSModel:
6016 case AttributeList::AT_Annotate:
6019 case AttributeList::AT_Availability:
6022 case AttributeList::AT_CarriesDependency:
6025 case AttributeList::AT_Common:
6028 case AttributeList::AT_CUDAConstant:
6031 case AttributeList::AT_PassObjectSize:
6034 case AttributeList::AT_Constructor:
6037 case AttributeList::AT_CXX11NoReturn:
6038 handleSimpleAttribute<CXX11NoReturnAttr>(
S, D, Attr);
6040 case AttributeList::AT_Deprecated:
6043 case AttributeList::AT_Destructor:
6046 case AttributeList::AT_EnableIf:
6049 case AttributeList::AT_DiagnoseIf:
6052 case AttributeList::AT_ExtVectorType:
6055 case AttributeList::AT_ExternalSourceSymbol:
6058 case AttributeList::AT_MinSize:
6061 case AttributeList::AT_OptimizeNone:
6064 case AttributeList::AT_FlagEnum:
6065 handleSimpleAttribute<FlagEnumAttr>(
S, D, Attr);
6067 case AttributeList::AT_EnumExtensibility:
6070 case AttributeList::AT_Flatten:
6071 handleSimpleAttribute<FlattenAttr>(
S, D, Attr);
6073 case AttributeList::AT_Format:
6076 case AttributeList::AT_FormatArg:
6079 case AttributeList::AT_CUDAGlobal:
6082 case AttributeList::AT_CUDADevice:
6083 handleSimpleAttributeWithExclusions<CUDADeviceAttr, CUDAGlobalAttr>(
S, D,
6086 case AttributeList::AT_CUDAHost:
6087 handleSimpleAttributeWithExclusions<CUDAHostAttr, CUDAGlobalAttr>(
S, D,
6090 case AttributeList::AT_GNUInline:
6093 case AttributeList::AT_CUDALaunchBounds:
6096 case AttributeList::AT_Restrict:
6099 case AttributeList::AT_MayAlias:
6100 handleSimpleAttribute<MayAliasAttr>(
S, D, Attr);
6102 case AttributeList::AT_Mode:
6105 case AttributeList::AT_NoAlias:
6106 handleSimpleAttribute<NoAliasAttr>(
S, D, Attr);
6108 case AttributeList::AT_NoCommon:
6109 handleSimpleAttribute<NoCommonAttr>(
S, D, Attr);
6111 case AttributeList::AT_NoSplitStack:
6112 handleSimpleAttribute<NoSplitStackAttr>(
S, D, Attr);
6114 case AttributeList::AT_NonNull:
6120 case AttributeList::AT_ReturnsNonNull:
6123 case AttributeList::AT_AssumeAligned:
6126 case AttributeList::AT_AllocAlign:
6129 case AttributeList::AT_Overloadable:
6130 handleSimpleAttribute<OverloadableAttr>(
S, D, Attr);
6132 case AttributeList::AT_Ownership:
6135 case AttributeList::AT_Cold:
6138 case AttributeList::AT_Hot:
6141 case AttributeList::AT_Naked:
6144 case AttributeList::AT_NoReturn:
6147 case AttributeList::AT_NoThrow:
6148 handleSimpleAttribute<NoThrowAttr>(
S, D, Attr);
6150 case AttributeList::AT_CUDAShared:
6153 case AttributeList::AT_VecReturn:
6156 case AttributeList::AT_ObjCOwnership:
6159 case AttributeList::AT_ObjCPreciseLifetime:
6162 case AttributeList::AT_ObjCReturnsInnerPointer:
6165 case AttributeList::AT_ObjCRequiresSuper:
6168 case AttributeList::AT_ObjCBridge:
6171 case AttributeList::AT_ObjCBridgeMutable:
6174 case AttributeList::AT_ObjCBridgeRelated:
6177 case AttributeList::AT_ObjCDesignatedInitializer:
6180 case AttributeList::AT_ObjCRuntimeName:
6183 case AttributeList::AT_ObjCRuntimeVisible:
6184 handleSimpleAttribute<ObjCRuntimeVisibleAttr>(
S, D, Attr);
6186 case AttributeList::AT_ObjCBoxable:
6189 case AttributeList::AT_CFAuditedTransfer:
6192 case AttributeList::AT_CFUnknownTransfer:
6195 case AttributeList::AT_CFConsumed:
6196 case AttributeList::AT_NSConsumed:
6199 case AttributeList::AT_NSConsumesSelf:
6200 handleSimpleAttribute<NSConsumesSelfAttr>(
S, D, Attr);
6202 case AttributeList::AT_NSReturnsAutoreleased:
6203 case AttributeList::AT_NSReturnsNotRetained:
6204 case AttributeList::AT_CFReturnsNotRetained:
6205 case AttributeList::AT_NSReturnsRetained:
6206 case AttributeList::AT_CFReturnsRetained:
6209 case AttributeList::AT_WorkGroupSizeHint:
6210 handleWorkGroupSize<WorkGroupSizeHintAttr>(
S, D, Attr);
6212 case AttributeList::AT_ReqdWorkGroupSize:
6213 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(
S, D, Attr);
6215 case AttributeList::AT_OpenCLIntelReqdSubGroupSize:
6218 case AttributeList::AT_VecTypeHint:
6221 case AttributeList::AT_RequireConstantInit:
6222 handleSimpleAttribute<RequireConstantInitAttr>(
S, D, Attr);
6224 case AttributeList::AT_InitPriority:
6227 case AttributeList::AT_Packed:
6230 case AttributeList::AT_Section:
6233 case AttributeList::AT_Target:
6236 case AttributeList::AT_Unavailable:
6237 handleAttrWithMessage<UnavailableAttr>(
S, D, Attr);
6239 case AttributeList::AT_ArcWeakrefUnavailable:
6240 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(
S, D, Attr);
6242 case AttributeList::AT_ObjCRootClass:
6243 handleSimpleAttribute<ObjCRootClassAttr>(
S, D, Attr);
6245 case AttributeList::AT_ObjCSubclassingRestricted:
6246 handleSimpleAttribute<ObjCSubclassingRestrictedAttr>(
S, D, Attr);
6248 case AttributeList::AT_ObjCExplicitProtocolImpl:
6251 case AttributeList::AT_ObjCRequiresPropertyDefs:
6252 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(
S, D, Attr);
6254 case AttributeList::AT_Unused:
6257 case AttributeList::AT_ReturnsTwice:
6258 handleSimpleAttribute<ReturnsTwiceAttr>(
S, D, Attr);
6260 case AttributeList::AT_NotTailCalled:
6263 case AttributeList::AT_DisableTailCalls:
6266 case AttributeList::AT_Used:
6269 case AttributeList::AT_Visibility:
6272 case AttributeList::AT_TypeVisibility:
6275 case AttributeList::AT_WarnUnused:
6276 handleSimpleAttribute<WarnUnusedAttr>(
S, D, Attr);
6278 case AttributeList::AT_WarnUnusedResult:
6281 case AttributeList::AT_Weak:
6282 handleSimpleAttribute<WeakAttr>(
S, D, Attr);
6284 case AttributeList::AT_WeakRef:
6287 case AttributeList::AT_WeakImport:
6290 case AttributeList::AT_TransparentUnion:
6293 case AttributeList::AT_ObjCException:
6294 handleSimpleAttribute<ObjCExceptionAttr>(
S, D, Attr);
6296 case AttributeList::AT_ObjCMethodFamily:
6299 case AttributeList::AT_ObjCNSObject:
6302 case AttributeList::AT_ObjCIndependentClass:
6305 case AttributeList::AT_Blocks:
6308 case AttributeList::AT_Sentinel:
6311 case AttributeList::AT_Const:
6312 handleSimpleAttribute<ConstAttr>(
S, D, Attr);
6314 case AttributeList::AT_Pure:
6315 handleSimpleAttribute<PureAttr>(
S, D, Attr);
6317 case AttributeList::AT_Cleanup:
6320 case AttributeList::AT_NoDebug:
6323 case AttributeList::AT_NoDuplicate:
6324 handleSimpleAttribute<NoDuplicateAttr>(
S, D, Attr);
6326 case AttributeList::AT_Convergent:
6327 handleSimpleAttribute<ConvergentAttr>(
S, D, Attr);
6329 case AttributeList::AT_NoInline:
6330 handleSimpleAttribute<NoInlineAttr>(
S, D, Attr);
6332 case AttributeList::AT_NoInstrumentFunction:
6333 handleSimpleAttribute<NoInstrumentFunctionAttr>(
S, D, Attr);
6335 case AttributeList::AT_StdCall:
6336 case AttributeList::AT_CDecl:
6337 case AttributeList::AT_FastCall:
6338 case AttributeList::AT_ThisCall:
6339 case AttributeList::AT_Pascal:
6340 case AttributeList::AT_RegCall:
6341 case AttributeList::AT_SwiftCall:
6342 case AttributeList::AT_VectorCall:
6343 case AttributeList::AT_MSABI:
6344 case AttributeList::AT_SysVABI:
6345 case AttributeList::AT_Pcs:
6346 case AttributeList::AT_IntelOclBicc:
6347 case AttributeList::AT_PreserveMost:
6348 case AttributeList::AT_PreserveAll:
6351 case AttributeList::AT_Suppress:
6354 case AttributeList::AT_OpenCLKernel:
6355 handleSimpleAttribute<OpenCLKernelAttr>(
S, D, Attr);
6357 case AttributeList::AT_OpenCLAccess:
6360 case AttributeList::AT_OpenCLNoSVM:
6363 case AttributeList::AT_SwiftContext:
6366 case AttributeList::AT_SwiftErrorResult:
6369 case AttributeList::AT_SwiftIndirectResult:
6372 case AttributeList::AT_InternalLinkage:
6375 case AttributeList::AT_LTOVisibilityPublic:
6376 handleSimpleAttribute<LTOVisibilityPublicAttr>(
S, D, Attr);
6380 case AttributeList::AT_EmptyBases:
6381 handleSimpleAttribute<EmptyBasesAttr>(
S, D, Attr);
6383 case AttributeList::AT_LayoutVersion:
6386 case AttributeList::AT_MSNoVTable:
6387 handleSimpleAttribute<MSNoVTableAttr>(
S, D, Attr);
6389 case AttributeList::AT_MSStruct:
6390 handleSimpleAttribute<MSStructAttr>(
S, D, Attr);
6392 case AttributeList::AT_Uuid:
6395 case AttributeList::AT_MSInheritance:
6398 case AttributeList::AT_SelectAny:
6399 handleSimpleAttribute<SelectAnyAttr>(
S, D, Attr);
6401 case AttributeList::AT_Thread:
6405 case AttributeList::AT_AbiTag:
6410 case AttributeList::AT_AssertExclusiveLock:
6413 case AttributeList::AT_AssertSharedLock:
6416 case AttributeList::AT_GuardedVar:
6417 handleSimpleAttribute<GuardedVarAttr>(
S, D, Attr);
6419 case AttributeList::AT_PtGuardedVar:
6422 case AttributeList::AT_ScopedLockable:
6423 handleSimpleAttribute<ScopedLockableAttr>(
S, D, Attr);
6425 case AttributeList::AT_NoSanitize:
6428 case AttributeList::AT_NoSanitizeSpecific:
6431 case AttributeList::AT_NoThreadSafetyAnalysis:
6432 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(
S, D, Attr);
6434 case AttributeList::AT_GuardedBy:
6437 case AttributeList::AT_PtGuardedBy:
6440 case AttributeList::AT_ExclusiveTrylockFunction:
6443 case AttributeList::AT_LockReturned:
6446 case AttributeList::AT_LocksExcluded:
6449 case AttributeList::AT_SharedTrylockFunction:
6452 case AttributeList::AT_AcquiredBefore:
6455 case AttributeList::AT_AcquiredAfter:
6460 case AttributeList::AT_Capability:
6461 case AttributeList::AT_Lockable:
6464 case AttributeList::AT_RequiresCapability:
6468 case AttributeList::AT_AssertCapability:
6471 case AttributeList::AT_AcquireCapability:
6474 case AttributeList::AT_ReleaseCapability:
6477 case AttributeList::AT_TryAcquireCapability:
6482 case AttributeList::AT_Consumable:
6485 case AttributeList::AT_ConsumableAutoCast:
6486 handleSimpleAttribute<ConsumableAutoCastAttr>(
S, D, Attr);
6488 case AttributeList::AT_ConsumableSetOnRead:
6489 handleSimpleAttribute<ConsumableSetOnReadAttr>(
S, D, Attr);
6491 case AttributeList::AT_CallableWhen:
6494 case AttributeList::AT_ParamTypestate:
6497 case AttributeList::AT_ReturnTypestate:
6500 case AttributeList::AT_SetTypestate:
6503 case AttributeList::AT_TestTypestate:
6508 case AttributeList::AT_ArgumentWithTypeTag:
6511 case AttributeList::AT_TypeTagForDatatype:
6514 case AttributeList::AT_AnyX86NoCallerSavedRegisters:
6517 case AttributeList::AT_RenderScriptKernel:
6518 handleSimpleAttribute<RenderScriptKernelAttr>(
S, D, Attr);
6521 case AttributeList::AT_XRayInstrument:
6522 handleSimpleAttribute<XRayInstrumentAttr>(
S, D, Attr);
6524 case AttributeList::AT_XRayLogArgs:
6534 bool IncludeCXX11Attributes) {
6543 Diag(AttrList->
getLoc(), diag::err_attribute_weakref_without_alias)
6544 << cast<NamedDecl>(D);
6553 if (!D->
hasAttr<OpenCLKernelAttr>()) {
6555 if (
Attr *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
6560 }
else if (
Attr *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
6563 }
else if (
Attr *A = D->
getAttr<VecTypeHintAttr>()) {
6566 }
else if (
Attr *A = D->
getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
6570 }
else if (
Attr *A = D->
getAttr<AMDGPUWavesPerEUAttr>()) {
6574 }
else if (
Attr *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
6578 }
else if (
Attr *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
6582 }
else if (
Attr *A = D->
getAttr<OpenCLIntelReqdSubGroupSizeAttr>()) {
6592 if (
Attr->
getKind() == AttributeList::AT_TransparentUnion) {
6603 if (l->getKind() == AttributeList::AT_Annotate) {
6606 Diag(l->getLoc(), diag::err_only_annotate_after_access_spec);
6617 for ( ; A; A = A->
getNext()) {
6623 S.
Diag(A->
getLoc(), diag::warn_unknown_attribute_ignored)
6626 S.
Diag(A->
getLoc(), diag::warn_attribute_not_on_decl)
6646 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
6670 for (
const auto &AI : FT->param_types()) {
6673 Params.push_back(Param);
6675 NewFD->setParams(Params);
6677 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(ND)) {
6679 VD->getInnerLocStart(), VD->getLocation(), II,
6680 VD->getType(), VD->getTypeSourceInfo(),
6681 VD->getStorageClass());
6682 if (VD->getQualifier()) {
6683 VarDecl *NewVD = cast<VarDecl>(NewD);
6721 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
6722 if (VD->isExternC())
6769 UnavailableAttr::ImplicitReason &reason) {
6773 if (!isa<FieldDecl>(decl) && !isa<ObjCPropertyDecl>(decl) &&
6774 !isa<FunctionDecl>(decl))
6782 if ((isa<ObjCIvarDecl>(decl) || isa<ObjCPropertyDecl>(decl))) {
6785 reason = UnavailableAttr::IR_ForbiddenWeak;
6794 reason = UnavailableAttr::IR_ARCForbiddenType;
6804 auto reason = UnavailableAttr::IR_None;
6806 assert(reason &&
"didn't set reason?");
6807 decl->
addAttr(UnavailableAttr::CreateImplicit(S.
Context,
"", reason,
6812 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(decl)) {
6815 if (FD->
hasAttr<UnavailableAttr>() &&
6817 diag::err_arc_array_param_no_ownership) {
6831 for (
const auto *A : D->
attrs()) {
6832 if (
const auto *Avail = dyn_cast<AvailabilityAttr>(A)) {
6838 StringRef ActualPlatform = Avail->getPlatform()->getName();
6839 StringRef RealizedPlatform = ActualPlatform;
6841 size_t suffix = RealizedPlatform.rfind(
"_app_extension");
6842 if (suffix != StringRef::npos)
6843 RealizedPlatform = RealizedPlatform.slice(0, suffix);
6849 if (RealizedPlatform == TargetPlatform)
6862 static std::pair<AvailabilityResult, const NamedDecl *>
6881 if (IDecl->getDefinition()) {
6882 D = IDecl->getDefinition();
6887 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(D))
6890 if (
const auto *TheEnumDecl = dyn_cast<EnumDecl>(DC)) {
6891 Result = TheEnumDecl->getAvailability(Message);
6906 assert(K !=
AR_Available &&
"Expected an unavailable declaration here!");
6909 auto CheckContext = [&](
const Decl *C) {
6912 if (AA->getIntroduced() >= DeclVersion)
6915 if (C->isDeprecated())
6918 if (C->isUnavailable())
6929 if (CheckContext(OrigCtx))
6933 if (
auto *CatOrImpl = dyn_cast<ObjCImplDecl>(OrigCtx)) {
6935 if (CheckContext(Interface))
6939 else if (
auto *CatD = dyn_cast<ObjCCategoryDecl>(OrigCtx))
6941 if (CheckContext(Interface))
6946 if (CheckContext(Ctx))
6950 if (
auto *CatOrImpl = dyn_cast<ObjCImplDecl>(Ctx)) {
6952 if (CheckContext(Interface))
6956 else if (
auto *CatD = dyn_cast<ObjCCategoryDecl>(Ctx))
6958 if (CheckContext(Interface))
6971 switch (Triple.getOS()) {
6972 case llvm::Triple::IOS:
6973 case llvm::Triple::TvOS:
6976 case llvm::Triple::WatchOS:
6979 case llvm::Triple::Darwin:
6980 case llvm::Triple::MacOSX:
6985 return Triple.getVendor() == llvm::Triple::Apple;
6987 return DeploymentVersion >= ForceAvailabilityFromVersion ||
6988 DeclVersion >= ForceAvailabilityFromVersion;
6992 for (
Decl *Ctx = OrigCtx; Ctx;
6993 Ctx = cast_or_null<Decl>(Ctx->getDeclContext())) {
6994 if (isa<TagDecl>(Ctx) || isa<FunctionDecl>(Ctx) || isa<ObjCMethodDecl>(Ctx))
6995 return cast<NamedDecl>(Ctx);
6996 if (
auto *CD = dyn_cast<ObjCContainerDecl>(Ctx)) {
6997 if (
auto *Imp = dyn_cast<ObjCImplDecl>(Ctx))
6998 return Imp->getClassInterface();
7022 bool ObjCPropertyAccess) {
7024 unsigned diag, diag_message, diag_fwdclass_message;
7025 unsigned diag_available_here = diag::note_availability_specified_here;
7029 unsigned property_note_select;
7032 unsigned available_here_select_kind;
7036 DeclVersion = AA->getIntroduced();
7043 diag = !ObjCPropertyAccess ? diag::warn_deprecated
7044 : diag::warn_property_method_deprecated;
7045 diag_message = diag::warn_deprecated_message;
7046 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
7047 property_note_select = 0;
7048 available_here_select_kind = 2;
7049 if (
const auto *attr = OffendingDecl->
getAttr<DeprecatedAttr>())
7050 NoteLocation = attr->getLocation();
7054 diag = !ObjCPropertyAccess ? diag::err_unavailable
7055 : diag::err_property_method_unavailable;
7056 diag_message = diag::err_unavailable_message;
7057 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
7058 property_note_select = 1;
7059 available_here_select_kind = 0;
7061 if (
auto attr = OffendingDecl->
getAttr<UnavailableAttr>()) {
7062 if (attr->isImplicit() && attr->getImplicitReason()) {
7065 auto flagARCError = [&] {
7069 diag = diag::err_unavailable_in_arc;
7072 switch (attr->getImplicitReason()) {
7073 case UnavailableAttr::IR_None:
break;
7075 case UnavailableAttr::IR_ARCForbiddenType:
7077 diag_available_here = diag::note_arc_forbidden_type;
7080 case UnavailableAttr::IR_ForbiddenWeak:
7082 diag_available_here = diag::note_arc_weak_disabled;
7084 diag_available_here = diag::note_arc_weak_no_runtime;
7087 case UnavailableAttr::IR_ARCForbiddenConversion:
7089 diag_available_here = diag::note_performs_forbidden_arc_conversion;
7092 case UnavailableAttr::IR_ARCInitReturnsUnrelated:
7094 diag_available_here = diag::note_arc_init_returns_unrelated;
7097 case UnavailableAttr::IR_ARCFieldWithOwnership:
7099 diag_available_here = diag::note_arc_field_with_ownership;
7111 const AvailabilityAttr *AA =
7117 diag = NewWarning ? diag::warn_partial_availability_new
7118 : diag::warn_partial_availability;
7119 diag_message = NewWarning ? diag::warn_partial_message_new
7120 : diag::warn_partial_message;
7121 diag_fwdclass_message = NewWarning ? diag::warn_partial_fwdclass_message_new
7122 : diag::warn_partial_fwdclass_message;
7123 property_note_select = 2;
7124 available_here_select_kind = 3;
7129 llvm_unreachable(
"Warning for availability of available declaration?");
7135 if (
auto attr = OffendingDecl->
getAttr<DeprecatedAttr>())
7136 Replacement = attr->getReplacement();
7138 Replacement = attr->getReplacement();
7140 if (!Replacement.empty())
7145 if (!Message.empty()) {
7146 S.
Diag(Loc, diag_message) << ReferringDecl << Message
7151 << ObjCProperty->
getDeclName() << property_note_select;
7152 }
else if (!UnknownObjCClass) {
7153 S.
Diag(Loc, diag) << ReferringDecl
7158 << ObjCProperty->
getDeclName() << property_note_select;
7160 S.
Diag(Loc, diag_fwdclass_message) << ReferringDecl
7169 if (A && A->isInherited()) {
7174 if (AForRedecl && !AForRedecl->isInherited()) {
7177 S.
Diag(Redecl->getLocation(), diag_available_here) << OffendingDecl
7178 << available_here_select_kind;
7184 S.
Diag(NoteLocation, diag_available_here)
7185 << OffendingDecl << available_here_select_kind;
7189 if (
auto *TD = dyn_cast<TagDecl>(Enclosing))
7190 if (TD->getDeclName().isEmpty()) {
7191 S.
Diag(TD->getLocation(), diag::note_partial_availability_silence)
7192 << 1 << TD->getKindName();
7195 S.
Diag(Enclosing->getLocation(), diag::note_partial_availability_silence)
7203 "Expected an availability diagnostic here");
7238 switch (diag.
Kind) {
7263 assert(curPool &&
"re-emitting in undelayed context not supported");
7264 curPool->
steal(pool);
7273 bool ObjCPropertyAccess) {
7278 AR, Loc, ReferringDecl, OffendingDecl, UnknownObjCClass,
7279 ObjCProperty, Message, ObjCPropertyAccess));
7285 Message, Loc, UnknownObjCClass, ObjCProperty,
7286 ObjCPropertyAccess);
7292 bool isBodyLikeChildStmt(
const Stmt *
S,
const Stmt *Parent) {
7294 case Stmt::IfStmtClass:
7295 return cast<IfStmt>(Parent)->getThen() == S ||
7296 cast<IfStmt>(Parent)->getElse() ==
S;
7297 case Stmt::WhileStmtClass:
7298 return cast<WhileStmt>(Parent)->getBody() ==
S;
7299 case Stmt::DoStmtClass:
7300 return cast<DoStmt>(Parent)->getBody() ==
S;
7301 case Stmt::ForStmtClass:
7302 return cast<ForStmt>(Parent)->getBody() ==
S;
7303 case Stmt::CXXForRangeStmtClass:
7304 return cast<CXXForRangeStmt>(Parent)->getBody() ==
S;
7305 case Stmt::ObjCForCollectionStmtClass:
7306 return cast<ObjCForCollectionStmt>(Parent)->getBody() ==
S;
7307 case Stmt::CaseStmtClass:
7308 case Stmt::DefaultStmtClass:
7309 return cast<SwitchCase>(Parent)->getSubStmt() ==
S;
7319 bool VisitStmt(
Stmt *S) {
return S != Target; }
7322 static bool isContained(
const Stmt *Target,
const Decl *D) {
7323 StmtUSEFinder Visitor;
7324 Visitor.Target = Target;
7325 return !Visitor.TraverseDecl(const_cast<Decl *>(D));
7341 static const Stmt *findLastStmtThatUsesDecl(
const Decl *D,
7343 LastDeclUSEFinder Visitor;
7347 if (!Visitor.TraverseStmt(const_cast<Stmt *>(S)))
7360 class DiagnoseUnguardedAvailability
7374 DiagnoseUnguardedAvailability(
Sema &SemaRef,
Decl *Ctx)
7375 : SemaRef(SemaRef), Ctx(Ctx) {
7376 AvailabilityStack.push_back(
7380 bool TraverseDecl(
Decl *D) {
7382 if (!D || isa<FunctionDecl>(D))
7384 return Base::TraverseDecl(D);
7387 bool TraverseStmt(
Stmt *S) {
7390 StmtStack.push_back(S);
7391 bool Result = Base::TraverseStmt(S);
7392 StmtStack.pop_back();
7396 void IssueDiagnostics(
Stmt *S) { TraverseStmt(S); }
7398 bool TraverseIfStmt(
IfStmt *If);
7400 bool TraverseLambdaExpr(
LambdaExpr *E) {
return true; }
7410 DiagnoseDeclAvailability(
7416 DiagnoseDeclAvailability(DRE->
getDecl(),
7433 bool VisitTypeLoc(
TypeLoc Ty);
7436 void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
7440 std::tie(Result, OffendingDecl) =
7448 const AvailabilityAttr *AA =
7452 if (AvailabilityStack.back() >= Introduced)
7468 ? diag::warn_unguarded_availability_new
7469 : diag::warn_unguarded_availability;
7473 << AvailabilityAttr::getPrettyPlatformName(
7475 << Introduced.getAsString();
7478 diag::note_availability_specified_here)
7479 << OffendingDecl << 3;
7482 SemaRef.
Diag(Range.
getBegin(), diag::note_unguarded_available_silence)
7488 if (StmtStack.empty())
7490 const Stmt *StmtOfUse = StmtStack.back();
7492 for (
const Stmt *S : llvm::reverse(StmtStack)) {
7493 if (
const auto *CS = dyn_cast<CompoundStmt>(S)) {
7497 if (isBodyLikeChildStmt(StmtOfUse, S)) {
7505 const Stmt *LastStmtOfUse =
nullptr;
7506 if (isa<DeclStmt>(StmtOfUse) && Scope) {
7507 for (
const Decl *D : cast<DeclStmt>(StmtOfUse)->decls()) {
7508 if (StmtUSEFinder::isContained(StmtStack.back(), D)) {
7509 LastStmtOfUse = LastDeclUSEFinder::findLastStmtThatUsesDecl(D, Scope);
7520 (LastStmtOfUse ? LastStmtOfUse : StmtOfUse)->getLocEnd())
7526 const char *ExtraIndentation =
" ";
7527 std::string FixItString;
7528 llvm::raw_string_ostream FixItOS(FixItString);
7529 FixItOS <<
"if (" << (SemaRef.
getLangOpts().ObjC1 ?
"@available"
7530 :
"__builtin_available")
7532 << AvailabilityAttr::getPlatformNameSourceSpelling(
7534 <<
" " << Introduced.getAsString() <<
", *)) {\n"
7535 << Indentation << ExtraIndentation;
7540 if (ElseInsertionLoc.isInvalid())
7543 FixItOS.str().clear();
7545 << Indentation <<
"} else {\n"
7546 << Indentation << ExtraIndentation
7547 <<
"// Fallback on earlier versions\n"
7548 << Indentation <<
"}";
7553 bool DiagnoseUnguardedAvailability::VisitTypeLoc(
TypeLoc Ty) {
7560 if (
const TagType *TT = dyn_cast<TagType>(TyPtr)) {
7562 DiagnoseDeclAvailability(TD, Range);
7564 }
else if (
const TypedefType *TD = dyn_cast<TypedefType>(TyPtr)) {
7566 DiagnoseDeclAvailability(D, Range);
7568 }
else if (
const auto *ObjCO = dyn_cast<ObjCObjectType>(TyPtr)) {
7569 if (
NamedDecl *D = ObjCO->getInterface())
7570 DiagnoseDeclAvailability(D, Range);
7576 bool DiagnoseUnguardedAvailability::TraverseIfStmt(
IfStmt *If) {
7578 if (
auto *E = dyn_cast<ObjCAvailabilityCheckExpr>(If->
getCond())) {
7583 if (CondVersion.
empty() || CondVersion <= AvailabilityStack.back())
7584 return Base::TraverseStmt(If->
getThen()) &&
7585 Base::TraverseStmt(If->
getElse());
7588 return Base::TraverseIfStmt(If);
7591 AvailabilityStack.push_back(CondVersion);
7592 bool ShouldContinue = TraverseStmt(If->
getThen());
7593 AvailabilityStack.pop_back();
7595 return ShouldContinue && TraverseStmt(If->
getElse());
7601 Stmt *Body =
nullptr;
7610 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(D))
7611 Body = MD->getBody();
7612 else if (
auto *BD = dyn_cast<BlockDecl>(D))
7613 Body = BD->getBody();
7615 assert(Body &&
"Need a body here!");
7617 DiagnoseUnguardedAvailability(*
this, D).IssueDiagnostics(Body);
7622 bool ObjCPropertyAccess,
7623 bool AvoidPartialAvailabilityChecks) {
7624 std::string Message;
7633 if (AvoidPartialAvailabilityChecks)
7652 if (PDeclResult == Result)
7658 UnknownObjCClass, ObjCPDecl, ObjCPropertyAccess);
bool CheckNoCallerSavedRegsAttr(const AttributeList &attr)
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
static void handleConsumableAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getFlags() const
getFlags - Return the flags for this scope.
bool CheckNoReturnAttr(const AttributeList &attr)
unsigned getAddressSpace() const
Return the address space of this type.
static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, const AttributeList &Attr)
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
static bool isGlobalVar(const Decl *D)
Defines the clang::ASTContext interface.
static bool hasFunctionProto(const Decl *D)
hasFunctionProto - Return true if the given decl has a argument information.
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
static bool threadSafetyCheckIsPointer(Sema &S, const Decl *D, const AttributeList &Attr)
Check if passed in Decl is a pointer type.
StmtClass getStmtClass() const
static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
static void handleAssertSharedLockAttr(Sema &S, Decl *D, const AttributeList &Attr)
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.
ExprResult PerformContextuallyConvertToBool(Expr *From)
PerformContextuallyConvertToBool - Perform a contextual conversion of the expression From to bool (C+...
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
static void handleDLLAttr(Sema &S, Decl *D, const AttributeList &A)
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates)...
const AttributeList * getAttrs() const
If there are attributes applied to this declaratorchunk, return them.
Represents a version number in the form major[.minor[.subminor[.build]]].
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.
DeclContext * getCurLexicalContext() const
bool isMemberPointerType() const
QualType getType() const
Retrieves the type of the base class.
static void handleAcquiredAfterAttr(Sema &S, Decl *D, const AttributeList &Attr)
AvailabilityResult getAvailability(std::string *Message=nullptr, VersionTuple EnclosingVersion=VersionTuple()) const
Determine the availability of the given declaration.
static void handleAVRInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
A class which encapsulates the logic for delaying diagnostics during parsing and other processing...
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
static bool checkAttributeNumArgsImpl(Sema &S, const AttributeList &Attr, unsigned Num, unsigned Diag, Compare Comp)
const LangOptions & getLangOpts() const
static QualType getFunctionOrMethodResultType(const Decl *D)
bool diagnoseAppertainsTo(class Sema &S, const Decl *D) const
Stmt - This represents one statement.
FunctionType - C99 6.7.5.3 - Function Declarators.
IfStmt - This represents an if/then/else.
Merge availability attributes for an override, which requires an exact match or a weakening of constr...
unsigned getSemanticSpelling() const
If the parsed attribute has a semantic equivalent, and it would have a semantic Spelling enumeration ...
static void handleObjCPreciseLifetimeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAcquireCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleUuidAttr(Sema &S, Decl *D, const AttributeList &Attr)
QualType getIntTypeForBitwidth(unsigned DestWidth, unsigned Signed) const
getIntTypeForBitwidth - sets integer QualTy according to specified details: bitwidth, signed/unsigned.
static void handleSimpleAttributeWithExclusions(Sema &S, Decl *D, const AttributeList &Attr)
Defines the SourceManager interface.
static void handleObjCIndependentClass(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAttrWithMessage(Sema &S, Decl *D, const AttributeList &Attr)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
const NamedDecl * getAvailabilityOffendingDecl() const
static InitializedEntity InitializeParameter(ASTContext &Context, const ParmVarDecl *Parm)
Create the initialization entity for a parameter.
QualType getUnderlyingType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Decl - This represents one declaration (or definition), e.g.
SourceRange getRange() const
static void handleCommonAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleObjCRuntimeName(Sema &S, Decl *D, const AttributeList &Attr)
static void handleSetTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr)
const AvailabilityChange & getAvailabilityDeprecated() const
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
const NamedDecl * getAvailabilityReferringDecl() const
Defines the C++ template declaration subclasses.
bool isVoidPointerType() const
static DelayedDiagnostic makeAvailability(AvailabilityResult AR, SourceLocation Loc, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess)
DeclContext * OriginalLexicalContext
Generally null except when we temporarily switch decl contexts, like in.
static void handleAllocAlignAttr(Sema &S, Decl *D, const AttributeList &Attr)
Decl * getPreviousDecl()
Retrieve the previous declaration that declares the same entity as this declaration, or NULL if there is no previous declaration.
bool hasDefinition() const
static void handleDestructorAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getProcessingCache() const
static void handleSuppressAttr(Sema &S, Decl *D, const AttributeList &Attr)
The base class of the type hierarchy.
static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, const AttributeList &Attr)
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
unsigned getRegParmMax() const
static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr)
Handle attribute((format(type,idx,firstarg))) attributes based on http://gcc.gnu.org/onlinedocs/gcc/F...
bool isBooleanType() const
A container of type source information.
const Stmt * getElse() const
static void handleNoReturnAttr(Sema &S, Decl *D, const AttributeList &attr)
bool isBlockPointerType() const
static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr)
Represents a path from a specific derived class (which is not represented as part of the path) to a p...
void LoadExternalWeakUndeclaredIdentifiers()
Load weak undeclared identifiers from the external source.
bool hasCustomParsing() const
static bool threadSafetyCheckIsSmartPointer(Sema &S, const RecordType *RT)
OptimizeNoneAttr * mergeOptimizeNoneAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
bool isValidPointerAttrType(QualType T, bool RefOkay=false)
Determine if type T is a valid subject for a nonnull and similar attributes.
static void handleOpenCLNoSVMAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr)
VarDecl - An instance of this class is created to represent a variable declaration or definition...
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled...
Information about one declarator, including the parsed type information and the identifier.
static void handleMinSizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool checkGuardedByAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, Expr *&Arg)
static bool isValidSwiftErrorResultType(QualType type)
Pointers and references to pointers in the default address space.
field_iterator field_begin() const
bool isUsedAsTypeAttr() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
ObjCMethodDecl - Represents an instance or class method declaration.
static bool checkParamIsIntegerType(Sema &S, const FunctionDecl *FD, const AttrInfo &Attr, Expr *AttrArg, unsigned FuncParamNo, unsigned AttrArgNo, bool AllowDependentType=false)
Checks to be sure that the given parameter number is in bounds, and is an integral type...
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
static void handleOwnershipAttr(Sema &S, Decl *D, const AttributeList &AL)
static void handleReturnTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr)
static ObjCPropertyDecl * findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, ObjCPropertyQueryKind queryKind)
Lookup a property by name in the specified DeclContext.
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 isArgIdent(unsigned Arg) const
void AddParameterABIAttr(SourceRange AttrRange, Decl *D, ParameterABI ABI, unsigned SpellingListIndex)
ParmVarDecl - Represents a parameter to a function.
bool isObjCRetainableType() const
Defines the clang::Expr interface and subclasses for C++ expressions.
const Expr * getReplacementExpr() const
FormatAttr * mergeFormatAttr(Decl *D, SourceRange Range, IdentifierInfo *Format, int FormatIdx, int FirstArg, unsigned AttrSpellingListIndex)
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
UuidAttr * mergeUuidAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex, StringRef Uuid)
static void handleDisableTailCallsAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isForbiddenTypeAllowed(Sema &S, Decl *decl, const DelayedDiagnostic &diag, UnavailableAttr::ImplicitReason &reason)
Is the given declaration allowed to use a forbidden type? If so, it'll still be annotated with an att...
Base wrapper for a particular "section" of type source info.
RecordDecl - Represents a struct/union/class.
static void handleExclusiveTrylockFunctionAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void checkAttrArgsAreCapabilityObjs(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args, int Sidx=0, bool ParamIdxOk=false)
Checks that all attribute arguments, starting from Sidx, resolve to a capability object.
static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const AttributeList &Attr, bool IncludeCXX11Attributes)
ProcessDeclAttribute - Apply the specific attribute to the specified decl if the attribute applies to...
bool isExternC() const
Determines whether this function is a function with external, C linkage.
static void handleMSP430InterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
DeclarationName getName() const
getName - Returns the embedded declaration name.
One of these records is kept for each identifier that is lexed.
static void handleAnyX86InterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
sema::DelayedDiagnosticPool * getCurrentPool() const
Returns the current delayed-diagnostics pool.
static StringRef getIndentationForLine(SourceLocation Loc, const SourceManager &SM)
Returns the leading whitespace for line that corresponds to the given location Loc.
SourceLocation getUnavailableLoc() const
static void handleAssumeAlignedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleIBOutlet(Sema &S, Decl *D, const AttributeList &Attr)
AttributeList * getList() const
std::pair< SourceLocation, SourceLocation > getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static void handleAnalyzerNoReturnAttr(Sema &S, Decl *D, const AttributeList &Attr)
ObjCInterfaceDecl * getClassReceiver() const
The results of name lookup within a DeclContext.
static bool checkTypedefTypeForCapability(QualType Ty)
static void handleObjCOwnershipAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleGlobalAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleNoCallerSavedRegsAttr(Sema &S, Decl *D, const AttributeList &Attr)
void AddModeAttr(SourceRange AttrRange, Decl *D, IdentifierInfo *Name, unsigned SpellingListIndex, bool InInstantiation=false)
AddModeAttr - Adds a mode attribute to a particular declaration.
static void handleOpenCLAccessAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isReferenceType() const
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
QualType getReturnType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
bool isAnyPointerType() const
static void handleRestrictAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleDeclspecThreadAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleModeAttr(Sema &S, Decl *D, const AttributeList &Attr)
handleModeAttr - This attribute modifies the width of a decl with primitive type. ...
static void handleCallableWhenAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isMicrosoftAttribute() const
static bool versionsMatch(const VersionTuple &X, const VersionTuple &Y, bool BeforeIsOkay)
Check whether the two versions match.
static void checkUnusedDeclAttributes(Sema &S, const AttributeList *A)
checkUnusedDeclAttributes - Check a list of attributes to see if it contains any decl attributes that...
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
CXXRecordDecl * getDefinition() const
static void handleLocksExcludedAttr(Sema &S, Decl *D, const AttributeList &Attr)
TagKind getTagKind() const
static void handleSubGroupSize(Sema &S, Decl *D, const AttributeList &Attr)
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
static void handleTransparentUnionAttr(Sema &S, Decl *D, const AttributeList &Attr)
const RecordType * getAsUnionType() const
NOTE: getAs*ArrayType are methods on ASTContext.
static void handleCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool hasVariadicArg() const
static void handleAssertExclusiveLockAttr(Sema &S, Decl *D, const AttributeList &Attr)
Represents an access specifier followed by colon ':'.
static void handleConstructorAttr(Sema &S, Decl *D, const AttributeList &Attr)
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
static void handleARMInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
void redelayDiagnostics(sema::DelayedDiagnosticPool &pool)
Given a set of delayed diagnostics, re-emit them as if they had been delayed in the current context i...
Describes a module or submodule.
static void handleMSInheritanceAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool attrNonNullArgCheck(Sema &S, QualType T, const AttributeList &Attr, SourceRange AttrParmRange, SourceRange TypeRange, bool isReturnValue=false)
static void handleNakedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void parseModeAttrArg(Sema &S, StringRef Str, unsigned &DestWidth, bool &IntegerMode, bool &ComplexMode)
parseModeAttrArg - Parses attribute mode string and returns parsed type attribute.
SourceLocation getBeginLoc() const
Get the begin source location.
void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE, unsigned SpellingListIndex)
AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular declaration.
static void handleExtVectorTypeAttr(Sema &S, Scope *scope, Decl *D, const AttributeList &Attr)
This parameter (which must have pointer type) uses the special Swift context-pointer ABI treatment...
const Type * getTypePtr() const
static void handleObjCReturnsInnerPointerAttr(Sema &S, Decl *D, const AttributeList &attr)
static void handleNotTailCalledAttr(Sema &S, Decl *D, const AttributeList &Attr)
const TargetInfo & getTargetInfo() const
TypeVisibilityAttr * mergeTypeVisibilityAttr(Decl *D, SourceRange Range, TypeVisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
static bool isIntOrBool(Expr *Exp)
Check if the passed-in expression is of type int or bool.
std::string getAsString() const
Retrieve a string representation of the version number.
MinSizeAttr * mergeMinSizeAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
const LangOptions & getLangOpts() const
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
CharUnits - This is an opaque type for sizes expressed in character units.
static void handleNoSanitizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isStaticDataMember(const Decl *D)
Determine whether the given declaration is a static data member.
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
DeclarationNameInfo getNameInfo() const
QualType getReturnType() const
static void handleInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, QualType LHSType, QualType RHSType)
CheckAssignmentConstraints - Perform type checking for assignment, argument passing, variable initialization, and function return values.
void PopParsingDeclaration(ParsingDeclState state, Decl *decl)
field_range fields() const
static void handleAlignValueAttr(Sema &S, Decl *D, const AttributeList &Attr)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
const DelayedDiagnosticPool * getParent() const
QualType getForbiddenTypeOperand() const
bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, const FunctionDecl *FD=nullptr)
bool hasParsedType() const
bool isValueDependent() const
isValueDependent - Determines whether this expression is value-dependent (C++ [temp.dep.constexpr]).
RecordDecl * getDecl() const
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
ObjCInterfaceDecl * getInterface() const
Gets the interface declaration for this object type, if the base type really is an interface...
static void handleObjCDesignatedInitializer(Sema &S, Decl *D, const AttributeList &Attr)
pool_iterator pool_end() const
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
bool hasProcessingCache() const
Expr * IgnoreParenCasts() LLVM_READONLY
IgnoreParenCasts - Ignore parentheses and casts.
bool isVariadic() const
Whether this function is variadic.
Scope - A scope is a transient data structure that is used while parsing the program.
static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D, const AttributeList &Attr)
static bool shouldDiagnoseAvailabilityByDefault(const ASTContext &Context, const VersionTuple &DeploymentVersion, const VersionTuple &DeclVersion)
bool isTemplateInstantiation() const
Determines if the given function was instantiated from a function template.
Represents information about a change in availability for an entity, which is part of the encoding of...
bool getLayoutCompatible() const
Represents an Objective-C protocol declaration.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
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)
A class that does preordor or postorder depth-first traversal on the entire Clang AST and visits each...
Represents an ObjC class declaration.
static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isExtVectorType() const
void setInvalid(bool b=true) const
detail::InMemoryDirectory::const_iterator I
static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this attribute.
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
void ProcessDeclAttributeList(Scope *S, Decl *D, const AttributeList *AL, bool IncludeCXX11Attributes=true)
ProcessDeclAttributeList - Apply all the decl attributes in the specified attribute list to the speci...
static void handleLaunchBoundsAttr(Sema &S, Decl *D, const AttributeList &Attr)
This parameter (which must have pointer-to-pointer type) uses the special Swift error-result ABI trea...
static bool checkPositiveIntArgument(Sema &S, const AttrInfo &Attr, 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...
virtual unsigned getUnwindWordWidth() const
static SourceRange getFunctionOrMethodParamRange(const Decl *D, unsigned Idx)
void AddAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex, bool IsPackExpansion)
AddAlignedAttr - Adds an aligned attribute to a particular declaration.
This object can be modified without requiring retains or releases.
param_iterator param_begin()
Represents the this expression in C++.
field_iterator field_end() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
AvailabilityResult
Captures the result of checking the availability of a declaration.
IdentifierInfo * getAlias() const
static void handleNSConsumedAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getReceiverLocation() const
VersionTuple getVersion()
static void handleAlignedAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool canBeWeakImported(bool &IsDefinition) const
Determines whether this symbol can be weak-imported, e.g., whether it would be well-formed to add the...
Sema - This implements semantic analysis and AST building for C.
Merge availability attributes for an implementation of a protocol requirement.
SourceLocation getLocEnd() const LLVM_READONLY
CompoundStmt - This represents a group of statements like { stmt stmt }.
Represents a prototype with parameter type info, e.g.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
static void handleObjCSuppresProtocolAttr(Sema &S, Decl *D, const AttributeList &Attr)
DeclarationNameTable DeclarationNames
const AvailabilityChange & getAvailabilityIntroduced() const
static void handleCFAuditedTransferAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getTypeSpecStartLoc() const
bool isCXXInstanceMember() const
Determine whether the given declaration is an instance member of a C++ class.
Captures information about a #pragma weak directive.
static void handleObjCBoxable(Sema &S, Decl *D, const AttributeList &Attr)
sema::FunctionScopeInfo * getEnclosingFunction() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
bool isFunctionPointerType() const
void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex)
AddAlignValueAttr - Adds an align_value attribute to a particular declaration.
static void handlePtGuardedVarAttr(Sema &S, Decl *D, const AttributeList &Attr)
Exposes information about the current target.
static bool isValidSubjectOfNSReturnsRetainedAttribute(QualType type)
const ObjCMethodDecl * getMethodDecl() const
static bool isCFStringType(QualType T, ASTContext &Ctx)
static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleObjCRequiresSuperAttr(Sema &S, Decl *D, const AttributeList &attr)
void popWithoutEmitting(DelayedDiagnosticsState state)
Leave a delayed-diagnostic state that was previously pushed.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
Expr - This represents one expression.
MSInheritanceAttr::Spelling calculateInheritanceModel() const
Calculate what the inheritance model would be for this class.
static void handleTargetAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleWarnUnusedResult(Sema &S, Decl *D, const AttributeList &Attr)
StringRef getName() const
Return the actual identifier string.
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.
SmallVector< Decl *, 2 > WeakTopLevelDecl
WeakTopLevelDecl - Translation-unit scoped declarations generated by #pragma weak during processing o...
static bool checkFunctionConditionAttr(Sema &S, Decl *D, const AttributeList &Attr, Expr *&Cond, StringRef &Msg)
Represents a character-granular source range.
DLLImportAttr * mergeDLLImportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
static bool checkIBOutletCommon(Sema &S, Decl *D, const AttributeList &Attr)
static bool hasDeclarator(const Decl *D)
Return true if the given decl has a declarator that should have been processed by Sema::GetTypeForDec...
static void handleTestTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr)
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...
static bool isCapabilityExpr(Sema &S, const Expr *Ex)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
SourceLocation getLocEnd() const LLVM_READONLY
virtual std::string isValidSectionSpecifier(StringRef SR) const
An optional hook that targets can implement to perform semantic checking on attribute((section("foo")...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
TranslationUnitDecl * getTranslationUnitDecl() const
static void handleCFUnknownTransferAttr(Sema &S, Decl *D, const AttributeList &Attr)
void DiagnoseUnguardedAvailabilityViolations(Decl *FD)
Issue any -Wunguarded-availability warnings in FD.
Defines the clang::Preprocessor interface.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, bool AllowFold=true)
VerifyIntegerConstantExpression - Verifies that an expression is an ICE, and reports the appropriate ...
static bool typeHasCapability(Sema &S, QualType Ty)
const ParmVarDecl * getParamDecl(unsigned i) const
llvm::MapVector< IdentifierInfo *, WeakInfo > WeakUndeclaredIdentifiers
WeakUndeclaredIdentifiers - Identifiers contained in #pragma weak before declared.
Defines the classes clang::DelayedDiagnostic and clang::AccessedEntity.
static void handleEnableIfAttr(Sema &S, Decl *D, const AttributeList &Attr)
DeclContext * getDeclContext()
void CheckAlignasUnderalignment(Decl *D)
bool isFloatingType() const
static void handleParameterABIAttr(Sema &S, Decl *D, const AttributeList &attr, ParameterABI abi)
void setProcessingCache(unsigned value) const
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
virtual void AssignInheritanceModel(CXXRecordDecl *RD)
Callback invoked when an MSInheritanceAttr has been attached to a CXXRecordDecl.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static void handleIFuncAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isObjCIdType() const
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
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...
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr)
void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx)
MSInheritanceAttr * mergeMSInheritanceAttr(Decl *D, SourceRange Range, bool BestCase, unsigned AttrSpellingListIndex, MSInheritanceAttr::Spelling SemanticSpelling)
ASTMutationListener * getASTMutationListener() const
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
virtual bool hasProtectedVisibility() const
Does this target support "protected" visibility?
const ParsedType & getTypeArg() const
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool EvaluateAsInt(llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
EvaluateAsInt - Return true if this is a constant which we can fold and convert to an integer...
An expression that sends a message to the given Objective-C object or class.
static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isNSStringType(QualType T, ASTContext &Ctx)
UnaryOperator - This represents the unary-expression's (except sizeof and alignof), the postinc/postdec operators from postfix-expression, and various extensions.
Represents a GCC generic vector type.
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
bool existsInTarget(const TargetInfo &Target) const
void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext=true)
Add this decl to the scope shadowed decl chains.
Wraps an identifier and optional source location for the identifier.
InternalLinkageAttr * mergeInternalLinkageAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
static void handleDeprecatedAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getForbiddenTypeDiagnostic() const
The diagnostic ID to emit.
The result type of a method or function.
static void handlePtGuardedByAttr(Sema &S, Decl *D, const AttributeList &Attr)
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &diag, Decl *decl)
Handle a delayed forbidden-type diagnostic.
bool isTemplateInstantiation(TemplateSpecializationKind Kind)
Determine whether this template specialization kind refers to an instantiation of an entity (as oppos...
SourceLocation getLocEnd() const LLVM_READONLY
TypeSourceInfo * getTypeSourceInfo() const
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
static void handleAbiTagAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr)
static CharSourceRange getCharRange(SourceRange R)
bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type)
This is a scope that corresponds to the parameters within a function prototype for a function declara...
static void handleAllocSizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType.
SourceLocation getEndLoc() const
Get the end source location.
static void handleMipsInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool checkAttributeNumArgs(Sema &S, const AttributeList &Attr, unsigned Num)
Check if the attribute has exactly as many args as Num.
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
SourceLocation getLocStart() const LLVM_READONLY
static void handleTryAcquireCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
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.
SourceRange getReturnTypeSourceRange() const
Attempt to compute an informative source range covering the function return type. ...
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
static bool checkRecordTypeForCapability(Sema &S, QualType Ty)
static bool isValidSubjectOfNSAttribute(Sema &S, QualType type)
unsigned getAttributeSpellingListIndex() const
Get an index into the attribute spelling list defined in Attr.td.
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
Assigning into this object requires the old value to be released and the new value to be retained...
static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
static FormatAttrKind getFormatAttrKind(StringRef Format)
getFormatAttrKind - Map from format attribute names to supported format types.
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
const ParsedType & getMatchingCType() const
not a target-specific vector type
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
AvailabilityResult getAvailabilityResult() const
bool HasPotentialAvailabilityViolations
Whether we make reference to a declaration that could be unavailable.
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
static bool handleCommonAttributeFeatures(Sema &S, Scope *scope, Decl *D, const AttributeList &Attr)
Handles semantic checking for features that are common to all attributes, such as checking whether a ...
void DiagnoseAvailabilityOfDecl(NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, bool ObjCPropertyAccess, bool AvoidPartialAvailabilityChecks=false)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
SourceLocation getEllipsisLoc() const
DLLExportAttr * mergeDLLExportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
void setUsed(bool Used=true)
bool isComplexType() const
isComplexType() does not include complex integers (a GCC extension).
bool isBuiltinType() const
Helper methods to distinguish type categories.
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
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.
ASTContext & getASTContext() const
const ObjCInterfaceDecl * getUnknownObjCClass() const
bool getMustBeNull() const
CommonAttr * mergeCommonAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
IdentifierTable & getIdentifierTable()
reverse_body_iterator body_rend()
static void handleLockReturnedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAvailabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
QualType getConstType(QualType T) const
Return the uniqued reference to the type for a const qualified type.
Represents a static or instance method of a struct/union/class.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
static std::enable_if< std::is_base_of< clang::Attr, AttrInfo >::value, SourceLocation >::type getAttrLoc(const AttrInfo &Attr)
A helper function to provide Attribute Location for the Attr types AND the AttributeList.
virtual unsigned getRegisterWidth() const
Return the "preferred" register width on this target.
static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D, const AttributeList &Attr)
static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, Decl *Ctx, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
Actually emit an availability diagnostic for a reference to an unavailable decl.
static T * mergeVisibilityAttr(Sema &S, Decl *D, SourceRange range, typename T::VisibilityType value, unsigned attrSpellingListIndex)
static void handleAlwaysInlineAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isIntegralType(const ASTContext &Ctx) const
Determine whether this type is an integral type.
static void handleBlocksAttr(Sema &S, Decl *D, const AttributeList &Attr)
ObjCCategoryDecl - Represents a category declaration.
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...
static void handlePackedAttr(Sema &S, Decl *D, const AttributeList &Attr)
void push_back(const T &LocalValue)
static void handleArgumentWithTypeTagAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getMajor() const
Retrieve the major version number.
static void handleXRayLogArgsAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleNSReturnsRetainedAttr(Sema &S, Decl *D, const AttributeList &Attr)
CUDADiagBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID)
Creates a CUDADiagBuilder that emits the diagnostic if the current context is "used as host code"...
static unsigned getNumAttributeArgs(const AttributeList &Attr)
ThreadStorageClassSpecifier getTSCSpec() const
Represents one property declaration in an Objective-C interface.
std::pair< SourceLocation, PartialDiagnostic > PartialDiagnosticAt
A partial diagnostic along with the source location where this diagnostic occurs. ...
unsigned getForbiddenTypeArgument() const
QualType getReturnType() const
SourceLocation getBegin() const
static void handleExternalSourceSymbolAttr(Sema &S, Decl *D, const AttributeList &Attr)
const T * castAs() const
Member-template castAs<specific type>.
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.
bool isArgExpr(unsigned Arg) const
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
static void handleObjCBridgeMutableAttr(Sema &S, Scope *Sc, Decl *D, const AttributeList &Attr)
static void handleDelayedAvailabilityCheck(Sema &S, DelayedDiagnostic &DD, Decl *Ctx)
IdentifierInfo * getScopeName() const
static void handleOptimizeNoneAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getSelectorStartLoc() const
bool isVectorType() const
sema::FunctionScopeInfo * getCurFunction() const
IdentifierLoc * getArgAsIdent(unsigned Arg) const
static void handleParamTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isInlineSpecified() const
Determine whether the "inline" keyword was specified for this function.
QualType getRealTypeForBitwidth(unsigned DestWidth) const
getRealTypeForBitwidth - sets floating point QualTy according to specified bitwidth.
Assigning into this object requires a lifetime extension.
static bool checkForConsumableClass(Sema &S, const CXXMethodDecl *MD, const AttributeList &Attr)
static void handleSharedTrylockFunctionAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getLocStart() const LLVM_READONLY
static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const AttributeList &Attr)
ParameterABI
Kinds of parameter ABI.
CUDAFunctionTarget CurrentCUDATarget()
Gets the CUDA target for the current context.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
QualType getPointeeType() const
unsigned getMinArgs() const
pool_iterator pool_begin() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
SourceLocation getLocation() const
attr::Kind getKind() const
Base class for declarations which introduce a typedef-name.
static bool normalizeName(StringRef &AttrName)
Normalize the attribute, foo becomes foo.
ExprResult PerformCopyInitialization(const InitializedEntity &Entity, SourceLocation EqualLoc, ExprResult Init, bool TopLevelOfInitList=false, bool AllowExplicit=false)
static void handleLayoutVersion(Sema &S, Decl *D, const AttributeList &Attr)
static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK)
Returns true if the given operator is implicitly static in a record context.
static void EmitAvailabilityWarning(Sema &S, AvailabilityResult AR, const NamedDecl *ReferringDecl, const NamedDecl *OffendingDecl, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D, const AttributeList &Attr)
bool checkStringLiteralArgumentAttr(const AttributeList &Attr, unsigned ArgNum, StringRef &Str, SourceLocation *ArgLocation=nullptr)
Check if the argument ArgNum of Attr is a ASCII string literal.
static std::enable_if< std::is_base_of< clang::Attr, AttrInfo >::value, const AttrInfo * >::type getAttrName(const AttrInfo &Attr)
A helper function to provide Attribute Name for the Attr types AND the AttributeList.
bool diagnoseLangOpts(class Sema &S) const
void checkUnusedDeclAttributes(Declarator &D)
checkUnusedDeclAttributes - Given a declarator which is not being used to build a declaration...
Don't merge availability attributes at all.
static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleReturnsNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr)
ParmVarDecl * BuildParmVarDeclForTypedef(DeclContext *DC, SourceLocation Loc, QualType T)
Synthesizes a variable for a parameter arising from a typedef.
const AvailabilityChange & getAvailabilityObsoleted() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
static void handleAMDGPUNumSGPRAttr(Sema &S, Decl *D, const AttributeList &Attr)
void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W)
DeclApplyPragmaWeak - A declaration (maybe definition) needs #pragma weak applied to it...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero)...
void ProcessPragmaWeak(Scope *S, Decl *D)
bool isInvalidDecl() const
NamedDecl * DeclClonePragmaWeak(NamedDecl *ND, IdentifierInfo *II, SourceLocation Loc)
DeclClonePragmaWeak - clone existing decl (maybe definition), #pragma weak needs a non-definition dec...
unsigned getCharWidth() const
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling)
bool isClassReceiver() const
static void handleObjCBridgeRelatedAttr(Sema &S, Scope *Sc, Decl *D, const AttributeList &Attr)
SectionAttr * mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
A runtime availability query.
Expr * getArgAsExpr(unsigned Arg) const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
static void handleSharedAttr(Sema &S, Decl *D, const AttributeList &Attr)
DeclarationName - The name of a declaration.
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
void AddNSConsumedAttr(SourceRange AttrRange, Decl *D, unsigned SpellingListIndex, bool isNSConsumed, bool isTemplateInstantiation)
StringRef getString() const
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible. ...
static void handleInternalLinkageAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
SourceLocation getLocStart() const LLVM_READONLY
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
EnumDecl - Represents an enum.
VisibilityAttr * mergeVisibilityAttr(Decl *D, SourceRange Range, VisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
detail::InMemoryDirectory::const_iterator E
bool inTemplateInstantiation() const
Determine whether we are currently performing template instantiation.
static void handleIBOutletCollection(Sema &S, Decl *D, const AttributeList &Attr)
void ProcessDeclAttributeDelayed(Decl *D, const AttributeList *AttrList)
static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr, bool isTypeVisibility)
static bool ShouldDiagnoseAvailabilityInContext(Sema &S, AvailabilityResult K, VersionTuple DeclVersion, Decl *Ctx)
whether we should emit a diagnostic for K and DeclVersion in the context of Ctx.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
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).
void AddPragmaAttributes(Scope *S, Decl *D)
Adds the attributes that have been specified using the '#pragma clang attribute push' directives to t...
param_iterator param_end()
const Stmt * getThen() const
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
const Expr * getMessageExpr() const
AvailabilityMergeKind
Describes the kind of merge to perform for availability attributes (including "deprecated", "unavailable", and "availability").
Represents a pointer to an Objective C object.
bool hasQualifier() const
Determine whether this declaration reference was preceded by a C++ nested-name-specifier, e.g., N::foo.
static bool checkAvailabilityAttr(Sema &S, SourceRange Range, IdentifierInfo *Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted)
bool isObjCObjectType() const
bool isPackExpansion() const
static void handleCallConvAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAVRSignalAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAMDGPUWavesPerEUAttr(Sema &S, Decl *D, const AttributeList &Attr)
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
static void handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr)
IdentifierInfo * getName() const
SourceManager & getSourceManager() const
const T * getAs() const
Member-template getAs<specific type>'.
static void handleSimpleAttribute(Sema &S, Decl *D, const AttributeList &Attr)
Applies the given attribute to the Decl without performing any additional semantic checking...
void add(const sema::DelayedDiagnostic &diag)
Adds a delayed diagnostic.
bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, const AttributeList *AttrList)
static bool checkUInt32Argument(Sema &S, const AttrInfo &Attr, const Expr *Expr, uint32_t &Val, unsigned Idx=UINT_MAX)
If Expr is a valid integer constant, get the value of the integer expression and return success or fa...
SourceLocation getStrictLoc() const
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)
static void handleGuardedByAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleReleaseCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getMaxArgs() const
static void handleWeakRefAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isFunctionType() const
Base for LValueReferenceType and RValueReferenceType.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
llvm::StringRef getParameterABISpelling(ParameterABI kind)
SourceLocation getLoc() 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.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl...
Represents a base class of a C++ class.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
void checkTargetAttr(SourceLocation LiteralLoc, StringRef Str)
char __ovld __cnfn max(char x, char y)
Returns y if x < y, otherwise it returns x.
SourceManager & getSourceManager()
bool isTLSSupported() const
Whether the target supports thread-local storage.
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
static void handleRequiresCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
Scope * getScopeForContext(DeclContext *Ctx)
Determines the active Scope associated with the given declaration context.
static void handleInitPriorityAttr(Sema &S, Decl *D, const AttributeList &Attr)
Handle attribute((init_priority(priority))) attributes based on http://gcc.gnu.org/onlinedocs/gcc/C_0...
bool CheckRegparmAttr(const AttributeList &attr, unsigned &value)
Checks a regparm attribute, returning true if it is ill-formed and otherwise setting numParams to the...
Merge availability attributes for a redeclaration, which requires an exact match. ...
const ObjCPropertyDecl * getObjCProperty() const
bool isCXX11Attribute() const
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
static bool checkAttributeAtMostNumArgs(Sema &S, const AttributeList &Attr, unsigned Num)
Check if the attribute has at most as many args as Num.
Reading or writing from this object requires a barrier call.
static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleX86ForceAlignArgPointerAttr(Sema &S, Decl *D, const AttributeList &Attr)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate.h) and friends (in DeclFriend.h).
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 void handleEnumExtensibilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isInstanceMethod(const Decl *D)
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)
ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in it, apply them to D...
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
Represents a C++ struct/union/class.
Compatible - the types are compatible according to the standard.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
static unsigned getFunctionOrMethodNumParams(const Decl *D)
getFunctionOrMethodNumParams - Return number of function or method parameters.
reverse_body_iterator body_rbegin()
bool isObjCObjectPointerType() const
static void handleAnnotateAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &Attr)
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
A diagnostic message which has been conditionally emitted pending the complete parsing of the current...
ObjCIvarDecl - Represents an ObjC instance variable.
CallingConv getDefaultCallingConvention(bool isVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
const Expr * getCond() const
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, Expr *MinBlocks, unsigned SpellingListIndex)
AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular declaration. ...
SourceLocation getLocStart() const
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.
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 void handleFormatArgAttr(Sema &S, Decl *D, const AttributeList &Attr)
Handle attribute((format_arg((idx)))) attribute based on http://gcc.gnu.org/onlinedocs/gcc/Function-A...
static SourceRange getFunctionOrMethodResultSourceRange(const Decl *D)
static void handleAssertCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
static void handleVecTypeHint(Sema &S, Decl *D, const AttributeList &Attr)
static bool checkAttributeAtLeastNumArgs(Sema &S, const AttributeList &Attr, unsigned Num)
Check if the attribute has at least as many args as Num.
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
void AddAllocAlignAttr(SourceRange AttrRange, Decl *D, Expr *ParamExpr, unsigned SpellingListIndex)
AddAllocAlignAttr - Adds an alloc_align attribute to a particular declaration.
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl, const AttributeList &Attr)
static void handleConstantAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D, const AttrInfo &Attr, unsigned AttrArgNum, const Expr *IdxExpr, uint64_t &Idx, bool AllowImplicitThis=false)
Check if IdxExpr is a valid parameter index for a function or instance method D.
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
NestedNameSpecifier * getQualifier() const
Retrieve the nested-name-specifier that qualifies the name of this declaration, if it was present in ...
A reference to a declared variable, function, enum, etc.
NamedDecl * getMostRecentDecl()
static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx)
static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr)
static NamedDecl * findEnclosingDeclToAnnotate(Decl *OrigCtx)
bool isDeclspecAttribute() 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...
static const AvailabilityAttr * getAttrForPlatform(ASTContext &Context, const Decl *D)
class clang::Sema::DelayedDiagnostics DelayedDiagnostics
A collection of diagnostics which were delayed.
static bool isValidSubjectOfCFAttribute(Sema &S, QualType type)
const DeclaratorChunk & getTypeObject(unsigned i) const
Return the specified TypeInfo from this declarator.
static bool checkLockFunAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
isPotentialConstantExprUnevaluted - Return true if this expression might be usable in a constant expr...
AttributeList * getNext() const
static Expr * makeLaunchBoundsArgExpr(Sema &S, Expr *E, const CUDALaunchBoundsAttr &Attr, const unsigned Idx)
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
void setLexicalDeclContext(DeclContext *DC)
static std::pair< AvailabilityResult, const NamedDecl * > ShouldDiagnoseAvailabilityOfDecl(const NamedDecl *D, std::string *Message)
The diagnostic we should emit for D, and the declaration that originated it, or AR_Available.
static void handlePassObjectSizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
NamedDecl - This represents a decl with a name.
static void handleTLSModelAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
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.
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
static bool isFunctionOrMethodVariadic(const Decl *D)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
static bool isObjCNSObjectType(QualType Ty)
Return true if this is an NSObject object with its NSObject attribute set.
Describes an entity that is being initialized.
void setHasDesignatedInitializers()
Indicate that this interface decl contains at least one initializer marked with the 'objc_designated_...
StringRef getAvailabilityMessage() const
SourceLocation getLocStart() const LLVM_READONLY
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
AttributeDeclKind
These constants match the enumerated choices of warn_attribute_wrong_decl_type and err_attribute_wron...
static bool checkAttrMutualExclusion(Sema &S, Decl *D, SourceRange Range, IdentifierInfo *Ident)
Diagnose mutually exclusive attributes when present on a given declaration.
bool isBeingDefined() const
isBeingDefined - Return true if this decl is currently being defined.
This class handles loading and caching of source files into memory.
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.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
static void handleWorkGroupSize(Sema &S, Decl *D, const AttributeList &Attr)
static bool isValidSwiftIndirectResultType(QualType type)
Pointers and references in the default address space.
Attr - This represents one attribute.
ParsedAttributes & getAttributes()
static void handleDiagnoseIfAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool hasPointerRepresentation() const
Whether this type is represented natively as a pointer.
This parameter (which must have pointer type) is a Swift indirect result parameter.
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
SmallVectorImpl< DelayedDiagnostic >::const_iterator pool_iterator
static bool isValidSwiftContextType(QualType type)
Pointer-like types in the default address space.
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
AttributeList - Represents a syntactic attribute.
static void handleAMDGPUFlatWorkGroupSizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
bool isPointerType() const
static void handleVecReturnAttr(Sema &S, Decl *D, const AttributeList &Attr)
static LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
const AttributeList * getAttributes() const
SourceLocation getLocStart() const LLVM_READONLY