From 241bfa20d3f4d11859b72a2f5bce056ba1a20f88 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 15 Aug 2015 00:34:15 +0000 Subject: [PATCH] [modules] Stop dropping 'module.timestamp' files into the current directory when building with implicit modules disabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245136 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/CompilerInstance.cpp | 9 ++++++--- lib/Frontend/FrontendAction.cpp | 8 +++++--- lib/Lex/HeaderSearch.cpp | 4 ++-- test/Modules/explicit-build-extra-files.cpp | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 test/Modules/explicit-build-extra-files.cpp diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index a31b33ec37..c678da982e 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -331,7 +331,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { PP->setPreprocessedOutput(getPreprocessorOutputOpts().ShowCPP); - if (PP->getLangOpts().Modules) + if (PP->getLangOpts().Modules && PP->getLangOpts().ImplicitModules) PP->getHeaderSearchInfo().setModuleCachePath(getSpecificModuleCachePath()); // Handle generating dependencies, if requested. @@ -1154,6 +1154,7 @@ static void pruneModuleCache(const HeaderSearchOptions &HSOpts) { struct stat StatBuf; llvm::SmallString<128> TimestampFile; TimestampFile = HSOpts.ModuleCachePath; + assert(!TimestampFile.empty()); llvm::sys::path::append(TimestampFile, "modules.timestamp"); // Try to stat() the timestamp file. @@ -1232,8 +1233,8 @@ void CompilerInstance::createModuleManager() { // If we're implicitly building modules but not currently recursively // building a module, check whether we need to prune the module cache. - if (getLangOpts().ImplicitModules && - getSourceManager().getModuleBuildStack().empty() && + if (getSourceManager().getModuleBuildStack().empty() && + !getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty() && getHeaderSearchOpts().ModuleCachePruneInterval > 0 && getHeaderSearchOpts().ModuleCachePruneAfter > 0) { pruneModuleCache(getHeaderSearchOpts()); @@ -1600,6 +1601,8 @@ void CompilerInstance::makeModuleVisible(Module *Mod, GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( SourceLocation TriggerLoc) { + if (getPreprocessor().getHeaderSearchInfo().getModuleCachePath().empty()) + return nullptr; if (!ModuleManager) createModuleManager(); // Can't do anything if we don't have the module manager. diff --git a/lib/Frontend/FrontendAction.cpp b/lib/Frontend/FrontendAction.cpp index 36135e816f..5b7494da58 100644 --- a/lib/Frontend/FrontendAction.cpp +++ b/lib/Frontend/FrontendAction.cpp @@ -442,9 +442,11 @@ bool FrontendAction::Execute() { // there were any module-build failures. if (CI.shouldBuildGlobalModuleIndex() && CI.hasFileManager() && CI.hasPreprocessor()) { - GlobalModuleIndex::writeIndex( - CI.getFileManager(), CI.getPCHContainerReader(), - CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath()); + StringRef Cache = + CI.getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); + if (!Cache.empty()) + GlobalModuleIndex::writeIndex(CI.getFileManager(), + CI.getPCHContainerReader(), Cache); } return true; diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 5282e8d42e..eea47198d6 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -129,10 +129,10 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath) { // If we don't have a module cache path or aren't supposed to use one, we // can't do anything. - if (ModuleCachePath.empty() || !LangOpts.ImplicitModules) + if (getModuleCachePath().empty()) return std::string(); - SmallString<256> Result(ModuleCachePath); + SmallString<256> Result(getModuleCachePath()); llvm::sys::fs::make_absolute(Result); if (HSOpts->DisableModuleHash) { diff --git a/test/Modules/explicit-build-extra-files.cpp b/test/Modules/explicit-build-extra-files.cpp new file mode 100644 index 0000000000..6cec420832 --- /dev/null +++ b/test/Modules/explicit-build-extra-files.cpp @@ -0,0 +1,14 @@ +// REQUIRES: shell +// +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cd %t +// RUN: echo 'module X {}' > %t/x +// RUN: echo 'module Y {}' > %t/y +// +// RUN: %clang_cc1 -emit-module -fmodules -fmodule-name=X %t/x -x c++ -o %t/x.pcm +// RUN: %clang_cc1 -emit-module -fmodules -fmodule-name=Y %t/y -x c++ -o %t/y.pcm +// RUN: %clang_cc1 -fmodules -fmodule-file=%t/x.pcm -fmodule-file=%t/y.pcm -x c++ /dev/null -fsyntax-only +// +// RUN: not test -f %t/modules.timestamp +// RUN: not test -f %t/modules.idx -- 2.40.0