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 (!dyn_cast_or_null<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()) {
726 Diag(attr.getBeginLoc(),
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,
777 reinterpret_cast<ObjCTypeParamDecl * const *>(typeParamsIn.data()),
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);
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) {
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 ||
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) {
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);
1120 if (
const TypedefNameDecl *TDecl = dyn_cast_or_null<TypedefNameDecl>(IDecl)) {
1121 QualType T = TDecl->getUnderlyingType();
1124 ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end());
1129 ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc);
1146 Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
1155 dyn_cast_or_null<TypedefNameDecl>(CDeclU)) {
1156 QualType T = TDecl->getUnderlyingType();
1159 ClassName = IDecl->getIdentifier();
1168 Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
1191 E = PList.
end(); I != E; ++I) {
1194 if (PDecl->getIdentifier() == PName) {
1195 Diag(Ploc, diag::err_protocol_has_circular_dependency);
1196 Diag(PrevLoc, diag::note_previous_definition);
1200 if (!PDecl->hasDefinition())
1204 PDecl->getLocation(), PDecl->getReferencedProtocols()))
1218 assert(ProtocolName &&
"Missing protocol identifier");
1224 Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName;
1225 Diag(Def->getLocation(), diag::note_previous_definition);
1232 ProtocolLoc, AtProtoInterfaceLoc,
1239 PDecl->startDefinition();
1247 ProtocolName, ProtocolLoc, PrevDecl->
getLocation(), PList);
1252 ProtocolLoc, AtProtoInterfaceLoc,
1266 if (!err && NumProtoRefs ) {
1269 NumProtoRefs, ProtoLocs);
1282 UndefinedProtocol = PDecl;
1288 UndefinedProtocol = PI;
1314 Diag(Pair.second, diag::err_undeclared_protocol) << Pair.first;
1323 if (!ForObjCContainer) {
1332 if (WarnOnDeclarations &&
1334 Diag(Pair.second, diag::warn_undef_protocolref) << Pair.first;
1335 Diag(UndefinedProtocol->
getLocation(), diag::note_protocol_decl_undefined)
1336 << UndefinedProtocol;
1338 Protocols.push_back(PDecl);
1345 class ObjCTypeArgOrProtocolValidatorCCC final
1350 ObjCTypeArgOrProtocolValidatorCCC(
ASTContext &context,
1352 : Context(context), LookupKind(lookupKind) { }
1354 bool ValidateCandidate(
const TypoCorrection &candidate)
override {
1368 if (isa<RecordDecl>(typeDecl) && !Context.
getLangOpts().CPlusPlus)
1374 if (
type->isObjCObjectPointerType() ||
1375 type->isBlockPointerType() ||
1376 type->isDependentType() ||
1377 type->isObjCObjectType())
1394 std::unique_ptr<CorrectionCandidateCallback> clone()
override {
1395 return std::make_unique<ObjCTypeArgOrProtocolValidatorCCC>(*
this);
1404 bool SelectProtocolFirst) {
1405 Diag(TypeArgLoc, diag::err_objc_type_args_and_protocols)
1406 << SelectProtocolFirst << TypeArgId << ProtocolId
1423 bool warnOnIncompleteProtocols) {
1426 unsigned numProtocolsResolved = 0;
1427 auto resolvedAsProtocols = [&] {
1428 assert(numProtocolsResolved == identifiers.size() &&
"Unresolved protocols");
1435 bool allAreTypeNames =
false;
1439 baseClass = objcObjectType->getInterface();
1441 if (
auto typeParams = baseClass->getTypeParamList()) {
1442 if (typeParams->size() == numProtocolsResolved) {
1444 allAreTypeNames =
true;
1451 for (
unsigned i = 0, n = protocols.size(); i != n; ++i) {
1453 = reinterpret_cast<ObjCProtocolDecl *&>(protocols[i]);
1456 if (!warnOnIncompleteProtocols) {
1468 if (warnOnIncompleteProtocols &&
1470 Diag(identifierLocs[i], diag::warn_undef_protocolref)
1479 if (allAreTypeNames) {
1482 if (isa<ObjCInterfaceDecl>(
decl)) {
1484 firstClassNameLoc = identifierLocs[i];
1485 }
else if (!isa<TypeDecl>(
decl)) {
1487 allAreTypeNames =
false;
1490 allAreTypeNames =
false;
1499 if (allAreTypeNames && firstClassNameLoc.
isValid()) {
1502 bool allProtocolsDeclared =
true;
1503 for (
auto proto : protocols) {
1504 if (knownProtocols.count(static_cast<ObjCProtocolDecl *>(proto)) == 0) {
1505 allProtocolsDeclared =
false;
1510 if (allProtocolsDeclared) {
1511 Diag(firstClassNameLoc, diag::warn_objc_redundant_qualified_class_type)
1512 << baseClass->getDeclName() <<
SourceRange(lAngleLoc, rAngleLoc)
1518 protocolLAngleLoc = lAngleLoc;
1519 protocolRAngleLoc = rAngleLoc;
1520 assert(protocols.size() == identifierLocs.size());
1524 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1526 protocols.push_back(proto);
1528 ++numProtocolsResolved;
1532 if (numProtocolsResolved == identifiers.size())
1533 return resolvedAsProtocols();
1539 typedef llvm::PointerUnion<TypeDecl *, ObjCInterfaceDecl *> TypeOrClassDecl;
1541 unsigned numTypeDeclsResolved = 0;
1542 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1546 typeDecls.push_back(TypeOrClassDecl());
1550 if (
auto typeDecl = dyn_cast<TypeDecl>(
decl)) {
1551 typeDecls.push_back(typeDecl);
1552 ++numTypeDeclsResolved;
1556 if (
auto objcClass = dyn_cast<ObjCInterfaceDecl>(
decl)) {
1557 typeDecls.push_back(objcClass);
1558 ++numTypeDeclsResolved;
1562 typeDecls.push_back(TypeOrClassDecl());
1569 auto resolveTypeReference = [&](TypeOrClassDecl typeDecl,
SourceLocation loc)
1573 const char* prevSpec;
1576 if (
auto *actualTypeDecl = typeDecl.dyn_cast<
TypeDecl *>())
1604 Diag(loc, diag::err_objc_type_arg_missing_star)
1615 auto resolvedAsTypeDecls = [&] {
1619 assert(numTypeDeclsResolved == identifiers.size() &&
"Unresolved type decl");
1621 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1623 TypeResult type = resolveTypeReference(typeDecls[i], identifierLocs[i]);
1624 if (!
type.isUsable()) {
1629 typeArgs.push_back(
type.get());
1632 typeArgsLAngleLoc = lAngleLoc;
1633 typeArgsRAngleLoc = rAngleLoc;
1638 if (numTypeDeclsResolved == identifiers.size())
1639 return resolvedAsTypeDecls();
1645 for (
unsigned i = 0, n = identifiers.size(); i != n; ++i) {
1648 if (protocols[i] || typeDecls[i]) {
1654 if (protocols[i] && typeDecls[i])
1677 identifiers[i], identifierLocs[i],
1678 protocols[i] !=
nullptr);
1686 ObjCTypeArgOrProtocolValidatorCCC CCC(
Context, lookupKind);
1694 PDiag(diag::err_undeclared_protocol_suggest)
1697 protocols[i] = proto;
1698 ++numProtocolsResolved;
1705 PDiag(diag::err_unknown_typename_suggest)
1708 typeDecls[i] = typeDecl;
1709 ++numTypeDeclsResolved;
1716 PDiag(diag::err_unknown_type_or_class_name_suggest)
1717 << identifiers[i] <<
true);
1719 typeDecls[i] = objcClass;
1720 ++numTypeDeclsResolved;
1726 Diag(identifierLocs[i],
1727 (lookupKind ==
LookupAnyName ? diag::err_objc_type_arg_missing
1729 : diag::err_unknown_typename))
1738 if (numProtocolsResolved == identifiers.size())
1739 return resolvedAsProtocols();
1742 assert(numTypeDeclsResolved == identifiers.size() &&
"Not all types?");
1743 return resolvedAsTypeDecls();
1754 llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
1755 for (
auto *MD :
ID->methods())
1756 MethodMap[MD->getSelector()] = MD;
1758 if (MethodMap.empty())
1760 for (
const auto *Method : CAT->
methods()) {
1761 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
1765 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
1766 << Method->getDeclName();
1784 IdentPair.second, AtProtocolLoc,
1796 DeclsInGroup.push_back(PDecl);
1806 Decl *
const *ProtoRefs,
unsigned NumProtoRefs,
1816 diag::err_category_forward_interface,
1817 CategoryName ==
nullptr)) {
1822 ClassLoc, CategoryLoc, CategoryName,
1823 IDecl, typeParamList);
1828 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1833 Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName;
1835 diag::note_implementation_declared);
1843 Diag(CategoryLoc, diag::warn_dup_category_def)
1844 << ClassName << CategoryName;
1845 Diag(
Previous->getLocation(), diag::note_previous_definition);
1850 if (typeParamList) {
1855 : TypeParamListContext::Extension))
1856 typeParamList =
nullptr;
1859 diag::err_objc_parameterized_category_nonclass)
1860 << (CategoryName !=
nullptr)
1864 typeParamList =
nullptr;
1869 ClassLoc, CategoryLoc, CategoryName, IDecl,
1882 NumProtoRefs, ProtoLocs);
1920 ClassLoc, AtCatImplLoc, CatLoc);
1923 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
1926 diag::err_undef_interface)) {
1938 if (IDecl && IDecl->
hasAttr<ObjCRuntimeVisibleAttr>()) {
1939 Diag(ClassLoc, diag::err_objc_runtime_visible_category)
1946 Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName
1949 diag::note_previous_definition);
1975 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
1976 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
1978 }
else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
1982 diag::warn_undef_interface);
1986 ObjCInterfaceValidatorCCC CCC{};
1995 PDiag(diag::warn_undef_interface_suggest) << ClassName,
1998 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
2004 if (SuperClassname) {
2008 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
2009 Diag(SuperClassLoc, diag::err_redefinition_different_kind)
2013 SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
2017 Diag(SuperClassLoc, diag::err_undef_superclass)
2018 << SuperClassname << ClassName;
2022 Diag(SuperClassLoc, diag::err_conflicting_super_class)
2061 ClassLoc, AtClassImplLoc, SuperClassLoc);
2072 Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
2074 diag::note_previous_definition);
2088 Diag(ClassLoc, diag::err_objc_runtime_visible_subclass)
2099 DeclsInGroup.reserve(Decls.size() + 1);
2101 for (
unsigned i = 0, e = Decls.size(); i != e; ++i) {
2102 Decl *Dcl = Decls[i];
2107 DeclsInGroup.push_back(Dcl);
2110 DeclsInGroup.push_back(ObjCImpDecl);
2118 assert(ImpDecl &&
"missing implementation decl");
2128 for (
unsigned i = 0, e = numIvars; i != e; ++i) {
2145 assert(ivars &&
"missing @implementation ivars");
2149 for (
unsigned i = 0; i < numIvars; i++) {
2154 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2162 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
2179 for (; numIvars > 0 && IVI != IVE; ++IVI) {
2182 assert (ImplIvar &&
"missing implementation ivar");
2183 assert (ClsIvar &&
"missing class ivar");
2195 diag::err_conflicting_ivar_bitwidth)
2198 diag::note_previous_definition);
2210 Diag(ivars[j]->getLocation(), diag::err_inconsistent_ivar_count);
2211 else if (IVI != IVE)
2212 Diag(IVI->getLocation(), diag::err_inconsistent_ivar_count);
2217 bool &IncompleteImpl,
2239 S.
Diag(MethodLoc, diag::note_method_declared_at) << method;
2315 (y & ~
Decl::OBJC_TQ_CSNullability);
2321 bool IsProtocolMethodDecl,
2322 bool IsOverridingMode,
2324 if (IsProtocolMethodDecl &&
2330 ? diag::warn_conflicting_overriding_ret_type_modifiers
2331 : diag::warn_conflicting_ret_type_modifiers))
2340 if (Warn && IsOverridingMode &&
2345 auto nullabilityMethodImpl =
2347 auto nullabilityMethodDecl =
2350 diag::warn_conflicting_nullability_attr_overriding_ret_types)
2352 nullabilityMethodImpl,
2356 nullabilityMethodDecl,
2369 IsOverridingMode ? diag::warn_conflicting_overriding_ret_types
2370 : diag::warn_conflicting_ret_types;
2386 IsOverridingMode ? diag::warn_non_covariant_overriding_ret_types
2387 : diag::warn_non_covariant_ret_types;
2396 ? diag::note_previous_declaration
2397 : diag::note_previous_definition)
2407 bool IsProtocolMethodDecl,
2408 bool IsOverridingMode,
2410 if (IsProtocolMethodDecl &&
2414 if (IsOverridingMode)
2416 diag::warn_conflicting_overriding_param_modifiers)
2420 diag::warn_conflicting_param_modifiers)
2432 if (Warn && IsOverridingMode &&
2436 diag::warn_conflicting_nullability_attr_overriding_param_types)
2453 IsOverridingMode ? diag::warn_conflicting_overriding_param_types
2454 : diag::warn_conflicting_param_types;
2470 IsOverridingMode ? diag::warn_non_contravariant_overriding_param_types
2471 : diag::warn_non_contravariant_param_types;
2477 << MethodImpl->
getDeclName() << IfaceTy << ImplTy;
2479 (IsOverridingMode ? diag::note_previous_declaration
2480 : diag::note_previous_definition))
2491 if (implFamily == declFamily)
return false;
2503 unsigned errorID = diag::err_arc_lost_method_convention;
2504 unsigned noteID = diag::note_arc_lost_method_convention;
2507 family = implFamily;
2508 errorID = diag::err_arc_gained_method_convention;
2509 noteID = diag::note_arc_gained_method_convention;
2513 enum FamilySelector {
2514 F_alloc, F_copy, F_mutableCopy = F_copy, F_init, F_new
2516 FamilySelector familySelector = FamilySelector();
2519 case OMF_None: llvm_unreachable(
"logic error, no method convention");
2533 case OMF_init: familySelector = F_init;
break;
2534 case OMF_alloc: familySelector = F_alloc;
break;
2535 case OMF_copy: familySelector = F_copy;
break;
2537 case OMF_new: familySelector = F_new;
break;
2540 enum ReasonSelector { R_NonObjectReturn, R_UnrelatedReturn };
2541 ReasonSelector reasonSelector;
2546 reasonSelector = R_UnrelatedReturn;
2548 reasonSelector = R_NonObjectReturn;
2552 S.
Diag(
decl->getLocation(), noteID) <<
int(familySelector) <<
int(reasonSelector);
2559 bool IsProtocolMethodDecl) {
2565 IsProtocolMethodDecl,
false,
2571 IM != EM && IF != EF; ++IM, ++IF) {
2573 IsProtocolMethodDecl,
false,
true);
2578 diag::warn_conflicting_variadic);
2585 bool IsProtocolMethodDecl) {
2588 IsProtocolMethodDecl,
true,
2594 IM != EM && IF != EF; ++IM, ++IF) {
2596 IsProtocolMethodDecl,
true,
true);
2601 diag::warn_conflicting_overriding_variadic);
2610 bool IsProtocolMethodDecl) {
2618 if (MethodDecl->
hasAttr<UnavailableAttr>() ||
2619 MethodDecl->
hasAttr<DeprecatedAttr>())
2623 IsProtocolMethodDecl,
false,
false);
2628 IM != EM && IF != EF; ++IM, ++IF) {
2631 IsProtocolMethodDecl,
false,
false);
2643 diag::warn_category_method_impl_match);
2660 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>())
2662 for (
const auto *PI : PDecl->
protocols())
2685 bool& IncompleteImpl,
2692 : dyn_cast<ObjCInterfaceDecl>(CDecl);
2693 assert (IDecl &&
"CheckProtocolMethodDefs - IDecl is null");
2709 if (PDecl->
hasAttr<ObjCExplicitProtocolImplAttr>()) {
2710 if (!ProtocolsExplictImpl) {
2715 ProtocolsExplictImpl->end())
2733 if (InsMap.count(fISelector))
2753 !method->isPropertyAccessor() &&
2754 !InsMap.count(method->getSelector()) &&
2774 if (C || MethodInClass->isPropertyAccessor())
2776 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2786 !ClsMap.count(method->getSelector()) &&
2799 unsigned DIAG = diag::warn_unimplemented_protocol_method;
2808 CDecl, ProtocolsExplictImpl);
2820 bool &IncompleteImpl,
2821 bool ImmediateClass,
2822 bool WarnCategoryMethodImpl) {
2826 if (!InsMapSeen.insert(I->getSelector()).second)
2828 if (!I->isPropertyAccessor() &&
2829 !InsMap.count(I->getSelector())) {
2832 diag::warn_undef_method_impl);
2838 "Expected to find the method through lookup as well");
2840 if (ImpMethodDecl) {
2844 if (!WarnCategoryMethodImpl)
2846 isa<ObjCProtocolDecl>(CDecl));
2847 else if (!I->isPropertyAccessor())
2856 if (!ClsMapSeen.insert(I->getSelector()).second)
2858 if (!I->isPropertyAccessor() &&
2859 !ClsMap.count(I->getSelector())) {
2862 diag::warn_undef_method_impl);
2867 "Expected to find the method through lookup as well");
2869 if (ImpMethodDecl) {
2873 if (!WarnCategoryMethodImpl)
2875 isa<ObjCProtocolDecl>(CDecl));
2876 else if (!I->isPropertyAccessor())
2885 for (
auto *PI : PD->protocols())
2887 IMPDecl, PI, IncompleteImpl,
false,
2888 WarnCategoryMethodImpl);
2895 if (!WarnCategoryMethodImpl) {
2896 for (
auto *Cat : I->visible_categories())
2898 IMPDecl, Cat, IncompleteImpl,
2899 ImmediateClass && Cat->IsClassExtension(),
2900 WarnCategoryMethodImpl);
2903 for (
auto *Ext : I->visible_extensions())
2905 IMPDecl, Ext, IncompleteImpl,
false,
2906 WarnCategoryMethodImpl);
2910 for (
auto *PI : I->all_referenced_protocols())
2912 IMPDecl, PI, IncompleteImpl,
false,
2913 WarnCategoryMethodImpl);
2917 if (!WarnCategoryMethodImpl && I->getSuperClass())
2920 I->getSuperClass(), IncompleteImpl,
false);
2951 if (SuperIDecl && SuperIDecl->
lookupMethod(Sel,
false))
2955 if (InsMap.empty() && ClsMap.empty())
2959 bool IncompleteImpl =
false;
2962 IncompleteImpl,
false,
2968 bool IncompleteImpl) {
2973 InsMap.insert(I->getSelector());
2981 const auto *
P = PImpl->getPropertyDecl();
2984 InsMap.insert(
P->getGetterName());
2985 if (!
P->getSetterName().isNull())
2986 InsMap.insert(
P->getSetterName());
2993 bool SynthesizeProperties =
LangOpts.ObjCDefaultSynthProperties &&
2995 !IDecl->isObjCRequiresPropertyDefs();
3004 ClsMap.insert(I->getSelector());
3011 IncompleteImpl,
true);
3016 dyn_cast<ObjCCategoryImplDecl>(IMPDecl))
3027 for (
auto *PI : I->all_referenced_protocols())
3029 InsMap, ClsMap, I, ExplicitImplProtocols);
3033 if (!
C->IsClassExtension()) {
3034 for (
auto *
P :
C->protocols())
3036 IncompleteImpl, InsMap, ClsMap, CDecl,
3037 ExplicitImplProtocols);
3042 llvm_unreachable(
"invalid ObjCContainerDecl type.");
3052 for (
unsigned i = 0; i != NumElts; ++i) {
3057 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
3067 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
3075 Diag(AtClassLoc, diag::warn_forward_class_redefinition)
3085 = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
3107 if (PrevIDecl && TypeParams) {
3111 *
this, PrevTypeParams, TypeParams,
3112 TypeParamListContext::ForwardDeclaration)) {
3113 TypeParams =
nullptr;
3117 Diag(IdentLocs[i], diag::err_objc_parameterized_forward_class)
3120 Diag(Def->getLocation(), diag::note_defined_here)
3123 TypeParams =
nullptr;
3129 ClassName, TypeParams, PrevIDecl,
3138 DeclsInGroup.push_back(IDecl);
3146 const Type *left,
const Type *right);
3155 if (left == right)
return true;
3178 if (isa<VectorType>(left))
return isa<VectorType>(right);
3179 if (isa<VectorType>(right))
return false;
3202 return (leftSK == rightSK);
3208 assert(lt && rt && lt != rt);
3210 if (!isa<RecordType>(lt) || !isa<RecordType>(rt))
return false;
3211 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3212 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3218 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3219 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3234 for (; li != le && ri != re; ++li, ++ri) {
3235 if (!
matchTypes(Context, strategy, li->getType(), ri->getType()))
3238 return (li == le && ri == re);
3259 (left->
hasAttr<NSReturnsRetainedAttr>()
3260 != right->
hasAttr<NSReturnsRetainedAttr>() ||
3261 left->
hasAttr<NSConsumesSelfAttr>()
3262 != right->
hasAttr<NSConsumesSelfAttr>()))
3269 for (; li != le && ri != re; ++li, ++ri) {
3270 assert(ri != right->
param_end() &&
"Param mismatch");
3277 lparm->hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3285 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3286 auto *MethodInListProtocol =
3290 if ((MethodProtocol && !MethodInListProtocol) ||
3291 (!MethodProtocol && MethodInListProtocol))
3294 if (MethodProtocol && MethodInListProtocol)
3300 return MethodInterface == MethodInListInterface;
3309 if (!CD->IsClassExtension() && List->getBits() < 2)
3310 List->setBits(List->getBits() + 1);
3313 if (List->getMethod() ==
nullptr) {
3314 List->setMethod(Method);
3315 List->setNext(
nullptr);
3323 for (; List;
Previous = List, List = List->getNext()) {
3340 if (!SameDeclaration ||
3346 List->setHasMoreThanOneDecl(
true);
3351 !ListWithSameDeclaration && !List->getMethod()->isDeprecated())
3352 ListWithSameDeclaration = List;
3355 !ListWithSameDeclaration &&
3357 ListWithSameDeclaration = List;
3371 List->setHasMoreThanOneDecl(
true);
3378 List->setMethod(Method);
3384 List->setMethod(Method);
3395 if (ListWithSameDeclaration) {
3398 ListWithSameDeclaration->
setMethod(Method);
3399 ListWithSameDeclaration->
setNext(List);
3409 assert(ExternalSource &&
"We need an external AST source");
3414 if (!ExternalSource)
3419 void Sema::AddMethodToGlobalPool(
ObjCMethodDecl *Method,
bool impl,
3435 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3472 assert(BoundInterface &&
"unexpected object type!");
3476 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->
getDeclContext());
3477 if (MethodProtocol) {
3487 return MethodInterface == BoundInterface ||
3488 MethodInterface->isSuperClassOf(BoundInterface) ||
3489 BoundInterface->isSuperClassOf(MethodInterface);
3491 llvm_unreachable(
"unknown method context");
3498 bool InstanceFirst,
bool CheckTheOther,
3503 GlobalMethodPool::iterator Pos =
MethodPool.find(Sel);
3511 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3513 Methods.push_back(M->getMethod());
3517 if (!Methods.empty())
3518 return Methods.size() > 1;
3527 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3529 Methods.push_back(M->getMethod());
3532 return Methods.size() > 1;
3540 FilteredMethods.push_back(BestMethod);
3542 for (
auto *M : Methods)
3543 if (M != BestMethod && !M->
hasAttr<UnavailableAttr>())
3544 FilteredMethods.push_back(M);
3546 if (FilteredMethods.size() > 1)
3550 GlobalMethodPool::iterator Pos =
MethodPool.find(Sel);
3561 bool receiverIdOrClass,
3566 GlobalMethodPool::iterator Pos =
MethodPool.find(Sel);
3571 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3574 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3575 return M->getMethod();
3582 bool receiverIdOrClass) {
3584 bool issueDiagnostic =
false, issueError =
false;
3588 bool strictSelectorMatch =
3589 receiverIdOrClass &&
3591 if (strictSelectorMatch) {
3592 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3594 issueDiagnostic =
true;
3603 if (!strictSelectorMatch ||
3604 (issueDiagnostic &&
getLangOpts().ObjCAutoRefCount))
3605 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3609 issueDiagnostic =
true;
3616 if (issueDiagnostic) {
3618 Diag(R.
getBegin(), diag::err_arc_multiple_method_decl) << Sel << R;
3619 else if (strictSelectorMatch)
3620 Diag(R.
getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
3622 Diag(R.
getBegin(), diag::warn_multiple_method_decl) << Sel << R;
3624 Diag(Methods[0]->getBeginLoc(),
3625 issueError ? diag::note_possibility : diag::note_using)
3626 << Methods[0]->getSourceRange();
3627 for (
unsigned I = 1, N = Methods.size(); I != N; ++I) {
3628 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3629 << Methods[I]->getSourceRange();
3635 GlobalMethodPool::iterator Pos =
MethodPool.find(Sel);
3641 Method = Method->getNext())
3642 if (Method->getMethod() &&
3645 return Method->getMethod();
3648 Method = Method->getNext())
3649 if (Method->getMethod() &&
3652 return Method->getMethod();
3660 const unsigned MaxEditDistance = 1;
3661 unsigned BestEditDistance = MaxEditDistance + 1;
3664 unsigned MinPossibleEditDistance =
abs((
int)MethodName.size() - (
int)Typo.size());
3665 if (MinPossibleEditDistance > 0 &&
3666 Typo.size() / MinPossibleEditDistance < 1)
3668 unsigned EditDistance = Typo.edit_distance(MethodName,
true, MaxEditDistance);
3669 if (EditDistance > MaxEditDistance)
3671 if (EditDistance == BestEditDistance)
3672 BestMethod.push_back(Method);
3673 else if (EditDistance < BestEditDistance) {
3675 BestMethod.push_back(Method);
3694 bool ObjectIsId =
true, ObjectIsClass =
true;
3696 ObjectIsId = ObjectIsClass =
false;
3701 ObjectType =
QualType(ObjCPtr->getInterfaceType(), 0);
3702 ObjectIsId = ObjectIsClass =
false;
3705 ObjectIsClass =
false;
3711 for (GlobalMethodPool::iterator
b =
MethodPool.begin(),
3715 if (M->getMethod() &&
3716 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3717 (M->getMethod()->getSelector() != Sel)) {
3719 Methods.push_back(M->getMethod());
3720 else if (!ObjectIsClass &&
3723 Methods.push_back(M->getMethod());
3727 if (M->getMethod() &&
3728 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3729 (M->getMethod()->getSelector() != Sel)) {
3731 Methods.push_back(M->getMethod());
3732 else if (!ObjectIsId &&
3735 Methods.push_back(M->getMethod());
3740 for (
unsigned i = 0, e = Methods.size(); i < e; i++) {
3744 return (SelectedMethods.size() == 1) ? SelectedMethods[0] :
nullptr;
3754 for (
auto *Ivar :
ID->ivars()) {
3755 if (Ivar->isInvalidDecl())
3760 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3762 Ivar->setInvalidDecl();
3772 for (
auto ivar =
ID->getClassInterface()->all_declared_ivar_begin();
3773 ivar; ivar = ivar->getNextIvar()) {
3774 if (ivar->isInvalidDecl())
continue;
3777 S.
Diag(ivar->getLocation(), diag::err_arc_weak_disabled);
3779 S.
Diag(ivar->getLocation(), diag::err_arc_weak_no_runtime);
3791 for (
auto ivar =
ID->all_declared_ivar_begin(); ivar;
3792 ivar = ivar->getNextIvar()) {
3793 if (ivar->isInvalidDecl())
3799 S.
Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3800 ivar->setInvalidDecl();
3807 case Decl::ObjCInterface:
3809 case Decl::ObjCProtocol:
3811 case Decl::ObjCCategory:
3812 if (cast<ObjCCategoryDecl>(
CurContext)->IsClassExtension())
3815 case Decl::ObjCImplementation:
3817 case Decl::ObjCCategoryImpl:
3829 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3836 if ((IntfDecl = dyn_cast<ObjCInterfaceDecl>(OCD))) {
3837 Ivars = IntfDecl->
ivars();
3838 }
else if (
auto *ImplDecl = dyn_cast<ObjCImplementationDecl>(OCD)) {
3839 IntfDecl = ImplDecl->getClassInterface();
3840 Ivars = ImplDecl->
ivars();
3841 }
else if (
auto *CategoryDecl = dyn_cast<ObjCCategoryDecl>(OCD)) {
3842 if (CategoryDecl->IsClassExtension()) {
3843 IntfDecl = CategoryDecl->getClassInterface();
3844 Ivars = CategoryDecl->
ivars();
3849 if (!isa<ObjCInterfaceDecl>(OCD)) {
3850 for (
auto ivar : Ivars) {
3852 S.
Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3853 << ivar->getDeclName() << ivar->getType();
3865 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3868 bool IsInvalidIvar =
false;
3870 S.
Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3871 << ivar->getDeclName() << IvarTy
3873 IsInvalidIvar =
true;
3875 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3876 S.
Diag(ivar->getLocation(),
3877 diag::err_objc_variable_sized_type_not_at_end)
3878 << ivar->getDeclName() << IvarTy;
3879 IsInvalidIvar =
true;
3882 if (IsInvalidIvar) {
3883 S.
Diag(ivar->getNextIvar()->getLocation(),
3884 diag::note_next_ivar_declaration)
3885 << ivar->getNextIvar()->getSynthesize();
3886 ivar->setInvalidDecl();
3894 (Ivars.begin() == Ivars.end()) ?
nullptr : *Ivars.begin();
3897 while (SuperClass && SuperClass->
ivar_empty())
3905 diag::warn_superclass_variable_sized_type_not_at_end)
3906 << FirstIvar->
getDeclName() << LastIvar->getDeclName()
3907 << LastIvar->getType() << SuperClass->
getDeclName();
3908 S.
Diag(LastIvar->getLocation(), diag::note_entity_declared_at)
3909 << LastIvar->getDeclName();
3920 const llvm::iterator_range<ObjCProtocolList::iterator> &Protocols) {
3921 for (
auto *PI : Protocols)
3932 for (
auto *MD : PDecl->
methods()) {
3933 if (!MD->isPropertyAccessor()) {
3934 if (
const auto *CMD =
3935 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3936 if (CMD->isDirectMethod())
3937 DirectMembers.push_back(CMD);
3942 if (
const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3943 PD->getIdentifier(),
3944 PD->isClassProperty()
3947 if (CPD->isDirectProperty())
3948 DirectMembers.push_back(CPD);
3951 if (!DirectMembers.empty()) {
3952 S.
Diag(CDecl->
getLocation(), diag::err_objc_direct_protocol_conformance)
3954 for (
const auto *MD : DirectMembers)
3955 S.
Diag(MD->getLocation(), diag::note_direct_member_here);
3970 assert(AtEnd.
isValid() &&
"Invalid location for '@end'");
3972 auto *OCD = cast<ObjCContainerDecl>(
CurContext);
3973 Decl *ClassDecl = OCD;
3975 bool isInterfaceDeclKind =
3976 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
3977 || isa<ObjCProtocolDecl>(ClassDecl);
3978 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
3984 if (
auto *OID = dyn_cast<ObjCImplementationDecl>(
CurContext)) {
3985 for (
auto PropImpl : OID->property_impls()) {
3986 if (
auto *Getter = PropImpl->getGetterMethodDecl())
3987 if (Getter->isSynthesizedAccessorStub())
3988 OID->addDecl(Getter);
3989 if (
auto *Setter = PropImpl->getSetterMethodDecl())
3990 if (Setter->isSynthesizedAccessorStub())
3991 OID->addDecl(Setter);
3996 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
3997 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
3999 for (
unsigned i = 0, e = allMethods.size(); i != e; i++ ) {
4001 cast_or_null<ObjCMethodDecl>(allMethods[i]);
4003 if (!Method)
continue;
4009 if ((isInterfaceDeclKind && PrevMethod && !
match)
4010 || (checkIdenticalMethods &&
match)) {
4033 if ((isInterfaceDeclKind && PrevMethod && !
match)
4034 || (checkIdenticalMethods &&
match)) {
4053 if (isa<ObjCInterfaceDecl>(ClassDecl)) {
4060 if (
C->IsClassExtension()) {
4068 if (CDecl->getIdentifier())
4072 for (
auto *I : CDecl->properties())
4074 CDecl->setAtEndRange(AtEnd);
4077 IC->setAtEndRange(AtEnd);
4084 for (
const auto *Ext : IDecl->visible_extensions()) {
4085 for (
const auto *
Property : Ext->instance_properties()) {
4088 = IC->FindPropertyImplDecl(
Property->getIdentifier(),
4090 if (PIDecl->getPropertyImplementation()
4094 for (
const auto *Ext : IDecl->visible_extensions()) {
4096 Ext->getInstanceMethod(
Property->getGetterName()))
4097 GetterMethod->setPropertyAccessor(
true);
4100 = Ext->getInstanceMethod(
Property->getSetterName()))
4101 SetterMethod->setPropertyAccessor(
true);
4109 if (IDecl->hasDesignatedInitializers())
4114 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4115 if (IDecl->getSuperClass() ==
nullptr) {
4118 if (!HasRootClassAttr) {
4121 Diag(DeclLoc, diag::warn_objc_root_class_missing)
4122 << IDecl->getIdentifier();
4129 if (NSObjectDecl && NSObjectDecl->getDefinition()) {
4130 Diag(SuperClassLoc, diag::note_objc_needs_superclass)
4133 Diag(SuperClassLoc, diag::note_objc_needs_superclass);
4136 }
else if (HasRootClassAttr) {
4138 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4146 if (IDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4147 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4148 Diag(IC->getLocation(), diag::err_restricted_superclass_mismatch);
4149 Diag(Super->getLocation(), diag::note_class_declared);
4153 if (IDecl->hasAttr<ObjCClassStubAttr>())
4154 Diag(IC->getLocation(), diag::err_implementation_of_class_stub);
4157 while (IDecl->getSuperClass()) {
4159 IDecl = IDecl->getSuperClass();
4165 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
4166 CatImplClass->setAtEndRange(AtEnd);
4172 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4176 }
else if (
const auto *IntfDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
4178 if (!IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>() &&
4179 Super->hasAttr<ObjCSubclassingRestrictedAttr>()) {
4180 Diag(IntfDecl->getLocation(), diag::err_restricted_superclass_mismatch);
4181 Diag(Super->getLocation(), diag::note_class_declared);
4185 if (IntfDecl->hasAttr<ObjCClassStubAttr>() &&
4186 !IntfDecl->hasAttr<ObjCSubclassingRestrictedAttr>())
4187 Diag(IntfDecl->getLocation(), diag::err_class_stub_subclassing_mismatch);
4190 if (isInterfaceDeclKind) {
4192 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4195 if (
VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
4196 if (!VDecl->hasExternalStorage())
4197 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4203 for (
unsigned i = 0, e = allTUVars.size(); i != e; i++) {
4206 (*I)->setTopLevelDeclInObjCContainer();
4235 if (ResultObjectType->isObjCIdType() ||
4236 ResultObjectType->isObjCQualifiedIdType())
4241 = ResultObjectType->getInterfaceDecl()) {
4247 if (ResultClass->isSuperClassOf(CurrentClass))
4263 class OverrideSearch {
4275 Sema::GlobalMethodPool::iterator it = S.
MethodPool.find(selector);
4295 dyn_cast<ObjCCategoryDecl>(container)) {
4296 searchFromContainer(container);
4298 searchFromContainer(Interface);
4300 searchFromContainer(container);
4304 typedef decltype(Overridden)::iterator iterator;
4305 iterator begin()
const {
return Overridden.begin(); }
4306 iterator end()
const {
return Overridden.end(); }
4313 #define OBJCCONTAINER(type, base) \ 4315 searchFrom(cast<type##Decl>(container)); \ 4317 #define ABSTRACT_DECL(expansion) 4318 #define DECL(type, base) \ 4320 #include "clang/AST/DeclNodes.inc" 4321 llvm_unreachable(
"not an ObjC container!");
4381 for (
const auto *Proto : protocols)
4393 Overridden.insert(meth);
4403 searchFromContainer(container);
4410 if (
const auto *attr = overridden->
getAttr<ObjCDirectAttr>()) {
4412 Diag(attr->getLocation(), diag::note_previous_declaration);
4413 }
else if (
const auto *attr = method->
getAttr<ObjCDirectAttr>()) {
4414 Diag(attr->getLocation(), diag::err_objc_direct_on_override)
4426 OverrideSearch overrides(*
this, ObjCMethod);
4432 bool hasOverriddenMethodsInBaseOrProtocol =
false;
4434 if (!hasOverriddenMethodsInBaseOrProtocol) {
4435 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4436 CurrentClass != overridden->getClassInterface() ||
4437 overridden->isOverriding()) {
4439 hasOverriddenMethodsInBaseOrProtocol =
true;
4448 GlobalMethodPool::iterator It =
4453 unsigned CategCount = List.getBits();
4454 if (CategCount > 0) {
4457 if (CategCount > 1 ||
4458 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4459 OverrideSearch overrides(*
this, overridden);
4461 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4462 CurrentClass != SuperOverridden->getClassInterface()) {
4464 hasOverriddenMethodsInBaseOrProtocol =
true;
4465 overridden->setOverriding(
true);
4482 if (ObjCMethod->
isImplicit() && overridden->isImplicit())
4489 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4491 if (CurrentClass && overridden->
getDeclContext() != CurrentClass &&
4492 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4497 PrevE = overridden->param_end();
4498 for (; ParamI != E && PrevI != PrevE; ++ParamI, ++PrevI) {
4499 assert(PrevI != overridden->param_end() &&
"Param mismatch");
4505 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4507 Diag(overridden->getLocation(), diag::note_previous_declaration);
4514 ObjCMethod->
setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4524 bool prevUsesCSKeyword) {
4526 auto nullability =
type->getNullability(S.
Context);
4530 if (nullability.hasValue() == prevNullability.hasValue()) {
4536 if (*nullability == *prevNullability)
4540 S.
Diag(loc, diag::err_nullability_conflicting)
4563 if (prevMethod->
hasAttr<ObjCRequiresSuperAttr>() &&
4564 !method->
hasAttr<ObjCRequiresSuperAttr>()) {
4567 ObjCRequiresSuperAttr::CreateImplicit(S.
Context,
4584 unsigned numPrevParams = prevMethod->
param_size();
4585 for (
unsigned i = 0, n =
std::min(numParams, numPrevParams); i != n; ++i) {
4605 llvm::Triple::x86 &&
4606 "x86-specific check invoked for a different target");
4610 if (
P->getType()->isVectorType()) {
4611 Loc =
P->getBeginLoc();
4616 if (Loc.isInvalid()) {
4627 VersionTuple AcceptedInVersion;
4628 if (Triple.getOS() == llvm::Triple::IOS)
4629 AcceptedInVersion = VersionTuple(9);
4630 else if (Triple.isMacOSX())
4631 AcceptedInVersion = VersionTuple(10, 11);
4637 SemaRef.
Diag(Loc, diag::err_objc_method_unsupported_param_ret_type)
4640 << (Triple.isMacOSX() ?
"macOS 10.11" :
"iOS 9");
4645 CD->
hasAttr<ObjCDirectMembersAttr>()) {
4656 bool diagnosed =
false;
4659 if (diagnosed || IMD->isImplicit())
4665 S.
Diag(IMD->getLocation(), diag::note_previous_declaration);
4683 if (
auto *IMD = IDecl->
getMethod(Sel, isInstance))
4686 if (Impl != ImpDecl)
4691 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4693 else if (
auto CatImpl = Cat->getImplementation())
4694 if (CatImpl != ImpDecl)
4695 if (
auto *IMD = Cat->getMethod(Sel, isInstance))
4708 bool isVariadic,
bool MethodDefinition) {
4711 Diag(MethodLoc, diag::err_missing_method_context);
4718 bool HasRelatedResultType =
false;
4726 QualType bareResultType = resultDeclType;
4731 Diag(MethodLoc, diag::warn_missing_method_return_type)
4737 MethodType == tok::minus, isVariadic,
4742 HasRelatedResultType);
4746 for (
unsigned i = 0, e = Sel.
getNumArgs(); i != e; ++i) {
4750 if (!ArgInfo[i].
Type) {
4757 LookupResult R(*
this, ArgInfo[i].Name, ArgInfo[i].NameLoc,
4762 if (S->isDeclScope(PrevDecl)) {
4763 Diag(ArgInfo[i].NameLoc,
4764 (MethodDefinition ? diag::warn_method_param_redefinition
4765 : diag::warn_method_param_declaration))
4768 diag::note_previous_declaration);
4777 ArgInfo[i].NameLoc, ArgInfo[i].Name,
4789 if (Param->
hasAttr<BlocksAttr>()) {
4796 Params.push_back(Param);
4799 for (
unsigned i = 0, e = CNumArgs; i != e; ++i) {
4800 ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
4801 QualType ArgType = Param->getType();
4808 Param->setDeclContext(ObjCMethod);
4809 Params.push_back(Param);
4821 if (
ObjCImplDecl *ImpDecl = dyn_cast<ObjCImplDecl>(ClassDecl)) {
4822 if (MethodType == tok::minus) {
4823 PrevMethod = ImpDecl->getInstanceMethod(Sel);
4824 ImpDecl->addInstanceMethod(ObjCMethod);
4826 PrevMethod = ImpDecl->getClassMethod(Sel);
4827 ImpDecl->addClassMethod(ObjCMethod);
4836 if (
auto *Setter = PropertyImpl->getSetterMethodDecl())
4837 if (Setter->getSelector() == Sel &&
4839 assert(Setter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4840 PropertyImpl->setSetterMethodDecl(ObjCMethod);
4842 if (
auto *Getter = PropertyImpl->getGetterMethodDecl())
4843 if (Getter->getSelector() == Sel &&
4845 assert(Getter->isSynthesizedAccessorStub() &&
"autosynth stub expected");
4846 PropertyImpl->setGetterMethodDecl(ObjCMethod);
4859 if (
const auto *attr = CanonicalMD->
getAttr<ObjCDirectAttr>()) {
4861 ObjCDirectAttr::CreateImplicit(
Context, attr->getLocation()));
4868 if (
auto *IMD = IDecl->lookupMethod(ObjCMethod->
getSelector(),
4888 if (IDecl == IMD->getClassInterface()) {
4889 auto diagContainerMismatch = [&] {
4890 int decl = 0, impl = 0;
4892 if (
auto *Cat = dyn_cast<ObjCCategoryDecl>(IMD->getDeclContext()))
4893 decl = Cat->IsClassExtension() ? 1 : 2;
4895 if (isa<ObjCCategoryImplDecl>(ImpDecl))
4896 impl = 1 + (
decl != 0);
4899 diag::err_objc_direct_impl_decl_mismatch)
4901 Diag(IMD->getLocation(), diag::note_previous_declaration);
4904 if (
const auto *attr = ObjCMethod->
getAttr<ObjCDirectAttr>()) {
4906 diagContainerMismatch();
4907 }
else if (!IMD->isDirectMethod()) {
4908 Diag(attr->getLocation(), diag::err_objc_direct_missing_on_decl);
4909 Diag(IMD->getLocation(), diag::note_previous_declaration);
4911 }
else if (
const auto *attr = IMD->getAttr<ObjCDirectAttr>()) {
4913 diagContainerMismatch();
4916 ObjCDirectAttr::CreateImplicit(
Context, attr->getLocation()));
4922 if (isa<ObjCCategoryImplDecl>(ImpDecl) && IMD->isOverriding() &&
4935 for (
auto *
C : IDecl->visible_categories())
4936 for (
auto &
P :
C->protocols())
4937 if (
auto *IMD =
P->lookupMethod(ObjCMethod->
getSelector(),
4940 IMD->parameters().size() &&
4941 "Methods have different number of parameters");
4942 auto OI = IMD->param_begin(), OE = IMD->param_end();
4944 for (; OI != OE; ++OI, ++NI)
4949 if (!isa<ObjCProtocolDecl>(ClassDecl)) {
4954 IDecl = cast<ObjCCategoryDecl>(ClassDecl)->getClassInterface();
4962 cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
4978 if (!CurrentClass) {
4980 CurrentClass = Cat->getClassInterface();
4981 else if (
ObjCImplDecl *Impl = dyn_cast<ObjCImplDecl>(ClassDecl))
4982 CurrentClass = Impl->getClassInterface();
4984 = dyn_cast<ObjCCategoryImplDecl>(ClassDecl))
4985 CurrentClass = CatImpl->getClassInterface();
4993 bool ARCError =
false;
5000 LangOpts.ObjCInferRelatedResultType) {
5001 bool InferRelatedResultType =
false;
5027 if (InferRelatedResultType &&
5032 if (MethodDefinition &&
5038 if (
const auto *attr = ObjCMethod->
getAttr<AvailabilityAttr>()) {
5041 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer)
5043 ObjCMethod->
dropAttr<AvailabilityAttr>();
5066 Diag(D->
getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);
5080 Diag(DeclStart, diag::err_undef_interface) << ClassName;
5084 Diag(DeclStart, diag::err_atdef_nonfragile_interface);
5092 for (
unsigned i = 0; i < Ivars.size(); i++) {
5094 RecordDecl *Record = dyn_cast<RecordDecl>(TagD);
5098 ID->getIdentifier(),
ID->getType(),
5100 Decls.push_back(FD);
5105 D != Decls.end(); ++D) {
5109 else if (
RecordDecl *Record = dyn_cast<RecordDecl>(TagD))
5110 Record->addDecl(FD);
5125 Diag(IdLoc, diag::err_arg_with_address_space);
5137 Diag(IdLoc, diag::err_illegal_qualifiers_on_catch_parm);
5142 Diag(IdLoc, diag::err_catch_param_not_objc_type);
5145 Diag(IdLoc, diag::err_catch_param_not_objc_type);
5178 diag::err_invalid_thread)
5212 if (New->
hasAttr<BlocksAttr>())
5225 Ivars.push_back(Iv);
5231 if (ExternalSource) {
5234 for (
unsigned I = 0, N = Sels.size(); I != N; ++I)
5245 Selector Sel = SelectorAndLocation.first;
5248 Diag(Loc, diag::warn_unimplemented_selector) << Sel;
5270 IV = const_cast<ObjCInterfaceDecl *>(IDecl)->lookupInstanceVariable(
5271 IV->getIdentifier());
5280 class UnusedBackingIvarChecker :
5287 bool InvokedSelfMethod;
5291 : S(S), Method(Method), IvarD(IvarD),
5292 AccessedIvar(
false), InvokedSelfMethod(
false) {
5298 AccessedIvar =
true;
5307 InvokedSelfMethod =
true;
5316 if (S->hasUnrecoverableErrorOccurred())
5320 unsigned DIAG = diag::warn_unused_property_backing_ivar;
5330 if (CurMethod->isSynthesizedAccessorStub())
5333 UnusedBackingIvarChecker Checker(*
this, CurMethod, IV);
5334 Checker.TraverseStmt(CurMethod->getBody());
5335 if (Checker.AccessedIvar)
5342 if (!IV->
isReferenced() || !Checker.InvokedSelfMethod) {
void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, ArrayRef< IdentifierLocPair > ProtocolId, SmallVectorImpl< Decl * > &Protocols)
FindProtocolDeclaration - This routine looks up protocols and issues an error if they are not declare...
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs=llvm::None)
Sets the method's parameters and selector source locations.
const ObjCInterfaceType * getInterfaceType() const
If this pointer points to an Objective C @interface type, gets the type for that interface.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
bool hasDefinition() const
Determine whether this class has been defined.
static bool tryMatchRecordTypes(ASTContext &Context, Sema::MethodMatchStrategy strategy, const Type *left, const Type *right)
ObjCIvarDecl * GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, const ObjCPropertyDecl *&PDecl) const
GetIvarBackingPropertyAccessor - If method is a property setter/getter and it property has a backing ...
void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, ObjCInterfaceDecl *ID)
DiagnoseClassExtensionDupMethods - Check for duplicate declaration of a class method in its extension...
bool isClassMethod() const
Decl * ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, IdentifierInfo *CategoryName, SourceLocation CategoryLoc, Decl *const *ProtoRefs, unsigned NumProtoRefs, const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList)
void setImplicit(bool I=true)
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
bool isSelfExpr(Expr *RExpr)
Private Helper predicate to check for 'self'.
The receiver is an object instance.
void setEndOfDefinitionLoc(SourceLocation LE)
VersionTuple getPlatformMinVersion() const
Retrieve the minimum desired version of the platform, to which the program should be compiled.
ExternalSemaSource * getExternalSource() const
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
Smart pointer class that efficiently represents Objective-C method names.
QualType getObjCIdType() const
Represents the Objective-CC id type.
QualType getAdjustedParameterType(QualType T) const
Perform adjustment on the parameter type of a function.
void PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl=nullptr, ExpressionEvaluationContextRecord::ExpressionKind Type=ExpressionEvaluationContextRecord::EK_Other)
PointerType - C99 6.7.5.1 - Pointer Declarators.
A (possibly-)qualified type.
Simple class containing the result of Sema::CorrectTypo.
void setStarLoc(SourceLocation Loc)
unsigned param_size() const
TypeResult actOnObjCTypeArgsAndProtocolQualifiers(Scope *S, SourceLocation Loc, ParsedType BaseType, SourceLocation TypeArgsLAngleLoc, ArrayRef< ParsedType > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< Decl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build a specialized and/or protocol-qualified Objective-C type.
ObjCInterfaceDecl * getClassInterface()
all_protocol_range all_referenced_protocols() const
ObjCInterfaceDecl * getClassInterface()
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
ObjCDeclQualifier getObjCDeclQualifier() const
static QualType getObjectType(APValue::LValueBase B)
Retrieves the "underlying object type" of the given expression, as used by __builtin_object_size.
llvm::DenseSet< IdentifierInfo * > ProtocolNameSet
FIXME: Type hierarchies in Objective-C can be deep.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
bool CheckParmsForFunctionDef(ArrayRef< ParmVarDecl * > Parameters, bool CheckParameterNames)
Helpers for dealing with blocks and functions.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
Look up the name of an Objective-C protocol.