From e7d67575f237a5cae8cf5cba2389567ae9fa3a6d 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 llvm-svn: 259859 --- clang/lib/Sema/SemaDecl.cpp | 8 +++++++- clang/test/Modules/Inputs/category_right.h | 1 + clang/test/Modules/objc-categories.m | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 510e70a..d26e5e1 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/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/clang/test/Modules/Inputs/category_right.h b/clang/test/Modules/Inputs/category_right.h index 3c83624..d8dedf8 100644 --- a/clang/test/Modules/Inputs/category_right.h +++ b/clang/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/clang/test/Modules/objc-categories.m b/clang/test/Modules/objc-categories.m index e8549fa..42baf35 100644 --- a/clang/test/Modules/objc-categories.m +++ b/clang/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.7.4