28 #include "llvm/ADT/DenseMap.h"
29 #include "llvm/ADT/DenseSet.h"
31 using namespace clang;
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);
1060 Diag(AtInterfaceLoc, diag::err_duplicate_class_def)
1062 Diag(Def->getLocation(), diag::note_previous_definition);
1086 ClassName, ClassLoc,
1087 SuperName, SuperLoc, SuperTypeArgs,
1088 SuperTypeArgsRange);
1096 NumProtoRefs, ProtoLocs);
1121 if (
const TypedefNameDecl *TDecl = dyn_cast_or_null<TypedefNameDecl>(IDecl)) {
1122 QualType T = TDecl->getUnderlyingType();
1125 ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end());
1130 ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc);
1147 Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
1156 dyn_cast_or_null<TypedefNameDecl>(CDeclU)) {
1157 QualType T = TDecl->getUnderlyingType();
1160 ClassName = IDecl->getIdentifier();
1169 Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
1192 E = PList.
end(); I != E; ++I) {
1195 if (PDecl->getIdentifier() == PName) {
1196 Diag(Ploc, diag::err_protocol_has_circular_dependency);
1197 Diag(PrevLoc, diag::note_previous_definition);
1201 if (!PDecl->hasDefinition())
1205 PDecl->getLocation(), PDecl->getReferencedProtocols()))
1219 assert(ProtocolName &&
"Missing protocol identifier");
1225 Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName;
1226 Diag(Def->getLocation(), diag::note_previous_definition);
1233 ProtocolLoc, AtProtoInterfaceLoc,
1248 ProtocolName, ProtocolLoc, PrevDecl->
getLocation(), PList);
1253 ProtocolLoc, AtProtoInterfaceLoc,
1267 if (!err && NumProtoRefs ) {
1270 NumProtoRefs, ProtoLocs);
1284 UndefinedProtocol = PDecl;
1290 UndefinedProtocol = PI;
1316 Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first;
1325 if (!ForObjCContainer) {
1334 if (WarnOnDeclarations &&
1336 Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first;
1337 Diag(UndefinedProtocol->
getLocation(), diag::note_protocol_decl_undefined)
1338 << UndefinedProtocol;
1340 Protocols.push_back(PDecl);
1347 class ObjCTypeArgOrProtocolValidatorCCC final
1352 ObjCTypeArgOrProtocolValidatorCCC(
ASTContext &context,
1354 : Context(context), LookupKind(lookupKind) { }
1356 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
1370 if (isa<RecordDecl>(typeDecl) && !Context.
getLangOpts().CPlusPlus)
1376 if (
type->isObjCObjectPointerType() ||
1377 type->isBlockPointerType() ||
1378 type->isDependentType() ||
1379 type->isObjCObjectType())
1396 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1397 return std::make_unique<ObjCTypeArgOrProtocolValidatorCCC>(*
this);
1406 bool SelectProtocolFirst) {
1407 Diag(TypeArgLoc, diag::err_objc_type_args_and_protocols)
1408 << SelectProtocolFirst << TypeArgId << ProtocolId
1425 bool warnOnIncompleteProtocols) {
1428 unsigned numProtocolsResolved = 0;
1429 auto resolvedAsProtocols = [&] {
1430 assert(numProtocolsResolved == identifiers.size() &&
"Unresolved protocols");
1437 bool allAreTypeNames =
false;
1441 baseClass = objcObjectType->getInterface();
1444 if (typeParams->size() == numProtocolsResolved) {
1446 allAreTypeNames =
true;
1453 for (
unsigned i = 0, n = protocols.size(); i != n; ++i) {
1458 if (!warnOnIncompleteProtocols) {
1470 if (warnOnIncompleteProtocols &&
1472 Diag(identifierLocs[i], diag::warn_undef_protocolref)
1481 if (allAreTypeNames) {
1484 if (isa<ObjCInterfaceDecl>(
decl)) {
1486 firstClassNameLoc = identifierLocs[i];
1487 }
else if (!isa<TypeDecl>(
decl)) {
1489 allAreTypeNames =
false;
1492 allAreTypeNames =
false;
1501 if (allAreTypeNames && firstClassNameLoc.
isValid()) {
1504 bool allProtocolsDeclared =
true;
1505 for (
auto proto : protocols) {
1507 allProtocolsDeclared =
false;
1512 if (allProtocolsDeclared) {
1513 Diag(firstClassNameLoc, diag::warn_objc_redundant_qualified_class_type)
1520 protocolLAngleLoc = lAngleLoc;
1521 protocolRAngleLoc = rAngleLoc;
1522 assert(protocols.size() == identifierLocs.size());
1526 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1528 protocols.push_back(proto);
1530 ++numProtocolsResolved;
1534 if (numProtocolsResolved == identifiers.size())
1535 return resolvedAsProtocols();
1541 typedef llvm::PointerUnion<TypeDecl *, ObjCInterfaceDecl *> TypeOrClassDecl;
1543 unsigned numTypeDeclsResolved = 0;
1544 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1548 typeDecls.push_back(TypeOrClassDecl());
1552 if (
auto typeDecl = dyn_cast<TypeDecl>(
decl)) {
1553 typeDecls.push_back(typeDecl);
1554 ++numTypeDeclsResolved;
1558 if (
auto objcClass = dyn_cast<ObjCInterfaceDecl>(
decl)) {
1559 typeDecls.push_back(objcClass);
1560 ++numTypeDeclsResolved;
1564 typeDecls.push_back(TypeOrClassDecl());
1571 auto resolveTypeReference = [&](TypeOrClassDecl typeDecl,
SourceLocation loc)
1575 const char* prevSpec;
1578 if (
auto *actualTypeDecl = typeDecl.dyn_cast<
TypeDecl *>())
1606 Diag(loc, diag::err_objc_type_arg_missing_star)
1617 auto resolvedAsTypeDecls = [&] {
1621 assert(numTypeDeclsResolved == identifiers.size() &&
"Unresolved type decl");
1623 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1625 TypeResult type = resolveTypeReference(typeDecls[i], identifierLocs[i]);
1626 if (!
type.isUsable()) {
1631 typeArgs.push_back(
type.get());
1634 typeArgsLAngleLoc = lAngleLoc;
1635 typeArgsRAngleLoc = rAngleLoc;
1640 if (numTypeDeclsResolved == identifiers.size())
1641 return resolvedAsTypeDecls();
1647 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1650 if (protocols[i] || typeDecls[i]) {
1656 if (protocols[i] && typeDecls[i])
1679 identifiers[i], identifierLocs[i],
1680 protocols[i] !=
nullptr);
1688 ObjCTypeArgOrProtocolValidatorCCC CCC(
Context, lookupKind);
1696 PDiag(diag::err_undeclared_protocol_suggest)
1699 protocols[i] = proto;
1700 ++numProtocolsResolved;
1707 PDiag(diag::err_unknown_typename_suggest)
1710 typeDecls[i] = typeDecl;
1711 ++numTypeDeclsResolved;
1718 PDiag(diag::err_unknown_type_or_class_name_suggest)
1719 << identifiers[i] <<
true);
1721 typeDecls[i] = objcClass;
1722 ++numTypeDeclsResolved;
1728 Diag(identifierLocs[i],
1729 (lookupKind ==
LookupAnyName ? diag::err_objc_type_arg_missing
1731 : diag::err_unknown_typename))
1740 if (numProtocolsResolved == identifiers.size())
1741 return resolvedAsProtocols();
1744 assert(numTypeDeclsResolved == identifiers.size() &&
"Not all types?");
1745 return resolvedAsTypeDecls();
1756 llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
1757 for (
auto *MD :
ID->methods())
1758 MethodMap[MD->getSelector()] = MD;
1760 if (MethodMap.empty())
1762 for (
const auto *Method : CAT->
methods()) {
1763 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
1767 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
1768 << Method->getDeclName();
1786 IdentPair.second, AtProtocolLoc,
1798 DeclsInGroup.push_back(PDecl);
1808 Decl *
const *ProtoRefs,
unsigned NumProtoRefs,
1818 diag::err_category_forward_interface,
1819 CategoryName ==
nullptr)) {
1824 ClassLoc, CategoryLoc, CategoryName,
1825 IDecl, typeParamList);
1830 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1836 Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName;
1838 diag::note_implementation_declared);
1846 Diag(CategoryLoc, diag::warn_dup_category_def)
1847 << ClassName << CategoryName;
1848 Diag(
Previous->getLocation(), diag::note_previous_definition);
1853 if (typeParamList) {
1858 : TypeParamListContext::Extension))
1859 typeParamList =
nullptr;
1862 diag::err_objc_parameterized_category_nonclass)
1863 << (CategoryName !=
nullptr)
1867 typeParamList =
nullptr;
1872 ClassLoc, CategoryLoc, CategoryName, IDecl,
1885 NumProtoRefs, ProtoLocs);
1923 ClassLoc, AtCatImplLoc, CatLoc);
1926 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1929 diag::err_undef_interface)) {
1941 if (IDecl && IDecl->
hasAttr<ObjCRuntimeVisibleAttr>()) {
1942 Diag(ClassLoc, diag::err_objc_runtime_visible_category)
1949 Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName
1952 diag::note_previous_definition);
1977 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
1978 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
1980 }
else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
1984 diag::warn_undef_interface);
1988 ObjCInterfaceValidatorCCC CCC{};
1997 PDiag(diag::warn_undef_interface_suggest) << ClassName,
2000 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
2006 if (SuperClassname) {
2010 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
2011 Diag(SuperClassLoc, diag::err_redefinition_different_kind)
2015 SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
2019 Diag(SuperClassLoc, diag::err_undef_superclass)
2020 << SuperClassname << ClassName;
2024 Diag(SuperClassLoc, diag::err_conflicting_super_class)
2063 ClassLoc, AtClassImplLoc, SuperClassLoc);
2076 Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
2078 diag::note_previous_definition);
2092 Diag(ClassLoc, diag::err_objc_runtime_visible_subclass)
2104 DeclsInGroup.reserve(Decls.size() + 1);
2106 for (
unsigned i = 0, e = Decls.size(); i != e; ++i) {
2107 Decl *Dcl = Decls[i];
2112 DeclsInGroup.push_back(Dcl);
2115 DeclsInGroup.push_back(ObjCImpDecl);
2123 assert(ImpDecl &&
"missing implementation decl");
2133 for (
unsigned i = 0, e = numIvars; i != e; ++i) {
2150 assert(ivars &&
"missing @implementation ivars");
2154 for (
unsigned i = 0; i < numIvars; i++) {
2159 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2167 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
2184 for (; numIvars > 0 && IVI != IVE; ++IVI) {
2187 assert (ImplIvar &&
"missing implementation ivar");
2188 assert (ClsIvar &&
"missing class ivar");
2200 diag::err_conflicting_ivar_bitwidth)
2203 diag::note_previous_definition);
2215 Diag(ivars[j]->getLocation(), diag::err_inconsistent_ivar_count);
2216 else if (IVI != IVE)
2217 Diag(IVI->getLocation(), diag::err_inconsistent_ivar_count);
2241 llvm::raw_string_ostream Out(FixItStr);
2252 S.
Diag(MethodLoc, diag::note_method_declared_at) << method;
2328 (y & ~
Decl::OBJC_TQ_CSNullability);
2334 bool IsProtocolMethodDecl,
2335 bool IsOverridingMode,
2337 if (IsProtocolMethodDecl &&
2343 ? diag::warn_conflicting_overriding_ret_type_modifiers
2344 : diag::warn_conflicting_ret_type_modifiers))
2353 if (Warn && IsOverridingMode &&
2358 auto nullabilityMethodImpl =
2360 auto nullabilityMethodDecl =
2363 diag::warn_conflicting_nullability_attr_overriding_ret_types)
2365 nullabilityMethodImpl,
2369 nullabilityMethodDecl,
2382 IsOverridingMode ? diag::warn_conflicting_overriding_ret_types
2383 : diag::warn_conflicting_ret_types;
2399 IsOverridingMode ? diag::warn_non_covariant_overriding_ret_types
2400 : diag::warn_non_covariant_ret_types;
2409 ? diag::note_previous_declaration
2410 : diag::note_previous_definition)
2420 bool IsProtocolMethodDecl,
2421 bool IsOverridingMode,
2423 if (IsProtocolMethodDecl &&
2427 if (IsOverridingMode)
2429 diag::warn_conflicting_overriding_param_modifiers)
2433 diag::warn_conflicting_param_modifiers)
2445 if (Warn && IsOverridingMode &&
2449 diag::warn_conflicting_nullability_attr_overriding_param_types)
2466 IsOverridingMode ? diag::warn_conflicting_overriding_param_types
2467 : diag::warn_conflicting_param_types;
2483 IsOverridingMode ? diag::warn_non_contravariant_overriding_param_types
2484 : diag::warn_non_contravariant_param_types;
2490 << MethodImpl->
getDeclName() << IfaceTy << ImplTy;
2492 (IsOverridingMode ? diag::note_previous_declaration
2493 : diag::note_previous_definition))
2504 if (implFamily == declFamily)
return false;
2516 unsigned errorID = diag::err_arc_lost_method_convention;
2517 unsigned noteID = diag::note_arc_lost_method_convention;
2520 family = implFamily;
2521 errorID = diag::err_arc_gained_method_convention;
2522 noteID = diag::note_arc_gained_method_convention;
2526 enum FamilySelector {
2527 F_alloc, F_copy, F_mutableCopy = F_copy, F_init, F_new
2529 FamilySelector familySelector = FamilySelector();
2532 case OMF_None: llvm_unreachable(
"logic error, no method convention");
2546 case OMF_init: familySelector = F_init;
break;
2547 case OMF_alloc: familySelector = F_alloc;
break;
2548 case OMF_copy: familySelector = F_copy;
break;
2550 case OMF_new: familySelector = F_new;
break;
2553 enum ReasonSelector { R_NonObjectReturn, R_UnrelatedReturn };
2554 ReasonSelector reasonSelector;
2559 reasonSelector = R_UnrelatedReturn;
2561 reasonSelector = R_NonObjectReturn;
2565 S.
Diag(
decl->getLocation(), noteID) <<
int(familySelector) <<
int(reasonSelector);
2572 bool IsProtocolMethodDecl) {
2578 IsProtocolMethodDecl,
false,
2584 IM != EM && IF != EF; ++IM, ++IF) {
2586 IsProtocolMethodDecl,
false,
true);
2591 diag::warn_conflicting_variadic);
2598 bool IsProtocolMethodDecl) {
2601 IsProtocolMethodDecl,
true,
2607 IM != EM && IF != EF; ++IM, ++IF) {
2609 IsProtocolMethodDecl,
true,
true);
2614 diag::warn_conflicting_overriding_variadic);
2623 bool IsProtocolMethodDecl) {
2631 if (MethodDecl->
hasAttr<UnavailableAttr>() ||
2632 MethodDecl->
hasAttr<DeprecatedAttr>())
2636 IsProtocolMethodDecl,
false,
false);
2641 IM != EM && IF != EF; ++IM, ++IF) {
2644 IsProtocolMethodDecl,
false,
false);
2656 diag::warn_category_method_impl_match);
2673 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>())
2675 for (
const auto *PI : PDecl->
protocols())
2701 : dyn_cast<ObjCInterfaceDecl>(CDecl);
2702 assert (IDecl &&
"CheckProtocolMethodDefs - IDecl is null");
2718 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>()) {
2719 if (!ProtocolsExplictImpl) {
2741 if (InsMap.count(fISelector))
2761 !method->isPropertyAccessor() &&
2762 !InsMap.count(method->getSelector()) &&
2782 if (C || MethodInClass->isPropertyAccessor())
2784 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2793 !ClsMap.count(method->getSelector()) &&
2806 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2815 ProtocolsExplictImpl);
2827 bool &IncompleteImpl,
2828 bool ImmediateClass,
2829 bool WarnCategoryMethodImpl) {
2833 if (!InsMapSeen.insert(I->getSelector()).second)
2835 if (!I->isPropertyAccessor() &&
2836 !InsMap.count(I->getSelector())) {
2839 diag::warn_undef_method_impl);
2845 "Expected to find the method through lookup as well");
2847 if (ImpMethodDecl) {
2851 if (!WarnCategoryMethodImpl)
2853 isa<ObjCProtocolDecl>(CDecl));
2854 else if (!I->isPropertyAccessor())
2863 if (!ClsMapSeen.insert(I->getSelector()).second)
2865 if (!I->isPropertyAccessor() &&
2866 !ClsMap.count(I->getSelector())) {
2869 diag::warn_undef_method_impl);
2874 "Expected to find the method through lookup as well");
2876 if (ImpMethodDecl) {
2880 if (!WarnCategoryMethodImpl)
2882 isa<ObjCProtocolDecl>(CDecl));
2883 else if (!I->isPropertyAccessor())
2892 for (
auto *PI : PD->protocols())
2894 IMPDecl, PI, IncompleteImpl,
false,
2895 WarnCategoryMethodImpl);
2902 if (!WarnCategoryMethodImpl) {
2903 for (
auto *Cat : I->visible_categories())
2905 IMPDecl, Cat, IncompleteImpl,
2906 ImmediateClass && Cat->IsClassExtension(),
2907 WarnCategoryMethodImpl);
2910 for (
auto *Ext : I->visible_extensions())
2912 IMPDecl, Ext, IncompleteImpl,
false,
2913 WarnCategoryMethodImpl);
2917 for (
auto *PI : I->all_referenced_protocols())
2919 IMPDecl, PI, IncompleteImpl,
false,
2920 WarnCategoryMethodImpl);
2924 if (!WarnCategoryMethodImpl && I->getSuperClass())
2927 I->getSuperClass(), IncompleteImpl,
false);
2958 if (SuperIDecl && SuperIDecl->
lookupMethod(Sel,
false))
2962 if (InsMap.empty() && ClsMap.empty())
2966 bool IncompleteImpl =
false;
2969 IncompleteImpl,
false,
2975 bool IncompleteImpl) {
2980 InsMap.insert(I->getSelector());
2988 const auto *
P = PImpl->getPropertyDecl();
2991 InsMap.insert(
P->getGetterName());
2992 if (!
P->getSetterName().isNull())
2993 InsMap.insert(
P->getSetterName());
3000 bool SynthesizeProperties =
LangOpts.ObjCDefaultSynthProperties &&
3002 !IDecl->isObjCRequiresPropertyDefs();
3011 ClsMap.insert(I->getSelector());
3018 IncompleteImpl,
true);
3023 dyn_cast<ObjCCategoryImplDecl>(IMPDecl))
3034 for (
auto *PI : I->all_referenced_protocols())
3036 ClsMap, I, ExplicitImplProtocols);
3040 if (!C->IsClassExtension()) {
3041 for (
auto *
P : C->protocols())
3043 ClsMap, CDecl, ExplicitImplProtocols);
3048 llvm_unreachable(
"invalid ObjCContainerDecl type.");
3058 for (
unsigned i = 0; i != NumElts; ++i) {
3063 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
3073 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
3081 Diag(AtClassLoc, diag::warn_forward_class_redefinition)
3091 = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
3113 if (PrevIDecl && TypeParams) {
3117 *
this, PrevTypeParams, TypeParams,
3118 TypeParamListContext::ForwardDeclaration)) {
3119 TypeParams =
nullptr;
3123 Diag(IdentLocs[i], diag::err_objc_parameterized_forward_class)
3126 Diag(Def->getLocation(), diag::note_defined_here)
3129 TypeParams =
nullptr;
3135 ClassName, TypeParams, PrevIDecl,
3144 DeclsInGroup.push_back(IDecl);
3152 const Type *left,
const Type *right);
3161 if (left == right)
return true;
3184 if (isa<VectorType>(left))
return isa<VectorType>(right);
3185 if (isa<VectorType>(right))
return false;
3208 return (leftSK == rightSK);
3214 assert(lt && rt && lt != rt);
3216 if (!isa<RecordType>(lt) || !isa<RecordType>(rt))
return false;
3217 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3218 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3224 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3225 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3240 for (; li != le && ri != re; ++li, ++ri) {
3241 if (!
matchTypes(Context, strategy, li->getType(), ri->getType()))
3244 return (li == le && ri == re);
3265 (left->
hasAttr<NSReturnsRetainedAttr>()
3266 != right->
hasAttr<NSReturnsRetainedAttr>() ||
3267 left->
hasAttr<NSConsumesSelfAttr>()
3268 != right->
hasAttr<NSConsumesSelfAttr>()))
3275 for (; li != le && ri != re; ++li, ++ri) {
3276 assert(ri != right->
param_end() &&
"Param mismatch");
3283 lparm->
hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3291 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3292 auto *MethodInListProtocol =
3296 if ((MethodProtocol && !MethodInListProtocol) ||
3297 (!MethodProtocol && MethodInListProtocol))
3300 if (MethodProtocol && MethodInListProtocol)
3306 return MethodInterface == MethodInListInterface;
3315 if (!CD->IsClassExtension() && List->getBits() < 2)
3316 List->setBits(List->getBits() + 1);
3319 if (List->getMethod() ==
nullptr) {
3320 List->setMethod(Method);
3321 List->setNext(
nullptr);
3329 for (; List;
Previous = List, List = List->getNext()) {
3346 if (!SameDeclaration ||
3352 List->setHasMoreThanOneDecl(
true);
3357 !ListWithSameDeclaration && !List->getMethod()->isDeprecated())
3358 ListWithSameDeclaration = List;
3361 !ListWithSameDeclaration &&
3363 ListWithSameDeclaration = List;
3377 List->setHasMoreThanOneDecl(
true);
3384 List->setMethod(Method);
3390 List->setMethod(Method);
3401 if (ListWithSameDeclaration) {
3404 ListWithSameDeclaration->
setMethod(Method);
3405 ListWithSameDeclaration->
setNext(List);
3415 assert(ExternalSource &&
"We need an external AST source");
3420 if (!ExternalSource)
3425 void Sema::AddMethodToGlobalPool(
ObjCMethodDecl *Method,
bool impl,
3443 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3480 assert(BoundInterface &&
"unexpected object type!");
3484 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3485 if (MethodProtocol) {
3495 return MethodInterface == BoundInterface ||
3496 MethodInterface->isSuperClassOf(BoundInterface) ||
3497 BoundInterface->isSuperClassOf(MethodInterface);
3499 llvm_unreachable(
"unknown method context");
3506 bool InstanceFirst,
bool CheckTheOther,
3519 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3521 Methods.push_back(M->getMethod());
3525 if (!Methods.empty())
3526 return Methods.size() > 1;
3535 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3537 Methods.push_back(M->getMethod());
3540 return Methods.size() > 1;
3548 FilteredMethods.push_back(BestMethod);
3550 for (
auto *M : Methods)
3551 if (M != BestMethod && !M->
hasAttr<UnavailableAttr>())
3552 FilteredMethods.push_back(M);
3554 if (FilteredMethods.size() > 1)
3569 bool receiverIdOrClass,
3579 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3582 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3583 return M->getMethod();
3590 bool receiverIdOrClass) {
3592 bool issueDiagnostic =
false, issueError =
false;
3596 bool strictSelectorMatch =
3597 receiverIdOrClass &&
3599 if (strictSelectorMatch) {
3600 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3602 issueDiagnostic =
true;
3611 if (!strictSelectorMatch ||
3612 (issueDiagnostic &&
getLangOpts().ObjCAutoRefCount))
3613 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3617 issueDiagnostic =
true;
3624 if (issueDiagnostic) {
3626 Diag(R.
getBegin(), diag::err_arc_multiple_method_decl) << Sel << R;
3627 else if (strictSelectorMatch)
3628 Diag(R.getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
3630 Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
3632 Diag(Methods[0]->getBeginLoc(),
3633 issueError ? diag::note_possibility : diag::note_using)
3634 << Methods[0]->getSourceRange();
3635 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3636 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3637 << Methods[I]->getSourceRange();
3649 Method = Method->getNext())
3650 if (Method->getMethod() &&
3653 return Method->getMethod();
3656 Method = Method->getNext())
3657 if (Method->getMethod() &&
3660 return Method->getMethod();
3668 const unsigned MaxEditDistance = 1;
3669 unsigned BestEditDistance = MaxEditDistance + 1;
3672 unsigned MinPossibleEditDistance =
abs((
int)MethodName.size() - (
int)Typo.size());
3673 if (MinPossibleEditDistance > 0 &&
3674 Typo.size() / MinPossibleEditDistance < 1)
3676 unsigned EditDistance = Typo.edit_distance(MethodName,
true, MaxEditDistance);
3677 if (EditDistance > MaxEditDistance)
3679 if (EditDistance == BestEditDistance)
3680 BestMethod.push_back(Method);
3681 else if (EditDistance < BestEditDistance) {
3683 BestMethod.push_back(Method);
3702 bool ObjectIsId =
true, ObjectIsClass =
true;
3704 ObjectIsId = ObjectIsClass =
false;
3709 ObjectType =
QualType(ObjCPtr->getInterfaceType(), 0);
3710 ObjectIsId = ObjectIsClass =
false;
3713 ObjectIsClass =
false;
3723 if (M->getMethod() &&
3724 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3725 (M->getMethod()->getSelector() != Sel)) {
3727 Methods.push_back(M->getMethod());
3728 else if (!ObjectIsClass &&
3731 Methods.push_back(M->getMethod());
3735 if (M->getMethod() &&
3736 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3737 (M->getMethod()->getSelector() != Sel)) {
3739 Methods.push_back(M->getMethod());
3740 else if (!ObjectIsId &&
3743 Methods.push_back(M->getMethod());
3748 for (
unsigned i = 0, e = Methods.size(); i < e; i++) {
3752 return (SelectedMethods.size() == 1) ? SelectedMethods[0] :
nullptr;
3762 for (
auto *Ivar :
ID->ivars()) {
3763 if (Ivar->isInvalidDecl())
3768 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3770 Ivar->setInvalidDecl();
3780 for (
auto ivar =
ID->getClassInterface()->all_declared_ivar_begin();
3781 ivar; ivar = ivar->getNextIvar()) {
3782 if (ivar->isInvalidDecl())
continue;
3785 S.
Diag(ivar->getLocation(), diag::err_arc_weak_disabled);
3787 S.
Diag(ivar->getLocation(), diag::err_arc_weak_no_runtime);
3799 for (
auto ivar =
ID->all_declared_ivar_begin(); ivar;
3800 ivar = ivar->getNextIvar()) {
3801 if (ivar->isInvalidDecl())
3807 S.
Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3808 ivar->setInvalidDecl();
3815 case Decl::ObjCInterface:
3817 case Decl::ObjCProtocol:
3819 case Decl::ObjCCategory:
3820 if (cast<ObjCCategoryDecl>(
CurContext)->IsClassExtension())
3823 case Decl::ObjCImplementation:
3825 case Decl::ObjCCategoryImpl:
3837 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3844 if ((IntfDecl = dyn_cast<ObjCInterfaceDecl>(OCD))) {
3845 Ivars = IntfDecl->
ivars();
3846 }
else if (
auto *ImplDecl = dyn_cast<ObjCImplementationDecl>(OCD)) {
3847 IntfDecl = ImplDecl->getClassInterface();
3848 Ivars = ImplDecl->
ivars();
3849 }
else if (
auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(OCD)) {
3850 if (CategoryDecl->IsClassExtension()) {
3851 IntfDecl = CategoryDecl->getClassInterface();
3852 Ivars = CategoryDecl->
ivars();
3857 if (!isa<ObjCInterfaceDecl>(OCD)) {
3858 for (
auto ivar : Ivars) {
3860 S.
Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3861 << ivar->getDeclName() << ivar->getType();
3873 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3876 bool IsInvalidIvar =
false;
3878 S.
Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3879 << ivar->getDeclName() << IvarTy
3881 IsInvalidIvar =
true;
3883 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3884 S.
Diag(ivar->getLocation(),
3885 diag::err_objc_variable_sized_type_not_at_end)
3886 << ivar->getDeclName() << IvarTy;
3887 IsInvalidIvar =
true;
3890 if (IsInvalidIvar) {
3891 S.
Diag(ivar->getNextIvar()->getLocation(),
3892 diag::note_next_ivar_declaration)
3893 << ivar->getNextIvar()->getSynthesize();
3894 ivar->setInvalidDecl();
3902 (Ivars.begin() == Ivars.end()) ?
nullptr : *Ivars.begin();
3905 while (SuperClass && SuperClass->
ivar_empty())
3913 diag::warn_superclass_variable_sized_type_not_at_end)
3928 const llvm::iterator_range<ObjCProtocolList::iterator> &Protocols) {
3929 for (
auto *PI : Protocols)
3940 for (
auto *MD : PDecl->
methods()) {
3941 if (!MD->isPropertyAccessor()) {
3942 if (
const auto *CMD =
3943 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3944 if (CMD->isDirectMethod())
3945 DirectMembers.push_back(CMD);
3950 if (
const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3951 PD->getIdentifier(),
3952 PD->isClassProperty()
3955 if (CPD->isDirectProperty())
3956 DirectMembers.push_back(CPD);
3959 if (!DirectMembers.empty()) {
3960 S.
Diag(CDecl->
getLocation(), diag::err_objc_direct_protocol_conformance)
3962 for (
const auto *MD : DirectMembers)
3963 S.
Diag(MD->getLocation(), diag::note_direct_member_here);
3978 assert(AtEnd.
isValid() &&
"Invalid location for '@end'");
3980 auto *OCD = cast<ObjCContainerDecl>(
CurContext);
3981 Decl *ClassDecl = OCD;
3983 bool isInterfaceDeclKind =
3984 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
3985 || isa<ObjCProtocolDecl>(ClassDecl);
3986 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
3992 if (
auto *OID = dyn_cast<ObjCImplementationDecl>(
CurContext)) {
3993 for (
auto PropImpl : OID->property_impls()) {
3994 if (
auto *Getter = PropImpl->getGetterMethodDecl())
3995 if (Getter->isSynthesizedAccessorStub())
3996 OID->addDecl(Getter);
3997 if (
auto *Setter = PropImpl->getSetterMethodDecl())
3998 if (Setter->isSynthesizedAccessorStub())
3999 OID->addDecl(Setter);
4004 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
4005 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
4007 for (
unsigned i = 0, e = allMethods.size(); i != e; i++ ) {
4009 cast_or_null<ObjCMethodDecl>(allMethods[i]);
4011 if (!Method)
continue;
4017 if ((isInterfaceDeclKind && PrevMethod && !
match)
4018 || (checkIdenticalMethods &&
match)) {
4041 if ((isInterfaceDeclKind && PrevMethod && !
match)
4042 || (checkIdenticalMethods &&
match)) {
4061 if (isa<ObjCInterfaceDecl>(ClassDecl)) {
4068 if (C->IsClassExtension()) {
4076 if (CDecl->getIdentifier())
4080 for (
auto *I : CDecl->properties())
4082 CDecl->setAtEndRange(AtEnd);
4085 IC->setAtEndRange(AtEnd);
4092 for (
const auto *Ext : IDecl->visible_extensions()) {
4093 for (
const auto *
Property : Ext->instance_properties()) {
4096 = IC->FindPropertyImplDecl(
Property->getIdentifier(),
4098 if (PIDecl->getPropertyImplementation()
4102 for (
const auto *Ext : IDecl->visible_extensions()) {
4104 Ext->getInstanceMethod(
Property->getGetterName()))
4105 GetterMethod->setPropertyAccessor(
true);
4108 = Ext->getInstanceMethod(
Property->getSetterName()))
4109 SetterMethod->setPropertyAccessor(
true);
4117 if (IDecl->hasDesignatedInitializers())
4122 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4123 if (IDecl->getSuperClass() ==
nullptr) {
4126 if (!HasRootClassAttr) {
4129 Diag(DeclLoc, diag::warn_objc_root_class_missing)
4130 << IDecl->getIdentifier();
4138 Diag(SuperClassLoc, diag::note_objc_needs_superclass)
4141 Diag(SuperClassLoc, diag::note_objc_needs_superclass);
4144 }
else if (HasRootClassAttr) {
4146 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4154 if (IDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4155 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4156 Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
4157 Diag(Super->getLocation(), diag::note_class_declared);
4161 if (IDecl->hasAttr<ObjCClassStubAttr>())
4162 Diag(IC->getLocation(), diag::err_implementation_of_class_stub);
4165 while (IDecl->getSuperClass()) {
4167 IDecl = IDecl->getSuperClass();
4173 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
4174 CatImplClass->setAtEndRange(AtEnd);
4180 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4184 }
else if (
const auto *IntfDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
4186 if (!IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4187 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4188 Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
4189 Diag(Super->getLocation(), diag::note_class_declared);
4193 if (IntfDecl->hasAttr<ObjCClassStubAttr>() &&
4194 !IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>())
4195 Diag(IntfDecl->getLocation(), diag::err_class_stub_subclassing_mismatch);
4198 if (isInterfaceDeclKind) {
4200 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4203 if (
VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
4204 if (!VDecl->hasExternalStorage())
4205 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4211 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4214 (*I)->setTopLevelDeclInObjCContainer();
4243 if (ResultObjectType->isObjCIdType() ||
4244 ResultObjectType->isObjCQualifiedIdType())
4249 = ResultObjectType->getInterfaceDecl()) {
4255 if (ResultClass->isSuperClassOf(CurrentClass))
4271 class OverrideSearch {
4303 dyn_cast<ObjCCategoryDecl>(container)) {
4304 searchFromContainer(container);
4306 searchFromContainer(Interface);
4308 searchFromContainer(container);
4312 typedef decltype(Overridden)::iterator iterator;
4313 iterator begin()
const {
return Overridden.begin(); }
4314 iterator end()
const {
return Overridden.end(); }
4321 #define OBJCCONTAINER(type, base) \
4323 searchFrom(cast<type##Decl>(container)); \
4325 #define ABSTRACT_DECL(expansion)
4326 #define DECL(type, base) \
4328 #include "clang/AST/DeclNodes.inc"
4329 llvm_unreachable(
"not an ObjC container!");
4389 for (
const auto *Proto : protocols)
4401 Overridden.insert(meth);
4411 searchFromContainer(container);
4419 const auto *
attr = overridden->
getAttr<ObjCDirectAttr>();
4421 Diag(
attr->getLocation(), diag::note_previous_declaration);
4423 const auto *
attr = method->
getAttr<ObjCDirectAttr>();
4424 Diag(
attr->getLocation(), diag::err_objc_direct_on_override)
4436 OverrideSearch overrides(*
this, ObjCMethod);
4442 bool hasOverriddenMethodsInBaseOrProtocol =
false;
4444 if (!hasOverriddenMethodsInBaseOrProtocol) {
4445 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4446 CurrentClass != overridden->getClassInterface() ||
4447 overridden->isOverriding()) {
4449 hasOverriddenMethodsInBaseOrProtocol =
true;
4463 unsigned CategCount = List.getBits();
4464 if (CategCount > 0) {
4467 if (CategCount > 1 ||
4468 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4469 OverrideSearch overrides(*
this, overridden);
4471 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4472 CurrentClass != SuperOverridden->getClassInterface()) {
4474 hasOverriddenMethodsInBaseOrProtocol =
true;
4475 overridden->setOverriding(
true);
4492 if (ObjCMethod->
isImplicit() && overridden->isImplicit())
4499 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4501 if (CurrentClass && overridden->
getDeclContext() != CurrentClass &&
4502 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4507 PrevE = overridden->param_end();
4508 for (; ParamI != E && PrevI != PrevE; ++ParamI, ++PrevI) {
4509 assert(PrevI != overridden->param_end() &&
"Param mismatch");
4515 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4517 Diag(overridden->getLocation(), diag::note_previous_declaration);
4524 ObjCMethod->
setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4534 bool prevUsesCSKeyword) {
4536 auto nullability =
type->getNullability(S.
Context);
4540 if (nullability.has_value() == prevNullability.has_value()) {
4546 if (*nullability == *prevNullability)
4550 S.
Diag(loc, diag::err_nullability_conflicting)
4573 if (prevMethod->
hasAttr<ObjCRequiresSuperAttr>() &&
4574 !method->
hasAttr<ObjCRequiresSuperAttr>()) {
4577 ObjCRequiresSuperAttr::CreateImplicit(S.
Context,
4594 unsigned numPrevParams = prevMethod->
param_size();
4595 for (
unsigned i = 0, n =
std::min(numParams, numPrevParams); i != n; ++i) {
4615 llvm::Triple::x86 &&
4616 "x86-specific check invoked for a different target");
4620 if (
P->getType()->isVectorType()) {
4621 Loc =
P->getBeginLoc();
4637 VersionTuple AcceptedInVersion;
4638 if (Triple.getOS() == llvm::Triple::IOS)
4639 AcceptedInVersion = VersionTuple(9);
4640 else if (Triple.isMacOSX())
4641 AcceptedInVersion = VersionTuple(10, 11);
4647 SemaRef.
Diag(Loc, diag::err_objc_method_unsupported_param_ret_type)
4650 << (Triple.isMacOSX() ?
"macOS 10.11" :
"iOS 9");
4655 CD->
hasAttr<ObjCDirectMembersAttr>()) {
4666 bool diagnosed =
false;
4669 if (diagnosed || IMD->isImplicit())
4675 S.
Diag(IMD->getLocation(), diag::note_previous_declaration);
4693 if (
auto *IMD = IDecl->
getMethod(Sel, isInstance))
4696 if (Impl != ImpDecl)
4701 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4703 else if (
auto CatImpl = Cat->getImplementation())
4704 if (CatImpl != ImpDecl)
4705 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4718 bool isVariadic,
bool MethodDefinition) {
4721 Diag(MethodLoc, diag::err_missing_method_context);
4728 bool HasRelatedResultType =
false;
4736 QualType bareResultType = resultDeclType;
4741 Diag(MethodLoc, diag::warn_missing_method_return_type)
4747 MethodType == tok::minus, isVariadic,
4752 HasRelatedResultType);
4756 for (
unsigned i = 0, e = Sel.
getNumArgs(); i != e; ++i) {
4760 if (!ArgInfo[i].
Type) {
4767 LookupResult R(*
this, ArgInfo[i].Name, ArgInfo[i].NameLoc,
4772 if (S->isDeclScope(PrevDecl)) {
4773 Diag(ArgInfo[i].NameLoc,
4774 (MethodDefinition ? diag::warn_method_param_redefinition
4775 : diag::warn_method_param_declaration))
4778 diag::note_previous_declaration);
4787 ArgInfo[i].NameLoc, ArgInfo[i].Name,
4799 if (Param->
hasAttr<BlocksAttr>()) {
4806 Params.push_back(Param);
4809 for (
unsigned i = 0, e = CNumArgs; i != e; ++i) {
4810 ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
4811 QualType ArgType = Param->getType();
4818 Param->setDeclContext(ObjCMethod);
4819 Params.push_back(Param);
4831 if (
ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(ClassDecl)) {
4832 if (MethodType == tok::minus) {
4833 PrevMethod = ImpDecl->getInstanceMethod(Sel);
4834 ImpDecl->addInstanceMethod(ObjCMethod);
4836 PrevMethod = ImpDecl->getClassMethod(Sel);
4837 ImpDecl->addClassMethod(ObjCMethod);
4846 if (
auto *Setter = PropertyImpl->getSetterMethodDecl())
4847 if (Setter->getSelector() == Sel &&
4849 assert(Setter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4850 PropertyImpl->setSetterMethodDecl(ObjCMethod);
4852 if (
auto *Getter = PropertyImpl->getGetterMethodDecl())
4853 if (Getter->getSelector() == Sel &&
4855 assert(Getter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4856 PropertyImpl->setGetterMethodDecl(ObjCMethod);
4870 const auto *
attr = CanonicalMD->
getAttr<ObjCDirectAttr>();
4872 ObjCDirectAttr::CreateImplicit(
Context,
attr->getLocation()));
4879 if (
auto *IMD = IDecl->lookupMethod(ObjCMethod->
getSelector(),
4899 if (IDecl == IMD->getClassInterface()) {
4900 auto diagContainerMismatch = [&] {
4901 int decl = 0, impl = 0;
4903 if (
auto *Cat = dyn_cast<ObjCCategoryDecl>(IMD->getDeclContext()))
4904 decl = Cat->IsClassExtension() ? 1 : 2;
4906 if (isa<ObjCCategoryImplDecl>(ImpDecl))
4907 impl = 1 + (
decl != 0);
4910 diag::err_objc_direct_impl_decl_mismatch)
4912 Diag(IMD->getLocation(), diag::note_previous_declaration);
4916 const auto *
attr = ObjCMethod->
getAttr<ObjCDirectAttr>();
4918 diagContainerMismatch();
4919 }
else if (!IMD->isDirectMethod()) {
4920 Diag(
attr->getLocation(), diag::err_objc_direct_missing_on_decl);
4921 Diag(IMD->getLocation(), diag::note_previous_declaration);
4923 }
else if (IMD->isDirectMethod()) {
4924 const auto *
attr = IMD->getAttr<ObjCDirectAttr>();
4926 diagContainerMismatch();
4929 ObjCDirectAttr::CreateImplicit(
Context,
attr->getLocation()));
4935 if (isa<ObjCCategoryImplDecl>(ImpDecl) && IMD->isOverriding() &&
4948 for (
auto *C : IDecl->visible_categories())
4949 for (
auto &
P : C->protocols())
4950 if (
auto *IMD =
P->lookupMethod(ObjCMethod->
getSelector(),
4953 IMD->parameters().size() &&
4954 "Methods have different number of parameters");
4955 auto OI = IMD->param_begin(), OE = IMD->param_end();
4957 for (; OI != OE; ++OI, ++NI)
4962 if (!isa<ObjCProtocolDecl>(ClassDecl)) {
4967 IDecl = cast<ObjCCategoryDecl>(ClassDecl)->getClassInterface();
4975 cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
4991 if (!CurrentClass) {
4993 CurrentClass = Cat->getClassInterface();
4994 else if (
ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(ClassDecl))
4995 CurrentClass = Impl->getClassInterface();
4997 = dyn_cast<ObjCCategoryImplDecl>(ClassDecl))
4998 CurrentClass = CatImpl->getClassInterface();
5006 bool ARCError =
false;
5013 LangOpts.ObjCInferRelatedResultType) {
5014 bool InferRelatedResultType =
false;
5040 if (InferRelatedResultType &&
5045 if (MethodDefinition &&
5051 if (
const auto *
attr = ObjCMethod->
getAttr<AvailabilityAttr>()) {
5054 Diag(
attr->getLocation(), diag::warn_availability_on_static_initializer)
5056 ObjCMethod->
dropAttr<AvailabilityAttr>();
5079 Diag(D->
getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);
5093 Diag(DeclStart, diag::err_undef_interface) << ClassName;
5097 Diag(DeclStart, diag::err_atdef_nonfragile_interface);
5105 for (
unsigned i = 0; i < Ivars.size(); i++) {
5107 RecordDecl *Record = dyn_cast<RecordDecl>(TagD);
5111 ID->getIdentifier(),
ID->getType(),
5113 Decls.push_back(FD);
5118 D != Decls.end(); ++D) {
5122 else if (
RecordDecl *Record = dyn_cast<RecordDecl>(TagD))
5123 Record->addDecl(FD);
5138 Diag(IdLoc, diag::err_arg_with_address_space);
5150 Diag(IdLoc, diag::err_illegal_qualifiers_on_catch_parm);
5155 Diag(IdLoc, diag::err_catch_param_not_objc_type);
5158 Diag(IdLoc, diag::err_catch_param_not_objc_type);
5191 diag::err_invalid_thread)
5225 if (New->
hasAttr<BlocksAttr>())
5238 Ivars.push_back(Iv);
5244 if (ExternalSource) {
5247 for (
unsigned I = 0, N = Sels.size(); I != N; ++I)
5258 Selector Sel = SelectorAndLocation.first;
5261 Diag(Loc, diag::warn_unimplemented_selector) << Sel;
5284 IV->getIdentifier());
5293 class UnusedBackingIvarChecker :
5300 bool InvokedSelfMethod;
5304 : S(S), Method(Method), IvarD(IvarD),
5305 AccessedIvar(
false), InvokedSelfMethod(
false) {
5311 AccessedIvar =
true;
5320 InvokedSelfMethod =
true;
5329 if (S->hasUnrecoverableErrorOccurred())
5333 unsigned DIAG = diag::warn_unused_property_backing_ivar;
5343 if (CurMethod->isSynthesizedAccessorStub())
5346 UnusedBackingIvarChecker Checker(*
this, CurMethod, IV);
5347 Checker.TraverseStmt(CurMethod->getBody());
5348 if (Checker.AccessedIvar)
5355 if (!IV->
isReferenced() || !Checker.InvokedSelfMethod) {