Lines Matching +full:oe +full:- +full:extra +full:- +full:delay

1 //===--- SemaDeclObjC.cpp - Semantic Analysis for ObjC Declarations -------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
39 /// \param receiverTypeIfCall - if null, check this as if declaring it;
40 /// if non-null, check this as if making a call to it with the given
48 if (method->isInvalidDecl()) return true;
57 method->getReturnType()->castAs<ObjCObjectPointerType>()->getObjectType();
59 if (result->isObjCId()) {
61 } else if (result->isObjCClass()) {
64 ObjCInterfaceDecl *resultClass = result->getInterface();
69 if (!resultClass->hasDefinition()) {
71 !isa<ObjCImplementationDecl>(method->getDeclContext()))
79 if (isa<ObjCProtocolDecl>(method->getDeclContext())) {
83 receiverClass = receiverTypeIfCall->castAs<ObjCObjectPointerType>()
84 ->getInterfaceDecl();
89 receiverClass = method->getClassInterface();
94 if (receiverClass->isSuperClassOf(resultClass) ||
95 resultClass->isSuperClassOf(receiverClass))
100 SourceLocation loc = method->getLocation();
106 method->addAttr(UnavailableAttr::CreateImplicit(Context, "",
113 method->setInvalidDecl();
117 /// Issue a warning if the parameter of the overridden method is non-escaping
121 if (OldD->hasAttr<NoEscapeAttr>() && !NewD->hasAttr<NoEscapeAttr>()) {
122 S.Diag(NewD->getLocation(), diag::warn_overriding_method_missing_noescape);
123 S.Diag(OldD->getLocation(), diag::note_overridden_marked_noescape);
131 /// defines a method taking a non-escaping parameter.
136 S.Diag(CD->getLocation(), diag::note_cat_conform_to_noescape_prot)
137 << CD->IsClassExtension() << PD
138 << cast<ObjCMethodDecl>(NewD->getDeclContext());
144 if (Overridden->hasRelatedResultType() &&
145 !NewMethod->hasRelatedResultType()) {
150 QualType ResultType = NewMethod->getReturnType();
151 SourceRange ResultTypeRange = NewMethod->getReturnTypeSourceRange();
155 = dyn_cast<ObjCInterfaceDecl>(NewMethod->getDeclContext());
157 DeclContext *DC = NewMethod->getDeclContext();
159 CurrentClass = Cat->getClassInterface();
161 CurrentClass = Impl->getClassInterface();
164 CurrentClass = CatImpl->getClassInterface();
168 Diag(NewMethod->getLocation(),
174 Diag(NewMethod->getLocation(),
180 if (ObjCMethodFamily Family = Overridden->getMethodFamily())
181 Diag(Overridden->getLocation(),
186 Diag(Overridden->getLocation(),
190 if ((NewMethod->hasAttr<NSReturnsRetainedAttr>() !=
191 Overridden->hasAttr<NSReturnsRetainedAttr>())) {
192 Diag(NewMethod->getLocation(),
197 Diag(Overridden->getLocation(), diag::note_previous_decl) << "method";
199 if ((NewMethod->hasAttr<NSReturnsNotRetainedAttr>() !=
200 Overridden->hasAttr<NSReturnsNotRetainedAttr>())) {
201 Diag(NewMethod->getLocation(),
206 Diag(Overridden->getLocation(), diag::note_previous_decl) << "method";
209 ObjCMethodDecl::param_const_iterator oi = Overridden->param_begin(),
210 oe = Overridden->param_end();
211 for (ObjCMethodDecl::param_iterator ni = NewMethod->param_begin(),
212 ne = NewMethod->param_end();
213 ni != ne && oi != oe; ++ni, ++oi) {
216 if (newDecl->hasAttr<NSConsumedAttr>() !=
217 oldDecl->hasAttr<NSConsumedAttr>()) {
218 Diag(newDecl->getLocation(),
222 Diag(oldDecl->getLocation(), diag::note_previous_decl) << "parameter";
229 /// Check a method declaration for compatibility with the Objective-C
233 ObjCMethodFamily family = method->getMethodFamily();
247 if (!Context.hasSameType(method->getReturnType(), Context.VoidTy)) {
248 SourceRange ResultTypeRange = method->getReturnTypeSourceRange();
250 Diag(method->getLocation(), diag::err_dealloc_bad_result_type)
251 << method->getReturnType()
252 << FixItHint::CreateInsertion(method->getSelectorLoc(0), "(void)");
254 Diag(method->getLocation(), diag::err_dealloc_bad_result_type)
255 << method->getReturnType()
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));
295 AvailabilityResult Availability = ND->getAvailability(
309 S.Diag(ND->getLocation(), diag::note_method_declared_at)
310 << ND->getDeclName();
314 if (!CD->getClassInterface()->isDeprecated())
316 ND = CD->getClassInterface();
327 S.Diag(ND->getLocation(), diag::note_method_declared_at)
328 << ND->getDeclName();
330 S.Diag(ND->getLocation(), diag::note_previous_decl)
334 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global
342 if (MDecl->isInstanceMethod())
348 /// HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer
352 QualType T = Param->getType();
354 if (const PointerType *PT = T->getAs<PointerType>()) {
355 T = PT->getPointeeType();
356 } else if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
357 T = RT->getPointeeType();
367 /// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible
382 QualType ResultType = MDecl->getReturnType();
383 if (!ResultType->isDependentType() && !ResultType->isVoidType() &&
384 !MDecl->isInvalidDecl() &&
385 SemaRef.RequireCompleteType(MDecl->getLocation(), ResultType,
387 MDecl->setInvalidDecl();
397 MDecl->createImplicitParams(Context, MDecl->getClassInterface());
399 SemaRef.PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
400 SemaRef.PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
403 SemaRef.CheckParmsForFunctionDef(MDecl->parameters(),
407 for (auto *Param : MDecl->parameters()) {
408 if (!Param->isInvalidDecl() && getLangOpts().ObjCAutoRefCount &&
410 Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
411 Param->getType();
413 if (Param->getIdentifier())
419 switch (MDecl->getMethodFamily()) {
424 Diag(MDecl->getLocation(), diag::err_arc_illegal_method_def)
425 << 0 << MDecl->getSelector();
443 // Warn on deprecated methods under -Wdeprecated-implementations,
445 if (ObjCInterfaceDecl *IC = MDecl->getClassInterface()) {
447 IC->lookupMethod(MDecl->getSelector(), MDecl->isInstanceMethod());
451 dyn_cast<ObjCImplDecl>(MDecl->getDeclContext());
453 dyn_cast<ObjCContainerDecl>(IMD->getDeclContext());
456 ImplDeclOfMethodDecl = OID->getImplementation();
458 if (CD->IsClassExtension()) {
459 if (ObjCInterfaceDecl *OID = CD->getClassInterface())
460 ImplDeclOfMethodDecl = OID->getImplementation();
462 ImplDeclOfMethodDecl = CD->getImplementation();
467 DiagnoseObjCImplementedDeprecations(SemaRef, IMD, MDecl->getLocation());
470 if (MDecl->getMethodFamily() == OMF_init) {
471 if (MDecl->isDesignatedInitializerForTheInterface()) {
472 SemaRef.getCurFunction()->ObjCIsDesignatedInit = true;
473 SemaRef.getCurFunction()->ObjCWarnForNoDesignatedInitChain =
474 IC->getSuperClass() != nullptr;
475 } else if (IC->hasDesignatedInitializers()) {
476 SemaRef.getCurFunction()->ObjCIsSecondaryInit = true;
477 SemaRef.getCurFunction()->ObjCWarnForNoInitDelegation = true;
485 if (const ObjCInterfaceDecl *SuperClass = IC->getSuperClass()) {
486 ObjCMethodFamily Family = MDecl->getMethodFamily();
490 SemaRef.getCurFunction()->ObjCShouldCallSuper = true;
494 SemaRef.getCurFunction()->ObjCShouldCallSuper = true;
498 SuperClass->lookupMethod(MDecl->getSelector(),
499 MDecl->isInstanceMethod());
500 SemaRef.getCurFunction()->ObjCShouldCallSuper =
501 (SuperMethod && SuperMethod->hasAttr<ObjCRequiresSuperAttr>());
513 // Callback to only accept typo corrections that are Objective-C classes.
579 IDecl->setEndOfDefinitionLoc(ClassLoc);
596 QualType T = TDecl->getUnderlyingType();
597 if (T->isObjCObjectType()) {
598 if (NamedDecl *IDecl = T->castAs<ObjCObjectType>()->getInterface()) {
619 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
629 SuperClassDecl->getDeclName(), ClassName,
661 IDecl->setSuperClass(SuperClassTInfo);
662 IDecl->setEndOfDefinitionLoc(SuperClassTInfo->getTypeLoc().getEndLoc());
671 // If there was an explicitly-provided type bound, check it.
674 // The type bound can be any Objective-C pointer type.
677 if (typeBound->isObjCObjectPointerType()) {
679 } else if (typeBound->isObjCObjectType()) {
680 // The user forgot the * on an Objective-C pointer type, e.g.,
683 SemaRef.getLocForEndOfToken(typeBoundInfo->getTypeLoc().getEndLoc());
684 Diag(typeBoundInfo->getTypeLoc().getBeginLoc(),
692 builder.pushFullCopy(typeBoundInfo->getTypeLoc());
694 // Create the Objective-C pointer type.
704 Diag(typeBoundInfo->getTypeLoc().getBeginLoc(),
715 QualType typeBound = typeBoundInfo->getType();
716 TypeLoc qual = typeBoundInfo->getTypeLoc().findExplicitQualifierLoc();
723 if (attr.getTypePtr()->getImmediateNullability()) {
735 : typeBoundInfo->getTypeLoc().getBeginLoc(),
773 // We know that the array only contains Objective-C type parameters.
780 // We do this now because Objective-C type parameters aren't pushed into
785 auto known = knownParams.find(typeParam->getIdentifier());
787 Diag(typeParam->getLocation(), diag::err_objc_type_param_redecl)
788 << typeParam->getIdentifier()
789 << SourceRange(known->second->getLocation());
791 typeParam->setInvalidDecl();
793 knownParams.insert(std::make_pair(typeParam->getIdentifier(), typeParam));
807 if (!typeParam->isInvalidDecl()) {
808 S->RemoveDecl(typeParam);
815 /// The context in which an Objective-C type parameter list occurs, for use
825 /// Check consistency between two Objective-C type parameter lists, e.g.,
833 if (prevTypeParams->size() != newTypeParams->size()) {
835 if (newTypeParams->size() > prevTypeParams->size()) {
836 diagLoc = newTypeParams->begin()[prevTypeParams->size()]->getLocation();
838 diagLoc = S.getLocForEndOfToken(newTypeParams->back()->getEndLoc());
843 << (newTypeParams->size() > prevTypeParams->size())
844 << prevTypeParams->size()
845 << newTypeParams->size();
851 for (unsigned i = 0, n = prevTypeParams->size(); i != n; ++i) {
852 ObjCTypeParamDecl *prevTypeParam = prevTypeParams->begin()[i];
853 ObjCTypeParamDecl *newTypeParam = newTypeParams->begin()[i];
856 if (newTypeParam->getVariance() != prevTypeParam->getVariance()) {
857 if (newTypeParam->getVariance() == ObjCTypeParamVariance::Invariant &&
861 newTypeParam->setVariance(prevTypeParam->getVariance());
862 } else if (prevTypeParam->getVariance()
864 !(isa<ObjCInterfaceDecl>(prevTypeParam->getDeclContext()) &&
865 cast<ObjCInterfaceDecl>(prevTypeParam->getDeclContext())
866 ->getDefinition() == prevTypeParam->getDeclContext())) {
873 SourceLocation diagLoc = newTypeParam->getVarianceLoc();
875 diagLoc = newTypeParam->getBeginLoc();
879 << static_cast<unsigned>(newTypeParam->getVariance())
880 << newTypeParam->getDeclName()
881 << static_cast<unsigned>(prevTypeParam->getVariance())
882 << prevTypeParam->getDeclName();
883 switch (prevTypeParam->getVariance()) {
885 diag << FixItHint::CreateRemoval(newTypeParam->getVarianceLoc());
891 = prevTypeParam->getVariance() == ObjCTypeParamVariance::Covariant
894 if (newTypeParam->getVariance()
896 diag << FixItHint::CreateInsertion(newTypeParam->getBeginLoc(),
899 diag << FixItHint::CreateReplacement(newTypeParam->getVarianceLoc(),
906 S.Diag(prevTypeParam->getLocation(), diag::note_objc_type_param_here)
907 << prevTypeParam->getDeclName();
910 newTypeParam->setVariance(prevTypeParam->getVariance());
915 if (S.Context.hasSameType(prevTypeParam->getUnderlyingType(),
916 newTypeParam->getUnderlyingType()))
921 if (newTypeParam->hasExplicitBound()) {
922 SourceRange newBoundRange = newTypeParam->getTypeSourceInfo()
923 ->getTypeLoc().getSourceRange();
925 << newTypeParam->getUnderlyingType()
926 << newTypeParam->getDeclName()
927 << prevTypeParam->hasExplicitBound()
928 << prevTypeParam->getUnderlyingType()
929 << (newTypeParam->getDeclName() == prevTypeParam->getDeclName())
930 << prevTypeParam->getDeclName()
933 prevTypeParam->getUnderlyingType().getAsString(
936 S.Diag(prevTypeParam->getLocation(), diag::note_objc_type_param_here)
937 << prevTypeParam->getDeclName();
952 = S.getLocForEndOfToken(newTypeParam->getLocation());
954 = " : " + prevTypeParam->getUnderlyingType().getAsString(
956 S.Diag(newTypeParam->getLocation(),
958 << prevTypeParam->getUnderlyingType()
959 << newTypeParam->getDeclName()
963 S.Diag(prevTypeParam->getLocation(), diag::note_objc_type_param_here)
964 << prevTypeParam->getDeclName();
992 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
998 if (PrevIDecl && PrevIDecl->getIdentifier() != ClassName) {
1008 // otherwise we will break IdentifierResolver and redecls-chain invariants.
1011 ClassName = PrevIDecl->getIdentifier();
1017 if (ObjCTypeParamList *prevTypeParamList = PrevIDecl->getTypeParamList()) {
1028 Diag(prevTypeParamList->getLAngleLoc(), diag::note_previous_decl)
1035 Context, SemaRef.CurContext, typeParam->getVariance(),
1036 SourceLocation(), typeParam->getIndex(), SourceLocation(),
1037 typeParam->getIdentifier(), SourceLocation(),
1039 typeParam->getUnderlyingType())));
1055 if (ObjCInterfaceDecl *Def = PrevIDecl->getDefinition()) {
1057 SkipBody->CheckSameAsPrevious = true;
1058 SkipBody->New = IDecl;
1059 SkipBody->Previous = Def;
1062 << PrevIDecl->getDeclName();
1063 Diag(Def->getLocation(), diag::note_previous_definition);
1064 IDecl->setInvalidDecl();
1081 if (SkipBody && SkipBody->CheckSameAsPrevious)
1082 IDecl->startDuplicateDefinitionForComparison();
1083 else if (!IDecl->hasDefinition())
1084 IDecl->startDefinition();
1095 IDecl->setEndOfDefinitionLoc(ClassLoc);
1102 IDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs,
1104 IDecl->setEndOfDefinitionLoc(EndProtoLoc);
1112 /// ActOnTypedefedProtocols - this action finds protocol list as part of the
1127 QualType T = TDecl->getUnderlyingType();
1128 if (T->isObjCObjectType())
1129 if (const ObjCObjectType *OPT = T->getAs<ObjCObjectType>()) {
1130 ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end());
1135 ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc);
1140 /// ActOnCompatibilityAlias - this action is called after complete parsing of
1154 Diag(ADecl->getLocation(), diag::note_previous_declaration);
1163 QualType T = TDecl->getUnderlyingType();
1164 if (T->isObjCObjectType()) {
1165 if (NamedDecl *IDecl = T->castAs<ObjCObjectType>()->getInterface()) {
1166 ClassName = IDecl->getIdentifier();
1177 Diag(CDeclU->getLocation(), diag::note_previous_declaration);
1198 if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier(), Ploc)) {
1199 if (PDecl->getIdentifier() == PName) {
1205 if (!PDecl->hasDefinition())
1209 PDecl->getLocation(), PDecl->getReferencedProtocols()))
1228 if (ObjCProtocolDecl *Def = PrevDecl? PrevDecl->getDefinition() : nullptr) {
1238 SkipBody->CheckSameAsPrevious = true;
1239 SkipBody->New = PDecl;
1240 SkipBody->Previous = Def;
1244 Diag(Def->getLocation(), diag::note_previous_definition);
1251 PDecl->startDuplicateDefinitionForComparison();
1255 // only happen if this protocol was forward-declared.
1259 ProtocolName, ProtocolLoc, PrevDecl->getLocation(), PList);
1268 PDecl->startDefinition();
1283 PDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs,
1294 if (!PDecl->hasDefinition() ||
1295 !PDecl->getDefinition()->isUnconditionallyVisible()) {
1300 for (auto *PI : PDecl->protocols())
1308 /// FindProtocolDeclaration - This routine looks up protocols and
1334 if (!PDecl->isThisDeclarationADefinition() && PDecl->getDefinition())
1335 PDecl = PDecl->getDefinition();
1337 // For an objc container, delay protocol reference checking until after we
1351 Diag(UndefinedProtocol->getLocation(), diag::note_protocol_decl_undefined)
1360 // Objective-C protocols or valid Objective-C type arguments.
1390 if (type->isObjCObjectPointerType() ||
1391 type->isBlockPointerType() ||
1392 type->isDependentType() ||
1393 type->isObjCObjectType())
1399 // If we have an Objective-C class type, accept it; there will
1449 if (const auto *objcObjectType = base->getAs<ObjCObjectType>()) {
1450 baseClass = objcObjectType->getInterface();
1452 if (auto typeParams = baseClass->getTypeParamList()) {
1453 if (typeParams->size() == numProtocolsResolved) {
1465 // For an objc container, delay protocol reference checking until after we
1472 if (!proto->isThisDeclarationADefinition() && proto->getDefinition())
1473 proto = proto->getDefinition();
1482 << proto->getDeclName();
1483 Diag(forwardDecl->getLocation(), diag::note_protocol_decl_undefined)
1508 // one is an Objective-C class name. Check whether all of the
1524 << baseClass->getDeclName() << SourceRange(lAngleLoc, rAngleLoc)
1548 // Objective-C class names. The latter is technically ill-formed,
1580 // Objective-C class declaration.
1582 -> TypeResult {
1603 // If we have a typedef of an Objective-C class type that is missing a '*',
1605 if (type->getAs<ObjCInterfaceType>()) {
1649 // Objective-C class names, we have type arguments.
1725 // Did we find an Objective-C class?
1759 /// DiagnoseClassExtensionDupMethods - Check for duplicate declaration of
1768 for (auto *MD : ID->methods())
1769 MethodMap[MD->getSelector()] = MD;
1773 for (const auto *Method : CAT->methods()) {
1774 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
1776 (PrevMethod->isInstanceMethod() == Method->isInstanceMethod()) &&
1778 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
1779 << Method->getDeclName();
1780 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
1785 /// ActOnForwardProtocolDeclaration - Handle \@protocol foo;
1837 CDecl->setInvalidDecl();
1838 SemaRef.CurContext->addDecl(CDecl);
1846 if (!CategoryName && IDecl->getImplementation()) {
1848 Diag(IDecl->getImplementation()->getLocation(),
1855 = IDecl->FindCategoryDeclaration(CategoryName)) {
1859 Diag(Previous->getLocation(), diag::note_previous_definition);
1865 if (auto prevTypeParamList = IDecl->getTypeParamList()) {
1872 Diag(typeParamList->getLAngleLoc(),
1876 << typeParamList->getSourceRange();
1886 SemaRef.CurContext->addDecl(CDecl);
1897 CDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs,
1900 if (CDecl->IsClassExtension())
1901 IDecl->mergeClassExtensionProtocolList((ObjCProtocolDecl*const*)ProtoRefs,
1910 /// ActOnStartCategoryImplementation - Perform semantic checks on the
1920 if (IDecl && IDecl->hasDefinition()) {
1921 CatIDecl = IDecl->FindCategoryDeclaration(CatName);
1929 CatIDecl->setImplicit();
1939 CDecl->setInvalidDecl();
1943 CDecl->setInvalidDecl();
1950 SemaRef.CurContext->addDecl(CDecl);
1954 if (IDecl && IDecl->hasAttr<ObjCRuntimeVisibleAttr>()) {
1956 << IDecl->getDeclName();
1961 if (CatIDecl->getImplementation()) {
1964 Diag(CatIDecl->getImplementation()->getLocation(),
1966 CDecl->setInvalidDecl();
1968 CatIDecl->setImplementation(CDecl);
1970 // -Wdeprecated-implementations flag.
1972 CDecl->getLocation());
1993 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
2008 // code-modification hint or use the typo name for recovery, because
2028 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
2031 if (SDecl && !SDecl->hasDefinition())
2036 else if (IDecl && !declaresSameEntity(IDecl->getSuperClass(), SDecl)) {
2040 << SDecl->getDeclName();
2041 Diag(SDecl->getLocation(), diag::note_previous_definition);
2057 IDecl->startDefinition();
2059 IDecl->setSuperClass(Context.getTrivialTypeSourceInfo(
2062 IDecl->setEndOfDefinitionLoc(SuperClassLoc);
2064 IDecl->setEndOfDefinitionLoc(ClassLoc);
2072 if (!IDecl->hasDefinition())
2073 IDecl->startDefinition();
2089 if (IDecl->getImplementation()) {
2092 Diag(IDecl->getImplementation()->getLocation(),
2094 IMPDecl->setInvalidDecl();
2096 IDecl->setImplementation(IMPDecl);
2099 // -Wdeprecated-implementations flag.
2100 DiagnoseObjCImplementedDeprecations(SemaRef, IDecl, IMPDecl->getLocation());
2105 if (IDecl->getSuperClass() &&
2106 IDecl->getSuperClass()->hasAttr<ObjCRuntimeVisibleAttr>()) {
2108 << IDecl->getDeclName()
2109 << IDecl->getSuperClass()->getDeclName();
2126 if (Dcl->getDeclContext()->isFileContext())
2127 Dcl->setTopLevelDeclInObjCContainer();
2141 ObjCInterfaceDecl* IDecl = ImpDecl->getClassInterface();
2144 /// Check case of non-existing \@interface decl.
2145 /// (legacy objective-c \@implementation decl without an \@interface decl).
2147 if (IDecl->isImplicitInterfaceDecl()) {
2148 IDecl->setEndOfDefinitionLoc(RBrace);
2151 ivars[i]->setLexicalDeclContext(ImpDecl);
2153 // ObjCInterfaceDecl while in a 'non-fragile' runtime the ivar is
2154 // only in the ObjCImplementationDecl. In the non-fragile case the ivar
2157 IDecl->makeDeclVisibleInContext(ivars[i]);
2158 ImpDecl->addDecl(ivars[i]);
2169 if (ImpDecl->getSuperClass())
2170 Diag(ImpDecl->getLocation(), diag::warn_on_superclass_use);
2174 IDecl->getIvarDecl(ImplIvar->getIdentifier())) {
2175 Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration);
2176 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2180 for (const auto *CDecl : IDecl->visible_extensions()) {
2182 CDecl->getIvarDecl(ImplIvar->getIdentifier())) {
2183 Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration);
2184 Diag(ClsExtIvar->getLocation(), diag::note_previous_definition);
2189 ImplIvar->setLexicalDeclContext(ImpDecl);
2190 IDecl->makeDeclVisibleInContext(ImplIvar);
2191 ImpDecl->addDecl(ImplIvar);
2200 IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end();
2208 if (!Context.hasSameType(ImplIvar->getType(), ClsIvar->getType())) {
2209 Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type)
2210 << ImplIvar->getIdentifier()
2211 << ImplIvar->getType() << ClsIvar->getType();
2212 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2213 } else if (ImplIvar->isBitField() && ClsIvar->isBitField() &&
2214 ImplIvar->getBitWidthValue(Context) !=
2215 ClsIvar->getBitWidthValue(Context)) {
2216 Diag(ImplIvar->getBitWidth()->getBeginLoc(),
2218 << ImplIvar->getIdentifier();
2219 Diag(ClsIvar->getBitWidth()->getBeginLoc(),
2223 if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
2224 Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name)
2225 << ImplIvar->getIdentifier() << ClsIvar->getIdentifier();
2226 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
2228 --numIvars;
2232 Diag(ivars[j]->getLocation(), diag::err_inconsistent_ivar_count);
2234 Diag(IVI->getLocation(), diag::err_inconsistent_ivar_count);
2239 return M->getAvailability() != AR_Unavailable;
2256 S.Diag(Impl->getLocation(), DiagID);
2264 method->print(Out, Impl->getASTContext().getPrintingPolicy());
2267 SourceLocation Loc = Impl->getAtEndRange().getBegin();
2272 SourceLocation MethodLoc = method->getBeginLoc();
2283 /// Object types in Objective-C describe the minimum requirements for an
2287 /// anywhere that we may use an instance of B - it will implement all of the
2307 /// for explicit down-casting by callers.
2314 // Reject a protocol-unqualified id.
2315 if (rejectId && B->isObjCIdType()) return false;
2321 if (B->isObjCQualifiedIdType()) {
2322 return A->isObjCQualifiedIdType() &&
2334 if (B->isObjCQualifiedIdType()) return false;
2337 // Now we know that A and B are (potentially-qualified) class types. The
2343 return (TSI ? TSI->getTypeLoc().getSourceRange() : SourceRange());
2346 /// Determine whether two set of Objective-C declaration qualifiers conflict.
2360 objcModifiersConflict(MethodDecl->getObjCDeclQualifier(),
2361 MethodImpl->getObjCDeclQualifier())) {
2363 S.Diag(MethodImpl->getLocation(),
2367 << MethodImpl->getDeclName()
2368 << MethodImpl->getReturnTypeSourceRange();
2369 S.Diag(MethodDecl->getLocation(), diag::note_previous_declaration)
2370 << MethodDecl->getReturnTypeSourceRange();
2376 !isa<ObjCImplementationDecl>(MethodImpl->getDeclContext()) &&
2377 !S.Context.hasSameNullabilityTypeQualifier(MethodImpl->getReturnType(),
2378 MethodDecl->getReturnType(),
2380 auto nullabilityMethodImpl = *MethodImpl->getReturnType()->getNullability();
2381 auto nullabilityMethodDecl = *MethodDecl->getReturnType()->getNullability();
2382 S.Diag(MethodImpl->getLocation(),
2385 ((MethodImpl->getObjCDeclQualifier() &
2388 ((MethodDecl->getObjCDeclQualifier() &
2390 S.Diag(MethodDecl->getLocation(), diag::note_previous_declaration);
2393 if (S.Context.hasSameUnqualifiedType(MethodImpl->getReturnType(),
2394 MethodDecl->getReturnType()))
2406 MethodImpl->getReturnType()->getAs<ObjCObjectPointerType>()) {
2408 MethodDecl->getReturnType()->getAs<ObjCObjectPointerType>()) {
2409 // Allow non-matching return types as long as they don't violate
2412 // or that are more-qualified versions of the declared type.
2422 S.Diag(MethodImpl->getLocation(), DiagID)
2423 << MethodImpl->getDeclName() << MethodDecl->getReturnType()
2424 << MethodImpl->getReturnType()
2425 << MethodImpl->getReturnTypeSourceRange();
2426 S.Diag(MethodDecl->getLocation(), IsOverridingMode
2429 << MethodDecl->getReturnTypeSourceRange();
2442 objcModifiersConflict(ImplVar->getObjCDeclQualifier(),
2443 IfaceVar->getObjCDeclQualifier())) {
2446 S.Diag(ImplVar->getLocation(),
2448 << getTypeRange(ImplVar->getTypeSourceInfo())
2449 << MethodImpl->getDeclName();
2450 else S.Diag(ImplVar->getLocation(),
2452 << getTypeRange(ImplVar->getTypeSourceInfo())
2453 << MethodImpl->getDeclName();
2454 S.Diag(IfaceVar->getLocation(), diag::note_previous_declaration)
2455 << getTypeRange(IfaceVar->getTypeSourceInfo());
2461 QualType ImplTy = ImplVar->getType();
2462 QualType IfaceTy = IfaceVar->getType();
2464 !isa<ObjCImplementationDecl>(MethodImpl->getDeclContext()) &&
2466 S.Diag(ImplVar->getLocation(),
2468 << DiagNullabilityKind(*ImplTy->getNullability(),
2469 ((ImplVar->getObjCDeclQualifier() &
2471 << DiagNullabilityKind(*IfaceTy->getNullability(),
2472 ((IfaceVar->getObjCDeclQualifier() &
2474 S.Diag(IfaceVar->getLocation(), diag::note_previous_declaration);
2488 ImplTy->getAs<ObjCObjectPointerType>()) {
2490 IfaceTy->getAs<ObjCObjectPointerType>()) {
2491 // Allow non-matching argument types as long as they don't
2504 S.Diag(ImplVar->getLocation(), DiagID)
2505 << getTypeRange(ImplVar->getTypeSourceInfo())
2506 << MethodImpl->getDeclName() << IfaceTy << ImplTy;
2507 S.Diag(IfaceVar->getLocation(),
2510 << getTypeRange(IfaceVar->getTypeSourceInfo());
2518 ObjCMethodFamily implFamily = impl->getMethodFamily();
2519 ObjCMethodFamily declFamily = decl->getMethodFamily();
2528 if (impl->isInvalidDecl() || decl->isInvalidDecl()) return true;
2574 if (unmatched->getReturnType()->isObjCObjectPointerType()) {
2580 S.Diag(impl->getLocation(), errorID) << int(familySelector) << int(reasonSelector);
2581 S.Diag(decl->getLocation(), noteID) << int(familySelector) << int(reasonSelector);
2596 for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
2597 IF = MethodDecl->param_begin(), EM = ImpMethodDecl->param_end(),
2598 EF = MethodDecl->param_end();
2604 if (ImpMethodDecl->isVariadic() != MethodDecl->isVariadic()) {
2605 Diag(ImpMethodDecl->getLocation(),
2607 Diag(MethodDecl->getLocation(), diag::note_previous_declaration);
2618 for (ObjCMethodDecl::param_iterator IM = Method->param_begin(),
2619 IF = Overridden->param_begin(), EM = Method->param_end(),
2620 EF = Overridden->param_end();
2626 if (Method->isVariadic() != Overridden->isVariadic()) {
2627 Diag(Method->getLocation(),
2629 Diag(Overridden->getLocation(), diag::note_previous_declaration);
2633 /// WarnExactTypedMethods - This routine issues a warning if method
2642 if (MethodDecl->getImplementationControl() ==
2647 if (MethodDecl->hasAttr<UnavailableAttr>() ||
2648 MethodDecl->hasAttr<DeprecatedAttr>())
2654 for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
2655 IF = MethodDecl->param_begin(), EM = ImpMethodDecl->param_end(),
2656 EF = MethodDecl->param_end();
2664 match = (ImpMethodDecl->isVariadic() == MethodDecl->isVariadic());
2666 match = !(MethodDecl->isClassMethod() &&
2667 MethodDecl->getSelector() == GetNullarySelector("load", Context));
2670 Diag(ImpMethodDecl->getLocation(),
2672 Diag(MethodDecl->getLocation(), diag::note_method_declared_at)
2673 << MethodDecl->getDeclName();
2677 /// FIXME: Type hierarchies in Objective-C can be deep. We could most likely
2688 if (PDecl->hasAttr<ObjCExplicitProtocolImplAttr>())
2689 PNS.insert(PDecl->getIdentifier());
2690 for (const auto *PI : PDecl->protocols())
2702 for (const auto *I : Super->all_referenced_protocols())
2705 findProtocolsWithExplicitImpls(Super->getSuperClass(), PNS);
2708 /// CheckProtocolMethodDefs - This routine checks unimplemented methods
2715 ObjCInterfaceDecl *IDecl = C ? C->getClassInterface()
2717 assert (IDecl && "CheckProtocolMethodDefs - IDecl is null");
2719 ObjCInterfaceDecl *Super = IDecl->getSuperClass();
2733 if (PDecl->hasAttr<ObjCExplicitProtocolImplAttr>()) {
2738 if (ProtocolsExplictImpl->contains(PDecl->getIdentifier()))
2759 NSIDecl = IDecl->lookupInheritedClass(&S.Context.Idents.get("NSProxy"));
2763 if (!PDecl->isThisDeclarationADefinition() &&
2764 PDecl->getDefinition())
2765 PDecl = PDecl->getDefinition();
2774 for (auto *method : PDecl->instance_methods()) {
2775 if (method->getImplementationControl() !=
2777 !method->isPropertyAccessor() &&
2778 !InsMap.count(method->getSelector()) &&
2779 (!Super || !Super->lookupMethod(
2780 method->getSelector(), true /* instance */,
2792 if (ObjCMethodDecl *MethodInClass = IDecl->lookupMethod(
2793 method->getSelector(), true /* instance */,
2795 if (C || MethodInClass->isPropertyAccessor())
2798 if (!S.Diags.isIgnored(DIAG, Impl->getLocation())) {
2804 for (auto *method : PDecl->class_methods()) {
2805 if (method->getImplementationControl() !=
2807 !ClsMap.count(method->getSelector()) &&
2808 (!Super || !Super->lookupMethod(
2809 method->getSelector(), false /* class method */,
2813 if (C && IDecl->lookupMethod(method->getSelector(),
2820 if (!S.Diags.isIgnored(DIAG, Impl->getLocation())) {
2826 for (auto *PI : PDecl->protocols())
2831 /// MatchAllMethodDeclarations - Check methods declared in interface
2841 for (auto *I : CDecl->instance_methods()) {
2842 if (!InsMapSeen.insert(I->getSelector()).second)
2844 if (!I->isPropertyAccessor() &&
2845 !InsMap.count(I->getSelector())) {
2852 IMPDecl->getInstanceMethod(I->getSelector());
2853 assert(CDecl->getInstanceMethod(I->getSelector(), true/*AllowHidden*/) &&
2858 if (ImpMethodDecl->isSynthesizedAccessorStub())
2863 else if (!I->isPropertyAccessor())
2871 for (auto *I : CDecl->class_methods()) {
2872 if (!ClsMapSeen.insert(I->getSelector()).second)
2874 if (!I->isPropertyAccessor() &&
2875 !ClsMap.count(I->getSelector())) {
2881 IMPDecl->getClassMethod(I->getSelector());
2882 assert(CDecl->getClassMethod(I->getSelector(), true/*AllowHidden*/) &&
2887 if (ImpMethodDecl->isSynthesizedAccessorStub())
2892 else if (!I->isPropertyAccessor())
2901 for (auto *PI : PD->protocols())
2912 for (auto *Cat : I->visible_categories())
2915 ImmediateClass && Cat->IsClassExtension(),
2919 for (auto *Ext : I->visible_extensions())
2926 for (auto *PI : I->all_referenced_protocols())
2933 if (!WarnCategoryMethodImpl && I->getSuperClass())
2936 I->getSuperClass(), IncompleteImpl, false);
2940 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in
2946 ObjCCategoryDecl *CatDecl = CatIMPDecl->getCategoryDecl();
2949 ObjCInterfaceDecl *IDecl = CatDecl->getClassInterface();
2952 ObjCInterfaceDecl *SuperIDecl = IDecl->getSuperClass();
2955 for (const auto *I : CatIMPDecl->instance_methods()) {
2956 Selector Sel = I->getSelector();
2960 if (SuperIDecl && SuperIDecl->lookupMethod(Sel, true))
2965 for (const auto *I : CatIMPDecl->class_methods()) {
2966 Selector Sel = I->getSelector();
2967 if (SuperIDecl && SuperIDecl->lookupMethod(Sel, false))
2988 for (const auto *I : IMPDecl->instance_methods())
2989 InsMap.insert(I->getSelector());
2992 for (const auto *PImpl : IMPDecl->property_impls()) {
2994 if (PImpl->getPropertyImplementation() != ObjCPropertyImplDecl::Dynamic)
2997 const auto *P = PImpl->getPropertyDecl();
3000 InsMap.insert(P->getGetterName());
3001 if (!P->getSetterName().isNull())
3002 InsMap.insert(P->getSetterName());
3011 !IDecl->isObjCRequiresPropertyDefs();
3015 // Diagnose null-resettable synthesized setters.
3019 for (const auto *I : IMPDecl->class_methods())
3020 ClsMap.insert(I->getSelector());
3043 for (auto *PI : I->all_referenced_protocols())
3049 if (!C->IsClassExtension()) {
3050 for (auto *P : C->protocols())
3080 if (!TDD || !TDD->getUnderlyingType()->isObjCObjectType()) {
3082 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
3088 if (isa<ObjCObjectType>(TDD->getUnderlyingType())) {
3091 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
3102 if (PrevIDecl && PrevIDecl->getIdentifier() != ClassName) {
3112 // otherwise we will break IdentifierResolver and redecls-chain invariants.
3115 ClassName = PrevIDecl->getIdentifier();
3122 if (ObjCTypeParamList *PrevTypeParams = PrevIDecl->getTypeParamList()) {
3129 } else if (ObjCInterfaceDecl *Def = PrevIDecl->getDefinition()) {
3133 << TypeParams->getSourceRange();
3134 Diag(Def->getLocation(), diag::note_defined_here)
3144 IDecl->setAtEndRange(IdentLocs[i]);
3175 if (left->isIncompleteType() || right->isIncompleteType()) return false;
3178 // validate the basic, low-level compatibility of the two types.
3189 // Consider all the kinds of non-dependent canonical types:
3190 // - functions and arrays aren't possible as return and parameter types
3192 // - vector types of equal size can be arbitrarily mixed
3196 // - references should only match references of identical type
3197 // - structs, unions, and Objective-C objects must match more-or-less
3199 // - everything else should be a scalar
3200 if (!left->isScalarType() || !right->isScalarType())
3204 // all non-member pointers together.
3205 Type::ScalarTypeKind leftSK = left->getScalarTypeKind();
3206 Type::ScalarTypeKind rightSK = right->getScalarTypeKind();
3226 RecordDecl *left = cast<RecordType>(lt)->getDecl();
3227 RecordDecl *right = cast<RecordType>(rt)->getDecl();
3229 // Require union-hood to match.
3230 if (left->isUnion() != right->isUnion()) return false;
3232 // Require an exact match if either is non-POD.
3233 if ((isa<CXXRecordDecl>(left) && !cast<CXXRecordDecl>(left)->isPOD()) ||
3234 (isa<CXXRecordDecl>(right) && !cast<CXXRecordDecl>(right)->isPOD()))
3247 RecordDecl::field_iterator li = left->field_begin(), le = left->field_end();
3248 RecordDecl::field_iterator ri = right->field_begin(), re = right->field_end();
3250 if (!matchTypes(Context, strategy, li->getType(), ri->getType()))
3256 /// MatchTwoMethodDeclarations - Checks that two methods have matching type and
3263 if (!matchTypes(Context, strategy, left->getReturnType(),
3264 right->getReturnType()))
3268 if (!left->isUnconditionallyVisible() || !right->isUnconditionallyVisible())
3271 if (left->isDirectMethod() != right->isDirectMethod())
3275 (left->hasAttr<NSReturnsRetainedAttr>()
3276 != right->hasAttr<NSReturnsRetainedAttr>() ||
3277 left->hasAttr<NSConsumesSelfAttr>()
3278 != right->hasAttr<NSConsumesSelfAttr>()))
3282 li = left->param_begin(), le = left->param_end(), ri = right->param_begin(),
3283 re = right->param_end();
3286 assert(ri != right->param_end() && "Param mismatch");
3289 if (!matchTypes(Context, strategy, lparm->getType(), rparm->getType()))
3293 lparm->hasAttr<NSConsumedAttr>() != rparm->hasAttr<NSConsumedAttr>())
3301 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext());
3303 dyn_cast<ObjCProtocolDecl>(MethodInList->getDeclContext());
3313 ObjCInterfaceDecl *MethodInterface = Method->getClassInterface();
3315 MethodInList->getClassInterface();
3324 dyn_cast<ObjCCategoryDecl>(Method->getDeclContext()))
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()) {
3345 List->getMethod());
3357 !isMethodContextSameForKindofLookup(Method, List->getMethod())) {
3361 if (!Method->isDefined())
3362 List->setHasMoreThanOneDecl(true);
3366 if (Method->isDeprecated() && SameDeclaration &&
3367 !ListWithSameDeclaration && !List->getMethod()->isDeprecated())
3370 if (Method->isUnavailable() && SameDeclaration &&
3372 List->getMethod()->getAvailability() < AR_Deprecated)
3377 ObjCMethodDecl *PrevObjCMethod = List->getMethod();
3380 if (Method->isDefined())
3381 PrevObjCMethod->setDefined(true);
3383 // Objective-C doesn't allow an @interface for a class after its
3387 List->setHasMoreThanOneDecl(true);
3392 if (Method->isDeprecated()) {
3393 if (!PrevObjCMethod->isDeprecated())
3394 List->setMethod(Method);
3398 if (Method->isUnavailable()) {
3399 if (PrevObjCMethod->getAvailability() < AR_Deprecated)
3400 List->setMethod(Method);
3406 // We have a new signature for an existing method - add it.
3414 ListWithSameDeclaration->setMethod(Method);
3415 ListWithSameDeclaration->setNext(List);
3419 Previous->setNext(new (Mem) ObjCMethodList(Method));
3426 SemaRef.ExternalSource->ReadMethodPool(Sel);
3432 SemaRef.ExternalSource->updateOutOfDateSelector(Sel);
3438 if (cast<Decl>(Method->getDeclContext())->isInvalidDecl())
3442 ReadMethodPool(Method->getSelector());
3444 GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector());
3447 .insert(std::make_pair(Method->getSelector(),
3451 Method->setDefined(impl);
3453 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
3464 if (!chosen->isInstanceMethod())
3467 if (chosen->isDirectMethod() != other->isDirectMethod())
3470 Selector sel = chosen->getSelector();
3474 // Don't complain about mismatches for -length if the method we
3476 return (chosen->getReturnType()->isIntegerType());
3485 if (TypeBound->isObjCId())
3489 auto *BoundInterface = TypeBound->getInterface();
3494 auto *MethodProtocol = dyn_cast<ObjCProtocolDecl>(Method->getDeclContext());
3501 if (ObjCInterfaceDecl *MethodInterface = Method->getClassInterface()) {
3506 MethodInterface->isSuperClassOf(BoundInterface) ||
3507 BoundInterface->isSuperClassOf(MethodInterface);
3524 // Gather the non-hidden methods.
3525 ObjCMethodList &MethList = InstanceFirst ? Pos->second.first :
3526 Pos->second.second;
3527 for (ObjCMethodList *M = &MethList; M; M = M->getNext())
3528 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3529 if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
3530 Methods.push_back(M->getMethod());
3541 ObjCMethodList &MethList2 = InstanceFirst ? Pos->second.second :
3542 Pos->second.first;
3543 for (ObjCMethodList *M = &MethList2; M; M = M->getNext())
3544 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible()) {
3545 if (FilterMethodsByTypeBound(M->getMethod(), TypeBound))
3546 Methods.push_back(M->getMethod());
3560 if (M != BestMethod && !M->hasAttr<UnavailableAttr>())
3573 BestMethod->isInstanceMethod() ? Pos->second.first : Pos->second.second;
3587 // Gather the non-hidden methods.
3588 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
3590 for (ObjCMethodList *M = &MethList; M; M = M->getNext()) {
3591 if (M->getMethod() && M->getMethod()->isUnconditionallyVisible())
3592 return M->getMethod();
3642 Diag(Methods[0]->getBeginLoc(),
3644 << Methods[0]->getSourceRange();
3646 Diag(Methods[I]->getBeginLoc(), diag::note_also_found)
3647 << Methods[I]->getSourceRange();
3657 GlobalMethodPool::Lists &Methods = Pos->second;
3659 Method = Method->getNext())
3660 if (Method->getMethod() &&
3661 (Method->getMethod()->isDefined() ||
3662 Method->getMethod()->isPropertyAccessor()))
3663 return Method->getMethod();
3666 Method = Method->getNext())
3667 if (Method->getMethod() &&
3668 (Method->getMethod()->isDefined() ||
3669 Method->getMethod()->isPropertyAccessor()))
3670 return Method->getMethod();
3680 std::string MethodName = Method->getSelector().getAsString();
3682 unsigned MinPossibleEditDistance = abs((int)MethodName.size() - (int)Typo.size());
3715 else if (!ObjectType->isObjCObjectPointerType())
3718 ObjectType->getAsObjCInterfacePointerType()) {
3719 ObjectType = QualType(ObjCPtr->getInterfaceType(), 0);
3722 else if (ObjectType->isObjCIdType() || ObjectType->isObjCQualifiedIdType())
3724 else if (ObjectType->isObjCClassType() || ObjectType->isObjCQualifiedClassType())
3732 for (ObjCMethodList *M = &b->second.first; M; M=M->getNext())
3733 if (M->getMethod() &&
3734 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3735 (M->getMethod()->getSelector() != Sel)) {
3737 Methods.push_back(M->getMethod());
3740 SemaRef, M->getMethod()->getSelector(), ObjectType))
3741 Methods.push_back(M->getMethod());
3744 for (ObjCMethodList *M = &b->second.second; M; M=M->getNext())
3745 if (M->getMethod() &&
3746 (M->getMethod()->getSelector().getNumArgs() == NumArgs) &&
3747 (M->getMethod()->getSelector() != Sel)) {
3749 Methods.push_back(M->getMethod());
3752 SemaRef, M->getMethod()->getSelector(), ObjectType))
3753 Methods.push_back(M->getMethod());
3765 /// DiagnoseDuplicateIvars -
3772 for (auto *Ivar : ID->ivars()) {
3773 if (Ivar->isInvalidDecl())
3775 if (IdentifierInfo *II = Ivar->getIdentifier()) {
3776 ObjCIvarDecl* prevIvar = SID->lookupInstanceVariable(II);
3778 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
3779 Diag(prevIvar->getLocation(), diag::note_previous_declaration);
3780 Ivar->setInvalidDecl();
3786 /// Diagnose attempts to define ARC-__weak ivars when __weak is disabled.
3790 for (auto ivar = ID->getClassInterface()->all_declared_ivar_begin();
3791 ivar; ivar = ivar->getNextIvar()) {
3792 if (ivar->isInvalidDecl()) continue;
3793 if (ivar->getType().getObjCLifetime() == Qualifiers::OCL_Weak) {
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())
3813 QualType IvarTy = ivar->getType();
3814 if (IvarTy->isIncompleteArrayType() &&
3816 IvarTy->isObjCLifetimeType()) {
3817 S.Diag(ivar->getLocation(), diag::err_flexible_array_arc_retainable);
3818 ivar->setInvalidDecl();
3824 switch (SemaRef.CurContext->getDeclKind()) {
3830 if (cast<ObjCCategoryDecl>(SemaRef.CurContext)->IsClassExtension())
3844 if (T->isIncompleteArrayType())
3846 const auto *RecordTy = T->getAs<RecordType>();
3847 return (RecordTy && RecordTy->getDecl()->hasFlexibleArrayMember());
3855 Ivars = IntfDecl->ivars();
3857 IntfDecl = ImplDecl->getClassInterface();
3858 Ivars = ImplDecl->ivars();
3860 if (CategoryDecl->IsClassExtension()) {
3861 IntfDecl = CategoryDecl->getClassInterface();
3862 Ivars = CategoryDecl->ivars();
3869 if (!ivar->isInvalidDecl() && IsVariableSizedType(ivar->getType())) {
3870 S.Diag(ivar->getLocation(), diag::warn_variable_sized_ivar_visibility)
3871 << ivar->getDeclName() << ivar->getType();
3881 for (ObjCIvarDecl *ivar = IntfDecl->all_declared_ivar_begin(); ivar;
3882 ivar = ivar->getNextIvar()) {
3883 if (ivar->isInvalidDecl() || !ivar->getNextIvar())
3885 QualType IvarTy = ivar->getType();
3887 if (IvarTy->isIncompleteArrayType()) {
3888 S.Diag(ivar->getLocation(), diag::err_flexible_array_not_at_end)
3889 << ivar->getDeclName() << IvarTy
3890 << llvm::to_underlying(TagTypeKind::Class); // Use "class" for Obj-C.
3892 } else if (const RecordType *RecordTy = IvarTy->getAs<RecordType>()) {
3893 if (RecordTy->getDecl()->hasFlexibleArrayMember()) {
3894 S.Diag(ivar->getLocation(),
3896 << ivar->getDeclName() << IvarTy;
3901 S.Diag(ivar->getNextIvar()->getLocation(),
3903 << ivar->getNextIvar()->getSynthesize();
3904 ivar->setInvalidDecl();
3913 if (FirstIvar && (FirstIvar == IntfDecl->all_declared_ivar_begin())) {
3914 const ObjCInterfaceDecl *SuperClass = IntfDecl->getSuperClass();
3915 while (SuperClass && SuperClass->ivar_empty())
3916 SuperClass = SuperClass->getSuperClass();
3918 auto IvarIter = SuperClass->ivar_begin();
3919 std::advance(IvarIter, SuperClass->ivar_size() - 1);
3921 if (IsVariableSizedType(LastIvar->getType())) {
3922 S.Diag(FirstIvar->getLocation(),
3924 << FirstIvar->getDeclName() << LastIvar->getDeclName()
3925 << LastIvar->getType() << SuperClass->getDeclName();
3926 S.Diag(LastIvar->getLocation(), diag::note_entity_declared_at)
3927 << LastIvar->getDeclName();
3945 if (!PDecl->isThisDeclarationADefinition() && PDecl->getDefinition())
3946 PDecl = PDecl->getDefinition();
3949 const auto *IDecl = CDecl->getClassInterface();
3950 for (auto *MD : PDecl->methods()) {
3951 if (!MD->isPropertyAccessor()) {
3953 IDecl->getMethod(MD->getSelector(), MD->isInstanceMethod())) {
3954 if (CMD->isDirectMethod())
3959 for (auto *PD : PDecl->properties()) {
3960 if (const auto *CPD = IDecl->FindPropertyVisibleInPrimaryClass(
3961 PD->getIdentifier(),
3962 PD->isClassProperty()
3965 if (CPD->isDirectProperty())
3970 S.Diag(CDecl->getLocation(), diag::err_objc_direct_protocol_conformance)
3971 << CDecl->IsClassExtension() << CDecl << PDecl << IDecl;
3973 S.Diag(MD->getLocation(), diag::note_direct_member_here);
3979 PDecl->protocols());
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);
4024 if (Method->isInstanceMethod()) {
4026 const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()];
4031 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
4032 << Method->getDeclName();
4033 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
4034 Method->setInvalidDecl();
4037 Method->setAsRedeclaration(PrevMethod);
4039 Method->getLocation()))
4040 Diag(Method->getLocation(), diag::warn_duplicate_method_decl)
4041 << Method->getDeclName();
4042 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
4044 InsMap[Method->getSelector()] = Method;
4050 const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()];
4055 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
4056 << Method->getDeclName();
4057 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
4058 Method->setInvalidDecl();
4061 Method->setAsRedeclaration(PrevMethod);
4063 Method->getLocation()))
4064 Diag(Method->getLocation(), diag::warn_duplicate_method_decl)
4065 << Method->getDeclName();
4066 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
4068 ClsMap[Method->getSelector()] = Method;
4080 if (C->IsClassExtension()) {
4081 ObjCInterfaceDecl *CCPrimary = C->getClassInterface();
4086 C->protocols());
4089 if (CDecl->getIdentifier())
4091 // user-defined setter/getter. It also synthesizes setter/getter methods
4093 for (auto *I : CDecl->properties())
4095 CDecl->setAtEndRange(AtEnd);
4098 IC->setAtEndRange(AtEnd);
4099 if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) {
4105 for (const auto *Ext : IDecl->visible_extensions()) {
4106 for (const auto *Property : Ext->instance_properties()) {
4109 = IC->FindPropertyImplDecl(Property->getIdentifier(),
4110 Property->getQueryKind()))
4111 if (PIDecl->getPropertyImplementation()
4115 for (const auto *Ext : IDecl->visible_extensions()) {
4117 Ext->getInstanceMethod(Property->getGetterName()))
4118 GetterMethod->setPropertyAccessor(true);
4119 if (!Property->isReadOnly())
4121 = Ext->getInstanceMethod(Property->getSetterName()))
4122 SetterMethod->setPropertyAccessor(true);
4130 if (IDecl->hasDesignatedInitializers())
4135 bool HasRootClassAttr = IDecl->hasAttr<ObjCRootClassAttr>();
4136 if (IDecl->getSuperClass() == nullptr) {
4140 SourceLocation DeclLoc(IDecl->getLocation());
4143 << IDecl->getIdentifier();
4147 SemaRef.TUScope, NSAPIObj->getNSClassId(NSAPI::ClassId_NSObject),
4150 if (NSObjectDecl && NSObjectDecl->getDefinition()) {
4159 Diag(IDecl->getLocation(), diag::err_objc_root_class_subclass);
4162 if (const ObjCInterfaceDecl *Super = IDecl->getSuperClass()) {
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()) {
4179 DiagnoseDuplicateIvars(IDecl, IDecl->getSuperClass());
4180 IDecl = IDecl->getSuperClass();
4187 CatImplClass->setAtEndRange(AtEnd);
4191 if (ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface()) {
4193 = IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier())) {
4198 if (const ObjCInterfaceDecl *Super = IntfDecl->getSuperClass()) {
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);
4217 if (!VDecl->hasExternalStorage())
4218 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
4227 (*I)->setTopLevelDeclInObjCContainer();
4235 /// CvtQTToAstBitMask - utility routine to produce an AST bitmask for
4236 /// objective-c's type qualifier from the parser version of the same info.
4242 /// Check whether the declared result type of the given Objective-C
4248 QualType ResultType = Method->getReturnType();
4250 // If an Objective-C method inherits its related result type, then its
4254 = ResultType->getAs<ObjCObjectPointerType>()) {
4255 // - it is id or qualified id, or
4256 if (ResultObjectType->isObjCIdType() ||
4257 ResultObjectType->isObjCQualifiedIdType())
4262 = ResultObjectType->getInterfaceDecl()) {
4263 // - it is the same as the method's class type, or
4267 // - it is a superclass of the method's class type
4268 if (ResultClass->isSuperClassOf(CurrentClass))
4272 // Any Objective-C pointer type might be acceptable for a protocol
4292 Selector selector = method->getSelector();
4307 method->isInstanceMethod() ? it->second.first : it->second.second;
4311 = cast<ObjCContainerDecl>(method->getDeclContext());
4319 if (const ObjCInterfaceDecl *Interface = Category->getClassInterface())
4332 if (container->isInvalidDecl()) return;
4334 switch (container->getDeclKind()) {
4348 if (!protocol->hasDefinition())
4353 search(protocol->getReferencedProtocols());
4360 search(category->getReferencedProtocols());
4367 if (ObjCCategoryDecl *category = impl->getCategoryDecl()) {
4369 if (ObjCInterfaceDecl *Interface = category->getClassInterface())
4373 } else if (const auto *Interface = impl->getClassInterface()) {
4380 if (!iface->hasDefinition())
4383 // - categories,
4384 for (auto *Cat : iface->known_categories())
4387 // - the super class, and
4388 if (ObjCInterfaceDecl *super = iface->getSuperClass())
4391 // - any referenced protocols.
4392 search(iface->getReferencedProtocols());
4398 if (const auto *Interface = impl->getClassInterface())
4409 ObjCMethodDecl *meth = container->getMethod(Method->getSelector(),
4410 Method->isInstanceMethod(),
4432 if (overridden->isDirectMethod()) {
4433 const auto *attr = overridden->getAttr<ObjCDirectAttr>();
4434 Diag(method->getLocation(), diag::err_objc_override_direct_method);
4435 Diag(attr->getLocation(), diag::note_previous_declaration);
4436 } else if (method->isDirectMethod()) {
4437 const auto *attr = method->getAttr<ObjCDirectAttr>();
4438 Diag(attr->getLocation(), diag::err_objc_direct_on_override)
4439 << isa<ObjCProtocolDecl>(overridden->getDeclContext());
4440 Diag(overridden->getLocation(), diag::note_previous_declaration);
4452 return M->getClassInterface()->getCanonicalDecl() ==
4453 CurrentClass->getCanonicalDecl();
4465 if (isa<ObjCProtocolDecl>(overridden->getDeclContext()) ||
4466 !IsMethodInCurrentClass(overridden) || overridden->isOverriding()) {
4469 } else if (isa<ObjCImplDecl>(ObjCMethod->getDeclContext())) {
4475 // extra info bits in GlobalMethodPool to check whether there were any
4478 MethodPool.find(ObjCMethod->getSelector());
4481 ObjCMethod->isInstanceMethod()? It->second.first: It->second.second;
4487 !isa<ObjCCategoryImplDecl>(overridden->getDeclContext())) {
4490 if (isa<ObjCProtocolDecl>(SuperOverridden->getDeclContext()) ||
4494 overridden->setOverriding(true);
4505 if (RTC != SemaObjC::RTC_Incompatible && overridden->hasRelatedResultType())
4506 ObjCMethod->setRelatedResultType();
4511 if (ObjCMethod->isImplicit() && overridden->isImplicit())
4515 if (isa<ObjCInterfaceDecl>(ObjCMethod->getDeclContext()) ||
4516 isa<ObjCImplementationDecl>(ObjCMethod->getDeclContext()))
4518 isa<ObjCProtocolDecl>(overridden->getDeclContext()));
4520 if (CurrentClass && overridden->getDeclContext() != CurrentClass &&
4521 isa<ObjCInterfaceDecl>(overridden->getDeclContext()) &&
4522 !overridden->isImplicit() /* not meant for properties */) {
4523 ObjCMethodDecl::param_iterator ParamI = ObjCMethod->param_begin(),
4524 E = ObjCMethod->param_end();
4525 ObjCMethodDecl::param_iterator PrevI = overridden->param_begin(),
4526 PrevE = overridden->param_end();
4528 assert(PrevI != overridden->param_end() && "Param mismatch");
4529 QualType T1 = Context.getCanonicalType((*ParamI)->getType());
4530 QualType T2 = Context.getCanonicalType((*PrevI)->getType());
4534 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
4536 Diag(overridden->getLocation(), diag::note_previous_declaration);
4543 ObjCMethod->setOverriding(hasOverriddenMethodsInBaseOrProtocol);
4555 auto nullability = type->getNullability();
4556 auto prevNullability = prevType->getNullability();
4592 if (prevMethod->hasAttr<ObjCRequiresSuperAttr>() &&
4593 !method->hasAttr<ObjCRequiresSuperAttr>()) {
4595 method->addAttr(
4597 method->getLocation()));
4603 S, method->getReturnTypeSourceRange().getBegin(),
4604 method->getReturnType(),
4605 method->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability,
4606 prevMethod->getReturnTypeSourceRange().getBegin(),
4607 prevMethod->getReturnType(),
4608 prevMethod->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability);
4609 method->setReturnType(newReturnType);
4612 unsigned numParams = method->param_size();
4613 unsigned numPrevParams = prevMethod->param_size();
4615 ParmVarDecl *param = method->param_begin()[i];
4616 ParmVarDecl *prevParam = prevMethod->param_begin()[i];
4621 S, param->getLocation(), param->getType(),
4622 param->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability,
4623 prevParam->getLocation(), prevParam->getType(),
4624 prevParam->getObjCDeclQualifier() & Decl::OBJC_TQ_CSNullability);
4625 param->setType(newParamType);
4635 "x86-specific check invoked for a different target");
4638 for (const ParmVarDecl *P : Method->parameters()) {
4639 if (P->getType()->isVectorType()) {
4640 Loc = P->getBeginLoc();
4641 T = P->getType();
4646 if (Method->getReturnType()->isVectorType()) {
4647 Loc = Method->getReturnTypeSourceRange().getBegin();
4648 T = Method->getReturnType();
4667 << T << (Method->getReturnType()->isVectorType() ? /*return value*/ 1
4673 if (!Method->isDirectMethod() && !Method->hasAttr<UnavailableAttr>() &&
4674 CD->hasAttr<ObjCDirectMembersAttr>()) {
4675 Method->addAttr(
4676 ObjCDirectAttr::CreateImplicit(S.Context, Method->getLocation()));
4683 auto Sel = Method->getSelector();
4684 bool isInstance = Method->isInstanceMethod();
4688 if (diagnosed || IMD->isImplicit())
4690 if (Method->isDirectMethod() || IMD->isDirectMethod()) {
4691 S.Diag(Method->getLocation(), diag::err_objc_direct_duplicate_decl)
4692 << Method->isDirectMethod() << /* method */ 0 << IMD->isDirectMethod()
4693 << Method->getDeclName();
4694 S.Diag(IMD->getLocation(), diag::note_previous_declaration);
4702 // We do not use IDecl->lookupMethod() because we have specific needs:
4704 // - we absolutely do not need to walk protocols, because
4708 // - when we do not find a match in a given @interface container,
4712 if (auto *IMD = IDecl->getMethod(Sel, isInstance))
4714 else if (auto *Impl = IDecl->getImplementation())
4716 if (auto *IMD = IDecl->getImplementation()->getMethod(Sel, isInstance))
4719 for (const auto *Cat : IDecl->visible_categories())
4720 if (auto *IMD = Cat->getMethod(Sel, isInstance))
4722 else if (auto CatImpl = Cat->getImplementation())
4724 if (auto *IMD = Cat->getMethod(Sel, isInstance))
4735 unsigned CNumArgs, // c-style args
4740 if (!SemaRef.CurContext->isObjCContainer()) {
4794 if (S->isDeclScope(PrevDecl)) {
4799 Diag(PrevDecl->getLocation(),
4805 ? DI->getTypeLoc().getBeginLoc()
4812 Param->setObjCMethodScopeInfo(i);
4814 Param->setObjCDeclQualifier(
4823 if (Param->hasAttr<BlocksAttr>()) {
4824 Diag(Param->getLocation(), diag::err_block_on_nonlocal);
4825 Param->setInvalidDecl();
4827 S->AddDecl(Param);
4835 QualType ArgType = Param->getType();
4842 Param->setDeclContext(ObjCMethod);
4846 ObjCMethod->setMethodParams(Context, Params, SelectorLocs);
4847 ObjCMethod->setObjCDeclQualifier(
4858 PrevMethod = ImpDecl->getInstanceMethod(Sel);
4859 ImpDecl->addInstanceMethod(ObjCMethod);
4861 PrevMethod = ImpDecl->getClassMethod(Sel);
4862 ImpDecl->addClassMethod(ObjCMethod);
4869 // user-specified implementation.
4870 for (ObjCPropertyImplDecl *PropertyImpl : ImpDecl->property_impls()) {
4871 if (auto *Setter = PropertyImpl->getSetterMethodDecl())
4872 if (Setter->getSelector() == Sel &&
4873 Setter->isInstanceMethod() == ObjCMethod->isInstanceMethod()) {
4874 assert(Setter->isSynthesizedAccessorStub() && "autosynth stub expected");
4875 PropertyImpl->setSetterMethodDecl(ObjCMethod);
4877 if (auto *Getter = PropertyImpl->getGetterMethodDecl())
4878 if (Getter->getSelector() == Sel &&
4879 Getter->isInstanceMethod() == ObjCMethod->isInstanceMethod()) {
4880 assert(Getter->isSynthesizedAccessorStub() && "autosynth stub expected");
4881 PropertyImpl->setGetterMethodDecl(ObjCMethod);
4890 // because IDecl->lookupMethod() returns more possible matches than just
4892 if (!ObjCMethod->isDirectMethod()) {
4893 const ObjCMethodDecl *CanonicalMD = ObjCMethod->getCanonicalDecl();
4894 if (CanonicalMD->isDirectMethod()) {
4895 const auto *attr = CanonicalMD->getAttr<ObjCDirectAttr>();
4896 ObjCMethod->addAttr(
4897 ObjCDirectAttr::CreateImplicit(Context, attr->getLocation()));
4903 if (ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface()) {
4904 if (auto *IMD = IDecl->lookupMethod(ObjCMethod->getSelector(),
4905 ObjCMethod->isInstanceMethod())) {
4908 // The Idecl->lookupMethod() above will find declarations for ObjCMethod
4923 // We deal with same-class container mismatches (Case 2) here.
4924 if (IDecl == IMD->getClassInterface()) {
4928 if (auto *Cat = dyn_cast<ObjCCategoryDecl>(IMD->getDeclContext()))
4929 decl = Cat->IsClassExtension() ? 1 : 2;
4934 Diag(ObjCMethod->getLocation(),
4937 Diag(IMD->getLocation(), diag::note_previous_declaration);
4940 if (ObjCMethod->isDirectMethod()) {
4941 const auto *attr = ObjCMethod->getAttr<ObjCDirectAttr>();
4942 if (ObjCMethod->getCanonicalDecl() != IMD) {
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()) {
4949 const auto *attr = IMD->getAttr<ObjCDirectAttr>();
4950 if (ObjCMethod->getCanonicalDecl() != IMD) {
4953 ObjCMethod->addAttr(
4954 ObjCDirectAttr::CreateImplicit(Context, attr->getLocation()));
4959 // Warn about defining -dealloc in a category.
4960 if (isa<ObjCCategoryImplDecl>(ImpDecl) && IMD->isOverriding() &&
4961 ObjCMethod->getSelector().getMethodFamily() == OMF_dealloc) {
4962 Diag(ObjCMethod->getLocation(), diag::warn_dealloc_in_category)
4963 << ObjCMethod->getDeclName();
4971 // extension conforms is non-escaping and the implementation's method is
4973 for (auto *C : IDecl->visible_categories())
4974 for (auto &P : C->protocols())
4975 if (auto *IMD = P->lookupMethod(ObjCMethod->getSelector(),
4976 ObjCMethod->isInstanceMethod())) {
4977 assert(ObjCMethod->parameters().size() ==
4978 IMD->parameters().size() &&
4980 auto OI = IMD->param_begin(), OE = IMD->param_end();
4981 auto NI = ObjCMethod->param_begin();
4982 for (; OI != OE; ++OI, ++NI)
4992 IDecl = cast<ObjCCategoryDecl>(ClassDecl)->getClassInterface();
5000 cast<DeclContext>(ClassDecl)->addDecl(ObjCMethod);
5005 Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl)
5006 << ObjCMethod->getDeclName();
5007 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
5008 ObjCMethod->setInvalidDecl();
5012 // If this Objective-C method does not have a related result type, but we
5018 CurrentClass = Cat->getClassInterface();
5020 CurrentClass = Impl->getClassInterface();
5023 CurrentClass = CatImpl->getClassInterface();
5037 !ObjCMethod->hasRelatedResultType() &&
5040 switch (ObjCMethod->getMethodFamily()) {
5054 InferRelatedResultType = ObjCMethod->isClassMethod();
5061 InferRelatedResultType = ObjCMethod->isInstanceMethod();
5066 !ObjCMethod->getReturnType()->isObjCIndependentClassType())
5067 ObjCMethod->setRelatedResultType();
5076 if (const auto *attr = ObjCMethod->getAttr<AvailabilityAttr>()) {
5077 if (ObjCMethod->isClassMethod() &&
5078 ObjCMethod->getSelector().getAsString() == "load") {
5079 Diag(attr->getLocation(), diag::warn_availability_on_static_initializer)
5081 ObjCMethod->dropAttr<AvailabilityAttr>();
5086 ObjCMethod->createImplicitParams(Context, ObjCMethod->getClassInterface());
5096 if (isa<ObjCContainerDecl>(SemaRef.CurContext->getRedeclContext()))
5102 SemaRef.getCurLexicalContext()->getRedeclContext()))
5105 Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);
5106 D->setInvalidDecl();
5136 /*FIXME: StartL=*/ID->getLocation(),
5137 ID->getLocation(),
5138 ID->getIdentifier(), ID->getType(),
5139 ID->getBitWidth());
5150 Record->addDecl(FD);
5154 /// Build a type-check a new Objective-C exception variable declaration.
5162 // duration shall not be qualified by an address-space qualifier."
5174 } else if (T->isDependentType()) {
5176 } else if (T->isObjCQualifiedIdType()) {
5179 } else if (T->isObjCIdType()) {
5181 } else if (!T->isObjCObjectPointerType()) {
5184 } else if (!T->castAs<ObjCObjectPointerType>()->getInterfaceType()) {
5191 New->setExceptionVariable(true);
5198 New->setInvalidDecl();
5231 QualType ExceptionType = TInfo->getType();
5243 New->setInvalidDecl();
5247 S->AddDecl(New);
5253 if (New->hasAttr<BlocksAttr>())
5254 Diag(New->getLocation(), diag::err_block_on_nonlocal);
5258 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require
5263 for (ObjCIvarDecl *Iv = OI->all_declared_ivar_begin(); Iv;
5264 Iv= Iv->getNextIvar()) {
5265 QualType QT = Context.getBaseElementType(Iv->getType());
5266 if (QT->isRecordType())
5276 SemaRef.ExternalSource->ReadReferencedSelectors(Sels);
5298 if (Method->isClassMethod())
5300 const ObjCInterfaceDecl *IDecl = Method->getClassInterface();
5303 Method = IDecl->lookupMethod(Method->getSelector(), /*isInstance=*/true,
5306 if (!Method || !Method->isPropertyAccessor())
5308 if ((PDecl = Method->findPropertyDecl()))
5309 if (ObjCIvarDecl *IV = PDecl->getPropertyIvarDecl()) {
5312 // FIXME. fix the const-ness issue.
5313 IV = const_cast<ObjCInterfaceDecl *>(IDecl)->lookupInstanceVariable(
5314 IV->getIdentifier());
5340 if (E->getDecl() == IvarD) {
5348 if (E->getReceiverKind() == ObjCMessageExpr::Instance &&
5349 S.ObjC().isSelfExpr(E->getInstanceReceiver(), Method)) {
5359 if (S->hasUnrecoverableErrorOccurred())
5362 for (const auto *CurMethod : ImplD->instance_methods()) {
5364 SourceLocation Loc = CurMethod->getLocation();
5373 if (CurMethod->isSynthesizedAccessorStub())
5377 Checker.TraverseStmt(CurMethod->getBody());
5385 if (!IV->isReferenced() || !Checker.InvokedSelfMethod) {
5387 Diag(PDecl->getLocation(), diag::note_property_declare);
5397 T.getObjCLifetime() != Qualifiers::OCL_None || !T->isObjCLifetimeType())
5403 // - if it's const, use __unsafe_unretained
5404 // - otherwise, it's an error
5405 if (T->isArrayType()) {
5413 << TSInfo->getTypeLoc().getSourceRange();
5417 Lifetime = T->getObjCARCImplicitLifetime();
5427 // The third "scope" argument is 0 since we aren't enabling lazy built-in
5434 // find an Objective-C class name.
5441 Id = IDecl->getIdentifier();
5446 if (Def && Def->getDefinition())
5447 Def = Def->getDefinition();
5453 QualType type = decl->getType();
5457 unsigned kind = -1U;
5459 if (var->hasAttr<BlocksAttr>())
5461 else if (!var->hasLocalStorage())
5469 if (kind != -1U) {
5470 Diag(decl->getLocation(), diag::err_arc_autoreleasing_var) << kind;
5474 if (!type->isObjCLifetimeType())
5477 lifetime = type->getObjCARCImplicitLifetime();
5479 decl->setType(type);
5483 // Thread-local variables cannot have lifetime.
5485 var->getTLSKind()) {
5486 Diag(var->getLocation(), diag::err_arc_thread_ownership)
5487 << var->getType();
5502 if (ObjCInterfaceDecl *OID = ObjCImplementation->getClassInterface()) {
5511 if (Field->isInvalidDecl())
5517 InitializationKind::CreateDefault(ObjCImplementation->getLocation());
5536 Context.getBaseElementType(Field->getType())
5537 ->getAs<RecordType>()) {
5538 CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
5540 SemaRef.MarkFunctionReferenced(Field->getLocation(), Destructor);
5542 Field->getLocation(), Destructor,
5544 << Context.getBaseElementType(Field->getType()));
5548 ObjCImplementation->setIvarInitializers(Context, AllToInit.data(),
5553 /// TranslateIvarVisibility - Translate visibility from a token ID to an
5571 /// ActOnIvar - Each ivar field of an objective-c class is passed into this
5585 QualType T = TInfo->getType();
5599 if (T->isReferenceType()) {
5605 else if (T->isVariablyModifiedType()) {
5618 if (!EnclosingDecl || EnclosingDecl->isInvalidDecl())
5626 EnclosingContext = IMPDecl->getClassInterface();
5632 if (getLangOpts().ObjCRuntime.isFragile() || !CDecl->IsClassExtension()) {
5633 Diag(Loc, diag::err_misplaced_ivar) << CDecl->IsClassExtension();
5645 if (T->containsErrors())
5646 NewID->setInvalidDecl();
5655 Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
5656 NewID->setInvalidDecl();
5664 NewID->setInvalidDecl();
5668 NewID->setInvalidDecl();
5671 NewID->setModulePrivate();
5676 S->AddDecl(NewID);
5680 if (getLangOpts().ObjCRuntime.isNonFragile() && !NewID->isInvalidDecl() &&