28#include "llvm/ADT/DenseMap.h"
29#include "llvm/ADT/DenseSet.h"
61 assert(resultClass &&
"unexpected object type!");
66 if (receiverTypeIfCall.
isNull() &&
76 if (receiverTypeIfCall.
isNull())
83 if (!receiverClass)
return false;
86 assert(receiverClass &&
"method not associated with a class!");
102 UnavailableAttr::IR_ARCInitReturnsUnrelated, loc));
107 Diag(loc, diag::err_arc_init_method_unrelated_result_type);
116 if (OldD->
hasAttr<NoEscapeAttr>() && !NewD->
hasAttr<NoEscapeAttr>()) {
117 S.
Diag(NewD->
getLocation(), diag::warn_overriding_method_missing_noescape);
153 CurrentClass = Cat->getClassInterface();
154 else if (
ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(DC))
155 CurrentClass = Impl->getClassInterface();
157 = dyn_cast<ObjCCategoryImplDecl>(DC))
158 CurrentClass = CatImpl->getClassInterface();
163 diag::warn_related_result_type_compatibility_class)
169 diag::warn_related_result_type_compatibility_protocol)
176 diag::note_related_result_type_family)
181 diag::note_related_result_type_overridden);
184 if ((NewMethod->
hasAttr<NSReturnsRetainedAttr>() !=
185 Overridden->
hasAttr<NSReturnsRetainedAttr>())) {
188 ? diag::err_nsreturns_retained_attribute_mismatch
189 : diag::warn_nsreturns_retained_attribute_mismatch)
193 if ((NewMethod->
hasAttr<NSReturnsNotRetainedAttr>() !=
194 Overridden->
hasAttr<NSReturnsNotRetainedAttr>())) {
197 ? diag::err_nsreturns_retained_attribute_mismatch
198 : diag::warn_nsreturns_retained_attribute_mismatch)
207 ni != ne && oi != oe; ++ni, ++oi) {
210 if (newDecl->
hasAttr<NSConsumedAttr>() !=
211 oldDecl->
hasAttr<NSConsumedAttr>()) {
214 ? diag::err_nsconsumed_attribute_mismatch
215 : diag::warn_nsconsumed_attribute_mismatch);
263 if (method->
hasAttr<NSReturnsRetainedAttr>())
271 if (method->
hasAttr<NSReturnsRetainedAttr>() ||
272 method->
hasAttr<NSReturnsNotRetainedAttr>() ||
273 method->
hasAttr<NSReturnsAutoreleasedAttr>())
286 bool IsCategory =
false;
287 StringRef RealizedPlatform;
289 nullptr, VersionTuple(),
292 if (isa<ObjCMethodDecl>(ND)) {
295 if (RealizedPlatform.empty())
299 if (RealizedPlatform.endswith(
"_app_extension"))
301 S.
Diag(ImplLoc, diag::warn_unavailable_def);
306 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
307 if (!CD->getClassInterface()->isDeprecated())
309 ND = CD->getClassInterface();
314 S.
Diag(ImplLoc, diag::warn_deprecated_def)
315 << (isa<ObjCMethodDecl>(ND)
317 : isa<ObjCCategoryDecl>(ND) || IsCategory ? 2
319 if (isa<ObjCMethodDecl>(ND))
324 << (isa<ObjCCategoryDecl>(ND) ?
"category" :
"class");
377 diag::err_func_def_incomplete_result))
399 if (!Param->isInvalidDecl() &&
402 Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
405 if (Param->getIdentifier())
448 ImplDeclOfMethodDecl = OID->getImplementation();
449 else if (
ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ContDeclOfMethodDecl)) {
450 if (CD->IsClassExtension()) {
452 ImplDeclOfMethodDecl = OID->getImplementation();
454 ImplDeclOfMethodDecl = CD->getImplementation();
458 if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
466 IC->getSuperClass() !=
nullptr;
467 }
else if (IC->hasDesignatedInitializers()) {
493 (SuperMethod && SuperMethod->
hasAttr<ObjCRequiresSuperAttr>());
506 ObjCInterfaceValidatorCCC() : CurrentIDecl(nullptr) {}
508 : CurrentIDecl(IDecl) {}
510 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
515 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
516 return std::make_unique<ObjCInterfaceValidatorCCC>(*
this);
528 unsigned NumProtoRefs,
533 for (
unsigned i = 0; i < NumProtoRefs; ++i) {
558 ObjCInterfaceValidatorCCC CCC(IDecl);
563 << SuperName << ClassName);
569 Diag(SuperLoc, diag::err_recursive_superclass)
570 << SuperName << ClassName <<
SourceRange(AtInterfaceLoc, ClassLoc);
574 dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
578 if (SuperClassDecl) {
583 if (PrevDecl && !SuperClassDecl) {
587 dyn_cast_or_null<TypedefNameDecl>(PrevDecl)) {
588 QualType T = TDecl->getUnderlyingType();
591 SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl);
608 if (!SuperClassDecl) {
609 Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName;
614 if (!isa_and_nonnull<TypedefNameDecl>(PrevDecl)) {
616 Diag(SuperLoc, diag::err_undef_superclass)
617 << SuperName << ClassName <<
SourceRange(AtInterfaceLoc, ClassLoc);
620 diag::err_forward_superclass,
624 SuperClassDecl =
nullptr;
629 if (SuperClassType.
isNull()) {
630 assert(!SuperClassDecl &&
"Failed to set SuperClassType?");
636 if (!SuperTypeArgs.empty()) {
644 SuperTypeArgsRange.
getEnd(),
656 if (!SuperClassTInfo) {
676 if (parsedTypeBound) {
687 diag::err_objc_type_param_bound_missing_pointer)
688 << typeBound << paramName
707 diag::err_objc_type_param_bound_nonobject)
708 << typeBound << paramName;
711 typeBoundInfo =
nullptr;
720 bool diagnosed =
false;
724 rangeToRemove =
attr.getLocalSourceRange();
725 if (
attr.getTypePtr()->getImmediateNullability()) {
727 diag::err_objc_type_param_bound_explicit_nullability)
728 << paramName << typeBound
738 diag::err_objc_type_param_bound_qualified)
739 << paramName << typeBound
749 if (!quals.
empty()) {
759 if (!typeBoundInfo) {
766 index, paramLoc, paramName, colonLoc,
778 typeParamsIn.size());
784 llvm::SmallDenseMap<IdentifierInfo *, ObjCTypeParamDecl *> knownParams;
785 for (
auto *typeParam : typeParams) {
786 auto known = knownParams.find(typeParam->getIdentifier());
787 if (known != knownParams.end()) {
788 Diag(typeParam->getLocation(), diag::err_objc_type_param_redecl)
789 << typeParam->getIdentifier()
792 typeParam->setInvalidDecl();
794 knownParams.insert(std::make_pair(typeParam->getIdentifier(), typeParam));
806 for (
auto *typeParam : *typeParamList) {
807 if (!typeParam->isInvalidDecl()) {
808 S->RemoveDecl(typeParam);
817 enum class TypeParamListContext {
831 TypeParamListContext newContext) {
833 if (prevTypeParams->
size() != newTypeParams->
size()) {
835 if (newTypeParams->
size() > prevTypeParams->
size()) {
841 S.
Diag(diagLoc, diag::err_objc_type_param_arity_mismatch)
842 <<
static_cast<unsigned>(newContext)
843 << (newTypeParams->
size() > prevTypeParams->
size())
844 << prevTypeParams->
size()
845 << newTypeParams->
size();
851 for (
unsigned i = 0, n = prevTypeParams->
size(); i != n; ++i) {
858 newContext != TypeParamListContext::Definition) {
877 auto diag = S.
Diag(diagLoc,
878 diag::err_objc_type_param_variance_conflict)
879 <<
static_cast<unsigned>(newTypeParam->
getVariance())
881 <<
static_cast<unsigned>(prevTypeParam->
getVariance())
890 StringRef newVarianceStr
897 (newVarianceStr +
" ").str());
924 S.
Diag(newBoundRange.
getBegin(), diag::err_objc_type_param_bound_conflict)
948 if (newContext == TypeParamListContext::ForwardDeclaration ||
949 newContext == TypeParamListContext::Definition) {
957 diag::err_objc_type_param_bound_missing)
960 << (newContext == TypeParamListContext::ForwardDeclaration)
979 Decl *
const *ProtoRefs,
unsigned NumProtoRefs,
982 assert(ClassName &&
"Missing class identifier");
989 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
990 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
1017 if (typeParamList) {
1021 TypeParamListContext::Definition)) {
1022 typeParamList =
nullptr;
1025 Diag(ClassLoc, diag::err_objc_parameterized_forward_class_first)
1027 Diag(prevTypeParamList->getLAngleLoc(), diag::note_previous_decl)
1032 for (
auto *typeParam : *prevTypeParamList) {
1033 clonedTypeParams.push_back(
1037 typeParam->getVariance(),
1039 typeParam->getIndex(),
1041 typeParam->getIdentifier(),
1056 typeParamList, PrevIDecl, ClassLoc);
1062 SkipBody->
New = IDecl;
1065 Diag(AtInterfaceLoc, diag::err_duplicate_class_def)
1067 Diag(Def->getLocation(), diag::note_previous_definition);
1094 ClassName, ClassLoc,
1095 SuperName, SuperLoc, SuperTypeArgs,
1096 SuperTypeArgsRange);
1104 NumProtoRefs, ProtoLocs);
1129 if (
const TypedefNameDecl *TDecl = dyn_cast_or_null<TypedefNameDecl>(IDecl)) {
1130 QualType T = TDecl->getUnderlyingType();
1133 ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end());
1138 ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc);
1155 Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
1164 dyn_cast_or_null<TypedefNameDecl>(CDeclU)) {
1165 QualType T = TDecl->getUnderlyingType();
1168 ClassName = IDecl->getIdentifier();
1177 Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
1200 E = PList.
end(); I != E; ++I) {
1203 if (PDecl->getIdentifier() == PName) {
1204 Diag(Ploc, diag::err_protocol_has_circular_dependency);
1205 Diag(PrevLoc, diag::note_previous_definition);
1209 if (!PDecl->hasDefinition())
1213 PDecl->getLocation(), PDecl->getReferencedProtocols()))
1227 assert(ProtocolName &&
"Missing protocol identifier");
1237 ProtocolLoc, AtProtoInterfaceLoc,
1242 SkipBody->
New = PDecl;
1246 Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName;
1247 Diag(Def->getLocation(), diag::note_previous_definition);
1262 ProtocolName, ProtocolLoc, PrevDecl->
getLocation(), PList);
1267 ProtocolLoc, AtProtoInterfaceLoc,
1281 if (!err && NumProtoRefs ) {
1284 NumProtoRefs, ProtoLocs);
1298 UndefinedProtocol = PDecl;
1304 UndefinedProtocol = PI;
1330 Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first;
1339 if (!ForObjCContainer) {
1348 if (WarnOnDeclarations &&
1350 Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first;
1351 Diag(UndefinedProtocol->
getLocation(), diag::note_protocol_decl_undefined)
1352 << UndefinedProtocol;
1354 Protocols.push_back(PDecl);
1361class ObjCTypeArgOrProtocolValidatorCCC final
1366 ObjCTypeArgOrProtocolValidatorCCC(
ASTContext &context,
1368 : Context(context), LookupKind(lookupKind) { }
1370 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
1384 if (isa<RecordDecl>(typeDecl) && !Context.
getLangOpts().CPlusPlus)
1390 if (
type->isObjCObjectPointerType() ||
1391 type->isBlockPointerType() ||
1392 type->isDependentType() ||
1393 type->isObjCObjectType())
1410 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1411 return std::make_unique<ObjCTypeArgOrProtocolValidatorCCC>(*
this);
1420 bool SelectProtocolFirst) {
1421 Diag(TypeArgLoc, diag::err_objc_type_args_and_protocols)
1422 << SelectProtocolFirst << TypeArgId << ProtocolId
1439 bool warnOnIncompleteProtocols) {
1442 unsigned numProtocolsResolved = 0;
1443 auto resolvedAsProtocols = [&] {
1444 assert(numProtocolsResolved == identifiers.size() &&
"Unresolved protocols");
1451 bool allAreTypeNames =
false;
1455 baseClass = objcObjectType->getInterface();
1458 if (typeParams->size() == numProtocolsResolved) {
1460 allAreTypeNames =
true;
1467 for (
unsigned i = 0, n = protocols.size(); i != n; ++i) {
1472 if (!warnOnIncompleteProtocols) {
1484 if (warnOnIncompleteProtocols &&
1486 Diag(identifierLocs[i], diag::warn_undef_protocolref)
1495 if (allAreTypeNames) {
1498 if (isa<ObjCInterfaceDecl>(
decl)) {
1500 firstClassNameLoc = identifierLocs[i];
1501 }
else if (!isa<TypeDecl>(
decl)) {
1503 allAreTypeNames =
false;
1506 allAreTypeNames =
false;
1515 if (allAreTypeNames && firstClassNameLoc.
isValid()) {
1518 bool allProtocolsDeclared =
true;
1519 for (
auto *proto : protocols) {
1521 allProtocolsDeclared =
false;
1526 if (allProtocolsDeclared) {
1527 Diag(firstClassNameLoc, diag::warn_objc_redundant_qualified_class_type)
1534 protocolLAngleLoc = lAngleLoc;
1535 protocolRAngleLoc = rAngleLoc;
1536 assert(protocols.size() == identifierLocs.size());
1540 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1542 protocols.push_back(proto);
1544 ++numProtocolsResolved;
1548 if (numProtocolsResolved == identifiers.size())
1549 return resolvedAsProtocols();
1555 typedef llvm::PointerUnion<TypeDecl *, ObjCInterfaceDecl *> TypeOrClassDecl;
1557 unsigned numTypeDeclsResolved = 0;
1558 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1562 typeDecls.push_back(TypeOrClassDecl());
1566 if (
auto typeDecl = dyn_cast<TypeDecl>(
decl)) {
1567 typeDecls.push_back(typeDecl);
1568 ++numTypeDeclsResolved;
1572 if (
auto objcClass = dyn_cast<ObjCInterfaceDecl>(
decl)) {
1573 typeDecls.push_back(objcClass);
1574 ++numTypeDeclsResolved;
1578 typeDecls.push_back(TypeOrClassDecl());
1585 auto resolveTypeReference = [&](TypeOrClassDecl typeDecl,
SourceLocation loc)
1589 const char* prevSpec;
1592 if (
auto *actualTypeDecl = typeDecl.dyn_cast<
TypeDecl *>())
1620 Diag(loc, diag::err_objc_type_arg_missing_star)
1631 auto resolvedAsTypeDecls = [&] {
1635 assert(numTypeDeclsResolved == identifiers.size() &&
"Unresolved type decl");
1637 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1639 TypeResult type = resolveTypeReference(typeDecls[i], identifierLocs[i]);
1640 if (!
type.isUsable()) {
1645 typeArgs.push_back(
type.get());
1648 typeArgsLAngleLoc = lAngleLoc;
1649 typeArgsRAngleLoc = rAngleLoc;
1654 if (numTypeDeclsResolved == identifiers.size())
1655 return resolvedAsTypeDecls();
1661 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1664 if (protocols[i] || typeDecls[i]) {
1670 if (protocols[i] && typeDecls[i])
1693 identifiers[i], identifierLocs[i],
1694 protocols[i] !=
nullptr);
1702 ObjCTypeArgOrProtocolValidatorCCC CCC(
Context, lookupKind);
1710 PDiag(diag::err_undeclared_protocol_suggest)
1713 protocols[i] = proto;
1714 ++numProtocolsResolved;
1721 PDiag(diag::err_unknown_typename_suggest)
1724 typeDecls[i] = typeDecl;
1725 ++numTypeDeclsResolved;
1732 PDiag(diag::err_unknown_type_or_class_name_suggest)
1733 << identifiers[i] <<
true);
1735 typeDecls[i] = objcClass;
1736 ++numTypeDeclsResolved;
1742 Diag(identifierLocs[i],
1743 (lookupKind ==
LookupAnyName ? diag::err_objc_type_arg_missing
1745 : diag::err_unknown_typename))
1754 if (numProtocolsResolved == identifiers.size())
1755 return resolvedAsProtocols();
1758 assert(numTypeDeclsResolved == identifiers.size() &&
"Not all types?");
1759 return resolvedAsTypeDecls();
1770 llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
1771 for (
auto *MD : ID->methods())
1772 MethodMap[MD->getSelector()] = MD;
1774 if (MethodMap.empty())
1776 for (
const auto *Method : CAT->
methods()) {
1777 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
1781 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
1782 << Method->getDeclName();
1800 IdentPair.second, AtProtocolLoc,
1812 DeclsInGroup.push_back(PDecl);
1822 Decl *
const *ProtoRefs,
unsigned NumProtoRefs,
1832 diag::err_category_forward_interface,
1833 CategoryName ==
nullptr)) {
1838 ClassLoc, CategoryLoc, CategoryName,
1839 IDecl, typeParamList);
1844 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1850 Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName;
1852 diag::note_implementation_declared);
1860 Diag(CategoryLoc, diag::warn_dup_category_def)
1861 << ClassName << CategoryName;
1862 Diag(
Previous->getLocation(), diag::note_previous_definition);
1867 if (typeParamList) {
1871 ? TypeParamListContext::Category
1872 : TypeParamListContext::Extension))
1873 typeParamList =
nullptr;
1876 diag::err_objc_parameterized_category_nonclass)
1877 << (CategoryName !=
nullptr)
1881 typeParamList =
nullptr;
1886 ClassLoc, CategoryLoc, CategoryName, IDecl,
1899 NumProtoRefs, ProtoLocs);
1937 ClassLoc, AtCatImplLoc, CatLoc);
1940 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1943 diag::err_undef_interface)) {
1955 if (IDecl && IDecl->
hasAttr<ObjCRuntimeVisibleAttr>()) {
1956 Diag(ClassLoc, diag::err_objc_runtime_visible_category)
1963 Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName
1966 diag::note_previous_definition);
1991 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
1992 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
1994 }
else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
1998 diag::warn_undef_interface);
2002 ObjCInterfaceValidatorCCC CCC{};
2011 PDiag(diag::warn_undef_interface_suggest) << ClassName,
2014 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
2020 if (SuperClassname) {
2024 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
2025 Diag(SuperClassLoc, diag::err_redefinition_different_kind)
2029 SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
2033 Diag(SuperClassLoc, diag::err_undef_superclass)
2034 << SuperClassname << ClassName;
2038 Diag(SuperClassLoc, diag::err_conflicting_super_class)
2077 ClassLoc, AtClassImplLoc, SuperClassLoc);
2090 Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
2092 diag::note_previous_definition);
2106 Diag(ClassLoc, diag::err_objc_runtime_visible_subclass)
2118 DeclsInGroup.reserve(Decls.size() + 1);
2120 for (
unsigned i = 0, e = Decls.size(); i != e; ++i) {
2121 Decl *Dcl = Decls[i];
2126 DeclsInGroup.push_back(Dcl);
2129 DeclsInGroup.push_back(ObjCImpDecl);
2137 assert(ImpDecl &&
"missing implementation decl");
2147 for (
unsigned i = 0, e = numIvars; i != e; ++i) {
2164 assert(ivars &&
"missing @implementation ivars");
2168 for (
unsigned i = 0; i < numIvars; i++) {
2173 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2181 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
2198 for (; numIvars > 0 && IVI != IVE; ++IVI) {
2201 assert (ImplIvar &&
"missing implementation ivar");
2202 assert (ClsIvar &&
"missing class ivar");
2214 diag::err_conflicting_ivar_bitwidth)
2217 diag::note_previous_definition);
2229 Diag(ivars[j]->getLocation(), diag::err_inconsistent_ivar_count);
2230 else if (IVI != IVE)
2231 Diag(IVI->getLocation(), diag::err_inconsistent_ivar_count);
2254 std::string FixItStr;
2255 llvm::raw_string_ostream Out(FixItStr);
2266 S.
Diag(MethodLoc, diag::note_method_declared_at) << method;
2342 (y &
~Decl::OBJC_TQ_CSNullability);
2348 bool IsProtocolMethodDecl,
2349 bool IsOverridingMode,
2351 if (IsProtocolMethodDecl &&
2357 ? diag::warn_conflicting_overriding_ret_type_modifiers
2358 : diag::warn_conflicting_ret_type_modifiers))
2367 if (Warn && IsOverridingMode &&
2375 diag::warn_conflicting_nullability_attr_overriding_ret_types)
2392 IsOverridingMode ? diag::warn_conflicting_overriding_ret_types
2393 : diag::warn_conflicting_ret_types;
2409 IsOverridingMode ? diag::warn_non_covariant_overriding_ret_types
2410 : diag::warn_non_covariant_ret_types;
2419 ? diag::note_previous_declaration
2420 : diag::note_previous_definition)
2430 bool IsProtocolMethodDecl,
2431 bool IsOverridingMode,
2433 if (IsProtocolMethodDecl &&
2437 if (IsOverridingMode)
2439 diag::warn_conflicting_overriding_param_modifiers)
2443 diag::warn_conflicting_param_modifiers)
2455 if (Warn && IsOverridingMode &&
2459 diag::warn_conflicting_nullability_attr_overriding_param_types)
2474 IsOverridingMode ? diag::warn_conflicting_overriding_param_types
2475 : diag::warn_conflicting_param_types;
2491 IsOverridingMode ? diag::warn_non_contravariant_overriding_param_types
2492 : diag::warn_non_contravariant_param_types;
2498 << MethodImpl->
getDeclName() << IfaceTy << ImplTy;
2500 (IsOverridingMode ? diag::note_previous_declaration
2501 : diag::note_previous_definition))
2512 if (implFamily == declFamily)
return false;
2524 unsigned errorID = diag::err_arc_lost_method_convention;
2525 unsigned noteID = diag::note_arc_lost_method_convention;
2528 family = implFamily;
2529 errorID = diag::err_arc_gained_method_convention;
2530 noteID = diag::note_arc_gained_method_convention;
2534 enum FamilySelector {
2535 F_alloc, F_copy, F_mutableCopy = F_copy, F_init, F_new
2537 FamilySelector familySelector = FamilySelector();
2540 case OMF_None: llvm_unreachable(
"logic error, no method convention");
2554 case OMF_init: familySelector = F_init;
break;
2555 case OMF_alloc: familySelector = F_alloc;
break;
2556 case OMF_copy: familySelector = F_copy;
break;
2558 case OMF_new: familySelector = F_new;
break;
2561 enum ReasonSelector { R_NonObjectReturn, R_UnrelatedReturn };
2562 ReasonSelector reasonSelector;
2567 reasonSelector = R_UnrelatedReturn;
2569 reasonSelector = R_NonObjectReturn;
2573 S.
Diag(
decl->getLocation(), noteID) <<
int(familySelector) <<
int(reasonSelector);
2580 bool IsProtocolMethodDecl) {
2586 IsProtocolMethodDecl,
false,
2592 IM != EM && IF != EF; ++IM, ++IF) {
2594 IsProtocolMethodDecl,
false,
true);
2599 diag::warn_conflicting_variadic);
2606 bool IsProtocolMethodDecl) {
2609 IsProtocolMethodDecl,
true,
2615 IM != EM && IF != EF; ++IM, ++IF) {
2617 IsProtocolMethodDecl,
true,
true);
2622 diag::warn_conflicting_overriding_variadic);
2631 bool IsProtocolMethodDecl) {
2639 if (MethodDecl->
hasAttr<UnavailableAttr>() ||
2640 MethodDecl->
hasAttr<DeprecatedAttr>())
2644 IsProtocolMethodDecl,
false,
false);
2649 IM != EM && IF != EF; ++IM, ++IF) {
2652 IsProtocolMethodDecl,
false,
false);
2664 diag::warn_category_method_impl_match);
2681 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>())
2683 for (
const auto *PI : PDecl->
protocols())
2709 : dyn_cast<ObjCInterfaceDecl>(CDecl);
2710 assert (IDecl &&
"CheckProtocolMethodDefs - IDecl is null");
2726 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>()) {
2727 if (!ProtocolsExplictImpl) {
2749 if (InsMap.count(fISelector))
2769 !method->isPropertyAccessor() &&
2770 !InsMap.count(method->getSelector()) &&
2790 if (
C || MethodInClass->isPropertyAccessor())
2792 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2801 !ClsMap.count(method->getSelector()) &&
2814 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2823 ProtocolsExplictImpl);
2835 bool &IncompleteImpl,
2836 bool ImmediateClass,
2837 bool WarnCategoryMethodImpl) {
2841 if (!InsMapSeen.insert(I->getSelector()).second)
2843 if (!I->isPropertyAccessor() &&
2844 !InsMap.count(I->getSelector())) {
2847 diag::warn_undef_method_impl);
2853 "Expected to find the method through lookup as well");
2855 if (ImpMethodDecl) {
2859 if (!WarnCategoryMethodImpl)
2861 isa<ObjCProtocolDecl>(CDecl));
2862 else if (!I->isPropertyAccessor())
2871 if (!ClsMapSeen.insert(I->getSelector()).second)
2873 if (!I->isPropertyAccessor() &&
2874 !ClsMap.count(I->getSelector())) {
2877 diag::warn_undef_method_impl);
2882 "Expected to find the method through lookup as well");
2884 if (ImpMethodDecl) {
2888 if (!WarnCategoryMethodImpl)
2890 isa<ObjCProtocolDecl>(CDecl));
2891 else if (!I->isPropertyAccessor())
2900 for (
auto *PI : PD->protocols())
2902 IMPDecl, PI, IncompleteImpl,
false,
2903 WarnCategoryMethodImpl);
2910 if (!WarnCategoryMethodImpl) {
2911 for (
auto *Cat : I->visible_categories())
2913 IMPDecl, Cat, IncompleteImpl,
2914 ImmediateClass && Cat->IsClassExtension(),
2915 WarnCategoryMethodImpl);
2918 for (
auto *Ext : I->visible_extensions())
2920 IMPDecl, Ext, IncompleteImpl,
false,
2921 WarnCategoryMethodImpl);
2925 for (
auto *PI : I->all_referenced_protocols())
2927 IMPDecl, PI, IncompleteImpl,
false,
2928 WarnCategoryMethodImpl);
2932 if (!WarnCategoryMethodImpl && I->getSuperClass())
2935 I->getSuperClass(), IncompleteImpl,
false);
2966 if (SuperIDecl && SuperIDecl->
lookupMethod(Sel,
false))
2970 if (InsMap.empty() && ClsMap.empty())
2974 bool IncompleteImpl =
false;
2977 IncompleteImpl,
false,
2983 bool IncompleteImpl) {
2988 InsMap.insert(I->getSelector());
2996 const auto *
P = PImpl->getPropertyDecl();
2999 InsMap.insert(
P->getGetterName());
3000 if (!
P->getSetterName().isNull())
3001 InsMap.insert(
P->getSetterName());
3008 bool SynthesizeProperties =
LangOpts.ObjCDefaultSynthProperties &&
3010 !IDecl->isObjCRequiresPropertyDefs();
3019 ClsMap.insert(I->getSelector());
3026 IncompleteImpl,
true);
3031 dyn_cast<ObjCCategoryImplDecl>(IMPDecl))
3042 for (
auto *PI : I->all_referenced_protocols())
3044 ClsMap, I, ExplicitImplProtocols);
3048 if (!
C->IsClassExtension()) {
3049 for (
auto *
P :
C->protocols())
3051 ClsMap, CDecl, ExplicitImplProtocols);
3056 llvm_unreachable(
"invalid ObjCContainerDecl type.");
3066 for (
unsigned i = 0; i != NumElts; ++i) {
3071 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
3081 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
3089 Diag(AtClassLoc, diag::warn_forward_class_redefinition)
3099 = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
3121 if (PrevIDecl && TypeParams) {
3125 *
this, PrevTypeParams, TypeParams,
3126 TypeParamListContext::ForwardDeclaration)) {
3127 TypeParams =
nullptr;
3131 Diag(IdentLocs[i], diag::err_objc_parameterized_forward_class)
3134 Diag(Def->getLocation(), diag::note_defined_here)
3137 TypeParams =
nullptr;
3143 ClassName, TypeParams, PrevIDecl,
3152 DeclsInGroup.push_back(IDecl);
3160 const Type *left,
const Type *right);
3169 if (left == right)
return true;
3192 if (isa<VectorType>(left))
return isa<VectorType>(right);
3193 if (isa<VectorType>(right))
return false;
3216 return (leftSK == rightSK);
3222 assert(lt && rt && lt != rt);
3224 if (!isa<RecordType>(lt) || !isa<RecordType>(rt))
return false;
3225 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3226 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3232 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3233 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3248 for (; li != le && ri != re; ++li, ++ri) {
3249 if (!
matchTypes(Context, strategy, li->getType(), ri->getType()))
3252 return (li == le && ri == re);
3273 (left->
hasAttr<NSReturnsRetainedAttr>()
3274 != right->
hasAttr<NSReturnsRetainedAttr>() ||
3275 left->
hasAttr<NSConsumesSelfAttr>()
3276 != right->
hasAttr<NSConsumesSelfAttr>()))
3283 for (; li != le && ri != re; ++li, ++ri) {
3284 assert(ri != right->
param_end() &&
"Param mismatch");
3291 lparm->
hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3299 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3300 auto *MethodInListProtocol =
3304 if ((MethodProtocol && !MethodInListProtocol) ||
3305 (!MethodProtocol && MethodInListProtocol))
3308 if (MethodProtocol && MethodInListProtocol)
3314 return MethodInterface == MethodInListInterface;
3323 if (!CD->IsClassExtension() && List->getBits() < 2)
3324 List->setBits(List->getBits() + 1);
3327 if (List->getMethod() ==
nullptr) {
3328 List->setMethod(Method);
3329 List->setNext(
nullptr);
3337 for (; List;
Previous = List, List = List->getNext()) {
3354 if (!SameDeclaration ||
3360 List->setHasMoreThanOneDecl(
true);
3365 !ListWithSameDeclaration && !List->getMethod()->isDeprecated())
3366 ListWithSameDeclaration = List;
3369 !ListWithSameDeclaration &&
3371 ListWithSameDeclaration = List;
3385 List->setHasMoreThanOneDecl(
true);
3392 List->setMethod(Method);
3398 List->setMethod(Method);
3409 if (ListWithSameDeclaration) {
3412 ListWithSameDeclaration->
setMethod(Method);
3413 ListWithSameDeclaration->
setNext(List);
3423 assert(ExternalSource &&
"We need an external AST source");
3424 ExternalSource->ReadMethodPool(Sel);
3428 if (!ExternalSource)
3430 ExternalSource->updateOutOfDateSelector(Sel);
3433void Sema::AddMethodToGlobalPool(
ObjCMethodDecl *Method,
bool impl,
3451 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3488 assert(BoundInterface &&
"unexpected object type!");
3492 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3493 if (MethodProtocol) {
3503 return MethodInterface == BoundInterface ||
3504 MethodInterface->isSuperClassOf(BoundInterface) ||
3505 BoundInterface->isSuperClassOf(MethodInterface);
3507 llvm_unreachable(
"unknown method context");
3514 bool InstanceFirst,
bool CheckTheOther,
3527 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3529 Methods.push_back(M->getMethod());
3533 if (!Methods.empty())
3534 return Methods.size() > 1;
3543 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3545 Methods.push_back(M->getMethod());
3548 return Methods.size() > 1;
3556 FilteredMethods.push_back(BestMethod);
3558 for (
auto *M : Methods)
3559 if (M != BestMethod && !M->
hasAttr<UnavailableAttr>())
3560 FilteredMethods.push_back(M);
3562 if (FilteredMethods.size() > 1)
3577 bool receiverIdOrClass,
3587 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3590 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3591 return M->getMethod();
3598 bool receiverIdOrClass) {
3600 bool issueDiagnostic =
false, issueError =
false;
3604 bool strictSelectorMatch =
3605 receiverIdOrClass &&
3607 if (strictSelectorMatch) {
3608 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3610 issueDiagnostic =
true;
3619 if (!strictSelectorMatch ||
3620 (issueDiagnostic &&
getLangOpts().ObjCAutoRefCount))
3621 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3625 issueDiagnostic =
true;
3632 if (issueDiagnostic) {
3634 Diag(R.
getBegin(), diag::err_arc_multiple_method_decl) << Sel << R;
3635 else if (strictSelectorMatch)
3636 Diag(R.getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
3638 Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
3640 Diag(Methods[0]->getBeginLoc(),
3641 issueError ? diag::note_possibility : diag::note_using)
3642 << Methods[0]->getSourceRange();
3643 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3644 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3645 << Methods[I]->getSourceRange();
3657 Method = Method->getNext())
3658 if (Method->getMethod() &&
3661 return Method->getMethod();
3664 Method = Method->getNext())
3665 if (Method->getMethod() &&
3668 return Method->getMethod();
3676 const unsigned MaxEditDistance = 1;
3677 unsigned BestEditDistance = MaxEditDistance + 1;
3680 unsigned MinPossibleEditDistance =
abs((
int)MethodName.size() - (
int)Typo.size());
3681 if (MinPossibleEditDistance > 0 &&
3682 Typo.size() / MinPossibleEditDistance < 1)
3684 unsigned EditDistance = Typo.edit_distance(MethodName,
true, MaxEditDistance);
3685 if (EditDistance > MaxEditDistance)
3687 if (EditDistance == BestEditDistance)
3688 BestMethod.push_back(Method);
3689 else if (EditDistance < BestEditDistance) {
3691 BestMethod.push_back(Method);
3710 bool ObjectIsId =
true, ObjectIsClass =
true;
3712 ObjectIsId = ObjectIsClass =
false;
3717 ObjectType =
QualType(ObjCPtr->getInterfaceType(), 0);
3718 ObjectIsId = ObjectIsClass =
false;
3721 ObjectIsClass =
false;
3731 if (M->getMethod() &&
3732 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3733 (M->getMethod()->getSelector() != Sel)) {
3735 Methods.push_back(M->getMethod());
3736 else if (!ObjectIsClass &&
3739 Methods.push_back(M->getMethod());
3743 if (M->getMethod() &&
3744 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3745 (M->getMethod()->getSelector() != Sel)) {
3747 Methods.push_back(M->getMethod());
3748 else if (!ObjectIsId &&
3751 Methods.push_back(M->getMethod());
3756 for (
unsigned i = 0, e = Methods.size(); i < e; i++) {
3760 return (SelectedMethods.size() == 1) ? SelectedMethods[0] :
nullptr;
3770 for (
auto *Ivar : ID->ivars()) {
3771 if (Ivar->isInvalidDecl())
3776 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3778 Ivar->setInvalidDecl();
3788 for (
auto ivar = ID->getClassInterface()->all_declared_ivar_begin();
3789 ivar; ivar = ivar->getNextIvar()) {
3790 if (ivar->isInvalidDecl())
continue;
3793 S.
Diag(ivar->getLocation(), diag::err_arc_weak_disabled);
3795 S.
Diag(ivar->getLocation(), diag::err_arc_weak_no_runtime);
3807 for (
auto ivar = ID->all_declared_ivar_begin(); ivar;
3808 ivar = ivar->getNextIvar()) {
3809 if (ivar->isInvalidDecl())
3815 S.
Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3816 ivar->setInvalidDecl();
3823 case Decl::ObjCInterface:
3825 case Decl::ObjCProtocol:
3827 case Decl::ObjCCategory:
3828 if (cast<ObjCCategoryDecl>(
CurContext)->IsClassExtension())
3831 case Decl::ObjCImplementation:
3833 case Decl::ObjCCategoryImpl:
3845 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3852 if ((IntfDecl = dyn_cast<ObjCInterfaceDecl>(OCD))) {
3853 Ivars = IntfDecl->
ivars();
3854 }
else if (
auto *ImplDecl = dyn_cast<ObjCImplementationDecl>(OCD)) {
3855 IntfDecl = ImplDecl->getClassInterface();
3856 Ivars = ImplDecl->
ivars();
3857 }
else if (
auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(OCD)) {
3858 if (CategoryDecl->IsClassExtension()) {
3859 IntfDecl = CategoryDecl->getClassInterface();
3860 Ivars = CategoryDecl->
ivars();
3865 if (!isa<ObjCInterfaceDecl>(OCD)) {
3866 for (
auto *ivar : Ivars) {
3868 S.
Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3869 << ivar->getDeclName() << ivar->getType();
3881 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3884 bool IsInvalidIvar =
false;
3886 S.
Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3887 << ivar->getDeclName() << IvarTy
3889 IsInvalidIvar =
true;
3891 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3892 S.
Diag(ivar->getLocation(),
3893 diag::err_objc_variable_sized_type_not_at_end)
3894 << ivar->getDeclName() << IvarTy;
3895 IsInvalidIvar =
true;
3898 if (IsInvalidIvar) {
3899 S.
Diag(ivar->getNextIvar()->getLocation(),
3900 diag::note_next_ivar_declaration)
3901 << ivar->getNextIvar()->getSynthesize();
3902 ivar->setInvalidDecl();
3910 (Ivars.begin() == Ivars.end()) ?
nullptr : *Ivars.begin();
3913 while (SuperClass && SuperClass->
ivar_empty())
3917 std::advance(IvarIter, SuperClass->
ivar_size() - 1);
3921 diag::warn_superclass_variable_sized_type_not_at_end)
3936 const llvm::iterator_range<ObjCProtocolList::iterator> &Protocols) {
3937 for (
auto *PI : Protocols)
3948 for (
auto *MD : PDecl->
methods()) {
3949 if (!MD->isPropertyAccessor()) {
3950 if (
const auto *CMD =
3951 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3952 if (CMD->isDirectMethod())
3953 DirectMembers.push_back(CMD);
3958 if (
const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3959 PD->getIdentifier(),
3960 PD->isClassProperty()
3963 if (CPD->isDirectProperty())
3964 DirectMembers.push_back(CPD);
3967 if (!DirectMembers.empty()) {
3968 S.
Diag(CDecl->
getLocation(), diag::err_objc_direct_protocol_conformance)
3970 for (
const auto *MD : DirectMembers)
3971 S.
Diag(MD->getLocation(), diag::note_direct_member_here);
3986 assert(AtEnd.
isValid() &&
"Invalid location for '@end'");
3988 auto *OCD = cast<ObjCContainerDecl>(
CurContext);
3989 Decl *ClassDecl = OCD;
3991 bool isInterfaceDeclKind =
3992 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
3993 || isa<ObjCProtocolDecl>(ClassDecl);
3994 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
4000 if (
auto *OID = dyn_cast<ObjCImplementationDecl>(
CurContext)) {
4001 for (
auto *PropImpl : OID->property_impls()) {
4002 if (
auto *Getter = PropImpl->getGetterMethodDecl())
4003 if (Getter->isSynthesizedAccessorStub())
4004 OID->addDecl(Getter);
4005 if (
auto *Setter = PropImpl->getSetterMethodDecl())
4006 if (Setter->isSynthesizedAccessorStub())
4007 OID->addDecl(Setter);
4012 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
4013 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
4015 for (
unsigned i = 0, e = allMethods.size(); i != e; i++ ) {
4017 cast_or_null<ObjCMethodDecl>(allMethods[i]);
4019 if (!Method)
continue;
4025 if ((isInterfaceDeclKind && PrevMethod && !
match)
4026 || (checkIdenticalMethods &&
match)) {
4049 if ((isInterfaceDeclKind && PrevMethod && !
match)
4050 || (checkIdenticalMethods &&
match)) {
4069 if (isa<ObjCInterfaceDecl>(ClassDecl)) {
4076 if (
C->IsClassExtension()) {
4084 if (CDecl->getIdentifier())
4088 for (
auto *I : CDecl->properties())
4090 CDecl->setAtEndRange(AtEnd);
4093 IC->setAtEndRange(AtEnd);
4100 for (
const auto *Ext : IDecl->visible_extensions()) {
4101 for (
const auto *
Property : Ext->instance_properties()) {
4104 = IC->FindPropertyImplDecl(
Property->getIdentifier(),
4106 if (PIDecl->getPropertyImplementation()
4110 for (
const auto *Ext : IDecl->visible_extensions()) {
4112 Ext->getInstanceMethod(
Property->getGetterName()))
4113 GetterMethod->setPropertyAccessor(
true);
4116 = Ext->getInstanceMethod(
Property->getSetterName()))
4117 SetterMethod->setPropertyAccessor(
true);
4125 if (IDecl->hasDesignatedInitializers())
4130 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4131 if (IDecl->getSuperClass() ==
nullptr) {
4134 if (!HasRootClassAttr) {
4137 Diag(DeclLoc, diag::warn_objc_root_class_missing)
4138 << IDecl->getIdentifier();
4146 Diag(SuperClassLoc, diag::note_objc_needs_superclass)
4149 Diag(SuperClassLoc, diag::note_objc_needs_superclass);
4152 }
else if (HasRootClassAttr) {
4154 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4162 if (IDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4163 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4164 Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
4165 Diag(Super->getLocation(), diag::note_class_declared);
4169 if (IDecl->hasAttr<ObjCClassStubAttr>())
4170 Diag(IC->getLocation(), diag::err_implementation_of_class_stub);
4173 while (IDecl->getSuperClass()) {
4175 IDecl = IDecl->getSuperClass();
4181 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
4182 CatImplClass->setAtEndRange(AtEnd);
4188 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4192 }
else if (
const auto *IntfDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
4194 if (!IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4195 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4196 Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
4197 Diag(Super->getLocation(), diag::note_class_declared);
4201 if (IntfDecl->hasAttr<ObjCClassStubAttr>() &&
4202 !IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>())
4203 Diag(IntfDecl->getLocation(), diag::err_class_stub_subclassing_mismatch);
4206 if (isInterfaceDeclKind) {
4208 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4211 if (
VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
4212 if (!VDecl->hasExternalStorage())
4213 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4219 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4222 (*I)->setTopLevelDeclInObjCContainer();
4251 if (ResultObjectType->isObjCIdType() ||
4252 ResultObjectType->isObjCQualifiedIdType())
4257 = ResultObjectType->getInterfaceDecl()) {
4263 if (ResultClass->isSuperClassOf(CurrentClass))
4279class OverrideSearch {
4311 dyn_cast<ObjCCategoryDecl>(container)) {
4312 searchFromContainer(container);
4314 searchFromContainer(Interface);
4316 searchFromContainer(container);
4320 typedef decltype(Overridden)::iterator iterator;
4321 iterator begin()
const {
return Overridden.begin(); }
4322 iterator end()
const {
return Overridden.end(); }
4329#define OBJCCONTAINER(type, base) \
4331 searchFrom(cast<type##Decl>(container)); \
4333#define ABSTRACT_DECL(expansion)
4334#define DECL(type, base) \
4336#include "clang/AST/DeclNodes.inc"
4337 llvm_unreachable(
"not an ObjC container!");
4397 for (
const auto *Proto : protocols)
4409 Overridden.insert(meth);
4419 searchFromContainer(container);
4427 const auto *
attr = overridden->
getAttr<ObjCDirectAttr>();
4429 Diag(
attr->getLocation(), diag::note_previous_declaration);
4431 const auto *
attr = method->
getAttr<ObjCDirectAttr>();
4432 Diag(
attr->getLocation(), diag::err_objc_direct_on_override)
4443 auto IsMethodInCurrentClass = [CurrentClass](
const ObjCMethodDecl *M) {
4445 return M->getClassInterface()->getCanonicalDecl() ==
4449 OverrideSearch overrides(*
this, ObjCMethod);
4455 bool hasOverriddenMethodsInBaseOrProtocol =
false;
4457 if (!hasOverriddenMethodsInBaseOrProtocol) {
4458 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4459 !IsMethodInCurrentClass(overridden) || overridden->isOverriding()) {
4461 hasOverriddenMethodsInBaseOrProtocol =
true;
4475 unsigned CategCount = List.getBits();
4476 if (CategCount > 0) {
4479 if (CategCount > 1 ||
4480 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4481 OverrideSearch overrides(*
this, overridden);
4483 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4484 !IsMethodInCurrentClass(SuperOverridden)) {
4486 hasOverriddenMethodsInBaseOrProtocol =
true;
4487 overridden->setOverriding(
true);
4504 if (ObjCMethod->
isImplicit() && overridden->isImplicit())
4511 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4513 if (CurrentClass && overridden->
getDeclContext() != CurrentClass &&
4514 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4519 PrevE = overridden->param_end();
4520 for (; ParamI != E && PrevI != PrevE; ++ParamI, ++PrevI) {
4521 assert(PrevI != overridden->param_end() &&
"Param mismatch");
4527 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4529 Diag(overridden->getLocation(), diag::note_previous_declaration);
4536 ObjCMethod->
setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4546 bool prevUsesCSKeyword) {
4548 auto nullability =
type->getNullability();
4552 if (nullability.has_value() == prevNullability.has_value()) {
4558 if (*nullability == *prevNullability)
4562 S.
Diag(loc, diag::err_nullability_conflicting)
4585 if (prevMethod->
hasAttr<ObjCRequiresSuperAttr>() &&
4586 !method->
hasAttr<ObjCRequiresSuperAttr>()) {
4589 ObjCRequiresSuperAttr::CreateImplicit(S.
Context,
4606 unsigned numPrevParams = prevMethod->
param_size();
4607 for (
unsigned i = 0, n = std::min(numParams, numPrevParams); i != n; ++i) {
4627 llvm::Triple::x86 &&
4628 "x86-specific check invoked for a different target");
4632 if (
P->getType()->isVectorType()) {
4633 Loc =
P->getBeginLoc();
4649 VersionTuple AcceptedInVersion;
4650 if (Triple.getOS() == llvm::Triple::IOS)
4651 AcceptedInVersion = VersionTuple(9);
4652 else if (Triple.isMacOSX())
4653 AcceptedInVersion = VersionTuple(10, 11);
4659 SemaRef.
Diag(Loc, diag::err_objc_method_unsupported_param_ret_type)
4662 << (Triple.isMacOSX() ?
"macOS 10.11" :
"iOS 9");
4667 CD->
hasAttr<ObjCDirectMembersAttr>()) {
4678 bool diagnosed =
false;
4681 if (diagnosed || IMD->isImplicit())
4687 S.
Diag(IMD->getLocation(), diag::note_previous_declaration);
4705 if (
auto *IMD = IDecl->
getMethod(Sel, isInstance))
4708 if (Impl != ImpDecl)
4713 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4715 else if (
auto CatImpl = Cat->getImplementation())
4716 if (CatImpl != ImpDecl)
4717 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4730 bool isVariadic,
bool MethodDefinition) {
4733 Diag(MethodLoc, diag::err_missing_method_context);
4740 bool HasRelatedResultType =
false;
4748 QualType bareResultType = resultDeclType;
4753 Diag(MethodLoc, diag::warn_missing_method_return_type)
4759 MethodType == tok::minus, isVariadic,
4764 HasRelatedResultType);
4768 for (
unsigned i = 0, e = Sel.
getNumArgs(); i != e; ++i) {
4772 if (!ArgInfo[i].
Type) {
4779 LookupResult R(*
this, ArgInfo[i].Name, ArgInfo[i].NameLoc,
4784 if (S->isDeclScope(PrevDecl)) {
4785 Diag(ArgInfo[i].NameLoc,
4786 (MethodDefinition ? diag::warn_method_param_redefinition
4787 : diag::warn_method_param_declaration))
4790 diag::note_previous_declaration);
4799 ArgInfo[i].NameLoc, ArgInfo[i].Name,
4811 if (Param->
hasAttr<BlocksAttr>()) {
4818 Params.push_back(Param);
4821 for (
unsigned i = 0, e = CNumArgs; i != e; ++i) {
4822 ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
4831 Params.push_back(Param);
4843 if (
ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(ClassDecl)) {
4844 if (MethodType == tok::minus) {
4845 PrevMethod = ImpDecl->getInstanceMethod(Sel);
4846 ImpDecl->addInstanceMethod(ObjCMethod);
4848 PrevMethod = ImpDecl->getClassMethod(Sel);
4849 ImpDecl->addClassMethod(ObjCMethod);
4858 if (
auto *Setter = PropertyImpl->getSetterMethodDecl())
4859 if (Setter->getSelector() == Sel &&
4861 assert(Setter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4862 PropertyImpl->setSetterMethodDecl(ObjCMethod);
4864 if (
auto *Getter = PropertyImpl->getGetterMethodDecl())
4865 if (Getter->getSelector() == Sel &&
4867 assert(Getter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4868 PropertyImpl->setGetterMethodDecl(ObjCMethod);
4882 const auto *
attr = CanonicalMD->
getAttr<ObjCDirectAttr>();
4884 ObjCDirectAttr::CreateImplicit(
Context,
attr->getLocation()));
4891 if (
auto *IMD = IDecl->lookupMethod(ObjCMethod->
getSelector(),
4911 if (IDecl == IMD->getClassInterface()) {
4912 auto diagContainerMismatch = [&] {
4913 int decl = 0, impl = 0;
4915 if (
auto *Cat = dyn_cast<ObjCCategoryDecl>(IMD->getDeclContext()))
4916 decl = Cat->IsClassExtension() ? 1 : 2;
4918 if (isa<ObjCCategoryImplDecl>(ImpDecl))
4919 impl = 1 + (
decl != 0);
4922 diag::err_objc_direct_impl_decl_mismatch)
4924 Diag(IMD->getLocation(), diag::note_previous_declaration);
4928 const auto *
attr = ObjCMethod->
getAttr<ObjCDirectAttr>();
4930 diagContainerMismatch();
4931 }
else if (!IMD->isDirectMethod()) {
4932 Diag(
attr->getLocation(), diag::err_objc_direct_missing_on_decl);
4933 Diag(IMD->getLocation(), diag::note_previous_declaration);
4935 }
else if (IMD->isDirectMethod()) {
4936 const auto *
attr = IMD->getAttr<ObjCDirectAttr>();
4938 diagContainerMismatch();
4941 ObjCDirectAttr::CreateImplicit(
Context,
attr->getLocation()));
4947 if (isa<ObjCCategoryImplDecl>(ImpDecl) && IMD->isOverriding() &&
4960 for (
auto *
C : IDecl->visible_categories())
4961 for (
auto &
P :
C->protocols())
4962 if (
auto *IMD =
P->lookupMethod(ObjCMethod->
getSelector(),
4965 IMD->parameters().size() &&
4966 "Methods have different number of parameters");
4967 auto OI = IMD->param_begin(), OE = IMD->param_end();
4969 for (; OI != OE; ++OI, ++NI)
4974 if (!isa<ObjCProtocolDecl>(ClassDecl)) {
4979 IDecl = cast<ObjCCategoryDecl>(ClassDecl)->getClassInterface();
4987 cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
5003 if (!CurrentClass) {
5005 CurrentClass = Cat->getClassInterface();
5006 else if (
ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(ClassDecl))
5007 CurrentClass = Impl->getClassInterface();
5009 = dyn_cast<ObjCCategoryImplDecl>(ClassDecl))
5010 CurrentClass = CatImpl->getClassInterface();
5018 bool ARCError =
false;
5025 LangOpts.ObjCInferRelatedResultType) {
5026 bool InferRelatedResultType =
false;
5052 if (InferRelatedResultType &&
5057 if (MethodDefinition &&
5063 if (
const auto *
attr = ObjCMethod->
getAttr<AvailabilityAttr>()) {
5066 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
5068 ObjCMethod->
dropAttr<AvailabilityAttr>();
5083 if (isa<ObjCContainerDecl>(