bruno created this revision.
bruno added a reviewer: rsmith.

Not doing so causes the AST writter to assert since the decl in question never 
gets emitted. This is fine when modules is not used, but otherwise we need to 
serialize something other than garbage.

rdar://problem/39844933


Repository:
  rC Clang

https://reviews.llvm.org/D47297

Files:
  lib/Sema/SemaDeclObjC.cpp
  test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
  
test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
  test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
  
test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
  test/Modules/protocol-redefinition.m


Index: test/Modules/protocol-redefinition.m
===================================================================
--- /dev/null
+++ test/Modules/protocol-redefinition.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t 
-F%S/Inputs/protocol-redefinition -fsyntax-only %s -Wno-private-module -verify
+
+// expected-no-diagnostics
+
+@import Kit;
Index: 
test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
===================================================================
--- /dev/null
+++ 
test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Kit {
+  header "Kit.h"
+  export *
+}
\ No newline at end of file
Index: test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
@@ -0,0 +1,6 @@
+#import <Base/Base.h>
+
+// REDECLARATION
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
Index: 
test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
===================================================================
--- /dev/null
+++ 
test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Base {
+  header "Base.h"
+  export *
+}
\ No newline at end of file
Index: test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
@@ -0,0 +1,3 @@
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
Index: lib/Sema/SemaDeclObjC.cpp
===================================================================
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -1202,6 +1202,11 @@
     PDecl = ObjCProtocolDecl::Create(Context, CurContext, ProtocolName,
                                      ProtocolLoc, AtProtoInterfaceLoc,
                                      /*PrevDecl=*/nullptr);
+
+    // If we are using modules, add the decl to the context in order to
+    // serialize something meaningful.
+    if (getLangOpts().Modules)
+      PushOnScopeChains(PDecl, TUScope);
     PDecl->startDefinition();
   } else {
     if (PrevDecl) {


Index: test/Modules/protocol-redefinition.m
===================================================================
--- /dev/null
+++ test/Modules/protocol-redefinition.m
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F%S/Inputs/protocol-redefinition -fsyntax-only %s -Wno-private-module -verify
+
+// expected-no-diagnostics
+
+@import Kit;
Index: test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Kit {
+  header "Kit.h"
+  export *
+}
\ No newline at end of file
Index: test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
@@ -0,0 +1,6 @@
+#import <Base/Base.h>
+
+// REDECLARATION
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
Index: test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module Base {
+  header "Base.h"
+  export *
+}
\ No newline at end of file
Index: test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
===================================================================
--- /dev/null
+++ test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
@@ -0,0 +1,3 @@
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
Index: lib/Sema/SemaDeclObjC.cpp
===================================================================
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -1202,6 +1202,11 @@
     PDecl = ObjCProtocolDecl::Create(Context, CurContext, ProtocolName,
                                      ProtocolLoc, AtProtoInterfaceLoc,
                                      /*PrevDecl=*/nullptr);
+
+    // If we are using modules, add the decl to the context in order to
+    // serialize something meaningful.
+    if (getLangOpts().Modules)
+      PushOnScopeChains(PDecl, TUScope);
     PDecl->startDefinition();
   } else {
     if (PrevDecl) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to