diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 7a5d22c00f8f..046c699a224f 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -1205,6 +1205,12 @@ void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { ProtoLocs.push_back(ReadSourceLocation()); CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), Reader.getContext()); + + // Protocols in the class extension belong to the class. + if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) + CD->ClassInterface->mergeClassExtensionProtocolList( + (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, + Reader.getContext()); } void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { diff --git a/clang/test/Modules/Inputs/class-extension/a-private.h b/clang/test/Modules/Inputs/class-extension/a-private.h new file mode 100644 index 000000000000..e35402ac18ad --- /dev/null +++ b/clang/test/Modules/Inputs/class-extension/a-private.h @@ -0,0 +1,5 @@ +#import "a.h" +#import "a-proto.h" + +@interface A () +@end diff --git a/clang/test/Modules/Inputs/class-extension/a-proto.h b/clang/test/Modules/Inputs/class-extension/a-proto.h new file mode 100644 index 000000000000..32043ec2498f --- /dev/null +++ b/clang/test/Modules/Inputs/class-extension/a-proto.h @@ -0,0 +1,7 @@ +@protocol NSObject +@end + +@protocol AProto +@property (nonatomic, readwrite, assign) int p0; +@property (nonatomic, readwrite, assign) int p1; +@end diff --git a/clang/test/Modules/Inputs/class-extension/a.h b/clang/test/Modules/Inputs/class-extension/a.h new file mode 100644 index 000000000000..28c409c33774 --- /dev/null +++ b/clang/test/Modules/Inputs/class-extension/a.h @@ -0,0 +1,5 @@ +@interface NSObject +@end + +@interface A : NSObject +@end diff --git a/clang/test/Modules/Inputs/class-extension/module.modulemap b/clang/test/Modules/Inputs/class-extension/module.modulemap new file mode 100644 index 000000000000..5c30bc57e46c --- /dev/null +++ b/clang/test/Modules/Inputs/class-extension/module.modulemap @@ -0,0 +1,11 @@ + +module A { + header "a.h" + header "a-proto.h" + export * +} + +module AP { + header "a-private.h" + export * +} diff --git a/clang/test/Modules/class-extension-protocol.m b/clang/test/Modules/class-extension-protocol.m new file mode 100644 index 000000000000..752e4e129d29 --- /dev/null +++ b/clang/test/Modules/class-extension-protocol.m @@ -0,0 +1,9 @@ +// RUN: rm -rf %t.cache +// RUN: %clang_cc1 %s -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.cache -I%S/Inputs/class-extension -verify +// expected-no-diagnostics + +#import "a-private.h" + +int foo(A *X) { + return X.p0 + X.p1; +}