]> granicus.if.org Git - clang/commitdiff
Module: Do not create Implicit ImportDecl for module X if we
authorManman Ren <manman.ren@gmail.com>
Wed, 11 Jan 2017 00:48:19 +0000 (00:48 +0000)
committerManman Ren <manman.ren@gmail.com>
Wed, 11 Jan 2017 00:48:19 +0000 (00:48 +0000)
 are building an implemenation of module X.

This fixes a regression caused by r280409.
rdar://problem/29930553

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291628 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
test/Modules/Inputs/module-impl-with-link/foo.h [new file with mode: 0644]
test/Modules/Inputs/module-impl-with-link/module.modulemap [new file with mode: 0644]
test/Modules/module-impl-with-link.c [new file with mode: 0644]

index 01141b32f7450d576110af9531b2b2e5a752fb52..943bbca7fdf16877aeb38842144badf664636599 100644 (file)
@@ -1905,7 +1905,8 @@ public:
   /// \brief The parser has processed a module import translated from a
   /// #include or similar preprocessing directive.
   void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
-  void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod);
+  void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod,
+                          bool NoImport);
 
   /// \brief The parsed has entered a submodule.
   void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);
index cdc9882d14ec25602f3b9ece2ea131a40ff6e49b..1fa131f627691d6681a095ef1f7bdf1376293028 100644 (file)
@@ -15652,10 +15652,11 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
 
 void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
   checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true);
-  BuildModuleInclude(DirectiveLoc, Mod);
+  BuildModuleInclude(DirectiveLoc, Mod, false/*NoImport*/);
 }
 
-void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
+void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod,
+                              bool NoImport) {
   // Determine whether we're in the #include buffer for a module. The #includes
   // in that buffer do not qualify as module imports; they're just an
   // implementation detail of us building the module.
@@ -15665,7 +15666,7 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
       TUKind == TU_Module &&
       getSourceManager().isWrittenInMainFile(DirectiveLoc);
 
-  bool ShouldAddImport = !IsInModuleIncludes;
+  bool ShouldAddImport = !IsInModuleIncludes && !NoImport;
 
   // If this module import was due to an inclusion directive, create an
   // implicit import declaration to capture it in the AST.
@@ -15713,7 +15714,11 @@ void Sema::ActOnModuleEnd(SourceLocation EofLoc, Module *Mod) {
   assert(File != getSourceManager().getMainFileID() &&
          "end of submodule in main source file");
   SourceLocation DirectiveLoc = getSourceManager().getIncludeLoc(File);
-  BuildModuleInclude(DirectiveLoc, Mod);
+  // Do not create implicit ImportDecl if we are building the implementation
+  // of a module.
+  bool NoImport = Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+                  !getLangOpts().isCompilingModule();
+  BuildModuleInclude(DirectiveLoc, Mod, NoImport);
 }
 
 void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc,
diff --git a/test/Modules/Inputs/module-impl-with-link/foo.h b/test/Modules/Inputs/module-impl-with-link/foo.h
new file mode 100644 (file)
index 0000000..90fe1bc
--- /dev/null
@@ -0,0 +1 @@
+//empty
diff --git a/test/Modules/Inputs/module-impl-with-link/module.modulemap b/test/Modules/Inputs/module-impl-with-link/module.modulemap
new file mode 100644 (file)
index 0000000..b85f8b6
--- /dev/null
@@ -0,0 +1,4 @@
+module Clib {
+  header "foo.h"
+  link "Clib"
+}
diff --git a/test/Modules/module-impl-with-link.c b/test/Modules/module-impl-with-link.c
new file mode 100644 (file)
index 0000000..5e5ca83
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fmodule-name=Clib %s -I %S/Inputs/module-impl-with-link -emit-llvm -o -
+#include "foo.h"
+// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[LINK_OPTIONS:[0-9]+]]}
+// Make sure we don't generate linker option for module Clib since this TU is
+// an implementation of Clib.
+// CHECK: ![[LINK_OPTIONS]] = !{}