summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-05-18 03:52:30 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-05-18 03:52:30 +0000
commit96c71a1fddcd4142848f616097c1de5490ceffcb (patch)
treebcf5c4f4115f998123971f79fa1af6ec48d093d1
parent0412b95c27d2f2b3ad91639277630b3798387f10 (diff)
[modules] If we see a #include that maps to a module, but use of precompiled modules is disabled, track submodule visibility anyway if -fmodules-local-submodule-visibility is enabled. This, in effect, gives modules semantics but without precompilation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237550 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/HeaderSearch.h3
-rw-r--r--lib/Lex/HeaderSearch.cpp10
-rw-r--r--lib/Lex/PPDirectives.cpp39
-rw-r--r--test/Modules/cstd.m2
-rw-r--r--test/Modules/submodule-visibility.cpp1
5 files changed, 27 insertions, 28 deletions
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h
index 57da87e1d3..0406c6d586 100644
--- a/include/clang/Lex/HeaderSearch.h
+++ b/include/clang/Lex/HeaderSearch.h
@@ -479,9 +479,6 @@ public:
/// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
- /// Returns true if modules are enabled.
- bool enabledModules() const { return LangOpts.Modules; }
-
/// \brief Retrieve the name of the module file that should be used to
/// load the given module.
///
diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp
index 04cdb0f69f..ad7d3449ac 100644
--- a/lib/Lex/HeaderSearch.cpp
+++ b/lib/Lex/HeaderSearch.cpp
@@ -595,7 +595,13 @@ const FileEntry *HeaderSearch::LookupFile(
RelativePath->append(Filename.begin(), Filename.end());
}
// Otherwise, just return the file.
- return FileMgr.getFile(Filename, /*openFile=*/true);
+ const FileEntry *File = FileMgr.getFile(Filename, /*openFile=*/true);
+ if (File && SuggestedModule) {
+ // If there is a module that corresponds to this header, suggest it.
+ hasModuleMap(Filename, File->getDir(), /*SystemHeaderDir*/false);
+ *SuggestedModule = findModuleForHeader(File);
+ }
+ return File;
}
// This is the header that MSVC's header search would have found.
@@ -1070,7 +1076,7 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {
bool HeaderSearch::hasModuleMap(StringRef FileName,
const DirectoryEntry *Root,
bool IsSystem) {
- if (!enabledModules() || !LangOpts.ModulesImplicitMaps)
+ if (!HSOpts->ModuleMaps || !LangOpts.ModulesImplicitMaps)
return false;
SmallVector<const DirectoryEntry *, 2> FixUpDirectories;
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index a41ed8a1b4..86abe5ed89 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1762,13 +1762,12 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
// If this is a module import, make it visible if needed.
- if (IsModuleImport) {
- makeModuleVisible(SuggestedModule.getModule(), HashLoc);
+ if (auto *M = SuggestedModule.getModule()) {
+ makeModuleVisible(M, HashLoc);
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() !=
tok::pp___include_macros)
- EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include,
- SuggestedModule.getModule());
+ EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_include, M);
}
return;
}
@@ -1782,31 +1781,27 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
FileID FID = SourceMgr.createFileID(File, IncludePos, FileCharacter);
assert(!FID.isInvalid() && "Expected valid file ID");
- // Determine if we're switching to building a new submodule, and which one.
- //
- // FIXME: If we've already processed this header, just make it visible rather
- // than entering it again.
- ModuleMap::KnownHeader BuildingModule;
- if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) {
- Module *RequestingModule = getModuleForLocation(FilenameLoc);
- BuildingModule =
- HeaderInfo.getModuleMap().findModuleForHeader(File, RequestingModule);
- }
-
// If all is good, enter the new file!
if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
return;
- // If we're walking into another part of the same module, let the parser
- // know that any future declarations are within that other submodule.
- if (BuildingModule) {
+ // Determine if we're switching to building a new submodule, and which one.
+ //
+ // FIXME: If we've already processed this header, just make it visible rather
+ // than entering it again.
+ if (auto *M = SuggestedModule.getModule()) {
assert(!CurSubmodule && "should not have marked this as a module yet");
- CurSubmodule = BuildingModule.getModule();
+ CurSubmodule = M;
- EnterSubmodule(CurSubmodule, HashLoc);
+ // Let the macro handling code know that any future macros are within
+ // the new submodule.
+ EnterSubmodule(M, HashLoc);
- EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin,
- CurSubmodule);
+ // Let the parser know that any future declarations are within the new
+ // submodule.
+ // FIXME: There's no point doing this if we're handling a #__include_macros
+ // directive.
+ EnterAnnotationToken(*this, HashLoc, End, tok::annot_module_begin, M);
}
}
diff --git a/test/Modules/cstd.m b/test/Modules/cstd.m
index 24bca19b7a..200779a0f3 100644
--- a/test/Modules/cstd.m
+++ b/test/Modules/cstd.m
@@ -1,5 +1,5 @@
// RUN: rm -rf %t
-// RUN: %clang -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
+// RUN: %clang_cc1 -fsyntax-only -isystem %S/Inputs/System/usr/include -ffreestanding -fmodules -fmodules-cache-path=%t -D__need_wint_t -Werror=implicit-function-declaration %s
@import uses_other_constants;
const double other_value = DBL_MAX;
diff --git a/test/Modules/submodule-visibility.cpp b/test/Modules/submodule-visibility.cpp
index c63d942cc9..07be1c2d0c 100644
--- a/test/Modules/submodule-visibility.cpp
+++ b/test/Modules/submodule-visibility.cpp
@@ -2,6 +2,7 @@
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DALLOW_NAME_LEAKAGE
// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s -DIMPORT
// RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodules-cache-path=%t -fmodule-name=x -I%S/Inputs/submodule-visibility -verify %s
+// RUN: %clang_cc1 -fmodule-maps -fmodules-local-submodule-visibility -fmodules-cache-path=%t -I%S/Inputs/submodule-visibility -verify %s
#include "a.h"
#include "b.h"