From: Richard Smith Date: Tue, 21 Jul 2015 18:07:47 +0000 (+0000) Subject: [modules] Produce an error if -cc1 wants to implicitly build a module and no X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c18c81f52f445e66029e3aea6096647be60a903;p=clang [modules] Produce an error if -cc1 wants to implicitly build a module and no module cache has been provided, rather than creating one in the current directory. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242819 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index c33b150e30..9da69d4766 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -372,9 +372,8 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { std::string CompilerInstance::getSpecificModuleCachePath() { // Set up the module path, including the hash for the // module-creation options. - SmallString<256> SpecificModuleCache( - getHeaderSearchOpts().ModuleCachePath); - if (!getHeaderSearchOpts().DisableModuleHash) + SmallString<256> SpecificModuleCache(getHeaderSearchOpts().ModuleCachePath); + if (!SpecificModuleCache.empty() && !getHeaderSearchOpts().DisableModuleHash) llvm::sys::path::append(SpecificModuleCache, getInvocation().getModuleHash()); return SpecificModuleCache.str(); @@ -1406,17 +1405,17 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, auto Override = ModuleFileOverrides.find(ModuleName); bool Explicit = Override != ModuleFileOverrides.end(); - if (!Explicit && !getLangOpts().ImplicitModules) { + + std::string ModuleFileName = + Explicit ? Override->second + : PP->getHeaderSearchInfo().getModuleFileName(Module); + if (ModuleFileName.empty()) { getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled) << ModuleName; ModuleBuildFailed = true; return ModuleLoadResult(); } - std::string ModuleFileName = - Explicit ? Override->second - : PP->getHeaderSearchInfo().getModuleFileName(Module); - // If we don't already have an ASTReader, create one now. if (!ModuleManager) createModuleManager(); diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index 983dc18b57..5282e8d42e 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -127,8 +127,9 @@ std::string HeaderSearch::getModuleFileName(Module *Module) { std::string HeaderSearch::getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath) { - // If we don't have a module cache path, we can't do anything. - if (ModuleCachePath.empty()) + // 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) return std::string(); SmallString<256> Result(ModuleCachePath); diff --git a/test/Modules/no-implicit-builds.cpp b/test/Modules/no-implicit-builds.cpp index bfc3562dbc..374ed5e418 100644 --- a/test/Modules/no-implicit-builds.cpp +++ b/test/Modules/no-implicit-builds.cpp @@ -4,6 +4,11 @@ // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \ // RUN: -fmodule-map-file=%S/Inputs/no-implicit-builds/b.modulemap \ // RUN: -fno-implicit-modules %s -verify +// +// Same thing if we're running -cc1 and no module cache path has been provided. +// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps \ +// RUN: -fmodule-map-file=%S/Inputs/no-implicit-builds/b.modulemap \ +// RUN: %s -verify // Compile the module and put it into the cache. // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \