From ef787f73ca9173268ee1a84abaf6e70e1c44b40a Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Fri, 5 Feb 2016 01:10:05 +0000 Subject: [PATCH] Don't synthesize an ImportDecl for a module named in -fmodule-implementation-of When building a PCH with modules enabled this import would assert in the ASTWriter and (if assertions were disabled) sometimes crash the compiler that loaded the resulting PCH when trying to lookup the submodule ID. rdar://problem/24137448 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 8 +++++++- test/Modules/Inputs/category_right.h | 1 + test/Modules/objc-categories.m | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 510e70aedb..d26e5e1883 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -14783,9 +14783,15 @@ void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { TUKind == TU_Module && getSourceManager().isWrittenInMainFile(DirectiveLoc); + // Similarly, if this module is specified by -fmodule-implementation-of + // don't actually synthesize an illegal module import. + bool ShouldAddImport = !IsInModuleIncludes && + (getLangOpts().ImplementationOfModule.empty() || + getLangOpts().ImplementationOfModule != Mod->getTopLevelModuleName()); + // If this module import was due to an inclusion directive, create an // implicit import declaration to capture it in the AST. - if (!IsInModuleIncludes) { + if (ShouldAddImport) { TranslationUnitDecl *TU = getASTContext().getTranslationUnitDecl(); ImportDecl *ImportD = ImportDecl::CreateImplicit(getASTContext(), TU, DirectiveLoc, Mod, diff --git a/test/Modules/Inputs/category_right.h b/test/Modules/Inputs/category_right.h index 3c83624c76..d8dedf888d 100644 --- a/test/Modules/Inputs/category_right.h +++ b/test/Modules/Inputs/category_right.h @@ -1,4 +1,5 @@ @import category_top; +#import "category_right_sub.h" @interface Foo(Right1) -(void)right1; diff --git a/test/Modules/objc-categories.m b/test/Modules/objc-categories.m index e8549fabb5..42baf352fb 100644 --- a/test/Modules/objc-categories.m +++ b/test/Modules/objc-categories.m @@ -9,7 +9,7 @@ @import category_bottom; // expected-note@Inputs/category_left.h:14 {{previous definition}} -// expected-warning@Inputs/category_right.h:11 {{duplicate definition of category}} +// expected-warning@Inputs/category_right.h:12 {{duplicate definition of category}} // expected-note@Inputs/category_top.h:1 {{receiver is instance of class declared here}} @interface Foo(Source) -- 2.50.1