<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">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-<wbr>project?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><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><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.<wbr>modulemap<br>
cfe/trunk/test/Modules/module-<wbr>impl-with-link.c<br>
Modified:<br>
cfe/trunk/include/clang/Sema/<wbr>Sema.h<br>
cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<br>
<br>
Modified: cfe/trunk/include/clang/Sema/<wbr>Sema.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-<wbr>project/cfe/trunk/include/<wbr>clang/Sema/Sema.h?rev=291628&<wbr>r1=291627&r2=291628&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Sema/<wbr>Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/<wbr>Sema.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(<wbr>SourceLocation DirectiveLoc, Module *Mod);<br>
- void BuildModuleInclude(<wbr>SourceLocation DirectiveLoc, Module *Mod);<br>
+ void BuildModuleInclude(<wbr>SourceLocation DirectiveLoc, Module *Mod,<br>
+ bool NoImport);<br>
<br>
/// \brief The parsed has entered a submodule.<br>
void ActOnModuleBegin(<wbr>SourceLocation DirectiveLoc, Module *Mod);<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp<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-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaDecl.cpp?rev=291628&r1=<wbr>291627&r2=291628&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.<wbr>cpp Tue Jan 10 18:48:19 2017<br>
@@ -15652,10 +15652,11 @@ DeclResult Sema::ActOnModuleImport(Sourc<br>
<br>
void Sema::ActOnModuleInclude(<wbr>SourceLocation DirectiveLoc, Module *Mod) {<br>
checkModuleImportContext(*<wbr>this, Mod, DirectiveLoc, CurContext, true);<br>
- BuildModuleInclude(<wbr>DirectiveLoc, Mod);<br>
+ BuildModuleInclude(<wbr>DirectiveLoc, Mod, false/*NoImport*/);<br>
}<br>
<br>
-void Sema::BuildModuleInclude(<wbr>SourceLocation DirectiveLoc, Module *Mod) {<br>
+void Sema::BuildModuleInclude(<wbr>SourceLocation 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(<wbr>SourceLoca<br>
TUKind == TU_Module &&<br>
getSourceManager().<wbr>isWrittenInMainFile(<wbr>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(<wbr>SourceLocation<br>
assert(File != getSourceManager().<wbr>getMainFileID() &&<br>
"end of submodule in main source file");<br>
SourceLocation DirectiveLoc = getSourceManager().<wbr>getIncludeLoc(File);<br>
- BuildModuleInclude(<wbr>DirectiveLoc, 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().<wbr>isCompilingModule();<br>
+ BuildModuleInclude(<wbr>DirectiveLoc, Mod, NoImport);<br>
}<br>
<br>
void Sema::<wbr>createImplicitModuleImportForE<wbr>rrorRecovery(SourceLocation 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-<wbr>project/cfe/trunk/test/<wbr>Modules/Inputs/module-impl-<wbr>with-link/foo.h?rev=291628&<wbr>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.<wbr>modulemap<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-<wbr>project/cfe/trunk/test/<wbr>Modules/Inputs/module-impl-<wbr>with-link/module.modulemap?<wbr>rev=291628&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.<wbr>modulemap (added)<br>
+++ cfe/trunk/test/Modules/Inputs/<wbr>module-impl-with-link/module.<wbr>modulemap 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-<wbr>project/cfe/trunk/test/<wbr>Modules/module-impl-with-link.<wbr>c?rev=291628&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-<wbr>link -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">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><br></div></div>