<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 10, 2017 at 5:59 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On 10 January 2017 at 17:57, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On 10 January 2017 at 16:48, Manman Ren via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mren<br>
Date: Tue Jan 10 18:48:19 2017<br>
New Revision: 291628<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=291628&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=291628&view=rev</a><br>
Log:<br>
Module: Do not create Implicit ImportDecl for module X if we<br>
 are building an implemenation of module X.<br></blockquote><div><br></div></span><div>Hmm. We do actually have an include mapping to a module header in this case. Perhaps it would be better to create a faithful AST representation and handle this in CodeGen instead -- we should not add any link flags when an implementation TU of a module imports a header of that same module.</div></div></div></div></blockquote><div><br></div></span><div>It's worth pointing out that the C++ modules TS allows a modular import of a module interface into an implementation unit of that module, so the current approach won't work for that case, but filtering these imports out in CodeGen would work.</div></div></div></div></blockquote><div><br></div><div>Makes sense. I will commit a follow-up patch.</div><div><br></div><div>Manman </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div><span style="color:rgb(80,0,80)"> </span></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_-1236040596202426969h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This fixes a regression caused by r280409.<br>
rdar://problem/29930553<br>
<br>
Added:<br>
    cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/<br>
    cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/foo.h<br>
    cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.m<wbr>odulemap<br>
    cfe/trunk/test/Modules/module-<wbr>impl-with-link.c<br>
Modified:<br>
    cfe/trunk/include/clang/Sema/S<wbr>ema.h<br>
    cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p<br>
<br>
Modified: cfe/trunk/include/clang/Sema/S<wbr>ema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=291628&r1=291627&r2=291628&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Sema/Sema.h?rev=291628&r1=2916<wbr>27&r2=291628&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/S<wbr>ema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/S<wbr>ema.h Tue Jan 10 18:48:19 2017<br>
@@ -1905,7 +1905,8 @@ public:<br>
   /// \brief The parser has processed a module import translated from a<br>
   /// #include or similar preprocessing directive.<br>
   void ActOnModuleInclude(SourceLocat<wbr>ion DirectiveLoc, Module *Mod);<br>
-  void BuildModuleInclude(SourceLocat<wbr>ion DirectiveLoc, Module *Mod);<br>
+  void BuildModuleInclude(SourceLocat<wbr>ion DirectiveLoc, Module *Mod,<br>
+                          bool NoImport);<br>
<br>
   /// \brief The parsed has entered a submodule.<br>
   void ActOnModuleBegin(SourceLocatio<wbr>n DirectiveLoc, Module *Mod);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=291628&r1=291627&r2=291628&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Sema/SemaD<wbr>ecl.cpp?rev=291628&r1=291627&r<wbr>2=291628&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cp<wbr>p Tue Jan 10 18:48:19 2017<br>
@@ -15652,10 +15652,11 @@ DeclResult Sema::ActOnModuleImport(Sourc<br>
<br>
 void Sema::ActOnModuleInclude(Sourc<wbr>eLocation DirectiveLoc, Module *Mod) {<br>
   checkModuleImportContext(*thi<wbr>s, Mod, DirectiveLoc, CurContext, true);<br>
-  BuildModuleInclude(DirectiveLo<wbr>c, Mod);<br>
+  BuildModuleInclude(DirectiveLo<wbr>c, Mod, false/*NoImport*/);<br>
 }<br>
<br>
-void Sema::BuildModuleInclude(Sourc<wbr>eLocation DirectiveLoc, Module *Mod) {<br>
+void Sema::BuildModuleInclude(Sourc<wbr>eLocation DirectiveLoc, Module *Mod,<br>
+                              bool NoImport) {<br>
   // Determine whether we're in the #include buffer for a module. The #includes<br>
   // in that buffer do not qualify as module imports; they're just an<br>
   // implementation detail of us building the module.<br>
@@ -15665,7 +15666,7 @@ void Sema::BuildModuleInclude(Sourc<wbr>eLoca<br>
       TUKind == TU_Module &&<br>
       getSourceManager().isWrittenI<wbr>nMainFile(DirectiveLoc);<br>
<br>
-  bool ShouldAddImport = !IsInModuleIncludes;<br>
+  bool ShouldAddImport = !IsInModuleIncludes && !NoImport;<br>
<br>
   // If this module import was due to an inclusion directive, create an<br>
   // implicit import declaration to capture it in the AST.<br>
@@ -15713,7 +15714,11 @@ void Sema::ActOnModuleEnd(SourceLoc<wbr>ation<br>
   assert(File != getSourceManager().getMainFile<wbr>ID() &&<br>
          "end of submodule in main source file");<br>
   SourceLocation DirectiveLoc = getSourceManager().getIncludeL<wbr>oc(File);<br>
-  BuildModuleInclude(DirectiveLo<wbr>c, Mod);<br>
+  // Do not create implicit ImportDecl if we are building the implementation<br>
+  // of a module.<br>
+  bool NoImport = Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&<br>
+                  !getLangOpts().isCompilingModu<wbr>le();<br>
+  BuildModuleInclude(DirectiveLo<wbr>c, Mod, NoImport);<br>
 }<br>
<br>
 void Sema::createImplicitModuleImpo<wbr>rtForErrorRecovery(SourceLocat<wbr>ion Loc,<br>
<br>
Added: cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/foo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module-impl-with-link/foo.h?rev=291628&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Modules/I<wbr>nputs/module-impl-with-link/fo<wbr>o.h?rev=291628&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/foo.h (added)<br>
+++ cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/foo.h Tue Jan 10 18:48:19 2017<br>
@@ -0,0 +1 @@<br>
+//empty<br>
<br>
Added: cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.m<wbr>odulemap<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module-impl-with-link/module.modulemap?rev=291628&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Modules/I<wbr>nputs/module-impl-with-link/mo<wbr>dule.modulemap?rev=291628&view<wbr>=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.m<wbr>odulemap (added)<br>
+++ cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.m<wbr>odulemap Tue Jan 10 18:48:19 2017<br>
@@ -0,0 +1,4 @@<br>
+module Clib {<br>
+  header "foo.h"<br>
+  link "Clib"<br>
+}<br>
<br>
Added: cfe/trunk/test/Modules/module-<wbr>impl-with-link.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module-impl-with-link.c?rev=291628&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Modules/m<wbr>odule-impl-with-link.c?rev=291<wbr>628&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Modules/module-<wbr>impl-with-link.c (added)<br>
+++ cfe/trunk/test/Modules/module-<wbr>impl-with-link.c Tue Jan 10 18:48:19 2017<br>
@@ -0,0 +1,7 @@<br>
+// RUN: rm -rf %t<br>
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fmodule-name=Clib %s -I %S/Inputs/module-impl-with-lin<wbr>k -emit-llvm -o -<br>
+#include "foo.h"<br>
+// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[LINK_OPTIONS:[0-9]+]]}<br>
+// Make sure we don't generate linker option for module Clib since this TU is<br>
+// an implementation of Clib.<br>
+// CHECK: ![[LINK_OPTIONS]] = !{}<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>