Index: include/clang/AST/ASTContext.h =================================================================== --- include/clang/AST/ASTContext.h +++ include/clang/AST/ASTContext.h @@ -123,6 +123,8 @@ : Width(Width), Align(Align), AlignIsRequired(AlignIsRequired) {} }; +typedef llvm::function_ref IsHiddenFunction; + /// \brief Holds long-lived AST nodes (such as types and decls) that can be /// referred to throughout the semantic analysis of a file. class ASTContext : public RefCountedBase { @@ -1395,12 +1397,14 @@ ArrayRef protocols, QualType Canonical = QualType()) const; - bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl); + bool ObjCObjectAdoptsQTypeProtocols(QualType QT, ObjCInterfaceDecl *Decl, + IsHiddenFunction IsHidden); /// QIdProtocolsAdoptObjCObjectProtocols - Checks that protocols in /// QT's qualified-id protocol list adopt all protocols in IDecl's list /// of protocols. bool QIdProtocolsAdoptObjCObjectProtocols(QualType QT, - ObjCInterfaceDecl *IDecl); + ObjCInterfaceDecl *IDecl, + IsHiddenFunction IsHidden); /// \brief Return a ObjCObjectPointerType type for the given ObjCObjectType. QualType getObjCObjectPointerType(QualType OIT) const; @@ -2060,8 +2064,10 @@ SmallVectorImpl &Ivars) const; unsigned CountNonClassIvars(const ObjCInterfaceDecl *OI) const; - void CollectInheritedProtocols(const Decl *CDecl, - llvm::SmallPtrSet &Protocols); + void + CollectInheritedProtocols(const Decl *CDecl, + llvm::SmallPtrSet &Protocols, + IsHiddenFunction IsHidden); //===--------------------------------------------------------------------===// // Type Operators @@ -2353,23 +2359,26 @@ return T == getObjCSelType(); } bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS, - bool ForCompare); + bool ForCompare, + IsHiddenFunction IsHidden); bool ObjCQualifiedClassTypesAreCompatible(QualType LHS, QualType RHS); // Check the safety of assignment from LHS to RHS bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT); + const ObjCObjectPointerType *RHSOPT, + IsHiddenFunction IsHidden); bool canAssignObjCInterfaces(const ObjCObjectType *LHS, - const ObjCObjectType *RHS); + const ObjCObjectType *RHS, + IsHiddenFunction IsHidden); bool canAssignObjCInterfacesInBlockPointer( - const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT, - bool BlockReturnType); + const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT, + bool BlockReturnType, IsHiddenFunction IsHidden); bool areComparableObjCPointerTypes(QualType LHS, QualType RHS); QualType areCommonBaseCompatible(const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT); - bool canBindObjCObjectType(QualType To, QualType From); + bool canBindObjCObjectType(QualType To, QualType From, + IsHiddenFunction IsHidden); // Functions for calculating composite types QualType mergeTypes(QualType, QualType, bool OfBlockPointer=false, Index: include/clang/AST/DeclObjC.h =================================================================== --- include/clang/AST/DeclObjC.h +++ include/clang/AST/DeclObjC.h @@ -89,7 +89,15 @@ const SourceLocation *Locs, ASTContext &Ctx); }; +/// A callback used to determine which declarations should be visible to ObjC +/// name lookups. +// FIXME: This should not be necessary; the name lookup logic should be in Sema. +typedef llvm::function_ref IsHiddenFunction; +/// An IsHiddenFunction callback for the case where all declarations should be +/// considered to be visible. +bool AllDeclsVisible(const NamedDecl*); + /// ObjCMethodDecl - Represents an instance or class method declaration. /// ObjC methods can be declared within 4 contexts: class interfaces, /// categories, protocols, and class implementations. While C++ member @@ -456,7 +464,8 @@ /// Note that even if this particular method is not marked as a property /// accessor, it is still possible for it to match a property declared in a /// superclass. Pass \c false if you only want to check the current class. - const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const; + const ObjCPropertyDecl *findPropertyDecl(IsHiddenFunction IsHidden, + bool CheckOverrides = true) const; // Related to protocols declared in \@protocol void setDeclImplementation(ImplementationControl ic) { @@ -480,6 +489,7 @@ /// the method declaration that was marked with the designated initializer /// attribute. bool isDesignatedInitializerForTheInterface( + IsHiddenFunction IsHidden, const ObjCMethodDecl **InitMethod = nullptr) const; /// \brief Determine whether this method has a body. @@ -906,7 +916,8 @@ /// Lookup a property by name in the specified DeclContext. static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, - ObjCPropertyQueryKind queryKind); + ObjCPropertyQueryKind queryKind, + IsHiddenFunction IsHidden); static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classofKind(Kind K) { return K == ObjCProperty; } @@ -1021,20 +1032,22 @@ // Get the local instance/class method declared in this interface. ObjCMethodDecl *getMethod(Selector Sel, bool isInstance, - bool AllowHidden = false) const; + IsHiddenFunction IsHidden) const; ObjCMethodDecl *getInstanceMethod(Selector Sel, - bool AllowHidden = false) const { - return getMethod(Sel, true/*isInstance*/, AllowHidden); + IsHiddenFunction IsHidden) const { + return getMethod(Sel, true/*isInstance*/, IsHidden); } - ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const { - return getMethod(Sel, false/*isInstance*/, AllowHidden); + ObjCMethodDecl *getClassMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + return getMethod(Sel, false/*isInstance*/, IsHidden); } - bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const; + bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P, + IsHiddenFunction IsHidden) const; ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const; - ObjCPropertyDecl * - FindPropertyDeclaration(const IdentifierInfo *PropertyId, - ObjCPropertyQueryKind QueryKind) const; + ObjCPropertyDecl *FindPropertyDeclaration(const IdentifierInfo *PropertyId, + ObjCPropertyQueryKind QueryKind, + IsHiddenFunction IsHidden) const; typedef llvm::DenseMap, @@ -1265,8 +1278,10 @@ /// Returns true if this interface decl declares a designated initializer /// or it inherites one from its super class. - bool declaresOrInheritsDesignatedInitializers() const { - return hasDesignatedInitializers() || inheritsDesignatedInitializers(); + bool + declaresOrInheritsDesignatedInitializers(IsHiddenFunction IsHidden) const { + return hasDesignatedInitializers() || + inheritsDesignatedInitializers(IsHidden); } const ObjCProtocolList &getReferencedProtocols() const { @@ -1280,14 +1295,18 @@ ObjCImplementationDecl *getImplementation() const; void setImplementation(ObjCImplementationDecl *ImplD); - ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const; + ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId, + IsHiddenFunction IsHidden) const; // Get the local instance/class method declared in a category. - ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const; - ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const; - ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const { - return isInstance ? getCategoryInstanceMethod(Sel) - : getCategoryClassMethod(Sel); + ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel, + IsHiddenFunction IsHidden) const; + ObjCMethodDecl *getCategoryClassMethod(Selector Sel, + IsHiddenFunction IsHidden) const; + ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden) const { + return isInstance ? getCategoryInstanceMethod(Sel, IsHidden) + : getCategoryClassMethod(Sel, IsHidden); } typedef ObjCProtocolList::iterator protocol_iterator; @@ -1433,7 +1452,8 @@ /// initializers then the interface inherits the designated initializers of /// its super class. void getDesignatedInitializers( - llvm::SmallVectorImpl &Methods) const; + llvm::SmallVectorImpl &Methods, + IsHiddenFunction IsHidden) const; /// Returns true if the given selector is a designated initializer for the /// interface. @@ -1444,9 +1464,13 @@ /// /// \param InitMethod if non-null and the function returns true, it receives /// the method that was marked as a designated initializer. - bool - isDesignatedInitializer(Selector Sel, - const ObjCMethodDecl **InitMethod = nullptr) const; + bool isDesignatedInitializer(Selector Sel, + const ObjCMethodDecl **InitMethod, + IsHiddenFunction IsHidden) const; + bool isDesignatedInitializer(Selector Sel, + IsHiddenFunction IsHidden) const { + return isDesignatedInitializer(Sel, nullptr, IsHidden); + } /// \brief Determine whether this particular declaration of this class is /// actually also a definition. @@ -1517,9 +1541,10 @@ /// /// This class template is used for the various permutations of category /// and extension iterators. - template + template class filtered_category_iterator { ObjCCategoryDecl *Current; + Filter FilterFn; void findAcceptableCategory(); @@ -1530,10 +1555,12 @@ typedef std::ptrdiff_t difference_type; typedef std::input_iterator_tag iterator_category; - filtered_category_iterator() : Current(nullptr) { } + filtered_category_iterator() : filtered_category_iterator(Filter()) {} + filtered_category_iterator(Filter F) : Current(nullptr), FilterFn(F) {} explicit filtered_category_iterator(ObjCCategoryDecl *Current) - : Current(Current) - { + : filtered_category_iterator(Current, Filter()) {} + explicit filtered_category_iterator(ObjCCategoryDecl *Current, Filter F) + : Current(Current), FilterFn(F) { findAcceptableCategory(); } @@ -1563,36 +1590,43 @@ /// \brief Test whether the given category is visible. /// /// Used in the \c visible_categories_iterator. - static bool isVisibleCategory(ObjCCategoryDecl *Cat); + struct IsVisibleCategoryFilter { + IsHiddenFunction IsHidden; + IsVisibleCategoryFilter(IsHiddenFunction IsHidden) : IsHidden(IsHidden) {} + bool operator()(ObjCCategoryDecl *Cat) const; + }; public: /// \brief Iterator that walks over the list of categories and extensions /// that are visible, i.e., not hidden in a non-imported submodule. - typedef filtered_category_iterator + typedef filtered_category_iterator visible_categories_iterator; typedef llvm::iterator_range visible_categories_range; - visible_categories_range visible_categories() const { - return visible_categories_range(visible_categories_begin(), - visible_categories_end()); + visible_categories_range visible_categories(IsHiddenFunction IsHidden) const { + return visible_categories_range(visible_categories_begin(IsHidden), + visible_categories_end(IsHidden)); } /// \brief Retrieve an iterator to the beginning of the visible-categories /// list. - visible_categories_iterator visible_categories_begin() const { - return visible_categories_iterator(getCategoryListRaw()); + visible_categories_iterator + visible_categories_begin(IsHiddenFunction IsHidden) const { + return visible_categories_iterator(getCategoryListRaw(), IsHidden); } /// \brief Retrieve an iterator to the end of the visible-categories list. - visible_categories_iterator visible_categories_end() const { - return visible_categories_iterator(); + visible_categories_iterator + visible_categories_end(IsHiddenFunction IsHidden) const { + return visible_categories_iterator(IsHidden); } /// \brief Determine whether the visible-categories list is empty. - bool visible_categories_empty() const { - return visible_categories_begin() == visible_categories_end(); + bool visible_categories_empty(IsHiddenFunction IsHidden) const { + return visible_categories_begin(IsHidden) == + visible_categories_end(IsHidden); } private: @@ -1599,12 +1633,15 @@ /// \brief Test whether the given category... is a category. /// /// Used in the \c known_categories_iterator. - static bool isKnownCategory(ObjCCategoryDecl *) { return true; } + struct IsKnownCategoryFilter { + bool operator()(ObjCCategoryDecl *) const { return true; } + }; public: /// \brief Iterator that walks over all of the known categories and /// extensions, including those that are hidden. - typedef filtered_category_iterator known_categories_iterator; + typedef filtered_category_iterator + known_categories_iterator; typedef llvm::iterator_range known_categories_range; @@ -1633,36 +1670,43 @@ /// \brief Test whether the given category is a visible extension. /// /// Used in the \c visible_extensions_iterator. - static bool isVisibleExtension(ObjCCategoryDecl *Cat); + struct IsVisibleExtensionFilter { + IsHiddenFunction IsHidden; + IsVisibleExtensionFilter(IsHiddenFunction IsHidden) : IsHidden(IsHidden) {} + bool operator()(ObjCCategoryDecl *Cat) const; + }; public: /// \brief Iterator that walks over all of the visible extensions, skipping /// any that are known but hidden. - typedef filtered_category_iterator + typedef filtered_category_iterator visible_extensions_iterator; typedef llvm::iterator_range visible_extensions_range; - visible_extensions_range visible_extensions() const { - return visible_extensions_range(visible_extensions_begin(), - visible_extensions_end()); + visible_extensions_range visible_extensions(IsHiddenFunction IsHidden) const { + return visible_extensions_range(visible_extensions_begin(IsHidden), + visible_extensions_end(IsHidden)); } /// \brief Retrieve an iterator to the beginning of the visible-extensions /// list. - visible_extensions_iterator visible_extensions_begin() const { - return visible_extensions_iterator(getCategoryListRaw()); + visible_extensions_iterator + visible_extensions_begin(IsHiddenFunction IsHidden) const { + return visible_extensions_iterator(getCategoryListRaw(), IsHidden); } /// \brief Retrieve an iterator to the end of the visible-extensions list. - visible_extensions_iterator visible_extensions_end() const { - return visible_extensions_iterator(); + visible_extensions_iterator + visible_extensions_end(IsHiddenFunction IsHidden) const { + return visible_extensions_iterator(IsHidden); } /// \brief Determine whether the visible-extensions list is empty. - bool visible_extensions_empty() const { - return visible_extensions_begin() == visible_extensions_end(); + bool visible_extensions_empty(IsHiddenFunction IsHidden) const { + return visible_extensions_begin(IsHidden) == + visible_extensions_end(IsHidden); } private: @@ -1669,11 +1713,13 @@ /// \brief Test whether the given category is an extension. /// /// Used in the \c known_extensions_iterator. - static bool isKnownExtension(ObjCCategoryDecl *Cat); + struct IsKnownExtensionFilter { + bool operator()(ObjCCategoryDecl *Cat) const; + }; public: /// \brief Iterator that walks over all of the known extensions. - typedef filtered_category_iterator + typedef filtered_category_iterator known_extensions_iterator; typedef llvm::iterator_range known_extensions_range; @@ -1720,7 +1766,8 @@ ObjCPropertyDecl *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId, - ObjCPropertyQueryKind QueryKind) const; + ObjCPropertyQueryKind QueryKind, + IsHiddenFunction IsHidden) const; void collectPropertiesToImplement(PropertyMap &PM, PropertyDeclOrder &PO) const override; @@ -1748,10 +1795,12 @@ const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const; ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, - ObjCInterfaceDecl *&ClassDeclared); - ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) { + ObjCInterfaceDecl *&ClassDeclared, + IsHiddenFunction IsHidden); + ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName, + IsHiddenFunction IsHidden) { ObjCInterfaceDecl *ClassDeclared; - return lookupInstanceVariable(IVarName, ClassDeclared); + return lookupInstanceVariable(IVarName, ClassDeclared, IsHidden); } ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name); @@ -1759,36 +1808,45 @@ // Lookup a method. First, we search locally. If a method isn't // found, we search referenced protocols and class categories. ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden, bool shallowCategoryLookup = false, bool followSuper = true, const ObjCCategoryDecl *C = nullptr) const; /// Lookup an instance method for a given selector. - ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { - return lookupMethod(Sel, true/*isInstance*/); + ObjCMethodDecl *lookupInstanceMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + return lookupMethod(Sel, true/*isInstance*/, IsHidden); } /// Lookup a class method for a given selector. - ObjCMethodDecl *lookupClassMethod(Selector Sel) const { - return lookupMethod(Sel, false/*isInstance*/); + ObjCMethodDecl *lookupClassMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + return lookupMethod(Sel, false/*isInstance*/, IsHidden); } ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName); /// \brief Lookup a method in the classes implementation hierarchy. ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, - bool Instance=true) const; - - ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) { - return lookupPrivateMethod(Sel, false); + bool Instance, + IsHiddenFunction IsHidden) const; + ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, + IsHiddenFunction IsHidden) const { + return lookupPrivateMethod(Sel, true, IsHidden); } + ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel, + IsHiddenFunction IsHidden) { + return lookupPrivateMethod(Sel, false, IsHidden); + } /// \brief Lookup a setter or getter in the class hierarchy, /// including in all categories except for category passed /// as argument. ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel, + IsHiddenFunction IsHidden, const ObjCCategoryDecl *Cat, bool IsClassProperty) const { - return lookupMethod(Sel, !IsClassProperty/*isInstance*/, + return lookupMethod(Sel, !IsClassProperty/*isInstance*/, IsHidden, false/*shallowCategoryLookup*/, true /* followsSuper */, Cat); @@ -1817,7 +1875,8 @@ /// has been implemented in IDecl class, its super class or categories (if /// lookupCategory is true). bool ClassImplementsProtocol(ObjCProtocolDecl *lProto, - bool lookupCategory, + bool LookupInCategories, + IsHiddenFunction IsHidden, bool RHSIsQualifiedID = false); typedef redeclarable_base::redecl_range redecl_range; @@ -1845,8 +1904,9 @@ friend class ASTDeclWriter; private: - const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const; - bool inheritsDesignatedInitializers() const; + const ObjCInterfaceDecl * + findInterfaceWithDesignatedInitializers(IsHiddenFunction IsHidden) const; + bool inheritsDesignatedInitializers(IsHiddenFunction IsHidden) const; }; /// ObjCIvarDecl - Represents an ObjC instance variable. In general, ObjC @@ -2092,12 +2152,15 @@ // Lookup a method. First, we search locally. If a method isn't // found, we search referenced protocols and class categories. - ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const; - ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const { - return lookupMethod(Sel, true/*isInstance*/); + ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden) const; + ObjCMethodDecl *lookupInstanceMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + return lookupMethod(Sel, true/*isInstance*/, IsHidden); } - ObjCMethodDecl *lookupClassMethod(Selector Sel) const { - return lookupMethod(Sel, false/*isInstance*/); + ObjCMethodDecl *lookupClassMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + return lookupMethod(Sel, false/*isInstance*/, IsHidden); } /// \brief Determine whether this protocol has a definition. @@ -2750,15 +2813,15 @@ friend class ASTDeclReader; }; -template +template void ObjCInterfaceDecl::filtered_category_iterator:: findAcceptableCategory() { - while (Current && !Filter(Current)) + while (Current && !FilterFn(Current)) Current = Current->getNextClassCategoryRaw(); } -template +template inline ObjCInterfaceDecl::filtered_category_iterator & ObjCInterfaceDecl::filtered_category_iterator::operator++() { Current = Current->getNextClassCategoryRaw(); @@ -2766,15 +2829,18 @@ return *this; } -inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) { - return !Cat->isHidden(); +inline bool ObjCInterfaceDecl::IsVisibleCategoryFilter:: +operator()(ObjCCategoryDecl *Cat) const { + return !IsHidden(Cat); } -inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) { - return Cat->IsClassExtension() && !Cat->isHidden(); +inline bool ObjCInterfaceDecl::IsVisibleExtensionFilter:: +operator()(ObjCCategoryDecl *Cat) const { + return Cat->IsClassExtension() && !IsHidden(Cat); } -inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) { +inline bool ObjCInterfaceDecl::IsKnownExtensionFilter:: +operator()(ObjCCategoryDecl *Cat) const { return Cat->IsClassExtension(); } Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -1531,6 +1531,13 @@ return !D->isHidden() || isVisibleSlow(D); } + /// "Is this declaration hidden?" callback used for ObjC lookups. + struct IsHiddenCallback { + Sema &S; + IsHiddenCallback(Sema &S) : S(S) {} + bool operator()(const NamedDecl *D) const { return !S.isVisible(D); } + }; + /// Determine whether any declaration of an entity is visible. bool hasVisibleDeclaration(const NamedDecl *D, @@ -3364,7 +3371,7 @@ /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. /// It also returns ivar's property on success. ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, - const ObjCPropertyDecl *&PDecl) const; + const ObjCPropertyDecl *&PDecl); /// Called by ActOnProperty to handle \@property declarations in /// class extensions. Index: lib/ARCMigrate/ObjCMT.cpp =================================================================== --- lib/ARCMigrate/ObjCMT.cpp +++ lib/ARCMigrate/ObjCMT.cpp @@ -1172,7 +1172,8 @@ SelectorTable::constructSetterSelector(PP.getIdentifierTable(), PP.getSelectorTable(), getterName); - ObjCMethodDecl *SetterMethod = D->getInstanceMethod(SetterSelector); + ObjCMethodDecl *SetterMethod = + D->getInstanceMethod(SetterSelector, AllDeclsVisible); unsigned LengthOfPrefix = 0; if (!SetterMethod) { // try a different naming convention for getter: isXxxxx @@ -1195,7 +1196,7 @@ SelectorTable::constructSetterSelector(PP.getIdentifierTable(), PP.getSelectorTable(), getterName); - SetterMethod = D->getInstanceMethod(SetterSelector); + SetterMethod = D->getInstanceMethod(SetterSelector, AllDeclsVisible); } } } @@ -1703,12 +1704,12 @@ return; for (const auto *MD : ImplD->instance_methods()) { - if (MD->isDeprecated() || - MD->getMethodFamily() != OMF_init || - MD->isDesignatedInitializerForTheInterface()) + if (MD->isDeprecated() || MD->getMethodFamily() != OMF_init || + MD->isDesignatedInitializerForTheInterface(AllDeclsVisible)) continue; - const ObjCMethodDecl *IFaceM = IFace->getMethod(MD->getSelector(), - /*isInstance=*/true); + const ObjCMethodDecl *IFaceM = + IFace->getMethod(MD->getSelector(), + /*isInstance=*/true, AllDeclsVisible); if (!IFaceM) continue; if (hasSuperInitCall(MD)) { Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -410,8 +410,8 @@ // Add redeclared method here. for (const auto *Ext : ID->known_extensions()) { if (ObjCMethodDecl *RedeclaredMethod = - Ext->getMethod(ObjCMethod->getSelector(), - ObjCMethod->isInstanceMethod())) + Ext->getMethod(ObjCMethod->getSelector(), + ObjCMethod->isInstanceMethod(), AllDeclsVisible)) Redeclared.push_back(RedeclaredMethod); } } @@ -465,7 +465,8 @@ SmallVector Overridden; const ObjCMethodDecl *OMD = dyn_cast(D); if (OMD && OMD->isPropertyAccessor()) - if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) + if (const ObjCPropertyDecl *PDecl = + OMD->findPropertyDecl(AllDeclsVisible)) if (comments::FullComment *FC = getCommentForDecl(PDecl, PP)) return cloneFullComment(FC, D); if (OMD) @@ -2074,27 +2075,28 @@ /// CollectInheritedProtocols - Collect all protocols in current class and /// those inherited by it. -void ASTContext::CollectInheritedProtocols(const Decl *CDecl, - llvm::SmallPtrSet &Protocols) { +void ASTContext::CollectInheritedProtocols( + const Decl *CDecl, llvm::SmallPtrSet &Protocols, + IsHiddenFunction IsHidden) { if (const ObjCInterfaceDecl *OI = dyn_cast(CDecl)) { // We can use protocol_iterator here instead of // all_referenced_protocol_iterator since we are walking all categories. for (auto *Proto : OI->all_referenced_protocols()) { - CollectInheritedProtocols(Proto, Protocols); + CollectInheritedProtocols(Proto, Protocols, IsHidden); } // Categories of this Interface. - for (const auto *Cat : OI->visible_categories()) - CollectInheritedProtocols(Cat, Protocols); + for (const auto *Cat : OI->visible_categories(IsHidden)) + CollectInheritedProtocols(Cat, Protocols, IsHidden); if (ObjCInterfaceDecl *SD = OI->getSuperClass()) while (SD) { - CollectInheritedProtocols(SD, Protocols); + CollectInheritedProtocols(SD, Protocols, IsHidden); SD = SD->getSuperClass(); } } else if (const ObjCCategoryDecl *OC = dyn_cast(CDecl)) { for (auto *Proto : OC->protocols()) { - CollectInheritedProtocols(Proto, Protocols); + CollectInheritedProtocols(Proto, Protocols, IsHidden); } } else if (const ObjCProtocolDecl *OP = dyn_cast(CDecl)) { // Insert the protocol. @@ -2103,7 +2105,7 @@ return; for (auto *Proto : OP->protocols()) - CollectInheritedProtocols(Proto, Protocols); + CollectInheritedProtocols(Proto, Protocols, IsHidden); } } @@ -4185,7 +4187,8 @@ /// protocol list adopt all protocols in QT's qualified-id protocol /// list. bool ASTContext::ObjCObjectAdoptsQTypeProtocols(QualType QT, - ObjCInterfaceDecl *IC) { + ObjCInterfaceDecl *IC, + IsHiddenFunction IsHidden) { if (!QT->isObjCQualifiedIdType()) return false; @@ -4192,7 +4195,7 @@ if (const ObjCObjectPointerType *OPT = QT->getAs()) { // If both the right and left sides have qualifiers. for (auto *Proto : OPT->quals()) { - if (!IC->ClassImplementsProtocol(Proto, false)) + if (!IC->ClassImplementsProtocol(Proto, false, IsHidden)) return false; } return true; @@ -4204,7 +4207,8 @@ /// QT's qualified-id protocol list adopt all protocols in IDecl's list /// of protocols. bool ASTContext::QIdProtocolsAdoptObjCObjectProtocols(QualType QT, - ObjCInterfaceDecl *IDecl) { + ObjCInterfaceDecl *IDecl, + IsHiddenFunction IsHidden) { if (!QT->isObjCQualifiedIdType()) return false; const ObjCObjectPointerType *OPT = QT->getAs(); @@ -4213,7 +4217,7 @@ if (!IDecl->hasDefinition()) return false; llvm::SmallPtrSet InheritedProtocols; - CollectInheritedProtocols(IDecl, InheritedProtocols); + CollectInheritedProtocols(IDecl, InheritedProtocols, IsHidden); if (InheritedProtocols.empty()) return false; // Check that if every protocol in list of id conforms to a protcol @@ -7239,7 +7243,8 @@ /// ObjCQualifiedIdTypesAreCompatible - We know that one of lhs/rhs is an /// ObjCQualifiedIDType. bool ASTContext::ObjCQualifiedIdTypesAreCompatible(QualType lhs, QualType rhs, - bool compare) { + bool compare, + IsHiddenFunction IsHidden) { // Allow id and an 'id' or void* type in all cases. if (lhs->isVoidPointerType() || lhs->isObjCIdType() || lhs->isObjCClassType()) @@ -7261,7 +7266,7 @@ // when comparing an id

