r228966 - Mangle the IsSystem bit into the .pcm file name

Ben Langmuir blangmuir at apple.com
Thu Feb 12 13:51:32 PST 2015


Author: benlangmuir
Date: Thu Feb 12 15:51:31 2015
New Revision: 228966

URL: http://llvm.org/viewvc/llvm-project?rev=228966&view=rev
Log:
Mangle the IsSystem bit into the .pcm file name

When mangling the module map path into a .pcm file name, also mangle the
IsSystem bit, which can also depend on the header search paths. For
example, the user may change from -I to -isystem.  This can affect
diagnostics in the importing TU.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
    cfe/trunk/include/clang/Lex/HeaderSearch.h
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/Modules/modules-with-same-name.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Thu Feb 12 15:51:31 2015
@@ -64,6 +64,9 @@ def err_imported_module_relocated : Erro
 def err_module_different_modmap : Error<
     "module '%0' %select{uses|does not use}1 additional module map '%2'"
     "%select{| not}1 used when the module was built">;
+def err_module_system_change : Error<
+    "module '%0' %select{is|is not}1 a 'system' module, but "
+    "%select{was not|was}1 when the module was built">;
 def warn_module_conflict : Warning<
     "module '%0' conflicts with already-imported module '%1': %2">, 
     InGroup<ModuleConflict>;

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Thu Feb 12 15:51:31 2015
@@ -496,11 +496,15 @@ public:
   /// \param ModuleName The module whose module file name will be returned.
   ///
   /// \param ModuleMapPath A path that when combined with \c ModuleName
-  /// uniquely identifies this module. See Module::ModuleMap.
+  /// and \p IsSystem uniquely identifies this module. See Module::ModuleMap.
+  ///
+  /// \param IsSystem Whether the \p ModuleName is a system module, which may
+  /// depend on how header search paths were specified.
   ///
   /// \returns The name of the module file that corresponds to this module,
   /// or an empty string if this module does not correspond to any module file.
-  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath);
+  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath,
+                                bool IsSystem);
 
   /// \brief Lookup a module Search for a module with the given name.
   ///

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Thu Feb 12 15:51:31 2015
@@ -366,7 +366,7 @@ bool GenerateModuleAction::ComputeASTCon
     HeaderSearch &HS = CI.getPreprocessor().getHeaderSearchInfo();
     CI.getFrontendOpts().OutputFile =
         HS.getModuleFileName(CI.getLangOpts().CurrentModule,
-                             ModuleMapForUniquing->getName());
+                             ModuleMapForUniquing->getName(), IsSystem);
   }
   
   // We use createOutputFile here because this is exposed via libclang, and we

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Thu Feb 12 15:51:31 2015
@@ -115,11 +115,13 @@ const HeaderMap *HeaderSearch::CreateHea
 std::string HeaderSearch::getModuleFileName(Module *Module) {
   const FileEntry *ModuleMap =
       getModuleMap().getModuleMapFileForUniquing(Module);
-  return getModuleFileName(Module->Name, ModuleMap->getName());
+  return getModuleFileName(Module->Name, ModuleMap->getName(),
+                           Module->IsSystem);
 }
 
 std::string HeaderSearch::getModuleFileName(StringRef ModuleName,
-                                            StringRef ModuleMapPath) {
+                                            StringRef ModuleMapPath,
+                                            bool IsSystem) {
   // If we don't have a module cache path, we can't do anything.
   if (ModuleCachePath.empty()) 
     return std::string();
@@ -147,6 +149,10 @@ std::string HeaderSearch::getModuleFileN
     llvm::hash_code Hash =
         llvm::hash_combine(DirName.lower(), FileName.lower());
 
+    // Hash the IsSystem bit, since changing search paths can change whether a
+    // module is considered 'system' or not.
+    Hash = llvm::hash_combine(Hash, IsSystem);
+
     SmallString<128> HashStr;
     llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36);
     llvm::sys::path::append(Result, ModuleName + "-" + HashStr.str() + ".pcm");

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Feb 12 15:51:31 2015
@@ -3435,6 +3435,13 @@ ASTReader::ReadModuleMapFileBlock(Record
           << F.ModuleName << /*not new*/1 << ModMap->getName();
       return OutOfDate;
     }
+
+    // Check whether the 'IsSystem' bit changed.
+    if (M->IsSystem != static_cast<bool>(Record[Idx])) {
+      if ((ClientLoadCapabilities & ARR_OutOfDate) == 0)
+        Diag(diag::err_module_system_change) << F.ModuleName << M->IsSystem;
+      return OutOfDate;
+    }
   }
 
   if (Listener)

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Feb 12 15:51:31 2015
@@ -1215,6 +1215,7 @@ void ASTWriter::WriteControlBlock(Prepro
       Record.push_back(0);
     }
 
+    Record.push_back(WritingModule->IsSystem);
     Stream.EmitRecord(MODULE_MAP_FILE, Record);
   }
 

Modified: cfe/trunk/test/Modules/modules-with-same-name.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/modules-with-same-name.m?rev=228966&r1=228965&r2=228966&view=diff
==============================================================================
--- cfe/trunk/test/Modules/modules-with-same-name.m (original)
+++ cfe/trunk/test/Modules/modules-with-same-name.m Thu Feb 12 15:51:31 2015
@@ -21,6 +21,14 @@
 // Confirm that we still have three pcm files, since DependsOnA will be rebuilt
 // RUN: find %t -name "*.pcm" | count 3
 
+// DependsOnA, using A from path 2, as a system path
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodules-ignore-macro=EXPECTED_PATH -fmodules-ignore-macro=DIRECT -fsyntax-only %s -I %S/Inputs/modules-with-same-name/DependsOnA -isystem %S/Inputs/modules-with-same-name/path2/A -DEXPECTED_PATH=2 -Rmodule-build 2> %t.log
+// Confirm that we built a new module for A
+// RUN: FileCheck %s < %t.log
+// CHECK: building module 'DependsOnA'
+// CHECK: building module 'A'
+// RUN: find %t -name "*.pcm" | count 4
+
 #ifdef DIRECT
 @import A;
 #else





More information about the cfe-commits mailing list