@@ -5971,9 +5971,15 @@ struct OrderDecls {
5971
5971
5972
5972
Identifier ExtensionDecl::getObjCCategoryName () const {
5973
5973
// 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
+
5976
5981
return Identifier ();
5982
+ }
5977
5983
5978
5984
auto category = dyn_cast<clang::ObjCCategoryDecl>(getClangDecl ());
5979
5985
if (!category)
@@ -6014,6 +6020,12 @@ constructResult(const llvm::TinyPtrVector<Decl *> &interfaces,
6014
6020
return ObjCInterfaceAndImplementation (interfaces, impls.front ());
6015
6021
}
6016
6022
6023
+ static bool isCategoryNameValid (ExtensionDecl *ext) {
6024
+ auto attr = ext->getAttrs ()
6025
+ .getAttribute <ObjCImplementationAttr>(/* AllowInvalid=*/ true );
6026
+ return attr && !attr->isCategoryNameInvalid ();
6027
+ }
6028
+
6017
6029
static ObjCInterfaceAndImplementation
6018
6030
findContextInterfaceAndImplementation (DeclContext *dc) {
6019
6031
if (!dc)
@@ -6028,16 +6040,11 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
6028
6040
Identifier categoryName;
6029
6041
6030
6042
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 ();
6041
6048
} else {
6042
6049
// Must be an imported class. Look for its main implementation.
6043
6050
assert (isa_and_nonnull<ClassDecl>(dc));
@@ -6051,7 +6058,8 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
6051
6058
llvm::TinyPtrVector<Decl *> implDecls;
6052
6059
for (ExtensionDecl *ext : classDecl->getExtensions ()) {
6053
6060
if (ext->isObjCImplementation ()
6054
- && ext->getCategoryNameForObjCImplementation () == categoryName)
6061
+ && ext->getObjCCategoryName () == categoryName
6062
+ && isCategoryNameValid (ext))
6055
6063
implDecls.push_back (ext);
6056
6064
}
6057
6065
0 commit comments