on lhs with a static type on rhs, // see if static class implements all of id's protocols, directly or // through its super class and categories. - if (!rhsID->ClassImplementsProtocol(I, true)) + if (!rhsID->ClassImplementsProtocol(I, true, IsHidden)) return false; } } @@ -7289,7 +7294,7 @@ // when comparing an id

on lhs with a static type on rhs, // see if static class implements all of id's protocols, directly or // through its super class and categories. - if (rhsID->ClassImplementsProtocol(I, true)) { + if (rhsID->ClassImplementsProtocol(I, true, IsHidden)) { match = true; break; } @@ -7326,12 +7331,13 @@ if (!match) return false; } - + // Static class's protocols, or its super class or category protocols - // must be found, direct or indirect in rhs's qualifier list or it is a mismatch. + // must be found, direct or indirect in rhs's qualifier list or it is a + // mismatch. if (ObjCInterfaceDecl *lhsID = lhsOPT->getInterfaceDecl()) { llvm::SmallPtrSet LHSInheritedProtocols; - CollectInheritedProtocols(lhsID, LHSInheritedProtocols); + CollectInheritedProtocols(lhsID, LHSInheritedProtocols, IsHidden); // This is rather dubious but matches gcc's behavior. If lhs has // no type qualifier and its class has no static protocol(s) // assume that it is mismatch. @@ -7360,7 +7366,8 @@ /// protocol qualifiers on the LHS or RHS. /// bool ASTContext::canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT) { + const ObjCObjectPointerType *RHSOPT, + IsHiddenFunction IsHidden) { const ObjCObjectType* LHS = LHSOPT->getObjectType(); const ObjCObjectType* RHS = RHSOPT->getObjectType(); @@ -7381,13 +7388,15 @@ // Strip off __kindof and protocol qualifiers, then check whether // we can assign the other way. return canAssignObjCInterfaces(RHSOPT->stripObjCKindOfTypeAndQuals(*this), - LHSOPT->stripObjCKindOfTypeAndQuals(*this)); + LHSOPT->stripObjCKindOfTypeAndQuals(*this), + IsHidden); }; if (LHS->isObjCQualifiedId() || RHS->isObjCQualifiedId()) { return finish(ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), QualType(RHSOPT,0), - false)); + false, + IsHidden)); } if (LHS->isObjCQualifiedClass() && RHS->isObjCQualifiedClass()) { @@ -7397,7 +7406,7 @@ // If we have 2 user-defined types, fall into that path. if (LHS->getInterface() && RHS->getInterface()) { - return finish(canAssignObjCInterfaces(LHS, RHS)); + return finish(canAssignObjCInterfaces(LHS, RHS, IsHidden)); } return false; @@ -7409,10 +7418,8 @@ /// 'id' is expected is not OK. Passing 'Sub *" where 'Super *" is expected is /// not OK. For the return type, the opposite is not OK. bool ASTContext::canAssignObjCInterfacesInBlockPointer( - const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT, - bool BlockReturnType) { - + const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT, + bool BlockReturnType, IsHiddenFunction IsHidden) { // Function object that propagates a successful result or handles // __kindof types. auto finish = [&](bool succeeded) -> bool { @@ -7428,7 +7435,7 @@ return canAssignObjCInterfacesInBlockPointer( RHSOPT->stripObjCKindOfTypeAndQuals(*this), LHSOPT->stripObjCKindOfTypeAndQuals(*this), - BlockReturnType); + BlockReturnType, IsHidden); }; if (RHSOPT->isObjCBuiltinType() || LHSOPT->isObjCIdType()) @@ -7442,7 +7449,7 @@ if (LHSOPT->isObjCQualifiedIdType() || RHSOPT->isObjCQualifiedIdType()) return finish(ObjCQualifiedIdTypesAreCompatible(QualType(LHSOPT,0), QualType(RHSOPT,0), - false)); + false, IsHidden)); const ObjCInterfaceType* LHS = LHSOPT->getInterfaceType(); const ObjCInterfaceType* RHS = RHSOPT->getInterfaceType(); @@ -7472,13 +7479,12 @@ /// the given common base. /// It is used to build composite qualifier list of the composite type of /// the conditional expression involving two objective-c pointer objects. -static -void getIntersectionOfProtocols(ASTContext &Context, - const ObjCInterfaceDecl *CommonBase, - const ObjCObjectPointerType *LHSOPT, - const ObjCObjectPointerType *RHSOPT, - SmallVectorImpl &IntersectionSet) { - +static void getIntersectionOfProtocols( + ASTContext &Context, const ObjCInterfaceDecl *CommonBase, + const ObjCObjectPointerType *LHSOPT, const ObjCObjectPointerType *RHSOPT, + SmallVectorImpl &IntersectionSet, + IsHiddenFunction IsHidden) { + const ObjCObjectType* LHS = LHSOPT->getObjectType(); const ObjCObjectType* RHS = RHSOPT->getObjectType(); assert(LHS->getInterface() && "LHS must have an interface base"); @@ -7489,11 +7495,12 @@ // Start with the protocol qualifiers. for (auto proto : LHS->quals()) { - Context.CollectInheritedProtocols(proto, LHSProtocolSet); + Context.CollectInheritedProtocols(proto, LHSProtocolSet, IsHidden); } // Also add the protocols associated with the LHS interface. - Context.CollectInheritedProtocols(LHS->getInterface(), LHSProtocolSet); + Context.CollectInheritedProtocols(LHS->getInterface(), LHSProtocolSet, + IsHidden); // Add all of the protocls for the RHS. llvm::SmallPtrSet RHSProtocolSet; @@ -7500,11 +7507,12 @@ // Start with the protocol qualifiers. for (auto proto : RHS->quals()) { - Context.CollectInheritedProtocols(proto, RHSProtocolSet); + Context.CollectInheritedProtocols(proto, RHSProtocolSet, IsHidden); } // Also add the protocols associated with the RHS interface. - Context.CollectInheritedProtocols(RHS->getInterface(), RHSProtocolSet); + Context.CollectInheritedProtocols(RHS->getInterface(), RHSProtocolSet, + IsHidden); // Compute the intersection of the collected protocol sets. for (auto proto : LHSProtocolSet) { @@ -7515,7 +7523,7 @@ // Compute the set of protocols that is implied by either the common type or // the protocols within the intersection. llvm::SmallPtrSet ImpliedProtocols; - Context.CollectInheritedProtocols(CommonBase, ImpliedProtocols); + Context.CollectInheritedProtocols(CommonBase, ImpliedProtocols, IsHidden); // Remove any implied protocols from the list of inherited protocols. if (!ImpliedProtocols.empty()) { @@ -7719,7 +7727,8 @@ } bool ASTContext::canAssignObjCInterfaces(const ObjCObjectType *LHS, - const ObjCObjectType *RHS) { + const ObjCObjectType *RHS, + IsHiddenFunction IsHidden) { assert(LHS->getInterface() && "LHS is not an interface type"); assert(RHS->getInterface() && "RHS is not an interface type"); @@ -7739,11 +7748,12 @@ // in LHS's protocol list. Example, SuperObj = lhs is ok. // But not SuperObj = lhs. llvm::SmallPtrSet SuperClassInheritedProtocols; - CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols); + CollectInheritedProtocols(RHS->getInterface(), SuperClassInheritedProtocols, + IsHidden); // Also, if RHS has explicit quelifiers, include them for comparing with LHS's // qualifiers. for (auto *RHSPI : RHS->quals()) - CollectInheritedProtocols(RHSPI, SuperClassInheritedProtocols); + CollectInheritedProtocols(RHSPI, SuperClassInheritedProtocols, IsHidden); // If there is no protocols associated with RHS, it is not a match. if (SuperClassInheritedProtocols.empty()) return false; @@ -7780,7 +7790,8 @@ return true; } -bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS) { +bool ASTContext::areComparableObjCPointerTypes(QualType LHS, QualType RHS, + IsHiddenFunction IsHidden) { // get the "pointed to" types const ObjCObjectPointerType *LHSOPT = LHS->getAs(); const ObjCObjectPointerType *RHSOPT = RHS->getAs(); @@ -7788,14 +7799,15 @@ if (!LHSOPT || !RHSOPT) return false; - return canAssignObjCInterfaces(LHSOPT, RHSOPT) || - canAssignObjCInterfaces(RHSOPT, LHSOPT); + return canAssignObjCInterfaces(LHSOPT, RHSOPT, IsHidden) || + canAssignObjCInterfaces(RHSOPT, LHSOPT, IsHidden); } -bool ASTContext::canBindObjCObjectType(QualType To, QualType From) { +bool ASTContext::canBindObjCObjectType(QualType To, QualType From, + IsHiddenFunction IsHidden) { return canAssignObjCInterfaces( - getObjCObjectPointerType(To)->getAs(), - getObjCObjectPointerType(From)->getAs()); + getObjCObjectPointerType(To)->getAs(), + getObjCObjectPointerType(From)->getAs(), IsHidden); } /// typesAreCompatible - C99 6.7.3p9: For two qualified types to be compatible, Index: lib/AST/ASTImporter.cpp =================================================================== --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -2680,8 +2680,8 @@ return nullptr; // Determine if we've already encountered this category. - ObjCCategoryDecl *MergeWithCategory - = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo()); + ObjCCategoryDecl *MergeWithCategory = ToInterface->FindCategoryDeclaration( + Name.getAsIdentifierInfo(), AllDeclsVisible); ObjCCategoryDecl *ToCategory = MergeWithCategory; if (!ToCategory) { ToCategory = ObjCCategoryDecl::Create(Importer.getToContext(), DC, Index: lib/AST/DeclObjC.cpp =================================================================== --- lib/AST/DeclObjC.cpp +++ lib/AST/DeclObjC.cpp @@ -63,15 +63,16 @@ return nullptr; } +bool clang::AllDeclsVisible(const NamedDecl *ND) { return false; } + // Get the local instance/class method declared in this interface. -ObjCMethodDecl * -ObjCContainerDecl::getMethod(Selector Sel, bool isInstance, - bool AllowHidden) const { +ObjCMethodDecl *ObjCContainerDecl::getMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden) const { // If this context is a hidden protocol definition, don't find any // methods there. if (const ObjCProtocolDecl *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden() && !AllowHidden) + if (IsHidden(Def)) return nullptr; } @@ -99,7 +100,7 @@ /// property. This is because, user must provide a setter method for the /// category's 'readwrite' property. bool ObjCContainerDecl::HasUserDeclaredSetterMethod( - const ObjCPropertyDecl *Property) const { + const ObjCPropertyDecl *Property, IsHiddenFunction IsHidden) const { Selector Sel = Property->getSetterName(); lookup_result R = lookup(Sel); for (lookup_iterator Meth = R.begin(), MethEnd = R.end(); @@ -112,8 +113,8 @@ if (const ObjCInterfaceDecl *ID = dyn_cast(this)) { // Also look into categories, including class extensions, looking // for a user declared instance method. - for (const auto *Cat : ID->visible_categories()) { - if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel)) + for (const auto *Cat : ID->visible_categories(IsHidden)) { + if (ObjCMethodDecl *MD = Cat->getInstanceMethod(Sel, IsHidden)) if (!MD->isImplicit()) return true; if (Cat->IsClassExtension()) @@ -132,13 +133,13 @@ // Also look into protocols, for a user declared instance method. for (const auto *Proto : ID->all_referenced_protocols()) - if (Proto->HasUserDeclaredSetterMethod(Property)) + if (Proto->HasUserDeclaredSetterMethod(Property, IsHidden)) return true; // And in its super class. ObjCInterfaceDecl *OSC = ID->getSuperClass(); while (OSC) { - if (OSC->HasUserDeclaredSetterMethod(Property)) + if (OSC->HasUserDeclaredSetterMethod(Property, IsHidden)) return true; OSC = OSC->getSuperClass(); } @@ -145,7 +146,7 @@ } if (const ObjCProtocolDecl *PD = dyn_cast(this)) for (const auto *PI : PD->protocols()) - if (PI->HasUserDeclaredSetterMethod(Property)) + if (PI->HasUserDeclaredSetterMethod(Property, IsHidden)) return true; return false; } @@ -153,12 +154,13 @@ ObjCPropertyDecl * ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC, const IdentifierInfo *propertyID, - ObjCPropertyQueryKind queryKind) { + ObjCPropertyQueryKind queryKind, + IsHiddenFunction IsHidden) { // If this context is a hidden protocol definition, don't find any // property. if (const ObjCProtocolDecl *Proto = dyn_cast(DC)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden()) + if (IsHidden(Def)) return nullptr; } @@ -165,10 +167,9 @@ // If context is class, then lookup property in its visible extensions. // This comes before property is looked up in primary class. if (auto *IDecl = dyn_cast(DC)) { - for (const auto *Ext : IDecl->visible_extensions()) - if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(Ext, - propertyID, - queryKind)) + for (const auto *Ext : IDecl->visible_extensions(IsHidden)) + if (ObjCPropertyDecl *PD = + findPropertyDecl(Ext, propertyID, queryKind, IsHidden)) return PD; } @@ -210,13 +211,14 @@ /// FindPropertyDeclaration - Finds declaration of the property given its name /// in 'PropertyId' and returns it. It returns 0, if not found. -ObjCPropertyDecl *ObjCContainerDecl::FindPropertyDeclaration( - const IdentifierInfo *PropertyId, - ObjCPropertyQueryKind QueryKind) const { +ObjCPropertyDecl * +ObjCContainerDecl::FindPropertyDeclaration(const IdentifierInfo *PropertyId, + ObjCPropertyQueryKind QueryKind, + IsHiddenFunction IsHidden) const { // Don't find properties within hidden protocol definitions. if (const ObjCProtocolDecl *Proto = dyn_cast(this)) { if (const ObjCProtocolDecl *Def = Proto->getDefinition()) - if (Def->isHidden()) + if (IsHidden(Def)) return nullptr; } @@ -223,8 +225,9 @@ // Search the extensions of a class first; they override what's in // the class itself. if (const auto *ClassDecl = dyn_cast(this)) { - for (const auto *Ext : ClassDecl->visible_extensions()) { - if (auto *P = Ext->FindPropertyDeclaration(PropertyId, QueryKind)) + for (const auto *Ext : ClassDecl->visible_extensions(IsHidden)) { + if (auto *P = + Ext->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; } } @@ -231,7 +234,7 @@ if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(cast(this), PropertyId, - QueryKind)) + QueryKind, IsHidden)) return PD; switch (getKind()) { @@ -240,8 +243,8 @@ case Decl::ObjCProtocol: { const ObjCProtocolDecl *PID = cast(this); for (const auto *I : PID->protocols()) - if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, - QueryKind)) + if (ObjCPropertyDecl *P = + I->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; break; } @@ -248,22 +251,23 @@ case Decl::ObjCInterface: { const ObjCInterfaceDecl *OID = cast(this); // Look through categories (but not extensions; they were handled above). - for (const auto *Cat : OID->visible_categories()) { + for (const auto *Cat : OID->visible_categories(IsHidden)) { if (!Cat->IsClassExtension()) - if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration( - PropertyId, QueryKind)) + if (ObjCPropertyDecl *P = + Cat->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; } // Look through protocols. for (const auto *I : OID->all_referenced_protocols()) - if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, - QueryKind)) + if (ObjCPropertyDecl *P = + I->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; // Finally, check the super class. if (const ObjCInterfaceDecl *superClass = OID->getSuperClass()) - return superClass->FindPropertyDeclaration(PropertyId, QueryKind); + return superClass->FindPropertyDeclaration(PropertyId, QueryKind, + IsHidden); break; } case Decl::ObjCCategory: { @@ -271,8 +275,8 @@ // Look through protocols. if (!OCD->IsClassExtension()) for (const auto *I : OCD->protocols()) - if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, - QueryKind)) + if (ObjCPropertyDecl *P = + I->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; break; } @@ -342,10 +346,9 @@ /// with name 'PropertyId' in the primary class; including those in protocols /// (direct or indirect) used by the primary class. /// -ObjCPropertyDecl * -ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( - IdentifierInfo *PropertyId, - ObjCPropertyQueryKind QueryKind) const { +ObjCPropertyDecl *ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass( + IdentifierInfo *PropertyId, ObjCPropertyQueryKind QueryKind, + IsHiddenFunction IsHidden) const { // FIXME: Should make sure no callers ever do this. if (!hasDefinition()) return nullptr; @@ -355,13 +358,13 @@ if (ObjCPropertyDecl *PD = ObjCPropertyDecl::findPropertyDecl(cast(this), PropertyId, - QueryKind)) + QueryKind, IsHidden)) return PD; // Look through protocols. for (const auto *I : all_referenced_protocols()) - if (ObjCPropertyDecl *P = I->FindPropertyDeclaration(PropertyId, - QueryKind)) + if (ObjCPropertyDecl *P = + I->FindPropertyDeclaration(PropertyId, QueryKind, IsHidden)) return P; return nullptr; @@ -450,12 +453,13 @@ } const ObjCInterfaceDecl * -ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers() const { +ObjCInterfaceDecl::findInterfaceWithDesignatedInitializers( + IsHiddenFunction IsHidden) const { const ObjCInterfaceDecl *IFace = this; while (IFace) { if (IFace->hasDesignatedInitializers()) return IFace; - if (!IFace->inheritsDesignatedInitializers()) + if (!IFace->inheritsDesignatedInitializers(IsHidden)) break; IFace = IFace->getSuperClass(); } @@ -462,12 +466,13 @@ return nullptr; } -static bool isIntroducingInitializers(const ObjCInterfaceDecl *D) { +static bool isIntroducingInitializers(const ObjCInterfaceDecl *D, + IsHiddenFunction IsHidden) { for (const auto *MD : D->instance_methods()) { if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) return true; } - for (const auto *Ext : D->visible_extensions()) { + for (const auto *Ext : D->visible_extensions(IsHidden)) { for (const auto *MD : Ext->instance_methods()) { if (MD->getMethodFamily() == OMF_init && !MD->isOverriding()) return true; @@ -482,7 +487,8 @@ return false; } -bool ObjCInterfaceDecl::inheritsDesignatedInitializers() const { +bool ObjCInterfaceDecl::inheritsDesignatedInitializers( + IsHiddenFunction IsHidden) const { switch (data().InheritedDesignatedInitializers) { case DefinitionData::IDI_Inherited: return true; @@ -492,12 +498,12 @@ // If the class introduced initializers we conservatively assume that we // don't know if any of them is a designated initializer to avoid possible // misleading warnings. - if (isIntroducingInitializers(this)) { + if (isIntroducingInitializers(this, IsHidden)) { data().InheritedDesignatedInitializers = DefinitionData::IDI_NotInherited; } else { if (auto SuperD = getSuperClass()) { data().InheritedDesignatedInitializers = - SuperD->declaresOrInheritsDesignatedInitializers() ? + SuperD->declaresOrInheritsDesignatedInitializers(IsHidden) ? DefinitionData::IDI_Inherited : DefinitionData::IDI_NotInherited; } else { @@ -516,7 +522,8 @@ } void ObjCInterfaceDecl::getDesignatedInitializers( - llvm::SmallVectorImpl &Methods) const { + llvm::SmallVectorImpl &Methods, + IsHiddenFunction IsHidden) const { // Check for a complete definition and recover if not so. if (!isThisDeclarationADefinition()) return; @@ -523,7 +530,8 @@ if (data().ExternallyCompleted) LoadExternalDefinition(); - const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); + const ObjCInterfaceDecl *IFace = + findInterfaceWithDesignatedInitializers(IsHidden); if (!IFace) return; @@ -530,7 +538,7 @@ for (const auto *MD : IFace->instance_methods()) if (MD->isThisDeclarationADesignatedInitializer()) Methods.push_back(MD); - for (const auto *Ext : IFace->visible_extensions()) { + for (const auto *Ext : IFace->visible_extensions(IsHidden)) { for (const auto *MD : Ext->instance_methods()) if (MD->isThisDeclarationADesignatedInitializer()) Methods.push_back(MD); @@ -537,8 +545,9 @@ } } -bool ObjCInterfaceDecl::isDesignatedInitializer(Selector Sel, - const ObjCMethodDecl **InitMethod) const { +bool ObjCInterfaceDecl::isDesignatedInitializer( + Selector Sel, const ObjCMethodDecl **InitMethod, + IsHiddenFunction IsHidden) const { bool HasCompleteDef = isThisDeclarationADefinition(); // During deserialization the data record for the ObjCInterfaceDecl could // be made invariant by reusing the canonical decl. Take this into account @@ -554,11 +563,12 @@ if (data().ExternallyCompleted) LoadExternalDefinition(); - const ObjCInterfaceDecl *IFace= findInterfaceWithDesignatedInitializers(); + const ObjCInterfaceDecl *IFace = + findInterfaceWithDesignatedInitializers(IsHidden); if (!IFace) return false; - if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel)) { + if (const ObjCMethodDecl *MD = IFace->getInstanceMethod(Sel, IsHidden)) { if (MD->isThisDeclarationADesignatedInitializer()) { if (InitMethod) *InitMethod = MD; @@ -565,8 +575,8 @@ return true; } } - for (const auto *Ext : IFace->visible_extensions()) { - if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel)) { + for (const auto *Ext : IFace->visible_extensions(IsHidden)) { + if (const ObjCMethodDecl *MD = Ext->getInstanceMethod(Sel, IsHidden)) { if (MD->isThisDeclarationADesignatedInitializer()) { if (InitMethod) *InitMethod = MD; @@ -597,8 +607,10 @@ } } -ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, - ObjCInterfaceDecl *&clsDeclared) { +ObjCIvarDecl * +ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID, + ObjCInterfaceDecl *&clsDeclared, + IsHiddenFunction IsHidden) { // FIXME: Should make sure no callers ever do this. if (!hasDefinition()) return nullptr; @@ -613,7 +625,7 @@ return I; } - for (const auto *Ext : ClassDecl->visible_extensions()) { + for (const auto *Ext : ClassDecl->visible_extensions(IsHidden)) { if (ObjCIvarDecl *I = Ext->getIvarDecl(ID)) { clsDeclared = ClassDecl; return I; @@ -661,6 +673,7 @@ /// in this category is ignored. ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden, bool shallowCategoryLookup, bool followSuper, const ObjCCategoryDecl *C) const @@ -677,29 +690,29 @@ while (ClassDecl) { // 1. Look through primary class. - if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance))) + if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance, IsHidden))) return MethodDecl; // 2. Didn't find one yet - now look through categories. - for (const auto *Cat : ClassDecl->visible_categories()) - if ((MethodDecl = Cat->getMethod(Sel, isInstance))) + for (const auto *Cat : ClassDecl->visible_categories(IsHidden)) + if ((MethodDecl = Cat->getMethod(Sel, isInstance, IsHidden))) if (C != Cat || !MethodDecl->isImplicit()) return MethodDecl; // 3. Didn't find one yet - look through primary class's protocols. for (const auto *I : ClassDecl->protocols()) - if ((MethodDecl = I->lookupMethod(Sel, isInstance))) + if ((MethodDecl = I->lookupMethod(Sel, isInstance, IsHidden))) return MethodDecl; // 4. Didn't find one yet - now look through categories' protocols if (!shallowCategoryLookup) - for (const auto *Cat : ClassDecl->visible_categories()) { + for (const auto *Cat : ClassDecl->visible_categories(IsHidden)) { // Didn't find one yet - look through protocols. const ObjCList &Protocols = Cat->getReferencedProtocols(); for (ObjCList::iterator I = Protocols.begin(), E = Protocols.end(); I != E; ++I) - if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance))) + if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance, IsHidden))) if (C != Cat || !MethodDecl->isImplicit()) return MethodDecl; } @@ -717,9 +730,9 @@ // Will search "local" class/category implementations for a method decl. // If failed, then we search in class's root for an instance method. // Returns 0 if no method is found. -ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod( - const Selector &Sel, - bool Instance) const { +ObjCMethodDecl * +ObjCInterfaceDecl::lookupPrivateMethod(const Selector &Sel, bool Instance, + IsHiddenFunction IsHidden) const { // FIXME: Should make sure no callers ever do this. if (!hasDefinition()) return nullptr; @@ -729,26 +742,26 @@ ObjCMethodDecl *Method = nullptr; if (ObjCImplementationDecl *ImpDecl = getImplementation()) - Method = Instance ? ImpDecl->getInstanceMethod(Sel) - : ImpDecl->getClassMethod(Sel); + Method = Instance ? ImpDecl->getInstanceMethod(Sel, IsHidden) + : ImpDecl->getClassMethod(Sel, IsHidden); // Look through local category implementations associated with the class. if (!Method) - Method = getCategoryMethod(Sel, Instance); + Method = getCategoryMethod(Sel, Instance, IsHidden); // Before we give up, check if the selector is an instance method. // But only in the root. This matches gcc's behavior and what the // runtime expects. if (!Instance && !Method && !getSuperClass()) { - Method = lookupInstanceMethod(Sel); + Method = lookupInstanceMethod(Sel, IsHidden); // Look through local category implementations associated // with the root class. if (!Method) - Method = lookupPrivateMethod(Sel, true); + Method = lookupPrivateMethod(Sel, true, IsHidden); } if (!Method && getSuperClass()) - return getSuperClass()->lookupPrivateMethod(Sel, Instance); + return getSuperClass()->lookupPrivateMethod(Sel, Instance, IsHidden); return Method; } @@ -779,7 +792,7 @@ } bool ObjCMethodDecl::isDesignatedInitializerForTheInterface( - const ObjCMethodDecl **InitMethod) const { + IsHiddenFunction IsHidden, const ObjCMethodDecl **InitMethod) const { if (getMethodFamily() != OMF_init) return false; const DeclContext *DC = getDeclContext(); @@ -786,7 +799,7 @@ if (isa(DC)) return false; if (const ObjCInterfaceDecl *ID = getClassInterface()) - return ID->isDesignatedInitializer(getSelector(), InitMethod); + return ID->isDesignatedInitializer(getSelector(), InitMethod, IsHidden); return false; } @@ -858,24 +871,28 @@ if (ObjCInterfaceDecl *IFD = dyn_cast(CtxD)) { if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD)) if (!ImplD->isInvalidDecl()) - Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod(), + AllDeclsVisible); } else if (ObjCCategoryDecl *CD = dyn_cast(CtxD)) { if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD)) if (!ImplD->isInvalidDecl()) - Redecl = ImplD->getMethod(getSelector(), isInstanceMethod()); + Redecl = ImplD->getMethod(getSelector(), isInstanceMethod(), + AllDeclsVisible); } else if (ObjCImplementationDecl *ImplD = dyn_cast(CtxD)) { if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) if (!IFD->isInvalidDecl()) - Redecl = IFD->getMethod(getSelector(), isInstanceMethod()); + Redecl = IFD->getMethod(getSelector(), isInstanceMethod(), + AllDeclsVisible); } else if (ObjCCategoryImplDecl *CImplD = dyn_cast(CtxD)) { if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) if (!CatD->isInvalidDecl()) - Redecl = CatD->getMethod(getSelector(), isInstanceMethod()); + Redecl = CatD->getMethod(getSelector(), isInstanceMethod(), + AllDeclsVisible); } } @@ -888,7 +905,8 @@ if (!Redecl && isRedeclaration()) { // This is the last redeclaration, go back to the first method. return cast(CtxD)->getMethod(getSelector(), - isInstanceMethod()); + isInstanceMethod(), + AllDeclsVisible); } return Redecl ? Redecl : this; @@ -899,23 +917,22 @@ if (ObjCImplementationDecl *ImplD = dyn_cast(CtxD)) { if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface()) - if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), - isInstanceMethod())) + if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(), isInstanceMethod(), + AllDeclsVisible)) return MD; } else if (ObjCCategoryImplDecl *CImplD = dyn_cast(CtxD)) { if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl()) - if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(), - isInstanceMethod())) + if (ObjCMethodDecl *MD = CatD->getMethod( + getSelector(), isInstanceMethod(), AllDeclsVisible)) return MD; } if (isRedeclaration()) { // It is possible that we have not done deserializing the ObjCMethod yet. - ObjCMethodDecl *MD = - cast(CtxD)->getMethod(getSelector(), - isInstanceMethod()); + ObjCMethodDecl *MD = cast(CtxD)->getMethod( + getSelector(), isInstanceMethod(), AllDeclsVisible); return MD ? MD : this; } @@ -1137,7 +1154,7 @@ if (ObjCMethodDecl * Overridden = Container->getMethod(Method->getSelector(), Method->isInstanceMethod(), - /*AllowHidden=*/true)) + AllDeclsVisible)) if (Method != Overridden) { // We found an override at this category; there is no need to look // into its protocols. @@ -1154,7 +1171,7 @@ if (const ObjCMethodDecl * Overridden = Container->getMethod(Method->getSelector(), Method->isInstanceMethod(), - /*AllowHidden=*/true)) + AllDeclsVisible)) if (Method != Overridden) { // We found an override at this level; there is no need to look // into other protocols or categories. @@ -1205,7 +1222,7 @@ // interface as starting point. if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), Method->isInstanceMethod(), - /*AllowHidden=*/true)) + AllDeclsVisible)) Method = IFaceMeth; CollectOverriddenMethods(ID, Method, overridden); @@ -1218,7 +1235,7 @@ // interface as starting point. if (const ObjCMethodDecl *IFaceMeth = ID->getMethod(Method->getSelector(), Method->isInstanceMethod(), - /*AllowHidden=*/true)) + AllDeclsVisible)) Method = IFaceMeth; CollectOverriddenMethods(ID, Method, overridden); @@ -1234,8 +1251,9 @@ const ObjCMethodDecl *Method = this; if (Method->isRedeclaration()) { - Method = cast(Method->getDeclContext())-> - getMethod(Method->getSelector(), Method->isInstanceMethod()); + Method = cast(Method->getDeclContext()) + ->getMethod(Method->getSelector(), Method->isInstanceMethod(), + AllDeclsVisible); } if (Method->isOverriding()) { @@ -1246,7 +1264,8 @@ } const ObjCPropertyDecl * -ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { +ObjCMethodDecl::findPropertyDecl(IsHiddenFunction IsHidden, + bool CheckOverrides) const { Selector Sel = getSelector(); unsigned NumArgs = Sel.getNumArgs(); if (NumArgs > 1) @@ -1297,7 +1316,7 @@ // If we have a class, check its visible extensions. if (ClassDecl) { - for (const auto *Ext : ClassDecl->visible_extensions()) { + for (const auto *Ext : ClassDecl->visible_extensions(IsHidden)) { if (Ext == Container) continue; @@ -1317,7 +1336,7 @@ getOverriddenMethods(Overrides); for (OverridesTy::const_iterator I = Overrides.begin(), E = Overrides.end(); I != E; ++I) { - if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(false)) + if (const ObjCPropertyDecl *Prop = (*I)->findPropertyDecl(IsHidden, false)) return Prop; } @@ -1612,7 +1631,8 @@ /// in 'CategoryId'. If category not found, return 0; /// ObjCCategoryDecl * -ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const { +ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId, + IsHiddenFunction IsHidden) const { // FIXME: Should make sure no callers ever do this. if (!hasDefinition()) return nullptr; @@ -1620,7 +1640,7 @@ if (data().ExternallyCompleted) LoadExternalDefinition(); - for (auto *Cat : visible_categories()) + for (auto *Cat : visible_categories(IsHidden)) if (Cat->getIdentifier() == CategoryId) return Cat; @@ -1628,10 +1648,11 @@ } ObjCMethodDecl * -ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const { - for (const auto *Cat : visible_categories()) { +ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + for (const auto *Cat : visible_categories(IsHidden)) { if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) - if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel)) + if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel, IsHidden)) return MD; } @@ -1638,10 +1659,12 @@ return nullptr; } -ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const { - for (const auto *Cat : visible_categories()) { +ObjCMethodDecl * +ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel, + IsHiddenFunction IsHidden) const { + for (const auto *Cat : visible_categories(IsHidden)) { if (ObjCCategoryImplDecl *Impl = Cat->getImplementation()) - if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel)) + if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel, IsHidden)) return MD; } @@ -1652,8 +1675,9 @@ /// has been implemented in IDecl class, its super class or categories (if /// lookupCategory is true). bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto, - bool lookupCategory, - bool RHSIsQualifiedID) { + bool LookupInCategories, + IsHiddenFunction IsHidden, + bool RHSIsQualifiedID) { if (!hasDefinition()) return false; @@ -1674,8 +1698,8 @@ } // 2nd, look up the category. - if (lookupCategory) - for (const auto *Cat : visible_categories()) { + if (LookupInCategories) + for (const auto *Cat : visible_categories(IsHidden)) { for (auto *PI : Cat->protocols()) if (getASTContext().ProtocolCompatibleWithProtocol(lProto, PI)) return true; @@ -1683,9 +1707,8 @@ // 3rd, look up the super class(s) if (IDecl->getSuperClass()) - return - IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory, - RHSIsQualifiedID); + return IDecl->getSuperClass()->ClassImplementsProtocol( + lProto, LookupInCategories, IsHidden, RHSIsQualifiedID); return false; } @@ -1839,21 +1862,22 @@ // lookupMethod - Lookup a instance/class method in the protocol and protocols // it inherited. -ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel, - bool isInstance) const { +ObjCMethodDecl * +ObjCProtocolDecl::lookupMethod(Selector Sel, bool isInstance, + IsHiddenFunction IsHidden) const { ObjCMethodDecl *MethodDecl = nullptr; // If there is no definition or the definition is hidden, we don't find // anything. const ObjCProtocolDecl *Def = getDefinition(); - if (!Def || Def->isHidden()) + if (!Def || IsHidden(Def)) return nullptr; - if ((MethodDecl = getMethod(Sel, isInstance))) + if ((MethodDecl = getMethod(Sel, isInstance, IsHidden))) return MethodDecl; for (const auto *I : protocols()) - if ((MethodDecl = I->lookupMethod(Sel, isInstance))) + if ((MethodDecl = I->lookupMethod(Sel, isInstance, IsHidden))) return MethodDecl; return nullptr; } @@ -2021,7 +2045,7 @@ ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const { // The class interface might be NULL if we are working with invalid code. if (const ObjCInterfaceDecl *ID = getClassInterface()) - return ID->FindCategoryDeclaration(getIdentifier()); + return ID->FindCategoryDeclaration(getIdentifier(), AllDeclsVisible); return nullptr; } @@ -2044,7 +2068,8 @@ } else if (ObjCCategoryImplDecl *ImplD = dyn_cast_or_null(this)) { - if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier())) + if (ObjCCategoryDecl *CD = + IFace->FindCategoryDeclaration(getIdentifier(), AllDeclsVisible)) Ctx.setObjCImplementation(CD, ImplD); } Index: lib/Analysis/BodyFarm.cpp =================================================================== --- lib/Analysis/BodyFarm.cpp +++ lib/Analysis/BodyFarm.cpp @@ -414,7 +414,7 @@ // is guaranteed to find the shadowing property, if it exists, rather than // the shadowed property. auto *ShadowingProp = PrimaryInterface->FindPropertyVisibleInPrimaryClass( - Prop->getIdentifier(), Prop->getQueryKind()); + Prop->getIdentifier(), Prop->getQueryKind(), AllDeclsVisible); if (ShadowingProp && ShadowingProp != Prop) { IVar = ShadowingProp->getPropertyIvarDecl(); } @@ -495,7 +495,7 @@ return Val.getValue(); Val = nullptr; - const ObjCPropertyDecl *Prop = D->findPropertyDecl(); + const ObjCPropertyDecl *Prop = D->findPropertyDecl(AllDeclsVisible); if (!Prop) return nullptr; Index: lib/Analysis/CallGraph.cpp =================================================================== --- lib/Analysis/CallGraph.cpp +++ lib/Analysis/CallGraph.cpp @@ -73,9 +73,9 @@ // Find the callee definition within the same translation unit. Decl *D = nullptr; if (ME->isInstanceMessage()) - D = IDecl->lookupPrivateMethod(Sel); + D = IDecl->lookupPrivateMethod(Sel, AllDeclsVisible); else - D = IDecl->lookupPrivateClassMethod(Sel); + D = IDecl->lookupPrivateClassMethod(Sel, AllDeclsVisible); if (D) { addCalledDecl(D); NumObjCCallEdges++; Index: lib/CodeGen/CGObjCMac.cpp =================================================================== --- lib/CodeGen/CGObjCMac.cpp +++ lib/CodeGen/CGObjCMac.cpp @@ -6187,7 +6187,8 @@ bool CGObjCNonFragileABIMac::ImplementationIsNonLazy(const ObjCImplDecl *OD) const { - return OD->getClassMethod(GetNullarySelector("load")) != nullptr; + return OD->getClassMethod(GetNullarySelector("load"), AllDeclsVisible) != + nullptr; } void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID, Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -3735,11 +3735,11 @@ // we want, that just indicates if the decl came from a // property. What we want to know is if the method is defined in // this implementation. - if (!D->getInstanceMethod(PD->getGetterName())) + if (!D->getInstanceMethod(PD->getGetterName(), AllDeclsVisible)) CodeGenFunction(*this).GenerateObjCGetter( const_cast(D), PID); if (!PD->isReadOnly() && - !D->getInstanceMethod(PD->getSetterName())) + !D->getInstanceMethod(PD->getSetterName(), AllDeclsVisible)) CodeGenFunction(*this).GenerateObjCSetter( const_cast(D), PID); } Index: lib/Edit/RewriteObjCFoundationAPI.cpp =================================================================== --- lib/Edit/RewriteObjCFoundationAPI.cpp +++ lib/Edit/RewriteObjCFoundationAPI.cpp @@ -162,7 +162,8 @@ return false; IFace = maybeAdjustInterfaceForSubscriptingCheck(IFace, Rec, Ctx); - if (const ObjCMethodDecl *MD = IFace->lookupInstanceMethod(subscriptSel)) { + if (const ObjCMethodDecl *MD = + IFace->lookupInstanceMethod(subscriptSel, AllDeclsVisible)) { if (!MD->isUnavailable()) return true; } Index: lib/Frontend/Rewrite/RewriteModernObjC.cpp =================================================================== --- lib/Frontend/Rewrite/RewriteModernObjC.cpp +++ lib/Frontend/Rewrite/RewriteModernObjC.cpp @@ -592,7 +592,7 @@ bool ImplementationIsNonLazy(const ObjCImplDecl *OD) const { IdentifierInfo* II = &Context->Idents.get("load"); Selector LoadSel = Context->Selectors.getSelector(0, &II); - return OD->getClassMethod(LoadSel) != nullptr; + return OD->getClassMethod(LoadSel, AllDeclsVisible) != nullptr; } StringLiteral *getStringLiteral(StringRef Str) { @@ -910,9 +910,8 @@ static bool mustSynthesizeSetterGetterMethod(ObjCImplementationDecl *IMP, ObjCPropertyDecl *PD, bool getter) { - return getter ? !IMP->getInstanceMethod(PD->getGetterName()) - : !IMP->getInstanceMethod(PD->getSetterName()); - + return !IMP->getInstanceMethod( + getter ? PD->getGetterName() : PD->getSetterName(), AllDeclsVisible); } void RewriteModernObjC::RewritePropertyImplDecl(ObjCPropertyImplDecl *PID, Index: lib/Index/IndexDecl.cpp =================================================================== --- lib/Index/IndexDecl.cpp +++ lib/Index/IndexDecl.cpp @@ -47,8 +47,8 @@ /// user. static bool hasUserDefined(const ObjCMethodDecl *D, const ObjCImplDecl *Container) { - const ObjCMethodDecl *MD = Container->getMethod(D->getSelector(), - D->isInstanceMethod()); + const ObjCMethodDecl *MD = Container->getMethod( + D->getSelector(), D->isInstanceMethod(), AllDeclsVisible); return MD && !MD->isImplicit() && MD->isThisDeclarationADefinition(); } Index: lib/Sema/ScopeInfo.cpp =================================================================== --- lib/Sema/ScopeInfo.cpp +++ lib/Sema/ScopeInfo.cpp @@ -207,7 +207,8 @@ Uses = WeakObjectUses.find(WeakObjectProfileTy(DRE)); } else if (const ObjCMessageExpr *MsgE = dyn_cast(E)) { if (const ObjCMethodDecl *MD = MsgE->getMethodDecl()) { - if (const ObjCPropertyDecl *Prop = MD->findPropertyDecl()) { + if (const ObjCPropertyDecl *Prop = + MD->findPropertyDecl(AllDeclsVisible)) { Uses = WeakObjectUses.find(WeakObjectProfileTy(MsgE->getInstanceReceiver(), Prop)); Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -2295,8 +2295,9 @@ // parameter in a setter. if (!Block && ObjCMethodParam && cast(Param->getDeclContext())->isPropertyAccessor()) { - if (const auto *PD = cast(Param->getDeclContext()) - ->findPropertyDecl(/*CheckOverrides=*/false)) + if (const auto *PD = + cast(Param->getDeclContext()) + ->findPropertyDecl(AllDeclsVisible, /*CheckOverrides=*/false)) findTypeLocationForBlockDecl(PD->getTypeSourceInfo(), Block, BlockProto, SuppressBlock); } @@ -2704,7 +2705,8 @@ const NamedDecl *ND = Declaration; if (const ObjCMethodDecl *M = dyn_cast(ND)) if (M->isPropertyAccessor()) - if (const ObjCPropertyDecl *PDecl = M->findPropertyDecl()) + if (const ObjCPropertyDecl *PDecl = + M->findPropertyDecl(AllDeclsVisible)) if (PDecl->getGetterName() == M->getSelector() && PDecl->getIdentifier() != M->getIdentifier()) { if (const RawComment *RC = @@ -2782,7 +2784,8 @@ } else if (const ObjCMethodDecl *OMD = dyn_cast(ND)) if (OMD->isPropertyAccessor()) - if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) + if (const ObjCPropertyDecl *PDecl = + OMD->findPropertyDecl(AllDeclsVisible)) if (const RawComment *RC = Ctx.getRawCommentForAnyRedecl(PDecl)) Result.addBriefComment(RC->getBriefText(Ctx)); } @@ -5658,14 +5661,16 @@ ObjCMethodDecl *SuperMethod = nullptr; while ((Class = Class->getSuperClass()) && !SuperMethod) { // Check in the class - SuperMethod = Class->getMethod(CurMethod->getSelector(), - CurMethod->isInstanceMethod()); + SuperMethod = Class->getMethod(CurMethod->getSelector(), + CurMethod->isInstanceMethod(), + Sema::IsHiddenCallback(S)); // Check in categories or class extensions. if (!SuperMethod) { for (const auto *Cat : Class->known_categories()) { if ((SuperMethod = Cat->getMethod(CurMethod->getSelector(), - CurMethod->isInstanceMethod()))) + CurMethod->isInstanceMethod(), + Sema::IsHiddenCallback(S)))) break; } } @@ -6390,7 +6395,7 @@ NamedDecl *CurClass = LookupSingleName(TUScope, ClassName, ClassNameLoc, LookupOrdinaryName); if (ObjCInterfaceDecl *Class = dyn_cast_or_null(CurClass)){ - for (const auto *Cat : Class->visible_categories()) + for (const auto *Cat : Class->visible_categories(IsHiddenCallback(*this))) CategoryNames.insert(Cat->getIdentifier()); } @@ -6435,7 +6440,7 @@ Results.EnterNewScope(); bool IgnoreImplemented = true; while (Class) { - for (const auto *Cat : Class->visible_categories()) { + for (const auto *Cat : Class->visible_categories(IsHiddenCallback(*this))) { if ((!IgnoreImplemented || !Cat->getImplementation()) && CategoryNames.insert(Cat->getIdentifier()).second) Results.AddResult(Result(Cat, Results.getBasePriority(Cat), nullptr), @@ -6520,7 +6525,8 @@ QualType PropertyType = Context.getObjCIdType(); if (Class) { if (ObjCPropertyDecl *Property = Class->FindPropertyDeclaration( - PropertyName, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + PropertyName, ObjCPropertyQueryKind::OBJC_PR_query_instance, + IsHiddenCallback(*this))) { PropertyType = Property->getType().getNonReferenceType().getUnqualifiedType(); @@ -6617,7 +6623,7 @@ KnownMethods, InOriginalClass); // Add methods from any class extensions and categories. - for (auto *Cat : IFace->visible_categories()) { + for (auto *Cat : IFace->known_categories()) { FindImplementableMethods(Context, Cat, WantInstanceMethods, ReturnType, KnownMethods, false); } @@ -7495,7 +7501,7 @@ IFace = Category->getClassInterface(); if (IFace) - for (auto *Cat : IFace->visible_categories()) + for (auto *Cat : IFace->visible_categories(IsHiddenCallback(*this))) Containers.push_back(Cat); for (unsigned I = 0, N = Containers.size(); I != N; ++I) Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -12383,8 +12383,8 @@ } if (getCurFunction()->ObjCWarnForNoDesignatedInitChain) { const ObjCMethodDecl *InitMethod = nullptr; - bool isDesignated = - MD->isDesignatedInitializerForTheInterface(&InitMethod); + bool isDesignated = MD->isDesignatedInitializerForTheInterface( + IsHiddenCallback(*this), &InitMethod); assert(isDesignated && InitMethod); (void)isDesignated; Index: lib/Sema/SemaDeclObjC.cpp =================================================================== --- lib/Sema/SemaDeclObjC.cpp +++ lib/Sema/SemaDeclObjC.cpp @@ -364,9 +364,10 @@ // Warn on deprecated methods under -Wdeprecated-implementations, // and prepare for warning on missing super calls. if (ObjCInterfaceDecl *IC = MDecl->getClassInterface()) { - ObjCMethodDecl *IMD = - IC->lookupMethod(MDecl->getSelector(), MDecl->isInstanceMethod()); - + ObjCMethodDecl *IMD = + IC->lookupMethod(MDecl->getSelector(), MDecl->isInstanceMethod(), + IsHiddenCallback(*this)); + if (IMD) { ObjCImplDecl *ImplDeclOfMethodDef = dyn_cast(MDecl->getDeclContext()); @@ -391,7 +392,8 @@ } if (MDecl->getMethodFamily() == OMF_init) { - if (MDecl->isDesignatedInitializerForTheInterface()) { + if (MDecl->isDesignatedInitializerForTheInterface( + IsHiddenCallback(*this))) { getCurFunction()->ObjCIsDesignatedInit = true; getCurFunction()->ObjCWarnForNoDesignatedInitChain = IC->getSuperClass() != nullptr; @@ -417,9 +419,9 @@ getCurFunction()->ObjCShouldCallSuper = true; } else { - const ObjCMethodDecl *SuperMethod = - SuperClass->lookupMethod(MDecl->getSelector(), - MDecl->isInstanceMethod()); + const ObjCMethodDecl *SuperMethod = SuperClass->lookupMethod( + MDecl->getSelector(), MDecl->isInstanceMethod(), + IsHiddenCallback(*this)); getCurFunction()->ObjCShouldCallSuper = (SuperMethod && SuperMethod->hasAttr()); } @@ -2675,6 +2677,7 @@ !InsMap.count(method->getSelector()) && (!Super || !Super->lookupMethod(method->getSelector(), true /* instance */, + Sema::IsHiddenCallback(S), false /* shallowCategory */, true /* followsSuper */, nullptr /* category */))) { @@ -2690,6 +2693,7 @@ if (ObjCMethodDecl *MethodInClass = IDecl->lookupMethod(method->getSelector(), true /* instance */, + Sema::IsHiddenCallback(S), true /* shallowCategoryLookup */, false /* followSuper */)) if (C || MethodInClass->isPropertyAccessor()) @@ -2707,6 +2711,7 @@ !ClsMap.count(method->getSelector()) && (!Super || !Super->lookupMethod(method->getSelector(), false /* class method */, + Sema::IsHiddenCallback(S), false /* shallowCategoryLookup */, true /* followSuper */, nullptr /* category */))) { @@ -2713,6 +2718,7 @@ // See above comment for instance method lookups. if (C && IDecl->lookupMethod(method->getSelector(), false /* class */, + Sema::IsHiddenCallback(S), true /* shallowCategoryLookup */, false /* followSuper */)) continue; @@ -2754,8 +2760,8 @@ continue; } else { ObjCMethodDecl *ImpMethodDecl = - IMPDecl->getInstanceMethod(I->getSelector()); - assert(CDecl->getInstanceMethod(I->getSelector(), true/*AllowHidden*/) && + IMPDecl->getInstanceMethod(I->getSelector(), IsHiddenCallback(*this)); + assert(CDecl->getInstanceMethod(I->getSelector(), AllDeclsVisible) && "Expected to find the method through lookup as well"); // ImpMethodDecl may be null as in a @dynamic property. if (ImpMethodDecl) { @@ -2780,8 +2786,8 @@ diag::warn_undef_method_impl); } else { ObjCMethodDecl *ImpMethodDecl = - IMPDecl->getClassMethod(I->getSelector()); - assert(CDecl->getClassMethod(I->getSelector(), true/*AllowHidden*/) && + IMPDecl->getClassMethod(I->getSelector(), IsHiddenCallback(*this)); + assert(CDecl->getClassMethod(I->getSelector(), AllDeclsVisible) && "Expected to find the method through lookup as well"); // ImpMethodDecl may be null as in a @dynamic property. if (ImpMethodDecl) { @@ -2856,7 +2862,8 @@ // When checking for methods implemented in the category, skip over // those declared in category class's super class. This is because // the super class must implement the method. - if (SuperIDecl && SuperIDecl->lookupMethod(Sel, true)) + if (SuperIDecl && + SuperIDecl->lookupMethod(Sel, true, IsHiddenCallback(*this))) continue; InsMap.insert(Sel); } @@ -2863,7 +2870,8 @@ for (const auto *I : CatIMPDecl->class_methods()) { Selector Sel = I->getSelector(); - if (SuperIDecl && SuperIDecl->lookupMethod(Sel, false)) + if (SuperIDecl && + SuperIDecl->lookupMethod(Sel, false, IsHiddenCallback(*this))) continue; ClsMap.insert(Sel); } @@ -3822,12 +3830,12 @@ continue; for (const auto *Ext : IDecl->visible_extensions()) { - if (ObjCMethodDecl *GetterMethod - = Ext->getInstanceMethod(Property->getGetterName())) + if (ObjCMethodDecl *GetterMethod = Ext->getInstanceMethod( + Property->getGetterName(), IsHiddenCallback(*this))) GetterMethod->setPropertyAccessor(true); if (!Property->isReadOnly()) - if (ObjCMethodDecl *SetterMethod - = Ext->getInstanceMethod(Property->getSetterName())) + if (ObjCMethodDecl *SetterMethod = Ext->getInstanceMethod( + Property->getSetterName(), IsHiddenCallback(*this))) SetterMethod->setPropertyAccessor(true); } } @@ -4108,7 +4116,7 @@ // Check for a method in this container which matches this selector. ObjCMethodDecl *meth = container->getMethod(Method->getSelector(), Method->isInstanceMethod(), - /*AllowHidden=*/true); + AllDeclsVisible); // If we find one, record it and bail out. if (meth) { @@ -4480,10 +4488,10 @@ const ObjCMethodDecl *PrevMethod = nullptr; if (ObjCImplDecl *ImpDecl = dyn_cast(ClassDecl)) { if (MethodType == tok::minus) { - PrevMethod = ImpDecl->getInstanceMethod(Sel); + PrevMethod = ImpDecl->getInstanceMethod(Sel, IsHiddenCallback(*this)); ImpDecl->addInstanceMethod(ObjCMethod); } else { - PrevMethod = ImpDecl->getClassMethod(Sel); + PrevMethod = ImpDecl->getClassMethod(Sel, IsHiddenCallback(*this)); ImpDecl->addClassMethod(ObjCMethod); } @@ -4491,7 +4499,8 @@ // @implementation. if (ObjCInterfaceDecl *IDecl = ImpDecl->getClassInterface()) { if (auto *IMD = IDecl->lookupMethod(ObjCMethod->getSelector(), - ObjCMethod->isInstanceMethod())) { + ObjCMethod->isInstanceMethod(), + IsHiddenCallback(*this))) { mergeInterfaceMethodToImpl(*this, ObjCMethod, IMD); // Warn about defining -dealloc in a category. @@ -4776,7 +4785,7 @@ ObjCIvarDecl * Sema::GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, - const ObjCPropertyDecl *&PDecl) const { + const ObjCPropertyDecl *&PDecl) { if (Method->isClassMethod()) return nullptr; const ObjCInterfaceDecl *IDecl = Method->getClassInterface(); @@ -4783,6 +4792,7 @@ if (!IDecl) return nullptr; Method = IDecl->lookupMethod(Method->getSelector(), /*isInstance=*/true, + IsHiddenCallback(*this), /*shallowCategoryLookup=*/false, /*followSuper=*/false); if (!Method || !Method->isPropertyAccessor()) Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -87,7 +87,8 @@ } } -static bool HasRedeclarationWithoutAvailabilityInCategory(const Decl *D) { +static bool HasRedeclarationWithoutAvailabilityInCategory(Sema &S, + const Decl *D) { const auto *OMD = dyn_cast(D); if (!OMD) return false; @@ -97,7 +98,8 @@ for (const ObjCCategoryDecl *Cat : OID->visible_categories()) if (ObjCMethodDecl *CatMeth = - Cat->getMethod(OMD->getSelector(), OMD->isInstanceMethod())) + Cat->getMethod(OMD->getSelector(), OMD->isInstanceMethod(), + Sema::IsHiddenCallback(S))) if (!CatMeth->hasAttr()) return true; return false; @@ -144,7 +146,7 @@ // Objective-C method declarations in categories are not modelled as // redeclarations, so manually look for a redeclaration in a category // if necessary. - if (Warn && HasRedeclarationWithoutAvailabilityInCategory(D)) + if (Warn && HasRedeclarationWithoutAvailabilityInCategory(*this, D)) Warn = false; // In general, D will point to the most recent redeclaration. However, // for `@class A;` decls, this isn't true -- manually go through the Index: lib/Sema/SemaExprMember.cpp =================================================================== --- lib/Sema/SemaExprMember.cpp +++ lib/Sema/SemaExprMember.cpp @@ -426,20 +426,21 @@ return VT; // should never get here (a typedef type should always be found). } -static Decl *FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl*PDecl, - IdentifierInfo *Member, - const Selector &Sel, - ASTContext &Context) { +static Decl * +FindGetterSetterNameDeclFromProtocolList(const ObjCProtocolDecl *PDecl, + IdentifierInfo *Member, + const Selector &Sel, Sema &S) { if (Member) if (ObjCPropertyDecl *PD = PDecl->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + Sema::IsHiddenCallback(S))) return PD; - if (ObjCMethodDecl *OMD = PDecl->getInstanceMethod(Sel)) + if (ObjCMethodDecl *OMD = + PDecl->getInstanceMethod(Sel, Sema::IsHiddenCallback(S))) return OMD; for (const auto *I : PDecl->protocols()) { - if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, - Context)) + if (Decl *D = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, S)) return D; } return nullptr; @@ -448,18 +449,20 @@ static Decl *FindGetterSetterNameDecl(const ObjCObjectPointerType *QIdTy, IdentifierInfo *Member, const Selector &Sel, - ASTContext &Context) { + Sema &S) { // Check protocols on qualified interfaces. Decl *GDecl = nullptr; for (const auto *I : QIdTy->quals()) { if (Member) if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + Sema::IsHiddenCallback(S))) { GDecl = PD; break; } // Also must look for a getter or setter name which uses property syntax. - if (ObjCMethodDecl *OMD = I->getInstanceMethod(Sel)) { + if (ObjCMethodDecl *OMD = + I->getInstanceMethod(Sel, Sema::IsHiddenCallback(S))) { GDecl = OMD; break; } @@ -467,7 +470,7 @@ if (!GDecl) { for (const auto *I : QIdTy->quals()) { // Search in the protocol-qualifier list of current protocol. - GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, Context); + GDecl = FindGetterSetterNameDeclFromProtocolList(I, Member, Sel, S); if (GDecl) return GDecl; } @@ -1408,7 +1411,8 @@ return ExprError(); ObjCInterfaceDecl *ClassDeclared = nullptr; - ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); + ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared, + Sema::IsHiddenCallback(S)); if (!IV) { // Attempt to correct for typos in ivar names. @@ -1439,7 +1443,8 @@ } else { if (IsArrow && IDecl->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + Sema::IsHiddenCallback(S))) { S.Diag(MemberLoc, diag::err_property_found_suggest) << Member << BaseExpr.get()->getType() << FixItHint::CreateReplacement(OpLoc, "."); @@ -1557,7 +1562,7 @@ // Check protocols on qualified interfaces. Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member); if (Decl *PMDecl = - FindGetterSetterNameDecl(OPT, Member, Sel, S.Context)) { + FindGetterSetterNameDecl(OPT, Member, Sel, S)) { if (ObjCPropertyDecl *PD = dyn_cast(PMDecl)) { // Check the use of this declaration if (S.DiagnoseUseOfDecl(PD, MemberLoc)) @@ -1579,7 +1584,7 @@ ObjCMethodDecl *SMD = nullptr; if (Decl *SDecl = FindGetterSetterNameDecl(OPT, /*Property id*/ nullptr, - SetterSel, S.Context)) + SetterSel, S)) SMD = dyn_cast(SDecl); return new (S.Context) @@ -1613,12 +1618,13 @@ Selector Sel = S.PP.getSelectorTable().getNullarySelector(Member); ObjCInterfaceDecl *IFace = MD->getClassInterface(); ObjCMethodDecl *Getter; - if ((Getter = IFace->lookupClassMethod(Sel))) { + if ((Getter = IFace->lookupClassMethod(Sel, Sema::IsHiddenCallback(S)))) { // Check the use of this method. if (S.DiagnoseUseOfDecl(Getter, MemberLoc)) return ExprError(); } else - Getter = IFace->lookupPrivateMethod(Sel, false); + Getter = + IFace->lookupPrivateClassMethod(Sel, Sema::IsHiddenCallback(S)); // If we found a getter then this may be a valid dot-reference, we // will look for the matching setter, in case it is needed. Selector SetterSel = @@ -1625,11 +1631,13 @@ SelectorTable::constructSetterSelector(S.PP.getIdentifierTable(), S.PP.getSelectorTable(), Member); - ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); + ObjCMethodDecl *Setter = + IFace->lookupClassMethod(SetterSel, Sema::IsHiddenCallback(S)); if (!Setter) { // If this reference is in an @implementation, also check for 'private' // methods. - Setter = IFace->lookupPrivateMethod(SetterSel, false); + Setter = IFace->lookupPrivateClassMethod(SetterSel, + Sema::IsHiddenCallback(S)); } if (Setter && S.DiagnoseUseOfDecl(Setter, MemberLoc)) Index: lib/Sema/SemaExprObjC.cpp =================================================================== --- lib/Sema/SemaExprObjC.cpp +++ lib/Sema/SemaExprObjC.cpp @@ -279,7 +279,8 @@ } // Look for the appropriate method within NSNumber. - ObjCMethodDecl *Method = S.NSNumberDecl->lookupClassMethod(Sel); + ObjCMethodDecl *Method = + S.NSNumberDecl->lookupClassMethod(Sel, Sema::IsHiddenCallback(S)); if (!Method && S.getLangOpts().DebuggerObjCLiteral) { // create a stub definition this NSNumber factory method. TypeSourceInfo *ReturnTInfo = nullptr; @@ -531,7 +532,8 @@ Selector stringWithUTF8String = Context.Selectors.getUnarySelector(II); // Look for the appropriate method within NSString. - BoxingMethod = NSStringDecl->lookupClassMethod(stringWithUTF8String); + BoxingMethod = NSStringDecl->lookupClassMethod( + stringWithUTF8String, Sema::IsHiddenCallback(*this)); if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) { // Debugger needs to work even if NSString hasn't been defined. TypeSourceInfo *ReturnTInfo = nullptr; @@ -636,7 +638,8 @@ Selector ValueWithBytesObjCType = Context.Selectors.getSelector(2, II); // Look for the appropriate method within NSValue. - BoxingMethod = NSValueDecl->lookupClassMethod(ValueWithBytesObjCType); + BoxingMethod = NSValueDecl->lookupClassMethod(ValueWithBytesObjCType, + IsHiddenCallback(*this)); if (!BoxingMethod && getLangOpts().DebuggerObjCLiteral) { // Debugger needs to work even if NSValue hasn't been defined. TypeSourceInfo *ReturnTInfo = nullptr; @@ -778,7 +781,8 @@ if (!ArrayWithObjectsMethod) { Selector Sel = NSAPIObj->getNSArraySelector(NSAPI::NSArr_arrayWithObjectsCount); - ObjCMethodDecl *Method = NSArrayDecl->lookupClassMethod(Sel); + ObjCMethodDecl *Method = + NSArrayDecl->lookupClassMethod(Sel, IsHiddenCallback(*this)); if (!Method && getLangOpts().DebuggerObjCLiteral) { TypeSourceInfo *ReturnTInfo = nullptr; Method = ObjCMethodDecl::Create( @@ -884,7 +888,8 @@ if (!DictionaryWithObjectsMethod) { Selector Sel = NSAPIObj->getNSDictionarySelector( NSAPI::NSDict_dictionaryWithObjectsForKeysCount); - ObjCMethodDecl *Method = NSDictionaryDecl->lookupClassMethod(Sel); + ObjCMethodDecl *Method = + NSDictionaryDecl->lookupClassMethod(Sel, IsHiddenCallback(*this)); if (!Method && getLangOpts().DebuggerObjCLiteral) { Method = ObjCMethodDecl::Create(Context, SourceLocation(), SourceLocation(), Sel, @@ -1402,7 +1407,7 @@ /// Look for an ObjC method whose result type exactly matches the given type. static const ObjCMethodDecl * -findExplicitInstancetypeDeclarer(const ObjCMethodDecl *MD, +findExplicitInstancetypeDeclarer(Sema &S, const ObjCMethodDecl *MD, QualType instancetype) { if (MD->getReturnType() == instancetype) return MD; @@ -1419,9 +1424,10 @@ iface = impl->getClassInterface(); } - const ObjCMethodDecl *ifaceMD = - iface->getMethod(MD->getSelector(), MD->isInstanceMethod()); - if (ifaceMD) return findExplicitInstancetypeDeclarer(ifaceMD, instancetype); + const ObjCMethodDecl *ifaceMD = iface->getMethod( + MD->getSelector(), MD->isInstanceMethod(), Sema::IsHiddenCallback(S)); + if (ifaceMD) + return findExplicitInstancetypeDeclarer(S, ifaceMD, instancetype); } SmallVector overrides; @@ -1428,7 +1434,7 @@ MD->getOverriddenMethods(overrides); for (unsigned i = 0, e = overrides.size(); i != e; ++i) { if (const ObjCMethodDecl *result = - findExplicitInstancetypeDeclarer(overrides[i], instancetype)) + findExplicitInstancetypeDeclarer(S, overrides[i], instancetype)) return result; } @@ -1445,8 +1451,8 @@ // Look for a method overridden by this method which explicitly uses // 'instancetype'. - if (const ObjCMethodDecl *overridden = - findExplicitInstancetypeDeclarer(MD, Context.getObjCInstanceType())) { + if (const ObjCMethodDecl *overridden = findExplicitInstancetypeDeclarer( + *this, MD, Context.getObjCInstanceType())) { SourceRange range = overridden->getReturnTypeSourceRange(); SourceLocation loc = range.getBegin(); if (loc.isInvalid()) @@ -1556,7 +1562,7 @@ ReceiverType->getAs()->getInterfaceDecl()) { Diag(ThisClass->getLocation(), diag::note_receiver_class_declared); if (!RecRange.isInvalid()) - if (ThisClass->lookupClassMethod(Sel)) + if (ThisClass->lookupClassMethod(Sel, IsHiddenCallback(*this))) Diag(RecRange.getBegin(),diag::note_receiver_expr_here) << FixItHint::CreateReplacement(RecRange, ThisClass->getNameAsString()); @@ -1717,18 +1723,21 @@ const ObjCObjectType *objType = type->castAs(); if (ObjCInterfaceDecl *iface = objType->getInterface()) { // Look it up in the main interface (and categories, etc.) - if (ObjCMethodDecl *method = iface->lookupMethod(sel, isInstance)) + if (ObjCMethodDecl *method = + iface->lookupMethod(sel, isInstance, IsHiddenCallback(*this))) return method; // Okay, look for "private" methods declared in any // @implementations we've seen. - if (ObjCMethodDecl *method = iface->lookupPrivateMethod(sel, isInstance)) + if (ObjCMethodDecl *method = iface->lookupPrivateMethod( + sel, isInstance, IsHiddenCallback(*this))) return method; } // Check qualifiers. for (const auto *I : objType->quals()) - if (ObjCMethodDecl *method = I->lookupMethod(sel, isInstance)) + if (ObjCMethodDecl *method = + I->lookupMethod(sel, isInstance, IsHiddenCallback(*this))) return method; return nullptr; @@ -1742,7 +1751,7 @@ { ObjCMethodDecl *MD = nullptr; for (const auto *PROTO : OPT->quals()) { - if ((MD = PROTO->lookupMethod(Sel, Instance))) { + if ((MD = PROTO->lookupMethod(Sel, Instance, IsHiddenCallback(*this)))) { return MD; } } @@ -1775,9 +1784,10 @@ diag::err_property_not_found_forward_class, MemberName, BaseRange)) return ExprError(); - + if (ObjCPropertyDecl *PD = IFace->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + IsHiddenCallback(*this))) { // Check whether we can reference this property. if (DiagnoseUseOfDecl(PD, MemberLoc)) return ExprError(); @@ -1793,7 +1803,8 @@ // Check protocols on qualified interfaces. for (const auto *I : OPT->quals()) if (ObjCPropertyDecl *PD = I->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + IsHiddenCallback(*this))) { // Check whether we can reference this property. if (DiagnoseUseOfDecl(PD, MemberLoc)) return ExprError(); @@ -1814,8 +1825,9 @@ // shared with the code in ActOnInstanceMessage. Selector Sel = PP.getSelectorTable().getNullarySelector(Member); - ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Sel); - + ObjCMethodDecl *Getter = + IFace->lookupInstanceMethod(Sel, IsHiddenCallback(*this)); + // May be found in property's qualified list. if (!Getter) Getter = LookupMethodInQualifiedType(Sel, OPT, true); @@ -1822,7 +1834,7 @@ // If this reference is in an @implementation, check for 'private' methods. if (!Getter) - Getter = IFace->lookupPrivateMethod(Sel); + Getter = IFace->lookupPrivateMethod(Sel, IsHiddenCallback(*this)); if (Getter) { // Check if we can reference this property. @@ -1834,8 +1846,9 @@ Selector SetterSel = SelectorTable::constructSetterSelector(PP.getIdentifierTable(), PP.getSelectorTable(), Member); - ObjCMethodDecl *Setter = IFace->lookupInstanceMethod(SetterSel); - + ObjCMethodDecl *Setter = + IFace->lookupInstanceMethod(SetterSel, IsHiddenCallback(*this)); + // May be found in property's qualified list. if (!Setter) Setter = LookupMethodInQualifiedType(SetterSel, OPT, true); @@ -1843,7 +1856,7 @@ if (!Setter) { // If this reference is in an @implementation, also check for 'private' // methods. - Setter = IFace->lookupPrivateMethod(SetterSel); + Setter = IFace->lookupPrivateMethod(SetterSel, IsHiddenCallback(*this)); } if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc)) @@ -1854,16 +1867,17 @@ // name 'x'. if (Setter && Setter->isImplicit() && Setter->isPropertyAccessor() && !IFace->FindPropertyDeclaration( - Member, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { - if (const ObjCPropertyDecl *PDecl = Setter->findPropertyDecl()) { - // Do not warn if user is using property-dot syntax to make call to - // user named setter. - if (!(PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter)) - Diag(MemberLoc, - diag::warn_property_access_suggest) - << MemberName << QualType(OPT, 0) << PDecl->getName() - << FixItHint::CreateReplacement(MemberLoc, PDecl->getName()); - } + Member, ObjCPropertyQueryKind::OBJC_PR_query_instance, + IsHiddenCallback(*this))) { + if (const ObjCPropertyDecl *PDecl = + Setter->findPropertyDecl(IsHiddenCallback(*this))) { + // Do not warn if user is using property-dot syntax to make call to + // user named setter. + if (!(PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter)) + Diag(MemberLoc, diag::warn_property_access_suggest) + << MemberName << QualType(OPT, 0) << PDecl->getName() + << FixItHint::CreateReplacement(MemberLoc, PDecl->getName()); + } } if (Getter || Setter) { @@ -1909,8 +1923,8 @@ } } ObjCInterfaceDecl *ClassDeclared; - if (ObjCIvarDecl *Ivar = - IFace->lookupInstanceVariable(Member, ClassDeclared)) { + if (ObjCIvarDecl *Ivar = IFace->lookupInstanceVariable( + Member, IsHiddenCallback(*this), ClassDeclared)) { QualType T = Ivar->getType(); if (const ObjCObjectPointerType * OBJPT = T->getAsObjCInterfacePointerType()) { @@ -1986,7 +2000,8 @@ Selector GetterSel; Selector SetterSel; if (auto PD = IFace->FindPropertyDeclaration( - &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class)) { + &propertyName, ObjCPropertyQueryKind::OBJC_PR_query_class, + IsHiddenCallback(*this))) { GetterSel = PD->getGetterName(); SetterSel = PD->getSetterName(); } else { @@ -1996,11 +2011,13 @@ } // Search for a declared property first. - ObjCMethodDecl *Getter = IFace->lookupClassMethod(GetterSel); + ObjCMethodDecl *Getter = + IFace->lookupClassMethod(GetterSel, IsHiddenCallback(*this)); // If this reference is in an @implementation, check for 'private' methods. if (!Getter) - Getter = IFace->lookupPrivateClassMethod(GetterSel); + Getter = + IFace->lookupPrivateClassMethod(GetterSel, IsHiddenCallback(*this)); if (Getter) { // FIXME: refactor/share with ActOnMemberReference(). @@ -2010,15 +2027,17 @@ } // Look for the matching setter, in case it is needed. - ObjCMethodDecl *Setter = IFace->lookupClassMethod(SetterSel); + ObjCMethodDecl *Setter = + IFace->lookupClassMethod(SetterSel, IsHiddenCallback(*this)); if (!Setter) { // If this reference is in an @implementation, also check for 'private' // methods. - Setter = IFace->lookupPrivateClassMethod(SetterSel); + Setter = + IFace->lookupPrivateClassMethod(SetterSel, IsHiddenCallback(*this)); } // Look through local category implementations associated with the class. if (!Setter) - Setter = IFace->getCategoryClassMethod(SetterSel); + Setter = IFace->getCategoryClassMethod(SetterSel, IsHiddenCallback(*this)); if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc)) return ExprError(); @@ -2282,19 +2301,20 @@ const auto *OPT = ReceiverType->getAs(); if (!OPT || !OPT->getInterfaceDecl()) return; - ImpliedMethod = - OPT->getInterfaceDecl()->lookupInstanceMethod(SE->getSelector()); + ImpliedMethod = OPT->getInterfaceDecl()->lookupInstanceMethod( + SE->getSelector(), Sema::IsHiddenCallback(S)); if (!ImpliedMethod) - ImpliedMethod = - OPT->getInterfaceDecl()->lookupPrivateMethod(SE->getSelector()); + ImpliedMethod = OPT->getInterfaceDecl()->lookupPrivateMethod( + SE->getSelector(), Sema::IsHiddenCallback(S)); } else { const auto *IT = ReceiverType->getAs(); if (!IT) return; - ImpliedMethod = IT->getDecl()->lookupClassMethod(SE->getSelector()); + ImpliedMethod = IT->getDecl()->lookupClassMethod(SE->getSelector(), + Sema::IsHiddenCallback(S)); if (!ImpliedMethod) - ImpliedMethod = - IT->getDecl()->lookupPrivateClassMethod(SE->getSelector()); + ImpliedMethod = IT->getDecl()->lookupPrivateClassMethod( + SE->getSelector(), Sema::IsHiddenCallback(S)); } if (!ImpliedMethod) return; @@ -2444,11 +2464,11 @@ << Method->getDeclName(); } if (!Method) - Method = Class->lookupClassMethod(Sel); + Method = Class->lookupClassMethod(Sel, IsHiddenCallback(*this)); // If we have an implementation in scope, check "private" methods. if (!Method) - Method = Class->lookupPrivateClassMethod(Sel); + Method = Class->lookupPrivateClassMethod(Sel, IsHiddenCallback(*this)); if (Method && DiagnoseUseOfDecl(Method, SelLoc)) return ExprError(); @@ -2760,10 +2780,12 @@ if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) { if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) { // First check the public methods in the class interface. - Method = ClassDecl->lookupClassMethod(Sel); + Method = + ClassDecl->lookupClassMethod(Sel, IsHiddenCallback(*this)); if (!Method) - Method = ClassDecl->lookupPrivateClassMethod(Sel); + Method = ClassDecl->lookupPrivateClassMethod( + Sel, IsHiddenCallback(*this)); } if (Method && DiagnoseUseOfDecl(Method, SelLoc)) return ExprError(); @@ -2838,7 +2860,8 @@ : SuperLoc, diag::note_receiver_is_id); Method = nullptr; } else { - Method = ClassDecl->lookupInstanceMethod(Sel); + Method = + ClassDecl->lookupInstanceMethod(Sel, IsHiddenCallback(*this)); } if (!Method) @@ -2847,7 +2870,7 @@ if (!Method) { // If we have implementations in scope, check "private" methods. - Method = ClassDecl->lookupPrivateMethod(Sel); + Method = ClassDecl->lookupPrivateMethod(Sel, IsHiddenCallback(*this)); if (!Method && getLangOpts().ObjCAutoRefCount) { Diag(SelLoc, diag::err_arc_may_not_respond) @@ -2912,8 +2935,9 @@ if (const ObjCInterfaceDecl *ID = OCIType->getInterfaceDecl()) { // Either we know this is a designated initializer or we // conservatively assume it because we don't know for sure. - if (!ID->declaresOrInheritsDesignatedInitializers() || - ID->isDesignatedInitializer(Sel)) { + if (!ID->declaresOrInheritsDesignatedInitializers( + IsHiddenCallback(*this)) || + ID->isDesignatedInitializer(Sel, IsHiddenCallback(*this))) { isDesignatedInitChain = true; DIFunctionScopeInfo->ObjCWarnForNoDesignatedInitChain = false; } @@ -2923,7 +2947,8 @@ if (!isDesignatedInitChain) { const ObjCMethodDecl *InitMethod = nullptr; bool isDesignated = - getCurMethodDecl()->isDesignatedInitializerForTheInterface(&InitMethod); + getCurMethodDecl()->isDesignatedInitializerForTheInterface( + IsHiddenCallback(*this), &InitMethod); assert(isDesignated && InitMethod); (void)isDesignated; Diag(SelLoc, SuperLoc.isValid() ? @@ -3103,7 +3128,8 @@ if (getLangOpts().ObjCWeak) { if (!isImplicit && Method) { - if (const ObjCPropertyDecl *Prop = Method->findPropertyDecl()) { + if (const ObjCPropertyDecl *Prop = + Method->findPropertyDecl(IsHiddenCallback(*this))) { bool IsWeak = Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak; if (!IsWeak && Sel.isUnarySelector()) @@ -3755,7 +3781,7 @@ return false; } else if (castType->isObjCIdType() || (S.Context.ObjCObjectAdoptsQTypeProtocols( - castType, ExprClass))) + castType, ExprClass, Sema::IsHiddenCallback(S)))) // ok to cast to 'id'. // casting to id is ok if bridge type adopts all of // p-list protocols. @@ -3822,7 +3848,8 @@ return false; } else if (castExpr->getType()->isObjCIdType() || (S.Context.QIdProtocolsAdoptObjCObjectProtocols( - castExpr->getType(), CastClass))) + castExpr->getType(), CastClass, + Sema::IsHiddenCallback(S)))) // ok to cast an 'id' expression to a CFtype. // ok to cast an 'id' expression to CFtype provided plist // adopts all of CFtype's ObjetiveC's class plist. @@ -3986,7 +4013,8 @@ // Check for an existing class method with the given selector name. if (CfToNs && CMId) { Selector Sel = Context.Selectors.getUnarySelector(CMId); - ClassMethod = RelatedClass->lookupMethod(Sel, false); + ClassMethod = + RelatedClass->lookupMethod(Sel, false, IsHiddenCallback(*this)); if (!ClassMethod) { if (Diagnose) { Diag(Loc, diag::err_objc_bridged_related_known_method) @@ -4000,7 +4028,8 @@ // Check for an existing instance method with the given selector name. if (!CfToNs && IMId) { Selector Sel = Context.Selectors.getNullarySelector(IMId); - InstanceMethod = RelatedClass->lookupMethod(Sel, true); + InstanceMethod = + RelatedClass->lookupMethod(Sel, true, IsHiddenCallback(*this)); if (!InstanceMethod) { if (Diagnose) { Diag(Loc, diag::err_objc_bridged_related_known_method) @@ -4071,7 +4100,7 @@ getLocForEndOfToken(SrcExpr->getLocEnd()); if (InstanceMethod->isPropertyAccessor()) if (const ObjCPropertyDecl *PDecl = - InstanceMethod->findPropertyDecl()) { + InstanceMethod->findPropertyDecl(IsHiddenCallback(*this))) { // fixit: ObjectExpr.propertyname when it is aproperty accessor. ExpressionString = "."; ExpressionString += PDecl->getNameAsString(); Index: lib/Sema/SemaLookup.cpp =================================================================== --- lib/Sema/SemaLookup.cpp +++ lib/Sema/SemaLookup.cpp @@ -1165,8 +1165,7 @@ if (ObjCInterfaceDecl *Class = Method->getClassInterface()) { ObjCInterfaceDecl *ClassDeclared; if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable( - Name.getAsIdentifierInfo(), - ClassDeclared)) { + Name.getAsIdentifierInfo(), ClassDeclared)) { if (NamedDecl *ND = R.getAcceptableDecl(Ivar)) { R.addDecl(ND); R.resolveKind(); @@ -3519,7 +3518,8 @@ // Traverse the contexts of Objective-C classes. if (ObjCInterfaceDecl *IFace = dyn_cast(Ctx)) { // Traverse categories. - for (auto *Cat : IFace->visible_categories()) { + for (auto *Cat : + IFace->visible_categories(Sema::IsHiddenCallback(Result.getSema()))) { ShadowContextRAII Shadow(Visited); LookupVisibleDecls(Cat, Result, QualifiedNameLookup, false, Consumer, Visited); @@ -4253,7 +4253,8 @@ if (MemberContext) { if (ObjCInterfaceDecl *Class = dyn_cast(MemberContext)) { if (isObjCIvarLookup) { - if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) { + if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable( + Name, Sema::IsHiddenCallback(SemaRef))) { Res.addDecl(Ivar); Res.resolveKind(); return; @@ -4261,7 +4262,8 @@ } if (ObjCPropertyDecl *Prop = Class->FindPropertyDeclaration( - Name, ObjCPropertyQueryKind::OBJC_PR_query_instance)) { + Name, ObjCPropertyQueryKind::OBJC_PR_query_instance, + Sema::IsHiddenCallback(SemaRef))) { Res.addDecl(Prop); Res.resolveKind(); return; @@ -4282,12 +4284,13 @@ (Res.empty() || (Res.isSingleResult() && Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) { - if (ObjCIvarDecl *IV - = Method->getClassInterface()->lookupInstanceVariable(Name)) { - Res.addDecl(IV); - Res.resolveKind(); - } - } + if (ObjCIvarDecl *IV = + Method->getClassInterface()->lookupInstanceVariable( + Name, Sema::IsHiddenCallback(SemaRef))) { + Res.addDecl(IV); + Res.resolveKind(); + } + } } } Index: lib/Sema/SemaObjCProperty.cpp =================================================================== --- lib/Sema/SemaObjCProperty.cpp +++ lib/Sema/SemaObjCProperty.cpp @@ -443,7 +443,8 @@ // Find the property in the extended class's primary class or // extensions. ObjCPropertyDecl *PIDecl = CCPrimary->FindPropertyVisibleInPrimaryClass( - PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty)); + PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty), + IsHiddenCallback(*this)); // If we found a property in an extension, complain. if (PIDecl && isa(PIDecl->getDeclContext())) { @@ -603,7 +604,8 @@ if (IDecl) if (ObjCProtocolDecl* PNSCopying = LookupProtocol(&Context.Idents.get("NSCopying"), AtLoc)) - if (IDecl->ClassImplementsProtocol(PNSCopying, true)) + if (IDecl->ClassImplementsProtocol(PNSCopying, true, + IsHiddenCallback(*this))) Diag(AtLoc, diag::warn_implements_nscopying) << PropertyId; } } @@ -628,7 +630,8 @@ (Attributes & ObjCDeclSpec::DQ_PR_class); // Class property and instance property can have the same name. if (ObjCPropertyDecl *prevDecl = ObjCPropertyDecl::findPropertyDecl( - DC, PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty))) { + DC, PropertyId, ObjCPropertyDecl::getQueryKind(isClassProperty), + IsHiddenCallback(*this))) { Diag(PDecl->getLocation(), diag::err_duplicate_property); Diag(prevDecl->getLocation(), diag::note_property_declare); PDecl->setInvalidDecl(); @@ -864,7 +867,7 @@ } /// Determine whether any storage attributes were written on the property. -static bool hasWrittenStorageAttribute(ObjCPropertyDecl *Prop, +static bool hasWrittenStorageAttribute(Sema &S, ObjCPropertyDecl *Prop, ObjCPropertyQueryKind QueryKind) { if (Prop->getPropertyAttributesAsWritten() & OwnershipMask) return true; @@ -889,7 +892,7 @@ // Look through all of the protocols. for (const auto *Proto : OrigClass->all_referenced_protocols()) { if (ObjCPropertyDecl *OrigProp = Proto->FindPropertyDeclaration( - Prop->getIdentifier(), QueryKind)) + Prop->getIdentifier(), QueryKind, Sema::IsHiddenCallback(S))) return OrigProp->getPropertyAttributesAsWritten() & OwnershipMask; } @@ -934,7 +937,8 @@ "ActOnPropertyImplDecl - @implementation without @interface"); // Look for this property declaration in the @implementation's @interface - property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind); + property = IDecl->FindPropertyDeclaration(PropertyId, QueryKind, + IsHiddenCallback(*this)); if (!property) { Diag(PropertyLoc, diag::err_bad_property_decl) << IDecl->getDeclName(); return nullptr; @@ -1008,8 +1012,8 @@ Diag(AtLoc, diag::err_missing_property_interface); return nullptr; } - ObjCCategoryDecl *Category = - IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); + ObjCCategoryDecl *Category = IDecl->FindCategoryDeclaration( + CatImplClass->getIdentifier(), IsHiddenCallback(*this)); // If category for this implementation not found, it is an error which // has already been reported eralier. @@ -1016,7 +1020,8 @@ if (!Category) return nullptr; // Look for this property declaration in @implementation's category - property = Category->FindPropertyDeclaration(PropertyId, QueryKind); + property = Category->FindPropertyDeclaration(PropertyId, QueryKind, + IsHiddenCallback(*this)); if (!property) { Diag(PropertyLoc, diag::err_bad_category_property_decl) << Category->getDeclName(); @@ -1036,7 +1041,8 @@ PropertyIvar = PropertyId; // Check that this is a previously declared 'ivar' in 'IDecl' interface ObjCInterfaceDecl *ClassDeclared; - Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared); + Ivar = IDecl->lookupInstanceVariable(PropertyIvar, IsHiddenCallback(*this), + ClassDeclared); QualType PropType = property->getType(); QualType PropertyIvarType = PropType.getNonReferenceType(); @@ -1128,7 +1134,7 @@ // It's an error if we have to do this and the user didn't // explicitly write an ownership attribute on the property. - if (!hasWrittenStorageAttribute(property, QueryKind) && + if (!hasWrittenStorageAttribute(*this, property, QueryKind) && !(kind & ObjCPropertyDecl::OBJC_PR_strong)) { Diag(PropertyDiagLoc, diag::err_arc_objc_property_default_assign_on_object); @@ -1184,10 +1190,9 @@ if (!Context.hasSameType(PropertyIvarType, IvarType)) { if (isa(PropertyIvarType) && isa(IvarType)) - compat = - Context.canAssignObjCInterfaces( - PropertyIvarType->getAs(), - IvarType->getAs()); + compat = Context.canAssignObjCInterfaces( + PropertyIvarType->getAs(), + IvarType->getAs(), IsHiddenCallback(*this)); else { compat = (CheckAssignmentConstraints(PropertyIvarLoc, PropertyIvarType, IvarType) @@ -1512,7 +1517,8 @@ if ((propertyObjCPtr = PropertyRValueType->getAs()) && (getterObjCPtr = GetterType->getAs())) - compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr); + compat = Context.canAssignObjCInterfaces(getterObjCPtr, propertyObjCPtr, + IsHiddenCallback(*this)); else if (CheckAssignmentConstraints(Loc, GetterType, PropertyRValueType) != Compatible) { Diag(Loc, diag::err_property_accessor_type) @@ -1543,7 +1549,7 @@ /// CollectImmediateProperties - This routine collects all properties in /// the class and its conforming protocols; but not those in its super class. static void -CollectImmediateProperties(ObjCContainerDecl *CDecl, +CollectImmediateProperties(Sema &S, ObjCContainerDecl *CDecl, ObjCContainerDecl::PropertyMap &PropMap, ObjCContainerDecl::PropertyMap &SuperPropMap, bool CollectClassPropsOnly = false, @@ -1557,14 +1563,14 @@ } // Collect the properties from visible extensions. - for (auto *Ext : IDecl->visible_extensions()) - CollectImmediateProperties(Ext, PropMap, SuperPropMap, + for (auto *Ext : IDecl->visible_extensions(Sema::IsHiddenCallback(S))) + CollectImmediateProperties(S, Ext, PropMap, SuperPropMap, CollectClassPropsOnly, IncludeProtocols); if (IncludeProtocols) { // Scan through class's protocols. for (auto *PI : IDecl->all_referenced_protocols()) - CollectImmediateProperties(PI, PropMap, SuperPropMap, + CollectImmediateProperties(S, PI, PropMap, SuperPropMap, CollectClassPropsOnly); } } @@ -1578,7 +1584,7 @@ if (IncludeProtocols) { // Scan through class's protocols. for (auto *PI : CATDecl->protocols()) - CollectImmediateProperties(PI, PropMap, SuperPropMap, + CollectImmediateProperties(S, PI, PropMap, SuperPropMap, CollectClassPropsOnly); } } @@ -1602,7 +1608,7 @@ } // Scan through protocol's protocols. for (auto *PI : PDecl->protocols()) - CollectImmediateProperties(PI, PropMap, SuperPropMap, + CollectImmediateProperties(S, PI, PropMap, SuperPropMap, CollectClassPropsOnly); } } @@ -1629,8 +1635,9 @@ ObjCMethodDecl *Method, ObjCIvarDecl *IV) { if (!IV->getSynthesize()) return false; - ObjCMethodDecl *IMD = IFace->lookupMethod(Method->getSelector(), - Method->isInstanceMethod()); + ObjCMethodDecl *IMD = + IFace->lookupMethod(Method->getSelector(), Method->isInstanceMethod(), + IsHiddenCallback(*this)); if (!IMD || !IMD->isPropertyAccessor()) return false; @@ -1653,7 +1660,7 @@ return false; } -static bool SuperClassImplementsProperty(ObjCInterfaceDecl *IDecl, +static bool SuperClassImplementsProperty(Sema &S, ObjCInterfaceDecl *IDecl, ObjCPropertyDecl *Prop) { bool SuperClassImplementsGetter = false; bool SuperClassImplementsSetter = false; @@ -1662,10 +1669,14 @@ while (IDecl->getSuperClass()) { ObjCInterfaceDecl *SDecl = IDecl->getSuperClass(); - if (!SuperClassImplementsGetter && SDecl->getInstanceMethod(Prop->getGetterName())) + if (!SuperClassImplementsGetter && + SDecl->getInstanceMethod(Prop->getGetterName(), + Sema::IsHiddenCallback(S))) SuperClassImplementsGetter = true; - if (!SuperClassImplementsSetter && SDecl->getInstanceMethod(Prop->getSetterName())) + if (!SuperClassImplementsSetter && + SDecl->getInstanceMethod(Prop->getSetterName(), + Sema::IsHiddenCallback(S))) SuperClassImplementsSetter = true; if (SuperClassImplementsGetter && SuperClassImplementsSetter) return true; @@ -1697,10 +1708,12 @@ if (IMPDecl->FindPropertyImplDecl( Prop->getIdentifier(), Prop->getQueryKind())) continue; - if (IMPDecl->getInstanceMethod(Prop->getGetterName())) { + if (IMPDecl->getInstanceMethod(Prop->getGetterName(), + IsHiddenCallback(*this))) { if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly) continue; - if (IMPDecl->getInstanceMethod(Prop->getSetterName())) + if (IMPDecl->getInstanceMethod(Prop->getSetterName(), + IsHiddenCallback(*this))) continue; } if (ObjCPropertyImplDecl *PID = @@ -1720,7 +1733,8 @@ // Suppress the warning if class's superclass implements property's // getter and implements property's setter (if readwrite property). // Or, if property is going to be implemented in its super class. - if (!SuperClassImplementsProperty(IDecl, Prop) && !PropInSuperClass) { + if (!SuperClassImplementsProperty(*this, IDecl, Prop) && + !PropInSuperClass) { Diag(IMPDecl->getLocation(), diag::warn_auto_synthesizing_protocol_property) << Prop << Proto; @@ -1730,11 +1744,13 @@ } // If property to be implemented in the super class, ignore. if (PropInSuperClass) { - if ((Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readwrite) && + if ((Prop->getPropertyAttributes() & + ObjCPropertyDecl::OBJC_PR_readwrite) && (PropInSuperClass->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_readonly) && - !IMPDecl->getInstanceMethod(Prop->getSetterName()) && - !IDecl->HasUserDeclaredSetterMethod(Prop)) { + !IMPDecl->getInstanceMethod(Prop->getSetterName(), + IsHiddenCallback(*this)) && + !IDecl->HasUserDeclaredSetterMethod(Prop, IsHiddenCallback(*this))) { Diag(Prop->getLocation(), diag::warn_no_autosynthesis_property) << Prop->getIdentifier(); Diag(PropInSuperClass->getLocation(), diag::note_property_declare); @@ -1793,8 +1809,8 @@ // the class is going to implement them. if (I == SMap.end() && (PrimaryClass == nullptr || - !PrimaryClass->lookupPropertyAccessor(Method, C, - Prop->isClassProperty()))) { + !PrimaryClass->lookupPropertyAccessor(Method, Sema::IsHiddenCallback(S), + C, Prop->isClassProperty()))) { unsigned diag = isa(CDecl) ? (Prop->isClassProperty() @@ -1838,7 +1854,7 @@ CollectSuperClassPropertyImplementations(IDecl, NoNeedToImplPropMap); // When SynthesizeProperties is true, we only check class properties. - CollectImmediateProperties(CDecl, PropMap, NoNeedToImplPropMap, + CollectImmediateProperties(*this, CDecl, PropMap, NoNeedToImplPropMap, SynthesizeProperties/*CollectClassPropsOnly*/); // Scan the @interface to see if any of the protocols it adopts @@ -1860,7 +1876,7 @@ if (!LazyMap) { ObjCContainerDecl::PropertyMap NoNeedToImplPropMap; LazyMap.reset(new ObjCContainerDecl::PropertyMap()); - CollectImmediateProperties(CDecl, *LazyMap, NoNeedToImplPropMap, + CollectImmediateProperties(*this, CDecl, *LazyMap, NoNeedToImplPropMap, /* CollectClassPropsOnly */ false, /* IncludeProtocols */ false); } @@ -1935,8 +1951,10 @@ property->getSetterMethodDecl()) { auto *getterMethod = property->getGetterMethodDecl(); auto *setterMethod = property->getSetterMethodDecl(); - if (!impDecl->getInstanceMethod(setterMethod->getSelector()) && - !impDecl->getInstanceMethod(getterMethod->getSelector())) { + if (!impDecl->getInstanceMethod(setterMethod->getSelector(), + IsHiddenCallback(*this)) && + !impDecl->getInstanceMethod(getterMethod->getSelector(), + IsHiddenCallback(*this))) { SourceLocation loc = propertyImpl->getLocation(); if (loc.isInvalid()) loc = impDecl->getLocStart(); @@ -1973,12 +1991,12 @@ if (!(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_atomic) && !(AttributesAsWritten & ObjCPropertyDecl::OBJC_PR_nonatomic)) { - GetterMethod = Property->isClassProperty() ? - IMPDecl->getClassMethod(Property->getGetterName()) : - IMPDecl->getInstanceMethod(Property->getGetterName()); - SetterMethod = Property->isClassProperty() ? - IMPDecl->getClassMethod(Property->getSetterName()) : - IMPDecl->getInstanceMethod(Property->getSetterName()); + GetterMethod = IMPDecl->getMethod(Property->getGetterName(), + !Property->isClassProperty(), + IsHiddenCallback(*this)); + SetterMethod = IMPDecl->getMethod(Property->getSetterName(), + !Property->isClassProperty(), + IsHiddenCallback(*this)); LookedUpGetterSetter = true; if (GetterMethod) { Diag(GetterMethod->getLocation(), @@ -2003,12 +2021,12 @@ if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) continue; if (!LookedUpGetterSetter) { - GetterMethod = Property->isClassProperty() ? - IMPDecl->getClassMethod(Property->getGetterName()) : - IMPDecl->getInstanceMethod(Property->getGetterName()); - SetterMethod = Property->isClassProperty() ? - IMPDecl->getClassMethod(Property->getSetterName()) : - IMPDecl->getInstanceMethod(Property->getSetterName()); + GetterMethod = IMPDecl->getMethod(Property->getGetterName(), + !Property->isClassProperty(), + IsHiddenCallback(*this)); + SetterMethod = IMPDecl->getMethod(Property->getSetterName(), + !Property->isClassProperty(), + IsHiddenCallback(*this)); } if ((GetterMethod && !SetterMethod) || (!GetterMethod && SetterMethod)) { SourceLocation MethodLoc = @@ -2052,7 +2070,7 @@ const ObjCPropertyDecl *PD = PID->getPropertyDecl(); if (PD && !PD->hasAttr() && !PD->isClassProperty() && - !D->getInstanceMethod(PD->getGetterName())) { + !D->getInstanceMethod(PD->getGetterName(), IsHiddenCallback(*this))) { ObjCMethodDecl *method = PD->getGetterMethodDecl(); if (!method) continue; @@ -2115,13 +2133,14 @@ InitSelSet.insert(I->getSelector()); SmallVector DesignatedInits; - SuperD->getDesignatedInitializers(DesignatedInits); + SuperD->getDesignatedInitializers(DesignatedInits, IsHiddenCallback(*this)); for (SmallVector::iterator I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) { const ObjCMethodDecl *MD = *I; if (!InitSelSet.count(MD->getSelector())) { bool Ignore = false; - if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) { + if (auto *IMD = IFD->getInstanceMethod(MD->getSelector(), + IsHiddenCallback(*this))) { Ignore = IMD->isUnavailable(); } if (!Ignore) { @@ -2158,9 +2177,8 @@ return; bool IsClassProperty = property->isClassProperty(); - GetterMethod = IsClassProperty ? - CD->getClassMethod(property->getGetterName()) : - CD->getInstanceMethod(property->getGetterName()); + GetterMethod = CD->getMethod(property->getGetterName(), !IsClassProperty, + IsHiddenCallback(*this)); // if setter or getter is not found in class extension, it might be // in the primary class. @@ -2167,21 +2185,18 @@ if (!GetterMethod) if (const ObjCCategoryDecl *CatDecl = dyn_cast(CD)) if (CatDecl->IsClassExtension()) - GetterMethod = IsClassProperty ? CatDecl->getClassInterface()-> - getClassMethod(property->getGetterName()) : - CatDecl->getClassInterface()-> - getInstanceMethod(property->getGetterName()); - - SetterMethod = IsClassProperty ? - CD->getClassMethod(property->getSetterName()) : - CD->getInstanceMethod(property->getSetterName()); + GetterMethod = CatDecl->getClassInterface()->getMethod( + property->getGetterName(), !IsClassProperty, + IsHiddenCallback(*this)); + + SetterMethod = CD->getMethod(property->getSetterName(), !IsClassProperty, + IsHiddenCallback(*this)); if (!SetterMethod) if (const ObjCCategoryDecl *CatDecl = dyn_cast(CD)) if (CatDecl->IsClassExtension()) - SetterMethod = IsClassProperty ? CatDecl->getClassInterface()-> - getClassMethod(property->getSetterName()) : - CatDecl->getClassInterface()-> - getInstanceMethod(property->getSetterName()); + SetterMethod = CatDecl->getClassInterface()->getMethod( + property->getSetterName(), !IsClassProperty, + IsHiddenCallback(*this)); DiagnosePropertyAccessorMismatch(property, GetterMethod, property->getLocation()); Index: lib/Sema/SemaOverload.cpp =================================================================== --- lib/Sema/SemaOverload.cpp +++ lib/Sema/SemaOverload.cpp @@ -2367,7 +2367,8 @@ return false; // Conversion between Objective-C pointers. - if (Context.canAssignObjCInterfaces(ToObjCPtr, FromObjCPtr)) { + if (Context.canAssignObjCInterfaces(ToObjCPtr, FromObjCPtr, + IsHiddenCallback(*this))) { const ObjCInterfaceType* LHS = ToObjCPtr->getInterfaceType(); const ObjCInterfaceType* RHS = FromObjCPtr->getInterfaceType(); if (getLangOpts().CPlusPlus && LHS && RHS && @@ -2381,7 +2382,8 @@ return true; } - if (Context.canAssignObjCInterfaces(FromObjCPtr, ToObjCPtr)) { + if (Context.canAssignObjCInterfaces(FromObjCPtr, ToObjCPtr, + IsHiddenCallback(*this))) { // Okay: this is some kind of implicit downcast of Objective-C // interfaces, which is permitted. However, we're going to // complain about it. @@ -3769,10 +3771,10 @@ const ObjCObjectPointerType* FromObjCPtr2 = FromType2->getAs(); if (FromObjCPtr1 && FromObjCPtr2) { - bool AssignLeft = S.Context.canAssignObjCInterfaces(FromObjCPtr1, - FromObjCPtr2); - bool AssignRight = S.Context.canAssignObjCInterfaces(FromObjCPtr2, - FromObjCPtr1); + bool AssignLeft = S.Context.canAssignObjCInterfaces( + FromObjCPtr1, FromObjCPtr2, Sema::IsHiddenCallback(S)); + bool AssignRight = S.Context.canAssignObjCInterfaces( + FromObjCPtr2, FromObjCPtr1, Sema::IsHiddenCallback(S)); if (AssignLeft != AssignRight) { return AssignLeft? ImplicitConversionSequence::Better : ImplicitConversionSequence::Worse; @@ -4039,14 +4041,14 @@ // that we do for C++ pointers to class types. However, we employ the // Objective-C pseudo-subtyping relationship used for assignment of // Objective-C pointer types. - bool FromAssignLeft - = S.Context.canAssignObjCInterfaces(FromPtr1, FromPtr2); - bool FromAssignRight - = S.Context.canAssignObjCInterfaces(FromPtr2, FromPtr1); - bool ToAssignLeft - = S.Context.canAssignObjCInterfaces(ToPtr1, ToPtr2); - bool ToAssignRight - = S.Context.canAssignObjCInterfaces(ToPtr2, ToPtr1); + bool FromAssignLeft = S.Context.canAssignObjCInterfaces( + FromPtr1, FromPtr2, Sema::IsHiddenCallback(S)); + bool FromAssignRight = S.Context.canAssignObjCInterfaces( + FromPtr2, FromPtr1, Sema::IsHiddenCallback(S)); + bool ToAssignLeft = S.Context.canAssignObjCInterfaces( + ToPtr1, ToPtr2, Sema::IsHiddenCallback(S)); + bool ToAssignRight = S.Context.canAssignObjCInterfaces( + ToPtr2, ToPtr1, Sema::IsHiddenCallback(S)); // A conversion to an a non-id object pointer type or qualified 'id' // type is better than a conversion to 'id'. @@ -4222,7 +4224,8 @@ DerivedToBase = true; else if (UnqualT1->isObjCObjectOrInterfaceType() && UnqualT2->isObjCObjectOrInterfaceType() && - Context.canBindObjCObjectType(UnqualT1, UnqualT2)) + Context.canBindObjCObjectType(UnqualT1, UnqualT2, + IsHiddenCallback(*this))) ObjCConversion = true; else if (UnqualT2->isFunctionType() && IsFunctionConversion(UnqualT2, UnqualT1, ConvertedT2)) Index: lib/Sema/SemaPseudoObject.cpp =================================================================== --- lib/Sema/SemaPseudoObject.cpp +++ lib/Sema/SemaPseudoObject.cpp @@ -660,7 +660,7 @@ PropertyName[0] = front; IdentifierInfo *AltMember = &S.PP.getIdentifierTable().get(PropertyName); if (ObjCPropertyDecl *prop1 = IFace->FindPropertyDeclaration( - AltMember, prop->getQueryKind())) + AltMember, prop->getQueryKind(), Sema::IsHiddenCallback(S))) if (prop != prop1 && (prop1->getSetterMethodDecl() == setter)) { S.Diag(RefExpr->getExprLoc(), diag::err_property_setter_ambiguous_use) << prop << prop1 << setter->getSelector(); Index: lib/Sema/SemaStmt.cpp =================================================================== --- lib/Sema/SemaStmt.cpp +++ lib/Sema/SemaStmt.cpp @@ -1750,8 +1750,9 @@ // If there's an interface, look in both the public and private APIs. if (iface) { - method = iface->lookupInstanceMethod(selector); - if (!method) method = iface->lookupPrivateMethod(selector); + method = iface->lookupInstanceMethod(selector, IsHiddenCallback(*this)); + if (!method) + method = iface->lookupPrivateMethod(selector, IsHiddenCallback(*this)); } // Also check protocol qualifiers. Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -921,7 +921,8 @@ // parameter bound is 'id'. if (boundObjC->isObjCIdType()) continue; - } else if (S.Context.canAssignObjCInterfaces(boundObjC, typeArgObjC)) { + } else if (S.Context.canAssignObjCInterfaces(boundObjC, typeArgObjC, + Sema::IsHiddenCallback(S))) { // Otherwise, we follow the assignability rules. continue; } Index: lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp +++ lib/StaticAnalyzer/Checkers/DirectIvarAssignment.cpp @@ -186,9 +186,9 @@ return; ObjCMethodDecl *GetterMethod = - InterfD->getInstanceMethod(PD->getGetterName()); + InterfD->getInstanceMethod(PD->getGetterName(), AllDeclsVisible); ObjCMethodDecl *SetterMethod = - InterfD->getInstanceMethod(PD->getSetterName()); + InterfD->getInstanceMethod(PD->getSetterName(), AllDeclsVisible); if (SetterMethod && SetterMethod->getCanonicalDecl() == MD) return; Index: lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp +++ lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp @@ -668,9 +668,9 @@ const ObjCInterfaceDecl *InterfaceDecl = TrackedType->getInterfaceDecl(); // The method might not be found. Selector Sel = MessageExpr->getSelector(); - Method = InterfaceDecl->lookupInstanceMethod(Sel); + Method = InterfaceDecl->lookupInstanceMethod(Sel, AllDeclsVisible); if (!Method) - Method = InterfaceDecl->lookupClassMethod(Sel); + Method = InterfaceDecl->lookupClassMethod(Sel, AllDeclsVisible); } } Index: lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -430,8 +430,8 @@ const ObjCMethodDecl *InterfD = *I; // Get the corresponding method in the @implementation. - const ObjCMethodDecl *D = ImplD->getMethod(InterfD->getSelector(), - InterfD->isInstanceMethod()); + const ObjCMethodDecl *D = ImplD->getMethod( + InterfD->getSelector(), InterfD->isInstanceMethod(), AllDeclsVisible); if (D && D->hasBody()) { AtImplementationContainsAtLeastOnePartialInvalidationMethod = true; @@ -482,8 +482,8 @@ const ObjCMethodDecl *InterfD = *I; // Get the corresponding method in the @implementation. - const ObjCMethodDecl *D = ImplD->getMethod(InterfD->getSelector(), - InterfD->isInstanceMethod()); + const ObjCMethodDecl *D = ImplD->getMethod( + InterfD->getSelector(), InterfD->isInstanceMethod(), AllDeclsVisible); if (D && D->hasBody()) { AtImplementationContainsAtLeastOneInvalidationMethod = true; Index: lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp +++ lib/StaticAnalyzer/Checkers/ObjCPropertyChecker.cpp @@ -62,7 +62,7 @@ ImplD = CatD->getClassInterface()->getImplementation(); } - if (!ImplD || ImplD->HasUserDeclaredSetterMethod(D)) + if (!ImplD || ImplD->HasUserDeclaredSetterMethod(D, AllDeclsVisible)) return; SmallString<128> Str; Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -1533,7 +1533,7 @@ Selector S = Msg.getSelector(); const ObjCMethodDecl *Method = Msg.getDecl(); if (!Method && ReceiverClass) - Method = ReceiverClass->getInstanceMethod(S); + Method = ReceiverClass->getInstanceMethod(S, AllDeclsVisible); return getMethodSummary(S, ReceiverClass, Method, Msg.getResultType(), ObjCMethodSummaries); Index: lib/StaticAnalyzer/Core/CallEvent.cpp =================================================================== --- lib/StaticAnalyzer/Core/CallEvent.cpp +++ lib/StaticAnalyzer/Core/CallEvent.cpp @@ -872,7 +872,7 @@ // the selector. ObjCMethodDecl *D = nullptr; while (true) { - D = IDecl->lookupMethod(Sel, true); + D = IDecl->lookupMethod(Sel, true, AllDeclsVisible); // Cannot find a public definition. if (!D) @@ -1026,7 +1026,7 @@ // Query lookupPrivateMethod() if the cache does not hit. if (!Val.hasValue()) { - Val = IDecl->lookupPrivateMethod(Sel); + Val = IDecl->lookupPrivateMethod(Sel, AllDeclsVisible); // If the method is a property accessor, we should try to "inline" it // even if we don't actually have an implementation. @@ -1048,13 +1048,14 @@ auto *ID = CompileTimeMD->getClassInterface(); for (auto *CatDecl : ID->visible_extensions()) { Val = CatDecl->getMethod(Sel, - CompileTimeMD->isInstanceMethod()); + CompileTimeMD->isInstanceMethod(), + AllDeclsVisible); if (*Val) break; } } if (!*Val) - Val = IDecl->lookupInstanceMethod(Sel); + Val = IDecl->lookupInstanceMethod(Sel, AllDeclsVisible); } } @@ -1071,7 +1072,8 @@ // class name. if (ObjCInterfaceDecl *IDecl = E->getReceiverInterface()) { // Find/Return the method implementation. - return RuntimeDefinition(IDecl->lookupPrivateClassMethod(Sel)); + return RuntimeDefinition( + IDecl->lookupPrivateClassMethod(Sel, AllDeclsVisible)); } } Index: test/Modules/interface-visibility.m =================================================================== --- test/Modules/interface-visibility.m +++ test/Modules/interface-visibility.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -fmodules -fobjc-arc -x objective-c-module-map %s -fmodule-name=Foo -verify + +module Foo {} + +#pragma clang module contents +#pragma clang module begin Foo + +// expected-no-diagnostics + +#pragma clang module build Foundation +module Foundation {} +#pragma clang module contents +#pragma clang module begin Foundation +@interface NSIndexSet +@end +#pragma clang module end +#pragma clang module endbuild + +#pragma clang module import Foundation + +@interface NSIndexSet (Testing) +- (int)foo; +@end + +static inline int test(NSIndexSet *obj) { + return [obj foo]; +} + +#pragma clang module end Index: tools/libclang/CIndex.cpp =================================================================== --- tools/libclang/CIndex.cpp +++ tools/libclang/CIndex.cpp @@ -1087,7 +1087,7 @@ IdentifierInfo *PropertyId = PD->getIdentifier(); ObjCPropertyDecl *prevDecl = ObjCPropertyDecl::findPropertyDecl(cast(ID), PropertyId, - PD->getQueryKind()); + PD->getQueryKind(), AllDeclsVisible); if (!prevDecl) return false; @@ -5949,8 +5949,9 @@ if (const ObjCInterfaceDecl *Class = dyn_cast(Method->getDeclContext())) if (ObjCImplementationDecl *ClassImpl = Class->getImplementation()) - if (ObjCMethodDecl *Def = ClassImpl->getMethod(Method->getSelector(), - Method->isInstanceMethod())) + if (ObjCMethodDecl *Def = ClassImpl->getMethod( + Method->getSelector(), Method->isInstanceMethod(), + AllDeclsVisible)) if (Def->isThisDeclarationADefinition()) return MakeCXCursor(Def, TU);