r331063 - [Modules][ObjC] ASTReader should add protocols for class extensions

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 27 11:01:23 PDT 2018


Author: bruno
Date: Fri Apr 27 11:01:23 2018
New Revision: 331063

URL: http://llvm.org/viewvc/llvm-project?rev=331063&view=rev
Log:
[Modules][ObjC] ASTReader should add protocols for class extensions

During deserialization clang is currently missing the merging of
protocols into the canonical interface for the class extension.

This merging only currently happens during parsing and should also
be considered during deserialization.

rdar://problem/38724303

Added:
    cfe/trunk/test/Modules/Inputs/class-extension/
    cfe/trunk/test/Modules/Inputs/class-extension/a-private.h
    cfe/trunk/test/Modules/Inputs/class-extension/a-proto.h
    cfe/trunk/test/Modules/Inputs/class-extension/a.h
    cfe/trunk/test/Modules/Inputs/class-extension/module.modulemap
    cfe/trunk/test/Modules/class-extension-protocol.m
Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=331063&r1=331062&r2=331063&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Fri Apr 27 11:01:23 2018
@@ -1205,6 +1205,12 @@ void ASTDeclReader::VisitObjCCategoryDec
     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) {

Added: cfe/trunk/test/Modules/Inputs/class-extension/a-private.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/class-extension/a-private.h?rev=331063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/class-extension/a-private.h (added)
+++ cfe/trunk/test/Modules/Inputs/class-extension/a-private.h Fri Apr 27 11:01:23 2018
@@ -0,0 +1,5 @@
+#import "a.h"
+#import "a-proto.h"
+
+ at interface A () <AProto>
+ at end

Added: cfe/trunk/test/Modules/Inputs/class-extension/a-proto.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/class-extension/a-proto.h?rev=331063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/class-extension/a-proto.h (added)
+++ cfe/trunk/test/Modules/Inputs/class-extension/a-proto.h Fri Apr 27 11:01:23 2018
@@ -0,0 +1,7 @@
+ at protocol NSObject
+ at end
+
+ at protocol AProto <NSObject>
+ at property (nonatomic, readwrite, assign) int p0;
+ at property (nonatomic, readwrite, assign) int p1;
+ at end

Added: cfe/trunk/test/Modules/Inputs/class-extension/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/class-extension/a.h?rev=331063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/class-extension/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/class-extension/a.h Fri Apr 27 11:01:23 2018
@@ -0,0 +1,5 @@
+ at interface NSObject
+ at end
+
+ at interface A : NSObject
+ at end

Added: cfe/trunk/test/Modules/Inputs/class-extension/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/class-extension/module.modulemap?rev=331063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/class-extension/module.modulemap (added)
+++ cfe/trunk/test/Modules/Inputs/class-extension/module.modulemap Fri Apr 27 11:01:23 2018
@@ -0,0 +1,11 @@
+
+module A {
+  header "a.h"
+  header "a-proto.h"
+  export *
+}
+
+module AP {
+  header "a-private.h"
+  export *
+}

Added: cfe/trunk/test/Modules/class-extension-protocol.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/class-extension-protocol.m?rev=331063&view=auto
==============================================================================
--- cfe/trunk/test/Modules/class-extension-protocol.m (added)
+++ cfe/trunk/test/Modules/class-extension-protocol.m Fri Apr 27 11:01:23 2018
@@ -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;
+}




More information about the cfe-commits mailing list