31#include "llvm/ADT/DenseMap.h"
32#include "llvm/ADT/DenseSet.h"
65 assert(resultClass &&
"unexpected object type!");
70 if (receiverTypeIfCall.
isNull() &&
80 if (receiverTypeIfCall.
isNull())
87 if (!receiverClass)
return false;
90 assert(receiverClass &&
"method not associated with a class!");
104 if (receiverTypeIfCall.
isNull() &&
106 method->
addAttr(UnavailableAttr::CreateImplicit(Context,
"",
107 UnavailableAttr::IR_ARCInitReturnsUnrelated, loc));
112 Diag(loc, diag::err_arc_init_method_unrelated_result_type);
121 if (OldD->
hasAttr<NoEscapeAttr>() && !NewD->
hasAttr<NoEscapeAttr>()) {
122 S.
Diag(NewD->
getLocation(), diag::warn_overriding_method_missing_noescape);
159 CurrentClass = Cat->getClassInterface();
160 else if (
ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(DC))
161 CurrentClass = Impl->getClassInterface();
163 = dyn_cast<ObjCCategoryImplDecl>(DC))
164 CurrentClass = CatImpl->getClassInterface();
169 diag::warn_related_result_type_compatibility_class)
175 diag::warn_related_result_type_compatibility_protocol)
182 diag::note_related_result_type_family)
187 diag::note_related_result_type_overridden);
190 if ((NewMethod->
hasAttr<NSReturnsRetainedAttr>() !=
191 Overridden->
hasAttr<NSReturnsRetainedAttr>())) {
194 ? diag::err_nsreturns_retained_attribute_mismatch
195 : diag::warn_nsreturns_retained_attribute_mismatch)
199 if ((NewMethod->
hasAttr<NSReturnsNotRetainedAttr>() !=
200 Overridden->
hasAttr<NSReturnsNotRetainedAttr>())) {
203 ? diag::err_nsreturns_retained_attribute_mismatch
204 : diag::warn_nsreturns_retained_attribute_mismatch)
213 ni != ne && oi != oe; ++ni, ++oi) {
216 if (newDecl->
hasAttr<NSConsumedAttr>() !=
217 oldDecl->
hasAttr<NSConsumedAttr>()) {
220 ? diag::err_nsconsumed_attribute_mismatch
221 : diag::warn_nsconsumed_attribute_mismatch);
266 method->
addAttr(NSConsumesSelfAttr::CreateImplicit(Context));
270 if (method->
hasAttr<NSReturnsRetainedAttr>())
278 if (method->
hasAttr<NSReturnsRetainedAttr>() ||
279 method->
hasAttr<NSReturnsNotRetainedAttr>() ||
280 method->
hasAttr<NSReturnsAutoreleasedAttr>())
285 method->
addAttr(NSReturnsRetainedAttr::CreateImplicit(Context));
293 bool IsCategory =
false;
294 StringRef RealizedPlatform;
296 nullptr, VersionTuple(),
299 if (isa<ObjCMethodDecl>(ND)) {
302 if (RealizedPlatform.empty())
306 if (RealizedPlatform.ends_with(
"_app_extension"))
308 S.
Diag(ImplLoc, diag::warn_unavailable_def);
313 if (
const auto *CD = dyn_cast<ObjCCategoryDecl>(ND)) {
314 if (!CD->getClassInterface()->isDeprecated())
316 ND = CD->getClassInterface();
321 S.
Diag(ImplLoc, diag::warn_deprecated_def)
322 << (isa<ObjCMethodDecl>(ND)
324 : isa<ObjCCategoryDecl>(ND) || IsCategory ? 2
326 if (isa<ObjCMethodDecl>(ND))
331 << (isa<ObjCCategoryDecl>(ND) ?
"category" :
"class");
364 return !
T.getLocalQualifiers().hasObjCLifetime();
386 diag::err_func_def_incomplete_result))
408 if (!Param->isInvalidDecl() &&
getLangOpts().ObjCAutoRefCount &&
410 Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
413 if (Param->getIdentifier())
456 ImplDeclOfMethodDecl = OID->getImplementation();
457 else if (
ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(ContDeclOfMethodDecl)) {
458 if (CD->IsClassExtension()) {
460 ImplDeclOfMethodDecl = OID->getImplementation();
462 ImplDeclOfMethodDecl = CD->getImplementation();
466 if (!ImplDeclOfMethodDecl || ImplDeclOfMethodDecl != ImplDeclOfMethodDef)
474 IC->getSuperClass() !=
nullptr;
475 }
else if (IC->hasDesignatedInitializers()) {
501 (SuperMethod && SuperMethod->
hasAttr<ObjCRequiresSuperAttr>());
518 ObjCInterfaceValidatorCCC() : CurrentIDecl(nullptr) {}
520 : CurrentIDecl(IDecl) {}
522 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
527 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
528 return std::make_unique<ObjCInterfaceValidatorCCC>(*
this);
540 unsigned NumProtoRefs,
545 for (
unsigned i = 0; i < NumProtoRefs; ++i) {
566 ObjCInterfaceValidatorCCC CCC(IDecl);
571 << SuperName << ClassName);
577 Diag(SuperLoc, diag::err_recursive_superclass)
578 << SuperName << ClassName <<
SourceRange(AtInterfaceLoc, ClassLoc);
582 dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
586 if (SuperClassDecl) {
591 if (PrevDecl && !SuperClassDecl) {
595 dyn_cast_or_null<TypedefNameDecl>(PrevDecl)) {
599 SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl);
617 if (!SuperClassDecl) {
618 Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName;
623 if (!isa_and_nonnull<TypedefNameDecl>(PrevDecl)) {
625 Diag(SuperLoc, diag::err_undef_superclass)
626 << SuperName << ClassName <<
SourceRange(AtInterfaceLoc, ClassLoc);
628 SuperLoc, SuperClassType, diag::err_forward_superclass,
631 SuperClassDecl =
nullptr;
636 if (SuperClassType.
isNull()) {
637 assert(!SuperClassDecl &&
"Failed to set SuperClassType?");
643 if (!SuperTypeArgs.empty()) {
646 SuperTypeArgsRange.
getBegin(), SuperTypeArgs,
656 if (!SuperClassTInfo) {
673 if (parsedTypeBound) {
685 diag::err_objc_type_param_bound_missing_pointer)
686 << typeBound << paramName
705 diag::err_objc_type_param_bound_nonobject)
706 << typeBound << paramName;
709 typeBoundInfo =
nullptr;
718 bool diagnosed =
false;
722 rangeToRemove =
attr.getLocalSourceRange();
723 if (
attr.getTypePtr()->getImmediateNullability()) {
725 diag::err_objc_type_param_bound_explicit_nullability)
726 << paramName << typeBound
736 diag::err_objc_type_param_bound_qualified)
737 << paramName << typeBound
747 if (!quals.
empty()) {
757 if (!typeBoundInfo) {
764 varianceLoc, index, paramLoc, paramName,
765 colonLoc, typeBoundInfo);
777 typeParamsIn.size());
783 llvm::SmallDenseMap<IdentifierInfo *, ObjCTypeParamDecl *> knownParams;
784 for (
auto *typeParam : typeParams) {
785 auto known = knownParams.find(typeParam->getIdentifier());
786 if (known != knownParams.end()) {
787 Diag(typeParam->getLocation(), diag::err_objc_type_param_redecl)
788 << typeParam->getIdentifier()
791 typeParam->setInvalidDecl();
793 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");
990 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
991 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
1018 if (typeParamList) {
1022 TypeParamListContext::Definition)) {
1023 typeParamList =
nullptr;
1026 Diag(ClassLoc, diag::err_objc_parameterized_forward_class_first)
1028 Diag(prevTypeParamList->getLAngleLoc(), diag::note_previous_decl)
1033 for (
auto *typeParam : *prevTypeParamList) {
1039 typeParam->getUnderlyingType())));
1052 ClassName, typeParamList, PrevIDecl, ClassLoc);
1058 SkipBody->
New = IDecl;
1061 Diag(AtInterfaceLoc, diag::err_duplicate_class_def)
1063 Diag(Def->getLocation(), diag::note_previous_definition);
1091 ClassName, ClassLoc,
1092 SuperName, SuperLoc, SuperTypeArgs,
1093 SuperTypeArgsRange);
1101 NumProtoRefs, ProtoLocs);
1103 ProtoLocs, Context);
1126 if (
const TypedefNameDecl *TDecl = dyn_cast_or_null<TypedefNameDecl>(IDecl)) {
1127 QualType T = TDecl->getUnderlyingType();
1130 ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end());
1135 ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc);
1153 Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
1162 dyn_cast_or_null<TypedefNameDecl>(CDeclU)) {
1163 QualType T = TDecl->getUnderlyingType();
1166 ClassName = IDecl->getIdentifier();
1175 Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
1197 E = PList.
end(); I !=
E; ++I) {
1199 if (PDecl->getIdentifier() == PName) {
1200 Diag(Ploc, diag::err_protocol_has_circular_dependency);
1201 Diag(PrevLoc, diag::note_previous_definition);
1205 if (!PDecl->hasDefinition())
1209 PDecl->getLocation(), PDecl->getReferencedProtocols()))
1224 assert(ProtocolName &&
"Missing protocol identifier");
1234 ProtocolLoc, AtProtoInterfaceLoc,
1239 SkipBody->
New = PDecl;
1243 Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName;
1244 Diag(Def->getLocation(), diag::note_previous_definition);
1259 ProtocolName, ProtocolLoc, PrevDecl->
getLocation(), PList);
1264 ProtocolLoc, AtProtoInterfaceLoc,
1279 if (!err && NumProtoRefs ) {
1282 NumProtoRefs, ProtoLocs);
1284 ProtoLocs, Context);
1296 UndefinedProtocol = PDecl;
1302 UndefinedProtocol = PI;
1312 bool ForObjCContainer,
1325 PDiag(diag::err_undeclared_protocol_suggest)
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
1433 bool warnOnIncompleteProtocols) {
1437 unsigned numProtocolsResolved = 0;
1438 auto resolvedAsProtocols = [&] {
1439 assert(numProtocolsResolved == identifiers.size() &&
"Unresolved protocols");
1446 bool allAreTypeNames =
false;
1450 baseClass = objcObjectType->getInterface();
1453 if (typeParams->size() == numProtocolsResolved) {
1455 allAreTypeNames =
true;
1462 for (
unsigned i = 0, n = protocols.size(); i != n; ++i) {
1467 if (!warnOnIncompleteProtocols) {
1479 if (warnOnIncompleteProtocols &&
1481 Diag(identifierLocs[i], diag::warn_undef_protocolref)
1490 if (allAreTypeNames) {
1494 if (isa<ObjCInterfaceDecl>(
decl)) {
1496 firstClassNameLoc = identifierLocs[i];
1497 }
else if (!isa<TypeDecl>(
decl)) {
1499 allAreTypeNames =
false;
1502 allAreTypeNames =
false;
1511 if (allAreTypeNames && firstClassNameLoc.
isValid()) {
1514 bool allProtocolsDeclared =
true;
1515 for (
auto *proto : protocols) {
1517 allProtocolsDeclared =
false;
1522 if (allProtocolsDeclared) {
1523 Diag(firstClassNameLoc, diag::warn_objc_redundant_qualified_class_type)
1530 protocolLAngleLoc = lAngleLoc;
1531 protocolRAngleLoc = rAngleLoc;
1532 assert(protocols.size() == identifierLocs.size());
1536 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1538 protocols.push_back(proto);
1540 ++numProtocolsResolved;
1544 if (numProtocolsResolved == identifiers.size())
1545 return resolvedAsProtocols();
1551 typedef llvm::PointerUnion<TypeDecl *, ObjCInterfaceDecl *> TypeOrClassDecl;
1553 unsigned numTypeDeclsResolved = 0;
1554 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1558 typeDecls.push_back(TypeOrClassDecl());
1562 if (
auto typeDecl = dyn_cast<TypeDecl>(
decl)) {
1563 typeDecls.push_back(typeDecl);
1564 ++numTypeDeclsResolved;
1568 if (
auto objcClass = dyn_cast<ObjCInterfaceDecl>(
decl)) {
1569 typeDecls.push_back(objcClass);
1570 ++numTypeDeclsResolved;
1574 typeDecls.push_back(TypeOrClassDecl());
1581 auto resolveTypeReference = [&](TypeOrClassDecl typeDecl,
SourceLocation loc)
1585 const char* prevSpec;
1588 if (
auto *actualTypeDecl = typeDecl.dyn_cast<
TypeDecl *>())
1616 Diag(loc, diag::err_objc_type_arg_missing_star)
1627 auto resolvedAsTypeDecls = [&] {
1631 assert(numTypeDeclsResolved == identifiers.size() &&
"Unresolved type decl");
1633 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1635 TypeResult type = resolveTypeReference(typeDecls[i], identifierLocs[i]);
1636 if (!
type.isUsable()) {
1641 typeArgs.push_back(
type.get());
1644 typeArgsLAngleLoc = lAngleLoc;
1645 typeArgsRAngleLoc = rAngleLoc;
1650 if (numTypeDeclsResolved == identifiers.size())
1651 return resolvedAsTypeDecls();
1657 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1660 if (protocols[i] || typeDecls[i]) {
1666 if (protocols[i] && typeDecls[i])
1689 identifiers[i], identifierLocs[i],
1690 protocols[i] !=
nullptr);
1698 ObjCTypeArgOrProtocolValidatorCCC CCC(Context, lookupKind);
1706 PDiag(diag::err_undeclared_protocol_suggest)
1709 protocols[i] = proto;
1710 ++numProtocolsResolved;
1717 PDiag(diag::err_unknown_typename_suggest)
1720 typeDecls[i] = typeDecl;
1721 ++numTypeDeclsResolved;
1728 PDiag(diag::err_unknown_type_or_class_name_suggest)
1729 << identifiers[i] <<
true);
1731 typeDecls[i] = objcClass;
1732 ++numTypeDeclsResolved;
1738 Diag(identifierLocs[i],
1741 ? diag::err_undeclared_protocol
1742 : diag::err_unknown_typename))
1751 if (numProtocolsResolved == identifiers.size())
1752 return resolvedAsProtocols();
1755 assert(numTypeDeclsResolved == identifiers.size() &&
"Not all types?");
1756 return resolvedAsTypeDecls();
1767 llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
1768 for (
auto *MD : ID->methods())
1769 MethodMap[MD->getSelector()] = MD;
1771 if (MethodMap.empty())
1773 for (
const auto *Method : CAT->
methods()) {
1774 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
1778 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
1779 << Method->getDeclName();
1797 IdentPair.second, AtProtocolLoc, PrevDecl);
1808 DeclsInGroup.push_back(PDecl);
1818 Decl *
const *ProtoRefs,
unsigned NumProtoRefs,
1829 diag::err_category_forward_interface,
1830 CategoryName ==
nullptr)) {
1835 AtInterfaceLoc, ClassLoc, CategoryLoc,
1836 CategoryName, IDecl, typeParamList);
1841 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1847 Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName;
1849 diag::note_implementation_declared);
1857 Diag(CategoryLoc, diag::warn_dup_category_def)
1858 << ClassName << CategoryName;
1859 Diag(
Previous->getLocation(), diag::note_previous_definition);
1864 if (typeParamList) {
1867 SemaRef, prevTypeParamList, typeParamList,
1868 CategoryName ? TypeParamListContext::Category
1869 : TypeParamListContext::Extension))
1870 typeParamList =
nullptr;
1873 diag::err_objc_parameterized_category_nonclass)
1874 << (CategoryName !=
nullptr)
1878 typeParamList =
nullptr;
1883 ClassLoc, CategoryLoc, CategoryName, IDecl,
1896 NumProtoRefs, ProtoLocs);
1898 ProtoLocs, Context);
1902 NumProtoRefs, Context);
1927 ClassLoc, CatLoc, CatName, IDecl,
1935 ClassLoc, AtCatImplLoc, CatLoc);
1938 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1942 diag::err_undef_interface)) {
1954 if (IDecl && IDecl->
hasAttr<ObjCRuntimeVisibleAttr>()) {
1955 Diag(ClassLoc, diag::err_objc_runtime_visible_category)
1962 Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName
1965 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 Corrected,
PDiag(diag::warn_undef_interface_suggest) << ClassName,
2014 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
2020 if (SuperClassname) {
2025 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
2026 Diag(SuperClassLoc, diag::err_redefinition_different_kind)
2030 SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
2034 Diag(SuperClassLoc, diag::err_undef_superclass)
2035 << SuperClassname << ClassName;
2039 Diag(SuperClassLoc, diag::err_conflicting_super_class)
2055 nullptr, ClassLoc,
true);
2078 ClassLoc, AtClassImplLoc, SuperClassLoc);
2091 Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
2093 diag::note_previous_definition);
2107 Diag(ClassLoc, diag::err_objc_runtime_visible_subclass)
2120 DeclsInGroup.reserve(Decls.size() + 1);
2122 for (
unsigned i = 0, e = Decls.size(); i != e; ++i) {
2123 Decl *Dcl = Decls[i];
2128 DeclsInGroup.push_back(Dcl);
2131 DeclsInGroup.push_back(ObjCImpDecl);
2139 assert(ImpDecl &&
"missing implementation decl");
2150 for (
unsigned i = 0, e = numIvars; i != e; ++i) {
2167 assert(ivars &&
"missing @implementation ivars");
2171 for (
unsigned i = 0; i < numIvars; i++) {
2176 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2184 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
2201 for (; numIvars > 0 && IVI != IVE; ++IVI) {
2204 assert (ImplIvar &&
"missing implementation ivar");
2205 assert (ClsIvar &&
"missing class ivar");
2217 diag::err_conflicting_ivar_bitwidth)
2220 diag::note_previous_definition);
2232 Diag(ivars[j]->getLocation(), diag::err_inconsistent_ivar_count);
2233 else if (IVI != IVE)
2234 Diag(IVI->getLocation(), diag::err_inconsistent_ivar_count);
2262 std::string FixItStr;
2263 llvm::raw_string_ostream Out(FixItStr);
2274 S.
Diag(MethodLoc, diag::note_method_declared_at) << method;
2350 (y &
~Decl::OBJC_TQ_CSNullability);
2356 bool IsProtocolMethodDecl,
2357 bool IsOverridingMode,
2359 if (IsProtocolMethodDecl &&
2365 ? diag::warn_conflicting_overriding_ret_type_modifiers
2366 : diag::warn_conflicting_ret_type_modifiers))
2375 if (Warn && IsOverridingMode &&
2383 diag::warn_conflicting_nullability_attr_overriding_ret_types)
2400 IsOverridingMode ? diag::warn_conflicting_overriding_ret_types
2401 : diag::warn_conflicting_ret_types;
2417 IsOverridingMode ? diag::warn_non_covariant_overriding_ret_types
2418 : diag::warn_non_covariant_ret_types;
2427 ? diag::note_previous_declaration
2428 : diag::note_previous_definition)
2438 bool IsProtocolMethodDecl,
2439 bool IsOverridingMode,
2441 if (IsProtocolMethodDecl &&
2445 if (IsOverridingMode)
2447 diag::warn_conflicting_overriding_param_modifiers)
2451 diag::warn_conflicting_param_modifiers)
2463 if (Warn && IsOverridingMode &&
2467 diag::warn_conflicting_nullability_attr_overriding_param_types)
2482 IsOverridingMode ? diag::warn_conflicting_overriding_param_types
2483 : diag::warn_conflicting_param_types;
2499 IsOverridingMode ? diag::warn_non_contravariant_overriding_param_types
2500 : diag::warn_non_contravariant_param_types;
2506 << MethodImpl->
getDeclName() << IfaceTy << ImplTy;
2508 (IsOverridingMode ? diag::note_previous_declaration
2509 : diag::note_previous_definition))
2520 if (implFamily == declFamily)
return false;
2532 unsigned errorID = diag::err_arc_lost_method_convention;
2533 unsigned noteID = diag::note_arc_lost_method_convention;
2536 family = implFamily;
2537 errorID = diag::err_arc_gained_method_convention;
2538 noteID = diag::note_arc_gained_method_convention;
2542 enum FamilySelector {
2543 F_alloc, F_copy, F_mutableCopy = F_copy, F_init, F_new
2545 FamilySelector familySelector = FamilySelector();
2548 case OMF_None: llvm_unreachable(
"logic error, no method convention");
2562 case OMF_init: familySelector = F_init;
break;
2563 case OMF_alloc: familySelector = F_alloc;
break;
2564 case OMF_copy: familySelector = F_copy;
break;
2566 case OMF_new: familySelector = F_new;
break;
2569 enum ReasonSelector { R_NonObjectReturn, R_UnrelatedReturn };
2570 ReasonSelector reasonSelector;
2575 reasonSelector = R_UnrelatedReturn;
2577 reasonSelector = R_NonObjectReturn;
2581 S.
Diag(
decl->getLocation(), noteID) <<
int(familySelector) <<
int(reasonSelector);
2588 bool IsProtocolMethodDecl) {
2594 IsProtocolMethodDecl,
false,
true);
2599 IM != EM && IF != EF; ++IM, ++IF) {
2601 IsProtocolMethodDecl,
false,
true);
2606 diag::warn_conflicting_variadic);
2613 bool IsProtocolMethodDecl) {
2621 IM != EM && IF != EF; ++IM, ++IF) {
2623 IsProtocolMethodDecl,
true,
true);
2628 diag::warn_conflicting_overriding_variadic);
2637 bool IsProtocolMethodDecl) {
2647 if (MethodDecl->
hasAttr<UnavailableAttr>() ||
2648 MethodDecl->
hasAttr<DeprecatedAttr>())
2652 IsProtocolMethodDecl,
false,
false);
2657 IM != EM && IF != EF; ++IM, ++IF) {
2659 *IF, IsProtocolMethodDecl,
false,
false);
2671 diag::warn_category_method_impl_match);
2688 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>())
2690 for (
const auto *PI : PDecl->
protocols())
2716 : dyn_cast<ObjCInterfaceDecl>(CDecl);
2717 assert (IDecl &&
"CheckProtocolMethodDefs - IDecl is null");
2733 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>()) {
2734 if (!ProtocolsExplictImpl) {
2756 if (InsMap.count(fISelector))
2775 if (method->getImplementationControl() !=
2777 !method->isPropertyAccessor() &&
2778 !InsMap.count(method->getSelector()) &&
2780 method->getSelector(),
true ,
2793 method->getSelector(),
true ,
2795 if (
C || MethodInClass->isPropertyAccessor())
2797 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2805 if (method->getImplementationControl() !=
2807 !ClsMap.count(method->getSelector()) &&
2809 method->getSelector(),
false ,
2811 true ,
nullptr ))) {
2819 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2828 ProtocolsExplictImpl);
2838 bool WarnCategoryMethodImpl) {
2842 if (!InsMapSeen.insert(I->getSelector()).second)
2844 if (!I->isPropertyAccessor() &&
2845 !InsMap.count(I->getSelector())) {
2848 diag::warn_undef_method_impl);
2854 "Expected to find the method through lookup as well");
2856 if (ImpMethodDecl) {
2860 if (!WarnCategoryMethodImpl)
2862 isa<ObjCProtocolDecl>(CDecl));
2863 else if (!I->isPropertyAccessor())
2872 if (!ClsMapSeen.insert(I->getSelector()).second)
2874 if (!I->isPropertyAccessor() &&
2875 !ClsMap.count(I->getSelector())) {
2878 diag::warn_undef_method_impl);
2883 "Expected to find the method through lookup as well");
2885 if (ImpMethodDecl) {
2889 if (!WarnCategoryMethodImpl)
2891 isa<ObjCProtocolDecl>(CDecl));
2892 else if (!I->isPropertyAccessor())
2901 for (
auto *PI : PD->protocols())
2903 IMPDecl, PI, IncompleteImpl,
false,
2904 WarnCategoryMethodImpl);
2911 if (!WarnCategoryMethodImpl) {
2912 for (
auto *Cat : I->visible_categories())
2914 IMPDecl, Cat, IncompleteImpl,
2915 ImmediateClass && Cat->IsClassExtension(),
2916 WarnCategoryMethodImpl);
2919 for (
auto *Ext : I->visible_extensions())
2921 IMPDecl, Ext, IncompleteImpl,
false,
2922 WarnCategoryMethodImpl);
2926 for (
auto *PI : I->all_referenced_protocols())
2928 IMPDecl, PI, IncompleteImpl,
false,
2929 WarnCategoryMethodImpl);
2933 if (!WarnCategoryMethodImpl && I->getSuperClass())
2936 I->getSuperClass(), IncompleteImpl,
false);
2967 if (SuperIDecl && SuperIDecl->
lookupMethod(Sel,
false))
2971 if (InsMap.empty() && ClsMap.empty())
2975 bool IncompleteImpl =
false;
2978 IncompleteImpl,
false,
2984 bool IncompleteImpl) {
2989 InsMap.insert(I->getSelector());
2997 const auto *
P = PImpl->getPropertyDecl();
3000 InsMap.insert(
P->getGetterName());
3001 if (!
P->getSetterName().isNull())
3002 InsMap.insert(
P->getSetterName());
3009 bool SynthesizeProperties =
getLangOpts().ObjCDefaultSynthProperties &&
3011 !IDecl->isObjCRequiresPropertyDefs();
3020 ClsMap.insert(I->getSelector());
3027 IncompleteImpl,
true);
3032 dyn_cast<ObjCCategoryImplDecl>(IMPDecl))
3043 for (
auto *PI : I->all_referenced_protocols())
3045 ClsMap, I, ExplicitImplProtocols);
3049 if (!
C->IsClassExtension()) {
3050 for (
auto *
P :
C->protocols())
3052 ClsMap, CDecl, ExplicitImplProtocols);
3057 llvm_unreachable(
"invalid ObjCContainerDecl type.");
3066 for (
unsigned i = 0; i != NumElts; ++i) {
3071 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
3081 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
3089 Diag(AtClassLoc, diag::warn_forward_class_redefinition)
3099 = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
3121 if (PrevIDecl && TypeParams) {
3125 SemaRef, PrevTypeParams, TypeParams,
3126 TypeParamListContext::ForwardDeclaration)) {
3127 TypeParams =
nullptr;
3131 Diag(IdentLocs[i], diag::err_objc_parameterized_forward_class)
3134 Diag(Def->getLocation(), diag::note_defined_here)
3137 TypeParams =
nullptr;
3143 PrevIDecl, IdentLocs[i]);
3151 DeclsInGroup.push_back(IDecl);
3159 const Type *left,
const Type *right);
3169 if (left == right)
return true;
3193 if (isa<VectorType>(left))
return isa<VectorType>(right);
3194 if (isa<VectorType>(right))
return false;
3217 return (leftSK == rightSK);
3223 assert(lt && rt && lt != rt);
3225 if (!isa<RecordType>(lt) || !isa<RecordType>(rt))
return false;
3226 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3227 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3233 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3234 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3249 for (; li != le && ri != re; ++li, ++ri) {
3250 if (!
matchTypes(Context, strategy, li->getType(), ri->getType()))
3253 return (li == le && ri == re);
3275 (left->
hasAttr<NSReturnsRetainedAttr>()
3276 != right->
hasAttr<NSReturnsRetainedAttr>() ||
3277 left->
hasAttr<NSConsumesSelfAttr>()
3278 != right->
hasAttr<NSConsumesSelfAttr>()))
3285 for (; li != le && ri != re; ++li, ++ri) {
3286 assert(ri != right->
param_end() &&
"Param mismatch");
3293 lparm->
hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3301 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3302 auto *MethodInListProtocol =
3306 if ((MethodProtocol && !MethodInListProtocol) ||
3307 (!MethodProtocol && MethodInListProtocol))
3310 if (MethodProtocol && MethodInListProtocol)
3316 return MethodInterface == MethodInListInterface;
3325 if (!CD->IsClassExtension() && List->getBits() < 2)
3326 List->setBits(List->getBits() + 1);
3329 if (List->getMethod() ==
nullptr) {
3330 List->setMethod(Method);
3331 List->setNext(
nullptr);
3339 for (; List;
Previous = List, List = List->getNext()) {
3356 if (!SameDeclaration ||
3362 List->setHasMoreThanOneDecl(
true);
3367 !ListWithSameDeclaration && !List->getMethod()->isDeprecated())
3368 ListWithSameDeclaration = List;
3371 !ListWithSameDeclaration &&
3373 ListWithSameDeclaration = List;
3387 List->setHasMoreThanOneDecl(
true);
3394 List->setMethod(Method);
3400 List->setMethod(Method);
3411 if (ListWithSameDeclaration) {
3414 ListWithSameDeclaration->
setMethod(Method);
3415 ListWithSameDeclaration->
setNext(List);
3435void SemaObjC::AddMethodToGlobalPool(
ObjCMethodDecl *Method,
bool impl,
3453 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3490 assert(BoundInterface &&
"unexpected object type!");
3494 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3495 if (MethodProtocol) {
3505 return MethodInterface == BoundInterface ||
3506 MethodInterface->isSuperClassOf(BoundInterface) ||
3507 BoundInterface->isSuperClassOf(MethodInterface);
3509 llvm_unreachable(
"unknown method context");
3516 bool InstanceFirst,
bool CheckTheOther,
const ObjCObjectType *TypeBound) {
3528 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3530 Methods.push_back(M->getMethod());
3534 if (!Methods.empty())
3535 return Methods.size() > 1;
3544 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3546 Methods.push_back(M->getMethod());
3549 return Methods.size() > 1;
3557 FilteredMethods.push_back(BestMethod);
3559 for (
auto *M : Methods)
3560 if (M != BestMethod && !M->
hasAttr<UnavailableAttr>())
3561 FilteredMethods.push_back(M);
3563 if (FilteredMethods.size() > 1)
3578 bool receiverIdOrClass,
3588 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3591 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3592 return M->getMethod();
3599 bool receiverIdOrClass) {
3601 bool issueDiagnostic =
false, issueError =
false;
3605 bool strictSelectorMatch =
3606 receiverIdOrClass &&
3609 if (strictSelectorMatch) {
3610 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3612 issueDiagnostic =
true;
3621 if (!strictSelectorMatch ||
3622 (issueDiagnostic &&
getLangOpts().ObjCAutoRefCount))
3623 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3627 issueDiagnostic =
true;
3634 if (issueDiagnostic) {
3636 Diag(R.
getBegin(), diag::err_arc_multiple_method_decl) << Sel << R;
3637 else if (strictSelectorMatch)
3638 Diag(R.getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
3640 Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
3642 Diag(Methods[0]->getBeginLoc(),
3643 issueError ? diag::note_possibility : diag::note_using)
3644 << Methods[0]->getSourceRange();
3645 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3646 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3647 << Methods[I]->getSourceRange();
3659 Method = Method->getNext())
3660 if (Method->getMethod() &&
3663 return Method->getMethod();
3666 Method = Method->getNext())
3667 if (Method->getMethod() &&
3670 return Method->getMethod();
3678 const unsigned MaxEditDistance = 1;
3679 unsigned BestEditDistance = MaxEditDistance + 1;
3682 unsigned MinPossibleEditDistance =
abs((
int)MethodName.size() - (
int)Typo.size());
3683 if (MinPossibleEditDistance > 0 &&
3684 Typo.size() / MinPossibleEditDistance < 1)
3686 unsigned EditDistance = Typo.edit_distance(MethodName,
true, MaxEditDistance);
3687 if (EditDistance > MaxEditDistance)
3689 if (EditDistance == BestEditDistance)
3690 BestMethod.push_back(Method);
3691 else if (EditDistance < BestEditDistance) {
3693 BestMethod.push_back(Method);
3712 bool ObjectIsId =
true, ObjectIsClass =
true;
3714 ObjectIsId = ObjectIsClass =
false;
3719 ObjectType =
QualType(ObjCPtr->getInterfaceType(), 0);
3720 ObjectIsId = ObjectIsClass =
false;
3723 ObjectIsClass =
false;
3733 if (M->getMethod() &&
3734 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3735 (M->getMethod()->getSelector() != Sel)) {
3737 Methods.push_back(M->getMethod());
3738 else if (!ObjectIsClass &&
3740 SemaRef, M->getMethod()->getSelector(), ObjectType))
3741 Methods.push_back(M->getMethod());
3745 if (M->getMethod() &&
3746 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3747 (M->getMethod()->getSelector() != Sel)) {
3749 Methods.push_back(M->getMethod());
3750 else if (!ObjectIsId &&
3752 SemaRef, M->getMethod()->getSelector(), ObjectType))
3753 Methods.push_back(M->getMethod());
3758 for (
unsigned i = 0, e = Methods.size(); i < e; i++) {
3762 return (SelectedMethods.size() == 1) ? SelectedMethods[0] :
nullptr;
3772 for (
auto *Ivar : ID->ivars()) {
3773 if (Ivar->isInvalidDecl())
3778 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3780 Ivar->setInvalidDecl();
3790 for (
auto ivar = ID->getClassInterface()->all_declared_ivar_begin();
3791 ivar; ivar = ivar->getNextIvar()) {
3792 if (ivar->isInvalidDecl())
continue;
3795 S.
Diag(ivar->getLocation(), diag::err_arc_weak_disabled);
3797 S.
Diag(ivar->getLocation(), diag::err_arc_weak_no_runtime);
3809 for (
auto ivar = ID->all_declared_ivar_begin(); ivar;
3810 ivar = ivar->getNextIvar()) {
3811 if (ivar->isInvalidDecl())
3817 S.
Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3818 ivar->setInvalidDecl();
3825 case Decl::ObjCInterface:
3827 case Decl::ObjCProtocol:
3829 case Decl::ObjCCategory:
3833 case Decl::ObjCImplementation:
3835 case Decl::ObjCCategoryImpl:
3847 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3854 if ((IntfDecl = dyn_cast<ObjCInterfaceDecl>(OCD))) {
3855 Ivars = IntfDecl->
ivars();
3856 }
else if (
auto *ImplDecl = dyn_cast<ObjCImplementationDecl>(OCD)) {
3857 IntfDecl = ImplDecl->getClassInterface();
3858 Ivars = ImplDecl->
ivars();
3859 }
else if (
auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(OCD)) {
3860 if (CategoryDecl->IsClassExtension()) {
3861 IntfDecl = CategoryDecl->getClassInterface();
3862 Ivars = CategoryDecl->
ivars();
3867 if (!isa<ObjCInterfaceDecl>(OCD)) {
3868 for (
auto *ivar : Ivars) {
3870 S.
Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3871 << ivar->getDeclName() << ivar->getType();
3883 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3886 bool IsInvalidIvar =
false;
3888 S.
Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3889 << ivar->getDeclName() << IvarTy
3891 IsInvalidIvar =
true;
3893 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3894 S.
Diag(ivar->getLocation(),
3895 diag::err_objc_variable_sized_type_not_at_end)
3896 << ivar->getDeclName() << IvarTy;
3897 IsInvalidIvar =
true;
3900 if (IsInvalidIvar) {
3901 S.
Diag(ivar->getNextIvar()->getLocation(),
3902 diag::note_next_ivar_declaration)
3903 << ivar->getNextIvar()->getSynthesize();
3904 ivar->setInvalidDecl();
3912 (Ivars.begin() == Ivars.end()) ?
nullptr : *Ivars.begin();
3915 while (SuperClass && SuperClass->
ivar_empty())
3919 std::advance(IvarIter, SuperClass->
ivar_size() - 1);
3923 diag::warn_superclass_variable_sized_type_not_at_end)
3938 const llvm::iterator_range<ObjCProtocolList::iterator> &Protocols) {
3939 for (
auto *PI : Protocols)
3950 for (
auto *MD : PDecl->
methods()) {
3951 if (!MD->isPropertyAccessor()) {
3952 if (
const auto *CMD =
3953 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3954 if (CMD->isDirectMethod())
3955 DirectMembers.push_back(CMD);
3960 if (
const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3961 PD->getIdentifier(),
3962 PD->isClassProperty()
3965 if (CPD->isDirectProperty())
3966 DirectMembers.push_back(CPD);
3969 if (!DirectMembers.empty()) {
3970 S.
Diag(CDecl->
getLocation(), diag::err_objc_direct_protocol_conformance)
3972 for (
const auto *MD : DirectMembers)
3973 S.
Diag(MD->getLocation(), diag::note_direct_member_here);
3990 assert(AtEnd.
isValid() &&
"Invalid location for '@end'");
3993 Decl *ClassDecl = OCD;
3995 bool isInterfaceDeclKind =
3996 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
3997 || isa<ObjCProtocolDecl>(ClassDecl);
3998 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
4005 for (
auto *PropImpl : OID->property_impls()) {
4006 if (
auto *Getter = PropImpl->getGetterMethodDecl())
4007 if (Getter->isSynthesizedAccessorStub())
4008 OID->addDecl(Getter);
4009 if (
auto *Setter = PropImpl->getSetterMethodDecl())
4010 if (Setter->isSynthesizedAccessorStub())
4011 OID->addDecl(Setter);
4016 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
4017 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
4019 for (
unsigned i = 0, e = allMethods.size(); i != e; i++ ) {
4021 cast_or_null<ObjCMethodDecl>(allMethods[i]);
4023 if (!Method)
continue;
4029 if ((isInterfaceDeclKind && PrevMethod && !
match)
4030 || (checkIdenticalMethods &&
match)) {
4053 if ((isInterfaceDeclKind && PrevMethod && !
match)
4054 || (checkIdenticalMethods &&
match)) {
4073 if (isa<ObjCInterfaceDecl>(ClassDecl)) {
4080 if (
C->IsClassExtension()) {
4089 if (CDecl->getIdentifier())
4093 for (
auto *I : CDecl->properties())
4095 CDecl->setAtEndRange(AtEnd);
4098 IC->setAtEndRange(AtEnd);
4105 for (
const auto *Ext : IDecl->visible_extensions()) {
4106 for (
const auto *
Property : Ext->instance_properties()) {
4109 = IC->FindPropertyImplDecl(
Property->getIdentifier(),
4111 if (PIDecl->getPropertyImplementation()
4115 for (
const auto *Ext : IDecl->visible_extensions()) {
4117 Ext->getInstanceMethod(
Property->getGetterName()))
4118 GetterMethod->setPropertyAccessor(
true);
4121 = Ext->getInstanceMethod(
Property->getSetterName()))
4122 SetterMethod->setPropertyAccessor(
true);
4130 if (IDecl->hasDesignatedInitializers())
4135 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4136 if (IDecl->getSuperClass() ==
nullptr) {
4139 if (!HasRootClassAttr) {
4142 Diag(DeclLoc, diag::warn_objc_root_class_missing)
4143 << IDecl->getIdentifier();
4151 Diag(SuperClassLoc, diag::note_objc_needs_superclass)
4154 Diag(SuperClassLoc, diag::note_objc_needs_superclass);
4157 }
else if (HasRootClassAttr) {
4159 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4167 if (IDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4168 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4169 Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
4170 Diag(Super->getLocation(), diag::note_class_declared);
4174 if (IDecl->hasAttr<ObjCClassStubAttr>())
4175 Diag(IC->getLocation(), diag::err_implementation_of_class_stub);
4178 while (IDecl->getSuperClass()) {
4180 IDecl = IDecl->getSuperClass();
4186 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
4187 CatImplClass->setAtEndRange(AtEnd);
4193 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4197 }
else if (
const auto *IntfDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
4199 if (!IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4200 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4201 Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
4202 Diag(Super->getLocation(), diag::note_class_declared);
4206 if (IntfDecl->hasAttr<ObjCClassStubAttr>() &&
4207 !IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>())
4208 Diag(IntfDecl->getLocation(), diag::err_class_stub_subclassing_mismatch);
4211 if (isInterfaceDeclKind) {
4213 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4216 if (
VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
4217 if (!VDecl->hasExternalStorage())
4218 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4224 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4227 (*I)->setTopLevelDeclInObjCContainer();
4256 if (ResultObjectType->isObjCIdType() ||
4257 ResultObjectType->isObjCQualifiedIdType())
4262 = ResultObjectType->getInterfaceDecl()) {
4268 if (ResultClass->isSuperClassOf(CurrentClass))
4284class OverrideSearch {
4317 dyn_cast<ObjCCategoryDecl>(container)) {
4318 searchFromContainer(container);
4322 searchFromContainer(container);
4326 typedef decltype(Overridden)::iterator iterator;
4327 iterator begin()
const {
return Overridden.begin(); }
4328 iterator end()
const {
return Overridden.end(); }
4335#define OBJCCONTAINER(type, base) \
4337 searchFrom(cast<type##Decl>(container)); \
4339#define ABSTRACT_DECL(expansion)
4340#define DECL(type, base) \
4342#include "clang/AST/DeclNodes.inc"
4343 llvm_unreachable(
"not an ObjC container!");
4403 for (
const auto *Proto : protocols)
4415 Overridden.insert(meth);
4425 searchFromContainer(container);
4433 const auto *
attr = overridden->
getAttr<ObjCDirectAttr>();
4435 Diag(
attr->getLocation(), diag::note_previous_declaration);
4437 const auto *
attr = method->
getAttr<ObjCDirectAttr>();
4438 Diag(
attr->getLocation(), diag::err_objc_direct_on_override)
4450 auto IsMethodInCurrentClass = [CurrentClass](
const ObjCMethodDecl *M) {
4452 return M->getClassInterface()->getCanonicalDecl() ==
4456 OverrideSearch overrides(
SemaRef, ObjCMethod);
4462 bool hasOverriddenMethodsInBaseOrProtocol =
false;
4464 if (!hasOverriddenMethodsInBaseOrProtocol) {
4465 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4466 !IsMethodInCurrentClass(overridden) || overridden->isOverriding()) {
4468 hasOverriddenMethodsInBaseOrProtocol =
true;
4482 unsigned CategCount = List.getBits();
4483 if (CategCount > 0) {
4486 if (CategCount > 1 ||
4487 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4488 OverrideSearch overrides(
SemaRef, overridden);
4490 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4491 !IsMethodInCurrentClass(SuperOverridden)) {
4493 hasOverriddenMethodsInBaseOrProtocol =
true;
4494 overridden->setOverriding(
true);
4511 if (ObjCMethod->
isImplicit() && overridden->isImplicit())
4518 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4520 if (CurrentClass && overridden->
getDeclContext() != CurrentClass &&
4521 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4526 PrevE = overridden->param_end();
4527 for (; ParamI !=
E && PrevI != PrevE; ++ParamI, ++PrevI) {
4528 assert(PrevI != overridden->param_end() &&
"Param mismatch");
4534 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4536 Diag(overridden->getLocation(), diag::note_previous_declaration);
4543 ObjCMethod->
setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4553 bool prevUsesCSKeyword) {
4555 auto nullability =
type->getNullability();
4559 if (nullability.has_value() == prevNullability.has_value()) {
4565 if (*nullability == *prevNullability)
4569 S.
Diag(loc, diag::err_nullability_conflicting)
4592 if (prevMethod->
hasAttr<ObjCRequiresSuperAttr>() &&
4593 !method->
hasAttr<ObjCRequiresSuperAttr>()) {
4596 ObjCRequiresSuperAttr::CreateImplicit(S.
Context,
4613 unsigned numPrevParams = prevMethod->
param_size();
4614 for (
unsigned i = 0, n = std::min(numParams, numPrevParams); i != n; ++i) {
4634 llvm::Triple::x86 &&
4635 "x86-specific check invoked for a different target");
4639 if (
P->getType()->isVectorType()) {
4640 Loc =
P->getBeginLoc();
4656 VersionTuple AcceptedInVersion;
4657 if (Triple.getOS() == llvm::Triple::IOS)
4658 AcceptedInVersion = VersionTuple(9);
4659 else if (Triple.isMacOSX())
4660 AcceptedInVersion = VersionTuple(10, 11);
4666 SemaRef.
Diag(
Loc, diag::err_objc_method_unsupported_param_ret_type)
4669 << (Triple.isMacOSX() ?
"macOS 10.11" :
"iOS 9");
4674 CD->
hasAttr<ObjCDirectMembersAttr>()) {
4685 bool diagnosed =
false;
4688 if (diagnosed || IMD->isImplicit())
4694 S.
Diag(IMD->getLocation(), diag::note_previous_declaration);
4712 if (
auto *IMD = IDecl->
getMethod(Sel, isInstance))
4715 if (Impl != ImpDecl)
4720 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4722 else if (
auto CatImpl = Cat->getImplementation())
4723 if (CatImpl != ImpDecl)
4724 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4737 bool isVariadic,
bool MethodDefinition) {
4741 Diag(MethodLoc, diag::err_missing_method_context);
4748 bool HasRelatedResultType =
false;
4756 QualType bareResultType = resultDeclType;
4761 Diag(MethodLoc, diag::warn_missing_method_return_type)
4766 Context, MethodLoc, EndLoc, Sel, resultDeclType, ReturnTInfo,
4770 MethodDeclKind == tok::objc_optional
4773 HasRelatedResultType);
4777 for (
unsigned i = 0, e = Sel.
getNumArgs(); i != e; ++i) {
4781 if (!ArgInfo[i].
Type) {
4794 if (S->isDeclScope(PrevDecl)) {
4795 Diag(ArgInfo[i].NameLoc,
4796 (MethodDefinition ? diag::warn_method_param_redefinition
4797 : diag::warn_method_param_declaration))
4800 diag::note_previous_declaration);
4810 ArgInfo[i].Name, ArgType, DI,
SC_None);
4823 if (Param->
hasAttr<BlocksAttr>()) {
4830 Params.push_back(Param);
4833 for (
unsigned i = 0, e = CNumArgs; i != e; ++i) {
4834 ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
4843 Params.push_back(Param);
4856 if (
ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(ClassDecl)) {
4857 if (MethodType == tok::minus) {
4858 PrevMethod = ImpDecl->getInstanceMethod(Sel);
4859 ImpDecl->addInstanceMethod(ObjCMethod);
4861 PrevMethod = ImpDecl->getClassMethod(Sel);
4862 ImpDecl->addClassMethod(ObjCMethod);
4871 if (
auto *Setter = PropertyImpl->getSetterMethodDecl())
4872 if (Setter->getSelector() == Sel &&
4874 assert(Setter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4875 PropertyImpl->setSetterMethodDecl(ObjCMethod);
4877 if (
auto *Getter = PropertyImpl->getGetterMethodDecl())
4878 if (Getter->getSelector() == Sel &&
4880 assert(Getter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4881 PropertyImpl->setGetterMethodDecl(ObjCMethod);
4895 const auto *
attr = CanonicalMD->
getAttr<ObjCDirectAttr>();
4897 ObjCDirectAttr::CreateImplicit(Context,
attr->getLocation()));
4904 if (
auto *IMD = IDecl->lookupMethod(ObjCMethod->
getSelector(),
4924 if (IDecl == IMD->getClassInterface()) {
4925 auto diagContainerMismatch = [&] {
4926 int decl = 0, impl = 0;
4928 if (
auto *Cat = dyn_cast<ObjCCategoryDecl>(IMD->getDeclContext()))
4929 decl = Cat->IsClassExtension() ? 1 : 2;
4931 if (isa<ObjCCategoryImplDecl>(ImpDecl))
4932 impl = 1 + (
decl != 0);
4935 diag::err_objc_direct_impl_decl_mismatch)
4937 Diag(IMD->getLocation(), diag::note_previous_declaration);
4941 const auto *
attr = ObjCMethod->
getAttr<ObjCDirectAttr>();
4943 diagContainerMismatch();
4944 }
else if (!IMD->isDirectMethod()) {
4945 Diag(
attr->getLocation(), diag::err_objc_direct_missing_on_decl);
4946 Diag(IMD->getLocation(), diag::note_previous_declaration);
4948 }
else if (IMD->isDirectMethod()) {