]> granicus.if.org Git - clang/commitdiff
Don't synthesize an ImportDecl for a module named in -fmodule-implementation-of
authorBen Langmuir <blangmuir@apple.com>
Fri, 5 Feb 2016 01:10:05 +0000 (01:10 +0000)
committerBen Langmuir <blangmuir@apple.com>
Fri, 5 Feb 2016 01:10:05 +0000 (01:10 +0000)
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
test/Modules/Inputs/category_right.h
test/Modules/objc-categories.m

index 510e70aedb134a065aa100618e46731fbbddd71a..d26e5e188306f87e26ca54b565e4bf3af5828d58 100644 (file)
@@ -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,
index 3c83624c761654e579715a0a11f2f0d492192f01..d8dedf888d15a86f29885960d13c7a25eae378a5 100644 (file)
@@ -1,4 +1,5 @@
 @import category_top;
+#import "category_right_sub.h"
 
 @interface Foo(Right1)
 -(void)right1;
index e8549fabb50ee1b00ebf4a990f224ca01a928b3e..42baf352fbf591cdb31bdcd11992330312a9fc4b 100644 (file)
@@ -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)