]> granicus.if.org Git - clang/commitdiff
[modules] Produce an error if -cc1 wants to implicitly build a module and no
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 21 Jul 2015 18:07:47 +0000 (18:07 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 21 Jul 2015 18:07:47 +0000 (18:07 +0000)
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

lib/Frontend/CompilerInstance.cpp
lib/Lex/HeaderSearch.cpp
test/Modules/no-implicit-builds.cpp

index c33b150e304739cfeddf4b4ab7801b2991782a95..9da69d476644d1cfefb9b77bd1c7c3c9b1a12ae4 100644 (file)
@@ -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();
index 983dc18b57afd6353f76bbaafca1c4e544e11170..5282e8d42e8d3e386b4d57aa55d8427bee79e3a6 100644 (file)
@@ -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);
index bfc3562dbcf414a44845920d4fa9acb80de108a7..374ed5e4181ef230f0c040635f013c5302541e91 100644 (file)
@@ -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 \