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) {
2640 if (MethodDecl->
hasAttr<UnavailableAttr>() ||
2641 MethodDecl->
hasAttr<DeprecatedAttr>())
2645 IsProtocolMethodDecl,
false,
false);
2650 IM != EM && IF != EF; ++IM, ++IF) {
2653 IsProtocolMethodDecl,
false,
false);
2665 diag::warn_category_method_impl_match);
2682 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>())
2684 for (
const auto *PI : PDecl->
protocols())
2710 : dyn_cast<ObjCInterfaceDecl>(CDecl);
2711 assert (IDecl &&
"CheckProtocolMethodDefs - IDecl is null");
2727 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>()) {
2728 if (!ProtocolsExplictImpl) {
2750 if (InsMap.count(fISelector))
2769 if (method->getImplementationControl() !=
2771 !method->isPropertyAccessor() &&
2772 !InsMap.count(method->getSelector()) &&
2774 method->getSelector(),
true ,
2787 method->getSelector(),
true ,
2789 if (
C || MethodInClass->isPropertyAccessor())
2791 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2799 if (method->getImplementationControl() !=
2801 !ClsMap.count(method->getSelector()) &&
2803 method->getSelector(),
false ,
2805 true ,
nullptr ))) {
2813 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2822 ProtocolsExplictImpl);
2834 bool &IncompleteImpl,
2835 bool ImmediateClass,
2836 bool WarnCategoryMethodImpl) {
2840 if (!InsMapSeen.insert(I->getSelector()).second)
2842 if (!I->isPropertyAccessor() &&
2843 !InsMap.count(I->getSelector())) {
2846 diag::warn_undef_method_impl);
2852 "Expected to find the method through lookup as well");
2854 if (ImpMethodDecl) {
2858 if (!WarnCategoryMethodImpl)
2860 isa<ObjCProtocolDecl>(CDecl));
2861 else if (!I->isPropertyAccessor())
2870 if (!ClsMapSeen.insert(I->getSelector()).second)
2872 if (!I->isPropertyAccessor() &&
2873 !ClsMap.count(I->getSelector())) {
2876 diag::warn_undef_method_impl);
2881 "Expected to find the method through lookup as well");
2883 if (ImpMethodDecl) {
2887 if (!WarnCategoryMethodImpl)
2889 isa<ObjCProtocolDecl>(CDecl));
2890 else if (!I->isPropertyAccessor())
2899 for (
auto *PI : PD->protocols())
2901 IMPDecl, PI, IncompleteImpl,
false,
2902 WarnCategoryMethodImpl);
2909 if (!WarnCategoryMethodImpl) {
2910 for (
auto *Cat : I->visible_categories())
2912 IMPDecl, Cat, IncompleteImpl,
2913 ImmediateClass && Cat->IsClassExtension(),
2914 WarnCategoryMethodImpl);
2917 for (
auto *Ext : I->visible_extensions())
2919 IMPDecl, Ext, IncompleteImpl,
false,
2920 WarnCategoryMethodImpl);
2924 for (
auto *PI : I->all_referenced_protocols())
2926 IMPDecl, PI, IncompleteImpl,
false,
2927 WarnCategoryMethodImpl);
2931 if (!WarnCategoryMethodImpl && I->getSuperClass())
2934 I->getSuperClass(), IncompleteImpl,
false);
2965 if (SuperIDecl && SuperIDecl->
lookupMethod(Sel,
false))
2969 if (InsMap.empty() && ClsMap.empty())
2973 bool IncompleteImpl =
false;
2976 IncompleteImpl,
false,
2982 bool IncompleteImpl) {
2987 InsMap.insert(I->getSelector());
2995 const auto *
P = PImpl->getPropertyDecl();
2998 InsMap.insert(
P->getGetterName());
2999 if (!
P->getSetterName().isNull())
3000 InsMap.insert(
P->getSetterName());
3007 bool SynthesizeProperties =
LangOpts.ObjCDefaultSynthProperties &&
3009 !IDecl->isObjCRequiresPropertyDefs();
3018 ClsMap.insert(I->getSelector());
3025 IncompleteImpl,
true);
3030 dyn_cast<ObjCCategoryImplDecl>(IMPDecl))
3041 for (
auto *PI : I->all_referenced_protocols())
3043 ClsMap, I, ExplicitImplProtocols);
3047 if (!
C->IsClassExtension()) {
3048 for (
auto *
P :
C->protocols())
3050 ClsMap, CDecl, ExplicitImplProtocols);
3055 llvm_unreachable(
"invalid ObjCContainerDecl type.");
3065 for (
unsigned i = 0; i != NumElts; ++i) {
3070 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
3080 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
3088 Diag(AtClassLoc, diag::warn_forward_class_redefinition)
3098 = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
3120 if (PrevIDecl && TypeParams) {
3124 *
this, PrevTypeParams, TypeParams,
3125 TypeParamListContext::ForwardDeclaration)) {
3126 TypeParams =
nullptr;
3130 Diag(IdentLocs[i], diag::err_objc_parameterized_forward_class)
3133 Diag(Def->getLocation(), diag::note_defined_here)
3136 TypeParams =
nullptr;
3142 ClassName, TypeParams, PrevIDecl,
3151 DeclsInGroup.push_back(IDecl);
3159 const Type *left,
const Type *right);
3168 if (left == right)
return true;
3191 if (isa<VectorType>(left))
return isa<VectorType>(right);
3192 if (isa<VectorType>(right))
return false;
3215 return (leftSK == rightSK);
3221 assert(lt && rt && lt != rt);
3223 if (!isa<RecordType>(lt) || !isa<RecordType>(rt))
return false;
3224 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3225 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3231 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3232 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3247 for (; li != le && ri != re; ++li, ++ri) {
3248 if (!
matchTypes(Context, strategy, li->getType(), ri->getType()))
3251 return (li == le && ri == re);
3272 (left->
hasAttr<NSReturnsRetainedAttr>()
3273 != right->
hasAttr<NSReturnsRetainedAttr>() ||
3274 left->
hasAttr<NSConsumesSelfAttr>()
3275 != right->
hasAttr<NSConsumesSelfAttr>()))
3282 for (; li != le && ri != re; ++li, ++ri) {
3283 assert(ri != right->
param_end() &&
"Param mismatch");
3290 lparm->
hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3298 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3299 auto *MethodInListProtocol =
3303 if ((MethodProtocol && !MethodInListProtocol) ||
3304 (!MethodProtocol && MethodInListProtocol))
3307 if (MethodProtocol && MethodInListProtocol)
3313 return MethodInterface == MethodInListInterface;
3322 if (!CD->IsClassExtension() &&
List->getBits() < 2)
3323 List->setBits(
List->getBits() + 1);
3326 if (
List->getMethod() ==
nullptr) {
3327 List->setMethod(Method);
3328 List->setNext(
nullptr);
3353 if (!SameDeclaration ||
3359 List->setHasMoreThanOneDecl(
true);
3364 !ListWithSameDeclaration && !
List->getMethod()->isDeprecated())
3365 ListWithSameDeclaration =
List;
3368 !ListWithSameDeclaration &&
3370 ListWithSameDeclaration =
List;
3384 List->setHasMoreThanOneDecl(
true);
3391 List->setMethod(Method);
3397 List->setMethod(Method);
3408 if (ListWithSameDeclaration) {
3411 ListWithSameDeclaration->
setMethod(Method);
3432void Sema::AddMethodToGlobalPool(
ObjCMethodDecl *Method,
bool impl,
3450 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3487 assert(BoundInterface &&
"unexpected object type!");
3491 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3492 if (MethodProtocol) {
3502 return MethodInterface == BoundInterface ||
3503 MethodInterface->isSuperClassOf(BoundInterface) ||
3504 BoundInterface->isSuperClassOf(MethodInterface);
3506 llvm_unreachable(
"unknown method context");
3513 bool InstanceFirst,
bool CheckTheOther,
3526 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3528 Methods.push_back(M->getMethod());
3532 if (!Methods.empty())
3533 return Methods.size() > 1;
3542 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3544 Methods.push_back(M->getMethod());
3547 return Methods.size() > 1;
3555 FilteredMethods.push_back(BestMethod);
3557 for (
auto *M : Methods)
3558 if (M != BestMethod && !M->
hasAttr<UnavailableAttr>())
3559 FilteredMethods.push_back(M);
3561 if (FilteredMethods.size() > 1)
3576 bool receiverIdOrClass,
3586 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3589 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3590 return M->getMethod();
3597 bool receiverIdOrClass) {
3599 bool issueDiagnostic =
false, issueError =
false;
3603 bool strictSelectorMatch =
3604 receiverIdOrClass &&
3606 if (strictSelectorMatch) {
3607 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3609 issueDiagnostic =
true;
3618 if (!strictSelectorMatch ||
3619 (issueDiagnostic &&
getLangOpts().ObjCAutoRefCount))
3620 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3624 issueDiagnostic =
true;
3631 if (issueDiagnostic) {
3633 Diag(R.
getBegin(), diag::err_arc_multiple_method_decl) << Sel << R;
3634 else if (strictSelectorMatch)
3635 Diag(R.getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
3637 Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
3639 Diag(Methods[0]->getBeginLoc(),
3640 issueError ? diag::note_possibility : diag::note_using)
3641 << Methods[0]->getSourceRange();
3642 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3643 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3644 << Methods[I]->getSourceRange();
3656 Method = Method->getNext())
3657 if (Method->getMethod() &&
3660 return Method->getMethod();
3663 Method = Method->getNext())
3664 if (Method->getMethod() &&
3667 return Method->getMethod();
3675 const unsigned MaxEditDistance = 1;
3676 unsigned BestEditDistance = MaxEditDistance + 1;
3679 unsigned MinPossibleEditDistance =
abs((
int)MethodName.size() - (
int)Typo.size());
3680 if (MinPossibleEditDistance > 0 &&
3681 Typo.size() / MinPossibleEditDistance < 1)
3683 unsigned EditDistance = Typo.edit_distance(MethodName,
true, MaxEditDistance);
3684 if (EditDistance > MaxEditDistance)
3686 if (EditDistance == BestEditDistance)
3687 BestMethod.push_back(Method);
3688 else if (EditDistance < BestEditDistance) {
3690 BestMethod.push_back(Method);
3709 bool ObjectIsId =
true, ObjectIsClass =
true;
3711 ObjectIsId = ObjectIsClass =
false;
3716 ObjectType =
QualType(ObjCPtr->getInterfaceType(), 0);
3717 ObjectIsId = ObjectIsClass =
false;
3720 ObjectIsClass =
false;
3730 if (M->getMethod() &&
3731 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3732 (M->getMethod()->getSelector() != Sel)) {
3734 Methods.push_back(M->getMethod());
3735 else if (!ObjectIsClass &&
3738 Methods.push_back(M->getMethod());
3742 if (M->getMethod() &&
3743 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3744 (M->getMethod()->getSelector() != Sel)) {
3746 Methods.push_back(M->getMethod());
3747 else if (!ObjectIsId &&
3750 Methods.push_back(M->getMethod());
3755 for (
unsigned i = 0, e = Methods.size(); i < e; i++) {
3759 return (SelectedMethods.size() == 1) ? SelectedMethods[0] :
nullptr;
3769 for (
auto *Ivar : ID->ivars()) {
3770 if (Ivar->isInvalidDecl())
3775 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3777 Ivar->setInvalidDecl();
3787 for (
auto ivar = ID->getClassInterface()->all_declared_ivar_begin();
3788 ivar; ivar = ivar->getNextIvar()) {
3789 if (ivar->isInvalidDecl())
continue;
3792 S.
Diag(ivar->getLocation(), diag::err_arc_weak_disabled);
3794 S.
Diag(ivar->getLocation(), diag::err_arc_weak_no_runtime);
3806 for (
auto ivar = ID->all_declared_ivar_begin(); ivar;
3807 ivar = ivar->getNextIvar()) {
3808 if (ivar->isInvalidDecl())
3814 S.
Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3815 ivar->setInvalidDecl();
3822 case Decl::ObjCInterface:
3824 case Decl::ObjCProtocol:
3826 case Decl::ObjCCategory:
3827 if (cast<ObjCCategoryDecl>(
CurContext)->IsClassExtension())
3830 case Decl::ObjCImplementation:
3832 case Decl::ObjCCategoryImpl:
3844 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3851 if ((IntfDecl = dyn_cast<ObjCInterfaceDecl>(OCD))) {
3852 Ivars = IntfDecl->
ivars();
3853 }
else if (
auto *ImplDecl = dyn_cast<ObjCImplementationDecl>(OCD)) {
3854 IntfDecl = ImplDecl->getClassInterface();
3855 Ivars = ImplDecl->
ivars();
3856 }
else if (
auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(OCD)) {
3857 if (CategoryDecl->IsClassExtension()) {
3858 IntfDecl = CategoryDecl->getClassInterface();
3859 Ivars = CategoryDecl->
ivars();
3864 if (!isa<ObjCInterfaceDecl>(OCD)) {
3865 for (
auto *ivar : Ivars) {
3867 S.
Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3868 << ivar->getDeclName() << ivar->getType();
3880 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3883 bool IsInvalidIvar =
false;
3885 S.
Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3886 << ivar->getDeclName() << IvarTy
3888 IsInvalidIvar =
true;
3890 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3891 S.
Diag(ivar->getLocation(),
3892 diag::err_objc_variable_sized_type_not_at_end)
3893 << ivar->getDeclName() << IvarTy;
3894 IsInvalidIvar =
true;
3897 if (IsInvalidIvar) {
3898 S.
Diag(ivar->getNextIvar()->getLocation(),
3899 diag::note_next_ivar_declaration)
3900 << ivar->getNextIvar()->getSynthesize();
3901 ivar->setInvalidDecl();
3909 (Ivars.begin() == Ivars.end()) ?
nullptr : *Ivars.begin();
3912 while (SuperClass && SuperClass->
ivar_empty())
3916 std::advance(IvarIter, SuperClass->
ivar_size() - 1);
3920 diag::warn_superclass_variable_sized_type_not_at_end)
3935 const llvm::iterator_range<ObjCProtocolList::iterator> &Protocols) {
3936 for (
auto *PI : Protocols)
3947 for (
auto *MD : PDecl->
methods()) {
3948 if (!MD->isPropertyAccessor()) {
3949 if (
const auto *CMD =
3950 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3951 if (CMD->isDirectMethod())
3952 DirectMembers.push_back(CMD);
3957 if (
const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3958 PD->getIdentifier(),
3959 PD->isClassProperty()
3962 if (CPD->isDirectProperty())
3963 DirectMembers.push_back(CPD);
3966 if (!DirectMembers.empty()) {
3967 S.
Diag(CDecl->
getLocation(), diag::err_objc_direct_protocol_conformance)
3969 for (
const auto *MD : DirectMembers)
3970 S.
Diag(MD->getLocation(), diag::note_direct_member_here);
3985 assert(AtEnd.
isValid() &&
"Invalid location for '@end'");
3987 auto *OCD = cast<ObjCContainerDecl>(
CurContext);
3988 Decl *ClassDecl = OCD;
3990 bool isInterfaceDeclKind =
3991 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
3992 || isa<ObjCProtocolDecl>(ClassDecl);
3993 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
3999 if (
auto *OID = dyn_cast<ObjCImplementationDecl>(
CurContext)) {
4000 for (
auto *PropImpl : OID->property_impls()) {
4001 if (
auto *Getter = PropImpl->getGetterMethodDecl())
4002 if (Getter->isSynthesizedAccessorStub())
4003 OID->addDecl(Getter);
4004 if (
auto *Setter = PropImpl->getSetterMethodDecl())
4005 if (Setter->isSynthesizedAccessorStub())
4006 OID->addDecl(Setter);
4011 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
4012 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
4014 for (
unsigned i = 0, e = allMethods.size(); i != e; i++ ) {
4016 cast_or_null<ObjCMethodDecl>(allMethods[i]);
4018 if (!Method)
continue;
4024 if ((isInterfaceDeclKind && PrevMethod && !
match)
4025 || (checkIdenticalMethods &&
match)) {
4048 if ((isInterfaceDeclKind && PrevMethod && !
match)
4049 || (checkIdenticalMethods &&
match)) {
4068 if (isa<ObjCInterfaceDecl>(ClassDecl)) {
4075 if (
C->IsClassExtension()) {
4083 if (CDecl->getIdentifier())
4087 for (
auto *I : CDecl->properties())
4089 CDecl->setAtEndRange(AtEnd);
4092 IC->setAtEndRange(AtEnd);
4099 for (
const auto *Ext : IDecl->visible_extensions()) {
4100 for (
const auto *
Property : Ext->instance_properties()) {
4103 = IC->FindPropertyImplDecl(
Property->getIdentifier(),
4105 if (PIDecl->getPropertyImplementation()
4109 for (
const auto *Ext : IDecl->visible_extensions()) {
4111 Ext->getInstanceMethod(
Property->getGetterName()))
4112 GetterMethod->setPropertyAccessor(
true);
4115 = Ext->getInstanceMethod(
Property->getSetterName()))
4116 SetterMethod->setPropertyAccessor(
true);
4124 if (IDecl->hasDesignatedInitializers())
4129 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4130 if (IDecl->getSuperClass() ==
nullptr) {
4133 if (!HasRootClassAttr) {
4136 Diag(DeclLoc, diag::warn_objc_root_class_missing)
4137 << IDecl->getIdentifier();
4145 Diag(SuperClassLoc, diag::note_objc_needs_superclass)
4148 Diag(SuperClassLoc, diag::note_objc_needs_superclass);
4151 }
else if (HasRootClassAttr) {
4153 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4161 if (IDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4162 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4163 Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
4164 Diag(Super->getLocation(), diag::note_class_declared);
4168 if (IDecl->hasAttr<ObjCClassStubAttr>())
4169 Diag(IC->getLocation(), diag::err_implementation_of_class_stub);
4172 while (IDecl->getSuperClass()) {
4174 IDecl = IDecl->getSuperClass();
4180 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
4181 CatImplClass->setAtEndRange(AtEnd);
4187 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4191 }
else if (
const auto *IntfDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
4193 if (!IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4194 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4195 Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
4196 Diag(Super->getLocation(), diag::note_class_declared);
4200 if (IntfDecl->hasAttr<ObjCClassStubAttr>() &&
4201 !IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>())
4202 Diag(IntfDecl->getLocation(), diag::err_class_stub_subclassing_mismatch);
4205 if (isInterfaceDeclKind) {
4207 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4210 if (
VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
4211 if (!VDecl->hasExternalStorage())
4212 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4218 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4221 (*I)->setTopLevelDeclInObjCContainer();
4250 if (ResultObjectType->isObjCIdType() ||
4251 ResultObjectType->isObjCQualifiedIdType())
4256 = ResultObjectType->getInterfaceDecl()) {
4262 if (ResultClass->isSuperClassOf(CurrentClass))
4278class OverrideSearch {
4310 dyn_cast<ObjCCategoryDecl>(container)) {
4311 searchFromContainer(container);
4315 searchFromContainer(container);
4319 typedef decltype(Overridden)::iterator iterator;
4320 iterator begin()
const {
return Overridden.begin(); }
4321 iterator end()
const {
return Overridden.end(); }
4328#define OBJCCONTAINER(type, base) \
4330 searchFrom(cast<type##Decl>(container)); \
4332#define ABSTRACT_DECL(expansion)
4333#define DECL(type, base) \
4335#include "clang/AST/DeclNodes.inc"
4336 llvm_unreachable(
"not an ObjC container!");
4396 for (
const auto *Proto : protocols)
4408 Overridden.insert(meth);
4418 searchFromContainer(container);
4426 const auto *
attr = overridden->
getAttr<ObjCDirectAttr>();
4428 Diag(
attr->getLocation(), diag::note_previous_declaration);
4430 const auto *
attr = method->
getAttr<ObjCDirectAttr>();
4431 Diag(
attr->getLocation(), diag::err_objc_direct_on_override)
4442 auto IsMethodInCurrentClass = [CurrentClass](
const ObjCMethodDecl *M) {
4444 return M->getClassInterface()->getCanonicalDecl() ==
4448 OverrideSearch overrides(*
this, ObjCMethod);
4454 bool hasOverriddenMethodsInBaseOrProtocol =
false;
4456 if (!hasOverriddenMethodsInBaseOrProtocol) {
4457 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4458 !IsMethodInCurrentClass(overridden) || overridden->isOverriding()) {
4460 hasOverriddenMethodsInBaseOrProtocol =
true;
4474 unsigned CategCount =
List.getBits();
4475 if (CategCount > 0) {
4478 if (CategCount > 1 ||
4479 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4480 OverrideSearch overrides(*
this, overridden);
4482 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4483 !IsMethodInCurrentClass(SuperOverridden)) {
4485 hasOverriddenMethodsInBaseOrProtocol =
true;
4486 overridden->setOverriding(
true);
4503 if (ObjCMethod->
isImplicit() && overridden->isImplicit())
4510 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4512 if (CurrentClass && overridden->
getDeclContext() != CurrentClass &&
4513 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4518 PrevE = overridden->param_end();
4519 for (; ParamI != E && PrevI != PrevE; ++ParamI, ++PrevI) {
4520 assert(PrevI != overridden->param_end() &&
"Param mismatch");
4526 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4528 Diag(overridden->getLocation(), diag::note_previous_declaration);
4535 ObjCMethod->
setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4545 bool prevUsesCSKeyword) {
4547 auto nullability =
type->getNullability();
4551 if (nullability.has_value() == prevNullability.has_value()) {
4557 if (*nullability == *prevNullability)
4561 S.
Diag(loc, diag::err_nullability_conflicting)
4584 if (prevMethod->
hasAttr<ObjCRequiresSuperAttr>() &&
4585 !method->
hasAttr<ObjCRequiresSuperAttr>()) {
4588 ObjCRequiresSuperAttr::CreateImplicit(S.
Context,
4605 unsigned numPrevParams = prevMethod->
param_size();
4606 for (
unsigned i = 0, n = std::min(numParams, numPrevParams); i != n; ++i) {
4626 llvm::Triple::x86 &&
4627 "x86-specific check invoked for a different target");
4631 if (
P->getType()->isVectorType()) {
4632 Loc =
P->getBeginLoc();
4648 VersionTuple AcceptedInVersion;
4649 if (Triple.getOS() == llvm::Triple::IOS)
4650 AcceptedInVersion = VersionTuple(9);
4651 else if (Triple.isMacOSX())
4652 AcceptedInVersion = VersionTuple(10, 11);
4658 SemaRef.
Diag(Loc, diag::err_objc_method_unsupported_param_ret_type)
4661 << (Triple.isMacOSX() ?
"macOS 10.11" :
"iOS 9");
4666 CD->
hasAttr<ObjCDirectMembersAttr>()) {
4677 bool diagnosed =
false;
4680 if (diagnosed || IMD->isImplicit())
4686 S.
Diag(IMD->getLocation(), diag::note_previous_declaration);
4704 if (
auto *IMD = IDecl->
getMethod(Sel, isInstance))
4707 if (Impl != ImpDecl)
4712 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4714 else if (
auto CatImpl = Cat->getImplementation())
4715 if (CatImpl != ImpDecl)
4716 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4729 bool isVariadic,
bool MethodDefinition) {
4732 Diag(MethodLoc, diag::err_missing_method_context);
4739 bool HasRelatedResultType =
false;
4747 QualType bareResultType = resultDeclType;
4752 Diag(MethodLoc, diag::warn_missing_method_return_type)
4758 MethodType == tok::minus, isVariadic,
4761 MethodDeclKind == tok::objc_optional
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 &&