@@ -5971,9 +5971,15 @@ struct OrderDecls {
59715971
59725972Identifier ExtensionDecl::getObjCCategoryName () const {
59735973 // Could it be an imported category?
5974- if (!hasClangNode ())
5975- // Nope, not imported.
5974+ if (!hasClangNode ()) {
5975+ // Nope, not imported. Is it an @implementation extension?
5976+ auto attr = getAttrs ()
5977+ .getAttribute <ObjCImplementationAttr>(/* AllowInvalid=*/ true );
5978+ if (attr && !attr->isCategoryNameInvalid ())
5979+ return attr->CategoryName ;
5980+
59765981 return Identifier ();
5982+ }
59775983
59785984 auto category = dyn_cast<clang::ObjCCategoryDecl>(getClangDecl ());
59795985 if (!category)
@@ -6014,6 +6020,12 @@ constructResult(const llvm::TinyPtrVector<Decl *> &interfaces,
60146020 return ObjCInterfaceAndImplementation (interfaces, impls.front ());
60156021}
60166022
6023+ static bool isCategoryNameValid (ExtensionDecl *ext) {
6024+ auto attr = ext->getAttrs ()
6025+ .getAttribute <ObjCImplementationAttr>(/* AllowInvalid=*/ true );
6026+ return attr && !attr->isCategoryNameInvalid ();
6027+ }
6028+
60176029static ObjCInterfaceAndImplementation
60186030findContextInterfaceAndImplementation (DeclContext *dc) {
60196031 if (!dc)
@@ -6028,16 +6040,11 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
60286040 Identifier categoryName;
60296041
60306042 if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
6031- if (ext->hasClangNode ()) {
6032- // This is either an interface, or it's not objcImpl at all.
6033- categoryName = ext->getObjCCategoryName ();
6034- } else {
6035- // This is either the implementation, or it's not objcImpl at all.
6036- if (auto name = ext->getCategoryNameForObjCImplementation ())
6037- categoryName = *name;
6038- else
6039- return {};
6040- }
6043+ assert (ext);
6044+ if (!ext->hasClangNode () && !isCategoryNameValid (ext))
6045+ return {};
6046+
6047+ categoryName = ext->getObjCCategoryName ();
60416048 } else {
60426049 // Must be an imported class. Look for its main implementation.
60436050 assert (isa_and_nonnull<ClassDecl>(dc));
@@ -6051,7 +6058,8 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
60516058 llvm::TinyPtrVector<Decl *> implDecls;
60526059 for (ExtensionDecl *ext : classDecl->getExtensions ()) {
60536060 if (ext->isObjCImplementation ()
6054- && ext->getCategoryNameForObjCImplementation () == categoryName)
6061+ && ext->getObjCCategoryName () == categoryName
6062+ && isCategoryNameValid (ext))
60556063 implDecls.push_back (ext);
60566064 }
60576065
0 commit comments