Add protocol redefinition to the current scope/context

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

llvm-svn: 336031
This commit is contained in:
Bruno Cardoso Lopes 2018-06-30 00:49:27 +00:00
parent 7c557f804d
commit 7dcf23ed83
6 changed files with 28 additions and 0 deletions

View 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) {

View File

@ -0,0 +1,3 @@
@protocol Foo
- (void)someMethodOnFoo;
@end

View File

@ -0,0 +1,4 @@
framework module Base {
header "Base.h"
export *
}

View File

@ -0,0 +1,6 @@
#import <Base/Base.h>
// REDECLARATION
@protocol Foo
- (void)someMethodOnFoo;
@end

View File

@ -0,0 +1,4 @@
framework module Kit {
header "Kit.h"
export *
}

View File

@ -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;