Module: Do not create Implicit ImportDecl for module X if we

are building an implemenation of module X.

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

llvm-svn: 291628
This commit is contained in:
Manman Ren 2017-01-11 00:48:19 +00:00
parent a9054ddd9c
commit 7f41c4d802
5 changed files with 23 additions and 5 deletions

View 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);

View 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,

View File

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

View File

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

View File

@ -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]] = !{}