]> granicus.if.org Git - clang/commitdiff
Add protocol redefinition to the current scope/context
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Sat, 30 Jun 2018 00:49:27 +0000 (00:49 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Sat, 30 Jun 2018 00:49:27 +0000 (00:49 +0000)
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

Differential Revision: https://reviews.llvm.org/D47297

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336031 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp
test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h [new file with mode: 0644]
test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap [new file with mode: 0644]
test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h [new file with mode: 0644]
test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap [new file with mode: 0644]
test/Modules/protocol-redefinition.m [new file with mode: 0644]

index d7544ecfaf79c16a9ae6b7cc66142a04e7f4257c..6809b48dc8a481eb9d9c6be42bfcf2339b1e05b9 100644 (file)
@@ -1210,6 +1210,11 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
     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) {
diff --git a/test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h b/test/Modules/Inputs/protocol-redefinition/Base.framework/Headers/Base.h
new file mode 100644 (file)
index 0000000..e3fe33c
--- /dev/null
@@ -0,0 +1,3 @@
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
diff --git a/test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap b/test/Modules/Inputs/protocol-redefinition/Base.framework/Modules/module.modulemap
new file mode 100644 (file)
index 0000000..0366bb4
--- /dev/null
@@ -0,0 +1,4 @@
+framework module Base {
+  header "Base.h"
+  export *
+}
\ No newline at end of file
diff --git a/test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h b/test/Modules/Inputs/protocol-redefinition/Kit.framework/Headers/Kit.h
new file mode 100644 (file)
index 0000000..93384c2
--- /dev/null
@@ -0,0 +1,6 @@
+#import <Base/Base.h>
+
+// REDECLARATION
+@protocol Foo
+- (void)someMethodOnFoo;
+@end
diff --git a/test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap b/test/Modules/Inputs/protocol-redefinition/Kit.framework/Modules/module.modulemap
new file mode 100644 (file)
index 0000000..2b790f4
--- /dev/null
@@ -0,0 +1,4 @@
+framework module Kit {
+  header "Kit.h"
+  export *
+}
\ No newline at end of file
diff --git a/test/Modules/protocol-redefinition.m b/test/Modules/protocol-redefinition.m
new file mode 100644 (file)
index 0000000..85a957b
--- /dev/null
@@ -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;