This reverts r291628. As suggested by Richard, we can simply

filter out the implicilty imported modules at CodeGen instead of removing the
implicit ImportDecl when an implementation TU of a module imports a header of
that same module.

llvm-svn: 291688
This commit is contained in:
Manman Ren 2017-01-11 18:32:30 +00:00
parent d1efea89c9
commit 3e9dea024e
5 changed files with 5 additions and 23 deletions

View File

@ -1905,8 +1905,7 @@ public:
/// \brief The parser has processed a module import translated from a /// \brief The parser has processed a module import translated from a
/// #include or similar preprocessing directive. /// #include or similar preprocessing directive.
void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); 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. /// \brief The parsed has entered a submodule.
void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod);

View File

@ -15652,11 +15652,10 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true); checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext, true);
BuildModuleInclude(DirectiveLoc, Mod, false/*NoImport*/); BuildModuleInclude(DirectiveLoc, Mod);
} }
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 // 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 // in that buffer do not qualify as module imports; they're just an
// implementation detail of us building the module. // implementation detail of us building the module.
@ -15666,7 +15665,7 @@ void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod,
TUKind == TU_Module && TUKind == TU_Module &&
getSourceManager().isWrittenInMainFile(DirectiveLoc); getSourceManager().isWrittenInMainFile(DirectiveLoc);
bool ShouldAddImport = !IsInModuleIncludes && !NoImport; bool ShouldAddImport = !IsInModuleIncludes;
// If this module import was due to an inclusion directive, create an // If this module import was due to an inclusion directive, create an
// implicit import declaration to capture it in the AST. // implicit import declaration to capture it in the AST.
@ -15714,11 +15713,7 @@ void Sema::ActOnModuleEnd(SourceLocation EofLoc, Module *Mod) {
assert(File != getSourceManager().getMainFileID() && assert(File != getSourceManager().getMainFileID() &&
"end of submodule in main source file"); "end of submodule in main source file");
SourceLocation DirectiveLoc = getSourceManager().getIncludeLoc(File); SourceLocation DirectiveLoc = getSourceManager().getIncludeLoc(File);
// Do not create implicit ImportDecl if we are building the implementation BuildModuleInclude(DirectiveLoc, Mod);
// of a module.
bool NoImport = Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
!getLangOpts().isCompilingModule();
BuildModuleInclude(DirectiveLoc, Mod, NoImport);
} }
void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc, void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc,

View File

@ -1 +0,0 @@
//empty

View File

@ -1,4 +0,0 @@
module Clib {
header "foo.h"
link "Clib"
}

View File

@ -1,7 +0,0 @@
// 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]] = !{}