32 #include "llvm/ADT/StringExtras.h"
33 #include "llvm/Support/MathExtras.h"
34 using namespace clang;
37 namespace AttributeLangSupport {
65 return isa<DeclaratorDecl>(D) || isa<BlockDecl>(D) || isa<TypedefNameDecl>(D) ||
66 isa<ObjCPropertyDecl>(D);
74 return isa<FunctionProtoType>(FnTy);
75 return isa<ObjCMethodDecl>(D) || isa<BlockDecl>(D);
83 return cast<FunctionProtoType>(FnTy)->getNumParams();
84 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
85 return BD->getNumParams();
86 return cast<ObjCMethodDecl>(D)->param_size();
91 return cast<FunctionProtoType>(FnTy)->getParamType(Idx);
92 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
93 return BD->getParamDecl(Idx)->getType();
95 return cast<ObjCMethodDecl>(D)->parameters()[Idx]->getType();
99 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
100 return FD->getParamDecl(Idx)->getSourceRange();
101 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
102 return MD->parameters()[Idx]->getSourceRange();
103 if (
const auto *BD = dyn_cast<BlockDecl>(D))
104 return BD->getParamDecl(Idx)->getSourceRange();
110 return cast<FunctionType>(FnTy)->getReturnType();
111 return cast<ObjCMethodDecl>(D)->getReturnType();
115 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
116 return FD->getReturnTypeSourceRange();
117 if (
const auto *MD = dyn_cast<ObjCMethodDecl>(D))
118 return MD->getReturnTypeSourceRange();
127 if (
const BlockDecl *BD = dyn_cast<BlockDecl>(D))
128 return BD->isVariadic();
130 return cast<ObjCMethodDecl>(D)->isVariadic();
134 if (
const CXXMethodDecl *MethodDecl = dyn_cast<CXXMethodDecl>(D))
135 return MethodDecl->isInstance();
151 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
152 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
176 template <
typename Compare>
178 unsigned Num,
unsigned Diag,
193 diag::err_attribute_wrong_number_arguments,
194 std::not_equal_to<unsigned>());
202 diag::err_attribute_too_few_arguments,
203 std::less<unsigned>());
211 diag::err_attribute_too_many_arguments,
212 std::greater<unsigned>());
224 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
226 << Expr->getSourceRange();
228 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type)
230 << Expr->getSourceRange();
236 << I.toString(10,
false) << 32 << 1;
240 Val = (uint32_t)I.getZExtValue();
246 template <
typename AttrTy>
249 if (AttrTy *A = D->
getAttr<AttrTy>()) {
250 S.
Diag(Attr.
getLoc(), diag::err_attributes_are_not_compatible)
279 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
281 << IdxExpr->getSourceRange();
285 Idx = IdxInt.getLimitedValue();
286 if (Idx < 1 || (!IV && Idx > NumParams)) {
287 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
288 << Attr.
getName() << AttrArgNum << IdxExpr->getSourceRange();
292 if (HasImplicitThisParam) {
295 diag::err_attribute_invalid_implicit_this_argument)
296 << Attr.
getName() << IdxExpr->getSourceRange();
310 unsigned ArgNum, StringRef &Str,
315 Diag(Loc->
Loc, diag::err_attribute_argument_type)
321 *ArgLocation = Loc->
Loc;
329 *ArgLocation = ArgExpr->getLocStart();
331 if (!Literal || !Literal->
isAscii()) {
332 Diag(ArgExpr->getLocStart(), diag::err_attribute_argument_type)
343 template <
typename AttrType>
378 const ValueDecl *vd = cast<ValueDecl>(D);
380 if (QT->isAnyPointerType())
387 if (RT->isIncompleteType())
394 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_decl_not_pointer)
429 if (RD->
hasAttr<CapabilityAttr>())
438 ->getDecl()->hasAttr<CapabilityAttr>();
454 return TN->
hasAttr<CapabilityAttr>();
473 if (
const auto *E = dyn_cast<DeclRefExpr>(Ex))
475 else if (
const auto *E = dyn_cast<CastExpr>(Ex))
477 else if (
const auto *E = dyn_cast<ParenExpr>(Ex))
479 else if (
const auto *E = dyn_cast<UnaryOperator>(Ex)) {
483 }
else if (
const auto *E = dyn_cast<BinaryOperator>(Ex)) {
502 bool ParamIdxOk =
false) {
503 for (
unsigned Idx = Sidx; Idx < Attr.
getNumArgs(); ++Idx) {
508 Args.push_back(ArgExp);
512 if (
StringLiteral *StrLit = dyn_cast<StringLiteral>(ArgExp)) {
513 if (StrLit->getLength() == 0 ||
514 (StrLit->isAscii() && StrLit->getString() == StringRef(
"*"))) {
517 Args.push_back(ArgExp);
523 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_ignored) <<
525 Args.push_back(ArgExp);
535 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(UOp->getSubExpr()))
536 if (DRE->getDecl()->isCXXInstanceMember())
537 ArgTy = DRE->getDecl()->getType();
543 if(!RT && ParamIdxOk) {
548 llvm::APInt ArgValue = IL->getValue();
549 uint64_t ParamIdxFromOne = ArgValue.getZExtValue();
550 uint64_t ParamIdxFromZero = ParamIdxFromOne - 1;
551 if(!ArgValue.isStrictlyPositive() || ParamIdxFromOne > NumParams) {
552 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_range)
553 << Attr.
getName() << Idx + 1 << NumParams;
565 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_argument_not_lockable)
568 Args.push_back(ArgExp);
592 unsigned Size = Args.size();
631 QualType QT = cast<ValueDecl>(D)->getType();
635 S.
Diag(Attr.
getLoc(), diag::warn_thread_attribute_decl_not_lockable)
655 Expr **StartArg = &Args[0];
658 StartArg, Args.size(),
668 Expr **StartArg = &Args[0];
671 StartArg, Args.size(),
691 unsigned Size = Args.size();
692 Expr **StartArg = Size == 0 ?
nullptr : &Args[0];
704 unsigned Size = Args.size();
705 Expr **StartArg = Size == 0 ?
nullptr : &Args[0];
720 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
740 Args.data(), Args.size(),
760 unsigned Size = Args.size();
777 unsigned Size = Args.size();
780 Expr **StartArg = &Args[0];
793 Cond = Converted.
get();
804 S.
Diag(Attr.
getLoc(), diag::err_enable_if_never_constant_expr);
805 for (
int I = 0, N = Diags.size(); I != N; ++I)
806 S.
Diag(Diags[I].first, Diags[I].second);
820 if (!ConsumableAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
822 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported)
827 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type)
844 if (!RD->hasAttr<ConsumableAttr>()) {
845 S.
Diag(Attr.
getLoc(), diag::warn_attr_on_unconsumable_class) <<
846 RD->getNameAsString();
865 for (
unsigned ArgIndex = 0; ArgIndex < Attr.
getNumArgs(); ++ArgIndex) {
868 StringRef StateString;
879 if (!CallableWhenAttr::ConvertStrToConsumedState(StateString,
881 S.
Diag(Loc, diag::warn_attribute_type_not_supported)
882 << Attr.
getName() << StateString;
886 States.push_back(CallableState);
903 if (!ParamTypestateAttr::ConvertStrToConsumedState(StateString,
905 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
906 << Attr.
getName() << StateString;
910 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
939 if (!ReturnTypestateAttr::ConvertStrToConsumedState(IL->
Ident->
getName(),
941 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported)
946 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
990 if (!SetTypestateAttr::ConvertStrToConsumedState(Param, NewState)) {
991 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
996 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1015 if (!TestTypestateAttr::ConvertStrToConsumedState(Param, TestState)) {
1016 S.
Diag(Ident->
Loc, diag::warn_attribute_type_not_supported)
1021 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type) <<
1038 if (
TagDecl *TD = dyn_cast<TagDecl>(D))
1041 else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
1044 if (!FD->getType()->isDependentType() &&
1045 !FD->getType()->isIncompleteType() &&
1047 S.
Diag(Attr.
getLoc(), diag::warn_attribute_ignored_for_field_of_type)
1048 << Attr.
getName() << FD->getType();
1061 if (
const ObjCIvarDecl *VD = dyn_cast<ObjCIvarDecl>(D)) {
1063 S.
Diag(Attr.
getLoc(), diag::warn_iboutlet_object_type)
1064 << Attr.
getName() << VD->getType() << 0;
1070 S.
Diag(Attr.
getLoc(), diag::warn_iboutlet_object_type)
1071 << Attr.
getName() << PD->getType() << 1;
1097 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
1113 S.
Diag(Attr.
getLoc(), diag::err_iboutletcollection_type) <<
"NSObject";
1129 QT->
isBuiltinType() ? diag::err_iboutletcollection_builtintype
1130 : diag::err_iboutletcollection_type) << QT;
1150 if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
1152 for (
const auto *I : UD->
fields()) {
1166 bool isReturnValue =
false) {
1169 ? diag::warn_attribute_return_pointers_only
1170 : diag::warn_attribute_pointers_only)
1171 << Attr.
getName() << AttrParmRange << TypeRange;
1179 for (
unsigned I = 0; I < Attr.
getNumArgs(); ++I) {
1188 Ex->getSourceRange(),
1192 NonNullArgs.push_back(Idx);
1203 I != E && !AnyPointers; ++I) {
1210 S.
Diag(Attr.
getLoc(), diag::warn_attribute_nonnull_no_pointers);
1213 unsigned *Start = NonNullArgs.data();
1214 unsigned Size = NonNullArgs.size();
1215 llvm::array_pod_sort(Start, Start + Size);
1227 S.
Diag(Attr.
getLoc(), diag::warn_attribute_nonnull_parm_no_args)
1265 Expr *OE,
unsigned SpellingListIndex) {
1269 AssumeAlignedAttr TmpAttr(AttrRange,
Context, E, OE, SpellingListIndex);
1273 Diag(AttrLoc, diag::warn_attribute_return_pointers_refs_only)
1274 << &TmpAttr << AttrRange << SR;
1282 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1284 << E->getSourceRange();
1286 Diag(AttrLoc, diag::err_attribute_argument_type)
1288 << E->getSourceRange();
1292 if (!I.isPowerOf2()) {
1293 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
1294 << E->getSourceRange();
1303 Diag(AttrLoc, diag::err_attribute_argument_n_type)
1305 << OE->getSourceRange();
1312 AssumeAlignedAttr(AttrRange,
Context, E, OE, SpellingListIndex));
1325 S.
Diag(AL.
getLoc(), diag::err_attribute_argument_n_type)
1331 OwnershipAttr::OwnershipKind K =
1337 case OwnershipAttr::Takes:
1338 case OwnershipAttr::Holds:
1340 S.
Diag(AL.
getLoc(), diag::err_attribute_too_few_arguments)
1345 case OwnershipAttr::Returns:
1347 S.
Diag(AL.
getLoc(), diag::err_attribute_too_many_arguments)
1357 StringRef ModuleName = Module->
getName();
1358 if (ModuleName.startswith(
"__") && ModuleName.endswith(
"__") &&
1359 ModuleName.size() > 4) {
1360 ModuleName = ModuleName.drop_front(2).drop_back(2);
1365 for (
unsigned i = 1; i < AL.
getNumArgs(); ++i) {
1375 case OwnershipAttr::Takes:
1376 case OwnershipAttr::Holds:
1380 case OwnershipAttr::Returns:
1387 << Ex->getSourceRange();
1395 if (I->getOwnKind() != K && I->args_end() !=
1396 std::find(I->args_begin(), I->args_end(), Idx)) {
1397 S.
Diag(AL.
getLoc(), diag::err_attributes_are_not_compatible)
1400 }
else if (K == OwnershipAttr::Returns &&
1401 I->getOwnKind() == OwnershipAttr::Returns) {
1405 if (std::find(I->args_begin(), I->args_end(), Idx) == I->args_end()) {
1406 S.
Diag(I->getLocation(), diag::err_ownership_returns_index_mismatch)
1407 << *(I->args_begin()) + 1;
1409 S.
Diag(AL.
getLoc(), diag::note_ownership_returns_index_mismatch)
1410 << (
unsigned)Idx + 1 << Ex->getSourceRange();
1415 OwnershipArgs.push_back(Idx);
1418 unsigned* start = OwnershipArgs.data();
1419 unsigned size = OwnershipArgs.size();
1420 llvm::array_pod_sort(start, start + size);
1430 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
1448 if (!Ctx->isFileContext()) {
1449 S.
Diag(Attr.
getLoc(), diag::err_attribute_weakref_not_global_context)
1497 S.
Diag(Attr.
getLoc(), diag::err_alias_not_supported_on_darwin);
1502 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
1503 if (FD->isThisDeclarationADefinition()) {
1504 S.
Diag(Attr.
getLoc(), diag::err_alias_is_definition) << FD;
1508 const auto *VD = cast<VarDecl>(D);
1509 if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
1510 S.
Diag(Attr.
getLoc(), diag::err_alias_is_definition) << VD;
1522 if (checkAttrMutualExclusion<HotAttr>(S, D, Attr))
1530 if (checkAttrMutualExclusion<ColdAttr>(S, D, Attr))
1546 if (Model !=
"global-dynamic" && Model !=
"local-dynamic"
1547 && Model !=
"initial-exec" && Model !=
"local-exec") {
1548 S.
Diag(LiteralLoc, diag::err_attr_tlsmodel_arg);
1565 S.
Diag(Attr.
getLoc(), diag::warn_attribute_return_pointers_only)
1571 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
1585 if (!isa<ObjCMethodDecl>(D)) {
1586 S.
Diag(attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
1616 : diag::warn_attribute_wrong_decl_type)
1652 if (VecReturnAttr *A = D->
getAttr<VecReturnAttr>()) {
1653 S.
Diag(Attr.
getLoc(), diag::err_repeat_attribute) << A;
1660 if (!isa<CXXRecordDecl>(record)) {
1661 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1665 if (!cast<CXXRecordDecl>(record)->isPOD()) {
1666 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_pod_record);
1670 for (
const auto *I : record->
fields()) {
1671 if ((count == 1) || !I->getType()->isVectorType()) {
1672 S.
Diag(Attr.
getLoc(), diag::err_attribute_vecreturn_only_vector_member);
1685 if (isa<ParmVarDecl>(D)) {
1690 diag::err_carries_dependency_param_not_function_decl);
1701 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
1702 if (VD->hasLocalStorage()) {
1707 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
1718 uint32_t priority = ConstructorAttr::DefaultPriority;
1729 uint32_t priority = DestructorAttr::DefaultPriority;
1739 template <
typename AttrTy>
1753 if (!cast<ObjCProtocolDecl>(D)->isThisDeclarationADefinition()) {
1754 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_protocol_requires_definition)
1769 StringRef PlatformName
1770 = AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
1771 if (PlatformName.empty())
1772 PlatformName = Platform->
getName();
1776 if (!Introduced.
empty() && !Deprecated.
empty() &&
1777 !(Introduced <= Deprecated)) {
1778 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
1784 if (!Introduced.
empty() && !Obsoleted.
empty() &&
1785 !(Introduced <= Obsoleted)) {
1786 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
1792 if (!Deprecated.
empty() && !Obsoleted.
empty() &&
1793 !(Deprecated <= Obsoleted)) {
1794 S.
Diag(Range.
getBegin(), diag::warn_availability_version_ordering)
1808 bool BeforeIsOkay) {
1815 if (BeforeIsOkay && X < Y)
1829 unsigned AttrSpellingListIndex) {
1833 bool FoundAny =
false;
1837 for (
unsigned i = 0, e = Attrs.size(); i != e;) {
1838 const AvailabilityAttr *OldAA = dyn_cast<AvailabilityAttr>(Attrs[i]);
1845 if (OldPlatform != Platform) {
1854 bool OldIsUnavailable = OldAA->getUnavailable();
1859 !(OldIsUnavailable == IsUnavailable ||
1860 (Override && !OldIsUnavailable && IsUnavailable))) {
1867 FirstVersion = OldIntroduced;
1868 SecondVersion = Introduced;
1869 }
else if (!
versionsMatch(Deprecated, OldDeprecated, Override)) {
1871 FirstVersion = Deprecated;
1872 SecondVersion = OldDeprecated;
1873 }
else if (!
versionsMatch(Obsoleted, OldObsoleted, Override)) {
1875 FirstVersion = Obsoleted;
1876 SecondVersion = OldObsoleted;
1880 Diag(OldAA->getLocation(),
1881 diag::warn_mismatched_availability_override_unavail)
1882 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName());
1884 Diag(OldAA->getLocation(),
1885 diag::warn_mismatched_availability_override)
1887 << AvailabilityAttr::getPrettyPlatformName(Platform->
getName())
1892 Diag(OldAA->getLocation(), diag::warn_mismatched_availability);
1896 Attrs.erase(Attrs.begin() + i);
1905 if (MergedIntroduced2.
empty())
1906 MergedIntroduced2 = OldIntroduced;
1907 if (MergedDeprecated2.
empty())
1908 MergedDeprecated2 = OldDeprecated;
1909 if (MergedObsoleted2.
empty())
1910 MergedObsoleted2 = OldObsoleted;
1913 MergedIntroduced2, MergedDeprecated2,
1914 MergedObsoleted2)) {
1915 Attrs.erase(Attrs.begin() + i);
1920 MergedIntroduced = MergedIntroduced2;
1921 MergedDeprecated = MergedDeprecated2;
1922 MergedObsoleted = MergedObsoleted2;
1928 MergedIntroduced == Introduced &&
1929 MergedDeprecated == Deprecated &&
1930 MergedObsoleted == Obsoleted)
1936 MergedDeprecated, MergedObsoleted) &&
1938 return ::new (
Context) AvailabilityAttr(Range,
Context, Platform,
1939 Introduced, Deprecated,
1940 Obsoleted, IsUnavailable, Message,
1941 AttrSpellingListIndex);
1954 if (AvailabilityAttr::getPrettyPlatformName(II->
getName()).empty())
1955 S.
Diag(Platform->
Loc, diag::warn_availability_unknown_platform)
1971 Str = SE->getString();
1986 typename T::VisibilityType value,
1987 unsigned attrSpellingListIndex) {
1988 T *existingAttr = D->
getAttr<T>();
1990 typename T::VisibilityType existingValue = existingAttr->getVisibility();
1991 if (existingValue == value)
1993 S.
Diag(existingAttr->getLocation(), diag::err_mismatched_visibility);
1994 S.
Diag(range.
getBegin(), diag::note_previous_attribute);
1997 return ::new (S.
Context) T(range, S.
Context, value, attrSpellingListIndex);
2001 VisibilityAttr::VisibilityType Vis,
2002 unsigned AttrSpellingListIndex) {
2003 return ::mergeVisibilityAttr<VisibilityAttr>(*
this, D, Range, Vis,
2004 AttrSpellingListIndex);
2008 TypeVisibilityAttr::VisibilityType Vis,
2009 unsigned AttrSpellingListIndex) {
2010 return ::mergeVisibilityAttr<TypeVisibilityAttr>(*
this, D, Range, Vis,
2011 AttrSpellingListIndex);
2015 bool isTypeVisibility) {
2017 if (isa<TypedefNameDecl>(D)) {
2024 if (isTypeVisibility &&
2025 !(isa<TagDecl>(D) ||
2026 isa<ObjCInterfaceDecl>(D) ||
2027 isa<NamespaceDecl>(D))) {
2039 VisibilityAttr::VisibilityType
type;
2040 if (!VisibilityAttr::ConvertStrToVisibilityType(TypeStr, type)) {
2041 S.
Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
2048 if (type == VisibilityAttr::Protected &&
2050 S.
Diag(Attr.
getLoc(), diag::warn_attribute_protected_visibility);
2051 type = VisibilityAttr::Default;
2056 if (isTypeVisibility) {
2058 (TypeVisibilityAttr::VisibilityType) type,
2071 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2077 ObjCMethodFamilyAttr::FamilyKind F;
2078 if (!ObjCMethodFamilyAttr::ConvertStrToFamilyKind(IL->
Ident->
getName(), F)) {
2079 S.
Diag(IL->
Loc, diag::warn_attribute_type_not_supported) << Attr.
getName()
2099 QualType T = TD->getUnderlyingType();
2101 S.
Diag(TD->getLocation(), diag::err_nsobject_attribute);
2108 S.
Diag(PD->getLocation(), diag::err_nsobject_attribute);
2128 QualType T = TD->getUnderlyingType();
2130 S.
Diag(TD->getLocation(), diag::warn_ptr_independentclass_attribute);
2144 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2150 BlocksAttr::BlockType
type;
2151 if (!BlocksAttr::ConvertStrToBlockType(II->
getName(),
type)) {
2152 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
2163 unsigned sentinel = (
unsigned)SentinelAttr::DefaultSentinel;
2166 llvm::APSInt Idx(32);
2169 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2171 << E->getSourceRange();
2175 if (Idx.isSigned() && Idx.isNegative()) {
2176 S.
Diag(Attr.
getLoc(), diag::err_attribute_sentinel_less_than_zero)
2177 << E->getSourceRange();
2181 sentinel = Idx.getZExtValue();
2184 unsigned nullPos = (
unsigned)SentinelAttr::DefaultNullPos;
2187 llvm::APSInt Idx(32);
2190 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2192 << E->getSourceRange();
2195 nullPos = Idx.getZExtValue();
2197 if ((Idx.isSigned() && Idx.isNegative()) || nullPos > 1) {
2200 S.
Diag(Attr.
getLoc(), diag::err_attribute_sentinel_not_zero_or_one)
2201 << E->getSourceRange();
2208 if (isa<FunctionNoProtoType>(FT)) {
2209 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_named_arguments);
2213 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2214 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2218 if (!MD->isVariadic()) {
2219 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0;
2222 }
else if (
BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
2223 if (!BD->isVariadic()) {
2224 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << 1;
2227 }
else if (
const VarDecl *V = dyn_cast<VarDecl>(D)) {
2233 if (!cast<FunctionProtoType>(FT)->isVariadic()) {
2235 S.
Diag(Attr.
getLoc(), diag::warn_attribute_sentinel_not_variadic) << m;
2239 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2244 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2256 S.
Diag(Attr.
getLoc(), diag::warn_attribute_void_function_method)
2261 if (MD->getReturnType()->isVoidType()) {
2262 S.
Diag(Attr.
getLoc(), diag::warn_attribute_void_function_method)
2277 S.
Diag(Attr.
getLoc(), diag::warn_attribute_invalid_on_definition)
2279 else if (isa<ObjCPropertyDecl>(D) || isa<ObjCMethodDecl>(D) ||
2281 (isa<ObjCInterfaceDecl>(D) || isa<EnumDecl>(D)))) {
2284 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2296 template <
typename WorkGroupAttr>
2300 for (
unsigned i = 0; i < 3; ++i) {
2304 if (WGSize[i] == 0) {
2305 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_is_zero)
2306 << Attr.
getName() << E->getSourceRange();
2311 WorkGroupAttr *Existing = D->
getAttr<WorkGroupAttr>();
2312 if (Existing && !(Existing->getXDim() == WGSize[0] &&
2313 Existing->getYDim() == WGSize[1] &&
2314 Existing->getZDim() == WGSize[2]))
2318 WGSize[0], WGSize[1], WGSize[2],
2324 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
2331 assert(ParmTSI &&
"no type source info for attribute argument");
2336 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_vec_type_hint)
2341 if (VecTypeHintAttr *A = D->
getAttr<VecTypeHintAttr>()) {
2355 unsigned AttrSpellingListIndex) {
2356 if (SectionAttr *ExistingAttr = D->
getAttr<SectionAttr>()) {
2357 if (ExistingAttr->getName() == Name)
2359 Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section);
2364 AttrSpellingListIndex);
2369 if (!Error.empty()) {
2370 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target) <<
Error;
2389 if (!Error.empty()) {
2390 S.
Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
2406 for (
auto Str : {
"tune=",
"fpmath="})
2407 if (AttrStr.find(Str) != StringRef::npos)
2408 Diag(LiteralLoc, diag::warn_unsupported_target_attribute) << Str;
2418 TargetAttr *NewAttr =
2425 VarDecl *VD = cast<VarDecl>(D);
2438 if (
DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
2439 if (DRE->hasQualifier())
2440 S.
Diag(Loc, diag::warn_cleanup_ext);
2442 NI = DRE->getNameInfo();
2444 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 1
2449 if (ULE->hasExplicitTemplateArgs())
2450 S.
Diag(Loc, diag::warn_cleanup_ext);
2452 NI = ULE->getNameInfo();
2454 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 2
2461 S.
Diag(Loc, diag::err_attribute_cleanup_arg_not_function) << 0;
2466 S.
Diag(Loc, diag::err_attribute_cleanup_func_must_take_one_arg)
2477 S.
Diag(Loc, diag::err_attribute_cleanup_func_arg_incompatible_type)
2478 << NI.
getName() << ParamTy << Ty;
2499 if (not_nsstring_type &&
2503 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
2504 << (not_nsstring_type ?
"a string type" :
"an NSString")
2513 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_result_not)
2514 << (not_nsstring_type ?
"string type" :
"NSString")
2542 return llvm::StringSwitch<FormatAttrKind>(Format)
2555 .Cases(
"gcc_diag",
"gcc_cdiag",
"gcc_cxxdiag",
"gcc_tdiag",
IgnoredFormat)
2569 S.
Diag(Attr.
getLoc(), diag::err_init_priority_object_attr);
2573 QualType T = cast<VarDecl>(D)->getType();
2577 S.
Diag(Attr.
getLoc(), diag::err_init_priority_object_attr);
2583 uint32_t prioritynum;
2589 if (prioritynum < 101 || prioritynum > 65535) {
2590 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_outof_range)
2591 << E->getSourceRange();
2603 unsigned AttrSpellingListIndex) {
2606 if (F->getType() == Format &&
2607 F->getFormatIdx() == FormatIdx &&
2608 F->getFirstArg() == FirstArg) {
2611 if (F->getLocation().isInvalid())
2617 return ::new (
Context) FormatAttr(Range,
Context, Format, FormatIdx,
2618 FirstArg, AttrSpellingListIndex);
2625 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
2636 StringRef Format = II->
getName();
2639 if (Format.startswith(
"__") && Format.endswith(
"__")) {
2640 Format = Format.substr(2, Format.size() - 4);
2652 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
2663 if (Idx < 1 || Idx > NumArgs) {
2664 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
2665 << Attr.
getName() << 2 << IdxExpr->getSourceRange();
2670 unsigned ArgIdx = Idx - 1;
2672 if (HasImplicitThisParam) {
2675 diag::err_format_attribute_implicit_this_format_string)
2676 << IdxExpr->getSourceRange();
2687 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
2688 <<
"a CFString" << IdxExpr->getSourceRange()
2696 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
2697 <<
"an NSString" << IdxExpr->getSourceRange()
2703 S.
Diag(Attr.
getLoc(), diag::err_format_attribute_not)
2704 <<
"a string type" << IdxExpr->getSourceRange()
2716 if (FirstArg != 0) {
2720 S.
Diag(D->
getLocation(), diag::err_format_attribute_requires_variadic);
2728 if (FirstArg != 0) {
2729 S.
Diag(Attr.
getLoc(), diag::err_format_strftime_third_parameter)
2730 << FirstArgExpr->getSourceRange();
2734 }
else if (FirstArg != 0 && FirstArg != NumArgs) {
2735 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
2736 << Attr.
getName() << 3 << FirstArgExpr->getSourceRange();
2758 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
2765 diag::warn_transparent_union_attribute_not_definition);
2771 if (Field == FieldEnd) {
2772 S.
Diag(Attr.
getLoc(), diag::warn_transparent_union_attribute_zero_fields);
2780 diag::warn_transparent_union_attribute_floating)
2787 for (; Field != FieldEnd; ++Field) {
2788 QualType FieldType = Field->getType();
2800 S.
Diag(Field->getLocation(),
2801 diag::warn_transparent_union_attribute_field_size_align)
2802 << isSize << Field->getDeclName() << FieldBits;
2803 unsigned FirstBits = isSize? FirstSize : FirstAlign;
2805 diag::note_transparent_union_first_field_size_align)
2806 << isSize << FirstBits;
2825 if (I->getAnnotation() == Str)
2841 unsigned SpellingListIndex) {
2842 AlignValueAttr TmpAttr(AttrRange,
Context, E, SpellingListIndex);
2847 T = TD->getUnderlyingType();
2848 else if (
ValueDecl *VD = dyn_cast<ValueDecl>(D))
2851 llvm_unreachable(
"Unknown decl type for align_value");
2855 Diag(AttrLoc, diag::warn_attribute_pointer_or_reference_only)
2861 llvm::APSInt Alignment(32);
2864 diag::err_align_value_attribute_argument_not_int,
2869 if (!Alignment.isPowerOf2()) {
2870 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
2871 << E->getSourceRange();
2876 AlignValueAttr(AttrRange,
Context, ICE.
get(),
2877 SpellingListIndex));
2889 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_number_arguments)
2903 diag::err_pack_expansion_without_parameter_packs);
2911 if (
const auto *TND = dyn_cast<TypedefNameDecl>(D)) {
2912 if (!TND->getUnderlyingType()->isDependentType()) {
2913 S.
Diag(Attr.
getLoc(), diag::err_alignment_dependent_typedef_name)
2914 << E->getSourceRange();
2925 unsigned SpellingListIndex,
bool IsPackExpansion) {
2926 AlignedAttr TmpAttr(AttrRange,
Context,
true, E, SpellingListIndex);
2930 if (TmpAttr.isAlignas()) {
2943 if (isa<ParmVarDecl>(D)) {
2945 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2948 if (VD->isExceptionVariable())
2950 }
else if (
FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
2951 if (FD->isBitField())
2953 }
else if (!isa<TagDecl>(D)) {
2954 Diag(AttrLoc, diag::err_attribute_wrong_decl_type) << &TmpAttr
2959 if (DiagKind != -1) {
2960 Diag(AttrLoc, diag::err_alignas_attribute_wrong_decl_type)
2961 << &TmpAttr << DiagKind;
2968 AlignedAttr *AA = ::new (
Context) AlignedAttr(TmpAttr);
2969 AA->setPackExpansion(IsPackExpansion);
2975 llvm::APSInt Alignment(32);
2978 diag::err_aligned_attribute_argument_not_int,
2988 if (!(TmpAttr.isAlignas() && !Alignment)) {
2989 if(!llvm::isPowerOf2_64(Alignment.getZExtValue())) {
2990 Diag(AttrLoc, diag::err_alignment_not_power_of_two)
2991 << E->getSourceRange();
2996 if (
VarDecl *VD = dyn_cast<VarDecl>(D)) {
2997 if (VD->getTLSKind()) {
2999 if (Alignment.getSExtValue() > MaxAlignChars.
getQuantity()) {
3000 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)
3001 << (
unsigned)Alignment.getZExtValue() << VD
3012 unsigned MaxValidAlignment = TmpAttr.isDeclspec() ? 8192 : 268435456;
3013 if (Alignment.getZExtValue() > MaxValidAlignment) {
3014 Diag(AttrLoc, diag::err_attribute_aligned_too_great) << MaxValidAlignment
3015 << E->getSourceRange();
3019 AlignedAttr *AA = ::new (
Context) AlignedAttr(AttrRange,
Context,
true,
3020 ICE.
get(), SpellingListIndex);
3021 AA->setPackExpansion(IsPackExpansion);
3026 unsigned SpellingListIndex,
bool IsPackExpansion) {
3029 AlignedAttr *AA = ::new (
Context) AlignedAttr(AttrRange,
Context,
false, TS,
3031 AA->setPackExpansion(IsPackExpansion);
3036 assert(D->
hasAttrs() &&
"no attributes on decl");
3039 if (
ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
3040 UnderlyingTy = DiagTy = VD->getType();
3043 if (
EnumDecl *ED = dyn_cast<EnumDecl>(D))
3044 UnderlyingTy = ED->getIntegerType();
3046 if (DiagTy->isDependentType() || DiagTy->isIncompleteType())
3053 AlignedAttr *AlignasAttr =
nullptr;
3056 if (I->isAlignmentDependent())
3060 Align = std::max(Align, I->getAlignment(
Context));
3063 if (AlignasAttr && Align) {
3066 if (NaturalAlign > RequestedAlign)
3067 Diag(AlignasAttr->getLocation(), diag::err_alignas_underaligned)
3068 << DiagTy << (
unsigned)NaturalAlign.
getQuantity();
3074 MSInheritanceAttr::Spelling SemanticSpelling) {
3083 if (SemanticSpelling == MSInheritanceAttr::Keyword_unspecified_inheritance)
3094 Diag(Range.
getBegin(), diag::err_mismatched_ms_inheritance)
3117 StringRef Str = Name->
getName();
3120 if (Str.startswith(
"__") && Str.endswith(
"__"))
3121 Str = Str.substr(2, Str.size() - 4);
3123 unsigned DestWidth = 0;
3124 bool IntegerMode =
true;
3125 bool ComplexMode =
false;
3126 switch (Str.size()) {
3129 case 'Q': DestWidth = 8;
break;
3130 case 'H': DestWidth = 16;
break;
3131 case 'S': DestWidth = 32;
break;
3132 case 'D': DestWidth = 64;
break;
3133 case 'X': DestWidth = 96;
break;
3134 case 'T': DestWidth = 128;
break;
3136 if (Str[1] ==
'F') {
3137 IntegerMode =
false;
3138 }
else if (Str[1] ==
'C') {
3139 IntegerMode =
false;
3141 }
else if (Str[1] !=
'I') {
3150 else if (Str ==
"byte")
3154 if (Str ==
"pointer")
3158 if (Str ==
"unwind_word")
3165 OldTy = TD->getUnderlyingType();
3166 else if (
ValueDecl *VD = dyn_cast<ValueDecl>(D))
3167 OldTy = VD->getType();
3178 OldElemTy = VT->getElementType();
3181 S.
Diag(Attr.
getLoc(), diag::err_mode_not_primitive);
3182 else if (IntegerMode) {
3184 S.
Diag(Attr.
getLoc(), diag::err_mode_wrong_type);
3185 }
else if (ComplexMode) {
3187 S.
Diag(Attr.
getLoc(), diag::err_mode_wrong_type);
3190 S.
Diag(Attr.
getLoc(), diag::err_mode_wrong_type);
3198 S.
Diag(Attr.
getLoc(), diag::err_machine_mode) << 0 << Name;
3210 if (NewElemTy.
isNull()) {
3211 S.
Diag(Attr.
getLoc(), diag::err_machine_mode) << 1 << Name;
3223 S.
Diag(Attr.
getLoc(), diag::err_complex_mode_vector_type);
3227 OldVT->getNumElements() /
3234 S.
Diag(Attr.
getLoc(), diag::err_mode_wrong_type);
3240 TD->setModedTypeSourceInfo(TD->getTypeSourceInfo(), NewTy);
3242 cast<ValueDecl>(D)->setType(NewTy);
3250 if (
const VarDecl *VD = dyn_cast<VarDecl>(D)) {
3251 if (!VD->hasGlobalStorage())
3253 diag::warn_attribute_requires_functions_or_static_globals)
3257 diag::warn_attribute_requires_functions_or_static_globals)
3269 unsigned AttrSpellingListIndex) {
3270 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
3271 Diag(Range.
getBegin(), diag::warn_attribute_ignored) << Ident;
3272 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
3276 if (D->
hasAttr<AlwaysInlineAttr>())
3280 AttrSpellingListIndex);
3284 unsigned AttrSpellingListIndex) {
3285 if (OptimizeNoneAttr *Optnone = D->
getAttr<OptimizeNoneAttr>()) {
3286 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'minsize'";
3287 Diag(Optnone->getLocation(), diag::note_conflicting_attribute);
3291 if (D->
hasAttr<MinSizeAttr>())
3294 return ::new (
Context) MinSizeAttr(Range,
Context, AttrSpellingListIndex);
3298 unsigned AttrSpellingListIndex) {
3299 if (AlwaysInlineAttr *Inline = D->
getAttr<AlwaysInlineAttr>()) {
3300 Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
3301 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
3304 if (MinSizeAttr *MinSize = D->
getAttr<MinSizeAttr>()) {
3305 Diag(MinSize->getLocation(), diag::warn_attribute_ignored) << MinSize;
3306 Diag(Range.
getBegin(), diag::note_conflicting_attribute);
3310 if (D->
hasAttr<OptimizeNoneAttr>())
3314 AttrSpellingListIndex);
3357 S.
Diag(Attr.
getLoc(), diag::warn_gnu_inline_attribute_requires_inline);
3375 if (!isa<ObjCMethodDecl>(D)) {
3376 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
3382 case AttributeList::AT_FastCall:
3387 case AttributeList::AT_StdCall:
3392 case AttributeList::AT_ThisCall:
3397 case AttributeList::AT_CDecl:
3402 case AttributeList::AT_Pascal:
3407 case AttributeList::AT_VectorCall:
3412 case AttributeList::AT_MSABI:
3417 case AttributeList::AT_SysVABI:
3422 case AttributeList::AT_Pcs: {
3423 PcsAttr::PCSType PCS;
3426 PCS = PcsAttr::AAPCS;
3429 PCS = PcsAttr::AAPCS_VFP;
3432 llvm_unreachable(
"unexpected calling convention in pcs attribute");
3440 case AttributeList::AT_IntelOclBicc:
3447 llvm_unreachable(
"unexpected attribute kind");
3456 unsigned ReqArgs = attr.
getKind() == AttributeList::AT_Pcs ? 1 : 0;
3464 case AttributeList::AT_CDecl: CC =
CC_C;
break;
3468 case AttributeList::AT_Pascal: CC =
CC_X86Pascal;
break;
3470 case AttributeList::AT_MSABI:
3474 case AttributeList::AT_SysVABI:
3478 case AttributeList::AT_Pcs: {
3484 if (StrRef ==
"aapcs") {
3487 }
else if (StrRef ==
"aapcs-vfp") {
3497 default: llvm_unreachable(
"unexpected attribute kind");
3537 Diag(Attr.
getLoc(), diag::err_attribute_regparm_wrong_platform)
3538 << NumParamsExpr->getSourceRange();
3545 Diag(Attr.
getLoc(), diag::err_attribute_regparm_invalid_number)
3557 const CUDALaunchBoundsAttr &
Attr,
3558 const unsigned Idx) {
3575 if (!I.isIntN(32)) {
3576 S.
Diag(E->
getExprLoc(), diag::err_ice_too_large) << I.toString(10,
false)
3581 S.
Diag(E->
getExprLoc(), diag::warn_attribute_argument_n_negative)
3582 << &Attr << Idx << E->getSourceRange();
3588 Expr *MinBlocks,
unsigned SpellingListIndex) {
3589 CUDALaunchBoundsAttr TmpAttr(AttrRange,
Context, MaxThreads, MinBlocks,
3599 AttrRange,
Context, MaxThreads, MinBlocks, SpellingListIndex));
3616 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
3627 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_decl_type)
3632 uint64_t ArgumentIdx;
3637 uint64_t TypeTagIdx;
3642 bool IsPointer = (Attr.
getName()->
getName() ==
"pointer_with_type_tag");
3647 S.
Diag(Attr.
getLoc(), diag::err_attribute_pointers_only)
3654 ArgumentIdx, TypeTagIdx, IsPointer,
3661 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_n_type)
3669 if (!isa<VarDecl>(D)) {
3670 S.
Diag(Attr.
getLoc(), diag::err_attribute_wrong_decl_type)
3678 assert(MatchingCTypeLoc &&
"no type source info for attribute argument");
3712 if (Attr.
getKind() == AttributeList::AT_NSConsumed) {
3721 S.
Diag(D->
getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
3742 returnType = MD->getReturnType();
3744 (Attr.
getKind() == AttributeList::AT_NSReturnsRetained))
3747 returnType = PD->getType();
3749 returnType = FD->getReturnType();
3750 else if (
auto *Param = dyn_cast<ParmVarDecl>(D)) {
3752 if (returnType.
isNull()) {
3753 S.
Diag(D->
getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
3761 default: llvm_unreachable(
"invalid ownership attribute");
3762 case AttributeList::AT_NSReturnsRetained:
3763 case AttributeList::AT_NSReturnsAutoreleased:
3764 case AttributeList::AT_NSReturnsNotRetained:
3768 case AttributeList::AT_CFReturnsRetained:
3769 case AttributeList::AT_CFReturnsNotRetained:
3781 default: llvm_unreachable(
"invalid ownership attribute");
3782 case AttributeList::AT_NSReturnsRetained:
3787 case AttributeList::AT_NSReturnsAutoreleased:
3788 case AttributeList::AT_NSReturnsNotRetained:
3793 case AttributeList::AT_CFReturnsRetained:
3794 case AttributeList::AT_CFReturnsNotRetained:
3801 if (isa<ParmVarDecl>(D)) {
3802 S.
Diag(D->
getLocStart(), diag::warn_ns_attribute_wrong_parameter_type)
3811 } SubjectKind = Function;
3812 if (isa<ObjCMethodDecl>(D))
3813 SubjectKind = Method;
3814 else if (isa<ObjCPropertyDecl>(D))
3817 << Attr.
getName() << SubjectKind << cf
3825 llvm_unreachable(
"invalid ownership attribute");
3826 case AttributeList::AT_NSReturnsAutoreleased:
3830 case AttributeList::AT_CFReturnsNotRetained:
3834 case AttributeList::AT_NSReturnsNotRetained:
3838 case AttributeList::AT_CFReturnsRetained:
3842 case AttributeList::AT_NSReturnsRetained:
3851 const int EP_ObjCMethod = 1;
3852 const int EP_ObjCProperty = 2;
3856 if (isa<ObjCMethodDecl>(D))
3857 resultType = cast<ObjCMethodDecl>(D)->getReturnType();
3859 resultType = cast<ObjCPropertyDecl>(D)->getType();
3866 << (isa<ObjCMethodDecl>(D) ? EP_ObjCMethod : EP_ObjCProperty)
3882 if (
const ObjCProtocolDecl *PDecl = dyn_cast_or_null<ObjCProtocolDecl>(DC)) {
3885 S.
Diag(PDecl->getLocation(), diag::note_protocol_decl);
3901 if (checkAttrMutualExclusion<CFUnknownTransferAttr>(S, D, Attr))
3911 if (checkAttrMutualExclusion<CFAuditedTransferAttr>(S, D, Attr))
3929 if (
auto TD = dyn_cast<TypedefNameDecl>(D)) {
3931 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_typedef_not_id)
3937 QualType T = TD->getUnderlyingType();
3939 S.
Diag(Attr.
getLoc(), diag::err_objc_attr_typedef_not_void_pointer);
3967 if (!RelatedClass) {
3977 ClassMethod, InstanceMethod,
3986 IFace = CatDecl->getClassInterface();
4001 StringRef MetaDataName;
4016 bool notify =
false;
4025 ObjCBoxableAttr *BoxableAttr = ::new (S.
Context)
4033 L->AddedAttributeToRecord(BoxableAttr, RD);
4051 if (!type->isDependentType() &&
4052 !type->isObjCLifetimeType()) {
4053 S.
Diag(Attr.
getLoc(), diag::err_objc_precise_lifetime_bad_type)
4063 lifetime = type->getObjCARCImplicitLifetime();
4067 assert(type->isDependentType() &&
4068 "didn't infer lifetime for non-dependent type?");
4077 S.
Diag(Attr.
getLoc(), diag::warn_objc_precise_lifetime_meaningless)
4093 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
4098 if (!isa<CXXRecordDecl>(D)) {
4099 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
4111 if (StrRef.size() == 38 && StrRef.front() ==
'{' && StrRef.back() ==
'}')
4112 StrRef = StrRef.drop_front().drop_back();
4115 if (StrRef.size() != 36) {
4116 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
4120 for (
unsigned i = 0; i < 36; ++i) {
4121 if (i == 8 || i == 13 || i == 18 || i == 23) {
4122 if (StrRef[i] !=
'-') {
4123 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
4127 S.
Diag(LiteralLoc, diag::err_attribute_uuid_malformed_guid);
4138 S.
Diag(Attr.
getLoc(), diag::err_attribute_not_supported_in_lang)
4152 VarDecl *VD = cast<VarDecl>(D);
4154 S.
Diag(Attr.
getLoc(), diag::err_thread_unsupported);
4158 S.
Diag(Attr.
getLoc(), diag::err_declspec_thread_on_thread_variable);
4162 S.
Diag(Attr.
getLoc(), diag::err_thread_non_global) <<
"__declspec(thread)";
4173 S.
Diag(Attr.
getLoc(), diag::err_attribute_too_many_arguments)
4186 ARMInterruptAttr::InterruptType
Kind;
4187 if (!ARMInterruptAttr::ConvertStrToInterruptType(Str, Kind)) {
4188 S.
Diag(Attr.
getLoc(), diag::warn_attribute_type_not_supported)
4189 << Attr.
getName() << Str << ArgLoc;
4212 llvm::APSInt NumParams(32);
4214 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_type)
4216 << NumParamsExpr->getSourceRange();
4220 unsigned Num = NumParams.getLimitedValue(255);
4221 if ((Num & 1) || Num > 30) {
4222 S.
Diag(Attr.
getLoc(), diag::err_attribute_argument_out_of_bounds)
4223 << Attr.
getName() << (int)NumParams.getSExtValue()
4224 << NumParamsExpr->getSourceRange();
4282 if (!isa<FunctionDecl>(D)) {
4283 S.
Diag(Attr.
getLoc(), diag::warn_attribute_wrong_decl_type)
4294 unsigned AttrSpellingListIndex) {
4295 if (D->
hasAttr<DLLExportAttr>()) {
4296 Diag(Range.
getBegin(), diag::warn_attribute_ignored) <<
"'dllimport'";
4300 if (D->
hasAttr<DLLImportAttr>())
4303 return ::new (
Context) DLLImportAttr(Range,
Context, AttrSpellingListIndex);
4307 unsigned AttrSpellingListIndex) {
4308 if (DLLImportAttr *Import = D->
getAttr<DLLImportAttr>()) {
4309 Diag(Import->getLocation(), diag::warn_attribute_ignored) << Import;
4313 if (D->
hasAttr<DLLExportAttr>())
4316 return ::new (
Context) DLLExportAttr(Range,
Context, AttrSpellingListIndex);
4320 if (isa<ClassTemplatePartialSpecializationDecl>(D) &&
4328 if (FD->isInlined() && A.
getKind() == AttributeList::AT_DLLImport &&
4338 Attr *NewAttr = A.
getKind() == AttributeList::AT_DLLExport
4347 unsigned AttrSpellingListIndex,
4348 MSInheritanceAttr::Spelling SemanticSpelling) {
4349 if (MSInheritanceAttr *IA = D->
getAttr<MSInheritanceAttr>()) {
4350 if (IA->getSemanticSpelling() == SemanticSpelling)
4352 Diag(IA->getLocation(), diag::err_mismatched_ms_inheritance)
4354 Diag(Range.
getBegin(), diag::note_previous_ms_inheritance);
4361 SemanticSpelling)) {
4365 if (isa<ClassTemplatePartialSpecializationDecl>(RD)) {
4366 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
4371 Diag(Range.
getBegin(), diag::warn_ignored_ms_inheritance)
4378 MSInheritanceAttr(Range,
Context, BestCase, AttrSpellingListIndex);
4390 StringRef N(
"mutex");
4392 if (Attr.
getKind() == AttributeList::AT_Capability &&
4398 if (!N.equals_lower(
"mutex") && !N.equals_lower(
"role"))
4399 S.
Diag(LiteralLoc, diag::warn_invalid_capability_name) << N;
4420 Args.data(), Args.size(),
4460 RequiresCapabilityAttr *RCA = ::new (S.
Context)
4468 if (
auto *NSD = dyn_cast<NamespaceDecl>(D)) {
4469 if (NSD->isAnonymousNamespace()) {
4470 S.
Diag(Attr.
getLoc(), diag::warn_deprecated_anonymous_namespace);
4481 S.
Diag(Attr.
getLoc(), diag::ext_deprecated_attr_is_a_cxx14_extension);
4483 handleAttrWithMessage<DeprecatedAttr>(
S, D, Attr);
4490 std::vector<std::string> Sanitizers;
4492 for (
unsigned I = 0, E = Attr.
getNumArgs(); I != E; ++I) {
4493 StringRef SanitizerName;
4500 S.
Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << SanitizerName;
4502 Sanitizers.push_back(SanitizerName);
4512 std::string SanitizerName =
4514 .Case(
"no_address_safety_analysis",
"address")
4515 .Case(
"no_sanitize_address",
"address")
4516 .Case(
"no_sanitize_thread",
"thread")
4517 .Case(
"no_sanitize_memory",
"memory");
4573 bool IncludeCXX11Attributes) {
4588 ? diag::warn_unhandled_ms_attribute_ignored
4589 : diag::warn_unknown_attribute_ignored)
4600 assert(Attr.
isTypeAttr() &&
"Non-type attribute not handled");
4602 case AttributeList::AT_Interrupt:
4605 case AttributeList::AT_X86ForceAlignArgPointer:
4608 case AttributeList::AT_DLLExport:
4609 case AttributeList::AT_DLLImport:
4612 case AttributeList::AT_Mips16:
4613 handleSimpleAttribute<Mips16Attr>(
S, D, Attr);
4615 case AttributeList::AT_NoMips16:
4616 handleSimpleAttribute<NoMips16Attr>(
S, D, Attr);
4618 case AttributeList::AT_AMDGPUNumVGPR:
4621 case AttributeList::AT_AMDGPUNumSGPR:
4624 case AttributeList::AT_IBAction:
4625 handleSimpleAttribute<IBActionAttr>(
S, D, Attr);
4627 case AttributeList::AT_IBOutlet:
4630 case AttributeList::AT_IBOutletCollection:
4633 case AttributeList::AT_Alias:
4636 case AttributeList::AT_Aligned:
4639 case AttributeList::AT_AlignValue:
4642 case AttributeList::AT_AlwaysInline:
4645 case AttributeList::AT_AnalyzerNoReturn:
4648 case AttributeList::AT_TLSModel:
4651 case AttributeList::AT_Annotate:
4654 case AttributeList::AT_Availability:
4657 case AttributeList::AT_CarriesDependency:
4660 case AttributeList::AT_Common:
4663 case AttributeList::AT_CUDAConstant:
4664 handleSimpleAttribute<CUDAConstantAttr>(
S, D, Attr);
4666 case AttributeList::AT_Constructor:
4669 case AttributeList::AT_CXX11NoReturn:
4670 handleSimpleAttribute<CXX11NoReturnAttr>(
S, D, Attr);
4672 case AttributeList::AT_Deprecated:
4675 case AttributeList::AT_Destructor:
4678 case AttributeList::AT_EnableIf:
4681 case AttributeList::AT_ExtVectorType:
4684 case AttributeList::AT_MinSize:
4687 case AttributeList::AT_OptimizeNone:
4690 case AttributeList::AT_FlagEnum:
4691 handleSimpleAttribute<FlagEnumAttr>(
S, D, Attr);
4693 case AttributeList::AT_Flatten:
4694 handleSimpleAttribute<FlattenAttr>(
S, D, Attr);
4696 case AttributeList::AT_Format:
4699 case AttributeList::AT_FormatArg:
4702 case AttributeList::AT_CUDAGlobal:
4705 case AttributeList::AT_CUDADevice:
4706 handleSimpleAttribute<CUDADeviceAttr>(
S, D, Attr);
4708 case AttributeList::AT_CUDAHost:
4709 handleSimpleAttribute<CUDAHostAttr>(
S, D, Attr);
4711 case AttributeList::AT_GNUInline:
4714 case AttributeList::AT_CUDALaunchBounds:
4717 case AttributeList::AT_Restrict:
4720 case AttributeList::AT_MayAlias:
4721 handleSimpleAttribute<MayAliasAttr>(
S, D, Attr);
4723 case AttributeList::AT_Mode:
4726 case AttributeList::AT_NoCommon:
4727 handleSimpleAttribute<NoCommonAttr>(
S, D, Attr);
4729 case AttributeList::AT_NoSplitStack:
4730 handleSimpleAttribute<NoSplitStackAttr>(
S, D, Attr);
4732 case AttributeList::AT_NonNull:
4738 case AttributeList::AT_ReturnsNonNull:
4741 case AttributeList::AT_AssumeAligned:
4744 case AttributeList::AT_Overloadable:
4745 handleSimpleAttribute<OverloadableAttr>(
S, D, Attr);
4747 case AttributeList::AT_Ownership:
4750 case AttributeList::AT_Cold:
4753 case AttributeList::AT_Hot:
4756 case AttributeList::AT_Naked:
4757 handleSimpleAttribute<NakedAttr>(
S, D, Attr);
4759 case AttributeList::AT_NoReturn:
4762 case AttributeList::AT_NoThrow:
4763 handleSimpleAttribute<NoThrowAttr>(
S, D, Attr);
4765 case AttributeList::AT_CUDAShared:
4766 handleSimpleAttribute<CUDASharedAttr>(
S, D, Attr);
4768 case AttributeList::AT_VecReturn:
4772 case AttributeList::AT_ObjCOwnership:
4775 case AttributeList::AT_ObjCPreciseLifetime:
4779 case AttributeList::AT_ObjCReturnsInnerPointer:
4783 case AttributeList::AT_ObjCRequiresSuper:
4787 case AttributeList::AT_ObjCBridge:
4791 case AttributeList::AT_ObjCBridgeMutable:
4795 case AttributeList::AT_ObjCBridgeRelated:
4799 case AttributeList::AT_ObjCDesignatedInitializer:
4803 case AttributeList::AT_ObjCRuntimeName:
4807 case AttributeList::AT_ObjCBoxable:
4811 case AttributeList::AT_CFAuditedTransfer:
4814 case AttributeList::AT_CFUnknownTransfer:
4818 case AttributeList::AT_CFConsumed:
4819 case AttributeList::AT_NSConsumed:
4822 case AttributeList::AT_NSConsumesSelf:
4823 handleSimpleAttribute<NSConsumesSelfAttr>(
S, D, Attr);
4826 case AttributeList::AT_NSReturnsAutoreleased:
4827 case AttributeList::AT_NSReturnsNotRetained:
4828 case AttributeList::AT_CFReturnsNotRetained:
4829 case AttributeList::AT_NSReturnsRetained:
4830 case AttributeList::AT_CFReturnsRetained:
4833 case AttributeList::AT_WorkGroupSizeHint:
4834 handleWorkGroupSize<WorkGroupSizeHintAttr>(
S, D, Attr);
4836 case AttributeList::AT_ReqdWorkGroupSize:
4837 handleWorkGroupSize<ReqdWorkGroupSizeAttr>(
S, D, Attr);
4839 case AttributeList::AT_VecTypeHint:
4843 case AttributeList::AT_InitPriority:
4847 case AttributeList::AT_Packed:
4850 case AttributeList::AT_Section:
4853 case AttributeList::AT_Target:
4856 case AttributeList::AT_Unavailable:
4857 handleAttrWithMessage<UnavailableAttr>(
S, D, Attr);
4859 case AttributeList::AT_ArcWeakrefUnavailable:
4860 handleSimpleAttribute<ArcWeakrefUnavailableAttr>(
S, D, Attr);
4862 case AttributeList::AT_ObjCRootClass:
4863 handleSimpleAttribute<ObjCRootClassAttr>(
S, D, Attr);
4865 case AttributeList::AT_ObjCExplicitProtocolImpl:
4868 case AttributeList::AT_ObjCRequiresPropertyDefs:
4869 handleSimpleAttribute<ObjCRequiresPropertyDefsAttr>(
S, D, Attr);
4871 case AttributeList::AT_Unused:
4872 handleSimpleAttribute<UnusedAttr>(
S, D, Attr);
4874 case AttributeList::AT_ReturnsTwice:
4875 handleSimpleAttribute<ReturnsTwiceAttr>(
S, D, Attr);
4877 case AttributeList::AT_Used:
4880 case AttributeList::AT_Visibility:
4883 case AttributeList::AT_TypeVisibility:
4886 case AttributeList::AT_WarnUnused:
4887 handleSimpleAttribute<WarnUnusedAttr>(
S, D, Attr);
4889 case AttributeList::AT_WarnUnusedResult:
4892 case AttributeList::AT_Weak:
4893 handleSimpleAttribute<WeakAttr>(
S, D, Attr);
4895 case AttributeList::AT_WeakRef:
4898 case AttributeList::AT_WeakImport:
4901 case AttributeList::AT_TransparentUnion:
4904 case AttributeList::AT_ObjCException:
4905 handleSimpleAttribute<ObjCExceptionAttr>(
S, D, Attr);
4907 case AttributeList::AT_ObjCMethodFamily:
4910 case AttributeList::AT_ObjCNSObject:
4913 case AttributeList::AT_ObjCIndependentClass:
4916 case AttributeList::AT_Blocks:
4919 case AttributeList::AT_Sentinel:
4922 case AttributeList::AT_Const:
4923 handleSimpleAttribute<ConstAttr>(
S, D, Attr);
4925 case AttributeList::AT_Pure:
4926 handleSimpleAttribute<PureAttr>(
S, D, Attr);
4928 case AttributeList::AT_Cleanup:
4931 case AttributeList::AT_NoDebug:
4934 case AttributeList::AT_NoDuplicate:
4935 handleSimpleAttribute<NoDuplicateAttr>(
S, D, Attr);
4937 case AttributeList::AT_NoInline:
4938 handleSimpleAttribute<NoInlineAttr>(
S, D, Attr);
4940 case AttributeList::AT_NoInstrumentFunction:
4941 handleSimpleAttribute<NoInstrumentFunctionAttr>(
S, D, Attr);
4943 case AttributeList::AT_StdCall:
4944 case AttributeList::AT_CDecl:
4945 case AttributeList::AT_FastCall:
4946 case AttributeList::AT_ThisCall:
4947 case AttributeList::AT_Pascal:
4948 case AttributeList::AT_VectorCall:
4949 case AttributeList::AT_MSABI:
4950 case AttributeList::AT_SysVABI:
4951 case AttributeList::AT_Pcs:
4952 case AttributeList::AT_IntelOclBicc:
4955 case AttributeList::AT_OpenCLKernel:
4956 handleSimpleAttribute<OpenCLKernelAttr>(
S, D, Attr);
4958 case AttributeList::AT_OpenCLImageAccess:
4959 handleSimpleAttribute<OpenCLImageAccessAttr>(
S, D, Attr);
4963 case AttributeList::AT_MSNoVTable:
4964 handleSimpleAttribute<MSNoVTableAttr>(
S, D, Attr);
4966 case AttributeList::AT_MSStruct:
4967 handleSimpleAttribute<MSStructAttr>(
S, D, Attr);
4969 case AttributeList::AT_Uuid:
4972 case AttributeList::AT_MSInheritance:
4975 case AttributeList::AT_SelectAny:
4976 handleSimpleAttribute<SelectAnyAttr>(
S, D, Attr);
4978 case AttributeList::AT_Thread:
4983 case AttributeList::AT_AssertExclusiveLock:
4986 case AttributeList::AT_AssertSharedLock:
4989 case AttributeList::AT_GuardedVar:
4990 handleSimpleAttribute<GuardedVarAttr>(
S, D, Attr);
4992 case AttributeList::AT_PtGuardedVar:
4995 case AttributeList::AT_ScopedLockable:
4996 handleSimpleAttribute<ScopedLockableAttr>(
S, D, Attr);
4998 case AttributeList::AT_NoSanitize:
5001 case AttributeList::AT_NoSanitizeSpecific:
5004 case AttributeList::AT_NoThreadSafetyAnalysis:
5005 handleSimpleAttribute<NoThreadSafetyAnalysisAttr>(
S, D, Attr);
5007 case AttributeList::AT_GuardedBy:
5010 case AttributeList::AT_PtGuardedBy:
5013 case AttributeList::AT_ExclusiveTrylockFunction:
5016 case AttributeList::AT_LockReturned:
5019 case AttributeList::AT_LocksExcluded:
5022 case AttributeList::AT_SharedTrylockFunction:
5025 case AttributeList::AT_AcquiredBefore:
5028 case AttributeList::AT_AcquiredAfter:
5033 case AttributeList::AT_Capability:
5034 case AttributeList::AT_Lockable:
5037 case AttributeList::AT_RequiresCapability:
5041 case AttributeList::AT_AssertCapability:
5044 case AttributeList::AT_AcquireCapability:
5047 case AttributeList::AT_ReleaseCapability:
5050 case AttributeList::AT_TryAcquireCapability:
5055 case AttributeList::AT_Consumable:
5058 case AttributeList::AT_ConsumableAutoCast:
5059 handleSimpleAttribute<ConsumableAutoCastAttr>(
S, D, Attr);
5061 case AttributeList::AT_ConsumableSetOnRead:
5062 handleSimpleAttribute<ConsumableSetOnReadAttr>(
S, D, Attr);
5064 case AttributeList::AT_CallableWhen:
5067 case AttributeList::AT_ParamTypestate:
5070 case AttributeList::AT_ReturnTypestate:
5073 case AttributeList::AT_SetTypestate:
5076 case AttributeList::AT_TestTypestate:
5081 case AttributeList::AT_ArgumentWithTypeTag:
5084 case AttributeList::AT_TypeTagForDatatype:
5094 bool IncludeCXX11Attributes) {
5103 Diag(AttrList->
getLoc(), diag::err_attribute_weakref_without_alias)
5104 << cast<NamedDecl>(D);
5113 if (!D->
hasAttr<OpenCLKernelAttr>()) {
5115 if (
Attr *A = D->
getAttr<ReqdWorkGroupSizeAttr>()) {
5120 }
else if (
Attr *A = D->
getAttr<WorkGroupSizeHintAttr>()) {
5123 }
else if (
Attr *A = D->
getAttr<VecTypeHintAttr>()) {
5126 }
else if (
Attr *A = D->
getAttr<AMDGPUNumVGPRAttr>()) {
5130 }
else if (
Attr *A = D->
getAttr<AMDGPUNumSGPRAttr>()) {
5143 if (l->getKind() == AttributeList::AT_Annotate) {
5146 Diag(l->getLoc(), diag::err_only_annotate_after_access_spec);
5157 for ( ; A; A = A->
getNext()) {
5163 S.
Diag(A->
getLoc(), diag::warn_unknown_attribute_ignored)
5166 S.
Diag(A->
getLoc(), diag::warn_attribute_not_on_decl)
5186 assert(isa<FunctionDecl>(ND) || isa<VarDecl>(ND));
5196 FD->getType(), FD->getTypeSourceInfo(),
5202 if (FD->getQualifier())
5210 for (
const auto &AI : FT->param_types()) {
5213 Params.push_back(Param);
5215 NewFD->setParams(Params);
5217 }
else if (
VarDecl *VD = dyn_cast<VarDecl>(ND)) {
5219 VD->getInnerLocStart(), VD->getLocation(), II,
5220 VD->getType(), VD->getTypeSourceInfo(),
5221 VD->getStorageClass());
5222 if (VD->getQualifier()) {
5223 VarDecl *NewVD = cast<VarDecl>(NewD);
5261 if (
VarDecl *VD = dyn_cast<VarDecl>(D))
5262 if (VD->isExternC())
5265 if (FD->isExternC())
5307 if (!isa<FieldDecl>(decl) && !isa<ObjCPropertyDecl>(decl) &&
5308 !isa<FunctionDecl>(decl))
5320 "this system declaration uses an unsupported type",
5325 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(decl)) {
5328 if (FD->hasAttr<UnavailableAttr>() &&
5330 diag::err_arc_array_param_no_ownership) {
5349 return Interface->isDeprecated();
5361 return Interface->isUnavailable();
5371 bool ObjCPropertyAccess) {
5373 unsigned diag, diag_message, diag_fwdclass_message;
5376 unsigned property_note_select;
5379 unsigned available_here_select_kind;
5386 diag = !ObjCPropertyAccess ? diag::warn_deprecated
5387 : diag::warn_property_method_deprecated;
5388 diag_message = diag::warn_deprecated_message;
5389 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
5390 property_note_select = 0;
5391 available_here_select_kind = 2;
5397 diag = !ObjCPropertyAccess ? diag::err_unavailable
5398 : diag::err_property_method_unavailable;
5399 diag_message = diag::err_unavailable_message;
5400 diag_fwdclass_message = diag::warn_unavailable_fwdclass_message;
5401 property_note_select = 1;
5402 available_here_select_kind = 0;
5406 diag = diag::warn_partial_availability;
5407 diag_message = diag::warn_partial_message;
5408 diag_fwdclass_message = diag::warn_partial_fwdclass_message;
5409 property_note_select = 2;
5410 available_here_select_kind = 3;
5414 if (!Message.empty()) {
5415 S.
Diag(Loc, diag_message) << D << Message;
5418 << ObjCProperty->
getDeclName() << property_note_select;
5419 }
else if (!UnknownObjCClass) {
5420 S.
Diag(Loc, diag) << D;
5423 << ObjCProperty->
getDeclName() << property_note_select;
5425 S.
Diag(Loc, diag_fwdclass_message) << D;
5430 << D << available_here_select_kind;
5432 S.
Diag(Loc, diag::note_partial_availability_silence) << D;
5474 switch (diag.
Kind) {
5500 assert(curPool &&
"re-emitting in undelayed context not supported");
5501 curPool->
steal(pool);
5509 bool ObjCPropertyAccess) {
5513 AD, Loc, D, UnknownObjCClass, ObjCProperty, Message,
5514 ObjCPropertyAccess));
5520 ObjCProperty, ObjCPropertyAccess);
static void handleConsumableAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getFlags() const
bool CheckNoReturnAttr(const AttributeList &attr)
static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D, const AttributeList &Attr)
Defines the clang::ASTContext interface.
static bool hasFunctionProto(const Decl *D)
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. Note that this function may produce an error message...
static bool checkTryLockFunAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
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
ExprResult PerformContextuallyConvertToBool(Expr *From)
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)
bool isUnavailable(std::string *Message=nullptr) const
Determine whether this declaration is marked 'unavailable'.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type...
static bool isDeclUnavailable(Decl *D)
IdentifierInfo * getIdentifier() const
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
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
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.
QualType getUnderlyingType() const
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
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...
static bool checkUInt32Argument(Sema &S, const AttributeList &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...
Defines the C++ template declaration subclasses.
bool isVoidPointerType() const
bool hasDefinition() const
static void handleDestructorAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, const AttributeList &Attr)
const ObjCObjectType * getObjectType() const
unsigned getRegParmMax() const
static void handleFormatAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isBooleanType() const
A container of type source information.
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)
static void handleHotAttr(Sema &S, Decl *D, const AttributeList &Attr)
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)
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.
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)
bool isArgIdent(unsigned Arg) const
ParmVarDecl - Represents a parameter to a function.
bool isObjCRetainableType() const
Defines the clang::Expr interface and subclasses for C++ expressions.
FormatAttr * mergeFormatAttr(Decl *D, SourceRange Range, IdentifierInfo *Format, int FormatIdx, int FirstArg, unsigned AttrSpellingListIndex)
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)
static void handleMSP430InterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
DeclarationName getName() const
getName - Returns the embedded declaration name.
sema::DelayedDiagnosticPool * getCurrentPool() const
Returns the current delayed-diagnostics pool.
SourceLocation getUnavailableLoc() const
static void DoEmitAvailabilityWarning(Sema &S, Sema::AvailabilityDiagnostic K, Decl *Ctx, const NamedDecl *D, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
static void handleAssumeAlignedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleIBOutlet(Sema &S, Decl *D, const AttributeList &Attr)
AttributeList * getList() const
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)
The results of name lookup within a DeclContext. This is either a single result (with no stable stora...
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)
bool isReferenceType() const
QualType getReturnType() const
bool isCompleteDefinition() const
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)
static void handleCallableWhenAttr(Sema &S, Decl *D, const AttributeList &Attr)
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)
const internal::VariadicAllOfMatcher< Decl > decl
Matches declarations.
CXXRecordDecl * getDefinition() const
static void handleLocksExcludedAttr(Sema &S, Decl *D, const AttributeList &Attr)
TagKind getTagKind() const
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
bool existsInTarget(const llvm::Triple &T) 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)
static void handleARMInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
void redelayDiagnostics(sema::DelayedDiagnosticPool &pool)
Describes a module or submodule.
virtual CallingConv getDefaultCallingConv(CallingConvMethodType MT) const
Gets the default calling convention for the given target and declaration context. ...
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)
void AddAssumeAlignedAttr(SourceRange AttrRange, Decl *D, Expr *E, Expr *OE, unsigned SpellingListIndex)
static void handleExtVectorTypeAttr(Sema &S, Scope *scope, Decl *D, const AttributeList &Attr)
static void handleObjCReturnsInnerPointerAttr(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)
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec *SS=nullptr, bool isClassName=false, bool HasTrailingDot=false, ParsedType ObjectType=ParsedType(), bool IsCtorOrDtorName=false, bool WantNontrivialTypeSourceInfo=false, IdentifierInfo **CorrectedII=nullptr)
If the identifier refers to a type name within this scope, return the declaration of that type...
static void handleNoSanitizeAttr(Sema &S, Decl *D, const AttributeList &Attr)
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
QualType getReturnType() const
static void handleInterruptAttr(Sema &S, Decl *D, const AttributeList &Attr)
AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, QualType LHSType, QualType RHSType)
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
const DelayedDiagnosticPool * getParent() const
QualType getForbiddenTypeOperand() const
bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC, const FunctionDecl *FD=nullptr)
bool hasParsedType() const
bool isValueDependent() const
RecordDecl * getDecl() const
void steal(DelayedDiagnosticPool &pool)
Steal the diagnostics from the given pool.
ObjCInterfaceDecl * getInterface() const
static void handleObjCDesignatedInitializer(Sema &S, Decl *D, const AttributeList &Attr)
pool_iterator pool_end() const
std::string getNameAsString() const
Expr * IgnoreParenCasts() LLVM_READONLY
static void handleDependencyAttr(Sema &S, Scope *Scope, Decl *D, const AttributeList &Attr)
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
Def If non-NULL, and the type refers to some kind of declaration that can be completed (such as a C s...
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
Represents an ObjC class declaration.
static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isExtVectorType() const
void setInvalid(bool b=true) const
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)
static void handleLaunchBoundsAttr(Sema &S, Decl *D, const AttributeList &Attr)
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.
field_iterator field_end() const
IdentifierInfo * getAlias() const
static void handleNSConsumedAttr(Sema &S, Decl *D, const AttributeList &Attr)
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.
static bool isDeclDeprecated(Decl *D)
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)
QualType getPointeeType() const
bool isFunctionPointerType() const
void AddAlignValueAttr(SourceRange AttrRange, Decl *D, Expr *E, unsigned SpellingListIndex)
static void handlePtGuardedVarAttr(Sema &S, Decl *D, const AttributeList &Attr)
Exposes information about the current target.
static bool isValidSubjectOfNSReturnsRetainedAttribute(QualType type)
static DelayedDiagnostic makeAvailability(Sema::AvailabilityDiagnostic AD, SourceLocation Loc, const NamedDecl *D, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, StringRef Msg, bool ObjCPropertyAccess)
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)
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
static bool checkLaunchBoundsArgument(Sema &S, Expr *E, const CUDALaunchBoundsAttr &Attr, const unsigned Idx)
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.
SmallVector< Decl *, 2 > WeakTopLevelDecl
DLLImportAttr * mergeDLLImportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
static bool checkIBOutletCommon(Sema &S, Decl *D, const AttributeList &Attr)
static bool hasDeclarator(const Decl *D)
static void handleTestTypestateAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isCapabilityExpr(Sema &S, const Expr *Ex)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
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)
TranslationUnitDecl * getTranslationUnitDecl() const
static void handleCFUnknownTransferAttr(Sema &S, Decl *D, const AttributeList &Attr)
Defines the clang::Preprocessor interface.
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, VerifyICEDiagnoser &Diagnoser, bool AllowFold=true)
static bool typeHasCapability(Sema &S, QualType Ty)
const ParmVarDecl * getParamDecl(unsigned i) const
llvm::MapVector< IdentifierInfo *, WeakInfo > WeakUndeclaredIdentifiers
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
An abstract interface that should be implemented by listeners that want to be notified when an AST en...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
bool isObjCIdType() const
unsigned getUnwindWordWidth() const
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
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
static void handleAcquiredBeforeAttr(Sema &S, Decl *D, const AttributeList &Attr)
static bool isNSStringType(QualType T, ASTContext &Ctx)
SmallVector< ActiveTemplateInstantiation, 16 > ActiveTemplateInstantiations
List of active template instantiations.
DeclarationName getDeclName() 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.
static void handleDeprecatedAttr(Sema &S, Decl *D, const AttributeList &Attr)
unsigned getForbiddenTypeDiagnostic() const
static void handlePtGuardedByAttr(Sema &S, Decl *D, const AttributeList &Attr)
RecordDecl * getDefinition() const
static void handleDelayedForbiddenType(Sema &S, DelayedDiagnostic &diag, Decl *decl)
Handle a delayed forbidden-type diagnostic.
void setDeclContext(DeclContext *DC)
CallingConv
CallingConv - Specifies the calling convention that a function uses.
static void handleWeakImportAttr(Sema &S, Decl *D, const AttributeList &Attr)
This is a scope that corresponds to the parameters within a function prototype for a function declara...
static const RecordType * getRecordType(QualType QT)
Checks that the passed in QualType either is of RecordType or points to RecordType. Returns the relevant RecordType, null if it does not exit.
static bool checkAttrMutualExclusion(Sema &S, Decl *D, const AttributeList &Attr)
Diagnose mutually exclusive attributes when present on a given declaration. Returns true if diagnosed...
static bool checkAttributeNumArgs(Sema &S, const AttributeList &Attr, unsigned Num)
Check if the attribute has exactly as many args as Num. May output an error.
SourceLocation getLocStart() const LLVM_READONLY
static void handleTryAcquireCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
ClassTemplateDecl * getDescribedClassTemplate() const
Retrieves the class template that is described by this class declaration.
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. This may omit quali...
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. This index is used by an attribute ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
static bool checkAcquireOrderAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
static FormatAttrKind getFormatAttrKind(StringRef Format)
bool isIntegralOrEnumerationType() const
Determine whether this type is an integral or enumeration type.
const ParsedType & getMatchingCType() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
unsigned getNumParams() const
void NoteAllOverloadCandidates(Expr *E, QualType DestType=QualType())
static bool handleCommonAttributeFeatures(Sema &S, Scope *scope, Decl *D, const AttributeList &Attr)
static bool isForbiddenTypeAllowed(Sema &S, Decl *decl)
Is the given declaration allowed to use a forbidden type?
SourceLocation getEllipsisLoc() const
DLLExportAttr * mergeDLLExportAttr(Decl *D, SourceRange Range, unsigned AttrSpellingListIndex)
void setUsed(bool Used=true)
bool isComplexType() const
bool isBuiltinType() const
isBuiltinType - returns true if the type is a builtin type.
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
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
IdentifierTable & getIdentifierTable()
const NamedDecl * getDeprecationDecl() const
static void handleLockReturnedAttr(Sema &S, Decl *D, const AttributeList &Attr)
static void handleAvailabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
Represents a static or instance method of a struct/union/class.
bool shouldDelayDiagnostics()
Determines whether diagnostics should be delayed.
static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D, const AttributeList &Attr)
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)
static void handleBlocksAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isIntegerConstantExpr(llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
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)
static void handleNSReturnsRetainedAttr(Sema &S, Decl *D, const AttributeList &Attr)
StringRef getDeprecationMessage() const
static unsigned getNumAttributeArgs(const AttributeList &Attr)
ThreadStorageClassSpecifier getTSCSpec() const
Represents one property declaration in an Objective-C interface.
unsigned getForbiddenTypeArgument() const
QualType getReturnType() const
SourceLocation getBegin() const
bool isTypeDependent() const
bool isArgExpr(unsigned Arg) const
lookup_result lookup(DeclarationName Name) const
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)
bool isVectorType() 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
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)
static void handleAMDGPUNumVGPRAttr(Sema &S, Decl *D, const AttributeList &Attr)
SourceLocation getExprLoc() const LLVM_READONLY
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
Base class for declarations which introduce a typedef-name.
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. If not emit an error and return false...
bool diagnoseLangOpts(class Sema &S) const
void checkUnusedDeclAttributes(Declarator &D)
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
static void handleAMDGPUNumSGPRAttr(Sema &S, Decl *D, const AttributeList &Attr)
void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, WeakInfo &W)
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)
unsigned getCharWidth() const
bool checkMSInheritanceAttrOnDefinition(CXXRecordDecl *RD, SourceRange Range, bool BestCase, MSInheritanceAttr::Spelling SemanticSpelling)
static void handleObjCBridgeRelatedAttr(Sema &S, Scope *Sc, Decl *D, const AttributeList &Attr)
SectionAttr * mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex)
Expr * getArgAsExpr(unsigned Arg) const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
unsigned short getMaxTLSAlign() const
Return the maximum alignment (in bits) of a TLS variable.
StringRef getString() const
const FunctionType * getFunctionType(bool BlocksToo=true) const
Looks through the Decl's underlying type to extract a FunctionType when possible. Will return null if...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
VisibilityAttr * mergeVisibilityAttr(Decl *D, SourceRange Range, VisibilityAttr::VisibilityType Vis, unsigned AttrSpellingListIndex)
static void handleIBOutletCollection(Sema &S, Decl *D, const AttributeList &Attr)
static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr, bool isTypeVisibility)
NamedDecl * getCurFunctionOrMethodDecl()
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
QualType getNonReferenceType() const
const Expr * getMessageExpr() const
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 handleObjCNSObject(Sema &S, Decl *D, const AttributeList &Attr)
IdentifierInfo * getName() const
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 isFunctionOrMethod(const Decl *D)
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
DeclContext * getRedeclContext()
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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)
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)
bool CheckRegparmAttr(const AttributeList &attr, unsigned &value)
const ObjCPropertyDecl * getObjCProperty() const
bool isCXX11Attribute() const
static bool checkAttributeAtMostNumArgs(Sema &S, const AttributeList &Attr, unsigned Num)
Check if the attribute has at most as many args as Num. May output an error.
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).
bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, UnexpandedParameterPackContext UPPC)
If the given type contains an unexpanded parameter pack, diagnose the error.
static bool isInstanceMethod(const Decl *D)
bool isCARCBridgableType() const
Determine whether the given type T is a "bridgeable" C type.
void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD)
virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target. A calling convention can eithe...
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)
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
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
void AddLaunchBoundsAttr(SourceRange AttrRange, Decl *D, Expr *MaxThreads, Expr *MinBlocks, unsigned SpellingListIndex)
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...
static void handleFormatArgAttr(Sema &S, Decl *D, const AttributeList &Attr)
static SourceRange getFunctionOrMethodResultSourceRange(const Decl *D)
static void handleAssertCapabilityAttr(Sema &S, Decl *D, const AttributeList &Attr)
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. May output an error.
Defines the clang::TargetInfo interface.
static void handleObjCMethodFamilyAttr(Sema &S, Decl *decl, const AttributeList &Attr)
bool checkSectionName(SourceLocation LiteralLoc, StringRef Str)
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx)
static void handleGNUInlineAttr(Sema &S, Decl *D, const AttributeList &Attr)
AvailabilityAttr * mergeAvailabilityAttr(NamedDecl *D, SourceRange Range, IdentifierInfo *Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool IsUnavailable, StringRef Message, bool Override, unsigned AttrSpellingListIndex)
Attribute merging methods. Return true if a new attribute was added.
bool isDeclspecAttribute() const
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
A collection of diagnostics which were delayed.
static bool isValidSubjectOfCFAttribute(Sema &S, QualType type)
const DeclaratorChunk & getTypeObject(unsigned i) const
static bool checkLockFunAttrCommon(Sema &S, Decl *D, const AttributeList &Attr, SmallVectorImpl< Expr * > &Args)
static bool isPotentialConstantExprUnevaluated(Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
AttributeList * getNext() const
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
void setLexicalDeclContext(DeclContext *DC)
AlwaysInlineAttr * mergeAlwaysInlineAttr(Decl *D, SourceRange Range, IdentifierInfo *Ident, unsigned AttrSpellingListIndex)
static void handleTLSModelAttr(Sema &S, Decl *D, const AttributeList &Attr)
bool isSignedIntegerType() const
static bool checkFunctionOrMethodParameterIndex(Sema &S, const Decl *D, const AttributeList &Attr, unsigned AttrArgNum, const Expr *IdxExpr, uint64_t &Idx)
Check if IdxExpr is a valid parameter index for a function or instance method D. May output an error...
static bool isFunctionOrMethodVariadic(const Decl *D)
bool isNull() const
isNull - 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.
void setHasDesignatedInitializers()
void EmitAvailabilityWarning(AvailabilityDiagnostic AD, NamedDecl *D, StringRef Message, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass, const ObjCPropertyDecl *ObjCProperty, bool ObjCPropertyAccess)
bool isIntegralType(ASTContext &Ctx) const
Determine whether this type is an integral type.
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)
Attr - This represents one attribute.
ParsedAttributes & getAttributes()
bool isIntegerType() const
bool hasLocalStorage() const
SmallVectorImpl< DelayedDiagnostic >::const_iterator pool_iterator
bool isDeprecated(std::string *Message=nullptr) const
Determine whether this declaration is marked 'deprecated'.
const DeclSpec & getDeclSpec() const
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