r259859 - Don't synthesize an ImportDecl for a module named in -fmodule-implementation-of

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 17:10:05 PST 2016


Author: benlangmuir
Date: Thu Feb  4 19:10:05 2016
New Revision: 259859

URL: http://llvm.org/viewvc/llvm-project?rev=259859&view=rev
Log:
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

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Modules/Inputs/category_right.h
    cfe/trunk/test/Modules/objc-categories.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=259859&r1=259858&r2=259859&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Feb  4 19:10:05 2016
@@ -14783,9 +14783,15 @@ void Sema::ActOnModuleInclude(SourceLoca
       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,

Modified: cfe/trunk/test/Modules/Inputs/category_right.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/category_right.h?rev=259859&r1=259858&r2=259859&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/category_right.h (original)
+++ cfe/trunk/test/Modules/Inputs/category_right.h Thu Feb  4 19:10:05 2016
@@ -1,4 +1,5 @@
 @import category_top;
+#import "category_right_sub.h"
 
 @interface Foo(Right1)
 -(void)right1;

Modified: cfe/trunk/test/Modules/objc-categories.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/objc-categories.m?rev=259859&r1=259858&r2=259859&view=diff
==============================================================================
--- cfe/trunk/test/Modules/objc-categories.m (original)
+++ cfe/trunk/test/Modules/objc-categories.m Thu Feb  4 19:10:05 2016
@@ -9,7 +9,7 @@
 @import category_bottom;
 
 // expected-note at Inputs/category_left.h:14 {{previous definition}}
-// expected-warning at Inputs/category_right.h:11 {{duplicate definition of category}}
+// expected-warning at Inputs/category_right.h:12 {{duplicate definition of category}}
 // expected-note at Inputs/category_top.h:1 {{receiver is instance of class declared here}}
 
 @interface Foo(Source)




More information about the cfe-commits mailing list